@dodoex/wallet-web3 0.0.22-0 → 0.0.22-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/__tslib-dd22ed7d.js +1 -0
  2. package/dist/_commonjs-dynamic-modules-7cfc9805.js +1 -0
  3. package/dist/blocto-69a506f8.js +1 -0
  4. package/dist/bn-3e892825.js +1 -0
  5. package/dist/cjs/__tslib-8344f379.cjs +1 -0
  6. package/dist/cjs/_commonjs-dynamic-modules-f09a98c7.cjs +1 -0
  7. package/dist/cjs/blocto-bdab3cea.cjs +1 -0
  8. package/dist/cjs/bn-ce9dbccd.cjs +1 -0
  9. package/dist/cjs/ethers-767c2337.cjs +1 -0
  10. package/dist/cjs/id-6c4d97dd.cjs +1 -0
  11. package/dist/cjs/index-2428f0a6.cjs +1 -0
  12. package/dist/cjs/index-3d1a3da9.cjs +1 -0
  13. package/dist/cjs/index-4585c950.cjs +1 -0
  14. package/dist/cjs/index-47f3e61d.cjs +1 -0
  15. package/dist/cjs/index-4abb9db3.cjs +1 -0
  16. package/dist/cjs/index-5d7b94fd.cjs +1 -0
  17. package/dist/cjs/index-659dc842.cjs +61 -0
  18. package/dist/cjs/index-67e59d1a.cjs +1 -0
  19. package/dist/cjs/index-795ad993.cjs +46 -0
  20. package/dist/cjs/index-a5fa1e6e.cjs +15 -0
  21. package/dist/cjs/index-aa04e7a3.cjs +1 -0
  22. package/dist/cjs/index-cfe3e391.cjs +10 -0
  23. package/dist/cjs/index-d226aab9.cjs +8 -0
  24. package/dist/cjs/index-e875b498.cjs +1 -0
  25. package/dist/cjs/index-f2c04d55.cjs +1 -0
  26. package/dist/cjs/index.cjs +1 -1
  27. package/dist/cjs/index.es-a3704620.cjs +9 -0
  28. package/dist/cjs/interface-1b54eefa.cjs +1 -0
  29. package/dist/cjs/node-ponyfill-a7a0b431.cjs +1 -0
  30. package/dist/cjs/portis-ec0ce54d.cjs +1 -0
  31. package/dist/cjs/provider-403219c9.cjs +1 -0
  32. package/dist/cjs/providers/wallets/index.d.ts +1 -0
  33. package/dist/cjs/providers/wallets/types.d.ts +1 -0
  34. package/dist/cjs/rainbow-caa66e39.cjs +1 -0
  35. package/dist/cjs/uAuth-a2d2617a.cjs +1 -0
  36. package/dist/cjs/walletConnect-c57b3b5d.cjs +1 -0
  37. package/dist/cjs/walletLink-f0f9e2a7.cjs +3 -0
  38. package/dist/ethers-51e19435.js +1 -0
  39. package/dist/id-830e09aa.js +1 -0
  40. package/dist/index-0103e089.js +1 -0
  41. package/dist/index-235259d8.js +1 -0
  42. package/dist/index-3158e93a.js +46 -0
  43. package/dist/index-46c2059e.js +1 -0
  44. package/dist/index-5091218e.js +1 -0
  45. package/dist/index-5f9e8321.js +1 -0
  46. package/dist/index-650785ec.js +1 -0
  47. package/dist/index-6bf494b0.js +1 -0
  48. package/dist/index-80483be2.js +8 -0
  49. package/dist/index-82b4fd64.js +60 -0
  50. package/dist/index-88837567.js +1 -0
  51. package/dist/index-c699a924.js +1 -0
  52. package/dist/index-cc453bb1.js +10 -0
  53. package/dist/index-de37f6bb.js +1 -0
  54. package/dist/index-f3052552.js +15 -0
  55. package/dist/index.es-877101c5.js +9 -0
  56. package/dist/index.js +1 -1
  57. package/dist/interface-f97a878a.js +1 -0
  58. package/dist/node-ponyfill-55b945e1.js +1 -0
  59. package/dist/portis-7d46b7ed.js +1 -0
  60. package/dist/provider-453e2483.js +1 -0
  61. package/dist/providers/wallets/index.d.ts +1 -0
  62. package/dist/providers/wallets/types.d.ts +1 -0
  63. package/dist/rainbow-61a52379.js +1 -0
  64. package/dist/uAuth-40d8acab.js +1 -0
  65. package/dist/walletConnect-d6a9aa67.js +1 -0
  66. package/dist/walletLink-106461e6.js +3 -0
  67. package/package.json +1 -1
  68. package/dist/blocto-81ce4cf0.js +0 -1
  69. package/dist/cjs/blocto-f4eca78a.cjs +0 -1
  70. package/dist/cjs/index-1aadca5d.cjs +0 -1
  71. package/dist/cjs/index-473f668c.cjs +0 -1
  72. package/dist/cjs/index-49e73d05.cjs +0 -1
  73. package/dist/cjs/index-8974ffc5.cjs +0 -1
  74. package/dist/cjs/index-9ca64306.cjs +0 -1
  75. package/dist/cjs/index-adec4f81.cjs +0 -1
  76. package/dist/cjs/portis-a7e7fb1a.cjs +0 -1
  77. package/dist/cjs/provider-c81ebdd6.cjs +0 -1
  78. package/dist/cjs/rainbow-7aaa17ca.cjs +0 -1
  79. package/dist/cjs/uAuth-d88a18fe.cjs +0 -1
  80. package/dist/cjs/walletConnect-1ed400eb.cjs +0 -1
  81. package/dist/cjs/walletLink-d7276923.cjs +0 -1
  82. package/dist/index-0915d9cd.js +0 -1
  83. package/dist/index-21b99e8f.js +0 -1
  84. package/dist/index-3f9057c8.js +0 -1
  85. package/dist/index-52b5f0d3.js +0 -1
  86. package/dist/index-7f590b21.js +0 -1
  87. package/dist/index-cb8cb0f4.js +0 -1
  88. package/dist/portis-2c8e6003.js +0 -1
  89. package/dist/provider-cd132432.js +0 -1
  90. package/dist/rainbow-7046183a.js +0 -1
  91. package/dist/uAuth-c3577e9b.js +0 -1
  92. package/dist/walletConnect-5350d3f5.js +0 -1
  93. package/dist/walletLink-69a6e65f.js +0 -1
