@gardenfi/core 0.3.0-beta.23 → 0.3.0-beta.25
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 +15 -14
- package/dist/src/lib/garden/garden.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
`.trim().replace(/\s+/g," "))}leaves(){return[{version:Un,output:this.redeemLeaf()},[{version:Un,output:this.refundLeaf()},{version:Un,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const s=yu(i,n);return[de.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(De.invalidLeaf)}}}function qr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class $h{constructor(){this.cache={}}set(t,r,n,i){const s={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=s}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class Ya{constructor(t,r){this.url=new ae.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){try{const t=await Ht.get(this.url);return re(t)}catch(t){return j("Failed to fetch block numbers",t)}}}const ls={mainnet:{orderbook:"https://orderbookv2.garden.finance",quote:"https://pricev2.garden.finance",info:"https://infov2.garden.finance"},testnet:{orderbook:"https://orderbook.garden.finance",quote:"https://price.garden.finance",info:"https://info.garden.finance"},localnet:{orderbook:"",quote:"",info:""}};class Xa{constructor(t){this.quoteUrl=new ae.Url("/quote",t)}async getQuote(t,r,n=!1,i){try{const s=this.quoteUrl.addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),o=await Ht.get(s,{retryCount:0,...i});return o.error?j(o.error):o.result?re(o.result):j("GetQuote: Unexpected error, result is undefined")}catch(s){return j("GetQuote:",String(s))}}async getAttestedQuote(t){try{const r=await Ht.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?j(r.error):r.result?re(r.result):j("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),j("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await Ht.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return j(t.error);if(!t.result)return j("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=da(n.source_chain,n.source_asset.asset,n.dest_chain,n.dest_asset.asset);r[i]={id:n.id,minAmount:n.min_amount,maxAmount:n.max_amount,fee:n.fee}}return re(r)}catch(t){return j("GetStrategies:",String(t))}}}var Ja={},Ur={},Cr={};Object.defineProperty(Cr,"__esModule",{value:!0});Cr.testnet=Cr.bitcoin=void 0;Cr.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
29
29
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Cr.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
30
30
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Qa={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=xa,e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe})(Qa);var ds={exports:{}},ps={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=At,n=r.Buffer;function i(o,a){for(var c in o)a[c]=o[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=s);function s(o,a,c){return n(o,a,c)}s.prototype=Object.create(n.prototype),i(n,s),s.from=function(o,a,c){if(typeof o=="number")throw new TypeError("Argument must not be a number");return n(o,a,c)},s.alloc=function(o,a,c){if(typeof o!="number")throw new TypeError("Argument must be a number");var l=n(o);return a!==void 0?typeof c=="string"?l.fill(a,c):l.fill(a):l.fill(0),l},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(o)}})(ps,ps.exports);var We=ps.exports,Vi=65536,Dh=4294967295;function jh(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
31
|
-
Use Chrome, Firefox or Internet Explorer 11`)}var Gh=We.Buffer,Jn=jt.crypto||jt.msCrypto;Jn&&Jn.getRandomValues?ds.exports=Wh:ds.exports=jh;function Wh(e,t){if(e>Dh)throw new RangeError("requested too many random bytes");var r=Gh.allocUnsafe(e);if(e>0)if(e>Vi)for(var n=0;n<e;n+=Vi)Jn.getRandomValues(r.slice(n,n+Vi));else Jn.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Vh=ds.exports,ys={exports:{}};typeof Object.create=="function"?ys.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:ys.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 ke=ys.exports,bs={exports:{}},Gs={exports:{}},Ar=typeof Reflect=="object"?Reflect:null,Oo=Ar&&typeof Ar.apply=="function"?Ar.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Vn;Ar&&typeof Ar.ownKeys=="function"?Vn=Ar.ownKeys:Object.getOwnPropertySymbols?Vn=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Vn=function(t){return Object.getOwnPropertyNames(t)};function zh(e){console&&console.warn&&console.warn(e)}var Za=Number.isNaN||function(t){return t!==t};function ne(){ne.init.call(this)}Gs.exports=ne;Gs.exports.once=Xh;ne.EventEmitter=ne;ne.prototype._events=void 0;ne.prototype._eventsCount=0;ne.prototype._maxListeners=void 0;var ko=10;function yi(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(ne,"defaultMaxListeners",{enumerable:!0,get:function(){return ko},set:function(e){if(typeof e!="number"||e<0||Za(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ko=e}});ne.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};ne.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Za(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 ef(e){return e._maxListeners===void 0?ne.defaultMaxListeners:e._maxListeners}ne.prototype.getMaxListeners=function(){return ef(this)};ne.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 c=s[t];if(c===void 0)return!1;if(typeof c=="function")Oo(c,this,r);else for(var l=c.length,d=of(c,l),n=0;n<l;++n)Oo(d[n],this,r);return!0};function tf(e,t,r,n){var i,s,o;if(yi(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=ef(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,zh(a)}return e}ne.prototype.addListener=function(t,r){return tf(this,t,r,!1)};ne.prototype.on=ne.prototype.addListener;ne.prototype.prependListener=function(t,r){return tf(this,t,r,!0)};function qh(){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 rf(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=qh.bind(n);return i.listener=r,n.wrapFn=i,i}ne.prototype.once=function(t,r){return yi(r),this.on(t,rf(this,t,r)),this};ne.prototype.prependOnceListener=function(t,r){return yi(r),this.prependListener(t,rf(this,t,r)),this};ne.prototype.removeListener=function(t,r){var n,i,s,o,a;if(yi(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():Kh(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};ne.prototype.off=ne.prototype.removeListener;ne.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 nf(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?Yh(i):of(i,i.length)}ne.prototype.listeners=function(t){return nf(this,t,!0)};ne.prototype.rawListeners=function(t){return nf(this,t,!1)};ne.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):sf.call(e,t)};ne.prototype.listenerCount=sf;function sf(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}ne.prototype.eventNames=function(){return this._eventsCount>0?Vn(this._events):[]};function of(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Kh(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Yh(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Xh(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))}af(e,t,s,{once:!0}),t!=="error"&&Jh(e,i,{once:!0})})}function Jh(e,t,r){typeof e.on=="function"&&af(e,"error",t,r)}function af(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 ff=Gs.exports,uf=ff.EventEmitter;const Qh={},Zh=Object.freeze(Object.defineProperty({__proto__:null,default:Qh},Symbol.toStringTag,{value:"Module"})),Ws=ba(Zh);var zi,Ro;function el(){if(Ro)return zi;Ro=1;function e(O,P){var A=Object.keys(O);if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(O);P&&(k=k.filter(function(U){return Object.getOwnPropertyDescriptor(O,U).enumerable})),A.push.apply(A,k)}return A}function t(O){for(var P=1;P<arguments.length;P++){var A=arguments[P]!=null?arguments[P]:{};P%2?e(Object(A),!0).forEach(function(k){r(O,k,A[k])}):Object.getOwnPropertyDescriptors?Object.defineProperties(O,Object.getOwnPropertyDescriptors(A)):e(Object(A)).forEach(function(k){Object.defineProperty(O,k,Object.getOwnPropertyDescriptor(A,k))})}return O}function r(O,P,A){return P=o(P),P in O?Object.defineProperty(O,P,{value:A,enumerable:!0,configurable:!0,writable:!0}):O[P]=A,O}function n(O,P){if(!(O instanceof P))throw new TypeError("Cannot call a class as a function")}function i(O,P){for(var A=0;A<P.length;A++){var k=P[A];k.enumerable=k.enumerable||!1,k.configurable=!0,"value"in k&&(k.writable=!0),Object.defineProperty(O,o(k.key),k)}}function s(O,P,A){return P&&i(O.prototype,P),Object.defineProperty(O,"prototype",{writable:!1}),O}function o(O){var P=a(O,"string");return typeof P=="symbol"?P:String(P)}function a(O,P){if(typeof O!="object"||O===null)return O;var A=O[Symbol.toPrimitive];if(A!==void 0){var k=A.call(O,P||"default");if(typeof k!="object")return k;throw new TypeError("@@toPrimitive must return a primitive value.")}return(P==="string"?String:Number)(O)}var c=At,l=c.Buffer,d=Ws,g=d.inspect,x=g&&g.custom||"inspect";function y(O,P,A){l.prototype.copy.call(O,P,A)}return zi=function(){function O(){n(this,O),this.head=null,this.tail=null,this.length=0}return s(O,[{key:"push",value:function(A){var k={data:A,next:null};this.length>0?this.tail.next=k:this.head=k,this.tail=k,++this.length}},{key:"unshift",value:function(A){var k={data:A,next:this.head};this.length===0&&(this.tail=k),this.head=k,++this.length}},{key:"shift",value:function(){if(this.length!==0){var A=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,A}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(A){if(this.length===0)return"";for(var k=this.head,U=""+k.data;k=k.next;)U+=A+k.data;return U}},{key:"concat",value:function(A){if(this.length===0)return l.alloc(0);for(var k=l.allocUnsafe(A>>>0),U=this.head,_=0;U;)y(U.data,k,_),_+=U.data.length,U=U.next;return k}},{key:"consume",value:function(A,k){var U;return A<this.head.data.length?(U=this.head.data.slice(0,A),this.head.data=this.head.data.slice(A)):A===this.head.data.length?U=this.shift():U=k?this._getString(A):this._getBuffer(A),U}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(A){var k=this.head,U=1,_=k.data;for(A-=_.length;k=k.next;){var m=k.data,S=A>m.length?m.length:A;if(S===m.length?_+=m:_+=m.slice(0,A),A-=S,A===0){S===m.length?(++U,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=m.slice(S));break}++U}return this.length-=U,_}},{key:"_getBuffer",value:function(A){var k=l.allocUnsafe(A),U=this.head,_=1;for(U.data.copy(k),A-=U.data.length;U=U.next;){var m=U.data,S=A>m.length?m.length:A;if(m.copy(k,k.length-A,0,S),A-=S,A===0){S===m.length?(++_,U.next?this.head=U.next:this.head=this.tail=null):(this.head=U,U.data=m.slice(S));break}++_}return this.length-=_,k}},{key:x,value:function(A,k){return g(this,t(t({},k),{},{depth:0,customInspect:!1}))}}]),O}(),zi}function tl(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(ws,this,e)):process.nextTick(ws,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(zn,r):(r._writableState.errorEmitted=!0,process.nextTick(Uo,r,s)):process.nextTick(Uo,r,s):t?(process.nextTick(zn,r),t(s)):process.nextTick(zn,r)}),this)}function Uo(e,t){ws(e,t),zn(e)}function zn(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function rl(){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 ws(e,t){e.emit("error",t)}function nl(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var cf={destroy:tl,undestroy:rl,errorOrDestroy:nl},cr={};function il(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var hf={};function Ze(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){il(o,s);function o(a,c,l){return s.call(this,n(a,c,l))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,hf[e]=i}function Co(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 sl(e,t,r){return e.substr(0,t.length)===t}function ol(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function al(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Ze("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Ze("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&sl(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(ol(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Co(t,"type"));else{var s=al(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Co(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Ze("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Ze("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Ze("ERR_STREAM_PREMATURE_CLOSE","Premature close");Ze("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Ze("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Ze("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Ze("ERR_STREAM_WRITE_AFTER_END","write after end");Ze("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Ze("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Ze("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");cr.codes=hf;var fl=cr.codes.ERR_INVALID_OPT_VALUE;function ul(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function cl(e,t,r,n){var i=ul(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new fl(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var lf={getHighWaterMark:cl},hl=ll;function ll(e,t){if(qi("noDeprecation"))return e;var r=!1;function n(){if(!r){if(qi("throwDeprecation"))throw new Error(t);qi("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function qi(e){try{if(!jt.localStorage)return!1}catch{return!1}var t=jt.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Ki,Lo;function df(){if(Lo)return Ki;Lo=1,Ki=D;function e(T){var B=this;this.next=null,this.entry=null,this.finish=function(){pt(B,T)}}var t;D.WritableState=E;var r={deprecate:hl},n=uf,i=At.Buffer,s=(typeof jt<"u"?jt:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(T){return i.from(T)}function a(T){return i.isBuffer(T)||T instanceof s}var c=cf,l=lf,d=l.getHighWaterMark,g=cr.codes,x=g.ERR_INVALID_ARG_TYPE,y=g.ERR_METHOD_NOT_IMPLEMENTED,O=g.ERR_MULTIPLE_CALLBACK,P=g.ERR_STREAM_CANNOT_PIPE,A=g.ERR_STREAM_DESTROYED,k=g.ERR_STREAM_NULL_VALUES,U=g.ERR_STREAM_WRITE_AFTER_END,_=g.ERR_UNKNOWN_ENCODING,m=c.errorOrDestroy;ke(D,n);function S(){}function E(T,B,F){t=t||Lr(),T=T||{},typeof F!="boolean"&&(F=B instanceof t),this.objectMode=!!T.objectMode,F&&(this.objectMode=this.objectMode||!!T.writableObjectMode),this.highWaterMark=d(this,T,"writableHighWaterMark",F),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var G=T.decodeStrings===!1;this.decodeStrings=!G,this.defaultEncoding=T.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(K){fe(B,K)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=T.emitClose!==!1,this.autoDestroy=!!T.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}E.prototype.getBuffer=function(){for(var B=this.bufferedRequest,F=[];B;)F.push(B),B=B.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(D,Symbol.hasInstance,{value:function(B){return H.call(this,B)?!0:this!==D?!1:B&&B._writableState instanceof E}})):H=function(B){return B instanceof this};function D(T){t=t||Lr();var B=this instanceof t;if(!B&&!H.call(D,this))return new D(T);this._writableState=new E(T,this,B),this.writable=!0,T&&(typeof T.write=="function"&&(this._write=T.write),typeof T.writev=="function"&&(this._writev=T.writev),typeof T.destroy=="function"&&(this._destroy=T.destroy),typeof T.final=="function"&&(this._final=T.final)),n.call(this)}D.prototype.pipe=function(){m(this,new P)};function R(T,B){var F=new U;m(T,F),process.nextTick(B,F)}function z(T,B,F,G){var K;return F===null?K=new k:typeof F!="string"&&!B.objectMode&&(K=new x("chunk",["string","Buffer"],F)),K?(m(T,K),process.nextTick(G,K),!1):!0}D.prototype.write=function(T,B,F){var G=this._writableState,K=!1,b=!G.objectMode&&a(T);return b&&!i.isBuffer(T)&&(T=o(T)),typeof B=="function"&&(F=B,B=null),b?B="buffer":B||(B=G.defaultEncoding),typeof F!="function"&&(F=S),G.ending?R(this,F):(b||z(this,G,T,F))&&(G.pendingcb++,K=C(this,G,b,T,B,F)),K},D.prototype.cork=function(){this._writableState.corked++},D.prototype.uncork=function(){var T=this._writableState;T.corked&&(T.corked--,!T.writing&&!T.corked&&!T.bufferProcessing&&T.bufferedRequest&&Ve(this,T))},D.prototype.setDefaultEncoding=function(B){if(typeof B=="string"&&(B=B.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((B+"").toLowerCase())>-1))throw new _(B);return this._writableState.defaultEncoding=B,this},Object.defineProperty(D.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Z(T,B,F){return!T.objectMode&&T.decodeStrings!==!1&&typeof B=="string"&&(B=i.from(B,F)),B}Object.defineProperty(D.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function C(T,B,F,G,K,b){if(!F){var w=Z(B,G,K);G!==w&&(F=!0,K="buffer",G=w)}var N=B.objectMode?1:G.length;B.length+=N;var $=B.length<B.highWaterMark;if($||(B.needDrain=!0),B.writing||B.corked){var we=B.lastBufferedRequest;B.lastBufferedRequest={chunk:G,encoding:K,isBuf:F,callback:b,next:null},we?we.next=B.lastBufferedRequest:B.bufferedRequest=B.lastBufferedRequest,B.bufferedRequestCount+=1}else M(T,B,!1,N,G,K,b);return $}function M(T,B,F,G,K,b,w){B.writelen=G,B.writecb=w,B.writing=!0,B.sync=!0,B.destroyed?B.onwrite(new A("write")):F?T._writev(K,B.onwrite):T._write(K,b,B.onwrite),B.sync=!1}function W(T,B,F,G,K){--B.pendingcb,F?(process.nextTick(K,G),process.nextTick(ze,T,B),T._writableState.errorEmitted=!0,m(T,G)):(K(G),T._writableState.errorEmitted=!0,m(T,G),ze(T,B))}function q(T){T.writing=!1,T.writecb=null,T.length-=T.writelen,T.writelen=0}function fe(T,B){var F=T._writableState,G=F.sync,K=F.writecb;if(typeof K!="function")throw new O;if(q(F),B)W(T,F,G,B,K);else{var b=it(F)||T.destroyed;!b&&!F.corked&&!F.bufferProcessing&&F.bufferedRequest&&Ve(T,F),G?process.nextTick(ue,T,F,b,K):ue(T,F,b,K)}}function ue(T,B,F,G){F||et(T,B),B.pendingcb--,G(),ze(T,B)}function et(T,B){B.length===0&&B.needDrain&&(B.needDrain=!1,T.emit("drain"))}function Ve(T,B){B.bufferProcessing=!0;var F=B.bufferedRequest;if(T._writev&&F&&F.next){var G=B.bufferedRequestCount,K=new Array(G),b=B.corkedRequestsFree;b.entry=F;for(var w=0,N=!0;F;)K[w]=F,F.isBuf||(N=!1),F=F.next,w+=1;K.allBuffers=N,M(T,B,!0,B.length,K,"",b.finish),B.pendingcb++,B.lastBufferedRequest=null,b.next?(B.corkedRequestsFree=b.next,b.next=null):B.corkedRequestsFree=new e(B),B.bufferedRequestCount=0}else{for(;F;){var $=F.chunk,we=F.encoding,Y=F.callback,te=B.objectMode?1:$.length;if(M(T,B,!1,te,$,we,Y),F=F.next,B.bufferedRequestCount--,B.writing)break}F===null&&(B.lastBufferedRequest=null)}B.bufferedRequest=F,B.bufferProcessing=!1}D.prototype._write=function(T,B,F){F(new y("_write()"))},D.prototype._writev=null,D.prototype.end=function(T,B,F){var G=this._writableState;return typeof T=="function"?(F=T,T=null,B=null):typeof B=="function"&&(F=B,B=null),T!=null&&this.write(T,B),G.corked&&(G.corked=1,this.uncork()),G.ending||It(this,G,F),this},Object.defineProperty(D.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function it(T){return T.ending&&T.length===0&&T.bufferedRequest===null&&!T.finished&&!T.writing}function be(T,B){T._final(function(F){B.pendingcb--,F&&m(T,F),B.prefinished=!0,T.emit("prefinish"),ze(T,B)})}function xe(T,B){!B.prefinished&&!B.finalCalled&&(typeof T._final=="function"&&!B.destroyed?(B.pendingcb++,B.finalCalled=!0,process.nextTick(be,T,B)):(B.prefinished=!0,T.emit("prefinish")))}function ze(T,B){var F=it(B);if(F&&(xe(T,B),B.pendingcb===0&&(B.finished=!0,T.emit("finish"),B.autoDestroy))){var G=T._readableState;(!G||G.autoDestroy&&G.endEmitted)&&T.destroy()}return F}function It(T,B,F){B.ending=!0,ze(T,B),F&&(B.finished?process.nextTick(F):T.once("finish",F)),B.ended=!0,T.writable=!1}function pt(T,B,F){var G=T.entry;for(T.entry=null;G;){var K=G.callback;B.pendingcb--,K(F),G=G.next}B.corkedRequestsFree.next=T}return Object.defineProperty(D.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(B){this._writableState&&(this._writableState.destroyed=B)}}),D.prototype.destroy=c.destroy,D.prototype._undestroy=c.undestroy,D.prototype._destroy=function(T,B){B(T)},Ki}var Yi,No;function Lr(){if(No)return Yi;No=1;var e=Object.keys||function(l){var d=[];for(var g in l)d.push(g);return d};Yi=o;var t=yf(),r=df();ke(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(l){if(!(this instanceof o))return new o(l);t.call(this,l),r.call(this,l),this.allowHalfOpen=!0,l&&(l.readable===!1&&(this.readable=!1),l.writable===!1&&(this.writable=!1),l.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(c,this)}function c(l){l.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)}}),Yi}var Qn={},Vs=We.Buffer,Fo=Vs.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 dl(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 pl(e){var t=dl(e);if(typeof t!="string"&&(Vs.isEncoding===Fo||!Fo(e)))throw new Error("Unknown encoding: "+e);return t||e}Qn.StringDecoder=gn;function gn(e){this.encoding=pl(e);var t;switch(this.encoding){case"utf16le":this.text=_l,this.end=vl,t=4;break;case"utf8":this.fillLast=wl,t=4;break;case"base64":this.text=El,this.end=xl,t=3;break;default:this.write=Sl,this.end=Bl;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Vs.allocUnsafe(t)}gn.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||""};gn.prototype.end=ml;gn.prototype.text=gl;gn.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 Xi(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function yl(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Xi(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Xi(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Xi(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function bl(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 wl(e){var t=this.lastTotal-this.lastNeed,r=bl(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 gl(e,t){var r=yl(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 ml(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function _l(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 vl(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 El(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 xl(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Sl(e){return e.toString(this.encoding)}function Bl(e){return e&&e.length?this.write(e):""}var Mo=cr.codes.ERR_STREAM_PREMATURE_CLOSE;function Pl(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 Tl(){}function Al(e){return e.setHeader&&typeof e.abort=="function"}function pf(e,t,r){if(typeof t=="function")return pf(e,null,t);t||(t={}),r=Pl(r||Tl);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)},c=e._readableState&&e._readableState.endEmitted,l=function(){n=!1,c=!0,i||r.call(e)},d=function(O){r.call(e,O)},g=function(){var O;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(O=new Mo),r.call(e,O);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(O=new Mo),r.call(e,O)},x=function(){e.req.on("finish",a)};return Al(e)?(e.on("complete",a),e.on("abort",g),e.req?x():e.on("request",x)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",l),e.on("finish",a),t.error!==!1&&e.on("error",d),e.on("close",g),function(){e.removeListener("complete",a),e.removeListener("abort",g),e.removeListener("request",x),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",l),e.removeListener("error",d),e.removeListener("close",g)}}var zs=pf,Ji,Ho;function Il(){if(Ho)return Ji;Ho=1;var e;function t(_,m,S){return m=r(m),m in _?Object.defineProperty(_,m,{value:S,enumerable:!0,configurable:!0,writable:!0}):_[m]=S,_}function r(_){var m=n(_,"string");return typeof m=="symbol"?m:String(m)}function n(_,m){if(typeof _!="object"||_===null)return _;var S=_[Symbol.toPrimitive];if(S!==void 0){var E=S.call(_,m||"default");if(typeof E!="object")return E;throw new TypeError("@@toPrimitive must return a primitive value.")}return(m==="string"?String:Number)(_)}var i=zs,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),l=Symbol("lastPromise"),d=Symbol("handlePromise"),g=Symbol("stream");function x(_,m){return{value:_,done:m}}function y(_){var m=_[s];if(m!==null){var S=_[g].read();S!==null&&(_[l]=null,_[s]=null,_[o]=null,m(x(S,!1)))}}function O(_){process.nextTick(y,_)}function P(_,m){return function(S,E){_.then(function(){if(m[c]){S(x(void 0,!0));return}m[d](S,E)},E)}}var A=Object.getPrototypeOf(function(){}),k=Object.setPrototypeOf((e={get stream(){return this[g]},next:function(){var m=this,S=this[a];if(S!==null)return Promise.reject(S);if(this[c])return Promise.resolve(x(void 0,!0));if(this[g].destroyed)return new Promise(function(R,z){process.nextTick(function(){m[a]?z(m[a]):R(x(void 0,!0))})});var E=this[l],H;if(E)H=new Promise(P(E,this));else{var D=this[g].read();if(D!==null)return Promise.resolve(x(D,!1));H=new Promise(this[d])}return this[l]=H,H}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var m=this;return new Promise(function(S,E){m[g].destroy(null,function(H){if(H){E(H);return}S(x(void 0,!0))})})}),e),A),U=function(m){var S,E=Object.create(k,(S={},t(S,g,{value:m,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,c,{value:m._readableState.endEmitted,writable:!0}),t(S,d,{value:function(D,R){var z=E[g].read();z?(E[l]=null,E[s]=null,E[o]=null,D(x(z,!1))):(E[s]=D,E[o]=R)},writable:!0}),S));return E[l]=null,i(m,function(H){if(H&&H.code!=="ERR_STREAM_PREMATURE_CLOSE"){var D=E[o];D!==null&&(E[l]=null,E[s]=null,E[o]=null,D(H)),E[a]=H;return}var R=E[s];R!==null&&(E[l]=null,E[s]=null,E[o]=null,R(x(void 0,!0))),E[c]=!0}),m.on("readable",O.bind(null,E)),E};return Ji=U,Ji}var Qi,$o;function Ol(){return $o||($o=1,Qi=function(){throw new Error("Readable.from is not available in the browser")}),Qi}var Zi,Do;function yf(){if(Do)return Zi;Do=1,Zi=R;var e;R.ReadableState=D,ff.EventEmitter;var t=function(w,N){return w.listeners(N).length},r=uf,n=At.Buffer,i=(typeof jt<"u"?jt: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=Ws,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var l=el(),d=cf,g=lf,x=g.getHighWaterMark,y=cr.codes,O=y.ERR_INVALID_ARG_TYPE,P=y.ERR_STREAM_PUSH_AFTER_EOF,A=y.ERR_METHOD_NOT_IMPLEMENTED,k=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,U,_,m;ke(R,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 D(b,w,N){e=e||Lr(),b=b||{},typeof N!="boolean"&&(N=w instanceof e),this.objectMode=!!b.objectMode,N&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=x(this,b,"readableHighWaterMark",N),this.buffer=new l,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=Qn.StringDecoder),this.decoder=new U(b.encoding),this.encoding=b.encoding)}function R(b){if(e=e||Lr(),!(this instanceof R))return new R(b);var w=this instanceof e;this._readableState=new D(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(R.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(w){this._readableState&&(this._readableState.destroyed=w)}}),R.prototype.destroy=d.destroy,R.prototype._undestroy=d.undestroy,R.prototype._destroy=function(b,w){w(b)},R.prototype.push=function(b,w){var N=this._readableState,$;return N.objectMode?$=!0:typeof b=="string"&&(w=w||N.defaultEncoding,w!==N.encoding&&(b=n.from(b,w),w=""),$=!0),z(this,b,w,!1,$)},R.prototype.unshift=function(b){return z(this,b,null,!0,!1)};function z(b,w,N,$,we){c("readableAddChunk",w);var Y=b._readableState;if(w===null)Y.reading=!1,fe(b,Y);else{var te;if(we||(te=C(Y,w)),te)S(b,te);else if(Y.objectMode||w&&w.length>0)if(typeof w!="string"&&!Y.objectMode&&Object.getPrototypeOf(w)!==n.prototype&&(w=s(w)),$)Y.endEmitted?S(b,new k):Z(b,Y,w,!0);else if(Y.ended)S(b,new P);else{if(Y.destroyed)return!1;Y.reading=!1,Y.decoder&&!N?(w=Y.decoder.write(w),Y.objectMode||w.length!==0?Z(b,Y,w,!1):Ve(b,Y)):Z(b,Y,w,!1)}else $||(Y.reading=!1,Ve(b,Y))}return!Y.ended&&(Y.length<Y.highWaterMark||Y.length===0)}function Z(b,w,N,$){w.flowing&&w.length===0&&!w.sync?(w.awaitDrain=0,b.emit("data",N)):(w.length+=w.objectMode?1:N.length,$?w.buffer.unshift(N):w.buffer.push(N),w.needReadable&&ue(b)),Ve(b,w)}function C(b,w){var N;return!o(w)&&typeof w!="string"&&w!==void 0&&!b.objectMode&&(N=new O("chunk",["string","Buffer","Uint8Array"],w)),N}R.prototype.isPaused=function(){return this._readableState.flowing===!1},R.prototype.setEncoding=function(b){U||(U=Qn.StringDecoder);var w=new U(b);this._readableState.decoder=w,this._readableState.encoding=this._readableState.decoder.encoding;for(var N=this._readableState.buffer.head,$="";N!==null;)$+=w.write(N.data),N=N.next;return this._readableState.buffer.clear(),$!==""&&this._readableState.buffer.push($),this._readableState.length=$.length,this};var M=1073741824;function W(b){return b>=M?b=M:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function q(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=W(b)),b<=w.length?b:w.ended?w.length:(w.needReadable=!0,0))}R.prototype.read=function(b){c("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 c("read: emitReadable",w.length,w.ended),w.length===0&&w.ended?F(this):ue(this),null;if(b=q(b,w),b===0&&w.ended)return w.length===0&&F(this),null;var $=w.needReadable;c("need readable",$),(w.length===0||w.length-b<w.highWaterMark)&&($=!0,c("length less than watermark",$)),w.ended||w.reading?($=!1,c("reading or ended",$)):$&&(c("do read"),w.reading=!0,w.sync=!0,w.length===0&&(w.needReadable=!0),this._read(w.highWaterMark),w.sync=!1,w.reading||(b=q(N,w)));var we;return b>0?we=B(b,w):we=null,we===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)),we!==null&&this.emit("data",we),we};function fe(b,w){if(c("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?ue(b):(w.needReadable=!1,w.emittedReadable||(w.emittedReadable=!0,et(b)))}}function ue(b){var w=b._readableState;c("emitReadable",w.needReadable,w.emittedReadable),w.needReadable=!1,w.emittedReadable||(c("emitReadable",w.flowing),w.emittedReadable=!0,process.nextTick(et,b))}function et(b){var w=b._readableState;c("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,T(b)}function Ve(b,w){w.readingMore||(w.readingMore=!0,process.nextTick(it,b,w))}function it(b,w){for(;!w.reading&&!w.ended&&(w.length<w.highWaterMark||w.flowing&&w.length===0);){var N=w.length;if(c("maybeReadMore read 0"),b.read(0),N===w.length)break}w.readingMore=!1}R.prototype._read=function(b){S(this,new A("_read()"))},R.prototype.pipe=function(b,w){var N=this,$=this._readableState;switch($.pipesCount){case 0:$.pipes=b;break;case 1:$.pipes=[$.pipes,b];break;default:$.pipes.push(b);break}$.pipesCount+=1,c("pipe count=%d opts=%j",$.pipesCount,w);var we=(!w||w.end!==!1)&&b!==process.stdout&&b!==process.stderr,Y=we?Ot:Yt;$.endEmitted?process.nextTick(Y):N.once("end",Y),b.on("unpipe",te);function te(h,f){c("onunpipe"),h===N&&f&&f.hasUnpiped===!1&&(f.hasUnpiped=!0,pr())}function Ot(){c("onend"),b.end()}var dr=be(N);b.on("drain",dr);var $r=!1;function pr(){c("cleanup"),b.removeListener("close",Dr),b.removeListener("finish",Xe),b.removeListener("drain",dr),b.removeListener("error",Kt),b.removeListener("unpipe",te),N.removeListener("end",Ot),N.removeListener("end",Yt),N.removeListener("data",qe),$r=!0,$.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&dr()}N.on("data",qe);function qe(h){c("ondata");var f=b.write(h);c("dest.write",f),f===!1&&(($.pipesCount===1&&$.pipes===b||$.pipesCount>1&&K($.pipes,b)!==-1)&&!$r&&(c("false write response, pause",$.awaitDrain),$.awaitDrain++),N.pause())}function Kt(h){c("onerror",h),Yt(),b.removeListener("error",Kt),t(b,"error")===0&&S(b,h)}H(b,"error",Kt);function Dr(){b.removeListener("finish",Xe),Yt()}b.once("close",Dr);function Xe(){c("onfinish"),b.removeListener("close",Dr),Yt()}b.once("finish",Xe);function Yt(){c("unpipe"),N.unpipe(b)}return b.emit("pipe",N),$.flowing||(c("pipe resume"),N.resume()),b};function be(b){return function(){var N=b._readableState;c("pipeOnDrain",N.awaitDrain),N.awaitDrain&&N.awaitDrain--,N.awaitDrain===0&&t(b,"data")&&(N.flowing=!0,T(b))}}R.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 $=w.pipes,we=w.pipesCount;w.pipes=null,w.pipesCount=0,w.flowing=!1;for(var Y=0;Y<we;Y++)$[Y].emit("unpipe",this,{hasUnpiped:!1});return this}var te=K(w.pipes,b);return te===-1?this:(w.pipes.splice(te,1),w.pipesCount-=1,w.pipesCount===1&&(w.pipes=w.pipes[0]),b.emit("unpipe",this,N),this)},R.prototype.on=function(b,w){var N=r.prototype.on.call(this,b,w),$=this._readableState;return b==="data"?($.readableListening=this.listenerCount("readable")>0,$.flowing!==!1&&this.resume()):b==="readable"&&!$.endEmitted&&!$.readableListening&&($.readableListening=$.needReadable=!0,$.flowing=!1,$.emittedReadable=!1,c("on readable",$.length,$.reading),$.length?ue(this):$.reading||process.nextTick(ze,this)),N},R.prototype.addListener=R.prototype.on,R.prototype.removeListener=function(b,w){var N=r.prototype.removeListener.call(this,b,w);return b==="readable"&&process.nextTick(xe,this),N},R.prototype.removeAllListeners=function(b){var w=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(xe,this),w};function xe(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 ze(b){c("readable nexttick read 0"),b.read(0)}R.prototype.resume=function(){var b=this._readableState;return b.flowing||(c("resume"),b.flowing=!b.readableListening,It(this,b)),b.paused=!1,this};function It(b,w){w.resumeScheduled||(w.resumeScheduled=!0,process.nextTick(pt,b,w))}function pt(b,w){c("resume",w.reading),w.reading||b.read(0),w.resumeScheduled=!1,b.emit("resume"),T(b),w.flowing&&!w.reading&&b.read(0)}R.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function T(b){var w=b._readableState;for(c("flow",w.flowing);w.flowing&&b.read()!==null;);}R.prototype.wrap=function(b){var w=this,N=this._readableState,$=!1;b.on("end",function(){if(c("wrapped end"),N.decoder&&!N.ended){var te=N.decoder.end();te&&te.length&&w.push(te)}w.push(null)}),b.on("data",function(te){if(c("wrapped data"),N.decoder&&(te=N.decoder.write(te)),!(N.objectMode&&te==null)&&!(!N.objectMode&&(!te||!te.length))){var Ot=w.push(te);Ot||($=!0,b.pause())}});for(var we in b)this[we]===void 0&&typeof b[we]=="function"&&(this[we]=function(Ot){return function(){return b[Ot].apply(b,arguments)}}(we));for(var Y=0;Y<E.length;Y++)b.on(E[Y],this.emit.bind(this,E[Y]));return this._read=function(te){c("wrapped _read",te),$&&($=!1,b.resume())},this},typeof Symbol=="function"&&(R.prototype[Symbol.asyncIterator]=function(){return _===void 0&&(_=Il()),_(this)}),Object.defineProperty(R.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(R.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(R.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(w){this._readableState&&(this._readableState.flowing=w)}}),R._fromList=B,Object.defineProperty(R.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function B(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;c("endReadable",w.endEmitted),w.endEmitted||(w.ended=!0,process.nextTick(G,w,b))}function G(b,w){if(c("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"&&(R.from=function(b,w){return m===void 0&&(m=Ol()),m(R,b,w)});function K(b,w){for(var N=0,$=b.length;N<$;N++)if(b[N]===w)return N;return-1}return Zi}var bf=Tt,bi=cr.codes,kl=bi.ERR_METHOD_NOT_IMPLEMENTED,Rl=bi.ERR_MULTIPLE_CALLBACK,Ul=bi.ERR_TRANSFORM_ALREADY_TRANSFORMING,Cl=bi.ERR_TRANSFORM_WITH_LENGTH_0,wi=Lr();ke(Tt,wi);function Ll(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new Rl);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 Tt(e){if(!(this instanceof Tt))return new Tt(e);wi.call(this,e),this._transformState={afterTransform:Ll.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",Nl)}function Nl(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){jo(e,t,r)}):jo(this,null,null)}Tt.prototype.push=function(e,t){return this._transformState.needTransform=!1,wi.prototype.push.call(this,e,t)};Tt.prototype._transform=function(e,t,r){r(new kl("_transform()"))};Tt.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)}};Tt.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};Tt.prototype._destroy=function(e,t){wi.prototype._destroy.call(this,e,function(r){t(r)})};function jo(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Cl;if(e._transformState.transforming)throw new Ul;return e.push(null)}var Fl=dn,wf=bf;ke(dn,wf);function dn(e){if(!(this instanceof dn))return new dn(e);wf.call(this,e)}dn.prototype._transform=function(e,t,r){r(null,e)};var es;function Ml(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var gf=cr.codes,Hl=gf.ERR_MISSING_ARGS,$l=gf.ERR_STREAM_DESTROYED;function Go(e){if(e)throw e}function Dl(e){return e.setHeader&&typeof e.abort=="function"}function jl(e,t,r,n){n=Ml(n);var i=!1;e.on("close",function(){i=!0}),es===void 0&&(es=zs),es(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,Dl(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new $l("pipe"))}}}function Wo(e){e()}function Gl(e,t){return e.pipe(t)}function Wl(e){return!e.length||typeof e[e.length-1]!="function"?Go:e.pop()}function Vl(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=Wl(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Hl("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,l=a>0;return jl(o,c,l,function(d){i||(i=d),d&&s.forEach(Wo),!c&&(s.forEach(Wo),n(i))})});return t.reduce(Gl)}var zl=Vl;(function(e,t){t=e.exports=yf(),t.Stream=t,t.Readable=t,t.Writable=df(),t.Duplex=Lr(),t.Transform=bf,t.PassThrough=Fl,t.finished=zs,t.pipeline=zl})(bs,bs.exports);var mf=bs.exports,Zn=We.Buffer,_f=mf.Transform,ql=ke;function Kl(e,t){if(!Zn.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Vt(e){_f.call(this),this._block=Zn.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}ql(Vt,_f);Vt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Vt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Vt.prototype.update=function(e,t){if(Kl(e,"Data"),this._finalized)throw new Error("Digest already called");Zn.isBuffer(e)||(e=Zn.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};Vt.prototype._update=function(){throw new Error("_update is not implemented")};Vt.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};Vt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Yl=Vt,Xl=ke,vf=Yl,Jl=We.Buffer,Ql=new Array(16);function gi(){vf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}Xl(gi,vf);gi.prototype._update=function(){for(var e=Ql,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=Ue(r,n,i,s,e[1],4129170786,5),s=Ue(s,r,n,i,e[6],3225465664,9),i=Ue(i,s,r,n,e[11],643717713,14),n=Ue(n,i,s,r,e[0],3921069994,20),r=Ue(r,n,i,s,e[5],3593408605,5),s=Ue(s,r,n,i,e[10],38016083,9),i=Ue(i,s,r,n,e[15],3634488961,14),n=Ue(n,i,s,r,e[4],3889429448,20),r=Ue(r,n,i,s,e[9],568446438,5),s=Ue(s,r,n,i,e[14],3275163606,9),i=Ue(i,s,r,n,e[3],4107603335,14),n=Ue(n,i,s,r,e[8],1163531501,20),r=Ue(r,n,i,s,e[13],2850285829,5),s=Ue(s,r,n,i,e[2],4243563512,9),i=Ue(i,s,r,n,e[7],1735328473,14),n=Ue(n,i,s,r,e[12],2368359562,20),r=Ce(r,n,i,s,e[5],4294588738,4),s=Ce(s,r,n,i,e[8],2272392833,11),i=Ce(i,s,r,n,e[11],1839030562,16),n=Ce(n,i,s,r,e[14],4259657740,23),r=Ce(r,n,i,s,e[1],2763975236,4),s=Ce(s,r,n,i,e[4],1272893353,11),i=Ce(i,s,r,n,e[7],4139469664,16),n=Ce(n,i,s,r,e[10],3200236656,23),r=Ce(r,n,i,s,e[13],681279174,4),s=Ce(s,r,n,i,e[0],3936430074,11),i=Ce(i,s,r,n,e[3],3572445317,16),n=Ce(n,i,s,r,e[6],76029189,23),r=Ce(r,n,i,s,e[9],3654602809,4),s=Ce(s,r,n,i,e[12],3873151461,11),i=Ce(i,s,r,n,e[15],530742520,16),n=Ce(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};gi.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=Jl.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 mi(e,t){return e<<t|e>>>32-t}function Re(e,t,r,n,i,s,o){return mi(e+(t&r|~t&n)+i+s|0,o)+t|0}function Ue(e,t,r,n,i,s,o){return mi(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ce(e,t,r,n,i,s,o){return mi(e+(t^r^n)+i+s|0,o)+t|0}function Le(e,t,r,n,i,s,o){return mi(e+(r^(t|~n))+i+s|0,o)+t|0}var Zl=gi,ei=We.Buffer,Ef=mf.Transform,e0=ke;function t0(e,t){if(!ei.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function zt(e){Ef.call(this),this._block=ei.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}e0(zt,Ef);zt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};zt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};zt.prototype.update=function(e,t){if(t0(e,"Data"),this._finalized)throw new Error("Digest already called");ei.isBuffer(e)||(e=ei.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};zt.prototype._update=function(){throw new Error("_update is not implemented")};zt.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};zt.prototype._digest=function(){throw new Error("_digest is not implemented")};var r0=zt,ts=At.Buffer,n0=ke,xf=r0,i0=new Array(16),Kr=[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],Yr=[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],Xr=[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],Jr=[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],Qr=[0,1518500249,1859775393,2400959708,2840853838],Zr=[1352829926,1548603684,1836072691,2053994217,0];function _i(){xf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}n0(_i,xf);_i.prototype._update=function(){for(var e=i0,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,c=this._b|0,l=this._c|0,d=this._d|0,g=this._e|0,x=0;x<80;x+=1){var y,O;x<16?(y=Vo(r,n,i,s,o,e[Kr[x]],Qr[0],Xr[x]),O=Yo(a,c,l,d,g,e[Yr[x]],Zr[0],Jr[x])):x<32?(y=zo(r,n,i,s,o,e[Kr[x]],Qr[1],Xr[x]),O=Ko(a,c,l,d,g,e[Yr[x]],Zr[1],Jr[x])):x<48?(y=qo(r,n,i,s,o,e[Kr[x]],Qr[2],Xr[x]),O=qo(a,c,l,d,g,e[Yr[x]],Zr[2],Jr[x])):x<64?(y=Ko(r,n,i,s,o,e[Kr[x]],Qr[3],Xr[x]),O=zo(a,c,l,d,g,e[Yr[x]],Zr[3],Jr[x])):(y=Yo(r,n,i,s,o,e[Kr[x]],Qr[4],Xr[x]),O=Vo(a,c,l,d,g,e[Yr[x]],Zr[4],Jr[x])),r=o,o=s,s=nr(i,10),i=n,n=y,a=g,g=d,d=nr(l,10),l=c,c=O}var P=this._b+i+d|0;this._b=this._c+s+g|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+l|0,this._a=P};_i.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=ts.alloc?ts.alloc(20):new ts(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 nr(e,t){return e<<t|e>>>32-t}function Vo(e,t,r,n,i,s,o,a){return nr(e+(t^r^n)+s+o|0,a)+i|0}function zo(e,t,r,n,i,s,o,a){return nr(e+(t&r|~t&n)+s+o|0,a)+i|0}function qo(e,t,r,n,i,s,o,a){return nr(e+((t|~r)^n)+s+o|0,a)+i|0}function Ko(e,t,r,n,i,s,o,a){return nr(e+(t&n|r&~n)+s+o|0,a)+i|0}function Yo(e,t,r,n,i,s,o,a){return nr(e+(t^(r|~n))+s+o|0,a)+i|0}var s0=_i,Sf={exports:{}},Bf=We.Buffer;function vi(e,t){this._block=Bf.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}vi.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Bf.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,c=Math.min(i-o,n-a),l=0;l<c;l++)r[a+l]=e[o+l];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};vi.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};vi.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Fr=vi,o0=ke,Pf=Fr,a0=We.Buffer,f0=[1518500249,1859775393,-1894007588,-899497514],u0=new Array(80);function mn(){this.init(),this._w=u0,Pf.call(this,64,56)}o0(mn,Pf);mn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function c0(e){return e<<5|e>>>27}function h0(e){return e<<30|e>>>2}function l0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}mn.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 c=0;c<80;++c){var l=~~(c/20),d=c0(r)+l0(l,n,i,s)+o+t[c]+f0[l]|0;o=s,s=i,i=h0(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};mn.prototype._hash=function(){var e=a0.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 d0=mn,p0=ke,Tf=Fr,y0=We.Buffer,b0=[1518500249,1859775393,-1894007588,-899497514],w0=new Array(80);function _n(){this.init(),this._w=w0,Tf.call(this,64,56)}p0(_n,Tf);_n.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function g0(e){return e<<1|e>>>31}function m0(e){return e<<5|e>>>27}function _0(e){return e<<30|e>>>2}function v0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}_n.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]=g0(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var l=~~(c/20),d=m0(r)+v0(l,n,i,s)+o+t[c]+b0[l]|0;o=s,s=i,i=_0(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};_n.prototype._hash=function(){var e=y0.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 E0=_n,x0=ke,Af=Fr,S0=We.Buffer,B0=[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],P0=new Array(64);function vn(){this.init(),this._w=P0,Af.call(this,64,56)}x0(vn,Af);vn.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 T0(e,t,r){return r^e&(t^r)}function A0(e,t,r){return e&t|r&(e|t)}function I0(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function O0(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function k0(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function R0(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}vn.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,c=this._g|0,l=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=R0(t[d-2])+t[d-7]+k0(t[d-15])+t[d-16]|0;for(var g=0;g<64;++g){var x=l+O0(o)+T0(o,a,c)+B0[g]+t[g]|0,y=I0(r)+A0(r,n,i)|0;l=c,c=a,a=o,o=s+x|0,s=i,i=n,n=r,r=x+y|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=c+this._g|0,this._h=l+this._h|0};vn.prototype._hash=function(){var e=S0.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 If=vn,U0=ke,C0=If,L0=Fr,N0=We.Buffer,F0=new Array(64);function Ei(){this.init(),this._w=F0,L0.call(this,64,56)}U0(Ei,C0);Ei.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};Ei.prototype._hash=function(){var e=N0.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 M0=Ei,H0=ke,Of=Fr,$0=We.Buffer,Xo=[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],D0=new Array(160);function En(){this.init(),this._w=D0,Of.call(this,128,112)}H0(En,Of);En.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 Jo(e,t,r){return r^e&(t^r)}function Qo(e,t,r){return e&t|r&(e|t)}function Zo(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function ea(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function j0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function G0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function W0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function V0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ae(e,t){return e>>>0<t>>>0?1:0}En.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,c=this._gh|0,l=this._hh|0,d=this._al|0,g=this._bl|0,x=this._cl|0,y=this._dl|0,O=this._el|0,P=this._fl|0,A=this._gl|0,k=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 _=t[U-30],m=t[U-15*2+1],S=j0(_,m),E=G0(m,_);_=t[U-2*2],m=t[U-2*2+1];var H=W0(_,m),D=V0(m,_),R=t[U-7*2],z=t[U-7*2+1],Z=t[U-16*2],C=t[U-16*2+1],M=E+z|0,W=S+R+Ae(M,E)|0;M=M+D|0,W=W+H+Ae(M,D)|0,M=M+C|0,W=W+Z+Ae(M,C)|0,t[U]=W,t[U+1]=M}for(var q=0;q<160;q+=2){W=t[q],M=t[q+1];var fe=Qo(r,n,i),ue=Qo(d,g,x),et=Zo(r,d),Ve=Zo(d,r),it=ea(o,O),be=ea(O,o),xe=Xo[q],ze=Xo[q+1],It=Jo(o,a,c),pt=Jo(O,P,A),T=k+be|0,B=l+it+Ae(T,k)|0;T=T+pt|0,B=B+It+Ae(T,pt)|0,T=T+ze|0,B=B+xe+Ae(T,ze)|0,T=T+M|0,B=B+W+Ae(T,M)|0;var F=Ve+ue|0,G=et+fe+Ae(F,Ve)|0;l=c,k=A,c=a,A=P,a=o,P=O,O=y+T|0,o=s+B+Ae(O,y)|0,s=i,y=x,i=n,x=g,n=r,g=d,d=T+F|0,r=B+G+Ae(d,T)|0}this._al=this._al+d|0,this._bl=this._bl+g|0,this._cl=this._cl+x|0,this._dl=this._dl+y|0,this._el=this._el+O|0,this._fl=this._fl+P|0,this._gl=this._gl+A|0,this._hl=this._hl+k|0,this._ah=this._ah+r+Ae(this._al,d)|0,this._bh=this._bh+n+Ae(this._bl,g)|0,this._ch=this._ch+i+Ae(this._cl,x)|0,this._dh=this._dh+s+Ae(this._dl,y)|0,this._eh=this._eh+o+Ae(this._el,O)|0,this._fh=this._fh+a+Ae(this._fl,P)|0,this._gh=this._gh+c+Ae(this._gl,A)|0,this._hh=this._hh+l+Ae(this._hl,k)|0};En.prototype._hash=function(){var e=$0.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 kf=En,z0=ke,q0=kf,K0=Fr,Y0=We.Buffer,X0=new Array(160);function xi(){this.init(),this._w=X0,K0.call(this,128,112)}z0(xi,q0);xi.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};xi.prototype._hash=function(){var e=Y0.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 J0=xi,hr=Sf.exports=function(t){t=t.toLowerCase();var r=hr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};hr.sha=d0;hr.sha1=E0;hr.sha224=M0;hr.sha256=If;hr.sha384=J0;hr.sha512=kf;var Q0=Sf.exports,Rf=We.Buffer,Uf=Ws.Transform,Z0=Qn.StringDecoder,ed=ke;function nt(e){Uf.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}ed(nt,Uf);nt.prototype.update=function(e,t,r){typeof e=="string"&&(e=Rf.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};nt.prototype.setAutoPadding=function(){};nt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};nt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};nt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};nt.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)}};nt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};nt.prototype._finalOrDigest=function(e){var t=this.__final()||Rf.alloc(0);return e&&(t=this._toString(t,e,!0)),t};nt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Z0(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 td=nt,rd=ke,nd=Zl,id=s0,sd=Q0,Cf=td;function Si(e){Cf.call(this,"digest"),this._hash=e}rd(Si,Cf);Si.prototype._update=function(e){this._hash.update(e)};Si.prototype._final=function(){return this._hash.digest()};var od=function(t){return t=t.toLowerCase(),t==="md5"?new nd:t==="rmd160"||t==="ripemd160"?new id:new Si(sd(t))},Cn=We.Buffer;function ad(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),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if((Array.isArray(y)||y instanceof Uint8Array)&&(y=Cn.from(y)),!Cn.isBuffer(y))throw new TypeError("Expected Buffer");if(y.length===0)return"";for(var O=0,P=0,A=0,k=y.length;A!==k&&y[A]===0;)A++,O++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=y[A],S=0,E=U-1;(m!==0||S<P)&&E!==-1;E--,S++)m+=256*_[E]>>>0,_[E]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");P=S,A++}for(var H=U-P;H!==U&&_[H]===0;)H++;for(var D=a.repeat(O);H<U;++H)D+=e.charAt(_[H]);return D}function g(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return Cn.alloc(0);for(var O=0,P=0,A=0;y[O]===a;)P++,O++;for(var k=(y.length-O)*c+1>>>0,U=new Uint8Array(k);O<y.length;){var _=t[y.charCodeAt(O)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,O++}for(var E=k-A;E!==k&&U[E]===0;)E++;var H=Cn.allocUnsafe(P+(k-E));H.fill(0,0,P);for(var D=P;E!==k;)H[D++]=U[E++];return H}function x(y){var O=g(y);if(O)return O;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:g,decode:x}}var fd=ad,ud=fd,cd="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",hd=ud(cd),rs=hd,ld=We.Buffer,dd=function(e){function t(s){var o=e(s);return rs.encode(ld.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=rs.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=rs.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},ta=od,pd=dd;function yd(e){var t=ta("sha256").update(e).digest();return ta("sha256").update(t).digest()}var bd=pd(yd),gs=bd;function Lf(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 ms(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 wd(e,t){return Lf(gs.decode(e),t)}function gd(e,t,r){return typeof e=="number"?gs.encode(ms(e,t,r)):gs.encode(ms(e.version,e.privateKey,e.compressed))}var md={decode:wd,decodeRaw:Lf,encode:gd,encodeRaw:ms},Bi={};Object.defineProperty(Bi,"__esModule",{value:!0});Bi.testEcc=void 0;const V=e=>Buffer.from(e,"hex");function _d(e){he(e.isPoint(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(!e.isPoint(V("030000000000000000000000000000000000000000000000000000000000000005"))),he(e.isPrivate(V("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),he(!e.isPrivate(V("0000000000000000000000000000000000000000000000000000000000000000"))),he(!e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),he(!e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),he(Buffer.from(e.privateAdd(V("0000000000000000000000000000000000000000000000000000000000000001"),V("0000000000000000000000000000000000000000000000000000000000000000"))).equals(V("0000000000000000000000000000000000000000000000000000000000000001"))),he(e.privateAdd(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),V("0000000000000000000000000000000000000000000000000000000000000003"))===null),he(Buffer.from(e.privateAdd(V("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),V("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(V("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),he(Buffer.from(e.privateNegate(V("0000000000000000000000000000000000000000000000000000000000000001"))).equals(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),he(Buffer.from(e.privateNegate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(V("0000000000000000000000000000000000000000000000000000000000000003"))),he(Buffer.from(e.privateNegate(V("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(V("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),he(Buffer.from(e.pointCompress(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(Buffer.from(e.pointCompress(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),he(Buffer.from(e.pointCompress(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(Buffer.from(e.pointCompress(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),he(Buffer.from(e.pointFromScalar(V("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(V("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),he(e.xOnlyPointAddTweak(V("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(V("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),V("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));he(Buffer.from(t.xOnlyPubkey).equals(V("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(V("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),V("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),he(Buffer.from(t.xOnlyPubkey).equals(V("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),he(Buffer.from(e.sign(V("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(V("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),he(e.verify(V("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),V("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),V("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&he(Buffer.from(e.signSchnorr(V("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),V("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),V("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(V("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&he(e.verifySchnorr(V("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),V("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),V("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}Bi.testEcc=_d;function he(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(Ur,"__esModule",{value:!0});Ur.ECPairFactory=Ur.networks=void 0;const _s=Cr;Ur.networks=_s;const je=Qa,vd=Vh,ra=md,Ed=Bi,ns=je.typeforce.maybe(je.typeforce.compile({compressed:je.maybe(je.Boolean),network:je.maybe(je.Network)})),xd=e=>e.length===32?e:e.slice(1,33);function Sd(e){(0,Ed.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(je.typeforce(je.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return je.typeforce(ns,c),new o(a,void 0,c)}function n(a,c){return je.typeforce(e.isPoint,a),je.typeforce(ns,c),new o(void 0,a,c)}function i(a,c){const l=ra.decode(a),d=l.version;if(je.Array(c)){if(c=c.filter(g=>d===g.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||_s.bitcoin,d!==c.wif)throw new Error("Invalid network version");return r(l.privateKey,{compressed:l.compressed,network:c})}function s(a){je.typeforce(ns,a),a===void 0&&(a={});const c=a.rng||vd;let l;do l=c(32),je.typeforce(je.Buffer256bit,l);while(!e.isPrivate(l));return r(l,a)}class o{constructor(c,l,d){yr(this,"__D");yr(this,"__Q");yr(this,"compressed");yr(this,"network");yr(this,"lowR");this.__D=c,this.__Q=l,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||_s.bitcoin,l!==void 0&&(this.__Q=Buffer.from(e.pointCompress(l,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const c=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(c)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return ra.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,l){if(!this.__D)throw new Error("Missing private key");if(l===void 0&&(l=this.lowR),l===!1)return Buffer.from(e.sign(c,this.__D));{let d=e.sign(c,this.__D);const g=Buffer.alloc(32,0);let x=0;for(;d[0]>127;)x++,g.writeUIntLE(x,0,6),d=e.sign(c,this.__D,g);return Buffer.from(d)}}signSchnorr(c){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(c,this.privateKey))}verify(c,l){return e.verify(c,this.publicKey,l)}verifySchnorr(c,l){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),l)}tweakFromPublicKey(c){const l=xd(this.publicKey),d=e.xOnlyPointAddTweak(l,c);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const g=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([g,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,g=e.privateAdd(d,c);if(!g)throw new Error("Invalid tweaked private key!");return r(Buffer.from(g),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}Ur.ECPairFactory=Sd;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=Ur;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}})})(Ja);const Bd=Tu(Ja);class pn extends ae.EventBroker{get isInitialized(){return!!this.privKey}constructor(t,r){super(),this.privKey=t,this.walletClient=r}static fromPrivKey(t){return new pn(Jt(t))}static fromWalletClient(t){return new pn(void 0,t)}async initialize(){if(this.privKey)return re("Already initialized");const t=await this.derivePrivKeyFromWalletClient();return t.error?j(t.error):(this.emit("initialized",!0),re("Initialized"))}async derivePrivKeyFromWalletClient(){if(!this.walletClient)return j("No walletClient found");if(!this.walletClient.account)return j("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.privKey=Jt(dt.sha256(t)),this.emit("initialized",!0),re(this.privKey)}catch(t){return j("Failed to initialize: "+t)}}async getMasterPrivKey(){if(!this.privKey&&!this.walletClient)return j("No private key or wallet client found");if(!this.privKey&&this.walletClient){const t=await this.derivePrivKeyFromWalletClient();if(t.error)return j(t.error)}return this.privKey?re(this.privKey):j("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return j(r.error);const n=dt.sha256(ae.with0x(r.val)),i=dt.sha256(n);return re({secret:n,secretHash:i})}async signMessage(t){if(!this.privKey){const l=await this.getMasterPrivKey();if(l.error)return j(l.error);this.privKey=l.val}const r=Bd(er),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=dt.sha256(i),o=Buffer.from(Jt(this.privKey),"hex");if(o.length!==32)return j("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(Jt(s),"hex"));return re(c.toString("hex"))}}class Pd extends ae.EventBroker{constructor(t){super(),this.getOrderThreshold=20,this.refundSacpCache=new Map,this.environment=t.environment;const r=t.environment===ae.Environment.MAINNET?ls.mainnet:t.environment===ae.Environment.TESTNET?ls.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);if(this._auth=new ae.Siwe(new ae.Url(t.orderbookURl??r.orderbook),t.evmWallet,t.siweOpts),this._quote=t.quote??new Xa(r.quote),this._orderBook=new le.Orderbook({url:t.orderbookURl??r.orderbook,walletClient:t.evmWallet,auth:this._auth}),this._orderbookUrl=new ae.Url(t.orderbookURl??r.orderbook),this._evmRelay=new ya(this._orderbookUrl,this._auth),this._secretManager=t.secretManager??pn.fromWalletClient(t.evmWallet),this.orderExecutorCache=new $h,this._evmWallet=t.evmWallet,!t.evmWallet.account)throw new Error("Account not found in evmWallet");this._blockNumberFetcher=t.blockNumberFetcher??new Ya(r.info,t.environment)}get orderbookUrl(){return this._orderbookUrl.toString()}get evmRelay(){return this._evmRelay}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}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return re(this._btcWallet);const t=await this._secretManager.getMasterPrivKey();if(t.error)return j(t.error);const r=new Ir.BitcoinProvider(gu(this.environment));return this._btcWallet=Ir.BitcoinWallet.fromPrivateKey(t.val,r),re(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return j(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 j(a.error);const{strategyId:c,btcAddress:l}=t.additionalData,d={strategy_id:c,...l&&{bitcoin_optional_recipient:l}},g={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:Jt(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},x=await this._quote.getAttestedQuote(g);if(x.error)return j(x.error);const y=await this._orderBook.createOrder(x.val);if(y.error)return j(y.error);const O=await this.pollOrder(y.val);return O.error?j(O.error):re(O.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return j("StrategyId is required");if(!t.fromAsset||!t.toAsset)return j("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return j("Source and destination assets cannot be the same");if(le.isMainnet(t.fromAsset.chain)&&!le.isMainnet(t.toAsset.chain)||!le.isMainnet(t.fromAsset.chain)&&le.isMainnet(t.toAsset.chain))return j("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return j(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return j(n.error);if(r<n)return j("Send amount should be greater than receive amount");const i=le.getTimeLock(t.fromAsset.chain);if(!i)return j("Unsupported chain for timelock");if(le.isBitcoin(t.fromAsset.chain)||le.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return j("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const a=await this.initializeSMandBTCWallet();if(a.error)return j(a.error);if(!this._btcWallet)return j("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return j(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?j(o.error):re({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(le.getBlockchainType(t)){case le.BlockchainType.EVM:return this._evmWallet.account?re(this._evmWallet.account.address):j("EVM Wallet not found");case le.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!bu(i)?j("Invalid btc public key"):re(yt(i))}default:return j("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return j("Invalid amount ",t);const r=new uu(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?j("Invalid amount ",t):re(r)}async pollOrder(t){let r=await this._orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ae.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return j(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return re(r.val);r=await this._orderBook.getOrder(t,!0)}return j(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderBook.subscribeToOrders(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=Ss(s.status);if(le.isBitcoin(s.source_swap.chain)&&s.status===pe.InitiateDetected){const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);continue}await this.postRefundSACP(s,a.val)}switch(o){case Pe.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(le.getBlockchainType(s.destination_swap.chain)){case le.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case le.BlockchainType.Bitcoin:{const c=this.getWallet(s.destination_swap.chain);if(c.error){this.emit("error",s,c.error);return}await this.postRedeemSACP(a.val.secret,s,c.val);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Pe.Refund:{switch(le.getBlockchainType(s.source_swap.chain)){case le.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by garden's relay service");break}case le.BlockchainType.Bitcoin:{const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);return}await this.btcRefund(a.val,s);break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Pe.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const i=await this._evmRelay.redeem(t.create_order.create_id,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Pe.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Pe.Redeem,i.val),this.emit("success",t,Pe.Redeem,i.val)}async btcRedeem(t,r,n){var a,c;const i=this.orderExecutorCache.get(r,Pe.Redeem),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.btcRedeemUTXO&&i.btcRedeemUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");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 l=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const g of l.vin)if(g.txid===s){d=!0;break}if(d){this.orderExecutorCache.set(r,Pe.Redeem,r.destination_swap.redeem_tx_hash,s),this.emit("log",r.create_order.create_id,"already a valid redeem");return}o=!0}catch(l){if(l.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+l);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const d=await(await Sr.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,yt(r.destination_swap.initiator),yt(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).redeem(Jt(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient);o?this.emit("log",r.create_order.create_id,"rbf: btc redeem success"):this.emit("success",r,Pe.Redeem,d),this.orderExecutorCache.set(r,Pe.Redeem,d,s)}catch(l){this.emit("error",r,"Failed btc redeem: "+l)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Pe.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await Sr.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,yt(r.source_swap.initiator),yt(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,Pe.Refund,s),this.emit("success",r,Pe.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(le.getBlockchainType(t)){case le.BlockchainType.EVM:return re(this._evmWallet);case le.BlockchainType.Bitcoin:return re(this._btcWallet);default:return j("Unsupported chain for wallet")}}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 Sr.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,yt(t.source_swap.initiator),yt(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),a=this._orderbookUrl.endpoint("orders/add-instant-refund-sacp");(await Ht.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:t.create_order.create_id,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 postRedeemSACP(t,r,n){console.log("posting redeem sacp",r.create_order.create_id);const i=await Sr.from(n,Number(r.destination_swap.amount),r.create_order.secret_hash,yt(r.destination_swap.initiator),yt(r.destination_swap.redeemer),r.destination_swap.timelock),s=r.create_order.additional_data.bitcoin_optional_recipient;if(s)try{const o=await i.generateRedeemSACP(t,s),a=this._orderbookUrl.endpoint("orders/add-redeem-sacp"),c=await Ht.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:r.create_order.create_id,redeem_tx_bytes:o})});c.status==="Ok"&&c.result&&(this.emit("log",r.create_order.create_id,`redeem sacp success: ${c.result}`),this.emit("success",r,Pe.Redeem,c.result))}catch(o){this.emit("error",r,"Failed to generate and post SACP: "+o);return}}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return j("Provide wallets to fetch the current block number");const n=le.isBitcoin(t.source_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.source.getProvider()):await ae.fetchEVMBlockNumber(r.source);if(n.error)return j(n.error);const i=le.isBitcoin(t.destination_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ae.fetchEVMBlockNumber(r.destination);return i.error?j(i.error):re({source:n.val,destination:i.val})}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return re([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return j(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(pa(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,l=r==null?void 0:r.val[a],d=r==null?void 0:r.val[c];if(!l||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const g=xs(o,l,d);n.push({...o,status:g})}return re(n)}}function lr(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const Nf="2.21.41";let en={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Nf}`};class ye extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof ye?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof ye&&r.cause.docsPath||r.docsPath,s=(a=en.getDocsUrl)==null?void 0:a.call(en,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...en.version?[`Version: ${en.version}`]:[]].join(`
|
|
31
|
+
Use Chrome, Firefox or Internet Explorer 11`)}var Gh=We.Buffer,Jn=jt.crypto||jt.msCrypto;Jn&&Jn.getRandomValues?ds.exports=Wh:ds.exports=jh;function Wh(e,t){if(e>Dh)throw new RangeError("requested too many random bytes");var r=Gh.allocUnsafe(e);if(e>0)if(e>Vi)for(var n=0;n<e;n+=Vi)Jn.getRandomValues(r.slice(n,n+Vi));else Jn.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Vh=ds.exports,ys={exports:{}};typeof Object.create=="function"?ys.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:ys.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 ke=ys.exports,bs={exports:{}},Gs={exports:{}},Ar=typeof Reflect=="object"?Reflect:null,Oo=Ar&&typeof Ar.apply=="function"?Ar.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Vn;Ar&&typeof Ar.ownKeys=="function"?Vn=Ar.ownKeys:Object.getOwnPropertySymbols?Vn=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Vn=function(t){return Object.getOwnPropertyNames(t)};function zh(e){console&&console.warn&&console.warn(e)}var Za=Number.isNaN||function(t){return t!==t};function ne(){ne.init.call(this)}Gs.exports=ne;Gs.exports.once=Xh;ne.EventEmitter=ne;ne.prototype._events=void 0;ne.prototype._eventsCount=0;ne.prototype._maxListeners=void 0;var ko=10;function yi(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(ne,"defaultMaxListeners",{enumerable:!0,get:function(){return ko},set:function(e){if(typeof e!="number"||e<0||Za(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ko=e}});ne.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};ne.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Za(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 ef(e){return e._maxListeners===void 0?ne.defaultMaxListeners:e._maxListeners}ne.prototype.getMaxListeners=function(){return ef(this)};ne.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 c=s[t];if(c===void 0)return!1;if(typeof c=="function")Oo(c,this,r);else for(var l=c.length,d=of(c,l),n=0;n<l;++n)Oo(d[n],this,r);return!0};function tf(e,t,r,n){var i,s,o;if(yi(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=ef(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,zh(a)}return e}ne.prototype.addListener=function(t,r){return tf(this,t,r,!1)};ne.prototype.on=ne.prototype.addListener;ne.prototype.prependListener=function(t,r){return tf(this,t,r,!0)};function qh(){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 rf(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=qh.bind(n);return i.listener=r,n.wrapFn=i,i}ne.prototype.once=function(t,r){return yi(r),this.on(t,rf(this,t,r)),this};ne.prototype.prependOnceListener=function(t,r){return yi(r),this.prependListener(t,rf(this,t,r)),this};ne.prototype.removeListener=function(t,r){var n,i,s,o,a;if(yi(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():Kh(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};ne.prototype.off=ne.prototype.removeListener;ne.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 nf(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?Yh(i):of(i,i.length)}ne.prototype.listeners=function(t){return nf(this,t,!0)};ne.prototype.rawListeners=function(t){return nf(this,t,!1)};ne.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):sf.call(e,t)};ne.prototype.listenerCount=sf;function sf(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}ne.prototype.eventNames=function(){return this._eventsCount>0?Vn(this._events):[]};function of(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Kh(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Yh(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Xh(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))}af(e,t,s,{once:!0}),t!=="error"&&Jh(e,i,{once:!0})})}function Jh(e,t,r){typeof e.on=="function"&&af(e,"error",t,r)}function af(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 ff=Gs.exports,uf=ff.EventEmitter;const Qh={},Zh=Object.freeze(Object.defineProperty({__proto__:null,default:Qh},Symbol.toStringTag,{value:"Module"})),Ws=ba(Zh);var zi,Ro;function el(){if(Ro)return zi;Ro=1;function e(O,P){var A=Object.keys(O);if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(O);P&&(k=k.filter(function(U){return Object.getOwnPropertyDescriptor(O,U).enumerable})),A.push.apply(A,k)}return A}function t(O){for(var P=1;P<arguments.length;P++){var A=arguments[P]!=null?arguments[P]:{};P%2?e(Object(A),!0).forEach(function(k){r(O,k,A[k])}):Object.getOwnPropertyDescriptors?Object.defineProperties(O,Object.getOwnPropertyDescriptors(A)):e(Object(A)).forEach(function(k){Object.defineProperty(O,k,Object.getOwnPropertyDescriptor(A,k))})}return O}function r(O,P,A){return P=o(P),P in O?Object.defineProperty(O,P,{value:A,enumerable:!0,configurable:!0,writable:!0}):O[P]=A,O}function n(O,P){if(!(O instanceof P))throw new TypeError("Cannot call a class as a function")}function i(O,P){for(var A=0;A<P.length;A++){var k=P[A];k.enumerable=k.enumerable||!1,k.configurable=!0,"value"in k&&(k.writable=!0),Object.defineProperty(O,o(k.key),k)}}function s(O,P,A){return P&&i(O.prototype,P),Object.defineProperty(O,"prototype",{writable:!1}),O}function o(O){var P=a(O,"string");return typeof P=="symbol"?P:String(P)}function a(O,P){if(typeof O!="object"||O===null)return O;var A=O[Symbol.toPrimitive];if(A!==void 0){var k=A.call(O,P||"default");if(typeof k!="object")return k;throw new TypeError("@@toPrimitive must return a primitive value.")}return(P==="string"?String:Number)(O)}var c=At,l=c.Buffer,d=Ws,g=d.inspect,x=g&&g.custom||"inspect";function y(O,P,A){l.prototype.copy.call(O,P,A)}return zi=function(){function O(){n(this,O),this.head=null,this.tail=null,this.length=0}return s(O,[{key:"push",value:function(A){var k={data:A,next:null};this.length>0?this.tail.next=k:this.head=k,this.tail=k,++this.length}},{key:"unshift",value:function(A){var k={data:A,next:this.head};this.length===0&&(this.tail=k),this.head=k,++this.length}},{key:"shift",value:function(){if(this.length!==0){var A=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,A}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(A){if(this.length===0)return"";for(var k=this.head,U=""+k.data;k=k.next;)U+=A+k.data;return U}},{key:"concat",value:function(A){if(this.length===0)return l.alloc(0);for(var k=l.allocUnsafe(A>>>0),U=this.head,_=0;U;)y(U.data,k,_),_+=U.data.length,U=U.next;return k}},{key:"consume",value:function(A,k){var U;return A<this.head.data.length?(U=this.head.data.slice(0,A),this.head.data=this.head.data.slice(A)):A===this.head.data.length?U=this.shift():U=k?this._getString(A):this._getBuffer(A),U}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(A){var k=this.head,U=1,_=k.data;for(A-=_.length;k=k.next;){var m=k.data,S=A>m.length?m.length:A;if(S===m.length?_+=m:_+=m.slice(0,A),A-=S,A===0){S===m.length?(++U,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=m.slice(S));break}++U}return this.length-=U,_}},{key:"_getBuffer",value:function(A){var k=l.allocUnsafe(A),U=this.head,_=1;for(U.data.copy(k),A-=U.data.length;U=U.next;){var m=U.data,S=A>m.length?m.length:A;if(m.copy(k,k.length-A,0,S),A-=S,A===0){S===m.length?(++_,U.next?this.head=U.next:this.head=this.tail=null):(this.head=U,U.data=m.slice(S));break}++_}return this.length-=_,k}},{key:x,value:function(A,k){return g(this,t(t({},k),{},{depth:0,customInspect:!1}))}}]),O}(),zi}function tl(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(ws,this,e)):process.nextTick(ws,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(zn,r):(r._writableState.errorEmitted=!0,process.nextTick(Uo,r,s)):process.nextTick(Uo,r,s):t?(process.nextTick(zn,r),t(s)):process.nextTick(zn,r)}),this)}function Uo(e,t){ws(e,t),zn(e)}function zn(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function rl(){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 ws(e,t){e.emit("error",t)}function nl(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var cf={destroy:tl,undestroy:rl,errorOrDestroy:nl},cr={};function il(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var hf={};function Ze(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){il(o,s);function o(a,c,l){return s.call(this,n(a,c,l))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,hf[e]=i}function Co(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 sl(e,t,r){return e.substr(0,t.length)===t}function ol(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function al(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Ze("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Ze("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&sl(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(ol(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Co(t,"type"));else{var s=al(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Co(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Ze("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Ze("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Ze("ERR_STREAM_PREMATURE_CLOSE","Premature close");Ze("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Ze("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Ze("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Ze("ERR_STREAM_WRITE_AFTER_END","write after end");Ze("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Ze("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Ze("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");cr.codes=hf;var fl=cr.codes.ERR_INVALID_OPT_VALUE;function ul(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function cl(e,t,r,n){var i=ul(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new fl(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var lf={getHighWaterMark:cl},hl=ll;function ll(e,t){if(qi("noDeprecation"))return e;var r=!1;function n(){if(!r){if(qi("throwDeprecation"))throw new Error(t);qi("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function qi(e){try{if(!jt.localStorage)return!1}catch{return!1}var t=jt.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Ki,Lo;function df(){if(Lo)return Ki;Lo=1,Ki=D;function e(T){var B=this;this.next=null,this.entry=null,this.finish=function(){pt(B,T)}}var t;D.WritableState=E;var r={deprecate:hl},n=uf,i=At.Buffer,s=(typeof jt<"u"?jt:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(T){return i.from(T)}function a(T){return i.isBuffer(T)||T instanceof s}var c=cf,l=lf,d=l.getHighWaterMark,g=cr.codes,x=g.ERR_INVALID_ARG_TYPE,y=g.ERR_METHOD_NOT_IMPLEMENTED,O=g.ERR_MULTIPLE_CALLBACK,P=g.ERR_STREAM_CANNOT_PIPE,A=g.ERR_STREAM_DESTROYED,k=g.ERR_STREAM_NULL_VALUES,U=g.ERR_STREAM_WRITE_AFTER_END,_=g.ERR_UNKNOWN_ENCODING,m=c.errorOrDestroy;ke(D,n);function S(){}function E(T,B,F){t=t||Lr(),T=T||{},typeof F!="boolean"&&(F=B instanceof t),this.objectMode=!!T.objectMode,F&&(this.objectMode=this.objectMode||!!T.writableObjectMode),this.highWaterMark=d(this,T,"writableHighWaterMark",F),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var G=T.decodeStrings===!1;this.decodeStrings=!G,this.defaultEncoding=T.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(K){fe(B,K)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=T.emitClose!==!1,this.autoDestroy=!!T.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}E.prototype.getBuffer=function(){for(var B=this.bufferedRequest,F=[];B;)F.push(B),B=B.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(D,Symbol.hasInstance,{value:function(B){return H.call(this,B)?!0:this!==D?!1:B&&B._writableState instanceof E}})):H=function(B){return B instanceof this};function D(T){t=t||Lr();var B=this instanceof t;if(!B&&!H.call(D,this))return new D(T);this._writableState=new E(T,this,B),this.writable=!0,T&&(typeof T.write=="function"&&(this._write=T.write),typeof T.writev=="function"&&(this._writev=T.writev),typeof T.destroy=="function"&&(this._destroy=T.destroy),typeof T.final=="function"&&(this._final=T.final)),n.call(this)}D.prototype.pipe=function(){m(this,new P)};function R(T,B){var F=new U;m(T,F),process.nextTick(B,F)}function z(T,B,F,G){var K;return F===null?K=new k:typeof F!="string"&&!B.objectMode&&(K=new x("chunk",["string","Buffer"],F)),K?(m(T,K),process.nextTick(G,K),!1):!0}D.prototype.write=function(T,B,F){var G=this._writableState,K=!1,b=!G.objectMode&&a(T);return b&&!i.isBuffer(T)&&(T=o(T)),typeof B=="function"&&(F=B,B=null),b?B="buffer":B||(B=G.defaultEncoding),typeof F!="function"&&(F=S),G.ending?R(this,F):(b||z(this,G,T,F))&&(G.pendingcb++,K=C(this,G,b,T,B,F)),K},D.prototype.cork=function(){this._writableState.corked++},D.prototype.uncork=function(){var T=this._writableState;T.corked&&(T.corked--,!T.writing&&!T.corked&&!T.bufferProcessing&&T.bufferedRequest&&Ve(this,T))},D.prototype.setDefaultEncoding=function(B){if(typeof B=="string"&&(B=B.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((B+"").toLowerCase())>-1))throw new _(B);return this._writableState.defaultEncoding=B,this},Object.defineProperty(D.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Z(T,B,F){return!T.objectMode&&T.decodeStrings!==!1&&typeof B=="string"&&(B=i.from(B,F)),B}Object.defineProperty(D.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function C(T,B,F,G,K,b){if(!F){var w=Z(B,G,K);G!==w&&(F=!0,K="buffer",G=w)}var N=B.objectMode?1:G.length;B.length+=N;var $=B.length<B.highWaterMark;if($||(B.needDrain=!0),B.writing||B.corked){var we=B.lastBufferedRequest;B.lastBufferedRequest={chunk:G,encoding:K,isBuf:F,callback:b,next:null},we?we.next=B.lastBufferedRequest:B.bufferedRequest=B.lastBufferedRequest,B.bufferedRequestCount+=1}else M(T,B,!1,N,G,K,b);return $}function M(T,B,F,G,K,b,w){B.writelen=G,B.writecb=w,B.writing=!0,B.sync=!0,B.destroyed?B.onwrite(new A("write")):F?T._writev(K,B.onwrite):T._write(K,b,B.onwrite),B.sync=!1}function W(T,B,F,G,K){--B.pendingcb,F?(process.nextTick(K,G),process.nextTick(ze,T,B),T._writableState.errorEmitted=!0,m(T,G)):(K(G),T._writableState.errorEmitted=!0,m(T,G),ze(T,B))}function q(T){T.writing=!1,T.writecb=null,T.length-=T.writelen,T.writelen=0}function fe(T,B){var F=T._writableState,G=F.sync,K=F.writecb;if(typeof K!="function")throw new O;if(q(F),B)W(T,F,G,B,K);else{var b=it(F)||T.destroyed;!b&&!F.corked&&!F.bufferProcessing&&F.bufferedRequest&&Ve(T,F),G?process.nextTick(ue,T,F,b,K):ue(T,F,b,K)}}function ue(T,B,F,G){F||et(T,B),B.pendingcb--,G(),ze(T,B)}function et(T,B){B.length===0&&B.needDrain&&(B.needDrain=!1,T.emit("drain"))}function Ve(T,B){B.bufferProcessing=!0;var F=B.bufferedRequest;if(T._writev&&F&&F.next){var G=B.bufferedRequestCount,K=new Array(G),b=B.corkedRequestsFree;b.entry=F;for(var w=0,N=!0;F;)K[w]=F,F.isBuf||(N=!1),F=F.next,w+=1;K.allBuffers=N,M(T,B,!0,B.length,K,"",b.finish),B.pendingcb++,B.lastBufferedRequest=null,b.next?(B.corkedRequestsFree=b.next,b.next=null):B.corkedRequestsFree=new e(B),B.bufferedRequestCount=0}else{for(;F;){var $=F.chunk,we=F.encoding,Y=F.callback,te=B.objectMode?1:$.length;if(M(T,B,!1,te,$,we,Y),F=F.next,B.bufferedRequestCount--,B.writing)break}F===null&&(B.lastBufferedRequest=null)}B.bufferedRequest=F,B.bufferProcessing=!1}D.prototype._write=function(T,B,F){F(new y("_write()"))},D.prototype._writev=null,D.prototype.end=function(T,B,F){var G=this._writableState;return typeof T=="function"?(F=T,T=null,B=null):typeof B=="function"&&(F=B,B=null),T!=null&&this.write(T,B),G.corked&&(G.corked=1,this.uncork()),G.ending||It(this,G,F),this},Object.defineProperty(D.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function it(T){return T.ending&&T.length===0&&T.bufferedRequest===null&&!T.finished&&!T.writing}function be(T,B){T._final(function(F){B.pendingcb--,F&&m(T,F),B.prefinished=!0,T.emit("prefinish"),ze(T,B)})}function xe(T,B){!B.prefinished&&!B.finalCalled&&(typeof T._final=="function"&&!B.destroyed?(B.pendingcb++,B.finalCalled=!0,process.nextTick(be,T,B)):(B.prefinished=!0,T.emit("prefinish")))}function ze(T,B){var F=it(B);if(F&&(xe(T,B),B.pendingcb===0&&(B.finished=!0,T.emit("finish"),B.autoDestroy))){var G=T._readableState;(!G||G.autoDestroy&&G.endEmitted)&&T.destroy()}return F}function It(T,B,F){B.ending=!0,ze(T,B),F&&(B.finished?process.nextTick(F):T.once("finish",F)),B.ended=!0,T.writable=!1}function pt(T,B,F){var G=T.entry;for(T.entry=null;G;){var K=G.callback;B.pendingcb--,K(F),G=G.next}B.corkedRequestsFree.next=T}return Object.defineProperty(D.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(B){this._writableState&&(this._writableState.destroyed=B)}}),D.prototype.destroy=c.destroy,D.prototype._undestroy=c.undestroy,D.prototype._destroy=function(T,B){B(T)},Ki}var Yi,No;function Lr(){if(No)return Yi;No=1;var e=Object.keys||function(l){var d=[];for(var g in l)d.push(g);return d};Yi=o;var t=yf(),r=df();ke(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(l){if(!(this instanceof o))return new o(l);t.call(this,l),r.call(this,l),this.allowHalfOpen=!0,l&&(l.readable===!1&&(this.readable=!1),l.writable===!1&&(this.writable=!1),l.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(c,this)}function c(l){l.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)}}),Yi}var Qn={},Vs=We.Buffer,Fo=Vs.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 dl(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 pl(e){var t=dl(e);if(typeof t!="string"&&(Vs.isEncoding===Fo||!Fo(e)))throw new Error("Unknown encoding: "+e);return t||e}Qn.StringDecoder=gn;function gn(e){this.encoding=pl(e);var t;switch(this.encoding){case"utf16le":this.text=_l,this.end=vl,t=4;break;case"utf8":this.fillLast=wl,t=4;break;case"base64":this.text=El,this.end=xl,t=3;break;default:this.write=Sl,this.end=Bl;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Vs.allocUnsafe(t)}gn.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||""};gn.prototype.end=ml;gn.prototype.text=gl;gn.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 Xi(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function yl(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Xi(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Xi(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Xi(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function bl(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 wl(e){var t=this.lastTotal-this.lastNeed,r=bl(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 gl(e,t){var r=yl(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 ml(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function _l(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 vl(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 El(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 xl(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Sl(e){return e.toString(this.encoding)}function Bl(e){return e&&e.length?this.write(e):""}var Mo=cr.codes.ERR_STREAM_PREMATURE_CLOSE;function Pl(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 Tl(){}function Al(e){return e.setHeader&&typeof e.abort=="function"}function pf(e,t,r){if(typeof t=="function")return pf(e,null,t);t||(t={}),r=Pl(r||Tl);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)},c=e._readableState&&e._readableState.endEmitted,l=function(){n=!1,c=!0,i||r.call(e)},d=function(O){r.call(e,O)},g=function(){var O;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(O=new Mo),r.call(e,O);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(O=new Mo),r.call(e,O)},x=function(){e.req.on("finish",a)};return Al(e)?(e.on("complete",a),e.on("abort",g),e.req?x():e.on("request",x)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",l),e.on("finish",a),t.error!==!1&&e.on("error",d),e.on("close",g),function(){e.removeListener("complete",a),e.removeListener("abort",g),e.removeListener("request",x),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",l),e.removeListener("error",d),e.removeListener("close",g)}}var zs=pf,Ji,Ho;function Il(){if(Ho)return Ji;Ho=1;var e;function t(_,m,S){return m=r(m),m in _?Object.defineProperty(_,m,{value:S,enumerable:!0,configurable:!0,writable:!0}):_[m]=S,_}function r(_){var m=n(_,"string");return typeof m=="symbol"?m:String(m)}function n(_,m){if(typeof _!="object"||_===null)return _;var S=_[Symbol.toPrimitive];if(S!==void 0){var E=S.call(_,m||"default");if(typeof E!="object")return E;throw new TypeError("@@toPrimitive must return a primitive value.")}return(m==="string"?String:Number)(_)}var i=zs,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),l=Symbol("lastPromise"),d=Symbol("handlePromise"),g=Symbol("stream");function x(_,m){return{value:_,done:m}}function y(_){var m=_[s];if(m!==null){var S=_[g].read();S!==null&&(_[l]=null,_[s]=null,_[o]=null,m(x(S,!1)))}}function O(_){process.nextTick(y,_)}function P(_,m){return function(S,E){_.then(function(){if(m[c]){S(x(void 0,!0));return}m[d](S,E)},E)}}var A=Object.getPrototypeOf(function(){}),k=Object.setPrototypeOf((e={get stream(){return this[g]},next:function(){var m=this,S=this[a];if(S!==null)return Promise.reject(S);if(this[c])return Promise.resolve(x(void 0,!0));if(this[g].destroyed)return new Promise(function(R,z){process.nextTick(function(){m[a]?z(m[a]):R(x(void 0,!0))})});var E=this[l],H;if(E)H=new Promise(P(E,this));else{var D=this[g].read();if(D!==null)return Promise.resolve(x(D,!1));H=new Promise(this[d])}return this[l]=H,H}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var m=this;return new Promise(function(S,E){m[g].destroy(null,function(H){if(H){E(H);return}S(x(void 0,!0))})})}),e),A),U=function(m){var S,E=Object.create(k,(S={},t(S,g,{value:m,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,c,{value:m._readableState.endEmitted,writable:!0}),t(S,d,{value:function(D,R){var z=E[g].read();z?(E[l]=null,E[s]=null,E[o]=null,D(x(z,!1))):(E[s]=D,E[o]=R)},writable:!0}),S));return E[l]=null,i(m,function(H){if(H&&H.code!=="ERR_STREAM_PREMATURE_CLOSE"){var D=E[o];D!==null&&(E[l]=null,E[s]=null,E[o]=null,D(H)),E[a]=H;return}var R=E[s];R!==null&&(E[l]=null,E[s]=null,E[o]=null,R(x(void 0,!0))),E[c]=!0}),m.on("readable",O.bind(null,E)),E};return Ji=U,Ji}var Qi,$o;function Ol(){return $o||($o=1,Qi=function(){throw new Error("Readable.from is not available in the browser")}),Qi}var Zi,Do;function yf(){if(Do)return Zi;Do=1,Zi=R;var e;R.ReadableState=D,ff.EventEmitter;var t=function(w,N){return w.listeners(N).length},r=uf,n=At.Buffer,i=(typeof jt<"u"?jt: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=Ws,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var l=el(),d=cf,g=lf,x=g.getHighWaterMark,y=cr.codes,O=y.ERR_INVALID_ARG_TYPE,P=y.ERR_STREAM_PUSH_AFTER_EOF,A=y.ERR_METHOD_NOT_IMPLEMENTED,k=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,U,_,m;ke(R,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 D(b,w,N){e=e||Lr(),b=b||{},typeof N!="boolean"&&(N=w instanceof e),this.objectMode=!!b.objectMode,N&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=x(this,b,"readableHighWaterMark",N),this.buffer=new l,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=Qn.StringDecoder),this.decoder=new U(b.encoding),this.encoding=b.encoding)}function R(b){if(e=e||Lr(),!(this instanceof R))return new R(b);var w=this instanceof e;this._readableState=new D(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(R.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(w){this._readableState&&(this._readableState.destroyed=w)}}),R.prototype.destroy=d.destroy,R.prototype._undestroy=d.undestroy,R.prototype._destroy=function(b,w){w(b)},R.prototype.push=function(b,w){var N=this._readableState,$;return N.objectMode?$=!0:typeof b=="string"&&(w=w||N.defaultEncoding,w!==N.encoding&&(b=n.from(b,w),w=""),$=!0),z(this,b,w,!1,$)},R.prototype.unshift=function(b){return z(this,b,null,!0,!1)};function z(b,w,N,$,we){c("readableAddChunk",w);var Y=b._readableState;if(w===null)Y.reading=!1,fe(b,Y);else{var te;if(we||(te=C(Y,w)),te)S(b,te);else if(Y.objectMode||w&&w.length>0)if(typeof w!="string"&&!Y.objectMode&&Object.getPrototypeOf(w)!==n.prototype&&(w=s(w)),$)Y.endEmitted?S(b,new k):Z(b,Y,w,!0);else if(Y.ended)S(b,new P);else{if(Y.destroyed)return!1;Y.reading=!1,Y.decoder&&!N?(w=Y.decoder.write(w),Y.objectMode||w.length!==0?Z(b,Y,w,!1):Ve(b,Y)):Z(b,Y,w,!1)}else $||(Y.reading=!1,Ve(b,Y))}return!Y.ended&&(Y.length<Y.highWaterMark||Y.length===0)}function Z(b,w,N,$){w.flowing&&w.length===0&&!w.sync?(w.awaitDrain=0,b.emit("data",N)):(w.length+=w.objectMode?1:N.length,$?w.buffer.unshift(N):w.buffer.push(N),w.needReadable&&ue(b)),Ve(b,w)}function C(b,w){var N;return!o(w)&&typeof w!="string"&&w!==void 0&&!b.objectMode&&(N=new O("chunk",["string","Buffer","Uint8Array"],w)),N}R.prototype.isPaused=function(){return this._readableState.flowing===!1},R.prototype.setEncoding=function(b){U||(U=Qn.StringDecoder);var w=new U(b);this._readableState.decoder=w,this._readableState.encoding=this._readableState.decoder.encoding;for(var N=this._readableState.buffer.head,$="";N!==null;)$+=w.write(N.data),N=N.next;return this._readableState.buffer.clear(),$!==""&&this._readableState.buffer.push($),this._readableState.length=$.length,this};var M=1073741824;function W(b){return b>=M?b=M:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function q(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=W(b)),b<=w.length?b:w.ended?w.length:(w.needReadable=!0,0))}R.prototype.read=function(b){c("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 c("read: emitReadable",w.length,w.ended),w.length===0&&w.ended?F(this):ue(this),null;if(b=q(b,w),b===0&&w.ended)return w.length===0&&F(this),null;var $=w.needReadable;c("need readable",$),(w.length===0||w.length-b<w.highWaterMark)&&($=!0,c("length less than watermark",$)),w.ended||w.reading?($=!1,c("reading or ended",$)):$&&(c("do read"),w.reading=!0,w.sync=!0,w.length===0&&(w.needReadable=!0),this._read(w.highWaterMark),w.sync=!1,w.reading||(b=q(N,w)));var we;return b>0?we=B(b,w):we=null,we===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)),we!==null&&this.emit("data",we),we};function fe(b,w){if(c("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?ue(b):(w.needReadable=!1,w.emittedReadable||(w.emittedReadable=!0,et(b)))}}function ue(b){var w=b._readableState;c("emitReadable",w.needReadable,w.emittedReadable),w.needReadable=!1,w.emittedReadable||(c("emitReadable",w.flowing),w.emittedReadable=!0,process.nextTick(et,b))}function et(b){var w=b._readableState;c("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,T(b)}function Ve(b,w){w.readingMore||(w.readingMore=!0,process.nextTick(it,b,w))}function it(b,w){for(;!w.reading&&!w.ended&&(w.length<w.highWaterMark||w.flowing&&w.length===0);){var N=w.length;if(c("maybeReadMore read 0"),b.read(0),N===w.length)break}w.readingMore=!1}R.prototype._read=function(b){S(this,new A("_read()"))},R.prototype.pipe=function(b,w){var N=this,$=this._readableState;switch($.pipesCount){case 0:$.pipes=b;break;case 1:$.pipes=[$.pipes,b];break;default:$.pipes.push(b);break}$.pipesCount+=1,c("pipe count=%d opts=%j",$.pipesCount,w);var we=(!w||w.end!==!1)&&b!==process.stdout&&b!==process.stderr,Y=we?Ot:Yt;$.endEmitted?process.nextTick(Y):N.once("end",Y),b.on("unpipe",te);function te(h,f){c("onunpipe"),h===N&&f&&f.hasUnpiped===!1&&(f.hasUnpiped=!0,pr())}function Ot(){c("onend"),b.end()}var dr=be(N);b.on("drain",dr);var $r=!1;function pr(){c("cleanup"),b.removeListener("close",Dr),b.removeListener("finish",Xe),b.removeListener("drain",dr),b.removeListener("error",Kt),b.removeListener("unpipe",te),N.removeListener("end",Ot),N.removeListener("end",Yt),N.removeListener("data",qe),$r=!0,$.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&dr()}N.on("data",qe);function qe(h){c("ondata");var f=b.write(h);c("dest.write",f),f===!1&&(($.pipesCount===1&&$.pipes===b||$.pipesCount>1&&K($.pipes,b)!==-1)&&!$r&&(c("false write response, pause",$.awaitDrain),$.awaitDrain++),N.pause())}function Kt(h){c("onerror",h),Yt(),b.removeListener("error",Kt),t(b,"error")===0&&S(b,h)}H(b,"error",Kt);function Dr(){b.removeListener("finish",Xe),Yt()}b.once("close",Dr);function Xe(){c("onfinish"),b.removeListener("close",Dr),Yt()}b.once("finish",Xe);function Yt(){c("unpipe"),N.unpipe(b)}return b.emit("pipe",N),$.flowing||(c("pipe resume"),N.resume()),b};function be(b){return function(){var N=b._readableState;c("pipeOnDrain",N.awaitDrain),N.awaitDrain&&N.awaitDrain--,N.awaitDrain===0&&t(b,"data")&&(N.flowing=!0,T(b))}}R.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 $=w.pipes,we=w.pipesCount;w.pipes=null,w.pipesCount=0,w.flowing=!1;for(var Y=0;Y<we;Y++)$[Y].emit("unpipe",this,{hasUnpiped:!1});return this}var te=K(w.pipes,b);return te===-1?this:(w.pipes.splice(te,1),w.pipesCount-=1,w.pipesCount===1&&(w.pipes=w.pipes[0]),b.emit("unpipe",this,N),this)},R.prototype.on=function(b,w){var N=r.prototype.on.call(this,b,w),$=this._readableState;return b==="data"?($.readableListening=this.listenerCount("readable")>0,$.flowing!==!1&&this.resume()):b==="readable"&&!$.endEmitted&&!$.readableListening&&($.readableListening=$.needReadable=!0,$.flowing=!1,$.emittedReadable=!1,c("on readable",$.length,$.reading),$.length?ue(this):$.reading||process.nextTick(ze,this)),N},R.prototype.addListener=R.prototype.on,R.prototype.removeListener=function(b,w){var N=r.prototype.removeListener.call(this,b,w);return b==="readable"&&process.nextTick(xe,this),N},R.prototype.removeAllListeners=function(b){var w=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(xe,this),w};function xe(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 ze(b){c("readable nexttick read 0"),b.read(0)}R.prototype.resume=function(){var b=this._readableState;return b.flowing||(c("resume"),b.flowing=!b.readableListening,It(this,b)),b.paused=!1,this};function It(b,w){w.resumeScheduled||(w.resumeScheduled=!0,process.nextTick(pt,b,w))}function pt(b,w){c("resume",w.reading),w.reading||b.read(0),w.resumeScheduled=!1,b.emit("resume"),T(b),w.flowing&&!w.reading&&b.read(0)}R.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function T(b){var w=b._readableState;for(c("flow",w.flowing);w.flowing&&b.read()!==null;);}R.prototype.wrap=function(b){var w=this,N=this._readableState,$=!1;b.on("end",function(){if(c("wrapped end"),N.decoder&&!N.ended){var te=N.decoder.end();te&&te.length&&w.push(te)}w.push(null)}),b.on("data",function(te){if(c("wrapped data"),N.decoder&&(te=N.decoder.write(te)),!(N.objectMode&&te==null)&&!(!N.objectMode&&(!te||!te.length))){var Ot=w.push(te);Ot||($=!0,b.pause())}});for(var we in b)this[we]===void 0&&typeof b[we]=="function"&&(this[we]=function(Ot){return function(){return b[Ot].apply(b,arguments)}}(we));for(var Y=0;Y<E.length;Y++)b.on(E[Y],this.emit.bind(this,E[Y]));return this._read=function(te){c("wrapped _read",te),$&&($=!1,b.resume())},this},typeof Symbol=="function"&&(R.prototype[Symbol.asyncIterator]=function(){return _===void 0&&(_=Il()),_(this)}),Object.defineProperty(R.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(R.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(R.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(w){this._readableState&&(this._readableState.flowing=w)}}),R._fromList=B,Object.defineProperty(R.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function B(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;c("endReadable",w.endEmitted),w.endEmitted||(w.ended=!0,process.nextTick(G,w,b))}function G(b,w){if(c("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"&&(R.from=function(b,w){return m===void 0&&(m=Ol()),m(R,b,w)});function K(b,w){for(var N=0,$=b.length;N<$;N++)if(b[N]===w)return N;return-1}return Zi}var bf=Tt,bi=cr.codes,kl=bi.ERR_METHOD_NOT_IMPLEMENTED,Rl=bi.ERR_MULTIPLE_CALLBACK,Ul=bi.ERR_TRANSFORM_ALREADY_TRANSFORMING,Cl=bi.ERR_TRANSFORM_WITH_LENGTH_0,wi=Lr();ke(Tt,wi);function Ll(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new Rl);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 Tt(e){if(!(this instanceof Tt))return new Tt(e);wi.call(this,e),this._transformState={afterTransform:Ll.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",Nl)}function Nl(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){jo(e,t,r)}):jo(this,null,null)}Tt.prototype.push=function(e,t){return this._transformState.needTransform=!1,wi.prototype.push.call(this,e,t)};Tt.prototype._transform=function(e,t,r){r(new kl("_transform()"))};Tt.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)}};Tt.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};Tt.prototype._destroy=function(e,t){wi.prototype._destroy.call(this,e,function(r){t(r)})};function jo(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Cl;if(e._transformState.transforming)throw new Ul;return e.push(null)}var Fl=dn,wf=bf;ke(dn,wf);function dn(e){if(!(this instanceof dn))return new dn(e);wf.call(this,e)}dn.prototype._transform=function(e,t,r){r(null,e)};var es;function Ml(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var gf=cr.codes,Hl=gf.ERR_MISSING_ARGS,$l=gf.ERR_STREAM_DESTROYED;function Go(e){if(e)throw e}function Dl(e){return e.setHeader&&typeof e.abort=="function"}function jl(e,t,r,n){n=Ml(n);var i=!1;e.on("close",function(){i=!0}),es===void 0&&(es=zs),es(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,Dl(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new $l("pipe"))}}}function Wo(e){e()}function Gl(e,t){return e.pipe(t)}function Wl(e){return!e.length||typeof e[e.length-1]!="function"?Go:e.pop()}function Vl(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=Wl(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Hl("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,l=a>0;return jl(o,c,l,function(d){i||(i=d),d&&s.forEach(Wo),!c&&(s.forEach(Wo),n(i))})});return t.reduce(Gl)}var zl=Vl;(function(e,t){t=e.exports=yf(),t.Stream=t,t.Readable=t,t.Writable=df(),t.Duplex=Lr(),t.Transform=bf,t.PassThrough=Fl,t.finished=zs,t.pipeline=zl})(bs,bs.exports);var mf=bs.exports,Zn=We.Buffer,_f=mf.Transform,ql=ke;function Kl(e,t){if(!Zn.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Vt(e){_f.call(this),this._block=Zn.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}ql(Vt,_f);Vt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Vt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Vt.prototype.update=function(e,t){if(Kl(e,"Data"),this._finalized)throw new Error("Digest already called");Zn.isBuffer(e)||(e=Zn.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};Vt.prototype._update=function(){throw new Error("_update is not implemented")};Vt.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};Vt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Yl=Vt,Xl=ke,vf=Yl,Jl=We.Buffer,Ql=new Array(16);function gi(){vf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}Xl(gi,vf);gi.prototype._update=function(){for(var e=Ql,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=Ue(r,n,i,s,e[1],4129170786,5),s=Ue(s,r,n,i,e[6],3225465664,9),i=Ue(i,s,r,n,e[11],643717713,14),n=Ue(n,i,s,r,e[0],3921069994,20),r=Ue(r,n,i,s,e[5],3593408605,5),s=Ue(s,r,n,i,e[10],38016083,9),i=Ue(i,s,r,n,e[15],3634488961,14),n=Ue(n,i,s,r,e[4],3889429448,20),r=Ue(r,n,i,s,e[9],568446438,5),s=Ue(s,r,n,i,e[14],3275163606,9),i=Ue(i,s,r,n,e[3],4107603335,14),n=Ue(n,i,s,r,e[8],1163531501,20),r=Ue(r,n,i,s,e[13],2850285829,5),s=Ue(s,r,n,i,e[2],4243563512,9),i=Ue(i,s,r,n,e[7],1735328473,14),n=Ue(n,i,s,r,e[12],2368359562,20),r=Ce(r,n,i,s,e[5],4294588738,4),s=Ce(s,r,n,i,e[8],2272392833,11),i=Ce(i,s,r,n,e[11],1839030562,16),n=Ce(n,i,s,r,e[14],4259657740,23),r=Ce(r,n,i,s,e[1],2763975236,4),s=Ce(s,r,n,i,e[4],1272893353,11),i=Ce(i,s,r,n,e[7],4139469664,16),n=Ce(n,i,s,r,e[10],3200236656,23),r=Ce(r,n,i,s,e[13],681279174,4),s=Ce(s,r,n,i,e[0],3936430074,11),i=Ce(i,s,r,n,e[3],3572445317,16),n=Ce(n,i,s,r,e[6],76029189,23),r=Ce(r,n,i,s,e[9],3654602809,4),s=Ce(s,r,n,i,e[12],3873151461,11),i=Ce(i,s,r,n,e[15],530742520,16),n=Ce(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};gi.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=Jl.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 mi(e,t){return e<<t|e>>>32-t}function Re(e,t,r,n,i,s,o){return mi(e+(t&r|~t&n)+i+s|0,o)+t|0}function Ue(e,t,r,n,i,s,o){return mi(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ce(e,t,r,n,i,s,o){return mi(e+(t^r^n)+i+s|0,o)+t|0}function Le(e,t,r,n,i,s,o){return mi(e+(r^(t|~n))+i+s|0,o)+t|0}var Zl=gi,ei=We.Buffer,Ef=mf.Transform,e0=ke;function t0(e,t){if(!ei.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function zt(e){Ef.call(this),this._block=ei.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}e0(zt,Ef);zt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};zt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};zt.prototype.update=function(e,t){if(t0(e,"Data"),this._finalized)throw new Error("Digest already called");ei.isBuffer(e)||(e=ei.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};zt.prototype._update=function(){throw new Error("_update is not implemented")};zt.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};zt.prototype._digest=function(){throw new Error("_digest is not implemented")};var r0=zt,ts=At.Buffer,n0=ke,xf=r0,i0=new Array(16),Kr=[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],Yr=[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],Xr=[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],Jr=[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],Qr=[0,1518500249,1859775393,2400959708,2840853838],Zr=[1352829926,1548603684,1836072691,2053994217,0];function _i(){xf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}n0(_i,xf);_i.prototype._update=function(){for(var e=i0,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,c=this._b|0,l=this._c|0,d=this._d|0,g=this._e|0,x=0;x<80;x+=1){var y,O;x<16?(y=Vo(r,n,i,s,o,e[Kr[x]],Qr[0],Xr[x]),O=Yo(a,c,l,d,g,e[Yr[x]],Zr[0],Jr[x])):x<32?(y=zo(r,n,i,s,o,e[Kr[x]],Qr[1],Xr[x]),O=Ko(a,c,l,d,g,e[Yr[x]],Zr[1],Jr[x])):x<48?(y=qo(r,n,i,s,o,e[Kr[x]],Qr[2],Xr[x]),O=qo(a,c,l,d,g,e[Yr[x]],Zr[2],Jr[x])):x<64?(y=Ko(r,n,i,s,o,e[Kr[x]],Qr[3],Xr[x]),O=zo(a,c,l,d,g,e[Yr[x]],Zr[3],Jr[x])):(y=Yo(r,n,i,s,o,e[Kr[x]],Qr[4],Xr[x]),O=Vo(a,c,l,d,g,e[Yr[x]],Zr[4],Jr[x])),r=o,o=s,s=nr(i,10),i=n,n=y,a=g,g=d,d=nr(l,10),l=c,c=O}var P=this._b+i+d|0;this._b=this._c+s+g|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+l|0,this._a=P};_i.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=ts.alloc?ts.alloc(20):new ts(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 nr(e,t){return e<<t|e>>>32-t}function Vo(e,t,r,n,i,s,o,a){return nr(e+(t^r^n)+s+o|0,a)+i|0}function zo(e,t,r,n,i,s,o,a){return nr(e+(t&r|~t&n)+s+o|0,a)+i|0}function qo(e,t,r,n,i,s,o,a){return nr(e+((t|~r)^n)+s+o|0,a)+i|0}function Ko(e,t,r,n,i,s,o,a){return nr(e+(t&n|r&~n)+s+o|0,a)+i|0}function Yo(e,t,r,n,i,s,o,a){return nr(e+(t^(r|~n))+s+o|0,a)+i|0}var s0=_i,Sf={exports:{}},Bf=We.Buffer;function vi(e,t){this._block=Bf.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}vi.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Bf.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,c=Math.min(i-o,n-a),l=0;l<c;l++)r[a+l]=e[o+l];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};vi.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};vi.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Fr=vi,o0=ke,Pf=Fr,a0=We.Buffer,f0=[1518500249,1859775393,-1894007588,-899497514],u0=new Array(80);function mn(){this.init(),this._w=u0,Pf.call(this,64,56)}o0(mn,Pf);mn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function c0(e){return e<<5|e>>>27}function h0(e){return e<<30|e>>>2}function l0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}mn.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 c=0;c<80;++c){var l=~~(c/20),d=c0(r)+l0(l,n,i,s)+o+t[c]+f0[l]|0;o=s,s=i,i=h0(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};mn.prototype._hash=function(){var e=a0.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 d0=mn,p0=ke,Tf=Fr,y0=We.Buffer,b0=[1518500249,1859775393,-1894007588,-899497514],w0=new Array(80);function _n(){this.init(),this._w=w0,Tf.call(this,64,56)}p0(_n,Tf);_n.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function g0(e){return e<<1|e>>>31}function m0(e){return e<<5|e>>>27}function _0(e){return e<<30|e>>>2}function v0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}_n.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]=g0(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var l=~~(c/20),d=m0(r)+v0(l,n,i,s)+o+t[c]+b0[l]|0;o=s,s=i,i=_0(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};_n.prototype._hash=function(){var e=y0.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 E0=_n,x0=ke,Af=Fr,S0=We.Buffer,B0=[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],P0=new Array(64);function vn(){this.init(),this._w=P0,Af.call(this,64,56)}x0(vn,Af);vn.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 T0(e,t,r){return r^e&(t^r)}function A0(e,t,r){return e&t|r&(e|t)}function I0(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function O0(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function k0(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function R0(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}vn.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,c=this._g|0,l=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=R0(t[d-2])+t[d-7]+k0(t[d-15])+t[d-16]|0;for(var g=0;g<64;++g){var x=l+O0(o)+T0(o,a,c)+B0[g]+t[g]|0,y=I0(r)+A0(r,n,i)|0;l=c,c=a,a=o,o=s+x|0,s=i,i=n,n=r,r=x+y|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=c+this._g|0,this._h=l+this._h|0};vn.prototype._hash=function(){var e=S0.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 If=vn,U0=ke,C0=If,L0=Fr,N0=We.Buffer,F0=new Array(64);function Ei(){this.init(),this._w=F0,L0.call(this,64,56)}U0(Ei,C0);Ei.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};Ei.prototype._hash=function(){var e=N0.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 M0=Ei,H0=ke,Of=Fr,$0=We.Buffer,Xo=[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],D0=new Array(160);function En(){this.init(),this._w=D0,Of.call(this,128,112)}H0(En,Of);En.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 Jo(e,t,r){return r^e&(t^r)}function Qo(e,t,r){return e&t|r&(e|t)}function Zo(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function ea(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function j0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function G0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function W0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function V0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ae(e,t){return e>>>0<t>>>0?1:0}En.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,c=this._gh|0,l=this._hh|0,d=this._al|0,g=this._bl|0,x=this._cl|0,y=this._dl|0,O=this._el|0,P=this._fl|0,A=this._gl|0,k=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 _=t[U-30],m=t[U-15*2+1],S=j0(_,m),E=G0(m,_);_=t[U-2*2],m=t[U-2*2+1];var H=W0(_,m),D=V0(m,_),R=t[U-7*2],z=t[U-7*2+1],Z=t[U-16*2],C=t[U-16*2+1],M=E+z|0,W=S+R+Ae(M,E)|0;M=M+D|0,W=W+H+Ae(M,D)|0,M=M+C|0,W=W+Z+Ae(M,C)|0,t[U]=W,t[U+1]=M}for(var q=0;q<160;q+=2){W=t[q],M=t[q+1];var fe=Qo(r,n,i),ue=Qo(d,g,x),et=Zo(r,d),Ve=Zo(d,r),it=ea(o,O),be=ea(O,o),xe=Xo[q],ze=Xo[q+1],It=Jo(o,a,c),pt=Jo(O,P,A),T=k+be|0,B=l+it+Ae(T,k)|0;T=T+pt|0,B=B+It+Ae(T,pt)|0,T=T+ze|0,B=B+xe+Ae(T,ze)|0,T=T+M|0,B=B+W+Ae(T,M)|0;var F=Ve+ue|0,G=et+fe+Ae(F,Ve)|0;l=c,k=A,c=a,A=P,a=o,P=O,O=y+T|0,o=s+B+Ae(O,y)|0,s=i,y=x,i=n,x=g,n=r,g=d,d=T+F|0,r=B+G+Ae(d,T)|0}this._al=this._al+d|0,this._bl=this._bl+g|0,this._cl=this._cl+x|0,this._dl=this._dl+y|0,this._el=this._el+O|0,this._fl=this._fl+P|0,this._gl=this._gl+A|0,this._hl=this._hl+k|0,this._ah=this._ah+r+Ae(this._al,d)|0,this._bh=this._bh+n+Ae(this._bl,g)|0,this._ch=this._ch+i+Ae(this._cl,x)|0,this._dh=this._dh+s+Ae(this._dl,y)|0,this._eh=this._eh+o+Ae(this._el,O)|0,this._fh=this._fh+a+Ae(this._fl,P)|0,this._gh=this._gh+c+Ae(this._gl,A)|0,this._hh=this._hh+l+Ae(this._hl,k)|0};En.prototype._hash=function(){var e=$0.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 kf=En,z0=ke,q0=kf,K0=Fr,Y0=We.Buffer,X0=new Array(160);function xi(){this.init(),this._w=X0,K0.call(this,128,112)}z0(xi,q0);xi.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};xi.prototype._hash=function(){var e=Y0.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 J0=xi,hr=Sf.exports=function(t){t=t.toLowerCase();var r=hr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};hr.sha=d0;hr.sha1=E0;hr.sha224=M0;hr.sha256=If;hr.sha384=J0;hr.sha512=kf;var Q0=Sf.exports,Rf=We.Buffer,Uf=Ws.Transform,Z0=Qn.StringDecoder,ed=ke;function nt(e){Uf.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}ed(nt,Uf);nt.prototype.update=function(e,t,r){typeof e=="string"&&(e=Rf.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};nt.prototype.setAutoPadding=function(){};nt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};nt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};nt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};nt.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)}};nt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};nt.prototype._finalOrDigest=function(e){var t=this.__final()||Rf.alloc(0);return e&&(t=this._toString(t,e,!0)),t};nt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Z0(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 td=nt,rd=ke,nd=Zl,id=s0,sd=Q0,Cf=td;function Si(e){Cf.call(this,"digest"),this._hash=e}rd(Si,Cf);Si.prototype._update=function(e){this._hash.update(e)};Si.prototype._final=function(){return this._hash.digest()};var od=function(t){return t=t.toLowerCase(),t==="md5"?new nd:t==="rmd160"||t==="ripemd160"?new id:new Si(sd(t))},Cn=We.Buffer;function ad(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),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if((Array.isArray(y)||y instanceof Uint8Array)&&(y=Cn.from(y)),!Cn.isBuffer(y))throw new TypeError("Expected Buffer");if(y.length===0)return"";for(var O=0,P=0,A=0,k=y.length;A!==k&&y[A]===0;)A++,O++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=y[A],S=0,E=U-1;(m!==0||S<P)&&E!==-1;E--,S++)m+=256*_[E]>>>0,_[E]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");P=S,A++}for(var H=U-P;H!==U&&_[H]===0;)H++;for(var D=a.repeat(O);H<U;++H)D+=e.charAt(_[H]);return D}function g(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return Cn.alloc(0);for(var O=0,P=0,A=0;y[O]===a;)P++,O++;for(var k=(y.length-O)*c+1>>>0,U=new Uint8Array(k);O<y.length;){var _=t[y.charCodeAt(O)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,O++}for(var E=k-A;E!==k&&U[E]===0;)E++;var H=Cn.allocUnsafe(P+(k-E));H.fill(0,0,P);for(var D=P;E!==k;)H[D++]=U[E++];return H}function x(y){var O=g(y);if(O)return O;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:g,decode:x}}var fd=ad,ud=fd,cd="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",hd=ud(cd),rs=hd,ld=We.Buffer,dd=function(e){function t(s){var o=e(s);return rs.encode(ld.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=rs.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=rs.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},ta=od,pd=dd;function yd(e){var t=ta("sha256").update(e).digest();return ta("sha256").update(t).digest()}var bd=pd(yd),gs=bd;function Lf(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 ms(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 wd(e,t){return Lf(gs.decode(e),t)}function gd(e,t,r){return typeof e=="number"?gs.encode(ms(e,t,r)):gs.encode(ms(e.version,e.privateKey,e.compressed))}var md={decode:wd,decodeRaw:Lf,encode:gd,encodeRaw:ms},Bi={};Object.defineProperty(Bi,"__esModule",{value:!0});Bi.testEcc=void 0;const V=e=>Buffer.from(e,"hex");function _d(e){he(e.isPoint(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(!e.isPoint(V("030000000000000000000000000000000000000000000000000000000000000005"))),he(e.isPrivate(V("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),he(!e.isPrivate(V("0000000000000000000000000000000000000000000000000000000000000000"))),he(!e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),he(!e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),he(Buffer.from(e.privateAdd(V("0000000000000000000000000000000000000000000000000000000000000001"),V("0000000000000000000000000000000000000000000000000000000000000000"))).equals(V("0000000000000000000000000000000000000000000000000000000000000001"))),he(e.privateAdd(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),V("0000000000000000000000000000000000000000000000000000000000000003"))===null),he(Buffer.from(e.privateAdd(V("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),V("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(V("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),he(Buffer.from(e.privateNegate(V("0000000000000000000000000000000000000000000000000000000000000001"))).equals(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),he(Buffer.from(e.privateNegate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(V("0000000000000000000000000000000000000000000000000000000000000003"))),he(Buffer.from(e.privateNegate(V("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(V("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),he(Buffer.from(e.pointCompress(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(Buffer.from(e.pointCompress(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),he(Buffer.from(e.pointCompress(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(Buffer.from(e.pointCompress(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),he(Buffer.from(e.pointFromScalar(V("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(V("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),he(e.xOnlyPointAddTweak(V("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(V("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),V("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));he(Buffer.from(t.xOnlyPubkey).equals(V("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(V("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),V("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),he(Buffer.from(t.xOnlyPubkey).equals(V("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),he(Buffer.from(e.sign(V("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(V("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),he(e.verify(V("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),V("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),V("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&he(Buffer.from(e.signSchnorr(V("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),V("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),V("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(V("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&he(e.verifySchnorr(V("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),V("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),V("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}Bi.testEcc=_d;function he(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(Ur,"__esModule",{value:!0});Ur.ECPairFactory=Ur.networks=void 0;const _s=Cr;Ur.networks=_s;const je=Qa,vd=Vh,ra=md,Ed=Bi,ns=je.typeforce.maybe(je.typeforce.compile({compressed:je.maybe(je.Boolean),network:je.maybe(je.Network)})),xd=e=>e.length===32?e:e.slice(1,33);function Sd(e){(0,Ed.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(je.typeforce(je.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return je.typeforce(ns,c),new o(a,void 0,c)}function n(a,c){return je.typeforce(e.isPoint,a),je.typeforce(ns,c),new o(void 0,a,c)}function i(a,c){const l=ra.decode(a),d=l.version;if(je.Array(c)){if(c=c.filter(g=>d===g.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||_s.bitcoin,d!==c.wif)throw new Error("Invalid network version");return r(l.privateKey,{compressed:l.compressed,network:c})}function s(a){je.typeforce(ns,a),a===void 0&&(a={});const c=a.rng||vd;let l;do l=c(32),je.typeforce(je.Buffer256bit,l);while(!e.isPrivate(l));return r(l,a)}class o{constructor(c,l,d){yr(this,"__D");yr(this,"__Q");yr(this,"compressed");yr(this,"network");yr(this,"lowR");this.__D=c,this.__Q=l,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||_s.bitcoin,l!==void 0&&(this.__Q=Buffer.from(e.pointCompress(l,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const c=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(c)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return ra.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,l){if(!this.__D)throw new Error("Missing private key");if(l===void 0&&(l=this.lowR),l===!1)return Buffer.from(e.sign(c,this.__D));{let d=e.sign(c,this.__D);const g=Buffer.alloc(32,0);let x=0;for(;d[0]>127;)x++,g.writeUIntLE(x,0,6),d=e.sign(c,this.__D,g);return Buffer.from(d)}}signSchnorr(c){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(c,this.privateKey))}verify(c,l){return e.verify(c,this.publicKey,l)}verifySchnorr(c,l){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),l)}tweakFromPublicKey(c){const l=xd(this.publicKey),d=e.xOnlyPointAddTweak(l,c);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const g=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([g,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,g=e.privateAdd(d,c);if(!g)throw new Error("Invalid tweaked private key!");return r(Buffer.from(g),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}Ur.ECPairFactory=Sd;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=Ur;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}})})(Ja);const Bd=Tu(Ja);class pn extends ae.EventBroker{get isInitialized(){return!!this.privKey}constructor(t,r){super(),this.privKey=t,this.walletClient=r}static fromPrivKey(t){return new pn(Jt(t))}static fromWalletClient(t){return new pn(void 0,t)}async initialize(){if(this.privKey)return re("Already initialized");const t=await this.derivePrivKeyFromWalletClient();return t.error?j(t.error):(this.emit("initialized",!0),re("Initialized"))}async derivePrivKeyFromWalletClient(){if(!this.walletClient)return j("No walletClient found");if(!this.walletClient.account)return j("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.privKey=Jt(dt.sha256(t)),this.emit("initialized",!0),re(this.privKey)}catch(t){return j("Failed to initialize: "+t)}}async getMasterPrivKey(){if(!this.privKey&&!this.walletClient)return j("No private key or wallet client found");if(!this.privKey&&this.walletClient){const t=await this.derivePrivKeyFromWalletClient();if(t.error)return j(t.error)}return this.privKey?re(this.privKey):j("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return j(r.error);const n=dt.sha256(ae.with0x(r.val)),i=dt.sha256(n);return re({secret:n,secretHash:i})}async signMessage(t){if(!this.privKey){const l=await this.getMasterPrivKey();if(l.error)return j(l.error);this.privKey=l.val}const r=Bd(er),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=dt.sha256(i),o=Buffer.from(Jt(this.privKey),"hex");if(o.length!==32)return j("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(Jt(s),"hex"));return re(c.toString("hex"))}}class Pd extends ae.EventBroker{constructor(t){super(),this.getOrderThreshold=20,this.refundSacpCache=new Map,this.redeemSacpCache=new Map,this.environment=t.environment;const r=t.environment===ae.Environment.MAINNET?ls.mainnet:t.environment===ae.Environment.TESTNET?ls.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);if(this._auth=new ae.Siwe(new ae.Url(t.orderbookURl??r.orderbook),t.evmWallet,t.siweOpts),this._quote=t.quote??new Xa(r.quote),this._orderBook=new le.Orderbook({url:t.orderbookURl??r.orderbook,walletClient:t.evmWallet,auth:this._auth}),this._orderbookUrl=new ae.Url(t.orderbookURl??r.orderbook),this._evmRelay=new ya(this._orderbookUrl,this._auth),this._secretManager=t.secretManager??pn.fromWalletClient(t.evmWallet),this.orderExecutorCache=new $h,this._evmWallet=t.evmWallet,!t.evmWallet.account)throw new Error("Account not found in evmWallet");this._blockNumberFetcher=t.blockNumberFetcher??new Ya(r.info,t.environment)}get orderbookUrl(){return this._orderbookUrl.toString()}get evmRelay(){return this._evmRelay}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}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return re(this._btcWallet);const t=await this._secretManager.getMasterPrivKey();if(t.error)return j(t.error);const r=new Ir.BitcoinProvider(gu(this.environment));return this._btcWallet=Ir.BitcoinWallet.fromPrivateKey(t.val,r),re(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return j(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 j(a.error);const{strategyId:c,btcAddress:l}=t.additionalData,d={strategy_id:c,...l&&{bitcoin_optional_recipient:l}},g={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:Jt(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},x=await this._quote.getAttestedQuote(g);if(x.error)return j(x.error);const y=await this._orderBook.createOrder(x.val);if(y.error)return j(y.error);const O=await this.pollOrder(y.val);return O.error?j(O.error):re(O.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return j("StrategyId is required");if(!t.fromAsset||!t.toAsset)return j("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return j("Source and destination assets cannot be the same");if(le.isMainnet(t.fromAsset.chain)&&!le.isMainnet(t.toAsset.chain)||!le.isMainnet(t.fromAsset.chain)&&le.isMainnet(t.toAsset.chain))return j("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return j(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return j(n.error);if(r<n)return j("Send amount should be greater than receive amount");const i=le.getTimeLock(t.fromAsset.chain);if(!i)return j("Unsupported chain for timelock");if(le.isBitcoin(t.fromAsset.chain)||le.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return j("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const a=await this.initializeSMandBTCWallet();if(a.error)return j(a.error);if(!this._btcWallet)return j("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return j(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?j(o.error):re({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(le.getBlockchainType(t)){case le.BlockchainType.EVM:return this._evmWallet.account?re(this._evmWallet.account.address):j("EVM Wallet not found");case le.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!bu(i)?j("Invalid btc public key"):re(yt(i))}default:return j("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return j("Invalid amount ",t);const r=new uu(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?j("Invalid amount ",t):re(r)}async pollOrder(t){let r=await this._orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ae.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return j(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return re(r.val);r=await this._orderBook.getOrder(t,!0)}return j(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderBook.subscribeToOrders(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=Ss(s.status);if(le.isBitcoin(s.source_swap.chain)&&s.status===pe.InitiateDetected){const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);continue}await this.postRefundSACP(s,a.val)}switch(o){case Pe.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(le.getBlockchainType(s.destination_swap.chain)){case le.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case le.BlockchainType.Bitcoin:{const c=this.getWallet(s.destination_swap.chain);if(c.error){this.emit("error",s,c.error);return}await this.postRedeemSACP(a.val.secret,s,c.val);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Pe.Refund:{switch(le.getBlockchainType(s.source_swap.chain)){case le.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by garden's relay service");break}case le.BlockchainType.Bitcoin:{const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);return}await this.btcRefund(a.val,s);break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Pe.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const i=await this._evmRelay.redeem(t.create_order.create_id,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Pe.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Pe.Redeem,i.val),this.emit("success",t,Pe.Redeem,i.val)}async btcRedeem(t,r,n){var a,c;const i=this.orderExecutorCache.get(r,Pe.Redeem),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.btcRedeemUTXO&&i.btcRedeemUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");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 l=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const g of l.vin)if(g.txid===s){d=!0;break}if(d){this.orderExecutorCache.set(r,Pe.Redeem,r.destination_swap.redeem_tx_hash,s),this.emit("log",r.create_order.create_id,"already a valid redeem");return}o=!0}catch(l){if(l.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+l);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const d=await(await Sr.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,yt(r.destination_swap.initiator),yt(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).redeem(Jt(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient);o?this.emit("log",r.create_order.create_id,"rbf: btc redeem success"):this.emit("success",r,Pe.Redeem,d),this.orderExecutorCache.set(r,Pe.Redeem,d,s)}catch(l){this.emit("error",r,"Failed btc redeem: "+l)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Pe.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await Sr.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,yt(r.source_swap.initiator),yt(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,Pe.Refund,s),this.emit("success",r,Pe.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(le.getBlockchainType(t)){case le.BlockchainType.EVM:return re(this._evmWallet);case le.BlockchainType.Bitcoin:return re(this._btcWallet);default:return j("Unsupported chain for wallet")}}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 Sr.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,yt(t.source_swap.initiator),yt(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),a=this._orderbookUrl.endpoint("orders/add-instant-refund-sacp");(await Ht.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:t.create_order.create_id,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 postRedeemSACP(t,r,n){if(this.redeemSacpCache.get(r.create_order.create_id))return;console.log("secret :",t),console.log("posting redeem sacp",r.create_order.create_id);const s=await Sr.from(n,Number(r.destination_swap.amount),r.create_order.secret_hash,yt(r.destination_swap.initiator),yt(r.destination_swap.redeemer),r.destination_swap.timelock),o=r.create_order.additional_data.bitcoin_optional_recipient;if(o)try{const a=await s.generateRedeemSACP(t,o),c=this._orderbookUrl.endpoint("orders/add-redeem-sacp"),l=await Ht.post(c,{headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:r.create_order.create_id,redeem_tx_bytes:a})});l.status==="Ok"&&l.result&&(this.emit("log",r.create_order.create_id,`redeem sacp success: ${l.result}`),this.emit("success",r,Pe.Redeem,l.result),this.redeemSacpCache.set(r.create_order.create_id,{}))}catch(a){this.emit("error",r,"Failed to generate and post SACP: "+a);return}}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return j("Provide wallets to fetch the current block number");const n=le.isBitcoin(t.source_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.source.getProvider()):await ae.fetchEVMBlockNumber(r.source);if(n.error)return j(n.error);const i=le.isBitcoin(t.destination_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ae.fetchEVMBlockNumber(r.destination);return i.error?j(i.error):re({source:n.val,destination:i.val})}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return re([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return j(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(pa(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,l=r==null?void 0:r.val[a],d=r==null?void 0:r.val[c];if(!l||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const g=xs(o,l,d);n.push({...o,status:g})}return re(n)}}function lr(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const Nf="2.21.41";let en={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Nf}`};class ye extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof ye?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof ye&&r.cause.docsPath||r.docsPath,s=(a=en.getDocsUrl)==null?void 0:a.call(en,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...en.version?[`Version: ${en.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=Nf}walk(t){return Ff(this,t)}}function Ff(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?Ff(e.cause,t):t?null:e}class Td extends ye{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 Ad extends ye{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function xn(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Nr(e){return xn(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function ti(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 Id extends ye{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 Mf extends ye{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 Mr(e,{dir:t,size:r=32}={}){return typeof e=="string"?Od(e,{dir:t,size:r}):kd(e,{dir:t,size:r})}function Od(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Mf({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function kd(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Mf({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 Rd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function J(e,t={}){return typeof e=="number"||typeof e=="bigint"?Hf(e,t):typeof e=="string"?Ld(e,t):typeof e=="boolean"?Ud(e,t):qt(e,t)}function Ud(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Hr(r,{size:t.size}),Mr(r,{size:t.size})):r}function qt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=Rd[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Hr(n,{size:t.size}),Mr(n,{dir:"right",size:t.size})):n}function Hf(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 c=typeof e=="bigint"?"n":"";throw new Td({max:s?`${s}${c}`:void 0,min:`${o}${c}`,signed:r,size:n,value:`${e}${c}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Mr(a,{size:n}):a}const Cd=new TextEncoder;function Ld(e,t={}){const r=Cd.encode(e);return qt(r,t)}const Nd=new TextEncoder;function $f(e,t={}){return typeof e=="number"||typeof e=="bigint"?Md(e,t):typeof e=="boolean"?Fd(e,t):xn(e)?ir(e,t):Df(e,t)}function Fd(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Hr(r,{size:t.size}),Mr(r,{size:t.size})):r}const _t={zero:48,nine:57,A:65,F:70,a:97,f:102};function na(e){if(e>=_t.zero&&e<=_t.nine)return e-_t.zero;if(e>=_t.A&&e<=_t.F)return e-(_t.A-10);if(e>=_t.a&&e<=_t.f)return e-(_t.a-10)}function ir(e,t={}){let r=e;t.size&&(Hr(r,{size:t.size}),r=Mr(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 c=na(n.charCodeAt(a++)),l=na(n.charCodeAt(a++));if(c===void 0||l===void 0)throw new ye(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+l}return s}function Md(e,t){const r=Hf(e,t);return ir(r)}function Df(e,t={}){const r=Nd.encode(e);return typeof t.size=="number"?(Hr(r,{size:t.size}),Mr(r,{dir:"right",size:t.size})):r}function Hr(e,{size:t}){if(Nr(e)>t)throw new Ad({givenSize:Nr(e),maxSize:t})}function xr(e,t={}){const{signed:r}=t;t.size&&Hr(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 ri(e,t={}){return Number(xr(e,t))}function qs(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 jf={"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?ri(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?ri(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?jf[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=$d(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 Hd=qs("transaction",Ks);function $d(e){return e.map(t=>({contractAddress:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function Dd(e){var r;const t=(r=e.transactions)==null?void 0:r.map(n=>typeof n=="string"?n:Ks(n));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 jd=qs("block",Dd);function Gd(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 Wd={"0x0":"reverted","0x1":"success"};function Vd(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=>Gd(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?ri(e.transactionIndex):null,status:e.status?Wd[e.status]:null,type:e.type?jf[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const zd=qs("transactionReceipt",Vd),Ys=2n**256n-1n;function Sn(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class ia extends ye{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class qd extends ye{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class Kd extends ye{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Yd={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 Kd({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new qd({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ia({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 ia({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 Gf(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(Yd);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function sr(e,t="hex"){const r=Wf(e),n=Gf(new Uint8Array(r.length));return r.encode(n),t==="hex"?qt(n.bytes):n.bytes}function Wf(e){return Array.isArray(e)?Xd(e.map(t=>Wf(t))):Jd(e)}function Xd(e){const t=e.reduce((i,s)=>i+s.length,0),r=Vf(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 Jd(e){const t=typeof e=="string"?ir(e):e,r=Vf(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 Vf(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 ye("Length is too large.")}const Qd={ether:-9,wei:9};function Zd(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 vs(e,t="wei"){return Zd(e,Qd[t])}function ep(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 tp extends ye{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class rp extends ye{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",ep(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 np extends ye{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 zf(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=>ir(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>qt(s))}function qf(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=>ir(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>ir(o)):e.commitments,s=[];for(let o=0;o<n.length;o++){const a=n[o],c=i[o];s.push(Uint8Array.from(t.computeBlobKzgProof(a,c)))}return r==="bytes"?s:s.map(o=>qt(o))}function ip(e,t){return Ha(xn(e,{strict:!1})?$f(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:qt(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 sa=6,Kf=32,Xs=4096,Yf=Kf*Xs,oa=Yf*sa-1-1*Xs*sa,Xf=1;class ap extends ye{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Jf extends ye{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class fp extends ye{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class up extends ye{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Xf}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function cp(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?ir(e.data):e.data,n=Nr(r);if(!n)throw new Jf;if(n>oa)throw new ap({maxSize:oa,size:n});const i=[];let s=!0,o=0;for(;s;){const a=Gf(new Uint8Array(Yf));let c=0;for(;c<Xs;){const l=r.slice(o,o+(Kf-1));if(a.pushByte(0),a.pushBytes(l),l.length<31){a.pushByte(128),s=!1;break}c++,o+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>qt(a.bytes))}function hp(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??cp({data:t,to:n}),s=e.commitments??zf({blobs:i,kzg:r,to:n}),o=e.proofs??qf({blobs:i,commitments:s,kzg:r,to:n}),a=[];for(let c=0;c<i.length;c++)a.push({blob:i[c],commitment:s[c],proof:o[c]});return a}function lp(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{contractAddress:n,chainId:i,nonce:s,...o}=r;t.push([i?J(i):"0x",n,s?J(s):"0x",...Bn({},o)])}return t}class or extends ye{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 Pi extends ye{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class Ti extends ye{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${vs(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Ti,"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 Qf extends ye{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${vs(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${vs(n)} gwei`:""}).`].join(`
|
|
34
34
|
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Qf,"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 Zf 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}}const Ln=BigInt(2**32-1),aa=BigInt(32);function dp(e,t=!1){return t?{h:Number(e&Ln),l:Number(e>>aa&Ln)}:{h:Number(e>>aa&Ln)|0,l:Number(e&Ln)|0}}function pp(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}=dp(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const yp=(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,eu=[],tu=[],ru=[],mp=BigInt(0),tn=BigInt(1),_p=BigInt(2),vp=BigInt(7),Ep=BigInt(256),xp=BigInt(113);for(let e=0,t=tn,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],eu.push(2*(5*n+r)),tu.push((e+1)*(e+2)/2%64);let i=mp;for(let s=0;s<7;s++)t=(t<<tn^(t>>vp)*xp)%Ep,t&_p&&(i^=tn<<(tn<<BigInt(s))-tn);ru.push(i)}const[Sp,Bp]=pp(ru,!0),fa=(e,t,r)=>r>32?wp(e,t,r):yp(e,t,r),ua=(e,t,r)=>r>32?gp(e,t,r):bp(e,t,r);function Pp(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,c=(o+2)%10,l=r[c],d=r[c+1],g=fa(l,d,1)^r[a],x=ua(l,d,1)^r[a+1];for(let y=0;y<50;y+=10)e[o+y]^=g,e[o+y+1]^=x}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=tu[o],c=fa(i,s,a),l=ua(i,s,a),d=eu[o];i=e[d],s=e[d+1],e[d]=c,e[d+1]=l}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]^=Sp[n],e[1]^=Bp[n]}r.fill(0)}class Js extends Ma{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,oo(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=ic(this.state)}keccak(){ao||fo(this.state32),Pp(this.state32,this.rounds),ao||fo(this.state32),this.posOut=0,this.pos=0}update(t){Yn(this);const{blockLen:r,state:n}=this;t=Cs(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){Yn(this,!1),Us(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 oo(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Fa(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 Js(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 Tp=(e,t,r)=>Ls(()=>new Js(t,e,r)),Ap=Tp(1,136,256/8);function Ip(e,t){return Ap(xn(e,{strict:!1})?$f(e):e)}const is=new Zf(8192);function Op(e,t){if(is.has(`${e}.${t}`))return is.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Ip(Df(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 is.set(`${e}.${t}`,s),s}const kp=/^0x[a-fA-F0-9]{40}$/,ss=new Zf(8192);function ar(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(ss.has(n))return ss.get(n);const i=kp.test(e)?e.toLowerCase()===e?!0:r?Op(e)===e:!0:!1;return ss.set(n,i),i}function Rp(e,t,r,{strict:n}={}){return xn(e,{strict:!1})?Cp(e,t,r,{strict:n}):Up(e,t,r,{strict:n})}function nu(e,t,r){if(Nr(e)!==r-t)throw new Id({offset:r,position:"end",size:Nr(e)})}function Up(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&nu(i,t,r),i}function Cp(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&nu(i,t,r),i}function Lp(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!ar(n))throw new or({address:n});if(i<0)throw new Pi({chainId:i})}Qs(e)}function Np(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Jf;for(const r of t){const n=Nr(r),i=ri(Rp(r,0,1));if(n!==32)throw new fp({hash:r,size:n});if(i!==Xf)throw new up({hash:r,version:i})}}Qs(e)}function Qs(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Pi({chainId:t});if(i&&!ar(i))throw new or({address:i});if(n&&n>Ys)throw new Ti({maxFeePerGas:n});if(r&&n&&r>n)throw new Qf({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Fp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new Pi({chainId:t});if(s&&!ar(s))throw new or({address:s});if(r||i)throw new ye("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ys)throw new Ti({maxFeePerGas:n})}function Mp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!ar(s))throw new or({address:s});if(typeof t<"u"&&t<=0)throw new Pi({chainId:t});if(r||i)throw new ye("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ys)throw new Ti({maxFeePerGas:n})}function Hp(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 rp({transaction:e})}function Ai(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 np({storageKey:i[s]});if(!ar(n,{strict:!1}))throw new or({address:n});t.push([n,i])}return t}function $p(e,t){const r=Hp(e);return r==="eip1559"?Gp(e,t):r==="eip2930"?Wp(e,t):r==="eip4844"?jp(e,t):r==="eip7702"?Dp(e,t):Vp(e,t)}function Dp(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:c,maxPriorityFeePerGas:l,accessList:d,data:g}=e;Lp(e);const x=Ai(d),y=lp(r);return Sn(["0x04",sr([J(n),s?J(s):"0x",l?J(l):"0x",c?J(c):"0x",i?J(i):"0x",o??"0x",a?J(a):"0x",g??"0x",x,y,...Bn(e,t)])])}function jp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:l,accessList:d,data:g}=e;Np(e);let x=e.blobVersionedHashes,y=e.sidecars;if(e.blobs&&(typeof x>"u"||typeof y>"u")){const _=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(E=>qt(E)),m=e.kzg,S=zf({blobs:_,kzg:m});if(typeof x>"u"&&(x=op({commitments:S})),typeof y>"u"){const E=qf({blobs:_,commitments:S,kzg:m});y=hp({blobs:_,commitments:S,proofs:E})}}const O=Ai(d),P=[J(r),i?J(i):"0x",l?J(l):"0x",c?J(c):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",g??"0x",O,a?J(a):"0x",x??[],...Bn(e,t)],A=[],k=[],U=[];if(y)for(let _=0;_<y.length;_++){const{blob:m,commitment:S,proof:E}=y[_];A.push(m),k.push(S),U.push(E)}return Sn(["0x03",sr(y?[P,A,k,U]:P)])}function Gp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:l,data:d}=e;Qs(e);const g=Ai(l),x=[J(r),i?J(i):"0x",c?J(c):"0x",a?J(a):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",d??"0x",g,...Bn(e,t)];return Sn(["0x02",sr(x)])}function Wp(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:c,gasPrice:l}=e;Fp(e);const d=Ai(c),g=[J(r),s?J(s):"0x",l?J(l):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x",d,...Bn(e,t)];return Sn(["0x01",sr(g)])}function Vp(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:c}=e;Mp(e);let l=[s?J(s):"0x",c?J(c):"0x",n?J(n):"0x",o??"0x",a?J(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 y=27n+(t.v===27n?0n:1n);if(t.v!==y)throw new tp({v:t.v});return y})(),g=ti(t.r),x=ti(t.s);l=[...l,J(d),g==="0x00"?"0x":g,x==="0x00"?"0x":x]}else r>0&&(l=[...l,J(r),"0x","0x"]);return sr(l)}function Bn(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=ti(r.r),o=ti(r.s);return[typeof i=="number"?i?J(1):"0x":n===0n?"0x":n===1n?J(1):n===27n?"0x":J(1),s==="0x00"?"0x":s,o==="0x00"?"0x":o]}const zp={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},qp={block:jd({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?xr(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Hd({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?xr(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:zd({format(e){return{l1GasPrice:e.l1GasPrice?xr(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?xr(e.l1GasUsed):null,l1Fee:e.l1Fee?xr(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function Kp(e,t){return Jp(e)?Xp(e):$p(e,t)}const Yp={transaction:Kp};function Xp(e){Qp(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:c}=e,l=[t,n,a??"0x",o?J(o):"0x",c?J(c):"0x",i?J(i):"0x",s?"0x1":"0x",r??"0x"];return Sn(["0x7e",sr(l)])}function Jp(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Qp(e){const{from:t,to:r}=e;if(t&&!ar(t))throw new or({address:t});if(r&&!ar(r))throw new or({address:r})}const ni={contracts:zp,formatters:qp,serializers:Yp},Zp=lr({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}}}),ey=lr({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}),rn=1,ty=lr({...ni,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:{...ni.contracts,disputeGameFactory:{[rn]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[rn]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[rn]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[rn]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:rn}),nn=11155111,ry=lr({...ni,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:{...ni.contracts,disputeGameFactory:{[nn]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[nn]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[nn]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[nn]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:nn}),ny=lr({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),iy=lr({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},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}}}),sy=lr({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}),oy={...sy,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},iu=dt.defineChain({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"",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/v2/"}},testnet:!0}),su={ethereum:iy,arbitrum:Zp,ethereum_sepolia:oy,arbitrum_sepolia:ey,ethereum_localnet:le.EthereumLocalnet,arbitrum_localnet:le.ArbitrumLocalnet,base_sepolia:ry,base:ty,bera_testnet:ny,citrea_testnet:iu},ay=async(e,t)=>{var n;const r=su[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return re({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=dt.createWalletClient({account:t.account,chain:r,transport:dt.custom(window.ethereum)});return re({message:"Switched chain",walletClient:i})}catch(i){if(fy(i))try{await t.addChain({chain:r});const s=dt.createWalletClient({account:t.account,chain:r,transport:dt.custom(window.ethereum)});return re({message:"Added network",walletClient:s})}catch{return j("Failed to add network")}else return j("Failed to switch network")}else return j("Chain not supported")},fy=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.API=ls;exports.BlockNumberFetcher=Ya;exports.EvmRelay=ya;exports.Garden=Pd;exports.OrderActions=Pe;exports.OrderStatus=pe;exports.ParseOrderStatus=xs;exports.ParseSwapStatus=fs;exports.Quote=Xa;exports.SecretManager=pn;exports.SwapStatus=me;exports.citreaTestnet=iu;exports.constructOrderPair=da;exports.evmToViemChainMap=su;exports.filterDeadlineExpiredOrders=_u;exports.isExpired=cn;exports.parseAction=mu;exports.parseActionFromStatus=Ss;exports.switchOrAddNetwork=ay;exports.validateBTCAddress=wu;
|
package/dist/index.js
CHANGED
|
@@ -9998,7 +9998,7 @@ class ii extends ga {
|
|
|
9998
9998
|
}
|
|
9999
9999
|
class Dy extends ga {
|
|
10000
10000
|
constructor(t) {
|
|
10001
|
-
super(), this.getOrderThreshold = 20, this.refundSacpCache = /* @__PURE__ */ new Map(), this.environment = t.environment;
|
|
10001
|
+
super(), this.getOrderThreshold = 20, this.refundSacpCache = /* @__PURE__ */ new Map(), this.redeemSacpCache = /* @__PURE__ */ new Map(), this.environment = t.environment;
|
|
10002
10002
|
const r = t.environment === Tr.MAINNET ? Fo.mainnet : t.environment === Tr.TESTNET ? Fo.testnet : void 0;
|
|
10003
10003
|
if (!r)
|
|
10004
10004
|
throw new Error(
|
|
@@ -10402,36 +10402,37 @@ class Dy extends ga {
|
|
|
10402
10402
|
}
|
|
10403
10403
|
}
|
|
10404
10404
|
async postRedeemSACP(t, r, n) {
|
|
10405
|
-
|
|
10406
|
-
|
|
10405
|
+
if (this.redeemSacpCache.get(r.create_order.create_id)) return;
|
|
10406
|
+
console.log("secret :", t), console.log("posting redeem sacp", r.create_order.create_id);
|
|
10407
|
+
const s = await Er.from(
|
|
10407
10408
|
n,
|
|
10408
10409
|
Number(r.destination_swap.amount),
|
|
10409
10410
|
r.create_order.secret_hash,
|
|
10410
10411
|
lt(r.destination_swap.initiator),
|
|
10411
10412
|
lt(r.destination_swap.redeemer),
|
|
10412
10413
|
r.destination_swap.timelock
|
|
10413
|
-
),
|
|
10414
|
-
if (
|
|
10414
|
+
), o = r.create_order.additional_data.bitcoin_optional_recipient;
|
|
10415
|
+
if (o)
|
|
10415
10416
|
try {
|
|
10416
|
-
const
|
|
10417
|
+
const a = await s.generateRedeemSACP(
|
|
10417
10418
|
t,
|
|
10418
|
-
|
|
10419
|
-
),
|
|
10419
|
+
o
|
|
10420
|
+
), c = this._orderbookUrl.endpoint("orders/add-redeem-sacp"), l = await Ft.post(c, {
|
|
10420
10421
|
headers: {
|
|
10421
10422
|
"Content-Type": "application/json"
|
|
10422
10423
|
},
|
|
10423
10424
|
body: JSON.stringify({
|
|
10424
10425
|
order_id: r.create_order.create_id,
|
|
10425
|
-
redeem_tx_bytes:
|
|
10426
|
+
redeem_tx_bytes: a
|
|
10426
10427
|
})
|
|
10427
10428
|
});
|
|
10428
|
-
|
|
10429
|
+
l.status === "Ok" && l.result && (this.emit(
|
|
10429
10430
|
"log",
|
|
10430
10431
|
r.create_order.create_id,
|
|
10431
|
-
`redeem sacp success: ${
|
|
10432
|
-
), this.emit("success", r, Be.Redeem,
|
|
10433
|
-
} catch (
|
|
10434
|
-
this.emit("error", r, "Failed to generate and post SACP: " +
|
|
10432
|
+
`redeem sacp success: ${l.result}`
|
|
10433
|
+
), this.emit("success", r, Be.Redeem, l.result), this.redeemSacpCache.set(r.create_order.create_id, {}));
|
|
10434
|
+
} catch (a) {
|
|
10435
|
+
this.emit("error", r, "Failed to generate and post SACP: " + a);
|
|
10435
10436
|
return;
|
|
10436
10437
|
}
|
|
10437
10438
|
}
|
|
@@ -19,6 +19,7 @@ export declare class Garden extends EventBroker<GardenEvents> implements IGarden
|
|
|
19
19
|
private orderExecutorCache;
|
|
20
20
|
private _blockNumberFetcher;
|
|
21
21
|
private refundSacpCache;
|
|
22
|
+
private redeemSacpCache;
|
|
22
23
|
private _evmRelay;
|
|
23
24
|
private _evmWallet;
|
|
24
25
|
private _btcWallet;
|