@gardenfi/core 2.1.3-beta.3 → 2.1.3-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
Use Chrome, Firefox or Internet Explorer 11`)}var Ml=Ve.Buffer,ti=zt.crypto||zt.msCrypto;ti&&ti.getRandomValues?bs.exports=Dl:bs.exports=Hl;function Dl(e,t){if(e>Fl)throw new RangeError("requested too many random bytes");var r=Ml.allocUnsafe(e);if(e>0)if(e>Yi)for(var n=0;n<e;n+=Yi)ti.getRandomValues(r.slice(n,n+Yi));else ti.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var $l=bs.exports,gs={exports:{}};typeof Object.create=="function"?gs.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:gs.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}};var Oe=gs.exports,_s={exports:{}},Gs={exports:{}},Or=typeof Reflect=="object"?Reflect:null,Bo=Or&&typeof Or.apply=="function"?Or.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Jn;Or&&typeof Or.ownKeys=="function"?Jn=Or.ownKeys:Object.getOwnPropertySymbols?Jn=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Jn=function(t){return Object.getOwnPropertyNames(t)};function jl(e){console&&console.warn&&console.warn(e)}var Wa=Number.isNaN||function(t){return t!==t};function se(){se.init.call(this)}Gs.exports=se;Gs.exports.once=ql;se.EventEmitter=se;se.prototype._events=void 0;se.prototype._eventsCount=0;se.prototype._maxListeners=void 0;var Io=10;function wi(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(se,"defaultMaxListeners",{enumerable:!0,get:function(){return Io},set:function(e){if(typeof e!="number"||e<0||Wa(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Io=e}});se.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};se.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Wa(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Ka(e){return e._maxListeners===void 0?se.defaultMaxListeners:e._maxListeners}se.prototype.getMaxListeners=function(){return Ka(this)};se.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var u=s[t];if(u===void 0)return!1;if(typeof u=="function")Bo(u,this,r);else for(var h=u.length,d=Za(u,h),n=0;n<h;++n)Bo(d[n],this,r);return!0};function Ya(e,t,r,n){var i,s,o;if(wi(r),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),o=s[t]),o===void 0)o=s[t]=r,++e._eventsCount;else if(typeof o=="function"?o=s[t]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),i=Ka(e),i>0&&o.length>i&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=o.length,jl(a)}return e}se.prototype.addListener=function(t,r){return Ya(this,t,r,!1)};se.prototype.on=se.prototype.addListener;se.prototype.prependListener=function(t,r){return Ya(this,t,r,!0)};function Gl(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Xa(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Gl.bind(n);return i.listener=r,n.wrapFn=i,i}se.prototype.once=function(t,r){return wi(r),this.on(t,Xa(this,t,r)),this};se.prototype.prependOnceListener=function(t,r){return wi(r),this.prependListener(t,Xa(this,t,r)),this};se.prototype.removeListener=function(t,r){var n,i,s,o,a;if(wi(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(s=-1,o=n.length-1;o>=0;o--)if(n[o]===r||n[o].listener===r){a=n[o].listener,s=o;break}if(s<0)return this;s===0?n.shift():Vl(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};se.prototype.off=se.prototype.removeListener;se.prototype.removeAllListeners=function(t){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var s=Object.keys(n),o;for(i=0;i<s.length;++i)o=s[i],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(t,r[i]);return this};function Ja(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?zl(i):Za(i,i.length)}se.prototype.listeners=function(t){return Ja(this,t,!0)};se.prototype.rawListeners=function(t){return Ja(this,t,!1)};se.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Qa.call(e,t)};se.prototype.listenerCount=Qa;function Qa(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}se.prototype.eventNames=function(){return this._eventsCount>0?Jn(this._events):[]};function Za(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Vl(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function zl(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function ql(e,t){return new Promise(function(r,n){function i(o){e.removeListener(t,s),n(o)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}ec(e,t,s,{once:!0}),t!=="error"&&Wl(e,i,{once:!0})})}function Wl(e,t,r){typeof e.on=="function"&&ec(e,"error",t,r)}function ec(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function i(s){n.once&&e.removeEventListener(t,i),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var tc=Gs.exports,rc=tc.EventEmitter;const Kl={},Yl=Object.freeze(Object.defineProperty({__proto__:null,default:Kl},Symbol.toStringTag,{value:"Module"})),Vs=Pf(Yl);var Xi,Po;function Xl(){if(Po)return Xi;Po=1;function e(I,B){var T=Object.keys(I);if(Object.getOwnPropertySymbols){var R=Object.getOwnPropertySymbols(I);B&&(R=R.filter(function(U){return Object.getOwnPropertyDescriptor(I,U).enumerable})),T.push.apply(T,R)}return T}function t(I){for(var B=1;B<arguments.length;B++){var T=arguments[B]!=null?arguments[B]:{};B%2?e(Object(T),!0).forEach(function(R){r(I,R,T[R])}):Object.getOwnPropertyDescriptors?Object.defineProperties(I,Object.getOwnPropertyDescriptors(T)):e(Object(T)).forEach(function(R){Object.defineProperty(I,R,Object.getOwnPropertyDescriptor(T,R))})}return I}function r(I,B,T){return B=o(B),B in I?Object.defineProperty(I,B,{value:T,enumerable:!0,configurable:!0,writable:!0}):I[B]=T,I}function n(I,B){if(!(I instanceof B))throw new TypeError("Cannot call a class as a function")}function i(I,B){for(var T=0;T<B.length;T++){var R=B[T];R.enumerable=R.enumerable||!1,R.configurable=!0,"value"in R&&(R.writable=!0),Object.defineProperty(I,o(R.key),R)}}function s(I,B,T){return B&&i(I.prototype,B),Object.defineProperty(I,"prototype",{writable:!1}),I}function o(I){var B=a(I,"string");return typeof B=="symbol"?B:String(B)}function a(I,B){if(typeof I!="object"||I===null)return I;var T=I[Symbol.toPrimitive];if(T!==void 0){var R=T.call(I,B);if(typeof R!="object")return R;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(I)}var u=It,h=u.Buffer,d=Vs,m=d.inspect,_=m&&m.custom||"inspect";function p(I,B,T){h.prototype.copy.call(I,B,T)}return Xi=function(){function I(){n(this,I),this.head=null,this.tail=null,this.length=0}return s(I,[{key:"push",value:function(T){var R={data:T,next:null};this.length>0?this.tail.next=R:this.head=R,this.tail=R,++this.length}},{key:"unshift",value:function(T){var R={data:T,next:this.head};this.length===0&&(this.tail=R),this.head=R,++this.length}},{key:"shift",value:function(){if(this.length!==0){var T=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,T}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(T){if(this.length===0)return"";for(var R=this.head,U=""+R.data;R=R.next;)U+=T+R.data;return U}},{key:"concat",value:function(T){if(this.length===0)return h.alloc(0);for(var R=h.allocUnsafe(T>>>0),U=this.head,x=0;U;)p(U.data,R,x),x+=U.data.length,U=U.next;return R}},{key:"consume",value:function(T,R){var U;return T<this.head.data.length?(U=this.head.data.slice(0,T),this.head.data=this.head.data.slice(T)):T===this.head.data.length?U=this.shift():U=R?this._getString(T):this._getBuffer(T),U}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(T){var R=this.head,U=1,x=R.data;for(T-=x.length;R=R.next;){var g=R.data,S=T>g.length?g.length:T;if(S===g.length?x+=g:x+=g.slice(0,T),T-=S,T===0){S===g.length?(++U,R.next?this.head=R.next:this.head=this.tail=null):(this.head=R,R.data=g.slice(S));break}++U}return this.length-=U,x}},{key:"_getBuffer",value:function(T){var R=h.allocUnsafe(T),U=this.head,x=1;for(U.data.copy(R),T-=U.data.length;U=U.next;){var g=U.data,S=T>g.length?g.length:T;if(g.copy(R,R.length-T,0,S),T-=S,T===0){S===g.length?(++x,U.next?this.head=U.next:this.head=this.tail=null):(this.head=U,U.data=g.slice(S));break}++x}return this.length-=x,R}},{key:_,value:function(T,R){return m(this,t(t({},R),{},{depth:0,customInspect:!1}))}}]),I}(),Xi}function Jl(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return n||i?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(vs,this,e)):process.nextTick(vs,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted?process.nextTick(Qn,r):(r._writableState.errorEmitted=!0,process.nextTick(Oo,r,s)):process.nextTick(Oo,r,s):t?(process.nextTick(Qn,r),t(s)):process.nextTick(Qn,r)}),this)}function Oo(e,t){vs(e,t),Qn(e)}function Qn(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Ql(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function vs(e,t){e.emit("error",t)}function Zl(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var nc={destroy:Jl,undestroy:Ql,errorOrDestroy:Zl},yr={};function eh(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var ic={};function tt(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){eh(o,s);function o(a,u,h){return s.call(this,n(a,u,h))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,ic[e]=i}function Ro(e,t){if(Array.isArray(e)){var r=e.length;return e=e.map(function(n){return String(n)}),r>2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:r===2?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}else return"of ".concat(t," ").concat(String(e))}function th(e,t,r){return e.substr(0,t.length)===t}function rh(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function nh(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}tt("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);tt("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&th(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(rh(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Ro(t,"type"));else{var s=nh(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Ro(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);tt("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");tt("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});tt("ERR_STREAM_PREMATURE_CLOSE","Premature close");tt("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});tt("ERR_MULTIPLE_CALLBACK","Callback called multiple times");tt("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");tt("ERR_STREAM_WRITE_AFTER_END","write after end");tt("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);tt("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);tt("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");yr.codes=ic;var ih=yr.codes.ERR_INVALID_OPT_VALUE;function sh(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function oh(e,t,r,n){var i=sh(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new ih(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var sc={getHighWaterMark:oh},ah=ch;function ch(e,t){if(Ji("noDeprecation"))return e;var r=!1;function n(){if(!r){if(Ji("throwDeprecation"))throw new Error(t);Ji("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function Ji(e){try{if(!zt.localStorage)return!1}catch{return!1}var t=zt.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Qi,Co;function oc(){if(Co)return Qi;Co=1,Qi=M;function e(k){var A=this;this.next=null,this.entry=null,this.finish=function(){pt(A,k)}}var t;M.WritableState=E;var r={deprecate:ah},n=rc,i=It.Buffer,s=(typeof zt<"u"?zt:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(k){return i.from(k)}function a(k){return i.isBuffer(k)||k instanceof s}var u=nc,h=sc,d=h.getHighWaterMark,m=yr.codes,_=m.ERR_INVALID_ARG_TYPE,p=m.ERR_METHOD_NOT_IMPLEMENTED,I=m.ERR_MULTIPLE_CALLBACK,B=m.ERR_STREAM_CANNOT_PIPE,T=m.ERR_STREAM_DESTROYED,R=m.ERR_STREAM_NULL_VALUES,U=m.ERR_STREAM_WRITE_AFTER_END,x=m.ERR_UNKNOWN_ENCODING,g=u.errorOrDestroy;Oe(M,n);function S(){}function E(k,A,F){t=t||Hr(),k=k||{},typeof F!="boolean"&&(F=A instanceof t),this.objectMode=!!k.objectMode,F&&(this.objectMode=this.objectMode||!!k.writableObjectMode),this.highWaterMark=d(this,k,"writableHighWaterMark",F),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var q=k.decodeStrings===!1;this.decodeStrings=!q,this.defaultEncoding=k.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(Y){ve(A,Y)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=k.emitClose!==!1,this.autoDestroy=!!k.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}E.prototype.getBuffer=function(){for(var A=this.bufferedRequest,F=[];A;)F.push(A),A=A.next;return F},function(){try{Object.defineProperty(E.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var H;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(H=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(A){return H.call(this,A)?!0:this!==M?!1:A&&A._writableState instanceof E}})):H=function(A){return A instanceof this};function M(k){t=t||Hr();var A=this instanceof t;if(!A&&!H.call(M,this))return new M(k);this._writableState=new E(k,this,A),this.writable=!0,k&&(typeof k.write=="function"&&(this._write=k.write),typeof k.writev=="function"&&(this._writev=k.writev),typeof k.destroy=="function"&&(this._destroy=k.destroy),typeof k.final=="function"&&(this._final=k.final)),n.call(this)}M.prototype.pipe=function(){g(this,new B)};function O(k,A){var F=new U;g(k,F),process.nextTick(A,F)}function K(k,A,F,q){var Y;return F===null?Y=new R:typeof F!="string"&&!A.objectMode&&(Y=new _("chunk",["string","Buffer"],F)),Y?(g(k,Y),process.nextTick(q,Y),!1):!0}M.prototype.write=function(k,A,F){var q=this._writableState,Y=!1,b=!q.objectMode&&a(k);return b&&!i.isBuffer(k)&&(k=o(k)),typeof A=="function"&&(F=A,A=null),b?A="buffer":A||(A=q.defaultEncoding),typeof F!="function"&&(F=S),q.ending?O(this,F):(b||K(this,q,k,F))&&(q.pendingcb++,Y=j(this,q,b,k,A,F)),Y},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var k=this._writableState;k.corked&&(k.corked--,!k.writing&&!k.corked&&!k.bufferProcessing&&k.bufferedRequest&&qe(this,k))},M.prototype.setDefaultEncoding=function(A){if(typeof A=="string"&&(A=A.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((A+"").toLowerCase())>-1))throw new x(A);return this._writableState.defaultEncoding=A,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function C(k,A,F){return!k.objectMode&&k.decodeStrings!==!1&&typeof A=="string"&&(A=i.from(A,F)),A}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function j(k,A,F,q,Y,b){if(!F){var w=C(A,q,Y);q!==w&&(F=!0,Y="buffer",q=w)}var N=A.objectMode?1:q.length;A.length+=N;var D=A.length<A.highWaterMark;if(D||(A.needDrain=!0),A.writing||A.corked){var pe=A.lastBufferedRequest;A.lastBufferedRequest={chunk:q,encoding:Y,isBuf:F,callback:b,next:null},pe?pe.next=A.lastBufferedRequest:A.bufferedRequest=A.lastBufferedRequest,A.bufferedRequestCount+=1}else G(k,A,!1,N,q,Y,b);return D}function G(k,A,F,q,Y,b,w){A.writelen=q,A.writecb=w,A.writing=!0,A.sync=!0,A.destroyed?A.onwrite(new T("write")):F?k._writev(Y,A.onwrite):k._write(Y,b,A.onwrite),A.sync=!1}function V(k,A,F,q,Y){--A.pendingcb,F?(process.nextTick(Y,q),process.nextTick(We,k,A),k._writableState.errorEmitted=!0,g(k,q)):(Y(q),k._writableState.errorEmitted=!0,g(k,q),We(k,A))}function ee(k){k.writing=!1,k.writecb=null,k.length-=k.writelen,k.writelen=0}function ve(k,A){var F=k._writableState,q=F.sync,Y=F.writecb;if(typeof Y!="function")throw new I;if(ee(F),A)V(k,F,q,A,Y);else{var b=Ot(F)||k.destroyed;!b&&!F.corked&&!F.bufferProcessing&&F.bufferedRequest&&qe(k,F),q?process.nextTick(ze,k,F,b,Y):ze(k,F,b,Y)}}function ze(k,A,F,q){F||rt(k,A),A.pendingcb--,q(),We(k,A)}function rt(k,A){A.length===0&&A.needDrain&&(A.needDrain=!1,k.emit("drain"))}function qe(k,A){A.bufferProcessing=!0;var F=A.bufferedRequest;if(k._writev&&F&&F.next){var q=A.bufferedRequestCount,Y=new Array(q),b=A.corkedRequestsFree;b.entry=F;for(var w=0,N=!0;F;)Y[w]=F,F.isBuf||(N=!1),F=F.next,w+=1;Y.allBuffers=N,G(k,A,!0,A.length,Y,"",b.finish),A.pendingcb++,A.lastBufferedRequest=null,b.next?(A.corkedRequestsFree=b.next,b.next=null):A.corkedRequestsFree=new e(A),A.bufferedRequestCount=0}else{for(;F;){var D=F.chunk,pe=F.encoding,X=F.callback,re=A.objectMode?1:D.length;if(G(k,A,!1,re,D,pe,X),F=F.next,A.bufferedRequestCount--,A.writing)break}F===null&&(A.lastBufferedRequest=null)}A.bufferedRequest=F,A.bufferProcessing=!1}M.prototype._write=function(k,A,F){F(new p("_write()"))},M.prototype._writev=null,M.prototype.end=function(k,A,F){var q=this._writableState;return typeof k=="function"?(F=k,k=null,A=null):typeof A=="function"&&(F=A,A=null),k!=null&&this.write(k,A),q.corked&&(q.corked=1,this.uncork()),q.ending||Rt(this,q,F),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function Ot(k){return k.ending&&k.length===0&&k.bufferedRequest===null&&!k.finished&&!k.writing}function de(k,A){k._final(function(F){A.pendingcb--,F&&g(k,F),A.prefinished=!0,k.emit("prefinish"),We(k,A)})}function Ee(k,A){!A.prefinished&&!A.finalCalled&&(typeof k._final=="function"&&!A.destroyed?(A.pendingcb++,A.finalCalled=!0,process.nextTick(de,k,A)):(A.prefinished=!0,k.emit("prefinish")))}function We(k,A){var F=Ot(A);if(F&&(Ee(k,A),A.pendingcb===0&&(A.finished=!0,k.emit("finish"),A.autoDestroy))){var q=k._readableState;(!q||q.autoDestroy&&q.endEmitted)&&k.destroy()}return F}function Rt(k,A,F){A.ending=!0,We(k,A),F&&(A.finished?process.nextTick(F):k.once("finish",F)),A.ended=!0,k.writable=!1}function pt(k,A,F){var q=k.entry;for(k.entry=null;q;){var Y=q.callback;A.pendingcb--,Y(F),q=q.next}A.corkedRequestsFree.next=k}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(A){this._writableState&&(this._writableState.destroyed=A)}}),M.prototype.destroy=u.destroy,M.prototype._undestroy=u.undestroy,M.prototype._destroy=function(k,A){A(k)},Qi}var Zi,Uo;function Hr(){if(Uo)return Zi;Uo=1;var e=Object.keys||function(h){var d=[];for(var m in h)d.push(m);return d};Zi=o;var t=cc(),r=oc();Oe(o,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var s=n[i];o.prototype[s]||(o.prototype[s]=r.prototype[s])}function o(h){if(!(this instanceof o))return new o(h);t.call(this,h),r.call(this,h),this.allowHalfOpen=!0,h&&(h.readable===!1&&(this.readable=!1),h.writable===!1&&(this.writable=!1),h.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",a)))}Object.defineProperty(o.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(o.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(o.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function a(){this._writableState.ended||process.nextTick(u,this)}function u(h){h.end()}return Object.defineProperty(o.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(d){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=d,this._writableState.destroyed=d)}}),Zi}var ri={},zs=Ve.Buffer,Lo=zs.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function fh(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function uh(e){var t=fh(e);if(typeof t!="string"&&(zs.isEncoding===Lo||!Lo(e)))throw new Error("Unknown encoding: "+e);return t||e}ri.StringDecoder=xn;function xn(e){this.encoding=uh(e);var t;switch(this.encoding){case"utf16le":this.text=mh,this.end=bh,t=4;break;case"utf8":this.fillLast=dh,t=4;break;case"base64":this.text=wh,this.end=gh,t=3;break;default:this.write=_h,this.end=vh;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=zs.allocUnsafe(t)}xn.prototype.write=function(e){if(e.length===0)return"";var t,r;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""};xn.prototype.end=yh;xn.prototype.text=ph;xn.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function es(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function lh(e,t,r){var n=t.length-1;if(n<r)return 0;var i=es(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=es(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=es(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function hh(e,t,r){if((t[0]&192)!==128)return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if((t[1]&192)!==128)return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&(t[2]&192)!==128)return e.lastNeed=2,"�"}}function dh(e){var t=this.lastTotal-this.lastNeed,r=hh(this,e);if(r!==void 0)return r;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function ph(e,t){var r=lh(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)}function yh(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function mh(e,t){if((e.length-t)%2===0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function bh(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function wh(e,t){var r=(e.length-t)%3;return r===0?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function gh(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function _h(e){return e.toString(this.encoding)}function vh(e){return e&&e.length?this.write(e):""}var No=yr.codes.ERR_STREAM_PREMATURE_CLOSE;function Eh(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];e.apply(this,n)}}}function xh(){}function Sh(e){return e.setHeader&&typeof e.abort=="function"}function ac(e,t,r){if(typeof t=="function")return ac(e,null,t);t||(t={}),r=Eh(r||xh);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||a()},o=e._writableState&&e._writableState.finished,a=function(){i=!1,o=!0,n||r.call(e)},u=e._readableState&&e._readableState.endEmitted,h=function(){n=!1,u=!0,i||r.call(e)},d=function(I){r.call(e,I)},m=function(){var I;if(n&&!u)return(!e._readableState||!e._readableState.ended)&&(I=new No),r.call(e,I);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(I=new No),r.call(e,I)},_=function(){e.req.on("finish",a)};return Sh(e)?(e.on("complete",a),e.on("abort",m),e.req?_():e.on("request",_)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",h),e.on("finish",a),t.error!==!1&&e.on("error",d),e.on("close",m),function(){e.removeListener("complete",a),e.removeListener("abort",m),e.removeListener("request",_),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",h),e.removeListener("error",d),e.removeListener("close",m)}}var qs=ac,ts,Fo;function Ah(){if(Fo)return ts;Fo=1;var e;function t(x,g,S){return g=r(g),g in x?Object.defineProperty(x,g,{value:S,enumerable:!0,configurable:!0,writable:!0}):x[g]=S,x}function r(x){var g=n(x,"string");return typeof g=="symbol"?g:String(g)}function n(x,g){if(typeof x!="object"||x===null)return x;var S=x[Symbol.toPrimitive];if(S!==void 0){var E=S.call(x,g);if(typeof E!="object")return E;throw new TypeError("@@toPrimitive must return a primitive value.")}return(g==="string"?String:Number)(x)}var i=qs,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),u=Symbol("ended"),h=Symbol("lastPromise"),d=Symbol("handlePromise"),m=Symbol("stream");function _(x,g){return{value:x,done:g}}function p(x){var g=x[s];if(g!==null){var S=x[m].read();S!==null&&(x[h]=null,x[s]=null,x[o]=null,g(_(S,!1)))}}function I(x){process.nextTick(p,x)}function B(x,g){return function(S,E){x.then(function(){if(g[u]){S(_(void 0,!0));return}g[d](S,E)},E)}}var T=Object.getPrototypeOf(function(){}),R=Object.setPrototypeOf((e={get stream(){return this[m]},next:function(){var g=this,S=this[a];if(S!==null)return Promise.reject(S);if(this[u])return Promise.resolve(_(void 0,!0));if(this[m].destroyed)return new Promise(function(O,K){process.nextTick(function(){g[a]?K(g[a]):O(_(void 0,!0))})});var E=this[h],H;if(E)H=new Promise(B(E,this));else{var M=this[m].read();if(M!==null)return Promise.resolve(_(M,!1));H=new Promise(this[d])}return this[h]=H,H}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var g=this;return new Promise(function(S,E){g[m].destroy(null,function(H){if(H){E(H);return}S(_(void 0,!0))})})}),e),T),U=function(g){var S,E=Object.create(R,(S={},t(S,m,{value:g,writable:!0}),t(S,s,{value:null,writable:!0}),t(S,o,{value:null,writable:!0}),t(S,a,{value:null,writable:!0}),t(S,u,{value:g._readableState.endEmitted,writable:!0}),t(S,d,{value:function(M,O){var K=E[m].read();K?(E[h]=null,E[s]=null,E[o]=null,M(_(K,!1))):(E[s]=M,E[o]=O)},writable:!0}),S));return E[h]=null,i(g,function(H){if(H&&H.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=E[o];M!==null&&(E[h]=null,E[s]=null,E[o]=null,M(H)),E[a]=H;return}var O=E[s];O!==null&&(E[h]=null,E[s]=null,E[o]=null,O(_(void 0,!0))),E[u]=!0}),g.on("readable",I.bind(null,E)),E};return ts=U,ts}var rs,Ho;function kh(){return Ho||(Ho=1,rs=function(){throw new Error("Readable.from is not available in the browser")}),rs}var ns,Mo;function cc(){if(Mo)return ns;Mo=1,ns=O;var e;O.ReadableState=M,tc.EventEmitter;var t=function(w,N){return w.listeners(N).length},r=rc,n=It.Buffer,i=(typeof zt<"u"?zt:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(b){return n.from(b)}function o(b){return n.isBuffer(b)||b instanceof i}var a=Vs,u;a&&a.debuglog?u=a.debuglog("stream"):u=function(){};var h=Xl(),d=nc,m=sc,_=m.getHighWaterMark,p=yr.codes,I=p.ERR_INVALID_ARG_TYPE,B=p.ERR_STREAM_PUSH_AFTER_EOF,T=p.ERR_METHOD_NOT_IMPLEMENTED,R=p.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,U,x,g;Oe(O,r);var S=d.errorOrDestroy,E=["error","close","destroy","pause","resume"];function H(b,w,N){if(typeof b.prependListener=="function")return b.prependListener(w,N);!b._events||!b._events[w]?b.on(w,N):Array.isArray(b._events[w])?b._events[w].unshift(N):b._events[w]=[N,b._events[w]]}function M(b,w,N){e=e||Hr(),b=b||{},typeof N!="boolean"&&(N=w instanceof e),this.objectMode=!!b.objectMode,N&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=_(this,b,"readableHighWaterMark",N),this.buffer=new h,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=b.emitClose!==!1,this.autoDestroy=!!b.autoDestroy,this.destroyed=!1,this.defaultEncoding=b.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,b.encoding&&(U||(U=ri.StringDecoder),this.decoder=new U(b.encoding),this.encoding=b.encoding)}function O(b){if(e=e||Hr(),!(this instanceof O))return new O(b);var w=this instanceof e;this._readableState=new M(b,this,w),this.readable=!0,b&&(typeof b.read=="function"&&(this._read=b.read),typeof b.destroy=="function"&&(this._destroy=b.destroy)),r.call(this)}Object.defineProperty(O.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(w){this._readableState&&(this._readableState.destroyed=w)}}),O.prototype.destroy=d.destroy,O.prototype._undestroy=d.undestroy,O.prototype._destroy=function(b,w){w(b)},O.prototype.push=function(b,w){var N=this._readableState,D;return N.objectMode?D=!0:typeof b=="string"&&(w=w||N.defaultEncoding,w!==N.encoding&&(b=n.from(b,w),w=""),D=!0),K(this,b,w,!1,D)},O.prototype.unshift=function(b){return K(this,b,null,!0,!1)};function K(b,w,N,D,pe){u("readableAddChunk",w);var X=b._readableState;if(w===null)X.reading=!1,ve(b,X);else{var re;if(pe||(re=j(X,w)),re)S(b,re);else if(X.objectMode||w&&w.length>0)if(typeof w!="string"&&!X.objectMode&&Object.getPrototypeOf(w)!==n.prototype&&(w=s(w)),D)X.endEmitted?S(b,new R):C(b,X,w,!0);else if(X.ended)S(b,new B);else{if(X.destroyed)return!1;X.reading=!1,X.decoder&&!N?(w=X.decoder.write(w),X.objectMode||w.length!==0?C(b,X,w,!1):qe(b,X)):C(b,X,w,!1)}else D||(X.reading=!1,qe(b,X))}return!X.ended&&(X.length<X.highWaterMark||X.length===0)}function C(b,w,N,D){w.flowing&&w.length===0&&!w.sync?(w.awaitDrain=0,b.emit("data",N)):(w.length+=w.objectMode?1:N.length,D?w.buffer.unshift(N):w.buffer.push(N),w.needReadable&&ze(b)),qe(b,w)}function j(b,w){var N;return!o(w)&&typeof w!="string"&&w!==void 0&&!b.objectMode&&(N=new I("chunk",["string","Buffer","Uint8Array"],w)),N}O.prototype.isPaused=function(){return this._readableState.flowing===!1},O.prototype.setEncoding=function(b){U||(U=ri.StringDecoder);var w=new U(b);this._readableState.decoder=w,this._readableState.encoding=this._readableState.decoder.encoding;for(var N=this._readableState.buffer.head,D="";N!==null;)D+=w.write(N.data),N=N.next;return this._readableState.buffer.clear(),D!==""&&this._readableState.buffer.push(D),this._readableState.length=D.length,this};var G=1073741824;function V(b){return b>=G?b=G:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function ee(b,w){return b<=0||w.length===0&&w.ended?0:w.objectMode?1:b!==b?w.flowing&&w.length?w.buffer.head.data.length:w.length:(b>w.highWaterMark&&(w.highWaterMark=V(b)),b<=w.length?b:w.ended?w.length:(w.needReadable=!0,0))}O.prototype.read=function(b){u("read",b),b=parseInt(b,10);var w=this._readableState,N=b;if(b!==0&&(w.emittedReadable=!1),b===0&&w.needReadable&&((w.highWaterMark!==0?w.length>=w.highWaterMark:w.length>0)||w.ended))return u("read: emitReadable",w.length,w.ended),w.length===0&&w.ended?F(this):ze(this),null;if(b=ee(b,w),b===0&&w.ended)return w.length===0&&F(this),null;var D=w.needReadable;u("need readable",D),(w.length===0||w.length-b<w.highWaterMark)&&(D=!0,u("length less than watermark",D)),w.ended||w.reading?(D=!1,u("reading or ended",D)):D&&(u("do read"),w.reading=!0,w.sync=!0,w.length===0&&(w.needReadable=!0),this._read(w.highWaterMark),w.sync=!1,w.reading||(b=ee(N,w)));var pe;return b>0?pe=A(b,w):pe=null,pe===null?(w.needReadable=w.length<=w.highWaterMark,b=0):(w.length-=b,w.awaitDrain=0),w.length===0&&(w.ended||(w.needReadable=!0),N!==b&&w.ended&&F(this)),pe!==null&&this.emit("data",pe),pe};function ve(b,w){if(u("onEofChunk"),!w.ended){if(w.decoder){var N=w.decoder.end();N&&N.length&&(w.buffer.push(N),w.length+=w.objectMode?1:N.length)}w.ended=!0,w.sync?ze(b):(w.needReadable=!1,w.emittedReadable||(w.emittedReadable=!0,rt(b)))}}function ze(b){var w=b._readableState;u("emitReadable",w.needReadable,w.emittedReadable),w.needReadable=!1,w.emittedReadable||(u("emitReadable",w.flowing),w.emittedReadable=!0,process.nextTick(rt,b))}function rt(b){var w=b._readableState;u("emitReadable_",w.destroyed,w.length,w.ended),!w.destroyed&&(w.length||w.ended)&&(b.emit("readable"),w.emittedReadable=!1),w.needReadable=!w.flowing&&!w.ended&&w.length<=w.highWaterMark,k(b)}function qe(b,w){w.readingMore||(w.readingMore=!0,process.nextTick(Ot,b,w))}function Ot(b,w){for(;!w.reading&&!w.ended&&(w.length<w.highWaterMark||w.flowing&&w.length===0);){var N=w.length;if(u("maybeReadMore read 0"),b.read(0),N===w.length)break}w.readingMore=!1}O.prototype._read=function(b){S(this,new T("_read()"))},O.prototype.pipe=function(b,w){var N=this,D=this._readableState;switch(D.pipesCount){case 0:D.pipes=b;break;case 1:D.pipes=[D.pipes,b];break;default:D.pipes.push(b);break}D.pipesCount+=1,u("pipe count=%d opts=%j",D.pipesCount,w);var pe=(!w||w.end!==!1)&&b!==process.stdout&&b!==process.stderr,X=pe?Ct:Zt;D.endEmitted?process.nextTick(X):N.once("end",X),b.on("unpipe",re);function re(l,c){u("onunpipe"),l===N&&c&&c.hasUnpiped===!1&&(c.hasUnpiped=!0,wr())}function Ct(){u("onend"),b.end()}var br=de(N);b.on("drain",br);var Gr=!1;function wr(){u("cleanup"),b.removeListener("close",Vr),b.removeListener("finish",Je),b.removeListener("drain",br),b.removeListener("error",Qt),b.removeListener("unpipe",re),N.removeListener("end",Ct),N.removeListener("end",Zt),N.removeListener("data",Ke),Gr=!0,D.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&br()}N.on("data",Ke);function Ke(l){u("ondata");var c=b.write(l);u("dest.write",c),c===!1&&((D.pipesCount===1&&D.pipes===b||D.pipesCount>1&&Y(D.pipes,b)!==-1)&&!Gr&&(u("false write response, pause",D.awaitDrain),D.awaitDrain++),N.pause())}function Qt(l){u("onerror",l),Zt(),b.removeListener("error",Qt),t(b,"error")===0&&S(b,l)}H(b,"error",Qt);function Vr(){b.removeListener("finish",Je),Zt()}b.once("close",Vr);function Je(){u("onfinish"),b.removeListener("close",Vr),Zt()}b.once("finish",Je);function Zt(){u("unpipe"),N.unpipe(b)}return b.emit("pipe",N),D.flowing||(u("pipe resume"),N.resume()),b};function de(b){return function(){var N=b._readableState;u("pipeOnDrain",N.awaitDrain),N.awaitDrain&&N.awaitDrain--,N.awaitDrain===0&&t(b,"data")&&(N.flowing=!0,k(b))}}O.prototype.unpipe=function(b){var w=this._readableState,N={hasUnpiped:!1};if(w.pipesCount===0)return this;if(w.pipesCount===1)return b&&b!==w.pipes?this:(b||(b=w.pipes),w.pipes=null,w.pipesCount=0,w.flowing=!1,b&&b.emit("unpipe",this,N),this);if(!b){var D=w.pipes,pe=w.pipesCount;w.pipes=null,w.pipesCount=0,w.flowing=!1;for(var X=0;X<pe;X++)D[X].emit("unpipe",this,{hasUnpiped:!1});return this}var re=Y(w.pipes,b);return re===-1?this:(w.pipes.splice(re,1),w.pipesCount-=1,w.pipesCount===1&&(w.pipes=w.pipes[0]),b.emit("unpipe",this,N),this)},O.prototype.on=function(b,w){var N=r.prototype.on.call(this,b,w),D=this._readableState;return b==="data"?(D.readableListening=this.listenerCount("readable")>0,D.flowing!==!1&&this.resume()):b==="readable"&&!D.endEmitted&&!D.readableListening&&(D.readableListening=D.needReadable=!0,D.flowing=!1,D.emittedReadable=!1,u("on readable",D.length,D.reading),D.length?ze(this):D.reading||process.nextTick(We,this)),N},O.prototype.addListener=O.prototype.on,O.prototype.removeListener=function(b,w){var N=r.prototype.removeListener.call(this,b,w);return b==="readable"&&process.nextTick(Ee,this),N},O.prototype.removeAllListeners=function(b){var w=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(Ee,this),w};function Ee(b){var w=b._readableState;w.readableListening=b.listenerCount("readable")>0,w.resumeScheduled&&!w.paused?w.flowing=!0:b.listenerCount("data")>0&&b.resume()}function We(b){u("readable nexttick read 0"),b.read(0)}O.prototype.resume=function(){var b=this._readableState;return b.flowing||(u("resume"),b.flowing=!b.readableListening,Rt(this,b)),b.paused=!1,this};function Rt(b,w){w.resumeScheduled||(w.resumeScheduled=!0,process.nextTick(pt,b,w))}function pt(b,w){u("resume",w.reading),w.reading||b.read(0),w.resumeScheduled=!1,b.emit("resume"),k(b),w.flowing&&!w.reading&&b.read(0)}O.prototype.pause=function(){return u("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(u("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function k(b){var w=b._readableState;for(u("flow",w.flowing);w.flowing&&b.read()!==null;);}O.prototype.wrap=function(b){var w=this,N=this._readableState,D=!1;b.on("end",function(){if(u("wrapped end"),N.decoder&&!N.ended){var re=N.decoder.end();re&&re.length&&w.push(re)}w.push(null)}),b.on("data",function(re){if(u("wrapped data"),N.decoder&&(re=N.decoder.write(re)),!(N.objectMode&&re==null)&&!(!N.objectMode&&(!re||!re.length))){var Ct=w.push(re);Ct||(D=!0,b.pause())}});for(var pe in b)this[pe]===void 0&&typeof b[pe]=="function"&&(this[pe]=function(Ct){return function(){return b[Ct].apply(b,arguments)}}(pe));for(var X=0;X<E.length;X++)b.on(E[X],this.emit.bind(this,E[X]));return this._read=function(re){u("wrapped _read",re),D&&(D=!1,b.resume())},this},typeof Symbol=="function"&&(O.prototype[Symbol.asyncIterator]=function(){return x===void 0&&(x=Ah()),x(this)}),Object.defineProperty(O.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(O.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(O.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(w){this._readableState&&(this._readableState.flowing=w)}}),O._fromList=A,Object.defineProperty(O.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function A(b,w){if(w.length===0)return null;var N;return w.objectMode?N=w.buffer.shift():!b||b>=w.length?(w.decoder?N=w.buffer.join(""):w.buffer.length===1?N=w.buffer.first():N=w.buffer.concat(w.length),w.buffer.clear()):N=w.buffer.consume(b,w.decoder),N}function F(b){var w=b._readableState;u("endReadable",w.endEmitted),w.endEmitted||(w.ended=!0,process.nextTick(q,w,b))}function q(b,w){if(u("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,w.readable=!1,w.emit("end"),b.autoDestroy)){var N=w._writableState;(!N||N.autoDestroy&&N.finished)&&w.destroy()}}typeof Symbol=="function"&&(O.from=function(b,w){return g===void 0&&(g=kh()),g(O,b,w)});function Y(b,w){for(var N=0,D=b.length;N<D;N++)if(b[N]===w)return N;return-1}return ns}var fc=Bt,gi=yr.codes,Th=gi.ERR_METHOD_NOT_IMPLEMENTED,Bh=gi.ERR_MULTIPLE_CALLBACK,Ih=gi.ERR_TRANSFORM_ALREADY_TRANSFORMING,Ph=gi.ERR_TRANSFORM_WITH_LENGTH_0,_i=Hr();Oe(Bt,_i);function Oh(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new Bh);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Bt(e){if(!(this instanceof Bt))return new Bt(e);_i.call(this,e),this._transformState={afterTransform:Oh.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.on("prefinish",Rh)}function Rh(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Do(e,t,r)}):Do(this,null,null)}Bt.prototype.push=function(e,t){return this._transformState.needTransform=!1,_i.prototype.push.call(this,e,t)};Bt.prototype._transform=function(e,t,r){r(new Th("_transform()"))};Bt.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}};Bt.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};Bt.prototype._destroy=function(e,t){_i.prototype._destroy.call(this,e,function(r){t(r)})};function Do(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Ph;if(e._transformState.transforming)throw new Ih;return e.push(null)}var Ch=bn,uc=fc;Oe(bn,uc);function bn(e){if(!(this instanceof bn))return new bn(e);uc.call(this,e)}bn.prototype._transform=function(e,t,r){r(null,e)};var is;function Uh(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var lc=yr.codes,Lh=lc.ERR_MISSING_ARGS,Nh=lc.ERR_STREAM_DESTROYED;function $o(e){if(e)throw e}function Fh(e){return e.setHeader&&typeof e.abort=="function"}function Hh(e,t,r,n){n=Uh(n);var i=!1;e.on("close",function(){i=!0}),is===void 0&&(is=qs),is(e,{readable:t,writable:r},function(o){if(o)return n(o);i=!0,n()});var s=!1;return function(o){if(!i&&!s){if(s=!0,Fh(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new Nh("pipe"))}}}function jo(e){e()}function Mh(e,t){return e.pipe(t)}function Dh(e){return!e.length||typeof e[e.length-1]!="function"?$o:e.pop()}function $h(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=Dh(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Lh("streams");var i,s=t.map(function(o,a){var u=a<t.length-1,h=a>0;return Hh(o,u,h,function(d){i||(i=d),d&&s.forEach(jo),!u&&(s.forEach(jo),n(i))})});return t.reduce(Mh)}var jh=$h;(function(e,t){t=e.exports=cc(),t.Stream=t,t.Readable=t,t.Writable=oc(),t.Duplex=Hr(),t.Transform=fc,t.PassThrough=Ch,t.finished=qs,t.pipeline=jh})(_s,_s.exports);var hc=_s.exports,ni=Ve.Buffer,dc=hc.Transform,Gh=Oe;function Vh(e,t){if(!ni.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Yt(e){dc.call(this),this._block=ni.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}Gh(Yt,dc);Yt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Yt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Yt.prototype.update=function(e,t){if(Vh(e,"Data"),this._finalized)throw new Error("Digest already called");ni.isBuffer(e)||(e=ni.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};Yt.prototype._update=function(){throw new Error("_update is not implemented")};Yt.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();e!==void 0&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t};Yt.prototype._digest=function(){throw new Error("_digest is not implemented")};var zh=Yt,qh=Oe,pc=zh,Wh=Ve.Buffer,Kh=new Array(16);function vi(){pc.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}qh(vi,pc);vi.prototype._update=function(){for(var e=Kh,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,s=this._d;r=Re(r,n,i,s,e[0],3614090360,7),s=Re(s,r,n,i,e[1],3905402710,12),i=Re(i,s,r,n,e[2],606105819,17),n=Re(n,i,s,r,e[3],3250441966,22),r=Re(r,n,i,s,e[4],4118548399,7),s=Re(s,r,n,i,e[5],1200080426,12),i=Re(i,s,r,n,e[6],2821735955,17),n=Re(n,i,s,r,e[7],4249261313,22),r=Re(r,n,i,s,e[8],1770035416,7),s=Re(s,r,n,i,e[9],2336552879,12),i=Re(i,s,r,n,e[10],4294925233,17),n=Re(n,i,s,r,e[11],2304563134,22),r=Re(r,n,i,s,e[12],1804603682,7),s=Re(s,r,n,i,e[13],4254626195,12),i=Re(i,s,r,n,e[14],2792965006,17),n=Re(n,i,s,r,e[15],1236535329,22),r=Ce(r,n,i,s,e[1],4129170786,5),s=Ce(s,r,n,i,e[6],3225465664,9),i=Ce(i,s,r,n,e[11],643717713,14),n=Ce(n,i,s,r,e[0],3921069994,20),r=Ce(r,n,i,s,e[5],3593408605,5),s=Ce(s,r,n,i,e[10],38016083,9),i=Ce(i,s,r,n,e[15],3634488961,14),n=Ce(n,i,s,r,e[4],3889429448,20),r=Ce(r,n,i,s,e[9],568446438,5),s=Ce(s,r,n,i,e[14],3275163606,9),i=Ce(i,s,r,n,e[3],4107603335,14),n=Ce(n,i,s,r,e[8],1163531501,20),r=Ce(r,n,i,s,e[13],2850285829,5),s=Ce(s,r,n,i,e[2],4243563512,9),i=Ce(i,s,r,n,e[7],1735328473,14),n=Ce(n,i,s,r,e[12],2368359562,20),r=Ue(r,n,i,s,e[5],4294588738,4),s=Ue(s,r,n,i,e[8],2272392833,11),i=Ue(i,s,r,n,e[11],1839030562,16),n=Ue(n,i,s,r,e[14],4259657740,23),r=Ue(r,n,i,s,e[1],2763975236,4),s=Ue(s,r,n,i,e[4],1272893353,11),i=Ue(i,s,r,n,e[7],4139469664,16),n=Ue(n,i,s,r,e[10],3200236656,23),r=Ue(r,n,i,s,e[13],681279174,4),s=Ue(s,r,n,i,e[0],3936430074,11),i=Ue(i,s,r,n,e[3],3572445317,16),n=Ue(n,i,s,r,e[6],76029189,23),r=Ue(r,n,i,s,e[9],3654602809,4),s=Ue(s,r,n,i,e[12],3873151461,11),i=Ue(i,s,r,n,e[15],530742520,16),n=Ue(n,i,s,r,e[2],3299628645,23),r=Le(r,n,i,s,e[0],4096336452,6),s=Le(s,r,n,i,e[7],1126891415,10),i=Le(i,s,r,n,e[14],2878612391,15),n=Le(n,i,s,r,e[5],4237533241,21),r=Le(r,n,i,s,e[12],1700485571,6),s=Le(s,r,n,i,e[3],2399980690,10),i=Le(i,s,r,n,e[10],4293915773,15),n=Le(n,i,s,r,e[1],2240044497,21),r=Le(r,n,i,s,e[8],1873313359,6),s=Le(s,r,n,i,e[15],4264355552,10),i=Le(i,s,r,n,e[6],2734768916,15),n=Le(n,i,s,r,e[13],1309151649,21),r=Le(r,n,i,s,e[4],4149444226,6),s=Le(s,r,n,i,e[11],3174756917,10),i=Le(i,s,r,n,e[2],718787259,15),n=Le(n,i,s,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+s|0};vi.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Wh.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};function Ei(e,t){return e<<t|e>>>32-t}function Re(e,t,r,n,i,s,o){return Ei(e+(t&r|~t&n)+i+s|0,o)+t|0}function Ce(e,t,r,n,i,s,o){return Ei(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ue(e,t,r,n,i,s,o){return Ei(e+(t^r^n)+i+s|0,o)+t|0}function Le(e,t,r,n,i,s,o){return Ei(e+(r^(t|~n))+i+s|0,o)+t|0}var Yh=vi,ii=Ve.Buffer,yc=hc.Transform,Xh=Oe;function Jh(e,t){if(!ii.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Xt(e){yc.call(this),this._block=ii.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}Xh(Xt,yc);Xt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Xt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Xt.prototype.update=function(e,t){if(Jh(e,"Data"),this._finalized)throw new Error("Digest already called");ii.isBuffer(e)||(e=ii.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};Xt.prototype._update=function(){throw new Error("_update is not implemented")};Xt.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();e!==void 0&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t};Xt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Qh=Xt,ss=It.Buffer,Zh=Oe,mc=Qh,ed=new Array(16),Xr=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],Jr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],Qr=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],Zr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],en=[0,1518500249,1859775393,2400959708,2840853838],tn=[1352829926,1548603684,1836072691,2053994217,0];function xi(){mc.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}Zh(xi,mc);xi.prototype._update=function(){for(var e=ed,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._a|0,u=this._b|0,h=this._c|0,d=this._d|0,m=this._e|0,_=0;_<80;_+=1){var p,I;_<16?(p=Go(r,n,i,s,o,e[Xr[_]],en[0],Qr[_]),I=Wo(a,u,h,d,m,e[Jr[_]],tn[0],Zr[_])):_<32?(p=Vo(r,n,i,s,o,e[Xr[_]],en[1],Qr[_]),I=qo(a,u,h,d,m,e[Jr[_]],tn[1],Zr[_])):_<48?(p=zo(r,n,i,s,o,e[Xr[_]],en[2],Qr[_]),I=zo(a,u,h,d,m,e[Jr[_]],tn[2],Zr[_])):_<64?(p=qo(r,n,i,s,o,e[Xr[_]],en[3],Qr[_]),I=Vo(a,u,h,d,m,e[Jr[_]],tn[3],Zr[_])):(p=Wo(r,n,i,s,o,e[Xr[_]],en[4],Qr[_]),I=Go(a,u,h,d,m,e[Jr[_]],tn[4],Zr[_])),r=o,o=s,s=cr(i,10),i=n,n=p,a=m,m=d,d=cr(h,10),h=u,u=I}var B=this._b+i+d|0;this._b=this._c+s+m|0,this._c=this._d+o+a|0,this._d=this._e+r+u|0,this._e=this._a+n+h|0,this._a=B};xi.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=ss.alloc?ss.alloc(20):new ss(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};function cr(e,t){return e<<t|e>>>32-t}function Go(e,t,r,n,i,s,o,a){return cr(e+(t^r^n)+s+o|0,a)+i|0}function Vo(e,t,r,n,i,s,o,a){return cr(e+(t&r|~t&n)+s+o|0,a)+i|0}function zo(e,t,r,n,i,s,o,a){return cr(e+((t|~r)^n)+s+o|0,a)+i|0}function qo(e,t,r,n,i,s,o,a){return cr(e+(t&n|r&~n)+s+o|0,a)+i|0}function Wo(e,t,r,n,i,s,o,a){return cr(e+(t^(r|~n))+s+o|0,a)+i|0}var td=xi,bc={exports:{}},wc=Ve.Buffer;function Si(e,t){this._block=wc.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}Si.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=wc.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,s=this._len,o=0;o<i;){for(var a=s%n,u=Math.min(i-o,n-a),h=0;h<u;h++)r[a+h]=e[o+h];s+=u,o+=u,s%n===0&&this._update(r)}return this._len+=i,this};Si.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=this._len*8;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(r&4294967295)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var s=this._hash();return e?s.toString(e):s};Si.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Dr=Si,rd=Oe,gc=Dr,nd=Ve.Buffer,id=[1518500249,1859775393,-1894007588,-899497514],sd=new Array(80);function Sn(){this.init(),this._w=sd,gc.call(this,64,56)}rd(Sn,gc);Sn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function od(e){return e<<5|e>>>27}function ad(e){return e<<30|e>>>2}function cd(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Sn.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=t[a-3]^t[a-8]^t[a-14]^t[a-16];for(var u=0;u<80;++u){var h=~~(u/20),d=od(r)+cd(h,n,i,s)+o+t[u]+id[h]|0;o=s,s=i,i=ad(n),n=r,r=d}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0};Sn.prototype._hash=function(){var e=nd.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var fd=Sn,ud=Oe,_c=Dr,ld=Ve.Buffer,hd=[1518500249,1859775393,-1894007588,-899497514],dd=new Array(80);function An(){this.init(),this._w=dd,_c.call(this,64,56)}ud(An,_c);An.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function pd(e){return e<<1|e>>>31}function yd(e){return e<<5|e>>>27}function md(e){return e<<30|e>>>2}function bd(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}An.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=pd(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var u=0;u<80;++u){var h=~~(u/20),d=yd(r)+bd(h,n,i,s)+o+t[u]+hd[h]|0;o=s,s=i,i=md(n),n=r,r=d}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0};An.prototype._hash=function(){var e=ld.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var wd=An,gd=Oe,vc=Dr,_d=Ve.Buffer,vd=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],Ed=new Array(64);function kn(){this.init(),this._w=Ed,vc.call(this,64,56)}gd(kn,vc);kn.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this};function xd(e,t,r){return r^e&(t^r)}function Sd(e,t,r){return e&t|r&(e|t)}function Ad(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function kd(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function Td(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function Bd(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}kn.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._f|0,u=this._g|0,h=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=Bd(t[d-2])+t[d-7]+Td(t[d-15])+t[d-16]|0;for(var m=0;m<64;++m){var _=h+kd(o)+xd(o,a,u)+vd[m]+t[m]|0,p=Ad(r)+Sd(r,n,i)|0;h=u,u=a,a=o,o=s+_|0,s=i,i=n,n=r,r=_+p|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0,this._f=a+this._f|0,this._g=u+this._g|0,this._h=h+this._h|0};kn.prototype._hash=function(){var e=_d.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var Ec=kn,Id=Oe,Pd=Ec,Od=Dr,Rd=Ve.Buffer,Cd=new Array(64);function Ai(){this.init(),this._w=Cd,Od.call(this,64,56)}Id(Ai,Pd);Ai.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this};Ai.prototype._hash=function(){var e=Rd.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var Ud=Ai,Ld=Oe,xc=Dr,Nd=Ve.Buffer,Ko=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],Fd=new Array(160);function Tn(){this.init(),this._w=Fd,xc.call(this,128,112)}Ld(Tn,xc);Tn.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this};function Yo(e,t,r){return r^e&(t^r)}function Xo(e,t,r){return e&t|r&(e|t)}function Jo(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function Qo(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function Hd(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function Md(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function Dd(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function $d(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Te(e,t){return e>>>0<t>>>0?1:0}Tn.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,s=this._dh|0,o=this._eh|0,a=this._fh|0,u=this._gh|0,h=this._hh|0,d=this._al|0,m=this._bl|0,_=this._cl|0,p=this._dl|0,I=this._el|0,B=this._fl|0,T=this._gl|0,R=this._hl|0,U=0;U<32;U+=2)t[U]=e.readInt32BE(U*4),t[U+1]=e.readInt32BE(U*4+4);for(;U<160;U+=2){var x=t[U-30],g=t[U-15*2+1],S=Hd(x,g),E=Md(g,x);x=t[U-2*2],g=t[U-2*2+1];var H=Dd(x,g),M=$d(g,x),O=t[U-7*2],K=t[U-7*2+1],C=t[U-16*2],j=t[U-16*2+1],G=E+K|0,V=S+O+Te(G,E)|0;G=G+M|0,V=V+H+Te(G,M)|0,G=G+j|0,V=V+C+Te(G,j)|0,t[U]=V,t[U+1]=G}for(var ee=0;ee<160;ee+=2){V=t[ee],G=t[ee+1];var ve=Xo(r,n,i),ze=Xo(d,m,_),rt=Jo(r,d),qe=Jo(d,r),Ot=Qo(o,I),de=Qo(I,o),Ee=Ko[ee],We=Ko[ee+1],Rt=Yo(o,a,u),pt=Yo(I,B,T),k=R+de|0,A=h+Ot+Te(k,R)|0;k=k+pt|0,A=A+Rt+Te(k,pt)|0,k=k+We|0,A=A+Ee+Te(k,We)|0,k=k+G|0,A=A+V+Te(k,G)|0;var F=qe+ze|0,q=rt+ve+Te(F,qe)|0;h=u,R=T,u=a,T=B,a=o,B=I,I=p+k|0,o=s+A+Te(I,p)|0,s=i,p=_,i=n,_=m,n=r,m=d,d=k+F|0,r=A+q+Te(d,k)|0}this._al=this._al+d|0,this._bl=this._bl+m|0,this._cl=this._cl+_|0,this._dl=this._dl+p|0,this._el=this._el+I|0,this._fl=this._fl+B|0,this._gl=this._gl+T|0,this._hl=this._hl+R|0,this._ah=this._ah+r+Te(this._al,d)|0,this._bh=this._bh+n+Te(this._bl,m)|0,this._ch=this._ch+i+Te(this._cl,_)|0,this._dh=this._dh+s+Te(this._dl,p)|0,this._eh=this._eh+o+Te(this._el,I)|0,this._fh=this._fh+a+Te(this._fl,B)|0,this._gh=this._gh+u+Te(this._gl,T)|0,this._hh=this._hh+h+Te(this._hl,R)|0};Tn.prototype._hash=function(){var e=Nd.allocUnsafe(64);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var Sc=Tn,jd=Oe,Gd=Sc,Vd=Dr,zd=Ve.Buffer,qd=new Array(160);function ki(){this.init(),this._w=qd,Vd.call(this,128,112)}jd(ki,Gd);ki.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this};ki.prototype._hash=function(){var e=zd.allocUnsafe(48);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var Wd=ki,mr=bc.exports=function(t){t=t.toLowerCase();var r=mr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};mr.sha=fd;mr.sha1=wd;mr.sha224=Ud;mr.sha256=Ec;mr.sha384=Wd;mr.sha512=Sc;var Kd=bc.exports,lt=Ve.Buffer,Ac=Vs.Transform,Yd=ri.StringDecoder,Xd=Oe;function it(e){Ac.call(this),this.hashMode=typeof e=="string",this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}Xd(it,Ac);var Jd=typeof Uint8Array<"u",Qd=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(lt.prototype instanceof Uint8Array||lt.TYPED_ARRAY_SUPPORT);function Zd(e,t){if(e instanceof lt)return e;if(typeof e=="string")return lt.from(e,t);if(Qd&&ArrayBuffer.isView(e)){if(e.byteLength===0)return lt.alloc(0);var r=lt.from(e.buffer,e.byteOffset,e.byteLength);if(r.byteLength===e.byteLength)return r}if(Jd&&e instanceof Uint8Array||lt.isBuffer(e)&&e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return lt.from(e);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}it.prototype.update=function(e,t,r){var n=Zd(e,t),i=this._update(n);return this.hashMode?this:(r&&(i=this._toString(i,r)),i)};it.prototype.setAutoPadding=function(){};it.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};it.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};it.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};it.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(i){n=i}finally{r(n)}};it.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};it.prototype._finalOrDigest=function(e){var t=this.__final()||lt.alloc(0);return e&&(t=this._toString(t,e,!0)),t};it.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Yd(t),this._encoding=t),this._encoding!==t)throw new Error("can’t switch encodings");var n=this._decoder.write(e);return r&&(n+=this._decoder.end()),n};var e0=it,t0=Oe,r0=Yh,n0=td,i0=Kd,kc=e0;function Ti(e){kc.call(this,"digest"),this._hash=e}t0(Ti,kc);Ti.prototype._update=function(e){this._hash.update(e)};Ti.prototype._final=function(){return this._hash.digest()};var s0=function(t){return t=t.toLowerCase(),t==="md5"?new r0:t==="rmd160"||t==="ripemd160"?new n0:new Ti(i0(t))},Dn=Ve.Buffer;function o0(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),u=Math.log(o)/Math.log(256),h=Math.log(256)/Math.log(o);function d(p){if((Array.isArray(p)||p instanceof Uint8Array)&&(p=Dn.from(p)),!Dn.isBuffer(p))throw new TypeError("Expected Buffer");if(p.length===0)return"";for(var I=0,B=0,T=0,R=p.length;T!==R&&p[T]===0;)T++,I++;for(var U=(R-T)*h+1>>>0,x=new Uint8Array(U);T!==R;){for(var g=p[T],S=0,E=U-1;(g!==0||S<B)&&E!==-1;E--,S++)g+=256*x[E]>>>0,x[E]=g%o>>>0,g=g/o>>>0;if(g!==0)throw new Error("Non-zero carry");B=S,T++}for(var H=U-B;H!==U&&x[H]===0;)H++;for(var M=a.repeat(I);H<U;++H)M+=e.charAt(x[H]);return M}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return Dn.alloc(0);for(var I=0,B=0,T=0;p[I]===a;)B++,I++;for(var R=(p.length-I)*u+1>>>0,U=new Uint8Array(R);I<p.length;){var x=p.charCodeAt(I);if(x>255)return;var g=t[x];if(g===255)return;for(var S=0,E=R-1;(g!==0||S<T)&&E!==-1;E--,S++)g+=o*U[E]>>>0,U[E]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");T=S,I++}for(var H=R-T;H!==R&&U[H]===0;)H++;var M=Dn.allocUnsafe(B+(R-H));M.fill(0,0,B);for(var O=B;H!==R;)M[O++]=U[H++];return M}function _(p){var I=m(p);if(I)return I;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:m,decode:_}}var a0=o0,c0=a0,f0="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",u0=c0(f0),os=u0,l0=Ve.Buffer,h0=function(e){function t(s){var o=e(s);return os.encode(l0.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),u=e(o);if(!(a[0]^u[0]|a[1]^u[1]|a[2]^u[2]|a[3]^u[3]))return o}function n(s){var o=os.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=os.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},Zo=s0,d0=h0;function p0(e){var t=Zo("sha256").update(e).digest();return Zo("sha256").update(t).digest()}var y0=d0(p0),Es=y0;function Tc(e,t){if(t!==void 0&&e[0]!==t)throw new Error("Invalid network version");if(e.length===33)return{version:e[0],privateKey:e.slice(1,33),compressed:!1};if(e.length!==34)throw new Error("Invalid WIF length");if(e[33]!==1)throw new Error("Invalid compression flag");return{version:e[0],privateKey:e.slice(1,33),compressed:!0}}function xs(e,t,r){var n=new Buffer(r?34:33);return n.writeUInt8(e,0),t.copy(n,1),r&&(n[33]=1),n}function m0(e,t){return Tc(Es.decode(e),t)}function b0(e,t,r){return typeof e=="number"?Es.encode(xs(e,t,r)):Es.encode(xs(e.version,e.privateKey,e.compressed))}var w0={decode:m0,decodeRaw:Tc,encode:b0,encodeRaw:xs},Bi={};Object.defineProperty(Bi,"__esModule",{value:!0});Bi.testEcc=void 0;const W=e=>Buffer.from(e,"hex");function g0(e){ue(e.isPoint(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(!e.isPoint(W("030000000000000000000000000000000000000000000000000000000000000005"))),ue(e.isPrivate(W("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(e.isPrivate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),ue(!e.isPrivate(W("0000000000000000000000000000000000000000000000000000000000000000"))),ue(!e.isPrivate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),ue(!e.isPrivate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),ue(Buffer.from(e.privateAdd(W("0000000000000000000000000000000000000000000000000000000000000001"),W("0000000000000000000000000000000000000000000000000000000000000000"))).equals(W("0000000000000000000000000000000000000000000000000000000000000001"))),ue(e.privateAdd(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),W("0000000000000000000000000000000000000000000000000000000000000003"))===null),ue(Buffer.from(e.privateAdd(W("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),W("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(W("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),ue(Buffer.from(e.privateNegate(W("0000000000000000000000000000000000000000000000000000000000000001"))).equals(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),ue(Buffer.from(e.privateNegate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(W("0000000000000000000000000000000000000000000000000000000000000003"))),ue(Buffer.from(e.privateNegate(W("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(W("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),ue(Buffer.from(e.pointCompress(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(Buffer.from(e.pointCompress(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),ue(Buffer.from(e.pointCompress(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(Buffer.from(e.pointCompress(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),ue(Buffer.from(e.pointFromScalar(W("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(W("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),ue(e.xOnlyPointAddTweak(W("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(W("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),W("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));ue(Buffer.from(t.xOnlyPubkey).equals(W("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(W("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),W("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),ue(Buffer.from(t.xOnlyPubkey).equals(W("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),ue(Buffer.from(e.sign(W("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(W("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),ue(e.verify(W("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),W("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),W("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&ue(Buffer.from(e.signSchnorr(W("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),W("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),W("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(W("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&ue(e.verifySchnorr(W("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),W("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),W("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}Bi.testEcc=g0;function ue(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(Nr,"__esModule",{value:!0});Nr.ECPairFactory=Nr.networks=void 0;const Ss=Fr;Nr.networks=Ss;const $e=qa,_0=$l,ea=w0,v0=Bi,as=$e.typeforce.maybe($e.typeforce.compile({compressed:$e.maybe($e.Boolean),network:$e.maybe($e.Network)})),E0=e=>e.length===32?e:e.slice(1,33);function x0(e){(0,v0.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,u){if($e.typeforce($e.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return $e.typeforce(as,u),new o(a,void 0,u)}function n(a,u){return $e.typeforce(e.isPoint,a),$e.typeforce(as,u),new o(void 0,a,u)}function i(a,u){const h=ea.decode(a),d=h.version;if($e.Array(u)){if(u=u.filter(m=>d===m.wif).pop(),!u)throw new Error("Unknown network version")}else if(u=u||Ss.bitcoin,d!==u.wif)throw new Error("Invalid network version");return r(h.privateKey,{compressed:h.compressed,network:u})}function s(a){$e.typeforce(as,a),a===void 0&&(a={});const u=a.rng||_0;let h;do h=u(32),$e.typeforce($e.Buffer256bit,h);while(!e.isPrivate(h));return r(h,a)}class o{constructor(u,h,d){gr(this,"__D");gr(this,"__Q");gr(this,"compressed");gr(this,"network");gr(this,"lowR");this.__D=u,this.__Q=h,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||Ss.bitcoin,h!==void 0&&(this.__Q=Buffer.from(e.pointCompress(h,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const u=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(u)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return ea.encode(this.network.wif,this.__D,this.compressed)}tweak(u){return this.privateKey?this.tweakFromPrivateKey(u):this.tweakFromPublicKey(u)}sign(u,h){if(!this.__D)throw new Error("Missing private key");if(h===void 0&&(h=this.lowR),h===!1)return Buffer.from(e.sign(u,this.__D));{let d=e.sign(u,this.__D);const m=Buffer.alloc(32,0);let _=0;for(;d[0]>127;)_++,m.writeUIntLE(_,0,6),d=e.sign(u,this.__D,m);return Buffer.from(d)}}signSchnorr(u){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(u,this.privateKey))}verify(u,h){return e.verify(u,this.publicKey,h)}verifySchnorr(u,h){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(u,this.publicKey.subarray(1,33),h)}tweakFromPublicKey(u){const h=E0(this.publicKey),d=e.xOnlyPointAddTweak(h,u);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const m=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([m,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(u){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,m=e.privateAdd(d,u);if(!m)throw new Error("Invalid tweaked private key!");return r(Buffer.from(m),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}Nr.ECPairFactory=x0;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=Nr;Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"ECPairFactory",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"networks",{enumerable:!0,get:function(){return t.networks}})})(za);const S0=If(za);class wn extends z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new wn(rr(t))}static fromWalletClient(t){return new wn(void 0,t)}async initialize(){if(this.digestKey)return ne("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?$(t.error):(this.emit("initialized",!0),ne("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return $("No walletClient found");if(!this.walletClient.account)return $("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.digestKey=rr(Et.sha256(t)),this.emit("initialized",!0),ne(this.digestKey)}catch(t){return $("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return $("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return $(t.error)}return this.digestKey?ne(this.digestKey):$("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return $(r.error);const n=Et.sha256(z.with0x(r.val)),i=Et.sha256(n);return ne({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const h=await this.getDigestKey();if(h.error)return $(h.error);this.digestKey=h.val}const r=S0(sr),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=Et.sha256(i),o=Buffer.from(rr(this.digestKey),"hex");if(o.length!==32)return $("Invalid private key length. Expected 32 bytes.");const u=r.fromPrivateKey(o).sign(Buffer.from(rr(s),"hex"));return ne(u.toString("hex"))}}const A0=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];function dt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const Bc="2.26.3";let rn={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Bc}`};class he extends Error{constructor(t,r={}){var a;const n=(()=>{var u;return r.cause instanceof he?r.cause.details:(u=r.cause)!=null&&u.message?r.cause.message:r.details})(),i=r.cause instanceof he&&r.cause.docsPath||r.docsPath,s=(a=rn.getDocsUrl)==null?void 0:a.call(rn,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...rn.version?[`Version: ${rn.version}`]:[]].join(`
|
|
32
32
|
`);super(o,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=Bc}walk(t){return Ic(this,t)}}function Ic(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?Ic(e.cause,t):t?null:e}class k0 extends he{constructor({max:t,min:r,signed:n,size:i,value:s}){super(`Number "${s}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class T0 extends he{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function Bn(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Mr(e){return Bn(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function si(e,{dir:t="left"}={}){let r=typeof e=="string"?e.replace("0x",""):e,n=0;for(let i=0;i<r.length-1&&r[t==="left"?i:r.length-i-1].toString()==="0";i++)n++;return r=t==="left"?r.slice(n):r.slice(0,r.length-n),typeof e=="string"?(r.length===1&&t==="right"&&(r=`${r}0`),`0x${r.length%2===1?`0${r}`:r}`):r}class B0 extends he{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class Pc extends he{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function $r(e,{dir:t,size:r=32}={}){return typeof e=="string"?I0(e,{dir:t,size:r}):P0(e,{dir:t,size:r})}function I0(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Pc({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function P0(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Pc({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const s=t==="right";n[s?i:r-i-1]=e[s?i:e.length-i-1]}return n}const O0=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Q(e,t={}){return typeof e=="number"||typeof e=="bigint"?Oc(e,t):typeof e=="string"?U0(e,t):typeof e=="boolean"?R0(e,t):Jt(e,t)}function R0(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(jr(r,{size:t.size}),$r(r,{size:t.size})):r}function Jt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=O0[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(jr(n,{size:t.size}),$r(n,{dir:"right",size:t.size})):n}function Oc(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const u=typeof e=="bigint"?"n":"";throw new k0({max:s?`${s}${u}`:void 0,min:`${o}${u}`,signed:r,size:n,value:`${e}${u}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?$r(a,{size:n}):a}const C0=new TextEncoder;function U0(e,t={}){const r=C0.encode(e);return Jt(r,t)}const L0=new TextEncoder;function Rc(e,t={}){return typeof e=="number"||typeof e=="bigint"?F0(e,t):typeof e=="boolean"?N0(e,t):Bn(e)?fr(e,t):Cc(e,t)}function N0(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(jr(r,{size:t.size}),$r(r,{size:t.size})):r}const gt={zero:48,nine:57,A:65,F:70,a:97,f:102};function ta(e){if(e>=gt.zero&&e<=gt.nine)return e-gt.zero;if(e>=gt.A&&e<=gt.F)return e-(gt.A-10);if(e>=gt.a&&e<=gt.f)return e-(gt.a-10)}function fr(e,t={}){let r=e;t.size&&(jr(r,{size:t.size}),r=$r(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,s=new Uint8Array(i);for(let o=0,a=0;o<i;o++){const u=ta(n.charCodeAt(a++)),h=ta(n.charCodeAt(a++));if(u===void 0||h===void 0)throw new he(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=u*16+h}return s}function F0(e,t){const r=Oc(e,t);return fr(r)}function Cc(e,t={}){const r=L0.encode(e);return typeof t.size=="number"?(jr(r,{size:t.size}),$r(r,{dir:"right",size:t.size})):r}function jr(e,{size:t}){if(Mr(e)>t)throw new T0({givenSize:Mr(e),maxSize:t})}function Tr(e,t={}){const{signed:r}=t;t.size&&jr(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,s=(1n<<BigInt(i)*8n-1n)-1n;return n<=s?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function oi(e,t={}){return Number(Tr(e,t))}function Ws(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const s=t(i);if(r)for(const o of r)delete s[o];return{...s,...n(i)}},type:e})}const Uc={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Ks(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?oi(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?oi(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?Uc[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(t.authorizationList=M0(e.authorizationList)),t.yParity=(()=>{if(e.yParity)return Number(e.yParity);if(typeof t.v=="bigint"){if(t.v===0n||t.v===27n)return 0;if(t.v===1n||t.v===28n)return 1;if(t.v>=35n)return t.v%2n===0n?1:0}})(),t.type==="legacy"&&(delete t.accessList,delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas,delete t.yParity),t.type==="eip2930"&&(delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas),t.type==="eip1559"&&delete t.maxFeePerBlobGas,t}const H0=Ws("transaction",Ks);function M0(e){return e.map(t=>({address:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function D0(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:Ks(r));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const $0=Ws("block",D0);function j0(e,{args:t,eventName:r}={}){return{...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,logIndex:e.logIndex?Number(e.logIndex):null,transactionHash:e.transactionHash?e.transactionHash:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,...r?{args:t,eventName:r}:{}}}const G0={"0x0":"reverted","0x1":"success"};function V0(e){const t={...e,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,contractAddress:e.contractAddress?e.contractAddress:null,cumulativeGasUsed:e.cumulativeGasUsed?BigInt(e.cumulativeGasUsed):null,effectiveGasPrice:e.effectiveGasPrice?BigInt(e.effectiveGasPrice):null,gasUsed:e.gasUsed?BigInt(e.gasUsed):null,logs:e.logs?e.logs.map(r=>j0(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?oi(e.transactionIndex):null,status:e.status?G0[e.status]:null,type:e.type?Uc[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const z0=Ws("transactionReceipt",V0),Ys=2n**256n-1n;function In(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class ra extends he{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class q0 extends he{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class W0 extends he{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const K0={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new W0({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new q0({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ra({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new ra({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const r=t??this.position;return this.assertPosition(r+e-1),this.bytes.subarray(r,r+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const r=this.inspectBytes(e);return this.position+=t??e,r},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Lc(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(K0);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function ur(e,t="hex"){const r=Nc(e),n=Lc(new Uint8Array(r.length));return r.encode(n),t==="hex"?Jt(n.bytes):n.bytes}function Nc(e){return Array.isArray(e)?Y0(e.map(t=>Nc(t))):X0(e)}function Y0(e){const t=e.reduce((i,s)=>i+s.length,0),r=Fc(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:s}of e)s(i)}}}function X0(e){const t=typeof e=="string"?fr(e):e,r=Fc(t.length);return{length:t.length===1&&t[0]<128?1:t.length<=55?1+t.length:1+r+t.length,encode(i){t.length===1&&t[0]<128?i.pushBytes(t):t.length<=55?(i.pushByte(128+t.length),i.pushBytes(t)):(i.pushByte(183+r),r===1?i.pushUint8(t.length):r===2?i.pushUint16(t.length):r===3?i.pushUint24(t.length):i.pushUint32(t.length),i.pushBytes(t))}}}function Fc(e){if(e<2**8)return 1;if(e<2**16)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new he("Length is too large.")}const J0={ether:-9,wei:9};function Q0(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,s]=[r.slice(0,r.length-t),r.slice(r.length-t)];return s=s.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${s?`.${s}`:""}`}function As(e,t="wei"){return Q0(e,J0[t])}function Z0(e){const t=Object.entries(e).map(([n,i])=>i===void 0||i===!1?null:[n,i]).filter(Boolean),r=t.reduce((n,[i])=>Math.max(n,i.length),0);return t.map(([n,i])=>` ${`${n}:`.padEnd(r+1)} ${i}`).join(`
|
|
33
33
|
`)}class ep extends he{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class tp extends he{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Z0(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:"InvalidSerializableTransactionError"})}}class rp extends he{constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}function np(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{chainId:n,nonce:i,...s}=r,o=r.address;t.push([n?Q(n):"0x",o,i?Q(i):"0x",...Pn({},s)])}return t}function Hc(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(s=>fr(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>Jt(s))}function Mc(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(o=>fr(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>fr(o)):e.commitments,s=[];for(let o=0;o<n.length;o++){const a=n[o],u=i[o];s.push(Uint8Array.from(t.computeBlobKzgProof(a,u)))}return r==="bytes"?s:s.map(o=>Jt(o))}function ip(e,t){return Ua(Bn(e,{strict:!1})?Rc(e):e)}function sp(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=ip(t);return i.set([r],0),n==="bytes"?i:Jt(i)}function op(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const s of t)i.push(sp({commitment:s,to:n,version:r}));return i}const na=6,Dc=32,Xs=4096,$c=Dc*Xs,ia=$c*na-1-1*Xs*na,jc=1;class ap extends he{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Gc extends he{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class cp extends he{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class fp extends he{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${jc}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function up(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?fr(e.data):e.data,n=Mr(r);if(!n)throw new Gc;if(n>ia)throw new ap({maxSize:ia,size:n});const i=[];let s=!0,o=0;for(;s;){const a=Lc(new Uint8Array($c));let u=0;for(;u<Xs;){const h=r.slice(o,o+(Dc-1));if(a.pushByte(0),a.pushBytes(h),h.length<31){a.pushByte(128),s=!1;break}u++,o+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>Jt(a.bytes))}function lp(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??up({data:t,to:n}),s=e.commitments??Hc({blobs:i,kzg:r,to:n}),o=e.proofs??Mc({blobs:i,commitments:s,kzg:r,to:n}),a=[];for(let u=0;u<i.length;u++)a.push({blob:i[u],commitment:s[u],proof:o[u]});return a}class lr extends he{constructor({address:t}){super(`Address "${t}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class Ii extends he{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class Pi extends he{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${As(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Pi,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class Vc extends he{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${As(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${As(n)} gwei`:""}).`].join(`
|
|
34
|
-
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Vc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class zc extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}function sa(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function hp(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Js(e,...t){if(!hp(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function oa(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function dp(e,t){Js(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const $n=BigInt(2**32-1),aa=BigInt(32);function pp(e,t=!1){return t?{h:Number(e&$n),l:Number(e>>aa&$n)}:{h:Number(e>>aa&$n)|0,l:Number(e&$n)|0}}function yp(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:s,l:o}=pp(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const mp=(e,t,r)=>e<<r|t>>>32-r,bp=(e,t,r)=>t<<r|e>>>32-r,wp=(e,t,r)=>t<<r-32|e>>>64-r,gp=(e,t,r)=>e<<r-32|t>>>64-r;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _p(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}const ca=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function vp(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function fa(e){for(let t=0;t<e.length;t++)e[t]=vp(e[t])}function Ep(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function qc(e){return typeof e=="string"&&(e=Ep(e)),Js(e),e}class xp{clone(){return this._cloneInto()}}function Sp(e){const t=n=>e().update(qc(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}const Wc=[],Kc=[],Yc=[],Ap=BigInt(0),nn=BigInt(1),kp=BigInt(2),Tp=BigInt(7),Bp=BigInt(256),Ip=BigInt(113);for(let e=0,t=nn,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Wc.push(2*(5*n+r)),Kc.push((e+1)*(e+2)/2%64);let i=Ap;for(let s=0;s<7;s++)t=(t<<nn^(t>>Tp)*Ip)%Bp,t&kp&&(i^=nn<<(nn<<BigInt(s))-nn);Yc.push(i)}const[Pp,Op]=yp(Yc,!0),ua=(e,t,r)=>r>32?wp(e,t,r):mp(e,t,r),la=(e,t,r)=>r>32?gp(e,t,r):bp(e,t,r);function Rp(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)r[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,u=(o+2)%10,h=r[u],d=r[u+1],m=ua(h,d,1)^r[a],_=la(h,d,1)^r[a+1];for(let p=0;p<50;p+=10)e[o+p]^=m,e[o+p+1]^=_}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=Kc[o],u=ua(i,s,a),h=la(i,s,a),d=Wc[o];i=e[d],s=e[d+1],e[d]=u,e[d+1]=h}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=Pp[n],e[1]^=Op[n]}r.fill(0)}class Qs extends xp{constructor(t,r,n,i=!1,s=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,sa(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=_p(this.state)}keccak(){ca||fa(this.state32),Rp(this.state32,this.rounds),ca||fa(this.state32),this.posOut=0,this.pos=0}update(t){oa(this);const{blockLen:r,state:n}=this;t=qc(t);const i=t.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=t[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){oa(this,!1),Js(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=t.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);t.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return sa(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(dp(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return t||(t=new Qs(r,n,i,o,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}}const Cp=(e,t,r)=>Sp(()=>new Qs(t,e,r)),Up=Cp(1,136,256/8);function Lp(e,t){return Up(Bn(e,{strict:!1})?Rc(e):e)}const cs=new zc(8192);function Np(e,t){if(cs.has(`${e}.${t}`))return cs.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Lp(Cc(r)),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return cs.set(`${e}.${t}`,s),s}const Fp=/^0x[a-fA-F0-9]{40}$/,fs=new zc(8192);function hr(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(fs.has(n))return fs.get(n);const i=Fp.test(e)?e.toLowerCase()===e?!0:r?Np(e)===e:!0:!1;return fs.set(n,i),i}function Hp(e,t,r,{strict:n}={}){return Bn(e,{strict:!1})?Dp(e,t,r,{strict:n}):Mp(e,t,r,{strict:n})}function Xc(e,t,r){if(Mr(e)!==r-t)throw new B0({offset:r,position:"end",size:Mr(e)})}function Mp(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&Xc(i,t,r),i}function Dp(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&Xc(i,t,r),i}function $p(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!hr(i))throw new lr({address:i});if(n<0)throw new Ii({chainId:n})}Zs(e)}function jp(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Gc;for(const r of t){const n=Mr(r),i=oi(Hp(r,0,1));if(n!==32)throw new cp({hash:r,size:n});if(i!==jc)throw new fp({hash:r,version:i})}}Zs(e)}function Zs(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Ii({chainId:t});if(i&&!hr(i))throw new lr({address:i});if(n&&n>Ys)throw new Pi({maxFeePerGas:n});if(r&&n&&r>n)throw new Vc({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Gp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new Ii({chainId:t});if(s&&!hr(s))throw new lr({address:s});if(r||i)throw new he("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ys)throw new Pi({maxFeePerGas:n})}function Vp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!hr(s))throw new lr({address:s});if(typeof t<"u"&&t<=0)throw new Ii({chainId:t});if(r||i)throw new he("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ys)throw new Pi({maxFeePerGas:n})}function zp(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new tp({transaction:e})}function Oi(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let s=0;s<i.length;s++)if(i[s].length-2!==64)throw new rp({storageKey:i[s]});if(!hr(n,{strict:!1}))throw new lr({address:n});t.push([n,i])}return t}function qp(e,t){const r=zp(e);return r==="eip1559"?Yp(e,t):r==="eip2930"?Xp(e,t):r==="eip4844"?Kp(e,t):r==="eip7702"?Wp(e,t):Jp(e,t)}function Wp(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:u,maxPriorityFeePerGas:h,accessList:d,data:m}=e;$p(e);const _=Oi(d),p=np(r);return In(["0x04",ur([Q(n),s?Q(s):"0x",h?Q(h):"0x",u?Q(u):"0x",i?Q(i):"0x",o??"0x",a?Q(a):"0x",m??"0x",_,p,...Pn(e,t)])])}function Kp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:u,maxPriorityFeePerGas:h,accessList:d,data:m}=e;jp(e);let _=e.blobVersionedHashes,p=e.sidecars;if(e.blobs&&(typeof _>"u"||typeof p>"u")){const x=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(E=>Jt(E)),g=e.kzg,S=Hc({blobs:x,kzg:g});if(typeof _>"u"&&(_=op({commitments:S})),typeof p>"u"){const E=Mc({blobs:x,commitments:S,kzg:g});p=lp({blobs:x,commitments:S,proofs:E})}}const I=Oi(d),B=[Q(r),i?Q(i):"0x",h?Q(h):"0x",u?Q(u):"0x",n?Q(n):"0x",s??"0x",o?Q(o):"0x",m??"0x",I,a?Q(a):"0x",_??[],...Pn(e,t)],T=[],R=[],U=[];if(p)for(let x=0;x<p.length;x++){const{blob:g,commitment:S,proof:E}=p[x];T.push(g),R.push(S),U.push(E)}return In(["0x03",ur(p?[B,T,R,U]:B)])}function Yp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:u,accessList:h,data:d}=e;Zs(e);const m=Oi(h),_=[Q(r),i?Q(i):"0x",u?Q(u):"0x",a?Q(a):"0x",n?Q(n):"0x",s??"0x",o?Q(o):"0x",d??"0x",m,...Pn(e,t)];return In(["0x02",ur(_)])}function Xp(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:u,gasPrice:h}=e;Gp(e);const d=Oi(u),m=[Q(r),s?Q(s):"0x",h?Q(h):"0x",n?Q(n):"0x",o??"0x",a?Q(a):"0x",i??"0x",d,...Pn(e,t)];return In(["0x01",ur(m)])}function Jp(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:u}=e;Vp(e);let h=[s?Q(s):"0x",u?Q(u):"0x",n?Q(n):"0x",o??"0x",a?Q(a):"0x",i??"0x"];if(t){const d=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const p=27n+(t.v===27n?0n:1n);if(t.v!==p)throw new ep({v:t.v});return p})(),m=si(t.r),_=si(t.s);h=[...h,Q(d),m==="0x00"?"0x":m,_==="0x00"?"0x":_]}else r>0&&(h=[...h,Q(r),"0x","0x"]);return ur(h)}function Pn(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const s=si(r.r),o=si(r.s);return[typeof i=="number"?i?Q(1):"0x":n===0n?"0x":n===1n?Q(1):n===27n?"0x":Q(1),s==="0x00"?"0x":s,o==="0x00"?"0x":o]}const Qp={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},Zp={block:$0({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Ks(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?Tr(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:H0({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?Tr(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:z0({format(e){return{l1GasPrice:e.l1GasPrice?Tr(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?Tr(e.l1GasUsed):null,l1Fee:e.l1Fee?Tr(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function ey(e,t){return ny(e)?ry(e):qp(e,t)}const ty={transaction:ey};function ry(e){iy(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:u}=e,h=[t,n,a??"0x",o?Q(o):"0x",u?Q(u):"0x",i?Q(i):"0x",s?"0x1":"0x",r??"0x"];return In(["0x7e",ur(h)])}function ny(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function iy(e){const{from:t,to:r}=e;if(t&&!hr(t))throw new lr({address:t});if(r&&!hr(r))throw new lr({address:r})}const ai={contracts:Qp,formatters:Zp,serializers:ty},sy=dt({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),oy=dt({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),sn=1,ay=dt({...ai,id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://basescan.org",apiUrl:"https://api.basescan.org/api"}},contracts:{...ai.contracts,disputeGameFactory:{[sn]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[sn]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[sn]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[sn]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:sn}),on=11155111,cy=dt({...ai,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...ai.contracts,disputeGameFactory:{[on]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[on]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[on]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[on]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:on}),fy=dt({id:80094,name:"Berachain",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:0},ensRegistry:{address:"0x5b22280886a2f5e09a49bea7e320eab0e5320e28",blockCreated:877007},ensUniversalResolver:{address:"0xddfb18888a9466688235887dec2a10c4f5effee9",blockCreated:877008}},rpcUrls:{default:{http:["https://rpc.berachain.com"]}},blockExplorers:{default:{name:"Berascan",url:"https://berascan.com"}},ensTlds:[".bera"],testnet:!1}),uy=dt({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269},ensRegistry:{address:"0xB0eef18971290b333450586D33dcA6cE122651D2",blockCreated:7736794},ensUniversalResolver:{address:"0x41692Ef1EA0C79E6b73077E4A67572D2BDbD7057",blockCreated:7736795}},ensTlds:[".bera"],rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),ly=dt({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"cBTC",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api"}},testnet:!0}),hy=dt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),dy=dt({id:10143,name:"Monad Testnet",nativeCurrency:{name:"Testnet MON Token",symbol:"MON",decimals:18},rpcUrls:{default:{http:["https://testnet-rpc.monad.xyz"]}},blockExplorers:{default:{name:"Monad Testnet explorer",url:"https://testnet.monadexplorer.com"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:251449}},testnet:!0}),py=dt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.drpc.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0}),yy={...py,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Jc={id:998,name:"Hyperliquid EVM Testnet",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://testnet.purrsec.com/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid-testnet.xyz/evm"]}}},Qc={id:999,name:"HyperEVM",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://hyperscan.gas.zip/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid.xyz/evm"]}}},Zc={ethereum:hy,arbitrum:sy,ethereum_sepolia:yy,arbitrum_sepolia:oy,ethereum_localnet:be.EthereumLocalnet,arbitrum_localnet:be.ArbitrumLocalnet,base_sepolia:cy,base:ay,bera_testnet:uy,citrea_testnet:ly,bera:fy,monad_testnet:dy,hyperliquid_testnet:Jc,hyperliquid:Qc},ef=async(e,t)=>{var n;const r=Zc[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return ne({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=Et.createWalletClient({account:t.account,chain:r,transport:Et.custom(t.transport)});return ne({message:"Switched chain",walletClient:i})}catch(i){if(my(i))try{await t.addChain({chain:r});const s=Et.createWalletClient({account:t.account,chain:r,transport:Et.custom(window.ethereum)});return ne({message:"Added network",walletClient:s})}catch{return $("Failed to add network")}else return $("Failed to switch network")}else return $("Chain not supported")},my=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;class tf{constructor(t,r,n){this.url=new z.Url("/relayer",t),this.auth=n,this.wallet=r}get htlcActorAddress(){if(!this.wallet.account)throw new Error("No account found");return this.wallet.account.address}async initiate(t){if(!this.wallet.account)return z.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return z.Err("Account address and order initiator mismatch");const r=await ef(t.source_swap.chain,this.wallet);if(r.error)return z.Err(r.error);if(this.wallet=r.val.walletClient,!this.wallet.account)return z.Err("No account found");const{create_order:n,source_swap:i}=t;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return z.Err("Invalid order");const s=z.with0x(n.secret_hash),o=BigInt(n.timelock),a=z.with0x(i.redeemer),u=BigInt(i.amount);try{const h=await this.auth.getAuthHeaders();if(h.error)return z.Err(h.error);const d=Et.getContract({address:z.with0x(t.source_swap.asset),abi:A0,client:this.wallet}),m=await d.read.token(),_=await z.checkAllowanceAndApprove(Number(u),m,t.source_swap.asset,this.wallet);if(_.error)return z.Err(_.error);const p=await d.read.eip712Domain(),I=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:p[1],version:p[2],chainId:Number(p[3]),verifyingContract:p[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:a,timelock:o,amount:u,secretHash:s}}),B={...h.val,"Content-Type":"application/json"},T=await xt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:n.create_id,signature:I,perform_on:"Source"}),headers:B});return T.error?z.Err(T.error):T.result?z.Ok(T.result):z.Err("Init: No result found")}catch(h){return console.log("init error :",h),z.Err(String(h))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return z.Err(n.error);const i=await xt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:rr(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});return i.error?z.Err(i.error):i.result?z.Ok(i.result):z.Err("Redeem: No result found")}catch(n){return z.Err(String(n))}}async refund(){return z.Err("Refund not supported")}}const rf=[{name:"LockingContract",type:"impl",interface_name:"src::mintable_lock_interface::ILockingContract"},{name:"src::mintable_lock_interface::ILockingContract",type:"interface",items:[{name:"set_locking_contract",type:"function",inputs:[{name:"locking_contract",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"get_locking_contract",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"}]},{name:"LockAndDelegate",type:"impl",interface_name:"src::mintable_lock_interface::ILockAndDelegate"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"src::mintable_lock_interface::ILockAndDelegate",type:"interface",items:[{name:"lock_and_delegate",type:"function",inputs:[{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"lock_and_delegate_by_sig",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"},{name:"nonce",type:"core::felt252"},{name:"expiry",type:"core::integer::u64"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"MintableToken",type:"impl",interface_name:"src::mintable_token_interface::IMintableToken"},{name:"src::mintable_token_interface::IMintableToken",type:"interface",items:[{name:"permissioned_mint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissioned_burn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"MintableTokenCamelImpl",type:"impl",interface_name:"src::mintable_token_interface::IMintableTokenCamel"},{name:"src::mintable_token_interface::IMintableTokenCamel",type:"interface",items:[{name:"permissionedMint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissionedBurn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"Replaceable",type:"impl",interface_name:"src::replaceability_interface::IReplaceable"},{name:"core::array::Span::<core::felt252>",type:"struct",members:[{name:"snapshot",type:"@core::array::Array::<core::felt252>"}]},{name:"src::replaceability_interface::EICData",type:"struct",members:[{name:"eic_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_init_data",type:"core::array::Span::<core::felt252>"}]},{name:"core::option::Option::<src::replaceability_interface::EICData>",type:"enum",variants:[{name:"Some",type:"src::replaceability_interface::EICData"},{name:"None",type:"()"}]},{name:"core::bool",type:"enum",variants:[{name:"False",type:"()"},{name:"True",type:"()"}]},{name:"src::replaceability_interface::ImplementationData",type:"struct",members:[{name:"impl_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_data",type:"core::option::Option::<src::replaceability_interface::EICData>"},{name:"final",type:"core::bool"}]},{name:"src::replaceability_interface::IReplaceable",type:"interface",items:[{name:"get_upgrade_delay",type:"function",inputs:[],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"get_impl_activation_time",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"add_new_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"remove_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"replace_to",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"}]},{name:"AccessControlImplExternal",type:"impl",interface_name:"src::access_control_interface::IAccessControl"},{name:"src::access_control_interface::IAccessControl",type:"interface",items:[{name:"has_role",type:"function",inputs:[{name:"role",type:"core::felt252"},{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"get_role_admin",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[{type:"core::felt252"}],state_mutability:"view"}]},{name:"RolesImpl",type:"impl",interface_name:"src::roles_interface::IMinimalRoles"},{name:"src::roles_interface::IMinimalRoles",type:"interface",items:[{name:"is_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"is_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"register_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"register_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"renounce",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[],state_mutability:"external"}]},{name:"ERC20Impl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20"},{name:"openzeppelin::token::erc20::interface::IERC20",type:"interface",items:[{name:"name",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"symbol",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"decimals",type:"function",inputs:[],outputs:[{type:"core::integer::u8"}],state_mutability:"view"},{name:"total_supply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balance_of",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"allowance",type:"function",inputs:[{name:"owner",type:"core::starknet::contract_address::ContractAddress"},{name:"spender",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transfer",type:"function",inputs:[{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"transfer_from",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"approve",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"ERC20CamelOnlyImpl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20CamelOnly"},{name:"openzeppelin::token::erc20::interface::IERC20CamelOnly",type:"interface",items:[{name:"totalSupply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balanceOf",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transferFrom",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"name",type:"core::felt252"},{name:"symbol",type:"core::felt252"},{name:"decimals",type:"core::integer::u8"},{name:"initial_supply",type:"core::integer::u256"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"permitted_minter",type:"core::starknet::contract_address::ContractAddress"},{name:"provisional_governance_admin",type:"core::starknet::contract_address::ContractAddress"},{name:"upgrade_delay",type:"core::integer::u64"}]},{name:"increase_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"added_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decrease_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtracted_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"increaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"addedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decreaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtractedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Transfer",type:"event",members:[{kind:"data",name:"from",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"to",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Approval",type:"event",members:[{kind:"data",name:"owner",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"spender",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationAdded",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationRemoved",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationReplaced",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationFinalized",type:"event",members:[{kind:"data",name:"impl_hash",type:"core::starknet::class_hash::ClassHash"}]},{kind:"struct",name:"src::access_control_interface::RoleGranted",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleRevoked",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleAdminChanged",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"previous_admin_role",type:"core::felt252"},{kind:"data",name:"new_admin_role",type:"core::felt252"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"enum",name:"src::strk::erc20_lockable::ERC20Lockable::Event",type:"event",variants:[{kind:"nested",name:"Transfer",type:"src::strk::erc20_lockable::ERC20Lockable::Transfer"},{kind:"nested",name:"Approval",type:"src::strk::erc20_lockable::ERC20Lockable::Approval"},{kind:"nested",name:"ImplementationAdded",type:"src::replaceability_interface::ImplementationAdded"},{kind:"nested",name:"ImplementationRemoved",type:"src::replaceability_interface::ImplementationRemoved"},{kind:"nested",name:"ImplementationReplaced",type:"src::replaceability_interface::ImplementationReplaced"},{kind:"nested",name:"ImplementationFinalized",type:"src::replaceability_interface::ImplementationFinalized"},{kind:"nested",name:"RoleGranted",type:"src::access_control_interface::RoleGranted"},{kind:"nested",name:"RoleRevoked",type:"src::access_control_interface::RoleRevoked"},{kind:"nested",name:"RoleAdminChanged",type:"src::access_control_interface::RoleAdminChanged"},{kind:"nested",name:"GovernanceAdminAdded",type:"src::roles_interface::GovernanceAdminAdded"},{kind:"nested",name:"GovernanceAdminRemoved",type:"src::roles_interface::GovernanceAdminRemoved"},{kind:"nested",name:"UpgradeGovernorAdded",type:"src::roles_interface::UpgradeGovernorAdded"},{kind:"nested",name:"UpgradeGovernorRemoved",type:"src::roles_interface::UpgradeGovernorRemoved"}]}],nf=async(e,t,r,n,i)=>{try{const s=new Ge.RpcProvider({nodeUrl:i}),a=await new Ge.Contract(rf,Rn(t),s).call("allowance",[Rn(e.address),Rn(r)]),u=BigInt((a==null?void 0:a.toString())||"0"),h=Ge.cairo.uint256(BigInt(Ge.uint256.UINT_256_MAX));if(u<n){const d=await e.execute([{contractAddress:Rn(t),entrypoint:"approve",calldata:[r,h.low,h.high]}]);return await s.waitForTransaction(d.transaction_hash,{retryInterval:3e3,successStates:[Ge.TransactionExecutionStatus.SUCCEEDED]}),await z.sleep(2e3),ne(d.transaction_hash)}return ne("Allowance already approved")}catch(s){return $(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},sf=[{name:"HTLC",type:"impl",interface_name:"starknet_htlc::interface::IHTLC"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"starknet_htlc::interface::IHTLC",type:"interface",items:[{name:"token",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"},{name:"initiate",type:"function",inputs:[{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_on_behalf",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_with_signature",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"},{name:"redeem",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"secret",type:"core::array::Array::<core::integer::u32>"}],outputs:[],state_mutability:"external"},{name:"refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"}],outputs:[],state_mutability:"external"},{name:"instant_refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"token",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"starknet_htlc::interface::events::Initiated",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"amount",type:"core::integer::u256"}]},{kind:"struct",name:"starknet_htlc::interface::events::Redeemed",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"secret",type:"core::array::Array::<core::integer::u32>"}]},{kind:"struct",name:"starknet_htlc::interface::events::Refunded",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"}]},{kind:"enum",name:"starknet_htlc::htlc::HTLC::Event",type:"event",variants:[{kind:"nested",name:"Initiated",type:"starknet_htlc::interface::events::Initiated"},{kind:"nested",name:"Redeemed",type:"starknet_htlc::interface::events::Redeemed"},{kind:"nested",name:"Refunded",type:"starknet_htlc::interface::events::Refunded"}]}],by={name:"HTLC",version:Ge.shortString.encodeShortString("1"),chainId:"0x534e5f5345504f4c4941",revision:Ge.TypedDataRevision.ACTIVE},wy={StarknetDomain:[{name:"name",type:"shortstring"},{name:"version",type:"shortstring"},{name:"chainId",type:"shortstring"},{name:"revision",type:"shortstring"}],Initiate:[{name:"redeemer",type:"ContractAddress"},{name:"amount",type:"u256"},{name:"timelock",type:"u128"},{name:"secretHash",type:"u128*"}]},gy="https://starknet-sepolia.public.blastapi.io/rpc/v0_7";class of{constructor(t,r,n){this.nodeUrl=n||gy,this.url=new z.Url("/",t),this.account=r}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async initiate(t){if(!this.account.address)return $("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return $("Invalid order");try{const o=new Ge.Contract(sf,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),u=Ge.num.toHex(a),h=await nf(this.account,u,n.asset,BigInt(s),this.nodeUrl);if(h.error)return $(h.error);const d={domain:by,primaryType:"Initiate",types:wy,message:{redeemer:i,amount:Ge.cairo.uint256(s),timelock:r.timelock,secretHash:z.hexToU32Array(r.secret_hash)}},m=await this.account.signMessage(d),_=vf(m);if(_.error)return $(_.error);const p=await xt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:_.val,perform_on:"Source"}),headers:{"Content-Type":"application/json"}});return p.error?$(p.error):p.result?ne(p.result):$("Init: No result found")}catch(o){return $(String(o))}}async redeem(t,r){try{const n=await xt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"}});return n.error?$(n.error):n.result?ne(n.result):$("Redeem: No result found")}catch(n){return $(String(n))}}async refund(){return $("Refund is taken care of by the relayer")}}class eo extends z.EventBroker{constructor(t){if(super(),this.environment=z.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new Nl,typeof t.digestKey=="string"){const n=z.DigestKey.from(t.digestKey);if(n.error)throw new Error(n.error);this._digestKey=n.val}else this._digestKey=t.digestKey;if(typeof t.environment=="string"){if(this.environment=t.environment,this._api=t.environment===z.Environment.MAINNET?un.mainnet:t.environment===z.Environment.TESTNET?un.testnet:void 0,!this._api)throw new Error("API not found, invalid environment "+t.environment)}else this._api=t.environment;this._quote=t.quote??new Va(this._api.quote),this._auth=t.auth??z.Siwe.fromDigestKey(new z.Url(this._api.auth),this._digestKey),this._orderbook=t.orderbook??new be.Orderbook(new z.Url(this._api.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._secretManager=t.secretManager??wn.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new Ll,this._blockNumberFetcher=t.blockNumberFetcher??new Ga(this._api.info,this.environment);const r=new Rr.BitcoinProvider(gf(this.environment));this._btcWallet=Rr.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,r)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const s=z.DigestKey.from(t.digestKey);if(s.error)throw new Error(s.error);r=s.val}else r=t.digestKey;let n;if(typeof t.environment=="string"?n=t.environment===z.Environment.MAINNET?un.mainnet:t.environment===z.Environment.TESTNET?un.testnet:void 0:n=t.environment,!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new tf(n.evmRelay,t.wallets.evm,z.Siwe.fromDigestKey(new z.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new of(n.starknetRelay,t.wallets.starknet):void 0};return new eo({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return $(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val,o=Date.now().toString(),a=await this._secretManager.generateSecret(o);if(a.error)return $(a.error);const{strategyId:u,btcAddress:h}=t.additionalData,d={strategy_id:u,...h&&{bitcoin_optional_recipient:h}},m={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o,timelock:s,secret_hash:rr(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},_=await this._quote.getAttestedQuote(m);if(_.error)return $(_.error);const p=await this._orderbook.createOrder(_.val,this.auth);if(p.error)return $(p.error);const I=await this.pollOrder(p.val);return I.error?$(I.error):ne(I.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return $("StrategyId is required");if(!t.fromAsset||!t.toAsset)return $("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return $("Source and destination assets cannot be the same");if(be.isMainnet(t.fromAsset.chain)&&!be.isMainnet(t.toAsset.chain)||!be.isMainnet(t.fromAsset.chain)&&be.isMainnet(t.toAsset.chain))return $("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return $(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return $(n.error);if(r<n)return $("Send amount should be greater than receive amount");const i=be.getTimeLock(t.fromAsset.chain);if(!i)return $("Unsupported chain for timelock");if((be.isBitcoin(t.fromAsset.chain)||be.isBitcoin(t.toAsset.chain))&&!t.additionalData.btcAddress)return $("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return $(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?$(o.error):ne({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(be.getBlockchainType(t)){case be.BlockchainType.EVM:return this._evmHTLC?ne(this._evmHTLC.htlcActorAddress):$("Please provide evmHTLC when initializing garden");case be.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!bf(i)?$("Invalid btc public key"):ne(Dt(i))}case be.BlockchainType.Starknet:return this._starknetHTLC?ne(this._starknetHTLC.htlcActorAddress):$("Please provide starknetHTLC when initializing garden");default:return $("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return $("Invalid amount ",t);const r=new uf(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?$("Invalid amount ",t):ne(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return $(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return ne(r.val);r=await this._orderbook.getOrder(t,!0)}return $(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{if(r.data.length===0)return;const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val);for(let i=0;i<n.val.length;i++){const s=n.val[i],o=Bs(s.status);if(be.isBitcoin(s.source_swap.chain)&&s.status===le.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Ae.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(be.getBlockchainType(s.destination_swap.chain)){case be.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case be.BlockchainType.Bitcoin:{const u=this.btcWallet;if(!u){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(u,s,a.val.secret);break}case be.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Ae.Refund:{switch(be.getBlockchainType(s.source_swap.chain)){case be.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case be.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case be.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},"pending",{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Ae.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ae.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Ae.Redeem,i.val),this.emit("success",t,Ae.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Ae.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ae.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Ae.Redeem,i.val),this.emit("success",t,Ae.Redeem,i.val))}async btcRedeem(t,r,n){var a,u;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const h=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const m of h.vin)if(m.txid===s){d=!0;break}if(d){this.emit("log",r.create_order.create_id,"already a valid redeem");let m=0;try{const[_]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);_!==0&&(m=_)}catch{m=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:m,redeemTxHash:r.destination_swap.redeem_tx_hash});return}o=!0}catch(h){if(h.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+h);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const d=await(await dn.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Dt(r.destination_swap.initiator),Dt(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(rr(n),(u=r.create_order.additional_data)==null?void 0:u.bitcoin_optional_recipient),m=await this.broadcastRedeemTx(d,r.create_order.create_id);if(m.error||!m.val){this.emit("error",r,m.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,m.val)):this.emit("success",r,Ae.Redeem,m.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:m.val})}catch(h){console.log("error",h),this.emit("error",r,"Failed btc redeem: "+h)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Ae.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await dn.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Dt(r.source_swap.initiator),Dt(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,Ae.Refund,s),this.emit("success",r,Ae.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await dn.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,Dt(t.source_swap.initiator),Dt(t.source_swap.redeemer),t.source_swap.timelock),s=t.create_order.additional_data.bitcoin_optional_recipient;if(s)try{const o=await i.generateInstantRefundSACP(s);if(!this._api)return;const a=new z.Url(this._api.orderbook).endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await xt.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:o})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(o){this.emit("error",t,"Failed to generate and post SACP: "+o);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return ne([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return $(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(ma(o))continue;const a=o.source_swap.chain,u=o.destination_swap.chain,h=r==null?void 0:r.val[a],d=r==null?void 0:r.val[u];if(!h||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const m=Ts(o,h,d);n.push({...o,status:m})}return ne(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return $("API not found");const n=new z.Url(this._api.evmRelay).endpoint("/bitcoin/redeem "),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?ne(o.result):$(o.error)}catch(n){return $("Failed to broadcast redeem tx: "+n)}}}const _y="https://starknet-sepolia.public.blastapi.io/rpc/v0_7";class vy{constructor(t,r){this.callData=new Ge.CallData(rf),this.nodeUrl=r||_y,this.account=t}get htlcActorAddress(){return this.account.address}async getHTLCContract(t,r=!1){const n=r?t.destination_swap.asset:t.source_swap.asset;return new Ge.Contract(sf,n,this.account)}async initiate(t){try{const n=await(await this.getHTLCContract(t)).token();if(!n)throw new Error("Token address retrieval failed");const i=Ge.num.toHex(n),s=Ge.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await nf(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.nodeUrl);if(a.error)return $(a.error)}catch(a){return $(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return ne(o.transaction_hash)}catch(r){return $(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:Ge.CallData.compile({swap_id:i,secret:z.hexToU32Array(r)})});return s.transaction_hash?ne(s.transaction_hash):$("Failed to redeem HTLC transaction")}catch{return $("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?ne(i.transaction_hash):$("Failed to refund HTLC transaction")}catch{return $("HTLC Refund Error")}}}exports.API=un;exports.BlockNumberFetcher=Ga;exports.EvmRelay=tf;exports.Garden=eo;exports.OrderActions=Ae;exports.OrderStatus=le;exports.ParseOrderStatus=Ts;exports.ParseSwapStatus=hs;exports.Quote=Va;exports.SecretManager=wn;exports.StarknetHTLC=vy;exports.StarknetRelay=of;exports.SwapStatus=me;exports.constructOrderPair=ya;exports.evmToViemChainMap=Zc;exports.filterDeadlineExpiredOrders=xf;exports.hyperliquid=Qc;exports.hyperliquidTestnet=Jc;exports.isExpired=pn;exports.parseAction=Ef;exports.parseActionFromStatus=Bs;exports.switchOrAddNetwork=ef;exports.toXOnly=Dt;exports.validateBTCAddress=wf;
|
|
34
|
+
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Vc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class zc extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}function sa(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function hp(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Js(e,...t){if(!hp(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function oa(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function dp(e,t){Js(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const $n=BigInt(2**32-1),aa=BigInt(32);function pp(e,t=!1){return t?{h:Number(e&$n),l:Number(e>>aa&$n)}:{h:Number(e>>aa&$n)|0,l:Number(e&$n)|0}}function yp(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:s,l:o}=pp(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const mp=(e,t,r)=>e<<r|t>>>32-r,bp=(e,t,r)=>t<<r|e>>>32-r,wp=(e,t,r)=>t<<r-32|e>>>64-r,gp=(e,t,r)=>e<<r-32|t>>>64-r;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _p(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}const ca=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function vp(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function fa(e){for(let t=0;t<e.length;t++)e[t]=vp(e[t])}function Ep(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function qc(e){return typeof e=="string"&&(e=Ep(e)),Js(e),e}class xp{clone(){return this._cloneInto()}}function Sp(e){const t=n=>e().update(qc(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}const Wc=[],Kc=[],Yc=[],Ap=BigInt(0),nn=BigInt(1),kp=BigInt(2),Tp=BigInt(7),Bp=BigInt(256),Ip=BigInt(113);for(let e=0,t=nn,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Wc.push(2*(5*n+r)),Kc.push((e+1)*(e+2)/2%64);let i=Ap;for(let s=0;s<7;s++)t=(t<<nn^(t>>Tp)*Ip)%Bp,t&kp&&(i^=nn<<(nn<<BigInt(s))-nn);Yc.push(i)}const[Pp,Op]=yp(Yc,!0),ua=(e,t,r)=>r>32?wp(e,t,r):mp(e,t,r),la=(e,t,r)=>r>32?gp(e,t,r):bp(e,t,r);function Rp(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)r[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,u=(o+2)%10,h=r[u],d=r[u+1],m=ua(h,d,1)^r[a],_=la(h,d,1)^r[a+1];for(let p=0;p<50;p+=10)e[o+p]^=m,e[o+p+1]^=_}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=Kc[o],u=ua(i,s,a),h=la(i,s,a),d=Wc[o];i=e[d],s=e[d+1],e[d]=u,e[d+1]=h}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=Pp[n],e[1]^=Op[n]}r.fill(0)}class Qs extends xp{constructor(t,r,n,i=!1,s=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,sa(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=_p(this.state)}keccak(){ca||fa(this.state32),Rp(this.state32,this.rounds),ca||fa(this.state32),this.posOut=0,this.pos=0}update(t){oa(this);const{blockLen:r,state:n}=this;t=qc(t);const i=t.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=t[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){oa(this,!1),Js(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=t.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);t.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return sa(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(dp(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return t||(t=new Qs(r,n,i,o,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}}const Cp=(e,t,r)=>Sp(()=>new Qs(t,e,r)),Up=Cp(1,136,256/8);function Lp(e,t){return Up(Bn(e,{strict:!1})?Rc(e):e)}const cs=new zc(8192);function Np(e,t){if(cs.has(`${e}.${t}`))return cs.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Lp(Cc(r)),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return cs.set(`${e}.${t}`,s),s}const Fp=/^0x[a-fA-F0-9]{40}$/,fs=new zc(8192);function hr(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(fs.has(n))return fs.get(n);const i=Fp.test(e)?e.toLowerCase()===e?!0:r?Np(e)===e:!0:!1;return fs.set(n,i),i}function Hp(e,t,r,{strict:n}={}){return Bn(e,{strict:!1})?Dp(e,t,r,{strict:n}):Mp(e,t,r,{strict:n})}function Xc(e,t,r){if(Mr(e)!==r-t)throw new B0({offset:r,position:"end",size:Mr(e)})}function Mp(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&Xc(i,t,r),i}function Dp(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&Xc(i,t,r),i}function $p(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!hr(i))throw new lr({address:i});if(n<0)throw new Ii({chainId:n})}Zs(e)}function jp(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Gc;for(const r of t){const n=Mr(r),i=oi(Hp(r,0,1));if(n!==32)throw new cp({hash:r,size:n});if(i!==jc)throw new fp({hash:r,version:i})}}Zs(e)}function Zs(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Ii({chainId:t});if(i&&!hr(i))throw new lr({address:i});if(n&&n>Ys)throw new Pi({maxFeePerGas:n});if(r&&n&&r>n)throw new Vc({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Gp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new Ii({chainId:t});if(s&&!hr(s))throw new lr({address:s});if(r||i)throw new he("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ys)throw new Pi({maxFeePerGas:n})}function Vp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!hr(s))throw new lr({address:s});if(typeof t<"u"&&t<=0)throw new Ii({chainId:t});if(r||i)throw new he("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ys)throw new Pi({maxFeePerGas:n})}function zp(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new tp({transaction:e})}function Oi(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let s=0;s<i.length;s++)if(i[s].length-2!==64)throw new rp({storageKey:i[s]});if(!hr(n,{strict:!1}))throw new lr({address:n});t.push([n,i])}return t}function qp(e,t){const r=zp(e);return r==="eip1559"?Yp(e,t):r==="eip2930"?Xp(e,t):r==="eip4844"?Kp(e,t):r==="eip7702"?Wp(e,t):Jp(e,t)}function Wp(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:u,maxPriorityFeePerGas:h,accessList:d,data:m}=e;$p(e);const _=Oi(d),p=np(r);return In(["0x04",ur([Q(n),s?Q(s):"0x",h?Q(h):"0x",u?Q(u):"0x",i?Q(i):"0x",o??"0x",a?Q(a):"0x",m??"0x",_,p,...Pn(e,t)])])}function Kp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:u,maxPriorityFeePerGas:h,accessList:d,data:m}=e;jp(e);let _=e.blobVersionedHashes,p=e.sidecars;if(e.blobs&&(typeof _>"u"||typeof p>"u")){const x=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(E=>Jt(E)),g=e.kzg,S=Hc({blobs:x,kzg:g});if(typeof _>"u"&&(_=op({commitments:S})),typeof p>"u"){const E=Mc({blobs:x,commitments:S,kzg:g});p=lp({blobs:x,commitments:S,proofs:E})}}const I=Oi(d),B=[Q(r),i?Q(i):"0x",h?Q(h):"0x",u?Q(u):"0x",n?Q(n):"0x",s??"0x",o?Q(o):"0x",m??"0x",I,a?Q(a):"0x",_??[],...Pn(e,t)],T=[],R=[],U=[];if(p)for(let x=0;x<p.length;x++){const{blob:g,commitment:S,proof:E}=p[x];T.push(g),R.push(S),U.push(E)}return In(["0x03",ur(p?[B,T,R,U]:B)])}function Yp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:u,accessList:h,data:d}=e;Zs(e);const m=Oi(h),_=[Q(r),i?Q(i):"0x",u?Q(u):"0x",a?Q(a):"0x",n?Q(n):"0x",s??"0x",o?Q(o):"0x",d??"0x",m,...Pn(e,t)];return In(["0x02",ur(_)])}function Xp(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:u,gasPrice:h}=e;Gp(e);const d=Oi(u),m=[Q(r),s?Q(s):"0x",h?Q(h):"0x",n?Q(n):"0x",o??"0x",a?Q(a):"0x",i??"0x",d,...Pn(e,t)];return In(["0x01",ur(m)])}function Jp(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:u}=e;Vp(e);let h=[s?Q(s):"0x",u?Q(u):"0x",n?Q(n):"0x",o??"0x",a?Q(a):"0x",i??"0x"];if(t){const d=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const p=27n+(t.v===27n?0n:1n);if(t.v!==p)throw new ep({v:t.v});return p})(),m=si(t.r),_=si(t.s);h=[...h,Q(d),m==="0x00"?"0x":m,_==="0x00"?"0x":_]}else r>0&&(h=[...h,Q(r),"0x","0x"]);return ur(h)}function Pn(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const s=si(r.r),o=si(r.s);return[typeof i=="number"?i?Q(1):"0x":n===0n?"0x":n===1n?Q(1):n===27n?"0x":Q(1),s==="0x00"?"0x":s,o==="0x00"?"0x":o]}const Qp={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},Zp={block:$0({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Ks(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?Tr(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:H0({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?Tr(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:z0({format(e){return{l1GasPrice:e.l1GasPrice?Tr(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?Tr(e.l1GasUsed):null,l1Fee:e.l1Fee?Tr(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function ey(e,t){return ny(e)?ry(e):qp(e,t)}const ty={transaction:ey};function ry(e){iy(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:u}=e,h=[t,n,a??"0x",o?Q(o):"0x",u?Q(u):"0x",i?Q(i):"0x",s?"0x1":"0x",r??"0x"];return In(["0x7e",ur(h)])}function ny(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function iy(e){const{from:t,to:r}=e;if(t&&!hr(t))throw new lr({address:t});if(r&&!hr(r))throw new lr({address:r})}const ai={contracts:Qp,formatters:Zp,serializers:ty},sy=dt({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),oy=dt({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),sn=1,ay=dt({...ai,id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://basescan.org",apiUrl:"https://api.basescan.org/api"}},contracts:{...ai.contracts,disputeGameFactory:{[sn]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[sn]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[sn]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[sn]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:sn}),on=11155111,cy=dt({...ai,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...ai.contracts,disputeGameFactory:{[on]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[on]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[on]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[on]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:on}),fy=dt({id:80094,name:"Berachain",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:0},ensRegistry:{address:"0x5b22280886a2f5e09a49bea7e320eab0e5320e28",blockCreated:877007},ensUniversalResolver:{address:"0xddfb18888a9466688235887dec2a10c4f5effee9",blockCreated:877008}},rpcUrls:{default:{http:["https://rpc.berachain.com"]}},blockExplorers:{default:{name:"Berascan",url:"https://berascan.com"}},ensTlds:[".bera"],testnet:!1}),uy=dt({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269},ensRegistry:{address:"0xB0eef18971290b333450586D33dcA6cE122651D2",blockCreated:7736794},ensUniversalResolver:{address:"0x41692Ef1EA0C79E6b73077E4A67572D2BDbD7057",blockCreated:7736795}},ensTlds:[".bera"],rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),ly=dt({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"cBTC",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api"}},testnet:!0}),hy=dt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),dy=dt({id:10143,name:"Monad Testnet",nativeCurrency:{name:"Testnet MON Token",symbol:"MON",decimals:18},rpcUrls:{default:{http:["https://testnet-rpc.monad.xyz"]}},blockExplorers:{default:{name:"Monad Testnet explorer",url:"https://testnet.monadexplorer.com"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:251449}},testnet:!0}),py=dt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.drpc.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0}),yy={...py,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Jc={id:998,name:"Hyperliquid EVM Testnet",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://testnet.purrsec.com/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid-testnet.xyz/evm"]}}},Qc={id:999,name:"HyperEVM",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://hyperscan.gas.zip/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid.xyz/evm"]}}},Zc={ethereum:hy,arbitrum:sy,ethereum_sepolia:yy,arbitrum_sepolia:oy,ethereum_localnet:be.EthereumLocalnet,arbitrum_localnet:be.ArbitrumLocalnet,base_sepolia:cy,base:ay,bera_testnet:uy,citrea_testnet:ly,bera:fy,monad_testnet:dy,hyperliquid_testnet:Jc,hyperliquid:Qc},ef=async(e,t)=>{var n;const r=Zc[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return ne({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=Et.createWalletClient({account:t.account,chain:r,transport:Et.custom(t.transport)});return ne({message:"Switched chain",walletClient:i})}catch(i){if(my(i))try{await t.addChain({chain:r});const s=Et.createWalletClient({account:t.account,chain:r,transport:Et.custom(window.ethereum)});return ne({message:"Added network",walletClient:s})}catch{return $("Failed to add network")}else return $("Failed to switch network")}else return $("Chain not supported")},my=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;class tf{constructor(t,r,n){this.url=new z.Url("/relayer",t),this.auth=n,this.wallet=r}get htlcActorAddress(){if(!this.wallet.account)throw new Error("No account found");return this.wallet.account.address}async initiate(t){if(!this.wallet.account)return z.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return z.Err("Account address and order initiator mismatch");const r=await ef(t.source_swap.chain,this.wallet);if(r.error)return z.Err(r.error);if(this.wallet=r.val.walletClient,!this.wallet.account)return z.Err("No account found");const{create_order:n,source_swap:i}=t;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return z.Err("Invalid order");const s=z.with0x(n.secret_hash),o=BigInt(n.timelock),a=z.with0x(i.redeemer),u=BigInt(i.amount);try{const h=await this.auth.getAuthHeaders();if(h.error)return z.Err(h.error);const d=Et.getContract({address:z.with0x(t.source_swap.asset),abi:A0,client:this.wallet}),m=await d.read.token(),_=await z.checkAllowanceAndApprove(Number(u),m,t.source_swap.asset,this.wallet);if(_.error)return z.Err(_.error);const p=await d.read.eip712Domain(),I=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:p[1],version:p[2],chainId:Number(p[3]),verifyingContract:p[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:a,timelock:o,amount:u,secretHash:s}}),B={...h.val,"Content-Type":"application/json"},T=await xt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:n.create_id,signature:I,perform_on:"Source"}),headers:B});return T.error?z.Err(T.error):T.result?z.Ok(T.result):z.Err("Init: No result found")}catch(h){return console.log("init error :",h),z.Err(String(h))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return z.Err(n.error);const i=await xt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:rr(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});return i.error?z.Err(i.error):i.result?z.Ok(i.result):z.Err("Redeem: No result found")}catch(n){return z.Err(String(n))}}async refund(){return z.Err("Refund not supported")}}const rf=[{name:"LockingContract",type:"impl",interface_name:"src::mintable_lock_interface::ILockingContract"},{name:"src::mintable_lock_interface::ILockingContract",type:"interface",items:[{name:"set_locking_contract",type:"function",inputs:[{name:"locking_contract",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"get_locking_contract",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"}]},{name:"LockAndDelegate",type:"impl",interface_name:"src::mintable_lock_interface::ILockAndDelegate"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"src::mintable_lock_interface::ILockAndDelegate",type:"interface",items:[{name:"lock_and_delegate",type:"function",inputs:[{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"lock_and_delegate_by_sig",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"},{name:"nonce",type:"core::felt252"},{name:"expiry",type:"core::integer::u64"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"MintableToken",type:"impl",interface_name:"src::mintable_token_interface::IMintableToken"},{name:"src::mintable_token_interface::IMintableToken",type:"interface",items:[{name:"permissioned_mint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissioned_burn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"MintableTokenCamelImpl",type:"impl",interface_name:"src::mintable_token_interface::IMintableTokenCamel"},{name:"src::mintable_token_interface::IMintableTokenCamel",type:"interface",items:[{name:"permissionedMint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissionedBurn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"Replaceable",type:"impl",interface_name:"src::replaceability_interface::IReplaceable"},{name:"core::array::Span::<core::felt252>",type:"struct",members:[{name:"snapshot",type:"@core::array::Array::<core::felt252>"}]},{name:"src::replaceability_interface::EICData",type:"struct",members:[{name:"eic_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_init_data",type:"core::array::Span::<core::felt252>"}]},{name:"core::option::Option::<src::replaceability_interface::EICData>",type:"enum",variants:[{name:"Some",type:"src::replaceability_interface::EICData"},{name:"None",type:"()"}]},{name:"core::bool",type:"enum",variants:[{name:"False",type:"()"},{name:"True",type:"()"}]},{name:"src::replaceability_interface::ImplementationData",type:"struct",members:[{name:"impl_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_data",type:"core::option::Option::<src::replaceability_interface::EICData>"},{name:"final",type:"core::bool"}]},{name:"src::replaceability_interface::IReplaceable",type:"interface",items:[{name:"get_upgrade_delay",type:"function",inputs:[],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"get_impl_activation_time",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"add_new_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"remove_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"replace_to",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"}]},{name:"AccessControlImplExternal",type:"impl",interface_name:"src::access_control_interface::IAccessControl"},{name:"src::access_control_interface::IAccessControl",type:"interface",items:[{name:"has_role",type:"function",inputs:[{name:"role",type:"core::felt252"},{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"get_role_admin",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[{type:"core::felt252"}],state_mutability:"view"}]},{name:"RolesImpl",type:"impl",interface_name:"src::roles_interface::IMinimalRoles"},{name:"src::roles_interface::IMinimalRoles",type:"interface",items:[{name:"is_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"is_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"register_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"register_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"renounce",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[],state_mutability:"external"}]},{name:"ERC20Impl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20"},{name:"openzeppelin::token::erc20::interface::IERC20",type:"interface",items:[{name:"name",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"symbol",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"decimals",type:"function",inputs:[],outputs:[{type:"core::integer::u8"}],state_mutability:"view"},{name:"total_supply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balance_of",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"allowance",type:"function",inputs:[{name:"owner",type:"core::starknet::contract_address::ContractAddress"},{name:"spender",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transfer",type:"function",inputs:[{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"transfer_from",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"approve",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"ERC20CamelOnlyImpl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20CamelOnly"},{name:"openzeppelin::token::erc20::interface::IERC20CamelOnly",type:"interface",items:[{name:"totalSupply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balanceOf",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transferFrom",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"name",type:"core::felt252"},{name:"symbol",type:"core::felt252"},{name:"decimals",type:"core::integer::u8"},{name:"initial_supply",type:"core::integer::u256"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"permitted_minter",type:"core::starknet::contract_address::ContractAddress"},{name:"provisional_governance_admin",type:"core::starknet::contract_address::ContractAddress"},{name:"upgrade_delay",type:"core::integer::u64"}]},{name:"increase_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"added_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decrease_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtracted_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"increaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"addedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decreaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtractedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Transfer",type:"event",members:[{kind:"data",name:"from",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"to",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Approval",type:"event",members:[{kind:"data",name:"owner",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"spender",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationAdded",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationRemoved",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationReplaced",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationFinalized",type:"event",members:[{kind:"data",name:"impl_hash",type:"core::starknet::class_hash::ClassHash"}]},{kind:"struct",name:"src::access_control_interface::RoleGranted",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleRevoked",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleAdminChanged",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"previous_admin_role",type:"core::felt252"},{kind:"data",name:"new_admin_role",type:"core::felt252"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"enum",name:"src::strk::erc20_lockable::ERC20Lockable::Event",type:"event",variants:[{kind:"nested",name:"Transfer",type:"src::strk::erc20_lockable::ERC20Lockable::Transfer"},{kind:"nested",name:"Approval",type:"src::strk::erc20_lockable::ERC20Lockable::Approval"},{kind:"nested",name:"ImplementationAdded",type:"src::replaceability_interface::ImplementationAdded"},{kind:"nested",name:"ImplementationRemoved",type:"src::replaceability_interface::ImplementationRemoved"},{kind:"nested",name:"ImplementationReplaced",type:"src::replaceability_interface::ImplementationReplaced"},{kind:"nested",name:"ImplementationFinalized",type:"src::replaceability_interface::ImplementationFinalized"},{kind:"nested",name:"RoleGranted",type:"src::access_control_interface::RoleGranted"},{kind:"nested",name:"RoleRevoked",type:"src::access_control_interface::RoleRevoked"},{kind:"nested",name:"RoleAdminChanged",type:"src::access_control_interface::RoleAdminChanged"},{kind:"nested",name:"GovernanceAdminAdded",type:"src::roles_interface::GovernanceAdminAdded"},{kind:"nested",name:"GovernanceAdminRemoved",type:"src::roles_interface::GovernanceAdminRemoved"},{kind:"nested",name:"UpgradeGovernorAdded",type:"src::roles_interface::UpgradeGovernorAdded"},{kind:"nested",name:"UpgradeGovernorRemoved",type:"src::roles_interface::UpgradeGovernorRemoved"}]}],nf=async(e,t,r,n,i)=>{try{const s=new Ge.RpcProvider({nodeUrl:i}),a=await new Ge.Contract(rf,Rn(t),s).call("allowance",[Rn(e.address),Rn(r)]),u=BigInt((a==null?void 0:a.toString())||"0"),h=Ge.cairo.uint256(BigInt(Ge.uint256.UINT_256_MAX));if(u<n){const d=await e.execute([{contractAddress:Rn(t),entrypoint:"approve",calldata:[r,h.low,h.high]}]);return await s.waitForTransaction(d.transaction_hash,{retryInterval:3e3,successStates:[Ge.TransactionExecutionStatus.SUCCEEDED]}),await z.sleep(2e3),ne(d.transaction_hash)}return ne("Allowance already approved")}catch(s){return $(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},sf=[{name:"HTLC",type:"impl",interface_name:"starknet_htlc::interface::IHTLC"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"starknet_htlc::interface::IHTLC",type:"interface",items:[{name:"token",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"},{name:"initiate",type:"function",inputs:[{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_on_behalf",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_with_signature",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"},{name:"redeem",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"secret",type:"core::array::Array::<core::integer::u32>"}],outputs:[],state_mutability:"external"},{name:"refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"}],outputs:[],state_mutability:"external"},{name:"instant_refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"token",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"starknet_htlc::interface::events::Initiated",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"amount",type:"core::integer::u256"}]},{kind:"struct",name:"starknet_htlc::interface::events::Redeemed",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"secret",type:"core::array::Array::<core::integer::u32>"}]},{kind:"struct",name:"starknet_htlc::interface::events::Refunded",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"}]},{kind:"enum",name:"starknet_htlc::htlc::HTLC::Event",type:"event",variants:[{kind:"nested",name:"Initiated",type:"starknet_htlc::interface::events::Initiated"},{kind:"nested",name:"Redeemed",type:"starknet_htlc::interface::events::Redeemed"},{kind:"nested",name:"Refunded",type:"starknet_htlc::interface::events::Refunded"}]}],by={name:"HTLC",version:Ge.shortString.encodeShortString("1"),chainId:"0x534e5f5345504f4c4941",revision:Ge.TypedDataRevision.ACTIVE},wy={StarknetDomain:[{name:"name",type:"shortstring"},{name:"version",type:"shortstring"},{name:"chainId",type:"shortstring"},{name:"revision",type:"shortstring"}],Initiate:[{name:"redeemer",type:"ContractAddress"},{name:"amount",type:"u256"},{name:"timelock",type:"u128"},{name:"secretHash",type:"u128*"}]},gy="https://starknet-sepolia.public.blastapi.io/rpc/v0_8";class of{constructor(t,r,n){this.nodeUrl=n||gy,this.url=new z.Url("/",t),this.account=r}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async initiate(t){if(!this.account.address)return $("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return $("Invalid order");try{const o=new Ge.Contract(sf,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),u=Ge.num.toHex(a),h=await nf(this.account,u,n.asset,BigInt(s),this.nodeUrl);if(h.error)return $(h.error);const d={domain:by,primaryType:"Initiate",types:wy,message:{redeemer:i,amount:Ge.cairo.uint256(s),timelock:r.timelock,secretHash:z.hexToU32Array(r.secret_hash)}},m=await this.account.signMessage(d),_=vf(m);if(_.error)return $(_.error);const p=await xt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:_.val,perform_on:"Source"}),headers:{"Content-Type":"application/json"}});return p.error?$(p.error):p.result?ne(p.result):$("Init: No result found")}catch(o){return $(String(o))}}async redeem(t,r){try{const n=await xt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"}});return n.error?$(n.error):n.result?ne(n.result):$("Redeem: No result found")}catch(n){return $(String(n))}}async refund(){return $("Refund is taken care of by the relayer")}}class eo extends z.EventBroker{constructor(t){if(super(),this.environment=z.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new Nl,typeof t.digestKey=="string"){const n=z.DigestKey.from(t.digestKey);if(n.error)throw new Error(n.error);this._digestKey=n.val}else this._digestKey=t.digestKey;if(typeof t.environment=="string"){if(this.environment=t.environment,this._api=t.environment===z.Environment.MAINNET?un.mainnet:t.environment===z.Environment.TESTNET?un.testnet:void 0,!this._api)throw new Error("API not found, invalid environment "+t.environment)}else this._api=t.environment;this._quote=t.quote??new Va(this._api.quote),this._auth=t.auth??z.Siwe.fromDigestKey(new z.Url(this._api.auth),this._digestKey),this._orderbook=t.orderbook??new be.Orderbook(new z.Url(this._api.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._secretManager=t.secretManager??wn.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new Ll,this._blockNumberFetcher=t.blockNumberFetcher??new Ga(this._api.info,this.environment);const r=new Rr.BitcoinProvider(gf(this.environment));this._btcWallet=Rr.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,r)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const s=z.DigestKey.from(t.digestKey);if(s.error)throw new Error(s.error);r=s.val}else r=t.digestKey;let n;if(typeof t.environment=="string"?n=t.environment===z.Environment.MAINNET?un.mainnet:t.environment===z.Environment.TESTNET?un.testnet:void 0:n=t.environment,!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new tf(n.evmRelay,t.wallets.evm,z.Siwe.fromDigestKey(new z.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new of(n.starknetRelay,t.wallets.starknet):void 0};return new eo({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return $(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val,o=Date.now().toString(),a=await this._secretManager.generateSecret(o);if(a.error)return $(a.error);const{strategyId:u,btcAddress:h}=t.additionalData,d={strategy_id:u,...h&&{bitcoin_optional_recipient:h}},m={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o,timelock:s,secret_hash:rr(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},_=await this._quote.getAttestedQuote(m);if(_.error)return $(_.error);const p=await this._orderbook.createOrder(_.val,this.auth);if(p.error)return $(p.error);const I=await this.pollOrder(p.val);return I.error?$(I.error):ne(I.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return $("StrategyId is required");if(!t.fromAsset||!t.toAsset)return $("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return $("Source and destination assets cannot be the same");if(be.isMainnet(t.fromAsset.chain)&&!be.isMainnet(t.toAsset.chain)||!be.isMainnet(t.fromAsset.chain)&&be.isMainnet(t.toAsset.chain))return $("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return $(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return $(n.error);if(r<n)return $("Send amount should be greater than receive amount");const i=be.getTimeLock(t.fromAsset.chain);if(!i)return $("Unsupported chain for timelock");if((be.isBitcoin(t.fromAsset.chain)||be.isBitcoin(t.toAsset.chain))&&!t.additionalData.btcAddress)return $("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return $(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?$(o.error):ne({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(be.getBlockchainType(t)){case be.BlockchainType.EVM:return this._evmHTLC?ne(this._evmHTLC.htlcActorAddress):$("Please provide evmHTLC when initializing garden");case be.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!bf(i)?$("Invalid btc public key"):ne(Dt(i))}case be.BlockchainType.Starknet:return this._starknetHTLC?ne(this._starknetHTLC.htlcActorAddress):$("Please provide starknetHTLC when initializing garden");default:return $("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return $("Invalid amount ",t);const r=new uf(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?$("Invalid amount ",t):ne(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return $(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return ne(r.val);r=await this._orderbook.getOrder(t,!0)}return $(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{if(r.data.length===0)return;const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val);for(let i=0;i<n.val.length;i++){const s=n.val[i],o=Bs(s.status);if(be.isBitcoin(s.source_swap.chain)&&s.status===le.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Ae.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(be.getBlockchainType(s.destination_swap.chain)){case be.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case be.BlockchainType.Bitcoin:{const u=this.btcWallet;if(!u){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(u,s,a.val.secret);break}case be.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Ae.Refund:{switch(be.getBlockchainType(s.source_swap.chain)){case be.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case be.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case be.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},"pending",{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Ae.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ae.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Ae.Redeem,i.val),this.emit("success",t,Ae.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Ae.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ae.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Ae.Redeem,i.val),this.emit("success",t,Ae.Redeem,i.val))}async btcRedeem(t,r,n){var a,u;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const h=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const m of h.vin)if(m.txid===s){d=!0;break}if(d){this.emit("log",r.create_order.create_id,"already a valid redeem");let m=0;try{const[_]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);_!==0&&(m=_)}catch{m=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:m,redeemTxHash:r.destination_swap.redeem_tx_hash});return}o=!0}catch(h){if(h.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+h);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const d=await(await dn.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Dt(r.destination_swap.initiator),Dt(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(rr(n),(u=r.create_order.additional_data)==null?void 0:u.bitcoin_optional_recipient),m=await this.broadcastRedeemTx(d,r.create_order.create_id);if(m.error||!m.val){this.emit("error",r,m.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,m.val)):this.emit("success",r,Ae.Redeem,m.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:m.val})}catch(h){console.log("error",h),this.emit("error",r,"Failed btc redeem: "+h)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Ae.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await dn.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Dt(r.source_swap.initiator),Dt(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,Ae.Refund,s),this.emit("success",r,Ae.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await dn.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,Dt(t.source_swap.initiator),Dt(t.source_swap.redeemer),t.source_swap.timelock),s=t.create_order.additional_data.bitcoin_optional_recipient;if(s)try{const o=await i.generateInstantRefundSACP(s);if(!this._api)return;const a=new z.Url(this._api.orderbook).endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await xt.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:o})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(o){this.emit("error",t,"Failed to generate and post SACP: "+o);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return ne([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return $(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(ma(o))continue;const a=o.source_swap.chain,u=o.destination_swap.chain,h=r==null?void 0:r.val[a],d=r==null?void 0:r.val[u];if(!h||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const m=Ts(o,h,d);n.push({...o,status:m})}return ne(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return $("API not found");const n=new z.Url(this._api.evmRelay).endpoint("/bitcoin/redeem "),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?ne(o.result):$(o.error)}catch(n){return $("Failed to broadcast redeem tx: "+n)}}}const _y="https://starknet-sepolia.public.blastapi.io/rpc/v0_7";class vy{constructor(t,r){this.callData=new Ge.CallData(rf),this.nodeUrl=r||_y,this.account=t}get htlcActorAddress(){return this.account.address}async getHTLCContract(t,r=!1){const n=r?t.destination_swap.asset:t.source_swap.asset;return new Ge.Contract(sf,n,this.account)}async initiate(t){try{const n=await(await this.getHTLCContract(t)).token();if(!n)throw new Error("Token address retrieval failed");const i=Ge.num.toHex(n),s=Ge.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await nf(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.nodeUrl);if(a.error)return $(a.error)}catch(a){return $(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return ne(o.transaction_hash)}catch(r){return $(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:Ge.CallData.compile({swap_id:i,secret:z.hexToU32Array(r)})});return s.transaction_hash?ne(s.transaction_hash):$("Failed to redeem HTLC transaction")}catch{return $("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?ne(i.transaction_hash):$("Failed to refund HTLC transaction")}catch{return $("HTLC Refund Error")}}}exports.API=un;exports.BlockNumberFetcher=Ga;exports.EvmRelay=tf;exports.Garden=eo;exports.OrderActions=Ae;exports.OrderStatus=le;exports.ParseOrderStatus=Ts;exports.ParseSwapStatus=hs;exports.Quote=Va;exports.SecretManager=wn;exports.StarknetHTLC=vy;exports.StarknetRelay=of;exports.SwapStatus=me;exports.constructOrderPair=ya;exports.evmToViemChainMap=Zc;exports.filterDeadlineExpiredOrders=xf;exports.hyperliquid=Qc;exports.hyperliquidTestnet=Jc;exports.isExpired=pn;exports.parseAction=Ef;exports.parseActionFromStatus=Bs;exports.switchOrAddNetwork=ef;exports.toXOnly=Dt;exports.validateBTCAddress=wf;
|
package/dist/index.js
CHANGED
|
@@ -13219,7 +13219,7 @@ const ff = [
|
|
|
13219
13219
|
{ name: "timelock", type: "u128" },
|
|
13220
13220
|
{ name: "secretHash", type: "u128*" }
|
|
13221
13221
|
]
|
|
13222
|
-
}, Vy = "https://starknet-sepolia.public.blastapi.io/rpc/
|
|
13222
|
+
}, Vy = "https://starknet-sepolia.public.blastapi.io/rpc/v0_8";
|
|
13223
13223
|
class zy {
|
|
13224
13224
|
constructor(t, r, n) {
|
|
13225
13225
|
this.nodeUrl = n || Vy, this.url = new vt("/", t), this.account = r;
|