@dodoex/wallet-web3 0.0.56 → 0.0.57-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/{alchemy-provider-5870b6fa-c3458ce0.js → alchemy-provider-5870b6fa-6b210484.js} +1 -1
  2. package/dist/{alchemy-websocket-provider-213da986-b76aadd7.js → alchemy-websocket-provider-213da986-3ac05e5b.js} +1 -1
  3. package/dist/{blocto-8dcd5378.js → blocto-8f5fd7d3.js} +1 -1
  4. package/dist/{ccip-2cdc0e6e.js → ccip-d1744cf2.js} +1 -1
  5. package/dist/cjs/{alchemy-provider-5870b6fa-22229235.cjs → alchemy-provider-5870b6fa-7453f6a0.cjs} +1 -1
  6. package/dist/cjs/{alchemy-websocket-provider-213da986-d0bd62ee.cjs → alchemy-websocket-provider-213da986-3b95cee6.cjs} +1 -1
  7. package/dist/cjs/{blocto-9189db02.cjs → blocto-b4a7092b.cjs} +1 -1
  8. package/dist/cjs/{ccip-cf4c8958.cjs → ccip-ce28d6bf.cjs} +1 -1
  9. package/dist/cjs/{draggabilly-4a795874.cjs → draggabilly-753ccd30.cjs} +1 -1
  10. package/dist/cjs/id-30b440b2.cjs +1 -0
  11. package/dist/cjs/{index-8df03db9.cjs → index-09b465f6.cjs} +2 -2
  12. package/dist/cjs/{index-32e6540a.cjs → index-17256a18.cjs} +6 -6
  13. package/dist/cjs/{index-1d309dce.cjs → index-2a98c637.cjs} +1 -1
  14. package/dist/cjs/{index-63281f6f.cjs → index-90a9af5d.cjs} +1 -1
  15. package/dist/cjs/{index-d229b8b4.cjs → index-c32675d7.cjs} +1 -1
  16. package/dist/cjs/{index-b289395f.cjs → index-c53fd9aa.cjs} +9 -9
  17. package/dist/cjs/{index-0d59d3a4.cjs → index-ecc3408d.cjs} +2 -2
  18. package/dist/cjs/{index-458ec813.cjs → index-edb35915.cjs} +1 -1
  19. package/dist/cjs/{index-f92b0bd8.cjs → index-fb968ad2.cjs} +1 -1
  20. package/dist/cjs/{index-2b5e634c.cjs → index-fc09a87b.cjs} +1 -1
  21. package/dist/cjs/index.cjs +1 -1
  22. package/dist/cjs/{index.es-f9414662.cjs → index.es-9ddf4378.cjs} +1 -1
  23. package/dist/cjs/{interface-af41c890.cjs → interface-2a09f64e.cjs} +1 -1
  24. package/dist/cjs/{lib-typedarrays-b768ceaf.cjs → lib-typedarrays-51607293.cjs} +1 -1
  25. package/dist/cjs/{portis-e8a9cfb5.cjs → portis-f57258db.cjs} +1 -1
  26. package/dist/cjs/{provider-bc656af9.cjs → provider-74da7349.cjs} +1 -1
  27. package/dist/cjs/{rainbow-3b59bcb8.cjs → rainbow-727e8ea5.cjs} +1 -1
  28. package/dist/cjs/{sha224-542ed113.cjs → sha224-423d5841.cjs} +1 -1
  29. package/dist/cjs/{sha256-56f21b8c.cjs → sha256-874c9a4f.cjs} +1 -1
  30. package/dist/cjs/{typed-data-a777dbe1.cjs → typed-data-d288b47c.cjs} +1 -1
  31. package/dist/cjs/{uAuth-977cd558.cjs → uAuth-361814ef.cjs} +1 -1
  32. package/dist/cjs/{walletConnect-59deaaa7.cjs → walletConnect-90bdf48f.cjs} +1 -1
  33. package/dist/cjs/{walletLink-8c611440.cjs → walletLink-1f27a868.cjs} +1 -1
  34. package/dist/{draggabilly-36d7b3a5.js → draggabilly-9d05d32a.js} +1 -1
  35. package/dist/id-d456493a.js +1 -0
  36. package/dist/{index-b967e22c.js → index-013d9a80.js} +1 -1
  37. package/dist/{index-7646623f.js → index-179c2bb2.js} +1 -1
  38. package/dist/{index-8c308a55.js → index-20266fbe.js} +1 -1
  39. package/dist/index-2270e11e.js +37 -0
  40. package/dist/{index-b6011204.js → index-4b539ae1.js} +2 -2
  41. package/dist/{index-8af79cad.js → index-54585d0b.js} +1 -1
  42. package/dist/{index-98d378b6.js → index-5865e5b8.js} +4 -4
  43. package/dist/{index-3e23698a.js → index-72b1f8bd.js} +1 -1
  44. package/dist/{index-7e946bf1.js → index-9aad50a9.js} +1 -1
  45. package/dist/{index-0a7c220d.js → index-afee6d12.js} +9 -9
  46. package/dist/{index.es-68fc128f.js → index.es-22ab18a7.js} +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/{interface-746c1865.js → interface-76e42a07.js} +1 -1
  49. package/dist/{lib-typedarrays-5c5921fd.js → lib-typedarrays-60ecdf93.js} +1 -1
  50. package/dist/{portis-00d754f6.js → portis-b9004d27.js} +1 -1
  51. package/dist/{provider-4fe47dba.js → provider-7049aff5.js} +1 -1
  52. package/dist/{rainbow-ba579cad.js → rainbow-1e89ee8a.js} +1 -1
  53. package/dist/sha224-778cae22.js +1 -0
  54. package/dist/{sha256-6b5b8897.js → sha256-a1fc65fb.js} +1 -1
  55. package/dist/{typed-data-a96333aa.js → typed-data-976cda33.js} +1 -1
  56. package/dist/{uAuth-6ea836c7.js → uAuth-1ec9ee54.js} +1 -1
  57. package/dist/{walletConnect-6b2a7a4e.js → walletConnect-4755969f.js} +1 -1
  58. package/dist/{walletLink-8d027247.js → walletLink-88901ef9.js} +1 -1
  59. package/package.json +1 -1
  60. package/dist/cjs/id-5a06c725.cjs +0 -1
  61. package/dist/id-cb48006b.js +0 -1
  62. package/dist/index-36aa5fe1.js +0 -37
  63. package/dist/sha224-ee67389b.js +0 -1
