essential-eth 0.9.2-beta.0 → 0.9.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/essential-eth.esm.mjs +1 -1
- package/dist/essential-eth.esm.mjs.map +1 -1
- package/dist/essential-eth.js +1 -1
- package/dist/essential-eth.js.map +1 -1
- package/dist/essential-eth.modern.mjs +1 -1
- package/dist/essential-eth.modern.mjs.map +1 -1
- package/dist/essential-eth.umd.js +1 -1
- package/dist/essential-eth.umd.js.map +1 -1
- package/dist/logger/package-version.d.ts +1 -1
- package/package.json +2 -1
- package/readme.md +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Keccak as r}from"sha3";import t from"big.js";import e from"isomorphic-unfetch";import{Point as n}from"@noble/secp256k1";import{Buffer as i}from"buffer";function o(){return o=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},o.apply(this,arguments)}function a(r,t){r.prototype=Object.create(t.prototype),r.prototype.constructor=r,s(r,t)}function s(r,t){return s=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r},s(r,t)}function u(r){return BigInt(r).toString()}function c(r){var t=r.startsWith("-");return(r=(r=(r=r.replace("-","")).replace(/\.0*$/g,"")).replace(/^0+/,"")).includes(".")&&(r=r.replace(/0+$/,"")),r.startsWith(".")&&(r="0"+r),(t?"-":"")+r}function l(r){if(!r.match(/e/i))return c(r);var t=r.split(/e/i),e=t[0],n=t[1],i=Number(e)<0,o=(e=c(e=e.replace("-",""))).split("."),a=o[0],s=o[1],u=void 0===s?"":s;if(0===Number(n))return(i?"-":"")+c(e);e.includes(".")||(e+=".");var l,h=(e=e.replace(".","")).length;return Number(n)<0?(a.length<Math.abs(Number(n))&&(e=e.padStart(h+Math.abs(Number(n))-a.length,"0")),l=e.split(""),a.length<Math.abs(Number(n))?l=["."].concat(l):l.splice(l.length-Math.abs(Number(n)),0,".")):(u.length<Math.abs(Number(n))&&(e=e.padEnd(h+Math.abs(Number(n))-u.length,"0")),l=e.split(""),u.length>Math.abs(Number(n))&&l.splice(l.length-Math.abs(Number(n)),0,".")),(i?"-":"")+c(l.join(""))}var h=/*#__PURE__*/function(r){function t(t){var e;return"string"==typeof t&&t.startsWith("0x")&&(t=u(t)),(e=r.call(this,t)||this).padAndChop=function(r,t,e){return(Array(e).fill(t).join("")+r).slice(-1*e)},e}a(t,r);var e=t.prototype;return e.toHexString=function(){return"0x"+BigInt(this.toString()).toString(16)},e.toNumber=function(){return Number(l(r.prototype.toString.call(this)))},e.toString=function(){return 0===this.toNumber()?"0":l(r.prototype.toString.call(this))},e.toTwos=function(r){var t;if(this.gte(0)){var e=this.toNumber().toString(2);t=this.padAndChop(e,"0",r||e.length)}else if(t=this.plus(Math.pow(2,r)).toNumber().toString(2),Number(t)<0)throw new Error("Cannot calculate twos complement");return f(Number("0b"+t))},t}(t);function f(r){return new h(r)}var g=function(r,t){if(!t.includes(typeof r))throw new Error(t.join(" or ")+" required. Received "+typeof r)};function m(t){if(g(t,["string"]),!/^(0x)?[0-9a-f]{40}$/i.test(t))throw new Error('Invalid Ethereum address "'+t+'"');for(var e=t.toLowerCase().replace(/^0x/i,""),n=new r(256).update(e).digest("hex").replace(/^0x/i,""),i="0x",o=0;o<e.length;o++)parseInt(n[o],16)>7?i+=e[o].toUpperCase():i+=e[o];if(t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&i!==t)throw new Error('Invalid Checksum address for "'+t+'"');return i}var v="0".repeat(64),p="0".repeat(63)+"1";function d(t,e){var n=new r(256),i=t.name+"("+t.inputs.map(function(r){return"uint[]"===(t=r.type)?"uint256[]":"int[]"===t?"int256[]":t;var t})+")",o=n.update(i).digest("hex"),a=t.inputs.length,s=!0;if(t.inputs.find(function(r){return r.type.includes("[")})&&(s=!1),s&&e.length!==a)throw new Error('args inputs of "'+e.length+'" does not match expected length of "'+t.inputs.length+'"');var u=(t.inputs||[]).reduce(function(r,t,n){if(t.type.includes("[")){var i,o=null==(i=/([^[]*)\[.*$/g.exec(t.type))?void 0:i[1];return e.forEach(function(t){r=r.concat([[t,o]])}),r}return r.concat([[e[n],t.type]])},[]).map(function(r){var t=r[0],e=r[1],n=t;switch(e){case"bool":return t?p:v;case"address":n=t.replace(/^0x/g,"").toLowerCase();break;default:if(e.startsWith("bytes"))return n.split("").map(function(r){return r.charCodeAt(0).toString(16)}).join("").padEnd(64,"0");if("uint256"===e)return BigInt(t).toString(16).padStart(64,"0");if(e.startsWith("uint"))break;throw new Error('essential-eth does not yet support "'+e+'" inputs. Make a PR today!"')}return n.toString(16).padStart(64,"0")});return"0x"+o.slice(0,8)+u.join("")}function y(r,t){var e,n=r.outputs,i=t.slice(2);if(1===(null==r||null==(e=r.outputs)?void 0:e.length)&&"string"===r.outputs[0].type){var o=[i.slice(0,64),i.slice(64)],a=o[1],s=Number(u("0x"+o[0])),c=a.slice(0,2*s),l=Number(u("0x"+c));return function(r){var t="",e=0,n=r.length;for("0x"===r.substring(0,2)&&(e=2);e<n;e+=2){var i=parseInt(r.substr(e,2),16);0!==i&&(t+=String.fromCharCode(i))}try{return decodeURIComponent(escape(t))}catch(r){return t}}(a.slice(2*s,2*s+2*l))}var h=(i.match(/.{1,64}/g)||[]).map(function(r,t){var e=(n||[])[t].type;switch(e){case"bool":return r===p;case"address":return m("0x"+r.slice(24));case"uint256":case"uint120":return f(u("0x"+r));case"bytes32":return"0x"+r;case"uint8":return Number(u("0x"+r));default:throw new Error('essential-eth does not yet support "'+e+'" outputs. Make a PR today!"')}});return 1===h.length?h[0]:h}function b(r){r.split("").reduce(function(r,t){return r+("0"===t?4:68)},0)}var P=function(r,t,e){var n=this,i=this;this._address=void 0,this._provider=void 0,this._address=r,this._provider=e,t.filter(function(r){return"function"===r.type}).forEach(function(r){var t;"name"in r&&"string"==typeof r.name&&(t=function(){try{var t=arguments,e=[].slice.call(t),n=e,a={},s=e[e.length-1];Array.isArray(s)||"object"!=typeof s||(a=s,n=e.slice(0,e.length-1));var u=d(r,n),c="number"==typeof a.gasLimit?a.gasLimit:"number"==typeof(null==r?void 0:r.gas)?b(u):null,l=function(){try{return Promise.resolve(i._provider.call(o({to:i._address.toLowerCase(),data:u},c?{gas:"0x"+c.toString(16)}:{}),"latest"))}catch(r){return Promise.reject(r)}};return Promise.resolve(l()).then(function(t){return y(r,t)})}catch(r){return Promise.reject(r)}},Object.defineProperty(n,r.name,{enumerable:!0,value:t,writable:!1}))})},x=/*#__PURE__*/function(r){function t(){return r.apply(this,arguments)||this}return a(t,r),t}(P);function w(r){var t=o({},r);return Object.keys(r).forEach(function(e){if(r[e])switch(e){case"blockNumber":case"chainId":case"transactionIndex":case"type":case"v":t[e]=Number(u(r[e]));break;case"from":case"to":r[e]&&(t[e]=m(r[e]));break;case"value":case"gas":case"gasPrice":case"maxFeePerGas":case"maxPriorityFeePerGas":case"nonce":t[e]=f(u(r[e]))}}),t}function E(r,t){var e=o({},r);return Object.keys(r).forEach(function(n){switch(n){case"address":e[n]=m(r[n]);break;case"blockNumber":case"logIndex":case"transactionIndex":e[n]=Number(u(r[n]));break;case"removed":t&&delete e[n]}}),e}function A(r,t){return{jsonrpc:"2.0",id:1,method:r,params:t}}var k=new(/*#__PURE__*/function(){function r(){this.packageVersion=void 0,this.packageVersion="0.9.2-beta.0"}var t=r.prototype;return t.throwError=function(r,t){var e=Object.keys(t).length;throw new Error(r+" ("+Object.entries(t).map(function(r,t){return r[0]+"="+r[1]+(t<e-1&&", ")})+", version=essential-eth@"+this.packageVersion+")")},t.throwArgumentError=function(r,t,e){throw new Error(r+' (argument="'+t+'" value='+e+", version=essential-eth@"+this.packageVersion+")")},t.checkSafeUint53=function(r,t){void 0===t&&(t="value not safe"),"number"==typeof r&&((r<0||r>=9007199254740991)&&this.throwError(t,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:r}),r%1&&this.throwError(t,{operation:"checkSafeInteger",fault:"non-integer",value:r}))},r}());function _(r){return!!r.toHexString}function S(r){return B(r)&&!(r.length%2)||j(r)}function N(r){return"number"==typeof r&&r==r&&r%1==0}function j(r){if(null==r)return!1;if(r.constructor===Uint8Array)return!0;if("string"==typeof r)return!1;if(!N(r.length)||r.length<0)return!1;for(var t=0;t<r.length;t++){var e=r[t];if(!N(e)||e<0||e>=256)return!1}return!0}function U(r,t){if(t||(t={}),"number"==typeof r){k.checkSafeUint53(r,"invalid arrayify value");for(var e=[];r;)e.unshift(255&r),r=parseInt(String(r/256));return 0===e.length&&e.push(0),new Uint8Array(e)}if(t.allowMissingPrefix&&"string"==typeof r&&"0x"!==r.substring(0,2)&&(r="0x"+r),_(r)&&(r=r.toHexString()),B(r)){var n=r.substring(2);n.length%2&&("left"===t.hexPad?n="0"+n:"right"===t.hexPad?n+="0":k.throwArgumentError("hex data is odd-length","value",r));for(var i=[],o=0;o<n.length;o+=2)i.push(parseInt(n.substring(o,o+2),16));return new Uint8Array(i)}return j(r)?new Uint8Array(r):k.throwArgumentError("invalid arrayify value","value",r)}function G(r){var t=r.map(function(r){return U(r)}),e=t.reduce(function(r,t){return r+t.length},0),n=new Uint8Array(e);return t.reduce(function(r,t){return n.set(t,r),r+t.length},0),n}function F(r){var t=U(r);if(0===t.length)return t;for(var e=0;e<t.length&&0===t[e];)e++;return e&&(t=t.slice(e)),t}function C(r,t){(r=U(r)).length>t&&k.throwArgumentError("value out of range","value",r);var e=new Uint8Array(t);return e.set(r,t-r.length),e}function B(r,t){return!("string"!=typeof r||!r.match(/^0x[0-9A-Fa-f]*$/)||t&&r.length!==2+2*t)}function I(r,t){if(t||(t={}),"number"==typeof r){k.checkSafeUint53(r,"invalid hexlify value");for(var e="";r;)e="0123456789abcdef"[15&r]+e,r=Math.floor(r/16);return e.length?(e.length%2&&(e="0"+e),"0x"+e):"0x00"}if("bigint"==typeof r)return(r=r.toString(16)).length%2?"0x0"+r:"0x"+r;if(t.allowMissingPrefix&&"string"==typeof r&&"0x"!==r.substring(0,2)&&(r="0x"+r),_(r))return r.toHexString();if(B(r))return r.length%2&&("left"===t.hexPad?r="0x0"+r.substring(2):"right"===t.hexPad?r+="0":k.throwArgumentError("hex data is odd-length","value",r)),r.toLowerCase();if(j(r)){for(var n="0x",i=0;i<r.length;i++){var o=r[i];n+="0123456789abcdef"[(240&o)>>4]+"0123456789abcdef"[15&o]}return n}return k.throwArgumentError("invalid hexlify value","value",r)}function O(r){if("string"!=typeof r)r=I(r);else if(!B(r)||r.length%2)return null;return(r.length-2)/2}function M(r,t,e){return"string"!=typeof r?r=I(r):(!B(r)||r.length%2)&&k.throwArgumentError("invalid hexData","value",r),t=2+2*t,null!=e?"0x"+r.substring(t,2+2*e):"0x"+r.substring(t)}function R(r){var t="0x";return r.forEach(function(r){t+=I(r).substring(2)}),t}function T(r){var t=L(I(r,{hexPad:"left"}));return"0x"===t?"0x0":t}function L(r){"string"!=typeof r&&(r=I(r)),B(r)||k.throwArgumentError("invalid hex string","value",r),r=r.substring(2);for(var t=0;t<r.length&&"0"===r[t];)t++;return"0x"+r.substring(t)}function H(r,t){for("string"!=typeof r?r=I(r):B(r)||k.throwArgumentError("invalid hex string","value",r),r.length>2*t+2&&k.throwError("value out of range",{value:r,length:t});r.length<2*t+2;)r="0x0"+r.substring(2);return r}function $(r){var e=o({},r);return Object.keys(r).forEach(function(n){switch(n){case"gas":case"gasPrice":case"nonce":case"maxFeePerGas":case"maxPriorityFeePerGas":case"value":var i=r[n];e[n]=i instanceof h?i.toHexString():i instanceof t?"0x"+BigInt(i.toString()).toString(16):"number"==typeof r[n]?"0x"+r[n].toString(16):r[n].toString();break;case"data":e[n]=I(r[n])}}),e}var W={1:["eth","0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"],5:["gor","0x112234455c3a32fd11230c42e7bccd4a84e02010"],10:["oeth"],50:["xdc"],56:["bnb"],100:["gno"],137:["matic"],250:["ftm"],324:["zksync"],1101:["zkevm"],1337:["geth"],7700:["canto"],9001:["evmos"],42161:["arb1"],42220:["celo"],43114:["avax"],59140:["linea-testnet"],80001:["maticmum"],421613:["arb-goerli"],534352:["scr"],11155111:["sep"]};function D(r){return"number"==typeof r?f(r).toHexString():r}var J=/*#__PURE__*/function(){function r(r){var t=this;this._rpcUrls=[],this._post=function(r){return function(r,t){return e(r,function(r){return{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}}(t)).then(function(r){try{return Promise.resolve(r.text()).then(function(r){try{return JSON.parse(r)}catch(t){throw new Error('Invalid JSON RPC response: "'+r+'"')}})}catch(r){return Promise.reject(r)}}).then(function(r){if(!(null==r?void 0:r.result))throw new Error("Invalid JSON RPC response: "+JSON.stringify(r));return r.result})}(t.selectRpcUrl(),r)},this._rpcUrls=r}var t=r.prototype;return t.getNetwork=function(){try{return Promise.resolve(this.post(A("eth_chainId",[]))).then(function(r){var t=u(r),e=W[t];return{chainId:Number(t),name:e[0]||"unknown",ensAddress:e[1]||null}})}catch(r){return Promise.reject(r)}},t.getBlockNumber=function(){try{return Promise.resolve(this.post(A("eth_blockNumber",[]))).then(function(r){return Number(u(r))})}catch(r){return Promise.reject(r)}},t.getTransaction=function(r){try{return Promise.resolve(Promise.all([this.post(A("eth_getTransactionByHash",[r])),this.getBlock("latest")])).then(function(r){var t=r[1],e=w(r[0]);return e.confirmations=t.number-e.blockNumber+1,e})}catch(r){return Promise.reject(r)}},t.getTransactionReceipt=function(r){try{return Promise.resolve(Promise.all([this.post(A("eth_getTransactionReceipt",[r])),this.getBlock("latest")])).then(function(r){var t=r[1],e=function(r){var t=o({},w(r));return Object.keys(r).forEach(function(e){if(r[e])switch(e){case"status":t[e]=Number(u(r[e]));break;case"contractAddress":r[e]&&(t[e]=m(r[e]));break;case"cumulativeGasUsed":case"effectiveGasPrice":case"gasUsed":t[e]=f(u(r[e]));break;case"logs":r[e].forEach(function(r,n){t[e][n]=E(r,!0)})}}),t.byzantium=t.blockNumber>=437e4,t}(r[0]);return e.confirmations=t.number-e.blockNumber+1,e})}catch(r){return Promise.reject(r)}},t.getTransactionCount=function(r,t){void 0===t&&(t="latest");try{return t=D(t),Promise.resolve(this.post(A("eth_getTransactionCount",[r,t]))).then(function(r){return Number(u(r))})}catch(r){return Promise.reject(r)}},t.getBlock=function(r,t){void 0===r&&(r="latest"),void 0===t&&(t=!1);try{var e="Number";return"string"==typeof r&&66===r.length?e="Hash":r=D(r),Promise.resolve(this.post(A("eth_getBlockBy"+e,[r,t]))).then(function(r){return function(r,t){var e=o({},r);return Object.keys(r).forEach(function(t){if(r[t])switch(t){case"difficulty":case"totalDifficulty":case"gasLimit":case"gasUsed":case"size":case"timestamp":case"baseFeePerGas":e[t]=f(u(r[t]));break;case"number":e[t]=Number(u(r[t]));break;case"miner":e[t]=m(r[t])}}),t&&r.transactions.forEach(function(r,t){e.transactions[t]=w(r)}),e}(r,t)})}catch(r){return Promise.reject(r)}},t.getGasPrice=function(){try{return Promise.resolve(this.post(A("eth_gasPrice",[]))).then(function(r){return f(u(r))})}catch(r){return Promise.reject(r)}},t.getBalance=function(r,t){void 0===t&&(t="latest");try{return t=D(t),Promise.resolve(this.post(A("eth_getBalance",[r,t]))).then(function(r){return f(u(r))})}catch(r){return Promise.reject(r)}},t.getCode=function(r,t){void 0===t&&(t="latest");try{return t=D(t),Promise.resolve(this.post(A("eth_getCode",[r,t])))}catch(r){return Promise.reject(r)}},t.estimateGas=function(r){try{var t=$(r);return Promise.resolve(this.post(A("eth_estimateGas",[t]))).then(function(r){return f(u(r))})}catch(r){return Promise.reject(r)}},t.getFeeData=function(){try{return Promise.resolve(Promise.all([this.getBlock("latest"),this.getGasPrice()])).then(function(r){var t=r[0],e=r[1],n=null,i=null,o=null;return t&&t.baseFeePerGas&&(n=t.baseFeePerGas,o=f("1500000000"),i=f(t.baseFeePerGas.mul(2).add(o))),{lastBaseFeePerGas:n,maxFeePerGas:i,maxPriorityFeePerGas:o,gasPrice:e}})}catch(r){return Promise.reject(r)}},t.getLogs=function(r){try{var t=r;return t.fromBlock&&(t.fromBlock=D(t.fromBlock)),t.toBlock&&(t.toBlock=D(t.toBlock)),Promise.resolve(this.post(A("eth_getLogs",[r]))).then(function(r){return r.map(function(r){return E(r,!1)})})}catch(r){return Promise.reject(r)}},t.call=function(r,t){void 0===t&&(t="latest");try{r.gasPrice&&(r.maxPriorityFeePerGas||r.maxFeePerGas)&&k.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")',{gasPrice:r.gasPrice,maxFeePerGas:r.maxFeePerGas,maxPriorityFeePerGas:r.maxPriorityFeePerGas}),r.maxFeePerGas&&r.maxPriorityFeePerGas&&k.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"',{maxFeePerGas:r.maxFeePerGas,maxPriorityFeePerGas:r.maxPriorityFeePerGas}),t=D(t);var e=$(r);return Promise.resolve(this.post(A("eth_call",[e,t])))}catch(r){return Promise.reject(r)}},r}(),z=/*#__PURE__*/function(r){a(e,r);var t=e.prototype;function e(t){return void 0===t&&(t="https://free-eth-node.com/api/eth"),r.call(this,[t])||this}return t.selectRpcUrl=function(){return this._rpcUrls[0]},t.post=function(r){return this._post(r)},e}(J);function V(r){return new z(r)}var q=/*#__PURE__*/function(r){function t(t,e){return void 0===e&&(e="mainnet"),r.call(this,"https://eth-"+e+".alchemyapi.io/v2/"+t)||this}return a(t,r),t}(z),K=/*#__PURE__*/function(r){function t(t,e){var n;return void 0===e&&(e={}),Array.isArray(t)||k.throwError("Array required",{rpcUrls:t}),t.length<=1&&k.throwError("More than one rpcUrl is required",{rpcUrls:t}),(n=r.call(this,t)||this).rpcUrlCounter=0,n.timeoutDuration=void 0,n.post=function(r){var t=n.rpcUrlCounter;return function e(){var i,o,a=n.selectRpcUrl();return(i=n._post(r),o=n.timeoutDuration,new Promise(function(r,t){var e=setTimeout(function(){return t(new Error("Promise timed out"))},o);i.then(function(t){clearTimeout(e),r(t)}).catch(function(r){clearTimeout(e),t(r)})})).catch(function(r){if(a===n.selectRpcUrl()&&(n.rpcUrlCounter=(n.rpcUrlCounter+1)%n._rpcUrls.length),n.rpcUrlCounter===t)throw r;return e()})}()},n.timeoutDuration=e.timeoutDuration||8e3,n}return a(t,r),t.prototype.selectRpcUrl=function(){return this._rpcUrls[this.rpcUrlCounter]},t}(J);function Q(r){return r=I(r).slice(2),"0x"+n.fromPrivateKey(r).toHex()}function X(t){var e;return e="string"==typeof t?Buffer.from(t.replace(/^0x/,""),"hex"):Buffer.from(t),"0x"+new r(256).update(e).digest("hex")}function Y(r){return r.startsWith("0x04")||r.startsWith("0x03")||r.startsWith("0x02")||(r=Q(r)),m(M(X(M(r,1)),12))}function Z(r){g(r,["string","number","object"]);var t=f(r).times("1000000000");return f(t)}function rr(r){g(r,["string","number","object"]);var t=f(r).times("1000000000000000000");return f(t)}function tr(r){g(r,["string","number","object"]);var t=f(r).div("1000000000");return f(t)}function er(r){return new Uint8Array(Buffer.from(r))}function nr(r){return"string"==typeof r&&(r=er(r)),X(G([er("Ethereum Signed Message:\n"),er(String(r.length)),r]))}function ir(r){g(r,["string"]);try{return m(r),!0}catch(r){return!1}}function or(r){var t={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(S(r)){var e=U(r);64===e.length?(t.v=27+(e[32]>>7),e[32]&=127,t.r=I(e.slice(0,32)),t.s=I(e.slice(32,64))):65===e.length?(t.r=I(e.slice(0,32)),t.s=I(e.slice(32,64)),t.v=e[64]):k.throwArgumentError("invalid signature string","signature",r),t.v<27&&(0===t.v||1===t.v?t.v+=27:k.throwArgumentError("signature invalid v byte","signature",r)),t.recoveryParam=1-t.v%2,t.recoveryParam&&(e[32]|=128),t._vs=I(e.slice(32,64))}else{if(t.r=r.r,t.s=r.s,t.v=r.v,t.recoveryParam=r.recoveryParam,t._vs=r._vs,null!=t._vs){var n=C(U(t._vs),32);t._vs=I(n);var i=n[0]>=128?1:0;null==t.recoveryParam?t.recoveryParam=i:t.recoveryParam!==i&&k.throwArgumentError("signature recoveryParam mismatch _vs","signature",r),n[0]&=127;var o=I(n);null==t.s?t.s=o:t.s!==o&&k.throwArgumentError("signature v mismatch _vs","signature",r)}null==t.recoveryParam?null==t.v?k.throwArgumentError("signature missing v and recoveryParam","signature",r):t.recoveryParam=0===t.v||1===t.v?t.v:1-t.v%2:null==t.v?t.v=27+t.recoveryParam:t.recoveryParam!==(0===t.v||1===t.v?t.v:1-t.v%2)&&k.throwArgumentError("signature recoveryParam mismatch v","signature",r),null!=t.r&&B(t.r)?t.r=H(t.r,32):k.throwArgumentError("signature missing or invalid r","signature",r),null!=t.s&&B(t.s)?t.s=H(t.s,32):k.throwArgumentError("signature missing or invalid s","signature",r);var a=U(t.s);a[0]>=128&&k.throwArgumentError("signature s out of range","signature",r),t.recoveryParam&&(a[0]|=128);var s=I(a);t._vs&&(B(t._vs)||k.throwArgumentError("signature invalid _vs","signature",r),t._vs=H(t._vs,32)),null==t._vs?t._vs=s:t._vs!==s&&k.throwArgumentError("signature _vs mismatch v and s","signature",r)}return t.yParityAndS=t._vs,t.compact=t.r+t.yParityAndS.substring(2),t}function ar(r){g(r,["string","number","object"]);try{var t=r;"string"==typeof r&&"0x"===r.slice(0,2)&&(t=BigInt(r).toString());var e=f(t).div("1000000000000000000");return f(e)}catch(r){throw r}}var sr=new RegExp("^bytes([0-9]+)$"),ur=new RegExp("^(u?int)([0-9]*)$"),cr=new RegExp("^(.*)\\[([0-9]*)\\]$");function lr(r,t,e){switch(r){case"address":return e?C(t,32):U(t);case"string":return i.from(t);case"bytes":return U(t);case"bool":return t=t?"0x01":"0x00",e?C(t,32):U(t)}var n=r.match(ur);if(n){var o=parseInt(n[2]||"256");return(n[2]&&String(o)!==n[2]||o%8!=0||0===o||o>256)&&k.throwArgumentError("invalid number type","type",r),e&&(o=256),C(I(t=f(t).toTwos(o).toNumber()),o/8)}if(n=r.match(sr)){var a=parseInt(n[1]);return(String(a)!==n[1]||0===a||a>32)&&k.throwArgumentError("invalid bytes type","type",r),U(t).byteLength!==a&&k.throwArgumentError("invalid value for "+r,"value",t),e?U((t+v).substring(0,66)):t}if((n=r.match(cr))&&Array.isArray(t)){var s=n[1];parseInt(n[2]||String(t.length))!=t.length&&k.throwArgumentError("invalid array length for "+r,"value",t);var u=[];return t.forEach(function(r){u.push(lr(s,r,!0))}),G(u)}return k.throwArgumentError("invalid type","type",r)}function hr(r,t){r.length!=t.length&&k.throwArgumentError("wrong number of values; expected ${ types.length }","values",t);var e=[];return r.forEach(function(r,n){e.push(lr(r,t[n]))}),I(G(e))}function fr(r,t){return X(hr(r,t))}export{q as AlchemyProvider,P as BaseContract,x as Contract,K as FallthroughProvider,z as JsonRpcProvider,h as TinyBig,U as arrayify,Y as computeAddress,Q as computePublicKey,G as concat,Z as etherToGwei,rr as etherToWei,tr as gweiToEther,nr as hashMessage,R as hexConcat,O as hexDataLength,M as hexDataSlice,L as hexStripZeros,T as hexValue,H as hexZeroPad,I as hexlify,ir as isAddress,j as isBytes,S as isBytesLike,B as isHexString,V as jsonRpcProvider,X as keccak256,hr as pack,fr as solidityKeccak256,or as splitSignature,F as stripZeros,f as tinyBig,m as toChecksumAddress,er as toUtf8Bytes,ar as weiToEther,C as zeroPad};
|
|
1
|
+
import{Keccak as r}from"sha3";import t from"big.js";import e from"isomorphic-unfetch";import{Point as n}from"@noble/secp256k1";import{Buffer as i}from"buffer";function o(){return o=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},o.apply(this,arguments)}function a(r,t){r.prototype=Object.create(t.prototype),r.prototype.constructor=r,s(r,t)}function s(r,t){return s=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r},s(r,t)}function u(r){return BigInt(r).toString()}function c(r){var t=r.startsWith("-");return(r=(r=(r=r.replace("-","")).replace(/\.0*$/g,"")).replace(/^0+/,"")).includes(".")&&(r=r.replace(/0+$/,"")),r.startsWith(".")&&(r="0"+r),(t?"-":"")+r}function l(r){if(!r.match(/e/i))return c(r);var t=r.split(/e/i),e=t[0],n=t[1],i=Number(e)<0,o=(e=c(e=e.replace("-",""))).split("."),a=o[0],s=o[1],u=void 0===s?"":s;if(0===Number(n))return(i?"-":"")+c(e);e.includes(".")||(e+=".");var l,h=(e=e.replace(".","")).length;return Number(n)<0?(a.length<Math.abs(Number(n))&&(e=e.padStart(h+Math.abs(Number(n))-a.length,"0")),l=e.split(""),a.length<Math.abs(Number(n))?l=["."].concat(l):l.splice(l.length-Math.abs(Number(n)),0,".")):(u.length<Math.abs(Number(n))&&(e=e.padEnd(h+Math.abs(Number(n))-u.length,"0")),l=e.split(""),u.length>Math.abs(Number(n))&&l.splice(l.length-Math.abs(Number(n)),0,".")),(i?"-":"")+c(l.join(""))}var h=/*#__PURE__*/function(r){function t(t){var e;return"string"==typeof t&&t.startsWith("0x")&&(t=u(t)),(e=r.call(this,t)||this).padAndChop=function(r,t,e){return(Array(e).fill(t).join("")+r).slice(-1*e)},e}a(t,r);var e=t.prototype;return e.toHexString=function(){return"0x"+BigInt(this.toString()).toString(16)},e.toNumber=function(){return Number(l(r.prototype.toString.call(this)))},e.toString=function(){return 0===this.toNumber()?"0":l(r.prototype.toString.call(this))},e.toTwos=function(r){var t;if(this.gte(0)){var e=this.toNumber().toString(2);t=this.padAndChop(e,"0",r||e.length)}else if(t=this.plus(Math.pow(2,r)).toNumber().toString(2),Number(t)<0)throw new Error("Cannot calculate twos complement");return f(Number("0b"+t))},t}(t);function f(r){return new h(r)}var g=function(r,t){if(!t.includes(typeof r))throw new Error(t.join(" or ")+" required. Received "+typeof r)};function m(t){if(g(t,["string"]),!/^(0x)?[0-9a-f]{40}$/i.test(t))throw new Error('Invalid Ethereum address "'+t+'"');for(var e=t.toLowerCase().replace(/^0x/i,""),n=new r(256).update(e).digest("hex").replace(/^0x/i,""),i="0x",o=0;o<e.length;o++)parseInt(n[o],16)>7?i+=e[o].toUpperCase():i+=e[o];if(t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&i!==t)throw new Error('Invalid Checksum address for "'+t+'"');return i}var v="0".repeat(64),p="0".repeat(63)+"1";function d(t,e){var n=new r(256),i=t.name+"("+t.inputs.map(function(r){return"uint[]"===(t=r.type)?"uint256[]":"int[]"===t?"int256[]":t;var t})+")",o=n.update(i).digest("hex"),a=t.inputs.length,s=!0;if(t.inputs.find(function(r){return r.type.includes("[")})&&(s=!1),s&&e.length!==a)throw new Error('args inputs of "'+e.length+'" does not match expected length of "'+t.inputs.length+'"');var u=(t.inputs||[]).reduce(function(r,t,n){if(t.type.includes("[")){var i,o=null==(i=/([^[]*)\[.*$/g.exec(t.type))?void 0:i[1];return e.forEach(function(t){r=r.concat([[t,o]])}),r}return r.concat([[e[n],t.type]])},[]).map(function(r){var t=r[0],e=r[1],n=t;switch(e){case"bool":return t?p:v;case"address":n=t.replace(/^0x/g,"").toLowerCase();break;default:if(e.startsWith("bytes"))return n.split("").map(function(r){return r.charCodeAt(0).toString(16)}).join("").padEnd(64,"0");if("uint256"===e)return BigInt(t).toString(16).padStart(64,"0");if(e.startsWith("uint"))break;throw new Error('essential-eth does not yet support "'+e+'" inputs. Make a PR today!"')}return n.toString(16).padStart(64,"0")});return"0x"+o.slice(0,8)+u.join("")}function y(r,t){var e,n=r.outputs,i=t.slice(2);if(1===(null==r||null==(e=r.outputs)?void 0:e.length)&&"string"===r.outputs[0].type){var o=[i.slice(0,64),i.slice(64)],a=o[1],s=Number(u("0x"+o[0])),c=a.slice(0,2*s),l=Number(u("0x"+c));return function(r){var t="",e=0,n=r.length;for("0x"===r.substring(0,2)&&(e=2);e<n;e+=2){var i=parseInt(r.substr(e,2),16);0!==i&&(t+=String.fromCharCode(i))}try{return decodeURIComponent(escape(t))}catch(r){return t}}(a.slice(2*s,2*s+2*l))}var h=(i.match(/.{1,64}/g)||[]).map(function(r,t){var e=(n||[])[t].type;switch(e){case"bool":return r===p;case"address":return m("0x"+r.slice(24));case"uint256":case"uint120":return f(u("0x"+r));case"bytes32":return"0x"+r;case"uint8":return Number(u("0x"+r));default:throw new Error('essential-eth does not yet support "'+e+'" outputs. Make a PR today!"')}});return 1===h.length?h[0]:h}function b(r){r.split("").reduce(function(r,t){return r+("0"===t?4:68)},0)}var P=function(r,t,e){var n=this,i=this;this._address=void 0,this._provider=void 0,this._address=r,this._provider=e,t.filter(function(r){return"function"===r.type}).forEach(function(r){var t;"name"in r&&"string"==typeof r.name&&(t=function(){try{var t=arguments,e=[].slice.call(t),n=e,a={},s=e[e.length-1];Array.isArray(s)||"object"!=typeof s||(a=s,n=e.slice(0,e.length-1));var u=d(r,n),c="number"==typeof a.gasLimit?a.gasLimit:"number"==typeof(null==r?void 0:r.gas)?b(u):null,l=function(){try{return Promise.resolve(i._provider.call(o({to:i._address.toLowerCase(),data:u},c?{gas:"0x"+c.toString(16)}:{}),"latest"))}catch(r){return Promise.reject(r)}};return Promise.resolve(l()).then(function(t){return y(r,t)})}catch(r){return Promise.reject(r)}},Object.defineProperty(n,r.name,{enumerable:!0,value:t,writable:!1}))})},x=/*#__PURE__*/function(r){function t(){return r.apply(this,arguments)||this}return a(t,r),t}(P);function w(r){var t=o({},r);return Object.keys(r).forEach(function(e){if(r[e])switch(e){case"blockNumber":case"chainId":case"transactionIndex":case"type":case"v":t[e]=Number(u(r[e]));break;case"from":case"to":r[e]&&(t[e]=m(r[e]));break;case"value":case"gas":case"gasPrice":case"maxFeePerGas":case"maxPriorityFeePerGas":case"nonce":t[e]=f(u(r[e]))}}),t}function E(r,t){var e=o({},r);return Object.keys(r).forEach(function(n){switch(n){case"address":e[n]=m(r[n]);break;case"blockNumber":case"logIndex":case"transactionIndex":e[n]=Number(u(r[n]));break;case"removed":t&&delete e[n]}}),e}function A(r,t){return{jsonrpc:"2.0",id:1,method:r,params:t}}var k=new(/*#__PURE__*/function(){function r(){this.packageVersion=void 0,this.packageVersion="0.9.2-beta.1"}var t=r.prototype;return t.throwError=function(r,t){var e=Object.keys(t).length;throw new Error(r+" ("+Object.entries(t).map(function(r,t){return r[0]+"="+r[1]+(t<e-1&&", ")})+", version=essential-eth@"+this.packageVersion+")")},t.throwArgumentError=function(r,t,e){throw new Error(r+' (argument="'+t+'" value='+e+", version=essential-eth@"+this.packageVersion+")")},t.checkSafeUint53=function(r,t){void 0===t&&(t="value not safe"),"number"==typeof r&&((r<0||r>=9007199254740991)&&this.throwError(t,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:r}),r%1&&this.throwError(t,{operation:"checkSafeInteger",fault:"non-integer",value:r}))},r}());function _(r){return!!r.toHexString}function S(r){return B(r)&&!(r.length%2)||j(r)}function N(r){return"number"==typeof r&&r==r&&r%1==0}function j(r){if(null==r)return!1;if(r.constructor===Uint8Array)return!0;if("string"==typeof r)return!1;if(!N(r.length)||r.length<0)return!1;for(var t=0;t<r.length;t++){var e=r[t];if(!N(e)||e<0||e>=256)return!1}return!0}function U(r,t){if(t||(t={}),"number"==typeof r){k.checkSafeUint53(r,"invalid arrayify value");for(var e=[];r;)e.unshift(255&r),r=parseInt(String(r/256));return 0===e.length&&e.push(0),new Uint8Array(e)}if(t.allowMissingPrefix&&"string"==typeof r&&"0x"!==r.substring(0,2)&&(r="0x"+r),_(r)&&(r=r.toHexString()),B(r)){var n=r.substring(2);n.length%2&&("left"===t.hexPad?n="0"+n:"right"===t.hexPad?n+="0":k.throwArgumentError("hex data is odd-length","value",r));for(var i=[],o=0;o<n.length;o+=2)i.push(parseInt(n.substring(o,o+2),16));return new Uint8Array(i)}return j(r)?new Uint8Array(r):k.throwArgumentError("invalid arrayify value","value",r)}function G(r){var t=r.map(function(r){return U(r)}),e=t.reduce(function(r,t){return r+t.length},0),n=new Uint8Array(e);return t.reduce(function(r,t){return n.set(t,r),r+t.length},0),n}function F(r){var t=U(r);if(0===t.length)return t;for(var e=0;e<t.length&&0===t[e];)e++;return e&&(t=t.slice(e)),t}function C(r,t){(r=U(r)).length>t&&k.throwArgumentError("value out of range","value",r);var e=new Uint8Array(t);return e.set(r,t-r.length),e}function B(r,t){return!("string"!=typeof r||!r.match(/^0x[0-9A-Fa-f]*$/)||t&&r.length!==2+2*t)}function I(r,t){if(t||(t={}),"number"==typeof r){k.checkSafeUint53(r,"invalid hexlify value");for(var e="";r;)e="0123456789abcdef"[15&r]+e,r=Math.floor(r/16);return e.length?(e.length%2&&(e="0"+e),"0x"+e):"0x00"}if("bigint"==typeof r)return(r=r.toString(16)).length%2?"0x0"+r:"0x"+r;if(t.allowMissingPrefix&&"string"==typeof r&&"0x"!==r.substring(0,2)&&(r="0x"+r),_(r))return r.toHexString();if(B(r))return r.length%2&&("left"===t.hexPad?r="0x0"+r.substring(2):"right"===t.hexPad?r+="0":k.throwArgumentError("hex data is odd-length","value",r)),r.toLowerCase();if(j(r)){for(var n="0x",i=0;i<r.length;i++){var o=r[i];n+="0123456789abcdef"[(240&o)>>4]+"0123456789abcdef"[15&o]}return n}return k.throwArgumentError("invalid hexlify value","value",r)}function O(r){if("string"!=typeof r)r=I(r);else if(!B(r)||r.length%2)return null;return(r.length-2)/2}function M(r,t,e){return"string"!=typeof r?r=I(r):(!B(r)||r.length%2)&&k.throwArgumentError("invalid hexData","value",r),t=2+2*t,null!=e?"0x"+r.substring(t,2+2*e):"0x"+r.substring(t)}function R(r){var t="0x";return r.forEach(function(r){t+=I(r).substring(2)}),t}function T(r){var t=L(I(r,{hexPad:"left"}));return"0x"===t?"0x0":t}function L(r){"string"!=typeof r&&(r=I(r)),B(r)||k.throwArgumentError("invalid hex string","value",r),r=r.substring(2);for(var t=0;t<r.length&&"0"===r[t];)t++;return"0x"+r.substring(t)}function H(r,t){for("string"!=typeof r?r=I(r):B(r)||k.throwArgumentError("invalid hex string","value",r),r.length>2*t+2&&k.throwError("value out of range",{value:r,length:t});r.length<2*t+2;)r="0x0"+r.substring(2);return r}function $(r){var e=o({},r);return Object.keys(r).forEach(function(n){switch(n){case"gas":case"gasPrice":case"nonce":case"maxFeePerGas":case"maxPriorityFeePerGas":case"value":var i=r[n];e[n]=i instanceof h?i.toHexString():i instanceof t?"0x"+BigInt(i.toString()).toString(16):"number"==typeof r[n]?"0x"+r[n].toString(16):r[n].toString();break;case"data":e[n]=I(r[n])}}),e}var W={1:["eth","0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"],5:["gor","0x112234455c3a32fd11230c42e7bccd4a84e02010"],10:["oeth"],50:["xdc"],56:["bnb"],100:["gno"],137:["matic"],250:["ftm"],324:["zksync"],1101:["zkevm"],1337:["geth"],7700:["canto"],9001:["evmos"],42161:["arb1"],42220:["celo"],43114:["avax"],59140:["linea-testnet"],80001:["maticmum"],421613:["arb-goerli"],534352:["scr"],11155111:["sep"]};function D(r){return"number"==typeof r?f(r).toHexString():r}var J=/*#__PURE__*/function(){function r(r){var t=this;this._rpcUrls=[],this._post=function(r){return function(r,t){return e(r,function(r){return{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}}(t)).then(function(r){try{return Promise.resolve(r.text()).then(function(r){try{return JSON.parse(r)}catch(t){throw new Error('Invalid JSON RPC response: "'+r+'"')}})}catch(r){return Promise.reject(r)}}).then(function(r){if(!(null==r?void 0:r.result))throw new Error("Invalid JSON RPC response: "+JSON.stringify(r));return r.result})}(t.selectRpcUrl(),r)},this._rpcUrls=r}var t=r.prototype;return t.getNetwork=function(){try{return Promise.resolve(this.post(A("eth_chainId",[]))).then(function(r){var t=u(r),e=W[t];return{chainId:Number(t),name:e[0]||"unknown",ensAddress:e[1]||null}})}catch(r){return Promise.reject(r)}},t.getBlockNumber=function(){try{return Promise.resolve(this.post(A("eth_blockNumber",[]))).then(function(r){return Number(u(r))})}catch(r){return Promise.reject(r)}},t.getTransaction=function(r){try{return Promise.resolve(Promise.all([this.post(A("eth_getTransactionByHash",[r])),this.getBlock("latest")])).then(function(r){var t=r[1],e=w(r[0]);return e.confirmations=t.number-e.blockNumber+1,e})}catch(r){return Promise.reject(r)}},t.getTransactionReceipt=function(r){try{return Promise.resolve(Promise.all([this.post(A("eth_getTransactionReceipt",[r])),this.getBlock("latest")])).then(function(r){var t=r[1],e=function(r){var t=o({},w(r));return Object.keys(r).forEach(function(e){if(r[e])switch(e){case"status":t[e]=Number(u(r[e]));break;case"contractAddress":r[e]&&(t[e]=m(r[e]));break;case"cumulativeGasUsed":case"effectiveGasPrice":case"gasUsed":t[e]=f(u(r[e]));break;case"logs":r[e].forEach(function(r,n){t[e][n]=E(r,!0)})}}),t.byzantium=t.blockNumber>=437e4,t}(r[0]);return e.confirmations=t.number-e.blockNumber+1,e})}catch(r){return Promise.reject(r)}},t.getTransactionCount=function(r,t){void 0===t&&(t="latest");try{return t=D(t),Promise.resolve(this.post(A("eth_getTransactionCount",[r,t]))).then(function(r){return Number(u(r))})}catch(r){return Promise.reject(r)}},t.getBlock=function(r,t){void 0===r&&(r="latest"),void 0===t&&(t=!1);try{var e="Number";return"string"==typeof r&&66===r.length?e="Hash":r=D(r),Promise.resolve(this.post(A("eth_getBlockBy"+e,[r,t]))).then(function(r){return function(r,t){var e=o({},r);return Object.keys(r).forEach(function(t){if(r[t])switch(t){case"difficulty":case"totalDifficulty":case"gasLimit":case"gasUsed":case"size":case"timestamp":case"baseFeePerGas":e[t]=f(u(r[t]));break;case"number":e[t]=Number(u(r[t]));break;case"miner":e[t]=m(r[t])}}),t&&r.transactions.forEach(function(r,t){e.transactions[t]=w(r)}),e}(r,t)})}catch(r){return Promise.reject(r)}},t.getGasPrice=function(){try{return Promise.resolve(this.post(A("eth_gasPrice",[]))).then(function(r){return f(u(r))})}catch(r){return Promise.reject(r)}},t.getBalance=function(r,t){void 0===t&&(t="latest");try{return t=D(t),Promise.resolve(this.post(A("eth_getBalance",[r,t]))).then(function(r){return f(u(r))})}catch(r){return Promise.reject(r)}},t.getCode=function(r,t){void 0===t&&(t="latest");try{return t=D(t),Promise.resolve(this.post(A("eth_getCode",[r,t])))}catch(r){return Promise.reject(r)}},t.estimateGas=function(r){try{var t=$(r);return Promise.resolve(this.post(A("eth_estimateGas",[t]))).then(function(r){return f(u(r))})}catch(r){return Promise.reject(r)}},t.getFeeData=function(){try{return Promise.resolve(Promise.all([this.getBlock("latest"),this.getGasPrice()])).then(function(r){var t=r[0],e=r[1],n=null,i=null,o=null;return t&&t.baseFeePerGas&&(n=t.baseFeePerGas,o=f("1500000000"),i=f(t.baseFeePerGas.mul(2).add(o))),{lastBaseFeePerGas:n,maxFeePerGas:i,maxPriorityFeePerGas:o,gasPrice:e}})}catch(r){return Promise.reject(r)}},t.getLogs=function(r){try{var t=r;return t.fromBlock&&(t.fromBlock=D(t.fromBlock)),t.toBlock&&(t.toBlock=D(t.toBlock)),Promise.resolve(this.post(A("eth_getLogs",[r]))).then(function(r){return r.map(function(r){return E(r,!1)})})}catch(r){return Promise.reject(r)}},t.call=function(r,t){void 0===t&&(t="latest");try{r.gasPrice&&(r.maxPriorityFeePerGas||r.maxFeePerGas)&&k.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")',{gasPrice:r.gasPrice,maxFeePerGas:r.maxFeePerGas,maxPriorityFeePerGas:r.maxPriorityFeePerGas}),r.maxFeePerGas&&r.maxPriorityFeePerGas&&k.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"',{maxFeePerGas:r.maxFeePerGas,maxPriorityFeePerGas:r.maxPriorityFeePerGas}),t=D(t);var e=$(r);return Promise.resolve(this.post(A("eth_call",[e,t])))}catch(r){return Promise.reject(r)}},r}(),z=/*#__PURE__*/function(r){a(e,r);var t=e.prototype;function e(t){return void 0===t&&(t="https://free-eth-node.com/api/eth"),r.call(this,[t])||this}return t.selectRpcUrl=function(){return this._rpcUrls[0]},t.post=function(r){return this._post(r)},e}(J);function V(r){return new z(r)}var q=/*#__PURE__*/function(r){function t(t,e){return void 0===e&&(e="mainnet"),r.call(this,"https://eth-"+e+".alchemyapi.io/v2/"+t)||this}return a(t,r),t}(z),K=/*#__PURE__*/function(r){function t(t,e){var n;return void 0===e&&(e={}),Array.isArray(t)||k.throwError("Array required",{rpcUrls:t}),t.length<=1&&k.throwError("More than one rpcUrl is required",{rpcUrls:t}),(n=r.call(this,t)||this).rpcUrlCounter=0,n.timeoutDuration=void 0,n.post=function(r){var t=n.rpcUrlCounter;return function e(){var i,o,a=n.selectRpcUrl();return(i=n._post(r),o=n.timeoutDuration,new Promise(function(r,t){var e=setTimeout(function(){return t(new Error("Promise timed out"))},o);i.then(function(t){clearTimeout(e),r(t)}).catch(function(r){clearTimeout(e),t(r)})})).catch(function(r){if(a===n.selectRpcUrl()&&(n.rpcUrlCounter=(n.rpcUrlCounter+1)%n._rpcUrls.length),n.rpcUrlCounter===t)throw r;return e()})}()},n.timeoutDuration=e.timeoutDuration||8e3,n}return a(t,r),t.prototype.selectRpcUrl=function(){return this._rpcUrls[this.rpcUrlCounter]},t}(J);function Q(r){return r=I(r).slice(2),"0x"+n.fromPrivateKey(r).toHex()}function X(t){var e;return e="string"==typeof t?Buffer.from(t.replace(/^0x/,""),"hex"):Buffer.from(t),"0x"+new r(256).update(e).digest("hex")}function Y(r){return r.startsWith("0x04")||r.startsWith("0x03")||r.startsWith("0x02")||(r=Q(r)),m(M(X(M(r,1)),12))}function Z(r){g(r,["string","number","object"]);var t=f(r).times("1000000000");return f(t)}function rr(r){g(r,["string","number","object"]);var t=f(r).times("1000000000000000000");return f(t)}function tr(r){g(r,["string","number","object"]);var t=f(r).div("1000000000");return f(t)}function er(r){return new Uint8Array(Buffer.from(r))}function nr(r){return"string"==typeof r&&(r=er(r)),X(G([er("Ethereum Signed Message:\n"),er(String(r.length)),r]))}function ir(r){g(r,["string"]);try{return m(r),!0}catch(r){return!1}}function or(r){var t={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(S(r)){var e=U(r);64===e.length?(t.v=27+(e[32]>>7),e[32]&=127,t.r=I(e.slice(0,32)),t.s=I(e.slice(32,64))):65===e.length?(t.r=I(e.slice(0,32)),t.s=I(e.slice(32,64)),t.v=e[64]):k.throwArgumentError("invalid signature string","signature",r),t.v<27&&(0===t.v||1===t.v?t.v+=27:k.throwArgumentError("signature invalid v byte","signature",r)),t.recoveryParam=1-t.v%2,t.recoveryParam&&(e[32]|=128),t._vs=I(e.slice(32,64))}else{if(t.r=r.r,t.s=r.s,t.v=r.v,t.recoveryParam=r.recoveryParam,t._vs=r._vs,null!=t._vs){var n=C(U(t._vs),32);t._vs=I(n);var i=n[0]>=128?1:0;null==t.recoveryParam?t.recoveryParam=i:t.recoveryParam!==i&&k.throwArgumentError("signature recoveryParam mismatch _vs","signature",r),n[0]&=127;var o=I(n);null==t.s?t.s=o:t.s!==o&&k.throwArgumentError("signature v mismatch _vs","signature",r)}null==t.recoveryParam?null==t.v?k.throwArgumentError("signature missing v and recoveryParam","signature",r):t.recoveryParam=0===t.v||1===t.v?t.v:1-t.v%2:null==t.v?t.v=27+t.recoveryParam:t.recoveryParam!==(0===t.v||1===t.v?t.v:1-t.v%2)&&k.throwArgumentError("signature recoveryParam mismatch v","signature",r),null!=t.r&&B(t.r)?t.r=H(t.r,32):k.throwArgumentError("signature missing or invalid r","signature",r),null!=t.s&&B(t.s)?t.s=H(t.s,32):k.throwArgumentError("signature missing or invalid s","signature",r);var a=U(t.s);a[0]>=128&&k.throwArgumentError("signature s out of range","signature",r),t.recoveryParam&&(a[0]|=128);var s=I(a);t._vs&&(B(t._vs)||k.throwArgumentError("signature invalid _vs","signature",r),t._vs=H(t._vs,32)),null==t._vs?t._vs=s:t._vs!==s&&k.throwArgumentError("signature _vs mismatch v and s","signature",r)}return t.yParityAndS=t._vs,t.compact=t.r+t.yParityAndS.substring(2),t}function ar(r){g(r,["string","number","object"]);try{var t=r;"string"==typeof r&&"0x"===r.slice(0,2)&&(t=BigInt(r).toString());var e=f(t).div("1000000000000000000");return f(e)}catch(r){throw r}}var sr=new RegExp("^bytes([0-9]+)$"),ur=new RegExp("^(u?int)([0-9]*)$"),cr=new RegExp("^(.*)\\[([0-9]*)\\]$");function lr(r,t,e){switch(r){case"address":return e?C(t,32):U(t);case"string":return i.from(t);case"bytes":return U(t);case"bool":return t=t?"0x01":"0x00",e?C(t,32):U(t)}var n=r.match(ur);if(n){var o=parseInt(n[2]||"256");return(n[2]&&String(o)!==n[2]||o%8!=0||0===o||o>256)&&k.throwArgumentError("invalid number type","type",r),e&&(o=256),C(I(t=f(t).toTwos(o).toNumber()),o/8)}if(n=r.match(sr)){var a=parseInt(n[1]);return(String(a)!==n[1]||0===a||a>32)&&k.throwArgumentError("invalid bytes type","type",r),U(t).byteLength!==a&&k.throwArgumentError("invalid value for "+r,"value",t),e?U((t+v).substring(0,66)):t}if((n=r.match(cr))&&Array.isArray(t)){var s=n[1];parseInt(n[2]||String(t.length))!=t.length&&k.throwArgumentError("invalid array length for "+r,"value",t);var u=[];return t.forEach(function(r){u.push(lr(s,r,!0))}),G(u)}return k.throwArgumentError("invalid type","type",r)}function hr(r,t){r.length!=t.length&&k.throwArgumentError("wrong number of values; expected ${ types.length }","values",t);var e=[];return r.forEach(function(r,n){e.push(lr(r,t[n]))}),I(G(e))}function fr(r,t){return X(hr(r,t))}export{q as AlchemyProvider,P as BaseContract,x as Contract,K as FallthroughProvider,z as JsonRpcProvider,h as TinyBig,U as arrayify,Y as computeAddress,Q as computePublicKey,G as concat,Z as etherToGwei,rr as etherToWei,tr as gweiToEther,nr as hashMessage,R as hexConcat,O as hexDataLength,M as hexDataSlice,L as hexStripZeros,T as hexValue,H as hexZeroPad,I as hexlify,ir as isAddress,j as isBytes,S as isBytesLike,B as isHexString,V as jsonRpcProvider,X as keccak256,hr as pack,fr as solidityKeccak256,or as splitSignature,F as stripZeros,f as tinyBig,m as toChecksumAddress,er as toUtf8Bytes,ar as weiToEther,C as zeroPad};
|
|
2
2
|
//# sourceMappingURL=essential-eth.esm.mjs.map
|