@dodoex/wallet-web3 0.3.3 → 0.3.4
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.
- package/dist/{alchemy-provider-5870b6fa-6e276e1b.js → alchemy-provider-5870b6fa-d73f10c3.js} +1 -1
- package/dist/{alchemy-websocket-provider-213da986-bb6a57e6.js → alchemy-websocket-provider-213da986-5548964b.js} +1 -1
- package/dist/{blocto-d21cfb95.js → blocto-087ab98b.js} +1 -1
- package/dist/{ccip-8431aba4.js → ccip-b0d2cb9b.js} +1 -1
- package/dist/cjs/{alchemy-provider-5870b6fa-a4a9827b.cjs → alchemy-provider-5870b6fa-13c38c30.cjs} +1 -1
- package/dist/cjs/{alchemy-websocket-provider-213da986-de8016ab.cjs → alchemy-websocket-provider-213da986-9c2a561f.cjs} +1 -1
- package/dist/cjs/{blocto-e7c05f55.cjs → blocto-59170006.cjs} +1 -1
- package/dist/cjs/{ccip-03b96ac0.cjs → ccip-f9b919b2.cjs} +1 -1
- package/dist/cjs/core/index.d.ts +2 -1
- package/dist/cjs/{draggabilly-e6ba61be.cjs → draggabilly-b2bd6560.cjs} +1 -1
- package/dist/cjs/id-6aec2278.cjs +1 -0
- package/dist/cjs/{index-ff2bf30e.cjs → index-4088da7a.cjs} +1 -1
- package/dist/cjs/{index-acaec64d.cjs → index-5fba0284.cjs} +4 -4
- package/dist/cjs/{index-46e66f67.cjs → index-6cb01ff5.cjs} +1 -1
- package/dist/cjs/{index-df573b7a.cjs → index-7e2b99b8.cjs} +1 -1
- package/dist/cjs/{index-2b0f2dc3.cjs → index-8f9c08b7.cjs} +1 -1
- package/dist/cjs/{index-ac826265.cjs → index-909ed09f.cjs} +1 -1
- package/dist/cjs/{index-690eebc7.cjs → index-a9e41217.cjs} +1 -1
- package/dist/cjs/{index-147e455b.cjs → index-afede0c1.cjs} +1 -1
- package/dist/cjs/{index-17949bd2.cjs → index-c8776c7e.cjs} +3 -3
- package/dist/cjs/{index-7fa2d3b6.cjs → index-e3a09800.cjs} +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/{index.es-df679ebf.cjs → index.es-5658402e.cjs} +1 -1
- package/dist/cjs/{interface-8cc0a528.cjs → interface-f8513d40.cjs} +1 -1
- package/dist/cjs/lib-typedarrays-0c53ed3f.cjs +1 -0
- package/dist/cjs/{portis-8128f750.cjs → portis-f1e438bd.cjs} +1 -1
- package/dist/cjs/{provider-02ef17ce.cjs → provider-1469a098.cjs} +1 -1
- package/dist/cjs/{rainbow-d40d1a7f.cjs → rainbow-3dc6f968.cjs} +1 -1
- package/dist/cjs/sha224-a96222a0.cjs +1 -0
- package/dist/cjs/{sha256-b078a56f.cjs → sha256-981f903c.cjs} +1 -1
- package/dist/cjs/{typed-data-29e9ba41.cjs → typed-data-d4238233.cjs} +1 -1
- package/dist/cjs/uAuth-89a23338.cjs +1 -0
- package/dist/cjs/{walletConnect-19922064.cjs → walletConnect-e69e2a9a.cjs} +1 -1
- package/dist/cjs/{walletLink-65ca3891.cjs → walletLink-0560c895.cjs} +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/{draggabilly-13c91f3b.js → draggabilly-4433218d.js} +1 -1
- package/dist/id-b18759a6.js +1 -0
- package/dist/{index-9607e7e6.js → index-08b24f87.js} +1 -1
- package/dist/{index-db13a7de.js → index-43cf1b4a.js} +1 -1
- package/dist/{index-bffd59f1.js → index-4ce5e1ef.js} +1 -1
- package/dist/{index-983baf38.js → index-8d387984.js} +4 -4
- package/dist/{index-cf57880c.js → index-8d7041e4.js} +3 -3
- package/dist/{index-187032eb.js → index-98e3a5b7.js} +1 -1
- package/dist/{index-b3c8d59e.js → index-a02313f2.js} +1 -1
- package/dist/{index-c8294cc6.js → index-e23ece16.js} +1 -1
- package/dist/{index-d3046dad.js → index-e8d823f4.js} +1 -1
- package/dist/{index-5866f671.js → index-fe2d0915.js} +1 -1
- package/dist/{index.es-0e287156.js → index.es-0097b19b.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/{interface-adba737d.js → interface-6ba1137a.js} +1 -1
- package/dist/lib-typedarrays-72196011.js +1 -0
- package/dist/{portis-aceac8e3.js → portis-37b07247.js} +1 -1
- package/dist/{provider-0e2c1ad2.js → provider-db4424b4.js} +1 -1
- package/dist/{rainbow-04918203.js → rainbow-367d8171.js} +1 -1
- package/dist/sha224-4183d3c7.js +1 -0
- package/dist/{sha256-53b92407.js → sha256-d65763b0.js} +1 -1
- package/dist/{typed-data-c4dc667a.js → typed-data-a771d851.js} +1 -1
- package/dist/uAuth-2c8aeeba.js +1 -0
- package/dist/{walletConnect-c6a32587.js → walletConnect-c14d2cb7.js} +1 -1
- package/dist/{walletLink-30b4e762.js → walletLink-062c2a28.js} +1 -1
- package/package.json +1 -1
- package/dist/cjs/id-977d274a.cjs +0 -1
- package/dist/cjs/lib-typedarrays-f16e2014.cjs +0 -1
- package/dist/cjs/sha224-25dc0525.cjs +0 -1
- package/dist/cjs/uAuth-a3baeb1d.cjs +0 -1
- package/dist/id-5204a899.js +0 -1
- package/dist/lib-typedarrays-78951703.js +0 -1
- package/dist/sha224-1a3c9027.js +0 -1
- package/dist/uAuth-3e20de1b.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./index-acaec64d.cjs"),t=require("./alchemy-provider-5870b6fa-a4a9827b.cjs"),s=require("@ethersproject/providers");require("@ethersproject/abstract-provider"),require("@ethersproject/contracts"),require("zustand"),require("@ethersproject/bytes"),require("@ethersproject/properties"),require("@ethersproject/address"),require("@ethersproject/abstract-signer"),require("buffer"),require("events"),require("@ethersproject/constants"),require("@ethersproject/transactions");var n={};Object.defineProperty(n,"__esModule",{value:!0});var i=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=o(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 r=!e||i(e);"boolean"==typeof r?this.handleWillReconnect(r,e,"Provided shouldReconnect() returned false. Closing permanently."):r.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 r=this.nextRetryTime;this.nextRetryTime=Math.max(s,Math.min(this.nextRetryTime*i,n)),setTimeout((function(){return e.openNewWebSocket()}),r);var o=r/1e3|0;this.debugLog("WebSocket was closed. Re-opening in "+o+" 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=c,this.ws.onclose=c,this.ws.onmessage=c,this.ws.onopen=c,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}(),r=n.default=i;function o(e){var t={};return Object.keys(i.DEFAULT_OPTIONS).forEach((function(s){var n=e[s];t[s]=void 0===n?i.DEFAULT_OPTIONS[s]:n})),t}function c(){}class l{constructor(e){this.provider=e,this.maxBackfillBlocks=120}getNewHeadsBackfill(t,s,n){return e.__awaiter$1(this,void 0,void 0,(function*(){d(t);const i=yield this.getBlockNumber();if(d(t),0===s.length)return this.getHeadEventsInRange(Math.max(n,i-this.maxBackfillBlocks)+1,i+1);const r=e.fromHex(s[s.length-1].number),o=i-this.maxBackfillBlocks+1;if(r<=o)return this.getHeadEventsInRange(o,i+1);const c=yield this.getReorgHeads(t,s);d(t);const l=yield this.getHeadEventsInRange(r+1,i+1);return d(t),[...c,...l]}))}getLogsBackfill(t,s,n,i){return e.__awaiter$1(this,void 0,void 0,(function*(){d(t);const r=yield this.getBlockNumber();if(d(t),0===n.length)return this.getLogsInRange(s,Math.max(i,r-this.maxBackfillBlocks)+1,r+1);const o=e.fromHex(n[n.length-1].blockNumber),c=r-this.maxBackfillBlocks+1;if(o<c)return this.getLogsInRange(s,c,r+1);const l=yield this.getCommonAncestor(t,n);d(t);const a=n.filter((t=>e.fromHex(t.blockNumber)>l.blockNumber)).map((e=>Object.assign(Object.assign({},e),{removed:!0}))),h=l.blockNumber===Number.NEGATIVE_INFINITY?e.fromHex(n[0].blockNumber):l.blockNumber;let u=yield this.getLogsInRange(s,h,r+1);return u=u.filter((t=>t&&(e.fromHex(t.blockNumber)>l.blockNumber||e.fromHex(t.logIndex)>l.logIndex))),d(t),[...a,...u]}))}setMaxBackfillBlock(e){this.maxBackfillBlocks=e}getBlockNumber(){return e.__awaiter$1(this,void 0,void 0,(function*(){const t=yield this.provider.send("eth_blockNumber");return e.fromHex(t)}))}getHeadEventsInRange(t,s){return e.__awaiter$1(this,void 0,void 0,(function*(){if(t>=s)return[];const n=[];for(let i=t;i<s;i++)n.push({method:"eth_getBlockByNumber",params:[e.toHex(i),!1]});return(yield this.provider.sendBatch(n)).map(a)}))}getReorgHeads(t,s){return e.__awaiter$1(this,void 0,void 0,(function*(){const n=[];for(let i=s.length-1;i>=0;i--){const r=s[i],o=yield this.getBlockByNumber(e.fromHex(r.number));if(d(t),r.hash===o.hash)break;n.push(a(o))}return n.reverse()}))}getBlockByNumber(t){return e.__awaiter$1(this,void 0,void 0,(function*(){return this.provider.send("eth_getBlockByNumber",[e.toHex(t),!1])}))}getCommonAncestor(t,s){return e.__awaiter$1(this,void 0,void 0,(function*(){let n=yield this.getBlockByNumber(e.fromHex(s[s.length-1].blockNumber));d(t);for(let t=s.length-1;t>=0;t--){const i=s[t];if(i.blockNumber!==n.number&&(n=yield this.getBlockByNumber(e.fromHex(i.blockNumber))),i.blockHash===n.hash)return{blockNumber:e.fromHex(i.blockNumber),logIndex:e.fromHex(i.logIndex)}}return{blockNumber:Number.NEGATIVE_INFINITY,logIndex:Number.NEGATIVE_INFINITY}}))}getLogsInRange(t,s,n){return e.__awaiter$1(this,void 0,void 0,(function*(){if(s>=n)return[];const i=Object.assign(Object.assign({},t),{fromBlock:e.toHex(s),toBlock:e.toHex(n-1)});return this.provider.send("eth_getLogs",[i])}))}}function a(e){const t=Object.assign({},e);return delete t.totalDifficulty,delete t.transactions,delete t.uncles,t}function h(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 u=new Error("Cancelled");function d(e){if(e())throw u}const f=10;class m extends s.WebSocketProvider{constructor(s,n){var i;const o=t.AlchemyProvider.getApiKey(s.apiKey),c=t.AlchemyProvider.getAlchemyNetwork(s.network),a=t.AlchemyProvider.getAlchemyConnectionInfo(c,o,"wss"),h=`alchemy-sdk-${e.VERSION}`;super(new r(null!==(i=s.url)&&void 0!==i?i:a.url,h,{wsConstructor:null!=n?n:"undefined"!=typeof process&&null!=process&&null!=process.versions&&null!=process.versions.node?require("websocket").w3cwebsocket:WebSocket}),e.EthersNetwork[c]),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,r=t,{isBackfilling:o,backfillBuffer:c}=e,{result:l}=r.params;o?function(e,t){w(e,t,k)}(c,l):s!==n?this.emitAndRememberEvent(n,l,k):this.rememberEvent(n,l,k);break}case"logs":{const e=i,r=t,{isBackfilling:o,backfillBuffer:c}=e,{result:l}=r.params;o?function(e,t){w(e,t,_)}(c,l):n!==s?this.emitAndRememberEvent(n,l,_):this.rememberEvent(n,l,_);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.__awaiter$1(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 l(this),this.addSocketListeners(),this.startHeartbeat(),this.cancelBackfill=e.noop}static getNetwork(s){return"string"==typeof s&&s in e.CustomNetworks?e.CustomNetworks[s]:t.getNetwork(s)}on(e,t){return this._addEventListener(e,t,!1)}once(e,t){return this._addEventListener(e,t,!0)}off(t,s){return e.isAlchemyEvent(t)?this._off(t,s):super.off(t,s)}removeAllListeners(t){return void 0!==t&&e.isAlchemyEvent(t)?this._removeAllListeners(t):super.removeAllListeners(t)}listenerCount(t){return void 0!==t&&e.isAlchemyEvent(t)?this._listenerCount(t):super.listenerCount(t)}listeners(t){return void 0!==t&&e.isAlchemyEvent(t)?this._listeners(t):super.listeners(t)}_addEventListener(t,s,n){if(e.isAlchemyEvent(t)){e.verifyAlchemyEventName(t);const i=new e.EthersEvent(e.getAlchemyEventTag(t),s,n);return this._events.push(i),this._startEvent(i),this}return super._addEventListener(t,s,n)}_startEvent(t){[...e.ALCHEMY_EVENT_TYPES,"block","filter"].includes(t.type)?this.customStartEvent(t):super._startEvent(t)}_subscribe(t,s,n,i){return e.__awaiter$1(this,void 0,void 0,(function*(){let e=this._subIds[t];const r=yield this.getBlockNumber();null==e&&(e=Promise.all(s).then((e=>this.send("eth_subscribe",e))),this._subIds[t]=e);const o=yield e,c=yield Promise.all(s);this.virtualSubscriptionsById.set(o,{event:i,method:"eth_subscribe",params:c,startingBlockNumber:r,virtualId:o,physicalId:o,sentEvents:[],isBackfilling:!1,backfillBuffer:[]}),this.virtualIdsByPhysicalId.set(o,o),this._subs[o]={tag:t,processFunc:n}}))}emit(t,...s){if(e.isAlchemyEvent(t)){let n=!1;const i=[],r=e.getAlchemyEventTag(t);return this._events=this._events.filter((e=>e.tag!==r||(setTimeout((()=>{e.listener.apply(this,s)}),0),n=!0,!e.once||(i.push(e),!1)))),i.forEach((e=>{this._stopEvent(e)})),n}return super.emit(t,...s)}sendBatch(t){return e.__awaiter$1(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===e.DEFAULT_ALCHEMY_API_KEY}_stopEvent(t){let s=t.tag;if(e.ALCHEMY_EVENT_TYPES.includes(t.type)){if(this._events.filter((t=>e.ALCHEMY_EVENT_TYPES.includes(t.type))).length)return}else if("tx"===t.type){if(this._events.filter((e=>"tx"===e.type)).length)return;s="tx"}else if(this.listenerCount(t.event))return;const n=this._subIds[s];n&&(delete this._subIds[s],n.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.__awaiter$1(this,void 0,void 0,(function*(){const{virtualId:e,method:n,params:i,sentEvents:r,backfillBuffer:o,startingBlockNumber:c}=s;s.isBackfilling=!0,o.length=0;try{const l=yield this.send(n,i);switch(d(t),s.physicalId=l,this.virtualIdsByPhysicalId.set(l,e),i[0]){case"newHeads":{const s=yield y((()=>E(this.backfiller.getNewHeadsBackfill(t,r,c),6e4)),5,(()=>!t()));d(t);(function(e){return h(e,(e=>e.hash))})([...s,...o]).forEach((t=>this.emitNewHeadsEvent(e,t)));break}case"logs":{const s=i[1]||{},n=yield y((()=>E(this.backfiller.getLogsBackfill(t,s,r,c),6e4)),5,(()=>!t()));d(t);(function(e){return h(e,(e=>`${e.blockHash}/${e.logIndex}`))})([...n,...o]).forEach((t=>this.emitLogsEvent(e,t)));break}}}finally{s.isBackfilling=!1,o.length=0}}))}emitNewHeadsEvent(e,t){this.emitAndRememberEvent(e,t,k)}emitLogsEvent(e,t){this.emitAndRememberEvent(e,t,_)}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.__awaiter$1(this,void 0,void 0,(function*(){try{yield E(this.send("net_version"),1e4)}catch(e){this._websocket.reconnect()}}))),3e4))}sendBatchConcurrently(t){return e.__awaiter$1(this,void 0,void 0,(function*(){return Promise.all(t.map((e=>this.send(e.method,e.params))))}))}customStartEvent(t){if(t.type===e.ALCHEMY_PENDING_TRANSACTIONS_EVENT_TYPE){const{fromAddress:s,toAddress:n,hashesOnly:i}=t;this._subscribe(t.tag,[e.AlchemySubscription.PENDING_TRANSACTIONS,{fromAddress:s,toAddress:n,hashesOnly:i}],this.emitProcessFn(t),t)}else if(t.type===e.ALCHEMY_MINED_TRANSACTIONS_EVENT_TYPE){const{addresses:s,includeRemoved:n,hashesOnly:i}=t;this._subscribe(t.tag,[e.AlchemySubscription.MINED_TRANSACTIONS,{addresses:s,includeRemoved:n,hashesOnly:i}],this.emitProcessFn(t),t)}else"block"===t.type?this._subscribe("block",["newHeads"],this.emitProcessFn(t),t):"filter"===t.type&&this._subscribe(t.tag,["logs",this._getFilter(t.filter)],this.emitProcessFn(t),t)}emitProcessFn(t){switch(t.type){case e.ALCHEMY_PENDING_TRANSACTIONS_EVENT_TYPE:return s=>this.emit({method:e.AlchemySubscription.PENDING_TRANSACTIONS,fromAddress:t.fromAddress,toAddress:t.toAddress,hashesOnly:t.hashesOnly},s);case e.ALCHEMY_MINED_TRANSACTIONS_EVENT_TYPE:return s=>this.emit({method:e.AlchemySubscription.MINED_TRANSACTIONS,addresses:t.addresses,includeRemoved:t.includeRemoved,hashesOnly:t.hashesOnly},s);case"block":return t=>{const s=e.BigNumber.from(t.number).toNumber();this._emitted.block=s,this.emit("block",s)};case"filter":return e=>{null==e.removed&&(e.removed=!1),this.emit(t.filter,this.formatter.filterLog(e))};default:throw new Error("Invalid event type to `emitProcessFn()`")}}_off(t,s){if(null==s)return this.removeAllListeners(t);const n=[];let i=!1;const r=e.getAlchemyEventTag(t);return this._events=this._events.filter((e=>e.tag!==r||e.listener!=s||(!!i||(i=!0,n.push(e),!1)))),n.forEach((e=>{this._stopEvent(e)})),this}_removeAllListeners(t){let s=[];if(null==t)s=this._events,this._events=[];else{const n=e.getAlchemyEventTag(t);this._events=this._events.filter((e=>e.tag!==n||(s.push(e),!1)))}return s.forEach((e=>{this._stopEvent(e)})),this}_listenerCount(t){if(!t)return this._events.length;const s=e.getAlchemyEventTag(t);return this._events.filter((e=>e.tag===s)).length}_listeners(t){if(null==t)return this._events.map((e=>e.listener));const s=e.getAlchemyEventTag(t);return this._events.filter((e=>e.tag===s)).map((e=>e.listener))}}const p=1e3,b=2,v=3e4;function y(t,s,n=(()=>!0)){return e.__awaiter$1(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 g(e),!n(t))throw t;e=0===e?p:Math.min(v,b*e)}}))}function g(e){return new Promise((t=>setTimeout(t,e)))}function E(e,t){return Promise.race([e,new Promise(((e,s)=>setTimeout((()=>s(new Error("Timeout"))),t)))])}function k(t){return e.fromHex(t.number)}function _(t){return e.fromHex(t.blockNumber)}function w(e,t,s){const n=s(t),i=e.findIndex((e=>s(e)>n-f));-1===i?e.length=0:e.splice(0,i),e.push(t)}exports.AlchemyWebSocketProvider=m;
|
|
1
|
+
"use strict";var e=require("./index-5fba0284.cjs"),t=require("./alchemy-provider-5870b6fa-13c38c30.cjs"),s=require("@ethersproject/providers");require("@ethersproject/abstract-provider"),require("@ethersproject/contracts"),require("zustand"),require("@ethersproject/bytes"),require("@ethersproject/properties"),require("@ethersproject/address"),require("@ethersproject/abstract-signer"),require("buffer"),require("events"),require("@ethersproject/constants"),require("@ethersproject/transactions");var n={};Object.defineProperty(n,"__esModule",{value:!0});var i=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=o(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 r=!e||i(e);"boolean"==typeof r?this.handleWillReconnect(r,e,"Provided shouldReconnect() returned false. Closing permanently."):r.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 r=this.nextRetryTime;this.nextRetryTime=Math.max(s,Math.min(this.nextRetryTime*i,n)),setTimeout((function(){return e.openNewWebSocket()}),r);var o=r/1e3|0;this.debugLog("WebSocket was closed. Re-opening in "+o+" 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=c,this.ws.onclose=c,this.ws.onmessage=c,this.ws.onopen=c,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}(),r=n.default=i;function o(e){var t={};return Object.keys(i.DEFAULT_OPTIONS).forEach((function(s){var n=e[s];t[s]=void 0===n?i.DEFAULT_OPTIONS[s]:n})),t}function c(){}class l{constructor(e){this.provider=e,this.maxBackfillBlocks=120}getNewHeadsBackfill(t,s,n){return e.__awaiter$1(this,void 0,void 0,(function*(){d(t);const i=yield this.getBlockNumber();if(d(t),0===s.length)return this.getHeadEventsInRange(Math.max(n,i-this.maxBackfillBlocks)+1,i+1);const r=e.fromHex(s[s.length-1].number),o=i-this.maxBackfillBlocks+1;if(r<=o)return this.getHeadEventsInRange(o,i+1);const c=yield this.getReorgHeads(t,s);d(t);const l=yield this.getHeadEventsInRange(r+1,i+1);return d(t),[...c,...l]}))}getLogsBackfill(t,s,n,i){return e.__awaiter$1(this,void 0,void 0,(function*(){d(t);const r=yield this.getBlockNumber();if(d(t),0===n.length)return this.getLogsInRange(s,Math.max(i,r-this.maxBackfillBlocks)+1,r+1);const o=e.fromHex(n[n.length-1].blockNumber),c=r-this.maxBackfillBlocks+1;if(o<c)return this.getLogsInRange(s,c,r+1);const l=yield this.getCommonAncestor(t,n);d(t);const a=n.filter((t=>e.fromHex(t.blockNumber)>l.blockNumber)).map((e=>Object.assign(Object.assign({},e),{removed:!0}))),h=l.blockNumber===Number.NEGATIVE_INFINITY?e.fromHex(n[0].blockNumber):l.blockNumber;let u=yield this.getLogsInRange(s,h,r+1);return u=u.filter((t=>t&&(e.fromHex(t.blockNumber)>l.blockNumber||e.fromHex(t.logIndex)>l.logIndex))),d(t),[...a,...u]}))}setMaxBackfillBlock(e){this.maxBackfillBlocks=e}getBlockNumber(){return e.__awaiter$1(this,void 0,void 0,(function*(){const t=yield this.provider.send("eth_blockNumber");return e.fromHex(t)}))}getHeadEventsInRange(t,s){return e.__awaiter$1(this,void 0,void 0,(function*(){if(t>=s)return[];const n=[];for(let i=t;i<s;i++)n.push({method:"eth_getBlockByNumber",params:[e.toHex(i),!1]});return(yield this.provider.sendBatch(n)).map(a)}))}getReorgHeads(t,s){return e.__awaiter$1(this,void 0,void 0,(function*(){const n=[];for(let i=s.length-1;i>=0;i--){const r=s[i],o=yield this.getBlockByNumber(e.fromHex(r.number));if(d(t),r.hash===o.hash)break;n.push(a(o))}return n.reverse()}))}getBlockByNumber(t){return e.__awaiter$1(this,void 0,void 0,(function*(){return this.provider.send("eth_getBlockByNumber",[e.toHex(t),!1])}))}getCommonAncestor(t,s){return e.__awaiter$1(this,void 0,void 0,(function*(){let n=yield this.getBlockByNumber(e.fromHex(s[s.length-1].blockNumber));d(t);for(let t=s.length-1;t>=0;t--){const i=s[t];if(i.blockNumber!==n.number&&(n=yield this.getBlockByNumber(e.fromHex(i.blockNumber))),i.blockHash===n.hash)return{blockNumber:e.fromHex(i.blockNumber),logIndex:e.fromHex(i.logIndex)}}return{blockNumber:Number.NEGATIVE_INFINITY,logIndex:Number.NEGATIVE_INFINITY}}))}getLogsInRange(t,s,n){return e.__awaiter$1(this,void 0,void 0,(function*(){if(s>=n)return[];const i=Object.assign(Object.assign({},t),{fromBlock:e.toHex(s),toBlock:e.toHex(n-1)});return this.provider.send("eth_getLogs",[i])}))}}function a(e){const t=Object.assign({},e);return delete t.totalDifficulty,delete t.transactions,delete t.uncles,t}function h(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 u=new Error("Cancelled");function d(e){if(e())throw u}const f=10;class m extends s.WebSocketProvider{constructor(s,n){var i;const o=t.AlchemyProvider.getApiKey(s.apiKey),c=t.AlchemyProvider.getAlchemyNetwork(s.network),a=t.AlchemyProvider.getAlchemyConnectionInfo(c,o,"wss"),h=`alchemy-sdk-${e.VERSION}`;super(new r(null!==(i=s.url)&&void 0!==i?i:a.url,h,{wsConstructor:null!=n?n:"undefined"!=typeof process&&null!=process&&null!=process.versions&&null!=process.versions.node?require("websocket").w3cwebsocket:WebSocket}),e.EthersNetwork[c]),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,r=t,{isBackfilling:o,backfillBuffer:c}=e,{result:l}=r.params;o?function(e,t){w(e,t,k)}(c,l):s!==n?this.emitAndRememberEvent(n,l,k):this.rememberEvent(n,l,k);break}case"logs":{const e=i,r=t,{isBackfilling:o,backfillBuffer:c}=e,{result:l}=r.params;o?function(e,t){w(e,t,_)}(c,l):n!==s?this.emitAndRememberEvent(n,l,_):this.rememberEvent(n,l,_);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.__awaiter$1(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 l(this),this.addSocketListeners(),this.startHeartbeat(),this.cancelBackfill=e.noop}static getNetwork(s){return"string"==typeof s&&s in e.CustomNetworks?e.CustomNetworks[s]:t.getNetwork(s)}on(e,t){return this._addEventListener(e,t,!1)}once(e,t){return this._addEventListener(e,t,!0)}off(t,s){return e.isAlchemyEvent(t)?this._off(t,s):super.off(t,s)}removeAllListeners(t){return void 0!==t&&e.isAlchemyEvent(t)?this._removeAllListeners(t):super.removeAllListeners(t)}listenerCount(t){return void 0!==t&&e.isAlchemyEvent(t)?this._listenerCount(t):super.listenerCount(t)}listeners(t){return void 0!==t&&e.isAlchemyEvent(t)?this._listeners(t):super.listeners(t)}_addEventListener(t,s,n){if(e.isAlchemyEvent(t)){e.verifyAlchemyEventName(t);const i=new e.EthersEvent(e.getAlchemyEventTag(t),s,n);return this._events.push(i),this._startEvent(i),this}return super._addEventListener(t,s,n)}_startEvent(t){[...e.ALCHEMY_EVENT_TYPES,"block","filter"].includes(t.type)?this.customStartEvent(t):super._startEvent(t)}_subscribe(t,s,n,i){return e.__awaiter$1(this,void 0,void 0,(function*(){let e=this._subIds[t];const r=yield this.getBlockNumber();null==e&&(e=Promise.all(s).then((e=>this.send("eth_subscribe",e))),this._subIds[t]=e);const o=yield e,c=yield Promise.all(s);this.virtualSubscriptionsById.set(o,{event:i,method:"eth_subscribe",params:c,startingBlockNumber:r,virtualId:o,physicalId:o,sentEvents:[],isBackfilling:!1,backfillBuffer:[]}),this.virtualIdsByPhysicalId.set(o,o),this._subs[o]={tag:t,processFunc:n}}))}emit(t,...s){if(e.isAlchemyEvent(t)){let n=!1;const i=[],r=e.getAlchemyEventTag(t);return this._events=this._events.filter((e=>e.tag!==r||(setTimeout((()=>{e.listener.apply(this,s)}),0),n=!0,!e.once||(i.push(e),!1)))),i.forEach((e=>{this._stopEvent(e)})),n}return super.emit(t,...s)}sendBatch(t){return e.__awaiter$1(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===e.DEFAULT_ALCHEMY_API_KEY}_stopEvent(t){let s=t.tag;if(e.ALCHEMY_EVENT_TYPES.includes(t.type)){if(this._events.filter((t=>e.ALCHEMY_EVENT_TYPES.includes(t.type))).length)return}else if("tx"===t.type){if(this._events.filter((e=>"tx"===e.type)).length)return;s="tx"}else if(this.listenerCount(t.event))return;const n=this._subIds[s];n&&(delete this._subIds[s],n.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.__awaiter$1(this,void 0,void 0,(function*(){const{virtualId:e,method:n,params:i,sentEvents:r,backfillBuffer:o,startingBlockNumber:c}=s;s.isBackfilling=!0,o.length=0;try{const l=yield this.send(n,i);switch(d(t),s.physicalId=l,this.virtualIdsByPhysicalId.set(l,e),i[0]){case"newHeads":{const s=yield y((()=>E(this.backfiller.getNewHeadsBackfill(t,r,c),6e4)),5,(()=>!t()));d(t);(function(e){return h(e,(e=>e.hash))})([...s,...o]).forEach((t=>this.emitNewHeadsEvent(e,t)));break}case"logs":{const s=i[1]||{},n=yield y((()=>E(this.backfiller.getLogsBackfill(t,s,r,c),6e4)),5,(()=>!t()));d(t);(function(e){return h(e,(e=>`${e.blockHash}/${e.logIndex}`))})([...n,...o]).forEach((t=>this.emitLogsEvent(e,t)));break}}}finally{s.isBackfilling=!1,o.length=0}}))}emitNewHeadsEvent(e,t){this.emitAndRememberEvent(e,t,k)}emitLogsEvent(e,t){this.emitAndRememberEvent(e,t,_)}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.__awaiter$1(this,void 0,void 0,(function*(){try{yield E(this.send("net_version"),1e4)}catch(e){this._websocket.reconnect()}}))),3e4))}sendBatchConcurrently(t){return e.__awaiter$1(this,void 0,void 0,(function*(){return Promise.all(t.map((e=>this.send(e.method,e.params))))}))}customStartEvent(t){if(t.type===e.ALCHEMY_PENDING_TRANSACTIONS_EVENT_TYPE){const{fromAddress:s,toAddress:n,hashesOnly:i}=t;this._subscribe(t.tag,[e.AlchemySubscription.PENDING_TRANSACTIONS,{fromAddress:s,toAddress:n,hashesOnly:i}],this.emitProcessFn(t),t)}else if(t.type===e.ALCHEMY_MINED_TRANSACTIONS_EVENT_TYPE){const{addresses:s,includeRemoved:n,hashesOnly:i}=t;this._subscribe(t.tag,[e.AlchemySubscription.MINED_TRANSACTIONS,{addresses:s,includeRemoved:n,hashesOnly:i}],this.emitProcessFn(t),t)}else"block"===t.type?this._subscribe("block",["newHeads"],this.emitProcessFn(t),t):"filter"===t.type&&this._subscribe(t.tag,["logs",this._getFilter(t.filter)],this.emitProcessFn(t),t)}emitProcessFn(t){switch(t.type){case e.ALCHEMY_PENDING_TRANSACTIONS_EVENT_TYPE:return s=>this.emit({method:e.AlchemySubscription.PENDING_TRANSACTIONS,fromAddress:t.fromAddress,toAddress:t.toAddress,hashesOnly:t.hashesOnly},s);case e.ALCHEMY_MINED_TRANSACTIONS_EVENT_TYPE:return s=>this.emit({method:e.AlchemySubscription.MINED_TRANSACTIONS,addresses:t.addresses,includeRemoved:t.includeRemoved,hashesOnly:t.hashesOnly},s);case"block":return t=>{const s=e.BigNumber.from(t.number).toNumber();this._emitted.block=s,this.emit("block",s)};case"filter":return e=>{null==e.removed&&(e.removed=!1),this.emit(t.filter,this.formatter.filterLog(e))};default:throw new Error("Invalid event type to `emitProcessFn()`")}}_off(t,s){if(null==s)return this.removeAllListeners(t);const n=[];let i=!1;const r=e.getAlchemyEventTag(t);return this._events=this._events.filter((e=>e.tag!==r||e.listener!=s||(!!i||(i=!0,n.push(e),!1)))),n.forEach((e=>{this._stopEvent(e)})),this}_removeAllListeners(t){let s=[];if(null==t)s=this._events,this._events=[];else{const n=e.getAlchemyEventTag(t);this._events=this._events.filter((e=>e.tag!==n||(s.push(e),!1)))}return s.forEach((e=>{this._stopEvent(e)})),this}_listenerCount(t){if(!t)return this._events.length;const s=e.getAlchemyEventTag(t);return this._events.filter((e=>e.tag===s)).length}_listeners(t){if(null==t)return this._events.map((e=>e.listener));const s=e.getAlchemyEventTag(t);return this._events.filter((e=>e.tag===s)).map((e=>e.listener))}}const p=1e3,b=2,v=3e4;function y(t,s,n=(()=>!0)){return e.__awaiter$1(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 g(e),!n(t))throw t;e=0===e?p:Math.min(v,b*e)}}))}function g(e){return new Promise((t=>setTimeout(t,e)))}function E(e,t){return Promise.race([e,new Promise(((e,s)=>setTimeout((()=>s(new Error("Timeout"))),t)))])}function k(t){return e.fromHex(t.number)}function _(t){return e.fromHex(t.blockNumber)}function w(e,t,s){const n=s(t),i=e.findIndex((e=>s(e)>n-f));-1===i?e.length=0:e.splice(0,i),e.push(t)}exports.AlchemyWebSocketProvider=m;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t,r=require("./index-acaec64d.cjs");function n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}function i(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 o(e,t){if(!e)throw new Error(t)}require("@ethersproject/providers"),require("zustand"),require("@ethersproject/bytes"),require("@ethersproject/properties"),require("@ethersproject/address"),require("@ethersproject/abstract-signer"),require("buffer"),require("@ethersproject/abstract-provider"),require("@ethersproject/contracts"),require("events"),require("@ethersproject/constants"),require("@ethersproject/transactions"),"function"==typeof SuppressedError&&SuppressedError,function(e){e.prod="BLOCTO_SDK",e.dev="BLOCTO_SDK_DEV",e.staging="BLOCTO_SDK_STAGING"}(e||(e={})),function(e){e.ETHEREUM="ethereum",e.APTOS="aptos"}(t||(t={}));const s={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"},a={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},u={prod:e.prod,staging:e.staging,dev:e.dev},c={1:e.prod,2:e.dev,3:e.dev,4:e.dev,5:e.staging},h={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 d;!function(e){e.Mainnet="mainnet",e.Testnet="testnet",e.Devnet="devnet",e.Testing="testing",e.Premainnet="premainnet"}(d||(d={}));const l={1:d.Mainnet,2:d.Testnet,3:d.Devnet,4:d.Testing,5:d.Premainnet},f={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"},p=["connect","disconnect","message","chainChanged","accountsChanged"],v="00000000-0000-0000-0000-000000000000",g="0.9.1";class y{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,p.forEach((e=>{this.eventListeners[e]=[]})),this.appId=v}request(e){return n(this,void 0,void 0,(function*(){}))}on(e,t){p.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 m(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 w(e){document.body.appendChild(e)}function b(e){const t=e&&e.parentNode;t&&t.removeChild instanceof Function&&t.removeChild(e)}var E=(e,t,r=window)=>{r.addEventListener(e,(function n(i){t(i,(()=>r.removeEventListener(e,n)))}))};const S="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]}},_=(()=>{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:S,A=(e,t=null)=>{const r=_.getItem(e);try{return r&&JSON.parse(r)||t}catch(e){return r||t}},O=(e,t)=>_.setItem(e,"string"==typeof t?t:JSON.stringify(t)),R=e=>{O(e,""),_.removeItem(e)},I=e=>{const t=A(e,null);return t?(new Date).getTime()>t.expiry||t.v!==g?(R(e),null):null==t?void 0:t.data:null},P=(e,t,r)=>{var n,i,o;const s=A(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:g};O(e,a)},T=(e,t)=>{var r,n,i;return(null===(r=I(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=I(e))||void 0===n?void 0:n.accounts)||void 0===i?void 0:i[t])||null:(R(e),null)},C=(e,t)=>{var r,n,i;return(null===(r=I(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=I(e))||void 0===n?void 0:n.evm)||void 0===i?void 0:i[t])||null:(R(e),null)},N=(e,t,r)=>{P(e,{evm:{[t]:r}})},j=e=>{const t=A(e);t&&(t.data.evm={},O(e,t))};function D(e,t,r){return n(this,void 0,void 0,(function*(){if(403!==e.status&&401!==e.status||(r&&r(),R(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 k=e=>/\S+@\S+\.\S+/.test(e);var x;!function(e){e.INVALID_TRANSACTION="Invalid transaction",e.INVALID_TRANSACTIONS="Invalid transactions",e.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'}(x||(x={}));var L="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},M=[],U=[],K="undefined"!=typeof Uint8Array?Uint8Array:Array,B=!1;function q(){B=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)M[t]=e[t],U[e.charCodeAt(t)]=t;U["-".charCodeAt(0)]=62,U["_".charCodeAt(0)]=63}function $(e,t,r){for(var n,i,o=[],s=t;s<r;s+=3)n=(e[s]<<16)+(e[s+1]<<8)+e[s+2],o.push(M[(i=n)>>18&63]+M[i>>12&63]+M[i>>6&63]+M[63&i]);return o.join("")}function V(e){var t;B||q();for(var r=e.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;a<u;a+=s)o.push($(e,a,a+s>u?u:a+s));return 1===n?(t=e[r-1],i+=M[t>>2],i+=M[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=M[t>>10],i+=M[t>>4&63],i+=M[t<<2&63],i+="="),o.push(i),o.join("")}function Y(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,h=-7,d=r?i-1:0,l=r?-1:1,f=e[t+d];for(d+=l,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+e[t+d],d+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+e[t+d],d+=l,h-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=c}return(f?-1:1)*s*Math.pow(2,o-n)}function F(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,h=(1<<c)-1,d=h>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+d>=1?l/u:l*Math.pow(2,1-d))*u>=2&&(s++,u/=2),s+d>=h?(a=0,s=h):s+d>=1?(a=(t*u-1)*Math.pow(2,i),s+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;e[r+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+f]=255&s,f+=p,s/=256,c-=8);e[r+f-p]|=128*v}var z={}.toString,J=Array.isArray||function(e){return"[object Array]"==z.call(e)};function G(){return W.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function H(e,t){if(G()<t)throw new RangeError("Invalid typed array length");return W.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=W.prototype:(null===e&&(e=new W(t)),e.length=t),e}function W(e,t,r){if(!(W.TYPED_ARRAY_SUPPORT||this instanceof W))return new W(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 Q(this,e)}return X(this,e,t,r)}function X(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);W.TYPED_ARRAY_SUPPORT?(e=t).__proto__=W.prototype:e=ee(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!W.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|ne(t,r);e=H(e,n);var i=e.write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(re(t)){var r=0|te(t.length);return 0===(e=H(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?H(e,0):ee(e,t);if("Buffer"===t.type&&J(t.data))return ee(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function Z(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 Q(e,t){if(Z(t),e=H(e,t<0?0:0|te(t)),!W.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function ee(e,t){var r=t.length<0?0:0|te(t.length);e=H(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function te(e){if(e>=G())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+G().toString(16)+" bytes");return 0|e}function re(e){return!(null==e||!e._isBuffer)}function ne(e,t){if(re(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 Ce(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Ne(e).length;default:if(n)return Ce(e).length;t=(""+t).toLowerCase(),n=!0}}function ie(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 we(this,t,r);case"utf8":case"utf-8":return ve(this,t,r);case"ascii":return ye(this,t,r);case"latin1":case"binary":return me(this,t,r);case"base64":return pe(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return be(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function oe(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function se(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=W.from(t,n)),re(t))return 0===t.length?-1:ae(e,t,r,n,i);if("number"==typeof t)return t&=255,W.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):ae(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ae(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var h=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===u)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var d=!0,l=0;l<u;l++)if(c(e,o+l)!==c(t,l)){d=!1;break}if(d)return o}return-1}function 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 ce(e,t,r,n){return je(Ce(t,e.length-r),e,r,n)}function he(e,t,r,n){return je(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function de(e,t,r,n){return he(e,t,r,n)}function le(e,t,r,n){return je(Ne(t),e,r,n)}function fe(e,t,r,n){return je(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 pe(e,t,r){return 0===t&&r===e.length?V(e):V(e.slice(t,r))}function ve(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,u,c=e[i],h=null,d=c>239?4:c>223?3:c>191?2:1;if(i+d<=r)switch(d){case 1:c<128&&(h=c);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&c)<<6|63&o)>127&&(h=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,d=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=d}return function(e){var t=e.length;if(t<=ge)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=ge));return r}(n)}W.TYPED_ARRAY_SUPPORT=void 0===L.TYPED_ARRAY_SUPPORT||L.TYPED_ARRAY_SUPPORT,G(),W.poolSize=8192,W._augment=function(e){return e.__proto__=W.prototype,e},W.from=function(e,t,r){return X(null,e,t,r)},W.TYPED_ARRAY_SUPPORT&&(W.prototype.__proto__=Uint8Array.prototype,W.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&W[Symbol.species]),W.alloc=function(e,t,r){return function(e,t,r,n){return Z(t),t<=0?H(e,t):void 0!==r?"string"==typeof n?H(e,t).fill(r,n):H(e,t).fill(r):H(e,t)}(null,e,t,r)},W.allocUnsafe=function(e){return Q(null,e)},W.allocUnsafeSlow=function(e){return Q(null,e)},W.isBuffer=function(e){return null!=e&&(!!e._isBuffer||De(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&De(e.slice(0,0))}(e))},W.compare=function(e,t){if(!re(e)||!re(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},W.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}},W.concat=function(e,t){if(!J(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return W.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=W.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!re(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},W.byteLength=ne,W.prototype._isBuffer=!0,W.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)oe(this,t,t+1);return this},W.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)oe(this,t,t+3),oe(this,t+1,t+2);return this},W.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)oe(this,t,t+7),oe(this,t+1,t+6),oe(this,t+2,t+5),oe(this,t+3,t+4);return this},W.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?ve(this,0,e):ie.apply(this,arguments)},W.prototype.equals=function(e){if(!re(e))throw new TypeError("Argument must be a Buffer");return this===e||0===W.compare(this,e)},W.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+">"},W.prototype.compare=function(e,t,r,n,i){if(!re(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(o,s),u=this.slice(n,i),c=e.slice(t,r),h=0;h<a;++h)if(u[h]!==c[h]){o=u[h],s=c[h];break}return o<s?-1:s<o?1:0},W.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},W.prototype.indexOf=function(e,t,r){return se(this,e,t,r,!0)},W.prototype.lastIndexOf=function(e,t,r){return se(this,e,t,r,!1)},W.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 ce(this,e,t,r);case"ascii":return he(this,e,t,r);case"latin1":case"binary":return de(this,e,t,r);case"base64":return le(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fe(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},W.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ge=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 me(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 we(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+=Te(e[o]);return i}function be(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 Ee(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 Se(e,t,r,n,i,o){if(!re(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 _e(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 Ae(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 Oe(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 Re(e,t,r,n,i){return i||Oe(e,0,r,4),F(e,t,r,n,23,4),r+4}function Ie(e,t,r,n,i){return i||Oe(e,0,r,8),F(e,t,r,n,52,8),r+8}W.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),W.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=W.prototype;else{var i=t-e;r=new W(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},W.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||Ee(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},W.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||Ee(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},W.prototype.readUInt8=function(e,t){return t||Ee(e,1,this.length),this[e]},W.prototype.readUInt16LE=function(e,t){return t||Ee(e,2,this.length),this[e]|this[e+1]<<8},W.prototype.readUInt16BE=function(e,t){return t||Ee(e,2,this.length),this[e]<<8|this[e+1]},W.prototype.readUInt32LE=function(e,t){return t||Ee(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},W.prototype.readUInt32BE=function(e,t){return t||Ee(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},W.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||Ee(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},W.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||Ee(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},W.prototype.readInt8=function(e,t){return t||Ee(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},W.prototype.readInt16LE=function(e,t){t||Ee(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},W.prototype.readInt16BE=function(e,t){t||Ee(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},W.prototype.readInt32LE=function(e,t){return t||Ee(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},W.prototype.readInt32BE=function(e,t){return t||Ee(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},W.prototype.readFloatLE=function(e,t){return t||Ee(e,4,this.length),Y(this,e,!0,23,4)},W.prototype.readFloatBE=function(e,t){return t||Ee(e,4,this.length),Y(this,e,!1,23,4)},W.prototype.readDoubleLE=function(e,t){return t||Ee(e,8,this.length),Y(this,e,!0,52,8)},W.prototype.readDoubleBE=function(e,t){return t||Ee(e,8,this.length),Y(this,e,!1,52,8)},W.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||Se(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},W.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||Se(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},W.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,1,255,0),W.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},W.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,65535,0),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):_e(this,e,t,!0),t+2},W.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,65535,0),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):_e(this,e,t,!1),t+2},W.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,4294967295,0),W.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):Ae(this,e,t,!0),t+4},W.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,4294967295,0),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Ae(this,e,t,!1),t+4},W.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);Se(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},W.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);Se(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},W.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,1,127,-128),W.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},W.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,32767,-32768),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):_e(this,e,t,!0),t+2},W.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,32767,-32768),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):_e(this,e,t,!1),t+2},W.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,2147483647,-2147483648),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):Ae(this,e,t,!0),t+4},W.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Ae(this,e,t,!1),t+4},W.prototype.writeFloatLE=function(e,t,r){return Re(this,e,t,!0,r)},W.prototype.writeFloatBE=function(e,t,r){return Re(this,e,t,!1,r)},W.prototype.writeDoubleLE=function(e,t,r){return Ie(this,e,t,!0,r)},W.prototype.writeDoubleBE=function(e,t,r){return Ie(this,e,t,!1,r)},W.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||!W.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},W.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&&!W.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=re(e)?e:Ce(new W(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var Pe=/[^+\/0-9A-Za-z-_]/g;function Te(e){return e<16?"0"+e.toString(16):e.toString(16)}function Ce(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 Ne(e){return function(e){var t,r,n,i,o,s;B||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 K(3*a/4-o),n=o>0?a-4:a;var u=0;for(t=0,r=0;t<n;t+=4,r+=3)i=U[e.charCodeAt(t)]<<18|U[e.charCodeAt(t+1)]<<12|U[e.charCodeAt(t+2)]<<6|U[e.charCodeAt(t+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=U[e.charCodeAt(t)]<<2|U[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=U[e.charCodeAt(t)]<<10|U[e.charCodeAt(t+1)]<<4|U[e.charCodeAt(t+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Pe,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function je(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 De(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}const ke=e=>"string"==typeof e&&/^0x[0-9A-Fa-f]*$/.test(e),xe=e=>e&&"object"==typeof e&&"from"in e?e.value&&!ke(e.value)?{isValid:!1,invalidMsg:x.INVALID_TRANSACTION_VALUE}:{isValid:!0}:{isValid:!1,invalidMsg:x.INVALID_TRANSACTION};function Le(){return n(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 Me={};function Ue(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ke(e){return Ke="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},Ke(e)}function Be(e){var t=function(e,t){if("object"!==Ke(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==Ke(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===Ke(t)?t:String(t)}function qe(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,Be(n.key),n)}}function $e(e,t,r){return t&&qe(e.prototype,t),r&&qe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ve(e,t){return Ve=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ve(e,t)}function Ye(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&&Ve(e,t)}function Fe(e,t){if(t&&("object"===Ke(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 ze(e){return ze=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ze(e)}function Je(e,t,r){return Je=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&&Ve(i,r.prototype),i},Je.apply(null,arguments)}function Ge(e){var t="function"==typeof Map?new Map:void 0;return Ge=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 Je(e,arguments,ze(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ve(n,e)},Ge(e)}var He={},We=rt;rt.default=rt,rt.stable=st,rt.stableStringify=st;var Xe="[...]",Ze="[Circular]",Qe=[],et=[];function tt(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function rt(e,t,r,n){var i;void 0===n&&(n=tt()),it(e,"",0,[],void 0,0,n);try{i=0===et.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!==Qe.length;){var o=Qe.pop();4===o.length?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function nt(e,t,r,n){var i=Object.getOwnPropertyDescriptor(n,r);void 0!==i.get?i.configurable?(Object.defineProperty(n,r,{value:e}),Qe.push([n,r,t,i])):et.push([t,r,e]):(n[r]=e,Qe.push([n,r,t]))}function it(e,t,r,n,i,o,s){var a;if(o+=1,"object"===Ke(e)&&null!==e){for(a=0;a<n.length;a++)if(n[a]===e)return void nt(Ze,e,t,i);if(void 0!==s.depthLimit&&o>s.depthLimit)return void nt(Xe,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void nt(Xe,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)it(e[a],a,a,n,e,o,s);else{var u=Object.keys(e);for(a=0;a<u.length;a++){var c=u[a];it(e[c],c,a,n,e,o,s)}}n.pop()}}function ot(e,t){return e<t?-1:e>t?1:0}function st(e,t,r,n){void 0===n&&(n=tt());var i,o=at(e,"",0,[],void 0,0,n)||e;try{i=0===et.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!==Qe.length;){var s=Qe.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return i}function at(e,t,r,n,i,o,s){var a;if(o+=1,"object"===Ke(e)&&null!==e){for(a=0;a<n.length;a++)if(n[a]===e)return void nt(Ze,e,t,i);try{if("function"==typeof e.toJSON)return}catch(e){return}if(void 0!==s.depthLimit&&o>s.depthLimit)return void nt(Xe,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void nt(Xe,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)at(e[a],a,a,n,e,o,s);else{var u={},c=Object.keys(e).sort(ot);for(a=0;a<c.length;a++){var h=c[a];at(e[h],h,a,n,e,o,s),u[h]=e[h]}if(void 0===i)return u;Qe.push([i,t,e]),i[t]=u}n.pop()}}function ut(e){return e=void 0!==e?e:function(e,t){return t},function(t,r){if(et.length>0)for(var n=0;n<et.length;n++){var i=et[n];if(i[1]===t&&i[0]===r){r=i[2],et.splice(n,1);break}}return e.call(this,t,r)}}function ct(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=ze(e);if(t){var i=ze(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return Fe(this,r)}}Object.defineProperty(He,"__esModule",{value:!0}),He.EthereumProviderError=He.EthereumRpcError=void 0;var ht=We,dt=function(e){Ye(r,Ge(Error));var t=ct(r);function r(e,n,i){var o;if(Ue(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 $e(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 ht.default(this.serialize(),ft,2)}}]),r}();He.EthereumRpcError=dt;var lt=function(e){Ye(r,dt);var t=ct(r);function r(e,n,i){if(Ue(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 $e(r)}();function ft(e,t){if("[Circular]"!==t)return t}He.EthereumProviderError=lt;var pt={},vt={};function gt(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=[],u=!0,c=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return gt(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)?gt(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(vt,"__esModule",{value:!0}),vt.errorValues=vt.errorCodes=void 0,vt.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}},vt.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=vt,r=He,n=t.errorCodes.rpc.internal,i="Unspecified error message. This is a bug, please report it.",o={code:n,message:s(n)};function s(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i;if(Number.isInteger(r)){var o=r.toString();if(h(t.errorValues,o))return t.errorValues[o].message;if(u(r))return e.JSON_RPC_SERVER_ERROR_MESSAGE}return n}function a(e){if(!Number.isInteger(e))return!1;var r=e.toString();return!!t.errorValues[r]||!!u(e)}function u(e){return e>=-32099&&e<=-32e3}function c(e){return e&&"object"===Ke(e)&&!Array.isArray(e)?Object.assign({},e):e}function h(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.JSON_RPC_SERVER_ERROR_MESSAGE="Unspecified server error.",e.getMessageFromCode=s,e.isValidCode=a,e.serializeError=function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=i.fallbackError,d=void 0===u?o:u,l=i.shouldIncludeStack,f=void 0!==l&&l;if(!d||!Number.isInteger(d.code)||"string"!=typeof d.message)throw new Error("Must provide fallback error with integer number code and string message.");if(e instanceof r.EthereumRpcError)return e.serialize();var p={};if(e&&"object"===Ke(e)&&!Array.isArray(e)&&h(e,"code")&&a(e.code)){var v=e;p.code=v.code,v.message&&"string"==typeof v.message?(p.message=v.message,h(v,"data")&&(p.data=v.data)):(p.message=s(p.code),p.data={originalError:c(e)})}else{p.code=d.code;var g=null===(t=e)||void 0===t?void 0:t.message;p.message=g&&"string"==typeof g?g:d.message,p.data={originalError:c(e)}}var y=null===(n=e)||void 0===n?void 0:n.stack;return f&&e&&y&&"string"==typeof y&&(p.stack=y),p}}(pt);var mt={};Object.defineProperty(mt,"__esModule",{value:!0}),mt.ethErrors=void 0;var wt,bt,Et,St,_t,At=He,Ot=pt,Rt=vt;function It(e,t){var r=yt(Tt(t),2),n=r[0],i=r[1];return new At.EthereumRpcError(e,n||Ot.getMessageFromCode(e),i)}function Pt(e,t){var r=yt(Tt(t),2),n=r[0],i=r[1];return new At.EthereumProviderError(e,n||Ot.getMessageFromCode(e),i)}function Tt(e){if(e){if("string"==typeof e)return[e];if("object"===Ke(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 Ct(e){return e?"number"==typeof e?e:e.startsWith("0x")?parseInt(e,16):parseInt(e,10):1}mt.ethErrors={rpc:{parse:function(e){return It(Rt.errorCodes.rpc.parse,e)},invalidRequest:function(e){return It(Rt.errorCodes.rpc.invalidRequest,e)},invalidParams:function(e){return It(Rt.errorCodes.rpc.invalidParams,e)},methodNotFound:function(e){return It(Rt.errorCodes.rpc.methodNotFound,e)},internal:function(e){return It(Rt.errorCodes.rpc.internal,e)},server:function(e){if(!e||"object"!==Ke(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 It(t,e)},invalidInput:function(e){return It(Rt.errorCodes.rpc.invalidInput,e)},resourceNotFound:function(e){return It(Rt.errorCodes.rpc.resourceNotFound,e)},resourceUnavailable:function(e){return It(Rt.errorCodes.rpc.resourceUnavailable,e)},transactionRejected:function(e){return It(Rt.errorCodes.rpc.transactionRejected,e)},methodNotSupported:function(e){return It(Rt.errorCodes.rpc.methodNotSupported,e)},limitExceeded:function(e){return It(Rt.errorCodes.rpc.limitExceeded,e)}},provider:{userRejectedRequest:function(e){return Pt(Rt.errorCodes.provider.userRejectedRequest,e)},unauthorized:function(e){return Pt(Rt.errorCodes.provider.unauthorized,e)},unsupportedMethod:function(e){return Pt(Rt.errorCodes.provider.unsupportedMethod,e)},disconnected:function(e){return Pt(Rt.errorCodes.provider.disconnected,e)},chainDisconnected:function(e){return Pt(Rt.errorCodes.provider.chainDisconnected,e)},custom:function(e){if(!e||"object"!==Ke(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 At.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=He;Object.defineProperty(e,"EthereumRpcError",{enumerable:!0,get:function(){return t.EthereumRpcError}}),Object.defineProperty(e,"EthereumProviderError",{enumerable:!0,get:function(){return t.EthereumProviderError}});var r=pt;Object.defineProperty(e,"serializeError",{enumerable:!0,get:function(){return r.serializeError}}),Object.defineProperty(e,"getMessageFromCode",{enumerable:!0,get:function(){return r.getMessageFromCode}});var n=mt;Object.defineProperty(e,"ethErrors",{enumerable:!0,get:function(){return n.ethErrors}});var i=vt;Object.defineProperty(e,"errorCodes",{enumerable:!0,get:function(){return i.errorCodes}})}(Me);class Nt extends y{get existedSDK(){if("undefined"!=typeof window)return window.ethereum}constructor(t){var r;if(super(),wt.add(this),this.networkVersion="1",this.off=this.removeListener,this.injectedWalletServer=t.walletServer,this._blocto={sessionKeyEnv:e.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",switchableNetwork:{}},this.appId=t.appId||v,"chainId"in t){const{chainId:e,rpc:r}=t;o(e,"'chainId' is required"),this.networkVersion=`${Ct(e)}`,this.chainId=`0x${Ct(e).toString(16)}`,this.rpc=r||s[this.networkVersion],o(this.rpc,"'rpc' is required")}else{const{defaultChainId:e,switchableChains:n}=t;o(e,"'defaultChainId' is required"),this.networkVersion=`${Ct(e)}`,this.chainId=`0x${Ct(e).toString(16)}`;const i=n.find((t=>Ct(t.chainId)===Ct(e)));if(!i)throw Me.ethErrors.provider.custom({code:1001,message:`Chain ${e} is not in switchableChains list`});this.rpc=(null===(r=i.rpcUrls)||void 0===r?void 0:r[0])||s[this.networkVersion],o(this.rpc,"'rpc' is required"),this._blocto.unloadedNetwork=n}}send(e,t){return n(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 n(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,u=Math.floor(1e4*Math.random()),c=a?[...o]:[this.request(s),...o];Promise.allSettled(c).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)||u+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 Me.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 n(this,void 0,void 0,(function*(){return this.request({method:"eth_sendUserOperation",params:[e]})}))}request(e){var t,r,o,s,a,u,c,h;return n(this,void 0,void 0,(function*(){if(Array.isArray(e))return this.sendAsync(e);if(!(null==e?void 0:e.method))throw Me.ethErrors.rpc.invalidRequest();const{blockchainName:n,switchableNetwork:d,sessionKeyEnv:l}=yield i(this,wt,"m",bt).call(this);if(null===(t=this.existedSDK)||void 0===t?void 0:t.isBlocto){if("wallet_switchEthereumChain"===e.method){if(!(null===(o=null===(r=null==e?void 0:e.params)||void 0===r?void 0:r[0])||void 0===o?void 0:o.chainId))throw Me.ethErrors.rpc.invalidParams();return this.existedSDK.request(e).then((()=>{var t,r,n;return this.networkVersion=`${Ct(null===(t=null==e?void 0:e.params)||void 0===t?void 0:t[0].chainId)}`,this.chainId=`0x${Ct(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 Me.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===(u=null===(a=null==e?void 0:e.params)||void 0===a?void 0:a[0])||void 0===u?void 0:u.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return C(l,n)||[]}if(!C(l,n)){const t=null===(c=null==e?void 0:e.params)||void 0===c?void 0:c[0];"eth_requestAccounts"===e.method&&k(t)?yield this.enable(t):yield this.enable()}try{let t=null,r=null;switch(e.method){case"eth_requestAccounts":r=yield this.fetchAccounts();break;case"eth_coinbase":r=null===(h=C(l,n))||void 0===h?void 0:h[0];break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":r=yield this.handleSign(e);break;case"eth_sign":throw Me.ethErrors.rpc.methodNotFound("Method Not Supported: eth_sign has been disabled");case"eth_sendTransaction":r=yield this.handleSendTransaction(e);break;case"wallet_sendMultiCallTransaction":r=yield this.handleSendBatchTransaction(e);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw Me.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.method);case"eth_sendUserOperation":r=yield this.handleSendUserOperation(e);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":r=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 Me.ethErrors.rpc.internal(e)}return t?t.result:r}catch(e){throw Me.ethErrors.rpc.internal(null==e?void 0:e.message)}}))}bloctoApi(e,t){var r;return n(this,void 0,void 0,(function*(){const{walletServer:n,blockchainName:o,sessionKeyEnv:s}=yield i(this,wt,"m",bt).call(this),a=(null===(r=I(s))||void 0===r?void 0:r.code)||"";if(!a)throw Me.ethErrors.provider.unauthorized();return fetch(`${n}/api/${o}${e}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},t)).then((e=>D(e,s,(()=>{var e;null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e(Me.ethErrors.provider.disconnected())))})))).catch((e=>{throw"unsupported_method"===(null==e?void 0:e.error_code)?Me.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.message):Me.ethErrors.rpc.server({code:-32005,message:`Blocto server error: ${e.message}`})}))}))}responseListener(e,t){return n(this,void 0,void 0,(function*(){const{walletServer:r}=yield i(this,wt,"m",bt).call(this);return new Promise(((n,i)=>E("message",((o,s)=>{const a=o;a.origin===r&&"ETH:FRAME:RESPONSE"===a.data.type&&("APPROVED"===a.data.status&&(s(),b(e),n(a.data[t])),"DECLINED"===a.data.status&&(s(),b(e),"incorrect_session_id"===a.data.errorCode&&this.handleDisconnect(),i(Me.ethErrors.provider.userRejectedRequest(a.data.errorMessage)))),"ETH:FRAME:CLOSE"===a.data.type&&(s(),b(e),i(Me.ethErrors.provider.userRejectedRequest("User declined the request")))}))))}))}setIframe(e,t){return n(this,void 0,void 0,(function*(){if("undefined"==typeof window)throw Me.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:r,blockchainName:n}=yield i(this,wt,"m",bt).call(this),o=m(`${r}/${this.appId}/${t||n}${e}`);return w(o),o}))}enable(e){var r;return n(this,void 0,void 0,(function*(){if("undefined"==typeof window)throw Me.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:n,blockchainName:o,sessionKeyEnv:s}=yield i(this,wt,"m",bt).call(this);if(null===(r=this.existedSDK)||void 0===r?void 0:r.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}]}),N(s,o,[this.existedSDK.address])),new Promise(((e,t)=>setTimeout((()=>this.existedSDK.enable().then(e).catch(t)),10)));const a=C(s,o);if(a)return new Promise((e=>{e(a)}));const u=new URLSearchParams;u.set("l6n",window.location.origin),u.set("v",g);const c=e&&k(e)?`/${e}`:"",h=yield this.setIframe(`/authn${c}?${u.toString()}`);return new Promise(((e,r)=>{E("message",((i,a)=>{var u,c;const d=i;d.origin===n&&("ETH:FRAME:RESPONSE"===d.data.type&&(a(),b(h),null===(u=this.eventListeners)||void 0===u||u.connect.forEach((e=>e({chainId:this.chainId}))),P(s,{code:d.data.code,evm:{[o]:[d.data.addr]}},d.data.exp),(null===(c=d.data)||void 0===c?void 0:c.isAccountChanged)&&postMessage({originChain:t.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),E("message",((e,r)=>{var n,i,o;const s=e,a="BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(n=s.data)||void 0===n?void 0:n.type),u=(null===(i=s.data)||void 0===i?void 0:i.originChain)!==t.ETHEREUM;a&&(null===(o=this.eventListeners)||void 0===o||o.accountsChanged.forEach((e=>e([d.data.addr])))),a&&u&&(this.handleDisconnect(),r())})),e([d.data.addr])),"ETH:FRAME:CLOSE"===d.data.type&&(a(),b(h),r(Me.ethErrors.provider.userRejectedRequest())))}))}))}))}fetchAccounts(){return n(this,void 0,void 0,(function*(){i(this,wt,"m",St).call(this);const{blockchainName:e,sessionKeyEnv:t}=yield i(this,wt,"m",bt).call(this),{accounts:r}=yield this.bloctoApi("/accounts");return N(t,e,r),r}))}handleReadRequests(e){return n(this,void 0,void 0,(function*(){return i(this,wt,"m",St).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 Me.ethErrors.rpc.internal(e)}))}))}handleSign({method:e,params:t}){return n(this,void 0,void 0,(function*(){let r="";if(Array.isArray(t))if("personal_sign"===e)r=ke(t[0])?t[0].slice(2):(n=t[0],W.from(n,"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(ke(e.chainId))throw Me.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must be a number`);if(Ct(e.chainId)!==Ct(this.chainId))throw Me.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must match the active chainId "${Ct(this.chainId)}"`)}var n;i(this,wt,"m",St).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,r;return n(this,void 0,void 0,(function*(){if(!e)throw Me.ethErrors.rpc.invalidParams();const{walletServer:n,blockchainName:o,sessionKeyEnv:s,switchableNetwork:a}=yield i(this,wt,"m",bt).call(this),u=null===(t=C(s,o))||void 0===t?void 0:t[0],c=Ct(this.chainId),h=Ct(e);if(c===h)return null;if(!a[h])throw Me.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:""}),!u)return null===(r=this.eventListeners)||void 0===r||r.chainChanged.forEach((e=>e(this.chainId))),yield i(this,wt,"m",bt).call(this),null;if(a[h].wallet_web_url!==a[c].wallet_web_url)return this.enable().then((([e])=>{var t;return e!==u&&(null===(t=this.eventListeners)||void 0===t||t.accountsChanged.forEach((t=>t([e])))),this.eventListeners.chainChanged.forEach((e=>e(this.chainId))),null})).catch((e=>{throw this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),i(this,wt,"m",bt).call(this),e}));const d=yield this.setIframe(`/switch-chain?to=${a[h].name}`,a[c].name);return new Promise(((e,t)=>{E("message",((r,o)=>{var l,f,p,v,g,y,m,w;const E=r;E.origin===n&&("ETH:FRAME:RESPONSE"===E.data.type&&(o(),b(d),(null===(l=E.data)||void 0===l?void 0:l.addr)&&u&&(P(s,{code:null===(f=E.data)||void 0===f?void 0:f.code,evm:{[a[h].name]:[E.data.addr]}},null===(p=E.data)||void 0===p?void 0:p.exp),E.data.addr!==u&&(null===(v=this.eventListeners)||void 0===v||v.accountsChanged.forEach((e=>e([E.data.addr]))))),null===(g=this.eventListeners)||void 0===g||g.chainChanged.forEach((e=>e(this.chainId))),i(this,wt,"m",bt).call(this),e(null)),"ETH:FRAME:CLOSE"===E.data.type&&(o(),b(d),(null===(y=E.data)||void 0===y?void 0:y.hasApprovedSwitchChain)?(null===(m=this.eventListeners)||void 0===m||m.chainChanged.forEach((e=>e(this.chainId))),j(s),null===(w=this.eventListeners)||void 0===w||w.disconnect.forEach((e=>e(Me.ethErrors.provider.disconnected()))),i(this,wt,"m",bt).call(this),e(null)):(this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),i(this,wt,"m",bt).call(this),t(Me.ethErrors.provider.userRejectedRequest()))))}))}))}))}handleSendTransaction(e){var t;return n(this,void 0,void 0,(function*(){i(this,wt,"m",St).call(this);const{isValid:r,invalidMsg:n}=xe(null===(t=e.params)||void 0===t?void 0:t[0]);if(!r)throw Me.ethErrors.rpc.invalidParams(n);return i(this,wt,"m",_t).call(this,e.params)}))}handleSendBatchTransaction(e){return n(this,void 0,void 0,(function*(){let t,r;i(this,wt,"m",St).call(this),Array.isArray(e.params)&&e.params.length>=2?[t,r]=e.params:(t=e.params,r=!1);const n=r||!1,{isValid:o,invalidMsg:s}=(e=>{if(!Array.isArray(e))return{isValid:!1,invalidMsg:x.INVALID_TRANSACTIONS};for(let t=0;t<e.length;t++){const{isValid:r,invalidMsg:n}=xe(e[t]);if(!r)return{isValid:r,invalidMsg:n}}return{isValid:!0}})(t);if(!o)throw Me.ethErrors.rpc.invalidParams(s);return i(this,wt,"m",_t).call(this,t,n)}))}handleSendUserOperation(e){return n(this,void 0,void 0,(function*(){i(this,wt,"m",St).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 n(this,void 0,void 0,(function*(){return i(this,wt,"m",St).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},e))})}))}handleDisconnect(){var e,t;return n(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 i(this,wt,"m",bt).call(this);j(r),null===(t=this.eventListeners)||void 0===t||t.disconnect.forEach((e=>e(Me.ethErrors.provider.disconnected())))}))}loadSwitchableNetwork(e){return n(this,void 0,void 0,(function*(){if(null==e?void 0:e.length){const t=e.map((({chainId:e,rpcUrls:t})=>{if(!e)throw Me.ethErrors.rpc.invalidParams("Empty chainId");const r=`${Ct(e)}`;if(this._blocto.switchableNetwork[r])return null;const n=(null==t?void 0:t[0])||s[r];if(!n)throw Me.ethErrors.rpc.invalidParams("rpcUrls required");return i(this,wt,"m",Et).call(this,{chainId:r,rpcUrls:[n]})}));return Promise.all(t).then((()=>null))}throw Me.ethErrors.rpc.invalidParams("Empty networkList")}))}supportChainList(){return n(this,void 0,void 0,(function*(){const e=yield Le().catch((e=>{throw Me.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)}}wt=new WeakSet,bt=function(){var e,t;return n(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 Le().catch((e=>{throw Me.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:c}=null!==(t=r[this.networkVersion])&&void 0!==t?t:{};if(!n)throw Me.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);const h=this.injectedWalletServer||a[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:c,network_type:o,wallet_web_url:h,rpc_url:this.rpc}})}),this._blocto}))},Et=function({chainId:e,rpcUrls:t}){var r;return n(this,void 0,void 0,(function*(){yield i(this,wt,"m",bt).call(this);const n=yield Le().catch((e=>{throw Me.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})),{chain_id:o,name:s,display_name:u,network_type:c,blocto_service_environment:h}=null!==(r=n[e])&&void 0!==r?r:{};if(!o)throw Me.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${e} might not be supported yet.`);const d=a[h];this._blocto.switchableNetwork[o]={name:s,display_name:u,network_type:c,wallet_web_url:d,rpc_url:t[0]}}))},St=function(){var e;if((null===(e=this.existedSDK)||void 0===e?void 0:e.isBlocto)&&Ct(this.existedSDK.chainId)!==Ct(this.chainId))throw Me.ethErrors.provider.chainDisconnected()},_t=function(e,t=!0){return n(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 jt 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,o(e,"'chainId' is required"),o(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=l[e],this.api=f[e],this.sessionKey=c[e];const n=h[e];this.appId=r||v,this.server=t||n||""}get publicAccount(){var e;return{address:(null===(e=T(this.sessionKey,t.APTOS))||void 0===e?void 0:e[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return n(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){var e;return n(this,void 0,void 0,(function*(){return!!(null===(e=T(this.sessionKey,t.APTOS))||void 0===e?void 0:e.length)}))}signTransaction(e){var r;return n(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signTransaction(e);if((yield this.isConnected())||(yield this.connect()),!(null===(r=T(this.sessionKey,t.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){var e;return n(this,void 0,void 0,(function*(){var r,n;this.existedSDK?yield this.existedSDK.disconnect():(r=this.sessionKey,n=t.APTOS,P(r,{accounts:{[n]:void 0}}),null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e({code:4900,message:"Wallet disconnected"}))))}))}signAndSubmitTransaction(e,r={}){var i,o;return n(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signAndSubmitTransaction(e,r);if((yield this.isConnected())||(yield this.connect()),!(null===(i=T(this.sessionKey,t.APTOS))||void 0===i?void 0:i.length))throw new Error("Fail to get account");const n=(null===(o=I(this.sessionKey))||void 0===o?void 0:o.code)||"",{authorizationId:s}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":n},body:JSON.stringify(Object.assign(Object.assign({},e),r))}).then((e=>D(e,this.sessionKey)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const a=m(`${this.server}/${this.appId}/aptos/authz/${s}`);return w(a),new Promise(((e,t)=>E("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),b(a),e({hash:i.data.txHash})),"DECLINED"===i.data.status&&(n(),b(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}signMessage(e){var r,i;return n(this,void 0,void 0,(function*(){const n=(e=>{var t,r;const n=Object.assign({},e),{message:i,nonce:o,address:s,application:a,chainId:u}=e;return"string"!=typeof i&&(n.message=null!==(t=String(i))&&void 0!==t?t:""),"string"!=typeof o&&(n.nonce=null!==(r=String(o))&&void 0!==r?r:""),s&&"boolean"!=typeof s&&(n.address=!!s),a&&"boolean"!=typeof a&&(n.application=!!a),u&&"boolean"!=typeof u&&(n.chainId=!!u),n})(e);if(this.existedSDK)return this.existedSDK.signMessage(n);if((yield this.isConnected())||(yield this.connect()),!(null===(r=T(this.sessionKey,t.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const o=(null===(i=I(this.sessionKey))||void 0===i?void 0:i.code)||"",{signatureId:s}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":o},body:JSON.stringify(n)}).then((e=>D(e,this.sessionKey))),a=m(`${this.server}/${this.appId}/aptos/user-signature/${s}`);return w(a),new Promise(((e,t)=>E("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),b(a),e(i.data)),"DECLINED"===i.data.status&&(n(),b(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}connect(){return n(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,r)=>{var i,o;if("undefined"==typeof window)return r("Currently only supported in browser");if(null===(i=T(this.sessionKey,t.APTOS))||void 0===i?void 0:i.length)return e({address:(null===(o=T(this.sessionKey,t.APTOS))||void 0===o?void 0:o[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const s=encodeURIComponent(window.location.origin),a=m(`${this.server}/${this.appId}/aptos/authn?l6n=${s}&v=${g}}`);w(a),E("message",((i,o)=>n(this,void 0,void 0,(function*(){var n,s,u,c;const h=i;if(h.origin===this.server){if("APTOS:FRAME:RESPONSE"===h.data.type){if(o(),b(a),P(this.sessionKey,{code:h.data.code,accounts:{[t.APTOS]:[h.data.addr]}},h.data.exp),(null===(n=h.data)||void 0===n?void 0:n.isAccountChanged)&&postMessage({originChain:t.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),E("message",((e,r)=>{var n,i;const o=e;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(n=o.data)||void 0===n?void 0:n.type)&&(null===(i=o.data)||void 0===i?void 0:i.originChain)!==t.APTOS&&(this.disconnect(),r())})),!(null===(s=T(this.sessionKey,t.APTOS))||void 0===s?void 0:s.length))return r();try{const{public_keys:r}=yield fetch(`${this.server}/blocto/aptos/accounts/${null===(u=T(this.sessionKey,t.APTOS))||void 0===u?void 0:u[0]}`).then((e=>e.json()));this.publicKey=r||[],e({address:(null===(c=T(this.sessionKey,t.APTOS))||void 0===c?void 0:c[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(e){return r(h)}}"APTOS:FRAME:CLOSE"===h.data.type&&(o(),b(a),r(new Error("User declined the login request")))}}))))}))}))}fetchAddress(){var e;return n(this,void 0,void 0,(function*(){const r=(null===(e=I(this.sessionKey))||void 0===e?void 0:e.code)||"",{accounts:n}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":r}}).then((e=>D(e,this.sessionKey)));var i,o;return i=this.sessionKey,o=t.APTOS,P(i,{accounts:{[o]:n}}),(null==n?void 0:n[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 Dt{constructor({appId:e,ethereum:t,aptos:r}){t&&(this.ethereum=new Nt(Object.assign(Object.assign({},t),{appId:e}))),r&&(this.aptos=new jt(Object.assign(Object.assign({},r),{appId:e})))}}exports.default=function({chainId:e,rpcUrl:t,rpc:n,bloctoParams:i},o){return r.__awaiter(this,void 0,void 0,(function*(){let s;if(!e)throw new Error("chainId is required");t?s=t:e&&n&&(s=n[e]),s||(s="null");const a=new Dt({appId:null==i?void 0:i.appId,ethereum:{chainId:e,rpc:s}}).ethereum;if(!a)throw new Error("No provider");return a.on("connect",o.connect),a.on("disconnect",o.disconnect),a.on("accountsChanged",o.accountsChanged),a.on("chainChanged",o.chainChanged),yield a.request({method:"eth_requestAccounts"}),r.convertWeb3Provider(a)}))};
|
|
1
|
+
"use strict";var e,t,r=require("./index-5fba0284.cjs");function n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}function i(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 o(e,t){if(!e)throw new Error(t)}require("@ethersproject/providers"),require("zustand"),require("@ethersproject/bytes"),require("@ethersproject/properties"),require("@ethersproject/address"),require("@ethersproject/abstract-signer"),require("buffer"),require("@ethersproject/abstract-provider"),require("@ethersproject/contracts"),require("events"),require("@ethersproject/constants"),require("@ethersproject/transactions"),"function"==typeof SuppressedError&&SuppressedError,function(e){e.prod="BLOCTO_SDK",e.dev="BLOCTO_SDK_DEV",e.staging="BLOCTO_SDK_STAGING"}(e||(e={})),function(e){e.ETHEREUM="ethereum",e.APTOS="aptos"}(t||(t={}));const s={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"},a={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},u={prod:e.prod,staging:e.staging,dev:e.dev},c={1:e.prod,2:e.dev,3:e.dev,4:e.dev,5:e.staging},h={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 d;!function(e){e.Mainnet="mainnet",e.Testnet="testnet",e.Devnet="devnet",e.Testing="testing",e.Premainnet="premainnet"}(d||(d={}));const l={1:d.Mainnet,2:d.Testnet,3:d.Devnet,4:d.Testing,5:d.Premainnet},f={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"},p=["connect","disconnect","message","chainChanged","accountsChanged"],v="00000000-0000-0000-0000-000000000000",g="0.9.1";class y{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,p.forEach((e=>{this.eventListeners[e]=[]})),this.appId=v}request(e){return n(this,void 0,void 0,(function*(){}))}on(e,t){p.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 m(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 w(e){document.body.appendChild(e)}function b(e){const t=e&&e.parentNode;t&&t.removeChild instanceof Function&&t.removeChild(e)}var E=(e,t,r=window)=>{r.addEventListener(e,(function n(i){t(i,(()=>r.removeEventListener(e,n)))}))};const S="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]}},_=(()=>{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:S,A=(e,t=null)=>{const r=_.getItem(e);try{return r&&JSON.parse(r)||t}catch(e){return r||t}},O=(e,t)=>_.setItem(e,"string"==typeof t?t:JSON.stringify(t)),R=e=>{O(e,""),_.removeItem(e)},I=e=>{const t=A(e,null);return t?(new Date).getTime()>t.expiry||t.v!==g?(R(e),null):null==t?void 0:t.data:null},P=(e,t,r)=>{var n,i,o;const s=A(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:g};O(e,a)},T=(e,t)=>{var r,n,i;return(null===(r=I(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=I(e))||void 0===n?void 0:n.accounts)||void 0===i?void 0:i[t])||null:(R(e),null)},C=(e,t)=>{var r,n,i;return(null===(r=I(e))||void 0===r?void 0:r.code)?(null===(i=null===(n=I(e))||void 0===n?void 0:n.evm)||void 0===i?void 0:i[t])||null:(R(e),null)},N=(e,t,r)=>{P(e,{evm:{[t]:r}})},j=e=>{const t=A(e);t&&(t.data.evm={},O(e,t))};function D(e,t,r){return n(this,void 0,void 0,(function*(){if(403!==e.status&&401!==e.status||(r&&r(),R(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 k=e=>/\S+@\S+\.\S+/.test(e);var x;!function(e){e.INVALID_TRANSACTION="Invalid transaction",e.INVALID_TRANSACTIONS="Invalid transactions",e.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'}(x||(x={}));var L="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},M=[],U=[],K="undefined"!=typeof Uint8Array?Uint8Array:Array,B=!1;function q(){B=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)M[t]=e[t],U[e.charCodeAt(t)]=t;U["-".charCodeAt(0)]=62,U["_".charCodeAt(0)]=63}function $(e,t,r){for(var n,i,o=[],s=t;s<r;s+=3)n=(e[s]<<16)+(e[s+1]<<8)+e[s+2],o.push(M[(i=n)>>18&63]+M[i>>12&63]+M[i>>6&63]+M[63&i]);return o.join("")}function V(e){var t;B||q();for(var r=e.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;a<u;a+=s)o.push($(e,a,a+s>u?u:a+s));return 1===n?(t=e[r-1],i+=M[t>>2],i+=M[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=M[t>>10],i+=M[t>>4&63],i+=M[t<<2&63],i+="="),o.push(i),o.join("")}function Y(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,h=-7,d=r?i-1:0,l=r?-1:1,f=e[t+d];for(d+=l,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+e[t+d],d+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+e[t+d],d+=l,h-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=c}return(f?-1:1)*s*Math.pow(2,o-n)}function F(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,h=(1<<c)-1,d=h>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+d>=1?l/u:l*Math.pow(2,1-d))*u>=2&&(s++,u/=2),s+d>=h?(a=0,s=h):s+d>=1?(a=(t*u-1)*Math.pow(2,i),s+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;e[r+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+f]=255&s,f+=p,s/=256,c-=8);e[r+f-p]|=128*v}var z={}.toString,J=Array.isArray||function(e){return"[object Array]"==z.call(e)};function G(){return W.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function H(e,t){if(G()<t)throw new RangeError("Invalid typed array length");return W.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=W.prototype:(null===e&&(e=new W(t)),e.length=t),e}function W(e,t,r){if(!(W.TYPED_ARRAY_SUPPORT||this instanceof W))return new W(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 Q(this,e)}return X(this,e,t,r)}function X(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);W.TYPED_ARRAY_SUPPORT?(e=t).__proto__=W.prototype:e=ee(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!W.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|ne(t,r);e=H(e,n);var i=e.write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(re(t)){var r=0|te(t.length);return 0===(e=H(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?H(e,0):ee(e,t);if("Buffer"===t.type&&J(t.data))return ee(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function Z(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 Q(e,t){if(Z(t),e=H(e,t<0?0:0|te(t)),!W.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function ee(e,t){var r=t.length<0?0:0|te(t.length);e=H(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function te(e){if(e>=G())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+G().toString(16)+" bytes");return 0|e}function re(e){return!(null==e||!e._isBuffer)}function ne(e,t){if(re(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 Ce(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Ne(e).length;default:if(n)return Ce(e).length;t=(""+t).toLowerCase(),n=!0}}function ie(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 we(this,t,r);case"utf8":case"utf-8":return ve(this,t,r);case"ascii":return ye(this,t,r);case"latin1":case"binary":return me(this,t,r);case"base64":return pe(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return be(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function oe(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function se(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=W.from(t,n)),re(t))return 0===t.length?-1:ae(e,t,r,n,i);if("number"==typeof t)return t&=255,W.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):ae(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ae(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var h=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===u)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var d=!0,l=0;l<u;l++)if(c(e,o+l)!==c(t,l)){d=!1;break}if(d)return o}return-1}function 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 ce(e,t,r,n){return je(Ce(t,e.length-r),e,r,n)}function he(e,t,r,n){return je(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function de(e,t,r,n){return he(e,t,r,n)}function le(e,t,r,n){return je(Ne(t),e,r,n)}function fe(e,t,r,n){return je(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 pe(e,t,r){return 0===t&&r===e.length?V(e):V(e.slice(t,r))}function ve(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,u,c=e[i],h=null,d=c>239?4:c>223?3:c>191?2:1;if(i+d<=r)switch(d){case 1:c<128&&(h=c);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&c)<<6|63&o)>127&&(h=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,d=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=d}return function(e){var t=e.length;if(t<=ge)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=ge));return r}(n)}W.TYPED_ARRAY_SUPPORT=void 0===L.TYPED_ARRAY_SUPPORT||L.TYPED_ARRAY_SUPPORT,G(),W.poolSize=8192,W._augment=function(e){return e.__proto__=W.prototype,e},W.from=function(e,t,r){return X(null,e,t,r)},W.TYPED_ARRAY_SUPPORT&&(W.prototype.__proto__=Uint8Array.prototype,W.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&W[Symbol.species]),W.alloc=function(e,t,r){return function(e,t,r,n){return Z(t),t<=0?H(e,t):void 0!==r?"string"==typeof n?H(e,t).fill(r,n):H(e,t).fill(r):H(e,t)}(null,e,t,r)},W.allocUnsafe=function(e){return Q(null,e)},W.allocUnsafeSlow=function(e){return Q(null,e)},W.isBuffer=function(e){return null!=e&&(!!e._isBuffer||De(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&De(e.slice(0,0))}(e))},W.compare=function(e,t){if(!re(e)||!re(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},W.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}},W.concat=function(e,t){if(!J(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return W.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=W.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!re(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},W.byteLength=ne,W.prototype._isBuffer=!0,W.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)oe(this,t,t+1);return this},W.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)oe(this,t,t+3),oe(this,t+1,t+2);return this},W.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)oe(this,t,t+7),oe(this,t+1,t+6),oe(this,t+2,t+5),oe(this,t+3,t+4);return this},W.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?ve(this,0,e):ie.apply(this,arguments)},W.prototype.equals=function(e){if(!re(e))throw new TypeError("Argument must be a Buffer");return this===e||0===W.compare(this,e)},W.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+">"},W.prototype.compare=function(e,t,r,n,i){if(!re(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(o,s),u=this.slice(n,i),c=e.slice(t,r),h=0;h<a;++h)if(u[h]!==c[h]){o=u[h],s=c[h];break}return o<s?-1:s<o?1:0},W.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},W.prototype.indexOf=function(e,t,r){return se(this,e,t,r,!0)},W.prototype.lastIndexOf=function(e,t,r){return se(this,e,t,r,!1)},W.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 ce(this,e,t,r);case"ascii":return he(this,e,t,r);case"latin1":case"binary":return de(this,e,t,r);case"base64":return le(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fe(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},W.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ge=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 me(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 we(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+=Te(e[o]);return i}function be(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 Ee(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 Se(e,t,r,n,i,o){if(!re(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 _e(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 Ae(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 Oe(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 Re(e,t,r,n,i){return i||Oe(e,0,r,4),F(e,t,r,n,23,4),r+4}function Ie(e,t,r,n,i){return i||Oe(e,0,r,8),F(e,t,r,n,52,8),r+8}W.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),W.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=W.prototype;else{var i=t-e;r=new W(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},W.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||Ee(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},W.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||Ee(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},W.prototype.readUInt8=function(e,t){return t||Ee(e,1,this.length),this[e]},W.prototype.readUInt16LE=function(e,t){return t||Ee(e,2,this.length),this[e]|this[e+1]<<8},W.prototype.readUInt16BE=function(e,t){return t||Ee(e,2,this.length),this[e]<<8|this[e+1]},W.prototype.readUInt32LE=function(e,t){return t||Ee(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},W.prototype.readUInt32BE=function(e,t){return t||Ee(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},W.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||Ee(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},W.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||Ee(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},W.prototype.readInt8=function(e,t){return t||Ee(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},W.prototype.readInt16LE=function(e,t){t||Ee(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},W.prototype.readInt16BE=function(e,t){t||Ee(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},W.prototype.readInt32LE=function(e,t){return t||Ee(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},W.prototype.readInt32BE=function(e,t){return t||Ee(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},W.prototype.readFloatLE=function(e,t){return t||Ee(e,4,this.length),Y(this,e,!0,23,4)},W.prototype.readFloatBE=function(e,t){return t||Ee(e,4,this.length),Y(this,e,!1,23,4)},W.prototype.readDoubleLE=function(e,t){return t||Ee(e,8,this.length),Y(this,e,!0,52,8)},W.prototype.readDoubleBE=function(e,t){return t||Ee(e,8,this.length),Y(this,e,!1,52,8)},W.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||Se(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},W.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||Se(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},W.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,1,255,0),W.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},W.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,65535,0),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):_e(this,e,t,!0),t+2},W.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,65535,0),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):_e(this,e,t,!1),t+2},W.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,4294967295,0),W.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):Ae(this,e,t,!0),t+4},W.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,4294967295,0),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Ae(this,e,t,!1),t+4},W.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);Se(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},W.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);Se(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},W.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,1,127,-128),W.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},W.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,32767,-32768),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):_e(this,e,t,!0),t+2},W.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,2,32767,-32768),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):_e(this,e,t,!1),t+2},W.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,2147483647,-2147483648),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):Ae(this,e,t,!0),t+4},W.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||Se(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Ae(this,e,t,!1),t+4},W.prototype.writeFloatLE=function(e,t,r){return Re(this,e,t,!0,r)},W.prototype.writeFloatBE=function(e,t,r){return Re(this,e,t,!1,r)},W.prototype.writeDoubleLE=function(e,t,r){return Ie(this,e,t,!0,r)},W.prototype.writeDoubleBE=function(e,t,r){return Ie(this,e,t,!1,r)},W.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||!W.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},W.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&&!W.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=re(e)?e:Ce(new W(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var Pe=/[^+\/0-9A-Za-z-_]/g;function Te(e){return e<16?"0"+e.toString(16):e.toString(16)}function Ce(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 Ne(e){return function(e){var t,r,n,i,o,s;B||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 K(3*a/4-o),n=o>0?a-4:a;var u=0;for(t=0,r=0;t<n;t+=4,r+=3)i=U[e.charCodeAt(t)]<<18|U[e.charCodeAt(t+1)]<<12|U[e.charCodeAt(t+2)]<<6|U[e.charCodeAt(t+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=U[e.charCodeAt(t)]<<2|U[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=U[e.charCodeAt(t)]<<10|U[e.charCodeAt(t+1)]<<4|U[e.charCodeAt(t+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Pe,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function je(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 De(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}const ke=e=>"string"==typeof e&&/^0x[0-9A-Fa-f]*$/.test(e),xe=e=>e&&"object"==typeof e&&"from"in e?e.value&&!ke(e.value)?{isValid:!1,invalidMsg:x.INVALID_TRANSACTION_VALUE}:{isValid:!0}:{isValid:!1,invalidMsg:x.INVALID_TRANSACTION};function Le(){return n(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 Me={};function Ue(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ke(e){return Ke="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},Ke(e)}function Be(e){var t=function(e,t){if("object"!==Ke(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==Ke(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===Ke(t)?t:String(t)}function qe(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,Be(n.key),n)}}function $e(e,t,r){return t&&qe(e.prototype,t),r&&qe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ve(e,t){return Ve=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ve(e,t)}function Ye(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&&Ve(e,t)}function Fe(e,t){if(t&&("object"===Ke(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 ze(e){return ze=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ze(e)}function Je(e,t,r){return Je=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&&Ve(i,r.prototype),i},Je.apply(null,arguments)}function Ge(e){var t="function"==typeof Map?new Map:void 0;return Ge=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 Je(e,arguments,ze(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ve(n,e)},Ge(e)}var He={},We=rt;rt.default=rt,rt.stable=st,rt.stableStringify=st;var Xe="[...]",Ze="[Circular]",Qe=[],et=[];function tt(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function rt(e,t,r,n){var i;void 0===n&&(n=tt()),it(e,"",0,[],void 0,0,n);try{i=0===et.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!==Qe.length;){var o=Qe.pop();4===o.length?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function nt(e,t,r,n){var i=Object.getOwnPropertyDescriptor(n,r);void 0!==i.get?i.configurable?(Object.defineProperty(n,r,{value:e}),Qe.push([n,r,t,i])):et.push([t,r,e]):(n[r]=e,Qe.push([n,r,t]))}function it(e,t,r,n,i,o,s){var a;if(o+=1,"object"===Ke(e)&&null!==e){for(a=0;a<n.length;a++)if(n[a]===e)return void nt(Ze,e,t,i);if(void 0!==s.depthLimit&&o>s.depthLimit)return void nt(Xe,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void nt(Xe,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)it(e[a],a,a,n,e,o,s);else{var u=Object.keys(e);for(a=0;a<u.length;a++){var c=u[a];it(e[c],c,a,n,e,o,s)}}n.pop()}}function ot(e,t){return e<t?-1:e>t?1:0}function st(e,t,r,n){void 0===n&&(n=tt());var i,o=at(e,"",0,[],void 0,0,n)||e;try{i=0===et.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!==Qe.length;){var s=Qe.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return i}function at(e,t,r,n,i,o,s){var a;if(o+=1,"object"===Ke(e)&&null!==e){for(a=0;a<n.length;a++)if(n[a]===e)return void nt(Ze,e,t,i);try{if("function"==typeof e.toJSON)return}catch(e){return}if(void 0!==s.depthLimit&&o>s.depthLimit)return void nt(Xe,e,t,i);if(void 0!==s.edgesLimit&&r+1>s.edgesLimit)return void nt(Xe,e,t,i);if(n.push(e),Array.isArray(e))for(a=0;a<e.length;a++)at(e[a],a,a,n,e,o,s);else{var u={},c=Object.keys(e).sort(ot);for(a=0;a<c.length;a++){var h=c[a];at(e[h],h,a,n,e,o,s),u[h]=e[h]}if(void 0===i)return u;Qe.push([i,t,e]),i[t]=u}n.pop()}}function ut(e){return e=void 0!==e?e:function(e,t){return t},function(t,r){if(et.length>0)for(var n=0;n<et.length;n++){var i=et[n];if(i[1]===t&&i[0]===r){r=i[2],et.splice(n,1);break}}return e.call(this,t,r)}}function ct(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=ze(e);if(t){var i=ze(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return Fe(this,r)}}Object.defineProperty(He,"__esModule",{value:!0}),He.EthereumProviderError=He.EthereumRpcError=void 0;var ht=We,dt=function(e){Ye(r,Ge(Error));var t=ct(r);function r(e,n,i){var o;if(Ue(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 $e(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 ht.default(this.serialize(),ft,2)}}]),r}();He.EthereumRpcError=dt;var lt=function(e){Ye(r,dt);var t=ct(r);function r(e,n,i){if(Ue(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 $e(r)}();function ft(e,t){if("[Circular]"!==t)return t}He.EthereumProviderError=lt;var pt={},vt={};function gt(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=[],u=!0,c=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return gt(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)?gt(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(vt,"__esModule",{value:!0}),vt.errorValues=vt.errorCodes=void 0,vt.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}},vt.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=vt,r=He,n=t.errorCodes.rpc.internal,i="Unspecified error message. This is a bug, please report it.",o={code:n,message:s(n)};function s(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i;if(Number.isInteger(r)){var o=r.toString();if(h(t.errorValues,o))return t.errorValues[o].message;if(u(r))return e.JSON_RPC_SERVER_ERROR_MESSAGE}return n}function a(e){if(!Number.isInteger(e))return!1;var r=e.toString();return!!t.errorValues[r]||!!u(e)}function u(e){return e>=-32099&&e<=-32e3}function c(e){return e&&"object"===Ke(e)&&!Array.isArray(e)?Object.assign({},e):e}function h(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.JSON_RPC_SERVER_ERROR_MESSAGE="Unspecified server error.",e.getMessageFromCode=s,e.isValidCode=a,e.serializeError=function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=i.fallbackError,d=void 0===u?o:u,l=i.shouldIncludeStack,f=void 0!==l&&l;if(!d||!Number.isInteger(d.code)||"string"!=typeof d.message)throw new Error("Must provide fallback error with integer number code and string message.");if(e instanceof r.EthereumRpcError)return e.serialize();var p={};if(e&&"object"===Ke(e)&&!Array.isArray(e)&&h(e,"code")&&a(e.code)){var v=e;p.code=v.code,v.message&&"string"==typeof v.message?(p.message=v.message,h(v,"data")&&(p.data=v.data)):(p.message=s(p.code),p.data={originalError:c(e)})}else{p.code=d.code;var g=null===(t=e)||void 0===t?void 0:t.message;p.message=g&&"string"==typeof g?g:d.message,p.data={originalError:c(e)}}var y=null===(n=e)||void 0===n?void 0:n.stack;return f&&e&&y&&"string"==typeof y&&(p.stack=y),p}}(pt);var mt={};Object.defineProperty(mt,"__esModule",{value:!0}),mt.ethErrors=void 0;var wt,bt,Et,St,_t,At=He,Ot=pt,Rt=vt;function It(e,t){var r=yt(Tt(t),2),n=r[0],i=r[1];return new At.EthereumRpcError(e,n||Ot.getMessageFromCode(e),i)}function Pt(e,t){var r=yt(Tt(t),2),n=r[0],i=r[1];return new At.EthereumProviderError(e,n||Ot.getMessageFromCode(e),i)}function Tt(e){if(e){if("string"==typeof e)return[e];if("object"===Ke(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 Ct(e){return e?"number"==typeof e?e:e.startsWith("0x")?parseInt(e,16):parseInt(e,10):1}mt.ethErrors={rpc:{parse:function(e){return It(Rt.errorCodes.rpc.parse,e)},invalidRequest:function(e){return It(Rt.errorCodes.rpc.invalidRequest,e)},invalidParams:function(e){return It(Rt.errorCodes.rpc.invalidParams,e)},methodNotFound:function(e){return It(Rt.errorCodes.rpc.methodNotFound,e)},internal:function(e){return It(Rt.errorCodes.rpc.internal,e)},server:function(e){if(!e||"object"!==Ke(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 It(t,e)},invalidInput:function(e){return It(Rt.errorCodes.rpc.invalidInput,e)},resourceNotFound:function(e){return It(Rt.errorCodes.rpc.resourceNotFound,e)},resourceUnavailable:function(e){return It(Rt.errorCodes.rpc.resourceUnavailable,e)},transactionRejected:function(e){return It(Rt.errorCodes.rpc.transactionRejected,e)},methodNotSupported:function(e){return It(Rt.errorCodes.rpc.methodNotSupported,e)},limitExceeded:function(e){return It(Rt.errorCodes.rpc.limitExceeded,e)}},provider:{userRejectedRequest:function(e){return Pt(Rt.errorCodes.provider.userRejectedRequest,e)},unauthorized:function(e){return Pt(Rt.errorCodes.provider.unauthorized,e)},unsupportedMethod:function(e){return Pt(Rt.errorCodes.provider.unsupportedMethod,e)},disconnected:function(e){return Pt(Rt.errorCodes.provider.disconnected,e)},chainDisconnected:function(e){return Pt(Rt.errorCodes.provider.chainDisconnected,e)},custom:function(e){if(!e||"object"!==Ke(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 At.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=He;Object.defineProperty(e,"EthereumRpcError",{enumerable:!0,get:function(){return t.EthereumRpcError}}),Object.defineProperty(e,"EthereumProviderError",{enumerable:!0,get:function(){return t.EthereumProviderError}});var r=pt;Object.defineProperty(e,"serializeError",{enumerable:!0,get:function(){return r.serializeError}}),Object.defineProperty(e,"getMessageFromCode",{enumerable:!0,get:function(){return r.getMessageFromCode}});var n=mt;Object.defineProperty(e,"ethErrors",{enumerable:!0,get:function(){return n.ethErrors}});var i=vt;Object.defineProperty(e,"errorCodes",{enumerable:!0,get:function(){return i.errorCodes}})}(Me);class Nt extends y{get existedSDK(){if("undefined"!=typeof window)return window.ethereum}constructor(t){var r;if(super(),wt.add(this),this.networkVersion="1",this.off=this.removeListener,this.injectedWalletServer=t.walletServer,this._blocto={sessionKeyEnv:e.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",switchableNetwork:{}},this.appId=t.appId||v,"chainId"in t){const{chainId:e,rpc:r}=t;o(e,"'chainId' is required"),this.networkVersion=`${Ct(e)}`,this.chainId=`0x${Ct(e).toString(16)}`,this.rpc=r||s[this.networkVersion],o(this.rpc,"'rpc' is required")}else{const{defaultChainId:e,switchableChains:n}=t;o(e,"'defaultChainId' is required"),this.networkVersion=`${Ct(e)}`,this.chainId=`0x${Ct(e).toString(16)}`;const i=n.find((t=>Ct(t.chainId)===Ct(e)));if(!i)throw Me.ethErrors.provider.custom({code:1001,message:`Chain ${e} is not in switchableChains list`});this.rpc=(null===(r=i.rpcUrls)||void 0===r?void 0:r[0])||s[this.networkVersion],o(this.rpc,"'rpc' is required"),this._blocto.unloadedNetwork=n}}send(e,t){return n(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 n(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,u=Math.floor(1e4*Math.random()),c=a?[...o]:[this.request(s),...o];Promise.allSettled(c).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)||u+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 Me.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 n(this,void 0,void 0,(function*(){return this.request({method:"eth_sendUserOperation",params:[e]})}))}request(e){var t,r,o,s,a,u,c,h;return n(this,void 0,void 0,(function*(){if(Array.isArray(e))return this.sendAsync(e);if(!(null==e?void 0:e.method))throw Me.ethErrors.rpc.invalidRequest();const{blockchainName:n,switchableNetwork:d,sessionKeyEnv:l}=yield i(this,wt,"m",bt).call(this);if(null===(t=this.existedSDK)||void 0===t?void 0:t.isBlocto){if("wallet_switchEthereumChain"===e.method){if(!(null===(o=null===(r=null==e?void 0:e.params)||void 0===r?void 0:r[0])||void 0===o?void 0:o.chainId))throw Me.ethErrors.rpc.invalidParams();return this.existedSDK.request(e).then((()=>{var t,r,n;return this.networkVersion=`${Ct(null===(t=null==e?void 0:e.params)||void 0===t?void 0:t[0].chainId)}`,this.chainId=`0x${Ct(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 Me.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===(u=null===(a=null==e?void 0:e.params)||void 0===a?void 0:a[0])||void 0===u?void 0:u.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return C(l,n)||[]}if(!C(l,n)){const t=null===(c=null==e?void 0:e.params)||void 0===c?void 0:c[0];"eth_requestAccounts"===e.method&&k(t)?yield this.enable(t):yield this.enable()}try{let t=null,r=null;switch(e.method){case"eth_requestAccounts":r=yield this.fetchAccounts();break;case"eth_coinbase":r=null===(h=C(l,n))||void 0===h?void 0:h[0];break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":r=yield this.handleSign(e);break;case"eth_sign":throw Me.ethErrors.rpc.methodNotFound("Method Not Supported: eth_sign has been disabled");case"eth_sendTransaction":r=yield this.handleSendTransaction(e);break;case"wallet_sendMultiCallTransaction":r=yield this.handleSendBatchTransaction(e);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw Me.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.method);case"eth_sendUserOperation":r=yield this.handleSendUserOperation(e);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":r=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 Me.ethErrors.rpc.internal(e)}return t?t.result:r}catch(e){throw Me.ethErrors.rpc.internal(null==e?void 0:e.message)}}))}bloctoApi(e,t){var r;return n(this,void 0,void 0,(function*(){const{walletServer:n,blockchainName:o,sessionKeyEnv:s}=yield i(this,wt,"m",bt).call(this),a=(null===(r=I(s))||void 0===r?void 0:r.code)||"";if(!a)throw Me.ethErrors.provider.unauthorized();return fetch(`${n}/api/${o}${e}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},t)).then((e=>D(e,s,(()=>{var e;null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e(Me.ethErrors.provider.disconnected())))})))).catch((e=>{throw"unsupported_method"===(null==e?void 0:e.error_code)?Me.ethErrors.rpc.methodNotSupported("Method Not Supported: "+e.message):Me.ethErrors.rpc.server({code:-32005,message:`Blocto server error: ${e.message}`})}))}))}responseListener(e,t){return n(this,void 0,void 0,(function*(){const{walletServer:r}=yield i(this,wt,"m",bt).call(this);return new Promise(((n,i)=>E("message",((o,s)=>{const a=o;a.origin===r&&"ETH:FRAME:RESPONSE"===a.data.type&&("APPROVED"===a.data.status&&(s(),b(e),n(a.data[t])),"DECLINED"===a.data.status&&(s(),b(e),"incorrect_session_id"===a.data.errorCode&&this.handleDisconnect(),i(Me.ethErrors.provider.userRejectedRequest(a.data.errorMessage)))),"ETH:FRAME:CLOSE"===a.data.type&&(s(),b(e),i(Me.ethErrors.provider.userRejectedRequest("User declined the request")))}))))}))}setIframe(e,t){return n(this,void 0,void 0,(function*(){if("undefined"==typeof window)throw Me.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:r,blockchainName:n}=yield i(this,wt,"m",bt).call(this),o=m(`${r}/${this.appId}/${t||n}${e}`);return w(o),o}))}enable(e){var r;return n(this,void 0,void 0,(function*(){if("undefined"==typeof window)throw Me.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:n,blockchainName:o,sessionKeyEnv:s}=yield i(this,wt,"m",bt).call(this);if(null===(r=this.existedSDK)||void 0===r?void 0:r.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}]}),N(s,o,[this.existedSDK.address])),new Promise(((e,t)=>setTimeout((()=>this.existedSDK.enable().then(e).catch(t)),10)));const a=C(s,o);if(a)return new Promise((e=>{e(a)}));const u=new URLSearchParams;u.set("l6n",window.location.origin),u.set("v",g);const c=e&&k(e)?`/${e}`:"",h=yield this.setIframe(`/authn${c}?${u.toString()}`);return new Promise(((e,r)=>{E("message",((i,a)=>{var u,c;const d=i;d.origin===n&&("ETH:FRAME:RESPONSE"===d.data.type&&(a(),b(h),null===(u=this.eventListeners)||void 0===u||u.connect.forEach((e=>e({chainId:this.chainId}))),P(s,{code:d.data.code,evm:{[o]:[d.data.addr]}},d.data.exp),(null===(c=d.data)||void 0===c?void 0:c.isAccountChanged)&&postMessage({originChain:t.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),E("message",((e,r)=>{var n,i,o;const s=e,a="BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(n=s.data)||void 0===n?void 0:n.type),u=(null===(i=s.data)||void 0===i?void 0:i.originChain)!==t.ETHEREUM;a&&(null===(o=this.eventListeners)||void 0===o||o.accountsChanged.forEach((e=>e([d.data.addr])))),a&&u&&(this.handleDisconnect(),r())})),e([d.data.addr])),"ETH:FRAME:CLOSE"===d.data.type&&(a(),b(h),r(Me.ethErrors.provider.userRejectedRequest())))}))}))}))}fetchAccounts(){return n(this,void 0,void 0,(function*(){i(this,wt,"m",St).call(this);const{blockchainName:e,sessionKeyEnv:t}=yield i(this,wt,"m",bt).call(this),{accounts:r}=yield this.bloctoApi("/accounts");return N(t,e,r),r}))}handleReadRequests(e){return n(this,void 0,void 0,(function*(){return i(this,wt,"m",St).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 Me.ethErrors.rpc.internal(e)}))}))}handleSign({method:e,params:t}){return n(this,void 0,void 0,(function*(){let r="";if(Array.isArray(t))if("personal_sign"===e)r=ke(t[0])?t[0].slice(2):(n=t[0],W.from(n,"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(ke(e.chainId))throw Me.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must be a number`);if(Ct(e.chainId)!==Ct(this.chainId))throw Me.ethErrors.rpc.invalidParams(`Provided chainId "${e.chainId}" must match the active chainId "${Ct(this.chainId)}"`)}var n;i(this,wt,"m",St).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,r;return n(this,void 0,void 0,(function*(){if(!e)throw Me.ethErrors.rpc.invalidParams();const{walletServer:n,blockchainName:o,sessionKeyEnv:s,switchableNetwork:a}=yield i(this,wt,"m",bt).call(this),u=null===(t=C(s,o))||void 0===t?void 0:t[0],c=Ct(this.chainId),h=Ct(e);if(c===h)return null;if(!a[h])throw Me.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:""}),!u)return null===(r=this.eventListeners)||void 0===r||r.chainChanged.forEach((e=>e(this.chainId))),yield i(this,wt,"m",bt).call(this),null;if(a[h].wallet_web_url!==a[c].wallet_web_url)return this.enable().then((([e])=>{var t;return e!==u&&(null===(t=this.eventListeners)||void 0===t||t.accountsChanged.forEach((t=>t([e])))),this.eventListeners.chainChanged.forEach((e=>e(this.chainId))),null})).catch((e=>{throw this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),i(this,wt,"m",bt).call(this),e}));const d=yield this.setIframe(`/switch-chain?to=${a[h].name}`,a[c].name);return new Promise(((e,t)=>{E("message",((r,o)=>{var l,f,p,v,g,y,m,w;const E=r;E.origin===n&&("ETH:FRAME:RESPONSE"===E.data.type&&(o(),b(d),(null===(l=E.data)||void 0===l?void 0:l.addr)&&u&&(P(s,{code:null===(f=E.data)||void 0===f?void 0:f.code,evm:{[a[h].name]:[E.data.addr]}},null===(p=E.data)||void 0===p?void 0:p.exp),E.data.addr!==u&&(null===(v=this.eventListeners)||void 0===v||v.accountsChanged.forEach((e=>e([E.data.addr]))))),null===(g=this.eventListeners)||void 0===g||g.chainChanged.forEach((e=>e(this.chainId))),i(this,wt,"m",bt).call(this),e(null)),"ETH:FRAME:CLOSE"===E.data.type&&(o(),b(d),(null===(y=E.data)||void 0===y?void 0:y.hasApprovedSwitchChain)?(null===(m=this.eventListeners)||void 0===m||m.chainChanged.forEach((e=>e(this.chainId))),j(s),null===(w=this.eventListeners)||void 0===w||w.disconnect.forEach((e=>e(Me.ethErrors.provider.disconnected()))),i(this,wt,"m",bt).call(this),e(null)):(this.networkVersion=`${c}`,this.chainId=`0x${c.toString(16)}`,this.rpc=a[c].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),i(this,wt,"m",bt).call(this),t(Me.ethErrors.provider.userRejectedRequest()))))}))}))}))}handleSendTransaction(e){var t;return n(this,void 0,void 0,(function*(){i(this,wt,"m",St).call(this);const{isValid:r,invalidMsg:n}=xe(null===(t=e.params)||void 0===t?void 0:t[0]);if(!r)throw Me.ethErrors.rpc.invalidParams(n);return i(this,wt,"m",_t).call(this,e.params)}))}handleSendBatchTransaction(e){return n(this,void 0,void 0,(function*(){let t,r;i(this,wt,"m",St).call(this),Array.isArray(e.params)&&e.params.length>=2?[t,r]=e.params:(t=e.params,r=!1);const n=r||!1,{isValid:o,invalidMsg:s}=(e=>{if(!Array.isArray(e))return{isValid:!1,invalidMsg:x.INVALID_TRANSACTIONS};for(let t=0;t<e.length;t++){const{isValid:r,invalidMsg:n}=xe(e[t]);if(!r)return{isValid:r,invalidMsg:n}}return{isValid:!0}})(t);if(!o)throw Me.ethErrors.rpc.invalidParams(s);return i(this,wt,"m",_t).call(this,t,n)}))}handleSendUserOperation(e){return n(this,void 0,void 0,(function*(){i(this,wt,"m",St).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 n(this,void 0,void 0,(function*(){return i(this,wt,"m",St).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},e))})}))}handleDisconnect(){var e,t;return n(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 i(this,wt,"m",bt).call(this);j(r),null===(t=this.eventListeners)||void 0===t||t.disconnect.forEach((e=>e(Me.ethErrors.provider.disconnected())))}))}loadSwitchableNetwork(e){return n(this,void 0,void 0,(function*(){if(null==e?void 0:e.length){const t=e.map((({chainId:e,rpcUrls:t})=>{if(!e)throw Me.ethErrors.rpc.invalidParams("Empty chainId");const r=`${Ct(e)}`;if(this._blocto.switchableNetwork[r])return null;const n=(null==t?void 0:t[0])||s[r];if(!n)throw Me.ethErrors.rpc.invalidParams("rpcUrls required");return i(this,wt,"m",Et).call(this,{chainId:r,rpcUrls:[n]})}));return Promise.all(t).then((()=>null))}throw Me.ethErrors.rpc.invalidParams("Empty networkList")}))}supportChainList(){return n(this,void 0,void 0,(function*(){const e=yield Le().catch((e=>{throw Me.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)}}wt=new WeakSet,bt=function(){var e,t;return n(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 Le().catch((e=>{throw Me.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:c}=null!==(t=r[this.networkVersion])&&void 0!==t?t:{};if(!n)throw Me.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);const h=this.injectedWalletServer||a[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:c,network_type:o,wallet_web_url:h,rpc_url:this.rpc}})}),this._blocto}))},Et=function({chainId:e,rpcUrls:t}){var r;return n(this,void 0,void 0,(function*(){yield i(this,wt,"m",bt).call(this);const n=yield Le().catch((e=>{throw Me.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${e.message}`})})),{chain_id:o,name:s,display_name:u,network_type:c,blocto_service_environment:h}=null!==(r=n[e])&&void 0!==r?r:{};if(!o)throw Me.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${e} might not be supported yet.`);const d=a[h];this._blocto.switchableNetwork[o]={name:s,display_name:u,network_type:c,wallet_web_url:d,rpc_url:t[0]}}))},St=function(){var e;if((null===(e=this.existedSDK)||void 0===e?void 0:e.isBlocto)&&Ct(this.existedSDK.chainId)!==Ct(this.chainId))throw Me.ethErrors.provider.chainDisconnected()},_t=function(e,t=!0){return n(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 jt 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,o(e,"'chainId' is required"),o(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=l[e],this.api=f[e],this.sessionKey=c[e];const n=h[e];this.appId=r||v,this.server=t||n||""}get publicAccount(){var e;return{address:(null===(e=T(this.sessionKey,t.APTOS))||void 0===e?void 0:e[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return n(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){var e;return n(this,void 0,void 0,(function*(){return!!(null===(e=T(this.sessionKey,t.APTOS))||void 0===e?void 0:e.length)}))}signTransaction(e){var r;return n(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signTransaction(e);if((yield this.isConnected())||(yield this.connect()),!(null===(r=T(this.sessionKey,t.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){var e;return n(this,void 0,void 0,(function*(){var r,n;this.existedSDK?yield this.existedSDK.disconnect():(r=this.sessionKey,n=t.APTOS,P(r,{accounts:{[n]:void 0}}),null===(e=this.eventListeners)||void 0===e||e.disconnect.forEach((e=>e({code:4900,message:"Wallet disconnected"}))))}))}signAndSubmitTransaction(e,r={}){var i,o;return n(this,void 0,void 0,(function*(){if(this.existedSDK)return this.existedSDK.signAndSubmitTransaction(e,r);if((yield this.isConnected())||(yield this.connect()),!(null===(i=T(this.sessionKey,t.APTOS))||void 0===i?void 0:i.length))throw new Error("Fail to get account");const n=(null===(o=I(this.sessionKey))||void 0===o?void 0:o.code)||"",{authorizationId:s}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":n},body:JSON.stringify(Object.assign(Object.assign({},e),r))}).then((e=>D(e,this.sessionKey)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const a=m(`${this.server}/${this.appId}/aptos/authz/${s}`);return w(a),new Promise(((e,t)=>E("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),b(a),e({hash:i.data.txHash})),"DECLINED"===i.data.status&&(n(),b(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}signMessage(e){var r,i;return n(this,void 0,void 0,(function*(){const n=(e=>{var t,r;const n=Object.assign({},e),{message:i,nonce:o,address:s,application:a,chainId:u}=e;return"string"!=typeof i&&(n.message=null!==(t=String(i))&&void 0!==t?t:""),"string"!=typeof o&&(n.nonce=null!==(r=String(o))&&void 0!==r?r:""),s&&"boolean"!=typeof s&&(n.address=!!s),a&&"boolean"!=typeof a&&(n.application=!!a),u&&"boolean"!=typeof u&&(n.chainId=!!u),n})(e);if(this.existedSDK)return this.existedSDK.signMessage(n);if((yield this.isConnected())||(yield this.connect()),!(null===(r=T(this.sessionKey,t.APTOS))||void 0===r?void 0:r.length))throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const o=(null===(i=I(this.sessionKey))||void 0===i?void 0:i.code)||"",{signatureId:s}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":o},body:JSON.stringify(n)}).then((e=>D(e,this.sessionKey))),a=m(`${this.server}/${this.appId}/aptos/user-signature/${s}`);return w(a),new Promise(((e,t)=>E("message",((r,n)=>{const i=r;i.origin===this.server&&"APTOS:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),b(a),e(i.data)),"DECLINED"===i.data.status&&(n(),b(a),"incorrect_session_id"===i.data.errorCode&&this.disconnect(),t(new Error(i.data.errorMessage))))}))))}))}connect(){return n(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,r)=>{var i,o;if("undefined"==typeof window)return r("Currently only supported in browser");if(null===(i=T(this.sessionKey,t.APTOS))||void 0===i?void 0:i.length)return e({address:(null===(o=T(this.sessionKey,t.APTOS))||void 0===o?void 0:o[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const s=encodeURIComponent(window.location.origin),a=m(`${this.server}/${this.appId}/aptos/authn?l6n=${s}&v=${g}}`);w(a),E("message",((i,o)=>n(this,void 0,void 0,(function*(){var n,s,u,c;const h=i;if(h.origin===this.server){if("APTOS:FRAME:RESPONSE"===h.data.type){if(o(),b(a),P(this.sessionKey,{code:h.data.code,accounts:{[t.APTOS]:[h.data.addr]}},h.data.exp),(null===(n=h.data)||void 0===n?void 0:n.isAccountChanged)&&postMessage({originChain:t.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),E("message",((e,r)=>{var n,i;const o=e;"BLOCTO_SDK:ACCOUNT_CHANGED"===(null===(n=o.data)||void 0===n?void 0:n.type)&&(null===(i=o.data)||void 0===i?void 0:i.originChain)!==t.APTOS&&(this.disconnect(),r())})),!(null===(s=T(this.sessionKey,t.APTOS))||void 0===s?void 0:s.length))return r();try{const{public_keys:r}=yield fetch(`${this.server}/blocto/aptos/accounts/${null===(u=T(this.sessionKey,t.APTOS))||void 0===u?void 0:u[0]}`).then((e=>e.json()));this.publicKey=r||[],e({address:(null===(c=T(this.sessionKey,t.APTOS))||void 0===c?void 0:c[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(e){return r(h)}}"APTOS:FRAME:CLOSE"===h.data.type&&(o(),b(a),r(new Error("User declined the login request")))}}))))}))}))}fetchAddress(){var e;return n(this,void 0,void 0,(function*(){const r=(null===(e=I(this.sessionKey))||void 0===e?void 0:e.code)||"",{accounts:n}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":r}}).then((e=>D(e,this.sessionKey)));var i,o;return i=this.sessionKey,o=t.APTOS,P(i,{accounts:{[o]:n}}),(null==n?void 0:n[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 Dt{constructor({appId:e,ethereum:t,aptos:r}){t&&(this.ethereum=new Nt(Object.assign(Object.assign({},t),{appId:e}))),r&&(this.aptos=new jt(Object.assign(Object.assign({},r),{appId:e})))}}exports.default=function({chainId:e,rpcUrl:t,rpc:n,bloctoParams:i},o){return r.__awaiter(this,void 0,void 0,(function*(){let s;if(!e)throw new Error("chainId is required");t?s=t:e&&n&&(s=n[e]),s||(s="null");const a=new Dt({appId:null==i?void 0:i.appId,ethereum:{chainId:e,rpc:s}}).ethereum;if(!a)throw new Error("No provider");return a.on("connect",o.connect),a.on("disconnect",o.disconnect),a.on("accountsChanged",o.accountsChanged),a.on("chainChanged",o.chainChanged),yield a.request({method:"eth_requestAccounts"}),r.convertWeb3Provider(a)}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./index-
|
|
1
|
+
"use strict";var e=require("./index-5fba0284.cjs");require("@ethersproject/providers"),require("zustand"),require("@ethersproject/bytes"),require("@ethersproject/properties"),require("@ethersproject/address"),require("@ethersproject/abstract-signer"),require("buffer"),require("@ethersproject/abstract-provider"),require("@ethersproject/contracts"),require("events"),require("@ethersproject/constants"),require("@ethersproject/transactions");class r extends e.BaseError{constructor({callbackSelector:r,cause:t,data:a,extraData:s,sender:o,urls:n}){super(t.shortMessage||"An error occurred while fetching for an offchain result.",{cause:t,metaMessages:[...t.metaMessages||[],t.metaMessages?.length?"":[],"Offchain Gateway Call:",n&&[" Gateway URL(s):",...n.map((r=>` ${e.getUrl(r)}`))],` Sender: ${o}`,` Data: ${a}`,` Callback selector: ${r}`,` Extra data: ${s}`].flat()}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupError"})}}class t extends e.BaseError{constructor({result:r,url:t}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${e.getUrl(t)}`,`Response: ${e.stringify(r)}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupResponseMalformedError"})}}class a extends e.BaseError{constructor({sender:e,to:r}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${r}`,`OffchainLookup sender address: ${e}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupSenderMismatchError"})}}const s={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 o({data:r,sender:a,urls:s}){let o=new Error("An unknown error occurred.");for(let n=0;n<s.length;n++){const c=s[n],i=c.includes("{data}")?"GET":"POST",d="POST"===i?{data:r,sender:a}:void 0;try{const s=await fetch(c.replace("{sender}",a).replace("{data}",r),{body:JSON.stringify(d),method:i});let n;if(n=s.headers.get("Content-Type")?.startsWith("application/json")?(await s.json()).data:await s.text(),!s.ok){o=new e.HttpRequestError({body:d,details:n?.error?e.stringify(n.error):s.statusText,headers:s.headers,status:s.status,url:c});continue}if(!e.isHex(n)){o=new t({result:n,url:c});continue}return n}catch(r){o=new e.HttpRequestError({body:d,details:r.message,url:c})}}throw o}exports.ccipFetch=o,exports.offchainLookup=async function(t,{blockNumber:n,blockTag:c,data:i,to:d}){const{args:u}=e.decodeErrorResult({data:i,abi:[s]}),[l,p,f,h,b]=u;try{if(!function(r,t){if(!e.isAddress(r,{strict:!1}))throw new e.InvalidAddressError({address:r});if(!e.isAddress(t,{strict:!1}))throw new e.InvalidAddressError({address:t});return r.toLowerCase()===t.toLowerCase()}(d,l))throw new a({sender:l,to:d});const r=await o({data:f,sender:l,urls:p}),{data:s}=await e.call(t,{blockNumber:n,blockTag:c,data:e.concat([h,e.encodeAbiParameters([{type:"bytes"},{type:"bytes"}],[r,b])]),to:d});return s}catch(e){throw new r({callbackSelector:h,cause:e,data:i,extraData:b,sender:l,urls:p})}},exports.offchainLookupAbiItem=s,exports.offchainLookupSignature="0x556f1830";
|
package/dist/cjs/core/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export default class Core {
|
|
|
16
16
|
isOpenBlockIframe: boolean;
|
|
17
17
|
isSafeIframe: boolean;
|
|
18
18
|
constructor(options: ICoreOptions);
|
|
19
|
+
setDisabledState(): Promise<void>;
|
|
19
20
|
setWalletListConfig(walletListConfig?: WalletListParams): void;
|
|
20
21
|
autoConnect(walletListConfig?: WalletListParams): Promise<import("@ethersproject/providers").JsonRpcProvider | undefined>;
|
|
21
22
|
setRpcUrl(url: string): void;
|
|
@@ -26,5 +27,5 @@ export default class Core {
|
|
|
26
27
|
getConnectedWallet(): Promise<Wallet | undefined>;
|
|
27
28
|
disconnectWallet(): Promise<void>;
|
|
28
29
|
connectWalletBefore(wallet: Wallet): boolean;
|
|
29
|
-
clickWallet(wallet: Wallet, providerConfig?: Partial<ConnectorParams>): Promise<import("@ethersproject/providers").JsonRpcProvider | undefined
|
|
30
|
+
clickWallet(wallet: Wallet, providerConfig?: Partial<ConnectorParams>): Promise<import("@ethersproject/providers").JsonRpcProvider | undefined> | undefined;
|
|
30
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var t=require("./index-
|
|
1
|
+
"use strict";var t=require("./index-5fba0284.cjs");function i(t,i){return i.forEach((function(i){i&&"string"!=typeof i&&!Array.isArray(i)&&Object.keys(i).forEach((function(e){if("default"!==e&&!(e in t)){var n=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:function(){return i[e]}})}}))})),Object.freeze(t)}var e,n={exports:{}},o={exports:{}};function s(){return e||(e=1,t=o,function(i,e){t.exports?t.exports=e():i.getSize=e()}(window,(function(){function t(t){let i=parseFloat(t);return-1==t.indexOf("%")&&!isNaN(i)&&i}let i=["paddingLeft","paddingRight","paddingTop","paddingBottom","marginLeft","marginRight","marginTop","marginBottom","borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth"];return function(e){if("string"==typeof e&&(e=document.querySelector(e)),!e||"object"!=typeof e||!e.nodeType)return;let n=getComputedStyle(e);if("none"==n.display)return function(){let t={width:0,height:0,innerWidth:0,innerHeight:0,outerWidth:0,outerHeight:0};return i.forEach((i=>{t[i]=0})),t}();let o={};o.width=e.offsetWidth,o.height=e.offsetHeight;let s=o.isBorderBox="border-box"==n.boxSizing;i.forEach((t=>{let i=n[t],e=parseFloat(i);o[t]=isNaN(e)?0:e}));let r=o.paddingLeft+o.paddingRight,h=o.paddingTop+o.paddingBottom,a=o.marginLeft+o.marginRight,d=o.marginTop+o.marginBottom,l=o.borderLeftWidth+o.borderRightWidth,c=o.borderTopWidth+o.borderBottomWidth,u=t(n.width);!1!==u&&(o.width=u+(s?0:r+l));let p=t(n.height);return!1!==p&&(o.height=p+(s?0:h+c)),o.innerWidth=o.width-(r+l),o.innerHeight=o.height-(h+c),o.outerWidth=o.width+a,o.outerHeight=o.height+d,o}}))),o.exports;var t}var r,h,a,d={exports:{}},l={exports:{}};function c(){return r||(r=1,i=l,e="undefined"!=typeof window?window:t.commonjsGlobal,n=function(){function t(){}let i=t.prototype;return i.on=function(t,i){if(!t||!i)return this;let e=this._events=this._events||{},n=e[t]=e[t]||[];return n.includes(i)||n.push(i),this},i.once=function(t,i){if(!t||!i)return this;this.on(t,i);let e=this._onceEvents=this._onceEvents||{};return(e[t]=e[t]||{})[i]=!0,this},i.off=function(t,i){let e=this._events&&this._events[t];if(!e||!e.length)return this;let n=e.indexOf(i);return-1!=n&&e.splice(n,1),this},i.emitEvent=function(t,i){let e=this._events&&this._events[t];if(!e||!e.length)return this;e=e.slice(0),i=i||[];let n=this._onceEvents&&this._onceEvents[t];for(let o of e)n&&n[o]&&(this.off(t,o),delete n[o]),o.apply(this,i);return this},i.allOff=function(){return delete this._events,delete this._onceEvents,this},t},i.exports?i.exports=n():e.EvEmitter=n()),l.exports;var i,e,n}
|
|
2
2
|
/*!
|
|
3
3
|
* Unidragger v3.0.1
|
|
4
4
|
* Draggable base class
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./index-5fba0284.cjs");exports.id=function(t){return e.keccak256(e.toUtf8Bytes(t))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./index-
|
|
1
|
+
"use strict";var e=require("./index-5fba0284.cjs"),r=require("@ethersproject/address");require("events");var t=require("@ethersproject/bytes"),n=require("./typed-data-d4238233.cjs"),i=require("@ethersproject/abstract-signer"),o=require("@ethersproject/properties");require("@ethersproject/providers"),require("zustand"),require("buffer"),require("@ethersproject/abstract-provider"),require("@ethersproject/contracts"),require("@ethersproject/constants"),require("@ethersproject/transactions"),require("./id-6aec2278.cjs");class s extends i.Signer{constructor(e,r,t,n){super(),this._address=r,this._index=null!=t?t:0,this.provider=e,this.app=n}_legacySignMessage(e){throw new Error("Method not implemented.")}sendUncheckedTransaction(e){throw new Error("Method not implemented.")}unlock(e){throw new Error("Method not implemented.")}getAddress(){return e.__awaiter(this,void 0,void 0,(function*(){return Promise.resolve(r.getAddress(this._address))}))}signMessage(r){return e.__awaiter(this,void 0,void 0,(function*(){const n=e.getOwnerProvider(),i="string"==typeof r?e.toUtf8Bytes(r):r,o=yield this.getAddress();return yield n.send("personal_sign",[t.hexlify(i),o.toLowerCase()])}))}_signTypedData(r,t,i){var o,s;return e.__awaiter(this,void 0,void 0,(function*(){const a=e.getOwnerProvider(),d=yield n.TypedDataEncoder.resolveNames(r,t,i,(r=>e.__awaiter(this,void 0,void 0,(function*(){return yield a.resolveName(r)})))),c=null!==(s=null===(o=e.getCyberAccount())||void 0===o?void 0:o.ownerAddress)&&void 0!==s?s:"";return yield a.send("eth_signTypedData_v4",[c.toLowerCase(),JSON.stringify(n.TypedDataEncoder.getPayload(d.domain,t,d.value))])}))}signTransaction(r){return e.__awaiter(this,void 0,void 0,(function*(){throw new Error("Method not implemented.")}))}sendTransaction(r){return e.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getChainId(),n=e.getCyberChain(this.app,t);return{hash:yield n.sendTransaction({to:r.to,value:r.value,data:r.data}).catch((r=>{if(r.name===e.ErrorType.SendTransactionError&&(console.error(r.shortMessage),r.shortMessage))throw new Error(r.shortMessage);throw r}))}}))}connect(e){return new s(null!=e?e:this.provider,this._address,this._index,this.app)}connectUnchecked(){return new s(this.provider,this._address,this._index,this.app)}}exports.getIsCyber=e.getIsCyber,exports.default=function(t,n){return e.__awaiter(this,void 0,void 0,(function*(){const i=yield function({appName:t,appLogoUrl:n,rpcUrl:i,rpc:a,chainId:d,cyberParams:c,JsonRpcProvider:u=e.DefaultJsonRpcProvider}){return e.__awaiter(this,void 0,void 0,(function*(){if(!t||!n)throw new Error("appName and appLogoUrl is required.");if(!(null==c?void 0:c.appId))throw new Error("cyberParams.appId and appLogoUrl is required.");const{app:h,cyberAccount:p}=yield e.connect({appName:t,appLogoUrl:n,appId:null==c?void 0:c.appId});if(!p)throw new Error("cyberAccount is not valid.");const l=p.address,v=new class extends u{constructor(r,t){super(r,t),this.updateUpWalletConfig=r=>{const t=null==a?void 0:a[r];if(!e.supportChains.includes(r))throw new Error(`chainId ${r} not supported`);if("object"==typeof this.network)this.network.chainId=r;else{const e={chainId:r,name:"unknown"};o.defineReadOnly(this,"_network",e),this.emit("network",e,null)}return this.rpcUrl=t,this.emit("chainChanged",`0x${r.toString(16)}`),{result:!0}}}getSigner(){return new s(v,l,0,h)}listAccounts(){return e.__awaiter(this,void 0,void 0,(function*(){return[l]}))}getAddress(){return Promise.resolve(r.getAddress(l))}}(i,d);return v}))}(t);return i.on("connect",n.connect),i.on("disconnect",n.disconnect),i.on("accountsChanged",n.accountsChanged),i.on("chainChanged",n.chainChanged),i.on("message",n.message),i}))},exports.switchChain=function(r){var t;const n=r.addChainParameters.chainId,i="string"==typeof n&&(null==n?void 0:n.startsWith("0x"))?parseInt(n,16):Number(n);if(!e.supportChains.includes(i))throw new Error(`chainId ${i} not supported`);return null===(t=e.useWalletStore.getState().provider)||void 0===t?void 0:t.updateUpWalletConfig(i)};
|