@gardenfi/core 2.0.23 → 2.0.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 +5 -5
- package/dist/index.js +784 -778
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var Vu=Object.defineProperty;var Gu=(e,t,r)=>t in e?Vu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var jr=(e,t,r)=>Gu(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ae=require("@gardenfi/orderbook"),Z=require("@gardenfi/utils"),nn=require("@catalogfi/wallets"),$t=require("viem"),Sc=require("varuint-bitcoin"),Wu=require("tiny-secp256k1"),Ac=require("bitcoinjs-lib"),Ku=require("bignumber.js"),Yu=require("crypto-browserify"),nt=require("starknet");function So(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const oa=So(Sc),Pr=So(Wu),de=So(Ac);var Bc=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},ws=(e,t,r)=>(Bc(e,t,"read from private field"),r?r.call(e):t.get(e)),_s=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},vs=(e,t,r,n)=>(Bc(e,t,"write to private field"),t.set(e,r),r);const Xu=e=>new Promise(t=>setTimeout(t,e));class Zu{constructor(t,r){this.maxRetries=Math.max(t,0),this.delay=r}async retry(t){let r=0,n;for(;r<this.maxRetries+1;)try{return await t()}catch(i){r++,n=i,await Xu(this.delay*r)}throw n}}const Ju=e=>{try{return JSON.parse(e)}catch{return e}};class jt{static async _postWithFallback(t,r){let n="";for(const i of t)try{const s=await fetch(i,{method:"POST",...r});if(s.status>=500){n=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){n=aa(s);continue}throw new Error(n||"All APIs failed")}static async postWithFallback(t,r){return await fi(r).retry(()=>this._postWithFallback(t,r))}static async _getWithFallback(t,r){let n="";for(const i of t)try{const s=await fetch(i,r);if(s.status>=500){n=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){n=aa(s);continue}throw new Error(n||"All APIs failed")}static async getWithFallback(t,r){return await fi(r).retry(()=>this._getWithFallback(t,r))}static async _get(t,r){return await this.parse(await fetch(t,r))}static async get(t,r){return await fi(r).retry(()=>this._get(t,r))}static async _post(t,r){return await this.parse(await fetch(t,{method:"POST",...r}))}static async post(t,r){return await fi(r).retry(()=>this._post(t,r))}static async parse(t){const r=await t.text();if(t.status>=200&&t.status<300)return Ju(r);throw new Error(r)}}function aa(e){return(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"unknown error"}const fi=e=>new Zu((e==null?void 0:e.retryCount)??2,(e==null?void 0:e.retryDelay)??1e3),ui=e=>e.startsWith("0x")?e:`0x${e}`,Tt=e=>e.startsWith("0x")?e.slice(2):e;var vi,Ei,xi;let no=class{constructor(t,r,n=void 0){_s(this,vi,void 0),_s(this,Ei,void 0),_s(this,xi,void 0),vs(this,vi,t),vs(this,xi,n),vs(this,Ei,r)}get ok(){return ws(this,vi)}get error(){return ws(this,xi)}get val(){return ws(this,Ei)}};vi=new WeakMap,Ei=new WeakMap,xi=new WeakMap;const ce=e=>new no(!0,e),V=(e,...t)=>{if(typeof e=="string"&&t&&t.length>0){let r=[e,...t].map(n=>{if(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;if(n!=null&&n.toString)return n.toString()}});return new no(!1,null,r.filter(n=>n!==void 0).join(" "))}return new no(!1,null,e)};var Re=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Re||{});function io(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function Er(e,t){if(!e)throw new Error(t)}function Qu(e){return Buffer.concat([Uint8Array.from([192]),el(e)])}function el(e){const t=oa.encodingLength(e.length),r=Buffer.allocUnsafe(t);return oa.encode(e.length,r),Buffer.concat([r,e])}function tl(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const xr=e=>e.length===64?e:e.slice(2),rl=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return Pr.isPoint(t)}catch{return!1}},Ic=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function nl(e,t){if(!e)return!1;const r=t===Z.Environment.MAINNET?de.networks.bitcoin:t===Z.Environment.TESTNET?de.networks.testnet:de.networks.regtest;if(!r)return!1;de.initEccLib(Pr);try{return de.address.toOutputScript(e,r),!0}catch{return!1}}const il=e=>{switch(e){case Z.Environment.MAINNET:return nn.BitcoinNetwork.Mainnet;case Z.Environment.TESTNET:return nn.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}};var ve=(e=>(e.Created="Created",e.Matched="Matched",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.CounterPartyInitiateDetected="CounterPartyInitiateDetected",e.CounterPartyInitiated="CounterPartyInitiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.CounterPartyRedeemDetected="CounterPartyRedeemDetected",e.CounterPartyRedeemed="CounterPartyRedeemed",e.Completed="Completed",e.CounterPartySwapExpired="CounterPartySwapExpired",e.Expired="Expired",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.CounterPartyRefundDetected="CounterPartyRefundDetected",e.CounterPartyRefunded="CounterPartyRefunded",e.Cancelled="Cancelled",e.DeadLineExceeded="DeadLineExceeded",e))(ve||{}),xe=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(xe||{});const Ao=(e,t,r)=>{const n=so(e.source_swap,t),i=so(e.destination_swap,r);if(i===xe.RedeemDetected)return ve.RedeemDetected;if(i===xe.Redeemed)return ve.Redeemed;if(n===xe.Refunded)return ve.Refunded;if(n===xe.RefundDetected)return ve.RefundDetected;if(i===xe.Expired)return ve.CounterPartySwapExpired;if(n===xe.Expired)return ve.Expired;if(i===xe.Refunded)return ve.CounterPartyRefunded;if(i===xe.RefundDetected)return ve.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===xe.Initiated?ve.CounterPartyInitiated:i===xe.InitiateDetected?ve.CounterPartyInitiateDetected:jn(s,12)?ve.DeadLineExceeded:n===xe.Initiated?ve.Initiated:jn(s,1)?ve.DeadLineExceeded:n===xe.InitiateDetected?ve.InitiateDetected:n===xe.Redeemed?ve.CounterPartyRedeemed:n===xe.RedeemDetected?ve.CounterPartyRedeemDetected:ve.Matched},so=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?xe.Redeemed:xe.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?xe.Refunded:xe.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return xe.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?xe.Initiated:xe.InitiateDetected:xe.Idle},sl=(e,t,r)=>{const n=Ao(e,t,r);return Bo(n)},Bo=e=>{switch(e){case ve.Matched:return Re.Initiate;case ve.CounterPartyInitiated:case ve.CounterPartyInitiateDetected:case ve.RedeemDetected:return Re.Redeem;case ve.Expired:return Re.Refund;default:return Re.Idle}},jn=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},ol=e=>e.filter(t=>!Tc(t)),Tc=e=>{const{source_swap:t,create_order:r}=e,{initiate_tx_hash:n,initiate_block_number:i}=t,{deadline:s}=r.additional_data;return n&&Number(i)?!1:n&&!Number(i)?jn(Number(s),12):n?!1:jn(Number(s),1)},al=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),cl=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),fl=Buffer.concat([al,cl]),ul=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),ca={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function ll(){const e=Ac.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=Pr.pointMultiply(Buffer.concat([Buffer.from("04","hex"),fl]),e);if(!t)throw new Error(ca.failedToCreateInternalPubkey);const r=Pr.pointAdd(ul,t);if(!r)throw new Error(ca.failedToCreateInternalPubkey);return io(Buffer.from(r))}var hr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function dl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function hl(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Be={},Ke={},Yt={},qi={};qi.byteLength=ml;qi.toByteArray=gl;qi.fromByteArray=vl;var It=[],ut=[],pl=typeof Uint8Array<"u"?Uint8Array:Array,Es="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var zr=0,yl=Es.length;zr<yl;++zr)It[zr]=Es[zr],ut[Es.charCodeAt(zr)]=zr;ut[45]=62;ut[95]=63;function kc(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ml(e){var t=kc(e),r=t[0],n=t[1];return(r+n)*3/4-n}function bl(e,t,r){return(t+r)*3/4-r}function gl(e){var t,r=kc(e),n=r[0],i=r[1],s=new pl(bl(e,n,i)),o=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)t=ut[e.charCodeAt(f)]<<18|ut[e.charCodeAt(f+1)]<<12|ut[e.charCodeAt(f+2)]<<6|ut[e.charCodeAt(f+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=ut[e.charCodeAt(f)]<<2|ut[e.charCodeAt(f+1)]>>4,s[o++]=t&255),i===1&&(t=ut[e.charCodeAt(f)]<<10|ut[e.charCodeAt(f+1)]<<4|ut[e.charCodeAt(f+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function wl(e){return It[e>>18&63]+It[e>>12&63]+It[e>>6&63]+It[e&63]}function _l(e,t,r){for(var n,i=[],s=t;s<r;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(e[s+2]&255),i.push(wl(n));return i.join("")}function vl(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(_l(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(It[t>>2]+It[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(It[t>>10]+It[t>>4&63]+It[t<<2&63]+"=")),i.join("")}var Io={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Io.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,f=(1<<a)-1,l=f>>1,d=-7,p=r?i-1:0,w=r?-1:1,y=e[t+p];for(p+=w,s=y&(1<<-d)-1,y>>=-d,d+=a;d>0;s=s*256+e[t+p],p+=w,d-=8);for(o=s&(1<<-d)-1,s>>=-d,d+=n;d>0;o=o*256+e[t+p],p+=w,d-=8);if(s===0)s=1-l;else{if(s===f)return o?NaN:(y?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-l}return(y?-1:1)*o*Math.pow(2,s-n)};Io.write=function(e,t,r,n,i,s){var o,a,f,l=s*8-i-1,d=(1<<l)-1,p=d>>1,w=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:s-1,I=n?1:-1,S=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=d):(o=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-o))<1&&(o--,f*=2),o+p>=1?t+=w/f:t+=w*Math.pow(2,1-p),t*f>=2&&(o++,f/=2),o+p>=d?(a=0,o=d):o+p>=1?(a=(t*f-1)*Math.pow(2,i),o=o+p):(a=t*Math.pow(2,p-1)*Math.pow(2,i),o=0));i>=8;e[r+y]=a&255,y+=I,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+y]=o&255,y+=I,o/=256,l-=8);e[r+y-I]|=S*128};/*!
|
|
1
|
+
"use strict";var Vu=Object.defineProperty;var Gu=(e,t,r)=>t in e?Vu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var jr=(e,t,r)=>Gu(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ae=require("@gardenfi/orderbook"),Z=require("@gardenfi/utils"),nn=require("@catalogfi/wallets"),$t=require("viem"),Sc=require("varuint-bitcoin"),Wu=require("tiny-secp256k1"),Ac=require("bitcoinjs-lib"),Ku=require("bignumber.js"),Yu=require("crypto-browserify"),et=require("starknet");function So(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const oa=So(Sc),Pr=So(Wu),de=So(Ac);var Bc=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},ws=(e,t,r)=>(Bc(e,t,"read from private field"),r?r.call(e):t.get(e)),_s=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},vs=(e,t,r,n)=>(Bc(e,t,"write to private field"),t.set(e,r),r);const Xu=e=>new Promise(t=>setTimeout(t,e));class Zu{constructor(t,r){this.maxRetries=Math.max(t,0),this.delay=r}async retry(t){let r=0,n;for(;r<this.maxRetries+1;)try{return await t()}catch(i){r++,n=i,await Xu(this.delay*r)}throw n}}const Ju=e=>{try{return JSON.parse(e)}catch{return e}};class jt{static async _postWithFallback(t,r){let n="";for(const i of t)try{const s=await fetch(i,{method:"POST",...r});if(s.status>=500){n=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){n=aa(s);continue}throw new Error(n||"All APIs failed")}static async postWithFallback(t,r){return await fi(r).retry(()=>this._postWithFallback(t,r))}static async _getWithFallback(t,r){let n="";for(const i of t)try{const s=await fetch(i,r);if(s.status>=500){n=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){n=aa(s);continue}throw new Error(n||"All APIs failed")}static async getWithFallback(t,r){return await fi(r).retry(()=>this._getWithFallback(t,r))}static async _get(t,r){return await this.parse(await fetch(t,r))}static async get(t,r){return await fi(r).retry(()=>this._get(t,r))}static async _post(t,r){return await this.parse(await fetch(t,{method:"POST",...r}))}static async post(t,r){return await fi(r).retry(()=>this._post(t,r))}static async parse(t){const r=await t.text();if(t.status>=200&&t.status<300)return Ju(r);throw new Error(r)}}function aa(e){return(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"unknown error"}const fi=e=>new Zu((e==null?void 0:e.retryCount)??2,(e==null?void 0:e.retryDelay)??1e3),ui=e=>e.startsWith("0x")?e:`0x${e}`,Tt=e=>e.startsWith("0x")?e.slice(2):e;var vi,Ei,xi;let no=class{constructor(t,r,n=void 0){_s(this,vi,void 0),_s(this,Ei,void 0),_s(this,xi,void 0),vs(this,vi,t),vs(this,xi,n),vs(this,Ei,r)}get ok(){return ws(this,vi)}get error(){return ws(this,xi)}get val(){return ws(this,Ei)}};vi=new WeakMap,Ei=new WeakMap,xi=new WeakMap;const ce=e=>new no(!0,e),V=(e,...t)=>{if(typeof e=="string"&&t&&t.length>0){let r=[e,...t].map(n=>{if(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;if(n!=null&&n.toString)return n.toString()}});return new no(!1,null,r.filter(n=>n!==void 0).join(" "))}return new no(!1,null,e)};var Re=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Re||{});function io(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function Er(e,t){if(!e)throw new Error(t)}function Qu(e){return Buffer.concat([Uint8Array.from([192]),el(e)])}function el(e){const t=oa.encodingLength(e.length),r=Buffer.allocUnsafe(t);return oa.encode(e.length,r),Buffer.concat([r,e])}function tl(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const xr=e=>e.length===64?e:e.slice(2),rl=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return Pr.isPoint(t)}catch{return!1}},Ic=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function nl(e,t){if(!e)return!1;const r=t===Z.Environment.MAINNET?de.networks.bitcoin:t===Z.Environment.TESTNET?de.networks.testnet:de.networks.regtest;if(!r)return!1;de.initEccLib(Pr);try{return de.address.toOutputScript(e,r),!0}catch{return!1}}const il=e=>{switch(e){case Z.Environment.MAINNET:return nn.BitcoinNetwork.Mainnet;case Z.Environment.TESTNET:return nn.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}};var ve=(e=>(e.Created="Created",e.Matched="Matched",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.CounterPartyInitiateDetected="CounterPartyInitiateDetected",e.CounterPartyInitiated="CounterPartyInitiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.CounterPartyRedeemDetected="CounterPartyRedeemDetected",e.CounterPartyRedeemed="CounterPartyRedeemed",e.Completed="Completed",e.CounterPartySwapExpired="CounterPartySwapExpired",e.Expired="Expired",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.CounterPartyRefundDetected="CounterPartyRefundDetected",e.CounterPartyRefunded="CounterPartyRefunded",e.Cancelled="Cancelled",e.DeadLineExceeded="DeadLineExceeded",e))(ve||{}),xe=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(xe||{});const Ao=(e,t,r)=>{const n=so(e.source_swap,t),i=so(e.destination_swap,r);if(i===xe.RedeemDetected)return ve.RedeemDetected;if(i===xe.Redeemed)return ve.Redeemed;if(n===xe.Refunded)return ve.Refunded;if(n===xe.RefundDetected)return ve.RefundDetected;if(i===xe.Expired)return ve.CounterPartySwapExpired;if(n===xe.Expired)return ve.Expired;if(i===xe.Refunded)return ve.CounterPartyRefunded;if(i===xe.RefundDetected)return ve.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===xe.Initiated?ve.CounterPartyInitiated:i===xe.InitiateDetected?ve.CounterPartyInitiateDetected:jn(s,12)?ve.DeadLineExceeded:n===xe.Initiated?ve.Initiated:jn(s,1)?ve.DeadLineExceeded:n===xe.InitiateDetected?ve.InitiateDetected:n===xe.Redeemed?ve.CounterPartyRedeemed:n===xe.RedeemDetected?ve.CounterPartyRedeemDetected:ve.Matched},so=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?xe.Redeemed:xe.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?xe.Refunded:xe.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return xe.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?xe.Initiated:xe.InitiateDetected:xe.Idle},sl=(e,t,r)=>{const n=Ao(e,t,r);return Bo(n)},Bo=e=>{switch(e){case ve.Matched:return Re.Initiate;case ve.CounterPartyInitiated:case ve.CounterPartyInitiateDetected:case ve.RedeemDetected:return Re.Redeem;case ve.Expired:return Re.Refund;default:return Re.Idle}},jn=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},ol=e=>e.filter(t=>!Tc(t)),Tc=e=>{const{source_swap:t,create_order:r}=e,{initiate_tx_hash:n,initiate_block_number:i}=t,{deadline:s}=r.additional_data;return n&&Number(i)?!1:n&&!Number(i)?jn(Number(s),12):n?!1:jn(Number(s),1)},al=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),cl=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),fl=Buffer.concat([al,cl]),ul=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),ca={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function ll(){const e=Ac.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=Pr.pointMultiply(Buffer.concat([Buffer.from("04","hex"),fl]),e);if(!t)throw new Error(ca.failedToCreateInternalPubkey);const r=Pr.pointAdd(ul,t);if(!r)throw new Error(ca.failedToCreateInternalPubkey);return io(Buffer.from(r))}var hr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function dl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function hl(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Be={},Ke={},Yt={},qi={};qi.byteLength=ml;qi.toByteArray=gl;qi.fromByteArray=vl;var It=[],ut=[],pl=typeof Uint8Array<"u"?Uint8Array:Array,Es="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var zr=0,yl=Es.length;zr<yl;++zr)It[zr]=Es[zr],ut[Es.charCodeAt(zr)]=zr;ut[45]=62;ut[95]=63;function kc(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ml(e){var t=kc(e),r=t[0],n=t[1];return(r+n)*3/4-n}function bl(e,t,r){return(t+r)*3/4-r}function gl(e){var t,r=kc(e),n=r[0],i=r[1],s=new pl(bl(e,n,i)),o=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)t=ut[e.charCodeAt(f)]<<18|ut[e.charCodeAt(f+1)]<<12|ut[e.charCodeAt(f+2)]<<6|ut[e.charCodeAt(f+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=ut[e.charCodeAt(f)]<<2|ut[e.charCodeAt(f+1)]>>4,s[o++]=t&255),i===1&&(t=ut[e.charCodeAt(f)]<<10|ut[e.charCodeAt(f+1)]<<4|ut[e.charCodeAt(f+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function wl(e){return It[e>>18&63]+It[e>>12&63]+It[e>>6&63]+It[e&63]}function _l(e,t,r){for(var n,i=[],s=t;s<r;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(e[s+2]&255),i.push(wl(n));return i.join("")}function vl(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(_l(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(It[t>>2]+It[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(It[t>>10]+It[t>>4&63]+It[t<<2&63]+"=")),i.join("")}var Io={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Io.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,f=(1<<a)-1,l=f>>1,d=-7,p=r?i-1:0,w=r?-1:1,y=e[t+p];for(p+=w,s=y&(1<<-d)-1,y>>=-d,d+=a;d>0;s=s*256+e[t+p],p+=w,d-=8);for(o=s&(1<<-d)-1,s>>=-d,d+=n;d>0;o=o*256+e[t+p],p+=w,d-=8);if(s===0)s=1-l;else{if(s===f)return o?NaN:(y?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-l}return(y?-1:1)*o*Math.pow(2,s-n)};Io.write=function(e,t,r,n,i,s){var o,a,f,l=s*8-i-1,d=(1<<l)-1,p=d>>1,w=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:s-1,I=n?1:-1,S=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=d):(o=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-o))<1&&(o--,f*=2),o+p>=1?t+=w/f:t+=w*Math.pow(2,1-p),t*f>=2&&(o++,f/=2),o+p>=d?(a=0,o=d):o+p>=1?(a=(t*f-1)*Math.pow(2,i),o=o+p):(a=t*Math.pow(2,p-1)*Math.pow(2,i),o=0));i>=8;e[r+y]=a&255,y+=I,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+y]=o&255,y+=I,o/=256,l-=8);e[r+y-I]|=S*128};/*!
|
|
2
2
|
* The buffer module from node.js, for the browser.
|
|
3
3
|
*
|
|
4
4
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
5
|
* @license MIT
|
|
6
|
-
*/(function(e){const t=qi,r=Io,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=k,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=s(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const h=new Uint8Array(1),c={foo:function(){return 42}};return Object.setPrototypeOf(c,Uint8Array.prototype),Object.setPrototypeOf(h,c),h.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function o(h){if(h>i)throw new RangeError('The value "'+h+'" is invalid for option "size"');const c=new Uint8Array(h);return Object.setPrototypeOf(c,a.prototype),c}function a(h,c,u){if(typeof h=="number"){if(typeof c=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return p(h)}return f(h,c,u)}a.poolSize=8192;function f(h,c,u){if(typeof h=="string")return w(h,c);if(ArrayBuffer.isView(h))return I(h);if(h==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h);if(rt(h,ArrayBuffer)||h&&rt(h.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(rt(h,SharedArrayBuffer)||h&&rt(h.buffer,SharedArrayBuffer)))return S(h,c,u);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const m=h.valueOf&&h.valueOf();if(m!=null&&m!==h)return a.from(m,c,u);const T=_(h);if(T)return T;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return a.from(h[Symbol.toPrimitive]("string"),c,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h)}a.from=function(h,c,u){return f(h,c,u)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function l(h){if(typeof h!="number")throw new TypeError('"size" argument must be of type number');if(h<0)throw new RangeError('The value "'+h+'" is invalid for option "size"')}function d(h,c,u){return l(h),h<=0?o(h):c!==void 0?typeof u=="string"?o(h).fill(c,u):o(h).fill(c):o(h)}a.alloc=function(h,c,u){return d(h,c,u)};function p(h){return l(h),o(h<0?0:A(h)|0)}a.allocUnsafe=function(h){return p(h)},a.allocUnsafeSlow=function(h){return p(h)};function w(h,c){if((typeof c!="string"||c==="")&&(c="utf8"),!a.isEncoding(c))throw new TypeError("Unknown encoding: "+c);const u=E(h,c)|0;let m=o(u);const T=m.write(h,c);return T!==u&&(m=m.slice(0,T)),m}function y(h){const c=h.length<0?0:A(h.length)|0,u=o(c);for(let m=0;m<c;m+=1)u[m]=h[m]&255;return u}function I(h){if(rt(h,Uint8Array)){const c=new Uint8Array(h);return S(c.buffer,c.byteOffset,c.byteLength)}return y(h)}function S(h,c,u){if(c<0||h.byteLength<c)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<c+(u||0))throw new RangeError('"length" is outside of buffer bounds');let m;return c===void 0&&u===void 0?m=new Uint8Array(h):u===void 0?m=new Uint8Array(h,c):m=new Uint8Array(h,c,u),Object.setPrototypeOf(m,a.prototype),m}function _(h){if(a.isBuffer(h)){const c=A(h.length)|0,u=o(c);return u.length===0||h.copy(u,0,0,c),u}if(h.length!==void 0)return typeof h.length!="number"||_r(h.length)?o(0):y(h);if(h.type==="Buffer"&&Array.isArray(h.data))return y(h.data)}function A(h){if(h>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return h|0}function k(h){return+h!=h&&(h=0),a.alloc(+h)}a.isBuffer=function(c){return c!=null&&c._isBuffer===!0&&c!==a.prototype},a.compare=function(c,u){if(rt(c,Uint8Array)&&(c=a.from(c,c.offset,c.byteLength)),rt(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(c)||!a.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(c===u)return 0;let m=c.length,T=u.length;for(let U=0,H=Math.min(m,T);U<H;++U)if(c[U]!==u[U]){m=c[U],T=u[U];break}return m<T?-1:T<m?1:0},a.isEncoding=function(c){switch(String(c).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(c,u){if(!Array.isArray(c))throw new TypeError('"list" argument must be an Array of Buffers');if(c.length===0)return a.alloc(0);let m;if(u===void 0)for(u=0,m=0;m<c.length;++m)u+=c[m].length;const T=a.allocUnsafe(u);let U=0;for(m=0;m<c.length;++m){let H=c[m];if(rt(H,Uint8Array))U+H.length>T.length?(a.isBuffer(H)||(H=a.from(H)),H.copy(T,U)):Uint8Array.prototype.set.call(T,H,U);else if(a.isBuffer(H))H.copy(T,U);else throw new TypeError('"list" argument must be an Array of Buffers');U+=H.length}return T};function E(h,c){if(a.isBuffer(h))return h.length;if(ArrayBuffer.isView(h)||rt(h,ArrayBuffer))return h.byteLength;if(typeof h!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof h);const u=h.length,m=arguments.length>2&&arguments[2]===!0;if(!m&&u===0)return 0;let T=!1;for(;;)switch(c){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return le(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return wn(h).length;default:if(T)return m?-1:le(h).length;c=(""+c).toLowerCase(),T=!0}}a.byteLength=E;function v(h,c,u){let m=!1;if((c===void 0||c<0)&&(c=0),c>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,c>>>=0,u<=c))return"";for(h||(h="utf8");;)switch(h){case"hex":return se(this,c,u);case"utf8":case"utf-8":return N(this,c,u);case"ascii":return W(this,c,u);case"latin1":case"binary":return J(this,c,u);case"base64":return j(this,c,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return be(this,c,u);default:if(m)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),m=!0}}a.prototype._isBuffer=!0;function B(h,c,u){const m=h[c];h[c]=h[u],h[u]=m}a.prototype.swap16=function(){const c=this.length;if(c%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<c;u+=2)B(this,u,u+1);return this},a.prototype.swap32=function(){const c=this.length;if(c%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<c;u+=4)B(this,u,u+3),B(this,u+1,u+2);return this},a.prototype.swap64=function(){const c=this.length;if(c%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<c;u+=8)B(this,u,u+7),B(this,u+1,u+6),B(this,u+2,u+5),B(this,u+3,u+4);return this},a.prototype.toString=function(){const c=this.length;return c===0?"":arguments.length===0?N(this,0,c):v.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(c){if(!a.isBuffer(c))throw new TypeError("Argument must be a Buffer");return this===c?!0:a.compare(this,c)===0},a.prototype.inspect=function(){let c="";const u=e.INSPECT_MAX_BYTES;return c=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(c+=" ... "),"<Buffer "+c+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(c,u,m,T,U){if(rt(c,Uint8Array)&&(c=a.from(c,c.offset,c.byteLength)),!a.isBuffer(c))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof c);if(u===void 0&&(u=0),m===void 0&&(m=c?c.length:0),T===void 0&&(T=0),U===void 0&&(U=this.length),u<0||m>c.length||T<0||U>this.length)throw new RangeError("out of range index");if(T>=U&&u>=m)return 0;if(T>=U)return-1;if(u>=m)return 1;if(u>>>=0,m>>>=0,T>>>=0,U>>>=0,this===c)return 0;let H=U-T,ie=m-u;const Ie=Math.min(H,ie),Ee=this.slice(T,U),Te=c.slice(u,m);for(let pe=0;pe<Ie;++pe)if(Ee[pe]!==Te[pe]){H=Ee[pe],ie=Te[pe];break}return H<ie?-1:ie<H?1:0};function x(h,c,u,m,T){if(h.length===0)return-1;if(typeof u=="string"?(m=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,_r(u)&&(u=T?0:h.length-1),u<0&&(u=h.length+u),u>=h.length){if(T)return-1;u=h.length-1}else if(u<0)if(T)u=0;else return-1;if(typeof c=="string"&&(c=a.from(c,m)),a.isBuffer(c))return c.length===0?-1:L(h,c,u,m,T);if(typeof c=="number")return c=c&255,typeof Uint8Array.prototype.indexOf=="function"?T?Uint8Array.prototype.indexOf.call(h,c,u):Uint8Array.prototype.lastIndexOf.call(h,c,u):L(h,[c],u,m,T);throw new TypeError("val must be string, number or Buffer")}function L(h,c,u,m,T){let U=1,H=h.length,ie=c.length;if(m!==void 0&&(m=String(m).toLowerCase(),m==="ucs2"||m==="ucs-2"||m==="utf16le"||m==="utf-16le")){if(h.length<2||c.length<2)return-1;U=2,H/=2,ie/=2,u/=2}function Ie(Te,pe){return U===1?Te[pe]:Te.readUInt16BE(pe*U)}let Ee;if(T){let Te=-1;for(Ee=u;Ee<H;Ee++)if(Ie(h,Ee)===Ie(c,Te===-1?0:Ee-Te)){if(Te===-1&&(Te=Ee),Ee-Te+1===ie)return Te*U}else Te!==-1&&(Ee-=Ee-Te),Te=-1}else for(u+ie>H&&(u=H-ie),Ee=u;Ee>=0;Ee--){let Te=!0;for(let pe=0;pe<ie;pe++)if(Ie(h,Ee+pe)!==Ie(c,pe)){Te=!1;break}if(Te)return Ee}return-1}a.prototype.includes=function(c,u,m){return this.indexOf(c,u,m)!==-1},a.prototype.indexOf=function(c,u,m){return x(this,c,u,m,!0)},a.prototype.lastIndexOf=function(c,u,m){return x(this,c,u,m,!1)};function M(h,c,u,m){u=Number(u)||0;const T=h.length-u;m?(m=Number(m),m>T&&(m=T)):m=T;const U=c.length;m>U/2&&(m=U/2);let H;for(H=0;H<m;++H){const ie=parseInt(c.substr(H*2,2),16);if(_r(ie))return H;h[u+H]=ie}return H}function P(h,c,u,m){return $r(le(c,h.length-u),h,u,m)}function G(h,c,u,m){return $r(Zt(c),h,u,m)}function K(h,c,u,m){return $r(wn(c),h,u,m)}function C(h,c,u,m){return $r(Dr(c,h.length-u),h,u,m)}a.prototype.write=function(c,u,m,T){if(u===void 0)T="utf8",m=this.length,u=0;else if(m===void 0&&typeof u=="string")T=u,m=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(m)?(m=m>>>0,T===void 0&&(T="utf8")):(T=m,m=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const U=this.length-u;if((m===void 0||m>U)&&(m=U),c.length>0&&(m<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");T||(T="utf8");let H=!1;for(;;)switch(T){case"hex":return M(this,c,u,m);case"utf8":case"utf-8":return P(this,c,u,m);case"ascii":case"latin1":case"binary":return G(this,c,u,m);case"base64":return K(this,c,u,m);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,c,u,m);default:if(H)throw new TypeError("Unknown encoding: "+T);T=(""+T).toLowerCase(),H=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function j(h,c,u){return c===0&&u===h.length?t.fromByteArray(h):t.fromByteArray(h.slice(c,u))}function N(h,c,u){u=Math.min(h.length,u);const m=[];let T=c;for(;T<u;){const U=h[T];let H=null,ie=U>239?4:U>223?3:U>191?2:1;if(T+ie<=u){let Ie,Ee,Te,pe;switch(ie){case 1:U<128&&(H=U);break;case 2:Ie=h[T+1],(Ie&192)===128&&(pe=(U&31)<<6|Ie&63,pe>127&&(H=pe));break;case 3:Ie=h[T+1],Ee=h[T+2],(Ie&192)===128&&(Ee&192)===128&&(pe=(U&15)<<12|(Ie&63)<<6|Ee&63,pe>2047&&(pe<55296||pe>57343)&&(H=pe));break;case 4:Ie=h[T+1],Ee=h[T+2],Te=h[T+3],(Ie&192)===128&&(Ee&192)===128&&(Te&192)===128&&(pe=(U&15)<<18|(Ie&63)<<12|(Ee&63)<<6|Te&63,pe>65535&&pe<1114112&&(H=pe))}}H===null?(H=65533,ie=1):H>65535&&(H-=65536,m.push(H>>>10&1023|55296),H=56320|H&1023),m.push(H),T+=ie}return z(m)}const $=4096;function z(h){const c=h.length;if(c<=$)return String.fromCharCode.apply(String,h);let u="",m=0;for(;m<c;)u+=String.fromCharCode.apply(String,h.slice(m,m+=$));return u}function W(h,c,u){let m="";u=Math.min(h.length,u);for(let T=c;T<u;++T)m+=String.fromCharCode(h[T]&127);return m}function J(h,c,u){let m="";u=Math.min(h.length,u);for(let T=c;T<u;++T)m+=String.fromCharCode(h[T]);return m}function se(h,c,u){const m=h.length;(!c||c<0)&&(c=0),(!u||u<0||u>m)&&(u=m);let T="";for(let U=c;U<u;++U)T+=_n[h[U]];return T}function be(h,c,u){const m=h.slice(c,u);let T="";for(let U=0;U<m.length-1;U+=2)T+=String.fromCharCode(m[U]+m[U+1]*256);return T}a.prototype.slice=function(c,u){const m=this.length;c=~~c,u=u===void 0?m:~~u,c<0?(c+=m,c<0&&(c=0)):c>m&&(c=m),u<0?(u+=m,u<0&&(u=0)):u>m&&(u=m),u<c&&(u=c);const T=this.subarray(c,u);return Object.setPrototypeOf(T,a.prototype),T};function te(h,c,u){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+c>u)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=this[c],U=1,H=0;for(;++H<u&&(U*=256);)T+=this[c+H]*U;return T},a.prototype.readUintBE=a.prototype.readUIntBE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=this[c+--u],U=1;for(;u>0&&(U*=256);)T+=this[c+--u]*U;return T},a.prototype.readUint8=a.prototype.readUInt8=function(c,u){return c=c>>>0,u||te(c,1,this.length),this[c]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(c,u){return c=c>>>0,u||te(c,2,this.length),this[c]|this[c+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(c,u){return c=c>>>0,u||te(c,2,this.length),this[c]<<8|this[c+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(c,u){return c=c>>>0,u||te(c,4,this.length),(this[c]|this[c+1]<<8|this[c+2]<<16)+this[c+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(c,u){return c=c>>>0,u||te(c,4,this.length),this[c]*16777216+(this[c+1]<<16|this[c+2]<<8|this[c+3])},a.prototype.readBigUInt64LE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=u+this[++c]*2**8+this[++c]*2**16+this[++c]*2**24,U=this[++c]+this[++c]*2**8+this[++c]*2**16+m*2**24;return BigInt(T)+(BigInt(U)<<BigInt(32))}),a.prototype.readBigUInt64BE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=u*2**24+this[++c]*2**16+this[++c]*2**8+this[++c],U=this[++c]*2**24+this[++c]*2**16+this[++c]*2**8+m;return(BigInt(T)<<BigInt(32))+BigInt(U)}),a.prototype.readIntLE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=this[c],U=1,H=0;for(;++H<u&&(U*=256);)T+=this[c+H]*U;return U*=128,T>=U&&(T-=Math.pow(2,8*u)),T},a.prototype.readIntBE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=u,U=1,H=this[c+--T];for(;T>0&&(U*=256);)H+=this[c+--T]*U;return U*=128,H>=U&&(H-=Math.pow(2,8*u)),H},a.prototype.readInt8=function(c,u){return c=c>>>0,u||te(c,1,this.length),this[c]&128?(255-this[c]+1)*-1:this[c]},a.prototype.readInt16LE=function(c,u){c=c>>>0,u||te(c,2,this.length);const m=this[c]|this[c+1]<<8;return m&32768?m|4294901760:m},a.prototype.readInt16BE=function(c,u){c=c>>>0,u||te(c,2,this.length);const m=this[c+1]|this[c]<<8;return m&32768?m|4294901760:m},a.prototype.readInt32LE=function(c,u){return c=c>>>0,u||te(c,4,this.length),this[c]|this[c+1]<<8|this[c+2]<<16|this[c+3]<<24},a.prototype.readInt32BE=function(c,u){return c=c>>>0,u||te(c,4,this.length),this[c]<<24|this[c+1]<<16|this[c+2]<<8|this[c+3]},a.prototype.readBigInt64LE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=this[c+4]+this[c+5]*2**8+this[c+6]*2**16+(m<<24);return(BigInt(T)<<BigInt(32))+BigInt(u+this[++c]*2**8+this[++c]*2**16+this[++c]*2**24)}),a.prototype.readBigInt64BE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=(u<<24)+this[++c]*2**16+this[++c]*2**8+this[++c];return(BigInt(T)<<BigInt(32))+BigInt(this[++c]*2**24+this[++c]*2**16+this[++c]*2**8+m)}),a.prototype.readFloatLE=function(c,u){return c=c>>>0,u||te(c,4,this.length),r.read(this,c,!0,23,4)},a.prototype.readFloatBE=function(c,u){return c=c>>>0,u||te(c,4,this.length),r.read(this,c,!1,23,4)},a.prototype.readDoubleLE=function(c,u){return c=c>>>0,u||te(c,8,this.length),r.read(this,c,!0,52,8)},a.prototype.readDoubleBE=function(c,u){return c=c>>>0,u||te(c,8,this.length),r.read(this,c,!1,52,8)};function fe(h,c,u,m,T,U){if(!a.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(c>T||c<U)throw new RangeError('"value" argument is out of bounds');if(u+m>h.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(c,u,m,T){if(c=+c,u=u>>>0,m=m>>>0,!T){const ie=Math.pow(2,8*m)-1;fe(this,c,u,m,ie,0)}let U=1,H=0;for(this[u]=c&255;++H<m&&(U*=256);)this[u+H]=c/U&255;return u+m},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(c,u,m,T){if(c=+c,u=u>>>0,m=m>>>0,!T){const ie=Math.pow(2,8*m)-1;fe(this,c,u,m,ie,0)}let U=m-1,H=1;for(this[u+U]=c&255;--U>=0&&(H*=256);)this[u+U]=c/H&255;return u+m},a.prototype.writeUint8=a.prototype.writeUInt8=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,1,255,0),this[u]=c&255,u+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,65535,0),this[u]=c&255,this[u+1]=c>>>8,u+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,65535,0),this[u]=c>>>8,this[u+1]=c&255,u+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,4294967295,0),this[u+3]=c>>>24,this[u+2]=c>>>16,this[u+1]=c>>>8,this[u]=c&255,u+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,4294967295,0),this[u]=c>>>24,this[u+1]=c>>>16,this[u+2]=c>>>8,this[u+3]=c&255,u+4};function ge(h,c,u,m,T){g(c,m,T,h,u,7);let U=Number(c&BigInt(4294967295));h[u++]=U,U=U>>8,h[u++]=U,U=U>>8,h[u++]=U,U=U>>8,h[u++]=U;let H=Number(c>>BigInt(32)&BigInt(4294967295));return h[u++]=H,H=H>>8,h[u++]=H,H=H>>8,h[u++]=H,H=H>>8,h[u++]=H,u}function Se(h,c,u,m,T){g(c,m,T,h,u,7);let U=Number(c&BigInt(4294967295));h[u+7]=U,U=U>>8,h[u+6]=U,U=U>>8,h[u+5]=U,U=U>>8,h[u+4]=U;let H=Number(c>>BigInt(32)&BigInt(4294967295));return h[u+3]=H,H=H>>8,h[u+2]=H,H=H>>8,h[u+1]=H,H=H>>8,h[u]=H,u+8}a.prototype.writeBigUInt64LE=ot(function(c,u=0){return ge(this,c,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=ot(function(c,u=0){return Se(this,c,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(c,u,m,T){if(c=+c,u=u>>>0,!T){const Ie=Math.pow(2,8*m-1);fe(this,c,u,m,Ie-1,-Ie)}let U=0,H=1,ie=0;for(this[u]=c&255;++U<m&&(H*=256);)c<0&&ie===0&&this[u+U-1]!==0&&(ie=1),this[u+U]=(c/H>>0)-ie&255;return u+m},a.prototype.writeIntBE=function(c,u,m,T){if(c=+c,u=u>>>0,!T){const Ie=Math.pow(2,8*m-1);fe(this,c,u,m,Ie-1,-Ie)}let U=m-1,H=1,ie=0;for(this[u+U]=c&255;--U>=0&&(H*=256);)c<0&&ie===0&&this[u+U+1]!==0&&(ie=1),this[u+U]=(c/H>>0)-ie&255;return u+m},a.prototype.writeInt8=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,1,127,-128),c<0&&(c=255+c+1),this[u]=c&255,u+1},a.prototype.writeInt16LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,32767,-32768),this[u]=c&255,this[u+1]=c>>>8,u+2},a.prototype.writeInt16BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,32767,-32768),this[u]=c>>>8,this[u+1]=c&255,u+2},a.prototype.writeInt32LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,2147483647,-2147483648),this[u]=c&255,this[u+1]=c>>>8,this[u+2]=c>>>16,this[u+3]=c>>>24,u+4},a.prototype.writeInt32BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,2147483647,-2147483648),c<0&&(c=4294967295+c+1),this[u]=c>>>24,this[u+1]=c>>>16,this[u+2]=c>>>8,this[u+3]=c&255,u+4},a.prototype.writeBigInt64LE=ot(function(c,u=0){return ge(this,c,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=ot(function(c,u=0){return Se(this,c,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function je(h,c,u,m,T,U){if(u+m>h.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function O(h,c,u,m,T){return c=+c,u=u>>>0,T||je(h,c,u,4),r.write(h,c,u,m,23,4),u+4}a.prototype.writeFloatLE=function(c,u,m){return O(this,c,u,!0,m)},a.prototype.writeFloatBE=function(c,u,m){return O(this,c,u,!1,m)};function R(h,c,u,m,T){return c=+c,u=u>>>0,T||je(h,c,u,8),r.write(h,c,u,m,52,8),u+8}a.prototype.writeDoubleLE=function(c,u,m){return R(this,c,u,!0,m)},a.prototype.writeDoubleBE=function(c,u,m){return R(this,c,u,!1,m)},a.prototype.copy=function(c,u,m,T){if(!a.isBuffer(c))throw new TypeError("argument should be a Buffer");if(m||(m=0),!T&&T!==0&&(T=this.length),u>=c.length&&(u=c.length),u||(u=0),T>0&&T<m&&(T=m),T===m||c.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(m<0||m>=this.length)throw new RangeError("Index out of range");if(T<0)throw new RangeError("sourceEnd out of bounds");T>this.length&&(T=this.length),c.length-u<T-m&&(T=c.length-u+m);const U=T-m;return this===c&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(u,m,T):Uint8Array.prototype.set.call(c,this.subarray(m,T),u),U},a.prototype.fill=function(c,u,m,T){if(typeof c=="string"){if(typeof u=="string"?(T=u,u=0,m=this.length):typeof m=="string"&&(T=m,m=this.length),T!==void 0&&typeof T!="string")throw new TypeError("encoding must be a string");if(typeof T=="string"&&!a.isEncoding(T))throw new TypeError("Unknown encoding: "+T);if(c.length===1){const H=c.charCodeAt(0);(T==="utf8"&&H<128||T==="latin1")&&(c=H)}}else typeof c=="number"?c=c&255:typeof c=="boolean"&&(c=Number(c));if(u<0||this.length<u||this.length<m)throw new RangeError("Out of range index");if(m<=u)return this;u=u>>>0,m=m===void 0?this.length:m>>>0,c||(c=0);let U;if(typeof c=="number")for(U=u;U<m;++U)this[U]=c;else{const H=a.isBuffer(c)?c:a.from(c,T),ie=H.length;if(ie===0)throw new TypeError('The value "'+c+'" is invalid for argument "value"');for(U=0;U<m-u;++U)this[U+u]=H[U%ie]}return this};const D={};function Y(h,c,u){D[h]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:c.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(T){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:T,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}Y("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Y("ERR_INVALID_ARG_TYPE",function(h,c){return`The "${h}" argument must be of type number. Received type ${typeof c}`},TypeError),Y("ERR_OUT_OF_RANGE",function(h,c,u){let m=`The value of "${h}" is out of range.`,T=u;return Number.isInteger(u)&&Math.abs(u)>2**32?T=Q(String(u)):typeof u=="bigint"&&(T=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(T=Q(T)),T+="n"),m+=` It must be ${c}. Received ${T}`,m},RangeError);function Q(h){let c="",u=h.length;const m=h[0]==="-"?1:0;for(;u>=m+4;u-=3)c=`_${h.slice(u-3,u)}${c}`;return`${h.slice(0,u)}${c}`}function b(h,c,u){F(c,"offset"),(h[c]===void 0||h[c+u]===void 0)&&q(c,h.length-(u+1))}function g(h,c,u,m,T,U){if(h>u||h<c){const H=typeof c=="bigint"?"n":"";let ie;throw c===0||c===BigInt(0)?ie=`>= 0${H} and < 2${H} ** ${(U+1)*8}${H}`:ie=`>= -(2${H} ** ${(U+1)*8-1}${H}) and < 2 ** ${(U+1)*8-1}${H}`,new D.ERR_OUT_OF_RANGE("value",ie,h)}b(m,T,U)}function F(h,c){if(typeof h!="number")throw new D.ERR_INVALID_ARG_TYPE(c,"number",h)}function q(h,c,u){throw Math.floor(h)!==h?(F(h,u),new D.ERR_OUT_OF_RANGE("offset","an integer",h)):c<0?new D.ERR_BUFFER_OUT_OF_BOUNDS:new D.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${c}`,h)}const ue=/[^+/0-9A-Za-z-_]/g;function re(h){if(h=h.split("=")[0],h=h.trim().replace(ue,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function le(h,c){c=c||1/0;let u;const m=h.length;let T=null;const U=[];for(let H=0;H<m;++H){if(u=h.charCodeAt(H),u>55295&&u<57344){if(!T){if(u>56319){(c-=3)>-1&&U.push(239,191,189);continue}else if(H+1===m){(c-=3)>-1&&U.push(239,191,189);continue}T=u;continue}if(u<56320){(c-=3)>-1&&U.push(239,191,189),T=u;continue}u=(T-55296<<10|u-56320)+65536}else T&&(c-=3)>-1&&U.push(239,191,189);if(T=null,u<128){if((c-=1)<0)break;U.push(u)}else if(u<2048){if((c-=2)<0)break;U.push(u>>6|192,u&63|128)}else if(u<65536){if((c-=3)<0)break;U.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((c-=4)<0)break;U.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return U}function Zt(h){const c=[];for(let u=0;u<h.length;++u)c.push(h.charCodeAt(u)&255);return c}function Dr(h,c){let u,m,T;const U=[];for(let H=0;H<h.length&&!((c-=2)<0);++H)u=h.charCodeAt(H),m=u>>8,T=u%256,U.push(T),U.push(m);return U}function wn(h){return t.toByteArray(re(h))}function $r(h,c,u,m){let T;for(T=0;T<m&&!(T+u>=c.length||T>=h.length);++T)c[T+u]=h[T];return T}function rt(h,c){return h instanceof c||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===c.name}function _r(h){return h!==h}const _n=function(){const h="0123456789abcdef",c=new Array(256);for(let u=0;u<16;++u){const m=u*16;for(let T=0;T<16;++T)c[m+T]=h[u]+h[T]}return c}();function ot(h){return typeof BigInt>"u"?vr:h}function vr(){throw new Error("BigInt not supported")}})(Yt);var zn={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};zn.Null=zn.Nil;for(var fa in zn)zn[fa].toJSON=(function(e){return e}).bind(null,fa);var To=zn,Br=To;function Pc(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function ko(e){return Br.Nil(e)?"":Pc(e.constructor)}function El(e){return Br.Function(e)?"":Br.String(e)?JSON.stringify(e):e&&Br.Object(e)?"":e}function Po(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Ri(e){return Br.Function(e)?e.toJSON?e.toJSON():Pc(e):Br.Array(e)?"Array":e&&Br.Object(e)?"Object":e!==void 0?e:""}function Oc(e,t,r){var n=El(t);return"Expected "+Ri(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Vt(e,t,r){r=r||ko(t),this.message=Oc(e,t,r),Po(this,Vt),this.__type=e,this.__value=t,this.__valueTypeName=r}Vt.prototype=Object.create(Error.prototype);Vt.prototype.constructor=Vt;function xl(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),Oc('property "'+Ri(r)+s+Ri(e),n,i)}function Qr(e,t,r,n,i){e?(i=i||ko(n),this.message=xl(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',Po(this,Vt),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Qr.prototype=Object.create(Error.prototype);Qr.prototype.constructor=Vt;function Sl(e,t){return new Vt(e,{},t)}function Al(e,t,r){return e instanceof Qr?(t=t+"."+e.__property,e=new Qr(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Vt&&(e=new Qr(e.__type,t,r,e.__value,e.__valueTypeName)),Po(e),e}var Rc={TfTypeError:Vt,TfPropertyTypeError:Qr,tfCustomError:Sl,tfSubError:Al,tfJSON:Ri,getValueTypeName:ko},xs,ua;function Bl(){if(ua)return xs;ua=1;var e=To,t=Rc;function r(x){return Buffer.isBuffer(x)}function n(x){return typeof x=="string"&&/^([0-9a-f]{2})+$/i.test(x)}function i(x,L){var M=x.toJSON();function P(G){if(!x(G))return!1;if(G.length===L)return!0;throw t.tfCustomError(M+"(Length: "+L+")",M+"(Length: "+G.length+")")}return P.toJSON=function(){return M},P}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),f=i.bind(null,e.String);function l(x,L,M){M=M||e.Number;function P(G,K){return M(G,K)&&G>x&&G<L}return P.toJSON=function(){return`${M.toJSON()} between [${x}, ${L}]`},P}var d=Math.pow(2,53)-1;function p(x){return typeof x=="number"&&isFinite(x)}function w(x){return x<<24>>24===x}function y(x){return x<<16>>16===x}function I(x){return(x|0)===x}function S(x){return typeof x=="number"&&x>=-d&&x<=d&&Math.floor(x)===x}function _(x){return(x&255)===x}function A(x){return(x&65535)===x}function k(x){return x>>>0===x}function E(x){return typeof x=="number"&&x>=0&&x<=d&&Math.floor(x)===x}var v={ArrayN:s,Buffer:r,BufferN:o,Finite:p,Hex:n,HexN:a,Int8:w,Int16:y,Int32:I,Int53:S,Range:l,StringN:f,UInt8:_,UInt16:A,UInt32:k,UInt53:E};for(var B in v)v[B].toJSON=(function(x){return x}).bind(null,B);return xs=v,xs}var Kn=Rc,Fe=To,Ot=Kn.tfJSON,Cc=Kn.TfTypeError,Uc=Kn.TfPropertyTypeError,vn=Kn.tfSubError,Il=Kn.getValueTypeName,Mt={arrayOf:function(t,r){t=Bt(t),r=r||{};function n(i,s){return!Fe.Array(i)||Fe.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(o,a){try{return Qe(t,o,s)}catch(f){throw vn(f,a)}})}return n.toJSON=function(){var i="["+Ot(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=Bt(t);function r(n,i){return Fe.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+Ot(t)},r},map:function(t,r){t=Bt(t),r&&(r=Bt(r));function n(i,s){if(!Fe.Object(i)||Fe.Nil(i))return!1;for(var o in i){try{r&&Qe(r,o,s)}catch(f){throw vn(f,o,"key")}try{var a=i[o];Qe(t,a,s)}catch(f){throw vn(f,o)}}return!0}return r?n.toJSON=function(){return"{"+Ot(r)+": "+Ot(t)+"}"}:n.toJSON=function(){return"{"+Ot(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Bt(t[n]);function i(s,o){if(!Fe.Object(s)||Fe.Nil(s))return!1;var a;try{for(a in r){var f=r[a],l=s[a];Qe(f,l,o)}}catch(d){throw vn(d,a)}if(o){for(a in s)if(!r[a])throw new Uc(void 0,a)}return!0}return i.toJSON=function(){return Ot(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Bt);function r(n,i){return t.some(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Ot).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Bt);function r(n,i){return t.every(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Ot).join(" & ")},r},quacksLike:function(t){function r(n){return t===Il(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Bt);function r(n,i){return Fe.Nil(n)||Fe.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return Qe(s,n[o],i)}catch(a){throw vn(a,o)}})}return r.toJSON=function(){return"("+t.map(Ot).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Mt.oneOf=Mt.anyOf;function Bt(e){if(Fe.String(e))return e[0]==="?"?Mt.maybe(e.slice(1)):Fe[e]||Mt.quacksLike(e);if(e&&Fe.Object(e)){if(Fe.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Mt.arrayOf(e[0])}return Mt.object(e)}else if(Fe.Function(e))return e;return Mt.value(e)}function Qe(e,t,r,n){if(Fe.Function(e)){if(e(t,r))return!0;throw new Cc(n||e,t)}return Qe(Bt(e),t,r)}for(var ur in Fe)Qe[ur]=Fe[ur];for(ur in Mt)Qe[ur]=Mt[ur];var la=Bl();for(ur in la)Qe[ur]=la[ur];Qe.compile=Bt;Qe.TfTypeError=Cc;Qe.TfPropertyTypeError=Uc;var Lc=Qe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Yt;e.typeforce=Lc;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(d,p){return d.length!==p.length?!1:d.every((w,y)=>w.equals(p[y]))}e.stacksEqual=i;function s(d){if(!t.Buffer.isBuffer(d)||d.length<33)return!1;const p=d[0],w=d.slice(1,33);if(w.compare(r)===0||w.compare(n)>=0)return!1;if((p===2||p===3)&&d.length===33)return!0;const y=d.slice(33);return y.compare(r)===0||y.compare(n)>=0?!1:p===4&&d.length===65}e.isPoint=s;const o=21*1e14;function a(d){return e.typeforce.UInt53(d)&&d<=o}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function f(d){return!d||!("output"in d)||!t.Buffer.isBuffer(d.output)?!1:d.version!==void 0?(d.version&e.TAPLEAF_VERSION_MASK)===d.version:!0}e.isTapleaf=f;function l(d){return(0,e.Array)(d)?d.length!==2?!1:d.every(p=>l(p)):f(d)}e.isTaptree=l,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(Ke);var Yn={},Me={};Object.defineProperty(Me,"__esModule",{value:!0});Me.BufferReader=Me.BufferWriter=Me.cloneBuffer=Me.reverseBuffer=Me.writeUInt64LE=Me.readUInt64LE=Me.varuint=void 0;const Ir=Ke,{typeforce:Nc}=Ir,qn=Sc;Me.varuint=qn;function Hc(e,t){if(typeof e!="number")throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function Fc(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Hc(n+r,9007199254740991),n+r}Me.readUInt64LE=Fc;function Mc(e,t,r){return Hc(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Me.writeUInt64LE=Mc;function Tl(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}Me.reverseBuffer=Tl;function kl(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Me.cloneBuffer=kl;class Oo{static withCapacity(t){return new Oo(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Nc(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=Mc(this.buffer,t,this.offset)}writeVarInt(t){qn.encode(t,this.buffer,this.offset),this.offset+=qn.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}Me.BufferWriter=Oo;class Pl{constructor(t,r=0){this.buffer=t,this.offset=r,Nc(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=Fc(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=qn.decode(this.buffer,this.offset);return this.offset+=qn.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}Me.BufferReader=Pl;var br={},sn={},kt={},gt={};Object.defineProperty(gt,"__esModule",{value:!0});gt.isBytes=$c;gt.number=Ci;gt.bool=Dc;gt.bytes=Ro;gt.hash=jc;gt.exists=zc;gt.output=qc;function Ci(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Dc(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function $c(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Ro(e,...t){if(!$c(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function jc(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ci(e.outputLen),Ci(e.blockLen)}function zc(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function qc(e,t){Ro(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const Ol={number:Ci,bool:Dc,bytes:Ro,hash:jc,exists:zc,output:qc};gt.default=Ol;var Xn={},Vi={};Object.defineProperty(Vi,"__esModule",{value:!0});Vi.crypto=void 0;Vi.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.Hash=e.nextTick=e.byteSwapIfBE=e.byteSwap=e.isLE=e.rotl=e.rotr=e.createView=e.u32=e.u8=void 0,e.isBytes=n,e.byteSwap32=d,e.bytesToHex=w,e.hexToBytes=S,e.asyncLoop=A,e.utf8ToBytes=k,e.toBytes=E,e.concatBytes=v,e.checkOpts=L,e.wrapConstructor=M,e.wrapConstructorWithOpts=P,e.wrapXOFConstructorWithOpts=G,e.randomBytes=K;const t=Vi,r=gt;function n(C){return C instanceof Uint8Array||C!=null&&typeof C=="object"&&C.constructor.name==="Uint8Array"}const i=C=>new Uint8Array(C.buffer,C.byteOffset,C.byteLength);e.u8=i;const s=C=>new Uint32Array(C.buffer,C.byteOffset,Math.floor(C.byteLength/4));e.u32=s;const o=C=>new DataView(C.buffer,C.byteOffset,C.byteLength);e.createView=o;const a=(C,j)=>C<<32-j|C>>>j;e.rotr=a;const f=(C,j)=>C<<j|C>>>32-j>>>0;e.rotl=f,e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;const l=C=>C<<24&4278190080|C<<8&16711680|C>>>8&65280|C>>>24&255;e.byteSwap=l,e.byteSwapIfBE=e.isLE?C=>C:C=>(0,e.byteSwap)(C);function d(C){for(let j=0;j<C.length;j++)C[j]=(0,e.byteSwap)(C[j])}const p=Array.from({length:256},(C,j)=>j.toString(16).padStart(2,"0"));function w(C){(0,r.bytes)(C);let j="";for(let N=0;N<C.length;N++)j+=p[C[N]];return j}const y={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function I(C){if(C>=y._0&&C<=y._9)return C-y._0;if(C>=y._A&&C<=y._F)return C-(y._A-10);if(C>=y._a&&C<=y._f)return C-(y._a-10)}function S(C){if(typeof C!="string")throw new Error("hex string expected, got "+typeof C);const j=C.length,N=j/2;if(j%2)throw new Error("padded hex string expected, got unpadded hex of length "+j);const $=new Uint8Array(N);for(let z=0,W=0;z<N;z++,W+=2){const J=I(C.charCodeAt(W)),se=I(C.charCodeAt(W+1));if(J===void 0||se===void 0){const be=C[W]+C[W+1];throw new Error('hex string expected, got non-hex character "'+be+'" at index '+W)}$[z]=J*16+se}return $}const _=async()=>{};e.nextTick=_;async function A(C,j,N){let $=Date.now();for(let z=0;z<C;z++){N(z);const W=Date.now()-$;W>=0&&W<j||(await(0,e.nextTick)(),$+=W)}}function k(C){if(typeof C!="string")throw new Error(`utf8ToBytes expected string, got ${typeof C}`);return new Uint8Array(new TextEncoder().encode(C))}function E(C){return typeof C=="string"&&(C=k(C)),(0,r.bytes)(C),C}function v(...C){let j=0;for(let $=0;$<C.length;$++){const z=C[$];(0,r.bytes)(z),j+=z.length}const N=new Uint8Array(j);for(let $=0,z=0;$<C.length;$++){const W=C[$];N.set(W,z),z+=W.length}return N}class B{clone(){return this._cloneInto()}}e.Hash=B;const x={}.toString;function L(C,j){if(j!==void 0&&x.call(j)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(C,j)}function M(C){const j=$=>C().update(E($)).digest(),N=C();return j.outputLen=N.outputLen,j.blockLen=N.blockLen,j.create=()=>C(),j}function P(C){const j=($,z)=>C(z).update(E($)).digest(),N=C({});return j.outputLen=N.outputLen,j.blockLen=N.blockLen,j.create=$=>C($),j}function G(C){const j=($,z)=>C(z).update(E($)).digest(),N=C({});return j.outputLen=N.outputLen,j.blockLen=N.blockLen,j.create=$=>C($),j}function K(C=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(C));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(C);throw new Error("crypto.getRandomValues must be defined")}})(Xn);Object.defineProperty(kt,"__esModule",{value:!0});kt.HashMD=kt.Maj=kt.Chi=void 0;const Ss=gt,En=Xn;function Rl(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),f=n?4:0,l=n?0:4;e.setUint32(t+f,o,n),e.setUint32(t+l,a,n)}const Cl=(e,t,r)=>e&t^~e&r;kt.Chi=Cl;const Ul=(e,t,r)=>e&t^e&r^t&r;kt.Maj=Ul;let Ll=class extends En.Hash{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,En.createView)(this.buffer)}update(t){(0,Ss.exists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,En.toBytes)(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const f=(0,En.createView)(t);for(;i<=s-o;o+=i)this.process(f,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Ss.exists)(this),(0,Ss.output)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let p=o;p<i;p++)r[p]=0;Rl(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,En.createView)(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=f/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,d[p],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}};kt.HashMD=Ll;Object.defineProperty(sn,"__esModule",{value:!0});sn.ripemd160=sn.RIPEMD160=void 0;const Nl=kt,Nn=Xn,Hl=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Vc=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Fl=Vc.map(e=>(9*e+5)%16);let Co=[Vc],Uo=[Fl];for(let e=0;e<4;e++)for(let t of[Co,Uo])t.push(t[e].map(r=>Hl[r]));const Gc=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),Ml=Co.map((e,t)=>e.map(r=>Gc[t][r])),Dl=Uo.map((e,t)=>e.map(r=>Gc[t][r])),$l=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),jl=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function da(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const li=new Uint32Array(16);let Wc=class extends Nl.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=s|0}process(t,r){for(let y=0;y<16;y++,r+=4)li[y]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,f=a,l=this.h3|0,d=l,p=this.h4|0,w=p;for(let y=0;y<5;y++){const I=4-y,S=$l[y],_=jl[y],A=Co[y],k=Uo[y],E=Ml[y],v=Dl[y];for(let B=0;B<16;B++){const x=(0,Nn.rotl)(n+da(y,s,a,l)+li[A[B]]+S,E[B])+p|0;n=p,p=l,l=(0,Nn.rotl)(a,10)|0,a=s,s=x}for(let B=0;B<16;B++){const x=(0,Nn.rotl)(i+da(I,o,f,d)+li[k[B]]+_,v[B])+w|0;i=w,w=d,d=(0,Nn.rotl)(f,10)|0,f=o,o=x}}this.set(this.h1+a+d|0,this.h2+l+w|0,this.h3+p+i|0,this.h4+n+o|0,this.h0+s+f|0)}roundClean(){li.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};sn.RIPEMD160=Wc;sn.ripemd160=(0,Nn.wrapConstructor)(()=>new Wc);var on={};Object.defineProperty(on,"__esModule",{value:!0});on.sha1=on.SHA1=void 0;const As=kt,Si=Xn,xn=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Jt=new Uint32Array(80);class Kc extends As.HashMD{constructor(){super(64,20,8,!1),this.A=xn[0]|0,this.B=xn[1]|0,this.C=xn[2]|0,this.D=xn[3]|0,this.E=xn[4]|0}get(){const{A:t,B:r,C:n,D:i,E:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0}process(t,r){for(let f=0;f<16;f++,r+=4)Jt[f]=t.getUint32(r,!1);for(let f=16;f<80;f++)Jt[f]=(0,Si.rotl)(Jt[f-3]^Jt[f-8]^Jt[f-14]^Jt[f-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let f=0;f<80;f++){let l,d;f<20?(l=(0,As.Chi)(i,s,o),d=1518500249):f<40?(l=i^s^o,d=1859775393):f<60?(l=(0,As.Maj)(i,s,o),d=2400959708):(l=i^s^o,d=3395469782);const p=(0,Si.rotl)(n,5)+l+a+d+Jt[f]|0;a=o,o=s,s=(0,Si.rotl)(i,30),i=n,n=p}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,this.set(n,i,s,o,a)}roundClean(){Jt.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}on.SHA1=Kc;on.sha1=(0,Si.wrapConstructor)(()=>new Kc);var zt={};Object.defineProperty(zt,"__esModule",{value:!0});zt.sha224=zt.sha256=zt.SHA256=void 0;const Bs=kt,ft=Xn,zl=new Uint32Array([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]),Qt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),er=new Uint32Array(64);let Lo=class extends Bs.HashMD{constructor(){super(64,32,8,!1),this.A=Qt[0]|0,this.B=Qt[1]|0,this.C=Qt[2]|0,this.D=Qt[3]|0,this.E=Qt[4]|0,this.F=Qt[5]|0,this.G=Qt[6]|0,this.H=Qt[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:f}=this;return[t,r,n,i,s,o,a,f]}set(t,r,n,i,s,o,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=f|0}process(t,r){for(let p=0;p<16;p++,r+=4)er[p]=t.getUint32(r,!1);for(let p=16;p<64;p++){const w=er[p-15],y=er[p-2],I=(0,ft.rotr)(w,7)^(0,ft.rotr)(w,18)^w>>>3,S=(0,ft.rotr)(y,17)^(0,ft.rotr)(y,19)^y>>>10;er[p]=S+er[p-7]+I+er[p-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:f,G:l,H:d}=this;for(let p=0;p<64;p++){const w=(0,ft.rotr)(a,6)^(0,ft.rotr)(a,11)^(0,ft.rotr)(a,25),y=d+w+(0,Bs.Chi)(a,f,l)+zl[p]+er[p]|0,S=((0,ft.rotr)(n,2)^(0,ft.rotr)(n,13)^(0,ft.rotr)(n,22))+(0,Bs.Maj)(n,i,s)|0;d=l,l=f,f=a,a=o+y|0,o=s,s=i,i=n,n=y+S|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,f,l,d)}roundClean(){er.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};zt.SHA256=Lo;class ql extends Lo{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}zt.sha256=(0,ft.wrapConstructor)(()=>new Lo);zt.sha224=(0,ft.wrapConstructor)(()=>new ql);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=sn,r=on,n=zt;function i(d){return Buffer.from((0,t.ripemd160)(Uint8Array.from(d)))}e.ripemd160=i;function s(d){return Buffer.from((0,r.sha1)(Uint8Array.from(d)))}e.sha1=s;function o(d){return Buffer.from((0,n.sha256)(Uint8Array.from(d)))}e.sha256=o;function a(d){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(d))))}e.hash160=a;function f(d){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(d))))}e.hash256=f,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Buffer.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Buffer.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Buffer.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Buffer.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Buffer.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Buffer.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Buffer.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Buffer.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function l(d,p){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[d],p]))}e.taggedHash=l})(br);var Is={},qt={};Object.defineProperty(qt,"__esModule",{value:!0});qt.encode=qt.decode=qt.check=void 0;function Vl(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const r=e[5+t];return!(r===0||6+t+r!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||r>1&&e[t+6]===0&&!(e[t+7]&128))}qt.check=Vl;function Gl(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const r=e[5+t];if(r===0)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(r>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}qt.decode=Gl;function Wl(e,t){const r=e.length,n=t.length;if(r===0)throw new Error("R length is zero");if(n===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(r>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(n>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=Buffer.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+r]=2,i[5+r]=t.length,t.copy(i,6+r),i}qt.encode=Wl;var Or={};Object.defineProperty(Or,"__esModule",{value:!0});Or.REVERSE_OPS=Or.OPS=void 0;const oo={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Or.OPS=oo;const Yc={};Or.REVERSE_OPS=Yc;for(const e of Object.keys(oo)){const t=oo[e];Yc[t]=e}var lr={};Object.defineProperty(lr,"__esModule",{value:!0});lr.decode=lr.encode=lr.encodingLength=void 0;const fr=Or;function Xc(e){return e<fr.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}lr.encodingLength=Xc;function Kl(e,t,r){const n=Xc(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(fr.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(fr.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(fr.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}lr.encode=Kl;function Yl(e,t){const r=e.readUInt8(t);let n,i;if(r<fr.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===fr.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===fr.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==fr.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}lr.decode=Yl;var an={};Object.defineProperty(an,"__esModule",{value:!0});an.encode=an.decode=void 0;function Xl(e,t,r){t=t||4,r=r===void 0?!0:r;const n=e.length;if(n===0)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(e[n-1]&127)&&(n<=1||!(e[n-2]&128)))throw new Error("Non-minimally encoded script number");if(n===5){const s=e.readUInt32LE(0),o=e.readUInt8(4);return o&128?-((o&-129)*4294967296+s):o*4294967296+s}let i=0;for(let s=0;s<n;++s)i|=e[s]<<8*s;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}an.decode=Xl;function Zl(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function Jl(e){let t=Math.abs(e);const r=Zl(t),n=Buffer.allocUnsafe(r),i=e<0;for(let s=0;s<r;++s)n.writeUInt8(t&255,s),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}an.encode=Jl;var Sr={},ha;function Ql(){if(ha)return Sr;ha=1,Object.defineProperty(Sr,"__esModule",{value:!0}),Sr.encode=Sr.decode=void 0;const e=qt,t=st(),r=Ke,{typeforce:n}=r,i=Buffer.alloc(1,0);function s(l){let d=0;for(;l[d]===0;)++d;return d===l.length?i:(l=l.slice(d),l[0]&128?Buffer.concat([i,l],1+l.length):l)}function o(l){l[0]===0&&(l=l.slice(1));const d=Buffer.alloc(32,0),p=Math.max(0,32-l.length);return l.copy(d,p),d}function a(l){const d=l.readUInt8(l.length-1);if(!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const p=e.decode(l.slice(0,-1)),w=o(p.r),y=o(p.s);return{signature:Buffer.concat([w,y],64),hashType:d}}Sr.decode=a;function f(l,d){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:l,hashType:d}),!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const p=Buffer.allocUnsafe(1);p.writeUInt8(d,0);const w=s(l.slice(0,32)),y=s(l.slice(32,64));return Buffer.concat([e.encode(w,y),p])}return Sr.encode=f,Sr}var pa;function st(){return pa||(pa=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=qt,r=Or;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=lr,i=an,s=Ql(),o=Ke,{typeforce:a}=o,f=r.OPS.OP_RESERVED;function l(P){return o.Number(P)&&(P===r.OPS.OP_0||P>=r.OPS.OP_1&&P<=r.OPS.OP_16||P===r.OPS.OP_1NEGATE)}function d(P){return o.Buffer(P)||l(P)}function p(P){return o.Array(P)&&P.every(d)}e.isPushOnly=p;function w(P){return P.length-P.filter(d).length}e.countNonPushOnlyOPs=w;function y(P){if(P.length===0)return r.OPS.OP_0;if(P.length===1){if(P[0]>=1&&P[0]<=16)return f+P[0];if(P[0]===129)return r.OPS.OP_1NEGATE}}function I(P){return Buffer.isBuffer(P)}function S(P){return o.Array(P)}function _(P){return Buffer.isBuffer(P)}function A(P){if(I(P))return P;a(o.Array,P);const G=P.reduce((j,N)=>_(N)?N.length===1&&y(N)!==void 0?j+1:j+n.encodingLength(N.length)+N.length:j+1,0),K=Buffer.allocUnsafe(G);let C=0;if(P.forEach(j=>{if(_(j)){const N=y(j);if(N!==void 0){K.writeUInt8(N,C),C+=1;return}C+=n.encode(K,j.length,C),j.copy(K,C),C+=j.length}else K.writeUInt8(j,C),C+=1}),C!==K.length)throw new Error("Could not decode chunks");return K}e.compile=A;function k(P){if(S(P))return P;a(o.Buffer,P);const G=[];let K=0;for(;K<P.length;){const C=P[K];if(C>r.OPS.OP_0&&C<=r.OPS.OP_PUSHDATA4){const j=n.decode(P,K);if(j===null||(K+=j.size,K+j.number>P.length))return null;const N=P.slice(K,K+j.number);K+=j.number;const $=y(N);$!==void 0?G.push($):G.push(N)}else G.push(C),K+=1}return G}e.decompile=k;function E(P){if(I(P)&&(P=k(P)),!P)throw new Error("Could not convert invalid chunks to ASM");return P.map(G=>{if(_(G)){const K=y(G);if(K===void 0)return G.toString("hex");G=K}return r.REVERSE_OPS[G]}).join(" ")}e.toASM=E;function v(P){return a(o.String,P),A(P.split(" ").map(G=>r.OPS[G]!==void 0?r.OPS[G]:(a(o.Hex,G),Buffer.from(G,"hex"))))}e.fromASM=v;function B(P){return P=k(P),a(p,P),P.map(G=>_(G)?G:G===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(G-f))}e.toStack=B;function x(P){return o.isPoint(P)}e.isCanonicalPubKey=x;function L(P){const G=P&-129;return G>0&&G<4}e.isDefinedHashType=L;function M(P){return!Buffer.isBuffer(P)||!L(P[P.length-1])?!1:t.check(P.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s}(Is)),Is}Object.defineProperty(Yn,"__esModule",{value:!0});Yn.Transaction=void 0;const Oe=Me,Ye=br,ya=st(),ed=st(),ae=Ke,{typeforce:_t}=ae;function St(e){const t=e.length;return Oe.varuint.encodingLength(t)+t}function td(e){const t=e.length;return Oe.varuint.encodingLength(t)+e.reduce((r,n)=>r+St(n),0)}const or=Buffer.allocUnsafe(0),ma=[],Ts=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),ba=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),rd=Buffer.from("ffffffffffffffff","hex"),nd={script:or,valueBuffer:rd};function id(e){return e.value!==void 0}class ne{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Oe.BufferReader(t),i=new ne;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===ne.ADVANCED_TRANSACTION_MARKER&&o===ne.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const f=n.readVarInt();for(let d=0;d<f;++d)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:ma});const l=n.readVarInt();for(let d=0;d<l;++d)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let d=0;d<f;++d)i.ins[d].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return ne.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){_t(ae.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&ne.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return _t(ae.tuple(ae.Hash256bit,ae.UInt32,ae.maybe(ae.UInt32),ae.maybe(ae.Buffer)),arguments),ae.Null(n)&&(n=ne.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||or,sequence:n,witness:ma})-1}addOutput(t,r){return _t(ae.tuple(ae.Buffer,ae.Satoshi),arguments),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),r=this.byteLength(!0);return t*3+r}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const r=t&&this.hasWitnesses();return(r?10:8)+Oe.varuint.encodingLength(this.ins.length)+Oe.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+St(i.script),0)+this.outs.reduce((n,i)=>n+8+St(i.script),0)+(r?this.ins.reduce((n,i)=>n+td(i.witness),0):0)}clone(){const t=new ne;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(_t(ae.tuple(ae.UInt32,ae.Buffer,ae.Number),arguments),t>=this.ins.length)return ba;const i=ya.compile(ya.decompile(r).filter(a=>a!==ed.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===ne.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,f)=>{f!==t&&(a.sequence=0)});else if((n&31)===ne.SIGHASH_SINGLE){if(t>=this.outs.length)return ba;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=nd;s.ins.forEach((a,f)=>{f!==t&&(a.sequence=0)})}n&ne.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=or}),s.ins[t].script=i);const o=Buffer.allocUnsafe(s.byteLength(!1)+4);return o.writeInt32LE(n,o.length-4),s.__toBuffer(o,0,!1),Ye.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(_t(ae.tuple(ae.UInt32,_t.arrayOf(ae.Buffer),_t.arrayOf(ae.Satoshi),ae.UInt32),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const a=i===ne.SIGHASH_DEFAULT?ne.SIGHASH_ALL:i&ne.SIGHASH_OUTPUT_MASK,l=(i&ne.SIGHASH_INPUT_MASK)===ne.SIGHASH_ANYONECANPAY,d=a===ne.SIGHASH_NONE,p=a===ne.SIGHASH_SINGLE;let w=or,y=or,I=or,S=or,_=or;if(!l){let v=Oe.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(B=>{v.writeSlice(B.hash),v.writeUInt32(B.index)}),w=Ye.sha256(v.end()),v=Oe.BufferWriter.withCapacity(8*this.ins.length),n.forEach(B=>v.writeUInt64(B)),y=Ye.sha256(v.end()),v=Oe.BufferWriter.withCapacity(r.map(St).reduce((B,x)=>B+x)),r.forEach(B=>v.writeVarSlice(B)),I=Ye.sha256(v.end()),v=Oe.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(B=>v.writeUInt32(B.sequence)),S=Ye.sha256(v.end())}if(d||p){if(p&&t<this.outs.length){const v=this.outs[t],B=Oe.BufferWriter.withCapacity(8+St(v.script));B.writeUInt64(v.value),B.writeVarSlice(v.script),_=Ye.sha256(B.end())}}else{const v=this.outs.map(x=>8+St(x.script)).reduce((x,L)=>x+L),B=Oe.BufferWriter.withCapacity(v);this.outs.forEach(x=>{B.writeUInt64(x.value),B.writeVarSlice(x.script)}),_=Ye.sha256(B.end())}const A=(s?2:0)+(o?1:0),k=174-(l?49:0)-(d?32:0)+(o?32:0)+(s?37:0),E=Oe.BufferWriter.withCapacity(k);if(E.writeUInt8(i),E.writeInt32(this.version),E.writeUInt32(this.locktime),E.writeSlice(w),E.writeSlice(y),E.writeSlice(I),E.writeSlice(S),d||p||E.writeSlice(_),E.writeUInt8(A),l){const v=this.ins[t];E.writeSlice(v.hash),E.writeUInt32(v.index),E.writeUInt64(n[t]),E.writeVarSlice(r[t]),E.writeUInt32(v.sequence)}else E.writeUInt32(t);if(o){const v=Oe.BufferWriter.withCapacity(St(o));v.writeVarSlice(o),E.writeSlice(Ye.sha256(v.end()))}return p&&E.writeSlice(_),s&&(E.writeSlice(s),E.writeUInt8(0),E.writeUInt32(4294967295)),Ye.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),E.end()]))}hashForWitnessV0(t,r,n,i){_t(ae.tuple(ae.UInt32,ae.Buffer,ae.Satoshi,ae.UInt32),arguments);let s=Buffer.from([]),o,a=Ts,f=Ts,l=Ts;if(i&ne.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Oe.BufferWriter(s,0),this.ins.forEach(p=>{o.writeSlice(p.hash),o.writeUInt32(p.index)}),f=Ye.hash256(s)),!(i&ne.SIGHASH_ANYONECANPAY)&&(i&31)!==ne.SIGHASH_SINGLE&&(i&31)!==ne.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Oe.BufferWriter(s,0),this.ins.forEach(p=>{o.writeUInt32(p.sequence)}),l=Ye.hash256(s)),(i&31)!==ne.SIGHASH_SINGLE&&(i&31)!==ne.SIGHASH_NONE){const p=this.outs.reduce((w,y)=>w+8+St(y.script),0);s=Buffer.allocUnsafe(p),o=new Oe.BufferWriter(s,0),this.outs.forEach(w=>{o.writeUInt64(w.value),o.writeVarSlice(w.script)}),a=Ye.hash256(s)}else if((i&31)===ne.SIGHASH_SINGLE&&t<this.outs.length){const p=this.outs[t];s=Buffer.allocUnsafe(8+St(p.script)),o=new Oe.BufferWriter(s,0),o.writeUInt64(p.value),o.writeVarSlice(p.script),a=Ye.hash256(s)}s=Buffer.allocUnsafe(156+St(r)),o=new Oe.BufferWriter(s,0);const d=this.ins[t];return o.writeInt32(this.version),o.writeSlice(f),o.writeSlice(l),o.writeSlice(d.hash),o.writeUInt32(d.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(d.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Ye.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):Ye.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Oe.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(t,r){_t(ae.tuple(ae.Number,ae.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){_t(ae.tuple(ae.Number,[ae.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Oe.BufferWriter(t,r||0);i.writeInt32(this.version);const s=n&&this.hasWitnesses();return s&&(i.writeUInt8(ne.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(ne.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(o=>{i.writeSlice(o.hash),i.writeUInt32(o.index),i.writeVarSlice(o.script),i.writeUInt32(o.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(o=>{id(o)?i.writeUInt64(o.value):i.writeSlice(o.valueBuffer),i.writeVarSlice(o.script)}),s&&this.ins.forEach(o=>{i.writeVector(o.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}Yn.Transaction=ne;ne.DEFAULT_SEQUENCE=4294967295;ne.SIGHASH_DEFAULT=0;ne.SIGHASH_ALL=1;ne.SIGHASH_NONE=2;ne.SIGHASH_SINGLE=3;ne.SIGHASH_ANYONECANPAY=128;ne.SIGHASH_OUTPUT_MASK=3;ne.SIGHASH_INPUT_MASK=128;ne.ADVANCED_TRANSACTION_MARKER=0;ne.ADVANCED_TRANSACTION_FLAG=1;var ye={},Zn={};Object.defineProperty(Zn,"__esModule",{value:!0});const sd=9007199254740991;function No(e){if(e<0||e>sd||e%1!==0)throw new RangeError("value out of range")}function Hn(e,t,r){if(No(e),t||(t=Buffer.allocUnsafe(Zc(e))),!Buffer.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Object.assign(Hn,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(Hn,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(Hn,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(Hn,{bytes:9})),t}Zn.encode=Hn;function Fn(e,t){if(!Buffer.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);const r=e.readUInt8(t);if(r<253)return Object.assign(Fn,{bytes:1}),r;if(r===253)return Object.assign(Fn,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(Fn,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(Fn,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return No(s),s}}Zn.decode=Fn;function Zc(e){return No(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Zn.encodingLength=Zc;var ks={},Gi={},We={};Object.defineProperty(We,"__esModule",{value:!0});We.testnet=We.regtest=We.bitcoin=void 0;We.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
6
|
+
*/(function(e){const t=qi,r=Io,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=k,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=s(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const h=new Uint8Array(1),c={foo:function(){return 42}};return Object.setPrototypeOf(c,Uint8Array.prototype),Object.setPrototypeOf(h,c),h.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function o(h){if(h>i)throw new RangeError('The value "'+h+'" is invalid for option "size"');const c=new Uint8Array(h);return Object.setPrototypeOf(c,a.prototype),c}function a(h,c,u){if(typeof h=="number"){if(typeof c=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return p(h)}return f(h,c,u)}a.poolSize=8192;function f(h,c,u){if(typeof h=="string")return w(h,c);if(ArrayBuffer.isView(h))return I(h);if(h==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h);if(nt(h,ArrayBuffer)||h&&nt(h.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(nt(h,SharedArrayBuffer)||h&&nt(h.buffer,SharedArrayBuffer)))return S(h,c,u);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const m=h.valueOf&&h.valueOf();if(m!=null&&m!==h)return a.from(m,c,u);const T=_(h);if(T)return T;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return a.from(h[Symbol.toPrimitive]("string"),c,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h)}a.from=function(h,c,u){return f(h,c,u)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function l(h){if(typeof h!="number")throw new TypeError('"size" argument must be of type number');if(h<0)throw new RangeError('The value "'+h+'" is invalid for option "size"')}function d(h,c,u){return l(h),h<=0?o(h):c!==void 0?typeof u=="string"?o(h).fill(c,u):o(h).fill(c):o(h)}a.alloc=function(h,c,u){return d(h,c,u)};function p(h){return l(h),o(h<0?0:A(h)|0)}a.allocUnsafe=function(h){return p(h)},a.allocUnsafeSlow=function(h){return p(h)};function w(h,c){if((typeof c!="string"||c==="")&&(c="utf8"),!a.isEncoding(c))throw new TypeError("Unknown encoding: "+c);const u=E(h,c)|0;let m=o(u);const T=m.write(h,c);return T!==u&&(m=m.slice(0,T)),m}function y(h){const c=h.length<0?0:A(h.length)|0,u=o(c);for(let m=0;m<c;m+=1)u[m]=h[m]&255;return u}function I(h){if(nt(h,Uint8Array)){const c=new Uint8Array(h);return S(c.buffer,c.byteOffset,c.byteLength)}return y(h)}function S(h,c,u){if(c<0||h.byteLength<c)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<c+(u||0))throw new RangeError('"length" is outside of buffer bounds');let m;return c===void 0&&u===void 0?m=new Uint8Array(h):u===void 0?m=new Uint8Array(h,c):m=new Uint8Array(h,c,u),Object.setPrototypeOf(m,a.prototype),m}function _(h){if(a.isBuffer(h)){const c=A(h.length)|0,u=o(c);return u.length===0||h.copy(u,0,0,c),u}if(h.length!==void 0)return typeof h.length!="number"||_r(h.length)?o(0):y(h);if(h.type==="Buffer"&&Array.isArray(h.data))return y(h.data)}function A(h){if(h>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return h|0}function k(h){return+h!=h&&(h=0),a.alloc(+h)}a.isBuffer=function(c){return c!=null&&c._isBuffer===!0&&c!==a.prototype},a.compare=function(c,u){if(nt(c,Uint8Array)&&(c=a.from(c,c.offset,c.byteLength)),nt(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(c)||!a.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(c===u)return 0;let m=c.length,T=u.length;for(let U=0,H=Math.min(m,T);U<H;++U)if(c[U]!==u[U]){m=c[U],T=u[U];break}return m<T?-1:T<m?1:0},a.isEncoding=function(c){switch(String(c).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(c,u){if(!Array.isArray(c))throw new TypeError('"list" argument must be an Array of Buffers');if(c.length===0)return a.alloc(0);let m;if(u===void 0)for(u=0,m=0;m<c.length;++m)u+=c[m].length;const T=a.allocUnsafe(u);let U=0;for(m=0;m<c.length;++m){let H=c[m];if(nt(H,Uint8Array))U+H.length>T.length?(a.isBuffer(H)||(H=a.from(H)),H.copy(T,U)):Uint8Array.prototype.set.call(T,H,U);else if(a.isBuffer(H))H.copy(T,U);else throw new TypeError('"list" argument must be an Array of Buffers');U+=H.length}return T};function E(h,c){if(a.isBuffer(h))return h.length;if(ArrayBuffer.isView(h)||nt(h,ArrayBuffer))return h.byteLength;if(typeof h!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof h);const u=h.length,m=arguments.length>2&&arguments[2]===!0;if(!m&&u===0)return 0;let T=!1;for(;;)switch(c){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return le(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return wn(h).length;default:if(T)return m?-1:le(h).length;c=(""+c).toLowerCase(),T=!0}}a.byteLength=E;function v(h,c,u){let m=!1;if((c===void 0||c<0)&&(c=0),c>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,c>>>=0,u<=c))return"";for(h||(h="utf8");;)switch(h){case"hex":return se(this,c,u);case"utf8":case"utf-8":return N(this,c,u);case"ascii":return W(this,c,u);case"latin1":case"binary":return J(this,c,u);case"base64":return j(this,c,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return be(this,c,u);default:if(m)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),m=!0}}a.prototype._isBuffer=!0;function B(h,c,u){const m=h[c];h[c]=h[u],h[u]=m}a.prototype.swap16=function(){const c=this.length;if(c%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<c;u+=2)B(this,u,u+1);return this},a.prototype.swap32=function(){const c=this.length;if(c%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<c;u+=4)B(this,u,u+3),B(this,u+1,u+2);return this},a.prototype.swap64=function(){const c=this.length;if(c%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<c;u+=8)B(this,u,u+7),B(this,u+1,u+6),B(this,u+2,u+5),B(this,u+3,u+4);return this},a.prototype.toString=function(){const c=this.length;return c===0?"":arguments.length===0?N(this,0,c):v.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(c){if(!a.isBuffer(c))throw new TypeError("Argument must be a Buffer");return this===c?!0:a.compare(this,c)===0},a.prototype.inspect=function(){let c="";const u=e.INSPECT_MAX_BYTES;return c=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(c+=" ... "),"<Buffer "+c+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(c,u,m,T,U){if(nt(c,Uint8Array)&&(c=a.from(c,c.offset,c.byteLength)),!a.isBuffer(c))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof c);if(u===void 0&&(u=0),m===void 0&&(m=c?c.length:0),T===void 0&&(T=0),U===void 0&&(U=this.length),u<0||m>c.length||T<0||U>this.length)throw new RangeError("out of range index");if(T>=U&&u>=m)return 0;if(T>=U)return-1;if(u>=m)return 1;if(u>>>=0,m>>>=0,T>>>=0,U>>>=0,this===c)return 0;let H=U-T,ie=m-u;const Ie=Math.min(H,ie),Ee=this.slice(T,U),Te=c.slice(u,m);for(let pe=0;pe<Ie;++pe)if(Ee[pe]!==Te[pe]){H=Ee[pe],ie=Te[pe];break}return H<ie?-1:ie<H?1:0};function x(h,c,u,m,T){if(h.length===0)return-1;if(typeof u=="string"?(m=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,_r(u)&&(u=T?0:h.length-1),u<0&&(u=h.length+u),u>=h.length){if(T)return-1;u=h.length-1}else if(u<0)if(T)u=0;else return-1;if(typeof c=="string"&&(c=a.from(c,m)),a.isBuffer(c))return c.length===0?-1:L(h,c,u,m,T);if(typeof c=="number")return c=c&255,typeof Uint8Array.prototype.indexOf=="function"?T?Uint8Array.prototype.indexOf.call(h,c,u):Uint8Array.prototype.lastIndexOf.call(h,c,u):L(h,[c],u,m,T);throw new TypeError("val must be string, number or Buffer")}function L(h,c,u,m,T){let U=1,H=h.length,ie=c.length;if(m!==void 0&&(m=String(m).toLowerCase(),m==="ucs2"||m==="ucs-2"||m==="utf16le"||m==="utf-16le")){if(h.length<2||c.length<2)return-1;U=2,H/=2,ie/=2,u/=2}function Ie(Te,pe){return U===1?Te[pe]:Te.readUInt16BE(pe*U)}let Ee;if(T){let Te=-1;for(Ee=u;Ee<H;Ee++)if(Ie(h,Ee)===Ie(c,Te===-1?0:Ee-Te)){if(Te===-1&&(Te=Ee),Ee-Te+1===ie)return Te*U}else Te!==-1&&(Ee-=Ee-Te),Te=-1}else for(u+ie>H&&(u=H-ie),Ee=u;Ee>=0;Ee--){let Te=!0;for(let pe=0;pe<ie;pe++)if(Ie(h,Ee+pe)!==Ie(c,pe)){Te=!1;break}if(Te)return Ee}return-1}a.prototype.includes=function(c,u,m){return this.indexOf(c,u,m)!==-1},a.prototype.indexOf=function(c,u,m){return x(this,c,u,m,!0)},a.prototype.lastIndexOf=function(c,u,m){return x(this,c,u,m,!1)};function M(h,c,u,m){u=Number(u)||0;const T=h.length-u;m?(m=Number(m),m>T&&(m=T)):m=T;const U=c.length;m>U/2&&(m=U/2);let H;for(H=0;H<m;++H){const ie=parseInt(c.substr(H*2,2),16);if(_r(ie))return H;h[u+H]=ie}return H}function P(h,c,u,m){return $r(le(c,h.length-u),h,u,m)}function G(h,c,u,m){return $r(Zt(c),h,u,m)}function K(h,c,u,m){return $r(wn(c),h,u,m)}function C(h,c,u,m){return $r(Dr(c,h.length-u),h,u,m)}a.prototype.write=function(c,u,m,T){if(u===void 0)T="utf8",m=this.length,u=0;else if(m===void 0&&typeof u=="string")T=u,m=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(m)?(m=m>>>0,T===void 0&&(T="utf8")):(T=m,m=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const U=this.length-u;if((m===void 0||m>U)&&(m=U),c.length>0&&(m<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");T||(T="utf8");let H=!1;for(;;)switch(T){case"hex":return M(this,c,u,m);case"utf8":case"utf-8":return P(this,c,u,m);case"ascii":case"latin1":case"binary":return G(this,c,u,m);case"base64":return K(this,c,u,m);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,c,u,m);default:if(H)throw new TypeError("Unknown encoding: "+T);T=(""+T).toLowerCase(),H=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function j(h,c,u){return c===0&&u===h.length?t.fromByteArray(h):t.fromByteArray(h.slice(c,u))}function N(h,c,u){u=Math.min(h.length,u);const m=[];let T=c;for(;T<u;){const U=h[T];let H=null,ie=U>239?4:U>223?3:U>191?2:1;if(T+ie<=u){let Ie,Ee,Te,pe;switch(ie){case 1:U<128&&(H=U);break;case 2:Ie=h[T+1],(Ie&192)===128&&(pe=(U&31)<<6|Ie&63,pe>127&&(H=pe));break;case 3:Ie=h[T+1],Ee=h[T+2],(Ie&192)===128&&(Ee&192)===128&&(pe=(U&15)<<12|(Ie&63)<<6|Ee&63,pe>2047&&(pe<55296||pe>57343)&&(H=pe));break;case 4:Ie=h[T+1],Ee=h[T+2],Te=h[T+3],(Ie&192)===128&&(Ee&192)===128&&(Te&192)===128&&(pe=(U&15)<<18|(Ie&63)<<12|(Ee&63)<<6|Te&63,pe>65535&&pe<1114112&&(H=pe))}}H===null?(H=65533,ie=1):H>65535&&(H-=65536,m.push(H>>>10&1023|55296),H=56320|H&1023),m.push(H),T+=ie}return z(m)}const $=4096;function z(h){const c=h.length;if(c<=$)return String.fromCharCode.apply(String,h);let u="",m=0;for(;m<c;)u+=String.fromCharCode.apply(String,h.slice(m,m+=$));return u}function W(h,c,u){let m="";u=Math.min(h.length,u);for(let T=c;T<u;++T)m+=String.fromCharCode(h[T]&127);return m}function J(h,c,u){let m="";u=Math.min(h.length,u);for(let T=c;T<u;++T)m+=String.fromCharCode(h[T]);return m}function se(h,c,u){const m=h.length;(!c||c<0)&&(c=0),(!u||u<0||u>m)&&(u=m);let T="";for(let U=c;U<u;++U)T+=_n[h[U]];return T}function be(h,c,u){const m=h.slice(c,u);let T="";for(let U=0;U<m.length-1;U+=2)T+=String.fromCharCode(m[U]+m[U+1]*256);return T}a.prototype.slice=function(c,u){const m=this.length;c=~~c,u=u===void 0?m:~~u,c<0?(c+=m,c<0&&(c=0)):c>m&&(c=m),u<0?(u+=m,u<0&&(u=0)):u>m&&(u=m),u<c&&(u=c);const T=this.subarray(c,u);return Object.setPrototypeOf(T,a.prototype),T};function te(h,c,u){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+c>u)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=this[c],U=1,H=0;for(;++H<u&&(U*=256);)T+=this[c+H]*U;return T},a.prototype.readUintBE=a.prototype.readUIntBE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=this[c+--u],U=1;for(;u>0&&(U*=256);)T+=this[c+--u]*U;return T},a.prototype.readUint8=a.prototype.readUInt8=function(c,u){return c=c>>>0,u||te(c,1,this.length),this[c]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(c,u){return c=c>>>0,u||te(c,2,this.length),this[c]|this[c+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(c,u){return c=c>>>0,u||te(c,2,this.length),this[c]<<8|this[c+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(c,u){return c=c>>>0,u||te(c,4,this.length),(this[c]|this[c+1]<<8|this[c+2]<<16)+this[c+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(c,u){return c=c>>>0,u||te(c,4,this.length),this[c]*16777216+(this[c+1]<<16|this[c+2]<<8|this[c+3])},a.prototype.readBigUInt64LE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=u+this[++c]*2**8+this[++c]*2**16+this[++c]*2**24,U=this[++c]+this[++c]*2**8+this[++c]*2**16+m*2**24;return BigInt(T)+(BigInt(U)<<BigInt(32))}),a.prototype.readBigUInt64BE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=u*2**24+this[++c]*2**16+this[++c]*2**8+this[++c],U=this[++c]*2**24+this[++c]*2**16+this[++c]*2**8+m;return(BigInt(T)<<BigInt(32))+BigInt(U)}),a.prototype.readIntLE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=this[c],U=1,H=0;for(;++H<u&&(U*=256);)T+=this[c+H]*U;return U*=128,T>=U&&(T-=Math.pow(2,8*u)),T},a.prototype.readIntBE=function(c,u,m){c=c>>>0,u=u>>>0,m||te(c,u,this.length);let T=u,U=1,H=this[c+--T];for(;T>0&&(U*=256);)H+=this[c+--T]*U;return U*=128,H>=U&&(H-=Math.pow(2,8*u)),H},a.prototype.readInt8=function(c,u){return c=c>>>0,u||te(c,1,this.length),this[c]&128?(255-this[c]+1)*-1:this[c]},a.prototype.readInt16LE=function(c,u){c=c>>>0,u||te(c,2,this.length);const m=this[c]|this[c+1]<<8;return m&32768?m|4294901760:m},a.prototype.readInt16BE=function(c,u){c=c>>>0,u||te(c,2,this.length);const m=this[c+1]|this[c]<<8;return m&32768?m|4294901760:m},a.prototype.readInt32LE=function(c,u){return c=c>>>0,u||te(c,4,this.length),this[c]|this[c+1]<<8|this[c+2]<<16|this[c+3]<<24},a.prototype.readInt32BE=function(c,u){return c=c>>>0,u||te(c,4,this.length),this[c]<<24|this[c+1]<<16|this[c+2]<<8|this[c+3]},a.prototype.readBigInt64LE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=this[c+4]+this[c+5]*2**8+this[c+6]*2**16+(m<<24);return(BigInt(T)<<BigInt(32))+BigInt(u+this[++c]*2**8+this[++c]*2**16+this[++c]*2**24)}),a.prototype.readBigInt64BE=ot(function(c){c=c>>>0,F(c,"offset");const u=this[c],m=this[c+7];(u===void 0||m===void 0)&&q(c,this.length-8);const T=(u<<24)+this[++c]*2**16+this[++c]*2**8+this[++c];return(BigInt(T)<<BigInt(32))+BigInt(this[++c]*2**24+this[++c]*2**16+this[++c]*2**8+m)}),a.prototype.readFloatLE=function(c,u){return c=c>>>0,u||te(c,4,this.length),r.read(this,c,!0,23,4)},a.prototype.readFloatBE=function(c,u){return c=c>>>0,u||te(c,4,this.length),r.read(this,c,!1,23,4)},a.prototype.readDoubleLE=function(c,u){return c=c>>>0,u||te(c,8,this.length),r.read(this,c,!0,52,8)},a.prototype.readDoubleBE=function(c,u){return c=c>>>0,u||te(c,8,this.length),r.read(this,c,!1,52,8)};function fe(h,c,u,m,T,U){if(!a.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(c>T||c<U)throw new RangeError('"value" argument is out of bounds');if(u+m>h.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(c,u,m,T){if(c=+c,u=u>>>0,m=m>>>0,!T){const ie=Math.pow(2,8*m)-1;fe(this,c,u,m,ie,0)}let U=1,H=0;for(this[u]=c&255;++H<m&&(U*=256);)this[u+H]=c/U&255;return u+m},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(c,u,m,T){if(c=+c,u=u>>>0,m=m>>>0,!T){const ie=Math.pow(2,8*m)-1;fe(this,c,u,m,ie,0)}let U=m-1,H=1;for(this[u+U]=c&255;--U>=0&&(H*=256);)this[u+U]=c/H&255;return u+m},a.prototype.writeUint8=a.prototype.writeUInt8=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,1,255,0),this[u]=c&255,u+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,65535,0),this[u]=c&255,this[u+1]=c>>>8,u+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,65535,0),this[u]=c>>>8,this[u+1]=c&255,u+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,4294967295,0),this[u+3]=c>>>24,this[u+2]=c>>>16,this[u+1]=c>>>8,this[u]=c&255,u+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,4294967295,0),this[u]=c>>>24,this[u+1]=c>>>16,this[u+2]=c>>>8,this[u+3]=c&255,u+4};function ge(h,c,u,m,T){g(c,m,T,h,u,7);let U=Number(c&BigInt(4294967295));h[u++]=U,U=U>>8,h[u++]=U,U=U>>8,h[u++]=U,U=U>>8,h[u++]=U;let H=Number(c>>BigInt(32)&BigInt(4294967295));return h[u++]=H,H=H>>8,h[u++]=H,H=H>>8,h[u++]=H,H=H>>8,h[u++]=H,u}function Se(h,c,u,m,T){g(c,m,T,h,u,7);let U=Number(c&BigInt(4294967295));h[u+7]=U,U=U>>8,h[u+6]=U,U=U>>8,h[u+5]=U,U=U>>8,h[u+4]=U;let H=Number(c>>BigInt(32)&BigInt(4294967295));return h[u+3]=H,H=H>>8,h[u+2]=H,H=H>>8,h[u+1]=H,H=H>>8,h[u]=H,u+8}a.prototype.writeBigUInt64LE=ot(function(c,u=0){return ge(this,c,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=ot(function(c,u=0){return Se(this,c,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(c,u,m,T){if(c=+c,u=u>>>0,!T){const Ie=Math.pow(2,8*m-1);fe(this,c,u,m,Ie-1,-Ie)}let U=0,H=1,ie=0;for(this[u]=c&255;++U<m&&(H*=256);)c<0&&ie===0&&this[u+U-1]!==0&&(ie=1),this[u+U]=(c/H>>0)-ie&255;return u+m},a.prototype.writeIntBE=function(c,u,m,T){if(c=+c,u=u>>>0,!T){const Ie=Math.pow(2,8*m-1);fe(this,c,u,m,Ie-1,-Ie)}let U=m-1,H=1,ie=0;for(this[u+U]=c&255;--U>=0&&(H*=256);)c<0&&ie===0&&this[u+U+1]!==0&&(ie=1),this[u+U]=(c/H>>0)-ie&255;return u+m},a.prototype.writeInt8=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,1,127,-128),c<0&&(c=255+c+1),this[u]=c&255,u+1},a.prototype.writeInt16LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,32767,-32768),this[u]=c&255,this[u+1]=c>>>8,u+2},a.prototype.writeInt16BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,2,32767,-32768),this[u]=c>>>8,this[u+1]=c&255,u+2},a.prototype.writeInt32LE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,2147483647,-2147483648),this[u]=c&255,this[u+1]=c>>>8,this[u+2]=c>>>16,this[u+3]=c>>>24,u+4},a.prototype.writeInt32BE=function(c,u,m){return c=+c,u=u>>>0,m||fe(this,c,u,4,2147483647,-2147483648),c<0&&(c=4294967295+c+1),this[u]=c>>>24,this[u+1]=c>>>16,this[u+2]=c>>>8,this[u+3]=c&255,u+4},a.prototype.writeBigInt64LE=ot(function(c,u=0){return ge(this,c,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=ot(function(c,u=0){return Se(this,c,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function je(h,c,u,m,T,U){if(u+m>h.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function O(h,c,u,m,T){return c=+c,u=u>>>0,T||je(h,c,u,4),r.write(h,c,u,m,23,4),u+4}a.prototype.writeFloatLE=function(c,u,m){return O(this,c,u,!0,m)},a.prototype.writeFloatBE=function(c,u,m){return O(this,c,u,!1,m)};function R(h,c,u,m,T){return c=+c,u=u>>>0,T||je(h,c,u,8),r.write(h,c,u,m,52,8),u+8}a.prototype.writeDoubleLE=function(c,u,m){return R(this,c,u,!0,m)},a.prototype.writeDoubleBE=function(c,u,m){return R(this,c,u,!1,m)},a.prototype.copy=function(c,u,m,T){if(!a.isBuffer(c))throw new TypeError("argument should be a Buffer");if(m||(m=0),!T&&T!==0&&(T=this.length),u>=c.length&&(u=c.length),u||(u=0),T>0&&T<m&&(T=m),T===m||c.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(m<0||m>=this.length)throw new RangeError("Index out of range");if(T<0)throw new RangeError("sourceEnd out of bounds");T>this.length&&(T=this.length),c.length-u<T-m&&(T=c.length-u+m);const U=T-m;return this===c&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(u,m,T):Uint8Array.prototype.set.call(c,this.subarray(m,T),u),U},a.prototype.fill=function(c,u,m,T){if(typeof c=="string"){if(typeof u=="string"?(T=u,u=0,m=this.length):typeof m=="string"&&(T=m,m=this.length),T!==void 0&&typeof T!="string")throw new TypeError("encoding must be a string");if(typeof T=="string"&&!a.isEncoding(T))throw new TypeError("Unknown encoding: "+T);if(c.length===1){const H=c.charCodeAt(0);(T==="utf8"&&H<128||T==="latin1")&&(c=H)}}else typeof c=="number"?c=c&255:typeof c=="boolean"&&(c=Number(c));if(u<0||this.length<u||this.length<m)throw new RangeError("Out of range index");if(m<=u)return this;u=u>>>0,m=m===void 0?this.length:m>>>0,c||(c=0);let U;if(typeof c=="number")for(U=u;U<m;++U)this[U]=c;else{const H=a.isBuffer(c)?c:a.from(c,T),ie=H.length;if(ie===0)throw new TypeError('The value "'+c+'" is invalid for argument "value"');for(U=0;U<m-u;++U)this[U+u]=H[U%ie]}return this};const D={};function Y(h,c,u){D[h]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:c.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(T){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:T,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}Y("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Y("ERR_INVALID_ARG_TYPE",function(h,c){return`The "${h}" argument must be of type number. Received type ${typeof c}`},TypeError),Y("ERR_OUT_OF_RANGE",function(h,c,u){let m=`The value of "${h}" is out of range.`,T=u;return Number.isInteger(u)&&Math.abs(u)>2**32?T=Q(String(u)):typeof u=="bigint"&&(T=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(T=Q(T)),T+="n"),m+=` It must be ${c}. Received ${T}`,m},RangeError);function Q(h){let c="",u=h.length;const m=h[0]==="-"?1:0;for(;u>=m+4;u-=3)c=`_${h.slice(u-3,u)}${c}`;return`${h.slice(0,u)}${c}`}function b(h,c,u){F(c,"offset"),(h[c]===void 0||h[c+u]===void 0)&&q(c,h.length-(u+1))}function g(h,c,u,m,T,U){if(h>u||h<c){const H=typeof c=="bigint"?"n":"";let ie;throw c===0||c===BigInt(0)?ie=`>= 0${H} and < 2${H} ** ${(U+1)*8}${H}`:ie=`>= -(2${H} ** ${(U+1)*8-1}${H}) and < 2 ** ${(U+1)*8-1}${H}`,new D.ERR_OUT_OF_RANGE("value",ie,h)}b(m,T,U)}function F(h,c){if(typeof h!="number")throw new D.ERR_INVALID_ARG_TYPE(c,"number",h)}function q(h,c,u){throw Math.floor(h)!==h?(F(h,u),new D.ERR_OUT_OF_RANGE("offset","an integer",h)):c<0?new D.ERR_BUFFER_OUT_OF_BOUNDS:new D.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${c}`,h)}const ue=/[^+/0-9A-Za-z-_]/g;function re(h){if(h=h.split("=")[0],h=h.trim().replace(ue,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function le(h,c){c=c||1/0;let u;const m=h.length;let T=null;const U=[];for(let H=0;H<m;++H){if(u=h.charCodeAt(H),u>55295&&u<57344){if(!T){if(u>56319){(c-=3)>-1&&U.push(239,191,189);continue}else if(H+1===m){(c-=3)>-1&&U.push(239,191,189);continue}T=u;continue}if(u<56320){(c-=3)>-1&&U.push(239,191,189),T=u;continue}u=(T-55296<<10|u-56320)+65536}else T&&(c-=3)>-1&&U.push(239,191,189);if(T=null,u<128){if((c-=1)<0)break;U.push(u)}else if(u<2048){if((c-=2)<0)break;U.push(u>>6|192,u&63|128)}else if(u<65536){if((c-=3)<0)break;U.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((c-=4)<0)break;U.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return U}function Zt(h){const c=[];for(let u=0;u<h.length;++u)c.push(h.charCodeAt(u)&255);return c}function Dr(h,c){let u,m,T;const U=[];for(let H=0;H<h.length&&!((c-=2)<0);++H)u=h.charCodeAt(H),m=u>>8,T=u%256,U.push(T),U.push(m);return U}function wn(h){return t.toByteArray(re(h))}function $r(h,c,u,m){let T;for(T=0;T<m&&!(T+u>=c.length||T>=h.length);++T)c[T+u]=h[T];return T}function nt(h,c){return h instanceof c||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===c.name}function _r(h){return h!==h}const _n=function(){const h="0123456789abcdef",c=new Array(256);for(let u=0;u<16;++u){const m=u*16;for(let T=0;T<16;++T)c[m+T]=h[u]+h[T]}return c}();function ot(h){return typeof BigInt>"u"?vr:h}function vr(){throw new Error("BigInt not supported")}})(Yt);var zn={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};zn.Null=zn.Nil;for(var fa in zn)zn[fa].toJSON=(function(e){return e}).bind(null,fa);var To=zn,Br=To;function Pc(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function ko(e){return Br.Nil(e)?"":Pc(e.constructor)}function El(e){return Br.Function(e)?"":Br.String(e)?JSON.stringify(e):e&&Br.Object(e)?"":e}function Po(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Ri(e){return Br.Function(e)?e.toJSON?e.toJSON():Pc(e):Br.Array(e)?"Array":e&&Br.Object(e)?"Object":e!==void 0?e:""}function Oc(e,t,r){var n=El(t);return"Expected "+Ri(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Vt(e,t,r){r=r||ko(t),this.message=Oc(e,t,r),Po(this,Vt),this.__type=e,this.__value=t,this.__valueTypeName=r}Vt.prototype=Object.create(Error.prototype);Vt.prototype.constructor=Vt;function xl(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),Oc('property "'+Ri(r)+s+Ri(e),n,i)}function Qr(e,t,r,n,i){e?(i=i||ko(n),this.message=xl(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',Po(this,Vt),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Qr.prototype=Object.create(Error.prototype);Qr.prototype.constructor=Vt;function Sl(e,t){return new Vt(e,{},t)}function Al(e,t,r){return e instanceof Qr?(t=t+"."+e.__property,e=new Qr(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Vt&&(e=new Qr(e.__type,t,r,e.__value,e.__valueTypeName)),Po(e),e}var Rc={TfTypeError:Vt,TfPropertyTypeError:Qr,tfCustomError:Sl,tfSubError:Al,tfJSON:Ri,getValueTypeName:ko},xs,ua;function Bl(){if(ua)return xs;ua=1;var e=To,t=Rc;function r(x){return Buffer.isBuffer(x)}function n(x){return typeof x=="string"&&/^([0-9a-f]{2})+$/i.test(x)}function i(x,L){var M=x.toJSON();function P(G){if(!x(G))return!1;if(G.length===L)return!0;throw t.tfCustomError(M+"(Length: "+L+")",M+"(Length: "+G.length+")")}return P.toJSON=function(){return M},P}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),f=i.bind(null,e.String);function l(x,L,M){M=M||e.Number;function P(G,K){return M(G,K)&&G>x&&G<L}return P.toJSON=function(){return`${M.toJSON()} between [${x}, ${L}]`},P}var d=Math.pow(2,53)-1;function p(x){return typeof x=="number"&&isFinite(x)}function w(x){return x<<24>>24===x}function y(x){return x<<16>>16===x}function I(x){return(x|0)===x}function S(x){return typeof x=="number"&&x>=-d&&x<=d&&Math.floor(x)===x}function _(x){return(x&255)===x}function A(x){return(x&65535)===x}function k(x){return x>>>0===x}function E(x){return typeof x=="number"&&x>=0&&x<=d&&Math.floor(x)===x}var v={ArrayN:s,Buffer:r,BufferN:o,Finite:p,Hex:n,HexN:a,Int8:w,Int16:y,Int32:I,Int53:S,Range:l,StringN:f,UInt8:_,UInt16:A,UInt32:k,UInt53:E};for(var B in v)v[B].toJSON=(function(x){return x}).bind(null,B);return xs=v,xs}var Kn=Rc,Fe=To,Ot=Kn.tfJSON,Cc=Kn.TfTypeError,Uc=Kn.TfPropertyTypeError,vn=Kn.tfSubError,Il=Kn.getValueTypeName,Mt={arrayOf:function(t,r){t=Bt(t),r=r||{};function n(i,s){return!Fe.Array(i)||Fe.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(o,a){try{return Qe(t,o,s)}catch(f){throw vn(f,a)}})}return n.toJSON=function(){var i="["+Ot(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=Bt(t);function r(n,i){return Fe.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+Ot(t)},r},map:function(t,r){t=Bt(t),r&&(r=Bt(r));function n(i,s){if(!Fe.Object(i)||Fe.Nil(i))return!1;for(var o in i){try{r&&Qe(r,o,s)}catch(f){throw vn(f,o,"key")}try{var a=i[o];Qe(t,a,s)}catch(f){throw vn(f,o)}}return!0}return r?n.toJSON=function(){return"{"+Ot(r)+": "+Ot(t)+"}"}:n.toJSON=function(){return"{"+Ot(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Bt(t[n]);function i(s,o){if(!Fe.Object(s)||Fe.Nil(s))return!1;var a;try{for(a in r){var f=r[a],l=s[a];Qe(f,l,o)}}catch(d){throw vn(d,a)}if(o){for(a in s)if(!r[a])throw new Uc(void 0,a)}return!0}return i.toJSON=function(){return Ot(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Bt);function r(n,i){return t.some(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Ot).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Bt);function r(n,i){return t.every(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Ot).join(" & ")},r},quacksLike:function(t){function r(n){return t===Il(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Bt);function r(n,i){return Fe.Nil(n)||Fe.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return Qe(s,n[o],i)}catch(a){throw vn(a,o)}})}return r.toJSON=function(){return"("+t.map(Ot).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Mt.oneOf=Mt.anyOf;function Bt(e){if(Fe.String(e))return e[0]==="?"?Mt.maybe(e.slice(1)):Fe[e]||Mt.quacksLike(e);if(e&&Fe.Object(e)){if(Fe.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Mt.arrayOf(e[0])}return Mt.object(e)}else if(Fe.Function(e))return e;return Mt.value(e)}function Qe(e,t,r,n){if(Fe.Function(e)){if(e(t,r))return!0;throw new Cc(n||e,t)}return Qe(Bt(e),t,r)}for(var ur in Fe)Qe[ur]=Fe[ur];for(ur in Mt)Qe[ur]=Mt[ur];var la=Bl();for(ur in la)Qe[ur]=la[ur];Qe.compile=Bt;Qe.TfTypeError=Cc;Qe.TfPropertyTypeError=Uc;var Lc=Qe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Yt;e.typeforce=Lc;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(d,p){return d.length!==p.length?!1:d.every((w,y)=>w.equals(p[y]))}e.stacksEqual=i;function s(d){if(!t.Buffer.isBuffer(d)||d.length<33)return!1;const p=d[0],w=d.slice(1,33);if(w.compare(r)===0||w.compare(n)>=0)return!1;if((p===2||p===3)&&d.length===33)return!0;const y=d.slice(33);return y.compare(r)===0||y.compare(n)>=0?!1:p===4&&d.length===65}e.isPoint=s;const o=21*1e14;function a(d){return e.typeforce.UInt53(d)&&d<=o}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function f(d){return!d||!("output"in d)||!t.Buffer.isBuffer(d.output)?!1:d.version!==void 0?(d.version&e.TAPLEAF_VERSION_MASK)===d.version:!0}e.isTapleaf=f;function l(d){return(0,e.Array)(d)?d.length!==2?!1:d.every(p=>l(p)):f(d)}e.isTaptree=l,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(Ke);var Yn={},Me={};Object.defineProperty(Me,"__esModule",{value:!0});Me.BufferReader=Me.BufferWriter=Me.cloneBuffer=Me.reverseBuffer=Me.writeUInt64LE=Me.readUInt64LE=Me.varuint=void 0;const Ir=Ke,{typeforce:Nc}=Ir,qn=Sc;Me.varuint=qn;function Hc(e,t){if(typeof e!="number")throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function Fc(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Hc(n+r,9007199254740991),n+r}Me.readUInt64LE=Fc;function Mc(e,t,r){return Hc(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Me.writeUInt64LE=Mc;function Tl(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}Me.reverseBuffer=Tl;function kl(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Me.cloneBuffer=kl;class Oo{static withCapacity(t){return new Oo(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Nc(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=Mc(this.buffer,t,this.offset)}writeVarInt(t){qn.encode(t,this.buffer,this.offset),this.offset+=qn.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}Me.BufferWriter=Oo;class Pl{constructor(t,r=0){this.buffer=t,this.offset=r,Nc(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=Fc(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=qn.decode(this.buffer,this.offset);return this.offset+=qn.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}Me.BufferReader=Pl;var br={},sn={},kt={},gt={};Object.defineProperty(gt,"__esModule",{value:!0});gt.isBytes=$c;gt.number=Ci;gt.bool=Dc;gt.bytes=Ro;gt.hash=jc;gt.exists=zc;gt.output=qc;function Ci(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Dc(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function $c(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Ro(e,...t){if(!$c(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function jc(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ci(e.outputLen),Ci(e.blockLen)}function zc(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function qc(e,t){Ro(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const Ol={number:Ci,bool:Dc,bytes:Ro,hash:jc,exists:zc,output:qc};gt.default=Ol;var Xn={},Vi={};Object.defineProperty(Vi,"__esModule",{value:!0});Vi.crypto=void 0;Vi.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.Hash=e.nextTick=e.byteSwapIfBE=e.byteSwap=e.isLE=e.rotl=e.rotr=e.createView=e.u32=e.u8=void 0,e.isBytes=n,e.byteSwap32=d,e.bytesToHex=w,e.hexToBytes=S,e.asyncLoop=A,e.utf8ToBytes=k,e.toBytes=E,e.concatBytes=v,e.checkOpts=L,e.wrapConstructor=M,e.wrapConstructorWithOpts=P,e.wrapXOFConstructorWithOpts=G,e.randomBytes=K;const t=Vi,r=gt;function n(C){return C instanceof Uint8Array||C!=null&&typeof C=="object"&&C.constructor.name==="Uint8Array"}const i=C=>new Uint8Array(C.buffer,C.byteOffset,C.byteLength);e.u8=i;const s=C=>new Uint32Array(C.buffer,C.byteOffset,Math.floor(C.byteLength/4));e.u32=s;const o=C=>new DataView(C.buffer,C.byteOffset,C.byteLength);e.createView=o;const a=(C,j)=>C<<32-j|C>>>j;e.rotr=a;const f=(C,j)=>C<<j|C>>>32-j>>>0;e.rotl=f,e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;const l=C=>C<<24&4278190080|C<<8&16711680|C>>>8&65280|C>>>24&255;e.byteSwap=l,e.byteSwapIfBE=e.isLE?C=>C:C=>(0,e.byteSwap)(C);function d(C){for(let j=0;j<C.length;j++)C[j]=(0,e.byteSwap)(C[j])}const p=Array.from({length:256},(C,j)=>j.toString(16).padStart(2,"0"));function w(C){(0,r.bytes)(C);let j="";for(let N=0;N<C.length;N++)j+=p[C[N]];return j}const y={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function I(C){if(C>=y._0&&C<=y._9)return C-y._0;if(C>=y._A&&C<=y._F)return C-(y._A-10);if(C>=y._a&&C<=y._f)return C-(y._a-10)}function S(C){if(typeof C!="string")throw new Error("hex string expected, got "+typeof C);const j=C.length,N=j/2;if(j%2)throw new Error("padded hex string expected, got unpadded hex of length "+j);const $=new Uint8Array(N);for(let z=0,W=0;z<N;z++,W+=2){const J=I(C.charCodeAt(W)),se=I(C.charCodeAt(W+1));if(J===void 0||se===void 0){const be=C[W]+C[W+1];throw new Error('hex string expected, got non-hex character "'+be+'" at index '+W)}$[z]=J*16+se}return $}const _=async()=>{};e.nextTick=_;async function A(C,j,N){let $=Date.now();for(let z=0;z<C;z++){N(z);const W=Date.now()-$;W>=0&&W<j||(await(0,e.nextTick)(),$+=W)}}function k(C){if(typeof C!="string")throw new Error(`utf8ToBytes expected string, got ${typeof C}`);return new Uint8Array(new TextEncoder().encode(C))}function E(C){return typeof C=="string"&&(C=k(C)),(0,r.bytes)(C),C}function v(...C){let j=0;for(let $=0;$<C.length;$++){const z=C[$];(0,r.bytes)(z),j+=z.length}const N=new Uint8Array(j);for(let $=0,z=0;$<C.length;$++){const W=C[$];N.set(W,z),z+=W.length}return N}class B{clone(){return this._cloneInto()}}e.Hash=B;const x={}.toString;function L(C,j){if(j!==void 0&&x.call(j)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(C,j)}function M(C){const j=$=>C().update(E($)).digest(),N=C();return j.outputLen=N.outputLen,j.blockLen=N.blockLen,j.create=()=>C(),j}function P(C){const j=($,z)=>C(z).update(E($)).digest(),N=C({});return j.outputLen=N.outputLen,j.blockLen=N.blockLen,j.create=$=>C($),j}function G(C){const j=($,z)=>C(z).update(E($)).digest(),N=C({});return j.outputLen=N.outputLen,j.blockLen=N.blockLen,j.create=$=>C($),j}function K(C=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(C));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(C);throw new Error("crypto.getRandomValues must be defined")}})(Xn);Object.defineProperty(kt,"__esModule",{value:!0});kt.HashMD=kt.Maj=kt.Chi=void 0;const Ss=gt,En=Xn;function Rl(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),f=n?4:0,l=n?0:4;e.setUint32(t+f,o,n),e.setUint32(t+l,a,n)}const Cl=(e,t,r)=>e&t^~e&r;kt.Chi=Cl;const Ul=(e,t,r)=>e&t^e&r^t&r;kt.Maj=Ul;let Ll=class extends En.Hash{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,En.createView)(this.buffer)}update(t){(0,Ss.exists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,En.toBytes)(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const f=(0,En.createView)(t);for(;i<=s-o;o+=i)this.process(f,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Ss.exists)(this),(0,Ss.output)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let p=o;p<i;p++)r[p]=0;Rl(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,En.createView)(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=f/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,d[p],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}};kt.HashMD=Ll;Object.defineProperty(sn,"__esModule",{value:!0});sn.ripemd160=sn.RIPEMD160=void 0;const Nl=kt,Nn=Xn,Hl=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Vc=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Fl=Vc.map(e=>(9*e+5)%16);let Co=[Vc],Uo=[Fl];for(let e=0;e<4;e++)for(let t of[Co,Uo])t.push(t[e].map(r=>Hl[r]));const Gc=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),Ml=Co.map((e,t)=>e.map(r=>Gc[t][r])),Dl=Uo.map((e,t)=>e.map(r=>Gc[t][r])),$l=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),jl=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function da(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const li=new Uint32Array(16);let Wc=class extends Nl.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=s|0}process(t,r){for(let y=0;y<16;y++,r+=4)li[y]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,f=a,l=this.h3|0,d=l,p=this.h4|0,w=p;for(let y=0;y<5;y++){const I=4-y,S=$l[y],_=jl[y],A=Co[y],k=Uo[y],E=Ml[y],v=Dl[y];for(let B=0;B<16;B++){const x=(0,Nn.rotl)(n+da(y,s,a,l)+li[A[B]]+S,E[B])+p|0;n=p,p=l,l=(0,Nn.rotl)(a,10)|0,a=s,s=x}for(let B=0;B<16;B++){const x=(0,Nn.rotl)(i+da(I,o,f,d)+li[k[B]]+_,v[B])+w|0;i=w,w=d,d=(0,Nn.rotl)(f,10)|0,f=o,o=x}}this.set(this.h1+a+d|0,this.h2+l+w|0,this.h3+p+i|0,this.h4+n+o|0,this.h0+s+f|0)}roundClean(){li.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};sn.RIPEMD160=Wc;sn.ripemd160=(0,Nn.wrapConstructor)(()=>new Wc);var on={};Object.defineProperty(on,"__esModule",{value:!0});on.sha1=on.SHA1=void 0;const As=kt,Si=Xn,xn=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Jt=new Uint32Array(80);class Kc extends As.HashMD{constructor(){super(64,20,8,!1),this.A=xn[0]|0,this.B=xn[1]|0,this.C=xn[2]|0,this.D=xn[3]|0,this.E=xn[4]|0}get(){const{A:t,B:r,C:n,D:i,E:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0}process(t,r){for(let f=0;f<16;f++,r+=4)Jt[f]=t.getUint32(r,!1);for(let f=16;f<80;f++)Jt[f]=(0,Si.rotl)(Jt[f-3]^Jt[f-8]^Jt[f-14]^Jt[f-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let f=0;f<80;f++){let l,d;f<20?(l=(0,As.Chi)(i,s,o),d=1518500249):f<40?(l=i^s^o,d=1859775393):f<60?(l=(0,As.Maj)(i,s,o),d=2400959708):(l=i^s^o,d=3395469782);const p=(0,Si.rotl)(n,5)+l+a+d+Jt[f]|0;a=o,o=s,s=(0,Si.rotl)(i,30),i=n,n=p}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,this.set(n,i,s,o,a)}roundClean(){Jt.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}on.SHA1=Kc;on.sha1=(0,Si.wrapConstructor)(()=>new Kc);var zt={};Object.defineProperty(zt,"__esModule",{value:!0});zt.sha224=zt.sha256=zt.SHA256=void 0;const Bs=kt,ft=Xn,zl=new Uint32Array([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]),Qt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),er=new Uint32Array(64);let Lo=class extends Bs.HashMD{constructor(){super(64,32,8,!1),this.A=Qt[0]|0,this.B=Qt[1]|0,this.C=Qt[2]|0,this.D=Qt[3]|0,this.E=Qt[4]|0,this.F=Qt[5]|0,this.G=Qt[6]|0,this.H=Qt[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:f}=this;return[t,r,n,i,s,o,a,f]}set(t,r,n,i,s,o,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=f|0}process(t,r){for(let p=0;p<16;p++,r+=4)er[p]=t.getUint32(r,!1);for(let p=16;p<64;p++){const w=er[p-15],y=er[p-2],I=(0,ft.rotr)(w,7)^(0,ft.rotr)(w,18)^w>>>3,S=(0,ft.rotr)(y,17)^(0,ft.rotr)(y,19)^y>>>10;er[p]=S+er[p-7]+I+er[p-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:f,G:l,H:d}=this;for(let p=0;p<64;p++){const w=(0,ft.rotr)(a,6)^(0,ft.rotr)(a,11)^(0,ft.rotr)(a,25),y=d+w+(0,Bs.Chi)(a,f,l)+zl[p]+er[p]|0,S=((0,ft.rotr)(n,2)^(0,ft.rotr)(n,13)^(0,ft.rotr)(n,22))+(0,Bs.Maj)(n,i,s)|0;d=l,l=f,f=a,a=o+y|0,o=s,s=i,i=n,n=y+S|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,f,l,d)}roundClean(){er.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};zt.SHA256=Lo;class ql extends Lo{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}zt.sha256=(0,ft.wrapConstructor)(()=>new Lo);zt.sha224=(0,ft.wrapConstructor)(()=>new ql);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=sn,r=on,n=zt;function i(d){return Buffer.from((0,t.ripemd160)(Uint8Array.from(d)))}e.ripemd160=i;function s(d){return Buffer.from((0,r.sha1)(Uint8Array.from(d)))}e.sha1=s;function o(d){return Buffer.from((0,n.sha256)(Uint8Array.from(d)))}e.sha256=o;function a(d){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(d))))}e.hash160=a;function f(d){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(d))))}e.hash256=f,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Buffer.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Buffer.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Buffer.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Buffer.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Buffer.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Buffer.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Buffer.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Buffer.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function l(d,p){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[d],p]))}e.taggedHash=l})(br);var Is={},qt={};Object.defineProperty(qt,"__esModule",{value:!0});qt.encode=qt.decode=qt.check=void 0;function Vl(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const r=e[5+t];return!(r===0||6+t+r!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||r>1&&e[t+6]===0&&!(e[t+7]&128))}qt.check=Vl;function Gl(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const r=e[5+t];if(r===0)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(r>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}qt.decode=Gl;function Wl(e,t){const r=e.length,n=t.length;if(r===0)throw new Error("R length is zero");if(n===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(r>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(n>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=Buffer.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+r]=2,i[5+r]=t.length,t.copy(i,6+r),i}qt.encode=Wl;var Or={};Object.defineProperty(Or,"__esModule",{value:!0});Or.REVERSE_OPS=Or.OPS=void 0;const oo={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Or.OPS=oo;const Yc={};Or.REVERSE_OPS=Yc;for(const e of Object.keys(oo)){const t=oo[e];Yc[t]=e}var lr={};Object.defineProperty(lr,"__esModule",{value:!0});lr.decode=lr.encode=lr.encodingLength=void 0;const fr=Or;function Xc(e){return e<fr.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}lr.encodingLength=Xc;function Kl(e,t,r){const n=Xc(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(fr.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(fr.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(fr.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}lr.encode=Kl;function Yl(e,t){const r=e.readUInt8(t);let n,i;if(r<fr.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===fr.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===fr.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==fr.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}lr.decode=Yl;var an={};Object.defineProperty(an,"__esModule",{value:!0});an.encode=an.decode=void 0;function Xl(e,t,r){t=t||4,r=r===void 0?!0:r;const n=e.length;if(n===0)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(e[n-1]&127)&&(n<=1||!(e[n-2]&128)))throw new Error("Non-minimally encoded script number");if(n===5){const s=e.readUInt32LE(0),o=e.readUInt8(4);return o&128?-((o&-129)*4294967296+s):o*4294967296+s}let i=0;for(let s=0;s<n;++s)i|=e[s]<<8*s;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}an.decode=Xl;function Zl(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function Jl(e){let t=Math.abs(e);const r=Zl(t),n=Buffer.allocUnsafe(r),i=e<0;for(let s=0;s<r;++s)n.writeUInt8(t&255,s),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}an.encode=Jl;var Sr={},ha;function Ql(){if(ha)return Sr;ha=1,Object.defineProperty(Sr,"__esModule",{value:!0}),Sr.encode=Sr.decode=void 0;const e=qt,t=st(),r=Ke,{typeforce:n}=r,i=Buffer.alloc(1,0);function s(l){let d=0;for(;l[d]===0;)++d;return d===l.length?i:(l=l.slice(d),l[0]&128?Buffer.concat([i,l],1+l.length):l)}function o(l){l[0]===0&&(l=l.slice(1));const d=Buffer.alloc(32,0),p=Math.max(0,32-l.length);return l.copy(d,p),d}function a(l){const d=l.readUInt8(l.length-1);if(!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const p=e.decode(l.slice(0,-1)),w=o(p.r),y=o(p.s);return{signature:Buffer.concat([w,y],64),hashType:d}}Sr.decode=a;function f(l,d){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:l,hashType:d}),!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const p=Buffer.allocUnsafe(1);p.writeUInt8(d,0);const w=s(l.slice(0,32)),y=s(l.slice(32,64));return Buffer.concat([e.encode(w,y),p])}return Sr.encode=f,Sr}var pa;function st(){return pa||(pa=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=qt,r=Or;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=lr,i=an,s=Ql(),o=Ke,{typeforce:a}=o,f=r.OPS.OP_RESERVED;function l(P){return o.Number(P)&&(P===r.OPS.OP_0||P>=r.OPS.OP_1&&P<=r.OPS.OP_16||P===r.OPS.OP_1NEGATE)}function d(P){return o.Buffer(P)||l(P)}function p(P){return o.Array(P)&&P.every(d)}e.isPushOnly=p;function w(P){return P.length-P.filter(d).length}e.countNonPushOnlyOPs=w;function y(P){if(P.length===0)return r.OPS.OP_0;if(P.length===1){if(P[0]>=1&&P[0]<=16)return f+P[0];if(P[0]===129)return r.OPS.OP_1NEGATE}}function I(P){return Buffer.isBuffer(P)}function S(P){return o.Array(P)}function _(P){return Buffer.isBuffer(P)}function A(P){if(I(P))return P;a(o.Array,P);const G=P.reduce((j,N)=>_(N)?N.length===1&&y(N)!==void 0?j+1:j+n.encodingLength(N.length)+N.length:j+1,0),K=Buffer.allocUnsafe(G);let C=0;if(P.forEach(j=>{if(_(j)){const N=y(j);if(N!==void 0){K.writeUInt8(N,C),C+=1;return}C+=n.encode(K,j.length,C),j.copy(K,C),C+=j.length}else K.writeUInt8(j,C),C+=1}),C!==K.length)throw new Error("Could not decode chunks");return K}e.compile=A;function k(P){if(S(P))return P;a(o.Buffer,P);const G=[];let K=0;for(;K<P.length;){const C=P[K];if(C>r.OPS.OP_0&&C<=r.OPS.OP_PUSHDATA4){const j=n.decode(P,K);if(j===null||(K+=j.size,K+j.number>P.length))return null;const N=P.slice(K,K+j.number);K+=j.number;const $=y(N);$!==void 0?G.push($):G.push(N)}else G.push(C),K+=1}return G}e.decompile=k;function E(P){if(I(P)&&(P=k(P)),!P)throw new Error("Could not convert invalid chunks to ASM");return P.map(G=>{if(_(G)){const K=y(G);if(K===void 0)return G.toString("hex");G=K}return r.REVERSE_OPS[G]}).join(" ")}e.toASM=E;function v(P){return a(o.String,P),A(P.split(" ").map(G=>r.OPS[G]!==void 0?r.OPS[G]:(a(o.Hex,G),Buffer.from(G,"hex"))))}e.fromASM=v;function B(P){return P=k(P),a(p,P),P.map(G=>_(G)?G:G===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(G-f))}e.toStack=B;function x(P){return o.isPoint(P)}e.isCanonicalPubKey=x;function L(P){const G=P&-129;return G>0&&G<4}e.isDefinedHashType=L;function M(P){return!Buffer.isBuffer(P)||!L(P[P.length-1])?!1:t.check(P.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s}(Is)),Is}Object.defineProperty(Yn,"__esModule",{value:!0});Yn.Transaction=void 0;const Oe=Me,Ye=br,ya=st(),ed=st(),ae=Ke,{typeforce:_t}=ae;function St(e){const t=e.length;return Oe.varuint.encodingLength(t)+t}function td(e){const t=e.length;return Oe.varuint.encodingLength(t)+e.reduce((r,n)=>r+St(n),0)}const or=Buffer.allocUnsafe(0),ma=[],Ts=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),ba=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),rd=Buffer.from("ffffffffffffffff","hex"),nd={script:or,valueBuffer:rd};function id(e){return e.value!==void 0}class ne{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Oe.BufferReader(t),i=new ne;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===ne.ADVANCED_TRANSACTION_MARKER&&o===ne.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const f=n.readVarInt();for(let d=0;d<f;++d)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:ma});const l=n.readVarInt();for(let d=0;d<l;++d)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let d=0;d<f;++d)i.ins[d].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return ne.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){_t(ae.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&ne.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return _t(ae.tuple(ae.Hash256bit,ae.UInt32,ae.maybe(ae.UInt32),ae.maybe(ae.Buffer)),arguments),ae.Null(n)&&(n=ne.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||or,sequence:n,witness:ma})-1}addOutput(t,r){return _t(ae.tuple(ae.Buffer,ae.Satoshi),arguments),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),r=this.byteLength(!0);return t*3+r}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const r=t&&this.hasWitnesses();return(r?10:8)+Oe.varuint.encodingLength(this.ins.length)+Oe.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+St(i.script),0)+this.outs.reduce((n,i)=>n+8+St(i.script),0)+(r?this.ins.reduce((n,i)=>n+td(i.witness),0):0)}clone(){const t=new ne;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(_t(ae.tuple(ae.UInt32,ae.Buffer,ae.Number),arguments),t>=this.ins.length)return ba;const i=ya.compile(ya.decompile(r).filter(a=>a!==ed.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===ne.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,f)=>{f!==t&&(a.sequence=0)});else if((n&31)===ne.SIGHASH_SINGLE){if(t>=this.outs.length)return ba;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=nd;s.ins.forEach((a,f)=>{f!==t&&(a.sequence=0)})}n&ne.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=or}),s.ins[t].script=i);const o=Buffer.allocUnsafe(s.byteLength(!1)+4);return o.writeInt32LE(n,o.length-4),s.__toBuffer(o,0,!1),Ye.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(_t(ae.tuple(ae.UInt32,_t.arrayOf(ae.Buffer),_t.arrayOf(ae.Satoshi),ae.UInt32),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const a=i===ne.SIGHASH_DEFAULT?ne.SIGHASH_ALL:i&ne.SIGHASH_OUTPUT_MASK,l=(i&ne.SIGHASH_INPUT_MASK)===ne.SIGHASH_ANYONECANPAY,d=a===ne.SIGHASH_NONE,p=a===ne.SIGHASH_SINGLE;let w=or,y=or,I=or,S=or,_=or;if(!l){let v=Oe.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(B=>{v.writeSlice(B.hash),v.writeUInt32(B.index)}),w=Ye.sha256(v.end()),v=Oe.BufferWriter.withCapacity(8*this.ins.length),n.forEach(B=>v.writeUInt64(B)),y=Ye.sha256(v.end()),v=Oe.BufferWriter.withCapacity(r.map(St).reduce((B,x)=>B+x)),r.forEach(B=>v.writeVarSlice(B)),I=Ye.sha256(v.end()),v=Oe.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(B=>v.writeUInt32(B.sequence)),S=Ye.sha256(v.end())}if(d||p){if(p&&t<this.outs.length){const v=this.outs[t],B=Oe.BufferWriter.withCapacity(8+St(v.script));B.writeUInt64(v.value),B.writeVarSlice(v.script),_=Ye.sha256(B.end())}}else{const v=this.outs.map(x=>8+St(x.script)).reduce((x,L)=>x+L),B=Oe.BufferWriter.withCapacity(v);this.outs.forEach(x=>{B.writeUInt64(x.value),B.writeVarSlice(x.script)}),_=Ye.sha256(B.end())}const A=(s?2:0)+(o?1:0),k=174-(l?49:0)-(d?32:0)+(o?32:0)+(s?37:0),E=Oe.BufferWriter.withCapacity(k);if(E.writeUInt8(i),E.writeInt32(this.version),E.writeUInt32(this.locktime),E.writeSlice(w),E.writeSlice(y),E.writeSlice(I),E.writeSlice(S),d||p||E.writeSlice(_),E.writeUInt8(A),l){const v=this.ins[t];E.writeSlice(v.hash),E.writeUInt32(v.index),E.writeUInt64(n[t]),E.writeVarSlice(r[t]),E.writeUInt32(v.sequence)}else E.writeUInt32(t);if(o){const v=Oe.BufferWriter.withCapacity(St(o));v.writeVarSlice(o),E.writeSlice(Ye.sha256(v.end()))}return p&&E.writeSlice(_),s&&(E.writeSlice(s),E.writeUInt8(0),E.writeUInt32(4294967295)),Ye.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),E.end()]))}hashForWitnessV0(t,r,n,i){_t(ae.tuple(ae.UInt32,ae.Buffer,ae.Satoshi,ae.UInt32),arguments);let s=Buffer.from([]),o,a=Ts,f=Ts,l=Ts;if(i&ne.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Oe.BufferWriter(s,0),this.ins.forEach(p=>{o.writeSlice(p.hash),o.writeUInt32(p.index)}),f=Ye.hash256(s)),!(i&ne.SIGHASH_ANYONECANPAY)&&(i&31)!==ne.SIGHASH_SINGLE&&(i&31)!==ne.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Oe.BufferWriter(s,0),this.ins.forEach(p=>{o.writeUInt32(p.sequence)}),l=Ye.hash256(s)),(i&31)!==ne.SIGHASH_SINGLE&&(i&31)!==ne.SIGHASH_NONE){const p=this.outs.reduce((w,y)=>w+8+St(y.script),0);s=Buffer.allocUnsafe(p),o=new Oe.BufferWriter(s,0),this.outs.forEach(w=>{o.writeUInt64(w.value),o.writeVarSlice(w.script)}),a=Ye.hash256(s)}else if((i&31)===ne.SIGHASH_SINGLE&&t<this.outs.length){const p=this.outs[t];s=Buffer.allocUnsafe(8+St(p.script)),o=new Oe.BufferWriter(s,0),o.writeUInt64(p.value),o.writeVarSlice(p.script),a=Ye.hash256(s)}s=Buffer.allocUnsafe(156+St(r)),o=new Oe.BufferWriter(s,0);const d=this.ins[t];return o.writeInt32(this.version),o.writeSlice(f),o.writeSlice(l),o.writeSlice(d.hash),o.writeUInt32(d.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(d.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Ye.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):Ye.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Oe.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(t,r){_t(ae.tuple(ae.Number,ae.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){_t(ae.tuple(ae.Number,[ae.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Oe.BufferWriter(t,r||0);i.writeInt32(this.version);const s=n&&this.hasWitnesses();return s&&(i.writeUInt8(ne.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(ne.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(o=>{i.writeSlice(o.hash),i.writeUInt32(o.index),i.writeVarSlice(o.script),i.writeUInt32(o.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(o=>{id(o)?i.writeUInt64(o.value):i.writeSlice(o.valueBuffer),i.writeVarSlice(o.script)}),s&&this.ins.forEach(o=>{i.writeVector(o.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}Yn.Transaction=ne;ne.DEFAULT_SEQUENCE=4294967295;ne.SIGHASH_DEFAULT=0;ne.SIGHASH_ALL=1;ne.SIGHASH_NONE=2;ne.SIGHASH_SINGLE=3;ne.SIGHASH_ANYONECANPAY=128;ne.SIGHASH_OUTPUT_MASK=3;ne.SIGHASH_INPUT_MASK=128;ne.ADVANCED_TRANSACTION_MARKER=0;ne.ADVANCED_TRANSACTION_FLAG=1;var ye={},Zn={};Object.defineProperty(Zn,"__esModule",{value:!0});const sd=9007199254740991;function No(e){if(e<0||e>sd||e%1!==0)throw new RangeError("value out of range")}function Hn(e,t,r){if(No(e),t||(t=Buffer.allocUnsafe(Zc(e))),!Buffer.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Object.assign(Hn,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(Hn,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(Hn,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(Hn,{bytes:9})),t}Zn.encode=Hn;function Fn(e,t){if(!Buffer.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);const r=e.readUInt8(t);if(r<253)return Object.assign(Fn,{bytes:1}),r;if(r===253)return Object.assign(Fn,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(Fn,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(Fn,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return No(s),s}}Zn.decode=Fn;function Zc(e){return No(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Zn.encodingLength=Zc;var ks={},Gi={},We={};Object.defineProperty(We,"__esModule",{value:!0});We.testnet=We.regtest=We.bitcoin=void 0;We.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
7
7
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};We.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
8
8
|
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};We.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
9
9
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var it={};Object.defineProperty(it,"__esModule",{value:!0});it.value=it.prop=void 0;function od(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}it.prop=od;function ad(e){let t;return()=>(t!==void 0||(t=e()),t)}it.value=ad;Object.defineProperty(Gi,"__esModule",{value:!0});Gi.p2data=void 0;const cd=We,Ai=st(),vt=Ke,ga=it,wa=Ai.OPS;function fd(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,vt.typeforce)({network:vt.typeforce.maybe(vt.typeforce.Object),output:vt.typeforce.maybe(vt.typeforce.Buffer),data:vt.typeforce.maybe(vt.typeforce.arrayOf(vt.typeforce.Buffer))},e);const n={name:"embed",network:e.network||cd.bitcoin};if(ga.prop(n,"output",()=>{if(e.data)return Ai.compile([wa.OP_RETURN].concat(e.data))}),ga.prop(n,"data",()=>{if(e.output)return Ai.decompile(e.output).slice(1)}),t.validate&&e.output){const i=Ai.decompile(e.output);if(i[0]!==wa.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(vt.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,vt.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}Gi.p2data=fd;var Wi={};Object.defineProperty(Wi,"__esModule",{value:!0});Wi.p2ms=void 0;const ud=We,Wr=st(),ke=Ke,tr=it,Kr=Wr.OPS,di=Kr.OP_RESERVED;function ld(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function r(f){return Wr.isCanonicalScriptSignature(f)||(t.allowIncomplete&&f===Kr.OP_0)!==void 0}(0,ke.typeforce)({network:ke.typeforce.maybe(ke.typeforce.Object),m:ke.typeforce.maybe(ke.typeforce.Number),n:ke.typeforce.maybe(ke.typeforce.Number),output:ke.typeforce.maybe(ke.typeforce.Buffer),pubkeys:ke.typeforce.maybe(ke.typeforce.arrayOf(ke.isPoint)),signatures:ke.typeforce.maybe(ke.typeforce.arrayOf(r)),input:ke.typeforce.maybe(ke.typeforce.Buffer)},e);const i={network:e.network||ud.bitcoin};let s=[],o=!1;function a(f){o||(o=!0,s=Wr.decompile(f),i.m=s[0]-di,i.n=s[s.length-2]-di,i.pubkeys=s.slice(1,-2))}if(tr.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Wr.compile([].concat(di+e.m,e.pubkeys,di+i.n,Kr.OP_CHECKMULTISIG))}),tr.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),tr.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),tr.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),tr.prop(i,"signatures",()=>{if(e.input)return Wr.decompile(e.input).slice(1)}),tr.prop(i,"input",()=>{if(e.signatures)return Wr.compile([Kr.OP_0].concat(e.signatures))}),tr.prop(i,"witness",()=>{if(i.input)return[]}),tr.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!ke.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!ke.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==Kr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==s.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(f=>(0,ke.isPoint)(f)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==i.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==i.n)throw new TypeError("n mismatch");if(e.pubkeys&&!(0,ke.stacksEqual)(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==Kr.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,ke.stacksEqual)(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}Wi.p2ms=ld;var Ki={};Object.defineProperty(Ki,"__esModule",{value:!0});Ki.p2pk=void 0;const dd=We,Yr=st(),pt=Ke,qr=it,_a=Yr.OPS;function hd(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,pt.typeforce)({network:pt.typeforce.maybe(pt.typeforce.Object),output:pt.typeforce.maybe(pt.typeforce.Buffer),pubkey:pt.typeforce.maybe(pt.isPoint),signature:pt.typeforce.maybe(Yr.isCanonicalScriptSignature),input:pt.typeforce.maybe(pt.typeforce.Buffer)},e);const r=qr.value(()=>Yr.decompile(e.input)),i={name:"p2pk",network:e.network||dd.bitcoin};if(qr.prop(i,"output",()=>{if(e.pubkey)return Yr.compile([e.pubkey,_a.OP_CHECKSIG])}),qr.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),qr.prop(i,"signature",()=>{if(e.input)return r()[0]}),qr.prop(i,"input",()=>{if(e.signature)return Yr.compile([e.signature])}),qr.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==_a.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,pt.isPoint)(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(i.input))throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!Yr.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}Ki.p2pk=hd;var Yi={};function pd(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),f=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var I=0,S=0,_=0,A=y.length;_!==A&&y[_]===0;)_++,I++;for(var k=(A-_)*l+1>>>0,E=new Uint8Array(k);_!==A;){for(var v=y[_],B=0,x=k-1;(v!==0||B<S)&&x!==-1;x--,B++)v+=256*E[x]>>>0,E[x]=v%o>>>0,v=v/o>>>0;if(v!==0)throw new Error("Non-zero carry");S=B,_++}for(var L=k-S;L!==k&&E[L]===0;)L++;for(var M=a.repeat(I);L<k;++L)M+=e.charAt(E[L]);return M}function p(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;for(var I=0,S=0,_=0;y[I]===a;)S++,I++;for(var A=(y.length-I)*f+1>>>0,k=new Uint8Array(A);y[I];){var E=t[y.charCodeAt(I)];if(E===255)return;for(var v=0,B=A-1;(E!==0||v<_)&&B!==-1;B--,v++)E+=o*k[B]>>>0,k[B]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");_=v,I++}for(var x=A-_;x!==A&&k[x]===0;)x++;for(var L=new Uint8Array(S+(A-x)),M=S;x!==A;)L[M++]=k[x++];return L}function w(y){var I=p(y);if(I)return I;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:p,decode:w}}var yd=pd;const md=yd,bd="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var gd=md(bd),Ps=gd,wd=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),f=o.length+4,l=new Uint8Array(f);return l.set(o,0),l.set(a.subarray(0,4),o.length),Ps.encode(l,f)}function r(s){var o=s.slice(0,-4),a=s.slice(-4),f=e(o);if(!(a[0]^f[0]|a[1]^f[1]|a[2]^f[2]|a[3]^f[3]))return o}function n(s){var o=Ps.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Ps.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:va}=zt,_d=wd;function vd(e){return va(va(e))}var Ho=_d(vd);Object.defineProperty(Yi,"__esModule",{value:!0});Yi.p2pkh=void 0;const Os=br,Ed=We,Xr=st(),Xe=Ke,Rt=it,Ea=Ho,rr=Xr.OPS;function xd(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,Xe.typeforce)({network:Xe.typeforce.maybe(Xe.typeforce.Object),address:Xe.typeforce.maybe(Xe.typeforce.String),hash:Xe.typeforce.maybe(Xe.typeforce.BufferN(20)),output:Xe.typeforce.maybe(Xe.typeforce.BufferN(25)),pubkey:Xe.typeforce.maybe(Xe.isPoint),signature:Xe.typeforce.maybe(Xr.isCanonicalScriptSignature),input:Xe.typeforce.maybe(Xe.typeforce.Buffer)},e);const r=Rt.value(()=>{const o=Buffer.from(Ea.decode(e.address)),a=o.readUInt8(0),f=o.slice(1);return{version:a,hash:f}}),n=Rt.value(()=>Xr.decompile(e.input)),i=e.network||Ed.bitcoin,s={name:"p2pkh",network:i};if(Rt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),Ea.encode(o)}),Rt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Os.hash160(e.pubkey||s.pubkey)}),Rt.prop(s,"output",()=>{if(s.hash)return Xr.compile([rr.OP_DUP,rr.OP_HASH160,s.hash,rr.OP_EQUALVERIFY,rr.OP_CHECKSIG])}),Rt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),Rt.prop(s,"signature",()=>{if(e.input)return n()[0]}),Rt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return Xr.compile([e.signature,e.pubkey])}),Rt.prop(s,"witness",()=>{if(s.input)return[]}),t.validate){let o=Buffer.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");o=r().hash}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==rr.OP_DUP||e.output[1]!==rr.OP_HASH160||e.output[2]!==20||e.output[23]!==rr.OP_EQUALVERIFY||e.output[24]!==rr.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.pubkey){const a=Os.hash160(e.pubkey);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!Xr.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,Xe.isPoint)(a[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(a[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(a[1]))throw new TypeError("Pubkey mismatch");const f=Os.hash160(a[1]);if(o.length>0&&!o.equals(f))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}Yi.p2pkh=xd;var Xi={};Object.defineProperty(Xi,"__esModule",{value:!0});Xi.p2sh=void 0;const xa=br,Sd=We,At=st(),we=Ke,Et=it,Sa=Ho,Sn=At.OPS;function Ad(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,we.typeforce)({network:we.typeforce.maybe(we.typeforce.Object),address:we.typeforce.maybe(we.typeforce.String),hash:we.typeforce.maybe(we.typeforce.BufferN(20)),output:we.typeforce.maybe(we.typeforce.BufferN(23)),redeem:we.typeforce.maybe({network:we.typeforce.maybe(we.typeforce.Object),output:we.typeforce.maybe(we.typeforce.Buffer),input:we.typeforce.maybe(we.typeforce.Buffer),witness:we.typeforce.maybe(we.typeforce.arrayOf(we.typeforce.Buffer))}),input:we.typeforce.maybe(we.typeforce.Buffer),witness:we.typeforce.maybe(we.typeforce.arrayOf(we.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Sd.bitcoin);const n={network:r},i=Et.value(()=>{const a=Buffer.from(Sa.decode(e.address)),f=a.readUInt8(0),l=a.slice(1);return{version:f,hash:l}}),s=Et.value(()=>At.decompile(e.input)),o=Et.value(()=>{const a=s(),f=a[a.length-1];return{network:r,output:f===Sn.OP_FALSE?Buffer.from([]):f,input:At.compile(a.slice(0,-1)),witness:e.witness||[]}});if(Et.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),Sa.encode(a)}),Et.prop(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return xa.hash160(n.redeem.output)}),Et.prop(n,"output",()=>{if(n.hash)return At.compile([Sn.OP_HASH160,n.hash,Sn.OP_EQUAL])}),Et.prop(n,"redeem",()=>{if(e.input)return o()}),Et.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return At.compile([].concat(At.decompile(e.redeem.input),e.redeem.output))}),Et.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),Et.prop(n,"name",()=>{const a=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");a=i().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Sn.OP_HASH160||e.output[1]!==20||e.output[22]!==Sn.OP_EQUAL)throw new TypeError("Output is invalid");const l=e.output.slice(2,22);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}const f=l=>{if(l.output){const d=At.decompile(l.output);if(!d||d.length<1)throw new TypeError("Redeem.output too short");if(l.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(At.countNonPushOnlyOPs(d)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const p=xa.hash160(l.output);if(a.length>0&&!a.equals(p))throw new TypeError("Hash mismatch");a=p}if(l.input){const d=l.input.length>0,p=l.witness&&l.witness.length>0;if(!d&&!p)throw new TypeError("Empty input");if(d&&p)throw new TypeError("Input and witness provided");if(d){const w=At.decompile(l.input);if(!At.isPushOnly(w))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const l=s();if(!l||l.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(o().output))throw new TypeError("Input is invalid");f(o())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const l=o();if(e.redeem.output&&!e.redeem.output.equals(l.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(l.input))throw new TypeError("Redeem.input mismatch")}f(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,we.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}Xi.p2sh=Ad;var Zi={},Gt={};Object.defineProperty(Gt,"__esModule",{value:!0});Gt.bech32m=Gt.bech32=void 0;const Ui="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Jc={};for(let e=0;e<Ui.length;e++){const t=Ui.charAt(e);Jc[t]=e}function en(e){const t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function Aa(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=en(t)^n>>5}t=en(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=en(t)^n&31}return t}function Fo(e,t,r,n){let i=0,s=0;const o=(1<<r)-1,a=[];for(let f=0;f<e.length;++f)for(i=i<<t|e[f],s+=t;s>=r;)s-=r,a.push(i>>s&o);if(n)s>0&&a.push(i<<r-s&o);else{if(s>=t)return"Excess padding";if(i<<r-s&o)return"Non-zero padding"}return a}function Bd(e){return Fo(e,8,5,!0)}function Id(e){const t=Fo(e,5,8,!1);if(Array.isArray(t))return t}function Td(e){const t=Fo(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Qc(e){let t;e==="bech32"?t=1:t=734539939;function r(o,a,f){if(f=f||90,o.length+7+a.length>f)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let l=Aa(o);if(typeof l=="string")throw new Error(l);let d=o+"1";for(let p=0;p<a.length;++p){const w=a[p];if(w>>5)throw new Error("Non 5-bit word");l=en(l)^w,d+=Ui.charAt(w)}for(let p=0;p<6;++p)l=en(l);l^=t;for(let p=0;p<6;++p){const w=l>>(5-p)*5&31;d+=Ui.charAt(w)}return d}function n(o,a){if(a=a||90,o.length<8)return o+" too short";if(o.length>a)return"Exceeds length limit";const f=o.toLowerCase(),l=o.toUpperCase();if(o!==f&&o!==l)return"Mixed-case string "+o;o=f;const d=o.lastIndexOf("1");if(d===-1)return"No separator character for "+o;if(d===0)return"Missing prefix for "+o;const p=o.slice(0,d),w=o.slice(d+1);if(w.length<6)return"Data too short";let y=Aa(p);if(typeof y=="string")return y;const I=[];for(let S=0;S<w.length;++S){const _=w.charAt(S),A=Jc[_];if(A===void 0)return"Unknown character "+_;y=en(y)^A,!(S+6>=w.length)&&I.push(A)}return y!==t?"Invalid checksum for "+o:{prefix:p,words:I}}function i(o,a){const f=n(o,a);if(typeof f=="object")return f}function s(o,a){const f=n(o,a);if(typeof f=="object")return f;throw new Error(f)}return{decodeUnsafe:i,decode:s,encode:r,toWords:Bd,fromWordsUnsafe:Id,fromWords:Td}}Gt.bech32=Qc("bech32");Gt.bech32m=Qc("bech32m");Object.defineProperty(Zi,"__esModule",{value:!0});Zi.p2wpkh=void 0;const Rs=br,kd=We,Bi=st(),Ce=Ke,nr=it,hi=Gt,Ba=Bi.OPS,Pd=Buffer.alloc(0);function Od(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,Ce.typeforce)({address:Ce.typeforce.maybe(Ce.typeforce.String),hash:Ce.typeforce.maybe(Ce.typeforce.BufferN(20)),input:Ce.typeforce.maybe(Ce.typeforce.BufferN(0)),network:Ce.typeforce.maybe(Ce.typeforce.Object),output:Ce.typeforce.maybe(Ce.typeforce.BufferN(22)),pubkey:Ce.typeforce.maybe(Ce.isPoint),signature:Ce.typeforce.maybe(Bi.isCanonicalScriptSignature),witness:Ce.typeforce.maybe(Ce.typeforce.arrayOf(Ce.typeforce.Buffer))},e);const r=nr.value(()=>{const s=hi.bech32.decode(e.address),o=s.words.shift(),a=hi.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||kd.bitcoin,i={name:"p2wpkh",network:n};if(nr.prop(i,"address",()=>{if(!i.hash)return;const s=hi.bech32.toWords(i.hash);return s.unshift(0),hi.bech32.encode(n.bech32,s)}),nr.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return Rs.hash160(e.pubkey||i.pubkey)}),nr.prop(i,"output",()=>{if(i.hash)return Bi.compile([Ba.OP_0,i.hash])}),nr.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),nr.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),nr.prop(i,"input",()=>{if(i.witness)return Pd}),nr.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let s=Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==Ba.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(s.length>0&&!s.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");s=e.output.slice(2)}if(e.pubkey){const o=Rs.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Ce.isPoint)(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!Bi.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Ce.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const o=Rs.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}Zi.p2wpkh=Od;var Ji={};Object.defineProperty(Ji,"__esModule",{value:!0});Ji.p2wsh=void 0;const Ia=br,Rd=We,Ht=st(),me=Ke,Ct=it,pi=Gt,Ta=Ht.OPS,Cs=Buffer.alloc(0);function yi(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,me.isPoint)(e))}function Cd(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,me.typeforce)({network:me.typeforce.maybe(me.typeforce.Object),address:me.typeforce.maybe(me.typeforce.String),hash:me.typeforce.maybe(me.typeforce.BufferN(32)),output:me.typeforce.maybe(me.typeforce.BufferN(34)),redeem:me.typeforce.maybe({input:me.typeforce.maybe(me.typeforce.Buffer),network:me.typeforce.maybe(me.typeforce.Object),output:me.typeforce.maybe(me.typeforce.Buffer),witness:me.typeforce.maybe(me.typeforce.arrayOf(me.typeforce.Buffer))}),input:me.typeforce.maybe(me.typeforce.BufferN(0)),witness:me.typeforce.maybe(me.typeforce.arrayOf(me.typeforce.Buffer))},e);const r=Ct.value(()=>{const o=pi.bech32.decode(e.address),a=o.words.shift(),f=pi.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(f)}}),n=Ct.value(()=>Ht.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Rd.bitcoin);const s={network:i};if(Ct.prop(s,"address",()=>{if(!s.hash)return;const o=pi.bech32.toWords(s.hash);return o.unshift(0),pi.bech32.encode(i.bech32,o)}),Ct.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return Ia.sha256(s.redeem.output)}),Ct.prop(s,"output",()=>{if(s.hash)return Ht.compile([Ta.OP_0,s.hash])}),Ct.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Cs,witness:e.witness.slice(0,-1)}}),Ct.prop(s,"input",()=>{if(s.witness)return Cs}),Ct.prop(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=Ht.toStack(n());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=Cs,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Ct.prop(s,"name",()=>{const o=["p2wsh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&o.push(s.redeem.name),o.join("-")}),t.validate){let o=Buffer.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==Ta.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const a=Ht.decompile(e.redeem.output);if(!a||a.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(Ht.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const f=Ia.sha256(e.redeem.output);if(o.length>0&&!o.equals(f))throw new TypeError("Hash mismatch");o=f}if(e.redeem.input&&!Ht.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,me.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(yi)||e.redeem.output&&(Ht.decompile(e.redeem.output)||[]).some(yi))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const a=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(a))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(yi)||(Ht.decompile(a)||[]).some(yi))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}Ji.p2wsh=Cd;var An={},Rr={};Object.defineProperty(Rr,"__esModule",{value:!0});Rr.getEccLib=Rr.initEccLib=void 0;const Mn={};function Ud(e){e?e!==Mn.eccLib&&(Nd(e),Mn.eccLib=e):Mn.eccLib=e}Rr.initEccLib=Ud;function Ld(){if(!Mn.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Mn.eccLib}Rr.getEccLib=Ld;const Ut=e=>Buffer.from(e,"hex");function Nd(e){at(typeof e.isXOnlyPoint=="function"),at(e.isXOnlyPoint(Ut("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),at(e.isXOnlyPoint(Ut("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),at(e.isXOnlyPoint(Ut("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),at(e.isXOnlyPoint(Ut("0000000000000000000000000000000000000000000000000000000000000001"))),at(!e.isXOnlyPoint(Ut("0000000000000000000000000000000000000000000000000000000000000000"))),at(!e.isXOnlyPoint(Ut("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),at(typeof e.xOnlyPointAddTweak=="function"),Hd.forEach(t=>{const r=e.xOnlyPointAddTweak(Ut(t.pubkey),Ut(t.tweak));t.result===null?at(r===null):(at(r!==null),at(r.parity===t.parity),at(Buffer.from(r.xOnlyPubkey).equals(Ut(t.result))))})}function at(e){if(!e)throw new Error("ecc library invalid")}const Hd=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];var Mo={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=Yt,r=Rr,n=br,i=Me,s=Ke;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=S=>"left"in S&&"right"in S;function a(S,_){if(S.length<33)throw new TypeError(`The control-block length is too small. Got ${S.length}, expected min 33.`);const A=(S.length-33)/32;let k=_;for(let E=0;E<A;E++){const v=S.slice(33+32*E,65+32*E);k.compare(v)<0?k=y(k,v):k=y(v,k)}return k}e.rootHashFromPath=a;function f(S){if((0,s.isTapleaf)(S))return{hash:d(S)};const _=[f(S[0]),f(S[1])];_.sort((E,v)=>E.hash.compare(v.hash));const[A,k]=_;return{hash:y(A.hash,k.hash),left:A,right:k}}e.toHashTree=f;function l(S,_){if(o(S)){const A=l(S.left,_);if(A!==void 0)return[...A,S.right.hash];const k=l(S.right,_);if(k!==void 0)return[...k,S.left.hash]}else if(S.hash.equals(_))return[]}e.findScriptPath=l;function d(S){const _=S.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([_]),I(S.output)]))}e.tapleafHash=d;function p(S,_){return n.taggedHash("TapTweak",t.Buffer.concat(_?[S,_]:[S]))}e.tapTweakHash=p;function w(S,_){if(!t.Buffer.isBuffer(S)||S.length!==32||_&&_.length!==32)return null;const A=p(S,_),k=(0,r.getEccLib)().xOnlyPointAddTweak(S,A);return!k||k.xOnlyPubkey===null?null:{parity:k.parity,x:t.Buffer.from(k.xOnlyPubkey)}}e.tweakKey=w;function y(S,_){return n.taggedHash("TapBranch",t.Buffer.concat([S,_]))}function I(S){const _=i.varuint.encodingLength(S.length),A=t.Buffer.allocUnsafe(_);return i.varuint.encode(S.length,A),t.Buffer.concat([A,S])}})(Mo);var Ze={},ka;function Fd(){if(ka)return Ze;ka=1,Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.toOutputScript=Ze.fromOutputScript=Ze.toBech32=Ze.toBase58Check=Ze.fromBech32=Ze.fromBase58Check=void 0;const e=We,t=Do(),r=st(),n=Ke,i=Gt,s=Ho,o=40,a=2,f=16,l=2,d=80,p="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function w(E,v){const B=E.slice(2);if(B.length<a||B.length>o)throw new TypeError("Invalid program length for segwit address");const x=E[0]-d;if(x<l||x>f)throw new TypeError("Invalid version for segwit address");if(E[1]!==B.length)throw new TypeError("Invalid script for segwit address");return console.warn(p),_(B,x,v.bech32)}function y(E){const v=Buffer.from(s.decode(E));if(v.length<21)throw new TypeError(E+" is too short");if(v.length>21)throw new TypeError(E+" is too long");const B=v.readUInt8(0),x=v.slice(1);return{version:B,hash:x}}Ze.fromBase58Check=y;function I(E){let v,B;try{v=i.bech32.decode(E)}catch{}if(v){if(B=v.words[0],B!==0)throw new TypeError(E+" uses wrong encoding")}else if(v=i.bech32m.decode(E),B=v.words[0],B===0)throw new TypeError(E+" uses wrong encoding");const x=i.bech32.fromWords(v.words.slice(1));return{version:B,prefix:v.prefix,data:Buffer.from(x)}}Ze.fromBech32=I;function S(E,v){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const B=Buffer.allocUnsafe(21);return B.writeUInt8(v,0),E.copy(B,1),s.encode(B)}Ze.toBase58Check=S;function _(E,v,B){const x=i.bech32.toWords(E);return x.unshift(v),v===0?i.bech32.encode(B,x):i.bech32m.encode(B,x)}Ze.toBech32=_;function A(E,v){v=v||e.bitcoin;try{return t.p2pkh({output:E,network:v}).address}catch{}try{return t.p2sh({output:E,network:v}).address}catch{}try{return t.p2wpkh({output:E,network:v}).address}catch{}try{return t.p2wsh({output:E,network:v}).address}catch{}try{return t.p2tr({output:E,network:v}).address}catch{}try{return w(E,v)}catch{}throw new Error(r.toASM(E)+" has no matching Address")}Ze.fromOutputScript=A;function k(E,v){v=v||e.bitcoin;let B,x;try{B=y(E)}catch{}if(B){if(B.version===v.pubKeyHash)return t.p2pkh({hash:B.hash}).output;if(B.version===v.scriptHash)return t.p2sh({hash:B.hash}).output}else{try{x=I(E)}catch{}if(x){if(x.prefix!==v.bech32)throw new Error(E+" has an invalid prefix");if(x.version===0){if(x.data.length===20)return t.p2wpkh({hash:x.data}).output;if(x.data.length===32)return t.p2wsh({hash:x.data}).output}else if(x.version===1){if(x.data.length===32)return t.p2tr({pubkey:x.data}).output}else if(x.version>=l&&x.version<=f&&x.data.length>=a&&x.data.length<=o)return console.warn(p),r.compile([x.version+d,x.data])}}throw new Error(E+" has no matching Script")}return Ze.toOutputScript=k,Ze}var Pa;function Md(){if(Pa)return An;Pa=1,Object.defineProperty(An,"__esModule",{value:!0}),An.p2tr=void 0;const e=Yt,t=We,r=st(),n=Ke,i=Rr,s=Mo,o=it,a=Gt,f=Fd(),l=r.OPS,d=1,p=80;function w(y,I){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");I=Object.assign({validate:!0},I||{}),(0,n.typeforce)({address:n.typeforce.maybe(n.typeforce.String),input:n.typeforce.maybe(n.typeforce.BufferN(0)),network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.BufferN(34)),internalPubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),hash:n.typeforce.maybe(n.typeforce.BufferN(32)),pubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),signature:n.typeforce.maybe(n.typeforce.anyOf(n.typeforce.BufferN(64),n.typeforce.BufferN(65))),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer)),scriptTree:n.typeforce.maybe(n.isTaptree),redeem:n.typeforce.maybe({output:n.typeforce.maybe(n.typeforce.Buffer),redeemVersion:n.typeforce.maybe(n.typeforce.Number),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))}),redeemVersion:n.typeforce.maybe(n.typeforce.Number)},y);const S=o.value(()=>(0,f.fromBech32)(y.address)),_=o.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===p?y.witness.slice(0,-1):y.witness.slice()}),A=o.value(()=>{if(y.scriptTree)return(0,s.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),k=y.network||t.bitcoin,E={name:"p2tr",network:k};if(o.prop(E,"address",()=>{if(!E.pubkey)return;const v=a.bech32m.toWords(E.pubkey);return v.unshift(d),a.bech32m.encode(k.bech32,v)}),o.prop(E,"hash",()=>{const v=A();if(v)return v.hash;const B=_();if(B&&B.length>1){const x=B[B.length-1],L=x[0]&n.TAPLEAF_VERSION_MASK,M=B[B.length-2],P=(0,s.tapleafHash)({output:M,version:L});return(0,s.rootHashFromPath)(x,P)}return null}),o.prop(E,"output",()=>{if(E.pubkey)return r.compile([l.OP_1,E.pubkey])}),o.prop(E,"redeemVersion",()=>y.redeemVersion?y.redeemVersion:y.redeem&&y.redeem.redeemVersion!==void 0&&y.redeem.redeemVersion!==null?y.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(E,"redeem",()=>{const v=_();if(!(!v||v.length<2))return{output:v[v.length-2],witness:v.slice(0,-2),redeemVersion:v[v.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(E,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return S().data;if(E.internalPubkey){const v=(0,s.tweakKey)(E.internalPubkey,E.hash);if(v)return v.x}}),o.prop(E,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const v=_();if(v&&v.length>1)return v[v.length-1].slice(1,33)}),o.prop(E,"signature",()=>{if(y.signature)return y.signature;const v=_();if(!(!v||v.length!==1))return v[0]}),o.prop(E,"witness",()=>{if(y.witness)return y.witness;const v=A();if(v&&y.redeem&&y.redeem.output&&y.internalPubkey){const B=(0,s.tapleafHash)({output:y.redeem.output,version:E.redeemVersion}),x=(0,s.findScriptPath)(v,B);if(!x)return;const L=(0,s.tweakKey)(y.internalPubkey,v.hash);if(!L)return;const M=e.Buffer.concat([e.Buffer.from([E.redeemVersion|L.parity]),y.internalPubkey].concat(x));return[y.redeem.output,M]}if(y.signature)return[y.signature]}),I.validate){let v=e.Buffer.from([]);if(y.address){if(k&&k.bech32!==S().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(S().version!==d)throw new TypeError("Invalid address version");if(S().data.length!==32)throw new TypeError("Invalid address data");v=S().data}if(y.pubkey){if(v.length>0&&!v.equals(y.pubkey))throw new TypeError("Pubkey mismatch");v=y.pubkey}if(y.output){if(y.output.length!==34||y.output[0]!==l.OP_1||y.output[1]!==32)throw new TypeError("Output is invalid");if(v.length>0&&!v.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");v=y.output.slice(2)}if(y.internalPubkey){const L=(0,s.tweakKey)(y.internalPubkey,E.hash);if(v.length>0&&!v.equals(L.x))throw new TypeError("Pubkey mismatch");v=L.x}if(v&&v.length&&!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid pubkey for p2tr");const B=A();if(y.hash&&B&&!y.hash.equals(B.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&B){const L=(0,s.tapleafHash)({output:y.redeem.output,version:E.redeemVersion});if(!(0,s.findScriptPath)(B,L))throw new TypeError("Redeem script not in tree")}const x=_();if(y.redeem&&E.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==E.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(y.redeem.output){if(r.decompile(y.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(E.redeem.output&&!y.redeem.output.equals(E.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&E.redeem.witness&&!(0,n.stacksEqual)(y.redeem.witness,E.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(x&&x.length)if(x.length===1){if(y.signature&&!y.signature.equals(x[0]))throw new TypeError("Signature mismatch")}else{const L=x[x.length-1];if(L.length<33)throw new TypeError(`The control-block length is too small. Got ${L.length}, expected min 33.`);if((L.length-33)%32!==0)throw new TypeError(`The control-block length of ${L.length} is incorrect!`);const M=(L.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const P=L.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(P))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(P))throw new TypeError("Invalid internalPubkey for p2tr witness");const G=L[0]&n.TAPLEAF_VERSION_MASK,K=x[x.length-2],C=(0,s.tapleafHash)({output:K,version:G}),j=(0,s.rootHashFromPath)(L,C),N=(0,s.tweakKey)(P,j);if(!N)throw new TypeError("Invalid outputKey for p2tr witness");if(v.length&&!v.equals(N.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(N.parity!==(L[0]&1))throw new Error("Incorrect parity")}}return Object.assign(E,y)}return An.p2tr=w,An}var Oa;function Do(){return Oa||(Oa=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=Gi;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=Wi;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=Ki;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=Yi;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=Xi;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=Zi;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=Ji;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const f=Md();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return f.p2tr}})}(ks)),ks}Object.defineProperty(ye,"__esModule",{value:!0});ye.signatureBlocksAction=ye.checkInputForSig=ye.pubkeyInScript=ye.pubkeyPositionInScript=ye.witnessStackToScriptWitness=ye.isP2TR=ye.isP2SHScript=ye.isP2WSHScript=ye.isP2WPKH=ye.isP2PKH=ye.isP2PK=ye.isP2MS=void 0;const Ra=Zn,Dn=st(),mi=Yn,Dd=br,Lr=Do();function Nr(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}ye.isP2MS=Nr(Lr.p2ms);ye.isP2PK=Nr(Lr.p2pk);ye.isP2PKH=Nr(Lr.p2pkh);ye.isP2WPKH=Nr(Lr.p2wpkh);ye.isP2WSHScript=Nr(Lr.p2wsh);ye.isP2SHScript=Nr(Lr.p2sh);ye.isP2TR=Nr(Lr.p2tr);function $d(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,f=Ra.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(f)]),Ra.encode(o,t,a)}function i(o){n(o.length),r(o)}function s(o){n(o.length),o.forEach(i)}return s(e),t}ye.witnessStackToScriptWitness=$d;function ef(e,t){const r=(0,Dd.hash160)(e),n=e.slice(1,33),i=Dn.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(s=>typeof s=="number"?!1:s.equals(e)||s.equals(r)||s.equals(n))}ye.pubkeyPositionInScript=ef;function jd(e,t){return ef(e,t)!==-1}ye.pubkeyInScript=jd;function zd(e,t){return qd(e).some(n=>tf(n,Dn.signature.decode,t))}ye.checkInputForSig=zd;function tf(e,t,r){const{hashType:n}=t(e),i=[];switch(n&mi.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case mi.Transaction.SIGHASH_ALL:break;case mi.Transaction.SIGHASH_SINGLE:case mi.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}ye.signatureBlocksAction=tf;function qd(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=Vd(e)}else t=e.partialSig;return t.map(r=>r.signature)}function Vd(e){const t=e.finalScriptSig?Dn.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?Dn.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&Dn.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(Be,"__esModule",{value:!0});Be.checkTaprootInputForSigs=Be.tapTreeFromList=Be.tapTreeToList=Be.tweakInternalPubKey=Be.checkTaprootOutputFields=Be.checkTaprootInputFields=Be.isTaprootOutput=Be.isTaprootInput=Ii=Be.serializeTaprootSignature=Be.tapScriptFinalizer=Be.toXOnly=void 0;const $o=Ke,Gd=Yn,Qi=ye,pr=Mo,Wd=Do(),Kd=ye,Yd=e=>e.length===32?e:e.slice(1,33);Be.toXOnly=Yd;function Xd(e,t,r){const n=ph(t,e,r);try{const s=dh(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,Qi.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}Be.tapScriptFinalizer=Xd;function Zd(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var Ii=Be.serializeTaprootSignature=Zd;function Ti(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,Qi.isP2TR)(e.witnessUtxo.script))}Be.isTaprootInput=Ti;function ki(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,Qi.isP2TR)(t))}Be.isTaprootOutput=ki;function Jd(e,t,r){fh(e,t,r),lh(e,t,r)}Be.checkTaprootInputFields=Jd;function Qd(e,t,r){uh(e,t,r),eh(e,t)}Be.checkTaprootOutputFields=Qd;function eh(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,s=th(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function th(e,t){const r=t&&rf(t.leaves),{output:n}=(0,Wd.p2tr)({internalPubkey:e,scriptTree:r});return n}function rh(e,t){const r=t.tapInternalKey,n=r&&(0,pr.tweakKey)(r,t.tapMerkleRoot);if(!n)throw new Error(`Cannot tweak tap internal key for input #${e}. Public key: ${r&&r.toString("hex")}`);return n.x}Be.tweakInternalPubKey=rh;function nh(e){if(!(0,$o.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ao(e)}Be.tapTreeToList=nh;function rf(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:ch(e)}Be.tapTreeFromList=rf;function ih(e,t){return oh(e).some(n=>(0,Kd.signatureBlocksAction)(n,sh,t))}Be.checkTaprootInputForSigs=ih;function sh(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||Gd.Transaction.SIGHASH_DEFAULT}}function oh(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=ah(e.finalScriptWitness);r&&t.push(r)}return t}function ah(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function ao(e,t=[],r=0){if(r>pr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,$o.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||pr.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&ao(e[0],t,r+1),e[1]&&ao(e[1],t,r+1),t):[]}function ch(e){let t;for(const r of e)if(t=co(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function co(e,t,r=0){if(r>pr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if((0,$o.isTapleaf)(t))return;const n=co(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=co(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function fh(e,t,r){const n=Ti(e)&&tn(t),i=tn(e)&&Ti(t),s=e===t&&Ti(t)&&tn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function uh(e,t,r){const n=ki(e)&&tn(t),i=tn(e)&&ki(t),s=e===t&&ki(t)&&tn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function lh(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>Us(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Us(s,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>Us(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Us(e,t){if(!t)return!0;const r=(0,pr.tapleafHash)({output:e.script,version:e.leafVersion});return(0,pr.rootHashFromPath)(e.controlBlock,r).equals(t)}function dh(e,t){const r=(0,pr.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>hh(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function hh(e,t){return Object.assign({positionInScript:(0,Qi.pubkeyPositionInScript)(t.pubkey,e)},t)}function ph(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((i,s)=>i.controlBlock.length-s.controlBlock.length).find(i=>yh(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function yh(e,t,r){const n=(0,pr.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function tn(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const He={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},bi=192;de.initEccLib(Pr);class $n{constructor(t,r,n,i,s,o,a,f){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=s,this.expiry=o,this.signer=t,this.network=a,this.internalPubkey=ll(),this.initiateAmount=r,this.utxoHashes=f}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,Er(n.length===64,He.secretHashLenMismatch),Er(i.length===64||i.length===66,`initiator ${He.pubkeyLenMismatch}`),Er(s.length===64||s.length===66,`redeemer ${He.pubkeyLenMismatch}`),Er(o>0,He.zeroOrNegativeExpiry);const f=await t.getNetwork();return new $n(t,r,n,io(s).toString("hex"),io(i).toString("hex"),o,f,a)}address(){const{address:t}=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(He.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new de.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const f of this.utxoHashes){const l=await s.getTransaction(f);for(let d=0;d<l.vout.length;d++){const p=l.vout[d];p.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:p.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((f,l)=>f+l.value,0);if(a===0)throw new Error(`${i} ${He.notFunded}`);for(let f=0;f<o.length;f++)n.addInput(Buffer.from(o[f].txid,"hex").reverse(),o[f].vout);return r??(r=await s.suggestFee(i,a,nn.Urgency.MEDIUM)),n.addOutput(de.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async _tempBuildRawTx(t,r){const n=new de.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const f of this.utxoHashes){const l=await s.getTransaction(f);for(let d=0;d<l.vout.length;d++){const p=l.vout[d];p.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:p.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((f,l)=>f+l.value,0);if(a===0)throw new Error(`${i} ${He.notFunded}`);for(let f=0;f<o.length;f++)n.addInput(Buffer.from(o[f].txid,"hex").reverse(),o[f].vout);if(n.addOutput(de.address.toOutputScript(t,this.network),a),r){const f=await s.getFeeRates(),l=Math.ceil(f.hourFee*r),d=a-l;n.outs[0].value=d}return{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return de.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,nn.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateRedeemSACP(t,r,n){const{tx:i,usedUtxos:s}=await this._buildRawTx(r,n),o=this.getOutputScript(),a=de.Transaction.SIGHASH_SINGLE|de.Transaction.SIGHASH_ANYONECANPAY,f=this.leafHash(1),l=s.map(p=>p.value),d=Vr(o,s.length);for(let p=0;p<i.ins.length;p++){const w=i.hashForWitnessV1(p,d,l,a,f),y=await this.signer.signSchnorr(w);i.setWitness(p,[Ii(y,a),Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return i.toHex()}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),s=this.getOutputScript(),o=de.Transaction.SIGHASH_SINGLE|de.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),f=i.map(d=>d.value),l=Vr(s,i.length);for(let d=0;d<n.ins.length;d++){const p=n.hashForWitnessV1(d,l,f,o,a),w=await this.signer.signSchnorr(p);n.setWitness(d,[Ii(w,o),Ii(w,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){Er(t.length>0,He.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const p of i)if(!t.find(w=>w.utxo===p.txid))throw new Error(He.counterPartySigNotFound(p.txid));const s=this.getOutputScript(),o=de.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),f=i.map(p=>p.value),l=Vr(s,i.length);for(let p=0;p<n.ins.length;p++){const w=n.hashForWitnessV1(p,l,f,o,a);if(!Pr.verifySchnorr(w,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[p].sig,"hex")))throw new Error(He.invalidCounterpartySigForUTXO(t[p].utxo));const y=await this.signer.signSchnorr(w),I=Buffer.from(n.ins[p].hash).reverse().toString("hex"),S=t.find(_=>_.utxo===I);if(!S)throw new Error(He.counterPartySigNotFound(I));n.setWitness(p,[Buffer.from(S.sig,"hex"),y,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){Er(de.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,He.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(w=>w.value),f=Vr(this.getOutputScript(),s.length),l=de.Transaction.SIGHASH_DEFAULT;for(let w=0;w<i.ins.length;w++){const y=i.hashForWitnessV1(w,f,a,l,o),I=await this.signer.signSchnorr(y);i.setWitness(w,[I,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:d}=await this._tempBuildRawTx(n,i.virtualSize());for(let w=0;w<d.ins.length;w++){const y=d.hashForWitnessV1(w,f,a,l,o),I=await this.signer.signSchnorr(y);d.setWitness(w,[I,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(d.toHex())}async getRedeemHex(t,r){Er(de.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,He.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n);console.log("utxos :",s);const o=this.leafHash(1),a=s.map(p=>p.value),f=Vr(this.getOutputScript(),s.length),l=de.Transaction.SIGHASH_DEFAULT;for(let p=0;p<i.ins.length;p++){const w=i.hashForWitnessV1(p,f,a,l,o),y=await this.signer.signSchnorr(w);i.setWitness(p,[y,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:d}=await this._tempBuildRawTx(n,i.virtualSize());for(let p=0;p<d.ins.length;p++){const w=d.hashForWitnessV1(p,f,a,l,o),y=await this.signer.signSchnorr(w);d.setWitness(p,[y,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return d.toHex()}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[s,o]=await this.canRefund(i);if(!s)throw new Error(He.htlcNotExpired(o));const a=this.leafHash(0),f=i.map(w=>w.value),l=Vr(this.getOutputScript(),i.length),d=de.Transaction.SIGHASH_DEFAULT;for(let w=0;w<n.ins.length;w++){n.ins[w].sequence=this.expiry;const y=n.hashForWitnessV1(w,l,f,d,a),I=await this.signer.signSchnorr(y);n.setWitness(w,[I,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let s=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?s=i.status.block_height+this.expiry-n+1:i.status.confirmed||(s=this.expiry+1),s>0)return[!1,s]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(He.invalidLeaf)}const n=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:bi}});if(!n.witness)throw new Error(He.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),de.crypto.taggedHash("TapLeaf",Qu(r))}refundLeaf(){return de.script.fromASM(`
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
OP_NUMEQUAL
|
|
28
28
|
`.trim().replace(/\s+/g," "))}leaves(){return[{version:bi,output:this.redeemLeaf()},[{version:bi,output:this.refundLeaf()},{version:bi,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const s=tl(i,n);return[de.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(He.invalidLeaf)}}}function Vr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class mh{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 bh{constructor(){this.cache={}}set(t,r){this.cache[t]=r}get(t){return this.cache[t]||null}}class nf{constructor(t,r){this.url=new Z.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){try{const t=await jt.get(this.url);return ce(t)}catch(t){return V("Failed to fetch block numbers",t)}}}const Zr={mainnet:{orderbook:"https://orderbookv2.garden.finance",quote:"https://pricev2.garden.finance",info:"https://infov2.garden.finance",evmRelay:"",starknetRelay:""},testnet:{orderbook:"https://orderbook.garden.finance",quote:"https://price.garden.finance",info:"https://info.garden.finance",evmRelay:"https://orderbook.garden.finance",starknetRelay:"https://starknet-relay.garden.finance"},localnet:{orderbook:"",quote:"",info:"",evmRelay:"",strkRelay:""}};class sf{constructor(t){this.quoteUrl=new Z.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 jt.get(s,{retryCount:0,...i});return o.error?V(o.error):o.result?ce(o.result):V("GetQuote: Unexpected error, result is undefined")}catch(s){return V("GetQuote:",String(s))}}async getAttestedQuote(t){try{const r=await jt.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?V(r.error):r.result?ce(r.result):V("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),V("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await jt.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return V(t.error);if(!t.result)return V("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=Ic(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 ce(r)}catch(t){return V("GetStrategies:",String(t))}}}var of={},cn={},fn={};Object.defineProperty(fn,"__esModule",{value:!0});fn.testnet=fn.bitcoin=void 0;fn.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
29
29
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};fn.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
30
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var af={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Lc,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})(af);var fo={exports:{}},uo={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Yt,n=r.Buffer;function i(o,a){for(var f in o)a[f]=o[f]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=s);function s(o,a,f){return n(o,a,f)}s.prototype=Object.create(n.prototype),i(n,s),s.from=function(o,a,f){if(typeof o=="number")throw new TypeError("Argument must not be a number");return n(o,a,f)},s.alloc=function(o,a,f){if(typeof o!="number")throw new TypeError("Argument must be a number");var l=n(o);return a!==void 0?typeof f=="string"?l.fill(a,f):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)}})(uo,uo.exports);var
|
|
31
|
-
Use Chrome, Firefox or Internet Explorer 11`)}var _h=et.Buffer,Li=hr.crypto||hr.msCrypto;Li&&Li.getRandomValues?fo.exports=vh:fo.exports=wh;function vh(e,t){if(e>gh)throw new RangeError("requested too many random bytes");var r=_h.allocUnsafe(e);if(e>0)if(e>Ls)for(var n=0;n<e;n+=Ls)Li.getRandomValues(r.slice(n,n+Ls));else Li.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Eh=fo.exports,lo={exports:{}};typeof Object.create=="function"?lo.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:lo.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 $e=lo.exports,ho={exports:{}},jo={exports:{}},rn=typeof Reflect=="object"?Reflect:null,Ca=rn&&typeof rn.apply=="function"?rn.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Pi;rn&&typeof rn.ownKeys=="function"?Pi=rn.ownKeys:Object.getOwnPropertySymbols?Pi=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Pi=function(t){return Object.getOwnPropertyNames(t)};function xh(e){console&&console.warn&&console.warn(e)}var cf=Number.isNaN||function(t){return t!==t};function he(){he.init.call(this)}jo.exports=he;jo.exports.once=Ih;he.EventEmitter=he;he.prototype._events=void 0;he.prototype._eventsCount=0;he.prototype._maxListeners=void 0;var Ua=10;function es(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(he,"defaultMaxListeners",{enumerable:!0,get:function(){return Ua},set:function(e){if(typeof e!="number"||e<0||cf(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ua=e}});he.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};he.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||cf(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 ff(e){return e._maxListeners===void 0?he.defaultMaxListeners:e._maxListeners}he.prototype.getMaxListeners=function(){return ff(this)};he.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 f=s[t];if(f===void 0)return!1;if(typeof f=="function")Ca(f,this,r);else for(var l=f.length,d=pf(f,l),n=0;n<l;++n)Ca(d[n],this,r);return!0};function uf(e,t,r,n){var i,s,o;if(es(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=ff(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,xh(a)}return e}he.prototype.addListener=function(t,r){return uf(this,t,r,!1)};he.prototype.on=he.prototype.addListener;he.prototype.prependListener=function(t,r){return uf(this,t,r,!0)};function Sh(){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 lf(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Sh.bind(n);return i.listener=r,n.wrapFn=i,i}he.prototype.once=function(t,r){return es(r),this.on(t,lf(this,t,r)),this};he.prototype.prependOnceListener=function(t,r){return es(r),this.prependListener(t,lf(this,t,r)),this};he.prototype.removeListener=function(t,r){var n,i,s,o,a;if(es(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():Ah(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};he.prototype.off=he.prototype.removeListener;he.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 df(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?Bh(i):pf(i,i.length)}he.prototype.listeners=function(t){return df(this,t,!0)};he.prototype.rawListeners=function(t){return df(this,t,!1)};he.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):hf.call(e,t)};he.prototype.listenerCount=hf;function hf(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}he.prototype.eventNames=function(){return this._eventsCount>0?Pi(this._events):[]};function pf(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Ah(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Bh(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Ih(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))}yf(e,t,s,{once:!0}),t!=="error"&&Th(e,i,{once:!0})})}function Th(e,t,r){typeof e.on=="function"&&yf(e,"error",t,r)}function yf(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 mf=jo.exports,bf=mf.EventEmitter;const kh={},Ph=Object.freeze(Object.defineProperty({__proto__:null,default:kh},Symbol.toStringTag,{value:"Module"})),zo=hl(Ph);var Ns,La;function Oh(){if(La)return Ns;La=1;function e(I,S){var _=Object.keys(I);if(Object.getOwnPropertySymbols){var A=Object.getOwnPropertySymbols(I);S&&(A=A.filter(function(k){return Object.getOwnPropertyDescriptor(I,k).enumerable})),_.push.apply(_,A)}return _}function t(I){for(var S=1;S<arguments.length;S++){var _=arguments[S]!=null?arguments[S]:{};S%2?e(Object(_),!0).forEach(function(A){r(I,A,_[A])}):Object.getOwnPropertyDescriptors?Object.defineProperties(I,Object.getOwnPropertyDescriptors(_)):e(Object(_)).forEach(function(A){Object.defineProperty(I,A,Object.getOwnPropertyDescriptor(_,A))})}return I}function r(I,S,_){return S=o(S),S in I?Object.defineProperty(I,S,{value:_,enumerable:!0,configurable:!0,writable:!0}):I[S]=_,I}function n(I,S){if(!(I instanceof S))throw new TypeError("Cannot call a class as a function")}function i(I,S){for(var _=0;_<S.length;_++){var A=S[_];A.enumerable=A.enumerable||!1,A.configurable=!0,"value"in A&&(A.writable=!0),Object.defineProperty(I,o(A.key),A)}}function s(I,S,_){return S&&i(I.prototype,S),Object.defineProperty(I,"prototype",{writable:!1}),I}function o(I){var S=a(I,"string");return typeof S=="symbol"?S:String(S)}function a(I,S){if(typeof I!="object"||I===null)return I;var _=I[Symbol.toPrimitive];if(_!==void 0){var A=_.call(I,S||"default");if(typeof A!="object")return A;throw new TypeError("@@toPrimitive must return a primitive value.")}return(S==="string"?String:Number)(I)}var f=Yt,l=f.Buffer,d=zo,p=d.inspect,w=p&&p.custom||"inspect";function y(I,S,_){l.prototype.copy.call(I,S,_)}return Ns=function(){function I(){n(this,I),this.head=null,this.tail=null,this.length=0}return s(I,[{key:"push",value:function(_){var A={data:_,next:null};this.length>0?this.tail.next=A:this.head=A,this.tail=A,++this.length}},{key:"unshift",value:function(_){var A={data:_,next:this.head};this.length===0&&(this.tail=A),this.head=A,++this.length}},{key:"shift",value:function(){if(this.length!==0){var _=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,_}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(_){if(this.length===0)return"";for(var A=this.head,k=""+A.data;A=A.next;)k+=_+A.data;return k}},{key:"concat",value:function(_){if(this.length===0)return l.alloc(0);for(var A=l.allocUnsafe(_>>>0),k=this.head,E=0;k;)y(k.data,A,E),E+=k.data.length,k=k.next;return A}},{key:"consume",value:function(_,A){var k;return _<this.head.data.length?(k=this.head.data.slice(0,_),this.head.data=this.head.data.slice(_)):_===this.head.data.length?k=this.shift():k=A?this._getString(_):this._getBuffer(_),k}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(_){var A=this.head,k=1,E=A.data;for(_-=E.length;A=A.next;){var v=A.data,B=_>v.length?v.length:_;if(B===v.length?E+=v:E+=v.slice(0,_),_-=B,_===0){B===v.length?(++k,A.next?this.head=A.next:this.head=this.tail=null):(this.head=A,A.data=v.slice(B));break}++k}return this.length-=k,E}},{key:"_getBuffer",value:function(_){var A=l.allocUnsafe(_),k=this.head,E=1;for(k.data.copy(A),_-=k.data.length;k=k.next;){var v=k.data,B=_>v.length?v.length:_;if(v.copy(A,A.length-_,0,B),_-=B,_===0){B===v.length?(++E,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=v.slice(B));break}++E}return this.length-=E,A}},{key:w,value:function(_,A){return p(this,t(t({},A),{},{depth:0,customInspect:!1}))}}]),I}(),Ns}function Rh(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(po,this,e)):process.nextTick(po,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(Oi,r):(r._writableState.errorEmitted=!0,process.nextTick(Na,r,s)):process.nextTick(Na,r,s):t?(process.nextTick(Oi,r),t(s)):process.nextTick(Oi,r)}),this)}function Na(e,t){po(e,t),Oi(e)}function Oi(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Ch(){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 po(e,t){e.emit("error",t)}function Uh(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var gf={destroy:Rh,undestroy:Ch,errorOrDestroy:Uh},Hr={};function Lh(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var wf={};function ht(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){Lh(o,s);function o(a,f,l){return s.call(this,n(a,f,l))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,wf[e]=i}function Ha(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 Nh(e,t,r){return e.substr(0,t.length)===t}function Hh(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Fh(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}ht("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);ht("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&Nh(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(Hh(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Ha(t,"type"));else{var s=Fh(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Ha(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);ht("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");ht("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});ht("ERR_STREAM_PREMATURE_CLOSE","Premature close");ht("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});ht("ERR_MULTIPLE_CALLBACK","Callback called multiple times");ht("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");ht("ERR_STREAM_WRITE_AFTER_END","write after end");ht("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);ht("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);ht("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");Hr.codes=wf;var Mh=Hr.codes.ERR_INVALID_OPT_VALUE;function Dh(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function $h(e,t,r,n){var i=Dh(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new Mh(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var _f={getHighWaterMark:$h},jh=zh;function zh(e,t){if(Hs("noDeprecation"))return e;var r=!1;function n(){if(!r){if(Hs("throwDeprecation"))throw new Error(t);Hs("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function Hs(e){try{if(!hr.localStorage)return!1}catch{return!1}var t=hr.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Fs,Fa;function vf(){if(Fa)return Fs;Fa=1,Fs=M;function e(O){var R=this;this.next=null,this.entry=null,this.finish=function(){je(R,O)}}var t;M.WritableState=x;var r={deprecate:jh},n=bf,i=Yt.Buffer,s=(typeof hr<"u"?hr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(O){return i.from(O)}function a(O){return i.isBuffer(O)||O instanceof s}var f=gf,l=_f,d=l.getHighWaterMark,p=Hr.codes,w=p.ERR_INVALID_ARG_TYPE,y=p.ERR_METHOD_NOT_IMPLEMENTED,I=p.ERR_MULTIPLE_CALLBACK,S=p.ERR_STREAM_CANNOT_PIPE,_=p.ERR_STREAM_DESTROYED,A=p.ERR_STREAM_NULL_VALUES,k=p.ERR_STREAM_WRITE_AFTER_END,E=p.ERR_UNKNOWN_ENCODING,v=f.errorOrDestroy;$e(M,n);function B(){}function x(O,R,D){t=t||un(),O=O||{},typeof D!="boolean"&&(D=R instanceof t),this.objectMode=!!O.objectMode,D&&(this.objectMode=this.objectMode||!!O.writableObjectMode),this.highWaterMark=d(this,O,"writableHighWaterMark",D),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var Y=O.decodeStrings===!1;this.decodeStrings=!Y,this.defaultEncoding=O.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(Q){z(R,Q)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=O.emitClose!==!1,this.autoDestroy=!!O.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}x.prototype.getBuffer=function(){for(var R=this.bufferedRequest,D=[];R;)D.push(R),R=R.next;return D},function(){try{Object.defineProperty(x.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var L;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(L=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(R){return L.call(this,R)?!0:this!==M?!1:R&&R._writableState instanceof x}})):L=function(R){return R instanceof this};function M(O){t=t||un();var R=this instanceof t;if(!R&&!L.call(M,this))return new M(O);this._writableState=new x(O,this,R),this.writable=!0,O&&(typeof O.write=="function"&&(this._write=O.write),typeof O.writev=="function"&&(this._writev=O.writev),typeof O.destroy=="function"&&(this._destroy=O.destroy),typeof O.final=="function"&&(this._final=O.final)),n.call(this)}M.prototype.pipe=function(){v(this,new S)};function P(O,R){var D=new k;v(O,D),process.nextTick(R,D)}function G(O,R,D,Y){var Q;return D===null?Q=new A:typeof D!="string"&&!R.objectMode&&(Q=new w("chunk",["string","Buffer"],D)),Q?(v(O,Q),process.nextTick(Y,Q),!1):!0}M.prototype.write=function(O,R,D){var Y=this._writableState,Q=!1,b=!Y.objectMode&&a(O);return b&&!i.isBuffer(O)&&(O=o(O)),typeof R=="function"&&(D=R,R=null),b?R="buffer":R||(R=Y.defaultEncoding),typeof D!="function"&&(D=B),Y.ending?P(this,D):(b||G(this,Y,O,D))&&(Y.pendingcb++,Q=C(this,Y,b,O,R,D)),Q},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var O=this._writableState;O.corked&&(O.corked--,!O.writing&&!O.corked&&!O.bufferProcessing&&O.bufferedRequest&&se(this,O))},M.prototype.setDefaultEncoding=function(R){if(typeof R=="string"&&(R=R.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((R+"").toLowerCase())>-1))throw new E(R);return this._writableState.defaultEncoding=R,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function K(O,R,D){return!O.objectMode&&O.decodeStrings!==!1&&typeof R=="string"&&(R=i.from(R,D)),R}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function C(O,R,D,Y,Q,b){if(!D){var g=K(R,Y,Q);Y!==g&&(D=!0,Q="buffer",Y=g)}var F=R.objectMode?1:Y.length;R.length+=F;var q=R.length<R.highWaterMark;if(q||(R.needDrain=!0),R.writing||R.corked){var ue=R.lastBufferedRequest;R.lastBufferedRequest={chunk:Y,encoding:Q,isBuf:D,callback:b,next:null},ue?ue.next=R.lastBufferedRequest:R.bufferedRequest=R.lastBufferedRequest,R.bufferedRequestCount+=1}else j(O,R,!1,F,Y,Q,b);return q}function j(O,R,D,Y,Q,b,g){R.writelen=Y,R.writecb=g,R.writing=!0,R.sync=!0,R.destroyed?R.onwrite(new _("write")):D?O._writev(Q,R.onwrite):O._write(Q,b,R.onwrite),R.sync=!1}function N(O,R,D,Y,Q){--R.pendingcb,D?(process.nextTick(Q,Y),process.nextTick(ge,O,R),O._writableState.errorEmitted=!0,v(O,Y)):(Q(Y),O._writableState.errorEmitted=!0,v(O,Y),ge(O,R))}function $(O){O.writing=!1,O.writecb=null,O.length-=O.writelen,O.writelen=0}function z(O,R){var D=O._writableState,Y=D.sync,Q=D.writecb;if(typeof Q!="function")throw new I;if($(D),R)N(O,D,Y,R,Q);else{var b=be(D)||O.destroyed;!b&&!D.corked&&!D.bufferProcessing&&D.bufferedRequest&&se(O,D),Y?process.nextTick(W,O,D,b,Q):W(O,D,b,Q)}}function W(O,R,D,Y){D||J(O,R),R.pendingcb--,Y(),ge(O,R)}function J(O,R){R.length===0&&R.needDrain&&(R.needDrain=!1,O.emit("drain"))}function se(O,R){R.bufferProcessing=!0;var D=R.bufferedRequest;if(O._writev&&D&&D.next){var Y=R.bufferedRequestCount,Q=new Array(Y),b=R.corkedRequestsFree;b.entry=D;for(var g=0,F=!0;D;)Q[g]=D,D.isBuf||(F=!1),D=D.next,g+=1;Q.allBuffers=F,j(O,R,!0,R.length,Q,"",b.finish),R.pendingcb++,R.lastBufferedRequest=null,b.next?(R.corkedRequestsFree=b.next,b.next=null):R.corkedRequestsFree=new e(R),R.bufferedRequestCount=0}else{for(;D;){var q=D.chunk,ue=D.encoding,re=D.callback,le=R.objectMode?1:q.length;if(j(O,R,!1,le,q,ue,re),D=D.next,R.bufferedRequestCount--,R.writing)break}D===null&&(R.lastBufferedRequest=null)}R.bufferedRequest=D,R.bufferProcessing=!1}M.prototype._write=function(O,R,D){D(new y("_write()"))},M.prototype._writev=null,M.prototype.end=function(O,R,D){var Y=this._writableState;return typeof O=="function"?(D=O,O=null,R=null):typeof R=="function"&&(D=R,R=null),O!=null&&this.write(O,R),Y.corked&&(Y.corked=1,this.uncork()),Y.ending||Se(this,Y,D),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function be(O){return O.ending&&O.length===0&&O.bufferedRequest===null&&!O.finished&&!O.writing}function te(O,R){O._final(function(D){R.pendingcb--,D&&v(O,D),R.prefinished=!0,O.emit("prefinish"),ge(O,R)})}function fe(O,R){!R.prefinished&&!R.finalCalled&&(typeof O._final=="function"&&!R.destroyed?(R.pendingcb++,R.finalCalled=!0,process.nextTick(te,O,R)):(R.prefinished=!0,O.emit("prefinish")))}function ge(O,R){var D=be(R);if(D&&(fe(O,R),R.pendingcb===0&&(R.finished=!0,O.emit("finish"),R.autoDestroy))){var Y=O._readableState;(!Y||Y.autoDestroy&&Y.endEmitted)&&O.destroy()}return D}function Se(O,R,D){R.ending=!0,ge(O,R),D&&(R.finished?process.nextTick(D):O.once("finish",D)),R.ended=!0,O.writable=!1}function je(O,R,D){var Y=O.entry;for(O.entry=null;Y;){var Q=Y.callback;R.pendingcb--,Q(D),Y=Y.next}R.corkedRequestsFree.next=O}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(R){this._writableState&&(this._writableState.destroyed=R)}}),M.prototype.destroy=f.destroy,M.prototype._undestroy=f.undestroy,M.prototype._destroy=function(O,R){R(O)},Fs}var Ms,Ma;function un(){if(Ma)return Ms;Ma=1;var e=Object.keys||function(l){var d=[];for(var p in l)d.push(p);return d};Ms=o;var t=xf(),r=vf();$e(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(f,this)}function f(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)}}),Ms}var Ni={},qo=et.Buffer,Da=qo.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 qh(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 Vh(e){var t=qh(e);if(typeof t!="string"&&(qo.isEncoding===Da||!Da(e)))throw new Error("Unknown encoding: "+e);return t||e}Ni.StringDecoder=Jn;function Jn(e){this.encoding=Vh(e);var t;switch(this.encoding){case"utf16le":this.text=Zh,this.end=Jh,t=4;break;case"utf8":this.fillLast=Kh,t=4;break;case"base64":this.text=Qh,this.end=e0,t=3;break;default:this.write=t0,this.end=r0;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=qo.allocUnsafe(t)}Jn.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||""};Jn.prototype.end=Xh;Jn.prototype.text=Yh;Jn.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 Ds(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Gh(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Ds(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Ds(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Ds(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function Wh(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 Kh(e){var t=this.lastTotal-this.lastNeed,r=Wh(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 Yh(e,t){var r=Gh(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 Xh(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function Zh(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 Jh(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 Qh(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 e0(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function t0(e){return e.toString(this.encoding)}function r0(e){return e&&e.length?this.write(e):""}var $a=Hr.codes.ERR_STREAM_PREMATURE_CLOSE;function n0(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 i0(){}function s0(e){return e.setHeader&&typeof e.abort=="function"}function Ef(e,t,r){if(typeof t=="function")return Ef(e,null,t);t||(t={}),r=n0(r||i0);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)},f=e._readableState&&e._readableState.endEmitted,l=function(){n=!1,f=!0,i||r.call(e)},d=function(I){r.call(e,I)},p=function(){var I;if(n&&!f)return(!e._readableState||!e._readableState.ended)&&(I=new $a),r.call(e,I);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(I=new $a),r.call(e,I)},w=function(){e.req.on("finish",a)};return s0(e)?(e.on("complete",a),e.on("abort",p),e.req?w():e.on("request",w)):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",p),function(){e.removeListener("complete",a),e.removeListener("abort",p),e.removeListener("request",w),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",p)}}var Vo=Ef,$s,ja;function o0(){if(ja)return $s;ja=1;var e;function t(E,v,B){return v=r(v),v in E?Object.defineProperty(E,v,{value:B,enumerable:!0,configurable:!0,writable:!0}):E[v]=B,E}function r(E){var v=n(E,"string");return typeof v=="symbol"?v:String(v)}function n(E,v){if(typeof E!="object"||E===null)return E;var B=E[Symbol.toPrimitive];if(B!==void 0){var x=B.call(E,v||"default");if(typeof x!="object")return x;throw new TypeError("@@toPrimitive must return a primitive value.")}return(v==="string"?String:Number)(E)}var i=Vo,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),f=Symbol("ended"),l=Symbol("lastPromise"),d=Symbol("handlePromise"),p=Symbol("stream");function w(E,v){return{value:E,done:v}}function y(E){var v=E[s];if(v!==null){var B=E[p].read();B!==null&&(E[l]=null,E[s]=null,E[o]=null,v(w(B,!1)))}}function I(E){process.nextTick(y,E)}function S(E,v){return function(B,x){E.then(function(){if(v[f]){B(w(void 0,!0));return}v[d](B,x)},x)}}var _=Object.getPrototypeOf(function(){}),A=Object.setPrototypeOf((e={get stream(){return this[p]},next:function(){var v=this,B=this[a];if(B!==null)return Promise.reject(B);if(this[f])return Promise.resolve(w(void 0,!0));if(this[p].destroyed)return new Promise(function(P,G){process.nextTick(function(){v[a]?G(v[a]):P(w(void 0,!0))})});var x=this[l],L;if(x)L=new Promise(S(x,this));else{var M=this[p].read();if(M!==null)return Promise.resolve(w(M,!1));L=new Promise(this[d])}return this[l]=L,L}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var v=this;return new Promise(function(B,x){v[p].destroy(null,function(L){if(L){x(L);return}B(w(void 0,!0))})})}),e),_),k=function(v){var B,x=Object.create(A,(B={},t(B,p,{value:v,writable:!0}),t(B,s,{value:null,writable:!0}),t(B,o,{value:null,writable:!0}),t(B,a,{value:null,writable:!0}),t(B,f,{value:v._readableState.endEmitted,writable:!0}),t(B,d,{value:function(M,P){var G=x[p].read();G?(x[l]=null,x[s]=null,x[o]=null,M(w(G,!1))):(x[s]=M,x[o]=P)},writable:!0}),B));return x[l]=null,i(v,function(L){if(L&&L.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=x[o];M!==null&&(x[l]=null,x[s]=null,x[o]=null,M(L)),x[a]=L;return}var P=x[s];P!==null&&(x[l]=null,x[s]=null,x[o]=null,P(w(void 0,!0))),x[f]=!0}),v.on("readable",I.bind(null,x)),x};return $s=k,$s}var js,za;function a0(){return za||(za=1,js=function(){throw new Error("Readable.from is not available in the browser")}),js}var zs,qa;function xf(){if(qa)return zs;qa=1,zs=P;var e;P.ReadableState=M,mf.EventEmitter;var t=function(g,F){return g.listeners(F).length},r=bf,n=Yt.Buffer,i=(typeof hr<"u"?hr: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=zo,f;a&&a.debuglog?f=a.debuglog("stream"):f=function(){};var l=Oh(),d=gf,p=_f,w=p.getHighWaterMark,y=Hr.codes,I=y.ERR_INVALID_ARG_TYPE,S=y.ERR_STREAM_PUSH_AFTER_EOF,_=y.ERR_METHOD_NOT_IMPLEMENTED,A=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,k,E,v;$e(P,r);var B=d.errorOrDestroy,x=["error","close","destroy","pause","resume"];function L(b,g,F){if(typeof b.prependListener=="function")return b.prependListener(g,F);!b._events||!b._events[g]?b.on(g,F):Array.isArray(b._events[g])?b._events[g].unshift(F):b._events[g]=[F,b._events[g]]}function M(b,g,F){e=e||un(),b=b||{},typeof F!="boolean"&&(F=g instanceof e),this.objectMode=!!b.objectMode,F&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=w(this,b,"readableHighWaterMark",F),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&&(k||(k=Ni.StringDecoder),this.decoder=new k(b.encoding),this.encoding=b.encoding)}function P(b){if(e=e||un(),!(this instanceof P))return new P(b);var g=this instanceof e;this._readableState=new M(b,this,g),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(P.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(g){this._readableState&&(this._readableState.destroyed=g)}}),P.prototype.destroy=d.destroy,P.prototype._undestroy=d.undestroy,P.prototype._destroy=function(b,g){g(b)},P.prototype.push=function(b,g){var F=this._readableState,q;return F.objectMode?q=!0:typeof b=="string"&&(g=g||F.defaultEncoding,g!==F.encoding&&(b=n.from(b,g),g=""),q=!0),G(this,b,g,!1,q)},P.prototype.unshift=function(b){return G(this,b,null,!0,!1)};function G(b,g,F,q,ue){f("readableAddChunk",g);var re=b._readableState;if(g===null)re.reading=!1,z(b,re);else{var le;if(ue||(le=C(re,g)),le)B(b,le);else if(re.objectMode||g&&g.length>0)if(typeof g!="string"&&!re.objectMode&&Object.getPrototypeOf(g)!==n.prototype&&(g=s(g)),q)re.endEmitted?B(b,new A):K(b,re,g,!0);else if(re.ended)B(b,new S);else{if(re.destroyed)return!1;re.reading=!1,re.decoder&&!F?(g=re.decoder.write(g),re.objectMode||g.length!==0?K(b,re,g,!1):se(b,re)):K(b,re,g,!1)}else q||(re.reading=!1,se(b,re))}return!re.ended&&(re.length<re.highWaterMark||re.length===0)}function K(b,g,F,q){g.flowing&&g.length===0&&!g.sync?(g.awaitDrain=0,b.emit("data",F)):(g.length+=g.objectMode?1:F.length,q?g.buffer.unshift(F):g.buffer.push(F),g.needReadable&&W(b)),se(b,g)}function C(b,g){var F;return!o(g)&&typeof g!="string"&&g!==void 0&&!b.objectMode&&(F=new I("chunk",["string","Buffer","Uint8Array"],g)),F}P.prototype.isPaused=function(){return this._readableState.flowing===!1},P.prototype.setEncoding=function(b){k||(k=Ni.StringDecoder);var g=new k(b);this._readableState.decoder=g,this._readableState.encoding=this._readableState.decoder.encoding;for(var F=this._readableState.buffer.head,q="";F!==null;)q+=g.write(F.data),F=F.next;return this._readableState.buffer.clear(),q!==""&&this._readableState.buffer.push(q),this._readableState.length=q.length,this};var j=1073741824;function N(b){return b>=j?b=j:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function $(b,g){return b<=0||g.length===0&&g.ended?0:g.objectMode?1:b!==b?g.flowing&&g.length?g.buffer.head.data.length:g.length:(b>g.highWaterMark&&(g.highWaterMark=N(b)),b<=g.length?b:g.ended?g.length:(g.needReadable=!0,0))}P.prototype.read=function(b){f("read",b),b=parseInt(b,10);var g=this._readableState,F=b;if(b!==0&&(g.emittedReadable=!1),b===0&&g.needReadable&&((g.highWaterMark!==0?g.length>=g.highWaterMark:g.length>0)||g.ended))return f("read: emitReadable",g.length,g.ended),g.length===0&&g.ended?D(this):W(this),null;if(b=$(b,g),b===0&&g.ended)return g.length===0&&D(this),null;var q=g.needReadable;f("need readable",q),(g.length===0||g.length-b<g.highWaterMark)&&(q=!0,f("length less than watermark",q)),g.ended||g.reading?(q=!1,f("reading or ended",q)):q&&(f("do read"),g.reading=!0,g.sync=!0,g.length===0&&(g.needReadable=!0),this._read(g.highWaterMark),g.sync=!1,g.reading||(b=$(F,g)));var ue;return b>0?ue=R(b,g):ue=null,ue===null?(g.needReadable=g.length<=g.highWaterMark,b=0):(g.length-=b,g.awaitDrain=0),g.length===0&&(g.ended||(g.needReadable=!0),F!==b&&g.ended&&D(this)),ue!==null&&this.emit("data",ue),ue};function z(b,g){if(f("onEofChunk"),!g.ended){if(g.decoder){var F=g.decoder.end();F&&F.length&&(g.buffer.push(F),g.length+=g.objectMode?1:F.length)}g.ended=!0,g.sync?W(b):(g.needReadable=!1,g.emittedReadable||(g.emittedReadable=!0,J(b)))}}function W(b){var g=b._readableState;f("emitReadable",g.needReadable,g.emittedReadable),g.needReadable=!1,g.emittedReadable||(f("emitReadable",g.flowing),g.emittedReadable=!0,process.nextTick(J,b))}function J(b){var g=b._readableState;f("emitReadable_",g.destroyed,g.length,g.ended),!g.destroyed&&(g.length||g.ended)&&(b.emit("readable"),g.emittedReadable=!1),g.needReadable=!g.flowing&&!g.ended&&g.length<=g.highWaterMark,O(b)}function se(b,g){g.readingMore||(g.readingMore=!0,process.nextTick(be,b,g))}function be(b,g){for(;!g.reading&&!g.ended&&(g.length<g.highWaterMark||g.flowing&&g.length===0);){var F=g.length;if(f("maybeReadMore read 0"),b.read(0),F===g.length)break}g.readingMore=!1}P.prototype._read=function(b){B(this,new _("_read()"))},P.prototype.pipe=function(b,g){var F=this,q=this._readableState;switch(q.pipesCount){case 0:q.pipes=b;break;case 1:q.pipes=[q.pipes,b];break;default:q.pipes.push(b);break}q.pipesCount+=1,f("pipe count=%d opts=%j",q.pipesCount,g);var ue=(!g||g.end!==!1)&&b!==process.stdout&&b!==process.stderr,re=ue?Zt:vr;q.endEmitted?process.nextTick(re):F.once("end",re),b.on("unpipe",le);function le(h,c){f("onunpipe"),h===F&&c&&c.hasUnpiped===!1&&(c.hasUnpiped=!0,$r())}function Zt(){f("onend"),b.end()}var Dr=te(F);b.on("drain",Dr);var wn=!1;function $r(){f("cleanup"),b.removeListener("close",_n),b.removeListener("finish",ot),b.removeListener("drain",Dr),b.removeListener("error",_r),b.removeListener("unpipe",le),F.removeListener("end",Zt),F.removeListener("end",vr),F.removeListener("data",rt),wn=!0,q.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&Dr()}F.on("data",rt);function rt(h){f("ondata");var c=b.write(h);f("dest.write",c),c===!1&&((q.pipesCount===1&&q.pipes===b||q.pipesCount>1&&Q(q.pipes,b)!==-1)&&!wn&&(f("false write response, pause",q.awaitDrain),q.awaitDrain++),F.pause())}function _r(h){f("onerror",h),vr(),b.removeListener("error",_r),t(b,"error")===0&&B(b,h)}L(b,"error",_r);function _n(){b.removeListener("finish",ot),vr()}b.once("close",_n);function ot(){f("onfinish"),b.removeListener("close",_n),vr()}b.once("finish",ot);function vr(){f("unpipe"),F.unpipe(b)}return b.emit("pipe",F),q.flowing||(f("pipe resume"),F.resume()),b};function te(b){return function(){var F=b._readableState;f("pipeOnDrain",F.awaitDrain),F.awaitDrain&&F.awaitDrain--,F.awaitDrain===0&&t(b,"data")&&(F.flowing=!0,O(b))}}P.prototype.unpipe=function(b){var g=this._readableState,F={hasUnpiped:!1};if(g.pipesCount===0)return this;if(g.pipesCount===1)return b&&b!==g.pipes?this:(b||(b=g.pipes),g.pipes=null,g.pipesCount=0,g.flowing=!1,b&&b.emit("unpipe",this,F),this);if(!b){var q=g.pipes,ue=g.pipesCount;g.pipes=null,g.pipesCount=0,g.flowing=!1;for(var re=0;re<ue;re++)q[re].emit("unpipe",this,{hasUnpiped:!1});return this}var le=Q(g.pipes,b);return le===-1?this:(g.pipes.splice(le,1),g.pipesCount-=1,g.pipesCount===1&&(g.pipes=g.pipes[0]),b.emit("unpipe",this,F),this)},P.prototype.on=function(b,g){var F=r.prototype.on.call(this,b,g),q=this._readableState;return b==="data"?(q.readableListening=this.listenerCount("readable")>0,q.flowing!==!1&&this.resume()):b==="readable"&&!q.endEmitted&&!q.readableListening&&(q.readableListening=q.needReadable=!0,q.flowing=!1,q.emittedReadable=!1,f("on readable",q.length,q.reading),q.length?W(this):q.reading||process.nextTick(ge,this)),F},P.prototype.addListener=P.prototype.on,P.prototype.removeListener=function(b,g){var F=r.prototype.removeListener.call(this,b,g);return b==="readable"&&process.nextTick(fe,this),F},P.prototype.removeAllListeners=function(b){var g=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(fe,this),g};function fe(b){var g=b._readableState;g.readableListening=b.listenerCount("readable")>0,g.resumeScheduled&&!g.paused?g.flowing=!0:b.listenerCount("data")>0&&b.resume()}function ge(b){f("readable nexttick read 0"),b.read(0)}P.prototype.resume=function(){var b=this._readableState;return b.flowing||(f("resume"),b.flowing=!b.readableListening,Se(this,b)),b.paused=!1,this};function Se(b,g){g.resumeScheduled||(g.resumeScheduled=!0,process.nextTick(je,b,g))}function je(b,g){f("resume",g.reading),g.reading||b.read(0),g.resumeScheduled=!1,b.emit("resume"),O(b),g.flowing&&!g.reading&&b.read(0)}P.prototype.pause=function(){return f("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(f("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function O(b){var g=b._readableState;for(f("flow",g.flowing);g.flowing&&b.read()!==null;);}P.prototype.wrap=function(b){var g=this,F=this._readableState,q=!1;b.on("end",function(){if(f("wrapped end"),F.decoder&&!F.ended){var le=F.decoder.end();le&&le.length&&g.push(le)}g.push(null)}),b.on("data",function(le){if(f("wrapped data"),F.decoder&&(le=F.decoder.write(le)),!(F.objectMode&&le==null)&&!(!F.objectMode&&(!le||!le.length))){var Zt=g.push(le);Zt||(q=!0,b.pause())}});for(var ue in b)this[ue]===void 0&&typeof b[ue]=="function"&&(this[ue]=function(Zt){return function(){return b[Zt].apply(b,arguments)}}(ue));for(var re=0;re<x.length;re++)b.on(x[re],this.emit.bind(this,x[re]));return this._read=function(le){f("wrapped _read",le),q&&(q=!1,b.resume())},this},typeof Symbol=="function"&&(P.prototype[Symbol.asyncIterator]=function(){return E===void 0&&(E=o0()),E(this)}),Object.defineProperty(P.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(P.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(P.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(g){this._readableState&&(this._readableState.flowing=g)}}),P._fromList=R,Object.defineProperty(P.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function R(b,g){if(g.length===0)return null;var F;return g.objectMode?F=g.buffer.shift():!b||b>=g.length?(g.decoder?F=g.buffer.join(""):g.buffer.length===1?F=g.buffer.first():F=g.buffer.concat(g.length),g.buffer.clear()):F=g.buffer.consume(b,g.decoder),F}function D(b){var g=b._readableState;f("endReadable",g.endEmitted),g.endEmitted||(g.ended=!0,process.nextTick(Y,g,b))}function Y(b,g){if(f("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,g.readable=!1,g.emit("end"),b.autoDestroy)){var F=g._writableState;(!F||F.autoDestroy&&F.finished)&&g.destroy()}}typeof Symbol=="function"&&(P.from=function(b,g){return v===void 0&&(v=a0()),v(P,b,g)});function Q(b,g){for(var F=0,q=b.length;F<q;F++)if(b[F]===g)return F;return-1}return zs}var Sf=Wt,ts=Hr.codes,c0=ts.ERR_METHOD_NOT_IMPLEMENTED,f0=ts.ERR_MULTIPLE_CALLBACK,u0=ts.ERR_TRANSFORM_ALREADY_TRANSFORMING,l0=ts.ERR_TRANSFORM_WITH_LENGTH_0,rs=un();$e(Wt,rs);function d0(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new f0);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 Wt(e){if(!(this instanceof Wt))return new Wt(e);rs.call(this,e),this._transformState={afterTransform:d0.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",h0)}function h0(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Va(e,t,r)}):Va(this,null,null)}Wt.prototype.push=function(e,t){return this._transformState.needTransform=!1,rs.prototype.push.call(this,e,t)};Wt.prototype._transform=function(e,t,r){r(new c0("_transform()"))};Wt.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)}};Wt.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};Wt.prototype._destroy=function(e,t){rs.prototype._destroy.call(this,e,function(r){t(r)})};function Va(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new l0;if(e._transformState.transforming)throw new u0;return e.push(null)}var p0=Vn,Af=Sf;$e(Vn,Af);function Vn(e){if(!(this instanceof Vn))return new Vn(e);Af.call(this,e)}Vn.prototype._transform=function(e,t,r){r(null,e)};var qs;function y0(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var Bf=Hr.codes,m0=Bf.ERR_MISSING_ARGS,b0=Bf.ERR_STREAM_DESTROYED;function Ga(e){if(e)throw e}function g0(e){return e.setHeader&&typeof e.abort=="function"}function w0(e,t,r,n){n=y0(n);var i=!1;e.on("close",function(){i=!0}),qs===void 0&&(qs=Vo),qs(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,g0(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new b0("pipe"))}}}function Wa(e){e()}function _0(e,t){return e.pipe(t)}function v0(e){return!e.length||typeof e[e.length-1]!="function"?Ga:e.pop()}function E0(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=v0(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new m0("streams");var i,s=t.map(function(o,a){var f=a<t.length-1,l=a>0;return w0(o,f,l,function(d){i||(i=d),d&&s.forEach(Wa),!f&&(s.forEach(Wa),n(i))})});return t.reduce(_0)}var x0=E0;(function(e,t){t=e.exports=xf(),t.Stream=t,t.Readable=t,t.Writable=vf(),t.Duplex=un(),t.Transform=Sf,t.PassThrough=p0,t.finished=Vo,t.pipeline=x0})(ho,ho.exports);var If=ho.exports,Hi=et.Buffer,Tf=If.Transform,S0=$e;function A0(e,t){if(!Hi.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function gr(e){Tf.call(this),this._block=Hi.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}S0(gr,Tf);gr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};gr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};gr.prototype.update=function(e,t){if(A0(e,"Data"),this._finalized)throw new Error("Digest already called");Hi.isBuffer(e)||(e=Hi.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};gr.prototype._update=function(){throw new Error("_update is not implemented")};gr.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};gr.prototype._digest=function(){throw new Error("_digest is not implemented")};var B0=gr,I0=$e,kf=B0,T0=et.Buffer,k0=new Array(16);function ns(){kf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}I0(ns,kf);ns.prototype._update=function(){for(var e=k0,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=ze(r,n,i,s,e[0],3614090360,7),s=ze(s,r,n,i,e[1],3905402710,12),i=ze(i,s,r,n,e[2],606105819,17),n=ze(n,i,s,r,e[3],3250441966,22),r=ze(r,n,i,s,e[4],4118548399,7),s=ze(s,r,n,i,e[5],1200080426,12),i=ze(i,s,r,n,e[6],2821735955,17),n=ze(n,i,s,r,e[7],4249261313,22),r=ze(r,n,i,s,e[8],1770035416,7),s=ze(s,r,n,i,e[9],2336552879,12),i=ze(i,s,r,n,e[10],4294925233,17),n=ze(n,i,s,r,e[11],2304563134,22),r=ze(r,n,i,s,e[12],1804603682,7),s=ze(s,r,n,i,e[13],4254626195,12),i=ze(i,s,r,n,e[14],2792965006,17),n=ze(n,i,s,r,e[15],1236535329,22),r=qe(r,n,i,s,e[1],4129170786,5),s=qe(s,r,n,i,e[6],3225465664,9),i=qe(i,s,r,n,e[11],643717713,14),n=qe(n,i,s,r,e[0],3921069994,20),r=qe(r,n,i,s,e[5],3593408605,5),s=qe(s,r,n,i,e[10],38016083,9),i=qe(i,s,r,n,e[15],3634488961,14),n=qe(n,i,s,r,e[4],3889429448,20),r=qe(r,n,i,s,e[9],568446438,5),s=qe(s,r,n,i,e[14],3275163606,9),i=qe(i,s,r,n,e[3],4107603335,14),n=qe(n,i,s,r,e[8],1163531501,20),r=qe(r,n,i,s,e[13],2850285829,5),s=qe(s,r,n,i,e[2],4243563512,9),i=qe(i,s,r,n,e[7],1735328473,14),n=qe(n,i,s,r,e[12],2368359562,20),r=Ve(r,n,i,s,e[5],4294588738,4),s=Ve(s,r,n,i,e[8],2272392833,11),i=Ve(i,s,r,n,e[11],1839030562,16),n=Ve(n,i,s,r,e[14],4259657740,23),r=Ve(r,n,i,s,e[1],2763975236,4),s=Ve(s,r,n,i,e[4],1272893353,11),i=Ve(i,s,r,n,e[7],4139469664,16),n=Ve(n,i,s,r,e[10],3200236656,23),r=Ve(r,n,i,s,e[13],681279174,4),s=Ve(s,r,n,i,e[0],3936430074,11),i=Ve(i,s,r,n,e[3],3572445317,16),n=Ve(n,i,s,r,e[6],76029189,23),r=Ve(r,n,i,s,e[9],3654602809,4),s=Ve(s,r,n,i,e[12],3873151461,11),i=Ve(i,s,r,n,e[15],530742520,16),n=Ve(n,i,s,r,e[2],3299628645,23),r=Ge(r,n,i,s,e[0],4096336452,6),s=Ge(s,r,n,i,e[7],1126891415,10),i=Ge(i,s,r,n,e[14],2878612391,15),n=Ge(n,i,s,r,e[5],4237533241,21),r=Ge(r,n,i,s,e[12],1700485571,6),s=Ge(s,r,n,i,e[3],2399980690,10),i=Ge(i,s,r,n,e[10],4293915773,15),n=Ge(n,i,s,r,e[1],2240044497,21),r=Ge(r,n,i,s,e[8],1873313359,6),s=Ge(s,r,n,i,e[15],4264355552,10),i=Ge(i,s,r,n,e[6],2734768916,15),n=Ge(n,i,s,r,e[13],1309151649,21),r=Ge(r,n,i,s,e[4],4149444226,6),s=Ge(s,r,n,i,e[11],3174756917,10),i=Ge(i,s,r,n,e[2],718787259,15),n=Ge(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};ns.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=T0.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 is(e,t){return e<<t|e>>>32-t}function ze(e,t,r,n,i,s,o){return is(e+(t&r|~t&n)+i+s|0,o)+t|0}function qe(e,t,r,n,i,s,o){return is(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ve(e,t,r,n,i,s,o){return is(e+(t^r^n)+i+s|0,o)+t|0}function Ge(e,t,r,n,i,s,o){return is(e+(r^(t|~n))+i+s|0,o)+t|0}var P0=ns,Fi=et.Buffer,Pf=If.Transform,O0=$e;function R0(e,t){if(!Fi.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function wr(e){Pf.call(this),this._block=Fi.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}O0(wr,Pf);wr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};wr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};wr.prototype.update=function(e,t){if(R0(e,"Data"),this._finalized)throw new Error("Digest already called");Fi.isBuffer(e)||(e=Fi.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};wr.prototype._update=function(){throw new Error("_update is not implemented")};wr.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};wr.prototype._digest=function(){throw new Error("_digest is not implemented")};var C0=wr,Vs=Yt.Buffer,U0=$e,Of=C0,L0=new Array(16),Bn=[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],In=[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],Tn=[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],kn=[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],Pn=[0,1518500249,1859775393,2400959708,2840853838],On=[1352829926,1548603684,1836072691,2053994217,0];function ss(){Of.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}U0(ss,Of);ss.prototype._update=function(){for(var e=L0,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,f=this._b|0,l=this._c|0,d=this._d|0,p=this._e|0,w=0;w<80;w+=1){var y,I;w<16?(y=Ka(r,n,i,s,o,e[Bn[w]],Pn[0],Tn[w]),I=Ja(a,f,l,d,p,e[In[w]],On[0],kn[w])):w<32?(y=Ya(r,n,i,s,o,e[Bn[w]],Pn[1],Tn[w]),I=Za(a,f,l,d,p,e[In[w]],On[1],kn[w])):w<48?(y=Xa(r,n,i,s,o,e[Bn[w]],Pn[2],Tn[w]),I=Xa(a,f,l,d,p,e[In[w]],On[2],kn[w])):w<64?(y=Za(r,n,i,s,o,e[Bn[w]],Pn[3],Tn[w]),I=Ya(a,f,l,d,p,e[In[w]],On[3],kn[w])):(y=Ja(r,n,i,s,o,e[Bn[w]],Pn[4],Tn[w]),I=Ka(a,f,l,d,p,e[In[w]],On[4],kn[w])),r=o,o=s,s=Cr(i,10),i=n,n=y,a=p,p=d,d=Cr(l,10),l=f,f=I}var S=this._b+i+d|0;this._b=this._c+s+p|0,this._c=this._d+o+a|0,this._d=this._e+r+f|0,this._e=this._a+n+l|0,this._a=S};ss.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=Vs.alloc?Vs.alloc(20):new Vs(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};function Cr(e,t){return e<<t|e>>>32-t}function Ka(e,t,r,n,i,s,o,a){return Cr(e+(t^r^n)+s+o|0,a)+i|0}function Ya(e,t,r,n,i,s,o,a){return Cr(e+(t&r|~t&n)+s+o|0,a)+i|0}function Xa(e,t,r,n,i,s,o,a){return Cr(e+((t|~r)^n)+s+o|0,a)+i|0}function Za(e,t,r,n,i,s,o,a){return Cr(e+(t&n|r&~n)+s+o|0,a)+i|0}function Ja(e,t,r,n,i,s,o,a){return Cr(e+(t^(r|~n))+s+o|0,a)+i|0}var N0=ss,Rf={exports:{}},Cf=et.Buffer;function os(e,t){this._block=Cf.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}os.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Cf.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,f=Math.min(i-o,n-a),l=0;l<f;l++)r[a+l]=e[o+l];s+=f,o+=f,s%n===0&&this._update(r)}return this._len+=i,this};os.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};os.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var mn=os,H0=$e,Uf=mn,F0=et.Buffer,M0=[1518500249,1859775393,-1894007588,-899497514],D0=new Array(80);function Qn(){this.init(),this._w=D0,Uf.call(this,64,56)}H0(Qn,Uf);Qn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function $0(e){return e<<5|e>>>27}function j0(e){return e<<30|e>>>2}function z0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Qn.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 f=0;f<80;++f){var l=~~(f/20),d=$0(r)+z0(l,n,i,s)+o+t[f]+M0[l]|0;o=s,s=i,i=j0(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};Qn.prototype._hash=function(){var e=F0.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 q0=Qn,V0=$e,Lf=mn,G0=et.Buffer,W0=[1518500249,1859775393,-1894007588,-899497514],K0=new Array(80);function ei(){this.init(),this._w=K0,Lf.call(this,64,56)}V0(ei,Lf);ei.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Y0(e){return e<<1|e>>>31}function X0(e){return e<<5|e>>>27}function Z0(e){return e<<30|e>>>2}function J0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}ei.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]=Y0(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var f=0;f<80;++f){var l=~~(f/20),d=X0(r)+J0(l,n,i,s)+o+t[f]+W0[l]|0;o=s,s=i,i=Z0(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};ei.prototype._hash=function(){var e=G0.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 Q0=ei,ep=$e,Nf=mn,tp=et.Buffer,rp=[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],np=new Array(64);function ti(){this.init(),this._w=np,Nf.call(this,64,56)}ep(ti,Nf);ti.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 ip(e,t,r){return r^e&(t^r)}function sp(e,t,r){return e&t|r&(e|t)}function op(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function ap(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function cp(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function fp(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}ti.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,f=this._g|0,l=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=fp(t[d-2])+t[d-7]+cp(t[d-15])+t[d-16]|0;for(var p=0;p<64;++p){var w=l+ap(o)+ip(o,a,f)+rp[p]+t[p]|0,y=op(r)+sp(r,n,i)|0;l=f,f=a,a=o,o=s+w|0,s=i,i=n,n=r,r=w+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=f+this._g|0,this._h=l+this._h|0};ti.prototype._hash=function(){var e=tp.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 Hf=ti,up=$e,lp=Hf,dp=mn,hp=et.Buffer,pp=new Array(64);function as(){this.init(),this._w=pp,dp.call(this,64,56)}up(as,lp);as.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};as.prototype._hash=function(){var e=hp.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 yp=as,mp=$e,Ff=mn,bp=et.Buffer,Qa=[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],gp=new Array(160);function ri(){this.init(),this._w=gp,Ff.call(this,128,112)}mp(ri,Ff);ri.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 ec(e,t,r){return r^e&(t^r)}function tc(e,t,r){return e&t|r&(e|t)}function rc(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function nc(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function wp(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function _p(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function vp(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function Ep(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ue(e,t){return e>>>0<t>>>0?1:0}ri.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,f=this._gh|0,l=this._hh|0,d=this._al|0,p=this._bl|0,w=this._cl|0,y=this._dl|0,I=this._el|0,S=this._fl|0,_=this._gl|0,A=this._hl|0,k=0;k<32;k+=2)t[k]=e.readInt32BE(k*4),t[k+1]=e.readInt32BE(k*4+4);for(;k<160;k+=2){var E=t[k-30],v=t[k-15*2+1],B=wp(E,v),x=_p(v,E);E=t[k-2*2],v=t[k-2*2+1];var L=vp(E,v),M=Ep(v,E),P=t[k-7*2],G=t[k-7*2+1],K=t[k-16*2],C=t[k-16*2+1],j=x+G|0,N=B+P+Ue(j,x)|0;j=j+M|0,N=N+L+Ue(j,M)|0,j=j+C|0,N=N+K+Ue(j,C)|0,t[k]=N,t[k+1]=j}for(var $=0;$<160;$+=2){N=t[$],j=t[$+1];var z=tc(r,n,i),W=tc(d,p,w),J=rc(r,d),se=rc(d,r),be=nc(o,I),te=nc(I,o),fe=Qa[$],ge=Qa[$+1],Se=ec(o,a,f),je=ec(I,S,_),O=A+te|0,R=l+be+Ue(O,A)|0;O=O+je|0,R=R+Se+Ue(O,je)|0,O=O+ge|0,R=R+fe+Ue(O,ge)|0,O=O+j|0,R=R+N+Ue(O,j)|0;var D=se+W|0,Y=J+z+Ue(D,se)|0;l=f,A=_,f=a,_=S,a=o,S=I,I=y+O|0,o=s+R+Ue(I,y)|0,s=i,y=w,i=n,w=p,n=r,p=d,d=O+D|0,r=R+Y+Ue(d,O)|0}this._al=this._al+d|0,this._bl=this._bl+p|0,this._cl=this._cl+w|0,this._dl=this._dl+y|0,this._el=this._el+I|0,this._fl=this._fl+S|0,this._gl=this._gl+_|0,this._hl=this._hl+A|0,this._ah=this._ah+r+Ue(this._al,d)|0,this._bh=this._bh+n+Ue(this._bl,p)|0,this._ch=this._ch+i+Ue(this._cl,w)|0,this._dh=this._dh+s+Ue(this._dl,y)|0,this._eh=this._eh+o+Ue(this._el,I)|0,this._fh=this._fh+a+Ue(this._fl,S)|0,this._gh=this._gh+f+Ue(this._gl,_)|0,this._hh=this._hh+l+Ue(this._hl,A)|0};ri.prototype._hash=function(){var e=bp.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 Mf=ri,xp=$e,Sp=Mf,Ap=mn,Bp=et.Buffer,Ip=new Array(160);function cs(){this.init(),this._w=Ip,Ap.call(this,128,112)}xp(cs,Sp);cs.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};cs.prototype._hash=function(){var e=Bp.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 Tp=cs,Fr=Rf.exports=function(t){t=t.toLowerCase();var r=Fr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};Fr.sha=q0;Fr.sha1=Q0;Fr.sha224=yp;Fr.sha256=Hf;Fr.sha384=Tp;Fr.sha512=Mf;var kp=Rf.exports,Df=et.Buffer,$f=zo.Transform,Pp=Ni.StringDecoder,Op=$e;function wt(e){$f.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}Op(wt,$f);wt.prototype.update=function(e,t,r){typeof e=="string"&&(e=Df.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};wt.prototype.setAutoPadding=function(){};wt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};wt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};wt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};wt.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)}};wt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};wt.prototype._finalOrDigest=function(e){var t=this.__final()||Df.alloc(0);return e&&(t=this._toString(t,e,!0)),t};wt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Pp(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 Rp=wt,Cp=$e,Up=P0,Lp=N0,Np=kp,jf=Rp;function fs(e){jf.call(this,"digest"),this._hash=e}Cp(fs,jf);fs.prototype._update=function(e){this._hash.update(e)};fs.prototype._final=function(){return this._hash.digest()};var Hp=function(t){return t=t.toLowerCase(),t==="md5"?new Up:t==="rmd160"||t==="ripemd160"?new Lp:new fs(Np(t))},gi=et.Buffer;function Fp(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),f=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if((Array.isArray(y)||y instanceof Uint8Array)&&(y=gi.from(y)),!gi.isBuffer(y))throw new TypeError("Expected Buffer");if(y.length===0)return"";for(var I=0,S=0,_=0,A=y.length;_!==A&&y[_]===0;)_++,I++;for(var k=(A-_)*l+1>>>0,E=new Uint8Array(k);_!==A;){for(var v=y[_],B=0,x=k-1;(v!==0||B<S)&&x!==-1;x--,B++)v+=256*E[x]>>>0,E[x]=v%o>>>0,v=v/o>>>0;if(v!==0)throw new Error("Non-zero carry");S=B,_++}for(var L=k-S;L!==k&&E[L]===0;)L++;for(var M=a.repeat(I);L<k;++L)M+=e.charAt(E[L]);return M}function p(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return gi.alloc(0);for(var I=0,S=0,_=0;y[I]===a;)S++,I++;for(var A=(y.length-I)*f+1>>>0,k=new Uint8Array(A);I<y.length;){var E=t[y.charCodeAt(I)];if(E===255)return;for(var v=0,B=A-1;(E!==0||v<_)&&B!==-1;B--,v++)E+=o*k[B]>>>0,k[B]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");_=v,I++}for(var x=A-_;x!==A&&k[x]===0;)x++;var L=gi.allocUnsafe(S+(A-x));L.fill(0,0,S);for(var M=S;x!==A;)L[M++]=k[x++];return L}function w(y){var I=p(y);if(I)return I;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:p,decode:w}}var Mp=Fp,Dp=Mp,$p="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",jp=Dp($p),Gs=jp,zp=et.Buffer,qp=function(e){function t(s){var o=e(s);return Gs.encode(zp.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),f=e(o);if(!(a[0]^f[0]|a[1]^f[1]|a[2]^f[2]|a[3]^f[3]))return o}function n(s){var o=Gs.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Gs.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},ic=Hp,Vp=qp;function Gp(e){var t=ic("sha256").update(e).digest();return ic("sha256").update(t).digest()}var Wp=Vp(Gp),yo=Wp;function zf(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 mo(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 Kp(e,t){return zf(yo.decode(e),t)}function Yp(e,t,r){return typeof e=="number"?yo.encode(mo(e,t,r)):yo.encode(mo(e.version,e.privateKey,e.compressed))}var Xp={decode:Kp,decodeRaw:zf,encode:Yp,encodeRaw:mo},us={};Object.defineProperty(us,"__esModule",{value:!0});us.testEcc=void 0;const X=e=>Buffer.from(e,"hex");function Zp(e){_e(e.isPoint(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(!e.isPoint(X("030000000000000000000000000000000000000000000000000000000000000005"))),_e(e.isPrivate(X("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(e.isPrivate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),_e(!e.isPrivate(X("0000000000000000000000000000000000000000000000000000000000000000"))),_e(!e.isPrivate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),_e(!e.isPrivate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),_e(Buffer.from(e.privateAdd(X("0000000000000000000000000000000000000000000000000000000000000001"),X("0000000000000000000000000000000000000000000000000000000000000000"))).equals(X("0000000000000000000000000000000000000000000000000000000000000001"))),_e(e.privateAdd(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),X("0000000000000000000000000000000000000000000000000000000000000003"))===null),_e(Buffer.from(e.privateAdd(X("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),X("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(X("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),_e(Buffer.from(e.privateNegate(X("0000000000000000000000000000000000000000000000000000000000000001"))).equals(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),_e(Buffer.from(e.privateNegate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(X("0000000000000000000000000000000000000000000000000000000000000003"))),_e(Buffer.from(e.privateNegate(X("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(X("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),_e(Buffer.from(e.pointCompress(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(Buffer.from(e.pointCompress(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),_e(Buffer.from(e.pointCompress(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(Buffer.from(e.pointCompress(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),_e(Buffer.from(e.pointFromScalar(X("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(X("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),_e(e.xOnlyPointAddTweak(X("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(X("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),X("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));_e(Buffer.from(t.xOnlyPubkey).equals(X("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(X("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),X("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),_e(Buffer.from(t.xOnlyPubkey).equals(X("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),_e(Buffer.from(e.sign(X("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(X("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),_e(e.verify(X("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),X("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),X("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&_e(Buffer.from(e.signSchnorr(X("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),X("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),X("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(X("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&_e(e.verifySchnorr(X("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),X("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),X("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}us.testEcc=Zp;function _e(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(cn,"__esModule",{value:!0});cn.ECPairFactory=cn.networks=void 0;const bo=fn;cn.networks=bo;const Je=af,Jp=Eh,sc=Xp,Qp=us,Ws=Je.typeforce.maybe(Je.typeforce.compile({compressed:Je.maybe(Je.Boolean),network:Je.maybe(Je.Network)})),ey=e=>e.length===32?e:e.slice(1,33);function ty(e){(0,Qp.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,f){if(Je.typeforce(Je.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return Je.typeforce(Ws,f),new o(a,void 0,f)}function n(a,f){return Je.typeforce(e.isPoint,a),Je.typeforce(Ws,f),new o(void 0,a,f)}function i(a,f){const l=sc.decode(a),d=l.version;if(Je.Array(f)){if(f=f.filter(p=>d===p.wif).pop(),!f)throw new Error("Unknown network version")}else if(f=f||bo.bitcoin,d!==f.wif)throw new Error("Invalid network version");return r(l.privateKey,{compressed:l.compressed,network:f})}function s(a){Je.typeforce(Ws,a),a===void 0&&(a={});const f=a.rng||Jp;let l;do l=f(32),Je.typeforce(Je.Buffer256bit,l);while(!e.isPrivate(l));return r(l,a)}class o{constructor(f,l,d){jr(this,"__D");jr(this,"__Q");jr(this,"compressed");jr(this,"network");jr(this,"lowR");this.__D=f,this.__Q=l,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||bo.bitcoin,l!==void 0&&(this.__Q=Buffer.from(e.pointCompress(l,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const f=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(f)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return sc.encode(this.network.wif,this.__D,this.compressed)}tweak(f){return this.privateKey?this.tweakFromPrivateKey(f):this.tweakFromPublicKey(f)}sign(f,l){if(!this.__D)throw new Error("Missing private key");if(l===void 0&&(l=this.lowR),l===!1)return Buffer.from(e.sign(f,this.__D));{let d=e.sign(f,this.__D);const p=Buffer.alloc(32,0);let w=0;for(;d[0]>127;)w++,p.writeUIntLE(w,0,6),d=e.sign(f,this.__D,p);return Buffer.from(d)}}signSchnorr(f){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(f,this.privateKey))}verify(f,l){return e.verify(f,this.publicKey,l)}verifySchnorr(f,l){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(f,this.publicKey.subarray(1,33),l)}tweakFromPublicKey(f){const l=ey(this.publicKey),d=e.xOnlyPointAddTweak(l,f);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const p=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([p,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(f){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,p=e.privateAdd(d,f);if(!p)throw new Error("Invalid tweaked private key!");return r(Buffer.from(p),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}cn.ECPairFactory=ty;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=cn;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}})})(of);const ry=dl(of);class Gn extends Z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new Gn(Tt(t))}static fromWalletClient(t){return new Gn(void 0,t)}async initialize(){if(this.digestKey)return ce("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?V(t.error):(this.emit("initialized",!0),ce("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return V("No walletClient found");if(!this.walletClient.account)return V("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.digestKey=Tt($t.sha256(t)),this.emit("initialized",!0),ce(this.digestKey)}catch(t){return V("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return V("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return V(t.error)}return this.digestKey?ce(this.digestKey):V("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return V(r.error);const n=$t.sha256(Z.with0x(r.val)),i=$t.sha256(n);return ce({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const l=await this.getDigestKey();if(l.error)return V(l.error);this.digestKey=l.val}const r=ry(Pr),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=$t.sha256(i),o=Buffer.from(Tt(this.digestKey),"hex");if(o.length!==32)return V("Invalid private key length. Expected 32 bytes.");const f=r.fromPrivateKey(o).sign(Buffer.from(Tt(s),"hex"));return ce(f.toString("hex"))}}function Mi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ny(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ni(e,...t){if(!ny(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function iy(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Mi(e.outputLen),Mi(e.blockLen)}function ln(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function qf(e,t){ni(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Gr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function sy(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Ks(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function xt(e,t){return e<<32-t|e>>>t}const oc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function oy(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function ac(e){for(let t=0;t<e.length;t++)e[t]=oy(e[t])}function ay(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function ls(e){return typeof e=="string"&&(e=ay(e)),ni(e),e}function cy(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];ni(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}class Go{clone(){return this._cloneInto()}}function Vf(e){const t=n=>e().update(ls(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function fy(e=32){if(Gr&&typeof Gr.getRandomValues=="function")return Gr.getRandomValues(new Uint8Array(e));if(Gr&&typeof Gr.randomBytes=="function")return Gr.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function uy(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),f=n?4:0,l=n?0:4;e.setUint32(t+f,o,n),e.setUint32(t+l,a,n)}function ly(e,t,r){return e&t^~e&r}function dy(e,t,r){return e&t^e&r^t&r}class hy extends Go{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ks(this.buffer)}update(t){ln(this);const{view:r,buffer:n,blockLen:i}=this;t=ls(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const f=Ks(t);for(;i<=s-o;o+=i)this.process(f,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ln(this),qf(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let p=o;p<i;p++)r[p]=0;uy(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Ks(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=f/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,d[p],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}}const py=new Uint32Array([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]),ir=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),sr=new Uint32Array(64);class yy extends hy{constructor(){super(64,32,8,!1),this.A=ir[0]|0,this.B=ir[1]|0,this.C=ir[2]|0,this.D=ir[3]|0,this.E=ir[4]|0,this.F=ir[5]|0,this.G=ir[6]|0,this.H=ir[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:f}=this;return[t,r,n,i,s,o,a,f]}set(t,r,n,i,s,o,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=f|0}process(t,r){for(let p=0;p<16;p++,r+=4)sr[p]=t.getUint32(r,!1);for(let p=16;p<64;p++){const w=sr[p-15],y=sr[p-2],I=xt(w,7)^xt(w,18)^w>>>3,S=xt(y,17)^xt(y,19)^y>>>10;sr[p]=S+sr[p-7]+I+sr[p-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:f,G:l,H:d}=this;for(let p=0;p<64;p++){const w=xt(a,6)^xt(a,11)^xt(a,25),y=d+w+ly(a,f,l)+py[p]+sr[p]|0,S=(xt(n,2)^xt(n,13)^xt(n,22))+dy(n,i,s)|0;d=l,l=f,f=a,a=o+y|0,o=s,s=i,i=n,n=y+S|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,f,l,d)}roundClean(){sr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Gf=Vf(()=>new yy);class Wf extends Go{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,iy(t);const n=ls(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(n.length>i?t.create().update(n).digest():n);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return ln(this),this.iHash.update(t),this}digestInto(t){ln(this),ni(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Kf=(e,t,r)=>new Wf(e,t).update(r).digest();Kf.create=(e,t)=>new Wf(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ds=BigInt(0),hs=BigInt(1),my=BigInt(2);function Ur(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ii(e){if(!Ur(e))throw new Error("Uint8Array expected")}function dn(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}const by=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function hn(e){ii(e);let t="";for(let r=0;r<e.length;r++)t+=by[e[r]];return t}function Jr(e){const t=e.toString(16);return t.length&1?"0"+t:t}function Wo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ds:BigInt("0x"+e)}const Lt={_0:48,_9:57,A:65,F:70,a:97,f:102};function cc(e){if(e>=Lt._0&&e<=Lt._9)return e-Lt._0;if(e>=Lt.A&&e<=Lt.F)return e-(Lt.A-10);if(e>=Lt.a&&e<=Lt.f)return e-(Lt.a-10)}function pn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=cc(e.charCodeAt(s)),a=cc(e.charCodeAt(s+1));if(o===void 0||a===void 0){const f=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[i]=o*16+a}return n}function Tr(e){return Wo(hn(e))}function Ko(e){return ii(e),Wo(hn(Uint8Array.from(e).reverse()))}function yn(e,t){return pn(e.toString(16).padStart(t*2,"0"))}function Yo(e,t){return yn(e,t).reverse()}function gy(e){return pn(Jr(e))}function yt(e,t,r){let n;if(typeof t=="string")try{n=pn(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ur(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const i=n.length;if(typeof r=="number"&&i!==r)throw new Error(e+" of length "+r+" expected, got "+i);return n}function Wn(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];ii(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}function wy(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function _y(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}const Ys=e=>typeof e=="bigint"&&ds<=e;function ps(e,t,r){return Ys(e)&&Ys(t)&&Ys(r)&&t<=e&&e<r}function kr(e,t,r,n){if(!ps(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Yf(e){let t;for(t=0;e>ds;e>>=hs,t+=1);return t}function vy(e,t){return e>>BigInt(t)&hs}function Ey(e,t,r){return e|(r?hs:ds)<<BigInt(t)}const Xo=e=>(my<<BigInt(e-1))-hs,Xs=e=>new Uint8Array(e),fc=e=>Uint8Array.from(e);function Xf(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Xs(e),i=Xs(e),s=0;const o=()=>{n.fill(1),i.fill(0),s=0},a=(...p)=>r(i,n,...p),f=(p=Xs())=>{i=a(fc([0]),p),n=a(),p.length!==0&&(i=a(fc([1]),p),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let p=0;const w=[];for(;p<t;){n=a();const y=n.slice();w.push(y),p+=n.length}return Wn(...w)};return(p,w)=>{o(),f(p);let y;for(;!(y=w(l()));)f();return o(),y}}const xy={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Ur(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function si(e,t,r={}){const n=(i,s,o)=>{const a=xy[s];if(typeof a!="function")throw new Error("invalid validator function");const f=e[i];if(!(o&&f===void 0)&&!a(f,e))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+f)};for(const[i,s]of Object.entries(t))n(i,s,!1);for(const[i,s]of Object.entries(r))n(i,s,!0);return e}const Sy=()=>{throw new Error("not implemented")};function go(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(i!==void 0)return i;const s=e(r,...n);return t.set(r,s),s}}const Ay=Object.freeze(Object.defineProperty({__proto__:null,aInRange:kr,abool:dn,abytes:ii,bitGet:vy,bitLen:Yf,bitMask:Xo,bitSet:Ey,bytesToHex:hn,bytesToNumberBE:Tr,bytesToNumberLE:Ko,concatBytes:Wn,createHmacDrbg:Xf,ensureBytes:yt,equalBytes:wy,hexToBytes:pn,hexToNumber:Wo,inRange:ps,isBytes:Ur,memoized:go,notImplemented:Sy,numberToBytesBE:yn,numberToBytesLE:Yo,numberToHexUnpadded:Jr,numberToVarBytesBE:gy,utf8ToBytes:_y,validateObject:si},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ne=BigInt(0),Pe=BigInt(1),Ar=BigInt(2),By=BigInt(3),wo=BigInt(4),uc=BigInt(5),lc=BigInt(8);function tt(e,t){const r=e%t;return r>=Ne?r:t+r}function Iy(e,t,r){if(t<Ne)throw new Error("invalid exponent, negatives unsupported");if(r<=Ne)throw new Error("invalid modulus");if(r===Pe)return Ne;let n=Pe;for(;t>Ne;)t&Pe&&(n=n*e%r),e=e*e%r,t>>=Pe;return n}function ct(e,t,r){let n=e;for(;t-- >Ne;)n*=n,n%=r;return n}function _o(e,t){if(e===Ne)throw new Error("invert: expected non-zero number");if(t<=Ne)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,i=Ne,s=Pe;for(;r!==Ne;){const a=n/r,f=n%r,l=i-s*a;n=r,r=f,i=s,s=l}if(n!==Pe)throw new Error("invert: does not exist");return tt(i,t)}function Ty(e){const t=(e-Pe)/Ar;let r,n,i;for(r=e-Pe,n=0;r%Ar===Ne;r/=Ar,n++);for(i=Ar;i<e&&Iy(i,t,e)!==e-Pe;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const o=(e+Pe)/wo;return function(f,l){const d=f.pow(l,o);if(!f.eql(f.sqr(d),l))throw new Error("Cannot find square root");return d}}const s=(r+Pe)/Ar;return function(a,f){if(a.pow(f,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,d=a.pow(a.mul(a.ONE,i),r),p=a.pow(f,s),w=a.pow(f,r);for(;!a.eql(w,a.ONE);){if(a.eql(w,a.ZERO))return a.ZERO;let y=1;for(let S=a.sqr(w);y<l&&!a.eql(S,a.ONE);y++)S=a.sqr(S);const I=a.pow(d,Pe<<BigInt(l-y-1));d=a.sqr(I),p=a.mul(p,I),w=a.mul(w,d),l=y}return p}}function ky(e){if(e%wo===By){const t=(e+Pe)/wo;return function(n,i){const s=n.pow(i,t);if(!n.eql(n.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%lc===uc){const t=(e-uc)/lc;return function(n,i){const s=n.mul(i,Ar),o=n.pow(s,t),a=n.mul(i,o),f=n.mul(n.mul(a,Ar),o),l=n.mul(a,n.sub(f,n.ONE));if(!n.eql(n.sqr(l),i))throw new Error("Cannot find square root");return l}}return Ty(e)}const Py=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Oy(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Py.reduce((n,i)=>(n[i]="function",n),t);return si(e,r)}function Ry(e,t,r){if(r<Ne)throw new Error("invalid exponent, negatives unsupported");if(r===Ne)return e.ONE;if(r===Pe)return t;let n=e.ONE,i=t;for(;r>Ne;)r&Pe&&(n=e.mul(n,i)),i=e.sqr(i),r>>=Pe;return n}function Cy(e,t){const r=new Array(t.length),n=t.reduce((s,o,a)=>e.is0(o)?s:(r[a]=s,e.mul(s,o)),e.ONE),i=e.inv(n);return t.reduceRight((s,o,a)=>e.is0(o)?s:(r[a]=e.mul(s,r[a]),e.mul(s,o)),i),r}function Zf(e,t){const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Jf(e,t,r=!1,n={}){if(e<=Ne)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:i,nByteLength:s}=Zf(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:s,MASK:Xo(i),ZERO:Ne,ONE:Pe,create:f=>tt(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return Ne<=f&&f<e},is0:f=>f===Ne,isOdd:f=>(f&Pe)===Pe,neg:f=>tt(-f,e),eql:(f,l)=>f===l,sqr:f=>tt(f*f,e),add:(f,l)=>tt(f+l,e),sub:(f,l)=>tt(f-l,e),mul:(f,l)=>tt(f*l,e),pow:(f,l)=>Ry(a,f,l),div:(f,l)=>tt(f*_o(l,e),e),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>_o(f,e),sqrt:n.sqrt||(f=>(o||(o=ky(e)),o(a,f))),invertBatch:f=>Cy(a,f),cmov:(f,l,d)=>d?l:f,toBytes:f=>r?Yo(f,s):yn(f,s),fromBytes:f=>{if(f.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+f.length);return r?Ko(f):Tr(f)}});return Object.freeze(a)}function Qf(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function eu(e){const t=Qf(e);return t+Math.ceil(t/2)}function Uy(e,t,r=!1){const n=e.length,i=Qf(t),s=eu(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const o=r?Ko(e):Tr(e),a=tt(o,t-Pe)+Pe;return r?Yo(a,i):yn(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dc=BigInt(0),wi=BigInt(1);function Zs(e,t){const r=t.negate();return e?r:t}function tu(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Js(e,t){tu(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function Ly(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ny(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}const Qs=new WeakMap,ru=new WeakMap;function eo(e){return ru.get(e)||1}function Hy(e,t){return{constTimeNegate:Zs,hasPrecomputes(r){return eo(r)!==1},unsafeLadder(r,n,i=e.ZERO){let s=r;for(;n>dc;)n&wi&&(i=i.add(s)),s=s.double(),n>>=wi;return i},precomputeWindow(r,n){const{windows:i,windowSize:s}=Js(n,t),o=[];let a=r,f=a;for(let l=0;l<i;l++){f=a,o.push(f);for(let d=1;d<s;d++)f=f.add(a),o.push(f);a=f.double()}return o},wNAF(r,n,i){const{windows:s,windowSize:o}=Js(r,t);let a=e.ZERO,f=e.BASE;const l=BigInt(2**r-1),d=2**r,p=BigInt(r);for(let w=0;w<s;w++){const y=w*o;let I=Number(i&l);i>>=p,I>o&&(I-=d,i+=wi);const S=y,_=y+Math.abs(I)-1,A=w%2!==0,k=I<0;I===0?f=f.add(Zs(A,n[S])):a=a.add(Zs(k,n[_]))}return{p:a,f}},wNAFUnsafe(r,n,i,s=e.ZERO){const{windows:o,windowSize:a}=Js(r,t),f=BigInt(2**r-1),l=2**r,d=BigInt(r);for(let p=0;p<o;p++){const w=p*a;if(i===dc)break;let y=Number(i&f);if(i>>=d,y>a&&(y-=l,i+=wi),y===0)continue;let I=n[w+Math.abs(y)-1];y<0&&(I=I.negate()),s=s.add(I)}return s},getPrecomputes(r,n,i){let s=Qs.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Qs.set(n,i(s))),s},wNAFCached(r,n,i){const s=eo(r);return this.wNAF(s,this.getPrecomputes(s,r,i),n)},wNAFCachedUnsafe(r,n,i,s){const o=eo(r);return o===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,i),n,s)},setWindowSize(r,n){tu(n,t),ru.set(r,n),Qs.delete(r)}}}function Fy(e,t,r,n){if(Ly(r,e),Ny(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=e.ZERO,s=Yf(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,f=new Array(a+1).fill(i),l=Math.floor((t.BITS-1)/o)*o;let d=i;for(let p=l;p>=0;p-=o){f.fill(i);for(let y=0;y<n.length;y++){const I=n[y],S=Number(I>>BigInt(p)&BigInt(a));f[S]=f[S].add(r[y])}let w=i;for(let y=f.length-1,I=i;y>0;y--)I=I.add(f[y]),w=w.add(I);if(d=d.add(w),p!==0)for(let y=0;y<o;y++)d=d.double()}return d}function nu(e){return Oy(e.Fp),si(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Zf(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function hc(e){e.lowS!==void 0&&dn("lowS",e.lowS),e.prehash!==void 0&&dn("prehash",e.prehash)}function My(e){const t=nu(e);si(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:i}=t;if(r){if(!n.eql(i,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:Dy,hexToBytes:$y}=Ay;class jy extends Error{constructor(t=""){super(t)}}const Ft={Err:jy,_tlv:{encode:(e,t)=>{const{Err:r}=Ft;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");const n=t.length/2,i=Jr(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const s=n>127?Jr(i.length/2|128):"";return Jr(e)+s+i+t},decode(e,t){const{Err:r}=Ft;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const i=t[n++],s=!!(i&128);let o=0;if(!s)o=i;else{const f=i&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");const l=t.subarray(n,n+f);if(l.length!==f)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const d of l)o=o<<8|d;if(n+=f,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){const{Err:t}=Ft;if(e<Dt)throw new t("integer: negative integers are not allowed");let r=Jr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=Ft;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Dy(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=Ft,i=typeof e=="string"?$y(e):e;ii(i);const{v:s,l:o}=n.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:f}=n.decode(2,s),{v:l,l:d}=n.decode(2,f);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(e){const{_tlv:t,_int:r}=Ft,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s)),s=n+i;return t.encode(48,s)}},Dt=BigInt(0),Le=BigInt(1);BigInt(2);const pc=BigInt(3);BigInt(4);function zy(e){const t=My(e),{Fp:r}=t,n=Jf(t.n,t.nBitLength),i=t.toBytes||((S,_,A)=>{const k=_.toAffine();return Wn(Uint8Array.from([4]),r.toBytes(k.x),r.toBytes(k.y))}),s=t.fromBytes||(S=>{const _=S.subarray(1),A=r.fromBytes(_.subarray(0,r.BYTES)),k=r.fromBytes(_.subarray(r.BYTES,2*r.BYTES));return{x:A,y:k}});function o(S){const{a:_,b:A}=t,k=r.sqr(S),E=r.mul(k,S);return r.add(r.add(E,r.mul(S,_)),A)}if(!r.eql(r.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function a(S){return ps(S,Le,t.n)}function f(S){const{allowedPrivateKeyLengths:_,nByteLength:A,wrapPrivateKey:k,n:E}=t;if(_&&typeof S!="bigint"){if(Ur(S)&&(S=hn(S)),typeof S!="string"||!_.includes(S.length))throw new Error("invalid private key");S=S.padStart(A*2,"0")}let v;try{v=typeof S=="bigint"?S:Tr(yt("private key",S,A))}catch{throw new Error("invalid private key, expected hex or "+A+" bytes, got "+typeof S)}return k&&(v=tt(v,E)),kr("private key",v,Le,E),v}function l(S){if(!(S instanceof w))throw new Error("ProjectivePoint expected")}const d=go((S,_)=>{const{px:A,py:k,pz:E}=S;if(r.eql(E,r.ONE))return{x:A,y:k};const v=S.is0();_==null&&(_=v?r.ONE:r.inv(E));const B=r.mul(A,_),x=r.mul(k,_),L=r.mul(E,_);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:B,y:x}}),p=go(S=>{if(S.is0()){if(t.allowInfinityPoint&&!r.is0(S.py))return;throw new Error("bad point: ZERO")}const{x:_,y:A}=S.toAffine();if(!r.isValid(_)||!r.isValid(A))throw new Error("bad point: x or y not FE");const k=r.sqr(A),E=o(_);if(!r.eql(k,E))throw new Error("bad point: equation left != right");if(!S.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(_,A,k){if(this.px=_,this.py=A,this.pz=k,_==null||!r.isValid(_))throw new Error("x required");if(A==null||!r.isValid(A))throw new Error("y required");if(k==null||!r.isValid(k))throw new Error("z required");Object.freeze(this)}static fromAffine(_){const{x:A,y:k}=_||{};if(!_||!r.isValid(A)||!r.isValid(k))throw new Error("invalid affine point");if(_ instanceof w)throw new Error("projective point not allowed");const E=v=>r.eql(v,r.ZERO);return E(A)&&E(k)?w.ZERO:new w(A,k,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(_){const A=r.invertBatch(_.map(k=>k.pz));return _.map((k,E)=>k.toAffine(A[E])).map(w.fromAffine)}static fromHex(_){const A=w.fromAffine(s(yt("pointHex",_)));return A.assertValidity(),A}static fromPrivateKey(_){return w.BASE.multiply(f(_))}static msm(_,A){return Fy(w,n,_,A)}_setWindowSize(_){I.setWindowSize(this,_)}assertValidity(){p(this)}hasEvenY(){const{y:_}=this.toAffine();if(r.isOdd)return!r.isOdd(_);throw new Error("Field doesn't support isOdd")}equals(_){l(_);const{px:A,py:k,pz:E}=this,{px:v,py:B,pz:x}=_,L=r.eql(r.mul(A,x),r.mul(v,E)),M=r.eql(r.mul(k,x),r.mul(B,E));return L&&M}negate(){return new w(this.px,r.neg(this.py),this.pz)}double(){const{a:_,b:A}=t,k=r.mul(A,pc),{px:E,py:v,pz:B}=this;let x=r.ZERO,L=r.ZERO,M=r.ZERO,P=r.mul(E,E),G=r.mul(v,v),K=r.mul(B,B),C=r.mul(E,v);return C=r.add(C,C),M=r.mul(E,B),M=r.add(M,M),x=r.mul(_,M),L=r.mul(k,K),L=r.add(x,L),x=r.sub(G,L),L=r.add(G,L),L=r.mul(x,L),x=r.mul(C,x),M=r.mul(k,M),K=r.mul(_,K),C=r.sub(P,K),C=r.mul(_,C),C=r.add(C,M),M=r.add(P,P),P=r.add(M,P),P=r.add(P,K),P=r.mul(P,C),L=r.add(L,P),K=r.mul(v,B),K=r.add(K,K),P=r.mul(K,C),x=r.sub(x,P),M=r.mul(K,G),M=r.add(M,M),M=r.add(M,M),new w(x,L,M)}add(_){l(_);const{px:A,py:k,pz:E}=this,{px:v,py:B,pz:x}=_;let L=r.ZERO,M=r.ZERO,P=r.ZERO;const G=t.a,K=r.mul(t.b,pc);let C=r.mul(A,v),j=r.mul(k,B),N=r.mul(E,x),$=r.add(A,k),z=r.add(v,B);$=r.mul($,z),z=r.add(C,j),$=r.sub($,z),z=r.add(A,E);let W=r.add(v,x);return z=r.mul(z,W),W=r.add(C,N),z=r.sub(z,W),W=r.add(k,E),L=r.add(B,x),W=r.mul(W,L),L=r.add(j,N),W=r.sub(W,L),P=r.mul(G,z),L=r.mul(K,N),P=r.add(L,P),L=r.sub(j,P),P=r.add(j,P),M=r.mul(L,P),j=r.add(C,C),j=r.add(j,C),N=r.mul(G,N),z=r.mul(K,z),j=r.add(j,N),N=r.sub(C,N),N=r.mul(G,N),z=r.add(z,N),C=r.mul(j,z),M=r.add(M,C),C=r.mul(W,z),L=r.mul($,L),L=r.sub(L,C),C=r.mul($,j),P=r.mul(W,P),P=r.add(P,C),new w(L,M,P)}subtract(_){return this.add(_.negate())}is0(){return this.equals(w.ZERO)}wNAF(_){return I.wNAFCached(this,_,w.normalizeZ)}multiplyUnsafe(_){const{endo:A,n:k}=t;kr("scalar",_,Dt,k);const E=w.ZERO;if(_===Dt)return E;if(this.is0()||_===Le)return this;if(!A||I.hasPrecomputes(this))return I.wNAFCachedUnsafe(this,_,w.normalizeZ);let{k1neg:v,k1:B,k2neg:x,k2:L}=A.splitScalar(_),M=E,P=E,G=this;for(;B>Dt||L>Dt;)B&Le&&(M=M.add(G)),L&Le&&(P=P.add(G)),G=G.double(),B>>=Le,L>>=Le;return v&&(M=M.negate()),x&&(P=P.negate()),P=new w(r.mul(P.px,A.beta),P.py,P.pz),M.add(P)}multiply(_){const{endo:A,n:k}=t;kr("scalar",_,Le,k);let E,v;if(A){const{k1neg:B,k1:x,k2neg:L,k2:M}=A.splitScalar(_);let{p:P,f:G}=this.wNAF(x),{p:K,f:C}=this.wNAF(M);P=I.constTimeNegate(B,P),K=I.constTimeNegate(L,K),K=new w(r.mul(K.px,A.beta),K.py,K.pz),E=P.add(K),v=G.add(C)}else{const{p:B,f:x}=this.wNAF(_);E=B,v=x}return w.normalizeZ([E,v])[0]}multiplyAndAddUnsafe(_,A,k){const E=w.BASE,v=(x,L)=>L===Dt||L===Le||!x.equals(E)?x.multiplyUnsafe(L):x.multiply(L),B=v(this,A).add(v(_,k));return B.is0()?void 0:B}toAffine(_){return d(this,_)}isTorsionFree(){const{h:_,isTorsionFree:A}=t;if(_===Le)return!0;if(A)return A(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:_,clearCofactor:A}=t;return _===Le?this:A?A(w,this):this.multiplyUnsafe(t.h)}toRawBytes(_=!0){return dn("isCompressed",_),this.assertValidity(),i(w,this,_)}toHex(_=!0){return dn("isCompressed",_),hn(this.toRawBytes(_))}}w.BASE=new w(t.Gx,t.Gy,r.ONE),w.ZERO=new w(r.ZERO,r.ONE,r.ZERO);const y=t.nBitLength,I=Hy(w,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:w,normPrivateKeyToScalar:f,weierstrassEquation:o,isWithinCurveOrder:a}}function qy(e){const t=nu(e);return si(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Vy(e){const t=qy(e),{Fp:r,n}=t,i=r.BYTES+1,s=2*r.BYTES+1;function o(N){return tt(N,n)}function a(N){return _o(N,n)}const{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:d,isWithinCurveOrder:p}=zy({...t,toBytes(N,$,z){const W=$.toAffine(),J=r.toBytes(W.x),se=Wn;return dn("isCompressed",z),z?se(Uint8Array.from([$.hasEvenY()?2:3]),J):se(Uint8Array.from([4]),J,r.toBytes(W.y))},fromBytes(N){const $=N.length,z=N[0],W=N.subarray(1);if($===i&&(z===2||z===3)){const J=Tr(W);if(!ps(J,Le,r.ORDER))throw new Error("Point is not on curve");const se=d(J);let be;try{be=r.sqrt(se)}catch(ge){const Se=ge instanceof Error?": "+ge.message:"";throw new Error("Point is not on curve"+Se)}const te=(be&Le)===Le;return(z&1)===1!==te&&(be=r.neg(be)),{x:J,y:be}}else if($===s&&z===4){const J=r.fromBytes(W.subarray(0,r.BYTES)),se=r.fromBytes(W.subarray(r.BYTES,2*r.BYTES));return{x:J,y:se}}else{const J=i,se=s;throw new Error("invalid Point, expected length of "+J+", or uncompressed "+se+", got "+$)}}}),w=N=>hn(yn(N,t.nByteLength));function y(N){const $=n>>Le;return N>$}function I(N){return y(N)?o(-N):N}const S=(N,$,z)=>Tr(N.slice($,z));class _{constructor($,z,W){this.r=$,this.s=z,this.recovery=W,this.assertValidity()}static fromCompact($){const z=t.nByteLength;return $=yt("compactSignature",$,z*2),new _(S($,0,z),S($,z,2*z))}static fromDER($){const{r:z,s:W}=Ft.toSig(yt("DER",$));return new _(z,W)}assertValidity(){kr("r",this.r,Le,n),kr("s",this.s,Le,n)}addRecoveryBit($){return new _(this.r,this.s,$)}recoverPublicKey($){const{r:z,s:W,recovery:J}=this,se=x(yt("msgHash",$));if(J==null||![0,1,2,3].includes(J))throw new Error("recovery id invalid");const be=J===2||J===3?z+t.n:z;if(be>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const te=J&1?"03":"02",fe=f.fromHex(te+w(be)),ge=a(be),Se=o(-se*ge),je=o(W*ge),O=f.BASE.multiplyAndAddUnsafe(fe,Se,je);if(!O)throw new Error("point at infinify");return O.assertValidity(),O}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new _(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return pn(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return pn(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const A={isValidPrivateKey(N){try{return l(N),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const N=eu(t.n);return Uy(t.randomBytes(N),t.n)},precompute(N=8,$=f.BASE){return $._setWindowSize(N),$.multiply(BigInt(3)),$}};function k(N,$=!0){return f.fromPrivateKey(N).toRawBytes($)}function E(N){const $=Ur(N),z=typeof N=="string",W=($||z)&&N.length;return $?W===i||W===s:z?W===2*i||W===2*s:N instanceof f}function v(N,$,z=!0){if(E(N))throw new Error("first arg must be private key");if(!E($))throw new Error("second arg must be public key");return f.fromHex($).multiply(l(N)).toRawBytes(z)}const B=t.bits2int||function(N){if(N.length>8192)throw new Error("input is too large");const $=Tr(N),z=N.length*8-t.nBitLength;return z>0?$>>BigInt(z):$},x=t.bits2int_modN||function(N){return o(B(N))},L=Xo(t.nBitLength);function M(N){return kr("num < 2^"+t.nBitLength,N,Dt,L),yn(N,t.nByteLength)}function P(N,$,z=G){if(["recovered","canonical"].some(D=>D in z))throw new Error("sign() legacy options not supported");const{hash:W,randomBytes:J}=t;let{lowS:se,prehash:be,extraEntropy:te}=z;se==null&&(se=!0),N=yt("msgHash",N),hc(z),be&&(N=yt("prehashed msgHash",W(N)));const fe=x(N),ge=l($),Se=[M(ge),M(fe)];if(te!=null&&te!==!1){const D=te===!0?J(r.BYTES):te;Se.push(yt("extraEntropy",D))}const je=Wn(...Se),O=fe;function R(D){const Y=B(D);if(!p(Y))return;const Q=a(Y),b=f.BASE.multiply(Y).toAffine(),g=o(b.x);if(g===Dt)return;const F=o(Q*o(O+g*ge));if(F===Dt)return;let q=(b.x===g?0:2)|Number(b.y&Le),ue=F;return se&&y(F)&&(ue=I(F),q^=1),new _(g,ue,q)}return{seed:je,k2sig:R}}const G={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function C(N,$,z=G){const{seed:W,k2sig:J}=P(N,$,z),se=t;return Xf(se.hash.outputLen,se.nByteLength,se.hmac)(W,J)}f.BASE._setWindowSize(8);function j(N,$,z,W=K){var q;const J=N;$=yt("msgHash",$),z=yt("publicKey",z);const{lowS:se,prehash:be,format:te}=W;if(hc(W),"strict"in W)throw new Error("options.strict was renamed to lowS");if(te!==void 0&&te!=="compact"&&te!=="der")throw new Error("format must be compact or der");const fe=typeof J=="string"||Ur(J),ge=!fe&&!te&&typeof J=="object"&&J!==null&&typeof J.r=="bigint"&&typeof J.s=="bigint";if(!fe&&!ge)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Se,je;try{if(ge&&(Se=new _(J.r,J.s)),fe){try{te!=="compact"&&(Se=_.fromDER(J))}catch(ue){if(!(ue instanceof Ft.Err))throw ue}!Se&&te!=="der"&&(Se=_.fromCompact(J))}je=f.fromHex(z)}catch{return!1}if(!Se||se&&Se.hasHighS())return!1;be&&($=t.hash($));const{r:O,s:R}=Se,D=x($),Y=a(R),Q=o(D*Y),b=o(O*Y),g=(q=f.BASE.multiplyAndAddUnsafe(je,Q,b))==null?void 0:q.toAffine();return g?o(g.x)===O:!1}return{CURVE:t,getPublicKey:k,getSharedSecret:v,sign:C,verify:j,ProjectivePoint:f,Signature:_,utils:A}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Gy(e){return{hash:e,hmac:(t,...r)=>Kf(e,t,cy(...r)),randomBytes:fy}}function Wy(e,t){const r=n=>Vy({...e,...Gy(n)});return{...r(t),create:r}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const iu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),yc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ky=BigInt(1),vo=BigInt(2),mc=(e,t)=>(e+t/vo)/t;function Yy(e){const t=iu,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),f=BigInt(88),l=e*e*e%t,d=l*l*e%t,p=ct(d,r,t)*d%t,w=ct(p,r,t)*d%t,y=ct(w,vo,t)*l%t,I=ct(y,i,t)*y%t,S=ct(I,s,t)*I%t,_=ct(S,a,t)*S%t,A=ct(_,f,t)*_%t,k=ct(A,a,t)*S%t,E=ct(k,r,t)*d%t,v=ct(E,o,t)*I%t,B=ct(v,n,t)*l%t,x=ct(B,vo,t);if(!Eo.eql(Eo.sqr(x),e))throw new Error("Cannot find square root");return x}const Eo=Jf(iu,void 0,void 0,{sqrt:Yy}),ys=Wy({a:BigInt(0),b:BigInt(7),Fp:Eo,n:yc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=yc,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ky*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,o=BigInt("0x100000000000000000000000000000000"),a=mc(s*e,t),f=mc(-n*e,t);let l=tt(e-a*r-f*i,t),d=tt(-a*n-f*s,t);const p=l>o,w=d>o;if(p&&(l=t-l),w&&(d=t-d),l>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:p,k1:l,k2neg:w,k2:d}}}},Gf);BigInt(0);ys.ProjectivePoint;const su="2.22.23";let Rn={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${su}`};class oe extends Error{constructor(t,r={}){var a;const n=(()=>{var f;return r.cause instanceof oe?r.cause.details:(f=r.cause)!=null&&f.message?r.cause.message:r.details})(),i=r.cause instanceof oe&&r.cause.docsPath||r.docsPath,s=(a=Rn.getDocsUrl)==null?void 0:a.call(Rn,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...Rn.version?[`Version: ${Rn.version}`]:[]].join(`
|
|
30
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var af={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Lc,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})(af);var fo={exports:{}},uo={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Yt,n=r.Buffer;function i(o,a){for(var f in o)a[f]=o[f]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=s);function s(o,a,f){return n(o,a,f)}s.prototype=Object.create(n.prototype),i(n,s),s.from=function(o,a,f){if(typeof o=="number")throw new TypeError("Argument must not be a number");return n(o,a,f)},s.alloc=function(o,a,f){if(typeof o!="number")throw new TypeError("Argument must be a number");var l=n(o);return a!==void 0?typeof f=="string"?l.fill(a,f):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)}})(uo,uo.exports);var tt=uo.exports,Ls=65536,gh=4294967295;function wh(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
31
|
+
Use Chrome, Firefox or Internet Explorer 11`)}var _h=tt.Buffer,Li=hr.crypto||hr.msCrypto;Li&&Li.getRandomValues?fo.exports=vh:fo.exports=wh;function vh(e,t){if(e>gh)throw new RangeError("requested too many random bytes");var r=_h.allocUnsafe(e);if(e>0)if(e>Ls)for(var n=0;n<e;n+=Ls)Li.getRandomValues(r.slice(n,n+Ls));else Li.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Eh=fo.exports,lo={exports:{}};typeof Object.create=="function"?lo.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:lo.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 $e=lo.exports,ho={exports:{}},jo={exports:{}},rn=typeof Reflect=="object"?Reflect:null,Ca=rn&&typeof rn.apply=="function"?rn.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Pi;rn&&typeof rn.ownKeys=="function"?Pi=rn.ownKeys:Object.getOwnPropertySymbols?Pi=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Pi=function(t){return Object.getOwnPropertyNames(t)};function xh(e){console&&console.warn&&console.warn(e)}var cf=Number.isNaN||function(t){return t!==t};function he(){he.init.call(this)}jo.exports=he;jo.exports.once=Ih;he.EventEmitter=he;he.prototype._events=void 0;he.prototype._eventsCount=0;he.prototype._maxListeners=void 0;var Ua=10;function es(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(he,"defaultMaxListeners",{enumerable:!0,get:function(){return Ua},set:function(e){if(typeof e!="number"||e<0||cf(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ua=e}});he.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};he.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||cf(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 ff(e){return e._maxListeners===void 0?he.defaultMaxListeners:e._maxListeners}he.prototype.getMaxListeners=function(){return ff(this)};he.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 f=s[t];if(f===void 0)return!1;if(typeof f=="function")Ca(f,this,r);else for(var l=f.length,d=pf(f,l),n=0;n<l;++n)Ca(d[n],this,r);return!0};function uf(e,t,r,n){var i,s,o;if(es(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=ff(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,xh(a)}return e}he.prototype.addListener=function(t,r){return uf(this,t,r,!1)};he.prototype.on=he.prototype.addListener;he.prototype.prependListener=function(t,r){return uf(this,t,r,!0)};function Sh(){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 lf(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Sh.bind(n);return i.listener=r,n.wrapFn=i,i}he.prototype.once=function(t,r){return es(r),this.on(t,lf(this,t,r)),this};he.prototype.prependOnceListener=function(t,r){return es(r),this.prependListener(t,lf(this,t,r)),this};he.prototype.removeListener=function(t,r){var n,i,s,o,a;if(es(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():Ah(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};he.prototype.off=he.prototype.removeListener;he.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 df(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?Bh(i):pf(i,i.length)}he.prototype.listeners=function(t){return df(this,t,!0)};he.prototype.rawListeners=function(t){return df(this,t,!1)};he.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):hf.call(e,t)};he.prototype.listenerCount=hf;function hf(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}he.prototype.eventNames=function(){return this._eventsCount>0?Pi(this._events):[]};function pf(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Ah(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Bh(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Ih(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))}yf(e,t,s,{once:!0}),t!=="error"&&Th(e,i,{once:!0})})}function Th(e,t,r){typeof e.on=="function"&&yf(e,"error",t,r)}function yf(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 mf=jo.exports,bf=mf.EventEmitter;const kh={},Ph=Object.freeze(Object.defineProperty({__proto__:null,default:kh},Symbol.toStringTag,{value:"Module"})),zo=hl(Ph);var Ns,La;function Oh(){if(La)return Ns;La=1;function e(I,S){var _=Object.keys(I);if(Object.getOwnPropertySymbols){var A=Object.getOwnPropertySymbols(I);S&&(A=A.filter(function(k){return Object.getOwnPropertyDescriptor(I,k).enumerable})),_.push.apply(_,A)}return _}function t(I){for(var S=1;S<arguments.length;S++){var _=arguments[S]!=null?arguments[S]:{};S%2?e(Object(_),!0).forEach(function(A){r(I,A,_[A])}):Object.getOwnPropertyDescriptors?Object.defineProperties(I,Object.getOwnPropertyDescriptors(_)):e(Object(_)).forEach(function(A){Object.defineProperty(I,A,Object.getOwnPropertyDescriptor(_,A))})}return I}function r(I,S,_){return S=o(S),S in I?Object.defineProperty(I,S,{value:_,enumerable:!0,configurable:!0,writable:!0}):I[S]=_,I}function n(I,S){if(!(I instanceof S))throw new TypeError("Cannot call a class as a function")}function i(I,S){for(var _=0;_<S.length;_++){var A=S[_];A.enumerable=A.enumerable||!1,A.configurable=!0,"value"in A&&(A.writable=!0),Object.defineProperty(I,o(A.key),A)}}function s(I,S,_){return S&&i(I.prototype,S),Object.defineProperty(I,"prototype",{writable:!1}),I}function o(I){var S=a(I,"string");return typeof S=="symbol"?S:String(S)}function a(I,S){if(typeof I!="object"||I===null)return I;var _=I[Symbol.toPrimitive];if(_!==void 0){var A=_.call(I,S||"default");if(typeof A!="object")return A;throw new TypeError("@@toPrimitive must return a primitive value.")}return(S==="string"?String:Number)(I)}var f=Yt,l=f.Buffer,d=zo,p=d.inspect,w=p&&p.custom||"inspect";function y(I,S,_){l.prototype.copy.call(I,S,_)}return Ns=function(){function I(){n(this,I),this.head=null,this.tail=null,this.length=0}return s(I,[{key:"push",value:function(_){var A={data:_,next:null};this.length>0?this.tail.next=A:this.head=A,this.tail=A,++this.length}},{key:"unshift",value:function(_){var A={data:_,next:this.head};this.length===0&&(this.tail=A),this.head=A,++this.length}},{key:"shift",value:function(){if(this.length!==0){var _=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,_}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(_){if(this.length===0)return"";for(var A=this.head,k=""+A.data;A=A.next;)k+=_+A.data;return k}},{key:"concat",value:function(_){if(this.length===0)return l.alloc(0);for(var A=l.allocUnsafe(_>>>0),k=this.head,E=0;k;)y(k.data,A,E),E+=k.data.length,k=k.next;return A}},{key:"consume",value:function(_,A){var k;return _<this.head.data.length?(k=this.head.data.slice(0,_),this.head.data=this.head.data.slice(_)):_===this.head.data.length?k=this.shift():k=A?this._getString(_):this._getBuffer(_),k}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(_){var A=this.head,k=1,E=A.data;for(_-=E.length;A=A.next;){var v=A.data,B=_>v.length?v.length:_;if(B===v.length?E+=v:E+=v.slice(0,_),_-=B,_===0){B===v.length?(++k,A.next?this.head=A.next:this.head=this.tail=null):(this.head=A,A.data=v.slice(B));break}++k}return this.length-=k,E}},{key:"_getBuffer",value:function(_){var A=l.allocUnsafe(_),k=this.head,E=1;for(k.data.copy(A),_-=k.data.length;k=k.next;){var v=k.data,B=_>v.length?v.length:_;if(v.copy(A,A.length-_,0,B),_-=B,_===0){B===v.length?(++E,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=v.slice(B));break}++E}return this.length-=E,A}},{key:w,value:function(_,A){return p(this,t(t({},A),{},{depth:0,customInspect:!1}))}}]),I}(),Ns}function Rh(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(po,this,e)):process.nextTick(po,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(Oi,r):(r._writableState.errorEmitted=!0,process.nextTick(Na,r,s)):process.nextTick(Na,r,s):t?(process.nextTick(Oi,r),t(s)):process.nextTick(Oi,r)}),this)}function Na(e,t){po(e,t),Oi(e)}function Oi(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Ch(){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 po(e,t){e.emit("error",t)}function Uh(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var gf={destroy:Rh,undestroy:Ch,errorOrDestroy:Uh},Hr={};function Lh(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var wf={};function ht(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){Lh(o,s);function o(a,f,l){return s.call(this,n(a,f,l))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,wf[e]=i}function Ha(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 Nh(e,t,r){return e.substr(0,t.length)===t}function Hh(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Fh(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}ht("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);ht("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&Nh(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(Hh(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Ha(t,"type"));else{var s=Fh(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Ha(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);ht("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");ht("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});ht("ERR_STREAM_PREMATURE_CLOSE","Premature close");ht("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});ht("ERR_MULTIPLE_CALLBACK","Callback called multiple times");ht("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");ht("ERR_STREAM_WRITE_AFTER_END","write after end");ht("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);ht("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);ht("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");Hr.codes=wf;var Mh=Hr.codes.ERR_INVALID_OPT_VALUE;function Dh(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function $h(e,t,r,n){var i=Dh(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new Mh(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var _f={getHighWaterMark:$h},jh=zh;function zh(e,t){if(Hs("noDeprecation"))return e;var r=!1;function n(){if(!r){if(Hs("throwDeprecation"))throw new Error(t);Hs("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function Hs(e){try{if(!hr.localStorage)return!1}catch{return!1}var t=hr.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Fs,Fa;function vf(){if(Fa)return Fs;Fa=1,Fs=M;function e(O){var R=this;this.next=null,this.entry=null,this.finish=function(){je(R,O)}}var t;M.WritableState=x;var r={deprecate:jh},n=bf,i=Yt.Buffer,s=(typeof hr<"u"?hr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(O){return i.from(O)}function a(O){return i.isBuffer(O)||O instanceof s}var f=gf,l=_f,d=l.getHighWaterMark,p=Hr.codes,w=p.ERR_INVALID_ARG_TYPE,y=p.ERR_METHOD_NOT_IMPLEMENTED,I=p.ERR_MULTIPLE_CALLBACK,S=p.ERR_STREAM_CANNOT_PIPE,_=p.ERR_STREAM_DESTROYED,A=p.ERR_STREAM_NULL_VALUES,k=p.ERR_STREAM_WRITE_AFTER_END,E=p.ERR_UNKNOWN_ENCODING,v=f.errorOrDestroy;$e(M,n);function B(){}function x(O,R,D){t=t||un(),O=O||{},typeof D!="boolean"&&(D=R instanceof t),this.objectMode=!!O.objectMode,D&&(this.objectMode=this.objectMode||!!O.writableObjectMode),this.highWaterMark=d(this,O,"writableHighWaterMark",D),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var Y=O.decodeStrings===!1;this.decodeStrings=!Y,this.defaultEncoding=O.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(Q){z(R,Q)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=O.emitClose!==!1,this.autoDestroy=!!O.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}x.prototype.getBuffer=function(){for(var R=this.bufferedRequest,D=[];R;)D.push(R),R=R.next;return D},function(){try{Object.defineProperty(x.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var L;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(L=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(R){return L.call(this,R)?!0:this!==M?!1:R&&R._writableState instanceof x}})):L=function(R){return R instanceof this};function M(O){t=t||un();var R=this instanceof t;if(!R&&!L.call(M,this))return new M(O);this._writableState=new x(O,this,R),this.writable=!0,O&&(typeof O.write=="function"&&(this._write=O.write),typeof O.writev=="function"&&(this._writev=O.writev),typeof O.destroy=="function"&&(this._destroy=O.destroy),typeof O.final=="function"&&(this._final=O.final)),n.call(this)}M.prototype.pipe=function(){v(this,new S)};function P(O,R){var D=new k;v(O,D),process.nextTick(R,D)}function G(O,R,D,Y){var Q;return D===null?Q=new A:typeof D!="string"&&!R.objectMode&&(Q=new w("chunk",["string","Buffer"],D)),Q?(v(O,Q),process.nextTick(Y,Q),!1):!0}M.prototype.write=function(O,R,D){var Y=this._writableState,Q=!1,b=!Y.objectMode&&a(O);return b&&!i.isBuffer(O)&&(O=o(O)),typeof R=="function"&&(D=R,R=null),b?R="buffer":R||(R=Y.defaultEncoding),typeof D!="function"&&(D=B),Y.ending?P(this,D):(b||G(this,Y,O,D))&&(Y.pendingcb++,Q=C(this,Y,b,O,R,D)),Q},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var O=this._writableState;O.corked&&(O.corked--,!O.writing&&!O.corked&&!O.bufferProcessing&&O.bufferedRequest&&se(this,O))},M.prototype.setDefaultEncoding=function(R){if(typeof R=="string"&&(R=R.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((R+"").toLowerCase())>-1))throw new E(R);return this._writableState.defaultEncoding=R,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function K(O,R,D){return!O.objectMode&&O.decodeStrings!==!1&&typeof R=="string"&&(R=i.from(R,D)),R}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function C(O,R,D,Y,Q,b){if(!D){var g=K(R,Y,Q);Y!==g&&(D=!0,Q="buffer",Y=g)}var F=R.objectMode?1:Y.length;R.length+=F;var q=R.length<R.highWaterMark;if(q||(R.needDrain=!0),R.writing||R.corked){var ue=R.lastBufferedRequest;R.lastBufferedRequest={chunk:Y,encoding:Q,isBuf:D,callback:b,next:null},ue?ue.next=R.lastBufferedRequest:R.bufferedRequest=R.lastBufferedRequest,R.bufferedRequestCount+=1}else j(O,R,!1,F,Y,Q,b);return q}function j(O,R,D,Y,Q,b,g){R.writelen=Y,R.writecb=g,R.writing=!0,R.sync=!0,R.destroyed?R.onwrite(new _("write")):D?O._writev(Q,R.onwrite):O._write(Q,b,R.onwrite),R.sync=!1}function N(O,R,D,Y,Q){--R.pendingcb,D?(process.nextTick(Q,Y),process.nextTick(ge,O,R),O._writableState.errorEmitted=!0,v(O,Y)):(Q(Y),O._writableState.errorEmitted=!0,v(O,Y),ge(O,R))}function $(O){O.writing=!1,O.writecb=null,O.length-=O.writelen,O.writelen=0}function z(O,R){var D=O._writableState,Y=D.sync,Q=D.writecb;if(typeof Q!="function")throw new I;if($(D),R)N(O,D,Y,R,Q);else{var b=be(D)||O.destroyed;!b&&!D.corked&&!D.bufferProcessing&&D.bufferedRequest&&se(O,D),Y?process.nextTick(W,O,D,b,Q):W(O,D,b,Q)}}function W(O,R,D,Y){D||J(O,R),R.pendingcb--,Y(),ge(O,R)}function J(O,R){R.length===0&&R.needDrain&&(R.needDrain=!1,O.emit("drain"))}function se(O,R){R.bufferProcessing=!0;var D=R.bufferedRequest;if(O._writev&&D&&D.next){var Y=R.bufferedRequestCount,Q=new Array(Y),b=R.corkedRequestsFree;b.entry=D;for(var g=0,F=!0;D;)Q[g]=D,D.isBuf||(F=!1),D=D.next,g+=1;Q.allBuffers=F,j(O,R,!0,R.length,Q,"",b.finish),R.pendingcb++,R.lastBufferedRequest=null,b.next?(R.corkedRequestsFree=b.next,b.next=null):R.corkedRequestsFree=new e(R),R.bufferedRequestCount=0}else{for(;D;){var q=D.chunk,ue=D.encoding,re=D.callback,le=R.objectMode?1:q.length;if(j(O,R,!1,le,q,ue,re),D=D.next,R.bufferedRequestCount--,R.writing)break}D===null&&(R.lastBufferedRequest=null)}R.bufferedRequest=D,R.bufferProcessing=!1}M.prototype._write=function(O,R,D){D(new y("_write()"))},M.prototype._writev=null,M.prototype.end=function(O,R,D){var Y=this._writableState;return typeof O=="function"?(D=O,O=null,R=null):typeof R=="function"&&(D=R,R=null),O!=null&&this.write(O,R),Y.corked&&(Y.corked=1,this.uncork()),Y.ending||Se(this,Y,D),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function be(O){return O.ending&&O.length===0&&O.bufferedRequest===null&&!O.finished&&!O.writing}function te(O,R){O._final(function(D){R.pendingcb--,D&&v(O,D),R.prefinished=!0,O.emit("prefinish"),ge(O,R)})}function fe(O,R){!R.prefinished&&!R.finalCalled&&(typeof O._final=="function"&&!R.destroyed?(R.pendingcb++,R.finalCalled=!0,process.nextTick(te,O,R)):(R.prefinished=!0,O.emit("prefinish")))}function ge(O,R){var D=be(R);if(D&&(fe(O,R),R.pendingcb===0&&(R.finished=!0,O.emit("finish"),R.autoDestroy))){var Y=O._readableState;(!Y||Y.autoDestroy&&Y.endEmitted)&&O.destroy()}return D}function Se(O,R,D){R.ending=!0,ge(O,R),D&&(R.finished?process.nextTick(D):O.once("finish",D)),R.ended=!0,O.writable=!1}function je(O,R,D){var Y=O.entry;for(O.entry=null;Y;){var Q=Y.callback;R.pendingcb--,Q(D),Y=Y.next}R.corkedRequestsFree.next=O}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(R){this._writableState&&(this._writableState.destroyed=R)}}),M.prototype.destroy=f.destroy,M.prototype._undestroy=f.undestroy,M.prototype._destroy=function(O,R){R(O)},Fs}var Ms,Ma;function un(){if(Ma)return Ms;Ma=1;var e=Object.keys||function(l){var d=[];for(var p in l)d.push(p);return d};Ms=o;var t=xf(),r=vf();$e(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(f,this)}function f(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)}}),Ms}var Ni={},qo=tt.Buffer,Da=qo.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 qh(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 Vh(e){var t=qh(e);if(typeof t!="string"&&(qo.isEncoding===Da||!Da(e)))throw new Error("Unknown encoding: "+e);return t||e}Ni.StringDecoder=Jn;function Jn(e){this.encoding=Vh(e);var t;switch(this.encoding){case"utf16le":this.text=Zh,this.end=Jh,t=4;break;case"utf8":this.fillLast=Kh,t=4;break;case"base64":this.text=Qh,this.end=e0,t=3;break;default:this.write=t0,this.end=r0;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=qo.allocUnsafe(t)}Jn.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||""};Jn.prototype.end=Xh;Jn.prototype.text=Yh;Jn.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 Ds(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Gh(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Ds(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Ds(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Ds(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function Wh(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 Kh(e){var t=this.lastTotal-this.lastNeed,r=Wh(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 Yh(e,t){var r=Gh(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 Xh(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function Zh(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 Jh(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 Qh(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 e0(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function t0(e){return e.toString(this.encoding)}function r0(e){return e&&e.length?this.write(e):""}var $a=Hr.codes.ERR_STREAM_PREMATURE_CLOSE;function n0(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 i0(){}function s0(e){return e.setHeader&&typeof e.abort=="function"}function Ef(e,t,r){if(typeof t=="function")return Ef(e,null,t);t||(t={}),r=n0(r||i0);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)},f=e._readableState&&e._readableState.endEmitted,l=function(){n=!1,f=!0,i||r.call(e)},d=function(I){r.call(e,I)},p=function(){var I;if(n&&!f)return(!e._readableState||!e._readableState.ended)&&(I=new $a),r.call(e,I);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(I=new $a),r.call(e,I)},w=function(){e.req.on("finish",a)};return s0(e)?(e.on("complete",a),e.on("abort",p),e.req?w():e.on("request",w)):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",p),function(){e.removeListener("complete",a),e.removeListener("abort",p),e.removeListener("request",w),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",p)}}var Vo=Ef,$s,ja;function o0(){if(ja)return $s;ja=1;var e;function t(E,v,B){return v=r(v),v in E?Object.defineProperty(E,v,{value:B,enumerable:!0,configurable:!0,writable:!0}):E[v]=B,E}function r(E){var v=n(E,"string");return typeof v=="symbol"?v:String(v)}function n(E,v){if(typeof E!="object"||E===null)return E;var B=E[Symbol.toPrimitive];if(B!==void 0){var x=B.call(E,v||"default");if(typeof x!="object")return x;throw new TypeError("@@toPrimitive must return a primitive value.")}return(v==="string"?String:Number)(E)}var i=Vo,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),f=Symbol("ended"),l=Symbol("lastPromise"),d=Symbol("handlePromise"),p=Symbol("stream");function w(E,v){return{value:E,done:v}}function y(E){var v=E[s];if(v!==null){var B=E[p].read();B!==null&&(E[l]=null,E[s]=null,E[o]=null,v(w(B,!1)))}}function I(E){process.nextTick(y,E)}function S(E,v){return function(B,x){E.then(function(){if(v[f]){B(w(void 0,!0));return}v[d](B,x)},x)}}var _=Object.getPrototypeOf(function(){}),A=Object.setPrototypeOf((e={get stream(){return this[p]},next:function(){var v=this,B=this[a];if(B!==null)return Promise.reject(B);if(this[f])return Promise.resolve(w(void 0,!0));if(this[p].destroyed)return new Promise(function(P,G){process.nextTick(function(){v[a]?G(v[a]):P(w(void 0,!0))})});var x=this[l],L;if(x)L=new Promise(S(x,this));else{var M=this[p].read();if(M!==null)return Promise.resolve(w(M,!1));L=new Promise(this[d])}return this[l]=L,L}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var v=this;return new Promise(function(B,x){v[p].destroy(null,function(L){if(L){x(L);return}B(w(void 0,!0))})})}),e),_),k=function(v){var B,x=Object.create(A,(B={},t(B,p,{value:v,writable:!0}),t(B,s,{value:null,writable:!0}),t(B,o,{value:null,writable:!0}),t(B,a,{value:null,writable:!0}),t(B,f,{value:v._readableState.endEmitted,writable:!0}),t(B,d,{value:function(M,P){var G=x[p].read();G?(x[l]=null,x[s]=null,x[o]=null,M(w(G,!1))):(x[s]=M,x[o]=P)},writable:!0}),B));return x[l]=null,i(v,function(L){if(L&&L.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=x[o];M!==null&&(x[l]=null,x[s]=null,x[o]=null,M(L)),x[a]=L;return}var P=x[s];P!==null&&(x[l]=null,x[s]=null,x[o]=null,P(w(void 0,!0))),x[f]=!0}),v.on("readable",I.bind(null,x)),x};return $s=k,$s}var js,za;function a0(){return za||(za=1,js=function(){throw new Error("Readable.from is not available in the browser")}),js}var zs,qa;function xf(){if(qa)return zs;qa=1,zs=P;var e;P.ReadableState=M,mf.EventEmitter;var t=function(g,F){return g.listeners(F).length},r=bf,n=Yt.Buffer,i=(typeof hr<"u"?hr: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=zo,f;a&&a.debuglog?f=a.debuglog("stream"):f=function(){};var l=Oh(),d=gf,p=_f,w=p.getHighWaterMark,y=Hr.codes,I=y.ERR_INVALID_ARG_TYPE,S=y.ERR_STREAM_PUSH_AFTER_EOF,_=y.ERR_METHOD_NOT_IMPLEMENTED,A=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,k,E,v;$e(P,r);var B=d.errorOrDestroy,x=["error","close","destroy","pause","resume"];function L(b,g,F){if(typeof b.prependListener=="function")return b.prependListener(g,F);!b._events||!b._events[g]?b.on(g,F):Array.isArray(b._events[g])?b._events[g].unshift(F):b._events[g]=[F,b._events[g]]}function M(b,g,F){e=e||un(),b=b||{},typeof F!="boolean"&&(F=g instanceof e),this.objectMode=!!b.objectMode,F&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=w(this,b,"readableHighWaterMark",F),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&&(k||(k=Ni.StringDecoder),this.decoder=new k(b.encoding),this.encoding=b.encoding)}function P(b){if(e=e||un(),!(this instanceof P))return new P(b);var g=this instanceof e;this._readableState=new M(b,this,g),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(P.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(g){this._readableState&&(this._readableState.destroyed=g)}}),P.prototype.destroy=d.destroy,P.prototype._undestroy=d.undestroy,P.prototype._destroy=function(b,g){g(b)},P.prototype.push=function(b,g){var F=this._readableState,q;return F.objectMode?q=!0:typeof b=="string"&&(g=g||F.defaultEncoding,g!==F.encoding&&(b=n.from(b,g),g=""),q=!0),G(this,b,g,!1,q)},P.prototype.unshift=function(b){return G(this,b,null,!0,!1)};function G(b,g,F,q,ue){f("readableAddChunk",g);var re=b._readableState;if(g===null)re.reading=!1,z(b,re);else{var le;if(ue||(le=C(re,g)),le)B(b,le);else if(re.objectMode||g&&g.length>0)if(typeof g!="string"&&!re.objectMode&&Object.getPrototypeOf(g)!==n.prototype&&(g=s(g)),q)re.endEmitted?B(b,new A):K(b,re,g,!0);else if(re.ended)B(b,new S);else{if(re.destroyed)return!1;re.reading=!1,re.decoder&&!F?(g=re.decoder.write(g),re.objectMode||g.length!==0?K(b,re,g,!1):se(b,re)):K(b,re,g,!1)}else q||(re.reading=!1,se(b,re))}return!re.ended&&(re.length<re.highWaterMark||re.length===0)}function K(b,g,F,q){g.flowing&&g.length===0&&!g.sync?(g.awaitDrain=0,b.emit("data",F)):(g.length+=g.objectMode?1:F.length,q?g.buffer.unshift(F):g.buffer.push(F),g.needReadable&&W(b)),se(b,g)}function C(b,g){var F;return!o(g)&&typeof g!="string"&&g!==void 0&&!b.objectMode&&(F=new I("chunk",["string","Buffer","Uint8Array"],g)),F}P.prototype.isPaused=function(){return this._readableState.flowing===!1},P.prototype.setEncoding=function(b){k||(k=Ni.StringDecoder);var g=new k(b);this._readableState.decoder=g,this._readableState.encoding=this._readableState.decoder.encoding;for(var F=this._readableState.buffer.head,q="";F!==null;)q+=g.write(F.data),F=F.next;return this._readableState.buffer.clear(),q!==""&&this._readableState.buffer.push(q),this._readableState.length=q.length,this};var j=1073741824;function N(b){return b>=j?b=j:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function $(b,g){return b<=0||g.length===0&&g.ended?0:g.objectMode?1:b!==b?g.flowing&&g.length?g.buffer.head.data.length:g.length:(b>g.highWaterMark&&(g.highWaterMark=N(b)),b<=g.length?b:g.ended?g.length:(g.needReadable=!0,0))}P.prototype.read=function(b){f("read",b),b=parseInt(b,10);var g=this._readableState,F=b;if(b!==0&&(g.emittedReadable=!1),b===0&&g.needReadable&&((g.highWaterMark!==0?g.length>=g.highWaterMark:g.length>0)||g.ended))return f("read: emitReadable",g.length,g.ended),g.length===0&&g.ended?D(this):W(this),null;if(b=$(b,g),b===0&&g.ended)return g.length===0&&D(this),null;var q=g.needReadable;f("need readable",q),(g.length===0||g.length-b<g.highWaterMark)&&(q=!0,f("length less than watermark",q)),g.ended||g.reading?(q=!1,f("reading or ended",q)):q&&(f("do read"),g.reading=!0,g.sync=!0,g.length===0&&(g.needReadable=!0),this._read(g.highWaterMark),g.sync=!1,g.reading||(b=$(F,g)));var ue;return b>0?ue=R(b,g):ue=null,ue===null?(g.needReadable=g.length<=g.highWaterMark,b=0):(g.length-=b,g.awaitDrain=0),g.length===0&&(g.ended||(g.needReadable=!0),F!==b&&g.ended&&D(this)),ue!==null&&this.emit("data",ue),ue};function z(b,g){if(f("onEofChunk"),!g.ended){if(g.decoder){var F=g.decoder.end();F&&F.length&&(g.buffer.push(F),g.length+=g.objectMode?1:F.length)}g.ended=!0,g.sync?W(b):(g.needReadable=!1,g.emittedReadable||(g.emittedReadable=!0,J(b)))}}function W(b){var g=b._readableState;f("emitReadable",g.needReadable,g.emittedReadable),g.needReadable=!1,g.emittedReadable||(f("emitReadable",g.flowing),g.emittedReadable=!0,process.nextTick(J,b))}function J(b){var g=b._readableState;f("emitReadable_",g.destroyed,g.length,g.ended),!g.destroyed&&(g.length||g.ended)&&(b.emit("readable"),g.emittedReadable=!1),g.needReadable=!g.flowing&&!g.ended&&g.length<=g.highWaterMark,O(b)}function se(b,g){g.readingMore||(g.readingMore=!0,process.nextTick(be,b,g))}function be(b,g){for(;!g.reading&&!g.ended&&(g.length<g.highWaterMark||g.flowing&&g.length===0);){var F=g.length;if(f("maybeReadMore read 0"),b.read(0),F===g.length)break}g.readingMore=!1}P.prototype._read=function(b){B(this,new _("_read()"))},P.prototype.pipe=function(b,g){var F=this,q=this._readableState;switch(q.pipesCount){case 0:q.pipes=b;break;case 1:q.pipes=[q.pipes,b];break;default:q.pipes.push(b);break}q.pipesCount+=1,f("pipe count=%d opts=%j",q.pipesCount,g);var ue=(!g||g.end!==!1)&&b!==process.stdout&&b!==process.stderr,re=ue?Zt:vr;q.endEmitted?process.nextTick(re):F.once("end",re),b.on("unpipe",le);function le(h,c){f("onunpipe"),h===F&&c&&c.hasUnpiped===!1&&(c.hasUnpiped=!0,$r())}function Zt(){f("onend"),b.end()}var Dr=te(F);b.on("drain",Dr);var wn=!1;function $r(){f("cleanup"),b.removeListener("close",_n),b.removeListener("finish",ot),b.removeListener("drain",Dr),b.removeListener("error",_r),b.removeListener("unpipe",le),F.removeListener("end",Zt),F.removeListener("end",vr),F.removeListener("data",nt),wn=!0,q.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&Dr()}F.on("data",nt);function nt(h){f("ondata");var c=b.write(h);f("dest.write",c),c===!1&&((q.pipesCount===1&&q.pipes===b||q.pipesCount>1&&Q(q.pipes,b)!==-1)&&!wn&&(f("false write response, pause",q.awaitDrain),q.awaitDrain++),F.pause())}function _r(h){f("onerror",h),vr(),b.removeListener("error",_r),t(b,"error")===0&&B(b,h)}L(b,"error",_r);function _n(){b.removeListener("finish",ot),vr()}b.once("close",_n);function ot(){f("onfinish"),b.removeListener("close",_n),vr()}b.once("finish",ot);function vr(){f("unpipe"),F.unpipe(b)}return b.emit("pipe",F),q.flowing||(f("pipe resume"),F.resume()),b};function te(b){return function(){var F=b._readableState;f("pipeOnDrain",F.awaitDrain),F.awaitDrain&&F.awaitDrain--,F.awaitDrain===0&&t(b,"data")&&(F.flowing=!0,O(b))}}P.prototype.unpipe=function(b){var g=this._readableState,F={hasUnpiped:!1};if(g.pipesCount===0)return this;if(g.pipesCount===1)return b&&b!==g.pipes?this:(b||(b=g.pipes),g.pipes=null,g.pipesCount=0,g.flowing=!1,b&&b.emit("unpipe",this,F),this);if(!b){var q=g.pipes,ue=g.pipesCount;g.pipes=null,g.pipesCount=0,g.flowing=!1;for(var re=0;re<ue;re++)q[re].emit("unpipe",this,{hasUnpiped:!1});return this}var le=Q(g.pipes,b);return le===-1?this:(g.pipes.splice(le,1),g.pipesCount-=1,g.pipesCount===1&&(g.pipes=g.pipes[0]),b.emit("unpipe",this,F),this)},P.prototype.on=function(b,g){var F=r.prototype.on.call(this,b,g),q=this._readableState;return b==="data"?(q.readableListening=this.listenerCount("readable")>0,q.flowing!==!1&&this.resume()):b==="readable"&&!q.endEmitted&&!q.readableListening&&(q.readableListening=q.needReadable=!0,q.flowing=!1,q.emittedReadable=!1,f("on readable",q.length,q.reading),q.length?W(this):q.reading||process.nextTick(ge,this)),F},P.prototype.addListener=P.prototype.on,P.prototype.removeListener=function(b,g){var F=r.prototype.removeListener.call(this,b,g);return b==="readable"&&process.nextTick(fe,this),F},P.prototype.removeAllListeners=function(b){var g=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(fe,this),g};function fe(b){var g=b._readableState;g.readableListening=b.listenerCount("readable")>0,g.resumeScheduled&&!g.paused?g.flowing=!0:b.listenerCount("data")>0&&b.resume()}function ge(b){f("readable nexttick read 0"),b.read(0)}P.prototype.resume=function(){var b=this._readableState;return b.flowing||(f("resume"),b.flowing=!b.readableListening,Se(this,b)),b.paused=!1,this};function Se(b,g){g.resumeScheduled||(g.resumeScheduled=!0,process.nextTick(je,b,g))}function je(b,g){f("resume",g.reading),g.reading||b.read(0),g.resumeScheduled=!1,b.emit("resume"),O(b),g.flowing&&!g.reading&&b.read(0)}P.prototype.pause=function(){return f("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(f("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function O(b){var g=b._readableState;for(f("flow",g.flowing);g.flowing&&b.read()!==null;);}P.prototype.wrap=function(b){var g=this,F=this._readableState,q=!1;b.on("end",function(){if(f("wrapped end"),F.decoder&&!F.ended){var le=F.decoder.end();le&&le.length&&g.push(le)}g.push(null)}),b.on("data",function(le){if(f("wrapped data"),F.decoder&&(le=F.decoder.write(le)),!(F.objectMode&&le==null)&&!(!F.objectMode&&(!le||!le.length))){var Zt=g.push(le);Zt||(q=!0,b.pause())}});for(var ue in b)this[ue]===void 0&&typeof b[ue]=="function"&&(this[ue]=function(Zt){return function(){return b[Zt].apply(b,arguments)}}(ue));for(var re=0;re<x.length;re++)b.on(x[re],this.emit.bind(this,x[re]));return this._read=function(le){f("wrapped _read",le),q&&(q=!1,b.resume())},this},typeof Symbol=="function"&&(P.prototype[Symbol.asyncIterator]=function(){return E===void 0&&(E=o0()),E(this)}),Object.defineProperty(P.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(P.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(P.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(g){this._readableState&&(this._readableState.flowing=g)}}),P._fromList=R,Object.defineProperty(P.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function R(b,g){if(g.length===0)return null;var F;return g.objectMode?F=g.buffer.shift():!b||b>=g.length?(g.decoder?F=g.buffer.join(""):g.buffer.length===1?F=g.buffer.first():F=g.buffer.concat(g.length),g.buffer.clear()):F=g.buffer.consume(b,g.decoder),F}function D(b){var g=b._readableState;f("endReadable",g.endEmitted),g.endEmitted||(g.ended=!0,process.nextTick(Y,g,b))}function Y(b,g){if(f("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,g.readable=!1,g.emit("end"),b.autoDestroy)){var F=g._writableState;(!F||F.autoDestroy&&F.finished)&&g.destroy()}}typeof Symbol=="function"&&(P.from=function(b,g){return v===void 0&&(v=a0()),v(P,b,g)});function Q(b,g){for(var F=0,q=b.length;F<q;F++)if(b[F]===g)return F;return-1}return zs}var Sf=Wt,ts=Hr.codes,c0=ts.ERR_METHOD_NOT_IMPLEMENTED,f0=ts.ERR_MULTIPLE_CALLBACK,u0=ts.ERR_TRANSFORM_ALREADY_TRANSFORMING,l0=ts.ERR_TRANSFORM_WITH_LENGTH_0,rs=un();$e(Wt,rs);function d0(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new f0);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 Wt(e){if(!(this instanceof Wt))return new Wt(e);rs.call(this,e),this._transformState={afterTransform:d0.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",h0)}function h0(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Va(e,t,r)}):Va(this,null,null)}Wt.prototype.push=function(e,t){return this._transformState.needTransform=!1,rs.prototype.push.call(this,e,t)};Wt.prototype._transform=function(e,t,r){r(new c0("_transform()"))};Wt.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)}};Wt.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};Wt.prototype._destroy=function(e,t){rs.prototype._destroy.call(this,e,function(r){t(r)})};function Va(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new l0;if(e._transformState.transforming)throw new u0;return e.push(null)}var p0=Vn,Af=Sf;$e(Vn,Af);function Vn(e){if(!(this instanceof Vn))return new Vn(e);Af.call(this,e)}Vn.prototype._transform=function(e,t,r){r(null,e)};var qs;function y0(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var Bf=Hr.codes,m0=Bf.ERR_MISSING_ARGS,b0=Bf.ERR_STREAM_DESTROYED;function Ga(e){if(e)throw e}function g0(e){return e.setHeader&&typeof e.abort=="function"}function w0(e,t,r,n){n=y0(n);var i=!1;e.on("close",function(){i=!0}),qs===void 0&&(qs=Vo),qs(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,g0(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new b0("pipe"))}}}function Wa(e){e()}function _0(e,t){return e.pipe(t)}function v0(e){return!e.length||typeof e[e.length-1]!="function"?Ga:e.pop()}function E0(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=v0(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new m0("streams");var i,s=t.map(function(o,a){var f=a<t.length-1,l=a>0;return w0(o,f,l,function(d){i||(i=d),d&&s.forEach(Wa),!f&&(s.forEach(Wa),n(i))})});return t.reduce(_0)}var x0=E0;(function(e,t){t=e.exports=xf(),t.Stream=t,t.Readable=t,t.Writable=vf(),t.Duplex=un(),t.Transform=Sf,t.PassThrough=p0,t.finished=Vo,t.pipeline=x0})(ho,ho.exports);var If=ho.exports,Hi=tt.Buffer,Tf=If.Transform,S0=$e;function A0(e,t){if(!Hi.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function gr(e){Tf.call(this),this._block=Hi.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}S0(gr,Tf);gr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};gr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};gr.prototype.update=function(e,t){if(A0(e,"Data"),this._finalized)throw new Error("Digest already called");Hi.isBuffer(e)||(e=Hi.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};gr.prototype._update=function(){throw new Error("_update is not implemented")};gr.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};gr.prototype._digest=function(){throw new Error("_digest is not implemented")};var B0=gr,I0=$e,kf=B0,T0=tt.Buffer,k0=new Array(16);function ns(){kf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}I0(ns,kf);ns.prototype._update=function(){for(var e=k0,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=ze(r,n,i,s,e[0],3614090360,7),s=ze(s,r,n,i,e[1],3905402710,12),i=ze(i,s,r,n,e[2],606105819,17),n=ze(n,i,s,r,e[3],3250441966,22),r=ze(r,n,i,s,e[4],4118548399,7),s=ze(s,r,n,i,e[5],1200080426,12),i=ze(i,s,r,n,e[6],2821735955,17),n=ze(n,i,s,r,e[7],4249261313,22),r=ze(r,n,i,s,e[8],1770035416,7),s=ze(s,r,n,i,e[9],2336552879,12),i=ze(i,s,r,n,e[10],4294925233,17),n=ze(n,i,s,r,e[11],2304563134,22),r=ze(r,n,i,s,e[12],1804603682,7),s=ze(s,r,n,i,e[13],4254626195,12),i=ze(i,s,r,n,e[14],2792965006,17),n=ze(n,i,s,r,e[15],1236535329,22),r=qe(r,n,i,s,e[1],4129170786,5),s=qe(s,r,n,i,e[6],3225465664,9),i=qe(i,s,r,n,e[11],643717713,14),n=qe(n,i,s,r,e[0],3921069994,20),r=qe(r,n,i,s,e[5],3593408605,5),s=qe(s,r,n,i,e[10],38016083,9),i=qe(i,s,r,n,e[15],3634488961,14),n=qe(n,i,s,r,e[4],3889429448,20),r=qe(r,n,i,s,e[9],568446438,5),s=qe(s,r,n,i,e[14],3275163606,9),i=qe(i,s,r,n,e[3],4107603335,14),n=qe(n,i,s,r,e[8],1163531501,20),r=qe(r,n,i,s,e[13],2850285829,5),s=qe(s,r,n,i,e[2],4243563512,9),i=qe(i,s,r,n,e[7],1735328473,14),n=qe(n,i,s,r,e[12],2368359562,20),r=Ve(r,n,i,s,e[5],4294588738,4),s=Ve(s,r,n,i,e[8],2272392833,11),i=Ve(i,s,r,n,e[11],1839030562,16),n=Ve(n,i,s,r,e[14],4259657740,23),r=Ve(r,n,i,s,e[1],2763975236,4),s=Ve(s,r,n,i,e[4],1272893353,11),i=Ve(i,s,r,n,e[7],4139469664,16),n=Ve(n,i,s,r,e[10],3200236656,23),r=Ve(r,n,i,s,e[13],681279174,4),s=Ve(s,r,n,i,e[0],3936430074,11),i=Ve(i,s,r,n,e[3],3572445317,16),n=Ve(n,i,s,r,e[6],76029189,23),r=Ve(r,n,i,s,e[9],3654602809,4),s=Ve(s,r,n,i,e[12],3873151461,11),i=Ve(i,s,r,n,e[15],530742520,16),n=Ve(n,i,s,r,e[2],3299628645,23),r=Ge(r,n,i,s,e[0],4096336452,6),s=Ge(s,r,n,i,e[7],1126891415,10),i=Ge(i,s,r,n,e[14],2878612391,15),n=Ge(n,i,s,r,e[5],4237533241,21),r=Ge(r,n,i,s,e[12],1700485571,6),s=Ge(s,r,n,i,e[3],2399980690,10),i=Ge(i,s,r,n,e[10],4293915773,15),n=Ge(n,i,s,r,e[1],2240044497,21),r=Ge(r,n,i,s,e[8],1873313359,6),s=Ge(s,r,n,i,e[15],4264355552,10),i=Ge(i,s,r,n,e[6],2734768916,15),n=Ge(n,i,s,r,e[13],1309151649,21),r=Ge(r,n,i,s,e[4],4149444226,6),s=Ge(s,r,n,i,e[11],3174756917,10),i=Ge(i,s,r,n,e[2],718787259,15),n=Ge(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};ns.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=T0.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 is(e,t){return e<<t|e>>>32-t}function ze(e,t,r,n,i,s,o){return is(e+(t&r|~t&n)+i+s|0,o)+t|0}function qe(e,t,r,n,i,s,o){return is(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ve(e,t,r,n,i,s,o){return is(e+(t^r^n)+i+s|0,o)+t|0}function Ge(e,t,r,n,i,s,o){return is(e+(r^(t|~n))+i+s|0,o)+t|0}var P0=ns,Fi=tt.Buffer,Pf=If.Transform,O0=$e;function R0(e,t){if(!Fi.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function wr(e){Pf.call(this),this._block=Fi.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}O0(wr,Pf);wr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};wr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};wr.prototype.update=function(e,t){if(R0(e,"Data"),this._finalized)throw new Error("Digest already called");Fi.isBuffer(e)||(e=Fi.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};wr.prototype._update=function(){throw new Error("_update is not implemented")};wr.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};wr.prototype._digest=function(){throw new Error("_digest is not implemented")};var C0=wr,Vs=Yt.Buffer,U0=$e,Of=C0,L0=new Array(16),Bn=[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],In=[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],Tn=[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],kn=[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],Pn=[0,1518500249,1859775393,2400959708,2840853838],On=[1352829926,1548603684,1836072691,2053994217,0];function ss(){Of.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}U0(ss,Of);ss.prototype._update=function(){for(var e=L0,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,f=this._b|0,l=this._c|0,d=this._d|0,p=this._e|0,w=0;w<80;w+=1){var y,I;w<16?(y=Ka(r,n,i,s,o,e[Bn[w]],Pn[0],Tn[w]),I=Ja(a,f,l,d,p,e[In[w]],On[0],kn[w])):w<32?(y=Ya(r,n,i,s,o,e[Bn[w]],Pn[1],Tn[w]),I=Za(a,f,l,d,p,e[In[w]],On[1],kn[w])):w<48?(y=Xa(r,n,i,s,o,e[Bn[w]],Pn[2],Tn[w]),I=Xa(a,f,l,d,p,e[In[w]],On[2],kn[w])):w<64?(y=Za(r,n,i,s,o,e[Bn[w]],Pn[3],Tn[w]),I=Ya(a,f,l,d,p,e[In[w]],On[3],kn[w])):(y=Ja(r,n,i,s,o,e[Bn[w]],Pn[4],Tn[w]),I=Ka(a,f,l,d,p,e[In[w]],On[4],kn[w])),r=o,o=s,s=Cr(i,10),i=n,n=y,a=p,p=d,d=Cr(l,10),l=f,f=I}var S=this._b+i+d|0;this._b=this._c+s+p|0,this._c=this._d+o+a|0,this._d=this._e+r+f|0,this._e=this._a+n+l|0,this._a=S};ss.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=Vs.alloc?Vs.alloc(20):new Vs(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};function Cr(e,t){return e<<t|e>>>32-t}function Ka(e,t,r,n,i,s,o,a){return Cr(e+(t^r^n)+s+o|0,a)+i|0}function Ya(e,t,r,n,i,s,o,a){return Cr(e+(t&r|~t&n)+s+o|0,a)+i|0}function Xa(e,t,r,n,i,s,o,a){return Cr(e+((t|~r)^n)+s+o|0,a)+i|0}function Za(e,t,r,n,i,s,o,a){return Cr(e+(t&n|r&~n)+s+o|0,a)+i|0}function Ja(e,t,r,n,i,s,o,a){return Cr(e+(t^(r|~n))+s+o|0,a)+i|0}var N0=ss,Rf={exports:{}},Cf=tt.Buffer;function os(e,t){this._block=Cf.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}os.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Cf.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,f=Math.min(i-o,n-a),l=0;l<f;l++)r[a+l]=e[o+l];s+=f,o+=f,s%n===0&&this._update(r)}return this._len+=i,this};os.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};os.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var mn=os,H0=$e,Uf=mn,F0=tt.Buffer,M0=[1518500249,1859775393,-1894007588,-899497514],D0=new Array(80);function Qn(){this.init(),this._w=D0,Uf.call(this,64,56)}H0(Qn,Uf);Qn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function $0(e){return e<<5|e>>>27}function j0(e){return e<<30|e>>>2}function z0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Qn.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 f=0;f<80;++f){var l=~~(f/20),d=$0(r)+z0(l,n,i,s)+o+t[f]+M0[l]|0;o=s,s=i,i=j0(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};Qn.prototype._hash=function(){var e=F0.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 q0=Qn,V0=$e,Lf=mn,G0=tt.Buffer,W0=[1518500249,1859775393,-1894007588,-899497514],K0=new Array(80);function ei(){this.init(),this._w=K0,Lf.call(this,64,56)}V0(ei,Lf);ei.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Y0(e){return e<<1|e>>>31}function X0(e){return e<<5|e>>>27}function Z0(e){return e<<30|e>>>2}function J0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}ei.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]=Y0(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var f=0;f<80;++f){var l=~~(f/20),d=X0(r)+J0(l,n,i,s)+o+t[f]+W0[l]|0;o=s,s=i,i=Z0(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};ei.prototype._hash=function(){var e=G0.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 Q0=ei,ep=$e,Nf=mn,tp=tt.Buffer,rp=[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],np=new Array(64);function ti(){this.init(),this._w=np,Nf.call(this,64,56)}ep(ti,Nf);ti.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 ip(e,t,r){return r^e&(t^r)}function sp(e,t,r){return e&t|r&(e|t)}function op(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function ap(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function cp(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function fp(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}ti.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,f=this._g|0,l=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=fp(t[d-2])+t[d-7]+cp(t[d-15])+t[d-16]|0;for(var p=0;p<64;++p){var w=l+ap(o)+ip(o,a,f)+rp[p]+t[p]|0,y=op(r)+sp(r,n,i)|0;l=f,f=a,a=o,o=s+w|0,s=i,i=n,n=r,r=w+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=f+this._g|0,this._h=l+this._h|0};ti.prototype._hash=function(){var e=tp.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 Hf=ti,up=$e,lp=Hf,dp=mn,hp=tt.Buffer,pp=new Array(64);function as(){this.init(),this._w=pp,dp.call(this,64,56)}up(as,lp);as.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};as.prototype._hash=function(){var e=hp.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 yp=as,mp=$e,Ff=mn,bp=tt.Buffer,Qa=[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],gp=new Array(160);function ri(){this.init(),this._w=gp,Ff.call(this,128,112)}mp(ri,Ff);ri.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 ec(e,t,r){return r^e&(t^r)}function tc(e,t,r){return e&t|r&(e|t)}function rc(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function nc(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function wp(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function _p(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function vp(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function Ep(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ue(e,t){return e>>>0<t>>>0?1:0}ri.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,f=this._gh|0,l=this._hh|0,d=this._al|0,p=this._bl|0,w=this._cl|0,y=this._dl|0,I=this._el|0,S=this._fl|0,_=this._gl|0,A=this._hl|0,k=0;k<32;k+=2)t[k]=e.readInt32BE(k*4),t[k+1]=e.readInt32BE(k*4+4);for(;k<160;k+=2){var E=t[k-30],v=t[k-15*2+1],B=wp(E,v),x=_p(v,E);E=t[k-2*2],v=t[k-2*2+1];var L=vp(E,v),M=Ep(v,E),P=t[k-7*2],G=t[k-7*2+1],K=t[k-16*2],C=t[k-16*2+1],j=x+G|0,N=B+P+Ue(j,x)|0;j=j+M|0,N=N+L+Ue(j,M)|0,j=j+C|0,N=N+K+Ue(j,C)|0,t[k]=N,t[k+1]=j}for(var $=0;$<160;$+=2){N=t[$],j=t[$+1];var z=tc(r,n,i),W=tc(d,p,w),J=rc(r,d),se=rc(d,r),be=nc(o,I),te=nc(I,o),fe=Qa[$],ge=Qa[$+1],Se=ec(o,a,f),je=ec(I,S,_),O=A+te|0,R=l+be+Ue(O,A)|0;O=O+je|0,R=R+Se+Ue(O,je)|0,O=O+ge|0,R=R+fe+Ue(O,ge)|0,O=O+j|0,R=R+N+Ue(O,j)|0;var D=se+W|0,Y=J+z+Ue(D,se)|0;l=f,A=_,f=a,_=S,a=o,S=I,I=y+O|0,o=s+R+Ue(I,y)|0,s=i,y=w,i=n,w=p,n=r,p=d,d=O+D|0,r=R+Y+Ue(d,O)|0}this._al=this._al+d|0,this._bl=this._bl+p|0,this._cl=this._cl+w|0,this._dl=this._dl+y|0,this._el=this._el+I|0,this._fl=this._fl+S|0,this._gl=this._gl+_|0,this._hl=this._hl+A|0,this._ah=this._ah+r+Ue(this._al,d)|0,this._bh=this._bh+n+Ue(this._bl,p)|0,this._ch=this._ch+i+Ue(this._cl,w)|0,this._dh=this._dh+s+Ue(this._dl,y)|0,this._eh=this._eh+o+Ue(this._el,I)|0,this._fh=this._fh+a+Ue(this._fl,S)|0,this._gh=this._gh+f+Ue(this._gl,_)|0,this._hh=this._hh+l+Ue(this._hl,A)|0};ri.prototype._hash=function(){var e=bp.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 Mf=ri,xp=$e,Sp=Mf,Ap=mn,Bp=tt.Buffer,Ip=new Array(160);function cs(){this.init(),this._w=Ip,Ap.call(this,128,112)}xp(cs,Sp);cs.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};cs.prototype._hash=function(){var e=Bp.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 Tp=cs,Fr=Rf.exports=function(t){t=t.toLowerCase();var r=Fr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};Fr.sha=q0;Fr.sha1=Q0;Fr.sha224=yp;Fr.sha256=Hf;Fr.sha384=Tp;Fr.sha512=Mf;var kp=Rf.exports,Df=tt.Buffer,$f=zo.Transform,Pp=Ni.StringDecoder,Op=$e;function wt(e){$f.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}Op(wt,$f);wt.prototype.update=function(e,t,r){typeof e=="string"&&(e=Df.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};wt.prototype.setAutoPadding=function(){};wt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};wt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};wt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};wt.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)}};wt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};wt.prototype._finalOrDigest=function(e){var t=this.__final()||Df.alloc(0);return e&&(t=this._toString(t,e,!0)),t};wt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Pp(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 Rp=wt,Cp=$e,Up=P0,Lp=N0,Np=kp,jf=Rp;function fs(e){jf.call(this,"digest"),this._hash=e}Cp(fs,jf);fs.prototype._update=function(e){this._hash.update(e)};fs.prototype._final=function(){return this._hash.digest()};var Hp=function(t){return t=t.toLowerCase(),t==="md5"?new Up:t==="rmd160"||t==="ripemd160"?new Lp:new fs(Np(t))},gi=tt.Buffer;function Fp(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),f=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if((Array.isArray(y)||y instanceof Uint8Array)&&(y=gi.from(y)),!gi.isBuffer(y))throw new TypeError("Expected Buffer");if(y.length===0)return"";for(var I=0,S=0,_=0,A=y.length;_!==A&&y[_]===0;)_++,I++;for(var k=(A-_)*l+1>>>0,E=new Uint8Array(k);_!==A;){for(var v=y[_],B=0,x=k-1;(v!==0||B<S)&&x!==-1;x--,B++)v+=256*E[x]>>>0,E[x]=v%o>>>0,v=v/o>>>0;if(v!==0)throw new Error("Non-zero carry");S=B,_++}for(var L=k-S;L!==k&&E[L]===0;)L++;for(var M=a.repeat(I);L<k;++L)M+=e.charAt(E[L]);return M}function p(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return gi.alloc(0);for(var I=0,S=0,_=0;y[I]===a;)S++,I++;for(var A=(y.length-I)*f+1>>>0,k=new Uint8Array(A);I<y.length;){var E=t[y.charCodeAt(I)];if(E===255)return;for(var v=0,B=A-1;(E!==0||v<_)&&B!==-1;B--,v++)E+=o*k[B]>>>0,k[B]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");_=v,I++}for(var x=A-_;x!==A&&k[x]===0;)x++;var L=gi.allocUnsafe(S+(A-x));L.fill(0,0,S);for(var M=S;x!==A;)L[M++]=k[x++];return L}function w(y){var I=p(y);if(I)return I;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:p,decode:w}}var Mp=Fp,Dp=Mp,$p="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",jp=Dp($p),Gs=jp,zp=tt.Buffer,qp=function(e){function t(s){var o=e(s);return Gs.encode(zp.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),f=e(o);if(!(a[0]^f[0]|a[1]^f[1]|a[2]^f[2]|a[3]^f[3]))return o}function n(s){var o=Gs.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Gs.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},ic=Hp,Vp=qp;function Gp(e){var t=ic("sha256").update(e).digest();return ic("sha256").update(t).digest()}var Wp=Vp(Gp),yo=Wp;function zf(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 mo(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 Kp(e,t){return zf(yo.decode(e),t)}function Yp(e,t,r){return typeof e=="number"?yo.encode(mo(e,t,r)):yo.encode(mo(e.version,e.privateKey,e.compressed))}var Xp={decode:Kp,decodeRaw:zf,encode:Yp,encodeRaw:mo},us={};Object.defineProperty(us,"__esModule",{value:!0});us.testEcc=void 0;const X=e=>Buffer.from(e,"hex");function Zp(e){_e(e.isPoint(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(!e.isPoint(X("030000000000000000000000000000000000000000000000000000000000000005"))),_e(e.isPrivate(X("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(e.isPrivate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),_e(!e.isPrivate(X("0000000000000000000000000000000000000000000000000000000000000000"))),_e(!e.isPrivate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),_e(!e.isPrivate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),_e(Buffer.from(e.privateAdd(X("0000000000000000000000000000000000000000000000000000000000000001"),X("0000000000000000000000000000000000000000000000000000000000000000"))).equals(X("0000000000000000000000000000000000000000000000000000000000000001"))),_e(e.privateAdd(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),X("0000000000000000000000000000000000000000000000000000000000000003"))===null),_e(Buffer.from(e.privateAdd(X("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),X("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(X("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),_e(Buffer.from(e.privateNegate(X("0000000000000000000000000000000000000000000000000000000000000001"))).equals(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),_e(Buffer.from(e.privateNegate(X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(X("0000000000000000000000000000000000000000000000000000000000000003"))),_e(Buffer.from(e.privateNegate(X("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(X("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),_e(Buffer.from(e.pointCompress(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(Buffer.from(e.pointCompress(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),_e(Buffer.from(e.pointCompress(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),_e(Buffer.from(e.pointCompress(X("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(X("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),_e(Buffer.from(e.pointFromScalar(X("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(X("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),_e(e.xOnlyPointAddTweak(X("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(X("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),X("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));_e(Buffer.from(t.xOnlyPubkey).equals(X("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(X("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),X("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),_e(Buffer.from(t.xOnlyPubkey).equals(X("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),_e(Buffer.from(e.sign(X("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),X("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(X("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),_e(e.verify(X("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),X("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),X("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&_e(Buffer.from(e.signSchnorr(X("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),X("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),X("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(X("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&_e(e.verifySchnorr(X("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),X("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),X("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}us.testEcc=Zp;function _e(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(cn,"__esModule",{value:!0});cn.ECPairFactory=cn.networks=void 0;const bo=fn;cn.networks=bo;const Je=af,Jp=Eh,sc=Xp,Qp=us,Ws=Je.typeforce.maybe(Je.typeforce.compile({compressed:Je.maybe(Je.Boolean),network:Je.maybe(Je.Network)})),ey=e=>e.length===32?e:e.slice(1,33);function ty(e){(0,Qp.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,f){if(Je.typeforce(Je.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return Je.typeforce(Ws,f),new o(a,void 0,f)}function n(a,f){return Je.typeforce(e.isPoint,a),Je.typeforce(Ws,f),new o(void 0,a,f)}function i(a,f){const l=sc.decode(a),d=l.version;if(Je.Array(f)){if(f=f.filter(p=>d===p.wif).pop(),!f)throw new Error("Unknown network version")}else if(f=f||bo.bitcoin,d!==f.wif)throw new Error("Invalid network version");return r(l.privateKey,{compressed:l.compressed,network:f})}function s(a){Je.typeforce(Ws,a),a===void 0&&(a={});const f=a.rng||Jp;let l;do l=f(32),Je.typeforce(Je.Buffer256bit,l);while(!e.isPrivate(l));return r(l,a)}class o{constructor(f,l,d){jr(this,"__D");jr(this,"__Q");jr(this,"compressed");jr(this,"network");jr(this,"lowR");this.__D=f,this.__Q=l,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||bo.bitcoin,l!==void 0&&(this.__Q=Buffer.from(e.pointCompress(l,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const f=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(f)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return sc.encode(this.network.wif,this.__D,this.compressed)}tweak(f){return this.privateKey?this.tweakFromPrivateKey(f):this.tweakFromPublicKey(f)}sign(f,l){if(!this.__D)throw new Error("Missing private key");if(l===void 0&&(l=this.lowR),l===!1)return Buffer.from(e.sign(f,this.__D));{let d=e.sign(f,this.__D);const p=Buffer.alloc(32,0);let w=0;for(;d[0]>127;)w++,p.writeUIntLE(w,0,6),d=e.sign(f,this.__D,p);return Buffer.from(d)}}signSchnorr(f){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(f,this.privateKey))}verify(f,l){return e.verify(f,this.publicKey,l)}verifySchnorr(f,l){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(f,this.publicKey.subarray(1,33),l)}tweakFromPublicKey(f){const l=ey(this.publicKey),d=e.xOnlyPointAddTweak(l,f);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const p=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([p,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(f){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,p=e.privateAdd(d,f);if(!p)throw new Error("Invalid tweaked private key!");return r(Buffer.from(p),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}cn.ECPairFactory=ty;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=cn;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}})})(of);const ry=dl(of);class Gn extends Z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new Gn(Tt(t))}static fromWalletClient(t){return new Gn(void 0,t)}async initialize(){if(this.digestKey)return ce("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?V(t.error):(this.emit("initialized",!0),ce("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return V("No walletClient found");if(!this.walletClient.account)return V("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.digestKey=Tt($t.sha256(t)),this.emit("initialized",!0),ce(this.digestKey)}catch(t){return V("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return V("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return V(t.error)}return this.digestKey?ce(this.digestKey):V("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return V(r.error);const n=$t.sha256(Z.with0x(r.val)),i=$t.sha256(n);return ce({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const l=await this.getDigestKey();if(l.error)return V(l.error);this.digestKey=l.val}const r=ry(Pr),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=$t.sha256(i),o=Buffer.from(Tt(this.digestKey),"hex");if(o.length!==32)return V("Invalid private key length. Expected 32 bytes.");const f=r.fromPrivateKey(o).sign(Buffer.from(Tt(s),"hex"));return ce(f.toString("hex"))}}function Mi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ny(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ni(e,...t){if(!ny(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function iy(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Mi(e.outputLen),Mi(e.blockLen)}function ln(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function qf(e,t){ni(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Gr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function sy(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Ks(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function xt(e,t){return e<<32-t|e>>>t}const oc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function oy(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function ac(e){for(let t=0;t<e.length;t++)e[t]=oy(e[t])}function ay(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function ls(e){return typeof e=="string"&&(e=ay(e)),ni(e),e}function cy(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];ni(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}class Go{clone(){return this._cloneInto()}}function Vf(e){const t=n=>e().update(ls(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function fy(e=32){if(Gr&&typeof Gr.getRandomValues=="function")return Gr.getRandomValues(new Uint8Array(e));if(Gr&&typeof Gr.randomBytes=="function")return Gr.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function uy(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),f=n?4:0,l=n?0:4;e.setUint32(t+f,o,n),e.setUint32(t+l,a,n)}function ly(e,t,r){return e&t^~e&r}function dy(e,t,r){return e&t^e&r^t&r}class hy extends Go{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ks(this.buffer)}update(t){ln(this);const{view:r,buffer:n,blockLen:i}=this;t=ls(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const f=Ks(t);for(;i<=s-o;o+=i)this.process(f,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ln(this),qf(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let p=o;p<i;p++)r[p]=0;uy(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Ks(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=f/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,d[p],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}}const py=new Uint32Array([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]),ir=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),sr=new Uint32Array(64);class yy extends hy{constructor(){super(64,32,8,!1),this.A=ir[0]|0,this.B=ir[1]|0,this.C=ir[2]|0,this.D=ir[3]|0,this.E=ir[4]|0,this.F=ir[5]|0,this.G=ir[6]|0,this.H=ir[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:f}=this;return[t,r,n,i,s,o,a,f]}set(t,r,n,i,s,o,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=f|0}process(t,r){for(let p=0;p<16;p++,r+=4)sr[p]=t.getUint32(r,!1);for(let p=16;p<64;p++){const w=sr[p-15],y=sr[p-2],I=xt(w,7)^xt(w,18)^w>>>3,S=xt(y,17)^xt(y,19)^y>>>10;sr[p]=S+sr[p-7]+I+sr[p-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:f,G:l,H:d}=this;for(let p=0;p<64;p++){const w=xt(a,6)^xt(a,11)^xt(a,25),y=d+w+ly(a,f,l)+py[p]+sr[p]|0,S=(xt(n,2)^xt(n,13)^xt(n,22))+dy(n,i,s)|0;d=l,l=f,f=a,a=o+y|0,o=s,s=i,i=n,n=y+S|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,f,l,d)}roundClean(){sr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Gf=Vf(()=>new yy);class Wf extends Go{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,iy(t);const n=ls(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(n.length>i?t.create().update(n).digest():n);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return ln(this),this.iHash.update(t),this}digestInto(t){ln(this),ni(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Kf=(e,t,r)=>new Wf(e,t).update(r).digest();Kf.create=(e,t)=>new Wf(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ds=BigInt(0),hs=BigInt(1),my=BigInt(2);function Ur(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ii(e){if(!Ur(e))throw new Error("Uint8Array expected")}function dn(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}const by=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function hn(e){ii(e);let t="";for(let r=0;r<e.length;r++)t+=by[e[r]];return t}function Jr(e){const t=e.toString(16);return t.length&1?"0"+t:t}function Wo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ds:BigInt("0x"+e)}const Lt={_0:48,_9:57,A:65,F:70,a:97,f:102};function cc(e){if(e>=Lt._0&&e<=Lt._9)return e-Lt._0;if(e>=Lt.A&&e<=Lt.F)return e-(Lt.A-10);if(e>=Lt.a&&e<=Lt.f)return e-(Lt.a-10)}function pn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=cc(e.charCodeAt(s)),a=cc(e.charCodeAt(s+1));if(o===void 0||a===void 0){const f=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[i]=o*16+a}return n}function Tr(e){return Wo(hn(e))}function Ko(e){return ii(e),Wo(hn(Uint8Array.from(e).reverse()))}function yn(e,t){return pn(e.toString(16).padStart(t*2,"0"))}function Yo(e,t){return yn(e,t).reverse()}function gy(e){return pn(Jr(e))}function yt(e,t,r){let n;if(typeof t=="string")try{n=pn(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ur(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const i=n.length;if(typeof r=="number"&&i!==r)throw new Error(e+" of length "+r+" expected, got "+i);return n}function Wn(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];ii(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}function wy(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function _y(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}const Ys=e=>typeof e=="bigint"&&ds<=e;function ps(e,t,r){return Ys(e)&&Ys(t)&&Ys(r)&&t<=e&&e<r}function kr(e,t,r,n){if(!ps(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Yf(e){let t;for(t=0;e>ds;e>>=hs,t+=1);return t}function vy(e,t){return e>>BigInt(t)&hs}function Ey(e,t,r){return e|(r?hs:ds)<<BigInt(t)}const Xo=e=>(my<<BigInt(e-1))-hs,Xs=e=>new Uint8Array(e),fc=e=>Uint8Array.from(e);function Xf(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Xs(e),i=Xs(e),s=0;const o=()=>{n.fill(1),i.fill(0),s=0},a=(...p)=>r(i,n,...p),f=(p=Xs())=>{i=a(fc([0]),p),n=a(),p.length!==0&&(i=a(fc([1]),p),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let p=0;const w=[];for(;p<t;){n=a();const y=n.slice();w.push(y),p+=n.length}return Wn(...w)};return(p,w)=>{o(),f(p);let y;for(;!(y=w(l()));)f();return o(),y}}const xy={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Ur(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function si(e,t,r={}){const n=(i,s,o)=>{const a=xy[s];if(typeof a!="function")throw new Error("invalid validator function");const f=e[i];if(!(o&&f===void 0)&&!a(f,e))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+f)};for(const[i,s]of Object.entries(t))n(i,s,!1);for(const[i,s]of Object.entries(r))n(i,s,!0);return e}const Sy=()=>{throw new Error("not implemented")};function go(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(i!==void 0)return i;const s=e(r,...n);return t.set(r,s),s}}const Ay=Object.freeze(Object.defineProperty({__proto__:null,aInRange:kr,abool:dn,abytes:ii,bitGet:vy,bitLen:Yf,bitMask:Xo,bitSet:Ey,bytesToHex:hn,bytesToNumberBE:Tr,bytesToNumberLE:Ko,concatBytes:Wn,createHmacDrbg:Xf,ensureBytes:yt,equalBytes:wy,hexToBytes:pn,hexToNumber:Wo,inRange:ps,isBytes:Ur,memoized:go,notImplemented:Sy,numberToBytesBE:yn,numberToBytesLE:Yo,numberToHexUnpadded:Jr,numberToVarBytesBE:gy,utf8ToBytes:_y,validateObject:si},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ne=BigInt(0),Pe=BigInt(1),Ar=BigInt(2),By=BigInt(3),wo=BigInt(4),uc=BigInt(5),lc=BigInt(8);function rt(e,t){const r=e%t;return r>=Ne?r:t+r}function Iy(e,t,r){if(t<Ne)throw new Error("invalid exponent, negatives unsupported");if(r<=Ne)throw new Error("invalid modulus");if(r===Pe)return Ne;let n=Pe;for(;t>Ne;)t&Pe&&(n=n*e%r),e=e*e%r,t>>=Pe;return n}function ct(e,t,r){let n=e;for(;t-- >Ne;)n*=n,n%=r;return n}function _o(e,t){if(e===Ne)throw new Error("invert: expected non-zero number");if(t<=Ne)throw new Error("invert: expected positive modulus, got "+t);let r=rt(e,t),n=t,i=Ne,s=Pe;for(;r!==Ne;){const a=n/r,f=n%r,l=i-s*a;n=r,r=f,i=s,s=l}if(n!==Pe)throw new Error("invert: does not exist");return rt(i,t)}function Ty(e){const t=(e-Pe)/Ar;let r,n,i;for(r=e-Pe,n=0;r%Ar===Ne;r/=Ar,n++);for(i=Ar;i<e&&Iy(i,t,e)!==e-Pe;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const o=(e+Pe)/wo;return function(f,l){const d=f.pow(l,o);if(!f.eql(f.sqr(d),l))throw new Error("Cannot find square root");return d}}const s=(r+Pe)/Ar;return function(a,f){if(a.pow(f,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,d=a.pow(a.mul(a.ONE,i),r),p=a.pow(f,s),w=a.pow(f,r);for(;!a.eql(w,a.ONE);){if(a.eql(w,a.ZERO))return a.ZERO;let y=1;for(let S=a.sqr(w);y<l&&!a.eql(S,a.ONE);y++)S=a.sqr(S);const I=a.pow(d,Pe<<BigInt(l-y-1));d=a.sqr(I),p=a.mul(p,I),w=a.mul(w,d),l=y}return p}}function ky(e){if(e%wo===By){const t=(e+Pe)/wo;return function(n,i){const s=n.pow(i,t);if(!n.eql(n.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%lc===uc){const t=(e-uc)/lc;return function(n,i){const s=n.mul(i,Ar),o=n.pow(s,t),a=n.mul(i,o),f=n.mul(n.mul(a,Ar),o),l=n.mul(a,n.sub(f,n.ONE));if(!n.eql(n.sqr(l),i))throw new Error("Cannot find square root");return l}}return Ty(e)}const Py=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Oy(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Py.reduce((n,i)=>(n[i]="function",n),t);return si(e,r)}function Ry(e,t,r){if(r<Ne)throw new Error("invalid exponent, negatives unsupported");if(r===Ne)return e.ONE;if(r===Pe)return t;let n=e.ONE,i=t;for(;r>Ne;)r&Pe&&(n=e.mul(n,i)),i=e.sqr(i),r>>=Pe;return n}function Cy(e,t){const r=new Array(t.length),n=t.reduce((s,o,a)=>e.is0(o)?s:(r[a]=s,e.mul(s,o)),e.ONE),i=e.inv(n);return t.reduceRight((s,o,a)=>e.is0(o)?s:(r[a]=e.mul(s,r[a]),e.mul(s,o)),i),r}function Zf(e,t){const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Jf(e,t,r=!1,n={}){if(e<=Ne)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:i,nByteLength:s}=Zf(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:s,MASK:Xo(i),ZERO:Ne,ONE:Pe,create:f=>rt(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return Ne<=f&&f<e},is0:f=>f===Ne,isOdd:f=>(f&Pe)===Pe,neg:f=>rt(-f,e),eql:(f,l)=>f===l,sqr:f=>rt(f*f,e),add:(f,l)=>rt(f+l,e),sub:(f,l)=>rt(f-l,e),mul:(f,l)=>rt(f*l,e),pow:(f,l)=>Ry(a,f,l),div:(f,l)=>rt(f*_o(l,e),e),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>_o(f,e),sqrt:n.sqrt||(f=>(o||(o=ky(e)),o(a,f))),invertBatch:f=>Cy(a,f),cmov:(f,l,d)=>d?l:f,toBytes:f=>r?Yo(f,s):yn(f,s),fromBytes:f=>{if(f.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+f.length);return r?Ko(f):Tr(f)}});return Object.freeze(a)}function Qf(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function eu(e){const t=Qf(e);return t+Math.ceil(t/2)}function Uy(e,t,r=!1){const n=e.length,i=Qf(t),s=eu(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const o=r?Ko(e):Tr(e),a=rt(o,t-Pe)+Pe;return r?Yo(a,i):yn(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dc=BigInt(0),wi=BigInt(1);function Zs(e,t){const r=t.negate();return e?r:t}function tu(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Js(e,t){tu(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function Ly(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ny(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}const Qs=new WeakMap,ru=new WeakMap;function eo(e){return ru.get(e)||1}function Hy(e,t){return{constTimeNegate:Zs,hasPrecomputes(r){return eo(r)!==1},unsafeLadder(r,n,i=e.ZERO){let s=r;for(;n>dc;)n&wi&&(i=i.add(s)),s=s.double(),n>>=wi;return i},precomputeWindow(r,n){const{windows:i,windowSize:s}=Js(n,t),o=[];let a=r,f=a;for(let l=0;l<i;l++){f=a,o.push(f);for(let d=1;d<s;d++)f=f.add(a),o.push(f);a=f.double()}return o},wNAF(r,n,i){const{windows:s,windowSize:o}=Js(r,t);let a=e.ZERO,f=e.BASE;const l=BigInt(2**r-1),d=2**r,p=BigInt(r);for(let w=0;w<s;w++){const y=w*o;let I=Number(i&l);i>>=p,I>o&&(I-=d,i+=wi);const S=y,_=y+Math.abs(I)-1,A=w%2!==0,k=I<0;I===0?f=f.add(Zs(A,n[S])):a=a.add(Zs(k,n[_]))}return{p:a,f}},wNAFUnsafe(r,n,i,s=e.ZERO){const{windows:o,windowSize:a}=Js(r,t),f=BigInt(2**r-1),l=2**r,d=BigInt(r);for(let p=0;p<o;p++){const w=p*a;if(i===dc)break;let y=Number(i&f);if(i>>=d,y>a&&(y-=l,i+=wi),y===0)continue;let I=n[w+Math.abs(y)-1];y<0&&(I=I.negate()),s=s.add(I)}return s},getPrecomputes(r,n,i){let s=Qs.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Qs.set(n,i(s))),s},wNAFCached(r,n,i){const s=eo(r);return this.wNAF(s,this.getPrecomputes(s,r,i),n)},wNAFCachedUnsafe(r,n,i,s){const o=eo(r);return o===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,i),n,s)},setWindowSize(r,n){tu(n,t),ru.set(r,n),Qs.delete(r)}}}function Fy(e,t,r,n){if(Ly(r,e),Ny(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=e.ZERO,s=Yf(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,f=new Array(a+1).fill(i),l=Math.floor((t.BITS-1)/o)*o;let d=i;for(let p=l;p>=0;p-=o){f.fill(i);for(let y=0;y<n.length;y++){const I=n[y],S=Number(I>>BigInt(p)&BigInt(a));f[S]=f[S].add(r[y])}let w=i;for(let y=f.length-1,I=i;y>0;y--)I=I.add(f[y]),w=w.add(I);if(d=d.add(w),p!==0)for(let y=0;y<o;y++)d=d.double()}return d}function nu(e){return Oy(e.Fp),si(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Zf(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function hc(e){e.lowS!==void 0&&dn("lowS",e.lowS),e.prehash!==void 0&&dn("prehash",e.prehash)}function My(e){const t=nu(e);si(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:i}=t;if(r){if(!n.eql(i,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:Dy,hexToBytes:$y}=Ay;class jy extends Error{constructor(t=""){super(t)}}const Ft={Err:jy,_tlv:{encode:(e,t)=>{const{Err:r}=Ft;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");const n=t.length/2,i=Jr(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const s=n>127?Jr(i.length/2|128):"";return Jr(e)+s+i+t},decode(e,t){const{Err:r}=Ft;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const i=t[n++],s=!!(i&128);let o=0;if(!s)o=i;else{const f=i&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");const l=t.subarray(n,n+f);if(l.length!==f)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const d of l)o=o<<8|d;if(n+=f,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){const{Err:t}=Ft;if(e<Dt)throw new t("integer: negative integers are not allowed");let r=Jr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=Ft;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Dy(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=Ft,i=typeof e=="string"?$y(e):e;ii(i);const{v:s,l:o}=n.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:f}=n.decode(2,s),{v:l,l:d}=n.decode(2,f);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(e){const{_tlv:t,_int:r}=Ft,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s)),s=n+i;return t.encode(48,s)}},Dt=BigInt(0),Le=BigInt(1);BigInt(2);const pc=BigInt(3);BigInt(4);function zy(e){const t=My(e),{Fp:r}=t,n=Jf(t.n,t.nBitLength),i=t.toBytes||((S,_,A)=>{const k=_.toAffine();return Wn(Uint8Array.from([4]),r.toBytes(k.x),r.toBytes(k.y))}),s=t.fromBytes||(S=>{const _=S.subarray(1),A=r.fromBytes(_.subarray(0,r.BYTES)),k=r.fromBytes(_.subarray(r.BYTES,2*r.BYTES));return{x:A,y:k}});function o(S){const{a:_,b:A}=t,k=r.sqr(S),E=r.mul(k,S);return r.add(r.add(E,r.mul(S,_)),A)}if(!r.eql(r.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function a(S){return ps(S,Le,t.n)}function f(S){const{allowedPrivateKeyLengths:_,nByteLength:A,wrapPrivateKey:k,n:E}=t;if(_&&typeof S!="bigint"){if(Ur(S)&&(S=hn(S)),typeof S!="string"||!_.includes(S.length))throw new Error("invalid private key");S=S.padStart(A*2,"0")}let v;try{v=typeof S=="bigint"?S:Tr(yt("private key",S,A))}catch{throw new Error("invalid private key, expected hex or "+A+" bytes, got "+typeof S)}return k&&(v=rt(v,E)),kr("private key",v,Le,E),v}function l(S){if(!(S instanceof w))throw new Error("ProjectivePoint expected")}const d=go((S,_)=>{const{px:A,py:k,pz:E}=S;if(r.eql(E,r.ONE))return{x:A,y:k};const v=S.is0();_==null&&(_=v?r.ONE:r.inv(E));const B=r.mul(A,_),x=r.mul(k,_),L=r.mul(E,_);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:B,y:x}}),p=go(S=>{if(S.is0()){if(t.allowInfinityPoint&&!r.is0(S.py))return;throw new Error("bad point: ZERO")}const{x:_,y:A}=S.toAffine();if(!r.isValid(_)||!r.isValid(A))throw new Error("bad point: x or y not FE");const k=r.sqr(A),E=o(_);if(!r.eql(k,E))throw new Error("bad point: equation left != right");if(!S.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(_,A,k){if(this.px=_,this.py=A,this.pz=k,_==null||!r.isValid(_))throw new Error("x required");if(A==null||!r.isValid(A))throw new Error("y required");if(k==null||!r.isValid(k))throw new Error("z required");Object.freeze(this)}static fromAffine(_){const{x:A,y:k}=_||{};if(!_||!r.isValid(A)||!r.isValid(k))throw new Error("invalid affine point");if(_ instanceof w)throw new Error("projective point not allowed");const E=v=>r.eql(v,r.ZERO);return E(A)&&E(k)?w.ZERO:new w(A,k,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(_){const A=r.invertBatch(_.map(k=>k.pz));return _.map((k,E)=>k.toAffine(A[E])).map(w.fromAffine)}static fromHex(_){const A=w.fromAffine(s(yt("pointHex",_)));return A.assertValidity(),A}static fromPrivateKey(_){return w.BASE.multiply(f(_))}static msm(_,A){return Fy(w,n,_,A)}_setWindowSize(_){I.setWindowSize(this,_)}assertValidity(){p(this)}hasEvenY(){const{y:_}=this.toAffine();if(r.isOdd)return!r.isOdd(_);throw new Error("Field doesn't support isOdd")}equals(_){l(_);const{px:A,py:k,pz:E}=this,{px:v,py:B,pz:x}=_,L=r.eql(r.mul(A,x),r.mul(v,E)),M=r.eql(r.mul(k,x),r.mul(B,E));return L&&M}negate(){return new w(this.px,r.neg(this.py),this.pz)}double(){const{a:_,b:A}=t,k=r.mul(A,pc),{px:E,py:v,pz:B}=this;let x=r.ZERO,L=r.ZERO,M=r.ZERO,P=r.mul(E,E),G=r.mul(v,v),K=r.mul(B,B),C=r.mul(E,v);return C=r.add(C,C),M=r.mul(E,B),M=r.add(M,M),x=r.mul(_,M),L=r.mul(k,K),L=r.add(x,L),x=r.sub(G,L),L=r.add(G,L),L=r.mul(x,L),x=r.mul(C,x),M=r.mul(k,M),K=r.mul(_,K),C=r.sub(P,K),C=r.mul(_,C),C=r.add(C,M),M=r.add(P,P),P=r.add(M,P),P=r.add(P,K),P=r.mul(P,C),L=r.add(L,P),K=r.mul(v,B),K=r.add(K,K),P=r.mul(K,C),x=r.sub(x,P),M=r.mul(K,G),M=r.add(M,M),M=r.add(M,M),new w(x,L,M)}add(_){l(_);const{px:A,py:k,pz:E}=this,{px:v,py:B,pz:x}=_;let L=r.ZERO,M=r.ZERO,P=r.ZERO;const G=t.a,K=r.mul(t.b,pc);let C=r.mul(A,v),j=r.mul(k,B),N=r.mul(E,x),$=r.add(A,k),z=r.add(v,B);$=r.mul($,z),z=r.add(C,j),$=r.sub($,z),z=r.add(A,E);let W=r.add(v,x);return z=r.mul(z,W),W=r.add(C,N),z=r.sub(z,W),W=r.add(k,E),L=r.add(B,x),W=r.mul(W,L),L=r.add(j,N),W=r.sub(W,L),P=r.mul(G,z),L=r.mul(K,N),P=r.add(L,P),L=r.sub(j,P),P=r.add(j,P),M=r.mul(L,P),j=r.add(C,C),j=r.add(j,C),N=r.mul(G,N),z=r.mul(K,z),j=r.add(j,N),N=r.sub(C,N),N=r.mul(G,N),z=r.add(z,N),C=r.mul(j,z),M=r.add(M,C),C=r.mul(W,z),L=r.mul($,L),L=r.sub(L,C),C=r.mul($,j),P=r.mul(W,P),P=r.add(P,C),new w(L,M,P)}subtract(_){return this.add(_.negate())}is0(){return this.equals(w.ZERO)}wNAF(_){return I.wNAFCached(this,_,w.normalizeZ)}multiplyUnsafe(_){const{endo:A,n:k}=t;kr("scalar",_,Dt,k);const E=w.ZERO;if(_===Dt)return E;if(this.is0()||_===Le)return this;if(!A||I.hasPrecomputes(this))return I.wNAFCachedUnsafe(this,_,w.normalizeZ);let{k1neg:v,k1:B,k2neg:x,k2:L}=A.splitScalar(_),M=E,P=E,G=this;for(;B>Dt||L>Dt;)B&Le&&(M=M.add(G)),L&Le&&(P=P.add(G)),G=G.double(),B>>=Le,L>>=Le;return v&&(M=M.negate()),x&&(P=P.negate()),P=new w(r.mul(P.px,A.beta),P.py,P.pz),M.add(P)}multiply(_){const{endo:A,n:k}=t;kr("scalar",_,Le,k);let E,v;if(A){const{k1neg:B,k1:x,k2neg:L,k2:M}=A.splitScalar(_);let{p:P,f:G}=this.wNAF(x),{p:K,f:C}=this.wNAF(M);P=I.constTimeNegate(B,P),K=I.constTimeNegate(L,K),K=new w(r.mul(K.px,A.beta),K.py,K.pz),E=P.add(K),v=G.add(C)}else{const{p:B,f:x}=this.wNAF(_);E=B,v=x}return w.normalizeZ([E,v])[0]}multiplyAndAddUnsafe(_,A,k){const E=w.BASE,v=(x,L)=>L===Dt||L===Le||!x.equals(E)?x.multiplyUnsafe(L):x.multiply(L),B=v(this,A).add(v(_,k));return B.is0()?void 0:B}toAffine(_){return d(this,_)}isTorsionFree(){const{h:_,isTorsionFree:A}=t;if(_===Le)return!0;if(A)return A(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:_,clearCofactor:A}=t;return _===Le?this:A?A(w,this):this.multiplyUnsafe(t.h)}toRawBytes(_=!0){return dn("isCompressed",_),this.assertValidity(),i(w,this,_)}toHex(_=!0){return dn("isCompressed",_),hn(this.toRawBytes(_))}}w.BASE=new w(t.Gx,t.Gy,r.ONE),w.ZERO=new w(r.ZERO,r.ONE,r.ZERO);const y=t.nBitLength,I=Hy(w,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:w,normPrivateKeyToScalar:f,weierstrassEquation:o,isWithinCurveOrder:a}}function qy(e){const t=nu(e);return si(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Vy(e){const t=qy(e),{Fp:r,n}=t,i=r.BYTES+1,s=2*r.BYTES+1;function o(N){return rt(N,n)}function a(N){return _o(N,n)}const{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:d,isWithinCurveOrder:p}=zy({...t,toBytes(N,$,z){const W=$.toAffine(),J=r.toBytes(W.x),se=Wn;return dn("isCompressed",z),z?se(Uint8Array.from([$.hasEvenY()?2:3]),J):se(Uint8Array.from([4]),J,r.toBytes(W.y))},fromBytes(N){const $=N.length,z=N[0],W=N.subarray(1);if($===i&&(z===2||z===3)){const J=Tr(W);if(!ps(J,Le,r.ORDER))throw new Error("Point is not on curve");const se=d(J);let be;try{be=r.sqrt(se)}catch(ge){const Se=ge instanceof Error?": "+ge.message:"";throw new Error("Point is not on curve"+Se)}const te=(be&Le)===Le;return(z&1)===1!==te&&(be=r.neg(be)),{x:J,y:be}}else if($===s&&z===4){const J=r.fromBytes(W.subarray(0,r.BYTES)),se=r.fromBytes(W.subarray(r.BYTES,2*r.BYTES));return{x:J,y:se}}else{const J=i,se=s;throw new Error("invalid Point, expected length of "+J+", or uncompressed "+se+", got "+$)}}}),w=N=>hn(yn(N,t.nByteLength));function y(N){const $=n>>Le;return N>$}function I(N){return y(N)?o(-N):N}const S=(N,$,z)=>Tr(N.slice($,z));class _{constructor($,z,W){this.r=$,this.s=z,this.recovery=W,this.assertValidity()}static fromCompact($){const z=t.nByteLength;return $=yt("compactSignature",$,z*2),new _(S($,0,z),S($,z,2*z))}static fromDER($){const{r:z,s:W}=Ft.toSig(yt("DER",$));return new _(z,W)}assertValidity(){kr("r",this.r,Le,n),kr("s",this.s,Le,n)}addRecoveryBit($){return new _(this.r,this.s,$)}recoverPublicKey($){const{r:z,s:W,recovery:J}=this,se=x(yt("msgHash",$));if(J==null||![0,1,2,3].includes(J))throw new Error("recovery id invalid");const be=J===2||J===3?z+t.n:z;if(be>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const te=J&1?"03":"02",fe=f.fromHex(te+w(be)),ge=a(be),Se=o(-se*ge),je=o(W*ge),O=f.BASE.multiplyAndAddUnsafe(fe,Se,je);if(!O)throw new Error("point at infinify");return O.assertValidity(),O}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new _(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return pn(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return pn(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const A={isValidPrivateKey(N){try{return l(N),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const N=eu(t.n);return Uy(t.randomBytes(N),t.n)},precompute(N=8,$=f.BASE){return $._setWindowSize(N),$.multiply(BigInt(3)),$}};function k(N,$=!0){return f.fromPrivateKey(N).toRawBytes($)}function E(N){const $=Ur(N),z=typeof N=="string",W=($||z)&&N.length;return $?W===i||W===s:z?W===2*i||W===2*s:N instanceof f}function v(N,$,z=!0){if(E(N))throw new Error("first arg must be private key");if(!E($))throw new Error("second arg must be public key");return f.fromHex($).multiply(l(N)).toRawBytes(z)}const B=t.bits2int||function(N){if(N.length>8192)throw new Error("input is too large");const $=Tr(N),z=N.length*8-t.nBitLength;return z>0?$>>BigInt(z):$},x=t.bits2int_modN||function(N){return o(B(N))},L=Xo(t.nBitLength);function M(N){return kr("num < 2^"+t.nBitLength,N,Dt,L),yn(N,t.nByteLength)}function P(N,$,z=G){if(["recovered","canonical"].some(D=>D in z))throw new Error("sign() legacy options not supported");const{hash:W,randomBytes:J}=t;let{lowS:se,prehash:be,extraEntropy:te}=z;se==null&&(se=!0),N=yt("msgHash",N),hc(z),be&&(N=yt("prehashed msgHash",W(N)));const fe=x(N),ge=l($),Se=[M(ge),M(fe)];if(te!=null&&te!==!1){const D=te===!0?J(r.BYTES):te;Se.push(yt("extraEntropy",D))}const je=Wn(...Se),O=fe;function R(D){const Y=B(D);if(!p(Y))return;const Q=a(Y),b=f.BASE.multiply(Y).toAffine(),g=o(b.x);if(g===Dt)return;const F=o(Q*o(O+g*ge));if(F===Dt)return;let q=(b.x===g?0:2)|Number(b.y&Le),ue=F;return se&&y(F)&&(ue=I(F),q^=1),new _(g,ue,q)}return{seed:je,k2sig:R}}const G={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function C(N,$,z=G){const{seed:W,k2sig:J}=P(N,$,z),se=t;return Xf(se.hash.outputLen,se.nByteLength,se.hmac)(W,J)}f.BASE._setWindowSize(8);function j(N,$,z,W=K){var q;const J=N;$=yt("msgHash",$),z=yt("publicKey",z);const{lowS:se,prehash:be,format:te}=W;if(hc(W),"strict"in W)throw new Error("options.strict was renamed to lowS");if(te!==void 0&&te!=="compact"&&te!=="der")throw new Error("format must be compact or der");const fe=typeof J=="string"||Ur(J),ge=!fe&&!te&&typeof J=="object"&&J!==null&&typeof J.r=="bigint"&&typeof J.s=="bigint";if(!fe&&!ge)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Se,je;try{if(ge&&(Se=new _(J.r,J.s)),fe){try{te!=="compact"&&(Se=_.fromDER(J))}catch(ue){if(!(ue instanceof Ft.Err))throw ue}!Se&&te!=="der"&&(Se=_.fromCompact(J))}je=f.fromHex(z)}catch{return!1}if(!Se||se&&Se.hasHighS())return!1;be&&($=t.hash($));const{r:O,s:R}=Se,D=x($),Y=a(R),Q=o(D*Y),b=o(O*Y),g=(q=f.BASE.multiplyAndAddUnsafe(je,Q,b))==null?void 0:q.toAffine();return g?o(g.x)===O:!1}return{CURVE:t,getPublicKey:k,getSharedSecret:v,sign:C,verify:j,ProjectivePoint:f,Signature:_,utils:A}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Gy(e){return{hash:e,hmac:(t,...r)=>Kf(e,t,cy(...r)),randomBytes:fy}}function Wy(e,t){const r=n=>Vy({...e,...Gy(n)});return{...r(t),create:r}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const iu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),yc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ky=BigInt(1),vo=BigInt(2),mc=(e,t)=>(e+t/vo)/t;function Yy(e){const t=iu,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),f=BigInt(88),l=e*e*e%t,d=l*l*e%t,p=ct(d,r,t)*d%t,w=ct(p,r,t)*d%t,y=ct(w,vo,t)*l%t,I=ct(y,i,t)*y%t,S=ct(I,s,t)*I%t,_=ct(S,a,t)*S%t,A=ct(_,f,t)*_%t,k=ct(A,a,t)*S%t,E=ct(k,r,t)*d%t,v=ct(E,o,t)*I%t,B=ct(v,n,t)*l%t,x=ct(B,vo,t);if(!Eo.eql(Eo.sqr(x),e))throw new Error("Cannot find square root");return x}const Eo=Jf(iu,void 0,void 0,{sqrt:Yy}),ys=Wy({a:BigInt(0),b:BigInt(7),Fp:Eo,n:yc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=yc,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ky*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,o=BigInt("0x100000000000000000000000000000000"),a=mc(s*e,t),f=mc(-n*e,t);let l=rt(e-a*r-f*i,t),d=rt(-a*n-f*s,t);const p=l>o,w=d>o;if(p&&(l=t-l),w&&(d=t-d),l>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:p,k1:l,k2neg:w,k2:d}}}},Gf);BigInt(0);ys.ProjectivePoint;const su="2.22.23";let Rn={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${su}`};class oe extends Error{constructor(t,r={}){var a;const n=(()=>{var f;return r.cause instanceof oe?r.cause.details:(f=r.cause)!=null&&f.message?r.cause.message:r.details})(),i=r.cause instanceof oe&&r.cause.docsPath||r.docsPath,s=(a=Rn.getDocsUrl)==null?void 0:a.call(Rn,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...Rn.version?[`Version: ${Rn.version}`]:[]].join(`
|
|
32
32
|
`);super(o,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=su}walk(t){return ou(this,t)}}function ou(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?ou(e.cause,t):t?null:e}class au extends oe{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 Xy extends oe{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}class cu extends oe{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 fu extends oe{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 bn(e,{dir:t,size:r=32}={}){return typeof e=="string"?dr(e,{dir:t,size:r}):Zy(e,{dir:t,size:r})}function dr(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new fu({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function Zy(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new fu({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}function oi(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function De(e){return oi(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function Di(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}const Jy=new TextEncoder;function uu(e,t={}){return typeof e=="number"||typeof e=="bigint"?em(e,t):typeof e=="boolean"?Qy(e,t):oi(e)?Kt(e,t):lu(e,t)}function Qy(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(gn(r,{size:t.size}),bn(r,{size:t.size})):r}const Nt={zero:48,nine:57,A:65,F:70,a:97,f:102};function bc(e){if(e>=Nt.zero&&e<=Nt.nine)return e-Nt.zero;if(e>=Nt.A&&e<=Nt.F)return e-(Nt.A-10);if(e>=Nt.a&&e<=Nt.f)return e-(Nt.a-10)}function Kt(e,t={}){let r=e;t.size&&(gn(r,{size:t.size}),r=bn(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 f=bc(n.charCodeAt(a++)),l=bc(n.charCodeAt(a++));if(f===void 0||l===void 0)throw new oe(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=f*16+l}return s}function em(e,t){const r=dt(e,t);return Kt(r)}function lu(e,t={}){const r=Jy.encode(e);return typeof t.size=="number"?(gn(r,{size:t.size}),bn(r,{dir:"right",size:t.size})):r}function gn(e,{size:t}){if(De(e)>t)throw new Xy({givenSize:De(e),maxSize:t})}function cr(e,t={}){const{signed:r}=t;t.size&&gn(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 $i(e,t={}){return Number(cr(e,t))}const tm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ee(e,t={}){return typeof e=="number"||typeof e=="bigint"?dt(e,t):typeof e=="string"?ji(e,t):typeof e=="boolean"?du(e,t):Xt(e,t)}function du(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(gn(r,{size:t.size}),bn(r,{size:t.size})):r}function Xt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=tm[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(gn(n,{size:t.size}),bn(n,{dir:"right",size:t.size})):n}function dt(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 f=typeof e=="bigint"?"n":"";throw new au({max:s?`${s}${f}`:void 0,min:`${o}${f}`,signed:r,size:n,value:`${e}${f}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?bn(a,{size:n}):a}const rm=new TextEncoder;function ji(e,t={}){const r=rm.encode(e);return Xt(r,t)}class mt extends oe{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 hu 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 _i=BigInt(2**32-1),gc=BigInt(32);function nm(e,t=!1){return t?{h:Number(e&_i),l:Number(e>>gc&_i)}:{h:Number(e>>gc&_i)|0,l:Number(e&_i)|0}}function im(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}=nm(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const sm=(e,t,r)=>e<<r|t>>>32-r,om=(e,t,r)=>t<<r|e>>>32-r,am=(e,t,r)=>t<<r-32|e>>>64-r,cm=(e,t,r)=>e<<r-32|t>>>64-r,pu=[],yu=[],mu=[],fm=BigInt(0),Cn=BigInt(1),um=BigInt(2),lm=BigInt(7),dm=BigInt(256),hm=BigInt(113);for(let e=0,t=Cn,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],pu.push(2*(5*n+r)),yu.push((e+1)*(e+2)/2%64);let i=fm;for(let s=0;s<7;s++)t=(t<<Cn^(t>>lm)*hm)%dm,t&um&&(i^=Cn<<(Cn<<BigInt(s))-Cn);mu.push(i)}const[pm,ym]=im(mu,!0),wc=(e,t,r)=>r>32?am(e,t,r):sm(e,t,r),_c=(e,t,r)=>r>32?cm(e,t,r):om(e,t,r);function mm(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,f=(o+2)%10,l=r[f],d=r[f+1],p=wc(l,d,1)^r[a],w=_c(l,d,1)^r[a+1];for(let y=0;y<50;y+=10)e[o+y]^=p,e[o+y+1]^=w}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=yu[o],f=wc(i,s,a),l=_c(i,s,a),d=pu[o];i=e[d],s=e[d+1],e[d]=f,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]^=pm[n],e[1]^=ym[n]}r.fill(0)}class Zo extends Go{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,Mi(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=sy(this.state)}keccak(){oc||ac(this.state32),mm(this.state32,this.rounds),oc||ac(this.state32),this.posOut=0,this.pos=0}update(t){ln(this);const{blockLen:r,state:n}=this;t=ls(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){ln(this,!1),ni(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 Mi(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(qf(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 Zo(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 bm=(e,t,r)=>Vf(()=>new Zo(t,e,r)),gm=bm(1,136,256/8);function lt(e,t){const r=t||"hex",n=gm(oi(e,{strict:!1})?uu(e):e);return r==="bytes"?n:ee(n)}const to=new hu(8192);function bu(e,t){if(to.has(`${e}.${t}`))return to.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=lt(lu(r),"bytes"),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 to.set(`${e}.${t}`,s),s}const wm=/^0x[a-fA-F0-9]{40}$/,ro=new hu(8192);function bt(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(ro.has(n))return ro.get(n);const i=wm.test(e)?e.toLowerCase()===e?!0:r?bu(e)===e:!0:!1;return ro.set(n,i),i}function _m(e){if(typeof e=="string"){if(!bt(e,{strict:!1}))throw new mt({address:e});return{address:e,type:"json-rpc"}}if(!bt(e.address,{strict:!1}))throw new mt({address:e.address});return{address:e.address,nonceManager:e.nonceManager,sign:e.sign,experimental_signAuthorization:e.experimental_signAuthorization,signMessage:e.signMessage,signTransaction:e.signTransaction,signTypedData:e.signTypedData,source:"custom",type:"local"}}function vm(e){const t=lt(`0x${e.substring(4)}`).substring(26);return bu(`0x${t}`)}function Em({r:e,s:t,to:r="hex",v:n,yParity:i}){const s=(()=>{if(i===0||i===1)return i;if(n&&(n===27n||n===28n||n>=35n))return n%2n===0n?1:0;throw new Error("Invalid `v` or `yParity` value")})(),o=`0x${new ys.Signature(cr(e),cr(t)).toCompactHex()}${s===0?"1b":"1c"}`;return r==="hex"?o:Kt(o)}let xm=!1;async function ai({hash:e,privateKey:t,to:r="object"}){const{r:n,s:i,recovery:s}=ys.sign(e.slice(2),t.slice(2),{lowS:!0,extraEntropy:xm}),o={r:dt(n,{size:32}),s:dt(i,{size:32}),v:s?28n:27n,yParity:s};return r==="bytes"||r==="hex"?Em({...o,to:r}):o}function yr(e){return typeof e[0]=="string"?Mr(e):Sm(e)}function Sm(e){let t=0;for(const i of e)t+=i.length;const r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.length;return r}function Mr(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class vc extends oe{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Am extends oe{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class Bm extends oe{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Im={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 Bm({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new Am({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new vc({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 vc({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 gu(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(Im);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function mr(e,t="hex"){const r=wu(e),n=gu(new Uint8Array(r.length));return r.encode(n),t==="hex"?Xt(n.bytes):n.bytes}function wu(e){return Array.isArray(e)?Tm(e.map(t=>wu(t))):km(e)}function Tm(e){const t=e.reduce((i,s)=>i+s.length,0),r=_u(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 km(e){const t=typeof e=="string"?Kt(e):e,r=_u(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 _u(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 oe("Length is too large.")}function Pm(e){const{chainId:t,contractAddress:r,nonce:n,to:i}=e,s=lt(Mr(["0x05",mr([t?dt(t):"0x",r,n?dt(n):"0x"])]));return i==="bytes"?Kt(s):s}async function Om(e){const{contractAddress:t,chainId:r,nonce:n,privateKey:i,to:s="object"}=e,o=await ai({hash:Pm({contractAddress:t,chainId:r,nonce:n}),privateKey:i,to:s});return s==="object"?{contractAddress:t,chainId:r,nonce:n,...o}:o}const Rm=`Ethereum Signed Message:
|
|
33
33
|
`;function Cm(e){const t=typeof e=="string"?ji(e):typeof e.raw=="string"?e.raw:Xt(e.raw),r=ji(`${Rm}${De(t)}`);return yr([r,t])}function Um(e,t){return lt(Cm(e),t)}async function Lm({message:e,privateKey:t}){return await ai({hash:Um(e),privateKey:t,to:"hex"})}const Nm={ether:-9,wei:9};function Hm(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 xo(e,t="wei"){return Hm(e,Nm[t])}function Fm(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(`
|
|
34
34
|
`)}class Mm extends oe{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class Dm extends oe{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Fm(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 $m extends oe{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 vu(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=>Kt(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>Xt(s))}function Eu(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=>Kt(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>Kt(o)):e.commitments,s=[];for(let o=0;o<n.length;o++){const a=n[o],f=i[o];s.push(Uint8Array.from(t.computeBlobKzgProof(a,f)))}return r==="bytes"?s:s.map(o=>Xt(o))}function jm(e,t){return Gf(oi(e,{strict:!1})?uu(e):e)}function zm(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=jm(t);return i.set([r],0),n==="bytes"?i:Xt(i)}function qm(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const s of t)i.push(zm({commitment:s,to:n,version:r}));return i}const Ec=6,xu=32,Jo=4096,Su=xu*Jo,xc=Su*Ec-1-1*Jo*Ec,Au=1;class Vm extends oe{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Bu extends oe{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class Gm extends oe{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class Wm extends oe{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Au}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function Km(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?Kt(e.data):e.data,n=De(r);if(!n)throw new Bu;if(n>xc)throw new Vm({maxSize:xc,size:n});const i=[];let s=!0,o=0;for(;s;){const a=gu(new Uint8Array(Su));let f=0;for(;f<Jo;){const l=r.slice(o,o+(xu-1));if(a.pushByte(0),a.pushBytes(l),l.length<31){a.pushByte(128),s=!1;break}f++,o+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>Xt(a.bytes))}function Ym(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??Km({data:t,to:n}),s=e.commitments??vu({blobs:i,kzg:r,to:n}),o=e.proofs??Eu({blobs:i,commitments:s,kzg:r,to:n}),a=[];for(let f=0;f<i.length;f++)a.push({blob:i[f],commitment:s[f],proof:o[f]});return a}function Xm(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?ee(i):"0x",n,s?ee(s):"0x",...ci({},o)])}return t}const Qo=2n**256n-1n;class ms extends oe{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class bs extends oe{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${xo(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(bs,"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 Iu extends oe{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${xo(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${xo(n)} gwei`:""}).`].join(`
|
|
@@ -36,4 +36,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}var _h=et.Buffer,Li=hr.crypto||hr.
|
|
|
36
36
|
`),{name:"AbiEncodingArrayLengthMismatchError"})}}class lb extends oe{constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${De(r)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class db extends oe{constructor({expectedLength:t,givenLength:r}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${t}`,`Given length (values): ${r}`].join(`
|
|
37
37
|
`),{name:"AbiEncodingLengthMismatchError"})}}class hb extends oe{constructor({expectedSize:t,givenSize:r}){super(`Expected bytes${t}, got bytes${r}.`,{name:"BytesSizeMismatchError"})}}class pb extends oe{constructor(t,{docsPath:r}){super([`Type "${t}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(`
|
|
38
38
|
`),{docsPath:r,name:"InvalidAbiEncodingType"})}}class yb extends oe{constructor(t){super([`Value "${t}" is not a valid array.`].join(`
|
|
39
|
-
`),{name:"InvalidArrayError"})}}const mb=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Ru=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function Cu(e,t){if(e.length!==t.length)throw new db({expectedLength:e.length,givenLength:t.length});const r=bb({params:e,values:t}),n=ra(r);return n.length===0?"0x":n}function bb({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(ta({param:e[n],value:t[n]}));return r}function ta({param:e,value:t}){const r=Ab(e.type);if(r){const[n,i]=r;return wb(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return Sb(t,{param:e});if(e.type==="address")return gb(t);if(e.type==="bool")return vb(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=Ru.exec(e.type)??[];return Eb(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return _b(t,{param:e});if(e.type==="string")return xb(t);throw new pb(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function ra(e){let t=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?t+=32:t+=De(a)}const r=[],n=[];let i=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?(r.push(dt(t+i,{size:32})),n.push(a),i+=De(a)):r.push(a)}return yr([...r,...n])}function gb(e){if(!bt(e))throw new mt({address:e});return{dynamic:!1,encoded:dr(e.toLowerCase())}}function wb(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new yb(e);if(!n&&e.length!==t)throw new ub({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const s=[];for(let o=0;o<e.length;o++){const a=ta({param:r,value:e[o]});a.dynamic&&(i=!0),s.push(a)}if(n||i){const o=ra(s);if(n){const a=dt(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?yr([a,o]):a}}if(i)return{dynamic:!0,encoded:o}}return{dynamic:!1,encoded:yr(s.map(({encoded:o})=>o))}}function _b(e,{param:t}){const[,r]=t.type.split("bytes"),n=De(e);if(!r){let i=e;return n%32!==0&&(i=dr(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:yr([dr(dt(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new lb({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:dr(e,{dir:"right"})}}function vb(e){if(typeof e!="boolean")throw new oe(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:dr(du(e))}}function Eb(e,{signed:t,size:r=256}){if(typeof r=="number"){const n=2n**(BigInt(r)-(t?1n:0n))-1n,i=t?-n-1n:0n;if(e>n||e<i)throw new au({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:dt(e,{size:32,signed:t})}}function xb(e){const t=ji(e),r=Math.ceil(De(t)/32),n=[];for(let i=0;i<r;i++)n.push(dr(Tu(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:yr([dr(dt(De(t),{size:32})),...n])}}function Sb(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const s=t.components[i],o=Array.isArray(e)?i:s.name,a=ta({param:s,value:e[o]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?ra(n):yr(n.map(({encoded:i})=>i))}}function Ab(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Bb=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);class Ib extends oe{constructor({domain:t}){super(`Invalid domain "${Bb(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class Tb extends oe{constructor({primaryType:t,types:r}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(r))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class kb extends oe{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function Pb(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(o,a)=>{for(const f of o){const{name:l,type:d}=f,p=a[l],w=d.match(Ru);if(w&&(typeof p=="number"||typeof p=="bigint")){const[S,_,A]=w;dt(p,{signed:_==="int",size:Number.parseInt(A)/8})}if(d==="address"&&typeof p=="string"&&!bt(p))throw new mt({address:p});const y=d.match(mb);if(y){const[S,_]=y;if(_&&De(p)!==Number.parseInt(_))throw new hb({expectedSize:Number.parseInt(_),givenSize:De(p)})}const I=i[d];I&&(Rb(d),s(I,p))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new Ib({domain:t});s(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])s(i[n],r);else throw new Tb({primaryType:n,types:i})}function Ob({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},(typeof(e==null?void 0:e.chainId)=="number"||typeof(e==null?void 0:e.chainId)=="bigint")&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}function Rb(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new kb({type:e})}function Cb(e){const{domain:t={},message:r,primaryType:n}=e,i={EIP712Domain:Ob({domain:t}),...e.types};Pb({domain:t,message:r,primaryType:n,types:i});const s=["0x1901"];return t&&s.push(Ub({domain:t,types:i})),n!=="EIP712Domain"&&s.push(Uu({data:r,primaryType:n,types:i})),lt(yr(s))}function Ub({domain:e,types:t}){return Uu({data:e,primaryType:"EIP712Domain",types:t})}function Uu({data:e,primaryType:t,types:r}){const n=Lu({data:e,primaryType:t,types:r});return lt(n)}function Lu({data:e,primaryType:t,types:r}){const n=[{type:"bytes32"}],i=[Lb({primaryType:t,types:r})];for(const s of r[t]){const[o,a]=Hu({types:r,name:s.name,type:s.type,value:e[s.name]});n.push(o),i.push(a)}return Cu(n,i)}function Lb({primaryType:e,types:t}){const r=ee(Nb({primaryType:e,types:t}));return lt(r)}function Nb({primaryType:e,types:t}){let r="";const n=Nu({primaryType:e,types:t});n.delete(e);const i=[e,...Array.from(n).sort()];for(const s of i)r+=`${s}(${t[s].map(({name:o,type:a})=>`${a} ${o}`).join(",")})`;return r}function Nu({primaryType:e,types:t},r=new Set){const n=e.match(/^\w*/u),i=n==null?void 0:n[0];if(r.has(i)||t[i]===void 0)return r;r.add(i);for(const s of t[i])Nu({primaryType:s.type,types:t},r);return r}function Hu({types:e,name:t,type:r,value:n}){if(e[r]!==void 0)return[{type:"bytes32"},lt(Lu({data:n,primaryType:r,types:e}))];if(r==="bytes")return n=`0x${(n.length%2?"0":"")+n.slice(2)}`,[{type:"bytes32"},lt(n)];if(r==="string")return[{type:"bytes32"},lt(ee(n))];if(r.lastIndexOf("]")===r.length-1){const i=r.slice(0,r.lastIndexOf("[")),s=n.map(o=>Hu({name:t,type:i,types:e,value:o}));return[{type:"bytes32"},lt(Cu(s.map(([o])=>o),s.map(([,o])=>o)))]}return[{type:r},n]}async function Hb(e){const{privateKey:t,...r}=e;return await ai({hash:Cb(r),privateKey:t,to:"hex"})}function Fb(e,t={}){const{nonceManager:r}=t,n=ee(ys.getPublicKey(e.slice(2),!1)),i=vm(n);return{..._m({address:i,nonceManager:r,async sign({hash:o}){return ai({hash:o,privateKey:e,to:"hex"})},async experimental_signAuthorization(o){return Om({...o,privateKey:e})},async signMessage({message:o}){return Lm({message:o,privateKey:e})},async signTransaction(o,{serializer:a}={}){return fb({privateKey:e,transaction:o,serializer:a})},async signTypedData(o){return Hb({...o,privateKey:e})}}),publicKey:n,source:"privateKey"}}class ar{constructor(t){this._digestKey=t;const r=Fb("0x"+t);this._userId=r.address}static from(t){return t=Tt(t),/^[0-9a-fA-F]{64}$/.test(t)?ar.isValidPrivateKey(t)?ce(new ar(t)):V("Invalid private key"):V("Invalid digest key format")}static generateRandom(){const t=ar.generateRandomDigestKey();return ar.from(t)}static isValidPrivateKey(t){const r=BigInt("0x"+t),n=1n,i=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");return r>=n&&r<i}static generateRandomDigestKey(){let t;if(typeof window<"u"&&window.crypto){const r=new Uint8Array(32);window.crypto.getRandomValues(r),t=Tt(Buffer.from(r).toString("hex"))}else{const r=Yu.randomBytes(32);t=Tt(Buffer.from(r).toString("hex"))}return ar.isValidPrivateKey(t)?t:ar.generateRandomDigestKey()}get digestKey(){return this._digestKey}get userId(){return this._userId}}const Mb=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];class Fu{constructor(t,r,n){this.url=new Z.Url("/relayer",t),this.auth=n,this.wallet=r}get htlcActorAddress(){if(!this.wallet.account)throw new Error("No account found");return this.wallet.account.address}async initiate(t){if(!this.wallet.account)return Z.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return Z.Err("Account address and order initiator mismatch");const{create_order:r,source_swap:n}=t;if(!n.amount||!n.redeemer||!r.timelock||!r.secret_hash)return Z.Err("Invalid order");const i=Z.with0x(r.secret_hash),s=BigInt(r.timelock),o=Z.with0x(n.redeemer),a=BigInt(n.amount);try{const f=await this.auth.getAuthHeaders();if(f.error)return Z.Err(f.error);const l=$t.getContract({address:Z.with0x(t.source_swap.asset),abi:Mb,client:this.wallet}),d=await l.read.token(),p=await Z.checkAllowanceAndApprove(Number(a),d,t.source_swap.asset,this.wallet);if(p.error)return Z.Err(p.error);const w=await l.read.eip712Domain(),y=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:w[1],version:w[2],chainId:Number(w[3]),verifyingContract:w[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:o,timelock:s,amount:a,secretHash:i}}),I={...f.val,"Content-Type":"application/json"},S=await jt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:y,perform_on:"Source"}),headers:I});return S.error?Z.Err(S.error):S.result?Z.Ok(S.result):Z.Err("Init: No result found")}catch(f){return console.log("init error :",f),Z.Err(String(f))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return Z.Err(n.error);const i=await jt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:Tt(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});return i.error?Z.Err(i.error):i.result?Z.Ok(i.result):Z.Err("Redeem: No result found")}catch(n){return Z.Err(String(n))}}async refund(){return Z.Err("Refund not supported")}}const Mu=[{name:"LockingContract",type:"impl",interface_name:"src::mintable_lock_interface::ILockingContract"},{name:"src::mintable_lock_interface::ILockingContract",type:"interface",items:[{name:"set_locking_contract",type:"function",inputs:[{name:"locking_contract",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"get_locking_contract",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"}]},{name:"LockAndDelegate",type:"impl",interface_name:"src::mintable_lock_interface::ILockAndDelegate"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"src::mintable_lock_interface::ILockAndDelegate",type:"interface",items:[{name:"lock_and_delegate",type:"function",inputs:[{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"lock_and_delegate_by_sig",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"},{name:"nonce",type:"core::felt252"},{name:"expiry",type:"core::integer::u64"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"MintableToken",type:"impl",interface_name:"src::mintable_token_interface::IMintableToken"},{name:"src::mintable_token_interface::IMintableToken",type:"interface",items:[{name:"permissioned_mint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissioned_burn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"MintableTokenCamelImpl",type:"impl",interface_name:"src::mintable_token_interface::IMintableTokenCamel"},{name:"src::mintable_token_interface::IMintableTokenCamel",type:"interface",items:[{name:"permissionedMint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissionedBurn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"Replaceable",type:"impl",interface_name:"src::replaceability_interface::IReplaceable"},{name:"core::array::Span::<core::felt252>",type:"struct",members:[{name:"snapshot",type:"@core::array::Array::<core::felt252>"}]},{name:"src::replaceability_interface::EICData",type:"struct",members:[{name:"eic_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_init_data",type:"core::array::Span::<core::felt252>"}]},{name:"core::option::Option::<src::replaceability_interface::EICData>",type:"enum",variants:[{name:"Some",type:"src::replaceability_interface::EICData"},{name:"None",type:"()"}]},{name:"core::bool",type:"enum",variants:[{name:"False",type:"()"},{name:"True",type:"()"}]},{name:"src::replaceability_interface::ImplementationData",type:"struct",members:[{name:"impl_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_data",type:"core::option::Option::<src::replaceability_interface::EICData>"},{name:"final",type:"core::bool"}]},{name:"src::replaceability_interface::IReplaceable",type:"interface",items:[{name:"get_upgrade_delay",type:"function",inputs:[],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"get_impl_activation_time",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"add_new_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"remove_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"replace_to",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"}]},{name:"AccessControlImplExternal",type:"impl",interface_name:"src::access_control_interface::IAccessControl"},{name:"src::access_control_interface::IAccessControl",type:"interface",items:[{name:"has_role",type:"function",inputs:[{name:"role",type:"core::felt252"},{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"get_role_admin",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[{type:"core::felt252"}],state_mutability:"view"}]},{name:"RolesImpl",type:"impl",interface_name:"src::roles_interface::IMinimalRoles"},{name:"src::roles_interface::IMinimalRoles",type:"interface",items:[{name:"is_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"is_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"register_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"register_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"renounce",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[],state_mutability:"external"}]},{name:"ERC20Impl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20"},{name:"openzeppelin::token::erc20::interface::IERC20",type:"interface",items:[{name:"name",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"symbol",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"decimals",type:"function",inputs:[],outputs:[{type:"core::integer::u8"}],state_mutability:"view"},{name:"total_supply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balance_of",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"allowance",type:"function",inputs:[{name:"owner",type:"core::starknet::contract_address::ContractAddress"},{name:"spender",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transfer",type:"function",inputs:[{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"transfer_from",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"approve",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"ERC20CamelOnlyImpl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20CamelOnly"},{name:"openzeppelin::token::erc20::interface::IERC20CamelOnly",type:"interface",items:[{name:"totalSupply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balanceOf",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transferFrom",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"name",type:"core::felt252"},{name:"symbol",type:"core::felt252"},{name:"decimals",type:"core::integer::u8"},{name:"initial_supply",type:"core::integer::u256"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"permitted_minter",type:"core::starknet::contract_address::ContractAddress"},{name:"provisional_governance_admin",type:"core::starknet::contract_address::ContractAddress"},{name:"upgrade_delay",type:"core::integer::u64"}]},{name:"increase_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"added_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decrease_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtracted_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"increaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"addedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decreaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtractedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Transfer",type:"event",members:[{kind:"data",name:"from",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"to",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Approval",type:"event",members:[{kind:"data",name:"owner",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"spender",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationAdded",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationRemoved",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationReplaced",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationFinalized",type:"event",members:[{kind:"data",name:"impl_hash",type:"core::starknet::class_hash::ClassHash"}]},{kind:"struct",name:"src::access_control_interface::RoleGranted",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleRevoked",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleAdminChanged",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"previous_admin_role",type:"core::felt252"},{kind:"data",name:"new_admin_role",type:"core::felt252"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"enum",name:"src::strk::erc20_lockable::ERC20Lockable::Event",type:"event",variants:[{kind:"nested",name:"Transfer",type:"src::strk::erc20_lockable::ERC20Lockable::Transfer"},{kind:"nested",name:"Approval",type:"src::strk::erc20_lockable::ERC20Lockable::Approval"},{kind:"nested",name:"ImplementationAdded",type:"src::replaceability_interface::ImplementationAdded"},{kind:"nested",name:"ImplementationRemoved",type:"src::replaceability_interface::ImplementationRemoved"},{kind:"nested",name:"ImplementationReplaced",type:"src::replaceability_interface::ImplementationReplaced"},{kind:"nested",name:"ImplementationFinalized",type:"src::replaceability_interface::ImplementationFinalized"},{kind:"nested",name:"RoleGranted",type:"src::access_control_interface::RoleGranted"},{kind:"nested",name:"RoleRevoked",type:"src::access_control_interface::RoleRevoked"},{kind:"nested",name:"RoleAdminChanged",type:"src::access_control_interface::RoleAdminChanged"},{kind:"nested",name:"GovernanceAdminAdded",type:"src::roles_interface::GovernanceAdminAdded"},{kind:"nested",name:"GovernanceAdminRemoved",type:"src::roles_interface::GovernanceAdminRemoved"},{kind:"nested",name:"UpgradeGovernorAdded",type:"src::roles_interface::UpgradeGovernorAdded"},{kind:"nested",name:"UpgradeGovernorRemoved",type:"src::roles_interface::UpgradeGovernorRemoved"}]}],Du=async(e,t,r,n,i)=>{try{const s=new nt.RpcProvider({nodeUrl:i}),a=await new nt.Contract(Mu,ui(t),s).call("allowance",[ui(e.address),ui(r)]),f=BigInt((a==null?void 0:a.toString())||"0"),l=nt.cairo.uint256(BigInt(n));if(f<n){const d=await e.execute([{contractAddress:ui(t),entrypoint:"approve",calldata:[r,l.low,l.high]}]);return ce(d.transaction_hash)}return ce("Allowance already approved")}catch(s){return V(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},$u=[{name:"HTLC",type:"impl",interface_name:"starknet_htlc::interface::IHTLC"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"starknet_htlc::interface::IHTLC",type:"interface",items:[{name:"token",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"},{name:"initiate",type:"function",inputs:[{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_on_behalf",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_with_signature",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"},{name:"redeem",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"secret",type:"core::array::Array::<core::integer::u32>"}],outputs:[],state_mutability:"external"},{name:"refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"}],outputs:[],state_mutability:"external"},{name:"instant_refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"token",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"starknet_htlc::interface::events::Initiated",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"amount",type:"core::integer::u256"}]},{kind:"struct",name:"starknet_htlc::interface::events::Redeemed",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"secret",type:"core::array::Array::<core::integer::u32>"}]},{kind:"struct",name:"starknet_htlc::interface::events::Refunded",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"}]},{kind:"enum",name:"starknet_htlc::htlc::HTLC::Event",type:"event",variants:[{kind:"nested",name:"Initiated",type:"starknet_htlc::interface::events::Initiated"},{kind:"nested",name:"Redeemed",type:"starknet_htlc::interface::events::Redeemed"},{kind:"nested",name:"Refunded",type:"starknet_htlc::interface::events::Refunded"}]}],Db={name:"HTLC",version:nt.shortString.encodeShortString("1"),chainId:"0x534e5f5345504f4c4941",revision:nt.TypedDataRevision.ACTIVE},$b={StarknetDomain:[{name:"name",type:"shortstring"},{name:"version",type:"shortstring"},{name:"chainId",type:"shortstring"},{name:"revision",type:"shortstring"}],Initiate:[{name:"redeemer",type:"ContractAddress"},{name:"amount",type:"u256"},{name:"timelock",type:"u128"},{name:"secretHash",type:"u128*"}]},jb="https://starknet-mainnet.public.blastapi.io";class ju{constructor(t,r,n){this.nodeUrl=n||jb,this.url=new Z.Url("/",t),this.account=r}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async initiate(t){if(!this.account.address)return V("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return V("Invalid order");try{const o=new nt.Contract($u,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),f=nt.num.toHex(a),l=await Du(this.account,f,n.asset,BigInt(s),this.nodeUrl);if(l.error)return V(l.error);const d={domain:Db,primaryType:"Initiate",types:$b,message:{redeemer:i,amount:nt.cairo.uint256(s),timelock:r.timelock,secretHash:Z.hexToU32Array(r.secret_hash)}},p=await this.account.signMessage(d),{r:w,s:y}=p,I=await jt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:{r:w.toString(),s:y.toString()},perform_on:"Source"}),headers:{"Content-Type":"application/json"}});return I.error?V(I.error):I.result?ce(I.result):V("Init: No result found")}catch(o){return V(String(o))}}async redeem(t,r){try{const n=await jt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"}});return n.error?V(n.error):n.result?ce(n.result):V("Redeem: No result found")}catch(n){return V(String(n))}}async refund(){return V("Refund is taken care of by the relayer")}}class na extends Z.EventBroker{constructor(t){super(),this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new bh;const r=ar.from(t.digestKey);if(r.error)throw new Error(r.error);this._digestKey=r.val,this.environment=t.environment;const n=t.environment===Z.Environment.MAINNET?Zr.mainnet:t.environment===Z.Environment.TESTNET?Zr.testnet:Zr.localnet;if(!n)throw new Error("API not found, invalid environment "+t.environment);this._orderbookUrl=new Z.Url(t.api??n.orderbook),this._quote=t.quote??new sf(n.quote),this._auth=Z.Siwe.fromDigestKey(new Z.Url(t.api??n.orderbook),this._digestKey.digestKey),this._orderbook=new Ae.Orderbook(new Z.Url(t.api??n.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._secretManager=t.secretManager??Gn.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new mh,this._blockNumberFetcher=t.blockNumberFetcher??new nf(n.info,t.environment)}static from(t){const r=t.environment===Z.Environment.MAINNET?Zr.mainnet:t.environment===Z.Environment.TESTNET?Zr.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);const n={evm:new Fu(r.evmRelay,t.wallets.evm,Z.Siwe.fromDigestKey(new Z.Url(r.orderbook),t.digestKey)),starknet:new ju(r.starknetRelay,t.wallets.starknet)};return new na({environment:t.environment,digestKey:t.digestKey,htlc:n})}get orderbookUrl(){return this._orderbookUrl.toString()}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return ce(this._btcWallet);const t=await this._secretManager.getDigestKey();if(t.error)return V(t.error);const r=new nn.BitcoinProvider(il(this.environment));return this._btcWallet=nn.BitcoinWallet.fromPrivateKey(t.val,r),ce(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return V(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 V(a.error);const{strategyId:f,btcAddress:l}=t.additionalData,d={strategy_id:f,...l&&{bitcoin_optional_recipient:l}},p={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:Tt(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},w=await this._quote.getAttestedQuote(p);if(w.error)return V(w.error);const y=await this._orderbook.createOrder(w.val,this.auth);if(y.error)return V(y.error);const I=await this.pollOrder(y.val);return I.error?V(I.error):ce(I.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return V("StrategyId is required");if(!t.fromAsset||!t.toAsset)return V("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return V("Source and destination assets cannot be the same");if(Ae.isMainnet(t.fromAsset.chain)&&!Ae.isMainnet(t.toAsset.chain)||!Ae.isMainnet(t.fromAsset.chain)&&Ae.isMainnet(t.toAsset.chain))return V("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return V(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return V(n.error);if(r<n)return V("Send amount should be greater than receive amount");const i=Ae.getTimeLock(t.fromAsset.chain);if(!i)return V("Unsupported chain for timelock");if(Ae.isBitcoin(t.fromAsset.chain)||Ae.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return V("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 V(a.error);if(!this._btcWallet)return V("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return V(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?V(o.error):ce({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(Ae.getBlockchainType(t)){case Ae.BlockchainType.EVM:return this._evmHTLC?ce(this._evmHTLC.htlcActorAddress):V("Please provide evmHTLC when initializing garden");case Ae.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!rl(i)?V("Invalid btc public key"):ce(xr(i))}case Ae.BlockchainType.Starknet:return this._starknetHTLC?ce(this._starknetHTLC.htlcActorAddress):V("Please provide starknetHTLC when initializing garden");default:return V("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return V("Invalid amount ",t);const r=new Ku(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?V("Invalid amount ",t):ce(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await Z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return V(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return ce(r.val);r=await this._orderbook.getOrder(t,!0)}return V(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{if(r.data.length===0)return;const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val);for(let i=0;i<n.val.length;i++){const s=n.val[i],o=Bo(s.status);if(Ae.isBitcoin(s.source_swap.chain)&&s.status===ve.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Re.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(Ae.getBlockchainType(s.destination_swap.chain)){case Ae.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case Ae.BlockchainType.Bitcoin:{const f=this.btcWallet;if(!f){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(f,s,a.val.secret);break}case Ae.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Re.Refund:{switch(Ae.getBlockchainType(s.source_swap.chain)){case Ae.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case Ae.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case Ae.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},!0,{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val))}async btcRedeem(t,r,n){var a,f;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const l=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const p of l.vin)if(p.txid===s){d=!0;break}if(d){this.emit("log",r.create_order.create_id,"already a valid redeem");let p=0;try{const[w]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);w!==0&&(p=w)}catch{p=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:p,redeemTxHash:r.destination_swap.redeem_tx_hash});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 $n.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,xr(r.destination_swap.initiator),xr(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(Tt(n),(f=r.create_order.additional_data)==null?void 0:f.bitcoin_optional_recipient),p=await this.broadcastRedeemTx(d,r.create_order.create_id);if(p.error||!p.val){this.emit("error",r,p.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,p.val)):this.emit("success",r,Re.Redeem,p.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:p.val})}catch(l){console.log("error",l),this.emit("error",r,"Failed btc redeem: "+l)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Re.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await $n.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,xr(r.source_swap.initiator),xr(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,Re.Refund,s),this.emit("success",r,Re.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await $n.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,xr(t.source_swap.initiator),xr(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 jt.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 filterExpiredAndAssignStatus(t){var i;if(t.length===0)return ce([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return V(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(Tc(o))continue;const a=o.source_swap.chain,f=o.destination_swap.chain,l=r==null?void 0:r.val[a],d=r==null?void 0:r.val[f];if(!l||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const p=Ao(o,l,d);n.push({...o,status:p})}return ce(n)}async broadcastRedeemTx(t,r){try{const n=this._orderbookUrl.endpoint("gasless/order/bitcoin/redeem"),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?ce(o.result):V(o.error)}catch(n){return V("Failed to broadcast redeem tx: "+n)}}}const zb="https://starknet-mainnet.public.blastapi.io";class qb{constructor(t,r){this.callData=new nt.CallData(Mu),this.nodeUrl=r||zb,this.account=t}get htlcActorAddress(){return this.account.address}async getHTLCContract(t,r=!1){const n=r?t.destination_swap.asset:t.source_swap.asset;return new nt.Contract($u,n,this.account)}async initiate(t){try{const n=await(await this.getHTLCContract(t)).token();if(!n)throw new Error("Token address retrieval failed");const i=nt.num.toHex(n),s=nt.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await Du(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.nodeUrl);if(a.error)return V(a.error)}catch(a){return V(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...Z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return ce(o.transaction_hash)}catch(r){return V(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:nt.CallData.compile({swap_id:i,secret:Z.hexToU32Array(r)})});return s.transaction_hash?ce(s.transaction_hash):V("Failed to redeem HTLC transaction")}catch{return V("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?ce(i.transaction_hash):V("Failed to refund HTLC transaction")}catch{return V("HTLC Refund Error")}}}function Pt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}function ia(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 zu={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function sa(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?$i(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?$i(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?zu[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=Gb(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 Vb=ia("transaction",sa);function Gb(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 Wb(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:sa(r));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const Kb=ia("block",Wb);function Yb(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 Xb={"0x0":"reverted","0x1":"success"};function Zb(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=>Yb(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?$i(e.transactionIndex):null,status:e.status?Xb[e.status]:null,type:e.type?zu[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const Jb=ia("transactionReceipt",Zb),Qb={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},e1={block:Kb({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=sa(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?cr(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Vb({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?cr(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Jb({format(e){return{l1GasPrice:e.l1GasPrice?cr(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?cr(e.l1GasUsed):null,l1Fee:e.l1Fee?cr(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function t1(e,t){return i1(e)?n1(e):Ou(e,t)}const r1={transaction:t1};function n1(e){s1(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:f}=e,l=[t,n,a??"0x",o?ee(o):"0x",f?ee(f):"0x",i?ee(i):"0x",s?"0x1":"0x",r??"0x"];return Mr(["0x7e",mr(l)])}function i1(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function s1(e){const{from:t,to:r}=e;if(t&&!bt(t))throw new mt({address:t});if(r&&!bt(r))throw new mt({address:r})}const zi={contracts:Qb,formatters:e1,serializers:r1},o1=Pt({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}}}),a1=Pt({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}),Un=1,c1=Pt({...zi,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:{...zi.contracts,disputeGameFactory:{[Un]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Un]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Un]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Un]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Un}),Ln=11155111,f1=Pt({...zi,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:{...zi.contracts,disputeGameFactory:{[Ln]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Ln]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Ln]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Ln]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Ln}),u1=Pt({id:80094,name:"Berachain",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:0}},rpcUrls:{default:{http:["https://rpc.berachain.com"]}},blockExplorers:{default:{name:"Berascan",url:"https://berascan.com"}},testnet:!1}),l1=Pt({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269},ensRegistry:{address:"0xB0eef18971290b333450586D33dcA6cE122651D2",blockCreated:7736794},ensUniversalResolver:{address:"0x41692Ef1EA0C79E6b73077E4A67572D2BDbD7057",blockCreated:7736795}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),d1=Pt({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"cBTC",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api"}},testnet:!0}),h1=Pt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),p1=Pt({id:10143,name:"Monad Testnet",nativeCurrency:{name:"Testnet MON Token",symbol:"MON",decimals:18},rpcUrls:{default:{http:["https://testnet-rpc.monad.xyz"]}},blockExplorers:{default:{name:"Monad Testnet explorer",url:"https://testnet.monadexplorer.com"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:251449}},testnet:!0}),y1=Pt({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}),m1={...y1,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},qu={ethereum:h1,arbitrum:o1,ethereum_sepolia:m1,arbitrum_sepolia:a1,ethereum_localnet:Ae.EthereumLocalnet,arbitrum_localnet:Ae.ArbitrumLocalnet,base_sepolia:f1,base:c1,bera_testnet:l1,citrea_testnet:d1,bera:u1,monad_testnet:p1},b1=async(e,t)=>{var n;const r=qu[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return ce({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=$t.createWalletClient({account:t.account,chain:r,transport:$t.custom(window.ethereum)});return ce({message:"Switched chain",walletClient:i})}catch(i){if(g1(i))try{await t.addChain({chain:r});const s=$t.createWalletClient({account:t.account,chain:r,transport:$t.custom(window.ethereum)});return ce({message:"Added network",walletClient:s})}catch{return V("Failed to add network")}else return V("Failed to switch network")}else return V("Chain not supported")},g1=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.API=Zr;exports.BlockNumberFetcher=nf;exports.EvmRelay=Fu;exports.Garden=na;exports.OrderActions=Re;exports.OrderStatus=ve;exports.ParseOrderStatus=Ao;exports.ParseSwapStatus=so;exports.Quote=sf;exports.SecretManager=Gn;exports.StarknetHTLC=qb;exports.StarknetRelay=ju;exports.SwapStatus=xe;exports.constructOrderPair=Ic;exports.evmToViemChainMap=qu;exports.filterDeadlineExpiredOrders=ol;exports.isExpired=jn;exports.parseAction=sl;exports.parseActionFromStatus=Bo;exports.switchOrAddNetwork=b1;exports.validateBTCAddress=nl;
|
|
39
|
+
`),{name:"InvalidArrayError"})}}const mb=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Ru=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function Cu(e,t){if(e.length!==t.length)throw new db({expectedLength:e.length,givenLength:t.length});const r=bb({params:e,values:t}),n=ra(r);return n.length===0?"0x":n}function bb({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(ta({param:e[n],value:t[n]}));return r}function ta({param:e,value:t}){const r=Ab(e.type);if(r){const[n,i]=r;return wb(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return Sb(t,{param:e});if(e.type==="address")return gb(t);if(e.type==="bool")return vb(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=Ru.exec(e.type)??[];return Eb(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return _b(t,{param:e});if(e.type==="string")return xb(t);throw new pb(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function ra(e){let t=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?t+=32:t+=De(a)}const r=[],n=[];let i=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?(r.push(dt(t+i,{size:32})),n.push(a),i+=De(a)):r.push(a)}return yr([...r,...n])}function gb(e){if(!bt(e))throw new mt({address:e});return{dynamic:!1,encoded:dr(e.toLowerCase())}}function wb(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new yb(e);if(!n&&e.length!==t)throw new ub({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const s=[];for(let o=0;o<e.length;o++){const a=ta({param:r,value:e[o]});a.dynamic&&(i=!0),s.push(a)}if(n||i){const o=ra(s);if(n){const a=dt(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?yr([a,o]):a}}if(i)return{dynamic:!0,encoded:o}}return{dynamic:!1,encoded:yr(s.map(({encoded:o})=>o))}}function _b(e,{param:t}){const[,r]=t.type.split("bytes"),n=De(e);if(!r){let i=e;return n%32!==0&&(i=dr(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:yr([dr(dt(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new lb({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:dr(e,{dir:"right"})}}function vb(e){if(typeof e!="boolean")throw new oe(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:dr(du(e))}}function Eb(e,{signed:t,size:r=256}){if(typeof r=="number"){const n=2n**(BigInt(r)-(t?1n:0n))-1n,i=t?-n-1n:0n;if(e>n||e<i)throw new au({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:dt(e,{size:32,signed:t})}}function xb(e){const t=ji(e),r=Math.ceil(De(t)/32),n=[];for(let i=0;i<r;i++)n.push(dr(Tu(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:yr([dr(dt(De(t),{size:32})),...n])}}function Sb(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const s=t.components[i],o=Array.isArray(e)?i:s.name,a=ta({param:s,value:e[o]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?ra(n):yr(n.map(({encoded:i})=>i))}}function Ab(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Bb=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);class Ib extends oe{constructor({domain:t}){super(`Invalid domain "${Bb(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class Tb extends oe{constructor({primaryType:t,types:r}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(r))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class kb extends oe{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function Pb(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(o,a)=>{for(const f of o){const{name:l,type:d}=f,p=a[l],w=d.match(Ru);if(w&&(typeof p=="number"||typeof p=="bigint")){const[S,_,A]=w;dt(p,{signed:_==="int",size:Number.parseInt(A)/8})}if(d==="address"&&typeof p=="string"&&!bt(p))throw new mt({address:p});const y=d.match(mb);if(y){const[S,_]=y;if(_&&De(p)!==Number.parseInt(_))throw new hb({expectedSize:Number.parseInt(_),givenSize:De(p)})}const I=i[d];I&&(Rb(d),s(I,p))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new Ib({domain:t});s(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])s(i[n],r);else throw new Tb({primaryType:n,types:i})}function Ob({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},(typeof(e==null?void 0:e.chainId)=="number"||typeof(e==null?void 0:e.chainId)=="bigint")&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}function Rb(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new kb({type:e})}function Cb(e){const{domain:t={},message:r,primaryType:n}=e,i={EIP712Domain:Ob({domain:t}),...e.types};Pb({domain:t,message:r,primaryType:n,types:i});const s=["0x1901"];return t&&s.push(Ub({domain:t,types:i})),n!=="EIP712Domain"&&s.push(Uu({data:r,primaryType:n,types:i})),lt(yr(s))}function Ub({domain:e,types:t}){return Uu({data:e,primaryType:"EIP712Domain",types:t})}function Uu({data:e,primaryType:t,types:r}){const n=Lu({data:e,primaryType:t,types:r});return lt(n)}function Lu({data:e,primaryType:t,types:r}){const n=[{type:"bytes32"}],i=[Lb({primaryType:t,types:r})];for(const s of r[t]){const[o,a]=Hu({types:r,name:s.name,type:s.type,value:e[s.name]});n.push(o),i.push(a)}return Cu(n,i)}function Lb({primaryType:e,types:t}){const r=ee(Nb({primaryType:e,types:t}));return lt(r)}function Nb({primaryType:e,types:t}){let r="";const n=Nu({primaryType:e,types:t});n.delete(e);const i=[e,...Array.from(n).sort()];for(const s of i)r+=`${s}(${t[s].map(({name:o,type:a})=>`${a} ${o}`).join(",")})`;return r}function Nu({primaryType:e,types:t},r=new Set){const n=e.match(/^\w*/u),i=n==null?void 0:n[0];if(r.has(i)||t[i]===void 0)return r;r.add(i);for(const s of t[i])Nu({primaryType:s.type,types:t},r);return r}function Hu({types:e,name:t,type:r,value:n}){if(e[r]!==void 0)return[{type:"bytes32"},lt(Lu({data:n,primaryType:r,types:e}))];if(r==="bytes")return n=`0x${(n.length%2?"0":"")+n.slice(2)}`,[{type:"bytes32"},lt(n)];if(r==="string")return[{type:"bytes32"},lt(ee(n))];if(r.lastIndexOf("]")===r.length-1){const i=r.slice(0,r.lastIndexOf("[")),s=n.map(o=>Hu({name:t,type:i,types:e,value:o}));return[{type:"bytes32"},lt(Cu(s.map(([o])=>o),s.map(([,o])=>o)))]}return[{type:r},n]}async function Hb(e){const{privateKey:t,...r}=e;return await ai({hash:Cb(r),privateKey:t,to:"hex"})}function Fb(e,t={}){const{nonceManager:r}=t,n=ee(ys.getPublicKey(e.slice(2),!1)),i=vm(n);return{..._m({address:i,nonceManager:r,async sign({hash:o}){return ai({hash:o,privateKey:e,to:"hex"})},async experimental_signAuthorization(o){return Om({...o,privateKey:e})},async signMessage({message:o}){return Lm({message:o,privateKey:e})},async signTransaction(o,{serializer:a}={}){return fb({privateKey:e,transaction:o,serializer:a})},async signTypedData(o){return Hb({...o,privateKey:e})}}),publicKey:n,source:"privateKey"}}class ar{constructor(t){this._digestKey=t;const r=Fb("0x"+t);this._userId=r.address}static from(t){return t=Tt(t),/^[0-9a-fA-F]{64}$/.test(t)?ar.isValidPrivateKey(t)?ce(new ar(t)):V("Invalid private key"):V("Invalid digest key format")}static generateRandom(){const t=ar.generateRandomDigestKey();return ar.from(t)}static isValidPrivateKey(t){const r=BigInt("0x"+t),n=1n,i=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");return r>=n&&r<i}static generateRandomDigestKey(){let t;if(typeof window<"u"&&window.crypto){const r=new Uint8Array(32);window.crypto.getRandomValues(r),t=Tt(Buffer.from(r).toString("hex"))}else{const r=Yu.randomBytes(32);t=Tt(Buffer.from(r).toString("hex"))}return ar.isValidPrivateKey(t)?t:ar.generateRandomDigestKey()}get digestKey(){return this._digestKey}get userId(){return this._userId}}const Mb=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];class Fu{constructor(t,r,n){this.url=new Z.Url("/relayer",t),this.auth=n,this.wallet=r}get htlcActorAddress(){if(!this.wallet.account)throw new Error("No account found");return this.wallet.account.address}async initiate(t){if(!this.wallet.account)return Z.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return Z.Err("Account address and order initiator mismatch");const{create_order:r,source_swap:n}=t;if(!n.amount||!n.redeemer||!r.timelock||!r.secret_hash)return Z.Err("Invalid order");const i=Z.with0x(r.secret_hash),s=BigInt(r.timelock),o=Z.with0x(n.redeemer),a=BigInt(n.amount);try{const f=await this.auth.getAuthHeaders();if(f.error)return Z.Err(f.error);const l=$t.getContract({address:Z.with0x(t.source_swap.asset),abi:Mb,client:this.wallet}),d=await l.read.token(),p=await Z.checkAllowanceAndApprove(Number(a),d,t.source_swap.asset,this.wallet);if(p.error)return Z.Err(p.error);const w=await l.read.eip712Domain(),y=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:w[1],version:w[2],chainId:Number(w[3]),verifyingContract:w[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:o,timelock:s,amount:a,secretHash:i}}),I={...f.val,"Content-Type":"application/json"},S=await jt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:y,perform_on:"Source"}),headers:I});return S.error?Z.Err(S.error):S.result?Z.Ok(S.result):Z.Err("Init: No result found")}catch(f){return console.log("init error :",f),Z.Err(String(f))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return Z.Err(n.error);const i=await jt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:Tt(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});return i.error?Z.Err(i.error):i.result?Z.Ok(i.result):Z.Err("Redeem: No result found")}catch(n){return Z.Err(String(n))}}async refund(){return Z.Err("Refund not supported")}}const Mu=[{name:"LockingContract",type:"impl",interface_name:"src::mintable_lock_interface::ILockingContract"},{name:"src::mintable_lock_interface::ILockingContract",type:"interface",items:[{name:"set_locking_contract",type:"function",inputs:[{name:"locking_contract",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"get_locking_contract",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"}]},{name:"LockAndDelegate",type:"impl",interface_name:"src::mintable_lock_interface::ILockAndDelegate"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"src::mintable_lock_interface::ILockAndDelegate",type:"interface",items:[{name:"lock_and_delegate",type:"function",inputs:[{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"lock_and_delegate_by_sig",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"},{name:"nonce",type:"core::felt252"},{name:"expiry",type:"core::integer::u64"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"MintableToken",type:"impl",interface_name:"src::mintable_token_interface::IMintableToken"},{name:"src::mintable_token_interface::IMintableToken",type:"interface",items:[{name:"permissioned_mint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissioned_burn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"MintableTokenCamelImpl",type:"impl",interface_name:"src::mintable_token_interface::IMintableTokenCamel"},{name:"src::mintable_token_interface::IMintableTokenCamel",type:"interface",items:[{name:"permissionedMint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissionedBurn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"Replaceable",type:"impl",interface_name:"src::replaceability_interface::IReplaceable"},{name:"core::array::Span::<core::felt252>",type:"struct",members:[{name:"snapshot",type:"@core::array::Array::<core::felt252>"}]},{name:"src::replaceability_interface::EICData",type:"struct",members:[{name:"eic_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_init_data",type:"core::array::Span::<core::felt252>"}]},{name:"core::option::Option::<src::replaceability_interface::EICData>",type:"enum",variants:[{name:"Some",type:"src::replaceability_interface::EICData"},{name:"None",type:"()"}]},{name:"core::bool",type:"enum",variants:[{name:"False",type:"()"},{name:"True",type:"()"}]},{name:"src::replaceability_interface::ImplementationData",type:"struct",members:[{name:"impl_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_data",type:"core::option::Option::<src::replaceability_interface::EICData>"},{name:"final",type:"core::bool"}]},{name:"src::replaceability_interface::IReplaceable",type:"interface",items:[{name:"get_upgrade_delay",type:"function",inputs:[],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"get_impl_activation_time",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"add_new_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"remove_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"replace_to",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"}]},{name:"AccessControlImplExternal",type:"impl",interface_name:"src::access_control_interface::IAccessControl"},{name:"src::access_control_interface::IAccessControl",type:"interface",items:[{name:"has_role",type:"function",inputs:[{name:"role",type:"core::felt252"},{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"get_role_admin",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[{type:"core::felt252"}],state_mutability:"view"}]},{name:"RolesImpl",type:"impl",interface_name:"src::roles_interface::IMinimalRoles"},{name:"src::roles_interface::IMinimalRoles",type:"interface",items:[{name:"is_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"is_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"register_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"register_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"renounce",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[],state_mutability:"external"}]},{name:"ERC20Impl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20"},{name:"openzeppelin::token::erc20::interface::IERC20",type:"interface",items:[{name:"name",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"symbol",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"decimals",type:"function",inputs:[],outputs:[{type:"core::integer::u8"}],state_mutability:"view"},{name:"total_supply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balance_of",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"allowance",type:"function",inputs:[{name:"owner",type:"core::starknet::contract_address::ContractAddress"},{name:"spender",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transfer",type:"function",inputs:[{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"transfer_from",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"approve",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"ERC20CamelOnlyImpl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20CamelOnly"},{name:"openzeppelin::token::erc20::interface::IERC20CamelOnly",type:"interface",items:[{name:"totalSupply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balanceOf",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transferFrom",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"name",type:"core::felt252"},{name:"symbol",type:"core::felt252"},{name:"decimals",type:"core::integer::u8"},{name:"initial_supply",type:"core::integer::u256"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"permitted_minter",type:"core::starknet::contract_address::ContractAddress"},{name:"provisional_governance_admin",type:"core::starknet::contract_address::ContractAddress"},{name:"upgrade_delay",type:"core::integer::u64"}]},{name:"increase_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"added_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decrease_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtracted_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"increaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"addedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decreaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtractedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Transfer",type:"event",members:[{kind:"data",name:"from",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"to",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Approval",type:"event",members:[{kind:"data",name:"owner",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"spender",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationAdded",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationRemoved",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationReplaced",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationFinalized",type:"event",members:[{kind:"data",name:"impl_hash",type:"core::starknet::class_hash::ClassHash"}]},{kind:"struct",name:"src::access_control_interface::RoleGranted",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleRevoked",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleAdminChanged",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"previous_admin_role",type:"core::felt252"},{kind:"data",name:"new_admin_role",type:"core::felt252"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"enum",name:"src::strk::erc20_lockable::ERC20Lockable::Event",type:"event",variants:[{kind:"nested",name:"Transfer",type:"src::strk::erc20_lockable::ERC20Lockable::Transfer"},{kind:"nested",name:"Approval",type:"src::strk::erc20_lockable::ERC20Lockable::Approval"},{kind:"nested",name:"ImplementationAdded",type:"src::replaceability_interface::ImplementationAdded"},{kind:"nested",name:"ImplementationRemoved",type:"src::replaceability_interface::ImplementationRemoved"},{kind:"nested",name:"ImplementationReplaced",type:"src::replaceability_interface::ImplementationReplaced"},{kind:"nested",name:"ImplementationFinalized",type:"src::replaceability_interface::ImplementationFinalized"},{kind:"nested",name:"RoleGranted",type:"src::access_control_interface::RoleGranted"},{kind:"nested",name:"RoleRevoked",type:"src::access_control_interface::RoleRevoked"},{kind:"nested",name:"RoleAdminChanged",type:"src::access_control_interface::RoleAdminChanged"},{kind:"nested",name:"GovernanceAdminAdded",type:"src::roles_interface::GovernanceAdminAdded"},{kind:"nested",name:"GovernanceAdminRemoved",type:"src::roles_interface::GovernanceAdminRemoved"},{kind:"nested",name:"UpgradeGovernorAdded",type:"src::roles_interface::UpgradeGovernorAdded"},{kind:"nested",name:"UpgradeGovernorRemoved",type:"src::roles_interface::UpgradeGovernorRemoved"}]}],Du=async(e,t,r,n,i)=>{try{const s=new et.RpcProvider({nodeUrl:i}),a=await new et.Contract(Mu,ui(t),s).call("allowance",[ui(e.address),ui(r)]),f=BigInt((a==null?void 0:a.toString())||"0"),l=et.cairo.uint256(BigInt(et.uint256.UINT_256_MAX));if(f<n){const d=await e.execute([{contractAddress:ui(t),entrypoint:"approve",calldata:[r,l.low,l.high]}]);return await s.waitForTransaction(d.transaction_hash,{retryInterval:3e3,successStates:[et.TransactionExecutionStatus.SUCCEEDED]}),ce(d.transaction_hash)}return ce("Allowance already approved")}catch(s){return V(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},$u=[{name:"HTLC",type:"impl",interface_name:"starknet_htlc::interface::IHTLC"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"starknet_htlc::interface::IHTLC",type:"interface",items:[{name:"token",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"},{name:"initiate",type:"function",inputs:[{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_on_behalf",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_with_signature",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"},{name:"redeem",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"secret",type:"core::array::Array::<core::integer::u32>"}],outputs:[],state_mutability:"external"},{name:"refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"}],outputs:[],state_mutability:"external"},{name:"instant_refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"token",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"starknet_htlc::interface::events::Initiated",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"amount",type:"core::integer::u256"}]},{kind:"struct",name:"starknet_htlc::interface::events::Redeemed",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"secret",type:"core::array::Array::<core::integer::u32>"}]},{kind:"struct",name:"starknet_htlc::interface::events::Refunded",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"}]},{kind:"enum",name:"starknet_htlc::htlc::HTLC::Event",type:"event",variants:[{kind:"nested",name:"Initiated",type:"starknet_htlc::interface::events::Initiated"},{kind:"nested",name:"Redeemed",type:"starknet_htlc::interface::events::Redeemed"},{kind:"nested",name:"Refunded",type:"starknet_htlc::interface::events::Refunded"}]}],Db={name:"HTLC",version:et.shortString.encodeShortString("1"),chainId:"0x534e5f5345504f4c4941",revision:et.TypedDataRevision.ACTIVE},$b={StarknetDomain:[{name:"name",type:"shortstring"},{name:"version",type:"shortstring"},{name:"chainId",type:"shortstring"},{name:"revision",type:"shortstring"}],Initiate:[{name:"redeemer",type:"ContractAddress"},{name:"amount",type:"u256"},{name:"timelock",type:"u128"},{name:"secretHash",type:"u128*"}]},jb="https://starknet-sepolia.public.blastapi.io/rpc/v0_7";class ju{constructor(t,r,n){this.nodeUrl=n||jb,this.url=new Z.Url("/",t),this.account=r}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async initiate(t){if(!this.account.address)return V("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return V("Invalid order");try{const o=new et.Contract($u,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),f=et.num.toHex(a),l=await Du(this.account,f,n.asset,BigInt(s),this.nodeUrl);if(l.error)return V(l.error);const d={domain:Db,primaryType:"Initiate",types:$b,message:{redeemer:i,amount:et.cairo.uint256(s),timelock:r.timelock,secretHash:Z.hexToU32Array(r.secret_hash)}},p=await this.account.signMessage(d),{r:w,s:y}=p,I=await jt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:{r:w.toString(),s:y.toString()},perform_on:"Source"}),headers:{"Content-Type":"application/json"}});return I.error?V(I.error):I.result?ce(I.result):V("Init: No result found")}catch(o){return V(String(o))}}async redeem(t,r){try{const n=await jt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"}});return n.error?V(n.error):n.result?ce(n.result):V("Redeem: No result found")}catch(n){return V(String(n))}}async refund(){return V("Refund is taken care of by the relayer")}}class na extends Z.EventBroker{constructor(t){super(),this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new bh;const r=ar.from(t.digestKey);if(r.error)throw new Error(r.error);this._digestKey=r.val,this.environment=t.environment;const n=t.environment===Z.Environment.MAINNET?Zr.mainnet:t.environment===Z.Environment.TESTNET?Zr.testnet:Zr.localnet;if(!n)throw new Error("API not found, invalid environment "+t.environment);this._orderbookUrl=new Z.Url(t.api??n.orderbook),this._quote=t.quote??new sf(n.quote),this._auth=Z.Siwe.fromDigestKey(new Z.Url(t.api??n.orderbook),this._digestKey.digestKey),this._orderbook=new Ae.Orderbook(new Z.Url(t.api??n.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._secretManager=t.secretManager??Gn.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new mh,this._blockNumberFetcher=t.blockNumberFetcher??new nf(n.info,t.environment)}static from(t){const r=t.environment===Z.Environment.MAINNET?Zr.mainnet:t.environment===Z.Environment.TESTNET?Zr.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);const n={evm:new Fu(r.evmRelay,t.wallets.evm,Z.Siwe.fromDigestKey(new Z.Url(r.orderbook),t.digestKey)),starknet:new ju(r.starknetRelay,t.wallets.starknet)};return new na({environment:t.environment,digestKey:t.digestKey,htlc:n})}get orderbookUrl(){return this._orderbookUrl.toString()}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return ce(this._btcWallet);const t=await this._secretManager.getDigestKey();if(t.error)return V(t.error);const r=new nn.BitcoinProvider(il(this.environment));return this._btcWallet=nn.BitcoinWallet.fromPrivateKey(t.val,r),ce(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return V(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 V(a.error);const{strategyId:f,btcAddress:l}=t.additionalData,d={strategy_id:f,...l&&{bitcoin_optional_recipient:l}},p={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:Tt(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},w=await this._quote.getAttestedQuote(p);if(w.error)return V(w.error);const y=await this._orderbook.createOrder(w.val,this.auth);if(y.error)return V(y.error);const I=await this.pollOrder(y.val);return I.error?V(I.error):ce(I.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return V("StrategyId is required");if(!t.fromAsset||!t.toAsset)return V("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return V("Source and destination assets cannot be the same");if(Ae.isMainnet(t.fromAsset.chain)&&!Ae.isMainnet(t.toAsset.chain)||!Ae.isMainnet(t.fromAsset.chain)&&Ae.isMainnet(t.toAsset.chain))return V("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return V(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return V(n.error);if(r<n)return V("Send amount should be greater than receive amount");const i=Ae.getTimeLock(t.fromAsset.chain);if(!i)return V("Unsupported chain for timelock");if(Ae.isBitcoin(t.fromAsset.chain)||Ae.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return V("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 V(a.error);if(!this._btcWallet)return V("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return V(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?V(o.error):ce({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(Ae.getBlockchainType(t)){case Ae.BlockchainType.EVM:return this._evmHTLC?ce(this._evmHTLC.htlcActorAddress):V("Please provide evmHTLC when initializing garden");case Ae.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!rl(i)?V("Invalid btc public key"):ce(xr(i))}case Ae.BlockchainType.Starknet:return this._starknetHTLC?ce(this._starknetHTLC.htlcActorAddress):V("Please provide starknetHTLC when initializing garden");default:return V("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return V("Invalid amount ",t);const r=new Ku(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?V("Invalid amount ",t):ce(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await Z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return V(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return ce(r.val);r=await this._orderbook.getOrder(t,!0)}return V(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{if(r.data.length===0)return;const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val);for(let i=0;i<n.val.length;i++){const s=n.val[i],o=Bo(s.status);if(Ae.isBitcoin(s.source_swap.chain)&&s.status===ve.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Re.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(Ae.getBlockchainType(s.destination_swap.chain)){case Ae.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case Ae.BlockchainType.Bitcoin:{const f=this.btcWallet;if(!f){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(f,s,a.val.secret);break}case Ae.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Re.Refund:{switch(Ae.getBlockchainType(s.source_swap.chain)){case Ae.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case Ae.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case Ae.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},!0,{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val))}async btcRedeem(t,r,n){var a,f;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const l=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const p of l.vin)if(p.txid===s){d=!0;break}if(d){this.emit("log",r.create_order.create_id,"already a valid redeem");let p=0;try{const[w]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);w!==0&&(p=w)}catch{p=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:p,redeemTxHash:r.destination_swap.redeem_tx_hash});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 $n.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,xr(r.destination_swap.initiator),xr(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(Tt(n),(f=r.create_order.additional_data)==null?void 0:f.bitcoin_optional_recipient),p=await this.broadcastRedeemTx(d,r.create_order.create_id);if(p.error||!p.val){this.emit("error",r,p.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,p.val)):this.emit("success",r,Re.Redeem,p.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:p.val})}catch(l){console.log("error",l),this.emit("error",r,"Failed btc redeem: "+l)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Re.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await $n.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,xr(r.source_swap.initiator),xr(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,Re.Refund,s),this.emit("success",r,Re.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await $n.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,xr(t.source_swap.initiator),xr(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 jt.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 filterExpiredAndAssignStatus(t){var i;if(t.length===0)return ce([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return V(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(Tc(o))continue;const a=o.source_swap.chain,f=o.destination_swap.chain,l=r==null?void 0:r.val[a],d=r==null?void 0:r.val[f];if(!l||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const p=Ao(o,l,d);n.push({...o,status:p})}return ce(n)}async broadcastRedeemTx(t,r){try{const n=this._orderbookUrl.endpoint("gasless/order/bitcoin/redeem"),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?ce(o.result):V(o.error)}catch(n){return V("Failed to broadcast redeem tx: "+n)}}}const zb="https://starknet-sepolia.public.blastapi.io/rpc/v0_7";class qb{constructor(t,r){this.callData=new et.CallData(Mu),this.nodeUrl=r||zb,this.account=t}get htlcActorAddress(){return this.account.address}async getHTLCContract(t,r=!1){const n=r?t.destination_swap.asset:t.source_swap.asset;return new et.Contract($u,n,this.account)}async initiate(t){try{const n=await(await this.getHTLCContract(t)).token();if(!n)throw new Error("Token address retrieval failed");const i=et.num.toHex(n),s=et.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await Du(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.nodeUrl);if(a.error)return V(a.error)}catch(a){return V(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...Z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return ce(o.transaction_hash)}catch(r){return V(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:et.CallData.compile({swap_id:i,secret:Z.hexToU32Array(r)})});return s.transaction_hash?ce(s.transaction_hash):V("Failed to redeem HTLC transaction")}catch{return V("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?ce(i.transaction_hash):V("Failed to refund HTLC transaction")}catch{return V("HTLC Refund Error")}}}function Pt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}function ia(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 zu={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function sa(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?$i(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?$i(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?zu[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=Gb(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 Vb=ia("transaction",sa);function Gb(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 Wb(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:sa(r));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const Kb=ia("block",Wb);function Yb(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 Xb={"0x0":"reverted","0x1":"success"};function Zb(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=>Yb(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?$i(e.transactionIndex):null,status:e.status?Xb[e.status]:null,type:e.type?zu[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const Jb=ia("transactionReceipt",Zb),Qb={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},e1={block:Kb({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=sa(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?cr(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Vb({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?cr(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Jb({format(e){return{l1GasPrice:e.l1GasPrice?cr(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?cr(e.l1GasUsed):null,l1Fee:e.l1Fee?cr(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function t1(e,t){return i1(e)?n1(e):Ou(e,t)}const r1={transaction:t1};function n1(e){s1(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:f}=e,l=[t,n,a??"0x",o?ee(o):"0x",f?ee(f):"0x",i?ee(i):"0x",s?"0x1":"0x",r??"0x"];return Mr(["0x7e",mr(l)])}function i1(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function s1(e){const{from:t,to:r}=e;if(t&&!bt(t))throw new mt({address:t});if(r&&!bt(r))throw new mt({address:r})}const zi={contracts:Qb,formatters:e1,serializers:r1},o1=Pt({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}}}),a1=Pt({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}),Un=1,c1=Pt({...zi,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:{...zi.contracts,disputeGameFactory:{[Un]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Un]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Un]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Un]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Un}),Ln=11155111,f1=Pt({...zi,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:{...zi.contracts,disputeGameFactory:{[Ln]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Ln]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Ln]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Ln]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Ln}),u1=Pt({id:80094,name:"Berachain",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:0}},rpcUrls:{default:{http:["https://rpc.berachain.com"]}},blockExplorers:{default:{name:"Berascan",url:"https://berascan.com"}},testnet:!1}),l1=Pt({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269},ensRegistry:{address:"0xB0eef18971290b333450586D33dcA6cE122651D2",blockCreated:7736794},ensUniversalResolver:{address:"0x41692Ef1EA0C79E6b73077E4A67572D2BDbD7057",blockCreated:7736795}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),d1=Pt({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"cBTC",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api"}},testnet:!0}),h1=Pt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),p1=Pt({id:10143,name:"Monad Testnet",nativeCurrency:{name:"Testnet MON Token",symbol:"MON",decimals:18},rpcUrls:{default:{http:["https://testnet-rpc.monad.xyz"]}},blockExplorers:{default:{name:"Monad Testnet explorer",url:"https://testnet.monadexplorer.com"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:251449}},testnet:!0}),y1=Pt({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}),m1={...y1,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},qu={ethereum:h1,arbitrum:o1,ethereum_sepolia:m1,arbitrum_sepolia:a1,ethereum_localnet:Ae.EthereumLocalnet,arbitrum_localnet:Ae.ArbitrumLocalnet,base_sepolia:f1,base:c1,bera_testnet:l1,citrea_testnet:d1,bera:u1,monad_testnet:p1},b1=async(e,t)=>{var n;const r=qu[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return ce({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=$t.createWalletClient({account:t.account,chain:r,transport:$t.custom(window.ethereum)});return ce({message:"Switched chain",walletClient:i})}catch(i){if(g1(i))try{await t.addChain({chain:r});const s=$t.createWalletClient({account:t.account,chain:r,transport:$t.custom(window.ethereum)});return ce({message:"Added network",walletClient:s})}catch{return V("Failed to add network")}else return V("Failed to switch network")}else return V("Chain not supported")},g1=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.API=Zr;exports.BlockNumberFetcher=nf;exports.EvmRelay=Fu;exports.Garden=na;exports.OrderActions=Re;exports.OrderStatus=ve;exports.ParseOrderStatus=Ao;exports.ParseSwapStatus=so;exports.Quote=sf;exports.SecretManager=Gn;exports.StarknetHTLC=qb;exports.StarknetRelay=ju;exports.SwapStatus=xe;exports.constructOrderPair=Ic;exports.evmToViemChainMap=qu;exports.filterDeadlineExpiredOrders=ol;exports.isExpired=jn;exports.parseAction=sl;exports.parseActionFromStatus=Bo;exports.switchOrAddNetwork=b1;exports.validateBTCAddress=nl;
|