@blocto/sdk
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).BloctoSDK=e()}(this,(function(){"use strict";function t(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function e(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}function r(t,e){if(!t)throw new Error(e)}var n,i;"function"==typeof SuppressedError&&SuppressedError,function(t){t.prod="BLOCTO_SDK",t.dev="BLOCTO_SDK_DEV",t.staging="BLOCTO_SDK_STAGING"}(n||(n={})),function(t){t.ETHEREUM="ethereum",t.APTOS="aptos"}(i||(i={}));const o={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545",137:"https://rpc-mainnet.maticvigil.com/",80001:"https://rpc-mumbai.matic.today/",43114:"https://api.avax.network/ext/bc/C/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",42161:"https://arb1.arbitrum.io/rpc",421613:"https://endpoints.omniatech.io/v1/arbitrum/goerli/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io"},s={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},a={prod:n.prod,staging:n.staging,dev:n.dev},u={1:n.prod,2:n.dev,3:n.dev,4:n.dev,5:n.staging},c={1:"https://wallet-v2.blocto.app",2:"https://wallet-v2-dev.blocto.app",3:"https://wallet-v2-dev.blocto.app",4:"https://wallet-v2-dev.blocto.app",5:"https://wallet-v2-staging.blocto.app"};var h;!function(t){t.Mainnet="mainnet",t.Testnet="testnet",t.Devnet="devnet",t.Testing="testing",t.Premainnet="premainnet"}(h||(h={}));const d={1:h.Mainnet,2:h.Testnet,3:h.Devnet,4:h.Testing,5:h.Premainnet},l={1:"https://fullnode.mainnet.aptoslabs.com/v1",2:"https://fullnode.testnet.aptoslabs.com/v1",3:"https://fullnode.devnet.aptoslabs.com/v1",4:"",5:"https://premainnet.aptosdev.com/v1"},f=["connect","disconnect","message","chainChanged","accountsChanged"],p="00000000-0000-0000-0000-000000000000",v="0.7.1";class g{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,f.forEach((t=>{this.eventListeners[t]=[]})),this.appId=p}request(e){return t(this,void 0,void 0,(function*(){}))}on(t,e){f.includes(t)&&this.eventListeners[t].push(e)}once(){}removeListener(t,e){const r=this.eventListeners[t].findIndex((t=>t===e));-1!==r&&this.eventListeners[t].splice(r,1)}}function y(t){const e=document.createElement("iframe");return e.setAttribute("src",t),e.setAttribute("style","width:100vw;height:100%;position:fixed;top:0;left:0;z-index:2147483646;border:none;box-sizing:border-box;color-scheme:light;inset:0px;display:block;pointer-events:auto;"),e}function m(t){document.body.appendChild(t)}function w(t){const e=t&&t.parentNode;e&&e.removeChild instanceof Function&&e.removeChild(t)}var b=(t,e,r=window)=>{r.addEventListener(t,(function n(i){e(i,(()=>r.removeEventListener(t,n)))}))};const E="undefined"!=typeof window?window.memoryStorage:new class{constructor(){this.storage={}}getItem(t){return this[t]||null}setItem(t,e){this.storage[t]=e}removeItem(t){delete this.storage[t]}},S=(()=>{if("undefined"==typeof window)return!1;try{window.sessionStorage.setItem("local_storage_supported","1");const t=window.sessionStorage.getItem("local_storage_supported");return window.sessionStorage.removeItem("local_storage_supported"),"1"===t}catch(t){return!1}})()?window.sessionStorage:E,_=(t,e=null)=>{const r=S.getItem(t);try{return r&&JSON.parse(r)||e}catch(t){return r||e}},A=(t,e)=>S.setItem(t,"string"==typeof e?e:JSON.stringify(e)),O=t=>{A(t,""),S.removeItem(t)},R=t=>{const e=_(t,null);return e?(new Date).getTime()>e.expiry||e.v!==v?(O(t),null):null==e?void 0:e.data:null},P=(t,e,r)=>{var n,i,o;const s=_(t),a={data:{code:(null==e?void 0:e.code)||(null===(n=null==s?void 0:s.data)||void 0===n?void 0:n.code),accounts:Object.assign(Object.assign({},null===(i=null==s?void 0:s.data)||void 0===i?void 0:i.accounts),null==e?void 0:e.accounts),evm:Object.assign(Object.assign({},null===(o=null==s?void 0:s.data)||void 0===o?void 0:o.evm),null==e?void 0:e.evm)},expiry:r||(null==s?void 0:s.expiry)||(new Date).getTime()+864e5,v:v};A(t,a)},I=(t,e)=>{var r,n,i;return(null===(r=R(t))||void 0===r?void 0:r.code)?(null===(i=null===(n=R(t))||void 0===n?void 0:n.accounts)||void 0===i?void 0:i[e])||null:(O(t),null)},T=(t,e)=>{var r,n,i;return(null===(r=R(t))||void 0===r?void 0:r.code)?(null===(i=null===(n=R(t))||void 0===n?void 0:n.evm)||void 0===i?void 0:i[e])||null:(O(t),null)},C=(t,e,r)=>{P(t,{evm:{[e]:r}})},N=t=>{const e=_(t);e&&(e.data.evm={},A(t,e))};function j(e,r,n){return t(this,void 0,void 0,(function*(){if(403!==e.status&&401!==e.status||(n&&n(),O(r)),!e.ok){const t=yield e.json(),r=new Error((null==t?void 0:t.message)||"unknown error");throw r.error_code=null==t?void 0:t.error_code,r}return e.json()}))}const L=t=>/\S+@\S+\.\S+/.test(t);var M;!function(t){t.INVALID_TRANSACTION="Invalid transaction",t.INVALID_TRANSACTIONS="Invalid transactions",t.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'}(M||(M={}));var k="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},U=[],B=[],D="undefined"!=typeof Uint8Array?Uint8Array:Array,x=!1;function K(){x=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)U[e]=t[e],B[t.charCodeAt(e)]=e;B["-".charCodeAt(0)]=62,B["_".charCodeAt(0)]=63}function $(t,e,r){for(var n,i,o=[],s=e;s<r;s+=3)n=(t[s]<<16)+(t[s+1]<<8)+t[s+2],o.push(U[(i=n)>>18&63]+U[i>>12&63]+U[i>>6&63]+U[63&i]);return o.join("")}function V(t){var e;x||K();for(var r=t.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;a<u;a+=s)o.push($(t,a,a+s>u?u:a+s));return 1===n?(e=t[r-1],i+=U[e>>2],i+=U[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=U[e>>10],i+=U[e>>4&63],i+=U[e<<2&63],i+="="),o.push(i),o.join("")}function Y(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,h=-7,d=r?i-1:0,l=r?-1:1,f=t[e+d];for(d+=l,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+t[e+d],d+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+d],d+=l,h-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=c}return(f?-1:1)*s*Math.pow(2,o-n)}function q(t,e,r,n,i,o){var s,a,u,c=8*o-i-1,h=(1<<c)-1,d=h>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,v=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+d>=1?l/u:l*Math.pow(2,1-d))*u>=2&&(s++,u/=2),s+d>=h?(a=0,s=h):s+d>=1?(a=(e*u-1)*Math.pow(2,i),s+=d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;t[r+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;t[r+f]=255&s,f+=p,s/=256,c-=8);t[r+f-p]|=128*v}var F={}.toString,z=Array.isArray||function(t){return"[object Array]"==F.call(t)};function J(){return G.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function H(t,e){if(J()<e)throw new RangeError("Invalid typed array length");return G.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=G.prototype:(null===t&&(t=new G(e)),t.length=e),t}function G(t,e,r){if(!(G.TYPED_ARRAY_SUPPORT||this instanceof G))return new G(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return Z(this,t)}return W(this,t,e,r)}function W(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);G.TYPED_ARRAY_SUPPORT?(t=e).__proto__=G.prototype:t=Q(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!G.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|rt(e,r);t=H(t,n);var i=t.write(e,r);i!==n&&(t=t.slice(0,i));return t}(t,e,r):function(t,e){if(et(e)){var r=0|tt(e.length);return 0===(t=H(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?H(t,0):Q(t,e);if("Buffer"===e.type&&z(e.data))return Q(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function X(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function Z(t,e){if(X(e),t=H(t,e<0?0:0|tt(e)),!G.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function Q(t,e){var r=e.length<0?0:0|tt(e.length);t=H(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function tt(t){if(t>=J())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+J().toString(16)+" bytes");return 0|t}function et(t){return!(null==t||!t._isBuffer)}function rt(t,e){if(et(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Tt(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Ct(t).length;default:if(n)return Tt(t).length;e=(""+e).toLowerCase(),n=!0}}function nt(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return mt(this,e,r);case"utf8":case"utf-8":return pt(this,e,r);case"ascii":return gt(this,e,r);case"latin1":case"binary":return yt(this,e,r);case"base64":return ft(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return wt(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function it(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function ot(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=G.from(e,n)),et(e))return 0===e.length?-1:st(t,e,r,n,i);if("number"==typeof e)return e&=255,G.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):st(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function st(t,e,r,n,i){var o,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var h=-1;for(o=r;o<a;o++)if(c(t,o)===c(e,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===u)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var d=!0,l=0;l<u;l++)if(c(t,o+l)!==c(e,l)){d=!1;break}if(d)return o}return-1}function at(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}function ut(t,e,r,n){return Nt(Tt(e,t.length-r),t,r,n)}function ct(t,e,r,n){return Nt(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function ht(t,e,r,n){return ct(t,e,r,n)}function dt(t,e,r,n){return Nt(Ct(e),t,r,n)}function lt(t,e,r,n){return Nt(function(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(r=t.charCodeAt(s))>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function ft(t,e,r){return 0===e&&r===t.length?V(t):V(t.slice(e,r))}function pt(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,a,u,c=t[i],h=null,d=c>239?4:c>223?3:c>191?2:1;if(i+d<=r)switch(d){case 1:c<128&&(h=c);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&c)<<6|63&o)>127&&(h=u);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,d=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=d}return function(t){var e=t.length;if(e<=vt)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=vt));return r}(n)}G.TYPED_ARRAY_SUPPORT=void 0===k.TYPED_ARRAY_SUPPORT||k.TYPED_ARRAY_SUPPORT,J(),G.poolSize=8192,G._augment=function(t){return t.__proto__=G.prototype,t},G.from=function(t,e,r){return W(null,t,e,r)},G.TYPED_ARRAY_SUPPORT&&(G.prototype.__proto__=Uint8Array.prototype,G.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&G[Symbol.species]),G.alloc=function(t,e,r){return function(t,e,r,n){return X(e),e<=0?H(t,e):void 0!==r?"string"==typeof n?H(t,e).fill(r,n):H(t,e).fill(r):H(t,e)}(null,t,e,r)},G.allocUnsafe=function(t){return Z(null,t)},G.allocUnsafeSlow=function(t){return Z(null,t)},G.isBuffer=function(t){return null!=t&&(!!t._isBuffer||jt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&jt(t.slice(0,0))}(t))},G.compare=function(t,e){if(!et(t)||!et(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},G.isEncoding=function(t){switch(String(t).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}},G.concat=function(t,e){if(!z(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return G.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=G.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(!et(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},G.byteLength=rt,G.prototype._isBuffer=!0,G.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)it(this,e,e+1);return this},G.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)it(this,e,e+3),it(this,e+1,e+2);return this},G.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)it(this,e,e+7),it(this,e+1,e+6),it(this,e+2,e+5),it(this,e+3,e+4);return this},G.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?pt(this,0,t):nt.apply(this,arguments)},G.prototype.equals=function(t){if(!et(t))throw new TypeError("Argument must be a Buffer");return this===t||0===G.compare(this,t)},G.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},G.prototype.compare=function(t,e,r,n,i){if(!et(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(o,s),u=this.slice(n,i),c=t.slice(e,r),h=0;h<a;++h)if(u[h]!==c[h]){o=u[h],s=c[h];break}return o<s?-1:s<o?1:0},G.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},G.prototype.indexOf=function(t,e,r){return ot(this,t,e,r,!0)},G.prototype.lastIndexOf=function(t,e,r){return ot(this,t,e,r,!1)},G.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return at(this,t,e,r);case"utf8":case"utf-8":return ut(this,t,e,r);case"ascii":return ct(this,t,e,r);case"latin1":case"binary":return ht(this,t,e,r);case"base64":return dt(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lt(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},G.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var vt=4096;function gt(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function yt(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function mt(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=It(t[o]);return i}function wt(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function bt(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function Et(t,e,r,n,i,o){if(!et(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function St(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function _t(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function At(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Ot(t,e,r,n,i){return i||At(t,0,r,4),q(t,e,r,n,23,4),r+4}function Rt(t,e,r,n,i){return i||At(t,0,r,8),q(t,e,r,n,52,8),r+8}G.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),G.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=G.prototype;else{var i=e-t;r=new G(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},G.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},G.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},G.prototype.readUInt8=function(t,e){return e||bt(t,1,this.length),this[t]},G.prototype.readUInt16LE=function(t,e){return e||bt(t,2,this.length),this[t]|this[t+1]<<8},G.prototype.readUInt16BE=function(t,e){return e||bt(t,2,this.length),this[t]<<8|this[t+1]},G.prototype.readUInt32LE=function(t,e){return e||bt(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},G.prototype.readUInt32BE=function(t,e){return e||bt(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},G.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},G.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},G.prototype.readInt8=function(t,e){return e||bt(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},G.prototype.readInt16LE=function(t,e){e||bt(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},G.prototype.readInt16BE=function(t,e){e||bt(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},G.prototype.readInt32LE=function(t,e){return e||bt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},G.prototype.readInt32BE=function(t,e){return e||bt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},G.prototype.readFloatLE=function(t,e){return e||bt(t,4,this.length),Y(this,t,!0,23,4)},G.prototype.readFloatBE=function(t,e){return e||bt(t,4,this.length),Y(this,t,!1,23,4)},G.prototype.readDoubleLE=function(t,e){return e||bt(t,8,this.length),Y(this,t,!0,52,8)},G.prototype.readDoubleBE=function(t,e){return e||bt(t,8,this.length),Y(this,t,!1,52,8)},G.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||Et(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},G.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||Et(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},G.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,1,255,0),G.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},G.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,2,65535,0),G.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):St(this,t,e,!0),e+2},G.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,2,65535,0),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):St(this,t,e,!1),e+2},G.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,4,4294967295,0),G.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):_t(this,t,e,!0),e+4},G.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,4,4294967295,0),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):_t(this,t,e,!1),e+4},G.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);Et(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===a&&0!==this[e+o-1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},G.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);Et(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},G.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,1,127,-128),G.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},G.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,2,32767,-32768),G.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):St(this,t,e,!0),e+2},G.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,2,32767,-32768),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):St(this,t,e,!1),e+2},G.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,4,2147483647,-2147483648),G.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):_t(this,t,e,!0),e+4},G.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||Et(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):_t(this,t,e,!1),e+4},G.prototype.writeFloatLE=function(t,e,r){return Ot(this,t,e,!0,r)},G.prototype.writeFloatBE=function(t,e,r){return Ot(this,t,e,!1,r)},G.prototype.writeDoubleLE=function(t,e,r){return Rt(this,t,e,!0,r)},G.prototype.writeDoubleBE=function(t,e,r){return Rt(this,t,e,!1,r)},G.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;i>=0;--i)t[i+e]=this[i+r];else if(o<1e3||!G.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},G.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!G.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=et(t)?t:Tt(new G(t,n).toString()),a=s.length;for(o=0;o<r-e;++o)this[o+e]=s[o%a]}return this};var Pt=/[^+\/0-9A-Za-z-_]/g;function It(t){return t<16?"0"+t.toString(16):t.toString(16)}function Tt(t,e){var r;e=e||1/0;for(var n=t.length,i=null,o=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Ct(t){return function(t){var e,r,n,i,o,s;x||K();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[a-2]?2:"="===t[a-1]?1:0,s=new D(3*a/4-o),n=o>0?a-4:a;var u=0;for(e=0,r=0;e<n;e+=4,r+=3)i=B[t.charCodeAt(e)]<<18|B[t.charCodeAt(e+1)]<<12|B[t.charCodeAt(e+2)]<<6|B[t.charCodeAt(e+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=B[t.charCodeAt(e)]<<2|B[t.charCodeAt(e+1)]>>4,s[u++]=255&i):1===o&&(i=B[t.charCodeAt(e)]<<10|B[t.charCodeAt(e+1)]<<4|B[t.charCodeAt(e+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Pt,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Nt(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function jt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}const Lt=t=>"string"==typeof t&&/^0x[0-9A-Fa-f]*$/.test(t),Mt=t=>G.from(t,"utf8").toString("hex"),kt=t=>t&&"object"==typeof t&&"from"in t?t.value&&!Lt(t.value)?{isValid:!1,invalidMsg:M.INVALID_TRANSACTION_VALUE}:{isValid:!0}:{isValid:!1,invalidMsg:M.INVALID_TRANSACTION};var Ut={};function Bt(t){return Bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Bt(t)}function Dt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function xt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(i=n.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(i,"string"))?o:String(o)),n)}var i,o}function Kt(t,e,r){return e&&xt(t.prototype,e),r&&xt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function $t(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Yt(t,e)}function Vt(t){return Vt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Vt(t)}function Yt(t,e){return Yt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Yt(t,e)}function qt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function Ft(t,e,r){return Ft=qt()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&Yt(i,r.prototype),i},Ft.apply(null,arguments)}function zt(t){var e="function"==typeof Map?new Map:void 0;return zt=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return Ft(t,arguments,Vt(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Yt(n,t)},zt(t)}function Jt(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function Ht(t){var e=qt();return function(){var r,n=Vt(t);if(e){var i=Vt(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return Jt(this,r)}}function Gt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,s,a=[],u=!0,c=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(a.push(n.value),a.length!==e);u=!0);}catch(t){c=!0,i=t}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return Wt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Wt(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Wt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var Xt={},Zt=ie;ie.default=ie,ie.stable=ue,ie.stableStringify=ue;var Qt="[...]",te="[Circular]",ee=[],re=[];function ne(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function ie(t,e,r,n){var i;void 0===n&&(n=ne()),se(t,"",0,[],void 0,0,n);try{i=0===re.length?JSON.stringify(t,e,r):JSON.stringify(t,he(e),r)}catch(t){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==ee.length;){var o=ee.pop();4===o.length?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function oe(t,e,r,n){var i=Object.getOwnPropertyDescriptor(n,r);void 0!==i.get?i.configurable?(Object.defineProperty(n,r,{value:t}),ee.push([n,r,e,i])):re.push([e,r,t]):(n[r]=t,ee.push([n,r,e]))}function se(t,e,r,n,i,o,s){var a;if(o+=1,"object"===Bt(t)&&null!==t){for(a=0;a<n.length;a++)if(n[a]===t)return void oe(te,t,e,i);if(void 0!==s.depthLimit&&o>s.depthLimit)return void oe(Qt,t,e,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void oe(Qt,t,e,i);if(n.push(t),Array.isArray(t))for(a=0;a<t.length;a++)se(t[a],a,a,n,t,o,s);else{var u=Object.keys(t);for(a=0;a<u.length;a++){var c=u[a];se(t[c],c,a,n,t,o,s)}}n.pop()}}function ae(t,e){return t<e?-1:t>e?1:0}function ue(t,e,r,n){void 0===n&&(n=ne());var i,o=ce(t,"",0,[],void 0,0,n)||t;try{i=0===re.length?JSON.stringify(o,e,r):JSON.stringify(o,he(e),r)}catch(t){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==ee.length;){var s=ee.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return i}function ce(t,e,r,n,i,o,s){var a;if(o+=1,"object"===Bt(t)&&null!==t){for(a=0;a<n.length;a++)if(n[a]===t)return void oe(te,t,e,i);try{if("function"==typeof t.toJSON)return}catch(t){return}if(void 0!==s.depthLimit&&o>s.depthLimit)return void oe(Qt,t,e,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void oe(Qt,t,e,i);if(n.push(t),Array.isArray(t))for(a=0;a<t.length;a++)ce(t[a],a,a,n,t,o,s);else{var u={},c=Object.keys(t).sort(ae);for(a=0;a<c.length;a++){var h=c[a];ce(t[h],h,a,n,t,o,s),u[h]=t[h]}if(void 0===i)return u;ee.push([i,e,t]),i[e]=u}n.pop()}}function he(t){return t=void 0!==t?t:function(t,e){return e},function(e,r){if(re.length>0)for(var n=0;n<re.length;n++){var i=re[n];if(i[1]===e&&i[0]===r){r=i[2],re.splice(n,1);break}}return t.call(this,e,r)}}Object.defineProperty(Xt,"__esModule",{value:!0}),Xt.EthereumProviderError=Xt.EthereumRpcError=void 0;var de=Zt,le=function(t){$t(r,t);var e=Ht(r);function r(t,n,i){var o;if(Dt(this,r),!Number.isInteger(t))throw new Error('"code" must be an integer.');if(!n||"string"!=typeof n)throw new Error('"message" must be a nonempty string.');return(o=e.call(this,n)).code=t,void 0!==i&&(o.data=i),o}return Kt(r,[{key:"serialize",value:function(){var t={code:this.code,message:this.message};return void 0!==this.data&&(t.data=this.data),this.stack&&(t.stack=this.stack),t}},{key:"toString",value:function(){return de.default(this.serialize(),pe,2)}}]),r}(zt(Error));Xt.EthereumRpcError=le;var fe=function(t){$t(r,t);var e=Ht(r);function r(t,n,i){if(Dt(this,r),!function(t){return Number.isInteger(t)&&t>=1e3&&t<=4999}(t))throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');return e.call(this,t,n,i)}return Kt(r)}(le);function pe(t,e){if("[Circular]"!==e)return e}Xt.EthereumProviderError=fe;var ve={},ge={};Object.defineProperty(ge,"__esModule",{value:!0}),ge.errorValues=ge.errorCodes=void 0,ge.errorCodes={rpc:{invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},provider:{userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901}},ge.errorValues={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."}},function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.serializeError=t.isValidCode=t.getMessageFromCode=t.JSON_RPC_SERVER_ERROR_MESSAGE=void 0;var e=ge,r=Xt,n=e.errorCodes.rpc.internal,i="Unspecified error message. This is a bug, please report it.",o={code:n,message:s(n)};function s(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i;if(Number.isInteger(r)){var o=r.toString();if(h(e.errorValues,o))return e.errorValues[o].message;if(u(r))return t.JSON_RPC_SERVER_ERROR_MESSAGE}return n}function a(t){if(!Number.isInteger(t))return!1;var r=t.toString();return!!e.errorValues[r]||!!u(t)}function u(t){return t>=-32099&&t<=-32e3}function c(t){return t&&"object"===Bt(t)&&!Array.isArray(t)?Object.assign({},t):t}function h(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.JSON_RPC_SERVER_ERROR_MESSAGE="Unspecified server error.",t.getMessageFromCode=s,t.isValidCode=a,t.serializeError=function(t){var e,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=i.fallbackError,d=void 0===u?o:u,l=i.shouldIncludeStack,f=void 0!==l&&l;if(!d||!Number.isInteger(d.code)||"string"!=typeof d.message)throw new Error("Must provide fallback error with integer number code and string message.");if(t instanceof r.EthereumRpcError)return t.serialize();var p={};if(t&&"object"===Bt(t)&&!Array.isArray(t)&&h(t,"code")&&a(t.code)){var v=t;p.code=v.code,v.message&&"string"==typeof v.message?(p.message=v.message,h(v,"data")&&(p.data=v.data)):(p.message=s(p.code),p.data={originalError:c(t)})}else{p.code=d.code;var g=null===(e=t)||void 0===e?void 0:e.message;p.message=g&&"string"==typeof g?g:d.message,p.data={originalError:c(t)}}var y=null===(n=t)||void 0===n?void 0:n.stack;return f&&t&&y&&"string"==typeof y&&(p.stack=y),p}}(ve);var ye={};Object.defineProperty(ye,"__esModule",{value:!0}),ye.ethErrors=void 0;var me,we,be,Ee,Se,_e=Xt,Ae=ve,Oe=ge;function Re(t,e){var r=Gt(Ie(e),2),n=r[0],i=r[1];return new _e.EthereumRpcError(t,n||Ae.getMessageFromCode(t),i)}function Pe(t,e){var r=Gt(Ie(e),2),n=r[0],i=r[1];return new _e.EthereumProviderError(t,n||Ae.getMessageFromCode(t),i)}function Ie(t){if(t){if("string"==typeof t)return[t];if("object"===Bt(t)&&!Array.isArray(t)){var e=t.message,r=t.data;if(e&&"string"!=typeof e)throw new Error("Must specify string message.");return[e||void 0,r]}}return[]}function Te(t){return t?"number"==typeof t?t:t.startsWith("0x")?parseInt(t,16):parseInt(t,10):1}ye.ethErrors={rpc:{parse:function(t){return Re(Oe.errorCodes.rpc.parse,t)},invalidRequest:function(t){return Re(Oe.errorCodes.rpc.invalidRequest,t)},invalidParams:function(t){return Re(Oe.errorCodes.rpc.invalidParams,t)},methodNotFound:function(t){return Re(Oe.errorCodes.rpc.methodNotFound,t)},internal:function(t){return Re(Oe.errorCodes.rpc.internal,t)},server:function(t){if(!t||"object"!==Bt(t)||Array.isArray(t))throw new Error("Ethereum RPC Server errors must provide single object argument.");var e=t.code;if(!Number.isInteger(e)||e>-32005||e<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return Re(e,t)},invalidInput:function(t){return Re(Oe.errorCodes.rpc.invalidInput,t)},resourceNotFound:function(t){return Re(Oe.errorCodes.rpc.resourceNotFound,t)},resourceUnavailable:function(t){return Re(Oe.errorCodes.rpc.resourceUnavailable,t)},transactionRejected:function(t){return Re(Oe.errorCodes.rpc.transactionRejected,t)},methodNotSupported:function(t){return Re(Oe.errorCodes.rpc.methodNotSupported,t)},limitExceeded:function(t){return Re(Oe.errorCodes.rpc.limitExceeded,t)}},provider:{userRejectedRequest:function(t){return Pe(Oe.errorCodes.provider.userRejectedRequest,t)},unauthorized:function(t){return Pe(Oe.errorCodes.provider.unauthorized,t)},unsupportedMethod:function(t){return Pe(Oe.errorCodes.provider.unsupportedMethod,t)},disconnected:function(t){return Pe(Oe.errorCodes.provider.disconnected,t)},chainDisconnected:function(t){return Pe(Oe.errorCodes.provider.chainDisconnected,t)},custom:function(t){if(!t||"object"!==Bt(t)||Array.isArray(t))throw new Error("Ethereum Provider custom errors must provide single object argument.");var e=t.code,r=t.message,n=t.data;if(!r||"string"!=typeof r)throw new Error('"message" must be a nonempty string');return new _e.EthereumProviderError(e,r,n)}}},function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.getMessageFromCode=t.serializeError=t.EthereumProviderError=t.EthereumRpcError=t.ethErrors=t.errorCodes=void 0;var e=Xt;Object.defineProperty(t,"EthereumRpcError",{enumerable:!0,get:function(){return e.EthereumRpcError}}),Object.defineProperty(t,"EthereumProviderError",{enumerable:!0,get:function(){return e.EthereumProviderError}});var r=ve;Object.defineProperty(t,"serializeError",{enumerable:!0,get:function(){return r.serializeError}}),Object.defineProperty(t,"getMessageFromCode",{enumerable:!0,get:function(){return r.getMessageFromCode}});var n=ye;Object.defineProperty(t,"ethErrors",{enumerable:!0,get:function(){return n.ethErrors}});var i=ge;Object.defineProperty(t,"errorCodes",{enumerable:!0,get:function(){return i.errorCodes}})}(Ut);class Ce extends g{constructor({chainId:t,rpc:e,walletServer:i,appId:s}){super(),me.add(this),this.networkVersion="1",r(t,"'chainId' is required"),this.networkVersion=`${Te(t)}`,this.chainId=`0x${Te(t).toString(16)}`,this.rpc=e||o[this.networkVersion],r(this.rpc,"'rpc' is required"),this.injectedWalletServer=i,this._blocto={sessionKey:n.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",supportNetworkList:{},switchableNetwork:{}},this.appId=s||p}send(e,r){return t(this,void 0,void 0,(function*(){switch(!0){case r instanceof Function:return this.sendAsync(e,r);case"string"==typeof e&&Array.isArray(r):return this.sendAsync({jsonrpc:"2.0",method:e,params:r});default:return this.sendAsync(e)}}))}sendAsync(e,r){return t(this,void 0,void 0,(function*(){const t=new Promise((t=>{if(Array.isArray(e)){const r=e.filter((t=>"eth_sendTransaction"===t.method)).map((t=>{var e;return null===(e=t.params)||void 0===e?void 0:e[0]})),n=Math.floor(1e4*Math.random()),i={method:"blocto_sendBatchTransaction",params:r},o=this.request(i),s=e.map((({method:t,params:e},r)=>"eth_sendTransaction"===t?o:this.request({id:n+r+1,jsonrpc:"2.0",method:t,params:e})));Promise.allSettled(s).then((r=>t(r.map(((t,r)=>({id:String(n+r+1),jsonrpc:"2.0",method:e[r].method,result:"fulfilled"===t.status?t.value:void 0,error:"fulfilled"!==t.status?t.reason:void 0})))))).catch((t=>{throw Ut.ethErrors.rpc.internal(null==t?void 0:t.message)}))}else this.request(Object.assign(Object.assign({},e),{id:Number(e.id)})).then(t)}));if(!r)return t;t.then((t=>r(null,t))).catch((t=>r(t)))}))}sendUserOperation(e){return t(this,void 0,void 0,(function*(){return this.request({method:"eth_sendUserOperation",params:[e]})}))}request(r){var n,i,o,s,a,u,c;return t(this,void 0,void 0,(function*(){if(!(null==r?void 0:r.method))throw Ut.ethErrors.rpc.invalidRequest();const t=window.ethereum;if(t&&t.isBlocto){if("wallet_switchEthereumChain"===r.method){if(!(null===(i=null===(n=null==r?void 0:r.params)||void 0===n?void 0:n[0])||void 0===i?void 0:i.chainId))throw Ut.ethErrors.rpc.invalidParams();return t.request(r).then((()=>{var t,e,n;return this.networkVersion=`${Te(null===(t=null==r?void 0:r.params)||void 0===t?void 0:t[0].chainId)}`,this.chainId=`0x${Te(null===(e=null==r?void 0:r.params)||void 0===e?void 0:e[0].chainId).toString(16)}`,this.rpc=null===(n=null==d?void 0:d[this.networkVersion])||void 0===n?void 0:n.rpc_url,null}))}return t.request(r)}const{blockchainName:h,switchableNetwork:d,sessionKey:l}=yield e(this,me,"m",we).call(this);switch(r.method){case"eth_chainId":return this.chainId;case"net_version":return this.networkVersion;case"wallet_addEthereumChain":return this.loadSwitchableNetwork((null==r?void 0:r.params)||[]);case"eth_call":{const t=yield this.handleReadRequests(r);if(!t||t&&!t.result&&t.error){const e=(null===(o=null==t?void 0:t.error)||void 0===o?void 0:o.message)?t.error.message:"Request failed";throw Ut.ethErrors.rpc.internal(e)}return t.result}case"wallet_switchEthereumChain":return this.handleSwitchChain(null===(a=null===(s=null==r?void 0:r.params)||void 0===s?void 0:s[0])||void 0===a?void 0:a.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return T(l,h)||[]}if(!T(l,h)){const t=null===(u=null==r?void 0:r.params)||void 0===u?void 0:u[0];"eth_requestAccounts"===r.method&&L(t)?yield this.enable(t):yield this.enable()}try{let t=null,e=null;switch(r.method){case"eth_requestAccounts":yield this.fetchAccounts();case"eth_coinbase":e=null===(c=T(l,h))||void 0===c?void 0:c[0];break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":case"eth_sign":e=yield this.handleSign(r);break;case"eth_sendTransaction":e=yield this.handleSendTransaction(r);break;case"blocto_sendBatchTransaction":e=yield this.handleSendBatchTransaction(r);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw Ut.ethErrors.rpc.methodNotSupported("Method Not Supported: "+r.method);case"eth_sendUserOperation":e=yield this.handleSendUserOperation(r);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":e=yield this.handleBundler(r);break;default:t=yield this.handleReadRequests(r)}if(t&&!t.result&&t.error){const e=t.error.message?t.error.message:"Request failed";throw Ut.ethErrors.rpc.internal(e)}return t?t.result:e}catch(t){throw Ut.ethErrors.rpc.internal(null==t?void 0:t.message)}}))}bloctoApi(r,n){var i;return t(this,void 0,void 0,(function*(){const{walletServer:t,blockchainName:o,sessionKey:s}=yield e(this,me,"m",we).call(this),a=(null===(i=R(s))||void 0===i?void 0:i.code)||"";if(!a)throw Ut.ethErrors.provider.unauthorized();return fetch(`${t}/api/${o}${r}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},n)).then((t=>j(t,s,(()=>{var t;null===(t=this.eventListeners)||void 0===t||t.disconnect.forEach((t=>t(Ut.ethErrors.provider.disconnected())))})))).catch((t=>{throw"unsupported_method"===(null==t?void 0:t.error_code)?Ut.ethErrors.rpc.methodNotSupported("Method Not Supported: "+t.message):Ut.ethErrors.rpc.server({code:-32005,message:`Blocto server error: ${t.message}`})}))}))}responseListener(r,n){return t(this,void 0,void 0,(function*(){const{walletServer:t}=yield e(this,me,"m",we).call(this);return new Promise(((e,i)=>b("message",((o,s)=>{const a=o;a.origin===t&&"ETH:FRAME:RESPONSE"===a.data.type&&("APPROVED"===a.data.status&&(s(),w(r),e(a.data[n])),"DECLINED"===a.data.status&&(s(),w(r),"incorrect_session_id"===a.data.errorCode&&this.handleDisconnect(),i(Ut.ethErrors.provider.userRejectedRequest(a.data.errorMessage)))),"ETH:FRAME:CLOSE"===a.data.type&&(s(),w(r),i(Ut.ethErrors.provider.userRejectedRequest("User declined the request")))}))))}))}setIframe(r,n){return t(this,void 0,void 0,(function*(){if("undefined"==typeof window)throw Ut.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:t,blockchainName:i}=yield e(this,me,"m",we).call(this),o=y(`${t}/${this.appId}/${n||i}${r}`);return m(o),o}))}enable(r){return t(this,void 0,void 0,(function*(){const{walletServer:t,blockchainName:n,sessionKey:o}=yield e(this,me,"m",we).call(this),s=window.ethereum;if(s&&s.isBlocto)return s.chainId!==this.chainId&&(yield s.request({method:"wallet_addEthereumChain",params:[{chainId:this.chainId}]}),yield s.request({method:"wallet_switchEthereumChain",params:[{chainId:this.chainId}]}),C(o,n,[s.address])),new Promise(((t,e)=>setTimeout((()=>s.enable().then(t).catch(e)),10)));const a=T(o,n);if(a)return new Promise((t=>{t(a)}));const u=new URLSearchParams;u.set("l6n",window.location.origin),u.set("v",v);const c=r&&L(r)?`/${r}`:"",h=yield this.setIframe(`/authn${c}?${u.toString()}`);return new Promise(((e,r)=>{b("message",((s,a)=>{var u,c;const d=s;d.origin===t&&("ETH:FRAME:RESPONSE"===d.data.type&&(a(),w(h),null===(u=this.eventListeners)||void 0===u||u.connect.forEach((t=>t({chainId:this.chainId}))),P(o,{code:d.data.code,evm:{[n]:[d.data.addr]}},d.data.exp),(null===(c=d.data)||void 0===c?void 0:c.isAccountChanged)&&postMessage({originChain:i.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),b("message",((t,e)=>{var r,n;const o=t;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=o.data)||void 0===r?void 0:r.type)&&(null===(n=o.data)||void 0===n?void 0:n.originChain)!==i.ETHEREUM&&(this.handleDisconnect(),e())})),e([d.data.addr])),"ETH:FRAME:CLOSE"===d.data.type&&(a(),w(h),r(Ut.ethErrors.provider.userRejectedRequest())))}))}))}))}fetchAccounts(){return t(this,void 0,void 0,(function*(){e(this,me,"m",Ee).call(this);const{blockchainName:t,sessionKey:r}=yield e(this,me,"m",we).call(this),{accounts:n}=yield this.bloctoApi("/accounts");return C(r,t,n),n}))}handleReadRequests(r){return t(this,void 0,void 0,(function*(){return e(this,me,"m",Ee).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},r))}).then((t=>t.json())).catch((t=>{throw Ut.ethErrors.rpc.internal(t)}))}))}handleSign({method:r,params:n}){return t(this,void 0,void 0,(function*(){let t="";if(Array.isArray(n))if("eth_sign"===r)t=Lt(n[1])?n[1].slice(2):Mt(n[1]);else if("personal_sign"===r)t=Lt(n[0])?n[0].slice(2):Mt(n[0]);else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(r)){t=n[1];const{domain:e}=JSON.parse(t);if(Lt(e.chainId))throw Ut.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must be a number`);if(Te(e.chainId)!==Te(this.chainId))throw Ut.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must match the active chainId "${Te(this.chainId)}"`)}e(this,me,"m",Ee).call(this);const{signatureId:i}=yield this.bloctoApi("/user-signature",{method:"POST",body:JSON.stringify({method:r,message:t})}),o=yield this.setIframe(`/user-signature/${i}`);return this.responseListener(o,"signature")}))}handleSwitchChain(r){var n,i;return t(this,void 0,void 0,(function*(){if(!r)throw Ut.ethErrors.rpc.invalidParams();const{walletServer:t,blockchainName:o,sessionKey:s,switchableNetwork:a}=yield e(this,me,"m",we).call(this),u=null===(n=T(s,o))||void 0===n?void 0:n[0],c=Te(this.chainId),h=Te(r);if(c===h)return null;if(!a[h])throw Ut.ethErrors.provider.custom({code:4902,message:`Unrecognized chain ID "${h}". Try adding the chain using wallet_addEthereumChain first.`});if(this.networkVersion=`${h}`,this.chainId=`0x${h.toString(16)}`,this.rpc=a[h].rpc_url,!u)return null===(i=this.eventListeners)||void 0===i||i.chainChanged.forEach((t=>t(this.chainId))),e(this,me,"m",we).call(this),null;if(a[h].wallet_web_url!==a[c].wallet_web_url)return this.enable().then((([t])=>{var e;return t!==u&&(null===(e=this.eventListeners)||void 0===e||e.accountsChanged.forEach((e=>e([t])))),this.eventListeners.chainChanged.forEach((t=>t(this.chainId))),null})).catch((t=>{throw this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,e(this,me,"m",we).call(this),t}));const d=yield this.setIframe(`/switch-chain?to=${a[h].name}`,a[c].name);return new Promise(((r,n)=>{b("message",((i,o)=>{var l,f,p,v,g,y,m,b;const E=i;E.origin===t&&("ETH:FRAME:RESPONSE"===E.data.type&&(o(),w(d),(null===(l=E.data)||void 0===l?void 0:l.addr)&&u&&(P(s,{code:null===(f=E.data)||void 0===f?void 0:f.code,evm:{[a[h].name]:[E.data.addr]}},null===(p=E.data)||void 0===p?void 0:p.exp),E.data.addr!==u&&(null===(v=this.eventListeners)||void 0===v||v.accountsChanged.forEach((t=>t([E.data.addr]))))),null===(g=this.eventListeners)||void 0===g||g.chainChanged.forEach((t=>t(this.chainId))),e(this,me,"m",we).call(this),r(null)),"ETH:FRAME:CLOSE"===E.data.type&&(o(),w(d),(null===(y=E.data)||void 0===y?void 0:y.hasApprovedSwitchChain)?(null===(m=this.eventListeners)||void 0===m||m.chainChanged.forEach((t=>t(this.chainId))),N(s),null===(b=this.eventListeners)||void 0===b||b.disconnect.forEach((t=>t(Ut.ethErrors.provider.disconnected()))),e(this,me,"m",we).call(this),r(null)):(this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,n(Ut.ethErrors.provider.userRejectedRequest()))))}))}))}))}handleSendTransaction(r){var n;return t(this,void 0,void 0,(function*(){e(this,me,"m",Ee).call(this);const{isValid:t,invalidMsg:i}=kt(null===(n=r.params)||void 0===n?void 0:n[0]);if(!t)throw Ut.ethErrors.rpc.invalidParams(i);return e(this,me,"m",Se).call(this,r.params)}))}handleSendBatchTransaction(r){return t(this,void 0,void 0,(function*(){e(this,me,"m",Ee).call(this);const t=r.params.map((t=>"params"in t?t.params[0]:t));const n=Object.assign(Object.assign({},r),{params:t}),{isValid:i,invalidMsg:o}=(t=>{if(!Array.isArray(t))return{isValid:!1,invalidMsg:M.INVALID_TRANSACTIONS};for(let e=0;e<t.length;e++){const{isValid:r,invalidMsg:n}=kt(t[e]);if(!r)return{isValid:r,invalidMsg:n}}return{isValid:!0}})(n.params);if(!i)throw Ut.ethErrors.rpc.invalidParams(o);return e(this,me,"m",Se).call(this,n.params)}))}handleSendUserOperation(r){return t(this,void 0,void 0,(function*(){e(this,me,"m",Ee).call(this);const{authorizationId:t}=yield this.bloctoApi("/user-operation",{method:"POST",body:JSON.stringify(r.params)}),n=yield this.setIframe(`/user-operation/${t}`);return this.responseListener(n,"userOpHash")}))}handleBundler(r){return t(this,void 0,void 0,(function*(){return e(this,me,"m",Ee).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},r))})}))}handleDisconnect(){var r;return t(this,void 0,void 0,(function*(){const t=window.ethereum;if(t&&t.isBlocto)return t.disconnect();const{sessionKey:n}=yield e(this,me,"m",we).call(this);N(n),null===(r=this.eventListeners)||void 0===r||r.disconnect.forEach((t=>t(Ut.ethErrors.provider.disconnected())))}))}loadSwitchableNetwork(r){return t(this,void 0,void 0,(function*(){if(null==r?void 0:r.length){const t=r.map((({chainId:t,rpcUrls:r})=>{if(!t)throw Ut.ethErrors.rpc.invalidParams("Empty chainId");const n=`${Te(t)}`;if(this._blocto.switchableNetwork[n])return null;const i=(null==r?void 0:r[0])||o[n];if(!i)throw Ut.ethErrors.rpc.invalidParams("rpcUrls required");return e(this,me,"m",be).call(this,{chainId:n,rpcUrls:[i]})}));return Promise.all(t).then((()=>null))}throw Ut.ethErrors.rpc.invalidParams("Empty networkList")}))}}me=new WeakSet,we=function(){var e;return t(this,void 0,void 0,(function*(){Object.keys(this._blocto.supportNetworkList).length||(yield function(){return t(this,void 0,void 0,(function*(){const{networks:t}=yield fetch("https://api.blocto.app/networks/evm").then((t=>t.json()));return t.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.chain_id]:e})),{})}))}().then((t=>this._blocto.supportNetworkList=t)).catch((t=>{throw Ut.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${t.message}`})})));const{chain_id:r,name:n,network_type:i,blocto_service_environment:o,display_name:u}=null!==(e=this._blocto.supportNetworkList[this.networkVersion])&&void 0!==e?e:{};if(!r)throw Ut.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);return this._blocto=Object.assign(Object.assign({},this._blocto),{sessionKey:a[o],walletServer:this.injectedWalletServer||s[o],blockchainName:n,networkType:i,switchableNetwork:Object.assign(Object.assign({},this._blocto.switchableNetwork),{[r]:{name:n,display_name:u,network_type:i,wallet_web_url:this._blocto.walletServer,rpc_url:this.rpc}})}),this._blocto}))},be=function({chainId:r,rpcUrls:n}){var i;return t(this,void 0,void 0,(function*(){const{supportNetworkList:t}=yield e(this,me,"m",we).call(this),{chain_id:o,name:a,display_name:u,network_type:c,blocto_service_environment:h}=null!==(i=t[r])&&void 0!==i?i:{};if(!o)throw Ut.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${r} might not be supported yet.`);const d=s[h];this._blocto.switchableNetwork[o]={name:a,display_name:u,network_type:c,wallet_web_url:d,rpc_url:n[0]}}))},Ee=function(){const t=window.ethereum;if(t&&t.isBlocto&&Te(t.chainId)!==Te(this.chainId))throw Ut.ethErrors.provider.chainDisconnected()},Se=function(e){return t(this,void 0,void 0,(function*(){const{authorizationId:t}=yield this.bloctoApi("/authz",{method:"POST",body:JSON.stringify(e)}),r=yield this.setIframe(`/authz/${t}`);return this.responseListener(r,"txHash")}))};class Ne extends g{constructor({chainId:t,server:e,appId:n}){super(),this.publicKey=[],this.authKey="",r(t,"'chainId' is required"),r(n,"It is necessary to interact with Blocto wallet via your app id. Please visit https://developers.blocto.app for more details."),this.chainId=t,this.networkName=d[t],this.api=l[t],this.sessionKey=u[t];const i=c[t];this.appId=n||p,this.server=e||i||""}get publicAccount(){var t;return{address:(null===(t=I(this.sessionKey,i.APTOS))||void 0===t?void 0:t[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return t(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){var e;return t(this,void 0,void 0,(function*(){return!!(null===(e=I(this.sessionKey,i.APTOS))||void 0===e?void 0:e.length)}))}signTransaction(e){var r;return t(this,void 0,void 0,(function*(){const t=window.bloctoAptos;if(t)return t.signTransaction(e);if((yield this.isConnected())||(yield this.connect()),!(null===(r=I(this.sessionKey,i.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){var e;return t(this,void 0,void 0,(function*(){const t=window.bloctoAptos;var r,n;t?yield t.disconnect():(r=this.sessionKey,n=i.APTOS,P(r,{accounts:{[n]:void 0}}),null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((t=>t({code:4900,message:"Wallet disconnected"}))))}))}signAndSubmitTransaction(e,r={}){var n,o;return t(this,void 0,void 0,(function*(){const t=window.bloctoAptos;if(t)return t.signAndSubmitTransaction(e,r);if((yield this.isConnected())||(yield this.connect()),!(null===(n=I(this.sessionKey,i.APTOS))||void 0===n?void 0:n.length))throw new Error("Fail to get account");const s=(null===(o=R(this.sessionKey))||void 0===o?void 0:o.code)||"",{authorizationId:a}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":s},body:JSON.stringify(Object.assign(Object.assign({},e),r))}).then((t=>j(t,this.sessionKey)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const u=y(`${this.server}/${this.appId}/aptos/authz/${a}`);return m(u),new Promise(((t,e)=>b("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),w(u),t({hash:i.data.txHash})),"DECLINED"===i.data.status&&(n(),w(u),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),e(new Error(i.data.errorMessage))))}))))}))}signMessage(e){var r,n;return t(this,void 0,void 0,(function*(){const t=window.bloctoAptos,o=(t=>{var e,r;const n=Object.assign({},t),{message:i,nonce:o,address:s,application:a,chainId:u}=t;return"string"!=typeof i&&(n.message=null!==(e=String(i))&&void 0!==e?e:""),"string"!=typeof o&&(n.nonce=null!==(r=String(o))&&void 0!==r?r:""),s&&"boolean"!=typeof s&&(n.address=!!s),a&&"boolean"!=typeof a&&(n.application=!!a),u&&"boolean"!=typeof u&&(n.chainId=!!u),n})(e);if(t)return t.signMessage(o);if((yield this.isConnected())||(yield this.connect()),!(null===(r=I(this.sessionKey,i.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const s=(null===(n=R(this.sessionKey))||void 0===n?void 0:n.code)||"",{signatureId:a}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":s},body:JSON.stringify(o)}).then((t=>j(t,this.sessionKey))),u=y(`${this.server}/${this.appId}/aptos/user-signature/${a}`);return m(u),new Promise(((t,e)=>b("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),w(u),t(i.data)),"DECLINED"===i.data.status&&(n(),w(u),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),e(new Error(i.data.errorMessage))))}))))}))}connect(){return t(this,void 0,void 0,(function*(){const e=window.bloctoAptos;return new Promise(e?(t,r)=>setTimeout((()=>e.connect().then(t).catch(r)),10):(e,r)=>{var n,o;if("undefined"==typeof window)return r("Currently only supported in browser");if(null===(n=I(this.sessionKey,i.APTOS))||void 0===n?void 0:n.length)return e({address:(null===(o=I(this.sessionKey,i.APTOS))||void 0===o?void 0:o[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const s=encodeURIComponent(window.location.origin),a=y(`${this.server}/${this.appId}/aptos/authn?l6n=${s}&v=${v}}`);m(a),b("message",((n,o)=>t(this,void 0,void 0,(function*(){var t,s,u,c;const h=n;if(h.origin===this.server){if("APTOS:FRAME:RESPONSE"===h.data.type){if(o(),w(a),P(this.sessionKey,{code:h.data.code,accounts:{[i.APTOS]:[h.data.addr]}},h.data.exp),(null===(t=h.data)||void 0===t?void 0:t.isAccountChanged)&&postMessage({originChain:i.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),b("message",((t,e)=>{var r,n;const o=t;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=o.data)||void 0===r?void 0:r.type)&&(null===(n=o.data)||void 0===n?void 0:n.originChain)!==i.APTOS&&(this.disconnect(),e())})),!(null===(s=I(this.sessionKey,i.APTOS))||void 0===s?void 0:s.length))return r();try{const{public_keys:t}=yield fetch(`${this.server}/blocto/aptos/accounts/${null===(u=I(this.sessionKey,i.APTOS))||void 0===u?void 0:u[0]}`).then((t=>t.json()));this.publicKey=t||[],e({address:(null===(c=I(this.sessionKey,i.APTOS))||void 0===c?void 0:c[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(t){return r(h)}}"APTOS:FRAME:CLOSE"===h.data.type&&(o(),w(a),r(new Error("User declined the login request")))}}))))})}))}fetchAddress(){var e;return t(this,void 0,void 0,(function*(){const t=(null===(e=R(this.sessionKey))||void 0===e?void 0:e.code)||"",{accounts:r}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":t}}).then((t=>j(t,this.sessionKey)));var n,o;return n=this.sessionKey,o=i.APTOS,P(n,{accounts:{[o]:r}}),(null==r?void 0:r[0])||""}))}}return class{constructor({appId:t,ethereum:e,aptos:r}){e&&(this.ethereum=new Ce(Object.assign(Object.assign({},e),{appId:t}))),r&&(this.aptos=new Ne(Object.assign(Object.assign({},r),{appId:t})))}}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).BloctoSDK=t()}(this,(function(){"use strict";function e(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}function t(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)}function r(e,t){if(!e)throw new Error(t)}var n,i;"function"==typeof SuppressedError&&SuppressedError,function(e){e.prod="BLOCTO_SDK",e.dev="BLOCTO_SDK_DEV",e.staging="BLOCTO_SDK_STAGING"}(n||(n={})),function(e){e.ETHEREUM="ethereum",e.APTOS="aptos"}(i||(i={}));const o={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545",137:"https://rpc-mainnet.maticvigil.com/",80001:"https://rpc-mumbai.matic.today/",43114:"https://api.avax.network/ext/bc/C/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",42161:"https://arb1.arbitrum.io/rpc",421613:"https://endpoints.omniatech.io/v1/arbitrum/goerli/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io"},s={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},a={prod:n.prod,staging:n.staging,dev:n.dev},u={1:n.prod,2:n.dev,3:n.dev,4:n.dev,5:n.staging},c={1:"https://wallet-v2.blocto.app",2:"https://wallet-v2-dev.blocto.app",3:"https://wallet-v2-dev.blocto.app",4:"https://wallet-v2-dev.blocto.app",5:"https://wallet-v2-staging.blocto.app"};var h;!function(e){e.Mainnet="mainnet",e.Testnet="testnet",e.Devnet="devnet",e.Testing="testing",e.Premainnet="premainnet"}(h||(h={}));const d={1:h.Mainnet,2:h.Testnet,3:h.Devnet,4:h.Testing,5:h.Premainnet},l={1:"https://fullnode.mainnet.aptoslabs.com/v1",2:"https://fullnode.testnet.aptoslabs.com/v1",3:"https://fullnode.devnet.aptoslabs.com/v1",4:"",5:"https://premainnet.aptosdev.com/v1"},f=["connect","disconnect","message","chainChanged","accountsChanged"],p="00000000-0000-0000-0000-000000000000",v="0.7.2";class g{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,f.forEach((e=>{this.eventListeners[e]=[]})),this.appId=p}request(t){return e(this,void 0,void 0,(function*(){}))}on(e,t){f.includes(e)&&this.eventListeners[e].push(t)}once(){}removeListener(e,t){const r=this.eventListeners[e].findIndex((e=>e===t));-1!==r&&this.eventListeners[e].splice(r,1)}}function y(e){const t=document.createElement("iframe");return t.setAttribute("src",e),t.setAttribute("style","width:100vw;height:100%;position:fixed;top:0;left:0;z-index:2147483646;border:none;box-sizing:border-box;color-scheme:light;inset:0px;display:block;pointer-events:auto;"),t}function m(e){document.body.appendChild(e)}function w(e){const t=e&&e.parentNode;t&&t.removeChild instanceof Function&&t.removeChild(e)}var b=(e,t,r=window)=>{r.addEventListener(e,(function n(i){t(i,(()=>r.removeEventListener(e,n)))}))};const E="undefined"!=typeof window?window.memoryStorage:new class{constructor(){this.storage={}}getItem(e){return this[e]||null}setItem(e,t){this.storage[e]=t}removeItem(e){delete this.storage[e]}},S=(()=>{if("undefined"==typeof window)return!1;try{window.sessionStorage.setItem("local_storage_supported","1");const e=window.sessionStorage.getItem("local_storage_supported");return window.sessionStorage.removeItem("local_storage_supported"),"1"===e}catch(e){return!1}})()?window.sessionStorage:E,_=(e,t=null)=>{const r=S.getItem(e);try{return r&&JSON.parse(r)||t}catch(e){return r||t}},A=(e,t)=>S.setItem(e,"string"==typeof t?t:JSON.stringify(t)),O=e=>{A(e,""),S.removeItem(e)},R=e=>{const t=_(e,null);return t?(new Date).getTime()>t.expiry||t.v!==v?(O(e),null):null==t?void 0:t.data:null},P=(e,t,r)=>{var n,i,o;const s=_(e),a={data:{code:(null==t?void 0:t.code)||(null===(n=null==s?void 0:s.data)||void 0===n?void 0:n.code),accounts:Object.assign(Object.assign({},null===(i=null==s?void 0:s.data)||void 0===i?void 0:i.accounts),null==t?void 0:t.accounts),evm:Object.assign(Object.assign({},null===(o=null==s?void 0:s.data)||void 0===o?void 0:o.evm),null==t?void 0:t.evm)},expiry:r||(null==s?void 0:s.expiry)||(new Date).getTime()+864e5,v:v};A(e,a)},I=(e,t)=>{var r,n,i;return(null===(r=R(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=R(e))||void 0===n?void 0:n.accounts)||void 0===i?void 0:i[t])||null:(O(e),null)},T=(e,t)=>{var r,n,i;return(null===(r=R(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=R(e))||void 0===n?void 0:n.evm)||void 0===i?void 0:i[t])||null:(O(e),null)},C=(e,t,r)=>{P(e,{evm:{[t]:r}})},N=e=>{const t=_(e);t&&(t.data.evm={},A(e,t))};function j(t,r,n){return e(this,void 0,void 0,(function*(){if(403!==t.status&&401!==t.status||(n&&n(),O(r)),!t.ok){const e=yield t.json(),r=new Error((null==e?void 0:e.message)||"unknown error");throw r.error_code=null==e?void 0:e.error_code,r}return t.json()}))}const L=e=>/\S+@\S+\.\S+/.test(e);var k;!function(e){e.INVALID_TRANSACTION="Invalid transaction",e.INVALID_TRANSACTIONS="Invalid transactions",e.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'}(k||(k={}));var M="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},U=[],B=[],D="undefined"!=typeof Uint8Array?Uint8Array:Array,x=!1;function K(){x=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)U[t]=e[t],B[e.charCodeAt(t)]=t;B["-".charCodeAt(0)]=62,B["_".charCodeAt(0)]=63}function $(e,t,r){for(var n,i,o=[],s=t;s<r;s+=3)n=(e[s]<<16)+(e[s+1]<<8)+e[s+2],o.push(U[(i=n)>>18&63]+U[i>>12&63]+U[i>>6&63]+U[63&i]);return o.join("")}function V(e){var t;x||K();for(var r=e.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;a<u;a+=s)o.push($(e,a,a+s>u?u:a+s));return 1===n?(t=e[r-1],i+=U[t>>2],i+=U[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=U[t>>10],i+=U[t>>4&63],i+=U[t<<2&63],i+="="),o.push(i),o.join("")}function Y(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,h=-7,d=r?i-1:0,l=r?-1:1,f=e[t+d];for(d+=l,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+e[t+d],d+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+e[t+d],d+=l,h-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=c}return(f?-1:1)*s*Math.pow(2,o-n)}function q(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,h=(1<<c)-1,d=h>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,v=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=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+d>=1?l/u:l*Math.pow(2,1-d))*u>=2&&(s++,u/=2),s+d>=h?(a=0,s=h):s+d>=1?(a=(t*u-1)*Math.pow(2,i),s+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;e[r+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+f]=255&s,f+=p,s/=256,c-=8);e[r+f-p]|=128*v}var F={}.toString,z=Array.isArray||function(e){return"[object Array]"==F.call(e)};function J(){return G.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function H(e,t){if(J()<t)throw new RangeError("Invalid typed array length");return G.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=G.prototype:(null===e&&(e=new G(t)),e.length=t),e}function G(e,t,r){if(!(G.TYPED_ARRAY_SUPPORT||this instanceof G))return new G(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return Z(this,e)}return W(this,e,t,r)}function W(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n);G.TYPED_ARRAY_SUPPORT?(e=t).__proto__=G.prototype:e=Q(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!G.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|re(t,r);e=H(e,n);var i=e.write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(te(t)){var r=0|ee(t.length);return 0===(e=H(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?H(e,0):Q(e,t);if("Buffer"===t.type&&z(t.data))return Q(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function X(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 Z(e,t){if(X(t),e=H(e,t<0?0:0|ee(t)),!G.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function Q(e,t){var r=t.length<0?0:0|ee(t.length);e=H(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function ee(e){if(e>=J())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+J().toString(16)+" bytes");return 0|e}function te(e){return!(null==e||!e._isBuffer)}function re(e,t){if(te(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 r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Te(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Ce(e).length;default:if(n)return Te(e).length;t=(""+t).toLowerCase(),n=!0}}function ne(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return me(this,t,r);case"utf8":case"utf-8":return pe(this,t,r);case"ascii":return ge(this,t,r);case"latin1":case"binary":return ye(this,t,r);case"base64":return fe(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return we(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function ie(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function oe(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=G.from(t,n)),te(t))return 0===t.length?-1:se(e,t,r,n,i);if("number"==typeof t)return t&=255,G.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):se(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function se(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var h=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===u)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var d=!0,l=0;l<u;l++)if(c(e,o+l)!==c(t,l)){d=!1;break}if(d)return o}return-1}function ae(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[r+s]=a}return s}function ue(e,t,r,n){return Ne(Te(t,e.length-r),e,r,n)}function ce(e,t,r,n){return Ne(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function he(e,t,r,n){return ce(e,t,r,n)}function de(e,t,r,n){return Ne(Ce(t),e,r,n)}function le(e,t,r,n){return Ne(function(e,t){for(var r,n,i,o=[],s=0;s<e.length&&!((t-=2)<0);++s)n=(r=e.charCodeAt(s))>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function fe(e,t,r){return 0===t&&r===e.length?V(e):V(e.slice(t,r))}function pe(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,u,c=e[i],h=null,d=c>239?4:c>223?3:c>191?2:1;if(i+d<=r)switch(d){case 1:c<128&&(h=c);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&c)<<6|63&o)>127&&(h=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,d=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=d}return function(e){var t=e.length;if(t<=ve)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=ve));return r}(n)}G.TYPED_ARRAY_SUPPORT=void 0===M.TYPED_ARRAY_SUPPORT||M.TYPED_ARRAY_SUPPORT,J(),G.poolSize=8192,G._augment=function(e){return e.__proto__=G.prototype,e},G.from=function(e,t,r){return W(null,e,t,r)},G.TYPED_ARRAY_SUPPORT&&(G.prototype.__proto__=Uint8Array.prototype,G.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&G[Symbol.species]),G.alloc=function(e,t,r){return function(e,t,r,n){return X(t),t<=0?H(e,t):void 0!==r?"string"==typeof n?H(e,t).fill(r,n):H(e,t).fill(r):H(e,t)}(null,e,t,r)},G.allocUnsafe=function(e){return Z(null,e)},G.allocUnsafeSlow=function(e){return Z(null,e)},G.isBuffer=function(e){return null!=e&&(!!e._isBuffer||je(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&je(e.slice(0,0))}(e))},G.compare=function(e,t){if(!te(e)||!te(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},G.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}},G.concat=function(e,t){if(!z(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return G.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=G.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!te(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},G.byteLength=re,G.prototype._isBuffer=!0,G.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)ie(this,t,t+1);return this},G.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)ie(this,t,t+3),ie(this,t+1,t+2);return this},G.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)ie(this,t,t+7),ie(this,t+1,t+6),ie(this,t+2,t+5),ie(this,t+3,t+4);return this},G.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?pe(this,0,e):ne.apply(this,arguments)},G.prototype.equals=function(e){if(!te(e))throw new TypeError("Argument must be a Buffer");return this===e||0===G.compare(this,e)},G.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+">"},G.prototype.compare=function(e,t,r,n,i){if(!te(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(o,s),u=this.slice(n,i),c=e.slice(t,r),h=0;h<a;++h)if(u[h]!==c[h]){o=u[h],s=c[h];break}return o<s?-1:s<o?1:0},G.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},G.prototype.indexOf=function(e,t,r){return oe(this,e,t,r,!0)},G.prototype.lastIndexOf=function(e,t,r){return oe(this,e,t,r,!1)},G.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return ae(this,e,t,r);case"utf8":case"utf-8":return ue(this,e,t,r);case"ascii":return ce(this,e,t,r);case"latin1":case"binary":return he(this,e,t,r);case"base64":return de(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return le(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},G.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ve=4096;function ge(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function ye(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function me(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o<r;++o)i+=Ie(e[o]);return i}function we(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function be(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function Ee(e,t,r,n,i,o){if(!te(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(r+n>e.length)throw new RangeError("Index out of range")}function Se(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i<o;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function _e(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i<o;++i)e[r+i]=t>>>8*(n?i:3-i)&255}function Ae(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Oe(e,t,r,n,i){return i||Ae(e,0,r,4),q(e,t,r,n,23,4),r+4}function Re(e,t,r,n,i){return i||Ae(e,0,r,8),q(e,t,r,n,52,8),r+8}G.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),G.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=G.prototype;else{var i=t-e;r=new G(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},G.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||be(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},G.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||be(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},G.prototype.readUInt8=function(e,t){return t||be(e,1,this.length),this[e]},G.prototype.readUInt16LE=function(e,t){return t||be(e,2,this.length),this[e]|this[e+1]<<8},G.prototype.readUInt16BE=function(e,t){return t||be(e,2,this.length),this[e]<<8|this[e+1]},G.prototype.readUInt32LE=function(e,t){return t||be(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},G.prototype.readUInt32BE=function(e,t){return t||be(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},G.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||be(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},G.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||be(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},G.prototype.readInt8=function(e,t){return t||be(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},G.prototype.readInt16LE=function(e,t){t||be(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},G.prototype.readInt16BE=function(e,t){t||be(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},G.prototype.readInt32LE=function(e,t){return t||be(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},G.prototype.readInt32BE=function(e,t){return t||be(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},G.prototype.readFloatLE=function(e,t){return t||be(e,4,this.length),Y(this,e,!0,23,4)},G.prototype.readFloatBE=function(e,t){return t||be(e,4,this.length),Y(this,e,!1,23,4)},G.prototype.readDoubleLE=function(e,t){return t||be(e,8,this.length),Y(this,e,!0,52,8)},G.prototype.readDoubleBE=function(e,t){return t||be(e,8,this.length),Y(this,e,!1,52,8)},G.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||Ee(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},G.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||Ee(this,e,t,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},G.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,1,255,0),G.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},G.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,2,65535,0),G.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Se(this,e,t,!0),t+2},G.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,2,65535,0),G.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Se(this,e,t,!1),t+2},G.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,4,4294967295,0),G.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):_e(this,e,t,!0),t+4},G.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,4,4294967295,0),G.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):_e(this,e,t,!1),t+4},G.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);Ee(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<r&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},G.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);Ee(this,e,t,r,i-1,-i)}var o=r-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+r},G.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,1,127,-128),G.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},G.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,2,32767,-32768),G.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Se(this,e,t,!0),t+2},G.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,2,32767,-32768),G.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Se(this,e,t,!1),t+2},G.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,4,2147483647,-2147483648),G.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):_e(this,e,t,!0),t+4},G.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||Ee(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),G.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):_e(this,e,t,!1),t+4},G.prototype.writeFloatLE=function(e,t,r){return Oe(this,e,t,!0,r)},G.prototype.writeFloatBE=function(e,t,r){return Oe(this,e,t,!1,r)},G.prototype.writeDoubleLE=function(e,t,r){return Re(this,e,t,!0,r)},G.prototype.writeDoubleBE=function(e,t,r){return Re(this,e,t,!1,r)},G.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i,o=n-r;if(this===e&&r<t&&t<n)for(i=o-1;i>=0;--i)e[i+t]=this[i+r];else if(o<1e3||!G.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+o),t);return o},G.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!G.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var o;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o<r;++o)this[o]=e;else{var s=te(e)?e:Te(new G(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var Pe=/[^+\/0-9A-Za-z-_]/g;function Ie(e){return e<16?"0"+e.toString(16):e.toString(16)}function Te(e,t){var r;t=t||1/0;for(var n=e.length,i=null,o=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Ce(e){return function(e){var t,r,n,i,o,s;x||K();var a=e.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===e[a-2]?2:"="===e[a-1]?1:0,s=new D(3*a/4-o),n=o>0?a-4:a;var u=0;for(t=0,r=0;t<n;t+=4,r+=3)i=B[e.charCodeAt(t)]<<18|B[e.charCodeAt(t+1)]<<12|B[e.charCodeAt(t+2)]<<6|B[e.charCodeAt(t+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=B[e.charCodeAt(t)]<<2|B[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=B[e.charCodeAt(t)]<<10|B[e.charCodeAt(t+1)]<<4|B[e.charCodeAt(t+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Pe,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Ne(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function je(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}const Le=e=>"string"==typeof e&&/^0x[0-9A-Fa-f]*$/.test(e),ke=e=>G.from(e,"utf8").toString("hex"),Me=e=>e&&"object"==typeof e&&"from"in e?e.value&&!Le(e.value)?{isValid:!1,invalidMsg:k.INVALID_TRANSACTION_VALUE}:{isValid:!0}:{isValid:!1,invalidMsg:k.INVALID_TRANSACTION};var Ue={};function Be(e){return Be="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Be(e)}function De(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function xe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(i=n.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(i,"string"))?o:String(o)),n)}var i,o}function Ke(e,t,r){return t&&xe(e.prototype,t),r&&xe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function $e(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ye(e,t)}function Ve(e){return Ve=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ve(e)}function Ye(e,t){return Ye=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ye(e,t)}function qe(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function Fe(e,t,r){return Fe=qe()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&Ye(i,r.prototype),i},Fe.apply(null,arguments)}function ze(e){var t="function"==typeof Map?new Map:void 0;return ze=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return Fe(e,arguments,Ve(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ye(n,e)},ze(e)}function Je(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function He(e){var t=qe();return function(){var r,n=Ve(e);if(t){var i=Ve(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return Je(this,r)}}function Ge(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,s,a=[],u=!0,c=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return We(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return We(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function We(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var Xe={},Ze=it;it.default=it,it.stable=ut,it.stableStringify=ut;var Qe="[...]",et="[Circular]",tt=[],rt=[];function nt(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function it(e,t,r,n){var i;void 0===n&&(n=nt()),st(e,"",0,[],void 0,0,n);try{i=0===rt.length?JSON.stringify(e,t,r):JSON.stringify(e,ht(t),r)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==tt.length;){var o=tt.pop();4===o.length?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function ot(e,t,r,n){var i=Object.getOwnPropertyDescriptor(n,r);void 0!==i.get?i.configurable?(Object.defineProperty(n,r,{value:e}),tt.push([n,r,t,i])):rt.push([t,r,e]):(n[r]=e,tt.push([n,r,t]))}function st(e,t,r,n,i,o,s){var a;if(o+=1,"object"===Be(e)&&null!==e){for(a=0;a<n.length;a++)if(n[a]===e)return void ot(et,e,t,i);if(void 0!==s.depthLimit&&o>s.depthLimit)return void ot(Qe,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void ot(Qe,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)st(e[a],a,a,n,e,o,s);else{var u=Object.keys(e);for(a=0;a<u.length;a++){var c=u[a];st(e[c],c,a,n,e,o,s)}}n.pop()}}function at(e,t){return e<t?-1:e>t?1:0}function ut(e,t,r,n){void 0===n&&(n=nt());var i,o=ct(e,"",0,[],void 0,0,n)||e;try{i=0===rt.length?JSON.stringify(o,t,r):JSON.stringify(o,ht(t),r)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==tt.length;){var s=tt.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return i}function ct(e,t,r,n,i,o,s){var a;if(o+=1,"object"===Be(e)&&null!==e){for(a=0;a<n.length;a++)if(n[a]===e)return void ot(et,e,t,i);try{if("function"==typeof e.toJSON)return}catch(e){return}if(void 0!==s.depthLimit&&o>s.depthLimit)return void ot(Qe,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void ot(Qe,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)ct(e[a],a,a,n,e,o,s);else{var u={},c=Object.keys(e).sort(at);for(a=0;a<c.length;a++){var h=c[a];ct(e[h],h,a,n,e,o,s),u[h]=e[h]}if(void 0===i)return u;tt.push([i,t,e]),i[t]=u}n.pop()}}function ht(e){return e=void 0!==e?e:function(e,t){return t},function(t,r){if(rt.length>0)for(var n=0;n<rt.length;n++){var i=rt[n];if(i[1]===t&&i[0]===r){r=i[2],rt.splice(n,1);break}}return e.call(this,t,r)}}Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.EthereumProviderError=Xe.EthereumRpcError=void 0;var dt=Ze,lt=function(e){$e(r,e);var t=He(r);function r(e,n,i){var o;if(De(this,r),!Number.isInteger(e))throw new Error('"code" must be an integer.');if(!n||"string"!=typeof n)throw new Error('"message" must be a nonempty string.');return(o=t.call(this,n)).code=e,void 0!==i&&(o.data=i),o}return Ke(r,[{key:"serialize",value:function(){var e={code:this.code,message:this.message};return void 0!==this.data&&(e.data=this.data),this.stack&&(e.stack=this.stack),e}},{key:"toString",value:function(){return dt.default(this.serialize(),pt,2)}}]),r}(ze(Error));Xe.EthereumRpcError=lt;var ft=function(e){$e(r,e);var t=He(r);function r(e,n,i){if(De(this,r),!function(e){return Number.isInteger(e)&&e>=1e3&&e<=4999}(e))throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');return t.call(this,e,n,i)}return Ke(r)}(lt);function pt(e,t){if("[Circular]"!==t)return t}Xe.EthereumProviderError=ft;var vt={},gt={};Object.defineProperty(gt,"__esModule",{value:!0}),gt.errorValues=gt.errorCodes=void 0,gt.errorCodes={rpc:{invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},provider:{userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901}},gt.errorValues={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.serializeError=e.isValidCode=e.getMessageFromCode=e.JSON_RPC_SERVER_ERROR_MESSAGE=void 0;var t=gt,r=Xe,n=t.errorCodes.rpc.internal,i="Unspecified error message. This is a bug, please report it.",o={code:n,message:s(n)};function s(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i;if(Number.isInteger(r)){var o=r.toString();if(h(t.errorValues,o))return t.errorValues[o].message;if(u(r))return e.JSON_RPC_SERVER_ERROR_MESSAGE}return n}function a(e){if(!Number.isInteger(e))return!1;var r=e.toString();return!!t.errorValues[r]||!!u(e)}function u(e){return e>=-32099&&e<=-32e3}function c(e){return e&&"object"===Be(e)&&!Array.isArray(e)?Object.assign({},e):e}function h(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.JSON_RPC_SERVER_ERROR_MESSAGE="Unspecified server error.",e.getMessageFromCode=s,e.isValidCode=a,e.serializeError=function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=i.fallbackError,d=void 0===u?o:u,l=i.shouldIncludeStack,f=void 0!==l&&l;if(!d||!Number.isInteger(d.code)||"string"!=typeof d.message)throw new Error("Must provide fallback error with integer number code and string message.");if(e instanceof r.EthereumRpcError)return e.serialize();var p={};if(e&&"object"===Be(e)&&!Array.isArray(e)&&h(e,"code")&&a(e.code)){var v=e;p.code=v.code,v.message&&"string"==typeof v.message?(p.message=v.message,h(v,"data")&&(p.data=v.data)):(p.message=s(p.code),p.data={originalError:c(e)})}else{p.code=d.code;var g=null===(t=e)||void 0===t?void 0:t.message;p.message=g&&"string"==typeof g?g:d.message,p.data={originalError:c(e)}}var y=null===(n=e)||void 0===n?void 0:n.stack;return f&&e&&y&&"string"==typeof y&&(p.stack=y),p}}(vt);var yt={};Object.defineProperty(yt,"__esModule",{value:!0}),yt.ethErrors=void 0;var mt,wt,bt,Et,St,_t=Xe,At=vt,Ot=gt;function Rt(e,t){var r=Ge(It(t),2),n=r[0],i=r[1];return new _t.EthereumRpcError(e,n||At.getMessageFromCode(e),i)}function Pt(e,t){var r=Ge(It(t),2),n=r[0],i=r[1];return new _t.EthereumProviderError(e,n||At.getMessageFromCode(e),i)}function It(e){if(e){if("string"==typeof e)return[e];if("object"===Be(e)&&!Array.isArray(e)){var t=e.message,r=e.data;if(t&&"string"!=typeof t)throw new Error("Must specify string message.");return[t||void 0,r]}}return[]}function Tt(e){return e?"number"==typeof e?e:e.startsWith("0x")?parseInt(e,16):parseInt(e,10):1}yt.ethErrors={rpc:{parse:function(e){return Rt(Ot.errorCodes.rpc.parse,e)},invalidRequest:function(e){return Rt(Ot.errorCodes.rpc.invalidRequest,e)},invalidParams:function(e){return Rt(Ot.errorCodes.rpc.invalidParams,e)},methodNotFound:function(e){return Rt(Ot.errorCodes.rpc.methodNotFound,e)},internal:function(e){return Rt(Ot.errorCodes.rpc.internal,e)},server:function(e){if(!e||"object"!==Be(e)||Array.isArray(e))throw new Error("Ethereum RPC Server errors must provide single object argument.");var t=e.code;if(!Number.isInteger(t)||t>-32005||t<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return Rt(t,e)},invalidInput:function(e){return Rt(Ot.errorCodes.rpc.invalidInput,e)},resourceNotFound:function(e){return Rt(Ot.errorCodes.rpc.resourceNotFound,e)},resourceUnavailable:function(e){return Rt(Ot.errorCodes.rpc.resourceUnavailable,e)},transactionRejected:function(e){return Rt(Ot.errorCodes.rpc.transactionRejected,e)},methodNotSupported:function(e){return Rt(Ot.errorCodes.rpc.methodNotSupported,e)},limitExceeded:function(e){return Rt(Ot.errorCodes.rpc.limitExceeded,e)}},provider:{userRejectedRequest:function(e){return Pt(Ot.errorCodes.provider.userRejectedRequest,e)},unauthorized:function(e){return Pt(Ot.errorCodes.provider.unauthorized,e)},unsupportedMethod:function(e){return Pt(Ot.errorCodes.provider.unsupportedMethod,e)},disconnected:function(e){return Pt(Ot.errorCodes.provider.disconnected,e)},chainDisconnected:function(e){return Pt(Ot.errorCodes.provider.chainDisconnected,e)},custom:function(e){if(!e||"object"!==Be(e)||Array.isArray(e))throw new Error("Ethereum Provider custom errors must provide single object argument.");var t=e.code,r=e.message,n=e.data;if(!r||"string"!=typeof r)throw new Error('"message" must be a nonempty string');return new _t.EthereumProviderError(t,r,n)}}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getMessageFromCode=e.serializeError=e.EthereumProviderError=e.EthereumRpcError=e.ethErrors=e.errorCodes=void 0;var t=Xe;Object.defineProperty(e,"EthereumRpcError",{enumerable:!0,get:function(){return t.EthereumRpcError}}),Object.defineProperty(e,"EthereumProviderError",{enumerable:!0,get:function(){return t.EthereumProviderError}});var r=vt;Object.defineProperty(e,"serializeError",{enumerable:!0,get:function(){return r.serializeError}}),Object.defineProperty(e,"getMessageFromCode",{enumerable:!0,get:function(){return r.getMessageFromCode}});var n=yt;Object.defineProperty(e,"ethErrors",{enumerable:!0,get:function(){return n.ethErrors}});var i=gt;Object.defineProperty(e,"errorCodes",{enumerable:!0,get:function(){return i.errorCodes}})}(Ue);class Ct extends g{constructor({chainId:e,rpc:t,walletServer:i,appId:s}){super(),mt.add(this),this.networkVersion="1",r(e,"'chainId' is required"),this.networkVersion=`${Tt(e)}`,this.chainId=`0x${Tt(e).toString(16)}`,this.rpc=t||o[this.networkVersion],r(this.rpc,"'rpc' is required"),this.injectedWalletServer=i,this._blocto={sessionKey:n.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",supportNetworkList:{},switchableNetwork:{}},this.appId=s||p}send(t,r){return e(this,void 0,void 0,(function*(){switch(!0){case r instanceof Function:return this.sendAsync(t,r);case"string"==typeof t&&Array.isArray(r):return this.sendAsync({jsonrpc:"2.0",method:t,params:r});default:return this.sendAsync(t)}}))}sendAsync(t,r){return e(this,void 0,void 0,(function*(){const e=new Promise((e=>{if(Array.isArray(t)){const r=t.filter((e=>"eth_sendTransaction"===e.method)).map((e=>{var t;return null===(t=e.params)||void 0===t?void 0:t[0]})),n=Math.floor(1e4*Math.random()),i={method:"blocto_sendBatchTransaction",params:r},o=this.request(i),s=t.map((({method:e,params:t},r)=>"eth_sendTransaction"===e?o:this.request({id:n+r+1,jsonrpc:"2.0",method:e,params:t})));Promise.allSettled(s).then((r=>e(r.map(((e,r)=>({id:String(n+r+1),jsonrpc:"2.0",method:t[r].method,result:"fulfilled"===e.status?e.value:void 0,error:"fulfilled"!==e.status?e.reason:void 0})))))).catch((e=>{throw Ue.ethErrors.rpc.internal(null==e?void 0:e.message)}))}else this.request(Object.assign(Object.assign({},t),{id:Number(t.id)})).then(e)}));if(!r)return e;e.then((e=>r(null,e))).catch((e=>r(e)))}))}sendUserOperation(t){return e(this,void 0,void 0,(function*(){return this.request({method:"eth_sendUserOperation",params:[t]})}))}request(r){var n,i,o,s,a,u,c;return e(this,void 0,void 0,(function*(){if(!(null==r?void 0:r.method))throw Ue.ethErrors.rpc.invalidRequest();const e=window.ethereum;if(e&&e.isBlocto){if("wallet_switchEthereumChain"===r.method){if(!(null===(i=null===(n=null==r?void 0:r.params)||void 0===n?void 0:n[0])||void 0===i?void 0:i.chainId))throw Ue.ethErrors.rpc.invalidParams();return e.request(r).then((()=>{var e,t,n;return this.networkVersion=`${Tt(null===(e=null==r?void 0:r.params)||void 0===e?void 0:e[0].chainId)}`,this.chainId=`0x${Tt(null===(t=null==r?void 0:r.params)||void 0===t?void 0:t[0].chainId).toString(16)}`,this.rpc=null===(n=null==d?void 0:d[this.networkVersion])||void 0===n?void 0:n.rpc_url,null}))}return e.request(r)}const{blockchainName:h,switchableNetwork:d,sessionKey:l}=yield t(this,mt,"m",wt).call(this);switch(r.method){case"eth_chainId":return this.chainId;case"net_version":return this.networkVersion;case"wallet_addEthereumChain":return this.loadSwitchableNetwork((null==r?void 0:r.params)||[]);case"eth_call":{const e=yield this.handleReadRequests(r);if(!e||e&&!e.result&&e.error){const t=(null===(o=null==e?void 0:e.error)||void 0===o?void 0:o.message)?e.error.message:"Request failed";throw Ue.ethErrors.rpc.internal(t)}return e.result}case"wallet_switchEthereumChain":return this.handleSwitchChain(null===(a=null===(s=null==r?void 0:r.params)||void 0===s?void 0:s[0])||void 0===a?void 0:a.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return T(l,h)||[]}if(!T(l,h)){const e=null===(u=null==r?void 0:r.params)||void 0===u?void 0:u[0];"eth_requestAccounts"===r.method&&L(e)?yield this.enable(e):yield this.enable()}try{let e=null,t=null;switch(r.method){case"eth_requestAccounts":t=yield this.fetchAccounts();break;case"eth_coinbase":t=null===(c=T(l,h))||void 0===c?void 0:c[0];break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":case"eth_sign":t=yield this.handleSign(r);break;case"eth_sendTransaction":t=yield this.handleSendTransaction(r);break;case"blocto_sendBatchTransaction":t=yield this.handleSendBatchTransaction(r);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw Ue.ethErrors.rpc.methodNotSupported("Method Not Supported: "+r.method);case"eth_sendUserOperation":t=yield this.handleSendUserOperation(r);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":t=yield this.handleBundler(r);break;default:e=yield this.handleReadRequests(r)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw Ue.ethErrors.rpc.internal(t)}return e?e.result:t}catch(e){throw Ue.ethErrors.rpc.internal(null==e?void 0:e.message)}}))}bloctoApi(r,n){var i;return e(this,void 0,void 0,(function*(){const{walletServer:e,blockchainName:o,sessionKey:s}=yield t(this,mt,"m",wt).call(this),a=(null===(i=R(s))||void 0===i?void 0:i.code)||"";if(!a)throw Ue.ethErrors.provider.unauthorized();return fetch(`${e}/api/${o}${r}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},n)).then((e=>j(e,s,(()=>{var e;null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected())))})))).catch((e=>{throw"unsupported_method"===(null==e?void 0:e.error_code)?Ue.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.message):Ue.ethErrors.rpc.server({code:-32005,message:`Blocto server error: ${e.message}`})}))}))}responseListener(r,n){return e(this,void 0,void 0,(function*(){const{walletServer:e}=yield t(this,mt,"m",wt).call(this);return new Promise(((t,i)=>b("message",((o,s)=>{const a=o;a.origin===e&&"ETH:FRAME:RESPONSE"===a.data.type&&("APPROVED"===a.data.status&&(s(),w(r),t(a.data[n])),"DECLINED"===a.data.status&&(s(),w(r),"incorrect_session_id"===a.data.errorCode&&this.handleDisconnect(),i(Ue.ethErrors.provider.userRejectedRequest(a.data.errorMessage)))),"ETH:FRAME:CLOSE"===a.data.type&&(s(),w(r),i(Ue.ethErrors.provider.userRejectedRequest("User declined the request")))}))))}))}setIframe(r,n){return e(this,void 0,void 0,(function*(){if("undefined"==typeof window)throw Ue.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:e,blockchainName:i}=yield t(this,mt,"m",wt).call(this),o=y(`${e}/${this.appId}/${n||i}${r}`);return m(o),o}))}enable(r){return e(this,void 0,void 0,(function*(){const{walletServer:e,blockchainName:n,sessionKey:o}=yield t(this,mt,"m",wt).call(this),s=window.ethereum;if(s&&s.isBlocto)return s.chainId!==this.chainId&&(yield s.request({method:"wallet_addEthereumChain",params:[{chainId:this.chainId}]}),yield s.request({method:"wallet_switchEthereumChain",params:[{chainId:this.chainId}]}),C(o,n,[s.address])),new Promise(((e,t)=>setTimeout((()=>s.enable().then(e).catch(t)),10)));const a=T(o,n);if(a)return new Promise((e=>{e(a)}));const u=new URLSearchParams;u.set("l6n",window.location.origin),u.set("v",v);const c=r&&L(r)?`/${r}`:"",h=yield this.setIframe(`/authn${c}?${u.toString()}`);return new Promise(((t,r)=>{b("message",((s,a)=>{var u,c;const d=s;d.origin===e&&("ETH:FRAME:RESPONSE"===d.data.type&&(a(),w(h),null===(u=this.eventListeners)||void 0===u||u.connect.forEach((e=>e({chainId:this.chainId}))),P(o,{code:d.data.code,evm:{[n]:[d.data.addr]}},d.data.exp),(null===(c=d.data)||void 0===c?void 0:c.isAccountChanged)&&postMessage({originChain:i.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),b("message",((e,t)=>{var r,n;const o=e;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=o.data)||void 0===r?void 0:r.type)&&(null===(n=o.data)||void 0===n?void 0:n.originChain)!==i.ETHEREUM&&(this.handleDisconnect(),t())})),t([d.data.addr])),"ETH:FRAME:CLOSE"===d.data.type&&(a(),w(h),r(Ue.ethErrors.provider.userRejectedRequest())))}))}))}))}fetchAccounts(){return e(this,void 0,void 0,(function*(){t(this,mt,"m",Et).call(this);const{blockchainName:e,sessionKey:r}=yield t(this,mt,"m",wt).call(this),{accounts:n}=yield this.bloctoApi("/accounts");return C(r,e,n),n}))}handleReadRequests(r){return e(this,void 0,void 0,(function*(){return t(this,mt,"m",Et).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},r))}).then((e=>e.json())).catch((e=>{throw Ue.ethErrors.rpc.internal(e)}))}))}handleSign({method:r,params:n}){return e(this,void 0,void 0,(function*(){let e="";if(Array.isArray(n))if("eth_sign"===r)e=Le(n[1])?n[1].slice(2):ke(n[1]);else if("personal_sign"===r)e=Le(n[0])?n[0].slice(2):ke(n[0]);else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(r)){e=n[1];const{domain:t}=JSON.parse(e);if(Le(t.chainId))throw Ue.ethErrors.rpc.invalidParams(`Provided chainId "${t.chainId}" must be a number`);if(Tt(t.chainId)!==Tt(this.chainId))throw Ue.ethErrors.rpc.invalidParams(`Provided chainId "${t.chainId}" must match the active chainId "${Tt(this.chainId)}"`)}t(this,mt,"m",Et).call(this);const{signatureId:i}=yield this.bloctoApi("/user-signature",{method:"POST",body:JSON.stringify({method:r,message:e})}),o=yield this.setIframe(`/user-signature/${i}`);return this.responseListener(o,"signature")}))}handleSwitchChain(r){var n,i;return e(this,void 0,void 0,(function*(){if(!r)throw Ue.ethErrors.rpc.invalidParams();const{walletServer:e,blockchainName:o,sessionKey:s,switchableNetwork:a}=yield t(this,mt,"m",wt).call(this),u=null===(n=T(s,o))||void 0===n?void 0:n[0],c=Tt(this.chainId),h=Tt(r);if(c===h)return null;if(!a[h])throw Ue.ethErrors.provider.custom({code:4902,message:`Unrecognized chain ID "${h}". Try adding the chain using wallet_addEthereumChain first.`});if(this.networkVersion=`${h}`,this.chainId=`0x${h.toString(16)}`,this.rpc=a[h].rpc_url,!u)return null===(i=this.eventListeners)||void 0===i||i.chainChanged.forEach((e=>e(this.chainId))),t(this,mt,"m",wt).call(this),null;if(a[h].wallet_web_url!==a[c].wallet_web_url)return this.enable().then((([e])=>{var t;return e!==u&&(null===(t=this.eventListeners)||void 0===t||t.accountsChanged.forEach((t=>t([e])))),this.eventListeners.chainChanged.forEach((e=>e(this.chainId))),null})).catch((e=>{throw this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,t(this,mt,"m",wt).call(this),e}));const d=yield this.setIframe(`/switch-chain?to=${a[h].name}`,a[c].name);return new Promise(((r,n)=>{b("message",((i,o)=>{var l,f,p,v,g,y,m,b;const E=i;E.origin===e&&("ETH:FRAME:RESPONSE"===E.data.type&&(o(),w(d),(null===(l=E.data)||void 0===l?void 0:l.addr)&&u&&(P(s,{code:null===(f=E.data)||void 0===f?void 0:f.code,evm:{[a[h].name]:[E.data.addr]}},null===(p=E.data)||void 0===p?void 0:p.exp),E.data.addr!==u&&(null===(v=this.eventListeners)||void 0===v||v.accountsChanged.forEach((e=>e([E.data.addr]))))),null===(g=this.eventListeners)||void 0===g||g.chainChanged.forEach((e=>e(this.chainId))),t(this,mt,"m",wt).call(this),r(null)),"ETH:FRAME:CLOSE"===E.data.type&&(o(),w(d),(null===(y=E.data)||void 0===y?void 0:y.hasApprovedSwitchChain)?(null===(m=this.eventListeners)||void 0===m||m.chainChanged.forEach((e=>e(this.chainId))),N(s),null===(b=this.eventListeners)||void 0===b||b.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected()))),t(this,mt,"m",wt).call(this),r(null)):(this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,n(Ue.ethErrors.provider.userRejectedRequest()))))}))}))}))}handleSendTransaction(r){var n;return e(this,void 0,void 0,(function*(){t(this,mt,"m",Et).call(this);const{isValid:e,invalidMsg:i}=Me(null===(n=r.params)||void 0===n?void 0:n[0]);if(!e)throw Ue.ethErrors.rpc.invalidParams(i);return t(this,mt,"m",St).call(this,r.params)}))}handleSendBatchTransaction(r){return e(this,void 0,void 0,(function*(){t(this,mt,"m",Et).call(this);const e=r.params.map((e=>"params"in e?e.params[0]:e));const n=Object.assign(Object.assign({},r),{params:e}),{isValid:i,invalidMsg:o}=(e=>{if(!Array.isArray(e))return{isValid:!1,invalidMsg:k.INVALID_TRANSACTIONS};for(let t=0;t<e.length;t++){const{isValid:r,invalidMsg:n}=Me(e[t]);if(!r)return{isValid:r,invalidMsg:n}}return{isValid:!0}})(n.params);if(!i)throw Ue.ethErrors.rpc.invalidParams(o);return t(this,mt,"m",St).call(this,n.params)}))}handleSendUserOperation(r){return e(this,void 0,void 0,(function*(){t(this,mt,"m",Et).call(this);const{authorizationId:e}=yield this.bloctoApi("/user-operation",{method:"POST",body:JSON.stringify(r.params)}),n=yield this.setIframe(`/user-operation/${e}`);return this.responseListener(n,"userOpHash")}))}handleBundler(r){return e(this,void 0,void 0,(function*(){return t(this,mt,"m",Et).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},r))})}))}handleDisconnect(){var r;return e(this,void 0,void 0,(function*(){const e=window.ethereum;if(e&&e.isBlocto)return e.disconnect();const{sessionKey:n}=yield t(this,mt,"m",wt).call(this);N(n),null===(r=this.eventListeners)||void 0===r||r.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected())))}))}loadSwitchableNetwork(r){return e(this,void 0,void 0,(function*(){if(null==r?void 0:r.length){const e=r.map((({chainId:e,rpcUrls:r})=>{if(!e)throw Ue.ethErrors.rpc.invalidParams("Empty chainId");const n=`${Tt(e)}`;if(this._blocto.switchableNetwork[n])return null;const i=(null==r?void 0:r[0])||o[n];if(!i)throw Ue.ethErrors.rpc.invalidParams("rpcUrls required");return t(this,mt,"m",bt).call(this,{chainId:n,rpcUrls:[i]})}));return Promise.all(e).then((()=>null))}throw Ue.ethErrors.rpc.invalidParams("Empty networkList")}))}}mt=new WeakSet,wt=function(){var t;return e(this,void 0,void 0,(function*(){Object.keys(this._blocto.supportNetworkList).length||(yield function(){return e(this,void 0,void 0,(function*(){const{networks:e}=yield fetch("https://api.blocto.app/networks/evm").then((e=>e.json()));return e.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.chain_id]:t})),{})}))}().then((e=>this._blocto.supportNetworkList=e)).catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})));const{chain_id:r,name:n,network_type:i,blocto_service_environment:o,display_name:u}=null!==(t=this._blocto.supportNetworkList[this.networkVersion])&&void 0!==t?t:{};if(!r)throw Ue.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);return this._blocto=Object.assign(Object.assign({},this._blocto),{sessionKey:a[o],walletServer:this.injectedWalletServer||s[o],blockchainName:n,networkType:i,switchableNetwork:Object.assign(Object.assign({},this._blocto.switchableNetwork),{[r]:{name:n,display_name:u,network_type:i,wallet_web_url:this._blocto.walletServer,rpc_url:this.rpc}})}),this._blocto}))},bt=function({chainId:r,rpcUrls:n}){var i;return e(this,void 0,void 0,(function*(){const{supportNetworkList:e}=yield t(this,mt,"m",wt).call(this),{chain_id:o,name:a,display_name:u,network_type:c,blocto_service_environment:h}=null!==(i=e[r])&&void 0!==i?i:{};if(!o)throw Ue.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${r} might not be supported yet.`);const d=s[h];this._blocto.switchableNetwork[o]={name:a,display_name:u,network_type:c,wallet_web_url:d,rpc_url:n[0]}}))},Et=function(){const e=window.ethereum;if(e&&e.isBlocto&&Tt(e.chainId)!==Tt(this.chainId))throw Ue.ethErrors.provider.chainDisconnected()},St=function(t){return e(this,void 0,void 0,(function*(){const{authorizationId:e}=yield this.bloctoApi("/authz",{method:"POST",body:JSON.stringify(t)}),r=yield this.setIframe(`/authz/${e}`);return this.responseListener(r,"txHash")}))};class Nt extends g{constructor({chainId:e,server:t,appId:n}){super(),this.publicKey=[],this.authKey="",r(e,"'chainId' is required"),r(n,"It is necessary to interact with Blocto wallet via your app id. Please visit https://developers.blocto.app for more details."),this.chainId=e,this.networkName=d[e],this.api=l[e],this.sessionKey=u[e];const i=c[e];this.appId=n||p,this.server=t||i||""}get publicAccount(){var e;return{address:(null===(e=I(this.sessionKey,i.APTOS))||void 0===e?void 0:e[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return e(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){var t;return e(this,void 0,void 0,(function*(){return!!(null===(t=I(this.sessionKey,i.APTOS))||void 0===t?void 0:t.length)}))}signTransaction(t){var r;return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signTransaction(t);if((yield this.isConnected())||(yield this.connect()),!(null===(r=I(this.sessionKey,i.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){var t;return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;var r,n;e?yield e.disconnect():(r=this.sessionKey,n=i.APTOS,P(r,{accounts:{[n]:void 0}}),null===(t=this.eventListeners)||void 0===t||t.disconnect.forEach((e=>e({code:4900,message:"Wallet disconnected"}))))}))}signAndSubmitTransaction(t,r={}){var n,o;return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signAndSubmitTransaction(t,r);if((yield this.isConnected())||(yield this.connect()),!(null===(n=I(this.sessionKey,i.APTOS))||void 0===n?void 0:n.length))throw new Error("Fail to get account");const s=(null===(o=R(this.sessionKey))||void 0===o?void 0:o.code)||"",{authorizationId:a}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":s},body:JSON.stringify(Object.assign(Object.assign({},t),r))}).then((e=>j(e,this.sessionKey)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const u=y(`${this.server}/${this.appId}/aptos/authz/${a}`);return m(u),new Promise(((e,t)=>b("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),w(u),e({hash:i.data.txHash})),"DECLINED"===i.data.status&&(n(),w(u),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}signMessage(t){var r,n;return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos,o=(e=>{var t,r;const n=Object.assign({},e),{message:i,nonce:o,address:s,application:a,chainId:u}=e;return"string"!=typeof i&&(n.message=null!==(t=String(i))&&void 0!==t?t:""),"string"!=typeof o&&(n.nonce=null!==(r=String(o))&&void 0!==r?r:""),s&&"boolean"!=typeof s&&(n.address=!!s),a&&"boolean"!=typeof a&&(n.application=!!a),u&&"boolean"!=typeof u&&(n.chainId=!!u),n})(t);if(e)return e.signMessage(o);if((yield this.isConnected())||(yield this.connect()),!(null===(r=I(this.sessionKey,i.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const s=(null===(n=R(this.sessionKey))||void 0===n?void 0:n.code)||"",{signatureId:a}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":s},body:JSON.stringify(o)}).then((e=>j(e,this.sessionKey))),u=y(`${this.server}/${this.appId}/aptos/user-signature/${a}`);return m(u),new Promise(((e,t)=>b("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),w(u),e(i.data)),"DECLINED"===i.data.status&&(n(),w(u),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}connect(){return e(this,void 0,void 0,(function*(){const t=window.bloctoAptos;return new Promise(t?(e,r)=>setTimeout((()=>t.connect().then(e).catch(r)),10):(t,r)=>{var n,o;if("undefined"==typeof window)return r("Currently only supported in browser");if(null===(n=I(this.sessionKey,i.APTOS))||void 0===n?void 0:n.length)return t({address:(null===(o=I(this.sessionKey,i.APTOS))||void 0===o?void 0:o[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const s=encodeURIComponent(window.location.origin),a=y(`${this.server}/${this.appId}/aptos/authn?l6n=${s}&v=${v}}`);m(a),b("message",((n,o)=>e(this,void 0,void 0,(function*(){var e,s,u,c;const h=n;if(h.origin===this.server){if("APTOS:FRAME:RESPONSE"===h.data.type){if(o(),w(a),P(this.sessionKey,{code:h.data.code,accounts:{[i.APTOS]:[h.data.addr]}},h.data.exp),(null===(e=h.data)||void 0===e?void 0:e.isAccountChanged)&&postMessage({originChain:i.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),b("message",((e,t)=>{var r,n;const o=e;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=o.data)||void 0===r?void 0:r.type)&&(null===(n=o.data)||void 0===n?void 0:n.originChain)!==i.APTOS&&(this.disconnect(),t())})),!(null===(s=I(this.sessionKey,i.APTOS))||void 0===s?void 0:s.length))return r();try{const{public_keys:e}=yield fetch(`${this.server}/blocto/aptos/accounts/${null===(u=I(this.sessionKey,i.APTOS))||void 0===u?void 0:u[0]}`).then((e=>e.json()));this.publicKey=e||[],t({address:(null===(c=I(this.sessionKey,i.APTOS))||void 0===c?void 0:c[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(e){return r(h)}}"APTOS:FRAME:CLOSE"===h.data.type&&(o(),w(a),r(new Error("User declined the login request")))}}))))})}))}fetchAddress(){var t;return e(this,void 0,void 0,(function*(){const e=(null===(t=R(this.sessionKey))||void 0===t?void 0:t.code)||"",{accounts:r}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":e}}).then((e=>j(e,this.sessionKey)));var n,o;return n=this.sessionKey,o=i.APTOS,P(n,{accounts:{[o]:r}}),(null==r?void 0:r[0])||""}))}}return class{constructor({appId:e,ethereum:t,aptos:r}){t&&(this.ethereum=new Ct(Object.assign(Object.assign({},t),{appId:e}))),r&&(this.aptos=new Nt(Object.assign(Object.assign({},r),{appId:e})))}}})); |
{ | ||
"name": "@blocto/sdk", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"repository": "git@github.com:portto/blocto-sdk.git", | ||
@@ -5,0 +5,0 @@ "author": "Chiaki.C", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
394477
8717