@ethda/blobs
Version:
Ethda Blobs SDK
3 lines (2 loc) • 13.2 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("path"),r=require("ethers"),n=require("c-kzg"),o=require("@ethereumjs/common"),i=require("@ethereumjs/tx"),a=require("ethereum-cryptography/keccak"),u=require("@ethereumjs/rlp"),s=require("@ethereumjs/util");function c(){c=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=Object.create((e&&e.prototype instanceof m?e:m).prototype),a=new G(n||[]);return o(i,"_invoke",{value:P(t,r,a)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var p="suspendedStart",v="executing",d="completed",y={};function m(){}function g(){}function x(){}var b={};l(b,a,(function(){return this}));var w=Object.getPrototypeOf,_=w&&w(w(F([])));_&&_!==r&&n.call(_,a)&&(b=_);var k=x.prototype=m.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function L(t,e){function r(o,i,a,u){var s=h(t[o],t,i);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){c.value=t,a(c)}),(function(t){return r("throw",t,a,u)}))}u(s.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function P(e,r,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var s=B(u,n);if(s){if(s===y)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var c=h(e,r,n);if("normal"===c.type){if(o=n.done?d:"suspendedYield",c.arg===y)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=d,n.method="throw",n.arg=c.arg)}}}function B(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,B(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function G(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function F(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return g.prototype=x,o(k,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:g,configurable:!0}),g.displayName=l(x,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,l(t,s,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},E(L.prototype),l(L.prototype,u,(function(){return this})),e.AsyncIterator=L,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new L(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(k),l(k,s,"Generator"),l(k,a,(function(){return this})),l(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=F,G.prototype={constructor:G,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(j),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:F(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},e}function l(t,e,r,n,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}function f(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){l(i,n,o,a,u,"next",t)}function u(t){l(i,n,o,a,u,"throw",t)}a(void 0)}))}}function h(t){return p.apply(this,arguments)}function p(){return(p=f(c().mark((function t(e){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t){return setTimeout(t,e)})));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function v(t){return function(t,e){if(t instanceof Uint8Array)return t;if("string"==typeof t&&t.match(/^0x([0-9a-f][0-9a-f])*$/i)){for(var r=new Uint8Array((t.length-2)/2),n=2,o=0;o<r.length;o++)r[o]=parseInt(t.substring(n,n+2),16),n+=2;return r}}(t)}function d(t,e){var n=new Uint8Array(32);n.set([e],0);var o=v(r.ethers.utils.sha256(t));return n.set(o.subarray(1),1),n}function y(t){return d(t,1)}function m(t){if(!t)throw Error("invalid blob data");if((t=v(t)).length<131072){var e=new Uint8Array(131072).fill(0);e.set(t),t=e}for(var r=[],n=0,o=0;o<4096;o++){var i=t.subarray(n+1,n+32);r=[].concat(r,i),n+=32}for(var a=r.length-1;a>=0&&0===r[a];a--);return r.slice(0,a+1)}function g(t){if(t){if("bigint"==typeof t)return"0x"+t.toString(16);if("object"==typeof t)return"0x"+BigInt(t._hex).toString(16)}return t}(t=exports.Network||(exports.Network={})).DencunDevnet12="dencun-devnet-12",t.EthDADevnet="ethda-devnet";var x=function(){function t(t){t instanceof r.ethers.providers.JsonRpcProvider?this._provider=t:(this._provider=t.provider,this._signer=t);var o=e.resolve(__dirname,"lib","trusted_setup.txt");console.log(o),n.loadTrustedSetup(o)}var l=t.prototype;return l.sanityCheck=function(){var t=f(c().mark((function t(e){var n,o,i,a,u,s,l,f,h,p,v;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u=e.nonce,s=e.to,l=e.value,f=e.data,h=e.maxPriorityFeePerGas,p=e.maxFeePerGas,v=e.maxFeePerBlobGas,a=e.chainId){t.next=5;break}return t.next=4,this._provider.getNetwork();case 4:a=t.sent.chainId;case 5:if(u){t.next=9;break}return t.next=8,this._signer.getTransactionCount();case 8:u=t.sent;case 9:return l=l?g(l):"0x",p=1000000000n,v=v?g(v):2e12,s=null!=(n=s)?n:r.constants.AddressZero,f=null!=(o=f)?o:"0x",h=null!=(i=h)?i:0,t.abrupt("return",{chainId:a,nonce:u,to:s,value:l,data:f,maxPriorityFeePerGas:h,maxFeePerGas:p,gasLimit:21e3,maxFeePerBlobGas:v});case 17:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),l.sendTx=function(){var t=f(c().mark((function t(e,r){var l,f,h,p,d,m,g,x,b,w,_,k,E,L,P,B,T,j,G,F,O,S,I,N;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return console.log("receive",r),t.next=3,this.sanityCheck(r);case 3:for(f=(l=t.sent).chainId,h=l.nonce,p=l.to,d=l.value,m=l.data,g=l.maxFeePerGas,x=l.gasLimit,b=l.maxFeePerBlobGas,w=[],_=[],k=[],E=0;E<e.length;E++)w.push(n.blobToKzgCommitment(e[E])),_.push(n.computeBlobKzgProof(e[E],w[E])),k.push(y(w[E]));return L=o.Common.custom({name:"ethda",networkId:f,chainId:f},{eips:[1559,3860,4844]}),console.log(f),B=a.keccak256(u.RLP.encode(P=[h,g,x,p,d,m,1001n,0,0])),T=v(this._signer.privateKey),j=s.ecsign(B,T),F=j.r,O=j.s,G=2n*1001n+8n+(G=j.v),console.log(P,h,G,Buffer.from(F).toString("hex"),Buffer.from(O).toString("hex")),S=new i.BlobEIP4844Transaction({chainId:f,nonce:h,to:p,value:d,data:m,maxPriorityFeePerGas:g,maxFeePerGas:g,gasLimit:x,maxFeePerBlobGas:b,blobVersionedHashes:k,blobs:e,kzgCommitments:w,kzgProofs:_,v:G-2n*1001n-35n,r:F,s:O},{common:L}),console.log(S),I=S.serializeNetworkWrapper(),N=Buffer.from(I).toString("hex"),t.next=31,this._provider.send("eth_sendRawTransaction",["0x"+N]);case 31:return t.abrupt("return",t.sent);case 32:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),l.isTransactionMined=function(){var t=f(c().mark((function t(e){var r;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._provider.getTransactionReceipt(e);case 2:if(!(r=t.sent)||!r.blockNumber){t.next=5;break}return t.abrupt("return",r);case 5:return t.abrupt("return",null);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),l.getTxReceipt=function(){var t=f(c().mark((function t(e){var r;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r){t.next=10;break}return t.next=3,this.isTransactionMined(e);case 3:if(!(r=t.sent)){t.next=6;break}return t.abrupt("break",10);case 6:return t.next=8,h(5e3);case 8:t.next=0;break;case 10:return t.abrupt("return",r);case 11:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),l.downloadBlobs=function(){var t=f(c().mark((function t(e){var r;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._provider.send("eth_getTransactionByHash",[e]);case 2:return t.abrupt("return",{blob_hashes:null==(r=t.sent)?void 0:r.blob_hashes,sidecar:null==r?void 0:r.sidecar});case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),l.getBlobHash=function(t){var e=y(n.blobToKzgCommitment(t)),o=new Uint8Array(32);return o.set(e.subarray(0,24)),r.ethers.utils.hexlify(o)},t}();exports.BLOB_SIZE=131072,exports.BlobClient=x,exports.BlobTxBytesPerFieldElement=32,exports.BlobTxFieldElementsPerBlob=4096,exports.DecodeBlob=m,exports.DecodeBlobs=function(t){if(!t)throw Error("invalid blobs");var e=(t=v(t)).length;if(0===e)throw Error("invalid blobs");for(var r=[],n=0;n<e;n+=131072){var o=n+131072;o>e&&(o=e);var i=m(t.subarray(n,o));r=[].concat(r,i)}return Buffer.from(r)},exports.EncodeBlobs=function(t){var e=t.length;if(0===e)throw Error("invalid blob data");for(var r=0,n=-1,o=[new Uint8Array(131072).fill(0)],i=0;i<e;i+=31){4096==++n&&(o.push(new Uint8Array(131072).fill(0)),r++,n=0);var a=i+31;a>e&&(a=e),o[r].set(t.subarray(i,a),32*n+1)}return o},exports.NULL_ADDRESS="0x0000000000000000000000000000000000000000",exports.ZERO_BYTES32="0x0000000000000000000000000000000000000000000000000000000000000000",exports.commitmentsToVersionedHashes=y,exports.computeVersionedHash=d,exports.debug=function(t){},exports.delay=h,exports.getBytes=v,exports.parseBigintValue=g;
//# sourceMappingURL=blobs.cjs.production.min.js.map