@@ -1 +1 @@
1
- import{L as e,aE as t,aF as r,aG as n,aH as i,aI as s,aJ as o,aK as a,aL as c,aM as d,m as h,aN as u,aO as l,aP as m}from"./index-98d378b6.js";import{JsonRpcProvider as f}from"@ethersproject/providers";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";const p=new e("networks/5.7.1");function v(e){const t=function(t,r){null==r&&(r={});const n=[];if(t.InfuraProvider&&"-"!==r.infura)try{n.push(new t.InfuraProvider(e,r.infura))}catch(e){}if(t.EtherscanProvider&&"-"!==r.etherscan)try{n.push(new t.EtherscanProvider(e,r.etherscan))}catch(e){}if(t.AlchemyProvider&&"-"!==r.alchemy)try{n.push(new t.AlchemyProvider(e,r.alchemy))}catch(e){}if(t.PocketProvider&&"-"!==r.pocket){const i=["goerli","ropsten","rinkeby","sepolia"];try{const s=new t.PocketProvider(e,r.pocket);s.network&&-1===i.indexOf(s.network.name)&&n.push(s)}catch(e){}}if(t.CloudflareProvider&&"-"!==r.cloudflare)try{n.push(new t.CloudflareProvider(e))}catch(e){}if(t.AnkrProvider&&"-"!==r.ankr)try{const i=["ropsten"],s=new t.AnkrProvider(e,r.ankr);s.network&&-1===i.indexOf(s.network.name)&&n.push(s)}catch(e){}if(0===n.length)return null;if(t.FallbackProvider){let i=1;return null!=r.quorum?i=r.quorum:"homestead"===e&&(i=2),new t.FallbackProvider(n,i)}return n[0]};return t.renetwork=function(e){return v(e)},t}function w(e,t){const r=function(r,n){return r.JsonRpcProvider?new r.JsonRpcProvider(e,t):null};return r.renetwork=function(t){return w(e,t)},r}const k={chainId:1,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"homestead",_defaultProvider:v("homestead")},b={chainId:3,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"ropsten",_defaultProvider:v("ropsten")},g={chainId:63,name:"classicMordor",_defaultProvider:w("https://www.ethercluster.com/mordor","classicMordor")},I={unspecified:{chainId:0,name:"unspecified"},homestead:k,mainnet:k,morden:{chainId:2,name:"morden"},ropsten:b,testnet:b,rinkeby:{chainId:4,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"rinkeby",_defaultProvider:v("rinkeby")},kovan:{chainId:42,name:"kovan",_defaultProvider:v("kovan")},goerli:{chainId:5,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"goerli",_defaultProvider:v("goerli")},kintsugi:{chainId:1337702,name:"kintsugi"},sepolia:{chainId:11155111,name:"sepolia",_defaultProvider:v("sepolia")},classic:{chainId:61,name:"classic",_defaultProvider:w("https://www.ethercluster.com/etc","classic")},classicMorden:{chainId:62,name:"classicMorden"},classicMordor:g,classicTestnet:g,classicKotti:{chainId:6,name:"classicKotti",_defaultProvider:w("https://www.ethercluster.com/kotti","classicKotti")},xdai:{chainId:100,name:"xdai"},matic:{chainId:137,name:"matic",_defaultProvider:v("matic")},maticmum:{chainId:80001,name:"maticmum"},optimism:{chainId:10,name:"optimism",_defaultProvider:v("optimism")},"optimism-kovan":{chainId:69,name:"optimism-kovan"},"optimism-goerli":{chainId:420,name:"optimism-goerli"},arbitrum:{chainId:42161,name:"arbitrum"},"arbitrum-rinkeby":{chainId:421611,name:"arbitrum-rinkeby"},"arbitrum-goerli":{chainId:421613,name:"arbitrum-goerli"},bnb:{chainId:56,name:"bnb"},bnbt:{chainId:97,name:"bnbt"}};function y(e){if(null==e)return null;if("number"==typeof e){for(const t in I){const r=I[t];if(r.chainId===e)return{name:r.name,chainId:r.chainId,ensAddress:r.ensAddress||null,_defaultProvider:r._defaultProvider||null}}return{chainId:e,name:"unknown"}}if("string"==typeof e){const t=I[e];return null==t?null:{name:t.name,chainId:t.chainId,ensAddress:t.ensAddress,_defaultProvider:t._defaultProvider||null}}const t=I[e.name];if(!t)return"number"!=typeof e.chainId&&p.throwArgumentError("invalid network chainId","network",e),e;0!==e.chainId&&e.chainId!==t.chainId&&p.throwArgumentError("network chainId mismatch","network",e);let r=e._defaultProvider||null;var n;return null==r&&t._defaultProvider&&(r=(n=t._defaultProvider)&&"function"==typeof n.renetwork?t._defaultProvider.renetwork(e):t._defaultProvider),{name:e.name,chainId:t.chainId,ensAddress:e.ensAddress||t.ensAddress||null,_defaultProvider:r}}class P{constructor(e,t=100){this.sendBatchFn=e,this.maxBatchSize=t,this.pendingBatch=[]}enqueueRequest(e){return a(this,void 0,void 0,(function*(){const t={request:e,resolve:void 0,reject:void 0},r=new Promise(((e,r)=>{t.resolve=e,t.reject=r}));return this.pendingBatch.push(t),this.pendingBatch.length===this.maxBatchSize?this.sendBatchRequest():this.pendingBatchTimer||(this.pendingBatchTimer=setTimeout((()=>this.sendBatchRequest()),10)),r}))}sendBatchRequest(){return a(this,void 0,void 0,(function*(){const e=this.pendingBatch;this.pendingBatch=[],this.pendingBatchTimer&&(clearTimeout(this.pendingBatchTimer),this.pendingBatchTimer=void 0);const t=e.map((e=>e.request));return this.sendBatchFn(t).then((t=>{e.forEach(((e,r)=>{const n=t[r];if(n.error){const t=new Error(n.error.message);t.code=n.error.code,t.data=n.error.data,e.reject(t)}else e.resolve(n.result)}))}),(t=>{e.forEach((e=>{e.reject(t)}))}))}))}}class A extends f{constructor(e){const t=A.getApiKey(e.apiKey),r=A.getAlchemyNetwork(e.network),n=A.getAlchemyConnectionInfo(r,t,"http");void 0!==e.url&&(n.url=e.url),n.throttleLimit=e.maxRetries;super(n,u[r]),this.apiKey=e.apiKey,this.maxRetries=e.maxRetries,this.batchRequests=e.batchRequests;const i=Object.assign(Object.assign({},this.connection),{headers:Object.assign(Object.assign({},this.connection.headers),{"Alchemy-Ethers-Sdk-Method":"batchSend"})});this.batcher=new P((e=>h(i,JSON.stringify(e)))),this.modifyFormatter()}static getApiKey(e){if(null==e)return t;if(e&&"string"!=typeof e)throw new Error(`Invalid apiKey '${e}' provided. apiKey must be a string.`);return e}static getNetwork(e){return"string"==typeof e&&e in r?r[e]:y(e)}static getAlchemyNetwork(e){if(void 0===e)return n;if("number"==typeof e)throw new Error(`Invalid network '${e}' provided. Network must be a string.`);if(!Object.values(i).includes(e))throw new Error(`Invalid network '${e}' provided. Network must be one of: ${Object.values(i).join(", ")}.`);return e}static getAlchemyConnectionInfo(e,t,r){const n="http"===r?l(e,t):m(e,t);return{headers:s?{"Alchemy-Ethers-Sdk-Version":o}:{"Alchemy-Ethers-Sdk-Version":o,"Accept-Encoding":"gzip"},allowGzip:!0,url:n}}detectNetwork(){const e=Object.create(null,{detectNetwork:{get:()=>super.detectNetwork}});return a(this,void 0,void 0,(function*(){let t=this.network;if(null==t&&(t=yield e.detectNetwork.call(this),!t))throw new Error("No network detected");return t}))}_startPending(){c("WARNING: Alchemy Provider does not support pending filters")}isCommunityResource(){return this.apiKey===t}send(e,t){return this._send(e,t,"send")}_send(e,t,r,n=!1){const i={method:e,params:t,id:this._nextId++,jsonrpc:"2.0"};if(Object.assign({},this.connection).headers["Alchemy-Ethers-Sdk-Method"]=r,this.batchRequests||n)return this.batcher.enqueueRequest(i);this.emit("debug",{action:"request",request:d(i),provider:this});const s=["eth_chainId","eth_blockNumber"].indexOf(e)>=0;if(s&&this._cache[e])return this._cache[e];const o=h(this.connection,JSON.stringify(i),_).then((e=>(this.emit("debug",{action:"response",request:i,response:e,provider:this}),e)),(e=>{throw this.emit("debug",{action:"response",error:e,request:i,provider:this}),e}));return s&&(this._cache[e]=o,setTimeout((()=>{this._cache[e]=null}),0)),o}modifyFormatter(){this.formatter.formats.receiptLog.removed=e=>{if("boolean"==typeof e)return e}}}function _(e){if(e.error){const t=new Error(e.error.message);throw t.code=e.error.code,t.data=e.error.data,t}return e.result}var E=Object.freeze({__proto__:null,AlchemyProvider:A});export{A,E as a,y as g};
1
+ import{L as e,aE as t,aF as r,aG as n,aH as i,aI as s,aJ as o,aK as a,aL as c,aM as d,m as h,aN as u,aO as l,aP as m}from"./index-5865e5b8.js";import{JsonRpcProvider as f}from"@ethersproject/providers";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";const p=new e("networks/5.7.1");function v(e){const t=function(t,r){null==r&&(r={});const n=[];if(t.InfuraProvider&&"-"!==r.infura)try{n.push(new t.InfuraProvider(e,r.infura))}catch(e){}if(t.EtherscanProvider&&"-"!==r.etherscan)try{n.push(new t.EtherscanProvider(e,r.etherscan))}catch(e){}if(t.AlchemyProvider&&"-"!==r.alchemy)try{n.push(new t.AlchemyProvider(e,r.alchemy))}catch(e){}if(t.PocketProvider&&"-"!==r.pocket){const i=["goerli","ropsten","rinkeby","sepolia"];try{const s=new t.PocketProvider(e,r.pocket);s.network&&-1===i.indexOf(s.network.name)&&n.push(s)}catch(e){}}if(t.CloudflareProvider&&"-"!==r.cloudflare)try{n.push(new t.CloudflareProvider(e))}catch(e){}if(t.AnkrProvider&&"-"!==r.ankr)try{const i=["ropsten"],s=new t.AnkrProvider(e,r.ankr);s.network&&-1===i.indexOf(s.network.name)&&n.push(s)}catch(e){}if(0===n.length)return null;if(t.FallbackProvider){let i=1;return null!=r.quorum?i=r.quorum:"homestead"===e&&(i=2),new t.FallbackProvider(n,i)}return n[0]};return t.renetwork=function(e){return v(e)},t}function w(e,t){const r=function(r,n){return r.JsonRpcProvider?new r.JsonRpcProvider(e,t):null};return r.renetwork=function(t){return w(e,t)},r}const k={chainId:1,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"homestead",_defaultProvider:v("homestead")},b={chainId:3,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"ropsten",_defaultProvider:v("ropsten")},g={chainId:63,name:"classicMordor",_defaultProvider:w("https://www.ethercluster.com/mordor","classicMordor")},I={unspecified:{chainId:0,name:"unspecified"},homestead:k,mainnet:k,morden:{chainId:2,name:"morden"},ropsten:b,testnet:b,rinkeby:{chainId:4,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"rinkeby",_defaultProvider:v("rinkeby")},kovan:{chainId:42,name:"kovan",_defaultProvider:v("kovan")},goerli:{chainId:5,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"goerli",_defaultProvider:v("goerli")},kintsugi:{chainId:1337702,name:"kintsugi"},sepolia:{chainId:11155111,name:"sepolia",_defaultProvider:v("sepolia")},classic:{chainId:61,name:"classic",_defaultProvider:w("https://www.ethercluster.com/etc","classic")},classicMorden:{chainId:62,name:"classicMorden"},classicMordor:g,classicTestnet:g,classicKotti:{chainId:6,name:"classicKotti",_defaultProvider:w("https://www.ethercluster.com/kotti","classicKotti")},xdai:{chainId:100,name:"xdai"},matic:{chainId:137,name:"matic",_defaultProvider:v("matic")},maticmum:{chainId:80001,name:"maticmum"},optimism:{chainId:10,name:"optimism",_defaultProvider:v("optimism")},"optimism-kovan":{chainId:69,name:"optimism-kovan"},"optimism-goerli":{chainId:420,name:"optimism-goerli"},arbitrum:{chainId:42161,name:"arbitrum"},"arbitrum-rinkeby":{chainId:421611,name:"arbitrum-rinkeby"},"arbitrum-goerli":{chainId:421613,name:"arbitrum-goerli"},bnb:{chainId:56,name:"bnb"},bnbt:{chainId:97,name:"bnbt"}};function y(e){if(null==e)return null;if("number"==typeof e){for(const t in I){const r=I[t];if(r.chainId===e)return{name:r.name,chainId:r.chainId,ensAddress:r.ensAddress||null,_defaultProvider:r._defaultProvider||null}}return{chainId:e,name:"unknown"}}if("string"==typeof e){const t=I[e];return null==t?null:{name:t.name,chainId:t.chainId,ensAddress:t.ensAddress,_defaultProvider:t._defaultProvider||null}}const t=I[e.name];if(!t)return"number"!=typeof e.chainId&&p.throwArgumentError("invalid network chainId","network",e),e;0!==e.chainId&&e.chainId!==t.chainId&&p.throwArgumentError("network chainId mismatch","network",e);let r=e._defaultProvider||null;var n;return null==r&&t._defaultProvider&&(r=(n=t._defaultProvider)&&"function"==typeof n.renetwork?t._defaultProvider.renetwork(e):t._defaultProvider),{name:e.name,chainId:t.chainId,ensAddress:e.ensAddress||t.ensAddress||null,_defaultProvider:r}}class P{constructor(e,t=100){this.sendBatchFn=e,this.maxBatchSize=t,this.pendingBatch=[]}enqueueRequest(e){return a(this,void 0,void 0,(function*(){const t={request:e,resolve:void 0,reject:void 0},r=new Promise(((e,r)=>{t.resolve=e,t.reject=r}));return this.pendingBatch.push(t),this.pendingBatch.length===this.maxBatchSize?this.sendBatchRequest():this.pendingBatchTimer||(this.pendingBatchTimer=setTimeout((()=>this.sendBatchRequest()),10)),r}))}sendBatchRequest(){return a(this,void 0,void 0,(function*(){const e=this.pendingBatch;this.pendingBatch=[],this.pendingBatchTimer&&(clearTimeout(this.pendingBatchTimer),this.pendingBatchTimer=void 0);const t=e.map((e=>e.request));return this.sendBatchFn(t).then((t=>{e.forEach(((e,r)=>{const n=t[r];if(n.error){const t=new Error(n.error.message);t.code=n.error.code,t.data=n.error.data,e.reject(t)}else e.resolve(n.result)}))}),(t=>{e.forEach((e=>{e.reject(t)}))}))}))}}class A extends f{constructor(e){const t=A.getApiKey(e.apiKey),r=A.getAlchemyNetwork(e.network),n=A.getAlchemyConnectionInfo(r,t,"http");void 0!==e.url&&(n.url=e.url),n.throttleLimit=e.maxRetries;super(n,u[r]),this.apiKey=e.apiKey,this.maxRetries=e.maxRetries,this.batchRequests=e.batchRequests;const i=Object.assign(Object.assign({},this.connection),{headers:Object.assign(Object.assign({},this.connection.headers),{"Alchemy-Ethers-Sdk-Method":"batchSend"})});this.batcher=new P((e=>h(i,JSON.stringify(e)))),this.modifyFormatter()}static getApiKey(e){if(null==e)return t;if(e&&"string"!=typeof e)throw new Error(`Invalid apiKey '${e}' provided. apiKey must be a string.`);return e}static getNetwork(e){return"string"==typeof e&&e in r?r[e]:y(e)}static getAlchemyNetwork(e){if(void 0===e)return n;if("number"==typeof e)throw new Error(`Invalid network '${e}' provided. Network must be a string.`);if(!Object.values(i).includes(e))throw new Error(`Invalid network '${e}' provided. Network must be one of: ${Object.values(i).join(", ")}.`);return e}static getAlchemyConnectionInfo(e,t,r){const n="http"===r?l(e,t):m(e,t);return{headers:s?{"Alchemy-Ethers-Sdk-Version":o}:{"Alchemy-Ethers-Sdk-Version":o,"Accept-Encoding":"gzip"},allowGzip:!0,url:n}}detectNetwork(){const e=Object.create(null,{detectNetwork:{get:()=>super.detectNetwork}});return a(this,void 0,void 0,(function*(){let t=this.network;if(null==t&&(t=yield e.detectNetwork.call(this),!t))throw new Error("No network detected");return t}))}_startPending(){c("WARNING: Alchemy Provider does not support pending filters")}isCommunityResource(){return this.apiKey===t}send(e,t){return this._send(e,t,"send")}_send(e,t,r,n=!1){const i={method:e,params:t,id:this._nextId++,jsonrpc:"2.0"};if(Object.assign({},this.connection).headers["Alchemy-Ethers-Sdk-Method"]=r,this.batchRequests||n)return this.batcher.enqueueRequest(i);this.emit("debug",{action:"request",request:d(i),provider:this});const s=["eth_chainId","eth_blockNumber"].indexOf(e)>=0;if(s&&this._cache[e])return this._cache[e];const o=h(this.connection,JSON.stringify(i),_).then((e=>(this.emit("debug",{action:"response",request:i,response:e,provider:this}),e)),(e=>{throw this.emit("debug",{action:"response",error:e,request:i,provider:this}),e}));return s&&(this._cache[e]=o,setTimeout((()=>{this._cache[e]=null}),0)),o}modifyFormatter(){this.formatter.formats.receiptLog.removed=e=>{if("boolean"==typeof e)return e}}}function _(e){if(e.error){const t=new Error(e.error.message);throw t.code=e.error.code,t.data=e.error.data,t}return e.result}var E=Object.freeze({__proto__:null,AlchemyProvider:A});export{A,E as a,y as g};
@@ -1 +1 @@
1
- import{aK as e,aQ as t,aF as s,aR as n,aS as i,aT as o,aU as r,aE as c,aV as l,aW as a,aX as h,aY as u,B as d,aZ as f,a_ as p,aJ as m,aN as b}from"./index-98d378b6.js";import{A as v,g as y}from"./alchemy-provider-5870b6fa-c3458ce0.js";import{WebSocketProvider as g}from"@ethersproject/providers";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";import"zustand";import"@ethersproject/bytes";import"@ethersproject/properties";import"@ethersproject/address";import"@ethersproject/abstract-signer";import"buffer";import"events";import"@ethersproject/constants";import"@ethersproject/transactions";var k={};Object.defineProperty(k,"__esModule",{value:!0});var E=function(){function e(t,s,n){if(void 0===n&&(n={}),this.url=t,this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this.ondown=null,this.onreopen=null,this.CONNECTING=e.CONNECTING,this.OPEN=e.OPEN,this.CLOSING=e.CLOSING,this.CLOSED=e.CLOSED,this.hasBeenOpened=!1,this.isClosed=!1,this.messageBuffer=[],this.nextRetryTime=0,this.reconnectCount=0,this.lastKnownExtensions="",this.lastKnownProtocol="",this.listeners={},null==s||"string"==typeof s||Array.isArray(s)?this.protocols=s:n=s,this.options=I(n),!this.options.wsConstructor){if("undefined"==typeof WebSocket)throw new Error("WebSocket not present in global scope and no wsConstructor option was provided.");this.options.wsConstructor=WebSocket}this.openNewWebSocket()}return Object.defineProperty(e.prototype,"binaryType",{get:function(){return this.binaryTypeInternal||"blob"},set:function(e){this.binaryTypeInternal=e,this.ws&&(this.ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){var e=this.ws?this.ws.bufferedAmount:0,t=!1;return this.messageBuffer.forEach((function(s){var n=function(e){return"string"==typeof e?2*e.length:e instanceof ArrayBuffer?e.byteLength:e instanceof Blob?e.size:void 0}(s);null!=n?e+=n:t=!0})),t&&this.debugLog("Some buffered data had unknown length. bufferedAmount() return value may be below the correct amount."),e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this.ws?this.ws.extensions:this.lastKnownExtensions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this.ws?this.ws.protocol:this.lastKnownProtocol},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this.isClosed?e.CLOSED:e.OPEN},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){this.disposeSocket(e,t),this.shutdown(),this.debugLog("WebSocket permanently closed by client.")},e.prototype.send=function(e){if(this.isClosed)throw new Error("WebSocket is already in CLOSING or CLOSED state.");this.ws&&this.ws.readyState===this.OPEN?this.ws.send(e):this.messageBuffer.push(e)},e.prototype.reconnect=function(){if(this.isClosed)throw new Error("Cannot call reconnect() on socket which is permanently closed.");this.disposeSocket(1e3,"Client requested reconnect."),this.handleClose(void 0)},e.prototype.addEventListener=function(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)},e.prototype.dispatchEvent=function(e){return this.dispatchEventOfType(e.type,e)},e.prototype.removeEventListener=function(e,t){this.listeners[e]&&(this.listeners[e]=this.listeners[e].filter((function(e){return e!==t})))},e.prototype.openNewWebSocket=function(){var e=this;if(!this.isClosed){var t=this.options,s=t.connectTimeout,n=t.wsConstructor;this.debugLog("Opening new WebSocket to "+this.url+".");var i=new n(this.url,this.protocols);i.onclose=function(t){return e.handleClose(t)},i.onerror=function(t){return e.handleError(t)},i.onmessage=function(t){return e.handleMessage(t)},i.onopen=function(t){return e.handleOpen(t)},this.connectTimeoutId=setTimeout((function(){e.clearConnectTimeout(),e.disposeSocket(),e.handleClose(void 0)}),s),this.ws=i}},e.prototype.handleOpen=function(e){var t=this;if(this.ws&&!this.isClosed){var s=this.options.allClearResetTime;this.debugLog("WebSocket opened."),null!=this.binaryTypeInternal?this.ws.binaryType=this.binaryTypeInternal:this.binaryTypeInternal=this.ws.binaryType,this.clearConnectTimeout(),this.hasBeenOpened?this.dispatchEventOfType("reopen",e):(this.dispatchEventOfType("open",e),this.hasBeenOpened=!0),this.messageBuffer.forEach((function(e){return t.send(e)})),this.messageBuffer=[],this.allClearTimeoutId=setTimeout((function(){t.clearAllClearTimeout(),t.nextRetryTime=0,t.reconnectCount=0;var e=s/1e3|0;t.debugLog("WebSocket remained open for "+e+" seconds. Resetting retry time and count.")}),s)}},e.prototype.handleMessage=function(e){this.isClosed||this.dispatchEventOfType("message",e)},e.prototype.handleClose=function(e){var t=this;if(!this.isClosed){var s=this.options,n=s.maxReconnectAttempts,i=s.shouldReconnect;if(this.clearConnectTimeout(),this.clearAllClearTimeout(),this.ws&&(this.lastKnownExtensions=this.ws.extensions,this.lastKnownProtocol=this.ws.protocol,this.disposeSocket()),this.dispatchEventOfType("down",e),this.reconnectCount>=n)this.stopReconnecting(e,this.getTooManyFailedReconnectsMessage());else{var o=!e||i(e);"boolean"==typeof o?this.handleWillReconnect(o,e,"Provided shouldReconnect() returned false. Closing permanently."):o.then((function(s){t.isClosed||t.handleWillReconnect(s,e,"Provided shouldReconnect() resolved to false. Closing permanently.")}))}}},e.prototype.handleError=function(e){this.dispatchEventOfType("error",e),this.debugLog("WebSocket encountered an error.")},e.prototype.handleWillReconnect=function(e,t,s){e?this.reestablishConnection():this.stopReconnecting(t,s)},e.prototype.reestablishConnection=function(){var e=this,t=this.options,s=t.minReconnectDelay,n=t.maxReconnectDelay,i=t.reconnectBackoffFactor;this.reconnectCount++;var o=this.nextRetryTime;this.nextRetryTime=Math.max(s,Math.min(this.nextRetryTime*i,n)),setTimeout((function(){return e.openNewWebSocket()}),o);var r=o/1e3|0;this.debugLog("WebSocket was closed. Re-opening in "+r+" seconds.")},e.prototype.stopReconnecting=function(e,t){this.debugLog(t),this.shutdown(),e&&this.dispatchEventOfType("close",e)},e.prototype.shutdown=function(){this.isClosed=!0,this.clearAllTimeouts(),this.messageBuffer=[],this.disposeSocket()},e.prototype.disposeSocket=function(e,t){this.ws&&(this.ws.onerror=N,this.ws.onclose=N,this.ws.onmessage=N,this.ws.onopen=N,this.ws.close(e,t),this.ws=void 0)},e.prototype.clearAllTimeouts=function(){this.clearConnectTimeout(),this.clearAllClearTimeout()},e.prototype.clearConnectTimeout=function(){null!=this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=void 0)},e.prototype.clearAllClearTimeout=function(){null!=this.allClearTimeoutId&&(clearTimeout(this.allClearTimeoutId),this.allClearTimeoutId=void 0)},e.prototype.dispatchEventOfType=function(e,t){var s=this;switch(e){case"close":this.onclose&&this.onclose(t);break;case"error":this.onerror&&this.onerror(t);break;case"message":this.onmessage&&this.onmessage(t);break;case"open":this.onopen&&this.onopen(t);break;case"down":this.ondown&&this.ondown(t);break;case"reopen":this.onreopen&&this.onreopen(t)}return e in this.listeners&&this.listeners[e].slice().forEach((function(e){return s.callListener(e,t)})),!t||!t.defaultPrevented},e.prototype.callListener=function(e,t){"function"==typeof e?e.call(this,t):e.handleEvent.call(this,t)},e.prototype.debugLog=function(e){this.options.debug&&console.log(e)},e.prototype.getTooManyFailedReconnectsMessage=function(){var e,t=this.options.maxReconnectAttempts;return"Failed to reconnect after "+t+" "+(e="attempt",(1===t?e:e+"s")+". Closing permanently.")},e.DEFAULT_OPTIONS={allClearResetTime:5e3,connectTimeout:5e3,debug:!1,minReconnectDelay:1e3,maxReconnectDelay:3e4,maxReconnectAttempts:Number.POSITIVE_INFINITY,reconnectBackoffFactor:1.5,shouldReconnect:function(){return!0},wsConstructor:void 0},e.CONNECTING=0,e.OPEN=1,e.CLOSING=2,e.CLOSED=3,e}(),w=k.default=E;function I(e){var t={};return Object.keys(E.DEFAULT_OPTIONS).forEach((function(s){var n=e[s];t[s]=void 0===n?E.DEFAULT_OPTIONS[s]:n})),t}function N(){}class B{constructor(e){this.provider=e,this.maxBackfillBlocks=120}getNewHeadsBackfill(t,s,n){return e(this,void 0,void 0,(function*(){O(t);const e=yield this.getBlockNumber();if(O(t),0===s.length)return this.getHeadEventsInRange(Math.max(n,e-this.maxBackfillBlocks)+1,e+1);const i=f(s[s.length-1].number),o=e-this.maxBackfillBlocks+1;if(i<=o)return this.getHeadEventsInRange(o,e+1);const r=yield this.getReorgHeads(t,s);O(t);const c=yield this.getHeadEventsInRange(i+1,e+1);return O(t),[...r,...c]}))}getLogsBackfill(t,s,n,i){return e(this,void 0,void 0,(function*(){O(t);const e=yield this.getBlockNumber();if(O(t),0===n.length)return this.getLogsInRange(s,Math.max(i,e-this.maxBackfillBlocks)+1,e+1);const o=f(n[n.length-1].blockNumber),r=e-this.maxBackfillBlocks+1;if(o<r)return this.getLogsInRange(s,r,e+1);const c=yield this.getCommonAncestor(t,n);O(t);const l=n.filter((e=>f(e.blockNumber)>c.blockNumber)).map((e=>Object.assign(Object.assign({},e),{removed:!0}))),a=c.blockNumber===Number.NEGATIVE_INFINITY?f(n[0].blockNumber):c.blockNumber;let h=yield this.getLogsInRange(s,a,e+1);return h=h.filter((e=>e&&(f(e.blockNumber)>c.blockNumber||f(e.logIndex)>c.logIndex))),O(t),[...l,...h]}))}setMaxBackfillBlock(e){this.maxBackfillBlocks=e}getBlockNumber(){return e(this,void 0,void 0,(function*(){const e=yield this.provider.send("eth_blockNumber");return f(e)}))}getHeadEventsInRange(t,s){return e(this,void 0,void 0,(function*(){if(t>=s)return[];const e=[];for(let n=t;n<s;n++)e.push({method:"eth_getBlockByNumber",params:[p(n),!1]});return(yield this.provider.sendBatch(e)).map(T)}))}getReorgHeads(t,s){return e(this,void 0,void 0,(function*(){const e=[];for(let n=s.length-1;n>=0;n--){const i=s[n],o=yield this.getBlockByNumber(f(i.number));if(O(t),i.hash===o.hash)break;e.push(T(o))}return e.reverse()}))}getBlockByNumber(t){return e(this,void 0,void 0,(function*(){return this.provider.send("eth_getBlockByNumber",[p(t),!1])}))}getCommonAncestor(t,s){return e(this,void 0,void 0,(function*(){let e=yield this.getBlockByNumber(f(s[s.length-1].blockNumber));O(t);for(let t=s.length-1;t>=0;t--){const n=s[t];if(n.blockNumber!==e.number&&(e=yield this.getBlockByNumber(f(n.blockNumber))),n.blockHash===e.hash)return{blockNumber:f(n.blockNumber),logIndex:f(n.logIndex)}}return{blockNumber:Number.NEGATIVE_INFINITY,logIndex:Number.NEGATIVE_INFINITY}}))}getLogsInRange(t,s,n){return e(this,void 0,void 0,(function*(){if(s>=n)return[];const e=Object.assign(Object.assign({},t),{fromBlock:p(s),toBlock:p(n-1)});return this.provider.send("eth_getLogs",[e])}))}}function T(e){const t=Object.assign({},e);return delete t.totalDifficulty,delete t.transactions,delete t.uncles,t}function C(e,t){const s=new Set,n=[];return e.forEach((e=>{const i=t(e);s.has(i)||(s.add(i),n.push(e))})),n}const _=new Error("Cancelled");function O(e){if(e())throw _}const A=10;class S extends g{constructor(s,n){var i;const o=v.getApiKey(s.apiKey),r=v.getAlchemyNetwork(s.network),c=v.getAlchemyConnectionInfo(r,o,"wss"),l=`alchemy-sdk-${m}`;super(new w(null!==(i=s.url)&&void 0!==i?i:c.url,l,{wsConstructor:null!=n?n:"undefined"!=typeof process&&null!=process&&null!=process.versions&&null!=process.versions.node?require("websocket").w3cwebsocket:WebSocket}),b[r]),this._events=[],this.virtualSubscriptionsById=new Map,this.virtualIdsByPhysicalId=new Map,this.handleMessage=e=>{const t=JSON.parse(e.data);if(!function(e){return!function(e){return Array.isArray(e)||"2.0"===e.jsonrpc&&void 0!==e.id}(e)}(t))return;const s=t.params.subscription,n=this.virtualIdsByPhysicalId.get(s);if(!n)return;const i=this.virtualSubscriptionsById.get(n);if("eth_subscribe"===i.method)switch(i.params[0]){case"newHeads":{const e=i,o=t,{isBackfilling:r,backfillBuffer:c}=e,{result:l}=o.params;r?function(e,t){W(e,t,H)}(c,l):s!==n?this.emitAndRememberEvent(n,l,H):this.rememberEvent(n,l,H);break}case"logs":{const e=i,o=t,{isBackfilling:r,backfillBuffer:c}=e,{result:l}=o.params;r?function(e,t){W(e,t,M)}(c,l):n!==s?this.emitAndRememberEvent(n,l,M):this.rememberEvent(n,l,M);break}default:if(s!==n){const{result:e}=t.params;this.emitEvent(n,e)}}},this.handleReopen=()=>{this.virtualIdsByPhysicalId.clear();const{cancel:t,isCancelled:s}=function(){let e=!1;return{cancel:()=>e=!0,isCancelled:()=>e}}();this.cancelBackfill=t;for(const t of this.virtualSubscriptionsById.values())(()=>{e(this,void 0,void 0,(function*(){try{yield this.resubscribeAndBackfill(s,t)}catch(e){s()||console.error(`Error while backfilling "${t.params[0]}" subscription. Some events may be missing.`,e)}}))})();this.startHeartbeat()},this.stopHeartbeatAndBackfill=()=>{null!=this.heartbeatIntervalId&&(clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=void 0),this.cancelBackfill()},this.apiKey=o,this.backfiller=new B(this),this.addSocketListeners(),this.startHeartbeat(),this.cancelBackfill=t}static getNetwork(e){return"string"==typeof e&&e in s?s[e]:y(e)}on(e,t){return this._addEventListener(e,t,!1)}once(e,t){return this._addEventListener(e,t,!0)}off(e,t){return n(e)?this._off(e,t):super.off(e,t)}removeAllListeners(e){return void 0!==e&&n(e)?this._removeAllListeners(e):super.removeAllListeners(e)}listenerCount(e){return void 0!==e&&n(e)?this._listenerCount(e):super.listenerCount(e)}listeners(e){return void 0!==e&&n(e)?this._listeners(e):super.listeners(e)}_addEventListener(e,t,s){if(n(e)){i(e);const n=new o(r(e),t,s);return this._events.push(n),this._startEvent(n),this}return super._addEventListener(e,t,s)}_startEvent(e){[...l,"block","filter"].includes(e.type)?this.customStartEvent(e):super._startEvent(e)}_subscribe(t,s,n,i){return e(this,void 0,void 0,(function*(){let e=this._subIds[t];const o=yield this.getBlockNumber();null==e&&(e=Promise.all(s).then((e=>this.send("eth_subscribe",e))),this._subIds[t]=e);const r=yield e,c=yield Promise.all(s);this.virtualSubscriptionsById.set(r,{event:i,method:"eth_subscribe",params:c,startingBlockNumber:o,virtualId:r,physicalId:r,sentEvents:[],isBackfilling:!1,backfillBuffer:[]}),this.virtualIdsByPhysicalId.set(r,r),this._subs[r]={tag:t,processFunc:n}}))}emit(e,...t){if(n(e)){let s=!1;const n=[],i=r(e);return this._events=this._events.filter((e=>e.tag!==i||(setTimeout((()=>{e.listener.apply(this,t)}),0),s=!0,!e.once||(n.push(e),!1)))),n.forEach((e=>{this._stopEvent(e)})),s}return super.emit(e,...t)}sendBatch(t){return e(this,void 0,void 0,(function*(){let e=0;const s=t.map((({method:t,params:s})=>({method:t,params:s,jsonrpc:"2.0",id:"alchemy-sdk:"+e++})));return this.sendBatchConcurrently(s)}))}destroy(){return this.removeSocketListeners(),this.stopHeartbeatAndBackfill(),super.destroy()}isCommunityResource(){return this.apiKey===c}_stopEvent(e){let t=e.tag;if(l.includes(e.type)){if(this._events.filter((e=>l.includes(e.type))).length)return}else if("tx"===e.type){if(this._events.filter((e=>"tx"===e.type)).length)return;t="tx"}else if(this.listenerCount(e.event))return;const s=this._subIds[t];s&&(delete this._subIds[t],s.then((e=>{this._subs[e]&&(delete this._subs[e],this.send("eth_unsubscribe",[e]))})))}addSocketListeners(){this._websocket.addEventListener("message",this.handleMessage),this._websocket.addEventListener("reopen",this.handleReopen),this._websocket.addEventListener("down",this.stopHeartbeatAndBackfill)}removeSocketListeners(){this._websocket.removeEventListener("message",this.handleMessage),this._websocket.removeEventListener("reopen",this.handleReopen),this._websocket.removeEventListener("down",this.stopHeartbeatAndBackfill)}resubscribeAndBackfill(t,s){return e(this,void 0,void 0,(function*(){const{virtualId:e,method:n,params:i,sentEvents:o,backfillBuffer:r,startingBlockNumber:c}=s;s.isBackfilling=!0,r.length=0;try{const l=yield this.send(n,i);switch(O(t),s.physicalId=l,this.virtualIdsByPhysicalId.set(l,e),i[0]){case"newHeads":{const s=yield x((()=>F(this.backfiller.getNewHeadsBackfill(t,o,c),6e4)),5,(()=>!t()));O(t);(function(e){return C(e,(e=>e.hash))})([...s,...r]).forEach((t=>this.emitNewHeadsEvent(e,t)));break}case"logs":{const s=i[1]||{},n=yield x((()=>F(this.backfiller.getLogsBackfill(t,s,o,c),6e4)),5,(()=>!t()));O(t);(function(e){return C(e,(e=>`${e.blockHash}/${e.logIndex}`))})([...n,...r]).forEach((t=>this.emitLogsEvent(e,t)));break}}}finally{s.isBackfilling=!1,r.length=0}}))}emitNewHeadsEvent(e,t){this.emitAndRememberEvent(e,t,H)}emitLogsEvent(e,t){this.emitAndRememberEvent(e,t,M)}emitAndRememberEvent(e,t,s){this.rememberEvent(e,t,s),this.emitEvent(e,t)}emitEvent(e,t){const s=this.virtualSubscriptionsById.get(e);s&&this.emitGenericEvent(s,t)}rememberEvent(e,t,s){const n=this.virtualSubscriptionsById.get(e);n&&W(n.sentEvents,Object.assign({},t),s)}emitGenericEvent(e,t){this.emitProcessFn(e.event)(t)}startHeartbeat(){null==this.heartbeatIntervalId&&(this.heartbeatIntervalId=setInterval((()=>e(this,void 0,void 0,(function*(){try{yield F(this.send("net_version"),1e4)}catch(e){this._websocket.reconnect()}}))),3e4))}sendBatchConcurrently(t){return e(this,void 0,void 0,(function*(){return Promise.all(t.map((e=>this.send(e.method,e.params))))}))}customStartEvent(e){if(e.type===a){const{fromAddress:t,toAddress:s,hashesOnly:n}=e;this._subscribe(e.tag,[h.PENDING_TRANSACTIONS,{fromAddress:t,toAddress:s,hashesOnly:n}],this.emitProcessFn(e),e)}else if(e.type===u){const{addresses:t,includeRemoved:s,hashesOnly:n}=e;this._subscribe(e.tag,[h.MINED_TRANSACTIONS,{addresses:t,includeRemoved:s,hashesOnly:n}],this.emitProcessFn(e),e)}else"block"===e.type?this._subscribe("block",["newHeads"],this.emitProcessFn(e),e):"filter"===e.type&&this._subscribe(e.tag,["logs",this._getFilter(e.filter)],this.emitProcessFn(e),e)}emitProcessFn(e){switch(e.type){case a:return t=>this.emit({method:h.PENDING_TRANSACTIONS,fromAddress:e.fromAddress,toAddress:e.toAddress,hashesOnly:e.hashesOnly},t);case u:return t=>this.emit({method:h.MINED_TRANSACTIONS,addresses:e.addresses,includeRemoved:e.includeRemoved,hashesOnly:e.hashesOnly},t);case"block":return e=>{const t=d.from(e.number).toNumber();this._emitted.block=t,this.emit("block",t)};case"filter":return t=>{null==t.removed&&(t.removed=!1),this.emit(e.filter,this.formatter.filterLog(t))};default:throw new Error("Invalid event type to `emitProcessFn()`")}}_off(e,t){if(null==t)return this.removeAllListeners(e);const s=[];let n=!1;const i=r(e);return this._events=this._events.filter((e=>e.tag!==i||e.listener!=t||(!!n||(n=!0,s.push(e),!1)))),s.forEach((e=>{this._stopEvent(e)})),this}_removeAllListeners(e){let t=[];if(null==e)t=this._events,this._events=[];else{const s=r(e);this._events=this._events.filter((e=>e.tag!==s||(t.push(e),!1)))}return t.forEach((e=>{this._stopEvent(e)})),this}_listenerCount(e){if(!e)return this._events.length;const t=r(e);return this._events.filter((e=>e.tag===t)).length}_listeners(e){if(null==e)return this._events.map((e=>e.listener));const t=r(e);return this._events.filter((e=>e.tag===t)).map((e=>e.listener))}}const R=1e3,L=2,P=3e4;function x(t,s,n=(()=>!0)){return e(this,void 0,void 0,(function*(){let e=0,i=0;for(;;)try{return yield t()}catch(t){if(i++,i>=s||!n(t))throw t;if(yield j(e),!n(t))throw t;e=0===e?R:Math.min(P,L*e)}}))}function j(e){return new Promise((t=>setTimeout(t,e)))}function F(e,t){return Promise.race([e,new Promise(((e,s)=>setTimeout((()=>s(new Error("Timeout"))),t)))])}function H(e){return f(e.number)}function M(e){return f(e.blockNumber)}function W(e,t,s){const n=s(t),i=e.findIndex((e=>s(e)>n-A));-1===i?e.length=0:e.splice(0,i),e.push(t)}export{S as AlchemyWebSocketProvider};
1
+ import{aK as e,aQ as t,aF as s,aR as n,aS as i,aT as o,aU as r,aE as c,aV as l,aW as a,aX as h,aY as u,B as d,aZ as f,a_ as p,aJ as m,aN as b}from"./index-5865e5b8.js";import{A as v,g as y}from"./alchemy-provider-5870b6fa-6b210484.js";import{WebSocketProvider as g}from"@ethersproject/providers";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";import"zustand";import"@ethersproject/bytes";import"@ethersproject/properties";import"@ethersproject/address";import"@ethersproject/abstract-signer";import"buffer";import"events";import"@ethersproject/constants";import"@ethersproject/transactions";var k={};Object.defineProperty(k,"__esModule",{value:!0});var E=function(){function e(t,s,n){if(void 0===n&&(n={}),this.url=t,this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this.ondown=null,this.onreopen=null,this.CONNECTING=e.CONNECTING,this.OPEN=e.OPEN,this.CLOSING=e.CLOSING,this.CLOSED=e.CLOSED,this.hasBeenOpened=!1,this.isClosed=!1,this.messageBuffer=[],this.nextRetryTime=0,this.reconnectCount=0,this.lastKnownExtensions="",this.lastKnownProtocol="",this.listeners={},null==s||"string"==typeof s||Array.isArray(s)?this.protocols=s:n=s,this.options=I(n),!this.options.wsConstructor){if("undefined"==typeof WebSocket)throw new Error("WebSocket not present in global scope and no wsConstructor option was provided.");this.options.wsConstructor=WebSocket}this.openNewWebSocket()}return Object.defineProperty(e.prototype,"binaryType",{get:function(){return this.binaryTypeInternal||"blob"},set:function(e){this.binaryTypeInternal=e,this.ws&&(this.ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){var e=this.ws?this.ws.bufferedAmount:0,t=!1;return this.messageBuffer.forEach((function(s){var n=function(e){return"string"==typeof e?2*e.length:e instanceof ArrayBuffer?e.byteLength:e instanceof Blob?e.size:void 0}(s);null!=n?e+=n:t=!0})),t&&this.debugLog("Some buffered data had unknown length. bufferedAmount() return value may be below the correct amount."),e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this.ws?this.ws.extensions:this.lastKnownExtensions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this.ws?this.ws.protocol:this.lastKnownProtocol},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this.isClosed?e.CLOSED:e.OPEN},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){this.disposeSocket(e,t),this.shutdown(),this.debugLog("WebSocket permanently closed by client.")},e.prototype.send=function(e){if(this.isClosed)throw new Error("WebSocket is already in CLOSING or CLOSED state.");this.ws&&this.ws.readyState===this.OPEN?this.ws.send(e):this.messageBuffer.push(e)},e.prototype.reconnect=function(){if(this.isClosed)throw new Error("Cannot call reconnect() on socket which is permanently closed.");this.disposeSocket(1e3,"Client requested reconnect."),this.handleClose(void 0)},e.prototype.addEventListener=function(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)},e.prototype.dispatchEvent=function(e){return this.dispatchEventOfType(e.type,e)},e.prototype.removeEventListener=function(e,t){this.listeners[e]&&(this.listeners[e]=this.listeners[e].filter((function(e){return e!==t})))},e.prototype.openNewWebSocket=function(){var e=this;if(!this.isClosed){var t=this.options,s=t.connectTimeout,n=t.wsConstructor;this.debugLog("Opening new WebSocket to "+this.url+".");var i=new n(this.url,this.protocols);i.onclose=function(t){return e.handleClose(t)},i.onerror=function(t){return e.handleError(t)},i.onmessage=function(t){return e.handleMessage(t)},i.onopen=function(t){return e.handleOpen(t)},this.connectTimeoutId=setTimeout((function(){e.clearConnectTimeout(),e.disposeSocket(),e.handleClose(void 0)}),s),this.ws=i}},e.prototype.handleOpen=function(e){var t=this;if(this.ws&&!this.isClosed){var s=this.options.allClearResetTime;this.debugLog("WebSocket opened."),null!=this.binaryTypeInternal?this.ws.binaryType=this.binaryTypeInternal:this.binaryTypeInternal=this.ws.binaryType,this.clearConnectTimeout(),this.hasBeenOpened?this.dispatchEventOfType("reopen",e):(this.dispatchEventOfType("open",e),this.hasBeenOpened=!0),this.messageBuffer.forEach((function(e){return t.send(e)})),this.messageBuffer=[],this.allClearTimeoutId=setTimeout((function(){t.clearAllClearTimeout(),t.nextRetryTime=0,t.reconnectCount=0;var e=s/1e3|0;t.debugLog("WebSocket remained open for "+e+" seconds. Resetting retry time and count.")}),s)}},e.prototype.handleMessage=function(e){this.isClosed||this.dispatchEventOfType("message",e)},e.prototype.handleClose=function(e){var t=this;if(!this.isClosed){var s=this.options,n=s.maxReconnectAttempts,i=s.shouldReconnect;if(this.clearConnectTimeout(),this.clearAllClearTimeout(),this.ws&&(this.lastKnownExtensions=this.ws.extensions,this.lastKnownProtocol=this.ws.protocol,this.disposeSocket()),this.dispatchEventOfType("down",e),this.reconnectCount>=n)this.stopReconnecting(e,this.getTooManyFailedReconnectsMessage());else{var o=!e||i(e);"boolean"==typeof o?this.handleWillReconnect(o,e,"Provided shouldReconnect() returned false. Closing permanently."):o.then((function(s){t.isClosed||t.handleWillReconnect(s,e,"Provided shouldReconnect() resolved to false. Closing permanently.")}))}}},e.prototype.handleError=function(e){this.dispatchEventOfType("error",e),this.debugLog("WebSocket encountered an error.")},e.prototype.handleWillReconnect=function(e,t,s){e?this.reestablishConnection():this.stopReconnecting(t,s)},e.prototype.reestablishConnection=function(){var e=this,t=this.options,s=t.minReconnectDelay,n=t.maxReconnectDelay,i=t.reconnectBackoffFactor;this.reconnectCount++;var o=this.nextRetryTime;this.nextRetryTime=Math.max(s,Math.min(this.nextRetryTime*i,n)),setTimeout((function(){return e.openNewWebSocket()}),o);var r=o/1e3|0;this.debugLog("WebSocket was closed. Re-opening in "+r+" seconds.")},e.prototype.stopReconnecting=function(e,t){this.debugLog(t),this.shutdown(),e&&this.dispatchEventOfType("close",e)},e.prototype.shutdown=function(){this.isClosed=!0,this.clearAllTimeouts(),this.messageBuffer=[],this.disposeSocket()},e.prototype.disposeSocket=function(e,t){this.ws&&(this.ws.onerror=N,this.ws.onclose=N,this.ws.onmessage=N,this.ws.onopen=N,this.ws.close(e,t),this.ws=void 0)},e.prototype.clearAllTimeouts=function(){this.clearConnectTimeout(),this.clearAllClearTimeout()},e.prototype.clearConnectTimeout=function(){null!=this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=void 0)},e.prototype.clearAllClearTimeout=function(){null!=this.allClearTimeoutId&&(clearTimeout(this.allClearTimeoutId),this.allClearTimeoutId=void 0)},e.prototype.dispatchEventOfType=function(e,t){var s=this;switch(e){case"close":this.onclose&&this.onclose(t);break;case"error":this.onerror&&this.onerror(t);break;case"message":this.onmessage&&this.onmessage(t);break;case"open":this.onopen&&this.onopen(t);break;case"down":this.ondown&&this.ondown(t);break;case"reopen":this.onreopen&&this.onreopen(t)}return e in this.listeners&&this.listeners[e].slice().forEach((function(e){return s.callListener(e,t)})),!t||!t.defaultPrevented},e.prototype.callListener=function(e,t){"function"==typeof e?e.call(this,t):e.handleEvent.call(this,t)},e.prototype.debugLog=function(e){this.options.debug&&console.log(e)},e.prototype.getTooManyFailedReconnectsMessage=function(){var e,t=this.options.maxReconnectAttempts;return"Failed to reconnect after "+t+" "+(e="attempt",(1===t?e:e+"s")+". Closing permanently.")},e.DEFAULT_OPTIONS={allClearResetTime:5e3,connectTimeout:5e3,debug:!1,minReconnectDelay:1e3,maxReconnectDelay:3e4,maxReconnectAttempts:Number.POSITIVE_INFINITY,reconnectBackoffFactor:1.5,shouldReconnect:function(){return!0},wsConstructor:void 0},e.CONNECTING=0,e.OPEN=1,e.CLOSING=2,e.CLOSED=3,e}(),w=k.default=E;function I(e){var t={};return Object.keys(E.DEFAULT_OPTIONS).forEach((function(s){var n=e[s];t[s]=void 0===n?E.DEFAULT_OPTIONS[s]:n})),t}function N(){}class B{constructor(e){this.provider=e,this.maxBackfillBlocks=120}getNewHeadsBackfill(t,s,n){return e(this,void 0,void 0,(function*(){O(t);const e=yield this.getBlockNumber();if(O(t),0===s.length)return this.getHeadEventsInRange(Math.max(n,e-this.maxBackfillBlocks)+1,e+1);const i=f(s[s.length-1].number),o=e-this.maxBackfillBlocks+1;if(i<=o)return this.getHeadEventsInRange(o,e+1);const r=yield this.getReorgHeads(t,s);O(t);const c=yield this.getHeadEventsInRange(i+1,e+1);return O(t),[...r,...c]}))}getLogsBackfill(t,s,n,i){return e(this,void 0,void 0,(function*(){O(t);const e=yield this.getBlockNumber();if(O(t),0===n.length)return this.getLogsInRange(s,Math.max(i,e-this.maxBackfillBlocks)+1,e+1);const o=f(n[n.length-1].blockNumber),r=e-this.maxBackfillBlocks+1;if(o<r)return this.getLogsInRange(s,r,e+1);const c=yield this.getCommonAncestor(t,n);O(t);const l=n.filter((e=>f(e.blockNumber)>c.blockNumber)).map((e=>Object.assign(Object.assign({},e),{removed:!0}))),a=c.blockNumber===Number.NEGATIVE_INFINITY?f(n[0].blockNumber):c.blockNumber;let h=yield this.getLogsInRange(s,a,e+1);return h=h.filter((e=>e&&(f(e.blockNumber)>c.blockNumber||f(e.logIndex)>c.logIndex))),O(t),[...l,...h]}))}setMaxBackfillBlock(e){this.maxBackfillBlocks=e}getBlockNumber(){return e(this,void 0,void 0,(function*(){const e=yield this.provider.send("eth_blockNumber");return f(e)}))}getHeadEventsInRange(t,s){return e(this,void 0,void 0,(function*(){if(t>=s)return[];const e=[];for(let n=t;n<s;n++)e.push({method:"eth_getBlockByNumber",params:[p(n),!1]});return(yield this.provider.sendBatch(e)).map(T)}))}getReorgHeads(t,s){return e(this,void 0,void 0,(function*(){const e=[];for(let n=s.length-1;n>=0;n--){const i=s[n],o=yield this.getBlockByNumber(f(i.number));if(O(t),i.hash===o.hash)break;e.push(T(o))}return e.reverse()}))}getBlockByNumber(t){return e(this,void 0,void 0,(function*(){return this.provider.send("eth_getBlockByNumber",[p(t),!1])}))}getCommonAncestor(t,s){return e(this,void 0,void 0,(function*(){let e=yield this.getBlockByNumber(f(s[s.length-1].blockNumber));O(t);for(let t=s.length-1;t>=0;t--){const n=s[t];if(n.blockNumber!==e.number&&(e=yield this.getBlockByNumber(f(n.blockNumber))),n.blockHash===e.hash)return{blockNumber:f(n.blockNumber),logIndex:f(n.logIndex)}}return{blockNumber:Number.NEGATIVE_INFINITY,logIndex:Number.NEGATIVE_INFINITY}}))}getLogsInRange(t,s,n){return e(this,void 0,void 0,(function*(){if(s>=n)return[];const e=Object.assign(Object.assign({},t),{fromBlock:p(s),toBlock:p(n-1)});return this.provider.send("eth_getLogs",[e])}))}}function T(e){const t=Object.assign({},e);return delete t.totalDifficulty,delete t.transactions,delete t.uncles,t}function C(e,t){const s=new Set,n=[];return e.forEach((e=>{const i=t(e);s.has(i)||(s.add(i),n.push(e))})),n}const _=new Error("Cancelled");function O(e){if(e())throw _}const A=10;class S extends g{constructor(s,n){var i;const o=v.getApiKey(s.apiKey),r=v.getAlchemyNetwork(s.network),c=v.getAlchemyConnectionInfo(r,o,"wss"),l=`alchemy-sdk-${m}`;super(new w(null!==(i=s.url)&&void 0!==i?i:c.url,l,{wsConstructor:null!=n?n:"undefined"!=typeof process&&null!=process&&null!=process.versions&&null!=process.versions.node?require("websocket").w3cwebsocket:WebSocket}),b[r]),this._events=[],this.virtualSubscriptionsById=new Map,this.virtualIdsByPhysicalId=new Map,this.handleMessage=e=>{const t=JSON.parse(e.data);if(!function(e){return!function(e){return Array.isArray(e)||"2.0"===e.jsonrpc&&void 0!==e.id}(e)}(t))return;const s=t.params.subscription,n=this.virtualIdsByPhysicalId.get(s);if(!n)return;const i=this.virtualSubscriptionsById.get(n);if("eth_subscribe"===i.method)switch(i.params[0]){case"newHeads":{const e=i,o=t,{isBackfilling:r,backfillBuffer:c}=e,{result:l}=o.params;r?function(e,t){W(e,t,H)}(c,l):s!==n?this.emitAndRememberEvent(n,l,H):this.rememberEvent(n,l,H);break}case"logs":{const e=i,o=t,{isBackfilling:r,backfillBuffer:c}=e,{result:l}=o.params;r?function(e,t){W(e,t,M)}(c,l):n!==s?this.emitAndRememberEvent(n,l,M):this.rememberEvent(n,l,M);break}default:if(s!==n){const{result:e}=t.params;this.emitEvent(n,e)}}},this.handleReopen=()=>{this.virtualIdsByPhysicalId.clear();const{cancel:t,isCancelled:s}=function(){let e=!1;return{cancel:()=>e=!0,isCancelled:()=>e}}();this.cancelBackfill=t;for(const t of this.virtualSubscriptionsById.values())(()=>{e(this,void 0,void 0,(function*(){try{yield this.resubscribeAndBackfill(s,t)}catch(e){s()||console.error(`Error while backfilling "${t.params[0]}" subscription. Some events may be missing.`,e)}}))})();this.startHeartbeat()},this.stopHeartbeatAndBackfill=()=>{null!=this.heartbeatIntervalId&&(clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=void 0),this.cancelBackfill()},this.apiKey=o,this.backfiller=new B(this),this.addSocketListeners(),this.startHeartbeat(),this.cancelBackfill=t}static getNetwork(e){return"string"==typeof e&&e in s?s[e]:y(e)}on(e,t){return this._addEventListener(e,t,!1)}once(e,t){return this._addEventListener(e,t,!0)}off(e,t){return n(e)?this._off(e,t):super.off(e,t)}removeAllListeners(e){return void 0!==e&&n(e)?this._removeAllListeners(e):super.removeAllListeners(e)}listenerCount(e){return void 0!==e&&n(e)?this._listenerCount(e):super.listenerCount(e)}listeners(e){return void 0!==e&&n(e)?this._listeners(e):super.listeners(e)}_addEventListener(e,t,s){if(n(e)){i(e);const n=new o(r(e),t,s);return this._events.push(n),this._startEvent(n),this}return super._addEventListener(e,t,s)}_startEvent(e){[...l,"block","filter"].includes(e.type)?this.customStartEvent(e):super._startEvent(e)}_subscribe(t,s,n,i){return e(this,void 0,void 0,(function*(){let e=this._subIds[t];const o=yield this.getBlockNumber();null==e&&(e=Promise.all(s).then((e=>this.send("eth_subscribe",e))),this._subIds[t]=e);const r=yield e,c=yield Promise.all(s);this.virtualSubscriptionsById.set(r,{event:i,method:"eth_subscribe",params:c,startingBlockNumber:o,virtualId:r,physicalId:r,sentEvents:[],isBackfilling:!1,backfillBuffer:[]}),this.virtualIdsByPhysicalId.set(r,r),this._subs[r]={tag:t,processFunc:n}}))}emit(e,...t){if(n(e)){let s=!1;const n=[],i=r(e);return this._events=this._events.filter((e=>e.tag!==i||(setTimeout((()=>{e.listener.apply(this,t)}),0),s=!0,!e.once||(n.push(e),!1)))),n.forEach((e=>{this._stopEvent(e)})),s}return super.emit(e,...t)}sendBatch(t){return e(this,void 0,void 0,(function*(){let e=0;const s=t.map((({method:t,params:s})=>({method:t,params:s,jsonrpc:"2.0",id:"alchemy-sdk:"+e++})));return this.sendBatchConcurrently(s)}))}destroy(){return this.removeSocketListeners(),this.stopHeartbeatAndBackfill(),super.destroy()}isCommunityResource(){return this.apiKey===c}_stopEvent(e){let t=e.tag;if(l.includes(e.type)){if(this._events.filter((e=>l.includes(e.type))).length)return}else if("tx"===e.type){if(this._events.filter((e=>"tx"===e.type)).length)return;t="tx"}else if(this.listenerCount(e.event))return;const s=this._subIds[t];s&&(delete this._subIds[t],s.then((e=>{this._subs[e]&&(delete this._subs[e],this.send("eth_unsubscribe",[e]))})))}addSocketListeners(){this._websocket.addEventListener("message",this.handleMessage),this._websocket.addEventListener("reopen",this.handleReopen),this._websocket.addEventListener("down",this.stopHeartbeatAndBackfill)}removeSocketListeners(){this._websocket.removeEventListener("message",this.handleMessage),this._websocket.removeEventListener("reopen",this.handleReopen),this._websocket.removeEventListener("down",this.stopHeartbeatAndBackfill)}resubscribeAndBackfill(t,s){return e(this,void 0,void 0,(function*(){const{virtualId:e,method:n,params:i,sentEvents:o,backfillBuffer:r,startingBlockNumber:c}=s;s.isBackfilling=!0,r.length=0;try{const l=yield this.send(n,i);switch(O(t),s.physicalId=l,this.virtualIdsByPhysicalId.set(l,e),i[0]){case"newHeads":{const s=yield x((()=>F(this.backfiller.getNewHeadsBackfill(t,o,c),6e4)),5,(()=>!t()));O(t);(function(e){return C(e,(e=>e.hash))})([...s,...r]).forEach((t=>this.emitNewHeadsEvent(e,t)));break}case"logs":{const s=i[1]||{},n=yield x((()=>F(this.backfiller.getLogsBackfill(t,s,o,c),6e4)),5,(()=>!t()));O(t);(function(e){return C(e,(e=>`${e.blockHash}/${e.logIndex}`))})([...n,...r]).forEach((t=>this.emitLogsEvent(e,t)));break}}}finally{s.isBackfilling=!1,r.length=0}}))}emitNewHeadsEvent(e,t){this.emitAndRememberEvent(e,t,H)}emitLogsEvent(e,t){this.emitAndRememberEvent(e,t,M)}emitAndRememberEvent(e,t,s){this.rememberEvent(e,t,s),this.emitEvent(e,t)}emitEvent(e,t){const s=this.virtualSubscriptionsById.get(e);s&&this.emitGenericEvent(s,t)}rememberEvent(e,t,s){const n=this.virtualSubscriptionsById.get(e);n&&W(n.sentEvents,Object.assign({},t),s)}emitGenericEvent(e,t){this.emitProcessFn(e.event)(t)}startHeartbeat(){null==this.heartbeatIntervalId&&(this.heartbeatIntervalId=setInterval((()=>e(this,void 0,void 0,(function*(){try{yield F(this.send("net_version"),1e4)}catch(e){this._websocket.reconnect()}}))),3e4))}sendBatchConcurrently(t){return e(this,void 0,void 0,(function*(){return Promise.all(t.map((e=>this.send(e.method,e.params))))}))}customStartEvent(e){if(e.type===a){const{fromAddress:t,toAddress:s,hashesOnly:n}=e;this._subscribe(e.tag,[h.PENDING_TRANSACTIONS,{fromAddress:t,toAddress:s,hashesOnly:n}],this.emitProcessFn(e),e)}else if(e.type===u){const{addresses:t,includeRemoved:s,hashesOnly:n}=e;this._subscribe(e.tag,[h.MINED_TRANSACTIONS,{addresses:t,includeRemoved:s,hashesOnly:n}],this.emitProcessFn(e),e)}else"block"===e.type?this._subscribe("block",["newHeads"],this.emitProcessFn(e),e):"filter"===e.type&&this._subscribe(e.tag,["logs",this._getFilter(e.filter)],this.emitProcessFn(e),e)}emitProcessFn(e){switch(e.type){case a:return t=>this.emit({method:h.PENDING_TRANSACTIONS,fromAddress:e.fromAddress,toAddress:e.toAddress,hashesOnly:e.hashesOnly},t);case u:return t=>this.emit({method:h.MINED_TRANSACTIONS,addresses:e.addresses,includeRemoved:e.includeRemoved,hashesOnly:e.hashesOnly},t);case"block":return e=>{const t=d.from(e.number).toNumber();this._emitted.block=t,this.emit("block",t)};case"filter":return t=>{null==t.removed&&(t.removed=!1),this.emit(e.filter,this.formatter.filterLog(t))};default:throw new Error("Invalid event type to `emitProcessFn()`")}}_off(e,t){if(null==t)return this.removeAllListeners(e);const s=[];let n=!1;const i=r(e);return this._events=this._events.filter((e=>e.tag!==i||e.listener!=t||(!!n||(n=!0,s.push(e),!1)))),s.forEach((e=>{this._stopEvent(e)})),this}_removeAllListeners(e){let t=[];if(null==e)t=this._events,this._events=[];else{const s=r(e);this._events=this._events.filter((e=>e.tag!==s||(t.push(e),!1)))}return t.forEach((e=>{this._stopEvent(e)})),this}_listenerCount(e){if(!e)return this._events.length;const t=r(e);return this._events.filter((e=>e.tag===t)).length}_listeners(e){if(null==e)return this._events.map((e=>e.listener));const t=r(e);return this._events.filter((e=>e.tag===t)).map((e=>e.listener))}}const R=1e3,L=2,P=3e4;function x(t,s,n=(()=>!0)){return e(this,void 0,void 0,(function*(){let e=0,i=0;for(;;)try{return yield t()}catch(t){if(i++,i>=s||!n(t))throw t;if(yield j(e),!n(t))throw t;e=0===e?R:Math.min(P,L*e)}}))}function j(e){return new Promise((t=>setTimeout(t,e)))}function F(e,t){return Promise.race([e,new Promise(((e,s)=>setTimeout((()=>s(new Error("Timeout"))),t)))])}function H(e){return f(e.number)}function M(e){return f(e.blockNumber)}function W(e,t,s){const n=s(t),i=e.findIndex((e=>s(e)>n-A));-1===i?e.length=0:e.splice(0,i),e.push(t)}export{S as AlchemyWebSocketProvider};
@@ -1 +1 @@
1
- import{_ as e,A as t}from"./index-98d378b6.js";import"@ethersproject/providers";import"zustand";import"@ethersproject/bytes";import"@ethersproject/properties";import"@ethersproject/address";import"@ethersproject/abstract-signer";import"buffer";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";import"events";import"@ethersproject/constants";import"@ethersproject/transactions";function r(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function n(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 i(e,t){if(!e)throw new Error(t)}var o,s;"function"==typeof SuppressedError&&SuppressedError,function(e){e.prod="BLOCTO_SDK",e.dev="BLOCTO_SDK_DEV",e.staging="BLOCTO_SDK_STAGING"}(o||(o={})),function(e){e.ETHEREUM="ethereum",e.APTOS="aptos"}(s||(s={}));const a={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",421614:"https://arbitrum-sepolia.blockpi.network/v1/rpc/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io",11155420:"https://sepolia.optimism.io",8453:"https://mainnet.base.org",84531:"https://goerli.base.org",84532:"https://sepolia.base.org",7777777:"https://rpc.zora.energy",999:"https://testnet.rpc.zora.energy",999999999:"https://sepolia.rpc.zora.energy",534352:"https://rpc.scroll.io",534353:"https://alpha-rpc.scroll.io/l2",534351:"https://sepolia-rpc.scroll.io",59144:"https://rpc.linea.build",59140:"https://rpc.goerli.linea.build",1261120:"https://rpc.startale.com/zkatana"},c={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},u={prod:o.prod,staging:o.staging,dev:o.dev},h={1:o.prod,2:o.dev,3:o.dev,4:o.dev,5:o.staging},d={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 l;!function(e){e.Mainnet="mainnet",e.Testnet="testnet",e.Devnet="devnet",e.Testing="testing",e.Premainnet="premainnet"}(l||(l={}));const f={1:l.Mainnet,2:l.Testnet,3:l.Devnet,4:l.Testing,5:l.Premainnet},p={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"},v=["connect","disconnect","message","chainChanged","accountsChanged"],g="00000000-0000-0000-0000-000000000000",m="0.9.1";class y{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,v.forEach((e=>{this.eventListeners[e]=[]})),this.appId=g}request(e){return r(this,void 0,void 0,(function*(){}))}on(e,t){v.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 w(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 b(e){document.body.appendChild(e)}function E(e){const t=e&&e.parentNode;t&&t.removeChild instanceof Function&&t.removeChild(e)}var S=(e,t,r=window)=>{r.addEventListener(e,(function n(i){t(i,(()=>r.removeEventListener(e,n)))}))};const _="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]}},A=(()=>{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:_,O=(e,t=null)=>{const r=A.getItem(e);try{return r&&JSON.parse(r)||t}catch(e){return r||t}},R=(e,t)=>A.setItem(e,"string"==typeof t?t:JSON.stringify(t)),I=e=>{R(e,""),A.removeItem(e)},P=e=>{const t=O(e,null);return t?(new Date).getTime()>t.expiry||t.v!==m?(I(e),null):null==t?void 0:t.data:null},T=(e,t,r)=>{var n,i,o;const s=O(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:m};R(e,a)},C=(e,t)=>{var r,n,i;return(null===(r=P(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=P(e))||void 0===n?void 0:n.accounts)||void 0===i?void 0:i[t])||null:(I(e),null)},N=(e,t)=>{var r,n,i;return(null===(r=P(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=P(e))||void 0===n?void 0:n.evm)||void 0===i?void 0:i[t])||null:(I(e),null)},j=(e,t,r)=>{T(e,{evm:{[t]:r}})},D=e=>{const t=O(e);t&&(t.data.evm={},R(e,t))};function k(e,t,n){return r(this,void 0,void 0,(function*(){if(403!==e.status&&401!==e.status||(n&&n(),I(t)),!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 x=e=>/\S+@\S+\.\S+/.test(e);var L;!function(e){e.INVALID_TRANSACTION="Invalid transaction",e.INVALID_TRANSACTIONS="Invalid transactions",e.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'}(L||(L={}));var M="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},U=[],K=[],B="undefined"!=typeof Uint8Array?Uint8Array:Array,q=!1;function $(){q=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)U[t]=e[t],K[e.charCodeAt(t)]=t;K["-".charCodeAt(0)]=62,K["_".charCodeAt(0)]=63}function V(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 Y(e){var t;q||$();for(var r=e.length,n=r%3,i="",o=[],s=16383,a=0,c=r-n;a<c;a+=s)o.push(V(e,a,a+s>c?c: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 F(e,t,r,n,i){var o,s,a=8*i-n-1,c=(1<<a)-1,u=c>>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-u;else{if(o===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=u}return(f?-1:1)*s*Math.pow(2,o-n)}function z(e,t,r,n,i,o){var s,a,c,u=8*o-i-1,h=(1<<u)-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*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+d>=1?l/c:l*Math.pow(2,1-d))*c>=2&&(s++,c/=2),s+d>=h?(a=0,s=h):s+d>=1?(a=(t*c-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,u+=i;u>0;e[r+f]=255&s,f+=p,s/=256,u-=8);e[r+f-p]|=128*v}var J={}.toString,G=Array.isArray||function(e){return"[object Array]"==J.call(e)};function H(){return X.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function W(e,t){if(H()<t)throw new RangeError("Invalid typed array length");return X.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=X.prototype:(null===e&&(e=new X(t)),e.length=t),e}function X(e,t,r){if(!(X.TYPED_ARRAY_SUPPORT||this instanceof X))return new X(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 ee(this,e)}return Z(this,e,t,r)}function Z(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);X.TYPED_ARRAY_SUPPORT?(e=t).__proto__=X.prototype:e=te(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!X.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|ie(t,r);e=W(e,n);var i=e.write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(ne(t)){var r=0|re(t.length);return 0===(e=W(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?W(e,0):te(e,t);if("Buffer"===t.type&&G(t.data))return te(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function Q(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 ee(e,t){if(Q(t),e=W(e,t<0?0:0|re(t)),!X.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function te(e,t){var r=t.length<0?0:0|re(t.length);e=W(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function re(e){if(e>=H())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+H().toString(16)+" bytes");return 0|e}function ne(e){return!(null==e||!e._isBuffer)}function ie(e,t){if(ne(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 Ne(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return je(e).length;default:if(n)return Ne(e).length;t=(""+t).toLowerCase(),n=!0}}function oe(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 be(this,t,r);case"utf8":case"utf-8":return ge(this,t,r);case"ascii":return ye(this,t,r);case"latin1":case"binary":return we(this,t,r);case"base64":return ve(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ee(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function se(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function ae(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=X.from(t,n)),ne(t))return 0===t.length?-1:ce(e,t,r,n,i);if("number"==typeof t)return t&=255,X.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):ce(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ce(e,t,r,n,i){var o,s=1,a=e.length,c=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,c/=2,r/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var h=-1;for(o=r;o<a;o++)if(u(e,o)===u(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===c)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+c>a&&(r=a-c),o=r;o>=0;o--){for(var d=!0,l=0;l<c;l++)if(u(e,o+l)!==u(t,l)){d=!1;break}if(d)return o}return-1}function ue(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 he(e,t,r,n){return De(Ne(t,e.length-r),e,r,n)}function de(e,t,r,n){return De(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function le(e,t,r,n){return de(e,t,r,n)}function fe(e,t,r,n){return De(je(t),e,r,n)}function pe(e,t,r,n){return De(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 ve(e,t,r){return 0===t&&r===e.length?Y(e):Y(e.slice(t,r))}function ge(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,c,u=e[i],h=null,d=u>239?4:u>223?3:u>191?2:1;if(i+d<=r)switch(d){case 1:u<128&&(h=u);break;case 2:128==(192&(o=e[i+1]))&&(c=(31&u)<<6|63&o)>127&&(h=c);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(c=(15&u)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(h=c)}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<=me)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=me));return r}(n)}X.TYPED_ARRAY_SUPPORT=void 0===M.TYPED_ARRAY_SUPPORT||M.TYPED_ARRAY_SUPPORT,H(),X.poolSize=8192,X._augment=function(e){return e.__proto__=X.prototype,e},X.from=function(e,t,r){return Z(null,e,t,r)},X.TYPED_ARRAY_SUPPORT&&(X.prototype.__proto__=Uint8Array.prototype,X.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&X[Symbol.species]),X.alloc=function(e,t,r){return function(e,t,r,n){return Q(t),t<=0?W(e,t):void 0!==r?"string"==typeof n?W(e,t).fill(r,n):W(e,t).fill(r):W(e,t)}(null,e,t,r)},X.allocUnsafe=function(e){return ee(null,e)},X.allocUnsafeSlow=function(e){return ee(null,e)},X.isBuffer=function(e){return null!=e&&(!!e._isBuffer||ke(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&ke(e.slice(0,0))}(e))},X.compare=function(e,t){if(!ne(e)||!ne(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},X.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}},X.concat=function(e,t){if(!G(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return X.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=X.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!ne(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},X.byteLength=ie,X.prototype._isBuffer=!0,X.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)se(this,t,t+1);return this},X.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)se(this,t,t+3),se(this,t+1,t+2);return this},X.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)se(this,t,t+7),se(this,t+1,t+6),se(this,t+2,t+5),se(this,t+3,t+4);return this},X.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?ge(this,0,e):oe.apply(this,arguments)},X.prototype.equals=function(e){if(!ne(e))throw new TypeError("Argument must be a Buffer");return this===e||0===X.compare(this,e)},X.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+">"},X.prototype.compare=function(e,t,r,n,i){if(!ne(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),c=this.slice(n,i),u=e.slice(t,r),h=0;h<a;++h)if(c[h]!==u[h]){o=c[h],s=u[h];break}return o<s?-1:s<o?1:0},X.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},X.prototype.indexOf=function(e,t,r){return ae(this,e,t,r,!0)},X.prototype.lastIndexOf=function(e,t,r){return ae(this,e,t,r,!1)},X.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 ue(this,e,t,r);case"utf8":case"utf-8":return he(this,e,t,r);case"ascii":return de(this,e,t,r);case"latin1":case"binary":return le(this,e,t,r);case"base64":return fe(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return pe(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},X.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var me=4096;function ye(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 we(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 be(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+=Ce(e[o]);return i}function Ee(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 Se(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 _e(e,t,r,n,i,o){if(!ne(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 Ae(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 Oe(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 Re(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 Ie(e,t,r,n,i){return i||Re(e,0,r,4),z(e,t,r,n,23,4),r+4}function Pe(e,t,r,n,i){return i||Re(e,0,r,8),z(e,t,r,n,52,8),r+8}X.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),X.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=X.prototype;else{var i=t-e;r=new X(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},X.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||Se(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},X.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||Se(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},X.prototype.readUInt8=function(e,t){return t||Se(e,1,this.length),this[e]},X.prototype.readUInt16LE=function(e,t){return t||Se(e,2,this.length),this[e]|this[e+1]<<8},X.prototype.readUInt16BE=function(e,t){return t||Se(e,2,this.length),this[e]<<8|this[e+1]},X.prototype.readUInt32LE=function(e,t){return t||Se(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},X.prototype.readUInt32BE=function(e,t){return t||Se(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},X.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||Se(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},X.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||Se(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},X.prototype.readInt8=function(e,t){return t||Se(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},X.prototype.readInt16LE=function(e,t){t||Se(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},X.prototype.readInt16BE=function(e,t){t||Se(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},X.prototype.readInt32LE=function(e,t){return t||Se(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},X.prototype.readInt32BE=function(e,t){return t||Se(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},X.prototype.readFloatLE=function(e,t){return t||Se(e,4,this.length),F(this,e,!0,23,4)},X.prototype.readFloatBE=function(e,t){return t||Se(e,4,this.length),F(this,e,!1,23,4)},X.prototype.readDoubleLE=function(e,t){return t||Se(e,8,this.length),F(this,e,!0,52,8)},X.prototype.readDoubleBE=function(e,t){return t||Se(e,8,this.length),F(this,e,!1,52,8)},X.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||_e(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},X.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||_e(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},X.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,1,255,0),X.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},X.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,65535,0),X.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Ae(this,e,t,!0),t+2},X.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,65535,0),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Ae(this,e,t,!1),t+2},X.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,4294967295,0),X.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):Oe(this,e,t,!0),t+4},X.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,4294967295,0),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Oe(this,e,t,!1),t+4},X.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);_e(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},X.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);_e(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},X.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,1,127,-128),X.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},X.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,32767,-32768),X.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Ae(this,e,t,!0),t+2},X.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,32767,-32768),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Ae(this,e,t,!1),t+2},X.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,2147483647,-2147483648),X.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):Oe(this,e,t,!0),t+4},X.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Oe(this,e,t,!1),t+4},X.prototype.writeFloatLE=function(e,t,r){return Ie(this,e,t,!0,r)},X.prototype.writeFloatBE=function(e,t,r){return Ie(this,e,t,!1,r)},X.prototype.writeDoubleLE=function(e,t,r){return Pe(this,e,t,!0,r)},X.prototype.writeDoubleBE=function(e,t,r){return Pe(this,e,t,!1,r)},X.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||!X.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},X.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&&!X.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=ne(e)?e:Ne(new X(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var Te=/[^+\/0-9A-Za-z-_]/g;function Ce(e){return e<16?"0"+e.toString(16):e.toString(16)}function Ne(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 je(e){return function(e){var t,r,n,i,o,s;q||$();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 B(3*a/4-o),n=o>0?a-4:a;var c=0;for(t=0,r=0;t<n;t+=4,r+=3)i=K[e.charCodeAt(t)]<<18|K[e.charCodeAt(t+1)]<<12|K[e.charCodeAt(t+2)]<<6|K[e.charCodeAt(t+3)],s[c++]=i>>16&255,s[c++]=i>>8&255,s[c++]=255&i;return 2===o?(i=K[e.charCodeAt(t)]<<2|K[e.charCodeAt(t+1)]>>4,s[c++]=255&i):1===o&&(i=K[e.charCodeAt(t)]<<10|K[e.charCodeAt(t+1)]<<4|K[e.charCodeAt(t+2)]>>2,s[c++]=i>>8&255,s[c++]=255&i),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Te,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function De(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 ke(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}const xe=e=>"string"==typeof e&&/^0x[0-9A-Fa-f]*$/.test(e),Le=e=>e&&"object"==typeof e&&"from"in e?e.value&&!xe(e.value)?{isValid:!1,invalidMsg:L.INVALID_TRANSACTION_VALUE}:{isValid:!0}:{isValid:!1,invalidMsg:L.INVALID_TRANSACTION};function Me(){return r(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})),{})}))}var Ue={};function Ke(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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 qe(e){var t=function(e,t){if("object"!==Be(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==Be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===Be(t)?t:String(t)}function $e(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,qe(n.key),n)}}function Ve(e,t,r){return t&&$e(e.prototype,t),r&&$e(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ye(e,t){return Ye=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ye(e,t)}function Fe(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 ze(e,t){if(t&&("object"===Be(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 Je(e){return Je=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Je(e)}function Ge(e,t,r){return Ge=function(){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}}()?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},Ge.apply(null,arguments)}function He(e){var t="function"==typeof Map?new Map:void 0;return He=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 Ge(e,arguments,Je(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ye(n,e)},He(e)}var We={},Xe=nt;nt.default=nt,nt.stable=at,nt.stableStringify=at;var Ze="[...]",Qe="[Circular]",et=[],tt=[];function rt(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function nt(e,t,r,n){var i;void 0===n&&(n=rt()),ot(e,"",0,[],void 0,0,n);try{i=0===tt.length?JSON.stringify(e,t,r):JSON.stringify(e,ut(t),r)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==et.length;){var o=et.pop();4===o.length?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function it(e,t,r,n){var i=Object.getOwnPropertyDescriptor(n,r);void 0!==i.get?i.configurable?(Object.defineProperty(n,r,{value:e}),et.push([n,r,t,i])):tt.push([t,r,e]):(n[r]=e,et.push([n,r,t]))}function ot(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 it(Qe,e,t,i);if(void 0!==s.depthLimit&&o>s.depthLimit)return void it(Ze,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void it(Ze,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)ot(e[a],a,a,n,e,o,s);else{var c=Object.keys(e);for(a=0;a<c.length;a++){var u=c[a];ot(e[u],u,a,n,e,o,s)}}n.pop()}}function st(e,t){return e<t?-1:e>t?1:0}function at(e,t,r,n){void 0===n&&(n=rt());var i,o=ct(e,"",0,[],void 0,0,n)||e;try{i=0===tt.length?JSON.stringify(o,t,r):JSON.stringify(o,ut(t),r)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==et.length;){var s=et.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 it(Qe,e,t,i);try{if("function"==typeof e.toJSON)return}catch(e){return}if(void 0!==s.depthLimit&&o>s.depthLimit)return void it(Ze,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void it(Ze,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 c={},u=Object.keys(e).sort(st);for(a=0;a<u.length;a++){var h=u[a];ct(e[h],h,a,n,e,o,s),c[h]=e[h]}if(void 0===i)return c;et.push([i,t,e]),i[t]=c}n.pop()}}function ut(e){return e=void 0!==e?e:function(e,t){return t},function(t,r){if(tt.length>0)for(var n=0;n<tt.length;n++){var i=tt[n];if(i[1]===t&&i[0]===r){r=i[2],tt.splice(n,1);break}}return e.call(this,t,r)}}function ht(e){var t=function(){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}}();return function(){var r,n=Je(e);if(t){var i=Je(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return ze(this,r)}}Object.defineProperty(We,"__esModule",{value:!0}),We.EthereumProviderError=We.EthereumRpcError=void 0;var dt=Xe,lt=function(e){Fe(r,He(Error));var t=ht(r);function r(e,n,i){var o;if(Ke(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 Ve(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}();We.EthereumRpcError=lt;var ft=function(e){Fe(r,lt);var t=ht(r);function r(e,n,i){if(Ke(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 Ve(r)}();function pt(e,t){if("[Circular]"!==t)return t}We.EthereumProviderError=ft;var vt={},gt={};function mt(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}function yt(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=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return mt(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?mt(e,t):void 0}}(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.")}()}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=We,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(c(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]||!!c(e)}function c(e){return e>=-32099&&e<=-32e3}function u(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]:{},c=i.fallbackError,d=void 0===c?o:c,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:u(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:u(e)}}var m=null===(n=e)||void 0===n?void 0:n.stack;return f&&e&&m&&"string"==typeof m&&(p.stack=m),p}}(vt);var wt={};Object.defineProperty(wt,"__esModule",{value:!0}),wt.ethErrors=void 0;var bt,Et,St,_t,At,Ot=We,Rt=vt,It=gt;function Pt(e,t){var r=yt(Ct(t),2),n=r[0],i=r[1];return new Ot.EthereumRpcError(e,n||Rt.getMessageFromCode(e),i)}function Tt(e,t){var r=yt(Ct(t),2),n=r[0],i=r[1];return new Ot.EthereumProviderError(e,n||Rt.getMessageFromCode(e),i)}function Ct(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 Nt(e){return e?"number"==typeof e?e:e.startsWith("0x")?parseInt(e,16):parseInt(e,10):1}wt.ethErrors={rpc:{parse:function(e){return Pt(It.errorCodes.rpc.parse,e)},invalidRequest:function(e){return Pt(It.errorCodes.rpc.invalidRequest,e)},invalidParams:function(e){return Pt(It.errorCodes.rpc.invalidParams,e)},methodNotFound:function(e){return Pt(It.errorCodes.rpc.methodNotFound,e)},internal:function(e){return Pt(It.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 Pt(t,e)},invalidInput:function(e){return Pt(It.errorCodes.rpc.invalidInput,e)},resourceNotFound:function(e){return Pt(It.errorCodes.rpc.resourceNotFound,e)},resourceUnavailable:function(e){return Pt(It.errorCodes.rpc.resourceUnavailable,e)},transactionRejected:function(e){return Pt(It.errorCodes.rpc.transactionRejected,e)},methodNotSupported:function(e){return Pt(It.errorCodes.rpc.methodNotSupported,e)},limitExceeded:function(e){return Pt(It.errorCodes.rpc.limitExceeded,e)}},provider:{userRejectedRequest:function(e){return Tt(It.errorCodes.provider.userRejectedRequest,e)},unauthorized:function(e){return Tt(It.errorCodes.provider.unauthorized,e)},unsupportedMethod:function(e){return Tt(It.errorCodes.provider.unsupportedMethod,e)},disconnected:function(e){return Tt(It.errorCodes.provider.disconnected,e)},chainDisconnected:function(e){return Tt(It.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 Ot.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=We;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=wt;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 jt extends y{get existedSDK(){if("undefined"!=typeof window)return window.ethereum}constructor(e){var t;if(super(),bt.add(this),this.networkVersion="1",this.off=this.removeListener,this.injectedWalletServer=e.walletServer,this._blocto={sessionKeyEnv:o.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",switchableNetwork:{}},this.appId=e.appId||g,"chainId"in e){const{chainId:t,rpc:r}=e;i(t,"'chainId' is required"),this.networkVersion=`${Nt(t)}`,this.chainId=`0x${Nt(t).toString(16)}`,this.rpc=r||a[this.networkVersion],i(this.rpc,"'rpc' is required")}else{const{defaultChainId:r,switchableChains:n}=e;i(r,"'defaultChainId' is required"),this.networkVersion=`${Nt(r)}`,this.chainId=`0x${Nt(r).toString(16)}`;const o=n.find((e=>Nt(e.chainId)===Nt(r)));if(!o)throw Ue.ethErrors.provider.custom({code:1001,message:`Chain ${r} is not in switchableChains list`});this.rpc=(null===(t=o.rpcUrls)||void 0===t?void 0:t[0])||a[this.networkVersion],i(this.rpc,"'rpc' is required"),this._blocto.unloadedNetwork=n}}send(e,t){return r(this,void 0,void 0,(function*(){switch(!0){case t instanceof Function:return this.sendAsync(e,t);case"string"==typeof e&&Array.isArray(t):return this.sendAsync({jsonrpc:"2.0",method:e,params:t});default:return this.sendAsync(e)}}))}sendAsync(e,t){return r(this,void 0,void 0,(function*(){const r=e=>e.reduce(((e,t)=>{var r;return"eth_sendTransaction"===t.method?e.sendRequests.push(null===(r=t.params)||void 0===r?void 0:r[0]):e.otherRequests.push(this.request(t)),e}),{sendRequests:[],otherRequests:[]});function n(e,t){const r=[];let n=1;return e.forEach((e=>{const i=function(e){return{id:String(e.id),jsonrpc:"2.0",method:e.method}}(e);"eth_sendTransaction"===e.method?(i.result=t[0].value,i.error="fulfilled"!==t[0].status?t[0].reason:void 0):n<t.length&&(i.result=t[n].value,i.error="fulfilled"!==t[n].status?t[n].reason:void 0,n++),r.push(i)})),r}const i=new Promise((t=>{if(Array.isArray(e)){const{sendRequests:i,otherRequests:o}=r(e),s={method:"wallet_sendMultiCallTransaction",params:[i,!1]},a=0===i.length,c=Math.floor(1e4*Math.random()),u=a?[...o]:[this.request(s),...o];Promise.allSettled(u).then((r=>{if(a)return t(r.map(((t,r)=>{var n;return{id:String((null===(n=e[r])||void 0===n?void 0:n.id)||c+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}})));const i=n(e,r);return t(i)})).catch((e=>{throw Ue.ethErrors.rpc.internal(null==e?void 0:e.message)}))}else this.request(Object.assign(Object.assign({},e),{id:Number(e.id)})).then(t)}));if("function"!=typeof t)return i;i.then((e=>t(null,e))).catch((e=>t(e)))}))}sendUserOperation(e){return r(this,void 0,void 0,(function*(){return this.request({method:"eth_sendUserOperation",params:[e]})}))}request(e){var t,i,o,s,a,c,u,h;return r(this,void 0,void 0,(function*(){if(Array.isArray(e))return this.sendAsync(e);if(!(null==e?void 0:e.method))throw Ue.ethErrors.rpc.invalidRequest();const{blockchainName:r,switchableNetwork:d,sessionKeyEnv:l}=yield n(this,bt,"m",Et).call(this);if(null===(t=this.existedSDK)||void 0===t?void 0:t.isBlocto){if("wallet_switchEthereumChain"===e.method){if(!(null===(o=null===(i=null==e?void 0:e.params)||void 0===i?void 0:i[0])||void 0===o?void 0:o.chainId))throw Ue.ethErrors.rpc.invalidParams();return this.existedSDK.request(e).then((()=>{var t,r,n;return this.networkVersion=`${Nt(null===(t=null==e?void 0:e.params)||void 0===t?void 0:t[0].chainId)}`,this.chainId=`0x${Nt(null===(r=null==e?void 0:e.params)||void 0===r?void 0:r[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 this.existedSDK.request(e)}switch(e.method){case"eth_chainId":return this.chainId;case"net_version":return this.networkVersion;case"wallet_addEthereumChain":return this.loadSwitchableNetwork((null==e?void 0:e.params)||[]);case"eth_blockNumber":case"web3_clientVersion":case"eth_call":{const t=yield this.handleReadRequests(e);if(!t||t&&!t.result&&t.error){const e=(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.message)?t.error.message:"Request failed";throw Ue.ethErrors.rpc.internal(e)}return"function"==typeof(null==e?void 0:e.callback)&&e.callback(null,t.result),t.result}case"wallet_switchEthereumChain":return this.handleSwitchChain(null===(c=null===(a=null==e?void 0:e.params)||void 0===a?void 0:a[0])||void 0===c?void 0:c.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return N(l,r)||[]}if(!N(l,r)){const t=null===(u=null==e?void 0:e.params)||void 0===u?void 0:u[0];"eth_requestAccounts"===e.method&&x(t)?yield this.enable(t):yield this.enable()}try{let t=null,n=null;switch(e.method){case"eth_requestAccounts":n=yield this.fetchAccounts();break;case"eth_coinbase":n=null===(h=N(l,r))||void 0===h?void 0:h[0];break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":n=yield this.handleSign(e);break;case"eth_sign":throw Ue.ethErrors.rpc.methodNotFound("Method Not Supported: eth_sign has been disabled");case"eth_sendTransaction":n=yield this.handleSendTransaction(e);break;case"wallet_sendMultiCallTransaction":n=yield this.handleSendBatchTransaction(e);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw Ue.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.method);case"eth_sendUserOperation":n=yield this.handleSendUserOperation(e);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":n=yield this.handleBundler(e);break;default:t=yield this.handleReadRequests(e)}if(t&&!t.result&&t.error){const e=t.error.message?t.error.message:"Request failed";throw Ue.ethErrors.rpc.internal(e)}return t?t.result:n}catch(e){throw Ue.ethErrors.rpc.internal(null==e?void 0:e.message)}}))}bloctoApi(e,t){var i;return r(this,void 0,void 0,(function*(){const{walletServer:r,blockchainName:o,sessionKeyEnv:s}=yield n(this,bt,"m",Et).call(this),a=(null===(i=P(s))||void 0===i?void 0:i.code)||"";if(!a)throw Ue.ethErrors.provider.unauthorized();return fetch(`${r}/api/${o}${e}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},t)).then((e=>k(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(e,t){return r(this,void 0,void 0,(function*(){const{walletServer:r}=yield n(this,bt,"m",Et).call(this);return new Promise(((n,i)=>S("message",((o,s)=>{const a=o;a.origin===r&&"ETH:FRAME:RESPONSE"===a.data.type&&("APPROVED"===a.data.status&&(s(),E(e),n(a.data[t])),"DECLINED"===a.data.status&&(s(),E(e),"incorrect_session_id"===a.data.errorCode&&this.handleDisconnect(),i(Ue.ethErrors.provider.userRejectedRequest(a.data.errorMessage)))),"ETH:FRAME:CLOSE"===a.data.type&&(s(),E(e),i(Ue.ethErrors.provider.userRejectedRequest("User declined the request")))}))))}))}setIframe(e,t){return r(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:r,blockchainName:i}=yield n(this,bt,"m",Et).call(this),o=w(`${r}/${this.appId}/${t||i}${e}`);return b(o),o}))}enable(e){var t;return r(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:r,blockchainName:i,sessionKeyEnv:o}=yield n(this,bt,"m",Et).call(this);if(null===(t=this.existedSDK)||void 0===t?void 0:t.isBlocto)return this.existedSDK.chainId!==this.chainId&&(yield this.existedSDK.request({method:"wallet_addEthereumChain",params:[{chainId:this.chainId}]}),yield this.existedSDK.request({method:"wallet_switchEthereumChain",params:[{chainId:this.chainId}]}),j(o,i,[this.existedSDK.address])),new Promise(((e,t)=>setTimeout((()=>this.existedSDK.enable().then(e).catch(t)),10)));const a=N(o,i);if(a)return new Promise((e=>{e(a)}));const c=new URLSearchParams;c.set("l6n",window.location.origin),c.set("v",m);const u=e&&x(e)?`/${e}`:"",h=yield this.setIframe(`/authn${u}?${c.toString()}`);return new Promise(((e,t)=>{S("message",((n,a)=>{var c,u;const d=n;d.origin===r&&("ETH:FRAME:RESPONSE"===d.data.type&&(a(),E(h),null===(c=this.eventListeners)||void 0===c||c.connect.forEach((e=>e({chainId:this.chainId}))),T(o,{code:d.data.code,evm:{[i]:[d.data.addr]}},d.data.exp),(null===(u=d.data)||void 0===u?void 0:u.isAccountChanged)&&postMessage({originChain:s.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),S("message",((e,t)=>{var r,n,i;const o=e,a="BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=o.data)||void 0===r?void 0:r.type),c=(null===(n=o.data)||void 0===n?void 0:n.originChain)!==s.ETHEREUM;a&&(null===(i=this.eventListeners)||void 0===i||i.accountsChanged.forEach((e=>e([d.data.addr])))),a&&c&&(this.handleDisconnect(),t())})),e([d.data.addr])),"ETH:FRAME:CLOSE"===d.data.type&&(a(),E(h),t(Ue.ethErrors.provider.userRejectedRequest())))}))}))}))}fetchAccounts(){return r(this,void 0,void 0,(function*(){n(this,bt,"m",_t).call(this);const{blockchainName:e,sessionKeyEnv:t}=yield n(this,bt,"m",Et).call(this),{accounts:r}=yield this.bloctoApi("/accounts");return j(t,e,r),r}))}handleReadRequests(e){return r(this,void 0,void 0,(function*(){return n(this,bt,"m",_t).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},e))}).then((e=>e.json())).catch((e=>{throw Ue.ethErrors.rpc.internal(e)}))}))}handleSign({method:e,params:t}){return r(this,void 0,void 0,(function*(){let r="";if(Array.isArray(t))if("personal_sign"===e)r=xe(t[0])?t[0].slice(2):(i=t[0],X.from(i,"utf8").toString("hex"));else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(e)){r=t[1];const{domain:e}=JSON.parse(r);if(xe(e.chainId))throw Ue.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must be a number`);if(Nt(e.chainId)!==Nt(this.chainId))throw Ue.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must match the active chainId "${Nt(this.chainId)}"`)}var i;n(this,bt,"m",_t).call(this);const{signatureId:o}=yield this.bloctoApi("/user-signature",{method:"POST",body:JSON.stringify({method:e,message:r})}),s=yield this.setIframe(`/user-signature/${o}`);return this.responseListener(s,"signature")}))}handleSwitchChain(e){var t,i;return r(this,void 0,void 0,(function*(){if(!e)throw Ue.ethErrors.rpc.invalidParams();const{walletServer:r,blockchainName:o,sessionKeyEnv:s,switchableNetwork:a}=yield n(this,bt,"m",Et).call(this),c=null===(t=N(s,o))||void 0===t?void 0:t[0],u=Nt(this.chainId),h=Nt(e);if(u===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,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),!c)return null===(i=this.eventListeners)||void 0===i||i.chainChanged.forEach((e=>e(this.chainId))),yield n(this,bt,"m",Et).call(this),null;if(a[h].wallet_web_url!==a[u].wallet_web_url)return this.enable().then((([e])=>{var t;return e!==c&&(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=`${u}`,this.chainId=`0x${u.toString(16)}`,this.rpc=a[u].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),n(this,bt,"m",Et).call(this),e}));const d=yield this.setIframe(`/switch-chain?to=${a[h].name}`,a[u].name);return new Promise(((e,t)=>{S("message",((i,o)=>{var l,f,p,v,g,m,y,w;const b=i;b.origin===r&&("ETH:FRAME:RESPONSE"===b.data.type&&(o(),E(d),(null===(l=b.data)||void 0===l?void 0:l.addr)&&c&&(T(s,{code:null===(f=b.data)||void 0===f?void 0:f.code,evm:{[a[h].name]:[b.data.addr]}},null===(p=b.data)||void 0===p?void 0:p.exp),b.data.addr!==c&&(null===(v=this.eventListeners)||void 0===v||v.accountsChanged.forEach((e=>e([b.data.addr]))))),null===(g=this.eventListeners)||void 0===g||g.chainChanged.forEach((e=>e(this.chainId))),n(this,bt,"m",Et).call(this),e(null)),"ETH:FRAME:CLOSE"===b.data.type&&(o(),E(d),(null===(m=b.data)||void 0===m?void 0:m.hasApprovedSwitchChain)?(null===(y=this.eventListeners)||void 0===y||y.chainChanged.forEach((e=>e(this.chainId))),D(s),null===(w=this.eventListeners)||void 0===w||w.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected()))),n(this,bt,"m",Et).call(this),e(null)):(this.networkVersion=`${u}`,this.chainId=`0x${u.toString(16)}`,this.rpc=a[u].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),n(this,bt,"m",Et).call(this),t(Ue.ethErrors.provider.userRejectedRequest()))))}))}))}))}handleSendTransaction(e){var t;return r(this,void 0,void 0,(function*(){n(this,bt,"m",_t).call(this);const{isValid:r,invalidMsg:i}=Le(null===(t=e.params)||void 0===t?void 0:t[0]);if(!r)throw Ue.ethErrors.rpc.invalidParams(i);return n(this,bt,"m",At).call(this,e.params)}))}handleSendBatchTransaction(e){return r(this,void 0,void 0,(function*(){let t,r;n(this,bt,"m",_t).call(this),Array.isArray(e.params)&&e.params.length>=2?[t,r]=e.params:(t=e.params,r=!1);const i=r||!1,{isValid:o,invalidMsg:s}=(e=>{if(!Array.isArray(e))return{isValid:!1,invalidMsg:L.INVALID_TRANSACTIONS};for(let t=0;t<e.length;t++){const{isValid:r,invalidMsg:n}=Le(e[t]);if(!r)return{isValid:r,invalidMsg:n}}return{isValid:!0}})(t);if(!o)throw Ue.ethErrors.rpc.invalidParams(s);return n(this,bt,"m",At).call(this,t,i)}))}handleSendUserOperation(e){return r(this,void 0,void 0,(function*(){n(this,bt,"m",_t).call(this);const{authorizationId:t}=yield this.bloctoApi("/user-operation",{method:"POST",body:JSON.stringify(e.params)}),r=yield this.setIframe(`/user-operation/${t}`);return this.responseListener(r,"userOpHash")}))}handleBundler(e){return r(this,void 0,void 0,(function*(){return n(this,bt,"m",_t).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},e))})}))}handleDisconnect(){var e,t;return r(this,void 0,void 0,(function*(){if(null===(e=this.existedSDK)||void 0===e?void 0:e.isBlocto)return this.existedSDK.request({method:"wallet_disconnect"});const{sessionKeyEnv:r}=yield n(this,bt,"m",Et).call(this);D(r),null===(t=this.eventListeners)||void 0===t||t.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected())))}))}loadSwitchableNetwork(e){return r(this,void 0,void 0,(function*(){if(null==e?void 0:e.length){const t=e.map((({chainId:e,rpcUrls:t})=>{if(!e)throw Ue.ethErrors.rpc.invalidParams("Empty chainId");const r=`${Nt(e)}`;if(this._blocto.switchableNetwork[r])return null;const i=(null==t?void 0:t[0])||a[r];if(!i)throw Ue.ethErrors.rpc.invalidParams("rpcUrls required");return n(this,bt,"m",St).call(this,{chainId:r,rpcUrls:[i]})}));return Promise.all(t).then((()=>null))}throw Ue.ethErrors.rpc.invalidParams("Empty networkList")}))}supportChainList(){return r(this,void 0,void 0,(function*(){const e=yield Me().catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})}));return Object.keys(e).map((t=>{const{display_name:r}=e[t];return{chainId:t,chainName:r}}))}))}on(e,t){var r;(null===(r=this.existedSDK)||void 0===r?void 0:r.isBlocto)&&this.existedSDK.on(e,t),super.on(e,t)}removeListener(e,t){var r;(null===(r=this.existedSDK)||void 0===r?void 0:r.isBlocto)&&this.existedSDK.off(e,t),super.removeListener(e,t)}}bt=new WeakSet,Et=function(){var e,t;return r(this,void 0,void 0,(function*(){if((null===(e=this._blocto)||void 0===e?void 0:e.unloadedNetwork)&&(yield this.loadSwitchableNetwork(this._blocto.unloadedNetwork),delete this._blocto.unloadedNetwork),this._blocto.sessionKeyEnv&&this._blocto.walletServer&&this._blocto.blockchainName&&this._blocto.networkType&&this._blocto.switchableNetwork)return this._blocto;const r=yield Me().catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})),{chain_id:n,name:i,network_type:o,blocto_service_environment:s,display_name:a}=null!==(t=r[this.networkVersion])&&void 0!==t?t:{};if(!n)throw Ue.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);const h=this.injectedWalletServer||c[s];return this._blocto=Object.assign(Object.assign({},this._blocto),{sessionKeyEnv:u[s],walletServer:h,blockchainName:i,networkType:o,switchableNetwork:Object.assign(Object.assign({},this._blocto.switchableNetwork),{[n]:{name:i,display_name:a,network_type:o,wallet_web_url:h,rpc_url:this.rpc}})}),this._blocto}))},St=function({chainId:e,rpcUrls:t}){var i;return r(this,void 0,void 0,(function*(){yield n(this,bt,"m",Et).call(this);const r=yield Me().catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})),{chain_id:o,name:s,display_name:a,network_type:u,blocto_service_environment:h}=null!==(i=r[e])&&void 0!==i?i:{};if(!o)throw Ue.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${e} might not be supported yet.`);const d=c[h];this._blocto.switchableNetwork[o]={name:s,display_name:a,network_type:u,wallet_web_url:d,rpc_url:t[0]}}))},_t=function(){var e;if((null===(e=this.existedSDK)||void 0===e?void 0:e.isBlocto)&&Nt(this.existedSDK.chainId)!==Nt(this.chainId))throw Ue.ethErrors.provider.chainDisconnected()},At=function(e,t=!0){return r(this,void 0,void 0,(function*(){const{authorizationId:r}=yield this.bloctoApi("/authz",{method:"POST",body:JSON.stringify([e,t])}),n=yield this.setIframe(`/authz/${r}`);return this.responseListener(n,"txHash")}))};class Dt extends y{get existedSDK(){if("undefined"!=typeof window)return window.bloctoAptos}constructor({chainId:e,server:t,appId:r}){super(),this.publicKey=[],this.authKey="",this.off=this.removeListener,i(e,"'chainId' is required"),i(r,"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=f[e],this.api=p[e],this.sessionKey=h[e];const n=d[e];this.appId=r||g,this.server=t||n||""}get publicAccount(){var e;return{address:(null===(e=C(this.sessionKey,s.APTOS))||void 0===e?void 0:e[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return r(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){var e;return r(this,void 0,void 0,(function*(){return!!(null===(e=C(this.sessionKey,s.APTOS))||void 0===e?void 0:e.length)}))}signTransaction(e){var t;return r(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signTransaction(e);if((yield this.isConnected())||(yield this.connect()),!(null===(t=C(this.sessionKey,s.APTOS))||void 0===t?void 0:t.length))throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){var e;return r(this,void 0,void 0,(function*(){var t,r;this.existedSDK?yield this.existedSDK.disconnect():(t=this.sessionKey,r=s.APTOS,T(t,{accounts:{[r]:void 0}}),null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e({code:4900,message:"Wallet disconnected"}))))}))}signAndSubmitTransaction(e,t={}){var n,i;return r(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signAndSubmitTransaction(e,t);if((yield this.isConnected())||(yield this.connect()),!(null===(n=C(this.sessionKey,s.APTOS))||void 0===n?void 0:n.length))throw new Error("Fail to get account");const r=(null===(i=P(this.sessionKey))||void 0===i?void 0:i.code)||"",{authorizationId:o}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":r},body:JSON.stringify(Object.assign(Object.assign({},e),t))}).then((e=>k(e,this.sessionKey)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const a=w(`${this.server}/${this.appId}/aptos/authz/${o}`);return b(a),new Promise(((e,t)=>S("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),E(a),e({hash:i.data.txHash})),"DECLINED"===i.data.status&&(n(),E(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}signMessage(e){var t,n;return r(this,void 0,void 0,(function*(){const r=(e=>{var t,r;const n=Object.assign({},e),{message:i,nonce:o,address:s,application:a,chainId:c}=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),c&&"boolean"!=typeof c&&(n.chainId=!!c),n})(e);if(this.existedSDK)return this.existedSDK.signMessage(r);if((yield this.isConnected())||(yield this.connect()),!(null===(t=C(this.sessionKey,s.APTOS))||void 0===t?void 0:t.length))throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const i=(null===(n=P(this.sessionKey))||void 0===n?void 0:n.code)||"",{signatureId:o}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":i},body:JSON.stringify(r)}).then((e=>k(e,this.sessionKey))),a=w(`${this.server}/${this.appId}/aptos/user-signature/${o}`);return b(a),new Promise(((e,t)=>S("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),E(a),e(i.data)),"DECLINED"===i.data.status&&(n(),E(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}connect(){return r(this,void 0,void 0,(function*(){return this.existedSDK?new Promise(((e,t)=>setTimeout((()=>this.existedSDK.connect().then(e).catch(t)),10))):new Promise(((e,t)=>{var n,i;if("undefined"==typeof window)return t("Currently only supported in browser");if(null===(n=C(this.sessionKey,s.APTOS))||void 0===n?void 0:n.length)return e({address:(null===(i=C(this.sessionKey,s.APTOS))||void 0===i?void 0:i[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const o=encodeURIComponent(window.location.origin),a=w(`${this.server}/${this.appId}/aptos/authn?l6n=${o}&v=${m}}`);b(a),S("message",((n,i)=>r(this,void 0,void 0,(function*(){var r,o,c,u;const h=n;if(h.origin===this.server){if("APTOS:FRAME:RESPONSE"===h.data.type){if(i(),E(a),T(this.sessionKey,{code:h.data.code,accounts:{[s.APTOS]:[h.data.addr]}},h.data.exp),(null===(r=h.data)||void 0===r?void 0:r.isAccountChanged)&&postMessage({originChain:s.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),S("message",((e,t)=>{var r,n;const i=e;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=i.data)||void 0===r?void 0:r.type)&&(null===(n=i.data)||void 0===n?void 0:n.originChain)!==s.APTOS&&(this.disconnect(),t())})),!(null===(o=C(this.sessionKey,s.APTOS))||void 0===o?void 0:o.length))return t();try{const{public_keys:t}=yield fetch(`${this.server}/blocto/aptos/accounts/${null===(c=C(this.sessionKey,s.APTOS))||void 0===c?void 0:c[0]}`).then((e=>e.json()));this.publicKey=t||[],e({address:(null===(u=C(this.sessionKey,s.APTOS))||void 0===u?void 0:u[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(e){return t(h)}}"APTOS:FRAME:CLOSE"===h.data.type&&(i(),E(a),t(new Error("User declined the login request")))}}))))}))}))}fetchAddress(){var e;return r(this,void 0,void 0,(function*(){const t=(null===(e=P(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((e=>k(e,this.sessionKey)));var n,i;return n=this.sessionKey,i=s.APTOS,T(n,{accounts:{[i]:r}}),(null==r?void 0:r[0])||""}))}on(e,t){this.existedSDK&&this.existedSDK.on(e,t),super.on(e,t)}removeListener(e,t){this.existedSDK&&this.existedSDK.off(e,t),super.removeListener(e,t)}}class kt{constructor({appId:e,ethereum:t,aptos:r}){t&&(this.ethereum=new jt(Object.assign(Object.assign({},t),{appId:e}))),r&&(this.aptos=new Dt(Object.assign(Object.assign({},r),{appId:e})))}}function xt({chainId:r,rpcUrl:n,rpc:i,bloctoParams:o},s){return e(this,void 0,void 0,(function*(){let e;if(!r)throw new Error("chainId is required");n?e=n:r&&i&&(e=i[r]),e||(e="null");const a=new kt({appId:null==o?void 0:o.appId,ethereum:{chainId:r,rpc:e}}).ethereum;if(!a)throw new Error("No provider");return a.on("connect",s.connect),a.on("disconnect",s.disconnect),a.on("accountsChanged",s.accountsChanged),a.on("chainChanged",s.chainChanged),yield a.request({method:"eth_requestAccounts"}),t(a)}))}export{xt as default};
1
+ import{_ as e,A as t}from"./index-5865e5b8.js";import"@ethersproject/providers";import"zustand";import"@ethersproject/bytes";import"@ethersproject/properties";import"@ethersproject/address";import"@ethersproject/abstract-signer";import"buffer";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";import"events";import"@ethersproject/constants";import"@ethersproject/transactions";function r(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function n(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 i(e,t){if(!e)throw new Error(t)}var o,s;"function"==typeof SuppressedError&&SuppressedError,function(e){e.prod="BLOCTO_SDK",e.dev="BLOCTO_SDK_DEV",e.staging="BLOCTO_SDK_STAGING"}(o||(o={})),function(e){e.ETHEREUM="ethereum",e.APTOS="aptos"}(s||(s={}));const a={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",421614:"https://arbitrum-sepolia.blockpi.network/v1/rpc/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io",11155420:"https://sepolia.optimism.io",8453:"https://mainnet.base.org",84531:"https://goerli.base.org",84532:"https://sepolia.base.org",7777777:"https://rpc.zora.energy",999:"https://testnet.rpc.zora.energy",999999999:"https://sepolia.rpc.zora.energy",534352:"https://rpc.scroll.io",534353:"https://alpha-rpc.scroll.io/l2",534351:"https://sepolia-rpc.scroll.io",59144:"https://rpc.linea.build",59140:"https://rpc.goerli.linea.build",1261120:"https://rpc.startale.com/zkatana"},c={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},u={prod:o.prod,staging:o.staging,dev:o.dev},h={1:o.prod,2:o.dev,3:o.dev,4:o.dev,5:o.staging},d={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 l;!function(e){e.Mainnet="mainnet",e.Testnet="testnet",e.Devnet="devnet",e.Testing="testing",e.Premainnet="premainnet"}(l||(l={}));const f={1:l.Mainnet,2:l.Testnet,3:l.Devnet,4:l.Testing,5:l.Premainnet},p={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"},v=["connect","disconnect","message","chainChanged","accountsChanged"],g="00000000-0000-0000-0000-000000000000",m="0.9.1";class y{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,v.forEach((e=>{this.eventListeners[e]=[]})),this.appId=g}request(e){return r(this,void 0,void 0,(function*(){}))}on(e,t){v.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 w(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 b(e){document.body.appendChild(e)}function E(e){const t=e&&e.parentNode;t&&t.removeChild instanceof Function&&t.removeChild(e)}var S=(e,t,r=window)=>{r.addEventListener(e,(function n(i){t(i,(()=>r.removeEventListener(e,n)))}))};const _="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]}},A=(()=>{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:_,O=(e,t=null)=>{const r=A.getItem(e);try{return r&&JSON.parse(r)||t}catch(e){return r||t}},R=(e,t)=>A.setItem(e,"string"==typeof t?t:JSON.stringify(t)),I=e=>{R(e,""),A.removeItem(e)},P=e=>{const t=O(e,null);return t?(new Date).getTime()>t.expiry||t.v!==m?(I(e),null):null==t?void 0:t.data:null},T=(e,t,r)=>{var n,i,o;const s=O(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:m};R(e,a)},C=(e,t)=>{var r,n,i;return(null===(r=P(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=P(e))||void 0===n?void 0:n.accounts)||void 0===i?void 0:i[t])||null:(I(e),null)},N=(e,t)=>{var r,n,i;return(null===(r=P(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=P(e))||void 0===n?void 0:n.evm)||void 0===i?void 0:i[t])||null:(I(e),null)},j=(e,t,r)=>{T(e,{evm:{[t]:r}})},D=e=>{const t=O(e);t&&(t.data.evm={},R(e,t))};function k(e,t,n){return r(this,void 0,void 0,(function*(){if(403!==e.status&&401!==e.status||(n&&n(),I(t)),!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 x=e=>/\S+@\S+\.\S+/.test(e);var L;!function(e){e.INVALID_TRANSACTION="Invalid transaction",e.INVALID_TRANSACTIONS="Invalid transactions",e.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'}(L||(L={}));var M="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},U=[],K=[],B="undefined"!=typeof Uint8Array?Uint8Array:Array,q=!1;function $(){q=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)U[t]=e[t],K[e.charCodeAt(t)]=t;K["-".charCodeAt(0)]=62,K["_".charCodeAt(0)]=63}function V(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 Y(e){var t;q||$();for(var r=e.length,n=r%3,i="",o=[],s=16383,a=0,c=r-n;a<c;a+=s)o.push(V(e,a,a+s>c?c: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 F(e,t,r,n,i){var o,s,a=8*i-n-1,c=(1<<a)-1,u=c>>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-u;else{if(o===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=u}return(f?-1:1)*s*Math.pow(2,o-n)}function z(e,t,r,n,i,o){var s,a,c,u=8*o-i-1,h=(1<<u)-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*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+d>=1?l/c:l*Math.pow(2,1-d))*c>=2&&(s++,c/=2),s+d>=h?(a=0,s=h):s+d>=1?(a=(t*c-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,u+=i;u>0;e[r+f]=255&s,f+=p,s/=256,u-=8);e[r+f-p]|=128*v}var J={}.toString,G=Array.isArray||function(e){return"[object Array]"==J.call(e)};function H(){return X.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function W(e,t){if(H()<t)throw new RangeError("Invalid typed array length");return X.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=X.prototype:(null===e&&(e=new X(t)),e.length=t),e}function X(e,t,r){if(!(X.TYPED_ARRAY_SUPPORT||this instanceof X))return new X(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 ee(this,e)}return Z(this,e,t,r)}function Z(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);X.TYPED_ARRAY_SUPPORT?(e=t).__proto__=X.prototype:e=te(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!X.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|ie(t,r);e=W(e,n);var i=e.write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(ne(t)){var r=0|re(t.length);return 0===(e=W(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?W(e,0):te(e,t);if("Buffer"===t.type&&G(t.data))return te(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function Q(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 ee(e,t){if(Q(t),e=W(e,t<0?0:0|re(t)),!X.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function te(e,t){var r=t.length<0?0:0|re(t.length);e=W(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function re(e){if(e>=H())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+H().toString(16)+" bytes");return 0|e}function ne(e){return!(null==e||!e._isBuffer)}function ie(e,t){if(ne(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 Ne(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return je(e).length;default:if(n)return Ne(e).length;t=(""+t).toLowerCase(),n=!0}}function oe(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 be(this,t,r);case"utf8":case"utf-8":return ge(this,t,r);case"ascii":return ye(this,t,r);case"latin1":case"binary":return we(this,t,r);case"base64":return ve(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ee(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function se(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function ae(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=X.from(t,n)),ne(t))return 0===t.length?-1:ce(e,t,r,n,i);if("number"==typeof t)return t&=255,X.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):ce(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ce(e,t,r,n,i){var o,s=1,a=e.length,c=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,c/=2,r/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var h=-1;for(o=r;o<a;o++)if(u(e,o)===u(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===c)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+c>a&&(r=a-c),o=r;o>=0;o--){for(var d=!0,l=0;l<c;l++)if(u(e,o+l)!==u(t,l)){d=!1;break}if(d)return o}return-1}function ue(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 he(e,t,r,n){return De(Ne(t,e.length-r),e,r,n)}function de(e,t,r,n){return De(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function le(e,t,r,n){return de(e,t,r,n)}function fe(e,t,r,n){return De(je(t),e,r,n)}function pe(e,t,r,n){return De(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 ve(e,t,r){return 0===t&&r===e.length?Y(e):Y(e.slice(t,r))}function ge(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,c,u=e[i],h=null,d=u>239?4:u>223?3:u>191?2:1;if(i+d<=r)switch(d){case 1:u<128&&(h=u);break;case 2:128==(192&(o=e[i+1]))&&(c=(31&u)<<6|63&o)>127&&(h=c);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(c=(15&u)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(h=c)}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<=me)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=me));return r}(n)}X.TYPED_ARRAY_SUPPORT=void 0===M.TYPED_ARRAY_SUPPORT||M.TYPED_ARRAY_SUPPORT,H(),X.poolSize=8192,X._augment=function(e){return e.__proto__=X.prototype,e},X.from=function(e,t,r){return Z(null,e,t,r)},X.TYPED_ARRAY_SUPPORT&&(X.prototype.__proto__=Uint8Array.prototype,X.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&X[Symbol.species]),X.alloc=function(e,t,r){return function(e,t,r,n){return Q(t),t<=0?W(e,t):void 0!==r?"string"==typeof n?W(e,t).fill(r,n):W(e,t).fill(r):W(e,t)}(null,e,t,r)},X.allocUnsafe=function(e){return ee(null,e)},X.allocUnsafeSlow=function(e){return ee(null,e)},X.isBuffer=function(e){return null!=e&&(!!e._isBuffer||ke(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&ke(e.slice(0,0))}(e))},X.compare=function(e,t){if(!ne(e)||!ne(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},X.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}},X.concat=function(e,t){if(!G(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return X.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=X.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!ne(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},X.byteLength=ie,X.prototype._isBuffer=!0,X.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)se(this,t,t+1);return this},X.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)se(this,t,t+3),se(this,t+1,t+2);return this},X.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)se(this,t,t+7),se(this,t+1,t+6),se(this,t+2,t+5),se(this,t+3,t+4);return this},X.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?ge(this,0,e):oe.apply(this,arguments)},X.prototype.equals=function(e){if(!ne(e))throw new TypeError("Argument must be a Buffer");return this===e||0===X.compare(this,e)},X.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+">"},X.prototype.compare=function(e,t,r,n,i){if(!ne(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),c=this.slice(n,i),u=e.slice(t,r),h=0;h<a;++h)if(c[h]!==u[h]){o=c[h],s=u[h];break}return o<s?-1:s<o?1:0},X.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},X.prototype.indexOf=function(e,t,r){return ae(this,e,t,r,!0)},X.prototype.lastIndexOf=function(e,t,r){return ae(this,e,t,r,!1)},X.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 ue(this,e,t,r);case"utf8":case"utf-8":return he(this,e,t,r);case"ascii":return de(this,e,t,r);case"latin1":case"binary":return le(this,e,t,r);case"base64":return fe(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return pe(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},X.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var me=4096;function ye(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 we(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 be(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+=Ce(e[o]);return i}function Ee(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 Se(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 _e(e,t,r,n,i,o){if(!ne(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 Ae(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 Oe(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 Re(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 Ie(e,t,r,n,i){return i||Re(e,0,r,4),z(e,t,r,n,23,4),r+4}function Pe(e,t,r,n,i){return i||Re(e,0,r,8),z(e,t,r,n,52,8),r+8}X.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),X.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=X.prototype;else{var i=t-e;r=new X(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},X.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||Se(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},X.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||Se(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},X.prototype.readUInt8=function(e,t){return t||Se(e,1,this.length),this[e]},X.prototype.readUInt16LE=function(e,t){return t||Se(e,2,this.length),this[e]|this[e+1]<<8},X.prototype.readUInt16BE=function(e,t){return t||Se(e,2,this.length),this[e]<<8|this[e+1]},X.prototype.readUInt32LE=function(e,t){return t||Se(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},X.prototype.readUInt32BE=function(e,t){return t||Se(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},X.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||Se(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},X.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||Se(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},X.prototype.readInt8=function(e,t){return t||Se(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},X.prototype.readInt16LE=function(e,t){t||Se(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},X.prototype.readInt16BE=function(e,t){t||Se(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},X.prototype.readInt32LE=function(e,t){return t||Se(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},X.prototype.readInt32BE=function(e,t){return t||Se(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},X.prototype.readFloatLE=function(e,t){return t||Se(e,4,this.length),F(this,e,!0,23,4)},X.prototype.readFloatBE=function(e,t){return t||Se(e,4,this.length),F(this,e,!1,23,4)},X.prototype.readDoubleLE=function(e,t){return t||Se(e,8,this.length),F(this,e,!0,52,8)},X.prototype.readDoubleBE=function(e,t){return t||Se(e,8,this.length),F(this,e,!1,52,8)},X.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||_e(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},X.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||_e(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},X.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,1,255,0),X.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},X.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,65535,0),X.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Ae(this,e,t,!0),t+2},X.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,65535,0),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Ae(this,e,t,!1),t+2},X.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,4294967295,0),X.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):Oe(this,e,t,!0),t+4},X.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,4294967295,0),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Oe(this,e,t,!1),t+4},X.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);_e(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},X.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);_e(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},X.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,1,127,-128),X.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},X.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,32767,-32768),X.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Ae(this,e,t,!0),t+2},X.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,2,32767,-32768),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Ae(this,e,t,!1),t+2},X.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,2147483647,-2147483648),X.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):Oe(this,e,t,!0),t+4},X.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||_e(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),X.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Oe(this,e,t,!1),t+4},X.prototype.writeFloatLE=function(e,t,r){return Ie(this,e,t,!0,r)},X.prototype.writeFloatBE=function(e,t,r){return Ie(this,e,t,!1,r)},X.prototype.writeDoubleLE=function(e,t,r){return Pe(this,e,t,!0,r)},X.prototype.writeDoubleBE=function(e,t,r){return Pe(this,e,t,!1,r)},X.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||!X.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},X.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&&!X.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=ne(e)?e:Ne(new X(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var Te=/[^+\/0-9A-Za-z-_]/g;function Ce(e){return e<16?"0"+e.toString(16):e.toString(16)}function Ne(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 je(e){return function(e){var t,r,n,i,o,s;q||$();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 B(3*a/4-o),n=o>0?a-4:a;var c=0;for(t=0,r=0;t<n;t+=4,r+=3)i=K[e.charCodeAt(t)]<<18|K[e.charCodeAt(t+1)]<<12|K[e.charCodeAt(t+2)]<<6|K[e.charCodeAt(t+3)],s[c++]=i>>16&255,s[c++]=i>>8&255,s[c++]=255&i;return 2===o?(i=K[e.charCodeAt(t)]<<2|K[e.charCodeAt(t+1)]>>4,s[c++]=255&i):1===o&&(i=K[e.charCodeAt(t)]<<10|K[e.charCodeAt(t+1)]<<4|K[e.charCodeAt(t+2)]>>2,s[c++]=i>>8&255,s[c++]=255&i),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Te,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function De(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 ke(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}const xe=e=>"string"==typeof e&&/^0x[0-9A-Fa-f]*$/.test(e),Le=e=>e&&"object"==typeof e&&"from"in e?e.value&&!xe(e.value)?{isValid:!1,invalidMsg:L.INVALID_TRANSACTION_VALUE}:{isValid:!0}:{isValid:!1,invalidMsg:L.INVALID_TRANSACTION};function Me(){return r(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})),{})}))}var Ue={};function Ke(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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 qe(e){var t=function(e,t){if("object"!==Be(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==Be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===Be(t)?t:String(t)}function $e(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,qe(n.key),n)}}function Ve(e,t,r){return t&&$e(e.prototype,t),r&&$e(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ye(e,t){return Ye=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ye(e,t)}function Fe(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 ze(e,t){if(t&&("object"===Be(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 Je(e){return Je=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Je(e)}function Ge(e,t,r){return Ge=function(){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}}()?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},Ge.apply(null,arguments)}function He(e){var t="function"==typeof Map?new Map:void 0;return He=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 Ge(e,arguments,Je(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ye(n,e)},He(e)}var We={},Xe=nt;nt.default=nt,nt.stable=at,nt.stableStringify=at;var Ze="[...]",Qe="[Circular]",et=[],tt=[];function rt(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function nt(e,t,r,n){var i;void 0===n&&(n=rt()),ot(e,"",0,[],void 0,0,n);try{i=0===tt.length?JSON.stringify(e,t,r):JSON.stringify(e,ut(t),r)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==et.length;){var o=et.pop();4===o.length?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function it(e,t,r,n){var i=Object.getOwnPropertyDescriptor(n,r);void 0!==i.get?i.configurable?(Object.defineProperty(n,r,{value:e}),et.push([n,r,t,i])):tt.push([t,r,e]):(n[r]=e,et.push([n,r,t]))}function ot(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 it(Qe,e,t,i);if(void 0!==s.depthLimit&&o>s.depthLimit)return void it(Ze,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void it(Ze,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)ot(e[a],a,a,n,e,o,s);else{var c=Object.keys(e);for(a=0;a<c.length;a++){var u=c[a];ot(e[u],u,a,n,e,o,s)}}n.pop()}}function st(e,t){return e<t?-1:e>t?1:0}function at(e,t,r,n){void 0===n&&(n=rt());var i,o=ct(e,"",0,[],void 0,0,n)||e;try{i=0===tt.length?JSON.stringify(o,t,r):JSON.stringify(o,ut(t),r)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==et.length;){var s=et.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 it(Qe,e,t,i);try{if("function"==typeof e.toJSON)return}catch(e){return}if(void 0!==s.depthLimit&&o>s.depthLimit)return void it(Ze,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void it(Ze,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 c={},u=Object.keys(e).sort(st);for(a=0;a<u.length;a++){var h=u[a];ct(e[h],h,a,n,e,o,s),c[h]=e[h]}if(void 0===i)return c;et.push([i,t,e]),i[t]=c}n.pop()}}function ut(e){return e=void 0!==e?e:function(e,t){return t},function(t,r){if(tt.length>0)for(var n=0;n<tt.length;n++){var i=tt[n];if(i[1]===t&&i[0]===r){r=i[2],tt.splice(n,1);break}}return e.call(this,t,r)}}function ht(e){var t=function(){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}}();return function(){var r,n=Je(e);if(t){var i=Je(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return ze(this,r)}}Object.defineProperty(We,"__esModule",{value:!0}),We.EthereumProviderError=We.EthereumRpcError=void 0;var dt=Xe,lt=function(e){Fe(r,He(Error));var t=ht(r);function r(e,n,i){var o;if(Ke(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 Ve(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}();We.EthereumRpcError=lt;var ft=function(e){Fe(r,lt);var t=ht(r);function r(e,n,i){if(Ke(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 Ve(r)}();function pt(e,t){if("[Circular]"!==t)return t}We.EthereumProviderError=ft;var vt={},gt={};function mt(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}function yt(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=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return mt(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?mt(e,t):void 0}}(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.")}()}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=We,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(c(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]||!!c(e)}function c(e){return e>=-32099&&e<=-32e3}function u(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]:{},c=i.fallbackError,d=void 0===c?o:c,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:u(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:u(e)}}var m=null===(n=e)||void 0===n?void 0:n.stack;return f&&e&&m&&"string"==typeof m&&(p.stack=m),p}}(vt);var wt={};Object.defineProperty(wt,"__esModule",{value:!0}),wt.ethErrors=void 0;var bt,Et,St,_t,At,Ot=We,Rt=vt,It=gt;function Pt(e,t){var r=yt(Ct(t),2),n=r[0],i=r[1];return new Ot.EthereumRpcError(e,n||Rt.getMessageFromCode(e),i)}function Tt(e,t){var r=yt(Ct(t),2),n=r[0],i=r[1];return new Ot.EthereumProviderError(e,n||Rt.getMessageFromCode(e),i)}function Ct(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 Nt(e){return e?"number"==typeof e?e:e.startsWith("0x")?parseInt(e,16):parseInt(e,10):1}wt.ethErrors={rpc:{parse:function(e){return Pt(It.errorCodes.rpc.parse,e)},invalidRequest:function(e){return Pt(It.errorCodes.rpc.invalidRequest,e)},invalidParams:function(e){return Pt(It.errorCodes.rpc.invalidParams,e)},methodNotFound:function(e){return Pt(It.errorCodes.rpc.methodNotFound,e)},internal:function(e){return Pt(It.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 Pt(t,e)},invalidInput:function(e){return Pt(It.errorCodes.rpc.invalidInput,e)},resourceNotFound:function(e){return Pt(It.errorCodes.rpc.resourceNotFound,e)},resourceUnavailable:function(e){return Pt(It.errorCodes.rpc.resourceUnavailable,e)},transactionRejected:function(e){return Pt(It.errorCodes.rpc.transactionRejected,e)},methodNotSupported:function(e){return Pt(It.errorCodes.rpc.methodNotSupported,e)},limitExceeded:function(e){return Pt(It.errorCodes.rpc.limitExceeded,e)}},provider:{userRejectedRequest:function(e){return Tt(It.errorCodes.provider.userRejectedRequest,e)},unauthorized:function(e){return Tt(It.errorCodes.provider.unauthorized,e)},unsupportedMethod:function(e){return Tt(It.errorCodes.provider.unsupportedMethod,e)},disconnected:function(e){return Tt(It.errorCodes.provider.disconnected,e)},chainDisconnected:function(e){return Tt(It.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 Ot.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=We;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=wt;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 jt extends y{get existedSDK(){if("undefined"!=typeof window)return window.ethereum}constructor(e){var t;if(super(),bt.add(this),this.networkVersion="1",this.off=this.removeListener,this.injectedWalletServer=e.walletServer,this._blocto={sessionKeyEnv:o.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",switchableNetwork:{}},this.appId=e.appId||g,"chainId"in e){const{chainId:t,rpc:r}=e;i(t,"'chainId' is required"),this.networkVersion=`${Nt(t)}`,this.chainId=`0x${Nt(t).toString(16)}`,this.rpc=r||a[this.networkVersion],i(this.rpc,"'rpc' is required")}else{const{defaultChainId:r,switchableChains:n}=e;i(r,"'defaultChainId' is required"),this.networkVersion=`${Nt(r)}`,this.chainId=`0x${Nt(r).toString(16)}`;const o=n.find((e=>Nt(e.chainId)===Nt(r)));if(!o)throw Ue.ethErrors.provider.custom({code:1001,message:`Chain ${r} is not in switchableChains list`});this.rpc=(null===(t=o.rpcUrls)||void 0===t?void 0:t[0])||a[this.networkVersion],i(this.rpc,"'rpc' is required"),this._blocto.unloadedNetwork=n}}send(e,t){return r(this,void 0,void 0,(function*(){switch(!0){case t instanceof Function:return this.sendAsync(e,t);case"string"==typeof e&&Array.isArray(t):return this.sendAsync({jsonrpc:"2.0",method:e,params:t});default:return this.sendAsync(e)}}))}sendAsync(e,t){return r(this,void 0,void 0,(function*(){const r=e=>e.reduce(((e,t)=>{var r;return"eth_sendTransaction"===t.method?e.sendRequests.push(null===(r=t.params)||void 0===r?void 0:r[0]):e.otherRequests.push(this.request(t)),e}),{sendRequests:[],otherRequests:[]});function n(e,t){const r=[];let n=1;return e.forEach((e=>{const i=function(e){return{id:String(e.id),jsonrpc:"2.0",method:e.method}}(e);"eth_sendTransaction"===e.method?(i.result=t[0].value,i.error="fulfilled"!==t[0].status?t[0].reason:void 0):n<t.length&&(i.result=t[n].value,i.error="fulfilled"!==t[n].status?t[n].reason:void 0,n++),r.push(i)})),r}const i=new Promise((t=>{if(Array.isArray(e)){const{sendRequests:i,otherRequests:o}=r(e),s={method:"wallet_sendMultiCallTransaction",params:[i,!1]},a=0===i.length,c=Math.floor(1e4*Math.random()),u=a?[...o]:[this.request(s),...o];Promise.allSettled(u).then((r=>{if(a)return t(r.map(((t,r)=>{var n;return{id:String((null===(n=e[r])||void 0===n?void 0:n.id)||c+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}})));const i=n(e,r);return t(i)})).catch((e=>{throw Ue.ethErrors.rpc.internal(null==e?void 0:e.message)}))}else this.request(Object.assign(Object.assign({},e),{id:Number(e.id)})).then(t)}));if("function"!=typeof t)return i;i.then((e=>t(null,e))).catch((e=>t(e)))}))}sendUserOperation(e){return r(this,void 0,void 0,(function*(){return this.request({method:"eth_sendUserOperation",params:[e]})}))}request(e){var t,i,o,s,a,c,u,h;return r(this,void 0,void 0,(function*(){if(Array.isArray(e))return this.sendAsync(e);if(!(null==e?void 0:e.method))throw Ue.ethErrors.rpc.invalidRequest();const{blockchainName:r,switchableNetwork:d,sessionKeyEnv:l}=yield n(this,bt,"m",Et).call(this);if(null===(t=this.existedSDK)||void 0===t?void 0:t.isBlocto){if("wallet_switchEthereumChain"===e.method){if(!(null===(o=null===(i=null==e?void 0:e.params)||void 0===i?void 0:i[0])||void 0===o?void 0:o.chainId))throw Ue.ethErrors.rpc.invalidParams();return this.existedSDK.request(e).then((()=>{var t,r,n;return this.networkVersion=`${Nt(null===(t=null==e?void 0:e.params)||void 0===t?void 0:t[0].chainId)}`,this.chainId=`0x${Nt(null===(r=null==e?void 0:e.params)||void 0===r?void 0:r[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 this.existedSDK.request(e)}switch(e.method){case"eth_chainId":return this.chainId;case"net_version":return this.networkVersion;case"wallet_addEthereumChain":return this.loadSwitchableNetwork((null==e?void 0:e.params)||[]);case"eth_blockNumber":case"web3_clientVersion":case"eth_call":{const t=yield this.handleReadRequests(e);if(!t||t&&!t.result&&t.error){const e=(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.message)?t.error.message:"Request failed";throw Ue.ethErrors.rpc.internal(e)}return"function"==typeof(null==e?void 0:e.callback)&&e.callback(null,t.result),t.result}case"wallet_switchEthereumChain":return this.handleSwitchChain(null===(c=null===(a=null==e?void 0:e.params)||void 0===a?void 0:a[0])||void 0===c?void 0:c.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return N(l,r)||[]}if(!N(l,r)){const t=null===(u=null==e?void 0:e.params)||void 0===u?void 0:u[0];"eth_requestAccounts"===e.method&&x(t)?yield this.enable(t):yield this.enable()}try{let t=null,n=null;switch(e.method){case"eth_requestAccounts":n=yield this.fetchAccounts();break;case"eth_coinbase":n=null===(h=N(l,r))||void 0===h?void 0:h[0];break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":n=yield this.handleSign(e);break;case"eth_sign":throw Ue.ethErrors.rpc.methodNotFound("Method Not Supported: eth_sign has been disabled");case"eth_sendTransaction":n=yield this.handleSendTransaction(e);break;case"wallet_sendMultiCallTransaction":n=yield this.handleSendBatchTransaction(e);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw Ue.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.method);case"eth_sendUserOperation":n=yield this.handleSendUserOperation(e);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":n=yield this.handleBundler(e);break;default:t=yield this.handleReadRequests(e)}if(t&&!t.result&&t.error){const e=t.error.message?t.error.message:"Request failed";throw Ue.ethErrors.rpc.internal(e)}return t?t.result:n}catch(e){throw Ue.ethErrors.rpc.internal(null==e?void 0:e.message)}}))}bloctoApi(e,t){var i;return r(this,void 0,void 0,(function*(){const{walletServer:r,blockchainName:o,sessionKeyEnv:s}=yield n(this,bt,"m",Et).call(this),a=(null===(i=P(s))||void 0===i?void 0:i.code)||"";if(!a)throw Ue.ethErrors.provider.unauthorized();return fetch(`${r}/api/${o}${e}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},t)).then((e=>k(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(e,t){return r(this,void 0,void 0,(function*(){const{walletServer:r}=yield n(this,bt,"m",Et).call(this);return new Promise(((n,i)=>S("message",((o,s)=>{const a=o;a.origin===r&&"ETH:FRAME:RESPONSE"===a.data.type&&("APPROVED"===a.data.status&&(s(),E(e),n(a.data[t])),"DECLINED"===a.data.status&&(s(),E(e),"incorrect_session_id"===a.data.errorCode&&this.handleDisconnect(),i(Ue.ethErrors.provider.userRejectedRequest(a.data.errorMessage)))),"ETH:FRAME:CLOSE"===a.data.type&&(s(),E(e),i(Ue.ethErrors.provider.userRejectedRequest("User declined the request")))}))))}))}setIframe(e,t){return r(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:r,blockchainName:i}=yield n(this,bt,"m",Et).call(this),o=w(`${r}/${this.appId}/${t||i}${e}`);return b(o),o}))}enable(e){var t;return r(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:r,blockchainName:i,sessionKeyEnv:o}=yield n(this,bt,"m",Et).call(this);if(null===(t=this.existedSDK)||void 0===t?void 0:t.isBlocto)return this.existedSDK.chainId!==this.chainId&&(yield this.existedSDK.request({method:"wallet_addEthereumChain",params:[{chainId:this.chainId}]}),yield this.existedSDK.request({method:"wallet_switchEthereumChain",params:[{chainId:this.chainId}]}),j(o,i,[this.existedSDK.address])),new Promise(((e,t)=>setTimeout((()=>this.existedSDK.enable().then(e).catch(t)),10)));const a=N(o,i);if(a)return new Promise((e=>{e(a)}));const c=new URLSearchParams;c.set("l6n",window.location.origin),c.set("v",m);const u=e&&x(e)?`/${e}`:"",h=yield this.setIframe(`/authn${u}?${c.toString()}`);return new Promise(((e,t)=>{S("message",((n,a)=>{var c,u;const d=n;d.origin===r&&("ETH:FRAME:RESPONSE"===d.data.type&&(a(),E(h),null===(c=this.eventListeners)||void 0===c||c.connect.forEach((e=>e({chainId:this.chainId}))),T(o,{code:d.data.code,evm:{[i]:[d.data.addr]}},d.data.exp),(null===(u=d.data)||void 0===u?void 0:u.isAccountChanged)&&postMessage({originChain:s.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),S("message",((e,t)=>{var r,n,i;const o=e,a="BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=o.data)||void 0===r?void 0:r.type),c=(null===(n=o.data)||void 0===n?void 0:n.originChain)!==s.ETHEREUM;a&&(null===(i=this.eventListeners)||void 0===i||i.accountsChanged.forEach((e=>e([d.data.addr])))),a&&c&&(this.handleDisconnect(),t())})),e([d.data.addr])),"ETH:FRAME:CLOSE"===d.data.type&&(a(),E(h),t(Ue.ethErrors.provider.userRejectedRequest())))}))}))}))}fetchAccounts(){return r(this,void 0,void 0,(function*(){n(this,bt,"m",_t).call(this);const{blockchainName:e,sessionKeyEnv:t}=yield n(this,bt,"m",Et).call(this),{accounts:r}=yield this.bloctoApi("/accounts");return j(t,e,r),r}))}handleReadRequests(e){return r(this,void 0,void 0,(function*(){return n(this,bt,"m",_t).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},e))}).then((e=>e.json())).catch((e=>{throw Ue.ethErrors.rpc.internal(e)}))}))}handleSign({method:e,params:t}){return r(this,void 0,void 0,(function*(){let r="";if(Array.isArray(t))if("personal_sign"===e)r=xe(t[0])?t[0].slice(2):(i=t[0],X.from(i,"utf8").toString("hex"));else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(e)){r=t[1];const{domain:e}=JSON.parse(r);if(xe(e.chainId))throw Ue.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must be a number`);if(Nt(e.chainId)!==Nt(this.chainId))throw Ue.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must match the active chainId "${Nt(this.chainId)}"`)}var i;n(this,bt,"m",_t).call(this);const{signatureId:o}=yield this.bloctoApi("/user-signature",{method:"POST",body:JSON.stringify({method:e,message:r})}),s=yield this.setIframe(`/user-signature/${o}`);return this.responseListener(s,"signature")}))}handleSwitchChain(e){var t,i;return r(this,void 0,void 0,(function*(){if(!e)throw Ue.ethErrors.rpc.invalidParams();const{walletServer:r,blockchainName:o,sessionKeyEnv:s,switchableNetwork:a}=yield n(this,bt,"m",Et).call(this),c=null===(t=N(s,o))||void 0===t?void 0:t[0],u=Nt(this.chainId),h=Nt(e);if(u===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,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),!c)return null===(i=this.eventListeners)||void 0===i||i.chainChanged.forEach((e=>e(this.chainId))),yield n(this,bt,"m",Et).call(this),null;if(a[h].wallet_web_url!==a[u].wallet_web_url)return this.enable().then((([e])=>{var t;return e!==c&&(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=`${u}`,this.chainId=`0x${u.toString(16)}`,this.rpc=a[u].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),n(this,bt,"m",Et).call(this),e}));const d=yield this.setIframe(`/switch-chain?to=${a[h].name}`,a[u].name);return new Promise(((e,t)=>{S("message",((i,o)=>{var l,f,p,v,g,m,y,w;const b=i;b.origin===r&&("ETH:FRAME:RESPONSE"===b.data.type&&(o(),E(d),(null===(l=b.data)||void 0===l?void 0:l.addr)&&c&&(T(s,{code:null===(f=b.data)||void 0===f?void 0:f.code,evm:{[a[h].name]:[b.data.addr]}},null===(p=b.data)||void 0===p?void 0:p.exp),b.data.addr!==c&&(null===(v=this.eventListeners)||void 0===v||v.accountsChanged.forEach((e=>e([b.data.addr]))))),null===(g=this.eventListeners)||void 0===g||g.chainChanged.forEach((e=>e(this.chainId))),n(this,bt,"m",Et).call(this),e(null)),"ETH:FRAME:CLOSE"===b.data.type&&(o(),E(d),(null===(m=b.data)||void 0===m?void 0:m.hasApprovedSwitchChain)?(null===(y=this.eventListeners)||void 0===y||y.chainChanged.forEach((e=>e(this.chainId))),D(s),null===(w=this.eventListeners)||void 0===w||w.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected()))),n(this,bt,"m",Et).call(this),e(null)):(this.networkVersion=`${u}`,this.chainId=`0x${u.toString(16)}`,this.rpc=a[u].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),n(this,bt,"m",Et).call(this),t(Ue.ethErrors.provider.userRejectedRequest()))))}))}))}))}handleSendTransaction(e){var t;return r(this,void 0,void 0,(function*(){n(this,bt,"m",_t).call(this);const{isValid:r,invalidMsg:i}=Le(null===(t=e.params)||void 0===t?void 0:t[0]);if(!r)throw Ue.ethErrors.rpc.invalidParams(i);return n(this,bt,"m",At).call(this,e.params)}))}handleSendBatchTransaction(e){return r(this,void 0,void 0,(function*(){let t,r;n(this,bt,"m",_t).call(this),Array.isArray(e.params)&&e.params.length>=2?[t,r]=e.params:(t=e.params,r=!1);const i=r||!1,{isValid:o,invalidMsg:s}=(e=>{if(!Array.isArray(e))return{isValid:!1,invalidMsg:L.INVALID_TRANSACTIONS};for(let t=0;t<e.length;t++){const{isValid:r,invalidMsg:n}=Le(e[t]);if(!r)return{isValid:r,invalidMsg:n}}return{isValid:!0}})(t);if(!o)throw Ue.ethErrors.rpc.invalidParams(s);return n(this,bt,"m",At).call(this,t,i)}))}handleSendUserOperation(e){return r(this,void 0,void 0,(function*(){n(this,bt,"m",_t).call(this);const{authorizationId:t}=yield this.bloctoApi("/user-operation",{method:"POST",body:JSON.stringify(e.params)}),r=yield this.setIframe(`/user-operation/${t}`);return this.responseListener(r,"userOpHash")}))}handleBundler(e){return r(this,void 0,void 0,(function*(){return n(this,bt,"m",_t).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},e))})}))}handleDisconnect(){var e,t;return r(this,void 0,void 0,(function*(){if(null===(e=this.existedSDK)||void 0===e?void 0:e.isBlocto)return this.existedSDK.request({method:"wallet_disconnect"});const{sessionKeyEnv:r}=yield n(this,bt,"m",Et).call(this);D(r),null===(t=this.eventListeners)||void 0===t||t.disconnect.forEach((e=>e(Ue.ethErrors.provider.disconnected())))}))}loadSwitchableNetwork(e){return r(this,void 0,void 0,(function*(){if(null==e?void 0:e.length){const t=e.map((({chainId:e,rpcUrls:t})=>{if(!e)throw Ue.ethErrors.rpc.invalidParams("Empty chainId");const r=`${Nt(e)}`;if(this._blocto.switchableNetwork[r])return null;const i=(null==t?void 0:t[0])||a[r];if(!i)throw Ue.ethErrors.rpc.invalidParams("rpcUrls required");return n(this,bt,"m",St).call(this,{chainId:r,rpcUrls:[i]})}));return Promise.all(t).then((()=>null))}throw Ue.ethErrors.rpc.invalidParams("Empty networkList")}))}supportChainList(){return r(this,void 0,void 0,(function*(){const e=yield Me().catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})}));return Object.keys(e).map((t=>{const{display_name:r}=e[t];return{chainId:t,chainName:r}}))}))}on(e,t){var r;(null===(r=this.existedSDK)||void 0===r?void 0:r.isBlocto)&&this.existedSDK.on(e,t),super.on(e,t)}removeListener(e,t){var r;(null===(r=this.existedSDK)||void 0===r?void 0:r.isBlocto)&&this.existedSDK.off(e,t),super.removeListener(e,t)}}bt=new WeakSet,Et=function(){var e,t;return r(this,void 0,void 0,(function*(){if((null===(e=this._blocto)||void 0===e?void 0:e.unloadedNetwork)&&(yield this.loadSwitchableNetwork(this._blocto.unloadedNetwork),delete this._blocto.unloadedNetwork),this._blocto.sessionKeyEnv&&this._blocto.walletServer&&this._blocto.blockchainName&&this._blocto.networkType&&this._blocto.switchableNetwork)return this._blocto;const r=yield Me().catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})),{chain_id:n,name:i,network_type:o,blocto_service_environment:s,display_name:a}=null!==(t=r[this.networkVersion])&&void 0!==t?t:{};if(!n)throw Ue.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);const h=this.injectedWalletServer||c[s];return this._blocto=Object.assign(Object.assign({},this._blocto),{sessionKeyEnv:u[s],walletServer:h,blockchainName:i,networkType:o,switchableNetwork:Object.assign(Object.assign({},this._blocto.switchableNetwork),{[n]:{name:i,display_name:a,network_type:o,wallet_web_url:h,rpc_url:this.rpc}})}),this._blocto}))},St=function({chainId:e,rpcUrls:t}){var i;return r(this,void 0,void 0,(function*(){yield n(this,bt,"m",Et).call(this);const r=yield Me().catch((e=>{throw Ue.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})),{chain_id:o,name:s,display_name:a,network_type:u,blocto_service_environment:h}=null!==(i=r[e])&&void 0!==i?i:{};if(!o)throw Ue.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${e} might not be supported yet.`);const d=c[h];this._blocto.switchableNetwork[o]={name:s,display_name:a,network_type:u,wallet_web_url:d,rpc_url:t[0]}}))},_t=function(){var e;if((null===(e=this.existedSDK)||void 0===e?void 0:e.isBlocto)&&Nt(this.existedSDK.chainId)!==Nt(this.chainId))throw Ue.ethErrors.provider.chainDisconnected()},At=function(e,t=!0){return r(this,void 0,void 0,(function*(){const{authorizationId:r}=yield this.bloctoApi("/authz",{method:"POST",body:JSON.stringify([e,t])}),n=yield this.setIframe(`/authz/${r}`);return this.responseListener(n,"txHash")}))};class Dt extends y{get existedSDK(){if("undefined"!=typeof window)return window.bloctoAptos}constructor({chainId:e,server:t,appId:r}){super(),this.publicKey=[],this.authKey="",this.off=this.removeListener,i(e,"'chainId' is required"),i(r,"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=f[e],this.api=p[e],this.sessionKey=h[e];const n=d[e];this.appId=r||g,this.server=t||n||""}get publicAccount(){var e;return{address:(null===(e=C(this.sessionKey,s.APTOS))||void 0===e?void 0:e[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return r(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){var e;return r(this,void 0,void 0,(function*(){return!!(null===(e=C(this.sessionKey,s.APTOS))||void 0===e?void 0:e.length)}))}signTransaction(e){var t;return r(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signTransaction(e);if((yield this.isConnected())||(yield this.connect()),!(null===(t=C(this.sessionKey,s.APTOS))||void 0===t?void 0:t.length))throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){var e;return r(this,void 0,void 0,(function*(){var t,r;this.existedSDK?yield this.existedSDK.disconnect():(t=this.sessionKey,r=s.APTOS,T(t,{accounts:{[r]:void 0}}),null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e({code:4900,message:"Wallet disconnected"}))))}))}signAndSubmitTransaction(e,t={}){var n,i;return r(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signAndSubmitTransaction(e,t);if((yield this.isConnected())||(yield this.connect()),!(null===(n=C(this.sessionKey,s.APTOS))||void 0===n?void 0:n.length))throw new Error("Fail to get account");const r=(null===(i=P(this.sessionKey))||void 0===i?void 0:i.code)||"",{authorizationId:o}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":r},body:JSON.stringify(Object.assign(Object.assign({},e),t))}).then((e=>k(e,this.sessionKey)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const a=w(`${this.server}/${this.appId}/aptos/authz/${o}`);return b(a),new Promise(((e,t)=>S("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),E(a),e({hash:i.data.txHash})),"DECLINED"===i.data.status&&(n(),E(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}signMessage(e){var t,n;return r(this,void 0,void 0,(function*(){const r=(e=>{var t,r;const n=Object.assign({},e),{message:i,nonce:o,address:s,application:a,chainId:c}=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),c&&"boolean"!=typeof c&&(n.chainId=!!c),n})(e);if(this.existedSDK)return this.existedSDK.signMessage(r);if((yield this.isConnected())||(yield this.connect()),!(null===(t=C(this.sessionKey,s.APTOS))||void 0===t?void 0:t.length))throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const i=(null===(n=P(this.sessionKey))||void 0===n?void 0:n.code)||"",{signatureId:o}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":i},body:JSON.stringify(r)}).then((e=>k(e,this.sessionKey))),a=w(`${this.server}/${this.appId}/aptos/user-signature/${o}`);return b(a),new Promise(((e,t)=>S("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),E(a),e(i.data)),"DECLINED"===i.data.status&&(n(),E(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}connect(){return r(this,void 0,void 0,(function*(){return this.existedSDK?new Promise(((e,t)=>setTimeout((()=>this.existedSDK.connect().then(e).catch(t)),10))):new Promise(((e,t)=>{var n,i;if("undefined"==typeof window)return t("Currently only supported in browser");if(null===(n=C(this.sessionKey,s.APTOS))||void 0===n?void 0:n.length)return e({address:(null===(i=C(this.sessionKey,s.APTOS))||void 0===i?void 0:i[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const o=encodeURIComponent(window.location.origin),a=w(`${this.server}/${this.appId}/aptos/authn?l6n=${o}&v=${m}}`);b(a),S("message",((n,i)=>r(this,void 0,void 0,(function*(){var r,o,c,u;const h=n;if(h.origin===this.server){if("APTOS:FRAME:RESPONSE"===h.data.type){if(i(),E(a),T(this.sessionKey,{code:h.data.code,accounts:{[s.APTOS]:[h.data.addr]}},h.data.exp),(null===(r=h.data)||void 0===r?void 0:r.isAccountChanged)&&postMessage({originChain:s.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),S("message",((e,t)=>{var r,n;const i=e;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(r=i.data)||void 0===r?void 0:r.type)&&(null===(n=i.data)||void 0===n?void 0:n.originChain)!==s.APTOS&&(this.disconnect(),t())})),!(null===(o=C(this.sessionKey,s.APTOS))||void 0===o?void 0:o.length))return t();try{const{public_keys:t}=yield fetch(`${this.server}/blocto/aptos/accounts/${null===(c=C(this.sessionKey,s.APTOS))||void 0===c?void 0:c[0]}`).then((e=>e.json()));this.publicKey=t||[],e({address:(null===(u=C(this.sessionKey,s.APTOS))||void 0===u?void 0:u[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(e){return t(h)}}"APTOS:FRAME:CLOSE"===h.data.type&&(i(),E(a),t(new Error("User declined the login request")))}}))))}))}))}fetchAddress(){var e;return r(this,void 0,void 0,(function*(){const t=(null===(e=P(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((e=>k(e,this.sessionKey)));var n,i;return n=this.sessionKey,i=s.APTOS,T(n,{accounts:{[i]:r}}),(null==r?void 0:r[0])||""}))}on(e,t){this.existedSDK&&this.existedSDK.on(e,t),super.on(e,t)}removeListener(e,t){this.existedSDK&&this.existedSDK.off(e,t),super.removeListener(e,t)}}class kt{constructor({appId:e,ethereum:t,aptos:r}){t&&(this.ethereum=new jt(Object.assign(Object.assign({},t),{appId:e}))),r&&(this.aptos=new Dt(Object.assign(Object.assign({},r),{appId:e})))}}function xt({chainId:r,rpcUrl:n,rpc:i,bloctoParams:o},s){return e(this,void 0,void 0,(function*(){let e;if(!r)throw new Error("chainId is required");n?e=n:r&&i&&(e=i[r]),e||(e="null");const a=new kt({appId:null==o?void 0:o.appId,ethereum:{chainId:r,rpc:e}}).ethereum;if(!a)throw new Error("No provider");return a.on("connect",s.connect),a.on("disconnect",s.disconnect),a.on("accountsChanged",s.accountsChanged),a.on("chainChanged",s.chainChanged),yield a.request({method:"eth_requestAccounts"}),t(a)}))}export{xt as default};
@@ -1 +1 @@
1
- import{a$ as e,b0 as t,b1 as a,b2 as r,b3 as s,b4 as o,b5 as n,b6 as c,b7 as i,b8 as d,b9 as l}from"./index-98d378b6.js";import"@ethersproject/providers";import"zustand";import"@ethersproject/bytes";import"@ethersproject/properties";import"@ethersproject/address";import"@ethersproject/abstract-signer";import"buffer";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";import"events";import"@ethersproject/constants";import"@ethersproject/transactions";class u extends e{constructor({callbackSelector:e,cause:a,data:r,extraData:s,sender:o,urls:n}){super(a.shortMessage||"An error occurred while fetching for an offchain result.",{cause:a,metaMessages:[...a.metaMessages||[],a.metaMessages?.length?"":[],"Offchain Gateway Call:",n&&[" Gateway URL(s):",...n.map((e=>` ${t(e)}`))],` Sender: ${o}`,` Data: ${r}`,` Callback selector: ${e}`,` Extra data: ${s}`].flat()}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupError"})}}class p extends e{constructor({result:e,url:r}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${t(r)}`,`Response: ${a(e)}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupResponseMalformedError"})}}class b extends e{constructor({sender:e,to:t}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${t}`,`OffchainLookup sender address: ${e}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupSenderMismatchError"})}}const f="0x556f1830",m={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function h(e,{blockNumber:t,blockTag:a,data:d,to:l}){const{args:p}=o({data:d,abi:[m]}),[f,h,w,g,j]=p;try{if(!function(e,t){if(!r(e,{strict:!1}))throw new s({address:e});if(!r(t,{strict:!1}))throw new s({address:t});return e.toLowerCase()===t.toLowerCase()}(l,f))throw new b({sender:f,to:l});const o=await y({data:w,sender:f,urls:h}),{data:d}=await n(e,{blockNumber:t,blockTag:a,data:c([g,i([{type:"bytes"},{type:"bytes"}],[o,j])]),to:l});return d}catch(e){throw new u({callbackSelector:g,cause:e,data:d,extraData:j,sender:f,urls:h})}}async function y({data:e,sender:t,urls:r}){let s=new Error("An unknown error occurred.");for(let o=0;o<r.length;o++){const n=r[o],c=n.includes("{data}")?"GET":"POST",i="POST"===c?{data:e,sender:t}:void 0;try{const r=await fetch(n.replace("{sender}",t).replace("{data}",e),{body:JSON.stringify(i),method:c});let o;if(o=r.headers.get("Content-Type")?.startsWith("application/json")?(await r.json()).data:await r.text(),!r.ok){s=new d({body:i,details:o?.error?a(o.error):r.statusText,headers:r.headers,status:r.status,url:n});continue}if(!l(o)){s=new p({result:o,url:n});continue}return o}catch(e){s=new d({body:i,details:e.message,url:n})}}throw s}export{y as ccipFetch,h as offchainLookup,m as offchainLookupAbiItem,f as offchainLookupSignature};
1
+ import{a$ as e,b0 as t,b1 as a,b2 as r,b3 as s,b4 as o,b5 as n,b6 as c,b7 as i,b8 as d,b9 as l}from"./index-5865e5b8.js";import"@ethersproject/providers";import"zustand";import"@ethersproject/bytes";import"@ethersproject/properties";import"@ethersproject/address";import"@ethersproject/abstract-signer";import"buffer";import"@ethersproject/abstract-provider";import"@ethersproject/contracts";import"events";import"@ethersproject/constants";import"@ethersproject/transactions";class u extends e{constructor({callbackSelector:e,cause:a,data:r,extraData:s,sender:o,urls:n}){super(a.shortMessage||"An error occurred while fetching for an offchain result.",{cause:a,metaMessages:[...a.metaMessages||[],a.metaMessages?.length?"":[],"Offchain Gateway Call:",n&&[" Gateway URL(s):",...n.map((e=>` ${t(e)}`))],` Sender: ${o}`,` Data: ${r}`,` Callback selector: ${e}`,` Extra data: ${s}`].flat()}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupError"})}}class p extends e{constructor({result:e,url:r}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${t(r)}`,`Response: ${a(e)}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupResponseMalformedError"})}}class b extends e{constructor({sender:e,to:t}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${t}`,`OffchainLookup sender address: ${e}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupSenderMismatchError"})}}const f="0x556f1830",m={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function h(e,{blockNumber:t,blockTag:a,data:d,to:l}){const{args:p}=o({data:d,abi:[m]}),[f,h,w,g,j]=p;try{if(!function(e,t){if(!r(e,{strict:!1}))throw new s({address:e});if(!r(t,{strict:!1}))throw new s({address:t});return e.toLowerCase()===t.toLowerCase()}(l,f))throw new b({sender:f,to:l});const o=await y({data:w,sender:f,urls:h}),{data:d}=await n(e,{blockNumber:t,blockTag:a,data:c([g,i([{type:"bytes"},{type:"bytes"}],[o,j])]),to:l});return d}catch(e){throw new u({callbackSelector:g,cause:e,data:d,extraData:j,sender:f,urls:h})}}async function y({data:e,sender:t,urls:r}){let s=new Error("An unknown error occurred.");for(let o=0;o<r.length;o++){const n=r[o],c=n.includes("{data}")?"GET":"POST",i="POST"===c?{data:e,sender:t}:void 0;try{const r=await fetch(n.replace("{sender}",t).replace("{data}",e),{body:JSON.stringify(i),method:c});let o;if(o=r.headers.get("Content-Type")?.startsWith("application/json")?(await r.json()).data:await r.text(),!r.ok){s=new d({body:i,details:o?.error?a(o.error):r.statusText,headers:r.headers,status:r.status,url:n});continue}if(!l(o)){s=new p({result:o,url:n});continue}return o}catch(e){s=new d({body:i,details:e.message,url:n})}}throw s}export{y as ccipFetch,h as offchainLookup,m as offchainLookupAbiItem,f as offchainLookupSignature};
@@ -1 +1 @@
1
- "use strict";var e=require("./index-32e6540a.cjs"),r=require("@ethersproject/providers");require("@ethersproject/abstract-provider"),require("@ethersproject/contracts");const t=new e.Logger("networks/5.7.1");function n(e){const r=function(r,t){null==t&&(t={});const n=[];if(r.InfuraProvider&&"-"!==t.infura)try{n.push(new r.InfuraProvider(e,t.infura))}catch(e){}if(r.EtherscanProvider&&"-"!==t.etherscan)try{n.push(new r.EtherscanProvider(e,t.etherscan))}catch(e){}if(r.AlchemyProvider&&"-"!==t.alchemy)try{n.push(new r.AlchemyProvider(e,t.alchemy))}catch(e){}if(r.PocketProvider&&"-"!==t.pocket){const i=["goerli","ropsten","rinkeby","sepolia"];try{const o=new r.PocketProvider(e,t.pocket);o.network&&-1===i.indexOf(o.network.name)&&n.push(o)}catch(e){}}if(r.CloudflareProvider&&"-"!==t.cloudflare)try{n.push(new r.CloudflareProvider(e))}catch(e){}if(r.AnkrProvider&&"-"!==t.ankr)try{const i=["ropsten"],o=new r.AnkrProvider(e,t.ankr);o.network&&-1===i.indexOf(o.network.name)&&n.push(o)}catch(e){}if(0===n.length)return null;if(r.FallbackProvider){let i=1;return null!=t.quorum?i=t.quorum:"homestead"===e&&(i=2),new r.FallbackProvider(n,i)}return n[0]};return r.renetwork=function(e){return n(e)},r}function i(e,r){const t=function(t,n){return t.JsonRpcProvider?new t.JsonRpcProvider(e,r):null};return t.renetwork=function(r){return i(e,r)},t}const o={chainId:1,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"homestead",_defaultProvider:n("homestead")},s={chainId:3,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"ropsten",_defaultProvider:n("ropsten")},a={chainId:63,name:"classicMordor",_defaultProvider:i("https://www.ethercluster.com/mordor","classicMordor")},c={unspecified:{chainId:0,name:"unspecified"},homestead:o,mainnet:o,morden:{chainId:2,name:"morden"},ropsten:s,testnet:s,rinkeby:{chainId:4,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"rinkeby",_defaultProvider:n("rinkeby")},kovan:{chainId:42,name:"kovan",_defaultProvider:n("kovan")},goerli:{chainId:5,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"goerli",_defaultProvider:n("goerli")},kintsugi:{chainId:1337702,name:"kintsugi"},sepolia:{chainId:11155111,name:"sepolia",_defaultProvider:n("sepolia")},classic:{chainId:61,name:"classic",_defaultProvider:i("https://www.ethercluster.com/etc","classic")},classicMorden:{chainId:62,name:"classicMorden"},classicMordor:a,classicTestnet:a,classicKotti:{chainId:6,name:"classicKotti",_defaultProvider:i("https://www.ethercluster.com/kotti","classicKotti")},xdai:{chainId:100,name:"xdai"},matic:{chainId:137,name:"matic",_defaultProvider:n("matic")},maticmum:{chainId:80001,name:"maticmum"},optimism:{chainId:10,name:"optimism",_defaultProvider:n("optimism")},"optimism-kovan":{chainId:69,name:"optimism-kovan"},"optimism-goerli":{chainId:420,name:"optimism-goerli"},arbitrum:{chainId:42161,name:"arbitrum"},"arbitrum-rinkeby":{chainId:421611,name:"arbitrum-rinkeby"},"arbitrum-goerli":{chainId:421613,name:"arbitrum-goerli"},bnb:{chainId:56,name:"bnb"},bnbt:{chainId:97,name:"bnbt"}};function d(e){if(null==e)return null;if("number"==typeof e){for(const r in c){const t=c[r];if(t.chainId===e)return{name:t.name,chainId:t.chainId,ensAddress:t.ensAddress||null,_defaultProvider:t._defaultProvider||null}}return{chainId:e,name:"unknown"}}if("string"==typeof e){const r=c[e];return null==r?null:{name:r.name,chainId:r.chainId,ensAddress:r.ensAddress,_defaultProvider:r._defaultProvider||null}}const r=c[e.name];if(!r)return"number"!=typeof e.chainId&&t.throwArgumentError("invalid network chainId","network",e),e;0!==e.chainId&&e.chainId!==r.chainId&&t.throwArgumentError("network chainId mismatch","network",e);let n=e._defaultProvider||null;var i;return null==n&&r._defaultProvider&&(n=(i=r._defaultProvider)&&"function"==typeof i.renetwork?r._defaultProvider.renetwork(e):r._defaultProvider),{name:e.name,chainId:r.chainId,ensAddress:e.ensAddress||r.ensAddress||null,_defaultProvider:n}}class h{constructor(e,r=100){this.sendBatchFn=e,this.maxBatchSize=r,this.pendingBatch=[]}enqueueRequest(r){return e.__awaiter$1(this,void 0,void 0,(function*(){const e={request:r,resolve:void 0,reject:void 0},t=new Promise(((r,t)=>{e.resolve=r,e.reject=t}));return this.pendingBatch.push(e),this.pendingBatch.length===this.maxBatchSize?this.sendBatchRequest():this.pendingBatchTimer||(this.pendingBatchTimer=setTimeout((()=>this.sendBatchRequest()),10)),t}))}sendBatchRequest(){return e.__awaiter$1(this,void 0,void 0,(function*(){const e=this.pendingBatch;this.pendingBatch=[],this.pendingBatchTimer&&(clearTimeout(this.pendingBatchTimer),this.pendingBatchTimer=void 0);const r=e.map((e=>e.request));return this.sendBatchFn(r).then((r=>{e.forEach(((e,t)=>{const n=r[t];if(n.error){const r=new Error(n.error.message);r.code=n.error.code,r.data=n.error.data,e.reject(r)}else e.resolve(n.result)}))}),(r=>{e.forEach((e=>{e.reject(r)}))}))}))}}class u extends r.JsonRpcProvider{constructor(r){const t=u.getApiKey(r.apiKey),n=u.getAlchemyNetwork(r.network),i=u.getAlchemyConnectionInfo(n,t,"http");void 0!==r.url&&(i.url=r.url),i.throttleLimit=r.maxRetries;super(i,e.EthersNetwork[n]),this.apiKey=r.apiKey,this.maxRetries=r.maxRetries,this.batchRequests=r.batchRequests;const o=Object.assign(Object.assign({},this.connection),{headers:Object.assign(Object.assign({},this.connection.headers),{"Alchemy-Ethers-Sdk-Method":"batchSend"})});this.batcher=new h((r=>e.fetchJson(o,JSON.stringify(r)))),this.modifyFormatter()}static getApiKey(r){if(null==r)return e.DEFAULT_ALCHEMY_API_KEY;if(r&&"string"!=typeof r)throw new Error(`Invalid apiKey '${r}' provided. apiKey must be a string.`);return r}static getNetwork(r){return"string"==typeof r&&r in e.CustomNetworks?e.CustomNetworks[r]:d(r)}static getAlchemyNetwork(r){if(void 0===r)return e.DEFAULT_NETWORK;if("number"==typeof r)throw new Error(`Invalid network '${r}' provided. Network must be a string.`);if(!Object.values(e.Network).includes(r))throw new Error(`Invalid network '${r}' provided. Network must be one of: ${Object.values(e.Network).join(", ")}.`);return r}static getAlchemyConnectionInfo(r,t,n){const i="http"===n?e.getAlchemyHttpUrl(r,t):e.getAlchemyWsUrl(r,t);return{headers:e.IS_BROWSER?{"Alchemy-Ethers-Sdk-Version":e.VERSION}:{"Alchemy-Ethers-Sdk-Version":e.VERSION,"Accept-Encoding":"gzip"},allowGzip:!0,url:i}}detectNetwork(){const r=Object.create(null,{detectNetwork:{get:()=>super.detectNetwork}});return e.__awaiter$1(this,void 0,void 0,(function*(){let e=this.network;if(null==e&&(e=yield r.detectNetwork.call(this),!e))throw new Error("No network detected");return e}))}_startPending(){e.logWarn("WARNING: Alchemy Provider does not support pending filters")}isCommunityResource(){return this.apiKey===e.DEFAULT_ALCHEMY_API_KEY}send(e,r){return this._send(e,r,"send")}_send(r,t,n,i=!1){const o={method:r,params:t,id:this._nextId++,jsonrpc:"2.0"};if(Object.assign({},this.connection).headers["Alchemy-Ethers-Sdk-Method"]=n,this.batchRequests||i)return this.batcher.enqueueRequest(o);this.emit("debug",{action:"request",request:e.deepCopy(o),provider:this});const s=["eth_chainId","eth_blockNumber"].indexOf(r)>=0;if(s&&this._cache[r])return this._cache[r];const a=e.fetchJson(this.connection,JSON.stringify(o),l).then((e=>(this.emit("debug",{action:"response",request:o,response:e,provider:this}),e)),(e=>{throw this.emit("debug",{action:"response",error:e,request:o,provider:this}),e}));return s&&(this._cache[r]=a,setTimeout((()=>{this._cache[r]=null}),0)),a}modifyFormatter(){this.formatter.formats.receiptLog.removed=e=>{if("boolean"==typeof e)return e}}}function l(e){if(e.error){const r=new Error(e.error.message);throw r.code=e.error.code,r.data=e.error.data,r}return e.result}var m=Object.freeze({__proto__:null,AlchemyProvider:u});exports.AlchemyProvider=u,exports.alchemyProvider5870b6fa=m,exports.getNetwork=d;
1
+ "use strict";var e=require("./index-17256a18.cjs"),r=require("@ethersproject/providers");require("@ethersproject/abstract-provider"),require("@ethersproject/contracts");const t=new e.Logger("networks/5.7.1");function n(e){const r=function(r,t){null==t&&(t={});const n=[];if(r.InfuraProvider&&"-"!==t.infura)try{n.push(new r.InfuraProvider(e,t.infura))}catch(e){}if(r.EtherscanProvider&&"-"!==t.etherscan)try{n.push(new r.EtherscanProvider(e,t.etherscan))}catch(e){}if(r.AlchemyProvider&&"-"!==t.alchemy)try{n.push(new r.AlchemyProvider(e,t.alchemy))}catch(e){}if(r.PocketProvider&&"-"!==t.pocket){const i=["goerli","ropsten","rinkeby","sepolia"];try{const o=new r.PocketProvider(e,t.pocket);o.network&&-1===i.indexOf(o.network.name)&&n.push(o)}catch(e){}}if(r.CloudflareProvider&&"-"!==t.cloudflare)try{n.push(new r.CloudflareProvider(e))}catch(e){}if(r.AnkrProvider&&"-"!==t.ankr)try{const i=["ropsten"],o=new r.AnkrProvider(e,t.ankr);o.network&&-1===i.indexOf(o.network.name)&&n.push(o)}catch(e){}if(0===n.length)return null;if(r.FallbackProvider){let i=1;return null!=t.quorum?i=t.quorum:"homestead"===e&&(i=2),new r.FallbackProvider(n,i)}return n[0]};return r.renetwork=function(e){return n(e)},r}function i(e,r){const t=function(t,n){return t.JsonRpcProvider?new t.JsonRpcProvider(e,r):null};return t.renetwork=function(r){return i(e,r)},t}const o={chainId:1,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"homestead",_defaultProvider:n("homestead")},s={chainId:3,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"ropsten",_defaultProvider:n("ropsten")},a={chainId:63,name:"classicMordor",_defaultProvider:i("https://www.ethercluster.com/mordor","classicMordor")},c={unspecified:{chainId:0,name:"unspecified"},homestead:o,mainnet:o,morden:{chainId:2,name:"morden"},ropsten:s,testnet:s,rinkeby:{chainId:4,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"rinkeby",_defaultProvider:n("rinkeby")},kovan:{chainId:42,name:"kovan",_defaultProvider:n("kovan")},goerli:{chainId:5,ensAddress:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",name:"goerli",_defaultProvider:n("goerli")},kintsugi:{chainId:1337702,name:"kintsugi"},sepolia:{chainId:11155111,name:"sepolia",_defaultProvider:n("sepolia")},classic:{chainId:61,name:"classic",_defaultProvider:i("https://www.ethercluster.com/etc","classic")},classicMorden:{chainId:62,name:"classicMorden"},classicMordor:a,classicTestnet:a,classicKotti:{chainId:6,name:"classicKotti",_defaultProvider:i("https://www.ethercluster.com/kotti","classicKotti")},xdai:{chainId:100,name:"xdai"},matic:{chainId:137,name:"matic",_defaultProvider:n("matic")},maticmum:{chainId:80001,name:"maticmum"},optimism:{chainId:10,name:"optimism",_defaultProvider:n("optimism")},"optimism-kovan":{chainId:69,name:"optimism-kovan"},"optimism-goerli":{chainId:420,name:"optimism-goerli"},arbitrum:{chainId:42161,name:"arbitrum"},"arbitrum-rinkeby":{chainId:421611,name:"arbitrum-rinkeby"},"arbitrum-goerli":{chainId:421613,name:"arbitrum-goerli"},bnb:{chainId:56,name:"bnb"},bnbt:{chainId:97,name:"bnbt"}};function d(e){if(null==e)return null;if("number"==typeof e){for(const r in c){const t=c[r];if(t.chainId===e)return{name:t.name,chainId:t.chainId,ensAddress:t.ensAddress||null,_defaultProvider:t._defaultProvider||null}}return{chainId:e,name:"unknown"}}if("string"==typeof e){const r=c[e];return null==r?null:{name:r.name,chainId:r.chainId,ensAddress:r.ensAddress,_defaultProvider:r._defaultProvider||null}}const r=c[e.name];if(!r)return"number"!=typeof e.chainId&&t.throwArgumentError("invalid network chainId","network",e),e;0!==e.chainId&&e.chainId!==r.chainId&&t.throwArgumentError("network chainId mismatch","network",e);let n=e._defaultProvider||null;var i;return null==n&&r._defaultProvider&&(n=(i=r._defaultProvider)&&"function"==typeof i.renetwork?r._defaultProvider.renetwork(e):r._defaultProvider),{name:e.name,chainId:r.chainId,ensAddress:e.ensAddress||r.ensAddress||null,_defaultProvider:n}}class h{constructor(e,r=100){this.sendBatchFn=e,this.maxBatchSize=r,this.pendingBatch=[]}enqueueRequest(r){return e.__awaiter$1(this,void 0,void 0,(function*(){const e={request:r,resolve:void 0,reject:void 0},t=new Promise(((r,t)=>{e.resolve=r,e.reject=t}));return this.pendingBatch.push(e),this.pendingBatch.length===this.maxBatchSize?this.sendBatchRequest():this.pendingBatchTimer||(this.pendingBatchTimer=setTimeout((()=>this.sendBatchRequest()),10)),t}))}sendBatchRequest(){return e.__awaiter$1(this,void 0,void 0,(function*(){const e=this.pendingBatch;this.pendingBatch=[],this.pendingBatchTimer&&(clearTimeout(this.pendingBatchTimer),this.pendingBatchTimer=void 0);const r=e.map((e=>e.request));return this.sendBatchFn(r).then((r=>{e.forEach(((e,t)=>{const n=r[t];if(n.error){const r=new Error(n.error.message);r.code=n.error.code,r.data=n.error.data,e.reject(r)}else e.resolve(n.result)}))}),(r=>{e.forEach((e=>{e.reject(r)}))}))}))}}class u extends r.JsonRpcProvider{constructor(r){const t=u.getApiKey(r.apiKey),n=u.getAlchemyNetwork(r.network),i=u.getAlchemyConnectionInfo(n,t,"http");void 0!==r.url&&(i.url=r.url),i.throttleLimit=r.maxRetries;super(i,e.EthersNetwork[n]),this.apiKey=r.apiKey,this.maxRetries=r.maxRetries,this.batchRequests=r.batchRequests;const o=Object.assign(Object.assign({},this.connection),{headers:Object.assign(Object.assign({},this.connection.headers),{"Alchemy-Ethers-Sdk-Method":"batchSend"})});this.batcher=new h((r=>e.fetchJson(o,JSON.stringify(r)))),this.modifyFormatter()}static getApiKey(r){if(null==r)return e.DEFAULT_ALCHEMY_API_KEY;if(r&&"string"!=typeof r)throw new Error(`Invalid apiKey '${r}' provided. apiKey must be a string.`);return r}static getNetwork(r){return"string"==typeof r&&r in e.CustomNetworks?e.CustomNetworks[r]:d(r)}static getAlchemyNetwork(r){if(void 0===r)return e.DEFAULT_NETWORK;if("number"==typeof r)throw new Error(`Invalid network '${r}' provided. Network must be a string.`);if(!Object.values(e.Network).includes(r))throw new Error(`Invalid network '${r}' provided. Network must be one of: ${Object.values(e.Network).join(", ")}.`);return r}static getAlchemyConnectionInfo(r,t,n){const i="http"===n?e.getAlchemyHttpUrl(r,t):e.getAlchemyWsUrl(r,t);return{headers:e.IS_BROWSER?{"Alchemy-Ethers-Sdk-Version":e.VERSION}:{"Alchemy-Ethers-Sdk-Version":e.VERSION,"Accept-Encoding":"gzip"},allowGzip:!0,url:i}}detectNetwork(){const r=Object.create(null,{detectNetwork:{get:()=>super.detectNetwork}});return e.__awaiter$1(this,void 0,void 0,(function*(){let e=this.network;if(null==e&&(e=yield r.detectNetwork.call(this),!e))throw new Error("No network detected");return e}))}_startPending(){e.logWarn("WARNING: Alchemy Provider does not support pending filters")}isCommunityResource(){return this.apiKey===e.DEFAULT_ALCHEMY_API_KEY}send(e,r){return this._send(e,r,"send")}_send(r,t,n,i=!1){const o={method:r,params:t,id:this._nextId++,jsonrpc:"2.0"};if(Object.assign({},this.connection).headers["Alchemy-Ethers-Sdk-Method"]=n,this.batchRequests||i)return this.batcher.enqueueRequest(o);this.emit("debug",{action:"request",request:e.deepCopy(o),provider:this});const s=["eth_chainId","eth_blockNumber"].indexOf(r)>=0;if(s&&this._cache[r])return this._cache[r];const a=e.fetchJson(this.connection,JSON.stringify(o),l).then((e=>(this.emit("debug",{action:"response",request:o,response:e,provider:this}),e)),(e=>{throw this.emit("debug",{action:"response",error:e,request:o,provider:this}),e}));return s&&(this._cache[r]=a,setTimeout((()=>{this._cache[r]=null}),0)),a}modifyFormatter(){this.formatter.formats.receiptLog.removed=e=>{if("boolean"==typeof e)return e}}}function l(e){if(e.error){const r=new Error(e.error.message);throw r.code=e.error.code,r.data=e.error.data,r}return e.result}var m=Object.freeze({__proto__:null,AlchemyProvider:u});exports.AlchemyProvider=u,exports.alchemyProvider5870b6fa=m,exports.getNetwork=d;