@@ -0,0 +1 @@
1
+ import{g as r,j as a}from"./index-cc453bb1.js";var s=r(a);export{s as r};
@@ -0,0 +1 @@
1
+ function r(r){throw new Error('Could not dynamically require "'+r+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}export{r as c};
@@ -0,0 +1 @@
1
+ import{_ as t,d as e}from"./index-cc453bb1.js";import"events";import"@ethersproject/providers";import"zustand";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"@ethersproject/properties";import"@ethersproject/transactions";import"@ethersproject/bytes";function n(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((r=r.apply(t,e||[])).next())}))}function r(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function i(t,e){if(!t)throw new Error(e)}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",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io"},o={1:"ethereum",5:"ethereum",56:"bsc",97:"bsc",137:"polygon",80001:"polygon",43114:"avalanche",43113:"avalanche",42161:"arbitrum",421613:"arbitrum",10:"optimism",420:"optimism"},a={1:"mainnet",5:"testnet",56:"mainnet",97:"testnet",137:"mainnet",80001:"testnet",43114:"mainnet",43113:"testnet",42161:"mainnet",421613:"testnet",10:"mainnet",420:"testnet"},c={1:"https://wallet-v2.blocto.app",5:"https://wallet-v2-dev.blocto.app",56:"https://wallet-v2.blocto.app",97:"https://wallet-v2-dev.blocto.app",137:"https://wallet-v2.blocto.app",80001:"https://wallet-v2-dev.blocto.app",43114:"https://wallet-v2.blocto.app",43113:"https://wallet-v2-dev.blocto.app",42161:"https://wallet-v2.blocto.app",421613:"https://wallet-v2-dev.blocto.app",10:"https://wallet-v2.blocto.app",420:"https://wallet-v2-dev.blocto.app"},h={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},u={devnet:"https://wallet-v2-dev.blocto.app",testnet:"https://wallet-v2-dev.blocto.app","mainnet-beta":"https://wallet-v2.blocto.app"},d=["devnet","testnet","mainnet-beta"],l={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 p;!function(t){t.Mainnet="mainnet",t.Testnet="testnet",t.Devnet="devnet",t.Testing="testing",t.Premainnet="premainnet"}(p||(p={}));const f={1:p.Mainnet,2:p.Testnet,3:p.Devnet,4:p.Testing,5:p.Premainnet},g={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"},w=["connect","disconnect","message","chainChanged","accountsChanged"],v=864e5,y="00000000-0000-0000-0000-000000000000",m="sdk.session";const b="undefined"!=typeof window?window.memoryStorage:new class{constructor(){this.storage={}}getItem(t){return this[t]||null}setItem(t,e){this.storage[t]=e}removeItem(t){delete this.storage[t]}};"undefined"!=typeof window&&(window.memoryStorage=b);const E=(()=>{if("undefined"==typeof window)return!1;try{window.localStorage.setItem("local_storage_supported","1");const t=window.localStorage.getItem("local_storage_supported");return window.localStorage.removeItem("local_storage_supported"),"1"===t}catch(t){return!1}})()?window.localStorage:b,A=(t,e=null)=>{const n=((t,e=null)=>{const n=E.getItem(t);try{return n&&JSON.parse(n)||e}catch(t){return n||e}})(t,null);return n?(new Date).getTime()>n.expiry?(T(t),e):n.value:e},I=(t,e)=>E.setItem(t,"string"==typeof e?e:JSON.stringify(e)),S=(t,e,n)=>I(t,{value:e,expiry:(new Date).getTime()+n}),T=t=>{I(t,""),E.removeItem(t)};class _{constructor(t){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.sessionKey=m,this.off=this.removeListener,this.session=t,w.forEach((t=>{this.eventListeners[t]=[]}))}formatAndSetSessionAccount(t={}){this.session.accounts=Object.keys(t).reduce(((e,n)=>(e[n]=[t[n]],e)),{})}tryRetrieveSessionFromStorage(t){const e=A(this.sessionKey,{}),n=e&&e.code,r=e&&e.address&&e.address[t];this.session.connected=Boolean(n&&r),this.session.code=n||null,this.formatAndSetSessionAccount(e?e.address:{})}request(t){return n(this,void 0,void 0,(function*(){}))}on(t,e){w.includes(t)&&this.eventListeners[t].push(e)}once(){}removeListener(t,e){const n=this.eventListeners[t].findIndex((t=>t===e));-1!==n&&this.eventListeners[t].splice(n,1)}}function R(t){const e=document.createElement("iframe");return e.setAttribute("src",t),e.setAttribute("style","width:100vw;height:100%;position:fixed;top:0;left:0;z-index:2147483646;border:none;"),e}function P(t){document.body.appendChild(t)}function O(t){const e=t&&t.parentNode;e&&e.removeChild instanceof Function&&e.removeChild(t)}var B=(t,e,n=window)=>{n.addEventListener(t,(function r(i){e(i,(()=>n.removeEventListener(t,r)))}))};function C(t,e){return n(this,void 0,void 0,(function*(){if(403===t.status)throw e.session.code=null,T(e.sessionKey),new Error("[Blocto SDK]: Session expired!");return t.json()}))}const U=t=>/\S+@\S+\.\S+/.test(t);function k(){return n(this,void 0,void 0,(function*(){const{networks:t}=yield fetch("https://api.blocto.app/networks/evm").then((t=>t.json()));return t.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.chain_id]:e})),{})}))}var N,M,L;function D(t){return t?"number"==typeof t?t:t.startsWith("0x")?parseInt(t,16):parseInt(t,10):1}class j extends _{constructor({chainId:t,rpc:e,server:n,appId:r,session:h}){super(h),N.add(this),this.supportNetwork={},this.switchableNetwork={},i(t,"'chainId' is required"),this.chainId=D(t),this.networkId=this.chainId,this.chain=o[this.chainId],this.net=a[this.chainId],i(this.chain,`unsupported 'chainId': ${this.chainId}`),this.rpc=e||s[this.chainId]||"",i(this.rpc,"'rpc' is required for Ethereum"),this.server=n||c[this.chainId]||"",this.appId=r||y,this.switchableNetwork[this.chainId]={name:this.chain,display_name:this.chain,network_type:this.net,wallet_web_url:this.server,rpc_url:this.rpc}}loadSwitchableNetwork(t){return n(this,void 0,void 0,(function*(){return k().then((e=>(this.supportNetwork=e,(null==t?void 0:t.length)&&t.forEach((({chainId:t,rpcUrls:e})=>{if(i(e,"rpcUrls is required for networksList"),!(null==e?void 0:e.length))throw new Error("Empty rpcUrls array");r(this,N,"m",M).call(this,{chainId:D(t),rpcUrls:e})})),null)))}))}send(t,e){return n(this,void 0,void 0,(function*(){switch(!0){case e instanceof Function:return this.sendAsync(t,e);case"string"==typeof t&&Array.isArray(e):return this.sendAsync({jsonrpc:"2.0",method:t,params:e});default:return this.sendAsync(t)}}))}sendAsync(t,e){return n(this,void 0,void 0,(function*(){const n=new Promise((e=>{if(Array.isArray(t)){const n=t.filter((t=>"eth_sendTransaction"===t.method)).map((t=>{var e;return null===(e=t.params)||void 0===e?void 0:e[0]})),r=Math.floor(1e4*Math.random()),i={method:"blocto_sendBatchTransaction",params:n},s=this.request(i),o=t.map((({method:t,params:e},n)=>"eth_sendTransaction"===t?s:this.request({id:r+n+1,jsonrpc:"2.0",method:t,params:e})));Promise.allSettled(o).then((n=>e(n.map(((e,n)=>({id:String(r+n+1),jsonrpc:"2.0",method:t[n].method,result:"fulfilled"===e.status?e.value:void 0,error:"fulfilled"!==e.status?e.reason:void 0}))))))}else this.request(Object.assign(Object.assign({},t),{id:Number(t.id)})).then(e)}));if(!e)return n;n.then((t=>e(null,t))).catch((t=>e(t)))}))}request(t){var e,s,o,a,c,h,u;return n(this,void 0,void 0,(function*(){const n=window.ethereum;if(n&&n.isBlocto)return n.request(t);if(!this.session.connected){const n=null===(e=null==t?void 0:t.params)||void 0===e?void 0:e[0];"eth_requestAccounts"===t.method&&U(n)?yield this.enable(n):yield this.enable()}try{let e=null,n=null;switch(t.method){case"eth_requestAccounts":yield this.fetchAccounts();case"eth_accounts":n=this.session.accounts[this.chain];break;case"eth_coinbase":n=this.session.accounts[this.chain][0];break;case"eth_chainId":n=this.chainId,n=`0x${n.toString(16)}`;break;case"net_version":n=this.networkId||this.chainId,n=`0x${n.toString(16)}`;break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":case"eth_sign":n=yield this.handleSign(t);break;case"wallet_disconnect":this.handleDisconnect(),n=null;break;case"blocto_sendBatchTransaction":case"eth_sendTransaction":n=yield this.handleSendTransaction(t);break;case"eth_signTransaction":case"eth_sendRawTransaction":n=null;break;case"wallet_addEthereumChain":if(!(null===(o=null===(s=null==t?void 0:t.params)||void 0===s?void 0:s[0])||void 0===o?void 0:o.chainId)||!(null===(c=null===(a=null==t?void 0:t.params)||void 0===a?void 0:a[0])||void 0===c?void 0:c.rpcUrls.length))throw new Error("Invalid params");yield k().then((e=>{var n,i,s;this.supportNetwork=e,r(this,N,"m",M).call(this,{chainId:D(null===(i=null===(n=null==t?void 0:t.params)||void 0===n?void 0:n[0])||void 0===i?void 0:i.chainId),rpcUrls:null===(s=null==t?void 0:t.params)||void 0===s?void 0:s[0].rpcUrls})})),n=null;break;case"wallet_switchEthereumChain":if(!(null===(u=null===(h=null==t?void 0:t.params)||void 0===h?void 0:h[0])||void 0===u?void 0:u.chainId))throw new Error("Invalid params");if(!this.switchableNetwork[D(t.params[0].chainId)]){const t=new Error("This chain has not been added to SDK. Please try wallet_addEthereumChain first.");throw t.code=4902,t}this.chainId=D(t.params[0].chainId),this.networkId=this.chainId,this.chain=this.switchableNetwork[this.chainId].name,this.net=this.switchableNetwork[this.chainId].network_type,i(this.chain,`unsupported 'chainId': ${this.chainId}`),this.rpc=this.switchableNetwork[this.chainId].rpc_url,i(this.rpc,"'rpc' is required"),this.server=this.switchableNetwork[this.chainId].wallet_web_url,yield this.fetchAccounts(),this.eventListeners.chainChanged.forEach((t=>t(this.chainId))),n=null;break;default:e=yield this.handleReadRequests(t)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw new Error(t)}return e?e.result:n}catch(t){throw console.error(t),t}}))}enable(t){return n(this,void 0,void 0,(function*(){const e=window.ethereum;if(e&&e.isBlocto){if(parseInt(e.chainId,16)!==this.chainId)try{yield e.request({method:"wallet_addEthereumChain",params:[{chainId:`0x${this.chainId.toString(16)}`}]}),this.session.accounts[this.chain]=[e.address]}catch(t){console.error(t)}return new Promise(((t,n)=>setTimeout((()=>e.enable().then(t).catch(n)),10)))}return this.tryRetrieveSessionFromStorage(this.chain),new Promise(((e,n)=>{if("undefined"==typeof window)return n("Currently only supported in browser");if(this.session.connected)return e(this.session.accounts[this.chain]);const r=new URLSearchParams;r.set("l6n",window.location.origin);const i=t&&U(t)?`/${t}`:"",s=R(`${this.server}/${this.appId}/${this.chain}/authn${i}?${r.toString()}`);P(s),B("message",((t,r)=>{const i=t;if(i.origin===this.server){if("ETH:FRAME:RESPONSE"===i.data.type){r(),O(s),this.session.code=i.data.code,this.session.connected=!0,this.eventListeners.connect.forEach((t=>t(this.chainId)));const t=i.data.address;this.formatAndSetSessionAccount(t),S(this.sessionKey,{code:this.session.code,address:t},v),e(this.session.accounts[this.chain])}"ETH:FRAME:CLOSE"===i.data.type&&(r(),O(s),n(new Error("User declined the login request")))}}))}))}))}fetchAccounts(){return n(this,void 0,void 0,(function*(){r(this,N,"m",L).call(this);const{accounts:t}=yield fetch(`${this.server}/api/${this.chain}/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>C(t,this)));return this.session.accounts[this.chain]=t,t}))}handleReadRequests(t){return n(this,void 0,void 0,(function*(){return r(this,N,"m",L).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then((t=>t.json()))}))}handleSign({method:t,params:e}){return n(this,void 0,void 0,(function*(){let n="";if(Array.isArray(e))if("eth_sign"===t)n=e[1].slice(2);else if("personal_sign"===t)n=e[0].slice(2);else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(t)){n=e[1];const{domain:t}=JSON.parse(n);if(D(t.chainId)!==D(this.chainId))throw new Error(`Provided chainId "${t.chainId}" must match the active chainId "${this.chainId}"`)}r(this,N,"m",L).call(this);const{signatureId:i}=yield fetch(`${this.server}/api/${this.chain}/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify({method:t,message:n})}).then((t=>C(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const s=R(`${this.server}/${this.appId}/${this.chain}/user-signature/${i}`);return P(s),new Promise(((t,e)=>B("message",((n,r)=>{const i=n;i.origin===this.server&&"ETH:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(r(),O(s),t(i.data.signature)),"DECLINED"===i.data.status&&(r(),O(s),e(new Error(i.data.errorMessage))))}))))}))}handleSendTransaction(t){return n(this,void 0,void 0,(function*(){r(this,N,"m",L).call(this);const{authorizationId:e}=yield fetch(`${this.server}/api/${this.chain}/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>C(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const n=R(`${this.server}/${this.appId}/${this.chain}/authz/${e}`);return P(n),new Promise(((t,e)=>B("message",((r,i)=>{const s=r;s.origin===this.server&&"ETH:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(i(),O(n),t(s.data.txHash)),"DECLINED"===s.data.status&&(i(),O(n),e(new Error(s.data.errorMessage))))}))))}))}handleDisconnect(){return n(this,void 0,void 0,(function*(){this.session.connected=!1,this.session.code=null,this.session.accounts={},T(m)}))}}N=new WeakSet,M=function({chainId:t,rpcUrls:e}){const n=new URL(e[0]).hostname,{chain_id:r,name:i,display_name:s,network_type:o,blocto_service_environment:a,rpc_endpoint_domains:c}=this.supportNetwork[t];if(c.includes(n)){const t=h[a];this.switchableNetwork[r]={name:i,display_name:s,network_type:o,wallet_web_url:t,rpc_url:e[0]}}else console.warn(`The rpc url ${e[0]} is not supported.`)},L=function(){const t=window.ethereum;if(t&&t.isBlocto&&parseInt(t.chainId,16)!==this.chainId)throw new Error("Blocto SDK network mismatched")};var $=[],x=[],Y="undefined"!=typeof Uint8Array?Uint8Array:Array,q=!1;function K(){q=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)$[e]=t[e],x[t.charCodeAt(e)]=e;x["-".charCodeAt(0)]=62,x["_".charCodeAt(0)]=63}function F(t,e,n){for(var r,i,s=[],o=e;o<n;o+=3)r=(t[o]<<16)+(t[o+1]<<8)+t[o+2],s.push($[(i=r)>>18&63]+$[i>>12&63]+$[i>>6&63]+$[63&i]);return s.join("")}function z(t){var e;q||K();for(var n=t.length,r=n%3,i="",s=[],o=16383,a=0,c=n-r;a<c;a+=o)s.push(F(t,a,a+o>c?c:a+o));return 1===r?(e=t[n-1],i+=$[e>>2],i+=$[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=$[e>>10],i+=$[e>>4&63],i+=$[e<<2&63],i+="="),s.push(i),s.join("")}function J(t,e,n,r,i){var s,o,a=8*i-r-1,c=(1<<a)-1,h=c>>1,u=-7,d=n?i-1:0,l=n?-1:1,p=t[e+d];for(d+=l,s=p&(1<<-u)-1,p>>=-u,u+=a;u>0;s=256*s+t[e+d],d+=l,u-=8);for(o=s&(1<<-u)-1,s>>=-u,u+=r;u>0;o=256*o+t[e+d],d+=l,u-=8);if(0===s)s=1-h;else{if(s===c)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,r),s-=h}return(p?-1:1)*o*Math.pow(2,s-r)}function W(t,e,n,r,i,s){var o,a,c,h=8*s-i-1,u=(1<<h)-1,d=u>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:s-1,f=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-o))<1&&(o--,c*=2),(e+=o+d>=1?l/c:l*Math.pow(2,1-d))*c>=2&&(o++,c/=2),o+d>=u?(a=0,o=u):o+d>=1?(a=(e*c-1)*Math.pow(2,i),o+=d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),o=0));i>=8;t[n+p]=255&a,p+=f,a/=256,i-=8);for(o=o<<i|a,h+=i;h>0;t[n+p]=255&o,p+=f,o/=256,h-=8);t[n+p-f]|=128*g}var V={}.toString,H=Array.isArray||function(t){return"[object Array]"==V.call(t)};function Z(){return Q.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function G(t,e){if(Z()<e)throw new RangeError("Invalid typed array length");return Q.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=Q.prototype:(null===t&&(t=new Q(e)),t.length=e),t}function Q(t,e,n){if(!(Q.TYPED_ARRAY_SUPPORT||this instanceof Q))return new Q(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return et(this,t)}return X(this,t,e,n)}function X(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r);Q.TYPED_ARRAY_SUPPORT?(t=e).__proto__=Q.prototype:t=nt(t,e);return t}(t,e,n,r):"string"==typeof e?function(t,e,n){"string"==typeof n&&""!==n||(n="utf8");if(!Q.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|st(e,n);t=G(t,r);var i=t.write(e,n);i!==r&&(t=t.slice(0,i));return t}(t,e,n):function(t,e){if(it(e)){var n=0|rt(e.length);return 0===(t=G(t,n)).length||e.copy(t,0,0,n),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?G(t,0):nt(t,e);if("Buffer"===e.type&&H(e.data))return nt(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function tt(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function et(t,e){if(tt(e),t=G(t,e<0?0:0|rt(e)),!Q.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function nt(t,e){var n=e.length<0?0:0|rt(e.length);t=G(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function rt(t){if(t>=Z())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Z().toString(16)+" bytes");return 0|t}function it(t){return!(null==t||!t._isBuffer)}function st(t,e){if(it(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return Ut(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return kt(t).length;default:if(r)return Ut(t).length;e=(""+e).toLowerCase(),r=!0}}function ot(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return Et(this,e,n);case"utf8":case"utf-8":return vt(this,e,n);case"ascii":return mt(this,e,n);case"latin1":case"binary":return bt(this,e,n);case"base64":return wt(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return At(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function at(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function ct(t,e,n,r,i){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=Q.from(e,r)),it(e))return 0===e.length?-1:ht(t,e,n,r,i);if("number"==typeof e)return e&=255,Q.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):ht(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function ht(t,e,n,r,i){var s,o=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;o=2,a/=2,c/=2,n/=2}function h(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){var u=-1;for(s=n;s<a;s++)if(h(t,s)===h(e,-1===u?0:s-u)){if(-1===u&&(u=s),s-u+1===c)return u*o}else-1!==u&&(s-=s-u),u=-1}else for(n+c>a&&(n=a-c),s=n;s>=0;s--){for(var d=!0,l=0;l<c;l++)if(h(t,s+l)!==h(e,l)){d=!1;break}if(d)return s}return-1}function ut(t,e,n,r){n=Number(n)||0;var i=t.length-n;r?(r=Number(r))>i&&(r=i):r=i;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o<r;++o){var a=parseInt(e.substr(2*o,2),16);if(isNaN(a))return o;t[n+o]=a}return o}function dt(t,e,n,r){return Nt(Ut(e,t.length-n),t,n,r)}function lt(t,e,n,r){return Nt(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function pt(t,e,n,r){return lt(t,e,n,r)}function ft(t,e,n,r){return Nt(kt(e),t,n,r)}function gt(t,e,n,r){return Nt(function(t,e){for(var n,r,i,s=[],o=0;o<t.length&&!((e-=2)<0);++o)r=(n=t.charCodeAt(o))>>8,i=n%256,s.push(i),s.push(r);return s}(e,t.length-n),t,n,r)}function wt(t,e,n){return 0===e&&n===t.length?z(t):z(t.slice(e,n))}function vt(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i<n;){var s,o,a,c,h=t[i],u=null,d=h>239?4:h>223?3:h>191?2:1;if(i+d<=n)switch(d){case 1:h<128&&(u=h);break;case 2:128==(192&(s=t[i+1]))&&(c=(31&h)<<6|63&s)>127&&(u=c);break;case 3:s=t[i+1],o=t[i+2],128==(192&s)&&128==(192&o)&&(c=(15&h)<<12|(63&s)<<6|63&o)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:s=t[i+1],o=t[i+2],a=t[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(c=(15&h)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&c<1114112&&(u=c)}null===u?(u=65533,d=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|1023&u),r.push(u),i+=d}return function(t){var e=t.length;if(e<=yt)return String.fromCharCode.apply(String,t);var n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=yt));return n}(r)}Q.TYPED_ARRAY_SUPPORT=void 0===global.TYPED_ARRAY_SUPPORT||global.TYPED_ARRAY_SUPPORT,Z(),Q.poolSize=8192,Q._augment=function(t){return t.__proto__=Q.prototype,t},Q.from=function(t,e,n){return X(null,t,e,n)},Q.TYPED_ARRAY_SUPPORT&&(Q.prototype.__proto__=Uint8Array.prototype,Q.__proto__=Uint8Array),Q.alloc=function(t,e,n){return function(t,e,n,r){return tt(e),e<=0?G(t,e):void 0!==n?"string"==typeof r?G(t,e).fill(n,r):G(t,e).fill(n):G(t,e)}(null,t,e,n)},Q.allocUnsafe=function(t){return et(null,t)},Q.allocUnsafeSlow=function(t){return et(null,t)},Q.isBuffer=function(t){return null!=t&&(!!t._isBuffer||Mt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Mt(t.slice(0,0))}(t))},Q.compare=function(t,e){if(!it(t)||!it(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,i=0,s=Math.min(n,r);i<s;++i)if(t[i]!==e[i]){n=t[i],r=e[i];break}return n<r?-1:r<n?1:0},Q.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Q.concat=function(t,e){if(!H(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return Q.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=Q.allocUnsafe(e),i=0;for(n=0;n<t.length;++n){var s=t[n];if(!it(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,i),i+=s.length}return r},Q.byteLength=st,Q.prototype._isBuffer=!0,Q.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)at(this,e,e+1);return this},Q.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)at(this,e,e+3),at(this,e+1,e+2);return this},Q.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)at(this,e,e+7),at(this,e+1,e+6),at(this,e+2,e+5),at(this,e+3,e+4);return this},Q.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?vt(this,0,t):ot.apply(this,arguments)},Q.prototype.equals=function(t){if(!it(t))throw new TypeError("Argument must be a Buffer");return this===t||0===Q.compare(this,t)},Q.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},Q.prototype.compare=function(t,e,n,r,i){if(!it(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(this===t)return 0;for(var s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(e>>>=0),a=Math.min(s,o),c=this.slice(r,i),h=t.slice(e,n),u=0;u<a;++u)if(c[u]!==h[u]){s=c[u],o=h[u];break}return s<o?-1:o<s?1:0},Q.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},Q.prototype.indexOf=function(t,e,n){return ct(this,t,e,n,!0)},Q.prototype.lastIndexOf=function(t,e,n){return ct(this,t,e,n,!1)},Q.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-e;if((void 0===n||n>i)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return ut(this,t,e,n);case"utf8":case"utf-8":return dt(this,t,e,n);case"ascii":return lt(this,t,e,n);case"latin1":case"binary":return pt(this,t,e,n);case"base64":return ft(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return gt(this,t,e,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},Q.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var yt=4096;function mt(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;i<n;++i)r+=String.fromCharCode(127&t[i]);return r}function bt(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;i<n;++i)r+=String.fromCharCode(t[i]);return r}function Et(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var i="",s=e;s<n;++s)i+=Ct(t[s]);return i}function At(t,e,n){for(var r=t.slice(e,n),i="",s=0;s<r.length;s+=2)i+=String.fromCharCode(r[s]+256*r[s+1]);return i}function It(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function St(t,e,n,r,i,s){if(!it(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function Tt(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,s=Math.min(t.length-n,2);i<s;++i)t[n+i]=(e&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function _t(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,s=Math.min(t.length-n,4);i<s;++i)t[n+i]=e>>>8*(r?i:3-i)&255}function Rt(t,e,n,r,i,s){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Pt(t,e,n,r,i){return i||Rt(t,0,n,4),W(t,e,n,r,23,4),n+4}function Ot(t,e,n,r,i){return i||Rt(t,0,n,8),W(t,e,n,r,52,8),n+8}Q.prototype.slice=function(t,e){var n,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),Q.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=Q.prototype;else{var i=e-t;n=new Q(i,void 0);for(var s=0;s<i;++s)n[s]=this[s+t]}return n},Q.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||It(t,e,this.length);for(var r=this[t],i=1,s=0;++s<e&&(i*=256);)r+=this[t+s]*i;return r},Q.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||It(t,e,this.length);for(var r=this[t+--e],i=1;e>0&&(i*=256);)r+=this[t+--e]*i;return r},Q.prototype.readUInt8=function(t,e){return e||It(t,1,this.length),this[t]},Q.prototype.readUInt16LE=function(t,e){return e||It(t,2,this.length),this[t]|this[t+1]<<8},Q.prototype.readUInt16BE=function(t,e){return e||It(t,2,this.length),this[t]<<8|this[t+1]},Q.prototype.readUInt32LE=function(t,e){return e||It(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Q.prototype.readUInt32BE=function(t,e){return e||It(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Q.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||It(t,e,this.length);for(var r=this[t],i=1,s=0;++s<e&&(i*=256);)r+=this[t+s]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*e)),r},Q.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||It(t,e,this.length);for(var r=e,i=1,s=this[t+--r];r>0&&(i*=256);)s+=this[t+--r]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*e)),s},Q.prototype.readInt8=function(t,e){return e||It(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Q.prototype.readInt16LE=function(t,e){e||It(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},Q.prototype.readInt16BE=function(t,e){e||It(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},Q.prototype.readInt32LE=function(t,e){return e||It(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Q.prototype.readInt32BE=function(t,e){return e||It(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Q.prototype.readFloatLE=function(t,e){return e||It(t,4,this.length),J(this,t,!0,23,4)},Q.prototype.readFloatBE=function(t,e){return e||It(t,4,this.length),J(this,t,!1,23,4)},Q.prototype.readDoubleLE=function(t,e){return e||It(t,8,this.length),J(this,t,!0,52,8)},Q.prototype.readDoubleBE=function(t,e){return e||It(t,8,this.length),J(this,t,!1,52,8)},Q.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||St(this,t,e,n,Math.pow(2,8*n)-1,0);var i=1,s=0;for(this[e]=255&t;++s<n&&(i*=256);)this[e+s]=t/i&255;return e+n},Q.prototype.writeUIntBE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||St(this,t,e,n,Math.pow(2,8*n)-1,0);var i=n-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+n},Q.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,1,255,0),Q.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Q.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,2,65535,0),Q.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Tt(this,t,e,!0),e+2},Q.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,2,65535,0),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Tt(this,t,e,!1),e+2},Q.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,4,4294967295,0),Q.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):_t(this,t,e,!0),e+4},Q.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,4,4294967295,0),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):_t(this,t,e,!1),e+4},Q.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);St(this,t,e,n,i-1,-i)}var s=0,o=1,a=0;for(this[e]=255&t;++s<n&&(o*=256);)t<0&&0===a&&0!==this[e+s-1]&&(a=1),this[e+s]=(t/o>>0)-a&255;return e+n},Q.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);St(this,t,e,n,i-1,-i)}var s=n-1,o=1,a=0;for(this[e+s]=255&t;--s>=0&&(o*=256);)t<0&&0===a&&0!==this[e+s+1]&&(a=1),this[e+s]=(t/o>>0)-a&255;return e+n},Q.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,1,127,-128),Q.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},Q.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,2,32767,-32768),Q.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Tt(this,t,e,!0),e+2},Q.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,2,32767,-32768),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Tt(this,t,e,!1),e+2},Q.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,4,2147483647,-2147483648),Q.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):_t(this,t,e,!0),e+4},Q.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||St(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):_t(this,t,e,!1),e+4},Q.prototype.writeFloatLE=function(t,e,n){return Pt(this,t,e,!0,n)},Q.prototype.writeFloatBE=function(t,e,n){return Pt(this,t,e,!1,n)},Q.prototype.writeDoubleLE=function(t,e,n){return Ot(this,t,e,!0,n)},Q.prototype.writeDoubleBE=function(t,e,n){return Ot(this,t,e,!1,n)},Q.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var i,s=r-n;if(this===t&&n<e&&e<r)for(i=s-1;i>=0;--i)t[i+e]=this[i+n];else if(s<1e3||!Q.TYPED_ARRAY_SUPPORT)for(i=0;i<s;++i)t[i+e]=this[i+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+s),e);return s},Q.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!Q.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var s;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(s=e;s<n;++s)this[s]=t;else{var o=it(t)?t:Ut(new Q(t,r).toString()),a=o.length;for(s=0;s<n-e;++s)this[s+e]=o[s%a]}return this};var Bt=/[^+\/0-9A-Za-z-_]/g;function Ct(t){return t<16?"0"+t.toString(16):t.toString(16)}function Ut(t,e){var n;e=e||1/0;for(var r=t.length,i=null,s=[],o=0;o<r;++o){if((n=t.charCodeAt(o))>55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===r){(e-=3)>-1&&s.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&s.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;s.push(n)}else if(n<2048){if((e-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function kt(t){return function(t){var e,n,r,i,s,o;q||K();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s="="===t[a-2]?2:"="===t[a-1]?1:0,o=new Y(3*a/4-s),r=s>0?a-4:a;var c=0;for(e=0,n=0;e<r;e+=4,n+=3)i=x[t.charCodeAt(e)]<<18|x[t.charCodeAt(e+1)]<<12|x[t.charCodeAt(e+2)]<<6|x[t.charCodeAt(e+3)],o[c++]=i>>16&255,o[c++]=i>>8&255,o[c++]=255&i;return 2===s?(i=x[t.charCodeAt(e)]<<2|x[t.charCodeAt(e+1)]>>4,o[c++]=255&i):1===s&&(i=x[t.charCodeAt(e)]<<10|x[t.charCodeAt(e+1)]<<4|x[t.charCodeAt(e+2)]>>2,o[c++]=i>>8&255,o[c++]=255&i),o}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Bt,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Nt(t,e,n,r){for(var i=0;i<r&&!(i+n>=e.length||i>=t.length);++i)e[i+n]=t[i];return i}function Mt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function Lt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Dt=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var i=t.charAt(r),s=i.charCodeAt(0);if(255!==e[s])throw new TypeError(i+" is ambiguous");e[s]=r}var o=t.length,a=t.charAt(0),c=Math.log(o)/Math.log(256),h=Math.log(256)/Math.log(o);function u(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var n=0,r=0,i=0;t[n]===a;)r++,n++;for(var s=(t.length-n)*c+1>>>0,h=new Uint8Array(s);t[n];){var u=e[t.charCodeAt(n)];if(255===u)return;for(var d=0,l=s-1;(0!==u||d<i)&&-1!==l;l--,d++)u+=o*h[l]>>>0,h[l]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");i=d,n++}for(var p=s-i;p!==s&&0===h[p];)p++;for(var f=new Uint8Array(r+(s-p)),g=r;p!==s;)f[g++]=h[p++];return f}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var n=0,r=0,i=0,s=e.length;i!==s&&0===e[i];)i++,n++;for(var c=(s-i)*h+1>>>0,u=new Uint8Array(c);i!==s;){for(var d=e[i],l=0,p=c-1;(0!==d||l<r)&&-1!==p;p--,l++)d+=256*u[p]>>>0,u[p]=d%o>>>0,d=d/o>>>0;if(0!==d)throw new Error("Non-zero carry");r=l,i++}for(var f=c-r;f!==c&&0===u[f];)f++;for(var g=a.repeat(n);f<c;++f)g+=t.charAt(u[f]);return g},decodeUnsafe:u,decode:function(t){var e=u(t);if(e)return e;throw new Error("Non-base"+o+" character")}}};var jt=Lt(Dt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));let $t;try{$t=require("@solana/web3.js")}catch(t){}class xt extends _{constructor({net:t="mainnet-beta",server:e,appId:n,rpc:r,session:s}){if(super(s),i(t,"'net' is required"),i(d.includes(t),"unsupported net"),this.net=t,this.rpc=r||("mainnet-beta"===t?"https://free.rpcpool.com":`https://api.${t}.solana.com`),this.server=e||u[this.net]||"",this.appId=n||y,!$t)throw new Error("No @solana/web3.js installed. Please install it to interact with Solana.")}request(t){return n(this,void 0,void 0,(function*(){this.session.connected||(yield this.connect());try{let e=null,n=null;switch(t.method){case"connect":n=yield this.fetchAccounts();break;case"disconnect":this.disconnect();break;case"getAccounts":n=this.session.accounts.solana.length?this.session.accounts.solana:yield this.fetchAccounts();break;case"getAccountInfo":{const e=yield this.handleReadRequests(t),[r,i]=e.result.value.data;n=Object.assign(Object.assign({},e.result.value),{data:Q.from(r,i),owner:new $t.PublicKey(e.result.value.owner)});break}case"convertToProgramWalletTransaction":n=yield this.handleConvertTransaction(t);break;case"signAndSendTransaction":n=yield this.handleSignAndSendTransaction(t);break;case"signTransaction":case"signAllTransactions":throw new Error(`Blocto is program wallet, which doesn't support ${t.method}. Use signAndSendTransaction instead.`);default:e=yield this.handleReadRequests(t)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw new Error(t)}return e?e.result:n}catch(t){throw console.error(t),t}}))}connect(){return n(this,void 0,void 0,(function*(){const t=window.solana;return t&&t.isBlocto?new Promise((e=>{t.on("connect",(()=>{this.session.accounts.solana=[t.publicKey.toBase58()],e()})),t.connect()})):(this.tryRetrieveSessionFromStorage("solana"),new Promise(((t,e)=>{if("undefined"==typeof window)return e("Currently only supported in browser");if(this.session.connected)return t();const n=encodeURIComponent(window.location.origin),r=R(`${this.server}/${this.appId}/solana/authn?l6n=${n}`);P(r),B("message",((n,i)=>{const s=n;if(s.origin===this.server){if("SOL:FRAME:RESPONSE"===s.data.type){i(),O(r),this.session.code=s.data.code,this.session.connected=!0,this.eventListeners.connect.forEach((t=>t(this.net)));const e=s.data.address;this.formatAndSetSessionAccount(e),S(this.sessionKey,{code:this.session.code,address:e},v),t()}"SOL:FRAME:CLOSE"===s.data.type&&(i(),O(r),e(new Error("User declined the login request")))}}))})))}))}disconnect(){return n(this,void 0,void 0,(function*(){const t=window.solana;t&&t.isBlocto?yield t.disconnect():(this.session.code=null,this.session.accounts={},this.eventListeners.disconnect.forEach((t=>t(null))),this.session.connected=!1)}))}fetchAccounts(){return n(this,void 0,void 0,(function*(){const{accounts:t}=yield fetch(`${this.server}/api/solana/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>t.json()));return this.session.accounts.solana=t,t}))}handleReadRequests(t){return n(this,void 0,void 0,(function*(){return fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then((t=>t.json()))}))}convertToProgramWalletTransaction(t){return n(this,void 0,void 0,(function*(){const e=window.solana;if(e&&e.isBlocto)return e.convertToProgramWalletTransaction(t);const n=yield this.request({method:"convertToProgramWalletTransaction",params:{message:t.serializeMessage().toString("hex")}});return this.toTransaction(n,[])}))}signAndSendTransaction(t,e){return n(this,void 0,void 0,(function*(){const n=window.solana;if(n&&n.isBlocto)return n.signAndSendTransaction(t);const r={};if(e){e.commitment&&(r.commitment=e.commitment);const t=e?e._rpcEndpoint:null;t&&t!==this.rpc&&(this.rpc=t,this.disconnect(),yield this.connect())}return this.request({method:"signAndSendTransaction",params:Object.assign({signatures:yield this.collectSignatures(t),message:t.serializeMessage().toString("hex")},r)})}))}toTransaction(t,e){return n(this,void 0,void 0,(function*(){const n=$t.Message.from(Q.from(t,"hex")),r=new $t.Transaction;return r.recentBlockhash=n.recentBlockhash,n.header.numRequiredSignatures>0&&(r.feePayer=n.accountKeys[0]),e.forEach(((t,e)=>{const i={signature:t===$t.PublicKey.default.toBase58()?null:jt.decode(t),publicKey:n.accountKeys[e]};r.signatures.push(i)})),n.instructions.forEach((t=>{const e=t.accounts.map((t=>({pubkey:n.accountKeys[t],isSigner:t<n.header.numRequiredSignatures,isWritable:n.isAccountWritable(t)})));r.instructions.push(new $t.TransactionInstruction({keys:e,programId:n.accountKeys[t.programIdIndex],data:jt.decode(t.data)}))})),r}))}collectSignatures(t){return n(this,void 0,void 0,(function*(){return t.signatures.reduce(((t,e)=>(e.signature&&(t[e.publicKey.toBase58()]=e.signature.toString("hex")),t)),{})}))}handleConvertTransaction(t){return n(this,void 0,void 0,(function*(){return fetch(`${this.server}/api/solana/convertToWalletTx`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>C(t,this)))}))}handleSignAndSendTransaction(t){return n(this,void 0,void 0,(function*(){const{authorizationId:e}=yield fetch(`${this.server}/api/solana/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>C(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const n=R(`${this.server}/${this.appId}/solana/authz/${e}`);return P(n),new Promise(((t,e)=>B("message",((r,i)=>{const s=r;s.origin===this.server&&"SOL:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(i(),O(n),t(s.data.txHash)),"DECLINED"===s.data.status&&(i(),O(n),e(new Error(s.data.errorMessage))))}))))}))}}class Yt extends _{constructor({chainId:t,server:e,appId:n,session:r}){super(r),this.publicKey=[],this.authKey="",i(t,"'chainId' is required"),i(n,"It is necessary to interact with Blocto wallet via your app id. Please visit https://developers.blocto.app for more details."),this.chainId=t,this.networkName=f[t],this.api=g[t];const s=l[t];this.appId=n||y,this.server=e||s||""}get publicAccount(){return{address:this.session.accounts.aptos[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(){return n(this,void 0,void 0,(function*(){return this.session.connected}))}signTransaction(t){return n(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signTransaction(t);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){return n(this,void 0,void 0,(function*(){const t=window.bloctoAptos;t?yield t.disconnect():(this.session.code=null,this.session.accounts={},this.session.connected=!1)}))}signAndSubmitTransaction(t,e={}){return n(this,void 0,void 0,(function*(){const n=window.bloctoAptos;if(n)return n.signAndSubmitTransaction(t,e);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");const{authorizationId:r}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(Object.assign(Object.assign({},t),e))}).then((t=>C(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const i=R(`${this.server}/${this.appId}/aptos/authz/${r}`);return P(i),new Promise(((t,e)=>B("message",((n,r)=>{const s=n;s.origin===this.server&&"APTOS:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(r(),O(i),t({hash:s.data.txHash})),"DECLINED"===s.data.status&&(r(),O(i),e(new Error(s.data.errorMessage))))}))))}))}signMessage(t){return n(this,void 0,void 0,(function*(){const e=window.bloctoAptos,n=(t=>{var e,n;const r=Object.assign({},t),{message:i,nonce:s,address:o,application:a,chainId:c}=t;return"string"!=typeof i&&(r.message=null!==(e=String(i))&&void 0!==e?e:""),"string"!=typeof s&&(r.nonce=null!==(n=String(s))&&void 0!==n?n:""),o&&"boolean"!=typeof o&&(r.address=!!o),a&&"boolean"!=typeof a&&(r.application=!!a),c&&"boolean"!=typeof c&&(r.chainId=!!c),r})(t);if(e)return e.signMessage(n);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const{signatureId:r}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(n)}).then((t=>C(t,this))),i=R(`${this.server}/${this.appId}/aptos/user-signature/${r}`);return P(i),new Promise(((t,e)=>B("message",((n,r)=>{const s=n;s.origin===this.server&&"APTOS:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(r(),O(i),t(s.data)),"DECLINED"===s.data.status&&(r(),O(i),e(new Error(s.data.errorMessage))))}))))}))}connect(){return n(this,void 0,void 0,(function*(){const t=window.bloctoAptos;return t?new Promise(((e,n)=>setTimeout((()=>t.connect().then(e).catch(n)),10))):(this.tryRetrieveSessionFromStorage("aptos"),new Promise(((t,e)=>{if("undefined"==typeof window)return e("Currently only supported in browser");if(this.session.connected&&this.session.accounts.aptos.length)return t({address:this.session.accounts.aptos[0],publicKey:this.publicKey,authKey:null,minKeysRequired:2});const r=encodeURIComponent(window.location.origin),i=R(`${this.server}/${this.appId}/aptos/authn?l6n=${r}`);P(i),B("message",((r,s)=>n(this,void 0,void 0,(function*(){const n=r;if(n.origin===this.server){if("APTOS:FRAME:RESPONSE"===n.data.type){s(),O(i),this.session.code=n.data.code,this.session.connected=!0;const r=n.data.address;if(this.formatAndSetSessionAccount(r),S(this.sessionKey,{code:this.session.code,address:r},v),!this.session.accounts.aptos.length)return e();try{const{public_keys:e}=yield fetch(`${this.server}/blocto/aptos/accounts/${this.session.accounts.aptos[0]}`).then((t=>t.json()));this.publicKey=e||[],t({address:this.session.accounts.aptos[0]||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(t){return e(n)}}"APTOS:FRAME:CLOSE"===n.data.type&&(s(),O(i),e(new Error("User declined the login request")))}}))))})))}))}fetchAddress(){return n(this,void 0,void 0,(function*(){const{accounts:t}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>C(t,this)));return this.session.accounts.aptos=t||[],this.session.accounts.aptos[0]}))}}const qt={connected:!1,code:null,accounts:{}};class Kt{constructor({appId:t,ethereum:e,solana:n,aptos:r}){e&&(this.ethereum=new j(Object.assign(Object.assign({},e),{appId:t,session:qt}))),n&&(this.solana=new xt(Object.assign(Object.assign({},n),{appId:t,session:qt}))),r&&(this.aptos=new Yt(Object.assign(Object.assign({},r),{appId:t,session:qt})))}}function Ft({chainId:n,rpcUrl:r,rpc:i,bloctoParams:s},o){return t(this,void 0,void 0,(function*(){let t;if(!n)throw new Error("chainId is required");r?t=r:n&&i&&(t=i[n]);const a=new Kt({appId:null==s?void 0:s.appId,ethereum:{chainId:n,rpc:t}}).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"}),e(a)}))}export{Ft as default};
@@ -0,0 +1 @@
1
+ import{c as t}from"./index-cc453bb1.js";import{c as i}from"./_commonjs-dynamic-modules-7cfc9805.js";var r,n={exports:{}};function e(){return r||(r=1,n.exports=(e=e||function(r,n){var e;if("undefined"!=typeof window&&window.crypto&&(e=window.crypto),"undefined"!=typeof self&&self.crypto&&(e=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(e=globalThis.crypto),!e&&"undefined"!=typeof window&&window.msCrypto&&(e=window.msCrypto),!e&&void 0!==t&&t.crypto&&(e=t.crypto),!e&&"function"==typeof i)try{e=require("crypto")}catch(t){}var h=function(){if(e){if("function"==typeof e.getRandomValues)try{return e.getRandomValues(new Uint32Array(1))[0]}catch(t){}if("function"==typeof e.randomBytes)try{return e.randomBytes(4).readInt32LE()}catch(t){}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||function(){function t(){}return function(i){var r;return t.prototype=i,r=new t,t.prototype=null,r}}(),s={},u=s.lib={},a=u.Base={extend:function(t){var i=o(this);return t&&i.mixIn(t),i.hasOwnProperty("init")&&this.init!==i.init||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var i in t)t.hasOwnProperty(i)&&(this[i]=t[i]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}},l=u.WordArray=a.extend({init:function(t,i){t=this.words=t||[],this.sigBytes=i!=n?i:4*t.length},toString:function(t){return(t||m).stringify(this)},concat:function(t){var i=this.words,r=t.words,n=this.sigBytes,e=t.sigBytes;if(this.clamp(),n%4)for(var h=0;h<e;h++){var o=r[h>>>2]>>>24-h%4*8&255;i[n+h>>>2]|=o<<24-(n+h)%4*8}else for(var s=0;s<e;s+=4)i[n+s>>>2]=r[s>>>2];return this.sigBytes+=e,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=r.ceil(i/4)},clone:function(){var t=a.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var i=[],r=0;r<t;r+=4)i.push(h());return new l.init(i,t)}}),f=s.enc={},m=f.Hex={stringify:function(t){for(var i=t.words,r=t.sigBytes,n=[],e=0;e<r;e++){var h=i[e>>>2]>>>24-e%4*8&255;n.push((h>>>4).toString(16)),n.push((15&h).toString(16))}return n.join("")},parse:function(t){for(var i=t.length,r=[],n=0;n<i;n+=2)r[n>>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new l.init(r,i/2)}},d=f.Latin1={stringify:function(t){for(var i=t.words,r=t.sigBytes,n=[],e=0;e<r;e++){var h=i[e>>>2]>>>24-e%4*8&255;n.push(String.fromCharCode(h))}return n.join("")},parse:function(t){for(var i=t.length,r=[],n=0;n<i;n++)r[n>>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new l.init(r,i)}},p=f.Utf8={stringify:function(t){try{return decodeURIComponent(escape(d.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return d.parse(unescape(encodeURIComponent(t)))}},c=u.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=p.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var i,n=this._data,e=n.words,h=n.sigBytes,o=this.blockSize,s=h/(4*o),u=(s=t?r.ceil(s):r.max((0|s)-this._minBufferSize,0))*o,a=r.min(4*u,h);if(u){for(var f=0;f<u;f+=o)this._doProcessBlock(e,f);i=e.splice(0,u),n.sigBytes-=a}return new l.init(i,a)},clone:function(){var t=a.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});u.Hasher=c.extend({cfg:a.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){c.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize()},blockSize:16,_createHelper:function(t){return function(i,r){return new t.init(r).finalize(i)}},_createHmacHelper:function(t){return function(i,r){return new M.HMAC.init(t,r).finalize(i)}}});var M=s.algo={};return s}(Math),e)),n.exports;var e}var h,o={exports:{}};o.exports=(h=e(),function(t){var i=h,r=i.lib,n=r.WordArray,e=r.Hasher,o=i.algo,s=[],u=[];!function(){function i(i){for(var r=t.sqrt(i),n=2;n<=r;n++)if(!(i%n))return!1;return!0}function r(t){return 4294967296*(t-(0|t))|0}for(var n=2,e=0;e<64;)i(n)&&(e<8&&(s[e]=r(t.pow(n,.5))),u[e]=r(t.pow(n,1/3)),e++),n++}();var a=[],l=o.SHA256=e.extend({_doReset:function(){this._hash=new n.init(s.slice(0))},_doProcessBlock:function(t,i){for(var r=this._hash.words,n=r[0],e=r[1],h=r[2],o=r[3],s=r[4],l=r[5],f=r[6],m=r[7],d=0;d<64;d++){if(d<16)a[d]=0|t[i+d];else{var p=a[d-15],c=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,M=a[d-2],v=(M<<15|M>>>17)^(M<<13|M>>>19)^M>>>10;a[d]=c+a[d-7]+v+a[d-16]}var g=n&e^n&h^e&h,w=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),y=m+((s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25))+(s&l^~s&f)+u[d]+a[d];m=f,f=l,l=s,s=o+y|0,o=h,h=e,e=n,n=y+(w+g)|0}r[0]=r[0]+n|0,r[1]=r[1]+e|0,r[2]=r[2]+h|0,r[3]=r[3]+o|0,r[4]=r[4]+s|0,r[5]=r[5]+l|0,r[6]=r[6]+f|0,r[7]=r[7]+m|0},_doFinalize:function(){var i=this._data,r=i.words,n=8*this._nDataBytes,e=8*i.sigBytes;return r[e>>>5]|=128<<24-e%32,r[14+(e+64>>>9<<4)]=t.floor(n/4294967296),r[15+(e+64>>>9<<4)]=n,i.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var t=e.clone.call(this);return t._hash=this._hash.clone(),t}});i.SHA256=e._createHelper(l),i.HmacSHA256=e._createHmacHelper(l)}(Math),h.SHA256);var s={exports:{}};!function(t,i){function r(t,i){if(!t)throw new Error(i||"Assertion failed")}function n(t,i){t.super_=i;var r=function(){};r.prototype=i.prototype,t.prototype=new r,t.prototype.constructor=t}function e(t,i,r){if(e.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(r=i,i=10),this._init(t||0,i||10,r||"be"))}var h;"object"==typeof t?t.exports=e:i.BN=e,e.BN=e,e.wordSize=26;try{h="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:require("buffer").Buffer}catch(t){}function o(t,i){var r=t.charCodeAt(i);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function s(t,i,r){var n=o(t,r);return r-1>=i&&(n|=o(t,r-1)<<4),n}function u(t,i,r,n){for(var e=0,h=Math.min(t.length,r),o=i;o<h;o++){var s=t.charCodeAt(o)-48;e*=n,e+=s>=49?s-49+10:s>=17?s-17+10:s}return e}e.isBN=function(t){return t instanceof e||null!==t&&"object"==typeof t&&t.constructor.wordSize===e.wordSize&&Array.isArray(t.words)},e.max=function(t,i){return t.cmp(i)>0?t:i},e.min=function(t,i){return t.cmp(i)<0?t:i},e.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),r(i===(0|i)&&i>=2&&i<=36);var e=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(e++,this.negative=1),e<t.length&&(16===i?this._parseHex(t,e,n):(this._parseBase(t,i,e),"le"===n&&this._initArray(this.toArray(),i,n)))},e.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},e.prototype._initArray=function(t,i,n){if(r("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var h,o,s=0;if("be"===n)for(e=t.length-1,h=0;e>=0;e-=3)o=t[e]|t[e-1]<<8|t[e-2]<<16,this.words[h]|=o<<s&67108863,this.words[h+1]=o>>>26-s&67108863,(s+=24)>=26&&(s-=26,h++);else if("le"===n)for(e=0,h=0;e<t.length;e+=3)o=t[e]|t[e+1]<<8|t[e+2]<<16,this.words[h]|=o<<s&67108863,this.words[h+1]=o>>>26-s&67108863,(s+=24)>=26&&(s-=26,h++);return this.strip()},e.prototype._parseHex=function(t,i,r){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var e,h=0,o=0;if("be"===r)for(n=t.length-1;n>=i;n-=2)e=s(t,i,n)<<h,this.words[o]|=67108863&e,h>=18?(h-=18,o+=1,this.words[o]|=e>>>26):h+=8;else for(n=(t.length-i)%2==0?i+1:i;n<t.length;n+=2)e=s(t,i,n)<<h,this.words[o]|=67108863&e,h>=18?(h-=18,o+=1,this.words[o]|=e>>>26):h+=8;this.strip()},e.prototype._parseBase=function(t,i,r){this.words=[0],this.length=1;for(var n=0,e=1;e<=67108863;e*=i)n++;n--,e=e/i|0;for(var h=t.length-r,o=h%n,s=Math.min(h,h-o)+r,a=0,l=r;l<s;l+=n)a=u(t,l,l+n,i),this.imuln(e),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==o){var f=1;for(a=u(t,l,t.length,i),l=0;l<o;l++)f*=i;this.imuln(f),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this.strip()},e.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},e.prototype.clone=function(){var t=new e(null);return this.copy(t),t},e.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},e.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},e.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},e.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function m(t,i,r){r.negative=i.negative^t.negative;var n=t.length+i.length|0;r.length=n,n=n-1|0;var e=0|t.words[0],h=0|i.words[0],o=e*h,s=67108863&o,u=o/67108864|0;r.words[0]=s;for(var a=1;a<n;a++){for(var l=u>>>26,f=67108863&u,m=Math.min(a,i.length-1),d=Math.max(0,a-t.length+1);d<=m;d++){var p=a-d|0;l+=(o=(e=0|t.words[p])*(h=0|i.words[d])+f)/67108864|0,f=67108863&o}r.words[a]=0|f,u=0|l}return 0!==u?r.words[a]=0|u:r.length--,r.strip()}e.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var e=0,h=0,o=0;o<this.length;o++){var s=this.words[o],u=(16777215&(s<<e|h)).toString(16);n=0!=(h=s>>>24-e&16777215)||o!==this.length-1?a[6-u.length]+u+n:u+n,(e+=2)>=26&&(e-=26,o--)}for(0!==h&&(n=h.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var m=l[t],d=f[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(d).toString(t);n=(p=p.idivn(d)).isZero()?c+n:a[m-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(!1,"Base should be between 2 and 36")},e.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},e.prototype.toJSON=function(){return this.toString(16)},e.prototype.toBuffer=function(t,i){return r(void 0!==h),this.toArrayLike(h,t,i)},e.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},e.prototype.toArrayLike=function(t,i,n){var e=this.byteLength(),h=n||Math.max(1,e);r(e<=h,"byte array longer than desired length"),r(h>0,"Requested array length <= 0"),this.strip();var o,s,u="le"===i,a=new t(h),l=this.clone();if(u){for(s=0;!l.isZero();s++)o=l.andln(255),l.iushrn(8),a[s]=o;for(;s<h;s++)a[s]=0}else{for(s=0;s<h-e;s++)a[s]=0;for(s=0;!l.isZero();s++)o=l.andln(255),l.iushrn(8),a[h-s-1]=o}return a},Math.clz32?e.prototype._countBits=function(t){return 32-Math.clz32(t)}:e.prototype._countBits=function(t){var i=t,r=0;return i>=4096&&(r+=13,i>>>=13),i>=64&&(r+=7,i>>>=7),i>=8&&(r+=4,i>>>=4),i>=2&&(r+=2,i>>>=2),r+i},e.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,r=0;return 0==(8191&i)&&(r+=13,i>>>=13),0==(127&i)&&(r+=7,i>>>=7),0==(15&i)&&(r+=4,i>>>=4),0==(3&i)&&(r+=2,i>>>=2),0==(1&i)&&r++,r},e.prototype.bitLength=function(){var t=this.words[this.length-1],i=this._countBits(t);return 26*(this.length-1)+i},e.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var r=this._zeroBits(this.words[i]);if(t+=r,26!==r)break}return t},e.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},e.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},e.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},e.prototype.isNeg=function(){return 0!==this.negative},e.prototype.neg=function(){return this.clone().ineg()},e.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},e.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},e.prototype.ior=function(t){return r(0==(this.negative|t.negative)),this.iuor(t)},e.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},e.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},e.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var r=0;r<i.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=i.length,this.strip()},e.prototype.iand=function(t){return r(0==(this.negative|t.negative)),this.iuand(t)},e.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},e.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},e.prototype.iuxor=function(t){var i,r;this.length>t.length?(i=this,r=t):(i=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=i.words[n]^r.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},e.prototype.ixor=function(t){return r(0==(this.negative|t.negative)),this.iuxor(t)},e.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},e.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},e.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var e=0;e<i;e++)this.words[e]=67108863&~this.words[e];return n>0&&(this.words[e]=~this.words[e]&67108863>>26-n),this.strip()},e.prototype.notn=function(t){return this.clone().inotn(t)},e.prototype.setn=function(t,i){r("number"==typeof t&&t>=0);var n=t/26|0,e=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<e:this.words[n]&~(1<<e),this.strip()},e.prototype.iadd=function(t){var i,r,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(r=this,n=t):(r=t,n=this);for(var e=0,h=0;h<n.length;h++)i=(0|r.words[h])+(0|n.words[h])+e,this.words[h]=67108863&i,e=i>>>26;for(;0!==e&&h<r.length;h++)i=(0|r.words[h])+e,this.words[h]=67108863&i,e=i>>>26;if(this.length=r.length,0!==e)this.words[this.length]=e,this.length++;else if(r!==this)for(;h<r.length;h++)this.words[h]=r.words[h];return this},e.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},e.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,n,e=this.cmp(t);if(0===e)return this.negative=0,this.length=1,this.words[0]=0,this;e>0?(r=this,n=t):(r=t,n=this);for(var h=0,o=0;o<n.length;o++)h=(i=(0|r.words[o])-(0|n.words[o])+h)>>26,this.words[o]=67108863&i;for(;0!==h&&o<r.length;o++)h=(i=(0|r.words[o])+h)>>26,this.words[o]=67108863&i;if(0===h&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this.strip()},e.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,i,r){var n,e,h,o=t.words,s=i.words,u=r.words,a=0,l=0|o[0],f=8191&l,m=l>>>13,d=0|o[1],p=8191&d,c=d>>>13,M=0|o[2],v=8191&M,g=M>>>13,w=0|o[3],y=8191&w,b=w>>>13,_=0|o[4],x=8191&_,A=_>>>13,B=0|o[5],k=8191&B,S=B>>>13,R=0|o[6],q=8191&R,Z=R>>>13,z=0|o[7],N=8191&z,I=z>>>13,H=0|o[8],L=8191&H,T=H>>>13,j=0|o[9],E=8191&j,O=j>>>13,C=0|s[0],P=8191&C,F=C>>>13,U=0|s[1],D=8191&U,K=U>>>13,V=0|s[2],W=8191&V,$=V>>>13,J=0|s[3],G=8191&J,Q=J>>>13,X=0|s[4],Y=8191&X,tt=X>>>13,it=0|s[5],rt=8191&it,nt=it>>>13,et=0|s[6],ht=8191&et,ot=et>>>13,st=0|s[7],ut=8191&st,at=st>>>13,lt=0|s[8],ft=8191&lt,mt=lt>>>13,dt=0|s[9],pt=8191&dt,ct=dt>>>13;r.negative=t.negative^i.negative,r.length=19;var Mt=(a+(n=Math.imul(f,P))|0)+((8191&(e=(e=Math.imul(f,F))+Math.imul(m,P)|0))<<13)|0;a=((h=Math.imul(m,F))+(e>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(p,P),e=(e=Math.imul(p,F))+Math.imul(c,P)|0,h=Math.imul(c,F);var vt=(a+(n=n+Math.imul(f,D)|0)|0)+((8191&(e=(e=e+Math.imul(f,K)|0)+Math.imul(m,D)|0))<<13)|0;a=((h=h+Math.imul(m,K)|0)+(e>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,P),e=(e=Math.imul(v,F))+Math.imul(g,P)|0,h=Math.imul(g,F),n=n+Math.imul(p,D)|0,e=(e=e+Math.imul(p,K)|0)+Math.imul(c,D)|0,h=h+Math.imul(c,K)|0;var gt=(a+(n=n+Math.imul(f,W)|0)|0)+((8191&(e=(e=e+Math.imul(f,$)|0)+Math.imul(m,W)|0))<<13)|0;a=((h=h+Math.imul(m,$)|0)+(e>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(y,P),e=(e=Math.imul(y,F))+Math.imul(b,P)|0,h=Math.imul(b,F),n=n+Math.imul(v,D)|0,e=(e=e+Math.imul(v,K)|0)+Math.imul(g,D)|0,h=h+Math.imul(g,K)|0,n=n+Math.imul(p,W)|0,e=(e=e+Math.imul(p,$)|0)+Math.imul(c,W)|0,h=h+Math.imul(c,$)|0;var wt=(a+(n=n+Math.imul(f,G)|0)|0)+((8191&(e=(e=e+Math.imul(f,Q)|0)+Math.imul(m,G)|0))<<13)|0;a=((h=h+Math.imul(m,Q)|0)+(e>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(x,P),e=(e=Math.imul(x,F))+Math.imul(A,P)|0,h=Math.imul(A,F),n=n+Math.imul(y,D)|0,e=(e=e+Math.imul(y,K)|0)+Math.imul(b,D)|0,h=h+Math.imul(b,K)|0,n=n+Math.imul(v,W)|0,e=(e=e+Math.imul(v,$)|0)+Math.imul(g,W)|0,h=h+Math.imul(g,$)|0,n=n+Math.imul(p,G)|0,e=(e=e+Math.imul(p,Q)|0)+Math.imul(c,G)|0,h=h+Math.imul(c,Q)|0;var yt=(a+(n=n+Math.imul(f,Y)|0)|0)+((8191&(e=(e=e+Math.imul(f,tt)|0)+Math.imul(m,Y)|0))<<13)|0;a=((h=h+Math.imul(m,tt)|0)+(e>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(k,P),e=(e=Math.imul(k,F))+Math.imul(S,P)|0,h=Math.imul(S,F),n=n+Math.imul(x,D)|0,e=(e=e+Math.imul(x,K)|0)+Math.imul(A,D)|0,h=h+Math.imul(A,K)|0,n=n+Math.imul(y,W)|0,e=(e=e+Math.imul(y,$)|0)+Math.imul(b,W)|0,h=h+Math.imul(b,$)|0,n=n+Math.imul(v,G)|0,e=(e=e+Math.imul(v,Q)|0)+Math.imul(g,G)|0,h=h+Math.imul(g,Q)|0,n=n+Math.imul(p,Y)|0,e=(e=e+Math.imul(p,tt)|0)+Math.imul(c,Y)|0,h=h+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(f,rt)|0)|0)+((8191&(e=(e=e+Math.imul(f,nt)|0)+Math.imul(m,rt)|0))<<13)|0;a=((h=h+Math.imul(m,nt)|0)+(e>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(q,P),e=(e=Math.imul(q,F))+Math.imul(Z,P)|0,h=Math.imul(Z,F),n=n+Math.imul(k,D)|0,e=(e=e+Math.imul(k,K)|0)+Math.imul(S,D)|0,h=h+Math.imul(S,K)|0,n=n+Math.imul(x,W)|0,e=(e=e+Math.imul(x,$)|0)+Math.imul(A,W)|0,h=h+Math.imul(A,$)|0,n=n+Math.imul(y,G)|0,e=(e=e+Math.imul(y,Q)|0)+Math.imul(b,G)|0,h=h+Math.imul(b,Q)|0,n=n+Math.imul(v,Y)|0,e=(e=e+Math.imul(v,tt)|0)+Math.imul(g,Y)|0,h=h+Math.imul(g,tt)|0,n=n+Math.imul(p,rt)|0,e=(e=e+Math.imul(p,nt)|0)+Math.imul(c,rt)|0,h=h+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(f,ht)|0)|0)+((8191&(e=(e=e+Math.imul(f,ot)|0)+Math.imul(m,ht)|0))<<13)|0;a=((h=h+Math.imul(m,ot)|0)+(e>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(N,P),e=(e=Math.imul(N,F))+Math.imul(I,P)|0,h=Math.imul(I,F),n=n+Math.imul(q,D)|0,e=(e=e+Math.imul(q,K)|0)+Math.imul(Z,D)|0,h=h+Math.imul(Z,K)|0,n=n+Math.imul(k,W)|0,e=(e=e+Math.imul(k,$)|0)+Math.imul(S,W)|0,h=h+Math.imul(S,$)|0,n=n+Math.imul(x,G)|0,e=(e=e+Math.imul(x,Q)|0)+Math.imul(A,G)|0,h=h+Math.imul(A,Q)|0,n=n+Math.imul(y,Y)|0,e=(e=e+Math.imul(y,tt)|0)+Math.imul(b,Y)|0,h=h+Math.imul(b,tt)|0,n=n+Math.imul(v,rt)|0,e=(e=e+Math.imul(v,nt)|0)+Math.imul(g,rt)|0,h=h+Math.imul(g,nt)|0,n=n+Math.imul(p,ht)|0,e=(e=e+Math.imul(p,ot)|0)+Math.imul(c,ht)|0,h=h+Math.imul(c,ot)|0;var xt=(a+(n=n+Math.imul(f,ut)|0)|0)+((8191&(e=(e=e+Math.imul(f,at)|0)+Math.imul(m,ut)|0))<<13)|0;a=((h=h+Math.imul(m,at)|0)+(e>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(L,P),e=(e=Math.imul(L,F))+Math.imul(T,P)|0,h=Math.imul(T,F),n=n+Math.imul(N,D)|0,e=(e=e+Math.imul(N,K)|0)+Math.imul(I,D)|0,h=h+Math.imul(I,K)|0,n=n+Math.imul(q,W)|0,e=(e=e+Math.imul(q,$)|0)+Math.imul(Z,W)|0,h=h+Math.imul(Z,$)|0,n=n+Math.imul(k,G)|0,e=(e=e+Math.imul(k,Q)|0)+Math.imul(S,G)|0,h=h+Math.imul(S,Q)|0,n=n+Math.imul(x,Y)|0,e=(e=e+Math.imul(x,tt)|0)+Math.imul(A,Y)|0,h=h+Math.imul(A,tt)|0,n=n+Math.imul(y,rt)|0,e=(e=e+Math.imul(y,nt)|0)+Math.imul(b,rt)|0,h=h+Math.imul(b,nt)|0,n=n+Math.imul(v,ht)|0,e=(e=e+Math.imul(v,ot)|0)+Math.imul(g,ht)|0,h=h+Math.imul(g,ot)|0,n=n+Math.imul(p,ut)|0,e=(e=e+Math.imul(p,at)|0)+Math.imul(c,ut)|0,h=h+Math.imul(c,at)|0;var At=(a+(n=n+Math.imul(f,ft)|0)|0)+((8191&(e=(e=e+Math.imul(f,mt)|0)+Math.imul(m,ft)|0))<<13)|0;a=((h=h+Math.imul(m,mt)|0)+(e>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(E,P),e=(e=Math.imul(E,F))+Math.imul(O,P)|0,h=Math.imul(O,F),n=n+Math.imul(L,D)|0,e=(e=e+Math.imul(L,K)|0)+Math.imul(T,D)|0,h=h+Math.imul(T,K)|0,n=n+Math.imul(N,W)|0,e=(e=e+Math.imul(N,$)|0)+Math.imul(I,W)|0,h=h+Math.imul(I,$)|0,n=n+Math.imul(q,G)|0,e=(e=e+Math.imul(q,Q)|0)+Math.imul(Z,G)|0,h=h+Math.imul(Z,Q)|0,n=n+Math.imul(k,Y)|0,e=(e=e+Math.imul(k,tt)|0)+Math.imul(S,Y)|0,h=h+Math.imul(S,tt)|0,n=n+Math.imul(x,rt)|0,e=(e=e+Math.imul(x,nt)|0)+Math.imul(A,rt)|0,h=h+Math.imul(A,nt)|0,n=n+Math.imul(y,ht)|0,e=(e=e+Math.imul(y,ot)|0)+Math.imul(b,ht)|0,h=h+Math.imul(b,ot)|0,n=n+Math.imul(v,ut)|0,e=(e=e+Math.imul(v,at)|0)+Math.imul(g,ut)|0,h=h+Math.imul(g,at)|0,n=n+Math.imul(p,ft)|0,e=(e=e+Math.imul(p,mt)|0)+Math.imul(c,ft)|0,h=h+Math.imul(c,mt)|0;var Bt=(a+(n=n+Math.imul(f,pt)|0)|0)+((8191&(e=(e=e+Math.imul(f,ct)|0)+Math.imul(m,pt)|0))<<13)|0;a=((h=h+Math.imul(m,ct)|0)+(e>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(E,D),e=(e=Math.imul(E,K))+Math.imul(O,D)|0,h=Math.imul(O,K),n=n+Math.imul(L,W)|0,e=(e=e+Math.imul(L,$)|0)+Math.imul(T,W)|0,h=h+Math.imul(T,$)|0,n=n+Math.imul(N,G)|0,e=(e=e+Math.imul(N,Q)|0)+Math.imul(I,G)|0,h=h+Math.imul(I,Q)|0,n=n+Math.imul(q,Y)|0,e=(e=e+Math.imul(q,tt)|0)+Math.imul(Z,Y)|0,h=h+Math.imul(Z,tt)|0,n=n+Math.imul(k,rt)|0,e=(e=e+Math.imul(k,nt)|0)+Math.imul(S,rt)|0,h=h+Math.imul(S,nt)|0,n=n+Math.imul(x,ht)|0,e=(e=e+Math.imul(x,ot)|0)+Math.imul(A,ht)|0,h=h+Math.imul(A,ot)|0,n=n+Math.imul(y,ut)|0,e=(e=e+Math.imul(y,at)|0)+Math.imul(b,ut)|0,h=h+Math.imul(b,at)|0,n=n+Math.imul(v,ft)|0,e=(e=e+Math.imul(v,mt)|0)+Math.imul(g,ft)|0,h=h+Math.imul(g,mt)|0;var kt=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(e=(e=e+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((h=h+Math.imul(c,ct)|0)+(e>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(E,W),e=(e=Math.imul(E,$))+Math.imul(O,W)|0,h=Math.imul(O,$),n=n+Math.imul(L,G)|0,e=(e=e+Math.imul(L,Q)|0)+Math.imul(T,G)|0,h=h+Math.imul(T,Q)|0,n=n+Math.imul(N,Y)|0,e=(e=e+Math.imul(N,tt)|0)+Math.imul(I,Y)|0,h=h+Math.imul(I,tt)|0,n=n+Math.imul(q,rt)|0,e=(e=e+Math.imul(q,nt)|0)+Math.imul(Z,rt)|0,h=h+Math.imul(Z,nt)|0,n=n+Math.imul(k,ht)|0,e=(e=e+Math.imul(k,ot)|0)+Math.imul(S,ht)|0,h=h+Math.imul(S,ot)|0,n=n+Math.imul(x,ut)|0,e=(e=e+Math.imul(x,at)|0)+Math.imul(A,ut)|0,h=h+Math.imul(A,at)|0,n=n+Math.imul(y,ft)|0,e=(e=e+Math.imul(y,mt)|0)+Math.imul(b,ft)|0,h=h+Math.imul(b,mt)|0;var St=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(e=(e=e+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((h=h+Math.imul(g,ct)|0)+(e>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(E,G),e=(e=Math.imul(E,Q))+Math.imul(O,G)|0,h=Math.imul(O,Q),n=n+Math.imul(L,Y)|0,e=(e=e+Math.imul(L,tt)|0)+Math.imul(T,Y)|0,h=h+Math.imul(T,tt)|0,n=n+Math.imul(N,rt)|0,e=(e=e+Math.imul(N,nt)|0)+Math.imul(I,rt)|0,h=h+Math.imul(I,nt)|0,n=n+Math.imul(q,ht)|0,e=(e=e+Math.imul(q,ot)|0)+Math.imul(Z,ht)|0,h=h+Math.imul(Z,ot)|0,n=n+Math.imul(k,ut)|0,e=(e=e+Math.imul(k,at)|0)+Math.imul(S,ut)|0,h=h+Math.imul(S,at)|0,n=n+Math.imul(x,ft)|0,e=(e=e+Math.imul(x,mt)|0)+Math.imul(A,ft)|0,h=h+Math.imul(A,mt)|0;var Rt=(a+(n=n+Math.imul(y,pt)|0)|0)+((8191&(e=(e=e+Math.imul(y,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((h=h+Math.imul(b,ct)|0)+(e>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(E,Y),e=(e=Math.imul(E,tt))+Math.imul(O,Y)|0,h=Math.imul(O,tt),n=n+Math.imul(L,rt)|0,e=(e=e+Math.imul(L,nt)|0)+Math.imul(T,rt)|0,h=h+Math.imul(T,nt)|0,n=n+Math.imul(N,ht)|0,e=(e=e+Math.imul(N,ot)|0)+Math.imul(I,ht)|0,h=h+Math.imul(I,ot)|0,n=n+Math.imul(q,ut)|0,e=(e=e+Math.imul(q,at)|0)+Math.imul(Z,ut)|0,h=h+Math.imul(Z,at)|0,n=n+Math.imul(k,ft)|0,e=(e=e+Math.imul(k,mt)|0)+Math.imul(S,ft)|0,h=h+Math.imul(S,mt)|0;var qt=(a+(n=n+Math.imul(x,pt)|0)|0)+((8191&(e=(e=e+Math.imul(x,ct)|0)+Math.imul(A,pt)|0))<<13)|0;a=((h=h+Math.imul(A,ct)|0)+(e>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(E,rt),e=(e=Math.imul(E,nt))+Math.imul(O,rt)|0,h=Math.imul(O,nt),n=n+Math.imul(L,ht)|0,e=(e=e+Math.imul(L,ot)|0)+Math.imul(T,ht)|0,h=h+Math.imul(T,ot)|0,n=n+Math.imul(N,ut)|0,e=(e=e+Math.imul(N,at)|0)+Math.imul(I,ut)|0,h=h+Math.imul(I,at)|0,n=n+Math.imul(q,ft)|0,e=(e=e+Math.imul(q,mt)|0)+Math.imul(Z,ft)|0,h=h+Math.imul(Z,mt)|0;var Zt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(e=(e=e+Math.imul(k,ct)|0)+Math.imul(S,pt)|0))<<13)|0;a=((h=h+Math.imul(S,ct)|0)+(e>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,n=Math.imul(E,ht),e=(e=Math.imul(E,ot))+Math.imul(O,ht)|0,h=Math.imul(O,ot),n=n+Math.imul(L,ut)|0,e=(e=e+Math.imul(L,at)|0)+Math.imul(T,ut)|0,h=h+Math.imul(T,at)|0,n=n+Math.imul(N,ft)|0,e=(e=e+Math.imul(N,mt)|0)+Math.imul(I,ft)|0,h=h+Math.imul(I,mt)|0;var zt=(a+(n=n+Math.imul(q,pt)|0)|0)+((8191&(e=(e=e+Math.imul(q,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((h=h+Math.imul(Z,ct)|0)+(e>>>13)|0)+(zt>>>26)|0,zt&=67108863,n=Math.imul(E,ut),e=(e=Math.imul(E,at))+Math.imul(O,ut)|0,h=Math.imul(O,at),n=n+Math.imul(L,ft)|0,e=(e=e+Math.imul(L,mt)|0)+Math.imul(T,ft)|0,h=h+Math.imul(T,mt)|0;var Nt=(a+(n=n+Math.imul(N,pt)|0)|0)+((8191&(e=(e=e+Math.imul(N,ct)|0)+Math.imul(I,pt)|0))<<13)|0;a=((h=h+Math.imul(I,ct)|0)+(e>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,n=Math.imul(E,ft),e=(e=Math.imul(E,mt))+Math.imul(O,ft)|0,h=Math.imul(O,mt);var It=(a+(n=n+Math.imul(L,pt)|0)|0)+((8191&(e=(e=e+Math.imul(L,ct)|0)+Math.imul(T,pt)|0))<<13)|0;a=((h=h+Math.imul(T,ct)|0)+(e>>>13)|0)+(It>>>26)|0,It&=67108863;var Ht=(a+(n=Math.imul(E,pt))|0)+((8191&(e=(e=Math.imul(E,ct))+Math.imul(O,pt)|0))<<13)|0;return a=((h=Math.imul(O,ct))+(e>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,u[0]=Mt,u[1]=vt,u[2]=gt,u[3]=wt,u[4]=yt,u[5]=bt,u[6]=_t,u[7]=xt,u[8]=At,u[9]=Bt,u[10]=kt,u[11]=St,u[12]=Rt,u[13]=qt,u[14]=Zt,u[15]=zt,u[16]=Nt,u[17]=It,u[18]=Ht,0!==a&&(u[19]=a,r.length++),r};function p(t,i,r){return(new c).mulp(t,i,r)}function c(t,i){this.x=t,this.y=i}Math.imul||(d=m),e.prototype.mulTo=function(t,i){var r,n=this.length+t.length;return r=10===this.length&&10===t.length?d(this,t,i):n<63?m(this,t,i):n<1024?function(t,i,r){r.negative=i.negative^t.negative,r.length=t.length+i.length;for(var n=0,e=0,h=0;h<r.length-1;h++){var o=e;e=0;for(var s=67108863&n,u=Math.min(h,i.length-1),a=Math.max(0,h-t.length+1);a<=u;a++){var l=h-a,f=(0|t.words[l])*(0|i.words[a]),m=67108863&f;s=67108863&(m=m+s|0),e+=(o=(o=o+(f/67108864|0)|0)+(m>>>26)|0)>>>26,o&=67108863}r.words[h]=s,n=o,o=e}return 0!==n?r.words[h]=n:r.length--,r.strip()}(this,t,i):p(this,t,i),r},c.prototype.makeRBT=function(t){for(var i=new Array(t),r=e.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,r,t);return i},c.prototype.revBin=function(t,i,r){if(0===t||t===r-1)return t;for(var n=0,e=0;e<i;e++)n|=(1&t)<<i-e-1,t>>=1;return n},c.prototype.permute=function(t,i,r,n,e,h){for(var o=0;o<h;o++)n[o]=i[t[o]],e[o]=r[t[o]]},c.prototype.transform=function(t,i,r,n,e,h){this.permute(h,t,i,r,n,e);for(var o=1;o<e;o<<=1)for(var s=o<<1,u=Math.cos(2*Math.PI/s),a=Math.sin(2*Math.PI/s),l=0;l<e;l+=s)for(var f=u,m=a,d=0;d<o;d++){var p=r[l+d],c=n[l+d],M=r[l+d+o],v=n[l+d+o],g=f*M-m*v;v=f*v+m*M,M=g,r[l+d]=p+M,n[l+d]=c+v,r[l+d+o]=p-M,n[l+d+o]=c-v,d!==s&&(g=u*f-a*m,m=u*m+a*f,f=g)}},c.prototype.guessLen13b=function(t,i){var r=1|Math.max(i,t),n=1&r,e=0;for(r=r/2|0;r;r>>>=1)e++;return 1<<e+1+n},c.prototype.conjugate=function(t,i,r){if(!(r<=1))for(var n=0;n<r/2;n++){var e=t[n];t[n]=t[r-n-1],t[r-n-1]=e,e=i[n],i[n]=-i[r-n-1],i[r-n-1]=-e}},c.prototype.normalize13b=function(t,i){for(var r=0,n=0;n<i/2;n++){var e=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+r;t[n]=67108863&e,r=e<67108864?0:e/67108864|0}return t},c.prototype.convert13b=function(t,i,n,e){for(var h=0,o=0;o<i;o++)h+=0|t[o],n[2*o]=8191&h,h>>>=13,n[2*o+1]=8191&h,h>>>=13;for(o=2*i;o<e;++o)n[o]=0;r(0===h),r(0==(-8192&h))},c.prototype.stub=function(t){for(var i=new Array(t),r=0;r<t;r++)i[r]=0;return i},c.prototype.mulp=function(t,i,r){var n=2*this.guessLen13b(t.length,i.length),e=this.makeRBT(n),h=this.stub(n),o=new Array(n),s=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),f=new Array(n),m=r.words;m.length=n,this.convert13b(t.words,t.length,o,n),this.convert13b(i.words,i.length,a,n),this.transform(o,h,s,u,n,e),this.transform(a,h,l,f,n,e);for(var d=0;d<n;d++){var p=s[d]*l[d]-u[d]*f[d];u[d]=s[d]*f[d]+u[d]*l[d],s[d]=p}return this.conjugate(s,u,n),this.transform(s,u,m,h,n,e),this.conjugate(m,h,n),this.normalize13b(m,n),r.negative=t.negative^i.negative,r.length=t.length+i.length,r.strip()},e.prototype.mul=function(t){var i=new e(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},e.prototype.mulf=function(t){var i=new e(null);return i.words=new Array(this.length+t.length),p(this,t,i)},e.prototype.imul=function(t){return this.clone().mulTo(t,this)},e.prototype.imuln=function(t){r("number"==typeof t),r(t<67108864);for(var i=0,n=0;n<this.length;n++){var e=(0|this.words[n])*t,h=(67108863&e)+(67108863&i);i>>=26,i+=e/67108864|0,i+=h>>>26,this.words[n]=67108863&h}return 0!==i&&(this.words[n]=i,this.length++),this},e.prototype.muln=function(t){return this.clone().imuln(t)},e.prototype.sqr=function(){return this.mul(this)},e.prototype.isqr=function(){return this.imul(this.clone())},e.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),r=0;r<i.length;r++){var n=r/26|0,e=r%26;i[r]=(t.words[n]&1<<e)>>>e}return i}(t);if(0===i.length)return new e(1);for(var r=this,n=0;n<i.length&&0===i[n];n++,r=r.sqr());if(++n<i.length)for(var h=r.sqr();n<i.length;n++,h=h.sqr())0!==i[n]&&(r=r.mul(h));return r},e.prototype.iushln=function(t){r("number"==typeof t&&t>=0);var i,n=t%26,e=(t-n)/26,h=67108863>>>26-n<<26-n;if(0!==n){var o=0;for(i=0;i<this.length;i++){var s=this.words[i]&h,u=(0|this.words[i])-s<<n;this.words[i]=u|o,o=s>>>26-n}o&&(this.words[i]=o,this.length++)}if(0!==e){for(i=this.length-1;i>=0;i--)this.words[i+e]=this.words[i];for(i=0;i<e;i++)this.words[i]=0;this.length+=e}return this.strip()},e.prototype.ishln=function(t){return r(0===this.negative),this.iushln(t)},e.prototype.iushrn=function(t,i,n){var e;r("number"==typeof t&&t>=0),e=i?(i-i%26)/26:0;var h=t%26,o=Math.min((t-h)/26,this.length),s=67108863^67108863>>>h<<h,u=n;if(e-=o,e=Math.max(0,e),u){for(var a=0;a<o;a++)u.words[a]=this.words[a];u.length=o}if(0===o);else if(this.length>o)for(this.length-=o,a=0;a<this.length;a++)this.words[a]=this.words[a+o];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=e);a--){var f=0|this.words[a];this.words[a]=l<<26-h|f>>>h,l=f&s}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},e.prototype.ishrn=function(t,i,n){return r(0===this.negative),this.iushrn(t,i,n)},e.prototype.shln=function(t){return this.clone().ishln(t)},e.prototype.ushln=function(t){return this.clone().iushln(t)},e.prototype.shrn=function(t){return this.clone().ishrn(t)},e.prototype.ushrn=function(t){return this.clone().iushrn(t)},e.prototype.testn=function(t){r("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26,e=1<<i;return!(this.length<=n||!(this.words[n]&e))},e.prototype.imaskn=function(t){r("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==i&&n++,this.length=Math.min(n,this.length),0!==i){var e=67108863^67108863>>>i<<i;this.words[this.length-1]&=e}return this.strip()},e.prototype.maskn=function(t){return this.clone().imaskn(t)},e.prototype.iaddn=function(t){return r("number"==typeof t),r(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},e.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},e.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},e.prototype.addn=function(t){return this.clone().iaddn(t)},e.prototype.subn=function(t){return this.clone().isubn(t)},e.prototype.iabs=function(){return this.negative=0,this},e.prototype.abs=function(){return this.clone().iabs()},e.prototype._ishlnsubmul=function(t,i,n){var e,h,o=t.length+n;this._expand(o);var s=0;for(e=0;e<t.length;e++){h=(0|this.words[e+n])+s;var u=(0|t.words[e])*i;s=((h-=67108863&u)>>26)-(u/67108864|0),this.words[e+n]=67108863&h}for(;e<this.length-n;e++)s=(h=(0|this.words[e+n])+s)>>26,this.words[e+n]=67108863&h;if(0===s)return this.strip();for(r(-1===s),s=0,e=0;e<this.length;e++)s=(h=-(0|this.words[e])+s)>>26,this.words[e]=67108863&h;return this.negative=1,this.strip()},e.prototype._wordDiv=function(t,i){var r=(this.length,t.length),n=this.clone(),h=t,o=0|h.words[h.length-1];0!=(r=26-this._countBits(o))&&(h=h.ushln(r),n.iushln(r),o=0|h.words[h.length-1]);var s,u=n.length-h.length;if("mod"!==i){(s=new e(null)).length=u+1,s.words=new Array(s.length);for(var a=0;a<s.length;a++)s.words[a]=0}var l=n.clone()._ishlnsubmul(h,1,u);0===l.negative&&(n=l,s&&(s.words[u]=1));for(var f=u-1;f>=0;f--){var m=67108864*(0|n.words[h.length+f])+(0|n.words[h.length+f-1]);for(m=Math.min(m/o|0,67108863),n._ishlnsubmul(h,m,f);0!==n.negative;)m--,n.negative=0,n._ishlnsubmul(h,1,f),n.isZero()||(n.negative^=1);s&&(s.words[f]=m)}return s&&s.strip(),n.strip(),"div"!==i&&0!==r&&n.iushrn(r),{div:s||null,mod:n}},e.prototype.divmod=function(t,i,n){return r(!t.isZero()),this.isZero()?{div:new e(0),mod:new e(0)}:0!==this.negative&&0===t.negative?(s=this.neg().divmod(t,i),"mod"!==i&&(h=s.div.neg()),"div"!==i&&(o=s.mod.neg(),n&&0!==o.negative&&o.iadd(t)),{div:h,mod:o}):0===this.negative&&0!==t.negative?(s=this.divmod(t.neg(),i),"mod"!==i&&(h=s.div.neg()),{div:h,mod:s.mod}):0!=(this.negative&t.negative)?(s=this.neg().divmod(t.neg(),i),"div"!==i&&(o=s.mod.neg(),n&&0!==o.negative&&o.isub(t)),{div:s.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new e(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new e(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new e(this.modn(t.words[0]))}:this._wordDiv(t,i);var h,o,s},e.prototype.div=function(t){return this.divmod(t,"div",!1).div},e.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},e.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},e.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var r=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),e=t.andln(1),h=r.cmp(n);return h<0||1===e&&0===h?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},e.prototype.modn=function(t){r(t<=67108863);for(var i=(1<<26)%t,n=0,e=this.length-1;e>=0;e--)n=(i*n+(0|this.words[e]))%t;return n},e.prototype.idivn=function(t){r(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var e=(0|this.words[n])+67108864*i;this.words[n]=e/t|0,i=e%t}return this.strip()},e.prototype.divn=function(t){return this.clone().idivn(t)},e.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var h=new e(1),o=new e(0),s=new e(0),u=new e(1),a=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),f=i.clone();!i.isZero();){for(var m=0,d=1;0==(i.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(i.iushrn(m);m-- >0;)(h.isOdd()||o.isOdd())&&(h.iadd(l),o.isub(f)),h.iushrn(1),o.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(s.isOdd()||u.isOdd())&&(s.iadd(l),u.isub(f)),s.iushrn(1),u.iushrn(1);i.cmp(n)>=0?(i.isub(n),h.isub(s),o.isub(u)):(n.isub(i),s.isub(h),u.isub(o))}return{a:s,b:u,gcd:n.iushln(a)}},e.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var h,o=new e(1),s=new e(0),u=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(i.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(i.iushrn(a);a-- >0;)o.isOdd()&&o.iadd(u),o.iushrn(1);for(var f=0,m=1;0==(n.words[0]&m)&&f<26;++f,m<<=1);if(f>0)for(n.iushrn(f);f-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);i.cmp(n)>=0?(i.isub(n),o.isub(s)):(n.isub(i),s.isub(o))}return(h=0===i.cmpn(1)?o:s).cmpn(0)<0&&h.iadd(t),h},e.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),r=t.clone();i.negative=0,r.negative=0;for(var n=0;i.isEven()&&r.isEven();n++)i.iushrn(1),r.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;r.isEven();)r.iushrn(1);var e=i.cmp(r);if(e<0){var h=i;i=r,r=h}else if(0===e||0===r.cmpn(1))break;i.isub(r)}return r.iushln(n)},e.prototype.invm=function(t){return this.egcd(t).a.umod(t)},e.prototype.isEven=function(){return 0==(1&this.words[0])},e.prototype.isOdd=function(){return 1==(1&this.words[0])},e.prototype.andln=function(t){return this.words[0]&t},e.prototype.bincn=function(t){r("number"==typeof t);var i=t%26,n=(t-i)/26,e=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=e,this;for(var h=e,o=n;0!==h&&o<this.length;o++){var s=0|this.words[o];h=(s+=h)>>>26,s&=67108863,this.words[o]=s}return 0!==h&&(this.words[o]=h,this.length++),this},e.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},e.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),r(t<=67108863,"Number is too big");var e=0|this.words[0];i=e===t?0:e<t?-1:1}return 0!==this.negative?0|-i:i},e.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},e.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],e=0|t.words[r];if(n!==e){n<e?i=-1:n>e&&(i=1);break}}return i},e.prototype.gtn=function(t){return 1===this.cmpn(t)},e.prototype.gt=function(t){return 1===this.cmp(t)},e.prototype.gten=function(t){return this.cmpn(t)>=0},e.prototype.gte=function(t){return this.cmp(t)>=0},e.prototype.ltn=function(t){return-1===this.cmpn(t)},e.prototype.lt=function(t){return-1===this.cmp(t)},e.prototype.lten=function(t){return this.cmpn(t)<=0},e.prototype.lte=function(t){return this.cmp(t)<=0},e.prototype.eqn=function(t){return 0===this.cmpn(t)},e.prototype.eq=function(t){return 0===this.cmp(t)},e.red=function(t){return new _(t)},e.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},e.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},e.prototype._forceRed=function(t){return this.red=t,this},e.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},e.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},e.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},e.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},e.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},e.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},e.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},e.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},e.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},e.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},e.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},e.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},e.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},e.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var M={k256:null,p224:null,p192:null,p25519:null};function v(t,i){this.name=t,this.p=new e(i,16),this.n=this.p.bitLength(),this.k=new e(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function w(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=e._prime(t);this.m=i.p,this.prime=i}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new e(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new e(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var i,r=t;do{this.split(r,this.tmp),i=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,i){t.iushrn(this.n,0,i)},v.prototype.imulK=function(t){return t.imul(this.k)},n(g,v),g.prototype.split=function(t,i){for(var r=4194303,n=Math.min(t.length,9),e=0;e<n;e++)i.words[e]=t.words[e];if(i.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var h=t.words[9];for(i.words[i.length++]=h&r,e=10;e<t.length;e++){var o=0|t.words[e];t.words[e-10]=(o&r)<<4|h>>>22,h=o}h>>>=22,t.words[e-10]=h,0===h&&t.length>10?t.length-=10:t.length-=9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,r=0;r<t.length;r++){var n=0|t.words[r];i+=977*n,t.words[r]=67108863&i,i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(w,v),n(y,v),n(b,v),b.prototype.imulK=function(t){for(var i=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+i,e=67108863&n;n>>>=26,t.words[r]=e,i=n}return 0!==i&&(t.words[t.length++]=i),t},e._prime=function(t){if(M[t])return M[t];var i;if("k256"===t)i=new g;else if("p224"===t)i=new w;else if("p192"===t)i=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return M[t]=i,i},_.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){r(0==(t.negative|i.negative),"red works only with positives"),r(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var r=t.add(i);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var r=t.iadd(i);return r.cmp(this.m)>=0&&r.isub(this.m),r},_.prototype.sub=function(t,i){this._verify2(t,i);var r=t.sub(i);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var r=t.isub(i);return r.cmpn(0)<0&&r.iadd(this.m),r},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(r(i%2==1),3===i){var n=this.m.add(new e(1)).iushrn(2);return this.pow(t,n)}for(var h=this.m.subn(1),o=0;!h.isZero()&&0===h.andln(1);)o++,h.iushrn(1);r(!h.isZero());var s=new e(1).toRed(this),u=s.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new e(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var f=this.pow(l,h),m=this.pow(t,h.addn(1).iushrn(1)),d=this.pow(t,h),p=o;0!==d.cmp(s);){for(var c=d,M=0;0!==c.cmp(s);M++)c=c.redSqr();r(M<p);var v=this.pow(f,new e(1).iushln(p-M-1));m=m.redMul(v),f=v.redSqr(),d=d.redMul(f),p=M}return m},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new e(1).toRed(this);if(0===i.cmpn(1))return t.clone();var r=new Array(16);r[0]=new e(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var h=r[0],o=0,s=0,u=i.bitLength()%26;for(0===u&&(u=26),n=i.length-1;n>=0;n--){for(var a=i.words[n],l=u-1;l>=0;l--){var f=a>>l&1;h!==r[0]&&(h=this.sqr(h)),0!==f||0!==o?(o<<=1,o|=f,(4==++s||0===n&&0===l)&&(h=this.mul(h,r[o]),s=0,o=0)):s=0}u=26}return h},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},e.mont=function(t){return new x(t)},n(x,_),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},x.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(i),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=r.isub(n).iushrn(this.shift),h=e;return e.cmp(this.m)>=0?h=e.isub(this.m):e.cmpn(0)<0&&(h=e.iadd(this.m)),h._forceRed(this)},x.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new e(0)._forceRed(this);var r=t.mul(i),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=r.isub(n).iushrn(this.shift),o=h;return h.cmp(this.m)>=0?o=h.isub(this.m):h.cmpn(0)<0&&(o=h.iadd(this.m)),o._forceRed(this)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(s,t);export{s as b,e as r,o as s};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("./index-cfe3e391.cjs"),r=e.getAugmentedNamespace(e._tslib);exports.require$$0=r;
@@ -0,0 +1 @@
1
+ "use strict";exports.commonjsRequire=function(r){throw new Error('Could not dynamically require "'+r+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')};
@@ -0,0 +1 @@
1
+ "use strict";var t=require("./index-cfe3e391.cjs");function e(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((r=r.apply(t,e||[])).next())}))}function n(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function r(t,e){if(!t)throw new Error(e)}require("events"),require("@ethersproject/providers"),require("zustand"),require("@ethersproject/constants"),require("@ethersproject/contracts"),require("@ethersproject/address"),require("@ethersproject/properties"),require("@ethersproject/transactions"),require("@ethersproject/bytes");const i={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545",137:"https://rpc-mainnet.maticvigil.com/",80001:"https://rpc-mumbai.matic.today/",43114:"https://api.avax.network/ext/bc/C/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",42161:"https://arb1.arbitrum.io/rpc",421613:"https://endpoints.omniatech.io/v1/arbitrum/goerli/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io"},s={1:"ethereum",5:"ethereum",56:"bsc",97:"bsc",137:"polygon",80001:"polygon",43114:"avalanche",43113:"avalanche",42161:"arbitrum",421613:"arbitrum",10:"optimism",420:"optimism"},o={1:"mainnet",5:"testnet",56:"mainnet",97:"testnet",137:"mainnet",80001:"testnet",43114:"mainnet",43113:"testnet",42161:"mainnet",421613:"testnet",10:"mainnet",420:"testnet"},a={1:"https://wallet-v2.blocto.app",5:"https://wallet-v2-dev.blocto.app",56:"https://wallet-v2.blocto.app",97:"https://wallet-v2-dev.blocto.app",137:"https://wallet-v2.blocto.app",80001:"https://wallet-v2-dev.blocto.app",43114:"https://wallet-v2.blocto.app",43113:"https://wallet-v2-dev.blocto.app",42161:"https://wallet-v2.blocto.app",421613:"https://wallet-v2-dev.blocto.app",10:"https://wallet-v2.blocto.app",420:"https://wallet-v2-dev.blocto.app"},c={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},h={devnet:"https://wallet-v2-dev.blocto.app",testnet:"https://wallet-v2-dev.blocto.app","mainnet-beta":"https://wallet-v2.blocto.app"},u=["devnet","testnet","mainnet-beta"],d={1:"https://wallet-v2.blocto.app",2:"https://wallet-v2-dev.blocto.app",3:"https://wallet-v2-dev.blocto.app",4:"https://wallet-v2-dev.blocto.app",5:"https://wallet-v2-staging.blocto.app"};var l;!function(t){t.Mainnet="mainnet",t.Testnet="testnet",t.Devnet="devnet",t.Testing="testing",t.Premainnet="premainnet"}(l||(l={}));const f={1:l.Mainnet,2:l.Testnet,3:l.Devnet,4:l.Testing,5:l.Premainnet},p={1:"https://fullnode.mainnet.aptoslabs.com/v1",2:"https://fullnode.testnet.aptoslabs.com/v1",3:"https://fullnode.devnet.aptoslabs.com/v1",4:"",5:"https://premainnet.aptosdev.com/v1"},g=["connect","disconnect","message","chainChanged","accountsChanged"],w=864e5,v="00000000-0000-0000-0000-000000000000",y="sdk.session";const m="undefined"!=typeof window?window.memoryStorage:new class{constructor(){this.storage={}}getItem(t){return this[t]||null}setItem(t,e){this.storage[t]=e}removeItem(t){delete this.storage[t]}};"undefined"!=typeof window&&(window.memoryStorage=m);const b=(()=>{if("undefined"==typeof window)return!1;try{window.localStorage.setItem("local_storage_supported","1");const t=window.localStorage.getItem("local_storage_supported");return window.localStorage.removeItem("local_storage_supported"),"1"===t}catch(t){return!1}})()?window.localStorage:m,E=(t,e=null)=>{const n=((t,e=null)=>{const n=b.getItem(t);try{return n&&JSON.parse(n)||e}catch(t){return n||e}})(t,null);return n?(new Date).getTime()>n.expiry?(S(t),e):n.value:e},A=(t,e)=>b.setItem(t,"string"==typeof e?e:JSON.stringify(e)),I=(t,e,n)=>A(t,{value:e,expiry:(new Date).getTime()+n}),S=t=>{A(t,""),b.removeItem(t)};class T{constructor(t){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.sessionKey=y,this.off=this.removeListener,this.session=t,g.forEach((t=>{this.eventListeners[t]=[]}))}formatAndSetSessionAccount(t={}){this.session.accounts=Object.keys(t).reduce(((e,n)=>(e[n]=[t[n]],e)),{})}tryRetrieveSessionFromStorage(t){const e=E(this.sessionKey,{}),n=e&&e.code,r=e&&e.address&&e.address[t];this.session.connected=Boolean(n&&r),this.session.code=n||null,this.formatAndSetSessionAccount(e?e.address:{})}request(t){return e(this,void 0,void 0,(function*(){}))}on(t,e){g.includes(t)&&this.eventListeners[t].push(e)}once(){}removeListener(t,e){const n=this.eventListeners[t].findIndex((t=>t===e));-1!==n&&this.eventListeners[t].splice(n,1)}}function _(t){const e=document.createElement("iframe");return e.setAttribute("src",t),e.setAttribute("style","width:100vw;height:100%;position:fixed;top:0;left:0;z-index:2147483646;border:none;"),e}function R(t){document.body.appendChild(t)}function P(t){const e=t&&t.parentNode;e&&e.removeChild instanceof Function&&e.removeChild(t)}var O=(t,e,n=window)=>{n.addEventListener(t,(function r(i){e(i,(()=>n.removeEventListener(t,r)))}))};function B(t,n){return e(this,void 0,void 0,(function*(){if(403===t.status)throw n.session.code=null,S(n.sessionKey),new Error("[Blocto SDK]: Session expired!");return t.json()}))}const C=t=>/\S+@\S+\.\S+/.test(t);function U(){return e(this,void 0,void 0,(function*(){const{networks:t}=yield fetch("https://api.blocto.app/networks/evm").then((t=>t.json()));return t.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.chain_id]:e})),{})}))}var k,N,M;function L(t){return t?"number"==typeof t?t:t.startsWith("0x")?parseInt(t,16):parseInt(t,10):1}class D extends T{constructor({chainId:t,rpc:e,server:n,appId:c,session:h}){super(h),k.add(this),this.supportNetwork={},this.switchableNetwork={},r(t,"'chainId' is required"),this.chainId=L(t),this.networkId=this.chainId,this.chain=s[this.chainId],this.net=o[this.chainId],r(this.chain,`unsupported 'chainId': ${this.chainId}`),this.rpc=e||i[this.chainId]||"",r(this.rpc,"'rpc' is required for Ethereum"),this.server=n||a[this.chainId]||"",this.appId=c||v,this.switchableNetwork[this.chainId]={name:this.chain,display_name:this.chain,network_type:this.net,wallet_web_url:this.server,rpc_url:this.rpc}}loadSwitchableNetwork(t){return e(this,void 0,void 0,(function*(){return U().then((e=>(this.supportNetwork=e,(null==t?void 0:t.length)&&t.forEach((({chainId:t,rpcUrls:e})=>{if(r(e,"rpcUrls is required for networksList"),!(null==e?void 0:e.length))throw new Error("Empty rpcUrls array");n(this,k,"m",N).call(this,{chainId:L(t),rpcUrls:e})})),null)))}))}send(t,n){return e(this,void 0,void 0,(function*(){switch(!0){case n instanceof Function:return this.sendAsync(t,n);case"string"==typeof t&&Array.isArray(n):return this.sendAsync({jsonrpc:"2.0",method:t,params:n});default:return this.sendAsync(t)}}))}sendAsync(t,n){return e(this,void 0,void 0,(function*(){const e=new Promise((e=>{if(Array.isArray(t)){const n=t.filter((t=>"eth_sendTransaction"===t.method)).map((t=>{var e;return null===(e=t.params)||void 0===e?void 0:e[0]})),r=Math.floor(1e4*Math.random()),i={method:"blocto_sendBatchTransaction",params:n},s=this.request(i),o=t.map((({method:t,params:e},n)=>"eth_sendTransaction"===t?s:this.request({id:r+n+1,jsonrpc:"2.0",method:t,params:e})));Promise.allSettled(o).then((n=>e(n.map(((e,n)=>({id:String(r+n+1),jsonrpc:"2.0",method:t[n].method,result:"fulfilled"===e.status?e.value:void 0,error:"fulfilled"!==e.status?e.reason:void 0}))))))}else this.request(Object.assign(Object.assign({},t),{id:Number(t.id)})).then(e)}));if(!n)return e;e.then((t=>n(null,t))).catch((t=>n(t)))}))}request(t){var i,s,o,a,c,h,u;return e(this,void 0,void 0,(function*(){const e=window.ethereum;if(e&&e.isBlocto)return e.request(t);if(!this.session.connected){const e=null===(i=null==t?void 0:t.params)||void 0===i?void 0:i[0];"eth_requestAccounts"===t.method&&C(e)?yield this.enable(e):yield this.enable()}try{let e=null,i=null;switch(t.method){case"eth_requestAccounts":yield this.fetchAccounts();case"eth_accounts":i=this.session.accounts[this.chain];break;case"eth_coinbase":i=this.session.accounts[this.chain][0];break;case"eth_chainId":i=this.chainId,i=`0x${i.toString(16)}`;break;case"net_version":i=this.networkId||this.chainId,i=`0x${i.toString(16)}`;break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":case"eth_sign":i=yield this.handleSign(t);break;case"wallet_disconnect":this.handleDisconnect(),i=null;break;case"blocto_sendBatchTransaction":case"eth_sendTransaction":i=yield this.handleSendTransaction(t);break;case"eth_signTransaction":case"eth_sendRawTransaction":i=null;break;case"wallet_addEthereumChain":if(!(null===(o=null===(s=null==t?void 0:t.params)||void 0===s?void 0:s[0])||void 0===o?void 0:o.chainId)||!(null===(c=null===(a=null==t?void 0:t.params)||void 0===a?void 0:a[0])||void 0===c?void 0:c.rpcUrls.length))throw new Error("Invalid params");yield U().then((e=>{var r,i,s;this.supportNetwork=e,n(this,k,"m",N).call(this,{chainId:L(null===(i=null===(r=null==t?void 0:t.params)||void 0===r?void 0:r[0])||void 0===i?void 0:i.chainId),rpcUrls:null===(s=null==t?void 0:t.params)||void 0===s?void 0:s[0].rpcUrls})})),i=null;break;case"wallet_switchEthereumChain":if(!(null===(u=null===(h=null==t?void 0:t.params)||void 0===h?void 0:h[0])||void 0===u?void 0:u.chainId))throw new Error("Invalid params");if(!this.switchableNetwork[L(t.params[0].chainId)]){const t=new Error("This chain has not been added to SDK. Please try wallet_addEthereumChain first.");throw t.code=4902,t}this.chainId=L(t.params[0].chainId),this.networkId=this.chainId,this.chain=this.switchableNetwork[this.chainId].name,this.net=this.switchableNetwork[this.chainId].network_type,r(this.chain,`unsupported 'chainId': ${this.chainId}`),this.rpc=this.switchableNetwork[this.chainId].rpc_url,r(this.rpc,"'rpc' is required"),this.server=this.switchableNetwork[this.chainId].wallet_web_url,yield this.fetchAccounts(),this.eventListeners.chainChanged.forEach((t=>t(this.chainId))),i=null;break;default:e=yield this.handleReadRequests(t)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw new Error(t)}return e?e.result:i}catch(t){throw console.error(t),t}}))}enable(t){return e(this,void 0,void 0,(function*(){const e=window.ethereum;if(e&&e.isBlocto){if(parseInt(e.chainId,16)!==this.chainId)try{yield e.request({method:"wallet_addEthereumChain",params:[{chainId:`0x${this.chainId.toString(16)}`}]}),this.session.accounts[this.chain]=[e.address]}catch(t){console.error(t)}return new Promise(((t,n)=>setTimeout((()=>e.enable().then(t).catch(n)),10)))}return this.tryRetrieveSessionFromStorage(this.chain),new Promise(((e,n)=>{if("undefined"==typeof window)return n("Currently only supported in browser");if(this.session.connected)return e(this.session.accounts[this.chain]);const r=new URLSearchParams;r.set("l6n",window.location.origin);const i=t&&C(t)?`/${t}`:"",s=_(`${this.server}/${this.appId}/${this.chain}/authn${i}?${r.toString()}`);R(s),O("message",((t,r)=>{const i=t;if(i.origin===this.server){if("ETH:FRAME:RESPONSE"===i.data.type){r(),P(s),this.session.code=i.data.code,this.session.connected=!0,this.eventListeners.connect.forEach((t=>t(this.chainId)));const t=i.data.address;this.formatAndSetSessionAccount(t),I(this.sessionKey,{code:this.session.code,address:t},w),e(this.session.accounts[this.chain])}"ETH:FRAME:CLOSE"===i.data.type&&(r(),P(s),n(new Error("User declined the login request")))}}))}))}))}fetchAccounts(){return e(this,void 0,void 0,(function*(){n(this,k,"m",M).call(this);const{accounts:t}=yield fetch(`${this.server}/api/${this.chain}/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>B(t,this)));return this.session.accounts[this.chain]=t,t}))}handleReadRequests(t){return e(this,void 0,void 0,(function*(){return n(this,k,"m",M).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then((t=>t.json()))}))}handleSign({method:t,params:r}){return e(this,void 0,void 0,(function*(){let e="";if(Array.isArray(r))if("eth_sign"===t)e=r[1].slice(2);else if("personal_sign"===t)e=r[0].slice(2);else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(t)){e=r[1];const{domain:t}=JSON.parse(e);if(L(t.chainId)!==L(this.chainId))throw new Error(`Provided chainId "${t.chainId}" must match the active chainId "${this.chainId}"`)}n(this,k,"m",M).call(this);const{signatureId:i}=yield fetch(`${this.server}/api/${this.chain}/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify({method:t,message:e})}).then((t=>B(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const s=_(`${this.server}/${this.appId}/${this.chain}/user-signature/${i}`);return R(s),new Promise(((t,e)=>O("message",((n,r)=>{const i=n;i.origin===this.server&&"ETH:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(r(),P(s),t(i.data.signature)),"DECLINED"===i.data.status&&(r(),P(s),e(new Error(i.data.errorMessage))))}))))}))}handleSendTransaction(t){return e(this,void 0,void 0,(function*(){n(this,k,"m",M).call(this);const{authorizationId:e}=yield fetch(`${this.server}/api/${this.chain}/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>B(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const r=_(`${this.server}/${this.appId}/${this.chain}/authz/${e}`);return R(r),new Promise(((t,e)=>O("message",((n,i)=>{const s=n;s.origin===this.server&&"ETH:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(i(),P(r),t(s.data.txHash)),"DECLINED"===s.data.status&&(i(),P(r),e(new Error(s.data.errorMessage))))}))))}))}handleDisconnect(){return e(this,void 0,void 0,(function*(){this.session.connected=!1,this.session.code=null,this.session.accounts={},S(y)}))}}k=new WeakSet,N=function({chainId:t,rpcUrls:e}){const n=new URL(e[0]).hostname,{chain_id:r,name:i,display_name:s,network_type:o,blocto_service_environment:a,rpc_endpoint_domains:h}=this.supportNetwork[t];if(h.includes(n)){const t=c[a];this.switchableNetwork[r]={name:i,display_name:s,network_type:o,wallet_web_url:t,rpc_url:e[0]}}else console.warn(`The rpc url ${e[0]} is not supported.`)},M=function(){const t=window.ethereum;if(t&&t.isBlocto&&parseInt(t.chainId,16)!==this.chainId)throw new Error("Blocto SDK network mismatched")};var j=[],$=[],x="undefined"!=typeof Uint8Array?Uint8Array:Array,q=!1;function Y(){q=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)j[e]=t[e],$[t.charCodeAt(e)]=e;$["-".charCodeAt(0)]=62,$["_".charCodeAt(0)]=63}function K(t,e,n){for(var r,i,s=[],o=e;o<n;o+=3)r=(t[o]<<16)+(t[o+1]<<8)+t[o+2],s.push(j[(i=r)>>18&63]+j[i>>12&63]+j[i>>6&63]+j[63&i]);return s.join("")}function F(t){var e;q||Y();for(var n=t.length,r=n%3,i="",s=[],o=16383,a=0,c=n-r;a<c;a+=o)s.push(K(t,a,a+o>c?c:a+o));return 1===r?(e=t[n-1],i+=j[e>>2],i+=j[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=j[e>>10],i+=j[e>>4&63],i+=j[e<<2&63],i+="="),s.push(i),s.join("")}function z(t,e,n,r,i){var s,o,a=8*i-r-1,c=(1<<a)-1,h=c>>1,u=-7,d=n?i-1:0,l=n?-1:1,f=t[e+d];for(d+=l,s=f&(1<<-u)-1,f>>=-u,u+=a;u>0;s=256*s+t[e+d],d+=l,u-=8);for(o=s&(1<<-u)-1,s>>=-u,u+=r;u>0;o=256*o+t[e+d],d+=l,u-=8);if(0===s)s=1-h;else{if(s===c)return o?NaN:1/0*(f?-1:1);o+=Math.pow(2,r),s-=h}return(f?-1:1)*o*Math.pow(2,s-r)}function J(t,e,n,r,i,s){var o,a,c,h=8*s-i-1,u=(1<<h)-1,d=u>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:s-1,p=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-o))<1&&(o--,c*=2),(e+=o+d>=1?l/c:l*Math.pow(2,1-d))*c>=2&&(o++,c/=2),o+d>=u?(a=0,o=u):o+d>=1?(a=(e*c-1)*Math.pow(2,i),o+=d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),o=0));i>=8;t[n+f]=255&a,f+=p,a/=256,i-=8);for(o=o<<i|a,h+=i;h>0;t[n+f]=255&o,f+=p,o/=256,h-=8);t[n+f-p]|=128*g}var W={}.toString,V=Array.isArray||function(t){return"[object Array]"==W.call(t)};function H(){return G.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Z(t,e){if(H()<e)throw new RangeError("Invalid typed array length");return G.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=G.prototype:(null===t&&(t=new G(e)),t.length=e),t}function G(t,e,n){if(!(G.TYPED_ARRAY_SUPPORT||this instanceof G))return new G(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return tt(this,t)}return Q(this,t,e,n)}function Q(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r);G.TYPED_ARRAY_SUPPORT?(t=e).__proto__=G.prototype:t=et(t,e);return t}(t,e,n,r):"string"==typeof e?function(t,e,n){"string"==typeof n&&""!==n||(n="utf8");if(!G.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|it(e,n);t=Z(t,r);var i=t.write(e,n);i!==r&&(t=t.slice(0,i));return t}(t,e,n):function(t,e){if(rt(e)){var n=0|nt(e.length);return 0===(t=Z(t,n)).length||e.copy(t,0,0,n),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?Z(t,0):et(t,e);if("Buffer"===e.type&&V(e.data))return et(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function X(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function tt(t,e){if(X(e),t=Z(t,e<0?0:0|nt(e)),!G.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function et(t,e){var n=e.length<0?0:0|nt(e.length);t=Z(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function nt(t){if(t>=H())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+H().toString(16)+" bytes");return 0|t}function rt(t){return!(null==t||!t._isBuffer)}function it(t,e){if(rt(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return Ct(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return Ut(t).length;default:if(r)return Ct(t).length;e=(""+e).toLowerCase(),r=!0}}function st(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return bt(this,e,n);case"utf8":case"utf-8":return wt(this,e,n);case"ascii":return yt(this,e,n);case"latin1":case"binary":return mt(this,e,n);case"base64":return gt(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Et(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function ot(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function at(t,e,n,r,i){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=G.from(e,r)),rt(e))return 0===e.length?-1:ct(t,e,n,r,i);if("number"==typeof e)return e&=255,G.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):ct(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function ct(t,e,n,r,i){var s,o=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;o=2,a/=2,c/=2,n/=2}function h(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){var u=-1;for(s=n;s<a;s++)if(h(t,s)===h(e,-1===u?0:s-u)){if(-1===u&&(u=s),s-u+1===c)return u*o}else-1!==u&&(s-=s-u),u=-1}else for(n+c>a&&(n=a-c),s=n;s>=0;s--){for(var d=!0,l=0;l<c;l++)if(h(t,s+l)!==h(e,l)){d=!1;break}if(d)return s}return-1}function ht(t,e,n,r){n=Number(n)||0;var i=t.length-n;r?(r=Number(r))>i&&(r=i):r=i;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o<r;++o){var a=parseInt(e.substr(2*o,2),16);if(isNaN(a))return o;t[n+o]=a}return o}function ut(t,e,n,r){return kt(Ct(e,t.length-n),t,n,r)}function dt(t,e,n,r){return kt(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function lt(t,e,n,r){return dt(t,e,n,r)}function ft(t,e,n,r){return kt(Ut(e),t,n,r)}function pt(t,e,n,r){return kt(function(t,e){for(var n,r,i,s=[],o=0;o<t.length&&!((e-=2)<0);++o)r=(n=t.charCodeAt(o))>>8,i=n%256,s.push(i),s.push(r);return s}(e,t.length-n),t,n,r)}function gt(t,e,n){return 0===e&&n===t.length?F(t):F(t.slice(e,n))}function wt(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i<n;){var s,o,a,c,h=t[i],u=null,d=h>239?4:h>223?3:h>191?2:1;if(i+d<=n)switch(d){case 1:h<128&&(u=h);break;case 2:128==(192&(s=t[i+1]))&&(c=(31&h)<<6|63&s)>127&&(u=c);break;case 3:s=t[i+1],o=t[i+2],128==(192&s)&&128==(192&o)&&(c=(15&h)<<12|(63&s)<<6|63&o)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:s=t[i+1],o=t[i+2],a=t[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(c=(15&h)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&c<1114112&&(u=c)}null===u?(u=65533,d=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|1023&u),r.push(u),i+=d}return function(t){var e=t.length;if(e<=vt)return String.fromCharCode.apply(String,t);var n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=vt));return n}(r)}G.TYPED_ARRAY_SUPPORT=void 0===global.TYPED_ARRAY_SUPPORT||global.TYPED_ARRAY_SUPPORT,H(),G.poolSize=8192,G._augment=function(t){return t.__proto__=G.prototype,t},G.from=function(t,e,n){return Q(null,t,e,n)},G.TYPED_ARRAY_SUPPORT&&(G.prototype.__proto__=Uint8Array.prototype,G.__proto__=Uint8Array),G.alloc=function(t,e,n){return function(t,e,n,r){return X(e),e<=0?Z(t,e):void 0!==n?"string"==typeof r?Z(t,e).fill(n,r):Z(t,e).fill(n):Z(t,e)}(null,t,e,n)},G.allocUnsafe=function(t){return tt(null,t)},G.allocUnsafeSlow=function(t){return tt(null,t)},G.isBuffer=function(t){return null!=t&&(!!t._isBuffer||Nt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Nt(t.slice(0,0))}(t))},G.compare=function(t,e){if(!rt(t)||!rt(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,i=0,s=Math.min(n,r);i<s;++i)if(t[i]!==e[i]){n=t[i],r=e[i];break}return n<r?-1:r<n?1:0},G.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},G.concat=function(t,e){if(!V(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return G.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=G.allocUnsafe(e),i=0;for(n=0;n<t.length;++n){var s=t[n];if(!rt(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,i),i+=s.length}return r},G.byteLength=it,G.prototype._isBuffer=!0,G.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)ot(this,e,e+1);return this},G.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)ot(this,e,e+3),ot(this,e+1,e+2);return this},G.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)ot(this,e,e+7),ot(this,e+1,e+6),ot(this,e+2,e+5),ot(this,e+3,e+4);return this},G.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?wt(this,0,t):st.apply(this,arguments)},G.prototype.equals=function(t){if(!rt(t))throw new TypeError("Argument must be a Buffer");return this===t||0===G.compare(this,t)},G.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},G.prototype.compare=function(t,e,n,r,i){if(!rt(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(this===t)return 0;for(var s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(e>>>=0),a=Math.min(s,o),c=this.slice(r,i),h=t.slice(e,n),u=0;u<a;++u)if(c[u]!==h[u]){s=c[u],o=h[u];break}return s<o?-1:o<s?1:0},G.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},G.prototype.indexOf=function(t,e,n){return at(this,t,e,n,!0)},G.prototype.lastIndexOf=function(t,e,n){return at(this,t,e,n,!1)},G.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-e;if((void 0===n||n>i)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return ht(this,t,e,n);case"utf8":case"utf-8":return ut(this,t,e,n);case"ascii":return dt(this,t,e,n);case"latin1":case"binary":return lt(this,t,e,n);case"base64":return ft(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return pt(this,t,e,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},G.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var vt=4096;function yt(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;i<n;++i)r+=String.fromCharCode(127&t[i]);return r}function mt(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;i<n;++i)r+=String.fromCharCode(t[i]);return r}function bt(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var i="",s=e;s<n;++s)i+=Bt(t[s]);return i}function Et(t,e,n){for(var r=t.slice(e,n),i="",s=0;s<r.length;s+=2)i+=String.fromCharCode(r[s]+256*r[s+1]);return i}function At(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function It(t,e,n,r,i,s){if(!rt(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function St(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,s=Math.min(t.length-n,2);i<s;++i)t[n+i]=(e&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function Tt(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,s=Math.min(t.length-n,4);i<s;++i)t[n+i]=e>>>8*(r?i:3-i)&255}function _t(t,e,n,r,i,s){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Rt(t,e,n,r,i){return i||_t(t,0,n,4),J(t,e,n,r,23,4),n+4}function Pt(t,e,n,r,i){return i||_t(t,0,n,8),J(t,e,n,r,52,8),n+8}G.prototype.slice=function(t,e){var n,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),G.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=G.prototype;else{var i=e-t;n=new G(i,void 0);for(var s=0;s<i;++s)n[s]=this[s+t]}return n},G.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||At(t,e,this.length);for(var r=this[t],i=1,s=0;++s<e&&(i*=256);)r+=this[t+s]*i;return r},G.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||At(t,e,this.length);for(var r=this[t+--e],i=1;e>0&&(i*=256);)r+=this[t+--e]*i;return r},G.prototype.readUInt8=function(t,e){return e||At(t,1,this.length),this[t]},G.prototype.readUInt16LE=function(t,e){return e||At(t,2,this.length),this[t]|this[t+1]<<8},G.prototype.readUInt16BE=function(t,e){return e||At(t,2,this.length),this[t]<<8|this[t+1]},G.prototype.readUInt32LE=function(t,e){return e||At(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},G.prototype.readUInt32BE=function(t,e){return e||At(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},G.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||At(t,e,this.length);for(var r=this[t],i=1,s=0;++s<e&&(i*=256);)r+=this[t+s]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*e)),r},G.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||At(t,e,this.length);for(var r=e,i=1,s=this[t+--r];r>0&&(i*=256);)s+=this[t+--r]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*e)),s},G.prototype.readInt8=function(t,e){return e||At(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},G.prototype.readInt16LE=function(t,e){e||At(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},G.prototype.readInt16BE=function(t,e){e||At(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},G.prototype.readInt32LE=function(t,e){return e||At(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},G.prototype.readInt32BE=function(t,e){return e||At(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},G.prototype.readFloatLE=function(t,e){return e||At(t,4,this.length),z(this,t,!0,23,4)},G.prototype.readFloatBE=function(t,e){return e||At(t,4,this.length),z(this,t,!1,23,4)},G.prototype.readDoubleLE=function(t,e){return e||At(t,8,this.length),z(this,t,!0,52,8)},G.prototype.readDoubleBE=function(t,e){return e||At(t,8,this.length),z(this,t,!1,52,8)},G.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||It(this,t,e,n,Math.pow(2,8*n)-1,0);var i=1,s=0;for(this[e]=255&t;++s<n&&(i*=256);)this[e+s]=t/i&255;return e+n},G.prototype.writeUIntBE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||It(this,t,e,n,Math.pow(2,8*n)-1,0);var i=n-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+n},G.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,1,255,0),G.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},G.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,2,65535,0),G.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):St(this,t,e,!0),e+2},G.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,2,65535,0),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):St(this,t,e,!1),e+2},G.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,4,4294967295,0),G.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):Tt(this,t,e,!0),e+4},G.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,4,4294967295,0),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Tt(this,t,e,!1),e+4},G.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);It(this,t,e,n,i-1,-i)}var s=0,o=1,a=0;for(this[e]=255&t;++s<n&&(o*=256);)t<0&&0===a&&0!==this[e+s-1]&&(a=1),this[e+s]=(t/o>>0)-a&255;return e+n},G.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);It(this,t,e,n,i-1,-i)}var s=n-1,o=1,a=0;for(this[e+s]=255&t;--s>=0&&(o*=256);)t<0&&0===a&&0!==this[e+s+1]&&(a=1),this[e+s]=(t/o>>0)-a&255;return e+n},G.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,1,127,-128),G.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},G.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,2,32767,-32768),G.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):St(this,t,e,!0),e+2},G.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,2,32767,-32768),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):St(this,t,e,!1),e+2},G.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,4,2147483647,-2147483648),G.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):Tt(this,t,e,!0),e+4},G.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||It(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),G.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Tt(this,t,e,!1),e+4},G.prototype.writeFloatLE=function(t,e,n){return Rt(this,t,e,!0,n)},G.prototype.writeFloatBE=function(t,e,n){return Rt(this,t,e,!1,n)},G.prototype.writeDoubleLE=function(t,e,n){return Pt(this,t,e,!0,n)},G.prototype.writeDoubleBE=function(t,e,n){return Pt(this,t,e,!1,n)},G.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var i,s=r-n;if(this===t&&n<e&&e<r)for(i=s-1;i>=0;--i)t[i+e]=this[i+n];else if(s<1e3||!G.TYPED_ARRAY_SUPPORT)for(i=0;i<s;++i)t[i+e]=this[i+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+s),e);return s},G.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!G.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var s;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(s=e;s<n;++s)this[s]=t;else{var o=rt(t)?t:Ct(new G(t,r).toString()),a=o.length;for(s=0;s<n-e;++s)this[s+e]=o[s%a]}return this};var Ot=/[^+\/0-9A-Za-z-_]/g;function Bt(t){return t<16?"0"+t.toString(16):t.toString(16)}function Ct(t,e){var n;e=e||1/0;for(var r=t.length,i=null,s=[],o=0;o<r;++o){if((n=t.charCodeAt(o))>55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===r){(e-=3)>-1&&s.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&s.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;s.push(n)}else if(n<2048){if((e-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function Ut(t){return function(t){var e,n,r,i,s,o;q||Y();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s="="===t[a-2]?2:"="===t[a-1]?1:0,o=new x(3*a/4-s),r=s>0?a-4:a;var c=0;for(e=0,n=0;e<r;e+=4,n+=3)i=$[t.charCodeAt(e)]<<18|$[t.charCodeAt(e+1)]<<12|$[t.charCodeAt(e+2)]<<6|$[t.charCodeAt(e+3)],o[c++]=i>>16&255,o[c++]=i>>8&255,o[c++]=255&i;return 2===s?(i=$[t.charCodeAt(e)]<<2|$[t.charCodeAt(e+1)]>>4,o[c++]=255&i):1===s&&(i=$[t.charCodeAt(e)]<<10|$[t.charCodeAt(e+1)]<<4|$[t.charCodeAt(e+2)]>>2,o[c++]=i>>8&255,o[c++]=255&i),o}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Ot,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function kt(t,e,n,r){for(var i=0;i<r&&!(i+n>=e.length||i>=t.length);++i)e[i+n]=t[i];return i}function Nt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function Mt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Lt=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var i=t.charAt(r),s=i.charCodeAt(0);if(255!==e[s])throw new TypeError(i+" is ambiguous");e[s]=r}var o=t.length,a=t.charAt(0),c=Math.log(o)/Math.log(256),h=Math.log(256)/Math.log(o);function u(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var n=0,r=0,i=0;t[n]===a;)r++,n++;for(var s=(t.length-n)*c+1>>>0,h=new Uint8Array(s);t[n];){var u=e[t.charCodeAt(n)];if(255===u)return;for(var d=0,l=s-1;(0!==u||d<i)&&-1!==l;l--,d++)u+=o*h[l]>>>0,h[l]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");i=d,n++}for(var f=s-i;f!==s&&0===h[f];)f++;for(var p=new Uint8Array(r+(s-f)),g=r;f!==s;)p[g++]=h[f++];return p}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var n=0,r=0,i=0,s=e.length;i!==s&&0===e[i];)i++,n++;for(var c=(s-i)*h+1>>>0,u=new Uint8Array(c);i!==s;){for(var d=e[i],l=0,f=c-1;(0!==d||l<r)&&-1!==f;f--,l++)d+=256*u[f]>>>0,u[f]=d%o>>>0,d=d/o>>>0;if(0!==d)throw new Error("Non-zero carry");r=l,i++}for(var p=c-r;p!==c&&0===u[p];)p++;for(var g=a.repeat(n);p<c;++p)g+=t.charAt(u[p]);return g},decodeUnsafe:u,decode:function(t){var e=u(t);if(e)return e;throw new Error("Non-base"+o+" character")}}};var Dt=Mt(Lt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));let jt;try{jt=require("@solana/web3.js")}catch(t){}class $t extends T{constructor({net:t="mainnet-beta",server:e,appId:n,rpc:i,session:s}){if(super(s),r(t,"'net' is required"),r(u.includes(t),"unsupported net"),this.net=t,this.rpc=i||("mainnet-beta"===t?"https://free.rpcpool.com":`https://api.${t}.solana.com`),this.server=e||h[this.net]||"",this.appId=n||v,!jt)throw new Error("No @solana/web3.js installed. Please install it to interact with Solana.")}request(t){return e(this,void 0,void 0,(function*(){this.session.connected||(yield this.connect());try{let e=null,n=null;switch(t.method){case"connect":n=yield this.fetchAccounts();break;case"disconnect":this.disconnect();break;case"getAccounts":n=this.session.accounts.solana.length?this.session.accounts.solana:yield this.fetchAccounts();break;case"getAccountInfo":{const e=yield this.handleReadRequests(t),[r,i]=e.result.value.data;n=Object.assign(Object.assign({},e.result.value),{data:G.from(r,i),owner:new jt.PublicKey(e.result.value.owner)});break}case"convertToProgramWalletTransaction":n=yield this.handleConvertTransaction(t);break;case"signAndSendTransaction":n=yield this.handleSignAndSendTransaction(t);break;case"signTransaction":case"signAllTransactions":throw new Error(`Blocto is program wallet, which doesn't support ${t.method}. Use signAndSendTransaction instead.`);default:e=yield this.handleReadRequests(t)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw new Error(t)}return e?e.result:n}catch(t){throw console.error(t),t}}))}connect(){return e(this,void 0,void 0,(function*(){const t=window.solana;return t&&t.isBlocto?new Promise((e=>{t.on("connect",(()=>{this.session.accounts.solana=[t.publicKey.toBase58()],e()})),t.connect()})):(this.tryRetrieveSessionFromStorage("solana"),new Promise(((t,e)=>{if("undefined"==typeof window)return e("Currently only supported in browser");if(this.session.connected)return t();const n=encodeURIComponent(window.location.origin),r=_(`${this.server}/${this.appId}/solana/authn?l6n=${n}`);R(r),O("message",((n,i)=>{const s=n;if(s.origin===this.server){if("SOL:FRAME:RESPONSE"===s.data.type){i(),P(r),this.session.code=s.data.code,this.session.connected=!0,this.eventListeners.connect.forEach((t=>t(this.net)));const e=s.data.address;this.formatAndSetSessionAccount(e),I(this.sessionKey,{code:this.session.code,address:e},w),t()}"SOL:FRAME:CLOSE"===s.data.type&&(i(),P(r),e(new Error("User declined the login request")))}}))})))}))}disconnect(){return e(this,void 0,void 0,(function*(){const t=window.solana;t&&t.isBlocto?yield t.disconnect():(this.session.code=null,this.session.accounts={},this.eventListeners.disconnect.forEach((t=>t(null))),this.session.connected=!1)}))}fetchAccounts(){return e(this,void 0,void 0,(function*(){const{accounts:t}=yield fetch(`${this.server}/api/solana/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>t.json()));return this.session.accounts.solana=t,t}))}handleReadRequests(t){return e(this,void 0,void 0,(function*(){return fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then((t=>t.json()))}))}convertToProgramWalletTransaction(t){return e(this,void 0,void 0,(function*(){const e=window.solana;if(e&&e.isBlocto)return e.convertToProgramWalletTransaction(t);const n=yield this.request({method:"convertToProgramWalletTransaction",params:{message:t.serializeMessage().toString("hex")}});return this.toTransaction(n,[])}))}signAndSendTransaction(t,n){return e(this,void 0,void 0,(function*(){const e=window.solana;if(e&&e.isBlocto)return e.signAndSendTransaction(t);const r={};if(n){n.commitment&&(r.commitment=n.commitment);const t=n?n._rpcEndpoint:null;t&&t!==this.rpc&&(this.rpc=t,this.disconnect(),yield this.connect())}return this.request({method:"signAndSendTransaction",params:Object.assign({signatures:yield this.collectSignatures(t),message:t.serializeMessage().toString("hex")},r)})}))}toTransaction(t,n){return e(this,void 0,void 0,(function*(){const e=jt.Message.from(G.from(t,"hex")),r=new jt.Transaction;return r.recentBlockhash=e.recentBlockhash,e.header.numRequiredSignatures>0&&(r.feePayer=e.accountKeys[0]),n.forEach(((t,n)=>{const i={signature:t===jt.PublicKey.default.toBase58()?null:Dt.decode(t),publicKey:e.accountKeys[n]};r.signatures.push(i)})),e.instructions.forEach((t=>{const n=t.accounts.map((t=>({pubkey:e.accountKeys[t],isSigner:t<e.header.numRequiredSignatures,isWritable:e.isAccountWritable(t)})));r.instructions.push(new jt.TransactionInstruction({keys:n,programId:e.accountKeys[t.programIdIndex],data:Dt.decode(t.data)}))})),r}))}collectSignatures(t){return e(this,void 0,void 0,(function*(){return t.signatures.reduce(((t,e)=>(e.signature&&(t[e.publicKey.toBase58()]=e.signature.toString("hex")),t)),{})}))}handleConvertTransaction(t){return e(this,void 0,void 0,(function*(){return fetch(`${this.server}/api/solana/convertToWalletTx`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>B(t,this)))}))}handleSignAndSendTransaction(t){return e(this,void 0,void 0,(function*(){const{authorizationId:e}=yield fetch(`${this.server}/api/solana/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>B(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const n=_(`${this.server}/${this.appId}/solana/authz/${e}`);return R(n),new Promise(((t,e)=>O("message",((r,i)=>{const s=r;s.origin===this.server&&"SOL:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(i(),P(n),t(s.data.txHash)),"DECLINED"===s.data.status&&(i(),P(n),e(new Error(s.data.errorMessage))))}))))}))}}class xt extends T{constructor({chainId:t,server:e,appId:n,session:i}){super(i),this.publicKey=[],this.authKey="",r(t,"'chainId' is required"),r(n,"It is necessary to interact with Blocto wallet via your app id. Please visit https://developers.blocto.app for more details."),this.chainId=t,this.networkName=f[t],this.api=p[t];const s=d[t];this.appId=n||v,this.server=e||s||""}get publicAccount(){return{address:this.session.accounts.aptos[0]||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return e(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){return e(this,void 0,void 0,(function*(){return this.session.connected}))}signTransaction(t){return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signTransaction(t);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){return e(this,void 0,void 0,(function*(){const t=window.bloctoAptos;t?yield t.disconnect():(this.session.code=null,this.session.accounts={},this.session.connected=!1)}))}signAndSubmitTransaction(t,n={}){return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signAndSubmitTransaction(t,n);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");const{authorizationId:r}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(Object.assign(Object.assign({},t),n))}).then((t=>B(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const i=_(`${this.server}/${this.appId}/aptos/authz/${r}`);return R(i),new Promise(((t,e)=>O("message",((n,r)=>{const s=n;s.origin===this.server&&"APTOS:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(r(),P(i),t({hash:s.data.txHash})),"DECLINED"===s.data.status&&(r(),P(i),e(new Error(s.data.errorMessage))))}))))}))}signMessage(t){return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos,n=(t=>{var e,n;const r=Object.assign({},t),{message:i,nonce:s,address:o,application:a,chainId:c}=t;return"string"!=typeof i&&(r.message=null!==(e=String(i))&&void 0!==e?e:""),"string"!=typeof s&&(r.nonce=null!==(n=String(s))&&void 0!==n?n:""),o&&"boolean"!=typeof o&&(r.address=!!o),a&&"boolean"!=typeof a&&(r.application=!!a),c&&"boolean"!=typeof c&&(r.chainId=!!c),r})(t);if(e)return e.signMessage(n);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const{signatureId:r}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(n)}).then((t=>B(t,this))),i=_(`${this.server}/${this.appId}/aptos/user-signature/${r}`);return R(i),new Promise(((t,e)=>O("message",((n,r)=>{const s=n;s.origin===this.server&&"APTOS:FRAME:RESPONSE"===s.data.type&&("APPROVED"===s.data.status&&(r(),P(i),t(s.data)),"DECLINED"===s.data.status&&(r(),P(i),e(new Error(s.data.errorMessage))))}))))}))}connect(){return e(this,void 0,void 0,(function*(){const t=window.bloctoAptos;return t?new Promise(((e,n)=>setTimeout((()=>t.connect().then(e).catch(n)),10))):(this.tryRetrieveSessionFromStorage("aptos"),new Promise(((t,n)=>{if("undefined"==typeof window)return n("Currently only supported in browser");if(this.session.connected&&this.session.accounts.aptos.length)return t({address:this.session.accounts.aptos[0],publicKey:this.publicKey,authKey:null,minKeysRequired:2});const r=encodeURIComponent(window.location.origin),i=_(`${this.server}/${this.appId}/aptos/authn?l6n=${r}`);R(i),O("message",((r,s)=>e(this,void 0,void 0,(function*(){const e=r;if(e.origin===this.server){if("APTOS:FRAME:RESPONSE"===e.data.type){s(),P(i),this.session.code=e.data.code,this.session.connected=!0;const r=e.data.address;if(this.formatAndSetSessionAccount(r),I(this.sessionKey,{code:this.session.code,address:r},w),!this.session.accounts.aptos.length)return n();try{const{public_keys:e}=yield fetch(`${this.server}/blocto/aptos/accounts/${this.session.accounts.aptos[0]}`).then((t=>t.json()));this.publicKey=e||[],t({address:this.session.accounts.aptos[0]||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(t){return n(e)}}"APTOS:FRAME:CLOSE"===e.data.type&&(s(),P(i),n(new Error("User declined the login request")))}}))))})))}))}fetchAddress(){return e(this,void 0,void 0,(function*(){const{accounts:t}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>B(t,this)));return this.session.accounts.aptos=t||[],this.session.accounts.aptos[0]}))}}const qt={connected:!1,code:null,accounts:{}};class Yt{constructor({appId:t,ethereum:e,solana:n,aptos:r}){e&&(this.ethereum=new D(Object.assign(Object.assign({},e),{appId:t,session:qt}))),n&&(this.solana=new $t(Object.assign(Object.assign({},n),{appId:t,session:qt}))),r&&(this.aptos=new xt(Object.assign(Object.assign({},r),{appId:t,session:qt})))}}exports.default=function({chainId:e,rpcUrl:n,rpc:r,bloctoParams:i},s){return t.__awaiter(this,void 0,void 0,(function*(){let o;if(!e)throw new Error("chainId is required");n?o=n:e&&r&&(o=r[e]);const a=new Yt({appId:null==i?void 0:i.appId,ethereum:{chainId:e,rpc:o}}).ethereum;if(!a)throw new Error("No provider");return a.on("connect",s.connect),a.on("disconnect",s.disconnect),a.on("accountsChanged",s.accountsChanged),a.on("chainChanged",s.chainChanged),yield a.request({method:"eth_requestAccounts"}),t.convertWeb3Provider(a)}))};
@@ -0,0 +1 @@
1
+ "use strict";var t,i=require("./index-cfe3e391.cjs"),r=require("./_commonjs-dynamic-modules-f09a98c7.cjs"),n={exports:{}};function e(){return t||(t=1,e=n,i.commonjsGlobal,e.exports=(h=h||function(t,n){var e;if("undefined"!=typeof window&&window.crypto&&(e=window.crypto),"undefined"!=typeof self&&self.crypto&&(e=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(e=globalThis.crypto),!e&&"undefined"!=typeof window&&window.msCrypto&&(e=window.msCrypto),!e&&void 0!==i.commonjsGlobal&&i.commonjsGlobal.crypto&&(e=i.commonjsGlobal.crypto),!e&&"function"==typeof r.commonjsRequire)try{e=require("crypto")}catch(t){}var h=function(){if(e){if("function"==typeof e.getRandomValues)try{return e.getRandomValues(new Uint32Array(1))[0]}catch(t){}if("function"==typeof e.randomBytes)try{return e.randomBytes(4).readInt32LE()}catch(t){}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||function(){function t(){}return function(i){var r;return t.prototype=i,r=new t,t.prototype=null,r}}(),s={},u=s.lib={},a=u.Base={extend:function(t){var i=o(this);return t&&i.mixIn(t),i.hasOwnProperty("init")&&this.init!==i.init||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var i in t)t.hasOwnProperty(i)&&(this[i]=t[i]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}},l=u.WordArray=a.extend({init:function(t,i){t=this.words=t||[],this.sigBytes=i!=n?i:4*t.length},toString:function(t){return(t||m).stringify(this)},concat:function(t){var i=this.words,r=t.words,n=this.sigBytes,e=t.sigBytes;if(this.clamp(),n%4)for(var h=0;h<e;h++){var o=r[h>>>2]>>>24-h%4*8&255;i[n+h>>>2]|=o<<24-(n+h)%4*8}else for(var s=0;s<e;s+=4)i[n+s>>>2]=r[s>>>2];return this.sigBytes+=e,this},clamp:function(){var i=this.words,r=this.sigBytes;i[r>>>2]&=4294967295<<32-r%4*8,i.length=t.ceil(r/4)},clone:function(){var t=a.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var i=[],r=0;r<t;r+=4)i.push(h());return new l.init(i,t)}}),f=s.enc={},m=f.Hex={stringify:function(t){for(var i=t.words,r=t.sigBytes,n=[],e=0;e<r;e++){var h=i[e>>>2]>>>24-e%4*8&255;n.push((h>>>4).toString(16)),n.push((15&h).toString(16))}return n.join("")},parse:function(t){for(var i=t.length,r=[],n=0;n<i;n+=2)r[n>>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new l.init(r,i/2)}},d=f.Latin1={stringify:function(t){for(var i=t.words,r=t.sigBytes,n=[],e=0;e<r;e++){var h=i[e>>>2]>>>24-e%4*8&255;n.push(String.fromCharCode(h))}return n.join("")},parse:function(t){for(var i=t.length,r=[],n=0;n<i;n++)r[n>>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new l.init(r,i)}},p=f.Utf8={stringify:function(t){try{return decodeURIComponent(escape(d.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return d.parse(unescape(encodeURIComponent(t)))}},c=u.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=p.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(i){var r,n=this._data,e=n.words,h=n.sigBytes,o=this.blockSize,s=h/(4*o),u=(s=i?t.ceil(s):t.max((0|s)-this._minBufferSize,0))*o,a=t.min(4*u,h);if(u){for(var f=0;f<u;f+=o)this._doProcessBlock(e,f);r=e.splice(0,u),n.sigBytes-=a}return new l.init(r,a)},clone:function(){var t=a.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});u.Hasher=c.extend({cfg:a.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){c.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize()},blockSize:16,_createHelper:function(t){return function(i,r){return new t.init(r).finalize(i)}},_createHmacHelper:function(t){return function(i,r){return new M.HMAC.init(t,r).finalize(i)}}});var M=s.algo={};return s}(Math),h)),n.exports;var e,h}var h,o,s={exports:{}};h=s,i.commonjsGlobal,h.exports=(o=e(),function(t){var i=o,r=i.lib,n=r.WordArray,e=r.Hasher,h=i.algo,s=[],u=[];!function(){function i(i){for(var r=t.sqrt(i),n=2;n<=r;n++)if(!(i%n))return!1;return!0}function r(t){return 4294967296*(t-(0|t))|0}for(var n=2,e=0;e<64;)i(n)&&(e<8&&(s[e]=r(t.pow(n,.5))),u[e]=r(t.pow(n,1/3)),e++),n++}();var a=[],l=h.SHA256=e.extend({_doReset:function(){this._hash=new n.init(s.slice(0))},_doProcessBlock:function(t,i){for(var r=this._hash.words,n=r[0],e=r[1],h=r[2],o=r[3],s=r[4],l=r[5],f=r[6],m=r[7],d=0;d<64;d++){if(d<16)a[d]=0|t[i+d];else{var p=a[d-15],c=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,M=a[d-2],v=(M<<15|M>>>17)^(M<<13|M>>>19)^M>>>10;a[d]=c+a[d-7]+v+a[d-16]}var g=n&e^n&h^e&h,w=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),y=m+((s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25))+(s&l^~s&f)+u[d]+a[d];m=f,f=l,l=s,s=o+y|0,o=h,h=e,e=n,n=y+(w+g)|0}r[0]=r[0]+n|0,r[1]=r[1]+e|0,r[2]=r[2]+h|0,r[3]=r[3]+o|0,r[4]=r[4]+s|0,r[5]=r[5]+l|0,r[6]=r[6]+f|0,r[7]=r[7]+m|0},_doFinalize:function(){var i=this._data,r=i.words,n=8*this._nDataBytes,e=8*i.sigBytes;return r[e>>>5]|=128<<24-e%32,r[14+(e+64>>>9<<4)]=t.floor(n/4294967296),r[15+(e+64>>>9<<4)]=n,i.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var t=e.clone.call(this);return t._hash=this._hash.clone(),t}});i.SHA256=e._createHelper(l),i.HmacSHA256=e._createHmacHelper(l)}(Math),o.SHA256);var u={exports:{}};!function(t,i){function r(t,i){if(!t)throw new Error(i||"Assertion failed")}function n(t,i){t.super_=i;var r=function(){};r.prototype=i.prototype,t.prototype=new r,t.prototype.constructor=t}function e(t,i,r){if(e.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(r=i,i=10),this._init(t||0,i||10,r||"be"))}var h;"object"==typeof t?t.exports=e:i.BN=e,e.BN=e,e.wordSize=26;try{h="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:require("buffer").Buffer}catch(t){}function o(t,i){var r=t.charCodeAt(i);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function s(t,i,r){var n=o(t,r);return r-1>=i&&(n|=o(t,r-1)<<4),n}function u(t,i,r,n){for(var e=0,h=Math.min(t.length,r),o=i;o<h;o++){var s=t.charCodeAt(o)-48;e*=n,e+=s>=49?s-49+10:s>=17?s-17+10:s}return e}e.isBN=function(t){return t instanceof e||null!==t&&"object"==typeof t&&t.constructor.wordSize===e.wordSize&&Array.isArray(t.words)},e.max=function(t,i){return t.cmp(i)>0?t:i},e.min=function(t,i){return t.cmp(i)<0?t:i},e.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),r(i===(0|i)&&i>=2&&i<=36);var e=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(e++,this.negative=1),e<t.length&&(16===i?this._parseHex(t,e,n):(this._parseBase(t,i,e),"le"===n&&this._initArray(this.toArray(),i,n)))},e.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},e.prototype._initArray=function(t,i,n){if(r("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var h,o,s=0;if("be"===n)for(e=t.length-1,h=0;e>=0;e-=3)o=t[e]|t[e-1]<<8|t[e-2]<<16,this.words[h]|=o<<s&67108863,this.words[h+1]=o>>>26-s&67108863,(s+=24)>=26&&(s-=26,h++);else if("le"===n)for(e=0,h=0;e<t.length;e+=3)o=t[e]|t[e+1]<<8|t[e+2]<<16,this.words[h]|=o<<s&67108863,this.words[h+1]=o>>>26-s&67108863,(s+=24)>=26&&(s-=26,h++);return this.strip()},e.prototype._parseHex=function(t,i,r){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var e,h=0,o=0;if("be"===r)for(n=t.length-1;n>=i;n-=2)e=s(t,i,n)<<h,this.words[o]|=67108863&e,h>=18?(h-=18,o+=1,this.words[o]|=e>>>26):h+=8;else for(n=(t.length-i)%2==0?i+1:i;n<t.length;n+=2)e=s(t,i,n)<<h,this.words[o]|=67108863&e,h>=18?(h-=18,o+=1,this.words[o]|=e>>>26):h+=8;this.strip()},e.prototype._parseBase=function(t,i,r){this.words=[0],this.length=1;for(var n=0,e=1;e<=67108863;e*=i)n++;n--,e=e/i|0;for(var h=t.length-r,o=h%n,s=Math.min(h,h-o)+r,a=0,l=r;l<s;l+=n)a=u(t,l,l+n,i),this.imuln(e),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==o){var f=1;for(a=u(t,l,t.length,i),l=0;l<o;l++)f*=i;this.imuln(f),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this.strip()},e.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},e.prototype.clone=function(){var t=new e(null);return this.copy(t),t},e.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},e.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},e.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},e.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function m(t,i,r){r.negative=i.negative^t.negative;var n=t.length+i.length|0;r.length=n,n=n-1|0;var e=0|t.words[0],h=0|i.words[0],o=e*h,s=67108863&o,u=o/67108864|0;r.words[0]=s;for(var a=1;a<n;a++){for(var l=u>>>26,f=67108863&u,m=Math.min(a,i.length-1),d=Math.max(0,a-t.length+1);d<=m;d++){var p=a-d|0;l+=(o=(e=0|t.words[p])*(h=0|i.words[d])+f)/67108864|0,f=67108863&o}r.words[a]=0|f,u=0|l}return 0!==u?r.words[a]=0|u:r.length--,r.strip()}e.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var e=0,h=0,o=0;o<this.length;o++){var s=this.words[o],u=(16777215&(s<<e|h)).toString(16);n=0!=(h=s>>>24-e&16777215)||o!==this.length-1?a[6-u.length]+u+n:u+n,(e+=2)>=26&&(e-=26,o--)}for(0!==h&&(n=h.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var m=l[t],d=f[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(d).toString(t);n=(p=p.idivn(d)).isZero()?c+n:a[m-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(!1,"Base should be between 2 and 36")},e.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},e.prototype.toJSON=function(){return this.toString(16)},e.prototype.toBuffer=function(t,i){return r(void 0!==h),this.toArrayLike(h,t,i)},e.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},e.prototype.toArrayLike=function(t,i,n){var e=this.byteLength(),h=n||Math.max(1,e);r(e<=h,"byte array longer than desired length"),r(h>0,"Requested array length <= 0"),this.strip();var o,s,u="le"===i,a=new t(h),l=this.clone();if(u){for(s=0;!l.isZero();s++)o=l.andln(255),l.iushrn(8),a[s]=o;for(;s<h;s++)a[s]=0}else{for(s=0;s<h-e;s++)a[s]=0;for(s=0;!l.isZero();s++)o=l.andln(255),l.iushrn(8),a[h-s-1]=o}return a},Math.clz32?e.prototype._countBits=function(t){return 32-Math.clz32(t)}:e.prototype._countBits=function(t){var i=t,r=0;return i>=4096&&(r+=13,i>>>=13),i>=64&&(r+=7,i>>>=7),i>=8&&(r+=4,i>>>=4),i>=2&&(r+=2,i>>>=2),r+i},e.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,r=0;return 0==(8191&i)&&(r+=13,i>>>=13),0==(127&i)&&(r+=7,i>>>=7),0==(15&i)&&(r+=4,i>>>=4),0==(3&i)&&(r+=2,i>>>=2),0==(1&i)&&r++,r},e.prototype.bitLength=function(){var t=this.words[this.length-1],i=this._countBits(t);return 26*(this.length-1)+i},e.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var r=this._zeroBits(this.words[i]);if(t+=r,26!==r)break}return t},e.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},e.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},e.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},e.prototype.isNeg=function(){return 0!==this.negative},e.prototype.neg=function(){return this.clone().ineg()},e.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},e.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},e.prototype.ior=function(t){return r(0==(this.negative|t.negative)),this.iuor(t)},e.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},e.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},e.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var r=0;r<i.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=i.length,this.strip()},e.prototype.iand=function(t){return r(0==(this.negative|t.negative)),this.iuand(t)},e.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},e.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},e.prototype.iuxor=function(t){var i,r;this.length>t.length?(i=this,r=t):(i=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=i.words[n]^r.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},e.prototype.ixor=function(t){return r(0==(this.negative|t.negative)),this.iuxor(t)},e.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},e.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},e.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var e=0;e<i;e++)this.words[e]=67108863&~this.words[e];return n>0&&(this.words[e]=~this.words[e]&67108863>>26-n),this.strip()},e.prototype.notn=function(t){return this.clone().inotn(t)},e.prototype.setn=function(t,i){r("number"==typeof t&&t>=0);var n=t/26|0,e=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<e:this.words[n]&~(1<<e),this.strip()},e.prototype.iadd=function(t){var i,r,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(r=this,n=t):(r=t,n=this);for(var e=0,h=0;h<n.length;h++)i=(0|r.words[h])+(0|n.words[h])+e,this.words[h]=67108863&i,e=i>>>26;for(;0!==e&&h<r.length;h++)i=(0|r.words[h])+e,this.words[h]=67108863&i,e=i>>>26;if(this.length=r.length,0!==e)this.words[this.length]=e,this.length++;else if(r!==this)for(;h<r.length;h++)this.words[h]=r.words[h];return this},e.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},e.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,n,e=this.cmp(t);if(0===e)return this.negative=0,this.length=1,this.words[0]=0,this;e>0?(r=this,n=t):(r=t,n=this);for(var h=0,o=0;o<n.length;o++)h=(i=(0|r.words[o])-(0|n.words[o])+h)>>26,this.words[o]=67108863&i;for(;0!==h&&o<r.length;o++)h=(i=(0|r.words[o])+h)>>26,this.words[o]=67108863&i;if(0===h&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this.strip()},e.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,i,r){var n,e,h,o=t.words,s=i.words,u=r.words,a=0,l=0|o[0],f=8191&l,m=l>>>13,d=0|o[1],p=8191&d,c=d>>>13,M=0|o[2],v=8191&M,g=M>>>13,w=0|o[3],y=8191&w,b=w>>>13,_=0|o[4],x=8191&_,A=_>>>13,B=0|o[5],k=8191&B,S=B>>>13,R=0|o[6],q=8191&R,Z=R>>>13,j=0|o[7],z=8191&j,N=j>>>13,I=0|o[8],H=8191&I,L=I>>>13,T=0|o[9],E=8191&T,O=T>>>13,C=0|s[0],P=8191&C,F=C>>>13,G=0|s[1],U=8191&G,D=G>>>13,K=0|s[2],V=8191&K,W=K>>>13,$=0|s[3],J=8191&$,Q=$>>>13,X=0|s[4],Y=8191&X,tt=X>>>13,it=0|s[5],rt=8191&it,nt=it>>>13,et=0|s[6],ht=8191&et,ot=et>>>13,st=0|s[7],ut=8191&st,at=st>>>13,lt=0|s[8],ft=8191&lt,mt=lt>>>13,dt=0|s[9],pt=8191&dt,ct=dt>>>13;r.negative=t.negative^i.negative,r.length=19;var Mt=(a+(n=Math.imul(f,P))|0)+((8191&(e=(e=Math.imul(f,F))+Math.imul(m,P)|0))<<13)|0;a=((h=Math.imul(m,F))+(e>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(p,P),e=(e=Math.imul(p,F))+Math.imul(c,P)|0,h=Math.imul(c,F);var vt=(a+(n=n+Math.imul(f,U)|0)|0)+((8191&(e=(e=e+Math.imul(f,D)|0)+Math.imul(m,U)|0))<<13)|0;a=((h=h+Math.imul(m,D)|0)+(e>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,P),e=(e=Math.imul(v,F))+Math.imul(g,P)|0,h=Math.imul(g,F),n=n+Math.imul(p,U)|0,e=(e=e+Math.imul(p,D)|0)+Math.imul(c,U)|0,h=h+Math.imul(c,D)|0;var gt=(a+(n=n+Math.imul(f,V)|0)|0)+((8191&(e=(e=e+Math.imul(f,W)|0)+Math.imul(m,V)|0))<<13)|0;a=((h=h+Math.imul(m,W)|0)+(e>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(y,P),e=(e=Math.imul(y,F))+Math.imul(b,P)|0,h=Math.imul(b,F),n=n+Math.imul(v,U)|0,e=(e=e+Math.imul(v,D)|0)+Math.imul(g,U)|0,h=h+Math.imul(g,D)|0,n=n+Math.imul(p,V)|0,e=(e=e+Math.imul(p,W)|0)+Math.imul(c,V)|0,h=h+Math.imul(c,W)|0;var wt=(a+(n=n+Math.imul(f,J)|0)|0)+((8191&(e=(e=e+Math.imul(f,Q)|0)+Math.imul(m,J)|0))<<13)|0;a=((h=h+Math.imul(m,Q)|0)+(e>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(x,P),e=(e=Math.imul(x,F))+Math.imul(A,P)|0,h=Math.imul(A,F),n=n+Math.imul(y,U)|0,e=(e=e+Math.imul(y,D)|0)+Math.imul(b,U)|0,h=h+Math.imul(b,D)|0,n=n+Math.imul(v,V)|0,e=(e=e+Math.imul(v,W)|0)+Math.imul(g,V)|0,h=h+Math.imul(g,W)|0,n=n+Math.imul(p,J)|0,e=(e=e+Math.imul(p,Q)|0)+Math.imul(c,J)|0,h=h+Math.imul(c,Q)|0;var yt=(a+(n=n+Math.imul(f,Y)|0)|0)+((8191&(e=(e=e+Math.imul(f,tt)|0)+Math.imul(m,Y)|0))<<13)|0;a=((h=h+Math.imul(m,tt)|0)+(e>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(k,P),e=(e=Math.imul(k,F))+Math.imul(S,P)|0,h=Math.imul(S,F),n=n+Math.imul(x,U)|0,e=(e=e+Math.imul(x,D)|0)+Math.imul(A,U)|0,h=h+Math.imul(A,D)|0,n=n+Math.imul(y,V)|0,e=(e=e+Math.imul(y,W)|0)+Math.imul(b,V)|0,h=h+Math.imul(b,W)|0,n=n+Math.imul(v,J)|0,e=(e=e+Math.imul(v,Q)|0)+Math.imul(g,J)|0,h=h+Math.imul(g,Q)|0,n=n+Math.imul(p,Y)|0,e=(e=e+Math.imul(p,tt)|0)+Math.imul(c,Y)|0,h=h+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(f,rt)|0)|0)+((8191&(e=(e=e+Math.imul(f,nt)|0)+Math.imul(m,rt)|0))<<13)|0;a=((h=h+Math.imul(m,nt)|0)+(e>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(q,P),e=(e=Math.imul(q,F))+Math.imul(Z,P)|0,h=Math.imul(Z,F),n=n+Math.imul(k,U)|0,e=(e=e+Math.imul(k,D)|0)+Math.imul(S,U)|0,h=h+Math.imul(S,D)|0,n=n+Math.imul(x,V)|0,e=(e=e+Math.imul(x,W)|0)+Math.imul(A,V)|0,h=h+Math.imul(A,W)|0,n=n+Math.imul(y,J)|0,e=(e=e+Math.imul(y,Q)|0)+Math.imul(b,J)|0,h=h+Math.imul(b,Q)|0,n=n+Math.imul(v,Y)|0,e=(e=e+Math.imul(v,tt)|0)+Math.imul(g,Y)|0,h=h+Math.imul(g,tt)|0,n=n+Math.imul(p,rt)|0,e=(e=e+Math.imul(p,nt)|0)+Math.imul(c,rt)|0,h=h+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(f,ht)|0)|0)+((8191&(e=(e=e+Math.imul(f,ot)|0)+Math.imul(m,ht)|0))<<13)|0;a=((h=h+Math.imul(m,ot)|0)+(e>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(z,P),e=(e=Math.imul(z,F))+Math.imul(N,P)|0,h=Math.imul(N,F),n=n+Math.imul(q,U)|0,e=(e=e+Math.imul(q,D)|0)+Math.imul(Z,U)|0,h=h+Math.imul(Z,D)|0,n=n+Math.imul(k,V)|0,e=(e=e+Math.imul(k,W)|0)+Math.imul(S,V)|0,h=h+Math.imul(S,W)|0,n=n+Math.imul(x,J)|0,e=(e=e+Math.imul(x,Q)|0)+Math.imul(A,J)|0,h=h+Math.imul(A,Q)|0,n=n+Math.imul(y,Y)|0,e=(e=e+Math.imul(y,tt)|0)+Math.imul(b,Y)|0,h=h+Math.imul(b,tt)|0,n=n+Math.imul(v,rt)|0,e=(e=e+Math.imul(v,nt)|0)+Math.imul(g,rt)|0,h=h+Math.imul(g,nt)|0,n=n+Math.imul(p,ht)|0,e=(e=e+Math.imul(p,ot)|0)+Math.imul(c,ht)|0,h=h+Math.imul(c,ot)|0;var xt=(a+(n=n+Math.imul(f,ut)|0)|0)+((8191&(e=(e=e+Math.imul(f,at)|0)+Math.imul(m,ut)|0))<<13)|0;a=((h=h+Math.imul(m,at)|0)+(e>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(H,P),e=(e=Math.imul(H,F))+Math.imul(L,P)|0,h=Math.imul(L,F),n=n+Math.imul(z,U)|0,e=(e=e+Math.imul(z,D)|0)+Math.imul(N,U)|0,h=h+Math.imul(N,D)|0,n=n+Math.imul(q,V)|0,e=(e=e+Math.imul(q,W)|0)+Math.imul(Z,V)|0,h=h+Math.imul(Z,W)|0,n=n+Math.imul(k,J)|0,e=(e=e+Math.imul(k,Q)|0)+Math.imul(S,J)|0,h=h+Math.imul(S,Q)|0,n=n+Math.imul(x,Y)|0,e=(e=e+Math.imul(x,tt)|0)+Math.imul(A,Y)|0,h=h+Math.imul(A,tt)|0,n=n+Math.imul(y,rt)|0,e=(e=e+Math.imul(y,nt)|0)+Math.imul(b,rt)|0,h=h+Math.imul(b,nt)|0,n=n+Math.imul(v,ht)|0,e=(e=e+Math.imul(v,ot)|0)+Math.imul(g,ht)|0,h=h+Math.imul(g,ot)|0,n=n+Math.imul(p,ut)|0,e=(e=e+Math.imul(p,at)|0)+Math.imul(c,ut)|0,h=h+Math.imul(c,at)|0;var At=(a+(n=n+Math.imul(f,ft)|0)|0)+((8191&(e=(e=e+Math.imul(f,mt)|0)+Math.imul(m,ft)|0))<<13)|0;a=((h=h+Math.imul(m,mt)|0)+(e>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(E,P),e=(e=Math.imul(E,F))+Math.imul(O,P)|0,h=Math.imul(O,F),n=n+Math.imul(H,U)|0,e=(e=e+Math.imul(H,D)|0)+Math.imul(L,U)|0,h=h+Math.imul(L,D)|0,n=n+Math.imul(z,V)|0,e=(e=e+Math.imul(z,W)|0)+Math.imul(N,V)|0,h=h+Math.imul(N,W)|0,n=n+Math.imul(q,J)|0,e=(e=e+Math.imul(q,Q)|0)+Math.imul(Z,J)|0,h=h+Math.imul(Z,Q)|0,n=n+Math.imul(k,Y)|0,e=(e=e+Math.imul(k,tt)|0)+Math.imul(S,Y)|0,h=h+Math.imul(S,tt)|0,n=n+Math.imul(x,rt)|0,e=(e=e+Math.imul(x,nt)|0)+Math.imul(A,rt)|0,h=h+Math.imul(A,nt)|0,n=n+Math.imul(y,ht)|0,e=(e=e+Math.imul(y,ot)|0)+Math.imul(b,ht)|0,h=h+Math.imul(b,ot)|0,n=n+Math.imul(v,ut)|0,e=(e=e+Math.imul(v,at)|0)+Math.imul(g,ut)|0,h=h+Math.imul(g,at)|0,n=n+Math.imul(p,ft)|0,e=(e=e+Math.imul(p,mt)|0)+Math.imul(c,ft)|0,h=h+Math.imul(c,mt)|0;var Bt=(a+(n=n+Math.imul(f,pt)|0)|0)+((8191&(e=(e=e+Math.imul(f,ct)|0)+Math.imul(m,pt)|0))<<13)|0;a=((h=h+Math.imul(m,ct)|0)+(e>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(E,U),e=(e=Math.imul(E,D))+Math.imul(O,U)|0,h=Math.imul(O,D),n=n+Math.imul(H,V)|0,e=(e=e+Math.imul(H,W)|0)+Math.imul(L,V)|0,h=h+Math.imul(L,W)|0,n=n+Math.imul(z,J)|0,e=(e=e+Math.imul(z,Q)|0)+Math.imul(N,J)|0,h=h+Math.imul(N,Q)|0,n=n+Math.imul(q,Y)|0,e=(e=e+Math.imul(q,tt)|0)+Math.imul(Z,Y)|0,h=h+Math.imul(Z,tt)|0,n=n+Math.imul(k,rt)|0,e=(e=e+Math.imul(k,nt)|0)+Math.imul(S,rt)|0,h=h+Math.imul(S,nt)|0,n=n+Math.imul(x,ht)|0,e=(e=e+Math.imul(x,ot)|0)+Math.imul(A,ht)|0,h=h+Math.imul(A,ot)|0,n=n+Math.imul(y,ut)|0,e=(e=e+Math.imul(y,at)|0)+Math.imul(b,ut)|0,h=h+Math.imul(b,at)|0,n=n+Math.imul(v,ft)|0,e=(e=e+Math.imul(v,mt)|0)+Math.imul(g,ft)|0,h=h+Math.imul(g,mt)|0;var kt=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(e=(e=e+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((h=h+Math.imul(c,ct)|0)+(e>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(E,V),e=(e=Math.imul(E,W))+Math.imul(O,V)|0,h=Math.imul(O,W),n=n+Math.imul(H,J)|0,e=(e=e+Math.imul(H,Q)|0)+Math.imul(L,J)|0,h=h+Math.imul(L,Q)|0,n=n+Math.imul(z,Y)|0,e=(e=e+Math.imul(z,tt)|0)+Math.imul(N,Y)|0,h=h+Math.imul(N,tt)|0,n=n+Math.imul(q,rt)|0,e=(e=e+Math.imul(q,nt)|0)+Math.imul(Z,rt)|0,h=h+Math.imul(Z,nt)|0,n=n+Math.imul(k,ht)|0,e=(e=e+Math.imul(k,ot)|0)+Math.imul(S,ht)|0,h=h+Math.imul(S,ot)|0,n=n+Math.imul(x,ut)|0,e=(e=e+Math.imul(x,at)|0)+Math.imul(A,ut)|0,h=h+Math.imul(A,at)|0,n=n+Math.imul(y,ft)|0,e=(e=e+Math.imul(y,mt)|0)+Math.imul(b,ft)|0,h=h+Math.imul(b,mt)|0;var St=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(e=(e=e+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((h=h+Math.imul(g,ct)|0)+(e>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(E,J),e=(e=Math.imul(E,Q))+Math.imul(O,J)|0,h=Math.imul(O,Q),n=n+Math.imul(H,Y)|0,e=(e=e+Math.imul(H,tt)|0)+Math.imul(L,Y)|0,h=h+Math.imul(L,tt)|0,n=n+Math.imul(z,rt)|0,e=(e=e+Math.imul(z,nt)|0)+Math.imul(N,rt)|0,h=h+Math.imul(N,nt)|0,n=n+Math.imul(q,ht)|0,e=(e=e+Math.imul(q,ot)|0)+Math.imul(Z,ht)|0,h=h+Math.imul(Z,ot)|0,n=n+Math.imul(k,ut)|0,e=(e=e+Math.imul(k,at)|0)+Math.imul(S,ut)|0,h=h+Math.imul(S,at)|0,n=n+Math.imul(x,ft)|0,e=(e=e+Math.imul(x,mt)|0)+Math.imul(A,ft)|0,h=h+Math.imul(A,mt)|0;var Rt=(a+(n=n+Math.imul(y,pt)|0)|0)+((8191&(e=(e=e+Math.imul(y,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((h=h+Math.imul(b,ct)|0)+(e>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(E,Y),e=(e=Math.imul(E,tt))+Math.imul(O,Y)|0,h=Math.imul(O,tt),n=n+Math.imul(H,rt)|0,e=(e=e+Math.imul(H,nt)|0)+Math.imul(L,rt)|0,h=h+Math.imul(L,nt)|0,n=n+Math.imul(z,ht)|0,e=(e=e+Math.imul(z,ot)|0)+Math.imul(N,ht)|0,h=h+Math.imul(N,ot)|0,n=n+Math.imul(q,ut)|0,e=(e=e+Math.imul(q,at)|0)+Math.imul(Z,ut)|0,h=h+Math.imul(Z,at)|0,n=n+Math.imul(k,ft)|0,e=(e=e+Math.imul(k,mt)|0)+Math.imul(S,ft)|0,h=h+Math.imul(S,mt)|0;var qt=(a+(n=n+Math.imul(x,pt)|0)|0)+((8191&(e=(e=e+Math.imul(x,ct)|0)+Math.imul(A,pt)|0))<<13)|0;a=((h=h+Math.imul(A,ct)|0)+(e>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(E,rt),e=(e=Math.imul(E,nt))+Math.imul(O,rt)|0,h=Math.imul(O,nt),n=n+Math.imul(H,ht)|0,e=(e=e+Math.imul(H,ot)|0)+Math.imul(L,ht)|0,h=h+Math.imul(L,ot)|0,n=n+Math.imul(z,ut)|0,e=(e=e+Math.imul(z,at)|0)+Math.imul(N,ut)|0,h=h+Math.imul(N,at)|0,n=n+Math.imul(q,ft)|0,e=(e=e+Math.imul(q,mt)|0)+Math.imul(Z,ft)|0,h=h+Math.imul(Z,mt)|0;var Zt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(e=(e=e+Math.imul(k,ct)|0)+Math.imul(S,pt)|0))<<13)|0;a=((h=h+Math.imul(S,ct)|0)+(e>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,n=Math.imul(E,ht),e=(e=Math.imul(E,ot))+Math.imul(O,ht)|0,h=Math.imul(O,ot),n=n+Math.imul(H,ut)|0,e=(e=e+Math.imul(H,at)|0)+Math.imul(L,ut)|0,h=h+Math.imul(L,at)|0,n=n+Math.imul(z,ft)|0,e=(e=e+Math.imul(z,mt)|0)+Math.imul(N,ft)|0,h=h+Math.imul(N,mt)|0;var jt=(a+(n=n+Math.imul(q,pt)|0)|0)+((8191&(e=(e=e+Math.imul(q,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((h=h+Math.imul(Z,ct)|0)+(e>>>13)|0)+(jt>>>26)|0,jt&=67108863,n=Math.imul(E,ut),e=(e=Math.imul(E,at))+Math.imul(O,ut)|0,h=Math.imul(O,at),n=n+Math.imul(H,ft)|0,e=(e=e+Math.imul(H,mt)|0)+Math.imul(L,ft)|0,h=h+Math.imul(L,mt)|0;var zt=(a+(n=n+Math.imul(z,pt)|0)|0)+((8191&(e=(e=e+Math.imul(z,ct)|0)+Math.imul(N,pt)|0))<<13)|0;a=((h=h+Math.imul(N,ct)|0)+(e>>>13)|0)+(zt>>>26)|0,zt&=67108863,n=Math.imul(E,ft),e=(e=Math.imul(E,mt))+Math.imul(O,ft)|0,h=Math.imul(O,mt);var Nt=(a+(n=n+Math.imul(H,pt)|0)|0)+((8191&(e=(e=e+Math.imul(H,ct)|0)+Math.imul(L,pt)|0))<<13)|0;a=((h=h+Math.imul(L,ct)|0)+(e>>>13)|0)+(Nt>>>26)|0,Nt&=67108863;var It=(a+(n=Math.imul(E,pt))|0)+((8191&(e=(e=Math.imul(E,ct))+Math.imul(O,pt)|0))<<13)|0;return a=((h=Math.imul(O,ct))+(e>>>13)|0)+(It>>>26)|0,It&=67108863,u[0]=Mt,u[1]=vt,u[2]=gt,u[3]=wt,u[4]=yt,u[5]=bt,u[6]=_t,u[7]=xt,u[8]=At,u[9]=Bt,u[10]=kt,u[11]=St,u[12]=Rt,u[13]=qt,u[14]=Zt,u[15]=jt,u[16]=zt,u[17]=Nt,u[18]=It,0!==a&&(u[19]=a,r.length++),r};function p(t,i,r){return(new c).mulp(t,i,r)}function c(t,i){this.x=t,this.y=i}Math.imul||(d=m),e.prototype.mulTo=function(t,i){var r,n=this.length+t.length;return r=10===this.length&&10===t.length?d(this,t,i):n<63?m(this,t,i):n<1024?function(t,i,r){r.negative=i.negative^t.negative,r.length=t.length+i.length;for(var n=0,e=0,h=0;h<r.length-1;h++){var o=e;e=0;for(var s=67108863&n,u=Math.min(h,i.length-1),a=Math.max(0,h-t.length+1);a<=u;a++){var l=h-a,f=(0|t.words[l])*(0|i.words[a]),m=67108863&f;s=67108863&(m=m+s|0),e+=(o=(o=o+(f/67108864|0)|0)+(m>>>26)|0)>>>26,o&=67108863}r.words[h]=s,n=o,o=e}return 0!==n?r.words[h]=n:r.length--,r.strip()}(this,t,i):p(this,t,i),r},c.prototype.makeRBT=function(t){for(var i=new Array(t),r=e.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,r,t);return i},c.prototype.revBin=function(t,i,r){if(0===t||t===r-1)return t;for(var n=0,e=0;e<i;e++)n|=(1&t)<<i-e-1,t>>=1;return n},c.prototype.permute=function(t,i,r,n,e,h){for(var o=0;o<h;o++)n[o]=i[t[o]],e[o]=r[t[o]]},c.prototype.transform=function(t,i,r,n,e,h){this.permute(h,t,i,r,n,e);for(var o=1;o<e;o<<=1)for(var s=o<<1,u=Math.cos(2*Math.PI/s),a=Math.sin(2*Math.PI/s),l=0;l<e;l+=s)for(var f=u,m=a,d=0;d<o;d++){var p=r[l+d],c=n[l+d],M=r[l+d+o],v=n[l+d+o],g=f*M-m*v;v=f*v+m*M,M=g,r[l+d]=p+M,n[l+d]=c+v,r[l+d+o]=p-M,n[l+d+o]=c-v,d!==s&&(g=u*f-a*m,m=u*m+a*f,f=g)}},c.prototype.guessLen13b=function(t,i){var r=1|Math.max(i,t),n=1&r,e=0;for(r=r/2|0;r;r>>>=1)e++;return 1<<e+1+n},c.prototype.conjugate=function(t,i,r){if(!(r<=1))for(var n=0;n<r/2;n++){var e=t[n];t[n]=t[r-n-1],t[r-n-1]=e,e=i[n],i[n]=-i[r-n-1],i[r-n-1]=-e}},c.prototype.normalize13b=function(t,i){for(var r=0,n=0;n<i/2;n++){var e=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+r;t[n]=67108863&e,r=e<67108864?0:e/67108864|0}return t},c.prototype.convert13b=function(t,i,n,e){for(var h=0,o=0;o<i;o++)h+=0|t[o],n[2*o]=8191&h,h>>>=13,n[2*o+1]=8191&h,h>>>=13;for(o=2*i;o<e;++o)n[o]=0;r(0===h),r(0==(-8192&h))},c.prototype.stub=function(t){for(var i=new Array(t),r=0;r<t;r++)i[r]=0;return i},c.prototype.mulp=function(t,i,r){var n=2*this.guessLen13b(t.length,i.length),e=this.makeRBT(n),h=this.stub(n),o=new Array(n),s=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),f=new Array(n),m=r.words;m.length=n,this.convert13b(t.words,t.length,o,n),this.convert13b(i.words,i.length,a,n),this.transform(o,h,s,u,n,e),this.transform(a,h,l,f,n,e);for(var d=0;d<n;d++){var p=s[d]*l[d]-u[d]*f[d];u[d]=s[d]*f[d]+u[d]*l[d],s[d]=p}return this.conjugate(s,u,n),this.transform(s,u,m,h,n,e),this.conjugate(m,h,n),this.normalize13b(m,n),r.negative=t.negative^i.negative,r.length=t.length+i.length,r.strip()},e.prototype.mul=function(t){var i=new e(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},e.prototype.mulf=function(t){var i=new e(null);return i.words=new Array(this.length+t.length),p(this,t,i)},e.prototype.imul=function(t){return this.clone().mulTo(t,this)},e.prototype.imuln=function(t){r("number"==typeof t),r(t<67108864);for(var i=0,n=0;n<this.length;n++){var e=(0|this.words[n])*t,h=(67108863&e)+(67108863&i);i>>=26,i+=e/67108864|0,i+=h>>>26,this.words[n]=67108863&h}return 0!==i&&(this.words[n]=i,this.length++),this},e.prototype.muln=function(t){return this.clone().imuln(t)},e.prototype.sqr=function(){return this.mul(this)},e.prototype.isqr=function(){return this.imul(this.clone())},e.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),r=0;r<i.length;r++){var n=r/26|0,e=r%26;i[r]=(t.words[n]&1<<e)>>>e}return i}(t);if(0===i.length)return new e(1);for(var r=this,n=0;n<i.length&&0===i[n];n++,r=r.sqr());if(++n<i.length)for(var h=r.sqr();n<i.length;n++,h=h.sqr())0!==i[n]&&(r=r.mul(h));return r},e.prototype.iushln=function(t){r("number"==typeof t&&t>=0);var i,n=t%26,e=(t-n)/26,h=67108863>>>26-n<<26-n;if(0!==n){var o=0;for(i=0;i<this.length;i++){var s=this.words[i]&h,u=(0|this.words[i])-s<<n;this.words[i]=u|o,o=s>>>26-n}o&&(this.words[i]=o,this.length++)}if(0!==e){for(i=this.length-1;i>=0;i--)this.words[i+e]=this.words[i];for(i=0;i<e;i++)this.words[i]=0;this.length+=e}return this.strip()},e.prototype.ishln=function(t){return r(0===this.negative),this.iushln(t)},e.prototype.iushrn=function(t,i,n){var e;r("number"==typeof t&&t>=0),e=i?(i-i%26)/26:0;var h=t%26,o=Math.min((t-h)/26,this.length),s=67108863^67108863>>>h<<h,u=n;if(e-=o,e=Math.max(0,e),u){for(var a=0;a<o;a++)u.words[a]=this.words[a];u.length=o}if(0===o);else if(this.length>o)for(this.length-=o,a=0;a<this.length;a++)this.words[a]=this.words[a+o];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=e);a--){var f=0|this.words[a];this.words[a]=l<<26-h|f>>>h,l=f&s}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},e.prototype.ishrn=function(t,i,n){return r(0===this.negative),this.iushrn(t,i,n)},e.prototype.shln=function(t){return this.clone().ishln(t)},e.prototype.ushln=function(t){return this.clone().iushln(t)},e.prototype.shrn=function(t){return this.clone().ishrn(t)},e.prototype.ushrn=function(t){return this.clone().iushrn(t)},e.prototype.testn=function(t){r("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26,e=1<<i;return!(this.length<=n||!(this.words[n]&e))},e.prototype.imaskn=function(t){r("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==i&&n++,this.length=Math.min(n,this.length),0!==i){var e=67108863^67108863>>>i<<i;this.words[this.length-1]&=e}return this.strip()},e.prototype.maskn=function(t){return this.clone().imaskn(t)},e.prototype.iaddn=function(t){return r("number"==typeof t),r(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},e.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},e.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},e.prototype.addn=function(t){return this.clone().iaddn(t)},e.prototype.subn=function(t){return this.clone().isubn(t)},e.prototype.iabs=function(){return this.negative=0,this},e.prototype.abs=function(){return this.clone().iabs()},e.prototype._ishlnsubmul=function(t,i,n){var e,h,o=t.length+n;this._expand(o);var s=0;for(e=0;e<t.length;e++){h=(0|this.words[e+n])+s;var u=(0|t.words[e])*i;s=((h-=67108863&u)>>26)-(u/67108864|0),this.words[e+n]=67108863&h}for(;e<this.length-n;e++)s=(h=(0|this.words[e+n])+s)>>26,this.words[e+n]=67108863&h;if(0===s)return this.strip();for(r(-1===s),s=0,e=0;e<this.length;e++)s=(h=-(0|this.words[e])+s)>>26,this.words[e]=67108863&h;return this.negative=1,this.strip()},e.prototype._wordDiv=function(t,i){var r=(this.length,t.length),n=this.clone(),h=t,o=0|h.words[h.length-1];0!=(r=26-this._countBits(o))&&(h=h.ushln(r),n.iushln(r),o=0|h.words[h.length-1]);var s,u=n.length-h.length;if("mod"!==i){(s=new e(null)).length=u+1,s.words=new Array(s.length);for(var a=0;a<s.length;a++)s.words[a]=0}var l=n.clone()._ishlnsubmul(h,1,u);0===l.negative&&(n=l,s&&(s.words[u]=1));for(var f=u-1;f>=0;f--){var m=67108864*(0|n.words[h.length+f])+(0|n.words[h.length+f-1]);for(m=Math.min(m/o|0,67108863),n._ishlnsubmul(h,m,f);0!==n.negative;)m--,n.negative=0,n._ishlnsubmul(h,1,f),n.isZero()||(n.negative^=1);s&&(s.words[f]=m)}return s&&s.strip(),n.strip(),"div"!==i&&0!==r&&n.iushrn(r),{div:s||null,mod:n}},e.prototype.divmod=function(t,i,n){return r(!t.isZero()),this.isZero()?{div:new e(0),mod:new e(0)}:0!==this.negative&&0===t.negative?(s=this.neg().divmod(t,i),"mod"!==i&&(h=s.div.neg()),"div"!==i&&(o=s.mod.neg(),n&&0!==o.negative&&o.iadd(t)),{div:h,mod:o}):0===this.negative&&0!==t.negative?(s=this.divmod(t.neg(),i),"mod"!==i&&(h=s.div.neg()),{div:h,mod:s.mod}):0!=(this.negative&t.negative)?(s=this.neg().divmod(t.neg(),i),"div"!==i&&(o=s.mod.neg(),n&&0!==o.negative&&o.isub(t)),{div:s.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new e(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new e(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new e(this.modn(t.words[0]))}:this._wordDiv(t,i);var h,o,s},e.prototype.div=function(t){return this.divmod(t,"div",!1).div},e.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},e.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},e.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var r=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),e=t.andln(1),h=r.cmp(n);return h<0||1===e&&0===h?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},e.prototype.modn=function(t){r(t<=67108863);for(var i=(1<<26)%t,n=0,e=this.length-1;e>=0;e--)n=(i*n+(0|this.words[e]))%t;return n},e.prototype.idivn=function(t){r(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var e=(0|this.words[n])+67108864*i;this.words[n]=e/t|0,i=e%t}return this.strip()},e.prototype.divn=function(t){return this.clone().idivn(t)},e.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var h=new e(1),o=new e(0),s=new e(0),u=new e(1),a=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),f=i.clone();!i.isZero();){for(var m=0,d=1;0==(i.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(i.iushrn(m);m-- >0;)(h.isOdd()||o.isOdd())&&(h.iadd(l),o.isub(f)),h.iushrn(1),o.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(s.isOdd()||u.isOdd())&&(s.iadd(l),u.isub(f)),s.iushrn(1),u.iushrn(1);i.cmp(n)>=0?(i.isub(n),h.isub(s),o.isub(u)):(n.isub(i),s.isub(h),u.isub(o))}return{a:s,b:u,gcd:n.iushln(a)}},e.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var h,o=new e(1),s=new e(0),u=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(i.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(i.iushrn(a);a-- >0;)o.isOdd()&&o.iadd(u),o.iushrn(1);for(var f=0,m=1;0==(n.words[0]&m)&&f<26;++f,m<<=1);if(f>0)for(n.iushrn(f);f-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);i.cmp(n)>=0?(i.isub(n),o.isub(s)):(n.isub(i),s.isub(o))}return(h=0===i.cmpn(1)?o:s).cmpn(0)<0&&h.iadd(t),h},e.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),r=t.clone();i.negative=0,r.negative=0;for(var n=0;i.isEven()&&r.isEven();n++)i.iushrn(1),r.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;r.isEven();)r.iushrn(1);var e=i.cmp(r);if(e<0){var h=i;i=r,r=h}else if(0===e||0===r.cmpn(1))break;i.isub(r)}return r.iushln(n)},e.prototype.invm=function(t){return this.egcd(t).a.umod(t)},e.prototype.isEven=function(){return 0==(1&this.words[0])},e.prototype.isOdd=function(){return 1==(1&this.words[0])},e.prototype.andln=function(t){return this.words[0]&t},e.prototype.bincn=function(t){r("number"==typeof t);var i=t%26,n=(t-i)/26,e=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=e,this;for(var h=e,o=n;0!==h&&o<this.length;o++){var s=0|this.words[o];h=(s+=h)>>>26,s&=67108863,this.words[o]=s}return 0!==h&&(this.words[o]=h,this.length++),this},e.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},e.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),r(t<=67108863,"Number is too big");var e=0|this.words[0];i=e===t?0:e<t?-1:1}return 0!==this.negative?0|-i:i},e.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},e.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],e=0|t.words[r];if(n!==e){n<e?i=-1:n>e&&(i=1);break}}return i},e.prototype.gtn=function(t){return 1===this.cmpn(t)},e.prototype.gt=function(t){return 1===this.cmp(t)},e.prototype.gten=function(t){return this.cmpn(t)>=0},e.prototype.gte=function(t){return this.cmp(t)>=0},e.prototype.ltn=function(t){return-1===this.cmpn(t)},e.prototype.lt=function(t){return-1===this.cmp(t)},e.prototype.lten=function(t){return this.cmpn(t)<=0},e.prototype.lte=function(t){return this.cmp(t)<=0},e.prototype.eqn=function(t){return 0===this.cmpn(t)},e.prototype.eq=function(t){return 0===this.cmp(t)},e.red=function(t){return new _(t)},e.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},e.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},e.prototype._forceRed=function(t){return this.red=t,this},e.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},e.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},e.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},e.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},e.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},e.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},e.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},e.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},e.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},e.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},e.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},e.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},e.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},e.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var M={k256:null,p224:null,p192:null,p25519:null};function v(t,i){this.name=t,this.p=new e(i,16),this.n=this.p.bitLength(),this.k=new e(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function w(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=e._prime(t);this.m=i.p,this.prime=i}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new e(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new e(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var i,r=t;do{this.split(r,this.tmp),i=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,i){t.iushrn(this.n,0,i)},v.prototype.imulK=function(t){return t.imul(this.k)},n(g,v),g.prototype.split=function(t,i){for(var r=4194303,n=Math.min(t.length,9),e=0;e<n;e++)i.words[e]=t.words[e];if(i.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var h=t.words[9];for(i.words[i.length++]=h&r,e=10;e<t.length;e++){var o=0|t.words[e];t.words[e-10]=(o&r)<<4|h>>>22,h=o}h>>>=22,t.words[e-10]=h,0===h&&t.length>10?t.length-=10:t.length-=9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,r=0;r<t.length;r++){var n=0|t.words[r];i+=977*n,t.words[r]=67108863&i,i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(w,v),n(y,v),n(b,v),b.prototype.imulK=function(t){for(var i=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+i,e=67108863&n;n>>>=26,t.words[r]=e,i=n}return 0!==i&&(t.words[t.length++]=i),t},e._prime=function(t){if(M[t])return M[t];var i;if("k256"===t)i=new g;else if("p224"===t)i=new w;else if("p192"===t)i=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return M[t]=i,i},_.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){r(0==(t.negative|i.negative),"red works only with positives"),r(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var r=t.add(i);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var r=t.iadd(i);return r.cmp(this.m)>=0&&r.isub(this.m),r},_.prototype.sub=function(t,i){this._verify2(t,i);var r=t.sub(i);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var r=t.isub(i);return r.cmpn(0)<0&&r.iadd(this.m),r},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(r(i%2==1),3===i){var n=this.m.add(new e(1)).iushrn(2);return this.pow(t,n)}for(var h=this.m.subn(1),o=0;!h.isZero()&&0===h.andln(1);)o++,h.iushrn(1);r(!h.isZero());var s=new e(1).toRed(this),u=s.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new e(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var f=this.pow(l,h),m=this.pow(t,h.addn(1).iushrn(1)),d=this.pow(t,h),p=o;0!==d.cmp(s);){for(var c=d,M=0;0!==c.cmp(s);M++)c=c.redSqr();r(M<p);var v=this.pow(f,new e(1).iushln(p-M-1));m=m.redMul(v),f=v.redSqr(),d=d.redMul(f),p=M}return m},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new e(1).toRed(this);if(0===i.cmpn(1))return t.clone();var r=new Array(16);r[0]=new e(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var h=r[0],o=0,s=0,u=i.bitLength()%26;for(0===u&&(u=26),n=i.length-1;n>=0;n--){for(var a=i.words[n],l=u-1;l>=0;l--){var f=a>>l&1;h!==r[0]&&(h=this.sqr(h)),0!==f||0!==o?(o<<=1,o|=f,(4==++s||0===n&&0===l)&&(h=this.mul(h,r[o]),s=0,o=0)):s=0}u=26}return h},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},e.mont=function(t){return new x(t)},n(x,_),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},x.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(i),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=r.isub(n).iushrn(this.shift),h=e;return e.cmp(this.m)>=0?h=e.isub(this.m):e.cmpn(0)<0&&(h=e.iadd(this.m)),h._forceRed(this)},x.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new e(0)._forceRed(this);var r=t.mul(i),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=r.isub(n).iushrn(this.shift),o=h;return h.cmp(this.m)>=0?o=h.isub(this.m):h.cmpn(0)<0&&(o=h.iadd(this.m)),o._forceRed(this)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(u,i.commonjsGlobal),exports.bn=u,exports.requireCore=e,exports.sha256=s;