/*! For license information please see provider.min.js.LICENSE.txt */ (()=>{var t={247:function(t,e,n){"use strict";var r=n(834).lW,o=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.AuthEVMAdapter=void 0;const i=n(996),s=n(24),a=n(248);e.AuthEVMAdapter=class{constructor(t){this.auth=t,this.auth=t}request(t){return o(this,void 0,void 0,(function*(){if("eth_requestAccounts"===t.method||"eth_accounts"===t.method){let t=this.auth.getWallet();if(t)return[t.public_address];if(yield this.auth.login(),t=this.auth.getWallet(),t)return[t.public_address];throw new Error("Create wallet failed")}if("eth_chainId"===t.method)return(0,i.intToHex)(this.auth.getChainId());if("eth_sendTransaction"===t.method){if(t.params&&t.params instanceof Array&&t.params[0]){const e=t.params[0];return(0,i.isNullish)(e.type)&&(s.chains.isChainSupportEIP1559(this.auth.getChain())?e.type="0x2":e.type="0x0"),(0,i.isNullish)(e.chainId)&&(e.chainId=(0,i.intToHex)(this.auth.getChainId())),(0,i.isNullish)(e.nonce)&&(e.nonce="0x0"),(0,i.isNullish)(e.data)&&(e.data="0x"),this.auth.sendTransaction(this.legacyToString(t.params[0]))}return Promise.reject(a.ProviderError.paramsError())}if("eth_signTypedData_v3"===t.method||"eth_signTypedData_v4"===t.method||"eth_signTypedData_v4_uniq"===t.method){if(t.params&&t.params instanceof Array&&t.params.length>=2){let e=t.params[1];return"string"!=typeof e||e.startsWith("0x")||(e=(0,i.addHexPrefix)(r.from(e).toString("hex"))),this.auth.sign(t.method,this.legacyToString(e))}return Promise.reject(a.ProviderError.paramsError())}if("eth_signTypedData"===t.method||"eth_signTypedData_v1"===t.method){if(t.params&&t.params instanceof Array&&t.params[0]){let e=t.params[0];return"string"!=typeof e||e.startsWith("0x")||(e=(0,i.addHexPrefix)(r.from(e).toString("hex"))),this.auth.sign(t.method,this.legacyToString(e))}return Promise.reject(a.ProviderError.paramsError())}if("personal_sign"===t.method||"personal_sign_uniq"===t.method)return t.params&&t.params instanceof Array&&t.params[0]?this.auth.sign(t.method,this.legacyToString(t.params[0])):Promise.reject(a.ProviderError.paramsError());if("wallet_switchEthereumChain"===t.method){if(t.params&&t.params instanceof Array&&t.params[0]&&t.params[0].chainId){const e=Number(t.params[0].chainId),n=s.chains.getEVMChainInfoById(e);return n?(yield this.auth.switchChain(n),Promise.resolve(null)):Promise.reject(a.ProviderError.unsupportedChain())}return Promise.reject(a.ProviderError.paramsError())}return Promise.reject(a.ProviderError.unsupportedMethod())}))}legacyToString(t){let e;return e="number"==typeof t?(0,i.addHexPrefix)(t.toString(16)):"string"==typeof t?t.toString().startsWith("0x")?t:(0,i.addHexPrefix)(r.from(t).toString("hex")):(0,i.addHexPrefix)(r.from(JSON.stringify(t)).toString("hex")),e}}},131:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.HttpConnection=void 0;const i=n(996),s=o(n(14)),a=n(248);class c extends a.IJsonRpcConnection{constructor(t){if(super(),this.config=t,this.registering=!1,!(0,i.isHttpUrl)(t.url))throw new Error(`Provided URL is not compatible with HTTP connection: ${t.url}`);this.config=t}get connected(){return void 0!==this.api}get connecting(){return this.registering}open(){return r(this,void 0,void 0,(function*(){this.api=yield this.register()}))}close(){return r(this,void 0,void 0,(function*(){this.onClose()}))}send(t){return r(this,void 0,void 0,(function*(){return void 0===this.api&&(this.api=yield this.register()),this.api.post("/",t).then((t=>t.data))}))}register(){return r(this,void 0,void 0,(function*(){const t=this.config;if(!(0,i.isHttpUrl)(t.url))throw new Error(`Provided URL is not compatible with HTTP connection: ${t.url}`);if(this.registering)return new Promise(((t,e)=>{this.events.once("open",(()=>{if(void 0===this.api)return e(new Error("HTTP connection is missing or invalid"));t(this.api)}))}));this.registering=!0;const e=s.default.create({baseURL:t.url,timeout:3e4,headers:{Accept:"application/json","Content-Type":"application/json"}});return e.interceptors.request.use((function(e){var n,r;return e.params||(e.params={}),e.params.chainId=null!==(r=null===(n=e.data)||void 0===n?void 0:n.chainId)&&void 0!==r?r:t.chainId(),e.params.projectUuid=t.authentication.projectId,e.params.projectKey=t.authentication.clientKey,e}),(t=>Promise.reject(t))),this.onOpen(e),e}))}onOpen(t){this.api=t,this.registering=!1,this.events.emit("open")}onClose(){this.api=void 0,this.events.emit("close")}}e.HttpConnection=c},118:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.ParticleDelegateProvider=void 0;const o=n(996),i=n(987),s=n(131),a=n(248);class c extends a.IJsonRpcProvider{constructor(t,e){super(),this.auth=t,this.signerProvider=e,this.isParticleDelegateProvider=!0,this.connection=this.setConnection(),this.listenEvent()}listenEvent(){const t=this.events;this.signerProvider.on("connect",(e=>t.emit("connect",e))),this.signerProvider.on("disconnect",(e=>t.emit("disconnect",e))),this.signerProvider.on("message",(e=>t.emit("message",e))),this.signerProvider.on("chainChanged",(e=>t.emit("chainChanged",e))),this.signerProvider.on("accountsChanged",(e=>t.emit("accountsChanged",e)))}setConnection(){return new s.HttpConnection({url:`${(0,o.rpcUrl)()}/evm-chain`,basicCredentials:this.auth.basicCredentials(),chainId:()=>{var t;return null!==(t=this.chainId)&&void 0!==t?t:this.auth.getChainId()},authentication:this.auth.config})}disconnect(){return r(this,void 0,void 0,(function*(){const t=this.signerProvider;if(t.disconnect&&"function"==typeof t.disconnect)try{yield t.disconnect()}catch(t){}}))}enable(){return r(this,void 0,void 0,(function*(){const t=this.signerProvider;let e;if(t.enable&&"function"==typeof t.enable)try{e=yield t.enable()}catch(t){e=yield this.request({method:"eth_requestAccounts"})}return e}))}request(t){var e,n;return r(this,void 0,void 0,(function*(){if(!t.method||a.notSupportMethods.includes(t.method))return Promise.reject(a.ProviderError.unsupportedMethod());this.connection.connected||(yield this.open());const r={id:null!==(e=t.id)&&void 0!==e?e:(0,i.v4)(),jsonrpc:null!==(n=t.jsonrpc)&&void 0!==n?n:"2.0",method:t.method,params:t.params};if(a.signerMethods.includes(r.method)||this.isParticleSignerMethod(r.method))return console.log("Particle Signer Provider Request",r),yield this.signerProvider.request(r);{try{this.chainId=Number(yield this.signerProvider.request({method:"eth_chainId"}))}catch(t){this.chainId=Number(this.auth.getChainId())}const t=Object.assign(Object.assign({},r),{chainId:this.chainId});return console.log("Particle Provider Delegate Request",t),yield this.requestStrict(t)}}))}isParticleSignerMethod(t){return this.signerProvider.isParticleNetwork&&a.particleSignerMethods.includes(t)}requestStrict(t){return r(this,void 0,void 0,(function*(){return this.connection.send(t).then((t=>t.error?Promise.reject(t.error):Promise.resolve(t.result)))}))}open(){return r(this,void 0,void 0,(function*(){yield this.connection.open()}))}}e.ParticleDelegateProvider=c},195:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(342),e),o(n(118),e)},342:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.ParticleProvider=void 0;const o=n(996),i=n(987),s=n(247),a=n(131),c=n(248),l=n(641);class u extends c.IJsonRpcProvider{constructor(t){super(),this.auth=t,this.isParticleNetwork=!0,this.auth=t,this.connection=this.setConnection(),this.authAdapter=new s.AuthEVMAdapter(this.auth),this.auth.on("chainChanged",(t=>{"Solana"!==t.name&&this.emit("chainChanged",(0,o.intToHex)(t.id))})),"undefined"!=typeof window&&window.particle&&(window.particle.particleProvider=this)}get version(){return console.log("get version"),(0,l.getVersion)()}setConnection(){return new a.HttpConnection({url:`${(0,o.rpcUrl)()}/evm-chain`,basicCredentials:this.auth.basicCredentials(),chainId:()=>this.auth.getChainId(),authentication:this.auth.config})}emit(t,...e){return this.events.emit(t,...e)}disconnect(){return r(this,void 0,void 0,(function*(){return this.auth.logout()}))}enable(){return r(this,void 0,void 0,(function*(){return this.request({method:"eth_requestAccounts"})}))}request(t){var e,n;return r(this,void 0,void 0,(function*(){if(!t.method||c.notSupportMethods.includes(t.method))return Promise.reject(c.ProviderError.unsupportedMethod());this.connection.connected||(yield this.open()),console.log("Particle Provider Request",t);const r={chainId:Number(this.auth.getChainId()),id:null!==(e=t.id)&&void 0!==e?e:(0,i.v4)(),jsonrpc:null!==(n=t.jsonrpc)&&void 0!==n?n:"2.0",method:t.method,params:t.params};return c.signerMethods.includes(t.method)||c.particleSignerMethods.includes(t.method)?this.authAdapter.request(t):this.requestStrict(r)}))}requestStrict(t){return r(this,void 0,void 0,(function*(){return this.connection.send(t).then((t=>t.error?Promise.reject(t.error):Promise.resolve(t.result)))}))}open(){return r(this,void 0,void 0,(function*(){yield this.connection.open(),this.connection.on("close",(()=>this.emit("disconnect"))),this.emit("connect",{chainId:(0,o.intToHex)(this.auth.getChainId())})}))}close(){return r(this,void 0,void 0,(function*(){yield this.connection.close()}))}}e.ParticleProvider=u},248:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.particleSignerMethods=e.signerMethods=e.notSupportMethods=e.IJsonRpcProvider=e.IJsonRpcConnection=e.IEvents=e.ProviderError=void 0;const r=n(699);class o extends Error{constructor(t,e,n){super(e),this.code=t,this.message=e,this.data=n,this.code=t,this.message=e,this.data=n}static userRejectedRequest(){return new o(4001,"The user rejected the request")}static userCancelOperation(){return new o(4011,"The user cancel the operation")}static unauthorized(){return new o(4100,"The requested method and/or account has not been authorized by the user")}static unsupportedMethod(){return new o(4200,"The Provider does not support the requested method")}static unsupportedChain(){return new o(4201,"The Provider does not support the chain")}static disconnected(){return new o(4900,"The Provider is disconnected from all chains")}static chainDisconnected(){return new o(4901,"The Provider is not connected to the requested chain")}static paramsError(){return new o(8002,"Param error, see doc for more info")}}e.ProviderError=o;class i{}e.IEvents=i,e.IJsonRpcConnection=class extends i{constructor(){super(...arguments),this.events=new r.EventEmitter}on(t,e){return this.events.on(t,e),this}once(t,e){return this.events.once(t,e),this}off(t,e){return this.events.off(t,e),this}removeListener(t,e){return this.events.removeListener(t,e),this}},e.IJsonRpcProvider=class extends i{constructor(){super(...arguments),this.events=new r.EventEmitter}on(t,e){return this.events.on(t,e),this}once(t,e){return this.events.once(t,e),this}off(t,e){return this.events.off(t,e),this}removeListener(t,e){return this.events.removeListener(t,e),this}},e.notSupportMethods=["eth_signTransaction","eth_sendRawTransaction"],e.signerMethods=["eth_requestAccounts","eth_accounts","eth_chainId","eth_sendTransaction","eth_signTypedData","eth_signTypedData_v1","eth_signTypedData_v3","eth_signTypedData_v4","personal_sign","wallet_switchEthereumChain","wallet_addEthereumChain","wallet_watchAsset"],e.particleSignerMethods=["personal_sign_uniq","eth_signTypedData_v4_uniq"]},641:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getVersion=void 0,e.getVersion=function(){return`web_${n(147).version}`}},766:(t,e)=>{"use strict";e.byteLength=function(t){var e=c(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){var e,n,i=c(t),s=i[0],a=i[1],l=new o(function(t,e,n){return 3*(e+n)/4-n}(0,s,a)),u=0,p=a>0?s-4:s;for(n=0;n
>16&255,l[u++]=e>>8&255,l[u++]=255&e;return 2===a&&(e=r[t.charCodeAt(n)]<<2|r[t.charCodeAt(n+1)]>>4,l[u++]=255&e),1===a&&(e=r[t.charCodeAt(n)]<<10|r[t.charCodeAt(n+1)]<<4|r[t.charCodeAt(n+2)]>>2,l[u++]=e>>8&255,l[u++]=255&e),l},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],s=16383,a=0,c=r-o;a