@gardenfi/core 2.0.3 → 2.0.5
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 +15 -15
- package/dist/index.js +1859 -1678
- package/dist/src/lib/quote/quote.d.ts +2 -2
- package/dist/src/lib/quote/quote.types.d.ts +2 -2
- package/dist/src/lib/utils.d.ts +2 -2
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";var qf=Object.defineProperty;var Kf=(e,t,r)=>t in e?qf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var lr=(e,t,r)=>Kf(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("@catalogfi/utils"),ce=require("@gardenfi/orderbook"),ge=require("@gardenfi/utils"),Br=require("@catalogfi/wallets"),lt=require("viem"),Qo=require("varuint-bitcoin"),Yf=require("tiny-secp256k1"),Zo=require("bitcoinjs-lib"),Xf=require("bignumber.js");function hs(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 js=hs(Qo),Jt=hs(Yf),be=hs(Zo);var Pe=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Pe||{});function Xi(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function dr(e,t){if(!e)throw new Error(t)}function Jf(e){return Buffer.concat([Uint8Array.from([192]),Qf(e)])}function Qf(e){const t=js.encodingLength(e.length),r=Buffer.allocUnsafe(t);return js.encode(e.length,r),Buffer.concat([r,e])}function Zf(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const qt=e=>e.length===64?e:e.slice(2),eu=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return Jt.isPoint(t)}catch{return!1}},ea=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function tu(e,t){if(!e)return!1;const r=t==="mainnet"?be.networks.bitcoin:be.networks.testnet;be.initEccLib(Jt);try{return be.address.toOutputScript(e,r),!0}catch{return!1}}const ru=e=>{switch(e){case ge.Environment.MAINNET:return Br.BitcoinNetwork.Mainnet;case ge.Environment.TESTNET:return Br.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}};var he=(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))(he||{}),we=(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))(we||{});const ls=(e,t,r)=>{const n=Ji(e.source_swap,t),i=Ji(e.destination_swap,r);if(i===we.RedeemDetected)return he.RedeemDetected;if(i===we.Redeemed)return he.Redeemed;if(n===we.Refunded)return he.Refunded;if(n===we.RefundDetected)return he.RefundDetected;if(i===we.Expired)return he.CounterPartySwapExpired;if(n===we.Expired)return he.Expired;if(i===we.Refunded)return he.CounterPartyRefunded;if(i===we.RefundDetected)return he.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===we.Initiated?he.CounterPartyInitiated:i===we.InitiateDetected?he.CounterPartyInitiateDetected:an(s,12)?he.DeadLineExceeded:n===we.Initiated?he.Initiated:an(s,1)?he.DeadLineExceeded:n===we.InitiateDetected?he.InitiateDetected:n===we.Redeemed?he.CounterPartyRedeemed:n===we.RedeemDetected?he.CounterPartyRedeemDetected:he.Matched},Ji=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?we.Redeemed:we.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?we.Refunded:we.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return we.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?we.Initiated:we.InitiateDetected:we.Idle},nu=(e,t,r)=>{const n=ls(e,t,r);return ds(n)},ds=e=>{switch(e){case he.Matched:return Pe.Initiate;case he.CounterPartyInitiated:case he.CounterPartyInitiateDetected:case he.RedeemDetected:return Pe.Redeem;case he.Expired:return Pe.Refund;default:return Pe.Idle}},an=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},iu=e=>e.filter(t=>!ta(t)),ta=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)?an(Number(s),12):n?!1:an(Number(s),1)},su=[{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 ra{constructor(t,r){this.url=new ge.Url("/relayer",t),this.auth=r}async init(t,r){if(!t.account)return N.Err("No account found");if(t.account.address.toLowerCase()!==r.source_swap.initiator.toLowerCase())return N.Err("Account address and order initiator mismatch");const{create_order:n,source_swap:i}=r;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return N.Err("Invalid order");const s=ge.with0x(n.secret_hash),o=BigInt(n.timelock),a=ge.with0x(i.redeemer),c=BigInt(i.amount);try{const l=await this.auth.getToken();if(l.error)return N.Err(l.error);const d=lt.getContract({address:ge.with0x(r.source_swap.asset),abi:su,client:t}),g=await d.read.token(),x=await ge.checkAllowanceAndApprove(Number(c),g,r.source_swap.asset,t);if(x.error)return N.Err(x.error);const y=await d.read.eip712Domain(),O=await t.signTypedData({account:t.account,domain:{name:y[1],version:y[2],chainId:Number(y[3]),verifyingContract:y[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:a,timelock:o,amount:c,secretHash:s}}),B=await N.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:n.create_id,signature:O,perform_on:"Source"}),headers:{Authorization:ge.Authorization(l.val),"Content-Type":"application/json"}});return B.error?N.Err(B.error):B.result?N.Ok(B.result):N.Err("Init: No result found")}catch(l){return console.log("init error :",l),N.Err(String(l))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return N.Err(n.error);const i=await N.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:N.trim0x(r),perform_on:"Destination"}),headers:{Authorization:ge.Authorization(n.val),"Content-Type":"application/json"}});return i.error?N.Err(i.error):i.result?N.Ok(i.result):N.Err("Redeem: No result found")}catch(n){return N.Err(String(n))}}}const ou=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),au=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),fu=Buffer.concat([ou,au]),uu=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Gs={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function cu(){const e=Zo.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=Jt.pointMultiply(Buffer.concat([Buffer.from("04","hex"),fu]),e);if(!t)throw new Error(Gs.failedToCreateInternalPubkey);const r=Jt.pointAdd(uu,t);if(!r)throw new Error(Gs.failedToCreateInternalPubkey);return Xi(Buffer.from(r))}var Ht=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function hu(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function na(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 me={},Ne={},Pt={},Jn={};Jn.byteLength=pu;Jn.toByteArray=bu;Jn.fromByteArray=mu;var ht=[],Je=[],lu=typeof Uint8Array<"u"?Uint8Array:Array,vi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var pr=0,du=vi.length;pr<du;++pr)ht[pr]=vi[pr],Je[vi.charCodeAt(pr)]=pr;Je[45]=62;Je[95]=63;function ia(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 pu(e){var t=ia(e),r=t[0],n=t[1];return(r+n)*3/4-n}function yu(e,t,r){return(t+r)*3/4-r}function bu(e){var t,r=ia(e),n=r[0],i=r[1],s=new lu(yu(e,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=Je[e.charCodeAt(c)]<<18|Je[e.charCodeAt(c+1)]<<12|Je[e.charCodeAt(c+2)]<<6|Je[e.charCodeAt(c+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=Je[e.charCodeAt(c)]<<2|Je[e.charCodeAt(c+1)]>>4,s[o++]=t&255),i===1&&(t=Je[e.charCodeAt(c)]<<10|Je[e.charCodeAt(c+1)]<<4|Je[e.charCodeAt(c+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function wu(e){return ht[e>>18&63]+ht[e>>12&63]+ht[e>>6&63]+ht[e&63]}function gu(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(wu(n));return i.join("")}function mu(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(gu(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(ht[t>>2]+ht[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(ht[t>>10]+ht[t>>4&63]+ht[t<<2&63]+"=")),i.join("")}var ps={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ps.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,c=(1<<a)-1,l=c>>1,d=-7,g=r?i-1:0,x=r?-1:1,y=e[t+g];for(g+=x,s=y&(1<<-d)-1,y>>=-d,d+=a;d>0;s=s*256+e[t+g],g+=x,d-=8);for(o=s&(1<<-d)-1,s>>=-d,d+=n;d>0;o=o*256+e[t+g],g+=x,d-=8);if(s===0)s=1-l;else{if(s===c)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)};ps.write=function(e,t,r,n,i,s){var o,a,c,l=s*8-i-1,d=(1<<l)-1,g=d>>1,x=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:s-1,O=n?1:-1,B=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*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+g>=1?t+=x/c:t+=x*Math.pow(2,1-g),t*c>=2&&(o++,c/=2),o+g>=d?(a=0,o=d):o+g>=1?(a=(t*c-1)*Math.pow(2,i),o=o+g):(a=t*Math.pow(2,g-1)*Math.pow(2,i),o=0));i>=8;e[r+y]=a&255,y+=O,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+y]=o&255,y+=O,o/=256,l-=8);e[r+y-O]|=B*128};/*!
|
|
1
|
+
"use strict";var ou=Object.defineProperty;var au=(e,t,r)=>t in e?ou(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var yr=(e,t,r)=>au(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=require("@gardenfi/orderbook"),ae=require("@gardenfi/utils"),Ar=require("@catalogfi/wallets"),dt=require("viem"),ca=require("varuint-bitcoin"),fu=require("tiny-secp256k1"),ha=require("bitcoinjs-lib"),uu=require("bignumber.js");function Es(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 Zs=Es(ca),er=Es(fu),de=Es(ha);var la=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},Ii=(e,t,r)=>(la(e,t,"read from private field"),r?r.call(e):t.get(e)),Oi=(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)},ki=(e,t,r,n)=>(la(e,t,"write to private field"),t.set(e,r),r);const cu=e=>new Promise(t=>setTimeout(t,e));class hu{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 cu(this.delay*r)}throw n}}const lu=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=eo(s);continue}throw new Error(n||"All APIs failed")}static async postWithFallback(t,r){return await Pn(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=eo(s);continue}throw new Error(n||"All APIs failed")}static async getWithFallback(t,r){return await Pn(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 Pn(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 Pn(r).retry(()=>this._post(t,r))}static async parse(t){const r=await t.text();if(t.status>=200&&t.status<300)return lu(r);throw new Error(r)}}function eo(e){return(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"unknown error"}const Pn=e=>new hu((e==null?void 0:e.retryCount)??2,(e==null?void 0:e.retryDelay)??1e3),Xt=e=>e.startsWith("0x")?e.slice(2):e;var Nn,Fn,Mn;let os=class{constructor(t,r,n=void 0){Oi(this,Nn,void 0),Oi(this,Fn,void 0),Oi(this,Mn,void 0),ki(this,Nn,t),ki(this,Mn,n),ki(this,Fn,r)}get ok(){return Ii(this,Nn)}get error(){return Ii(this,Mn)}get val(){return Ii(this,Fn)}};Nn=new WeakMap,Fn=new WeakMap,Mn=new WeakMap;const re=e=>new os(!0,e),j=(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 os(!1,null,r.filter(n=>n!==void 0).join(" "))}return new os(!1,null,e)};var Te=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Te||{});function as(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function br(e,t){if(!e)throw new Error(t)}function du(e){return Buffer.concat([Uint8Array.from([192]),pu(e)])}function pu(e){const t=Zs.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Zs.encode(e.length,r),Buffer.concat([r,e])}function yu(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Kt=e=>e.length===64?e:e.slice(2),bu=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return er.isPoint(t)}catch{return!1}},da=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function wu(e,t){if(!e)return!1;const r=t===ae.Environment.MAINNET?de.networks.bitcoin:t===ae.Environment.TESTNET?de.networks.testnet:de.networks.regtest;if(!r)return!1;de.initEccLib(er);try{return de.address.toOutputScript(e,r),!0}catch{return!1}}const gu=e=>{switch(e){case ae.Environment.MAINNET:return Ar.BitcoinNetwork.Mainnet;case ae.Environment.TESTNET:return Ar.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}};var pe=(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))(pe||{}),me=(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))(me||{});const xs=(e,t,r)=>{const n=fs(e.source_swap,t),i=fs(e.destination_swap,r);if(i===me.RedeemDetected)return pe.RedeemDetected;if(i===me.Redeemed)return pe.Redeemed;if(n===me.Refunded)return pe.Refunded;if(n===me.RefundDetected)return pe.RefundDetected;if(i===me.Expired)return pe.CounterPartySwapExpired;if(n===me.Expired)return pe.Expired;if(i===me.Refunded)return pe.CounterPartyRefunded;if(i===me.RefundDetected)return pe.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===me.Initiated?pe.CounterPartyInitiated:i===me.InitiateDetected?pe.CounterPartyInitiateDetected:cn(s,12)?pe.DeadLineExceeded:n===me.Initiated?pe.Initiated:cn(s,1)?pe.DeadLineExceeded:n===me.InitiateDetected?pe.InitiateDetected:n===me.Redeemed?pe.CounterPartyRedeemed:n===me.RedeemDetected?pe.CounterPartyRedeemDetected:pe.Matched},fs=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?me.Redeemed:me.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?me.Refunded:me.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return me.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?me.Initiated:me.InitiateDetected:me.Idle},mu=(e,t,r)=>{const n=xs(e,t,r);return Ss(n)},Ss=e=>{switch(e){case pe.Matched:return Te.Initiate;case pe.CounterPartyInitiated:case pe.CounterPartyInitiateDetected:case pe.RedeemDetected:return Te.Redeem;case pe.Expired:return Te.Refund;default:return Te.Idle}},cn=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},_u=e=>e.filter(t=>!pa(t)),pa=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)?cn(Number(s),12):n?!1:cn(Number(s),1)},vu=[{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 ya{constructor(t,r){this.url=new ae.Url("/relayer",t),this.auth=r}async init(t,r){if(!t.account)return j("No account found");if(t.account.address.toLowerCase()!==r.source_swap.initiator.toLowerCase())return j("Account address and order initiator mismatch");const{create_order:n,source_swap:i}=r;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return j("Invalid order");const s=ae.with0x(n.secret_hash),o=BigInt(n.timelock),a=ae.with0x(i.redeemer),c=BigInt(i.amount);try{const l=await this.auth.getToken();if(l.error)return j(l.error);const d=dt.getContract({address:ae.with0x(r.source_swap.asset),abi:vu,client:t}),g=await d.read.token(),x=await ae.checkAllowanceAndApprove(Number(c),g,r.source_swap.asset,t);if(x.error)return j(x.error);const y=await d.read.eip712Domain(),O=await t.signTypedData({account:t.account,domain:{name:y[1],version:y[2],chainId:Number(y[3]),verifyingContract:y[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:a,timelock:o,amount:c,secretHash:s}}),B=await Jt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:n.create_id,signature:O,perform_on:"Source"}),headers:{Authorization:ae.Authorization(l.val),"Content-Type":"application/json"}});return B.error?j(B.error):B.result?re(B.result):j("Init: No result found")}catch(l){return console.log("init error :",l),j(String(l))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return j(n.error);const i=await Jt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:Xt(r),perform_on:"Destination"}),headers:{Authorization:ae.Authorization(n.val),"Content-Type":"application/json"}});return i.error?j(i.error):i.result?re(i.result):j("Redeem: No result found")}catch(n){return j(String(n))}}}const Eu=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),xu=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),Su=Buffer.concat([Eu,xu]),Bu=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),to={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function Pu(){const e=ha.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=er.pointMultiply(Buffer.concat([Buffer.from("04","hex"),Su]),e);if(!t)throw new Error(to.failedToCreateInternalPubkey);const r=er.pointAdd(Bu,t);if(!r)throw new Error(to.failedToCreateInternalPubkey);return as(Buffer.from(r))}var $t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Tu(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ba(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 _e={},Fe={},Tt={},ii={};ii.byteLength=Ou;ii.toByteArray=Ru;ii.fromByteArray=Lu;var lt=[],Qe=[],Au=typeof Uint8Array<"u"?Uint8Array:Array,Ri="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var wr=0,Iu=Ri.length;wr<Iu;++wr)lt[wr]=Ri[wr],Qe[Ri.charCodeAt(wr)]=wr;Qe[45]=62;Qe[95]=63;function wa(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 Ou(e){var t=wa(e),r=t[0],n=t[1];return(r+n)*3/4-n}function ku(e,t,r){return(t+r)*3/4-r}function Ru(e){var t,r=wa(e),n=r[0],i=r[1],s=new Au(ku(e,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=Qe[e.charCodeAt(c)]<<18|Qe[e.charCodeAt(c+1)]<<12|Qe[e.charCodeAt(c+2)]<<6|Qe[e.charCodeAt(c+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=Qe[e.charCodeAt(c)]<<2|Qe[e.charCodeAt(c+1)]>>4,s[o++]=t&255),i===1&&(t=Qe[e.charCodeAt(c)]<<10|Qe[e.charCodeAt(c+1)]<<4|Qe[e.charCodeAt(c+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function Uu(e){return lt[e>>18&63]+lt[e>>12&63]+lt[e>>6&63]+lt[e&63]}function Cu(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(Uu(n));return i.join("")}function Lu(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(Cu(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(lt[t>>2]+lt[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(lt[t>>10]+lt[t>>4&63]+lt[t<<2&63]+"=")),i.join("")}var Bs={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Bs.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,c=(1<<a)-1,l=c>>1,d=-7,g=r?i-1:0,x=r?-1:1,y=e[t+g];for(g+=x,s=y&(1<<-d)-1,y>>=-d,d+=a;d>0;s=s*256+e[t+g],g+=x,d-=8);for(o=s&(1<<-d)-1,s>>=-d,d+=n;d>0;o=o*256+e[t+g],g+=x,d-=8);if(s===0)s=1-l;else{if(s===c)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)};Bs.write=function(e,t,r,n,i,s){var o,a,c,l=s*8-i-1,d=(1<<l)-1,g=d>>1,x=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:s-1,O=n?1:-1,B=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*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+g>=1?t+=x/c:t+=x*Math.pow(2,1-g),t*c>=2&&(o++,c/=2),o+g>=d?(a=0,o=d):o+g>=1?(a=(t*c-1)*Math.pow(2,i),o=o+g):(a=t*Math.pow(2,g-1)*Math.pow(2,i),o=0));i>=8;e[r+y]=a&255,y+=O,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+y]=o&255,y+=O,o/=256,l-=8);e[r+y-O]|=B*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=Jn,r=ps,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=U,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),f={foo:function(){return 42}};return Object.setPrototypeOf(f,Uint8Array.prototype),Object.setPrototypeOf(h,f),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 f=new Uint8Array(h);return Object.setPrototypeOf(f,a.prototype),f}function a(h,f,u){if(typeof h=="number"){if(typeof f=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return g(h)}return c(h,f,u)}a.poolSize=8192;function c(h,f,u){if(typeof h=="string")return x(h,f);if(ArrayBuffer.isView(h))return O(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(ze(h,ArrayBuffer)||h&&ze(h.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(ze(h,SharedArrayBuffer)||h&&ze(h.buffer,SharedArrayBuffer)))return B(h,f,u);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const p=h.valueOf&&h.valueOf();if(p!=null&&p!==h)return a.from(p,f,u);const E=A(h);if(E)return E;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return a.from(h[Symbol.toPrimitive]("string"),f,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,f,u){return c(h,f,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,f,u){return l(h),h<=0?o(h):f!==void 0?typeof u=="string"?o(h).fill(f,u):o(h).fill(f):o(h)}a.alloc=function(h,f,u){return d(h,f,u)};function g(h){return l(h),o(h<0?0:k(h)|0)}a.allocUnsafe=function(h){return g(h)},a.allocUnsafeSlow=function(h){return g(h)};function x(h,f){if((typeof f!="string"||f==="")&&(f="utf8"),!a.isEncoding(f))throw new TypeError("Unknown encoding: "+f);const u=_(h,f)|0;let p=o(u);const E=p.write(h,f);return E!==u&&(p=p.slice(0,E)),p}function y(h){const f=h.length<0?0:k(h.length)|0,u=o(f);for(let p=0;p<f;p+=1)u[p]=h[p]&255;return u}function O(h){if(ze(h,Uint8Array)){const f=new Uint8Array(h);return B(f.buffer,f.byteOffset,f.byteLength)}return y(h)}function B(h,f,u){if(f<0||h.byteLength<f)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<f+(u||0))throw new RangeError('"length" is outside of buffer bounds');let p;return f===void 0&&u===void 0?p=new Uint8Array(h):u===void 0?p=new Uint8Array(h,f):p=new Uint8Array(h,f,u),Object.setPrototypeOf(p,a.prototype),p}function A(h){if(a.isBuffer(h)){const f=k(h.length)|0,u=o(f);return u.length===0||h.copy(u,0,0,f),u}if(h.length!==void 0)return typeof h.length!="number"||Wt(h.length)?o(0):y(h);if(h.type==="Buffer"&&Array.isArray(h.data))return y(h.data)}function k(h){if(h>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return h|0}function U(h){return+h!=h&&(h=0),a.alloc(+h)}a.isBuffer=function(f){return f!=null&&f._isBuffer===!0&&f!==a.prototype},a.compare=function(f,u){if(ze(f,Uint8Array)&&(f=a.from(f,f.offset,f.byteLength)),ze(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(f)||!a.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(f===u)return 0;let p=f.length,E=u.length;for(let I=0,L=Math.min(p,E);I<L;++I)if(f[I]!==u[I]){p=f[I],E=u[I];break}return p<E?-1:E<p?1:0},a.isEncoding=function(f){switch(String(f).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(f,u){if(!Array.isArray(f))throw new TypeError('"list" argument must be an Array of Buffers');if(f.length===0)return a.alloc(0);let p;if(u===void 0)for(u=0,p=0;p<f.length;++p)u+=f[p].length;const E=a.allocUnsafe(u);let I=0;for(p=0;p<f.length;++p){let L=f[p];if(ze(L,Uint8Array))I+L.length>E.length?(a.isBuffer(L)||(L=a.from(L)),L.copy(E,I)):Uint8Array.prototype.set.call(E,L,I);else if(a.isBuffer(L))L.copy(E,I);else throw new TypeError('"list" argument must be an Array of Buffers');I+=L.length}return E};function _(h,f){if(a.isBuffer(h))return h.length;if(ArrayBuffer.isView(h)||ze(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,p=arguments.length>2&&arguments[2]===!0;if(!p&&u===0)return 0;let E=!1;for(;;)switch(f){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return te(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return Nr(h).length;default:if(E)return p?-1:te(h).length;f=(""+f).toLowerCase(),E=!0}}a.byteLength=_;function m(h,f,u){let p=!1;if((f===void 0||f<0)&&(f=0),f>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,f>>>=0,u<=f))return"";for(h||(h="utf8");;)switch(h){case"hex":return Ve(this,f,u);case"utf8":case"utf-8":return V(this,f,u);case"ascii":return ae(this,f,u);case"latin1":case"binary":return Ze(this,f,u);case"base64":return H(this,f,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return nt(this,f,u);default:if(p)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),p=!0}}a.prototype._isBuffer=!0;function S(h,f,u){const p=h[f];h[f]=h[u],h[u]=p}a.prototype.swap16=function(){const f=this.length;if(f%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<f;u+=2)S(this,u,u+1);return this},a.prototype.swap32=function(){const f=this.length;if(f%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<f;u+=4)S(this,u,u+3),S(this,u+1,u+2);return this},a.prototype.swap64=function(){const f=this.length;if(f%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<f;u+=8)S(this,u,u+7),S(this,u+1,u+6),S(this,u+2,u+5),S(this,u+3,u+4);return this},a.prototype.toString=function(){const f=this.length;return f===0?"":arguments.length===0?V(this,0,f):m.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(f){if(!a.isBuffer(f))throw new TypeError("Argument must be a Buffer");return this===f?!0:a.compare(this,f)===0},a.prototype.inspect=function(){let f="";const u=e.INSPECT_MAX_BYTES;return f=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(f+=" ... "),"<Buffer "+f+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(f,u,p,E,I){if(ze(f,Uint8Array)&&(f=a.from(f,f.offset,f.byteLength)),!a.isBuffer(f))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof f);if(u===void 0&&(u=0),p===void 0&&(p=f?f.length:0),E===void 0&&(E=0),I===void 0&&(I=this.length),u<0||p>f.length||E<0||I>this.length)throw new RangeError("out of range index");if(E>=I&&u>=p)return 0;if(E>=I)return-1;if(u>=p)return 1;if(u>>>=0,p>>>=0,E>>>=0,I>>>=0,this===f)return 0;let L=I-E,Q=p-u;const _e=Math.min(L,Q),ye=this.slice(E,I),Ee=f.slice(u,p);for(let ne=0;ne<_e;++ne)if(ye[ne]!==Ee[ne]){L=ye[ne],Q=Ee[ne];break}return L<Q?-1:Q<L?1:0};function v(h,f,u,p,E){if(h.length===0)return-1;if(typeof u=="string"?(p=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,Wt(u)&&(u=E?0:h.length-1),u<0&&(u=h.length+u),u>=h.length){if(E)return-1;u=h.length-1}else if(u<0)if(E)u=0;else return-1;if(typeof f=="string"&&(f=a.from(f,p)),a.isBuffer(f))return f.length===0?-1:$(h,f,u,p,E);if(typeof f=="number")return f=f&255,typeof Uint8Array.prototype.indexOf=="function"?E?Uint8Array.prototype.indexOf.call(h,f,u):Uint8Array.prototype.lastIndexOf.call(h,f,u):$(h,[f],u,p,E);throw new TypeError("val must be string, number or Buffer")}function $(h,f,u,p,E){let I=1,L=h.length,Q=f.length;if(p!==void 0&&(p=String(p).toLowerCase(),p==="ucs2"||p==="ucs-2"||p==="utf16le"||p==="utf-16le")){if(h.length<2||f.length<2)return-1;I=2,L/=2,Q/=2,u/=2}function _e(Ee,ne){return I===1?Ee[ne]:Ee.readUInt16BE(ne*I)}let ye;if(E){let Ee=-1;for(ye=u;ye<L;ye++)if(_e(h,ye)===_e(f,Ee===-1?0:ye-Ee)){if(Ee===-1&&(Ee=ye),ye-Ee+1===Q)return Ee*I}else Ee!==-1&&(ye-=ye-Ee),Ee=-1}else for(u+Q>L&&(u=L-Q),ye=u;ye>=0;ye--){let Ee=!0;for(let ne=0;ne<Q;ne++)if(_e(h,ye+ne)!==_e(f,ne)){Ee=!1;break}if(Ee)return ye}return-1}a.prototype.includes=function(f,u,p){return this.indexOf(f,u,p)!==-1},a.prototype.indexOf=function(f,u,p){return v(this,f,u,p,!0)},a.prototype.lastIndexOf=function(f,u,p){return v(this,f,u,p,!1)};function j(h,f,u,p){u=Number(u)||0;const E=h.length-u;p?(p=Number(p),p>E&&(p=E)):p=E;const I=f.length;p>I/2&&(p=I/2);let L;for(L=0;L<p;++L){const Q=parseInt(f.substr(L*2,2),16);if(Wt(Q))return L;h[u+L]=Q}return L}function R(h,f,u,p){return hr(te(f,h.length-u),h,u,p)}function z(h,f,u,p){return hr(At(f),h,u,p)}function Z(h,f,u,p){return hr(Nr(f),h,u,p)}function C(h,f,u,p){return hr(cr(f,h.length-u),h,u,p)}a.prototype.write=function(f,u,p,E){if(u===void 0)E="utf8",p=this.length,u=0;else if(p===void 0&&typeof u=="string")E=u,p=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(p)?(p=p>>>0,E===void 0&&(E="utf8")):(E=p,p=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const I=this.length-u;if((p===void 0||p>I)&&(p=I),f.length>0&&(p<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");E||(E="utf8");let L=!1;for(;;)switch(E){case"hex":return j(this,f,u,p);case"utf8":case"utf-8":return R(this,f,u,p);case"ascii":case"latin1":case"binary":return z(this,f,u,p);case"base64":return Z(this,f,u,p);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,f,u,p);default:if(L)throw new TypeError("Unknown encoding: "+E);E=(""+E).toLowerCase(),L=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function H(h,f,u){return f===0&&u===h.length?t.fromByteArray(h):t.fromByteArray(h.slice(f,u))}function V(h,f,u){u=Math.min(h.length,u);const p=[];let E=f;for(;E<u;){const I=h[E];let L=null,Q=I>239?4:I>223?3:I>191?2:1;if(E+Q<=u){let _e,ye,Ee,ne;switch(Q){case 1:I<128&&(L=I);break;case 2:_e=h[E+1],(_e&192)===128&&(ne=(I&31)<<6|_e&63,ne>127&&(L=ne));break;case 3:_e=h[E+1],ye=h[E+2],(_e&192)===128&&(ye&192)===128&&(ne=(I&15)<<12|(_e&63)<<6|ye&63,ne>2047&&(ne<55296||ne>57343)&&(L=ne));break;case 4:_e=h[E+1],ye=h[E+2],Ee=h[E+3],(_e&192)===128&&(ye&192)===128&&(Ee&192)===128&&(ne=(I&15)<<18|(_e&63)<<12|(ye&63)<<6|Ee&63,ne>65535&&ne<1114112&&(L=ne))}}L===null?(L=65533,Q=1):L>65535&&(L-=65536,p.push(L>>>10&1023|55296),L=56320|L&1023),p.push(L),E+=Q}return oe(p)}const q=4096;function oe(h){const f=h.length;if(f<=q)return String.fromCharCode.apply(String,h);let u="",p=0;for(;p<f;)u+=String.fromCharCode.apply(String,h.slice(p,p+=q));return u}function ae(h,f,u){let p="";u=Math.min(h.length,u);for(let E=f;E<u;++E)p+=String.fromCharCode(h[E]&127);return p}function Ze(h,f,u){let p="";u=Math.min(h.length,u);for(let E=f;E<u;++E)p+=String.fromCharCode(h[E]);return p}function Ve(h,f,u){const p=h.length;(!f||f<0)&&(f=0),(!u||u<0||u>p)&&(u=p);let E="";for(let I=f;I<u;++I)E+=Fr[h[I]];return E}function nt(h,f,u){const p=h.slice(f,u);let E="";for(let I=0;I<p.length-1;I+=2)E+=String.fromCharCode(p[I]+p[I+1]*256);return E}a.prototype.slice=function(f,u){const p=this.length;f=~~f,u=u===void 0?p:~~u,f<0?(f+=p,f<0&&(f=0)):f>p&&(f=p),u<0?(u+=p,u<0&&(u=0)):u>p&&(u=p),u<f&&(u=f);const E=this.subarray(f,u);return Object.setPrototypeOf(E,a.prototype),E};function de(h,f,u){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+f>u)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(f,u,p){f=f>>>0,u=u>>>0,p||de(f,u,this.length);let E=this[f],I=1,L=0;for(;++L<u&&(I*=256);)E+=this[f+L]*I;return E},a.prototype.readUintBE=a.prototype.readUIntBE=function(f,u,p){f=f>>>0,u=u>>>0,p||de(f,u,this.length);let E=this[f+--u],I=1;for(;u>0&&(I*=256);)E+=this[f+--u]*I;return E},a.prototype.readUint8=a.prototype.readUInt8=function(f,u){return f=f>>>0,u||de(f,1,this.length),this[f]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(f,u){return f=f>>>0,u||de(f,2,this.length),this[f]|this[f+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(f,u){return f=f>>>0,u||de(f,2,this.length),this[f]<<8|this[f+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(f,u){return f=f>>>0,u||de(f,4,this.length),(this[f]|this[f+1]<<8|this[f+2]<<16)+this[f+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(f,u){return f=f>>>0,u||de(f,4,this.length),this[f]*16777216+(this[f+1]<<16|this[f+2]<<8|this[f+3])},a.prototype.readBigUInt64LE=Ye(function(f){f=f>>>0,F(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&D(f,this.length-8);const E=u+this[++f]*2**8+this[++f]*2**16+this[++f]*2**24,I=this[++f]+this[++f]*2**8+this[++f]*2**16+p*2**24;return BigInt(E)+(BigInt(I)<<BigInt(32))}),a.prototype.readBigUInt64BE=Ye(function(f){f=f>>>0,F(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&D(f,this.length-8);const E=u*2**24+this[++f]*2**16+this[++f]*2**8+this[++f],I=this[++f]*2**24+this[++f]*2**16+this[++f]*2**8+p;return(BigInt(E)<<BigInt(32))+BigInt(I)}),a.prototype.readIntLE=function(f,u,p){f=f>>>0,u=u>>>0,p||de(f,u,this.length);let E=this[f],I=1,L=0;for(;++L<u&&(I*=256);)E+=this[f+L]*I;return I*=128,E>=I&&(E-=Math.pow(2,8*u)),E},a.prototype.readIntBE=function(f,u,p){f=f>>>0,u=u>>>0,p||de(f,u,this.length);let E=u,I=1,L=this[f+--E];for(;E>0&&(I*=256);)L+=this[f+--E]*I;return I*=128,L>=I&&(L-=Math.pow(2,8*u)),L},a.prototype.readInt8=function(f,u){return f=f>>>0,u||de(f,1,this.length),this[f]&128?(255-this[f]+1)*-1:this[f]},a.prototype.readInt16LE=function(f,u){f=f>>>0,u||de(f,2,this.length);const p=this[f]|this[f+1]<<8;return p&32768?p|4294901760:p},a.prototype.readInt16BE=function(f,u){f=f>>>0,u||de(f,2,this.length);const p=this[f+1]|this[f]<<8;return p&32768?p|4294901760:p},a.prototype.readInt32LE=function(f,u){return f=f>>>0,u||de(f,4,this.length),this[f]|this[f+1]<<8|this[f+2]<<16|this[f+3]<<24},a.prototype.readInt32BE=function(f,u){return f=f>>>0,u||de(f,4,this.length),this[f]<<24|this[f+1]<<16|this[f+2]<<8|this[f+3]},a.prototype.readBigInt64LE=Ye(function(f){f=f>>>0,F(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&D(f,this.length-8);const E=this[f+4]+this[f+5]*2**8+this[f+6]*2**16+(p<<24);return(BigInt(E)<<BigInt(32))+BigInt(u+this[++f]*2**8+this[++f]*2**16+this[++f]*2**24)}),a.prototype.readBigInt64BE=Ye(function(f){f=f>>>0,F(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&D(f,this.length-8);const E=(u<<24)+this[++f]*2**16+this[++f]*2**8+this[++f];return(BigInt(E)<<BigInt(32))+BigInt(this[++f]*2**24+this[++f]*2**16+this[++f]*2**8+p)}),a.prototype.readFloatLE=function(f,u){return f=f>>>0,u||de(f,4,this.length),r.read(this,f,!0,23,4)},a.prototype.readFloatBE=function(f,u){return f=f>>>0,u||de(f,4,this.length),r.read(this,f,!1,23,4)},a.prototype.readDoubleLE=function(f,u){return f=f>>>0,u||de(f,8,this.length),r.read(this,f,!0,52,8)},a.prototype.readDoubleBE=function(f,u){return f=f>>>0,u||de(f,8,this.length),r.read(this,f,!1,52,8)};function ve(h,f,u,p,E,I){if(!a.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(f>E||f<I)throw new RangeError('"value" argument is out of bounds');if(u+p>h.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(f,u,p,E){if(f=+f,u=u>>>0,p=p>>>0,!E){const Q=Math.pow(2,8*p)-1;ve(this,f,u,p,Q,0)}let I=1,L=0;for(this[u]=f&255;++L<p&&(I*=256);)this[u+L]=f/I&255;return u+p},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(f,u,p,E){if(f=+f,u=u>>>0,p=p>>>0,!E){const Q=Math.pow(2,8*p)-1;ve(this,f,u,p,Q,0)}let I=p-1,L=1;for(this[u+I]=f&255;--I>=0&&(L*=256);)this[u+I]=f/L&255;return u+p},a.prototype.writeUint8=a.prototype.writeUInt8=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,1,255,0),this[u]=f&255,u+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,2,65535,0),this[u]=f&255,this[u+1]=f>>>8,u+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,2,65535,0),this[u]=f>>>8,this[u+1]=f&255,u+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,4,4294967295,0),this[u+3]=f>>>24,this[u+2]=f>>>16,this[u+1]=f>>>8,this[u]=f&255,u+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,4,4294967295,0),this[u]=f>>>24,this[u+1]=f>>>16,this[u+2]=f>>>8,this[u+3]=f&255,u+4};function We(h,f,u,p,E){w(f,p,E,h,u,7);let I=Number(f&BigInt(4294967295));h[u++]=I,I=I>>8,h[u++]=I,I=I>>8,h[u++]=I,I=I>>8,h[u++]=I;let L=Number(f>>BigInt(32)&BigInt(4294967295));return h[u++]=L,L=L>>8,h[u++]=L,L=L>>8,h[u++]=L,L=L>>8,h[u++]=L,u}function Tt(h,f,u,p,E){w(f,p,E,h,u,7);let I=Number(f&BigInt(4294967295));h[u+7]=I,I=I>>8,h[u+6]=I,I=I>>8,h[u+5]=I,I=I>>8,h[u+4]=I;let L=Number(f>>BigInt(32)&BigInt(4294967295));return h[u+3]=L,L=L>>8,h[u+2]=L,L=L>>8,h[u+1]=L,L=L>>8,h[u]=L,u+8}a.prototype.writeBigUInt64LE=Ye(function(f,u=0){return We(this,f,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Ye(function(f,u=0){return Tt(this,f,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(f,u,p,E){if(f=+f,u=u>>>0,!E){const _e=Math.pow(2,8*p-1);ve(this,f,u,p,_e-1,-_e)}let I=0,L=1,Q=0;for(this[u]=f&255;++I<p&&(L*=256);)f<0&&Q===0&&this[u+I-1]!==0&&(Q=1),this[u+I]=(f/L>>0)-Q&255;return u+p},a.prototype.writeIntBE=function(f,u,p,E){if(f=+f,u=u>>>0,!E){const _e=Math.pow(2,8*p-1);ve(this,f,u,p,_e-1,-_e)}let I=p-1,L=1,Q=0;for(this[u+I]=f&255;--I>=0&&(L*=256);)f<0&&Q===0&&this[u+I+1]!==0&&(Q=1),this[u+I]=(f/L>>0)-Q&255;return u+p},a.prototype.writeInt8=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,1,127,-128),f<0&&(f=255+f+1),this[u]=f&255,u+1},a.prototype.writeInt16LE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,2,32767,-32768),this[u]=f&255,this[u+1]=f>>>8,u+2},a.prototype.writeInt16BE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,2,32767,-32768),this[u]=f>>>8,this[u+1]=f&255,u+2},a.prototype.writeInt32LE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,4,2147483647,-2147483648),this[u]=f&255,this[u+1]=f>>>8,this[u+2]=f>>>16,this[u+3]=f>>>24,u+4},a.prototype.writeInt32BE=function(f,u,p){return f=+f,u=u>>>0,p||ve(this,f,u,4,2147483647,-2147483648),f<0&&(f=4294967295+f+1),this[u]=f>>>24,this[u+1]=f>>>16,this[u+2]=f>>>8,this[u+3]=f&255,u+4},a.prototype.writeBigInt64LE=Ye(function(f,u=0){return We(this,f,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Ye(function(f,u=0){return Tt(this,f,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function dt(h,f,u,p,E,I){if(u+p>h.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function T(h,f,u,p,E){return f=+f,u=u>>>0,E||dt(h,f,u,4),r.write(h,f,u,p,23,4),u+4}a.prototype.writeFloatLE=function(f,u,p){return T(this,f,u,!0,p)},a.prototype.writeFloatBE=function(f,u,p){return T(this,f,u,!1,p)};function P(h,f,u,p,E){return f=+f,u=u>>>0,E||dt(h,f,u,8),r.write(h,f,u,p,52,8),u+8}a.prototype.writeDoubleLE=function(f,u,p){return P(this,f,u,!0,p)},a.prototype.writeDoubleBE=function(f,u,p){return P(this,f,u,!1,p)},a.prototype.copy=function(f,u,p,E){if(!a.isBuffer(f))throw new TypeError("argument should be a Buffer");if(p||(p=0),!E&&E!==0&&(E=this.length),u>=f.length&&(u=f.length),u||(u=0),E>0&&E<p&&(E=p),E===p||f.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(p<0||p>=this.length)throw new RangeError("Index out of range");if(E<0)throw new RangeError("sourceEnd out of bounds");E>this.length&&(E=this.length),f.length-u<E-p&&(E=f.length-u+p);const I=E-p;return this===f&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(u,p,E):Uint8Array.prototype.set.call(f,this.subarray(p,E),u),I},a.prototype.fill=function(f,u,p,E){if(typeof f=="string"){if(typeof u=="string"?(E=u,u=0,p=this.length):typeof p=="string"&&(E=p,p=this.length),E!==void 0&&typeof E!="string")throw new TypeError("encoding must be a string");if(typeof E=="string"&&!a.isEncoding(E))throw new TypeError("Unknown encoding: "+E);if(f.length===1){const L=f.charCodeAt(0);(E==="utf8"&&L<128||E==="latin1")&&(f=L)}}else typeof f=="number"?f=f&255:typeof f=="boolean"&&(f=Number(f));if(u<0||this.length<u||this.length<p)throw new RangeError("Out of range index");if(p<=u)return this;u=u>>>0,p=p===void 0?this.length:p>>>0,f||(f=0);let I;if(typeof f=="number")for(I=u;I<p;++I)this[I]=f;else{const L=a.isBuffer(f)?f:a.from(f,E),Q=L.length;if(Q===0)throw new TypeError('The value "'+f+'" is invalid for argument "value"');for(I=0;I<p-u;++I)this[I+u]=L[I%Q]}return this};const M={};function G(h,f,u){M[h]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:f.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(E){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:E,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}G("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(h,f){return`The "${h}" argument must be of type number. Received type ${typeof f}`},TypeError),G("ERR_OUT_OF_RANGE",function(h,f,u){let p=`The value of "${h}" is out of range.`,E=u;return Number.isInteger(u)&&Math.abs(u)>2**32?E=K(String(u)):typeof u=="bigint"&&(E=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(E=K(E)),E+="n"),p+=` It must be ${f}. Received ${E}`,p},RangeError);function K(h){let f="",u=h.length;const p=h[0]==="-"?1:0;for(;u>=p+4;u-=3)f=`_${h.slice(u-3,u)}${f}`;return`${h.slice(0,u)}${f}`}function b(h,f,u){F(f,"offset"),(h[f]===void 0||h[f+u]===void 0)&&D(f,h.length-(u+1))}function w(h,f,u,p,E,I){if(h>u||h<f){const L=typeof f=="bigint"?"n":"";let Q;throw f===0||f===BigInt(0)?Q=`>= 0${L} and < 2${L} ** ${(I+1)*8}${L}`:Q=`>= -(2${L} ** ${(I+1)*8-1}${L}) and < 2 ** ${(I+1)*8-1}${L}`,new M.ERR_OUT_OF_RANGE("value",Q,h)}b(p,E,I)}function F(h,f){if(typeof h!="number")throw new M.ERR_INVALID_ARG_TYPE(f,"number",h)}function D(h,f,u){throw Math.floor(h)!==h?(F(h,u),new M.ERR_OUT_OF_RANGE("offset","an integer",h)):f<0?new M.ERR_BUFFER_OUT_OF_BOUNDS:new M.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${f}`,h)}const pe=/[^+/0-9A-Za-z-_]/g;function Y(h){if(h=h.split("=")[0],h=h.trim().replace(pe,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function te(h,f){f=f||1/0;let u;const p=h.length;let E=null;const I=[];for(let L=0;L<p;++L){if(u=h.charCodeAt(L),u>55295&&u<57344){if(!E){if(u>56319){(f-=3)>-1&&I.push(239,191,189);continue}else if(L+1===p){(f-=3)>-1&&I.push(239,191,189);continue}E=u;continue}if(u<56320){(f-=3)>-1&&I.push(239,191,189),E=u;continue}u=(E-55296<<10|u-56320)+65536}else E&&(f-=3)>-1&&I.push(239,191,189);if(E=null,u<128){if((f-=1)<0)break;I.push(u)}else if(u<2048){if((f-=2)<0)break;I.push(u>>6|192,u&63|128)}else if(u<65536){if((f-=3)<0)break;I.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((f-=4)<0)break;I.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return I}function At(h){const f=[];for(let u=0;u<h.length;++u)f.push(h.charCodeAt(u)&255);return f}function cr(h,f){let u,p,E;const I=[];for(let L=0;L<h.length&&!((f-=2)<0);++L)u=h.charCodeAt(L),p=u>>8,E=u%256,I.push(E),I.push(p);return I}function Nr(h){return t.toByteArray(Y(h))}function hr(h,f,u,p){let E;for(E=0;E<p&&!(E+u>=f.length||E>=h.length);++E)f[E+u]=h[E];return E}function ze(h,f){return h instanceof f||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===f.name}function Wt(h){return h!==h}const Fr=function(){const h="0123456789abcdef",f=new Array(256);for(let u=0;u<16;++u){const p=u*16;for(let E=0;E<16;++E)f[p+E]=h[u]+h[E]}return f}();function Ye(h){return typeof BigInt>"u"?zt:h}function zt(){throw new Error("BigInt not supported")}})(Pt);var fn={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}};fn.Null=fn.Nil;for(var Vs in fn)fn[Vs].toJSON=(function(e){return e}).bind(null,Vs);var ys=fn,Yt=ys;function sa(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function bs(e){return Yt.Nil(e)?"":sa(e.constructor)}function _u(e){return Yt.Function(e)?"":Yt.String(e)?JSON.stringify(e):e&&Yt.Object(e)?"":e}function ws(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function $n(e){return Yt.Function(e)?e.toJSON?e.toJSON():sa(e):Yt.Array(e)?"Array":e&&Yt.Object(e)?"Object":e!==void 0?e:""}function oa(e,t,r){var n=_u(t);return"Expected "+$n(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function xt(e,t,r){r=r||bs(t),this.message=oa(e,t,r),ws(this,xt),this.__type=e,this.__value=t,this.__valueTypeName=r}xt.prototype=Object.create(Error.prototype);xt.prototype.constructor=xt;function Eu(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),oa('property "'+$n(r)+s+$n(e),n,i)}function Er(e,t,r,n,i){e?(i=i||bs(n),this.message=Eu(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',ws(this,xt),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Er.prototype=Object.create(Error.prototype);Er.prototype.constructor=xt;function vu(e,t){return new xt(e,{},t)}function xu(e,t,r){return e instanceof Er?(t=t+"."+e.__property,e=new Er(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof xt&&(e=new Er(e.__type,t,r,e.__value,e.__valueTypeName)),ws(e),e}var aa={TfTypeError:xt,TfPropertyTypeError:Er,tfCustomError:vu,tfSubError:xu,tfJSON:$n,getValueTypeName:bs},xi,Ws;function Su(){if(Ws)return xi;Ws=1;var e=ys,t=aa;function r(v){return Buffer.isBuffer(v)}function n(v){return typeof v=="string"&&/^([0-9a-f]{2})+$/i.test(v)}function i(v,$){var j=v.toJSON();function R(z){if(!v(z))return!1;if(z.length===$)return!0;throw t.tfCustomError(j+"(Length: "+$+")",j+"(Length: "+z.length+")")}return R.toJSON=function(){return j},R}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function l(v,$,j){j=j||e.Number;function R(z,Z){return j(z,Z)&&z>v&&z<$}return R.toJSON=function(){return`${j.toJSON()} between [${v}, ${$}]`},R}var d=Math.pow(2,53)-1;function g(v){return typeof v=="number"&&isFinite(v)}function x(v){return v<<24>>24===v}function y(v){return v<<16>>16===v}function O(v){return(v|0)===v}function B(v){return typeof v=="number"&&v>=-d&&v<=d&&Math.floor(v)===v}function A(v){return(v&255)===v}function k(v){return(v&65535)===v}function U(v){return v>>>0===v}function _(v){return typeof v=="number"&&v>=0&&v<=d&&Math.floor(v)===v}var m={ArrayN:s,Buffer:r,BufferN:o,Finite:g,Hex:n,HexN:a,Int8:x,Int16:y,Int32:O,Int53:B,Range:l,StringN:c,UInt8:A,UInt16:k,UInt32:U,UInt53:_};for(var S in m)m[S].toJSON=(function(v){return v}).bind(null,S);return xi=m,xi}var ln=aa,Ae=ys,pt=ln.tfJSON,fa=ln.TfTypeError,ua=ln.TfPropertyTypeError,Mr=ln.tfSubError,Bu=ln.getValueTypeName,_t={arrayOf:function(t,r){t=ct(t),r=r||{};function n(i,s){return!Ae.Array(i)||Ae.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 je(t,o,s)}catch(c){throw Mr(c,a)}})}return n.toJSON=function(){var i="["+pt(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=ct(t);function r(n,i){return Ae.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+pt(t)},r},map:function(t,r){t=ct(t),r&&(r=ct(r));function n(i,s){if(!Ae.Object(i)||Ae.Nil(i))return!1;for(var o in i){try{r&&je(r,o,s)}catch(c){throw Mr(c,o,"key")}try{var a=i[o];je(t,a,s)}catch(c){throw Mr(c,o)}}return!0}return r?n.toJSON=function(){return"{"+pt(r)+": "+pt(t)+"}"}:n.toJSON=function(){return"{"+pt(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=ct(t[n]);function i(s,o){if(!Ae.Object(s)||Ae.Nil(s))return!1;var a;try{for(a in r){var c=r[a],l=s[a];je(c,l,o)}}catch(d){throw Mr(d,a)}if(o){for(a in s)if(!r[a])throw new ua(void 0,a)}return!0}return i.toJSON=function(){return pt(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(ct);function r(n,i){return t.some(function(s){try{return je(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(pt).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(ct);function r(n,i){return t.every(function(s){try{return je(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(pt).join(" & ")},r},quacksLike:function(t){function r(n){return t===Bu(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(ct);function r(n,i){return Ae.Nil(n)||Ae.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return je(s,n[o],i)}catch(a){throw Mr(a,o)}})}return r.toJSON=function(){return"("+t.map(pt).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};_t.oneOf=_t.anyOf;function ct(e){if(Ae.String(e))return e[0]==="?"?_t.maybe(e.slice(1)):Ae[e]||_t.quacksLike(e);if(e&&Ae.Object(e)){if(Ae.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return _t.arrayOf(e[0])}return _t.object(e)}else if(Ae.Function(e))return e;return _t.value(e)}function je(e,t,r,n){if(Ae.Function(e)){if(e(t,r))return!0;throw new fa(n||e,t)}return je(ct(e),t,r)}for(var Ft in Ae)je[Ft]=Ae[Ft];for(Ft in _t)je[Ft]=_t[Ft];var zs=Su();for(Ft in zs)je[Ft]=zs[Ft];je.compile=ct;je.TfTypeError=fa;je.TfPropertyTypeError=ua;var ca=je;(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=Pt;e.typeforce=ca;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(d,g){return d.length!==g.length?!1:d.every((x,y)=>x.equals(g[y]))}e.stacksEqual=i;function s(d){if(!t.Buffer.isBuffer(d)||d.length<33)return!1;const g=d[0],x=d.slice(1,33);if(x.compare(r)===0||x.compare(n)>=0)return!1;if((g===2||g===3)&&d.length===33)return!0;const y=d.slice(33);return y.compare(r)===0||y.compare(n)>=0?!1:g===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 c(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=c;function l(d){return(0,e.Array)(d)?d.length!==2?!1:d.every(g=>l(g)):c(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})(Ne);var dn={},Ie={};Object.defineProperty(Ie,"__esModule",{value:!0});Ie.BufferReader=Ie.BufferWriter=Ie.cloneBuffer=Ie.reverseBuffer=Ie.writeUInt64LE=Ie.readUInt64LE=Ie.varuint=void 0;const Xt=Ne,{typeforce:ha}=Xt,un=Qo;Ie.varuint=un;function la(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 da(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,la(n+r,9007199254740991),n+r}Ie.readUInt64LE=da;function pa(e,t,r){return la(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Ie.writeUInt64LE=pa;function Pu(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}Ie.reverseBuffer=Pu;function Tu(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Ie.cloneBuffer=Tu;class gs{static withCapacity(t){return new gs(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,ha(Xt.tuple(Xt.Buffer,Xt.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=pa(this.buffer,t,this.offset)}writeVarInt(t){un.encode(t,this.buffer,this.offset),this.offset+=un.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}`)}}Ie.BufferWriter=gs;class Au{constructor(t,r=0){this.buffer=t,this.offset=r,ha(Xt.tuple(Xt.Buffer,Xt.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=da(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=un.decode(this.buffer,this.offset);return this.offset+=un.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}}Ie.BufferReader=Au;var Dt={},Pr={},Et={},tt={};Object.defineProperty(tt,"__esModule",{value:!0});tt.isBytes=ba;tt.number=Dn;tt.bool=ya;tt.bytes=ms;tt.hash=wa;tt.exists=ga;tt.output=ma;function Dn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function ya(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function ba(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function ms(e,...t){if(!ba(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 wa(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Dn(e.outputLen),Dn(e.blockLen)}function ga(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 ma(e,t){ms(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const Iu={number:Dn,bool:ya,bytes:ms,hash:wa,exists:ga,output:ma};tt.default=Iu;var Qn={},Zn={};Object.defineProperty(Zn,"__esModule",{value:!0});Zn.crypto=void 0;Zn.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=x,e.hexToBytes=B,e.asyncLoop=k,e.utf8ToBytes=U,e.toBytes=_,e.concatBytes=m,e.checkOpts=$,e.wrapConstructor=j,e.wrapConstructorWithOpts=R,e.wrapXOFConstructorWithOpts=z,e.randomBytes=Z;const t=Zn,r=tt;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,H)=>C<<32-H|C>>>H;e.rotr=a;const c=(C,H)=>C<<H|C>>>32-H>>>0;e.rotl=c,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 H=0;H<C.length;H++)C[H]=(0,e.byteSwap)(C[H])}const g=Array.from({length:256},(C,H)=>H.toString(16).padStart(2,"0"));function x(C){(0,r.bytes)(C);let H="";for(let V=0;V<C.length;V++)H+=g[C[V]];return H}const y={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function O(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 B(C){if(typeof C!="string")throw new Error("hex string expected, got "+typeof C);const H=C.length,V=H/2;if(H%2)throw new Error("padded hex string expected, got unpadded hex of length "+H);const q=new Uint8Array(V);for(let oe=0,ae=0;oe<V;oe++,ae+=2){const Ze=O(C.charCodeAt(ae)),Ve=O(C.charCodeAt(ae+1));if(Ze===void 0||Ve===void 0){const nt=C[ae]+C[ae+1];throw new Error('hex string expected, got non-hex character "'+nt+'" at index '+ae)}q[oe]=Ze*16+Ve}return q}const A=async()=>{};e.nextTick=A;async function k(C,H,V){let q=Date.now();for(let oe=0;oe<C;oe++){V(oe);const ae=Date.now()-q;ae>=0&&ae<H||(await(0,e.nextTick)(),q+=ae)}}function U(C){if(typeof C!="string")throw new Error(`utf8ToBytes expected string, got ${typeof C}`);return new Uint8Array(new TextEncoder().encode(C))}function _(C){return typeof C=="string"&&(C=U(C)),(0,r.bytes)(C),C}function m(...C){let H=0;for(let q=0;q<C.length;q++){const oe=C[q];(0,r.bytes)(oe),H+=oe.length}const V=new Uint8Array(H);for(let q=0,oe=0;q<C.length;q++){const ae=C[q];V.set(ae,oe),oe+=ae.length}return V}class S{clone(){return this._cloneInto()}}e.Hash=S;const v={}.toString;function $(C,H){if(H!==void 0&&v.call(H)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(C,H)}function j(C){const H=q=>C().update(_(q)).digest(),V=C();return H.outputLen=V.outputLen,H.blockLen=V.blockLen,H.create=()=>C(),H}function R(C){const H=(q,oe)=>C(oe).update(_(q)).digest(),V=C({});return H.outputLen=V.outputLen,H.blockLen=V.blockLen,H.create=q=>C(q),H}function z(C){const H=(q,oe)=>C(oe).update(_(q)).digest(),V=C({});return H.outputLen=V.outputLen,H.blockLen=V.blockLen,H.create=q=>C(q),H}function Z(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")}})(Qn);Object.defineProperty(Et,"__esModule",{value:!0});Et.HashMD=Et.Maj=Et.Chi=void 0;const Si=tt,Hr=Qn;function Ou(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),c=n?4:0,l=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+l,a,n)}const ku=(e,t,r)=>e&t^~e&r;Et.Chi=ku;const Ru=(e,t,r)=>e&t^e&r^t&r;Et.Maj=Ru;let Uu=class extends Hr.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,Hr.createView)(this.buffer)}update(t){(0,Si.exists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,Hr.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 c=(0,Hr.createView)(t);for(;i<=s-o;o+=i)this.process(c,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,Si.exists)(this),(0,Si.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 g=o;g<i;g++)r[g]=0;Ou(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,Hr.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<l;g++)a.setUint32(4*g,d[g],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}};Et.HashMD=Uu;Object.defineProperty(Pr,"__esModule",{value:!0});Pr.ripemd160=Pr.RIPEMD160=void 0;const Cu=Et,en=Qn,Lu=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),_a=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Nu=_a.map(e=>(9*e+5)%16);let _s=[_a],Es=[Nu];for(let e=0;e<4;e++)for(let t of[_s,Es])t.push(t[e].map(r=>Lu[r]));const Ea=[[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)),Fu=_s.map((e,t)=>e.map(r=>Ea[t][r])),Mu=Es.map((e,t)=>e.map(r=>Ea[t][r])),Hu=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),$u=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function qs(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 xn=new Uint32Array(16);let va=class extends Cu.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)xn[y]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,l=this.h3|0,d=l,g=this.h4|0,x=g;for(let y=0;y<5;y++){const O=4-y,B=Hu[y],A=$u[y],k=_s[y],U=Es[y],_=Fu[y],m=Mu[y];for(let S=0;S<16;S++){const v=(0,en.rotl)(n+qs(y,s,a,l)+xn[k[S]]+B,_[S])+g|0;n=g,g=l,l=(0,en.rotl)(a,10)|0,a=s,s=v}for(let S=0;S<16;S++){const v=(0,en.rotl)(i+qs(O,o,c,d)+xn[U[S]]+A,m[S])+x|0;i=x,x=d,d=(0,en.rotl)(c,10)|0,c=o,o=v}}this.set(this.h1+a+d|0,this.h2+l+x|0,this.h3+g+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){xn.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};Pr.RIPEMD160=va;Pr.ripemd160=(0,en.wrapConstructor)(()=>new va);var Tr={};Object.defineProperty(Tr,"__esModule",{value:!0});Tr.sha1=Tr.SHA1=void 0;const Bi=Et,Rn=Qn,$r=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),It=new Uint32Array(80);class xa extends Bi.HashMD{constructor(){super(64,20,8,!1),this.A=$r[0]|0,this.B=$r[1]|0,this.C=$r[2]|0,this.D=$r[3]|0,this.E=$r[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 c=0;c<16;c++,r+=4)It[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)It[c]=(0,Rn.rotl)(It[c-3]^It[c-8]^It[c-14]^It[c-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let c=0;c<80;c++){let l,d;c<20?(l=(0,Bi.Chi)(i,s,o),d=1518500249):c<40?(l=i^s^o,d=1859775393):c<60?(l=(0,Bi.Maj)(i,s,o),d=2400959708):(l=i^s^o,d=3395469782);const g=(0,Rn.rotl)(n,5)+l+a+d+It[c]|0;a=o,o=s,s=(0,Rn.rotl)(i,30),i=n,n=g}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(){It.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}Tr.SHA1=xa;Tr.sha1=(0,Rn.wrapConstructor)(()=>new xa);function Ks(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Du(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function vs(e,...t){if(!Du(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 jn(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 Sa(e,t){vs(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ju=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Pi=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),it=(e,t)=>e<<32-t|e>>>t,Ys=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,Gu=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;function Xs(e){for(let t=0;t<e.length;t++)e[t]=Gu(e[t])}function Vu(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function xs(e){return typeof e=="string"&&(e=Vu(e)),vs(e),e}let Ba=class{clone(){return this._cloneInto()}};function Ss(e){const t=n=>e().update(xs(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Wu(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),c=n?4:0,l=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+l,a,n)}const zu=(e,t,r)=>e&t^~e&r,qu=(e,t,r)=>e&t^e&r^t&r;class Ku extends Ba{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=Pi(this.buffer)}update(t){jn(this);const{view:r,buffer:n,blockLen:i}=this;t=xs(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Pi(t);for(;i<=s-o;o+=i)this.process(c,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){jn(this),Sa(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 g=o;g<i;g++)r[g]=0;Wu(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Pi(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<l;g++)a.setUint32(4*g,d[g],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 Yu=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]),Ot=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),kt=new Uint32Array(64);class Bs extends Ku{constructor(){super(64,32,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[t,r,n,i,s,o,a,c]}set(t,r,n,i,s,o,a,c){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=c|0}process(t,r){for(let g=0;g<16;g++,r+=4)kt[g]=t.getUint32(r,!1);for(let g=16;g<64;g++){const x=kt[g-15],y=kt[g-2],O=it(x,7)^it(x,18)^x>>>3,B=it(y,17)^it(y,19)^y>>>10;kt[g]=B+kt[g-7]+O+kt[g-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:l,H:d}=this;for(let g=0;g<64;g++){const x=it(a,6)^it(a,11)^it(a,25),y=d+x+zu(a,c,l)+Yu[g]+kt[g]|0,B=(it(n,2)^it(n,13)^it(n,22))+qu(n,i,s)|0;d=l,l=c,c=a,a=o+y|0,o=s,s=i,i=n,n=y+B|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,c=c+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,c,l,d)}roundClean(){kt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Xu extends Bs{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}}const Pa=Ss(()=>new Bs),Ju=Ss(()=>new Xu),Qu=Object.freeze(Object.defineProperty({__proto__:null,SHA256:Bs,sha224:Ju,sha256:Pa},Symbol.toStringTag,{value:"Module"})),Ta=na(Qu);(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=Pr,r=Tr,n=Ta;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 c(d){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(d))))}e.hash256=c,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,g){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[d],g]))}e.taggedHash=l})(Dt);var Ti={},vt={};Object.defineProperty(vt,"__esModule",{value:!0});vt.encode=vt.decode=vt.check=void 0;function Zu(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))}vt.check=Zu;function ec(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)}}vt.decode=ec;function tc(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}vt.encode=tc;var Qt={};Object.defineProperty(Qt,"__esModule",{value:!0});Qt.REVERSE_OPS=Qt.OPS=void 0;const Qi={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};Qt.OPS=Qi;const Aa={};Qt.REVERSE_OPS=Aa;for(const e of Object.keys(Qi)){const t=Qi[e];Aa[t]=e}var Mt={};Object.defineProperty(Mt,"__esModule",{value:!0});Mt.decode=Mt.encode=Mt.encodingLength=void 0;const Nt=Qt;function Ia(e){return e<Nt.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Mt.encodingLength=Ia;function rc(e,t,r){const n=Ia(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(Nt.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(Nt.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(Nt.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Mt.encode=rc;function nc(e,t){const r=e.readUInt8(t);let n,i;if(r<Nt.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===Nt.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===Nt.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!==Nt.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Mt.decode=nc;var Ar={};Object.defineProperty(Ar,"__esModule",{value:!0});Ar.encode=Ar.decode=void 0;function ic(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}Ar.decode=ic;function sc(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function oc(e){let t=Math.abs(e);const r=sc(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}Ar.encode=oc;var Kt={},Js;function ac(){if(Js)return Kt;Js=1,Object.defineProperty(Kt,"__esModule",{value:!0}),Kt.encode=Kt.decode=void 0;const e=vt,t=Ke(),r=Ne,{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),g=Math.max(0,32-l.length);return l.copy(d,g),d}function a(l){const d=l.readUInt8(l.length-1);if(!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const g=e.decode(l.slice(0,-1)),x=o(g.r),y=o(g.s);return{signature:Buffer.concat([x,y],64),hashType:d}}Kt.decode=a;function c(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 g=Buffer.allocUnsafe(1);g.writeUInt8(d,0);const x=s(l.slice(0,32)),y=s(l.slice(32,64));return Buffer.concat([e.encode(x,y),g])}return Kt.encode=c,Kt}var Qs;function Ke(){return Qs||(Qs=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=vt,r=Qt;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Mt,i=Ar,s=ac(),o=Ne,{typeforce:a}=o,c=r.OPS.OP_RESERVED;function l(R){return o.Number(R)&&(R===r.OPS.OP_0||R>=r.OPS.OP_1&&R<=r.OPS.OP_16||R===r.OPS.OP_1NEGATE)}function d(R){return o.Buffer(R)||l(R)}function g(R){return o.Array(R)&&R.every(d)}e.isPushOnly=g;function x(R){return R.length-R.filter(d).length}e.countNonPushOnlyOPs=x;function y(R){if(R.length===0)return r.OPS.OP_0;if(R.length===1){if(R[0]>=1&&R[0]<=16)return c+R[0];if(R[0]===129)return r.OPS.OP_1NEGATE}}function O(R){return Buffer.isBuffer(R)}function B(R){return o.Array(R)}function A(R){return Buffer.isBuffer(R)}function k(R){if(O(R))return R;a(o.Array,R);const z=R.reduce((H,V)=>A(V)?V.length===1&&y(V)!==void 0?H+1:H+n.encodingLength(V.length)+V.length:H+1,0),Z=Buffer.allocUnsafe(z);let C=0;if(R.forEach(H=>{if(A(H)){const V=y(H);if(V!==void 0){Z.writeUInt8(V,C),C+=1;return}C+=n.encode(Z,H.length,C),H.copy(Z,C),C+=H.length}else Z.writeUInt8(H,C),C+=1}),C!==Z.length)throw new Error("Could not decode chunks");return Z}e.compile=k;function U(R){if(B(R))return R;a(o.Buffer,R);const z=[];let Z=0;for(;Z<R.length;){const C=R[Z];if(C>r.OPS.OP_0&&C<=r.OPS.OP_PUSHDATA4){const H=n.decode(R,Z);if(H===null||(Z+=H.size,Z+H.number>R.length))return null;const V=R.slice(Z,Z+H.number);Z+=H.number;const q=y(V);q!==void 0?z.push(q):z.push(V)}else z.push(C),Z+=1}return z}e.decompile=U;function _(R){if(O(R)&&(R=U(R)),!R)throw new Error("Could not convert invalid chunks to ASM");return R.map(z=>{if(A(z)){const Z=y(z);if(Z===void 0)return z.toString("hex");z=Z}return r.REVERSE_OPS[z]}).join(" ")}e.toASM=_;function m(R){return a(o.String,R),k(R.split(" ").map(z=>r.OPS[z]!==void 0?r.OPS[z]:(a(o.Hex,z),Buffer.from(z,"hex"))))}e.fromASM=m;function S(R){return R=U(R),a(g,R),R.map(z=>A(z)?z:z===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(z-c))}e.toStack=S;function v(R){return o.isPoint(R)}e.isCanonicalPubKey=v;function $(R){const z=R&-129;return z>0&&z<4}e.isDefinedHashType=$;function j(R){return!Buffer.isBuffer(R)||!$(R[R.length-1])?!1:t.check(R.slice(0,-1))}e.isCanonicalScriptSignature=j,e.number=i,e.signature=s}(Ti)),Ti}Object.defineProperty(dn,"__esModule",{value:!0});dn.Transaction=void 0;const Se=Ie,Fe=Dt,Zs=Ke(),fc=Ke(),ee=Ne,{typeforce:st}=ee;function ft(e){const t=e.length;return Se.varuint.encodingLength(t)+t}function uc(e){const t=e.length;return Se.varuint.encodingLength(t)+e.reduce((r,n)=>r+ft(n),0)}const Lt=Buffer.allocUnsafe(0),eo=[],Ai=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),to=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),cc=Buffer.from("ffffffffffffffff","hex"),hc={script:Lt,valueBuffer:cc};function lc(e){return e.value!==void 0}class X{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Se.BufferReader(t),i=new X;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===X.ADVANCED_TRANSACTION_MARKER&&o===X.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let d=0;d<c;++d)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:eo});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<c;++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 X.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){st(ee.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&X.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return st(ee.tuple(ee.Hash256bit,ee.UInt32,ee.maybe(ee.UInt32),ee.maybe(ee.Buffer)),arguments),ee.Null(n)&&(n=X.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||Lt,sequence:n,witness:eo})-1}addOutput(t,r){return st(ee.tuple(ee.Buffer,ee.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)+Se.varuint.encodingLength(this.ins.length)+Se.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+ft(i.script),0)+this.outs.reduce((n,i)=>n+8+ft(i.script),0)+(r?this.ins.reduce((n,i)=>n+uc(i.witness),0):0)}clone(){const t=new X;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(st(ee.tuple(ee.UInt32,ee.Buffer,ee.Number),arguments),t>=this.ins.length)return to;const i=Zs.compile(Zs.decompile(r).filter(a=>a!==fc.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===X.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===X.SIGHASH_SINGLE){if(t>=this.outs.length)return to;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=hc;s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&X.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=Lt}),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),Fe.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(st(ee.tuple(ee.UInt32,st.arrayOf(ee.Buffer),st.arrayOf(ee.Satoshi),ee.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===X.SIGHASH_DEFAULT?X.SIGHASH_ALL:i&X.SIGHASH_OUTPUT_MASK,l=(i&X.SIGHASH_INPUT_MASK)===X.SIGHASH_ANYONECANPAY,d=a===X.SIGHASH_NONE,g=a===X.SIGHASH_SINGLE;let x=Lt,y=Lt,O=Lt,B=Lt,A=Lt;if(!l){let m=Se.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(S=>{m.writeSlice(S.hash),m.writeUInt32(S.index)}),x=Fe.sha256(m.end()),m=Se.BufferWriter.withCapacity(8*this.ins.length),n.forEach(S=>m.writeUInt64(S)),y=Fe.sha256(m.end()),m=Se.BufferWriter.withCapacity(r.map(ft).reduce((S,v)=>S+v)),r.forEach(S=>m.writeVarSlice(S)),O=Fe.sha256(m.end()),m=Se.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(S=>m.writeUInt32(S.sequence)),B=Fe.sha256(m.end())}if(d||g){if(g&&t<this.outs.length){const m=this.outs[t],S=Se.BufferWriter.withCapacity(8+ft(m.script));S.writeUInt64(m.value),S.writeVarSlice(m.script),A=Fe.sha256(S.end())}}else{const m=this.outs.map(v=>8+ft(v.script)).reduce((v,$)=>v+$),S=Se.BufferWriter.withCapacity(m);this.outs.forEach(v=>{S.writeUInt64(v.value),S.writeVarSlice(v.script)}),A=Fe.sha256(S.end())}const k=(s?2:0)+(o?1:0),U=174-(l?49:0)-(d?32:0)+(o?32:0)+(s?37:0),_=Se.BufferWriter.withCapacity(U);if(_.writeUInt8(i),_.writeInt32(this.version),_.writeUInt32(this.locktime),_.writeSlice(x),_.writeSlice(y),_.writeSlice(O),_.writeSlice(B),d||g||_.writeSlice(A),_.writeUInt8(k),l){const m=this.ins[t];_.writeSlice(m.hash),_.writeUInt32(m.index),_.writeUInt64(n[t]),_.writeVarSlice(r[t]),_.writeUInt32(m.sequence)}else _.writeUInt32(t);if(o){const m=Se.BufferWriter.withCapacity(ft(o));m.writeVarSlice(o),_.writeSlice(Fe.sha256(m.end()))}return g&&_.writeSlice(A),s&&(_.writeSlice(s),_.writeUInt8(0),_.writeUInt32(4294967295)),Fe.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),_.end()]))}hashForWitnessV0(t,r,n,i){st(ee.tuple(ee.UInt32,ee.Buffer,ee.Satoshi,ee.UInt32),arguments);let s=Buffer.from([]),o,a=Ai,c=Ai,l=Ai;if(i&X.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Se.BufferWriter(s,0),this.ins.forEach(g=>{o.writeSlice(g.hash),o.writeUInt32(g.index)}),c=Fe.hash256(s)),!(i&X.SIGHASH_ANYONECANPAY)&&(i&31)!==X.SIGHASH_SINGLE&&(i&31)!==X.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Se.BufferWriter(s,0),this.ins.forEach(g=>{o.writeUInt32(g.sequence)}),l=Fe.hash256(s)),(i&31)!==X.SIGHASH_SINGLE&&(i&31)!==X.SIGHASH_NONE){const g=this.outs.reduce((x,y)=>x+8+ft(y.script),0);s=Buffer.allocUnsafe(g),o=new Se.BufferWriter(s,0),this.outs.forEach(x=>{o.writeUInt64(x.value),o.writeVarSlice(x.script)}),a=Fe.hash256(s)}else if((i&31)===X.SIGHASH_SINGLE&&t<this.outs.length){const g=this.outs[t];s=Buffer.allocUnsafe(8+ft(g.script)),o=new Se.BufferWriter(s,0),o.writeUInt64(g.value),o.writeVarSlice(g.script),a=Fe.hash256(s)}s=Buffer.allocUnsafe(156+ft(r)),o=new Se.BufferWriter(s,0);const d=this.ins[t];return o.writeInt32(this.version),o.writeSlice(c),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),Fe.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):Fe.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Se.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){st(ee.tuple(ee.Number,ee.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){st(ee.tuple(ee.Number,[ee.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Se.BufferWriter(t,r||0);i.writeInt32(this.version);const s=n&&this.hasWitnesses();return s&&(i.writeUInt8(X.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(X.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=>{lc(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}}dn.Transaction=X;X.DEFAULT_SEQUENCE=4294967295;X.SIGHASH_DEFAULT=0;X.SIGHASH_ALL=1;X.SIGHASH_NONE=2;X.SIGHASH_SINGLE=3;X.SIGHASH_ANYONECANPAY=128;X.SIGHASH_OUTPUT_MASK=3;X.SIGHASH_INPUT_MASK=128;X.ADVANCED_TRANSACTION_MARKER=0;X.ADVANCED_TRANSACTION_FLAG=1;var ie={},pn={};Object.defineProperty(pn,"__esModule",{value:!0});const dc=9007199254740991;function Ps(e){if(e<0||e>dc||e%1!==0)throw new RangeError("value out of range")}function tn(e,t,r){if(Ps(e),t||(t=Buffer.allocUnsafe(Oa(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(tn,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(tn,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(tn,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(tn,{bytes:9})),t}pn.encode=tn;function rn(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(rn,{bytes:1}),r;if(r===253)return Object.assign(rn,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(rn,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(rn,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return Ps(s),s}}pn.decode=rn;function Oa(e){return Ps(e),e<253?1:e<=65535?3:e<=4294967295?5:9}pn.encodingLength=Oa;var Ii={},ei={},Le={};Object.defineProperty(Le,"__esModule",{value:!0});Le.testnet=Le.regtest=Le.bitcoin=void 0;Le.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
7
|
-
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};
|
|
8
|
-
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};
|
|
9
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var qe={};Object.defineProperty(qe,"__esModule",{value:!0});qe.value=qe.prop=void 0;function pc(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})}})}qe.prop=pc;function yc(e){let t;return()=>(t!==void 0||(t=e()),t)}qe.value=yc;Object.defineProperty(ei,"__esModule",{value:!0});ei.p2data=void 0;const bc=Le,Un=Ke(),ot=Ne,ro=qe,no=Un.OPS;function wc(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,ot.typeforce)({network:ot.typeforce.maybe(ot.typeforce.Object),output:ot.typeforce.maybe(ot.typeforce.Buffer),data:ot.typeforce.maybe(ot.typeforce.arrayOf(ot.typeforce.Buffer))},e);const n={name:"embed",network:e.network||bc.bitcoin};if(ro.prop(n,"output",()=>{if(e.data)return Un.compile([no.OP_RETURN].concat(e.data))}),ro.prop(n,"data",()=>{if(e.output)return Un.decompile(e.output).slice(1)}),t.validate&&e.output){const i=Un.decompile(e.output);if(i[0]!==no.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(ot.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,ot.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}ei.p2data=wc;var ti={};Object.defineProperty(ti,"__esModule",{value:!0});ti.p2ms=void 0;const gc=Le,br=Ke(),xe=Ne,Rt=qe,wr=br.OPS,Sn=wr.OP_RESERVED;function mc(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(c){return br.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===wr.OP_0)!==void 0}(0,xe.typeforce)({network:xe.typeforce.maybe(xe.typeforce.Object),m:xe.typeforce.maybe(xe.typeforce.Number),n:xe.typeforce.maybe(xe.typeforce.Number),output:xe.typeforce.maybe(xe.typeforce.Buffer),pubkeys:xe.typeforce.maybe(xe.typeforce.arrayOf(xe.isPoint)),signatures:xe.typeforce.maybe(xe.typeforce.arrayOf(r)),input:xe.typeforce.maybe(xe.typeforce.Buffer)},e);const i={network:e.network||gc.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=br.decompile(c),i.m=s[0]-Sn,i.n=s[s.length-2]-Sn,i.pubkeys=s.slice(1,-2))}if(Rt.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return br.compile([].concat(Sn+e.m,e.pubkeys,Sn+i.n,wr.OP_CHECKMULTISIG))}),Rt.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),Rt.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Rt.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),Rt.prop(i,"signatures",()=>{if(e.input)return br.decompile(e.input).slice(1)}),Rt.prop(i,"input",()=>{if(e.signatures)return br.compile([wr.OP_0].concat(e.signatures))}),Rt.prop(i,"witness",()=>{if(i.input)return[]}),Rt.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!xe.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!xe.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==wr.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(c=>(0,xe.isPoint)(c)))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,xe.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]!==wr.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,xe.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)}ti.p2ms=mc;var ri={};Object.defineProperty(ri,"__esModule",{value:!0});ri.p2pk=void 0;const _c=Le,gr=Ke(),et=Ne,yr=qe,io=gr.OPS;function Ec(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,et.typeforce)({network:et.typeforce.maybe(et.typeforce.Object),output:et.typeforce.maybe(et.typeforce.Buffer),pubkey:et.typeforce.maybe(et.isPoint),signature:et.typeforce.maybe(gr.isCanonicalScriptSignature),input:et.typeforce.maybe(et.typeforce.Buffer)},e);const r=yr.value(()=>gr.decompile(e.input)),i={name:"p2pk",network:e.network||_c.bitcoin};if(yr.prop(i,"output",()=>{if(e.pubkey)return gr.compile([e.pubkey,io.OP_CHECKSIG])}),yr.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),yr.prop(i,"signature",()=>{if(e.input)return r()[0]}),yr.prop(i,"input",()=>{if(e.signature)return gr.compile([e.signature])}),yr.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==io.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,et.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(!gr.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}ri.p2pk=Ec;var ni={};function vc(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if(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 O=0,B=0,A=0,k=y.length;A!==k&&y[A]===0;)A++,O++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=y[A],S=0,v=U-1;(m!==0||S<B)&&v!==-1;v--,S++)m+=256*_[v]>>>0,_[v]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");B=S,A++}for(var $=U-B;$!==U&&_[$]===0;)$++;for(var j=a.repeat(O);$<U;++$)j+=e.charAt(_[$]);return j}function g(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;for(var O=0,B=0,A=0;y[O]===a;)B++,O++;for(var k=(y.length-O)*c+1>>>0,U=new Uint8Array(k);y[O];){var _=t[y.charCodeAt(O)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,O++}for(var v=k-A;v!==k&&U[v]===0;)v++;for(var $=new Uint8Array(B+(k-v)),j=B;v!==k;)$[j++]=U[v++];return $}function x(y){var O=g(y);if(O)return O;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:g,decode:x}}var xc=vc;const Sc=xc,Bc="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var Pc=Sc(Bc),Oi=Pc,Tc=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,l=new Uint8Array(c);return l.set(o,0),l.set(a.subarray(0,4),o.length),Oi.encode(l,c)}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=Oi.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Oi.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:so}=Ta,Ac=Tc;function Ic(e){return so(so(e))}var Ts=Ac(Ic);Object.defineProperty(ni,"__esModule",{value:!0});ni.p2pkh=void 0;const ki=Dt,Oc=Le,mr=Ke(),Me=Ne,yt=qe,oo=Ts,Ut=mr.OPS;function kc(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,Me.typeforce)({network:Me.typeforce.maybe(Me.typeforce.Object),address:Me.typeforce.maybe(Me.typeforce.String),hash:Me.typeforce.maybe(Me.typeforce.BufferN(20)),output:Me.typeforce.maybe(Me.typeforce.BufferN(25)),pubkey:Me.typeforce.maybe(Me.isPoint),signature:Me.typeforce.maybe(mr.isCanonicalScriptSignature),input:Me.typeforce.maybe(Me.typeforce.Buffer)},e);const r=yt.value(()=>{const o=Buffer.from(oo.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=yt.value(()=>mr.decompile(e.input)),i=e.network||Oc.bitcoin,s={name:"p2pkh",network:i};if(yt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),oo.encode(o)}),yt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return ki.hash160(e.pubkey||s.pubkey)}),yt.prop(s,"output",()=>{if(s.hash)return mr.compile([Ut.OP_DUP,Ut.OP_HASH160,s.hash,Ut.OP_EQUALVERIFY,Ut.OP_CHECKSIG])}),yt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),yt.prop(s,"signature",()=>{if(e.input)return n()[0]}),yt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return mr.compile([e.signature,e.pubkey])}),yt.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]!==Ut.OP_DUP||e.output[1]!==Ut.OP_HASH160||e.output[2]!==20||e.output[23]!==Ut.OP_EQUALVERIFY||e.output[24]!==Ut.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=ki.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(!mr.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,Me.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 c=ki.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}ni.p2pkh=kc;var ii={};Object.defineProperty(ii,"__esModule",{value:!0});ii.p2sh=void 0;const ao=Dt,Rc=Le,ut=Ke(),fe=Ne,at=qe,fo=Ts,Dr=ut.OPS;function Uc(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,fe.typeforce)({network:fe.typeforce.maybe(fe.typeforce.Object),address:fe.typeforce.maybe(fe.typeforce.String),hash:fe.typeforce.maybe(fe.typeforce.BufferN(20)),output:fe.typeforce.maybe(fe.typeforce.BufferN(23)),redeem:fe.typeforce.maybe({network:fe.typeforce.maybe(fe.typeforce.Object),output:fe.typeforce.maybe(fe.typeforce.Buffer),input:fe.typeforce.maybe(fe.typeforce.Buffer),witness:fe.typeforce.maybe(fe.typeforce.arrayOf(fe.typeforce.Buffer))}),input:fe.typeforce.maybe(fe.typeforce.Buffer),witness:fe.typeforce.maybe(fe.typeforce.arrayOf(fe.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Rc.bitcoin);const n={network:r},i=at.value(()=>{const a=Buffer.from(fo.decode(e.address)),c=a.readUInt8(0),l=a.slice(1);return{version:c,hash:l}}),s=at.value(()=>ut.decompile(e.input)),o=at.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Dr.OP_FALSE?Buffer.from([]):c,input:ut.compile(a.slice(0,-1)),witness:e.witness||[]}});if(at.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),fo.encode(a)}),at.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 ao.hash160(n.redeem.output)}),at.prop(n,"output",()=>{if(n.hash)return ut.compile([Dr.OP_HASH160,n.hash,Dr.OP_EQUAL])}),at.prop(n,"redeem",()=>{if(e.input)return o()}),at.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return ut.compile([].concat(ut.decompile(e.redeem.input),e.redeem.output))}),at.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),at.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]!==Dr.OP_HASH160||e.output[1]!==20||e.output[22]!==Dr.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 c=l=>{if(l.output){const d=ut.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(ut.countNonPushOnlyOPs(d)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const g=ao.hash160(l.output);if(a.length>0&&!a.equals(g))throw new TypeError("Hash mismatch");a=g}if(l.input){const d=l.input.length>0,g=l.witness&&l.witness.length>0;if(!d&&!g)throw new TypeError("Empty input");if(d&&g)throw new TypeError("Input and witness provided");if(d){const x=ut.decompile(l.input);if(!ut.isPushOnly(x))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");c(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")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,fe.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}ii.p2sh=Uc;var si={},St={};Object.defineProperty(St,"__esModule",{value:!0});St.bech32m=St.bech32=void 0;const Gn="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ka={};for(let e=0;e<Gn.length;e++){const t=Gn.charAt(e);ka[t]=e}function vr(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 uo(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=vr(t)^n>>5}t=vr(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=vr(t)^n&31}return t}function As(e,t,r,n){let i=0,s=0;const o=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],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 Cc(e){return As(e,8,5,!0)}function Lc(e){const t=As(e,5,8,!1);if(Array.isArray(t))return t}function Nc(e){const t=As(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Ra(e){let t;e==="bech32"?t=1:t=734539939;function r(o,a,c){if(c=c||90,o.length+7+a.length>c)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let l=uo(o);if(typeof l=="string")throw new Error(l);let d=o+"1";for(let g=0;g<a.length;++g){const x=a[g];if(x>>5)throw new Error("Non 5-bit word");l=vr(l)^x,d+=Gn.charAt(x)}for(let g=0;g<6;++g)l=vr(l);l^=t;for(let g=0;g<6;++g){const x=l>>(5-g)*5&31;d+=Gn.charAt(x)}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 c=o.toLowerCase(),l=o.toUpperCase();if(o!==c&&o!==l)return"Mixed-case string "+o;o=c;const d=o.lastIndexOf("1");if(d===-1)return"No separator character for "+o;if(d===0)return"Missing prefix for "+o;const g=o.slice(0,d),x=o.slice(d+1);if(x.length<6)return"Data too short";let y=uo(g);if(typeof y=="string")return y;const O=[];for(let B=0;B<x.length;++B){const A=x.charAt(B),k=ka[A];if(k===void 0)return"Unknown character "+A;y=vr(y)^k,!(B+6>=x.length)&&O.push(k)}return y!==t?"Invalid checksum for "+o:{prefix:g,words:O}}function i(o,a){const c=n(o,a);if(typeof c=="object")return c}function s(o,a){const c=n(o,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:s,encode:r,toWords:Cc,fromWordsUnsafe:Lc,fromWords:Nc}}St.bech32=Ra("bech32");St.bech32m=Ra("bech32m");Object.defineProperty(si,"__esModule",{value:!0});si.p2wpkh=void 0;const Ri=Dt,Fc=Le,Cn=Ke(),Be=Ne,Ct=qe,Bn=St,co=Cn.OPS,Mc=Buffer.alloc(0);function Hc(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,Be.typeforce)({address:Be.typeforce.maybe(Be.typeforce.String),hash:Be.typeforce.maybe(Be.typeforce.BufferN(20)),input:Be.typeforce.maybe(Be.typeforce.BufferN(0)),network:Be.typeforce.maybe(Be.typeforce.Object),output:Be.typeforce.maybe(Be.typeforce.BufferN(22)),pubkey:Be.typeforce.maybe(Be.isPoint),signature:Be.typeforce.maybe(Cn.isCanonicalScriptSignature),witness:Be.typeforce.maybe(Be.typeforce.arrayOf(Be.typeforce.Buffer))},e);const r=Ct.value(()=>{const s=Bn.bech32.decode(e.address),o=s.words.shift(),a=Bn.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||Fc.bitcoin,i={name:"p2wpkh",network:n};if(Ct.prop(i,"address",()=>{if(!i.hash)return;const s=Bn.bech32.toWords(i.hash);return s.unshift(0),Bn.bech32.encode(n.bech32,s)}),Ct.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return Ri.hash160(e.pubkey||i.pubkey)}),Ct.prop(i,"output",()=>{if(i.hash)return Cn.compile([co.OP_0,i.hash])}),Ct.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Ct.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Ct.prop(i,"input",()=>{if(i.witness)return Mc}),Ct.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]!==co.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=Ri.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Be.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(!Cn.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Be.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=Ri.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}si.p2wpkh=Hc;var oi={};Object.defineProperty(oi,"__esModule",{value:!0});oi.p2wsh=void 0;const ho=Dt,$c=Le,mt=Ke(),se=Ne,bt=qe,Pn=St,lo=mt.OPS,Ui=Buffer.alloc(0);function Tn(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,se.isPoint)(e))}function Dc(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,se.typeforce)({network:se.typeforce.maybe(se.typeforce.Object),address:se.typeforce.maybe(se.typeforce.String),hash:se.typeforce.maybe(se.typeforce.BufferN(32)),output:se.typeforce.maybe(se.typeforce.BufferN(34)),redeem:se.typeforce.maybe({input:se.typeforce.maybe(se.typeforce.Buffer),network:se.typeforce.maybe(se.typeforce.Object),output:se.typeforce.maybe(se.typeforce.Buffer),witness:se.typeforce.maybe(se.typeforce.arrayOf(se.typeforce.Buffer))}),input:se.typeforce.maybe(se.typeforce.BufferN(0)),witness:se.typeforce.maybe(se.typeforce.arrayOf(se.typeforce.Buffer))},e);const r=bt.value(()=>{const o=Pn.bech32.decode(e.address),a=o.words.shift(),c=Pn.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=bt.value(()=>mt.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||$c.bitcoin);const s={network:i};if(bt.prop(s,"address",()=>{if(!s.hash)return;const o=Pn.bech32.toWords(s.hash);return o.unshift(0),Pn.bech32.encode(i.bech32,o)}),bt.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return ho.sha256(s.redeem.output)}),bt.prop(s,"output",()=>{if(s.hash)return mt.compile([lo.OP_0,s.hash])}),bt.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Ui,witness:e.witness.slice(0,-1)}}),bt.prop(s,"input",()=>{if(s.witness)return Ui}),bt.prop(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=mt.toStack(n());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=Ui,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),bt.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]!==lo.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=mt.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(mt.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=ho.sha256(e.redeem.output);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch");o=c}if(e.redeem.input&&!mt.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,se.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Tn)||e.redeem.output&&(mt.decompile(e.redeem.output)||[]).some(Tn))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(Tn)||(mt.decompile(a)||[]).some(Tn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}oi.p2wsh=Dc;var jr={},Zt={};Object.defineProperty(Zt,"__esModule",{value:!0});Zt.getEccLib=Zt.initEccLib=void 0;const nn={};function jc(e){e?e!==nn.eccLib&&(Vc(e),nn.eccLib=e):nn.eccLib=e}Zt.initEccLib=jc;function Gc(){if(!nn.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return nn.eccLib}Zt.getEccLib=Gc;const wt=e=>Buffer.from(e,"hex");function Vc(e){Xe(typeof e.isXOnlyPoint=="function"),Xe(e.isXOnlyPoint(wt("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Xe(e.isXOnlyPoint(wt("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Xe(e.isXOnlyPoint(wt("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Xe(e.isXOnlyPoint(wt("0000000000000000000000000000000000000000000000000000000000000001"))),Xe(!e.isXOnlyPoint(wt("0000000000000000000000000000000000000000000000000000000000000000"))),Xe(!e.isXOnlyPoint(wt("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Xe(typeof e.xOnlyPointAddTweak=="function"),Wc.forEach(t=>{const r=e.xOnlyPointAddTweak(wt(t.pubkey),wt(t.tweak));t.result===null?Xe(r===null):(Xe(r!==null),Xe(r.parity===t.parity),Xe(Buffer.from(r.xOnlyPubkey).equals(wt(t.result))))})}function Xe(e){if(!e)throw new Error("ecc library invalid")}const Wc=[{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 Is={};(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=Pt,r=Zt,n=Dt,i=Ie,s=Ne;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=B=>"left"in B&&"right"in B;function a(B,A){if(B.length<33)throw new TypeError(`The control-block length is too small. Got ${B.length}, expected min 33.`);const k=(B.length-33)/32;let U=A;for(let _=0;_<k;_++){const m=B.slice(33+32*_,65+32*_);U.compare(m)<0?U=y(U,m):U=y(m,U)}return U}e.rootHashFromPath=a;function c(B){if((0,s.isTapleaf)(B))return{hash:d(B)};const A=[c(B[0]),c(B[1])];A.sort((_,m)=>_.hash.compare(m.hash));const[k,U]=A;return{hash:y(k.hash,U.hash),left:k,right:U}}e.toHashTree=c;function l(B,A){if(o(B)){const k=l(B.left,A);if(k!==void 0)return[...k,B.right.hash];const U=l(B.right,A);if(U!==void 0)return[...U,B.left.hash]}else if(B.hash.equals(A))return[]}e.findScriptPath=l;function d(B){const A=B.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([A]),O(B.output)]))}e.tapleafHash=d;function g(B,A){return n.taggedHash("TapTweak",t.Buffer.concat(A?[B,A]:[B]))}e.tapTweakHash=g;function x(B,A){if(!t.Buffer.isBuffer(B)||B.length!==32||A&&A.length!==32)return null;const k=g(B,A),U=(0,r.getEccLib)().xOnlyPointAddTweak(B,k);return!U||U.xOnlyPubkey===null?null:{parity:U.parity,x:t.Buffer.from(U.xOnlyPubkey)}}e.tweakKey=x;function y(B,A){return n.taggedHash("TapBranch",t.Buffer.concat([B,A]))}function O(B){const A=i.varuint.encodingLength(B.length),k=t.Buffer.allocUnsafe(A);return i.varuint.encode(B.length,k),t.Buffer.concat([k,B])}})(Is);var He={},po;function zc(){if(po)return He;po=1,Object.defineProperty(He,"__esModule",{value:!0}),He.toOutputScript=He.fromOutputScript=He.toBech32=He.toBase58Check=He.fromBech32=He.fromBase58Check=void 0;const e=Le,t=Os(),r=Ke(),n=Ne,i=St,s=Ts,o=40,a=2,c=16,l=2,d=80,g="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 x(_,m){const S=_.slice(2);if(S.length<a||S.length>o)throw new TypeError("Invalid program length for segwit address");const v=_[0]-d;if(v<l||v>c)throw new TypeError("Invalid version for segwit address");if(_[1]!==S.length)throw new TypeError("Invalid script for segwit address");return console.warn(g),A(S,v,m.bech32)}function y(_){const m=Buffer.from(s.decode(_));if(m.length<21)throw new TypeError(_+" is too short");if(m.length>21)throw new TypeError(_+" is too long");const S=m.readUInt8(0),v=m.slice(1);return{version:S,hash:v}}He.fromBase58Check=y;function O(_){let m,S;try{m=i.bech32.decode(_)}catch{}if(m){if(S=m.words[0],S!==0)throw new TypeError(_+" uses wrong encoding")}else if(m=i.bech32m.decode(_),S=m.words[0],S===0)throw new TypeError(_+" uses wrong encoding");const v=i.bech32.fromWords(m.words.slice(1));return{version:S,prefix:m.prefix,data:Buffer.from(v)}}He.fromBech32=O;function B(_,m){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const S=Buffer.allocUnsafe(21);return S.writeUInt8(m,0),_.copy(S,1),s.encode(S)}He.toBase58Check=B;function A(_,m,S){const v=i.bech32.toWords(_);return v.unshift(m),m===0?i.bech32.encode(S,v):i.bech32m.encode(S,v)}He.toBech32=A;function k(_,m){m=m||e.bitcoin;try{return t.p2pkh({output:_,network:m}).address}catch{}try{return t.p2sh({output:_,network:m}).address}catch{}try{return t.p2wpkh({output:_,network:m}).address}catch{}try{return t.p2wsh({output:_,network:m}).address}catch{}try{return t.p2tr({output:_,network:m}).address}catch{}try{return x(_,m)}catch{}throw new Error(r.toASM(_)+" has no matching Address")}He.fromOutputScript=k;function U(_,m){m=m||e.bitcoin;let S,v;try{S=y(_)}catch{}if(S){if(S.version===m.pubKeyHash)return t.p2pkh({hash:S.hash}).output;if(S.version===m.scriptHash)return t.p2sh({hash:S.hash}).output}else{try{v=O(_)}catch{}if(v){if(v.prefix!==m.bech32)throw new Error(_+" has an invalid prefix");if(v.version===0){if(v.data.length===20)return t.p2wpkh({hash:v.data}).output;if(v.data.length===32)return t.p2wsh({hash:v.data}).output}else if(v.version===1){if(v.data.length===32)return t.p2tr({pubkey:v.data}).output}else if(v.version>=l&&v.version<=c&&v.data.length>=a&&v.data.length<=o)return console.warn(g),r.compile([v.version+d,v.data])}}throw new Error(_+" has no matching Script")}return He.toOutputScript=U,He}var yo;function qc(){if(yo)return jr;yo=1,Object.defineProperty(jr,"__esModule",{value:!0}),jr.p2tr=void 0;const e=Pt,t=Le,r=Ke(),n=Ne,i=Zt,s=Is,o=qe,a=St,c=zc(),l=r.OPS,d=1,g=80;function x(y,O){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");O=Object.assign({validate:!0},O||{}),(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 B=o.value(()=>(0,c.fromBech32)(y.address)),A=o.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===g?y.witness.slice(0,-1):y.witness.slice()}),k=o.value(()=>{if(y.scriptTree)return(0,s.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),U=y.network||t.bitcoin,_={name:"p2tr",network:U};if(o.prop(_,"address",()=>{if(!_.pubkey)return;const m=a.bech32m.toWords(_.pubkey);return m.unshift(d),a.bech32m.encode(U.bech32,m)}),o.prop(_,"hash",()=>{const m=k();if(m)return m.hash;const S=A();if(S&&S.length>1){const v=S[S.length-1],$=v[0]&n.TAPLEAF_VERSION_MASK,j=S[S.length-2],R=(0,s.tapleafHash)({output:j,version:$});return(0,s.rootHashFromPath)(v,R)}return null}),o.prop(_,"output",()=>{if(_.pubkey)return r.compile([l.OP_1,_.pubkey])}),o.prop(_,"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(_,"redeem",()=>{const m=A();if(!(!m||m.length<2))return{output:m[m.length-2],witness:m.slice(0,-2),redeemVersion:m[m.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(_,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return B().data;if(_.internalPubkey){const m=(0,s.tweakKey)(_.internalPubkey,_.hash);if(m)return m.x}}),o.prop(_,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const m=A();if(m&&m.length>1)return m[m.length-1].slice(1,33)}),o.prop(_,"signature",()=>{if(y.signature)return y.signature;const m=A();if(!(!m||m.length!==1))return m[0]}),o.prop(_,"witness",()=>{if(y.witness)return y.witness;const m=k();if(m&&y.redeem&&y.redeem.output&&y.internalPubkey){const S=(0,s.tapleafHash)({output:y.redeem.output,version:_.redeemVersion}),v=(0,s.findScriptPath)(m,S);if(!v)return;const $=(0,s.tweakKey)(y.internalPubkey,m.hash);if(!$)return;const j=e.Buffer.concat([e.Buffer.from([_.redeemVersion|$.parity]),y.internalPubkey].concat(v));return[y.redeem.output,j]}if(y.signature)return[y.signature]}),O.validate){let m=e.Buffer.from([]);if(y.address){if(U&&U.bech32!==B().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(B().version!==d)throw new TypeError("Invalid address version");if(B().data.length!==32)throw new TypeError("Invalid address data");m=B().data}if(y.pubkey){if(m.length>0&&!m.equals(y.pubkey))throw new TypeError("Pubkey mismatch");m=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(m.length>0&&!m.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");m=y.output.slice(2)}if(y.internalPubkey){const $=(0,s.tweakKey)(y.internalPubkey,_.hash);if(m.length>0&&!m.equals($.x))throw new TypeError("Pubkey mismatch");m=$.x}if(m&&m.length&&!(0,i.getEccLib)().isXOnlyPoint(m))throw new TypeError("Invalid pubkey for p2tr");const S=k();if(y.hash&&S&&!y.hash.equals(S.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&S){const $=(0,s.tapleafHash)({output:y.redeem.output,version:_.redeemVersion});if(!(0,s.findScriptPath)(S,$))throw new TypeError("Redeem script not in tree")}const v=A();if(y.redeem&&_.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==_.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(_.redeem.output&&!y.redeem.output.equals(_.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&_.redeem.witness&&!(0,n.stacksEqual)(y.redeem.witness,_.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(v&&v.length)if(v.length===1){if(y.signature&&!y.signature.equals(v[0]))throw new TypeError("Signature mismatch")}else{const $=v[v.length-1];if($.length<33)throw new TypeError(`The control-block length is too small. Got ${$.length}, expected min 33.`);if(($.length-33)%32!==0)throw new TypeError(`The control-block length of ${$.length} is incorrect!`);const j=($.length-33)/32;if(j>128)throw new TypeError(`The script path is too long. Got ${j}, expected max 128.`);const R=$.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(R))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(R))throw new TypeError("Invalid internalPubkey for p2tr witness");const z=$[0]&n.TAPLEAF_VERSION_MASK,Z=v[v.length-2],C=(0,s.tapleafHash)({output:Z,version:z}),H=(0,s.rootHashFromPath)($,C),V=(0,s.tweakKey)(R,H);if(!V)throw new TypeError("Invalid outputKey for p2tr witness");if(m.length&&!m.equals(V.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(V.parity!==($[0]&1))throw new Error("Incorrect parity")}}return Object.assign(_,y)}return jr.p2tr=x,jr}var bo;function Os(){return bo||(bo=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=ei;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=ti;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=ri;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=ni;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=ii;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=si;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=oi;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=qc();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Ii)),Ii}Object.defineProperty(ie,"__esModule",{value:!0});ie.signatureBlocksAction=ie.checkInputForSig=ie.pubkeyInScript=ie.pubkeyPositionInScript=ie.witnessStackToScriptWitness=ie.isP2TR=ie.isP2SHScript=ie.isP2WSHScript=ie.isP2WPKH=ie.isP2PKH=ie.isP2PK=ie.isP2MS=void 0;const wo=pn,sn=Ke(),An=dn,Kc=Dt,sr=Os();function or(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}ie.isP2MS=or(sr.p2ms);ie.isP2PK=or(sr.p2pk);ie.isP2PKH=or(sr.p2pkh);ie.isP2WPKH=or(sr.p2wpkh);ie.isP2WSHScript=or(sr.p2wsh);ie.isP2SHScript=or(sr.p2sh);ie.isP2TR=or(sr.p2tr);function Yc(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=wo.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),wo.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}ie.witnessStackToScriptWitness=Yc;function Ua(e,t){const r=(0,Kc.hash160)(e),n=e.slice(1,33),i=sn.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))}ie.pubkeyPositionInScript=Ua;function Xc(e,t){return Ua(e,t)!==-1}ie.pubkeyInScript=Xc;function Jc(e,t){return Qc(e).some(n=>Ca(n,sn.signature.decode,t))}ie.checkInputForSig=Jc;function Ca(e,t,r){const{hashType:n}=t(e),i=[];switch(n&An.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case An.Transaction.SIGHASH_ALL:break;case An.Transaction.SIGHASH_SINGLE:case An.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}ie.signatureBlocksAction=Ca;function Qc(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=Zc(e)}else t=e.partialSig;return t.map(r=>r.signature)}function Zc(e){const t=e.finalScriptSig?sn.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?sn.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&sn.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(me,"__esModule",{value:!0});me.checkTaprootInputForSigs=me.tapTreeFromList=me.tapTreeToList=me.tweakInternalPubKey=me.checkTaprootOutputFields=me.checkTaprootInputFields=me.isTaprootOutput=me.isTaprootInput=Ln=me.serializeTaprootSignature=me.tapScriptFinalizer=me.toXOnly=void 0;const ks=Ne,eh=dn,ai=ie,$t=Is,th=Os(),rh=ie,nh=e=>e.length===32?e:e.slice(1,33);me.toXOnly=nh;function ih(e,t,r){const n=vh(t,e,r);try{const s=_h(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,ai.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}me.tapScriptFinalizer=ih;function sh(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var Ln=me.serializeTaprootSignature=sh;function Nn(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,ai.isP2TR)(e.witnessUtxo.script))}me.isTaprootInput=Nn;function Fn(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,ai.isP2TR)(t))}me.isTaprootOutput=Fn;function oh(e,t,r){wh(e,t,r),mh(e,t,r)}me.checkTaprootInputFields=oh;function ah(e,t,r){gh(e,t,r),fh(e,t)}me.checkTaprootOutputFields=ah;function fh(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=uh(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function uh(e,t){const r=t&&La(t.leaves),{output:n}=(0,th.p2tr)({internalPubkey:e,scriptTree:r});return n}function ch(e,t){const r=t.tapInternalKey,n=r&&(0,$t.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}me.tweakInternalPubKey=ch;function hh(e){if(!(0,ks.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return Zi(e)}me.tapTreeToList=hh;function La(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:bh(e)}me.tapTreeFromList=La;function lh(e,t){return ph(e).some(n=>(0,rh.signatureBlocksAction)(n,dh,t))}me.checkTaprootInputForSigs=lh;function dh(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||eh.Transaction.SIGHASH_DEFAULT}}function ph(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=yh(e.finalScriptWitness);r&&t.push(r)}return t}function yh(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function Zi(e,t=[],r=0){if(r>$t.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,ks.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||$t.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&Zi(e[0],t,r+1),e[1]&&Zi(e[1],t,r+1),t):[]}function bh(e){let t;for(const r of e)if(t=es(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function es(e,t,r=0){if(r>$t.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,ks.isTapleaf)(t))return;const n=es(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=es(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function wh(e,t,r){const n=Nn(e)&&xr(t),i=xr(e)&&Nn(t),s=e===t&&Nn(t)&&xr(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function gh(e,t,r){const n=Fn(e)&&xr(t),i=xr(e)&&Fn(t),s=e===t&&Fn(t)&&xr(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function mh(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>Ci(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Ci(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=>Ci(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Ci(e,t){if(!t)return!0;const r=(0,$t.tapleafHash)({output:e.script,version:e.leafVersion});return(0,$t.rootHashFromPath)(e.controlBlock,r).equals(t)}function _h(e,t){const r=(0,$t.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>Eh(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function Eh(e,t){return Object.assign({positionInScript:(0,ai.pubkeyPositionInScript)(t.pubkey,e)},t)}function vh(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=>xh(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function xh(e,t,r){const n=(0,$t.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function xr(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const $e={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"},In=192;be.initEccLib(Jt);class on{constructor(t,r,n,i,s,o,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=s,this.expiry=o,this.signer=t,this.network=a,this.internalPubkey=cu(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,dr(n.length===64,$e.secretHashLenMismatch),dr(i.length===64||i.length===66,`initiator ${$e.pubkeyLenMismatch}`),dr(s.length===64||s.length===66,`redeemer ${$e.pubkeyLenMismatch}`),dr(o>0,$e.zeroOrNegativeExpiry);const c=await t.getNetwork();return new on(t,r,n,Xi(s).toString("hex"),Xi(i).toString("hex"),o,c,a)}address(){const{address:t}=be.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error($e.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new be.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const l=await s.getTransaction(c);for(let d=0;d<l.vout.length;d++){const g=l.vout[d];g.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:g.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,l)=>c+l.value,0);if(a===0)throw new Error(`${i} ${$e.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);return r??(r=await s.suggestFee(i,a,Br.Urgency.MEDIUM)),n.addOutput(be.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return be.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Br.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=be.Transaction.SIGHASH_SINGLE|be.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),l=s.map(g=>g.value),d=Gr(o,s.length);for(let g=0;g<i.ins.length;g++){const x=i.hashForWitnessV1(g,d,l,a,c),y=await this.signer.signSchnorr(x);i.setWitness(g,[Ln(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=be.Transaction.SIGHASH_SINGLE|be.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(d=>d.value),l=Gr(s,i.length);for(let d=0;d<n.ins.length;d++){const g=n.hashForWitnessV1(d,l,c,o,a),x=await this.signer.signSchnorr(g);n.setWitness(d,[Ln(x,o),Ln(x,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){dr(t.length>0,$e.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const g of i)if(!t.find(x=>x.utxo===g.txid))throw new Error($e.counterPartySigNotFound(g.txid));const s=this.getOutputScript(),o=be.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(g=>g.value),l=Gr(s,i.length);for(let g=0;g<n.ins.length;g++){const x=n.hashForWitnessV1(g,l,c,o,a);if(!Jt.verifySchnorr(x,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[g].sig,"hex")))throw new Error($e.invalidCounterpartySigForUTXO(t[g].utxo));const y=await this.signer.signSchnorr(x),O=Buffer.from(n.ins[g].hash).reverse().toString("hex"),B=t.find(A=>A.utxo===O);if(!B)throw new Error($e.counterPartySigNotFound(O));n.setWitness(g,[Buffer.from(B.sig,"hex"),y,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){dr(be.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,$e.secretMismatch);const{tx:i,usedUtxos:s}=await this._buildRawTx(r??await this.signer.getAddress(),n),o=this.leafHash(1),a=s.map(g=>g.value),c=Gr(this.getOutputScript(),s.length),l=be.Transaction.SIGHASH_DEFAULT;for(let g=0;g<i.ins.length;g++){const x=i.hashForWitnessV1(g,c,a,l,o),y=await this.signer.signSchnorr(x);i.setWitness(g,[y,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(i.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($e.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(x=>x.value),l=Gr(this.getOutputScript(),i.length),d=be.Transaction.SIGHASH_DEFAULT;for(let x=0;x<n.ins.length;x++){n.ins[x].sequence=this.expiry;const y=n.hashForWitnessV1(x,l,c,d,a),O=await this.signer.signSchnorr(y);n.setWitness(x,[O,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($e.invalidLeaf)}const n=be.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:In}});if(!n.witness)throw new Error($e.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()),be.crypto.taggedHash("TapLeaf",Jf(r))}refundLeaf(){return be.script.fromASM(`
|
|
10
|
-
${
|
|
6
|
+
*/(function(e){const t=ii,r=Bs,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=U,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),f={foo:function(){return 42}};return Object.setPrototypeOf(f,Uint8Array.prototype),Object.setPrototypeOf(h,f),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 f=new Uint8Array(h);return Object.setPrototypeOf(f,a.prototype),f}function a(h,f,u){if(typeof h=="number"){if(typeof f=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return g(h)}return c(h,f,u)}a.poolSize=8192;function c(h,f,u){if(typeof h=="string")return x(h,f);if(ArrayBuffer.isView(h))return O(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(qe(h,ArrayBuffer)||h&&qe(h.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qe(h,SharedArrayBuffer)||h&&qe(h.buffer,SharedArrayBuffer)))return B(h,f,u);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const p=h.valueOf&&h.valueOf();if(p!=null&&p!==h)return a.from(p,f,u);const v=A(h);if(v)return v;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return a.from(h[Symbol.toPrimitive]("string"),f,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,f,u){return c(h,f,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,f,u){return l(h),h<=0?o(h):f!==void 0?typeof u=="string"?o(h).fill(f,u):o(h).fill(f):o(h)}a.alloc=function(h,f,u){return d(h,f,u)};function g(h){return l(h),o(h<0?0:k(h)|0)}a.allocUnsafe=function(h){return g(h)},a.allocUnsafeSlow=function(h){return g(h)};function x(h,f){if((typeof f!="string"||f==="")&&(f="utf8"),!a.isEncoding(f))throw new TypeError("Unknown encoding: "+f);const u=_(h,f)|0;let p=o(u);const v=p.write(h,f);return v!==u&&(p=p.slice(0,v)),p}function y(h){const f=h.length<0?0:k(h.length)|0,u=o(f);for(let p=0;p<f;p+=1)u[p]=h[p]&255;return u}function O(h){if(qe(h,Uint8Array)){const f=new Uint8Array(h);return B(f.buffer,f.byteOffset,f.byteLength)}return y(h)}function B(h,f,u){if(f<0||h.byteLength<f)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<f+(u||0))throw new RangeError('"length" is outside of buffer bounds');let p;return f===void 0&&u===void 0?p=new Uint8Array(h):u===void 0?p=new Uint8Array(h,f):p=new Uint8Array(h,f,u),Object.setPrototypeOf(p,a.prototype),p}function A(h){if(a.isBuffer(h)){const f=k(h.length)|0,u=o(f);return u.length===0||h.copy(u,0,0,f),u}if(h.length!==void 0)return typeof h.length!="number"||zt(h.length)?o(0):y(h);if(h.type==="Buffer"&&Array.isArray(h.data))return y(h.data)}function k(h){if(h>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return h|0}function U(h){return+h!=h&&(h=0),a.alloc(+h)}a.isBuffer=function(f){return f!=null&&f._isBuffer===!0&&f!==a.prototype},a.compare=function(f,u){if(qe(f,Uint8Array)&&(f=a.from(f,f.offset,f.byteLength)),qe(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(f)||!a.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(f===u)return 0;let p=f.length,v=u.length;for(let I=0,L=Math.min(p,v);I<L;++I)if(f[I]!==u[I]){p=f[I],v=u[I];break}return p<v?-1:v<p?1:0},a.isEncoding=function(f){switch(String(f).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(f,u){if(!Array.isArray(f))throw new TypeError('"list" argument must be an Array of Buffers');if(f.length===0)return a.alloc(0);let p;if(u===void 0)for(u=0,p=0;p<f.length;++p)u+=f[p].length;const v=a.allocUnsafe(u);let I=0;for(p=0;p<f.length;++p){let L=f[p];if(qe(L,Uint8Array))I+L.length>v.length?(a.isBuffer(L)||(L=a.from(L)),L.copy(v,I)):Uint8Array.prototype.set.call(v,L,I);else if(a.isBuffer(L))L.copy(v,I);else throw new TypeError('"list" argument must be an Array of Buffers');I+=L.length}return v};function _(h,f){if(a.isBuffer(h))return h.length;if(ArrayBuffer.isView(h)||qe(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,p=arguments.length>2&&arguments[2]===!0;if(!p&&u===0)return 0;let v=!1;for(;;)switch(f){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return te(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return Hr(h).length;default:if(v)return p?-1:te(h).length;f=(""+f).toLowerCase(),v=!0}}a.byteLength=_;function m(h,f,u){let p=!1;if((f===void 0||f<0)&&(f=0),f>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,f>>>=0,u<=f))return"";for(h||(h="utf8");;)switch(h){case"hex":return Ve(this,f,u);case"utf8":case"utf-8":return W(this,f,u);case"ascii":return ue(this,f,u);case"latin1":case"binary":return et(this,f,u);case"base64":return M(this,f,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return it(this,f,u);default:if(p)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),p=!0}}a.prototype._isBuffer=!0;function S(h,f,u){const p=h[f];h[f]=h[u],h[u]=p}a.prototype.swap16=function(){const f=this.length;if(f%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<f;u+=2)S(this,u,u+1);return this},a.prototype.swap32=function(){const f=this.length;if(f%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<f;u+=4)S(this,u,u+3),S(this,u+1,u+2);return this},a.prototype.swap64=function(){const f=this.length;if(f%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<f;u+=8)S(this,u,u+7),S(this,u+1,u+6),S(this,u+2,u+5),S(this,u+3,u+4);return this},a.prototype.toString=function(){const f=this.length;return f===0?"":arguments.length===0?W(this,0,f):m.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(f){if(!a.isBuffer(f))throw new TypeError("Argument must be a Buffer");return this===f?!0:a.compare(this,f)===0},a.prototype.inspect=function(){let f="";const u=e.INSPECT_MAX_BYTES;return f=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(f+=" ... "),"<Buffer "+f+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(f,u,p,v,I){if(qe(f,Uint8Array)&&(f=a.from(f,f.offset,f.byteLength)),!a.isBuffer(f))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof f);if(u===void 0&&(u=0),p===void 0&&(p=f?f.length:0),v===void 0&&(v=0),I===void 0&&(I=this.length),u<0||p>f.length||v<0||I>this.length)throw new RangeError("out of range index");if(v>=I&&u>=p)return 0;if(v>=I)return-1;if(u>=p)return 1;if(u>>>=0,p>>>=0,v>>>=0,I>>>=0,this===f)return 0;let L=I-v,Q=p-u;const ve=Math.min(L,Q),ge=this.slice(v,I),Ee=f.slice(u,p);for(let ie=0;ie<ve;++ie)if(ge[ie]!==Ee[ie]){L=ge[ie],Q=Ee[ie];break}return L<Q?-1:Q<L?1:0};function E(h,f,u,p,v){if(h.length===0)return-1;if(typeof u=="string"?(p=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,zt(u)&&(u=v?0:h.length-1),u<0&&(u=h.length+u),u>=h.length){if(v)return-1;u=h.length-1}else if(u<0)if(v)u=0;else return-1;if(typeof f=="string"&&(f=a.from(f,p)),a.isBuffer(f))return f.length===0?-1:H(h,f,u,p,v);if(typeof f=="number")return f=f&255,typeof Uint8Array.prototype.indexOf=="function"?v?Uint8Array.prototype.indexOf.call(h,f,u):Uint8Array.prototype.lastIndexOf.call(h,f,u):H(h,[f],u,p,v);throw new TypeError("val must be string, number or Buffer")}function H(h,f,u,p,v){let I=1,L=h.length,Q=f.length;if(p!==void 0&&(p=String(p).toLowerCase(),p==="ucs2"||p==="ucs-2"||p==="utf16le"||p==="utf-16le")){if(h.length<2||f.length<2)return-1;I=2,L/=2,Q/=2,u/=2}function ve(Ee,ie){return I===1?Ee[ie]:Ee.readUInt16BE(ie*I)}let ge;if(v){let Ee=-1;for(ge=u;ge<L;ge++)if(ve(h,ge)===ve(f,Ee===-1?0:ge-Ee)){if(Ee===-1&&(Ee=ge),ge-Ee+1===Q)return Ee*I}else Ee!==-1&&(ge-=ge-Ee),Ee=-1}else for(u+Q>L&&(u=L-Q),ge=u;ge>=0;ge--){let Ee=!0;for(let ie=0;ie<Q;ie++)if(ve(h,ge+ie)!==ve(f,ie)){Ee=!1;break}if(Ee)return ge}return-1}a.prototype.includes=function(f,u,p){return this.indexOf(f,u,p)!==-1},a.prototype.indexOf=function(f,u,p){return E(this,f,u,p,!0)},a.prototype.lastIndexOf=function(f,u,p){return E(this,f,u,p,!1)};function D(h,f,u,p){u=Number(u)||0;const v=h.length-u;p?(p=Number(p),p>v&&(p=v)):p=v;const I=f.length;p>I/2&&(p=I/2);let L;for(L=0;L<p;++L){const Q=parseInt(f.substr(L*2,2),16);if(zt(Q))return L;h[u+L]=Q}return L}function R(h,f,u,p){return pr(te(f,h.length-u),h,u,p)}function z(h,f,u,p){return pr(It(f),h,u,p)}function Z(h,f,u,p){return pr(Hr(f),h,u,p)}function C(h,f,u,p){return pr(dr(f,h.length-u),h,u,p)}a.prototype.write=function(f,u,p,v){if(u===void 0)v="utf8",p=this.length,u=0;else if(p===void 0&&typeof u=="string")v=u,p=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(p)?(p=p>>>0,v===void 0&&(v="utf8")):(v=p,p=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const I=this.length-u;if((p===void 0||p>I)&&(p=I),f.length>0&&(p<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");v||(v="utf8");let L=!1;for(;;)switch(v){case"hex":return D(this,f,u,p);case"utf8":case"utf-8":return R(this,f,u,p);case"ascii":case"latin1":case"binary":return z(this,f,u,p);case"base64":return Z(this,f,u,p);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,f,u,p);default:if(L)throw new TypeError("Unknown encoding: "+v);v=(""+v).toLowerCase(),L=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function M(h,f,u){return f===0&&u===h.length?t.fromByteArray(h):t.fromByteArray(h.slice(f,u))}function W(h,f,u){u=Math.min(h.length,u);const p=[];let v=f;for(;v<u;){const I=h[v];let L=null,Q=I>239?4:I>223?3:I>191?2:1;if(v+Q<=u){let ve,ge,Ee,ie;switch(Q){case 1:I<128&&(L=I);break;case 2:ve=h[v+1],(ve&192)===128&&(ie=(I&31)<<6|ve&63,ie>127&&(L=ie));break;case 3:ve=h[v+1],ge=h[v+2],(ve&192)===128&&(ge&192)===128&&(ie=(I&15)<<12|(ve&63)<<6|ge&63,ie>2047&&(ie<55296||ie>57343)&&(L=ie));break;case 4:ve=h[v+1],ge=h[v+2],Ee=h[v+3],(ve&192)===128&&(ge&192)===128&&(Ee&192)===128&&(ie=(I&15)<<18|(ve&63)<<12|(ge&63)<<6|Ee&63,ie>65535&&ie<1114112&&(L=ie))}}L===null?(L=65533,Q=1):L>65535&&(L-=65536,p.push(L>>>10&1023|55296),L=56320|L&1023),p.push(L),v+=Q}return fe(p)}const q=4096;function fe(h){const f=h.length;if(f<=q)return String.fromCharCode.apply(String,h);let u="",p=0;for(;p<f;)u+=String.fromCharCode.apply(String,h.slice(p,p+=q));return u}function ue(h,f,u){let p="";u=Math.min(h.length,u);for(let v=f;v<u;++v)p+=String.fromCharCode(h[v]&127);return p}function et(h,f,u){let p="";u=Math.min(h.length,u);for(let v=f;v<u;++v)p+=String.fromCharCode(h[v]);return p}function Ve(h,f,u){const p=h.length;(!f||f<0)&&(f=0),(!u||u<0||u>p)&&(u=p);let v="";for(let I=f;I<u;++I)v+=$r[h[I]];return v}function it(h,f,u){const p=h.slice(f,u);let v="";for(let I=0;I<p.length-1;I+=2)v+=String.fromCharCode(p[I]+p[I+1]*256);return v}a.prototype.slice=function(f,u){const p=this.length;f=~~f,u=u===void 0?p:~~u,f<0?(f+=p,f<0&&(f=0)):f>p&&(f=p),u<0?(u+=p,u<0&&(u=0)):u>p&&(u=p),u<f&&(u=f);const v=this.subarray(f,u);return Object.setPrototypeOf(v,a.prototype),v};function be(h,f,u){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+f>u)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(f,u,p){f=f>>>0,u=u>>>0,p||be(f,u,this.length);let v=this[f],I=1,L=0;for(;++L<u&&(I*=256);)v+=this[f+L]*I;return v},a.prototype.readUintBE=a.prototype.readUIntBE=function(f,u,p){f=f>>>0,u=u>>>0,p||be(f,u,this.length);let v=this[f+--u],I=1;for(;u>0&&(I*=256);)v+=this[f+--u]*I;return v},a.prototype.readUint8=a.prototype.readUInt8=function(f,u){return f=f>>>0,u||be(f,1,this.length),this[f]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(f,u){return f=f>>>0,u||be(f,2,this.length),this[f]|this[f+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(f,u){return f=f>>>0,u||be(f,2,this.length),this[f]<<8|this[f+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(f,u){return f=f>>>0,u||be(f,4,this.length),(this[f]|this[f+1]<<8|this[f+2]<<16)+this[f+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(f,u){return f=f>>>0,u||be(f,4,this.length),this[f]*16777216+(this[f+1]<<16|this[f+2]<<8|this[f+3])},a.prototype.readBigUInt64LE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&$(f,this.length-8);const v=u+this[++f]*2**8+this[++f]*2**16+this[++f]*2**24,I=this[++f]+this[++f]*2**8+this[++f]*2**16+p*2**24;return BigInt(v)+(BigInt(I)<<BigInt(32))}),a.prototype.readBigUInt64BE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&$(f,this.length-8);const v=u*2**24+this[++f]*2**16+this[++f]*2**8+this[++f],I=this[++f]*2**24+this[++f]*2**16+this[++f]*2**8+p;return(BigInt(v)<<BigInt(32))+BigInt(I)}),a.prototype.readIntLE=function(f,u,p){f=f>>>0,u=u>>>0,p||be(f,u,this.length);let v=this[f],I=1,L=0;for(;++L<u&&(I*=256);)v+=this[f+L]*I;return I*=128,v>=I&&(v-=Math.pow(2,8*u)),v},a.prototype.readIntBE=function(f,u,p){f=f>>>0,u=u>>>0,p||be(f,u,this.length);let v=u,I=1,L=this[f+--v];for(;v>0&&(I*=256);)L+=this[f+--v]*I;return I*=128,L>=I&&(L-=Math.pow(2,8*u)),L},a.prototype.readInt8=function(f,u){return f=f>>>0,u||be(f,1,this.length),this[f]&128?(255-this[f]+1)*-1:this[f]},a.prototype.readInt16LE=function(f,u){f=f>>>0,u||be(f,2,this.length);const p=this[f]|this[f+1]<<8;return p&32768?p|4294901760:p},a.prototype.readInt16BE=function(f,u){f=f>>>0,u||be(f,2,this.length);const p=this[f+1]|this[f]<<8;return p&32768?p|4294901760:p},a.prototype.readInt32LE=function(f,u){return f=f>>>0,u||be(f,4,this.length),this[f]|this[f+1]<<8|this[f+2]<<16|this[f+3]<<24},a.prototype.readInt32BE=function(f,u){return f=f>>>0,u||be(f,4,this.length),this[f]<<24|this[f+1]<<16|this[f+2]<<8|this[f+3]},a.prototype.readBigInt64LE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&$(f,this.length-8);const v=this[f+4]+this[f+5]*2**8+this[f+6]*2**16+(p<<24);return(BigInt(v)<<BigInt(32))+BigInt(u+this[++f]*2**8+this[++f]*2**16+this[++f]*2**24)}),a.prototype.readBigInt64BE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],p=this[f+7];(u===void 0||p===void 0)&&$(f,this.length-8);const v=(u<<24)+this[++f]*2**16+this[++f]*2**8+this[++f];return(BigInt(v)<<BigInt(32))+BigInt(this[++f]*2**24+this[++f]*2**16+this[++f]*2**8+p)}),a.prototype.readFloatLE=function(f,u){return f=f>>>0,u||be(f,4,this.length),r.read(this,f,!0,23,4)},a.prototype.readFloatBE=function(f,u){return f=f>>>0,u||be(f,4,this.length),r.read(this,f,!1,23,4)},a.prototype.readDoubleLE=function(f,u){return f=f>>>0,u||be(f,8,this.length),r.read(this,f,!0,52,8)},a.prototype.readDoubleBE=function(f,u){return f=f>>>0,u||be(f,8,this.length),r.read(this,f,!1,52,8)};function xe(h,f,u,p,v,I){if(!a.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(f>v||f<I)throw new RangeError('"value" argument is out of bounds');if(u+p>h.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(f,u,p,v){if(f=+f,u=u>>>0,p=p>>>0,!v){const Q=Math.pow(2,8*p)-1;xe(this,f,u,p,Q,0)}let I=1,L=0;for(this[u]=f&255;++L<p&&(I*=256);)this[u+L]=f/I&255;return u+p},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(f,u,p,v){if(f=+f,u=u>>>0,p=p>>>0,!v){const Q=Math.pow(2,8*p)-1;xe(this,f,u,p,Q,0)}let I=p-1,L=1;for(this[u+I]=f&255;--I>=0&&(L*=256);)this[u+I]=f/L&255;return u+p},a.prototype.writeUint8=a.prototype.writeUInt8=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,1,255,0),this[u]=f&255,u+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,2,65535,0),this[u]=f&255,this[u+1]=f>>>8,u+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,2,65535,0),this[u]=f>>>8,this[u+1]=f&255,u+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,4,4294967295,0),this[u+3]=f>>>24,this[u+2]=f>>>16,this[u+1]=f>>>8,this[u]=f&255,u+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,4,4294967295,0),this[u]=f>>>24,this[u+1]=f>>>16,this[u+2]=f>>>8,this[u+3]=f&255,u+4};function ze(h,f,u,p,v){w(f,p,v,h,u,7);let I=Number(f&BigInt(4294967295));h[u++]=I,I=I>>8,h[u++]=I,I=I>>8,h[u++]=I,I=I>>8,h[u++]=I;let L=Number(f>>BigInt(32)&BigInt(4294967295));return h[u++]=L,L=L>>8,h[u++]=L,L=L>>8,h[u++]=L,L=L>>8,h[u++]=L,u}function At(h,f,u,p,v){w(f,p,v,h,u,7);let I=Number(f&BigInt(4294967295));h[u+7]=I,I=I>>8,h[u+6]=I,I=I>>8,h[u+5]=I,I=I>>8,h[u+4]=I;let L=Number(f>>BigInt(32)&BigInt(4294967295));return h[u+3]=L,L=L>>8,h[u+2]=L,L=L>>8,h[u+1]=L,L=L>>8,h[u]=L,u+8}a.prototype.writeBigUInt64LE=Xe(function(f,u=0){return ze(this,f,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Xe(function(f,u=0){return At(this,f,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(f,u,p,v){if(f=+f,u=u>>>0,!v){const ve=Math.pow(2,8*p-1);xe(this,f,u,p,ve-1,-ve)}let I=0,L=1,Q=0;for(this[u]=f&255;++I<p&&(L*=256);)f<0&&Q===0&&this[u+I-1]!==0&&(Q=1),this[u+I]=(f/L>>0)-Q&255;return u+p},a.prototype.writeIntBE=function(f,u,p,v){if(f=+f,u=u>>>0,!v){const ve=Math.pow(2,8*p-1);xe(this,f,u,p,ve-1,-ve)}let I=p-1,L=1,Q=0;for(this[u+I]=f&255;--I>=0&&(L*=256);)f<0&&Q===0&&this[u+I+1]!==0&&(Q=1),this[u+I]=(f/L>>0)-Q&255;return u+p},a.prototype.writeInt8=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,1,127,-128),f<0&&(f=255+f+1),this[u]=f&255,u+1},a.prototype.writeInt16LE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,2,32767,-32768),this[u]=f&255,this[u+1]=f>>>8,u+2},a.prototype.writeInt16BE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,2,32767,-32768),this[u]=f>>>8,this[u+1]=f&255,u+2},a.prototype.writeInt32LE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,4,2147483647,-2147483648),this[u]=f&255,this[u+1]=f>>>8,this[u+2]=f>>>16,this[u+3]=f>>>24,u+4},a.prototype.writeInt32BE=function(f,u,p){return f=+f,u=u>>>0,p||xe(this,f,u,4,2147483647,-2147483648),f<0&&(f=4294967295+f+1),this[u]=f>>>24,this[u+1]=f>>>16,this[u+2]=f>>>8,this[u+3]=f&255,u+4},a.prototype.writeBigInt64LE=Xe(function(f,u=0){return ze(this,f,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Xe(function(f,u=0){return At(this,f,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function pt(h,f,u,p,v,I){if(u+p>h.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function T(h,f,u,p,v){return f=+f,u=u>>>0,v||pt(h,f,u,4),r.write(h,f,u,p,23,4),u+4}a.prototype.writeFloatLE=function(f,u,p){return T(this,f,u,!0,p)},a.prototype.writeFloatBE=function(f,u,p){return T(this,f,u,!1,p)};function P(h,f,u,p,v){return f=+f,u=u>>>0,v||pt(h,f,u,8),r.write(h,f,u,p,52,8),u+8}a.prototype.writeDoubleLE=function(f,u,p){return P(this,f,u,!0,p)},a.prototype.writeDoubleBE=function(f,u,p){return P(this,f,u,!1,p)},a.prototype.copy=function(f,u,p,v){if(!a.isBuffer(f))throw new TypeError("argument should be a Buffer");if(p||(p=0),!v&&v!==0&&(v=this.length),u>=f.length&&(u=f.length),u||(u=0),v>0&&v<p&&(v=p),v===p||f.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(p<0||p>=this.length)throw new RangeError("Index out of range");if(v<0)throw new RangeError("sourceEnd out of bounds");v>this.length&&(v=this.length),f.length-u<v-p&&(v=f.length-u+p);const I=v-p;return this===f&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(u,p,v):Uint8Array.prototype.set.call(f,this.subarray(p,v),u),I},a.prototype.fill=function(f,u,p,v){if(typeof f=="string"){if(typeof u=="string"?(v=u,u=0,p=this.length):typeof p=="string"&&(v=p,p=this.length),v!==void 0&&typeof v!="string")throw new TypeError("encoding must be a string");if(typeof v=="string"&&!a.isEncoding(v))throw new TypeError("Unknown encoding: "+v);if(f.length===1){const L=f.charCodeAt(0);(v==="utf8"&&L<128||v==="latin1")&&(f=L)}}else typeof f=="number"?f=f&255:typeof f=="boolean"&&(f=Number(f));if(u<0||this.length<u||this.length<p)throw new RangeError("Out of range index");if(p<=u)return this;u=u>>>0,p=p===void 0?this.length:p>>>0,f||(f=0);let I;if(typeof f=="number")for(I=u;I<p;++I)this[I]=f;else{const L=a.isBuffer(f)?f:a.from(f,v),Q=L.length;if(Q===0)throw new TypeError('The value "'+f+'" is invalid for argument "value"');for(I=0;I<p-u;++I)this[I+u]=L[I%Q]}return this};const F={};function G(h,f,u){F[h]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:f.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(v){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:v,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}G("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(h,f){return`The "${h}" argument must be of type number. Received type ${typeof f}`},TypeError),G("ERR_OUT_OF_RANGE",function(h,f,u){let p=`The value of "${h}" is out of range.`,v=u;return Number.isInteger(u)&&Math.abs(u)>2**32?v=K(String(u)):typeof u=="bigint"&&(v=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(v=K(v)),v+="n"),p+=` It must be ${f}. Received ${v}`,p},RangeError);function K(h){let f="",u=h.length;const p=h[0]==="-"?1:0;for(;u>=p+4;u-=3)f=`_${h.slice(u-3,u)}${f}`;return`${h.slice(0,u)}${f}`}function b(h,f,u){N(f,"offset"),(h[f]===void 0||h[f+u]===void 0)&&$(f,h.length-(u+1))}function w(h,f,u,p,v,I){if(h>u||h<f){const L=typeof f=="bigint"?"n":"";let Q;throw f===0||f===BigInt(0)?Q=`>= 0${L} and < 2${L} ** ${(I+1)*8}${L}`:Q=`>= -(2${L} ** ${(I+1)*8-1}${L}) and < 2 ** ${(I+1)*8-1}${L}`,new F.ERR_OUT_OF_RANGE("value",Q,h)}b(p,v,I)}function N(h,f){if(typeof h!="number")throw new F.ERR_INVALID_ARG_TYPE(f,"number",h)}function $(h,f,u){throw Math.floor(h)!==h?(N(h,u),new F.ERR_OUT_OF_RANGE("offset","an integer",h)):f<0?new F.ERR_BUFFER_OUT_OF_BOUNDS:new F.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${f}`,h)}const we=/[^+/0-9A-Za-z-_]/g;function Y(h){if(h=h.split("=")[0],h=h.trim().replace(we,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function te(h,f){f=f||1/0;let u;const p=h.length;let v=null;const I=[];for(let L=0;L<p;++L){if(u=h.charCodeAt(L),u>55295&&u<57344){if(!v){if(u>56319){(f-=3)>-1&&I.push(239,191,189);continue}else if(L+1===p){(f-=3)>-1&&I.push(239,191,189);continue}v=u;continue}if(u<56320){(f-=3)>-1&&I.push(239,191,189),v=u;continue}u=(v-55296<<10|u-56320)+65536}else v&&(f-=3)>-1&&I.push(239,191,189);if(v=null,u<128){if((f-=1)<0)break;I.push(u)}else if(u<2048){if((f-=2)<0)break;I.push(u>>6|192,u&63|128)}else if(u<65536){if((f-=3)<0)break;I.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((f-=4)<0)break;I.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return I}function It(h){const f=[];for(let u=0;u<h.length;++u)f.push(h.charCodeAt(u)&255);return f}function dr(h,f){let u,p,v;const I=[];for(let L=0;L<h.length&&!((f-=2)<0);++L)u=h.charCodeAt(L),p=u>>8,v=u%256,I.push(v),I.push(p);return I}function Hr(h){return t.toByteArray(Y(h))}function pr(h,f,u,p){let v;for(v=0;v<p&&!(v+u>=f.length||v>=h.length);++v)f[v+u]=h[v];return v}function qe(h,f){return h instanceof f||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===f.name}function zt(h){return h!==h}const $r=function(){const h="0123456789abcdef",f=new Array(256);for(let u=0;u<16;++u){const p=u*16;for(let v=0;v<16;++v)f[p+v]=h[u]+h[v]}return f}();function Xe(h){return typeof BigInt>"u"?qt:h}function qt(){throw new Error("BigInt not supported")}})(Tt);var hn={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}};hn.Null=hn.Nil;for(var ro in hn)hn[ro].toJSON=(function(e){return e}).bind(null,ro);var Ps=hn,Qt=Ps;function ga(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function Ts(e){return Qt.Nil(e)?"":ga(e.constructor)}function Nu(e){return Qt.Function(e)?"":Qt.String(e)?JSON.stringify(e):e&&Qt.Object(e)?"":e}function As(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function qn(e){return Qt.Function(e)?e.toJSON?e.toJSON():ga(e):Qt.Array(e)?"Array":e&&Qt.Object(e)?"Object":e!==void 0?e:""}function ma(e,t,r){var n=Nu(t);return"Expected "+qn(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function St(e,t,r){r=r||Ts(t),this.message=ma(e,t,r),As(this,St),this.__type=e,this.__value=t,this.__valueTypeName=r}St.prototype=Object.create(Error.prototype);St.prototype.constructor=St;function Fu(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),ma('property "'+qn(r)+s+qn(e),n,i)}function Sr(e,t,r,n,i){e?(i=i||Ts(n),this.message=Fu(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',As(this,St),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Sr.prototype=Object.create(Error.prototype);Sr.prototype.constructor=St;function Mu(e,t){return new St(e,{},t)}function Hu(e,t,r){return e instanceof Sr?(t=t+"."+e.__property,e=new Sr(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof St&&(e=new Sr(e.__type,t,r,e.__value,e.__valueTypeName)),As(e),e}var _a={TfTypeError:St,TfPropertyTypeError:Sr,tfCustomError:Mu,tfSubError:Hu,tfJSON:qn,getValueTypeName:Ts},Ui,no;function $u(){if(no)return Ui;no=1;var e=Ps,t=_a;function r(E){return Buffer.isBuffer(E)}function n(E){return typeof E=="string"&&/^([0-9a-f]{2})+$/i.test(E)}function i(E,H){var D=E.toJSON();function R(z){if(!E(z))return!1;if(z.length===H)return!0;throw t.tfCustomError(D+"(Length: "+H+")",D+"(Length: "+z.length+")")}return R.toJSON=function(){return D},R}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function l(E,H,D){D=D||e.Number;function R(z,Z){return D(z,Z)&&z>E&&z<H}return R.toJSON=function(){return`${D.toJSON()} between [${E}, ${H}]`},R}var d=Math.pow(2,53)-1;function g(E){return typeof E=="number"&&isFinite(E)}function x(E){return E<<24>>24===E}function y(E){return E<<16>>16===E}function O(E){return(E|0)===E}function B(E){return typeof E=="number"&&E>=-d&&E<=d&&Math.floor(E)===E}function A(E){return(E&255)===E}function k(E){return(E&65535)===E}function U(E){return E>>>0===E}function _(E){return typeof E=="number"&&E>=0&&E<=d&&Math.floor(E)===E}var m={ArrayN:s,Buffer:r,BufferN:o,Finite:g,Hex:n,HexN:a,Int8:x,Int16:y,Int32:O,Int53:B,Range:l,StringN:c,UInt8:A,UInt16:k,UInt32:U,UInt53:_};for(var S in m)m[S].toJSON=(function(E){return E}).bind(null,S);return Ui=m,Ui}var yn=_a,Ie=Ps,yt=yn.tfJSON,va=yn.TfTypeError,Ea=yn.TfPropertyTypeError,Dr=yn.tfSubError,Du=yn.getValueTypeName,vt={arrayOf:function(t,r){t=ht(t),r=r||{};function n(i,s){return!Ie.Array(i)||Ie.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 Ge(t,o,s)}catch(c){throw Dr(c,a)}})}return n.toJSON=function(){var i="["+yt(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=ht(t);function r(n,i){return Ie.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+yt(t)},r},map:function(t,r){t=ht(t),r&&(r=ht(r));function n(i,s){if(!Ie.Object(i)||Ie.Nil(i))return!1;for(var o in i){try{r&&Ge(r,o,s)}catch(c){throw Dr(c,o,"key")}try{var a=i[o];Ge(t,a,s)}catch(c){throw Dr(c,o)}}return!0}return r?n.toJSON=function(){return"{"+yt(r)+": "+yt(t)+"}"}:n.toJSON=function(){return"{"+yt(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=ht(t[n]);function i(s,o){if(!Ie.Object(s)||Ie.Nil(s))return!1;var a;try{for(a in r){var c=r[a],l=s[a];Ge(c,l,o)}}catch(d){throw Dr(d,a)}if(o){for(a in s)if(!r[a])throw new Ea(void 0,a)}return!0}return i.toJSON=function(){return yt(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(ht);function r(n,i){return t.some(function(s){try{return Ge(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(yt).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(ht);function r(n,i){return t.every(function(s){try{return Ge(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(yt).join(" & ")},r},quacksLike:function(t){function r(n){return t===Du(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(ht);function r(n,i){return Ie.Nil(n)||Ie.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return Ge(s,n[o],i)}catch(a){throw Dr(a,o)}})}return r.toJSON=function(){return"("+t.map(yt).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};vt.oneOf=vt.anyOf;function ht(e){if(Ie.String(e))return e[0]==="?"?vt.maybe(e.slice(1)):Ie[e]||vt.quacksLike(e);if(e&&Ie.Object(e)){if(Ie.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return vt.arrayOf(e[0])}return vt.object(e)}else if(Ie.Function(e))return e;return vt.value(e)}function Ge(e,t,r,n){if(Ie.Function(e)){if(e(t,r))return!0;throw new va(n||e,t)}return Ge(ht(e),t,r)}for(var Mt in Ie)Ge[Mt]=Ie[Mt];for(Mt in vt)Ge[Mt]=vt[Mt];var io=$u();for(Mt in io)Ge[Mt]=io[Mt];Ge.compile=ht;Ge.TfTypeError=va;Ge.TfPropertyTypeError=Ea;var xa=Ge;(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=Tt;e.typeforce=xa;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(d,g){return d.length!==g.length?!1:d.every((x,y)=>x.equals(g[y]))}e.stacksEqual=i;function s(d){if(!t.Buffer.isBuffer(d)||d.length<33)return!1;const g=d[0],x=d.slice(1,33);if(x.compare(r)===0||x.compare(n)>=0)return!1;if((g===2||g===3)&&d.length===33)return!0;const y=d.slice(33);return y.compare(r)===0||y.compare(n)>=0?!1:g===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 c(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=c;function l(d){return(0,e.Array)(d)?d.length!==2?!1:d.every(g=>l(g)):c(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})(Fe);var bn={},Oe={};Object.defineProperty(Oe,"__esModule",{value:!0});Oe.BufferReader=Oe.BufferWriter=Oe.cloneBuffer=Oe.reverseBuffer=Oe.writeUInt64LE=Oe.readUInt64LE=Oe.varuint=void 0;const Zt=Fe,{typeforce:Sa}=Zt,ln=ca;Oe.varuint=ln;function Ba(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 Pa(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Ba(n+r,9007199254740991),n+r}Oe.readUInt64LE=Pa;function Ta(e,t,r){return Ba(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Oe.writeUInt64LE=Ta;function ju(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}Oe.reverseBuffer=ju;function Gu(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Oe.cloneBuffer=Gu;class Is{static withCapacity(t){return new Is(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Sa(Zt.tuple(Zt.Buffer,Zt.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=Ta(this.buffer,t,this.offset)}writeVarInt(t){ln.encode(t,this.buffer,this.offset),this.offset+=ln.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}`)}}Oe.BufferWriter=Is;class Wu{constructor(t,r=0){this.buffer=t,this.offset=r,Sa(Zt.tuple(Zt.Buffer,Zt.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=Pa(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=ln.decode(this.buffer,this.offset);return this.offset+=ln.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}}Oe.BufferReader=Wu;var jt={},Ir={},Et={},rt={};Object.defineProperty(rt,"__esModule",{value:!0});rt.isBytes=Ia;rt.number=Kn;rt.bool=Aa;rt.bytes=Os;rt.hash=Oa;rt.exists=ka;rt.output=Ra;function Kn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Aa(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function Ia(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Os(e,...t){if(!Ia(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 Oa(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Kn(e.outputLen),Kn(e.blockLen)}function ka(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 Ra(e,t){Os(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const Vu={number:Kn,bool:Aa,bytes:Os,hash:Oa,exists:ka,output:Ra};rt.default=Vu;var si={},oi={};Object.defineProperty(oi,"__esModule",{value:!0});oi.crypto=void 0;oi.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=x,e.hexToBytes=B,e.asyncLoop=k,e.utf8ToBytes=U,e.toBytes=_,e.concatBytes=m,e.checkOpts=H,e.wrapConstructor=D,e.wrapConstructorWithOpts=R,e.wrapXOFConstructorWithOpts=z,e.randomBytes=Z;const t=oi,r=rt;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,M)=>C<<32-M|C>>>M;e.rotr=a;const c=(C,M)=>C<<M|C>>>32-M>>>0;e.rotl=c,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 M=0;M<C.length;M++)C[M]=(0,e.byteSwap)(C[M])}const g=Array.from({length:256},(C,M)=>M.toString(16).padStart(2,"0"));function x(C){(0,r.bytes)(C);let M="";for(let W=0;W<C.length;W++)M+=g[C[W]];return M}const y={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function O(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 B(C){if(typeof C!="string")throw new Error("hex string expected, got "+typeof C);const M=C.length,W=M/2;if(M%2)throw new Error("padded hex string expected, got unpadded hex of length "+M);const q=new Uint8Array(W);for(let fe=0,ue=0;fe<W;fe++,ue+=2){const et=O(C.charCodeAt(ue)),Ve=O(C.charCodeAt(ue+1));if(et===void 0||Ve===void 0){const it=C[ue]+C[ue+1];throw new Error('hex string expected, got non-hex character "'+it+'" at index '+ue)}q[fe]=et*16+Ve}return q}const A=async()=>{};e.nextTick=A;async function k(C,M,W){let q=Date.now();for(let fe=0;fe<C;fe++){W(fe);const ue=Date.now()-q;ue>=0&&ue<M||(await(0,e.nextTick)(),q+=ue)}}function U(C){if(typeof C!="string")throw new Error(`utf8ToBytes expected string, got ${typeof C}`);return new Uint8Array(new TextEncoder().encode(C))}function _(C){return typeof C=="string"&&(C=U(C)),(0,r.bytes)(C),C}function m(...C){let M=0;for(let q=0;q<C.length;q++){const fe=C[q];(0,r.bytes)(fe),M+=fe.length}const W=new Uint8Array(M);for(let q=0,fe=0;q<C.length;q++){const ue=C[q];W.set(ue,fe),fe+=ue.length}return W}class S{clone(){return this._cloneInto()}}e.Hash=S;const E={}.toString;function H(C,M){if(M!==void 0&&E.call(M)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(C,M)}function D(C){const M=q=>C().update(_(q)).digest(),W=C();return M.outputLen=W.outputLen,M.blockLen=W.blockLen,M.create=()=>C(),M}function R(C){const M=(q,fe)=>C(fe).update(_(q)).digest(),W=C({});return M.outputLen=W.outputLen,M.blockLen=W.blockLen,M.create=q=>C(q),M}function z(C){const M=(q,fe)=>C(fe).update(_(q)).digest(),W=C({});return M.outputLen=W.outputLen,M.blockLen=W.blockLen,M.create=q=>C(q),M}function Z(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")}})(si);Object.defineProperty(Et,"__esModule",{value:!0});Et.HashMD=Et.Maj=Et.Chi=void 0;const Ci=rt,jr=si;function zu(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),c=n?4:0,l=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+l,a,n)}const qu=(e,t,r)=>e&t^~e&r;Et.Chi=qu;const Ku=(e,t,r)=>e&t^e&r^t&r;Et.Maj=Ku;let Yu=class extends jr.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,jr.createView)(this.buffer)}update(t){(0,Ci.exists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,jr.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 c=(0,jr.createView)(t);for(;i<=s-o;o+=i)this.process(c,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,Ci.exists)(this),(0,Ci.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 g=o;g<i;g++)r[g]=0;zu(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,jr.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<l;g++)a.setUint32(4*g,d[g],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}};Et.HashMD=Yu;Object.defineProperty(Ir,"__esModule",{value:!0});Ir.ripemd160=Ir.RIPEMD160=void 0;const Xu=Et,nn=si,Ju=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ua=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Qu=Ua.map(e=>(9*e+5)%16);let ks=[Ua],Rs=[Qu];for(let e=0;e<4;e++)for(let t of[ks,Rs])t.push(t[e].map(r=>Ju[r]));const Ca=[[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)),Zu=ks.map((e,t)=>e.map(r=>Ca[t][r])),ec=Rs.map((e,t)=>e.map(r=>Ca[t][r])),tc=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),rc=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function so(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 Tn=new Uint32Array(16);let La=class extends Xu.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)Tn[y]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,l=this.h3|0,d=l,g=this.h4|0,x=g;for(let y=0;y<5;y++){const O=4-y,B=tc[y],A=rc[y],k=ks[y],U=Rs[y],_=Zu[y],m=ec[y];for(let S=0;S<16;S++){const E=(0,nn.rotl)(n+so(y,s,a,l)+Tn[k[S]]+B,_[S])+g|0;n=g,g=l,l=(0,nn.rotl)(a,10)|0,a=s,s=E}for(let S=0;S<16;S++){const E=(0,nn.rotl)(i+so(O,o,c,d)+Tn[U[S]]+A,m[S])+x|0;i=x,x=d,d=(0,nn.rotl)(c,10)|0,c=o,o=E}}this.set(this.h1+a+d|0,this.h2+l+x|0,this.h3+g+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){Tn.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};Ir.RIPEMD160=La;Ir.ripemd160=(0,nn.wrapConstructor)(()=>new La);var Or={};Object.defineProperty(Or,"__esModule",{value:!0});Or.sha1=Or.SHA1=void 0;const Li=Et,Hn=si,Gr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Ot=new Uint32Array(80);class Na extends Li.HashMD{constructor(){super(64,20,8,!1),this.A=Gr[0]|0,this.B=Gr[1]|0,this.C=Gr[2]|0,this.D=Gr[3]|0,this.E=Gr[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 c=0;c<16;c++,r+=4)Ot[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)Ot[c]=(0,Hn.rotl)(Ot[c-3]^Ot[c-8]^Ot[c-14]^Ot[c-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let c=0;c<80;c++){let l,d;c<20?(l=(0,Li.Chi)(i,s,o),d=1518500249):c<40?(l=i^s^o,d=1859775393):c<60?(l=(0,Li.Maj)(i,s,o),d=2400959708):(l=i^s^o,d=3395469782);const g=(0,Hn.rotl)(n,5)+l+a+d+Ot[c]|0;a=o,o=s,s=(0,Hn.rotl)(i,30),i=n,n=g}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(){Ot.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}Or.SHA1=Na;Or.sha1=(0,Hn.wrapConstructor)(()=>new Na);function oo(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function nc(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Us(e,...t){if(!nc(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 Yn(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 Fa(e,t){Us(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ic=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Ni=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),st=(e,t)=>e<<32-t|e>>>t,ao=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,sc=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;function fo(e){for(let t=0;t<e.length;t++)e[t]=sc(e[t])}function oc(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Cs(e){return typeof e=="string"&&(e=oc(e)),Us(e),e}let Ma=class{clone(){return this._cloneInto()}};function Ls(e){const t=n=>e().update(Cs(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ac(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),c=n?4:0,l=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+l,a,n)}const fc=(e,t,r)=>e&t^~e&r,uc=(e,t,r)=>e&t^e&r^t&r;class cc extends Ma{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=Ni(this.buffer)}update(t){Yn(this);const{view:r,buffer:n,blockLen:i}=this;t=Cs(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Ni(t);for(;i<=s-o;o+=i)this.process(c,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){Yn(this),Fa(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 g=o;g<i;g++)r[g]=0;ac(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Ni(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<l;g++)a.setUint32(4*g,d[g],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 hc=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]),kt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rt=new Uint32Array(64);class Ns extends cc{constructor(){super(64,32,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[t,r,n,i,s,o,a,c]}set(t,r,n,i,s,o,a,c){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=c|0}process(t,r){for(let g=0;g<16;g++,r+=4)Rt[g]=t.getUint32(r,!1);for(let g=16;g<64;g++){const x=Rt[g-15],y=Rt[g-2],O=st(x,7)^st(x,18)^x>>>3,B=st(y,17)^st(y,19)^y>>>10;Rt[g]=B+Rt[g-7]+O+Rt[g-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:l,H:d}=this;for(let g=0;g<64;g++){const x=st(a,6)^st(a,11)^st(a,25),y=d+x+fc(a,c,l)+hc[g]+Rt[g]|0,B=(st(n,2)^st(n,13)^st(n,22))+uc(n,i,s)|0;d=l,l=c,c=a,a=o+y|0,o=s,s=i,i=n,n=y+B|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,c=c+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,c,l,d)}roundClean(){Rt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class lc extends Ns{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}}const Ha=Ls(()=>new Ns),dc=Ls(()=>new lc),pc=Object.freeze(Object.defineProperty({__proto__:null,SHA256:Ns,sha224:dc,sha256:Ha},Symbol.toStringTag,{value:"Module"})),$a=ba(pc);(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=Ir,r=Or,n=$a;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 c(d){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(d))))}e.hash256=c,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,g){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[d],g]))}e.taggedHash=l})(jt);var Fi={},xt={};Object.defineProperty(xt,"__esModule",{value:!0});xt.encode=xt.decode=xt.check=void 0;function yc(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))}xt.check=yc;function bc(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)}}xt.decode=bc;function wc(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}xt.encode=wc;var tr={};Object.defineProperty(tr,"__esModule",{value:!0});tr.REVERSE_OPS=tr.OPS=void 0;const us={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};tr.OPS=us;const Da={};tr.REVERSE_OPS=Da;for(const e of Object.keys(us)){const t=us[e];Da[t]=e}var Ht={};Object.defineProperty(Ht,"__esModule",{value:!0});Ht.decode=Ht.encode=Ht.encodingLength=void 0;const Ft=tr;function ja(e){return e<Ft.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Ht.encodingLength=ja;function gc(e,t,r){const n=ja(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(Ft.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(Ft.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(Ft.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Ht.encode=gc;function mc(e,t){const r=e.readUInt8(t);let n,i;if(r<Ft.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===Ft.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===Ft.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!==Ft.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Ht.decode=mc;var kr={};Object.defineProperty(kr,"__esModule",{value:!0});kr.encode=kr.decode=void 0;function _c(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}kr.decode=_c;function vc(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function Ec(e){let t=Math.abs(e);const r=vc(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}kr.encode=Ec;var Yt={},uo;function xc(){if(uo)return Yt;uo=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.encode=Yt.decode=void 0;const e=xt,t=Ye(),r=Fe,{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),g=Math.max(0,32-l.length);return l.copy(d,g),d}function a(l){const d=l.readUInt8(l.length-1);if(!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const g=e.decode(l.slice(0,-1)),x=o(g.r),y=o(g.s);return{signature:Buffer.concat([x,y],64),hashType:d}}Yt.decode=a;function c(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 g=Buffer.allocUnsafe(1);g.writeUInt8(d,0);const x=s(l.slice(0,32)),y=s(l.slice(32,64));return Buffer.concat([e.encode(x,y),g])}return Yt.encode=c,Yt}var co;function Ye(){return co||(co=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=xt,r=tr;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Ht,i=kr,s=xc(),o=Fe,{typeforce:a}=o,c=r.OPS.OP_RESERVED;function l(R){return o.Number(R)&&(R===r.OPS.OP_0||R>=r.OPS.OP_1&&R<=r.OPS.OP_16||R===r.OPS.OP_1NEGATE)}function d(R){return o.Buffer(R)||l(R)}function g(R){return o.Array(R)&&R.every(d)}e.isPushOnly=g;function x(R){return R.length-R.filter(d).length}e.countNonPushOnlyOPs=x;function y(R){if(R.length===0)return r.OPS.OP_0;if(R.length===1){if(R[0]>=1&&R[0]<=16)return c+R[0];if(R[0]===129)return r.OPS.OP_1NEGATE}}function O(R){return Buffer.isBuffer(R)}function B(R){return o.Array(R)}function A(R){return Buffer.isBuffer(R)}function k(R){if(O(R))return R;a(o.Array,R);const z=R.reduce((M,W)=>A(W)?W.length===1&&y(W)!==void 0?M+1:M+n.encodingLength(W.length)+W.length:M+1,0),Z=Buffer.allocUnsafe(z);let C=0;if(R.forEach(M=>{if(A(M)){const W=y(M);if(W!==void 0){Z.writeUInt8(W,C),C+=1;return}C+=n.encode(Z,M.length,C),M.copy(Z,C),C+=M.length}else Z.writeUInt8(M,C),C+=1}),C!==Z.length)throw new Error("Could not decode chunks");return Z}e.compile=k;function U(R){if(B(R))return R;a(o.Buffer,R);const z=[];let Z=0;for(;Z<R.length;){const C=R[Z];if(C>r.OPS.OP_0&&C<=r.OPS.OP_PUSHDATA4){const M=n.decode(R,Z);if(M===null||(Z+=M.size,Z+M.number>R.length))return null;const W=R.slice(Z,Z+M.number);Z+=M.number;const q=y(W);q!==void 0?z.push(q):z.push(W)}else z.push(C),Z+=1}return z}e.decompile=U;function _(R){if(O(R)&&(R=U(R)),!R)throw new Error("Could not convert invalid chunks to ASM");return R.map(z=>{if(A(z)){const Z=y(z);if(Z===void 0)return z.toString("hex");z=Z}return r.REVERSE_OPS[z]}).join(" ")}e.toASM=_;function m(R){return a(o.String,R),k(R.split(" ").map(z=>r.OPS[z]!==void 0?r.OPS[z]:(a(o.Hex,z),Buffer.from(z,"hex"))))}e.fromASM=m;function S(R){return R=U(R),a(g,R),R.map(z=>A(z)?z:z===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(z-c))}e.toStack=S;function E(R){return o.isPoint(R)}e.isCanonicalPubKey=E;function H(R){const z=R&-129;return z>0&&z<4}e.isDefinedHashType=H;function D(R){return!Buffer.isBuffer(R)||!H(R[R.length-1])?!1:t.check(R.slice(0,-1))}e.isCanonicalScriptSignature=D,e.number=i,e.signature=s}(Fi)),Fi}Object.defineProperty(bn,"__esModule",{value:!0});bn.Transaction=void 0;const Be=Oe,Me=jt,ho=Ye(),Sc=Ye(),ee=Fe,{typeforce:ot}=ee;function ut(e){const t=e.length;return Be.varuint.encodingLength(t)+t}function Bc(e){const t=e.length;return Be.varuint.encodingLength(t)+e.reduce((r,n)=>r+ut(n),0)}const Nt=Buffer.allocUnsafe(0),lo=[],Mi=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),po=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Pc=Buffer.from("ffffffffffffffff","hex"),Tc={script:Nt,valueBuffer:Pc};function Ac(e){return e.value!==void 0}class X{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Be.BufferReader(t),i=new X;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===X.ADVANCED_TRANSACTION_MARKER&&o===X.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let d=0;d<c;++d)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:lo});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<c;++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 X.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){ot(ee.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&X.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return ot(ee.tuple(ee.Hash256bit,ee.UInt32,ee.maybe(ee.UInt32),ee.maybe(ee.Buffer)),arguments),ee.Null(n)&&(n=X.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||Nt,sequence:n,witness:lo})-1}addOutput(t,r){return ot(ee.tuple(ee.Buffer,ee.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)+Be.varuint.encodingLength(this.ins.length)+Be.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+ut(i.script),0)+this.outs.reduce((n,i)=>n+8+ut(i.script),0)+(r?this.ins.reduce((n,i)=>n+Bc(i.witness),0):0)}clone(){const t=new X;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(ot(ee.tuple(ee.UInt32,ee.Buffer,ee.Number),arguments),t>=this.ins.length)return po;const i=ho.compile(ho.decompile(r).filter(a=>a!==Sc.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===X.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===X.SIGHASH_SINGLE){if(t>=this.outs.length)return po;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=Tc;s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&X.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=Nt}),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),Me.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(ot(ee.tuple(ee.UInt32,ot.arrayOf(ee.Buffer),ot.arrayOf(ee.Satoshi),ee.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===X.SIGHASH_DEFAULT?X.SIGHASH_ALL:i&X.SIGHASH_OUTPUT_MASK,l=(i&X.SIGHASH_INPUT_MASK)===X.SIGHASH_ANYONECANPAY,d=a===X.SIGHASH_NONE,g=a===X.SIGHASH_SINGLE;let x=Nt,y=Nt,O=Nt,B=Nt,A=Nt;if(!l){let m=Be.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(S=>{m.writeSlice(S.hash),m.writeUInt32(S.index)}),x=Me.sha256(m.end()),m=Be.BufferWriter.withCapacity(8*this.ins.length),n.forEach(S=>m.writeUInt64(S)),y=Me.sha256(m.end()),m=Be.BufferWriter.withCapacity(r.map(ut).reduce((S,E)=>S+E)),r.forEach(S=>m.writeVarSlice(S)),O=Me.sha256(m.end()),m=Be.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(S=>m.writeUInt32(S.sequence)),B=Me.sha256(m.end())}if(d||g){if(g&&t<this.outs.length){const m=this.outs[t],S=Be.BufferWriter.withCapacity(8+ut(m.script));S.writeUInt64(m.value),S.writeVarSlice(m.script),A=Me.sha256(S.end())}}else{const m=this.outs.map(E=>8+ut(E.script)).reduce((E,H)=>E+H),S=Be.BufferWriter.withCapacity(m);this.outs.forEach(E=>{S.writeUInt64(E.value),S.writeVarSlice(E.script)}),A=Me.sha256(S.end())}const k=(s?2:0)+(o?1:0),U=174-(l?49:0)-(d?32:0)+(o?32:0)+(s?37:0),_=Be.BufferWriter.withCapacity(U);if(_.writeUInt8(i),_.writeInt32(this.version),_.writeUInt32(this.locktime),_.writeSlice(x),_.writeSlice(y),_.writeSlice(O),_.writeSlice(B),d||g||_.writeSlice(A),_.writeUInt8(k),l){const m=this.ins[t];_.writeSlice(m.hash),_.writeUInt32(m.index),_.writeUInt64(n[t]),_.writeVarSlice(r[t]),_.writeUInt32(m.sequence)}else _.writeUInt32(t);if(o){const m=Be.BufferWriter.withCapacity(ut(o));m.writeVarSlice(o),_.writeSlice(Me.sha256(m.end()))}return g&&_.writeSlice(A),s&&(_.writeSlice(s),_.writeUInt8(0),_.writeUInt32(4294967295)),Me.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),_.end()]))}hashForWitnessV0(t,r,n,i){ot(ee.tuple(ee.UInt32,ee.Buffer,ee.Satoshi,ee.UInt32),arguments);let s=Buffer.from([]),o,a=Mi,c=Mi,l=Mi;if(i&X.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(g=>{o.writeSlice(g.hash),o.writeUInt32(g.index)}),c=Me.hash256(s)),!(i&X.SIGHASH_ANYONECANPAY)&&(i&31)!==X.SIGHASH_SINGLE&&(i&31)!==X.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(g=>{o.writeUInt32(g.sequence)}),l=Me.hash256(s)),(i&31)!==X.SIGHASH_SINGLE&&(i&31)!==X.SIGHASH_NONE){const g=this.outs.reduce((x,y)=>x+8+ut(y.script),0);s=Buffer.allocUnsafe(g),o=new Be.BufferWriter(s,0),this.outs.forEach(x=>{o.writeUInt64(x.value),o.writeVarSlice(x.script)}),a=Me.hash256(s)}else if((i&31)===X.SIGHASH_SINGLE&&t<this.outs.length){const g=this.outs[t];s=Buffer.allocUnsafe(8+ut(g.script)),o=new Be.BufferWriter(s,0),o.writeUInt64(g.value),o.writeVarSlice(g.script),a=Me.hash256(s)}s=Buffer.allocUnsafe(156+ut(r)),o=new Be.BufferWriter(s,0);const d=this.ins[t];return o.writeInt32(this.version),o.writeSlice(c),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),Me.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):Me.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Be.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){ot(ee.tuple(ee.Number,ee.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){ot(ee.tuple(ee.Number,[ee.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Be.BufferWriter(t,r||0);i.writeInt32(this.version);const s=n&&this.hasWitnesses();return s&&(i.writeUInt8(X.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(X.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=>{Ac(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}}bn.Transaction=X;X.DEFAULT_SEQUENCE=4294967295;X.SIGHASH_DEFAULT=0;X.SIGHASH_ALL=1;X.SIGHASH_NONE=2;X.SIGHASH_SINGLE=3;X.SIGHASH_ANYONECANPAY=128;X.SIGHASH_OUTPUT_MASK=3;X.SIGHASH_INPUT_MASK=128;X.ADVANCED_TRANSACTION_MARKER=0;X.ADVANCED_TRANSACTION_FLAG=1;var se={},wn={};Object.defineProperty(wn,"__esModule",{value:!0});const Ic=9007199254740991;function Fs(e){if(e<0||e>Ic||e%1!==0)throw new RangeError("value out of range")}function sn(e,t,r){if(Fs(e),t||(t=Buffer.allocUnsafe(Ga(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(sn,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(sn,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(sn,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(sn,{bytes:9})),t}wn.encode=sn;function on(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(on,{bytes:1}),r;if(r===253)return Object.assign(on,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(on,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(on,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return Fs(s),s}}wn.decode=on;function Ga(e){return Fs(e),e<253?1:e<=65535?3:e<=4294967295?5:9}wn.encodingLength=Ga;var Hi={},ai={},Ne={};Object.defineProperty(Ne,"__esModule",{value:!0});Ne.testnet=Ne.regtest=Ne.bitcoin=void 0;Ne.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
7
|
+
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Ne.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
8
|
+
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};Ne.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
9
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Ke={};Object.defineProperty(Ke,"__esModule",{value:!0});Ke.value=Ke.prop=void 0;function Oc(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})}})}Ke.prop=Oc;function kc(e){let t;return()=>(t!==void 0||(t=e()),t)}Ke.value=kc;Object.defineProperty(ai,"__esModule",{value:!0});ai.p2data=void 0;const Rc=Ne,$n=Ye(),at=Fe,yo=Ke,bo=$n.OPS;function Uc(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,at.typeforce)({network:at.typeforce.maybe(at.typeforce.Object),output:at.typeforce.maybe(at.typeforce.Buffer),data:at.typeforce.maybe(at.typeforce.arrayOf(at.typeforce.Buffer))},e);const n={name:"embed",network:e.network||Rc.bitcoin};if(yo.prop(n,"output",()=>{if(e.data)return $n.compile([bo.OP_RETURN].concat(e.data))}),yo.prop(n,"data",()=>{if(e.output)return $n.decompile(e.output).slice(1)}),t.validate&&e.output){const i=$n.decompile(e.output);if(i[0]!==bo.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(at.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,at.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}ai.p2data=Uc;var fi={};Object.defineProperty(fi,"__esModule",{value:!0});fi.p2ms=void 0;const Cc=Ne,mr=Ye(),Se=Fe,Ut=Ke,_r=mr.OPS,An=_r.OP_RESERVED;function Lc(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(c){return mr.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===_r.OP_0)!==void 0}(0,Se.typeforce)({network:Se.typeforce.maybe(Se.typeforce.Object),m:Se.typeforce.maybe(Se.typeforce.Number),n:Se.typeforce.maybe(Se.typeforce.Number),output:Se.typeforce.maybe(Se.typeforce.Buffer),pubkeys:Se.typeforce.maybe(Se.typeforce.arrayOf(Se.isPoint)),signatures:Se.typeforce.maybe(Se.typeforce.arrayOf(r)),input:Se.typeforce.maybe(Se.typeforce.Buffer)},e);const i={network:e.network||Cc.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=mr.decompile(c),i.m=s[0]-An,i.n=s[s.length-2]-An,i.pubkeys=s.slice(1,-2))}if(Ut.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return mr.compile([].concat(An+e.m,e.pubkeys,An+i.n,_r.OP_CHECKMULTISIG))}),Ut.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),Ut.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Ut.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),Ut.prop(i,"signatures",()=>{if(e.input)return mr.decompile(e.input).slice(1)}),Ut.prop(i,"input",()=>{if(e.signatures)return mr.compile([_r.OP_0].concat(e.signatures))}),Ut.prop(i,"witness",()=>{if(i.input)return[]}),Ut.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!Se.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!Se.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==_r.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(c=>(0,Se.isPoint)(c)))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,Se.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]!==_r.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,Se.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)}fi.p2ms=Lc;var ui={};Object.defineProperty(ui,"__esModule",{value:!0});ui.p2pk=void 0;const Nc=Ne,vr=Ye(),tt=Fe,gr=Ke,wo=vr.OPS;function Fc(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,tt.typeforce)({network:tt.typeforce.maybe(tt.typeforce.Object),output:tt.typeforce.maybe(tt.typeforce.Buffer),pubkey:tt.typeforce.maybe(tt.isPoint),signature:tt.typeforce.maybe(vr.isCanonicalScriptSignature),input:tt.typeforce.maybe(tt.typeforce.Buffer)},e);const r=gr.value(()=>vr.decompile(e.input)),i={name:"p2pk",network:e.network||Nc.bitcoin};if(gr.prop(i,"output",()=>{if(e.pubkey)return vr.compile([e.pubkey,wo.OP_CHECKSIG])}),gr.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),gr.prop(i,"signature",()=>{if(e.input)return r()[0]}),gr.prop(i,"input",()=>{if(e.signature)return vr.compile([e.signature])}),gr.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==wo.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,tt.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(!vr.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}ui.p2pk=Fc;var ci={};function Mc(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if(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 O=0,B=0,A=0,k=y.length;A!==k&&y[A]===0;)A++,O++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=y[A],S=0,E=U-1;(m!==0||S<B)&&E!==-1;E--,S++)m+=256*_[E]>>>0,_[E]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");B=S,A++}for(var H=U-B;H!==U&&_[H]===0;)H++;for(var D=a.repeat(O);H<U;++H)D+=e.charAt(_[H]);return D}function g(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;for(var O=0,B=0,A=0;y[O]===a;)B++,O++;for(var k=(y.length-O)*c+1>>>0,U=new Uint8Array(k);y[O];){var _=t[y.charCodeAt(O)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,O++}for(var E=k-A;E!==k&&U[E]===0;)E++;for(var H=new Uint8Array(B+(k-E)),D=B;E!==k;)H[D++]=U[E++];return H}function x(y){var O=g(y);if(O)return O;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:g,decode:x}}var Hc=Mc;const $c=Hc,Dc="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var jc=$c(Dc),$i=jc,Gc=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,l=new Uint8Array(c);return l.set(o,0),l.set(a.subarray(0,4),o.length),$i.encode(l,c)}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=$i.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=$i.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:go}=$a,Wc=Gc;function Vc(e){return go(go(e))}var Ms=Wc(Vc);Object.defineProperty(ci,"__esModule",{value:!0});ci.p2pkh=void 0;const Di=jt,zc=Ne,Er=Ye(),He=Fe,bt=Ke,mo=Ms,Ct=Er.OPS;function qc(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,He.typeforce)({network:He.typeforce.maybe(He.typeforce.Object),address:He.typeforce.maybe(He.typeforce.String),hash:He.typeforce.maybe(He.typeforce.BufferN(20)),output:He.typeforce.maybe(He.typeforce.BufferN(25)),pubkey:He.typeforce.maybe(He.isPoint),signature:He.typeforce.maybe(Er.isCanonicalScriptSignature),input:He.typeforce.maybe(He.typeforce.Buffer)},e);const r=bt.value(()=>{const o=Buffer.from(mo.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=bt.value(()=>Er.decompile(e.input)),i=e.network||zc.bitcoin,s={name:"p2pkh",network:i};if(bt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),mo.encode(o)}),bt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Di.hash160(e.pubkey||s.pubkey)}),bt.prop(s,"output",()=>{if(s.hash)return Er.compile([Ct.OP_DUP,Ct.OP_HASH160,s.hash,Ct.OP_EQUALVERIFY,Ct.OP_CHECKSIG])}),bt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),bt.prop(s,"signature",()=>{if(e.input)return n()[0]}),bt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return Er.compile([e.signature,e.pubkey])}),bt.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]!==Ct.OP_DUP||e.output[1]!==Ct.OP_HASH160||e.output[2]!==20||e.output[23]!==Ct.OP_EQUALVERIFY||e.output[24]!==Ct.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=Di.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(!Er.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,He.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 c=Di.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}ci.p2pkh=qc;var hi={};Object.defineProperty(hi,"__esModule",{value:!0});hi.p2sh=void 0;const _o=jt,Kc=Ne,ct=Ye(),ce=Fe,ft=Ke,vo=Ms,Wr=ct.OPS;function Yc(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,ce.typeforce)({network:ce.typeforce.maybe(ce.typeforce.Object),address:ce.typeforce.maybe(ce.typeforce.String),hash:ce.typeforce.maybe(ce.typeforce.BufferN(20)),output:ce.typeforce.maybe(ce.typeforce.BufferN(23)),redeem:ce.typeforce.maybe({network:ce.typeforce.maybe(ce.typeforce.Object),output:ce.typeforce.maybe(ce.typeforce.Buffer),input:ce.typeforce.maybe(ce.typeforce.Buffer),witness:ce.typeforce.maybe(ce.typeforce.arrayOf(ce.typeforce.Buffer))}),input:ce.typeforce.maybe(ce.typeforce.Buffer),witness:ce.typeforce.maybe(ce.typeforce.arrayOf(ce.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Kc.bitcoin);const n={network:r},i=ft.value(()=>{const a=Buffer.from(vo.decode(e.address)),c=a.readUInt8(0),l=a.slice(1);return{version:c,hash:l}}),s=ft.value(()=>ct.decompile(e.input)),o=ft.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Wr.OP_FALSE?Buffer.from([]):c,input:ct.compile(a.slice(0,-1)),witness:e.witness||[]}});if(ft.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),vo.encode(a)}),ft.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 _o.hash160(n.redeem.output)}),ft.prop(n,"output",()=>{if(n.hash)return ct.compile([Wr.OP_HASH160,n.hash,Wr.OP_EQUAL])}),ft.prop(n,"redeem",()=>{if(e.input)return o()}),ft.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return ct.compile([].concat(ct.decompile(e.redeem.input),e.redeem.output))}),ft.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),ft.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]!==Wr.OP_HASH160||e.output[1]!==20||e.output[22]!==Wr.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 c=l=>{if(l.output){const d=ct.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(ct.countNonPushOnlyOPs(d)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const g=_o.hash160(l.output);if(a.length>0&&!a.equals(g))throw new TypeError("Hash mismatch");a=g}if(l.input){const d=l.input.length>0,g=l.witness&&l.witness.length>0;if(!d&&!g)throw new TypeError("Empty input");if(d&&g)throw new TypeError("Input and witness provided");if(d){const x=ct.decompile(l.input);if(!ct.isPushOnly(x))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");c(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")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,ce.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}hi.p2sh=Yc;var li={},Bt={};Object.defineProperty(Bt,"__esModule",{value:!0});Bt.bech32m=Bt.bech32=void 0;const Xn="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Wa={};for(let e=0;e<Xn.length;e++){const t=Xn.charAt(e);Wa[t]=e}function Br(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 Eo(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=Br(t)^n>>5}t=Br(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=Br(t)^n&31}return t}function Hs(e,t,r,n){let i=0,s=0;const o=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],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 Xc(e){return Hs(e,8,5,!0)}function Jc(e){const t=Hs(e,5,8,!1);if(Array.isArray(t))return t}function Qc(e){const t=Hs(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Va(e){let t;e==="bech32"?t=1:t=734539939;function r(o,a,c){if(c=c||90,o.length+7+a.length>c)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let l=Eo(o);if(typeof l=="string")throw new Error(l);let d=o+"1";for(let g=0;g<a.length;++g){const x=a[g];if(x>>5)throw new Error("Non 5-bit word");l=Br(l)^x,d+=Xn.charAt(x)}for(let g=0;g<6;++g)l=Br(l);l^=t;for(let g=0;g<6;++g){const x=l>>(5-g)*5&31;d+=Xn.charAt(x)}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 c=o.toLowerCase(),l=o.toUpperCase();if(o!==c&&o!==l)return"Mixed-case string "+o;o=c;const d=o.lastIndexOf("1");if(d===-1)return"No separator character for "+o;if(d===0)return"Missing prefix for "+o;const g=o.slice(0,d),x=o.slice(d+1);if(x.length<6)return"Data too short";let y=Eo(g);if(typeof y=="string")return y;const O=[];for(let B=0;B<x.length;++B){const A=x.charAt(B),k=Wa[A];if(k===void 0)return"Unknown character "+A;y=Br(y)^k,!(B+6>=x.length)&&O.push(k)}return y!==t?"Invalid checksum for "+o:{prefix:g,words:O}}function i(o,a){const c=n(o,a);if(typeof c=="object")return c}function s(o,a){const c=n(o,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:s,encode:r,toWords:Xc,fromWordsUnsafe:Jc,fromWords:Qc}}Bt.bech32=Va("bech32");Bt.bech32m=Va("bech32m");Object.defineProperty(li,"__esModule",{value:!0});li.p2wpkh=void 0;const ji=jt,Zc=Ne,Dn=Ye(),Pe=Fe,Lt=Ke,In=Bt,xo=Dn.OPS,eh=Buffer.alloc(0);function th(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,Pe.typeforce)({address:Pe.typeforce.maybe(Pe.typeforce.String),hash:Pe.typeforce.maybe(Pe.typeforce.BufferN(20)),input:Pe.typeforce.maybe(Pe.typeforce.BufferN(0)),network:Pe.typeforce.maybe(Pe.typeforce.Object),output:Pe.typeforce.maybe(Pe.typeforce.BufferN(22)),pubkey:Pe.typeforce.maybe(Pe.isPoint),signature:Pe.typeforce.maybe(Dn.isCanonicalScriptSignature),witness:Pe.typeforce.maybe(Pe.typeforce.arrayOf(Pe.typeforce.Buffer))},e);const r=Lt.value(()=>{const s=In.bech32.decode(e.address),o=s.words.shift(),a=In.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||Zc.bitcoin,i={name:"p2wpkh",network:n};if(Lt.prop(i,"address",()=>{if(!i.hash)return;const s=In.bech32.toWords(i.hash);return s.unshift(0),In.bech32.encode(n.bech32,s)}),Lt.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return ji.hash160(e.pubkey||i.pubkey)}),Lt.prop(i,"output",()=>{if(i.hash)return Dn.compile([xo.OP_0,i.hash])}),Lt.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Lt.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Lt.prop(i,"input",()=>{if(i.witness)return eh}),Lt.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]!==xo.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=ji.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Pe.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(!Dn.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Pe.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=ji.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}li.p2wpkh=th;var di={};Object.defineProperty(di,"__esModule",{value:!0});di.p2wsh=void 0;const So=jt,rh=Ne,_t=Ye(),oe=Fe,wt=Ke,On=Bt,Bo=_t.OPS,Gi=Buffer.alloc(0);function kn(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,oe.isPoint)(e))}function nh(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,oe.typeforce)({network:oe.typeforce.maybe(oe.typeforce.Object),address:oe.typeforce.maybe(oe.typeforce.String),hash:oe.typeforce.maybe(oe.typeforce.BufferN(32)),output:oe.typeforce.maybe(oe.typeforce.BufferN(34)),redeem:oe.typeforce.maybe({input:oe.typeforce.maybe(oe.typeforce.Buffer),network:oe.typeforce.maybe(oe.typeforce.Object),output:oe.typeforce.maybe(oe.typeforce.Buffer),witness:oe.typeforce.maybe(oe.typeforce.arrayOf(oe.typeforce.Buffer))}),input:oe.typeforce.maybe(oe.typeforce.BufferN(0)),witness:oe.typeforce.maybe(oe.typeforce.arrayOf(oe.typeforce.Buffer))},e);const r=wt.value(()=>{const o=On.bech32.decode(e.address),a=o.words.shift(),c=On.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=wt.value(()=>_t.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||rh.bitcoin);const s={network:i};if(wt.prop(s,"address",()=>{if(!s.hash)return;const o=On.bech32.toWords(s.hash);return o.unshift(0),On.bech32.encode(i.bech32,o)}),wt.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return So.sha256(s.redeem.output)}),wt.prop(s,"output",()=>{if(s.hash)return _t.compile([Bo.OP_0,s.hash])}),wt.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Gi,witness:e.witness.slice(0,-1)}}),wt.prop(s,"input",()=>{if(s.witness)return Gi}),wt.prop(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=_t.toStack(n());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=Gi,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),wt.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]!==Bo.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=_t.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(_t.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=So.sha256(e.redeem.output);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch");o=c}if(e.redeem.input&&!_t.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,oe.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(kn)||e.redeem.output&&(_t.decompile(e.redeem.output)||[]).some(kn))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(kn)||(_t.decompile(a)||[]).some(kn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}di.p2wsh=nh;var Vr={},rr={};Object.defineProperty(rr,"__esModule",{value:!0});rr.getEccLib=rr.initEccLib=void 0;const an={};function ih(e){e?e!==an.eccLib&&(oh(e),an.eccLib=e):an.eccLib=e}rr.initEccLib=ih;function sh(){if(!an.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return an.eccLib}rr.getEccLib=sh;const gt=e=>Buffer.from(e,"hex");function oh(e){Je(typeof e.isXOnlyPoint=="function"),Je(e.isXOnlyPoint(gt("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Je(e.isXOnlyPoint(gt("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Je(e.isXOnlyPoint(gt("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Je(e.isXOnlyPoint(gt("0000000000000000000000000000000000000000000000000000000000000001"))),Je(!e.isXOnlyPoint(gt("0000000000000000000000000000000000000000000000000000000000000000"))),Je(!e.isXOnlyPoint(gt("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Je(typeof e.xOnlyPointAddTweak=="function"),ah.forEach(t=>{const r=e.xOnlyPointAddTweak(gt(t.pubkey),gt(t.tweak));t.result===null?Je(r===null):(Je(r!==null),Je(r.parity===t.parity),Je(Buffer.from(r.xOnlyPubkey).equals(gt(t.result))))})}function Je(e){if(!e)throw new Error("ecc library invalid")}const ah=[{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 $s={};(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=Tt,r=rr,n=jt,i=Oe,s=Fe;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=B=>"left"in B&&"right"in B;function a(B,A){if(B.length<33)throw new TypeError(`The control-block length is too small. Got ${B.length}, expected min 33.`);const k=(B.length-33)/32;let U=A;for(let _=0;_<k;_++){const m=B.slice(33+32*_,65+32*_);U.compare(m)<0?U=y(U,m):U=y(m,U)}return U}e.rootHashFromPath=a;function c(B){if((0,s.isTapleaf)(B))return{hash:d(B)};const A=[c(B[0]),c(B[1])];A.sort((_,m)=>_.hash.compare(m.hash));const[k,U]=A;return{hash:y(k.hash,U.hash),left:k,right:U}}e.toHashTree=c;function l(B,A){if(o(B)){const k=l(B.left,A);if(k!==void 0)return[...k,B.right.hash];const U=l(B.right,A);if(U!==void 0)return[...U,B.left.hash]}else if(B.hash.equals(A))return[]}e.findScriptPath=l;function d(B){const A=B.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([A]),O(B.output)]))}e.tapleafHash=d;function g(B,A){return n.taggedHash("TapTweak",t.Buffer.concat(A?[B,A]:[B]))}e.tapTweakHash=g;function x(B,A){if(!t.Buffer.isBuffer(B)||B.length!==32||A&&A.length!==32)return null;const k=g(B,A),U=(0,r.getEccLib)().xOnlyPointAddTweak(B,k);return!U||U.xOnlyPubkey===null?null:{parity:U.parity,x:t.Buffer.from(U.xOnlyPubkey)}}e.tweakKey=x;function y(B,A){return n.taggedHash("TapBranch",t.Buffer.concat([B,A]))}function O(B){const A=i.varuint.encodingLength(B.length),k=t.Buffer.allocUnsafe(A);return i.varuint.encode(B.length,k),t.Buffer.concat([k,B])}})($s);var $e={},Po;function fh(){if(Po)return $e;Po=1,Object.defineProperty($e,"__esModule",{value:!0}),$e.toOutputScript=$e.fromOutputScript=$e.toBech32=$e.toBase58Check=$e.fromBech32=$e.fromBase58Check=void 0;const e=Ne,t=Ds(),r=Ye(),n=Fe,i=Bt,s=Ms,o=40,a=2,c=16,l=2,d=80,g="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 x(_,m){const S=_.slice(2);if(S.length<a||S.length>o)throw new TypeError("Invalid program length for segwit address");const E=_[0]-d;if(E<l||E>c)throw new TypeError("Invalid version for segwit address");if(_[1]!==S.length)throw new TypeError("Invalid script for segwit address");return console.warn(g),A(S,E,m.bech32)}function y(_){const m=Buffer.from(s.decode(_));if(m.length<21)throw new TypeError(_+" is too short");if(m.length>21)throw new TypeError(_+" is too long");const S=m.readUInt8(0),E=m.slice(1);return{version:S,hash:E}}$e.fromBase58Check=y;function O(_){let m,S;try{m=i.bech32.decode(_)}catch{}if(m){if(S=m.words[0],S!==0)throw new TypeError(_+" uses wrong encoding")}else if(m=i.bech32m.decode(_),S=m.words[0],S===0)throw new TypeError(_+" uses wrong encoding");const E=i.bech32.fromWords(m.words.slice(1));return{version:S,prefix:m.prefix,data:Buffer.from(E)}}$e.fromBech32=O;function B(_,m){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const S=Buffer.allocUnsafe(21);return S.writeUInt8(m,0),_.copy(S,1),s.encode(S)}$e.toBase58Check=B;function A(_,m,S){const E=i.bech32.toWords(_);return E.unshift(m),m===0?i.bech32.encode(S,E):i.bech32m.encode(S,E)}$e.toBech32=A;function k(_,m){m=m||e.bitcoin;try{return t.p2pkh({output:_,network:m}).address}catch{}try{return t.p2sh({output:_,network:m}).address}catch{}try{return t.p2wpkh({output:_,network:m}).address}catch{}try{return t.p2wsh({output:_,network:m}).address}catch{}try{return t.p2tr({output:_,network:m}).address}catch{}try{return x(_,m)}catch{}throw new Error(r.toASM(_)+" has no matching Address")}$e.fromOutputScript=k;function U(_,m){m=m||e.bitcoin;let S,E;try{S=y(_)}catch{}if(S){if(S.version===m.pubKeyHash)return t.p2pkh({hash:S.hash}).output;if(S.version===m.scriptHash)return t.p2sh({hash:S.hash}).output}else{try{E=O(_)}catch{}if(E){if(E.prefix!==m.bech32)throw new Error(_+" has an invalid prefix");if(E.version===0){if(E.data.length===20)return t.p2wpkh({hash:E.data}).output;if(E.data.length===32)return t.p2wsh({hash:E.data}).output}else if(E.version===1){if(E.data.length===32)return t.p2tr({pubkey:E.data}).output}else if(E.version>=l&&E.version<=c&&E.data.length>=a&&E.data.length<=o)return console.warn(g),r.compile([E.version+d,E.data])}}throw new Error(_+" has no matching Script")}return $e.toOutputScript=U,$e}var To;function uh(){if(To)return Vr;To=1,Object.defineProperty(Vr,"__esModule",{value:!0}),Vr.p2tr=void 0;const e=Tt,t=Ne,r=Ye(),n=Fe,i=rr,s=$s,o=Ke,a=Bt,c=fh(),l=r.OPS,d=1,g=80;function x(y,O){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");O=Object.assign({validate:!0},O||{}),(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 B=o.value(()=>(0,c.fromBech32)(y.address)),A=o.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===g?y.witness.slice(0,-1):y.witness.slice()}),k=o.value(()=>{if(y.scriptTree)return(0,s.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),U=y.network||t.bitcoin,_={name:"p2tr",network:U};if(o.prop(_,"address",()=>{if(!_.pubkey)return;const m=a.bech32m.toWords(_.pubkey);return m.unshift(d),a.bech32m.encode(U.bech32,m)}),o.prop(_,"hash",()=>{const m=k();if(m)return m.hash;const S=A();if(S&&S.length>1){const E=S[S.length-1],H=E[0]&n.TAPLEAF_VERSION_MASK,D=S[S.length-2],R=(0,s.tapleafHash)({output:D,version:H});return(0,s.rootHashFromPath)(E,R)}return null}),o.prop(_,"output",()=>{if(_.pubkey)return r.compile([l.OP_1,_.pubkey])}),o.prop(_,"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(_,"redeem",()=>{const m=A();if(!(!m||m.length<2))return{output:m[m.length-2],witness:m.slice(0,-2),redeemVersion:m[m.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(_,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return B().data;if(_.internalPubkey){const m=(0,s.tweakKey)(_.internalPubkey,_.hash);if(m)return m.x}}),o.prop(_,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const m=A();if(m&&m.length>1)return m[m.length-1].slice(1,33)}),o.prop(_,"signature",()=>{if(y.signature)return y.signature;const m=A();if(!(!m||m.length!==1))return m[0]}),o.prop(_,"witness",()=>{if(y.witness)return y.witness;const m=k();if(m&&y.redeem&&y.redeem.output&&y.internalPubkey){const S=(0,s.tapleafHash)({output:y.redeem.output,version:_.redeemVersion}),E=(0,s.findScriptPath)(m,S);if(!E)return;const H=(0,s.tweakKey)(y.internalPubkey,m.hash);if(!H)return;const D=e.Buffer.concat([e.Buffer.from([_.redeemVersion|H.parity]),y.internalPubkey].concat(E));return[y.redeem.output,D]}if(y.signature)return[y.signature]}),O.validate){let m=e.Buffer.from([]);if(y.address){if(U&&U.bech32!==B().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(B().version!==d)throw new TypeError("Invalid address version");if(B().data.length!==32)throw new TypeError("Invalid address data");m=B().data}if(y.pubkey){if(m.length>0&&!m.equals(y.pubkey))throw new TypeError("Pubkey mismatch");m=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(m.length>0&&!m.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");m=y.output.slice(2)}if(y.internalPubkey){const H=(0,s.tweakKey)(y.internalPubkey,_.hash);if(m.length>0&&!m.equals(H.x))throw new TypeError("Pubkey mismatch");m=H.x}if(m&&m.length&&!(0,i.getEccLib)().isXOnlyPoint(m))throw new TypeError("Invalid pubkey for p2tr");const S=k();if(y.hash&&S&&!y.hash.equals(S.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&S){const H=(0,s.tapleafHash)({output:y.redeem.output,version:_.redeemVersion});if(!(0,s.findScriptPath)(S,H))throw new TypeError("Redeem script not in tree")}const E=A();if(y.redeem&&_.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==_.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(_.redeem.output&&!y.redeem.output.equals(_.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&_.redeem.witness&&!(0,n.stacksEqual)(y.redeem.witness,_.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(E&&E.length)if(E.length===1){if(y.signature&&!y.signature.equals(E[0]))throw new TypeError("Signature mismatch")}else{const H=E[E.length-1];if(H.length<33)throw new TypeError(`The control-block length is too small. Got ${H.length}, expected min 33.`);if((H.length-33)%32!==0)throw new TypeError(`The control-block length of ${H.length} is incorrect!`);const D=(H.length-33)/32;if(D>128)throw new TypeError(`The script path is too long. Got ${D}, expected max 128.`);const R=H.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(R))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(R))throw new TypeError("Invalid internalPubkey for p2tr witness");const z=H[0]&n.TAPLEAF_VERSION_MASK,Z=E[E.length-2],C=(0,s.tapleafHash)({output:Z,version:z}),M=(0,s.rootHashFromPath)(H,C),W=(0,s.tweakKey)(R,M);if(!W)throw new TypeError("Invalid outputKey for p2tr witness");if(m.length&&!m.equals(W.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(W.parity!==(H[0]&1))throw new Error("Incorrect parity")}}return Object.assign(_,y)}return Vr.p2tr=x,Vr}var Ao;function Ds(){return Ao||(Ao=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=ai;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=fi;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=ui;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=ci;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=hi;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=li;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=di;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=uh();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Hi)),Hi}Object.defineProperty(se,"__esModule",{value:!0});se.signatureBlocksAction=se.checkInputForSig=se.pubkeyInScript=se.pubkeyPositionInScript=se.witnessStackToScriptWitness=se.isP2TR=se.isP2SHScript=se.isP2WSHScript=se.isP2WPKH=se.isP2PKH=se.isP2PK=se.isP2MS=void 0;const Io=wn,fn=Ye(),Rn=bn,ch=jt,fr=Ds();function ur(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}se.isP2MS=ur(fr.p2ms);se.isP2PK=ur(fr.p2pk);se.isP2PKH=ur(fr.p2pkh);se.isP2WPKH=ur(fr.p2wpkh);se.isP2WSHScript=ur(fr.p2wsh);se.isP2SHScript=ur(fr.p2sh);se.isP2TR=ur(fr.p2tr);function hh(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=Io.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Io.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}se.witnessStackToScriptWitness=hh;function za(e,t){const r=(0,ch.hash160)(e),n=e.slice(1,33),i=fn.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))}se.pubkeyPositionInScript=za;function lh(e,t){return za(e,t)!==-1}se.pubkeyInScript=lh;function dh(e,t){return ph(e).some(n=>qa(n,fn.signature.decode,t))}se.checkInputForSig=dh;function qa(e,t,r){const{hashType:n}=t(e),i=[];switch(n&Rn.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case Rn.Transaction.SIGHASH_ALL:break;case Rn.Transaction.SIGHASH_SINGLE:case Rn.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}se.signatureBlocksAction=qa;function ph(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=yh(e)}else t=e.partialSig;return t.map(r=>r.signature)}function yh(e){const t=e.finalScriptSig?fn.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?fn.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&fn.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(_e,"__esModule",{value:!0});_e.checkTaprootInputForSigs=_e.tapTreeFromList=_e.tapTreeToList=_e.tweakInternalPubKey=_e.checkTaprootOutputFields=_e.checkTaprootInputFields=_e.isTaprootOutput=_e.isTaprootInput=jn=_e.serializeTaprootSignature=_e.tapScriptFinalizer=_e.toXOnly=void 0;const js=Fe,bh=bn,pi=se,Dt=$s,wh=Ds(),gh=se,mh=e=>e.length===32?e:e.slice(1,33);_e.toXOnly=mh;function _h(e,t,r){const n=Mh(t,e,r);try{const s=Nh(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,pi.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}_e.tapScriptFinalizer=_h;function vh(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var jn=_e.serializeTaprootSignature=vh;function Gn(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,pi.isP2TR)(e.witnessUtxo.script))}_e.isTaprootInput=Gn;function Wn(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,pi.isP2TR)(t))}_e.isTaprootOutput=Wn;function Eh(e,t,r){Uh(e,t,r),Lh(e,t,r)}_e.checkTaprootInputFields=Eh;function xh(e,t,r){Ch(e,t,r),Sh(e,t)}_e.checkTaprootOutputFields=xh;function Sh(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=Bh(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function Bh(e,t){const r=t&&Ka(t.leaves),{output:n}=(0,wh.p2tr)({internalPubkey:e,scriptTree:r});return n}function Ph(e,t){const r=t.tapInternalKey,n=r&&(0,Dt.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}_e.tweakInternalPubKey=Ph;function Th(e){if(!(0,js.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return cs(e)}_e.tapTreeToList=Th;function Ka(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:Rh(e)}_e.tapTreeFromList=Ka;function Ah(e,t){return Oh(e).some(n=>(0,gh.signatureBlocksAction)(n,Ih,t))}_e.checkTaprootInputForSigs=Ah;function Ih(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||bh.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=kh(e.finalScriptWitness);r&&t.push(r)}return t}function kh(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function cs(e,t=[],r=0){if(r>Dt.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,js.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||Dt.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&cs(e[0],t,r+1),e[1]&&cs(e[1],t,r+1),t):[]}function Rh(e){let t;for(const r of e)if(t=hs(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function hs(e,t,r=0){if(r>Dt.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,js.isTapleaf)(t))return;const n=hs(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=hs(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function Uh(e,t,r){const n=Gn(e)&&Pr(t),i=Pr(e)&&Gn(t),s=e===t&&Gn(t)&&Pr(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Ch(e,t,r){const n=Wn(e)&&Pr(t),i=Pr(e)&&Wn(t),s=e===t&&Wn(t)&&Pr(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=>Wi(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Wi(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=>Wi(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Wi(e,t){if(!t)return!0;const r=(0,Dt.tapleafHash)({output:e.script,version:e.leafVersion});return(0,Dt.rootHashFromPath)(e.controlBlock,r).equals(t)}function Nh(e,t){const r=(0,Dt.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>Fh(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function Fh(e,t){return Object.assign({positionInScript:(0,pi.pubkeyPositionInScript)(t.pubkey,e)},t)}function Mh(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=>Hh(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function Hh(e,t,r){const n=(0,Dt.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function Pr(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const De={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"},Un=192;de.initEccLib(er);class un{constructor(t,r,n,i,s,o,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=s,this.expiry=o,this.signer=t,this.network=a,this.internalPubkey=Pu(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,br(n.length===64,De.secretHashLenMismatch),br(i.length===64||i.length===66,`initiator ${De.pubkeyLenMismatch}`),br(s.length===64||s.length===66,`redeemer ${De.pubkeyLenMismatch}`),br(o>0,De.zeroOrNegativeExpiry);const c=await t.getNetwork();return new un(t,r,n,as(s).toString("hex"),as(i).toString("hex"),o,c,a)}address(){const{address:t}=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(De.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 c of this.utxoHashes){const l=await s.getTransaction(c);for(let d=0;d<l.vout.length;d++){const g=l.vout[d];g.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:g.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,l)=>c+l.value,0);if(a===0)throw new Error(`${i} ${De.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);return r??(r=await s.suggestFee(i,a,Ar.Urgency.MEDIUM)),n.addOutput(de.address.toOutputScript(t,this.network),a-r),{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,Ar.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,c=this.leafHash(1),l=s.map(g=>g.value),d=zr(o,s.length);for(let g=0;g<i.ins.length;g++){const x=i.hashForWitnessV1(g,d,l,a,c),y=await this.signer.signSchnorr(x);i.setWitness(g,[jn(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),c=i.map(d=>d.value),l=zr(s,i.length);for(let d=0;d<n.ins.length;d++){const g=n.hashForWitnessV1(d,l,c,o,a),x=await this.signer.signSchnorr(g);n.setWitness(d,[jn(x,o),jn(x,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){br(t.length>0,De.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const g of i)if(!t.find(x=>x.utxo===g.txid))throw new Error(De.counterPartySigNotFound(g.txid));const s=this.getOutputScript(),o=de.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(g=>g.value),l=zr(s,i.length);for(let g=0;g<n.ins.length;g++){const x=n.hashForWitnessV1(g,l,c,o,a);if(!er.verifySchnorr(x,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[g].sig,"hex")))throw new Error(De.invalidCounterpartySigForUTXO(t[g].utxo));const y=await this.signer.signSchnorr(x),O=Buffer.from(n.ins[g].hash).reverse().toString("hex"),B=t.find(A=>A.utxo===O);if(!B)throw new Error(De.counterPartySigNotFound(O));n.setWitness(g,[Buffer.from(B.sig,"hex"),y,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){br(de.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,De.secretMismatch);const{tx:i,usedUtxos:s}=await this._buildRawTx(r??await this.signer.getAddress(),n),o=this.leafHash(1),a=s.map(g=>g.value),c=zr(this.getOutputScript(),s.length),l=de.Transaction.SIGHASH_DEFAULT;for(let g=0;g<i.ins.length;g++){const x=i.hashForWitnessV1(g,c,a,l,o),y=await this.signer.signSchnorr(x);i.setWitness(g,[y,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(i.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(De.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(x=>x.value),l=zr(this.getOutputScript(),i.length),d=de.Transaction.SIGHASH_DEFAULT;for(let x=0;x<n.ins.length;x++){n.ins[x].sequence=this.expiry;const y=n.hashForWitnessV1(x,l,c,d,a),O=await this.signer.signSchnorr(y);n.setWitness(x,[O,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(De.invalidLeaf)}const n=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:Un}});if(!n.witness)throw new Error(De.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",du(r))}refundLeaf(){return de.script.fromASM(`
|
|
10
|
+
${de.script.number.encode(this.expiry).toString("hex")}
|
|
11
11
|
OP_CHECKSEQUENCEVERIFY
|
|
12
12
|
OP_DROP
|
|
13
13
|
${this.initiatorPubkey}
|
|
14
14
|
OP_CHECKSIG
|
|
15
|
-
`.trim().replace(/\s+/g," "))}redeemLeaf(){return
|
|
15
|
+
`.trim().replace(/\s+/g," "))}redeemLeaf(){return de.script.fromASM(`
|
|
16
16
|
OP_SHA256
|
|
17
17
|
${this.secretHash}
|
|
18
18
|
OP_EQUALVERIFY
|
|
19
19
|
${this.redeemerPubkey}
|
|
20
20
|
OP_CHECKSIG
|
|
21
|
-
`.trim().replace(/\s+/g," "))}instantRefundLeaf(){return
|
|
21
|
+
`.trim().replace(/\s+/g," "))}instantRefundLeaf(){return de.script.fromASM(`
|
|
22
22
|
${this.initiatorPubkey}
|
|
23
23
|
OP_CHECKSIG
|
|
24
24
|
${this.redeemerPubkey}
|
|
25
25
|
OP_CHECKSIGADD
|
|
26
26
|
OP_2
|
|
27
27
|
OP_NUMEQUAL
|
|
28
|
-
`.trim().replace(/\s+/g," "))}leaves(){return[{version:
|
|
29
|
-
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};
|
|
30
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var
|
|
31
|
-
Use Chrome, Firefox or Internet Explorer 11`)}var Th=Ge.Buffer,Vn=Ht.crypto||Ht.msCrypto;Vn&&Vn.getRandomValues?rs.exports=Ah:rs.exports=Ph;function Ah(e,t){if(e>Bh)throw new RangeError("requested too many random bytes");var r=Th.allocUnsafe(e);if(e>0)if(e>Li)for(var n=0;n<e;n+=Li)Vn.getRandomValues(r.slice(n,n+Li));else Vn.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Ih=rs.exports,is={exports:{}};typeof Object.create=="function"?is.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:is.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}};var Oe=is.exports,ss={exports:{}},Rs={exports:{}},Sr=typeof Reflect=="object"?Reflect:null,go=Sr&&typeof Sr.apply=="function"?Sr.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Mn;Sr&&typeof Sr.ownKeys=="function"?Mn=Sr.ownKeys:Object.getOwnPropertySymbols?Mn=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Mn=function(t){return Object.getOwnPropertyNames(t)};function Oh(e){console&&console.warn&&console.warn(e)}var $a=Number.isNaN||function(t){return t!==t};function re(){re.init.call(this)}Rs.exports=re;Rs.exports.once=Ch;re.EventEmitter=re;re.prototype._events=void 0;re.prototype._eventsCount=0;re.prototype._maxListeners=void 0;var mo=10;function fi(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(re,"defaultMaxListeners",{enumerable:!0,get:function(){return mo},set:function(e){if(typeof e!="number"||e<0||$a(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");mo=e}});re.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};re.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||$a(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 Da(e){return e._maxListeners===void 0?re.defaultMaxListeners:e._maxListeners}re.prototype.getMaxListeners=function(){return Da(this)};re.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=s[t];if(c===void 0)return!1;if(typeof c=="function")go(c,this,r);else for(var l=c.length,d=za(c,l),n=0;n<l;++n)go(d[n],this,r);return!0};function ja(e,t,r,n){var i,s,o;if(fi(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=Da(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,Oh(a)}return e}re.prototype.addListener=function(t,r){return ja(this,t,r,!1)};re.prototype.on=re.prototype.addListener;re.prototype.prependListener=function(t,r){return ja(this,t,r,!0)};function kh(){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 Ga(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=kh.bind(n);return i.listener=r,n.wrapFn=i,i}re.prototype.once=function(t,r){return fi(r),this.on(t,Ga(this,t,r)),this};re.prototype.prependOnceListener=function(t,r){return fi(r),this.prependListener(t,Ga(this,t,r)),this};re.prototype.removeListener=function(t,r){var n,i,s,o,a;if(fi(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():Rh(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};re.prototype.off=re.prototype.removeListener;re.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 Va(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?Uh(i):za(i,i.length)}re.prototype.listeners=function(t){return Va(this,t,!0)};re.prototype.rawListeners=function(t){return Va(this,t,!1)};re.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Wa.call(e,t)};re.prototype.listenerCount=Wa;function Wa(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}re.prototype.eventNames=function(){return this._eventsCount>0?Mn(this._events):[]};function za(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Rh(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Uh(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Ch(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))}qa(e,t,s,{once:!0}),t!=="error"&&Lh(e,i,{once:!0})})}function Lh(e,t,r){typeof e.on=="function"&&qa(e,"error",t,r)}function qa(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 Ka=Rs.exports,Ya=Ka.EventEmitter;const Nh={},Fh=Object.freeze(Object.defineProperty({__proto__:null,default:Nh},Symbol.toStringTag,{value:"Module"})),Us=na(Fh);var Ni,_o;function Mh(){if(_o)return Ni;_o=1;function e(O,B){var A=Object.keys(O);if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(O);B&&(k=k.filter(function(U){return Object.getOwnPropertyDescriptor(O,U).enumerable})),A.push.apply(A,k)}return A}function t(O){for(var B=1;B<arguments.length;B++){var A=arguments[B]!=null?arguments[B]:{};B%2?e(Object(A),!0).forEach(function(k){r(O,k,A[k])}):Object.getOwnPropertyDescriptors?Object.defineProperties(O,Object.getOwnPropertyDescriptors(A)):e(Object(A)).forEach(function(k){Object.defineProperty(O,k,Object.getOwnPropertyDescriptor(A,k))})}return O}function r(O,B,A){return B=o(B),B in O?Object.defineProperty(O,B,{value:A,enumerable:!0,configurable:!0,writable:!0}):O[B]=A,O}function n(O,B){if(!(O instanceof B))throw new TypeError("Cannot call a class as a function")}function i(O,B){for(var A=0;A<B.length;A++){var k=B[A];k.enumerable=k.enumerable||!1,k.configurable=!0,"value"in k&&(k.writable=!0),Object.defineProperty(O,o(k.key),k)}}function s(O,B,A){return B&&i(O.prototype,B),Object.defineProperty(O,"prototype",{writable:!1}),O}function o(O){var B=a(O,"string");return typeof B=="symbol"?B:String(B)}function a(O,B){if(typeof O!="object"||O===null)return O;var A=O[Symbol.toPrimitive];if(A!==void 0){var k=A.call(O,B||"default");if(typeof k!="object")return k;throw new TypeError("@@toPrimitive must return a primitive value.")}return(B==="string"?String:Number)(O)}var c=Pt,l=c.Buffer,d=Us,g=d.inspect,x=g&&g.custom||"inspect";function y(O,B,A){l.prototype.copy.call(O,B,A)}return Ni=function(){function O(){n(this,O),this.head=null,this.tail=null,this.length=0}return s(O,[{key:"push",value:function(A){var k={data:A,next:null};this.length>0?this.tail.next=k:this.head=k,this.tail=k,++this.length}},{key:"unshift",value:function(A){var k={data:A,next:this.head};this.length===0&&(this.tail=k),this.head=k,++this.length}},{key:"shift",value:function(){if(this.length!==0){var A=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,A}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(A){if(this.length===0)return"";for(var k=this.head,U=""+k.data;k=k.next;)U+=A+k.data;return U}},{key:"concat",value:function(A){if(this.length===0)return l.alloc(0);for(var k=l.allocUnsafe(A>>>0),U=this.head,_=0;U;)y(U.data,k,_),_+=U.data.length,U=U.next;return k}},{key:"consume",value:function(A,k){var U;return A<this.head.data.length?(U=this.head.data.slice(0,A),this.head.data=this.head.data.slice(A)):A===this.head.data.length?U=this.shift():U=k?this._getString(A):this._getBuffer(A),U}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(A){var k=this.head,U=1,_=k.data;for(A-=_.length;k=k.next;){var m=k.data,S=A>m.length?m.length:A;if(S===m.length?_+=m:_+=m.slice(0,A),A-=S,A===0){S===m.length?(++U,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=m.slice(S));break}++U}return this.length-=U,_}},{key:"_getBuffer",value:function(A){var k=l.allocUnsafe(A),U=this.head,_=1;for(U.data.copy(k),A-=U.data.length;U=U.next;){var m=U.data,S=A>m.length?m.length:A;if(m.copy(k,k.length-A,0,S),A-=S,A===0){S===m.length?(++_,U.next?this.head=U.next:this.head=this.tail=null):(this.head=U,U.data=m.slice(S));break}++_}return this.length-=_,k}},{key:x,value:function(A,k){return g(this,t(t({},k),{},{depth:0,customInspect:!1}))}}]),O}(),Ni}function Hh(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(os,this,e)):process.nextTick(os,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(Hn,r):(r._writableState.errorEmitted=!0,process.nextTick(Eo,r,s)):process.nextTick(Eo,r,s):t?(process.nextTick(Hn,r),t(s)):process.nextTick(Hn,r)}),this)}function Eo(e,t){os(e,t),Hn(e)}function Hn(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function $h(){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 os(e,t){e.emit("error",t)}function Dh(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var Xa={destroy:Hh,undestroy:$h,errorOrDestroy:Dh},ar={};function jh(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Ja={};function Qe(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){jh(o,s);function o(a,c,l){return s.call(this,n(a,c,l))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,Ja[e]=i}function vo(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 Gh(e,t,r){return e.substr(0,t.length)===t}function Vh(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Wh(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Qe("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Qe("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&Gh(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(Vh(e," argument"))i="The ".concat(e," ").concat(n," ").concat(vo(t,"type"));else{var s=Wh(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(vo(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Qe("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Qe("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Qe("ERR_STREAM_PREMATURE_CLOSE","Premature close");Qe("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Qe("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Qe("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Qe("ERR_STREAM_WRITE_AFTER_END","write after end");Qe("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Qe("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Qe("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");ar.codes=Ja;var zh=ar.codes.ERR_INVALID_OPT_VALUE;function qh(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function Kh(e,t,r,n){var i=qh(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new zh(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var Qa={getHighWaterMark:Kh},Yh=Xh;function Xh(e,t){if(Fi("noDeprecation"))return e;var r=!1;function n(){if(!r){if(Fi("throwDeprecation"))throw new Error(t);Fi("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function Fi(e){try{if(!Ht.localStorage)return!1}catch{return!1}var t=Ht.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Mi,xo;function Za(){if(xo)return Mi;xo=1,Mi=j;function e(T){var P=this;this.next=null,this.entry=null,this.finish=function(){dt(P,T)}}var t;j.WritableState=v;var r={deprecate:Yh},n=Ya,i=Pt.Buffer,s=(typeof Ht<"u"?Ht:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(T){return i.from(T)}function a(T){return i.isBuffer(T)||T instanceof s}var c=Xa,l=Qa,d=l.getHighWaterMark,g=ar.codes,x=g.ERR_INVALID_ARG_TYPE,y=g.ERR_METHOD_NOT_IMPLEMENTED,O=g.ERR_MULTIPLE_CALLBACK,B=g.ERR_STREAM_CANNOT_PIPE,A=g.ERR_STREAM_DESTROYED,k=g.ERR_STREAM_NULL_VALUES,U=g.ERR_STREAM_WRITE_AFTER_END,_=g.ERR_UNKNOWN_ENCODING,m=c.errorOrDestroy;Oe(j,n);function S(){}function v(T,P,M){t=t||kr(),T=T||{},typeof M!="boolean"&&(M=P instanceof t),this.objectMode=!!T.objectMode,M&&(this.objectMode=this.objectMode||!!T.writableObjectMode),this.highWaterMark=d(this,T,"writableHighWaterMark",M),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var G=T.decodeStrings===!1;this.decodeStrings=!G,this.defaultEncoding=T.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(K){oe(P,K)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=T.emitClose!==!1,this.autoDestroy=!!T.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}v.prototype.getBuffer=function(){for(var P=this.bufferedRequest,M=[];P;)M.push(P),P=P.next;return M},function(){try{Object.defineProperty(v.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var $;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?($=Function.prototype[Symbol.hasInstance],Object.defineProperty(j,Symbol.hasInstance,{value:function(P){return $.call(this,P)?!0:this!==j?!1:P&&P._writableState instanceof v}})):$=function(P){return P instanceof this};function j(T){t=t||kr();var P=this instanceof t;if(!P&&!$.call(j,this))return new j(T);this._writableState=new v(T,this,P),this.writable=!0,T&&(typeof T.write=="function"&&(this._write=T.write),typeof T.writev=="function"&&(this._writev=T.writev),typeof T.destroy=="function"&&(this._destroy=T.destroy),typeof T.final=="function"&&(this._final=T.final)),n.call(this)}j.prototype.pipe=function(){m(this,new B)};function R(T,P){var M=new U;m(T,M),process.nextTick(P,M)}function z(T,P,M,G){var K;return M===null?K=new k:typeof M!="string"&&!P.objectMode&&(K=new x("chunk",["string","Buffer"],M)),K?(m(T,K),process.nextTick(G,K),!1):!0}j.prototype.write=function(T,P,M){var G=this._writableState,K=!1,b=!G.objectMode&&a(T);return b&&!i.isBuffer(T)&&(T=o(T)),typeof P=="function"&&(M=P,P=null),b?P="buffer":P||(P=G.defaultEncoding),typeof M!="function"&&(M=S),G.ending?R(this,M):(b||z(this,G,T,M))&&(G.pendingcb++,K=C(this,G,b,T,P,M)),K},j.prototype.cork=function(){this._writableState.corked++},j.prototype.uncork=function(){var T=this._writableState;T.corked&&(T.corked--,!T.writing&&!T.corked&&!T.bufferProcessing&&T.bufferedRequest&&Ve(this,T))},j.prototype.setDefaultEncoding=function(P){if(typeof P=="string"&&(P=P.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((P+"").toLowerCase())>-1))throw new _(P);return this._writableState.defaultEncoding=P,this},Object.defineProperty(j.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Z(T,P,M){return!T.objectMode&&T.decodeStrings!==!1&&typeof P=="string"&&(P=i.from(P,M)),P}Object.defineProperty(j.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function C(T,P,M,G,K,b){if(!M){var w=Z(P,G,K);G!==w&&(M=!0,K="buffer",G=w)}var F=P.objectMode?1:G.length;P.length+=F;var D=P.length<P.highWaterMark;if(D||(P.needDrain=!0),P.writing||P.corked){var pe=P.lastBufferedRequest;P.lastBufferedRequest={chunk:G,encoding:K,isBuf:M,callback:b,next:null},pe?pe.next=P.lastBufferedRequest:P.bufferedRequest=P.lastBufferedRequest,P.bufferedRequestCount+=1}else H(T,P,!1,F,G,K,b);return D}function H(T,P,M,G,K,b,w){P.writelen=G,P.writecb=w,P.writing=!0,P.sync=!0,P.destroyed?P.onwrite(new A("write")):M?T._writev(K,P.onwrite):T._write(K,b,P.onwrite),P.sync=!1}function V(T,P,M,G,K){--P.pendingcb,M?(process.nextTick(K,G),process.nextTick(We,T,P),T._writableState.errorEmitted=!0,m(T,G)):(K(G),T._writableState.errorEmitted=!0,m(T,G),We(T,P))}function q(T){T.writing=!1,T.writecb=null,T.length-=T.writelen,T.writelen=0}function oe(T,P){var M=T._writableState,G=M.sync,K=M.writecb;if(typeof K!="function")throw new O;if(q(M),P)V(T,M,G,P,K);else{var b=nt(M)||T.destroyed;!b&&!M.corked&&!M.bufferProcessing&&M.bufferedRequest&&Ve(T,M),G?process.nextTick(ae,T,M,b,K):ae(T,M,b,K)}}function ae(T,P,M,G){M||Ze(T,P),P.pendingcb--,G(),We(T,P)}function Ze(T,P){P.length===0&&P.needDrain&&(P.needDrain=!1,T.emit("drain"))}function Ve(T,P){P.bufferProcessing=!0;var M=P.bufferedRequest;if(T._writev&&M&&M.next){var G=P.bufferedRequestCount,K=new Array(G),b=P.corkedRequestsFree;b.entry=M;for(var w=0,F=!0;M;)K[w]=M,M.isBuf||(F=!1),M=M.next,w+=1;K.allBuffers=F,H(T,P,!0,P.length,K,"",b.finish),P.pendingcb++,P.lastBufferedRequest=null,b.next?(P.corkedRequestsFree=b.next,b.next=null):P.corkedRequestsFree=new e(P),P.bufferedRequestCount=0}else{for(;M;){var D=M.chunk,pe=M.encoding,Y=M.callback,te=P.objectMode?1:D.length;if(H(T,P,!1,te,D,pe,Y),M=M.next,P.bufferedRequestCount--,P.writing)break}M===null&&(P.lastBufferedRequest=null)}P.bufferedRequest=M,P.bufferProcessing=!1}j.prototype._write=function(T,P,M){M(new y("_write()"))},j.prototype._writev=null,j.prototype.end=function(T,P,M){var G=this._writableState;return typeof T=="function"?(M=T,T=null,P=null):typeof P=="function"&&(M=P,P=null),T!=null&&this.write(T,P),G.corked&&(G.corked=1,this.uncork()),G.ending||Tt(this,G,M),this},Object.defineProperty(j.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function nt(T){return T.ending&&T.length===0&&T.bufferedRequest===null&&!T.finished&&!T.writing}function de(T,P){T._final(function(M){P.pendingcb--,M&&m(T,M),P.prefinished=!0,T.emit("prefinish"),We(T,P)})}function ve(T,P){!P.prefinished&&!P.finalCalled&&(typeof T._final=="function"&&!P.destroyed?(P.pendingcb++,P.finalCalled=!0,process.nextTick(de,T,P)):(P.prefinished=!0,T.emit("prefinish")))}function We(T,P){var M=nt(P);if(M&&(ve(T,P),P.pendingcb===0&&(P.finished=!0,T.emit("finish"),P.autoDestroy))){var G=T._readableState;(!G||G.autoDestroy&&G.endEmitted)&&T.destroy()}return M}function Tt(T,P,M){P.ending=!0,We(T,P),M&&(P.finished?process.nextTick(M):T.once("finish",M)),P.ended=!0,T.writable=!1}function dt(T,P,M){var G=T.entry;for(T.entry=null;G;){var K=G.callback;P.pendingcb--,K(M),G=G.next}P.corkedRequestsFree.next=T}return Object.defineProperty(j.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(P){this._writableState&&(this._writableState.destroyed=P)}}),j.prototype.destroy=c.destroy,j.prototype._undestroy=c.undestroy,j.prototype._destroy=function(T,P){P(T)},Mi}var Hi,So;function kr(){if(So)return Hi;So=1;var e=Object.keys||function(l){var d=[];for(var g in l)d.push(g);return d};Hi=o;var t=tf(),r=Za();Oe(o,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var s=n[i];o.prototype[s]||(o.prototype[s]=r.prototype[s])}function o(l){if(!(this instanceof o))return new o(l);t.call(this,l),r.call(this,l),this.allowHalfOpen=!0,l&&(l.readable===!1&&(this.readable=!1),l.writable===!1&&(this.writable=!1),l.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",a)))}Object.defineProperty(o.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(o.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(o.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function a(){this._writableState.ended||process.nextTick(c,this)}function c(l){l.end()}return Object.defineProperty(o.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(d){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=d,this._writableState.destroyed=d)}}),Hi}var Wn={},Cs=Ge.Buffer,Bo=Cs.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 Jh(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 Qh(e){var t=Jh(e);if(typeof t!="string"&&(Cs.isEncoding===Bo||!Bo(e)))throw new Error("Unknown encoding: "+e);return t||e}Wn.StringDecoder=yn;function yn(e){this.encoding=Qh(e);var t;switch(this.encoding){case"utf16le":this.text=il,this.end=sl,t=4;break;case"utf8":this.fillLast=tl,t=4;break;case"base64":this.text=ol,this.end=al,t=3;break;default:this.write=fl,this.end=ul;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Cs.allocUnsafe(t)}yn.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||""};yn.prototype.end=nl;yn.prototype.text=rl;yn.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 $i(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Zh(e,t,r){var n=t.length-1;if(n<r)return 0;var i=$i(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=$i(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=$i(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function el(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 tl(e){var t=this.lastTotal-this.lastNeed,r=el(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 rl(e,t){var r=Zh(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 nl(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function il(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 sl(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 ol(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 al(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function fl(e){return e.toString(this.encoding)}function ul(e){return e&&e.length?this.write(e):""}var Po=ar.codes.ERR_STREAM_PREMATURE_CLOSE;function cl(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 hl(){}function ll(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=cl(r||hl);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||a()},o=e._writableState&&e._writableState.finished,a=function(){i=!1,o=!0,n||r.call(e)},c=e._readableState&&e._readableState.endEmitted,l=function(){n=!1,c=!0,i||r.call(e)},d=function(O){r.call(e,O)},g=function(){var O;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(O=new Po),r.call(e,O);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(O=new Po),r.call(e,O)},x=function(){e.req.on("finish",a)};return ll(e)?(e.on("complete",a),e.on("abort",g),e.req?x():e.on("request",x)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",l),e.on("finish",a),t.error!==!1&&e.on("error",d),e.on("close",g),function(){e.removeListener("complete",a),e.removeListener("abort",g),e.removeListener("request",x),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",l),e.removeListener("error",d),e.removeListener("close",g)}}var Ls=ef,Di,To;function dl(){if(To)return Di;To=1;var e;function t(_,m,S){return m=r(m),m in _?Object.defineProperty(_,m,{value:S,enumerable:!0,configurable:!0,writable:!0}):_[m]=S,_}function r(_){var m=n(_,"string");return typeof m=="symbol"?m:String(m)}function n(_,m){if(typeof _!="object"||_===null)return _;var S=_[Symbol.toPrimitive];if(S!==void 0){var v=S.call(_,m||"default");if(typeof v!="object")return v;throw new TypeError("@@toPrimitive must return a primitive value.")}return(m==="string"?String:Number)(_)}var i=Ls,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),l=Symbol("lastPromise"),d=Symbol("handlePromise"),g=Symbol("stream");function x(_,m){return{value:_,done:m}}function y(_){var m=_[s];if(m!==null){var S=_[g].read();S!==null&&(_[l]=null,_[s]=null,_[o]=null,m(x(S,!1)))}}function O(_){process.nextTick(y,_)}function B(_,m){return function(S,v){_.then(function(){if(m[c]){S(x(void 0,!0));return}m[d](S,v)},v)}}var A=Object.getPrototypeOf(function(){}),k=Object.setPrototypeOf((e={get stream(){return this[g]},next:function(){var m=this,S=this[a];if(S!==null)return Promise.reject(S);if(this[c])return Promise.resolve(x(void 0,!0));if(this[g].destroyed)return new Promise(function(R,z){process.nextTick(function(){m[a]?z(m[a]):R(x(void 0,!0))})});var v=this[l],$;if(v)$=new Promise(B(v,this));else{var j=this[g].read();if(j!==null)return Promise.resolve(x(j,!1));$=new Promise(this[d])}return this[l]=$,$}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var m=this;return new Promise(function(S,v){m[g].destroy(null,function($){if($){v($);return}S(x(void 0,!0))})})}),e),A),U=function(m){var S,v=Object.create(k,(S={},t(S,g,{value:m,writable:!0}),t(S,s,{value:null,writable:!0}),t(S,o,{value:null,writable:!0}),t(S,a,{value:null,writable:!0}),t(S,c,{value:m._readableState.endEmitted,writable:!0}),t(S,d,{value:function(j,R){var z=v[g].read();z?(v[l]=null,v[s]=null,v[o]=null,j(x(z,!1))):(v[s]=j,v[o]=R)},writable:!0}),S));return v[l]=null,i(m,function($){if($&&$.code!=="ERR_STREAM_PREMATURE_CLOSE"){var j=v[o];j!==null&&(v[l]=null,v[s]=null,v[o]=null,j($)),v[a]=$;return}var R=v[s];R!==null&&(v[l]=null,v[s]=null,v[o]=null,R(x(void 0,!0))),v[c]=!0}),m.on("readable",O.bind(null,v)),v};return Di=U,Di}var ji,Ao;function pl(){return Ao||(Ao=1,ji=function(){throw new Error("Readable.from is not available in the browser")}),ji}var Gi,Io;function tf(){if(Io)return Gi;Io=1,Gi=R;var e;R.ReadableState=j,Ka.EventEmitter;var t=function(w,F){return w.listeners(F).length},r=Ya,n=Pt.Buffer,i=(typeof Ht<"u"?Ht: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=Us,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var l=Mh(),d=Xa,g=Qa,x=g.getHighWaterMark,y=ar.codes,O=y.ERR_INVALID_ARG_TYPE,B=y.ERR_STREAM_PUSH_AFTER_EOF,A=y.ERR_METHOD_NOT_IMPLEMENTED,k=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,U,_,m;Oe(R,r);var S=d.errorOrDestroy,v=["error","close","destroy","pause","resume"];function $(b,w,F){if(typeof b.prependListener=="function")return b.prependListener(w,F);!b._events||!b._events[w]?b.on(w,F):Array.isArray(b._events[w])?b._events[w].unshift(F):b._events[w]=[F,b._events[w]]}function j(b,w,F){e=e||kr(),b=b||{},typeof F!="boolean"&&(F=w instanceof e),this.objectMode=!!b.objectMode,F&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=x(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&&(U||(U=Wn.StringDecoder),this.decoder=new U(b.encoding),this.encoding=b.encoding)}function R(b){if(e=e||kr(),!(this instanceof R))return new R(b);var w=this instanceof e;this._readableState=new j(b,this,w),this.readable=!0,b&&(typeof b.read=="function"&&(this._read=b.read),typeof b.destroy=="function"&&(this._destroy=b.destroy)),r.call(this)}Object.defineProperty(R.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(w){this._readableState&&(this._readableState.destroyed=w)}}),R.prototype.destroy=d.destroy,R.prototype._undestroy=d.undestroy,R.prototype._destroy=function(b,w){w(b)},R.prototype.push=function(b,w){var F=this._readableState,D;return F.objectMode?D=!0:typeof b=="string"&&(w=w||F.defaultEncoding,w!==F.encoding&&(b=n.from(b,w),w=""),D=!0),z(this,b,w,!1,D)},R.prototype.unshift=function(b){return z(this,b,null,!0,!1)};function z(b,w,F,D,pe){c("readableAddChunk",w);var Y=b._readableState;if(w===null)Y.reading=!1,oe(b,Y);else{var te;if(pe||(te=C(Y,w)),te)S(b,te);else if(Y.objectMode||w&&w.length>0)if(typeof w!="string"&&!Y.objectMode&&Object.getPrototypeOf(w)!==n.prototype&&(w=s(w)),D)Y.endEmitted?S(b,new k):Z(b,Y,w,!0);else if(Y.ended)S(b,new B);else{if(Y.destroyed)return!1;Y.reading=!1,Y.decoder&&!F?(w=Y.decoder.write(w),Y.objectMode||w.length!==0?Z(b,Y,w,!1):Ve(b,Y)):Z(b,Y,w,!1)}else D||(Y.reading=!1,Ve(b,Y))}return!Y.ended&&(Y.length<Y.highWaterMark||Y.length===0)}function Z(b,w,F,D){w.flowing&&w.length===0&&!w.sync?(w.awaitDrain=0,b.emit("data",F)):(w.length+=w.objectMode?1:F.length,D?w.buffer.unshift(F):w.buffer.push(F),w.needReadable&&ae(b)),Ve(b,w)}function C(b,w){var F;return!o(w)&&typeof w!="string"&&w!==void 0&&!b.objectMode&&(F=new O("chunk",["string","Buffer","Uint8Array"],w)),F}R.prototype.isPaused=function(){return this._readableState.flowing===!1},R.prototype.setEncoding=function(b){U||(U=Wn.StringDecoder);var w=new U(b);this._readableState.decoder=w,this._readableState.encoding=this._readableState.decoder.encoding;for(var F=this._readableState.buffer.head,D="";F!==null;)D+=w.write(F.data),F=F.next;return this._readableState.buffer.clear(),D!==""&&this._readableState.buffer.push(D),this._readableState.length=D.length,this};var H=1073741824;function V(b){return b>=H?b=H:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function q(b,w){return b<=0||w.length===0&&w.ended?0:w.objectMode?1:b!==b?w.flowing&&w.length?w.buffer.head.data.length:w.length:(b>w.highWaterMark&&(w.highWaterMark=V(b)),b<=w.length?b:w.ended?w.length:(w.needReadable=!0,0))}R.prototype.read=function(b){c("read",b),b=parseInt(b,10);var w=this._readableState,F=b;if(b!==0&&(w.emittedReadable=!1),b===0&&w.needReadable&&((w.highWaterMark!==0?w.length>=w.highWaterMark:w.length>0)||w.ended))return c("read: emitReadable",w.length,w.ended),w.length===0&&w.ended?M(this):ae(this),null;if(b=q(b,w),b===0&&w.ended)return w.length===0&&M(this),null;var D=w.needReadable;c("need readable",D),(w.length===0||w.length-b<w.highWaterMark)&&(D=!0,c("length less than watermark",D)),w.ended||w.reading?(D=!1,c("reading or ended",D)):D&&(c("do read"),w.reading=!0,w.sync=!0,w.length===0&&(w.needReadable=!0),this._read(w.highWaterMark),w.sync=!1,w.reading||(b=q(F,w)));var pe;return b>0?pe=P(b,w):pe=null,pe===null?(w.needReadable=w.length<=w.highWaterMark,b=0):(w.length-=b,w.awaitDrain=0),w.length===0&&(w.ended||(w.needReadable=!0),F!==b&&w.ended&&M(this)),pe!==null&&this.emit("data",pe),pe};function oe(b,w){if(c("onEofChunk"),!w.ended){if(w.decoder){var F=w.decoder.end();F&&F.length&&(w.buffer.push(F),w.length+=w.objectMode?1:F.length)}w.ended=!0,w.sync?ae(b):(w.needReadable=!1,w.emittedReadable||(w.emittedReadable=!0,Ze(b)))}}function ae(b){var w=b._readableState;c("emitReadable",w.needReadable,w.emittedReadable),w.needReadable=!1,w.emittedReadable||(c("emitReadable",w.flowing),w.emittedReadable=!0,process.nextTick(Ze,b))}function Ze(b){var w=b._readableState;c("emitReadable_",w.destroyed,w.length,w.ended),!w.destroyed&&(w.length||w.ended)&&(b.emit("readable"),w.emittedReadable=!1),w.needReadable=!w.flowing&&!w.ended&&w.length<=w.highWaterMark,T(b)}function Ve(b,w){w.readingMore||(w.readingMore=!0,process.nextTick(nt,b,w))}function nt(b,w){for(;!w.reading&&!w.ended&&(w.length<w.highWaterMark||w.flowing&&w.length===0);){var F=w.length;if(c("maybeReadMore read 0"),b.read(0),F===w.length)break}w.readingMore=!1}R.prototype._read=function(b){S(this,new A("_read()"))},R.prototype.pipe=function(b,w){var F=this,D=this._readableState;switch(D.pipesCount){case 0:D.pipes=b;break;case 1:D.pipes=[D.pipes,b];break;default:D.pipes.push(b);break}D.pipesCount+=1,c("pipe count=%d opts=%j",D.pipesCount,w);var pe=(!w||w.end!==!1)&&b!==process.stdout&&b!==process.stderr,Y=pe?At:zt;D.endEmitted?process.nextTick(Y):F.once("end",Y),b.on("unpipe",te);function te(h,f){c("onunpipe"),h===F&&f&&f.hasUnpiped===!1&&(f.hasUnpiped=!0,hr())}function At(){c("onend"),b.end()}var cr=de(F);b.on("drain",cr);var Nr=!1;function hr(){c("cleanup"),b.removeListener("close",Fr),b.removeListener("finish",Ye),b.removeListener("drain",cr),b.removeListener("error",Wt),b.removeListener("unpipe",te),F.removeListener("end",At),F.removeListener("end",zt),F.removeListener("data",ze),Nr=!0,D.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&cr()}F.on("data",ze);function ze(h){c("ondata");var f=b.write(h);c("dest.write",f),f===!1&&((D.pipesCount===1&&D.pipes===b||D.pipesCount>1&&K(D.pipes,b)!==-1)&&!Nr&&(c("false write response, pause",D.awaitDrain),D.awaitDrain++),F.pause())}function Wt(h){c("onerror",h),zt(),b.removeListener("error",Wt),t(b,"error")===0&&S(b,h)}$(b,"error",Wt);function Fr(){b.removeListener("finish",Ye),zt()}b.once("close",Fr);function Ye(){c("onfinish"),b.removeListener("close",Fr),zt()}b.once("finish",Ye);function zt(){c("unpipe"),F.unpipe(b)}return b.emit("pipe",F),D.flowing||(c("pipe resume"),F.resume()),b};function de(b){return function(){var F=b._readableState;c("pipeOnDrain",F.awaitDrain),F.awaitDrain&&F.awaitDrain--,F.awaitDrain===0&&t(b,"data")&&(F.flowing=!0,T(b))}}R.prototype.unpipe=function(b){var w=this._readableState,F={hasUnpiped:!1};if(w.pipesCount===0)return this;if(w.pipesCount===1)return b&&b!==w.pipes?this:(b||(b=w.pipes),w.pipes=null,w.pipesCount=0,w.flowing=!1,b&&b.emit("unpipe",this,F),this);if(!b){var D=w.pipes,pe=w.pipesCount;w.pipes=null,w.pipesCount=0,w.flowing=!1;for(var Y=0;Y<pe;Y++)D[Y].emit("unpipe",this,{hasUnpiped:!1});return this}var te=K(w.pipes,b);return te===-1?this:(w.pipes.splice(te,1),w.pipesCount-=1,w.pipesCount===1&&(w.pipes=w.pipes[0]),b.emit("unpipe",this,F),this)},R.prototype.on=function(b,w){var F=r.prototype.on.call(this,b,w),D=this._readableState;return b==="data"?(D.readableListening=this.listenerCount("readable")>0,D.flowing!==!1&&this.resume()):b==="readable"&&!D.endEmitted&&!D.readableListening&&(D.readableListening=D.needReadable=!0,D.flowing=!1,D.emittedReadable=!1,c("on readable",D.length,D.reading),D.length?ae(this):D.reading||process.nextTick(We,this)),F},R.prototype.addListener=R.prototype.on,R.prototype.removeListener=function(b,w){var F=r.prototype.removeListener.call(this,b,w);return b==="readable"&&process.nextTick(ve,this),F},R.prototype.removeAllListeners=function(b){var w=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(ve,this),w};function ve(b){var w=b._readableState;w.readableListening=b.listenerCount("readable")>0,w.resumeScheduled&&!w.paused?w.flowing=!0:b.listenerCount("data")>0&&b.resume()}function We(b){c("readable nexttick read 0"),b.read(0)}R.prototype.resume=function(){var b=this._readableState;return b.flowing||(c("resume"),b.flowing=!b.readableListening,Tt(this,b)),b.paused=!1,this};function Tt(b,w){w.resumeScheduled||(w.resumeScheduled=!0,process.nextTick(dt,b,w))}function dt(b,w){c("resume",w.reading),w.reading||b.read(0),w.resumeScheduled=!1,b.emit("resume"),T(b),w.flowing&&!w.reading&&b.read(0)}R.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function T(b){var w=b._readableState;for(c("flow",w.flowing);w.flowing&&b.read()!==null;);}R.prototype.wrap=function(b){var w=this,F=this._readableState,D=!1;b.on("end",function(){if(c("wrapped end"),F.decoder&&!F.ended){var te=F.decoder.end();te&&te.length&&w.push(te)}w.push(null)}),b.on("data",function(te){if(c("wrapped data"),F.decoder&&(te=F.decoder.write(te)),!(F.objectMode&&te==null)&&!(!F.objectMode&&(!te||!te.length))){var At=w.push(te);At||(D=!0,b.pause())}});for(var pe in b)this[pe]===void 0&&typeof b[pe]=="function"&&(this[pe]=function(At){return function(){return b[At].apply(b,arguments)}}(pe));for(var Y=0;Y<v.length;Y++)b.on(v[Y],this.emit.bind(this,v[Y]));return this._read=function(te){c("wrapped _read",te),D&&(D=!1,b.resume())},this},typeof Symbol=="function"&&(R.prototype[Symbol.asyncIterator]=function(){return _===void 0&&(_=dl()),_(this)}),Object.defineProperty(R.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(R.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(R.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(w){this._readableState&&(this._readableState.flowing=w)}}),R._fromList=P,Object.defineProperty(R.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function P(b,w){if(w.length===0)return null;var F;return w.objectMode?F=w.buffer.shift():!b||b>=w.length?(w.decoder?F=w.buffer.join(""):w.buffer.length===1?F=w.buffer.first():F=w.buffer.concat(w.length),w.buffer.clear()):F=w.buffer.consume(b,w.decoder),F}function M(b){var w=b._readableState;c("endReadable",w.endEmitted),w.endEmitted||(w.ended=!0,process.nextTick(G,w,b))}function G(b,w){if(c("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,w.readable=!1,w.emit("end"),b.autoDestroy)){var F=w._writableState;(!F||F.autoDestroy&&F.finished)&&w.destroy()}}typeof Symbol=="function"&&(R.from=function(b,w){return m===void 0&&(m=pl()),m(R,b,w)});function K(b,w){for(var F=0,D=b.length;F<D;F++)if(b[F]===w)return F;return-1}return Gi}var rf=Bt,ui=ar.codes,yl=ui.ERR_METHOD_NOT_IMPLEMENTED,bl=ui.ERR_MULTIPLE_CALLBACK,wl=ui.ERR_TRANSFORM_ALREADY_TRANSFORMING,gl=ui.ERR_TRANSFORM_WITH_LENGTH_0,ci=kr();Oe(Bt,ci);function ml(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new bl);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Bt(e){if(!(this instanceof Bt))return new Bt(e);ci.call(this,e),this._transformState={afterTransform:ml.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",_l)}function _l(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Oo(e,t,r)}):Oo(this,null,null)}Bt.prototype.push=function(e,t){return this._transformState.needTransform=!1,ci.prototype.push.call(this,e,t)};Bt.prototype._transform=function(e,t,r){r(new yl("_transform()"))};Bt.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}};Bt.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};Bt.prototype._destroy=function(e,t){ci.prototype._destroy.call(this,e,function(r){t(r)})};function Oo(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new gl;if(e._transformState.transforming)throw new wl;return e.push(null)}var El=cn,nf=rf;Oe(cn,nf);function cn(e){if(!(this instanceof cn))return new cn(e);nf.call(this,e)}cn.prototype._transform=function(e,t,r){r(null,e)};var Vi;function vl(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var sf=ar.codes,xl=sf.ERR_MISSING_ARGS,Sl=sf.ERR_STREAM_DESTROYED;function ko(e){if(e)throw e}function Bl(e){return e.setHeader&&typeof e.abort=="function"}function Pl(e,t,r,n){n=vl(n);var i=!1;e.on("close",function(){i=!0}),Vi===void 0&&(Vi=Ls),Vi(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,Bl(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new Sl("pipe"))}}}function Ro(e){e()}function Tl(e,t){return e.pipe(t)}function Al(e){return!e.length||typeof e[e.length-1]!="function"?ko:e.pop()}function Il(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=Al(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new xl("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,l=a>0;return Pl(o,c,l,function(d){i||(i=d),d&&s.forEach(Ro),!c&&(s.forEach(Ro),n(i))})});return t.reduce(Tl)}var Ol=Il;(function(e,t){t=e.exports=tf(),t.Stream=t,t.Readable=t,t.Writable=Za(),t.Duplex=kr(),t.Transform=rf,t.PassThrough=El,t.finished=Ls,t.pipeline=Ol})(ss,ss.exports);var of=ss.exports,zn=Ge.Buffer,af=of.Transform,kl=Oe;function Rl(e,t){if(!zn.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function jt(e){af.call(this),this._block=zn.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}kl(jt,af);jt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};jt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};jt.prototype.update=function(e,t){if(Rl(e,"Data"),this._finalized)throw new Error("Digest already called");zn.isBuffer(e)||(e=zn.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};jt.prototype._update=function(){throw new Error("_update is not implemented")};jt.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};jt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Ul=jt,Cl=Oe,ff=Ul,Ll=Ge.Buffer,Nl=new Array(16);function hi(){ff.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}Cl(hi,ff);hi.prototype._update=function(){for(var e=Nl,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=ke(r,n,i,s,e[0],3614090360,7),s=ke(s,r,n,i,e[1],3905402710,12),i=ke(i,s,r,n,e[2],606105819,17),n=ke(n,i,s,r,e[3],3250441966,22),r=ke(r,n,i,s,e[4],4118548399,7),s=ke(s,r,n,i,e[5],1200080426,12),i=ke(i,s,r,n,e[6],2821735955,17),n=ke(n,i,s,r,e[7],4249261313,22),r=ke(r,n,i,s,e[8],1770035416,7),s=ke(s,r,n,i,e[9],2336552879,12),i=ke(i,s,r,n,e[10],4294925233,17),n=ke(n,i,s,r,e[11],2304563134,22),r=ke(r,n,i,s,e[12],1804603682,7),s=ke(s,r,n,i,e[13],4254626195,12),i=ke(i,s,r,n,e[14],2792965006,17),n=ke(n,i,s,r,e[15],1236535329,22),r=Re(r,n,i,s,e[1],4129170786,5),s=Re(s,r,n,i,e[6],3225465664,9),i=Re(i,s,r,n,e[11],643717713,14),n=Re(n,i,s,r,e[0],3921069994,20),r=Re(r,n,i,s,e[5],3593408605,5),s=Re(s,r,n,i,e[10],38016083,9),i=Re(i,s,r,n,e[15],3634488961,14),n=Re(n,i,s,r,e[4],3889429448,20),r=Re(r,n,i,s,e[9],568446438,5),s=Re(s,r,n,i,e[14],3275163606,9),i=Re(i,s,r,n,e[3],4107603335,14),n=Re(n,i,s,r,e[8],1163531501,20),r=Re(r,n,i,s,e[13],2850285829,5),s=Re(s,r,n,i,e[2],4243563512,9),i=Re(i,s,r,n,e[7],1735328473,14),n=Re(n,i,s,r,e[12],2368359562,20),r=Ue(r,n,i,s,e[5],4294588738,4),s=Ue(s,r,n,i,e[8],2272392833,11),i=Ue(i,s,r,n,e[11],1839030562,16),n=Ue(n,i,s,r,e[14],4259657740,23),r=Ue(r,n,i,s,e[1],2763975236,4),s=Ue(s,r,n,i,e[4],1272893353,11),i=Ue(i,s,r,n,e[7],4139469664,16),n=Ue(n,i,s,r,e[10],3200236656,23),r=Ue(r,n,i,s,e[13],681279174,4),s=Ue(s,r,n,i,e[0],3936430074,11),i=Ue(i,s,r,n,e[3],3572445317,16),n=Ue(n,i,s,r,e[6],76029189,23),r=Ue(r,n,i,s,e[9],3654602809,4),s=Ue(s,r,n,i,e[12],3873151461,11),i=Ue(i,s,r,n,e[15],530742520,16),n=Ue(n,i,s,r,e[2],3299628645,23),r=Ce(r,n,i,s,e[0],4096336452,6),s=Ce(s,r,n,i,e[7],1126891415,10),i=Ce(i,s,r,n,e[14],2878612391,15),n=Ce(n,i,s,r,e[5],4237533241,21),r=Ce(r,n,i,s,e[12],1700485571,6),s=Ce(s,r,n,i,e[3],2399980690,10),i=Ce(i,s,r,n,e[10],4293915773,15),n=Ce(n,i,s,r,e[1],2240044497,21),r=Ce(r,n,i,s,e[8],1873313359,6),s=Ce(s,r,n,i,e[15],4264355552,10),i=Ce(i,s,r,n,e[6],2734768916,15),n=Ce(n,i,s,r,e[13],1309151649,21),r=Ce(r,n,i,s,e[4],4149444226,6),s=Ce(s,r,n,i,e[11],3174756917,10),i=Ce(i,s,r,n,e[2],718787259,15),n=Ce(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};hi.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=Ll.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 li(e,t){return e<<t|e>>>32-t}function ke(e,t,r,n,i,s,o){return li(e+(t&r|~t&n)+i+s|0,o)+t|0}function Re(e,t,r,n,i,s,o){return li(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ue(e,t,r,n,i,s,o){return li(e+(t^r^n)+i+s|0,o)+t|0}function Ce(e,t,r,n,i,s,o){return li(e+(r^(t|~n))+i+s|0,o)+t|0}var Fl=hi,qn=Ge.Buffer,uf=of.Transform,Ml=Oe;function Hl(e,t){if(!qn.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Gt(e){uf.call(this),this._block=qn.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}Ml(Gt,uf);Gt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Gt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Gt.prototype.update=function(e,t){if(Hl(e,"Data"),this._finalized)throw new Error("Digest already called");qn.isBuffer(e)||(e=qn.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};Gt.prototype._update=function(){throw new Error("_update is not implemented")};Gt.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};Gt.prototype._digest=function(){throw new Error("_digest is not implemented")};var $l=Gt,Wi=Pt.Buffer,Dl=Oe,cf=$l,jl=new Array(16),Vr=[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],Wr=[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],zr=[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],qr=[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],Kr=[0,1518500249,1859775393,2400959708,2840853838],Yr=[1352829926,1548603684,1836072691,2053994217,0];function di(){cf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}Dl(di,cf);di.prototype._update=function(){for(var e=jl,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._a|0,c=this._b|0,l=this._c|0,d=this._d|0,g=this._e|0,x=0;x<80;x+=1){var y,O;x<16?(y=Uo(r,n,i,s,o,e[Vr[x]],Kr[0],zr[x]),O=Fo(a,c,l,d,g,e[Wr[x]],Yr[0],qr[x])):x<32?(y=Co(r,n,i,s,o,e[Vr[x]],Kr[1],zr[x]),O=No(a,c,l,d,g,e[Wr[x]],Yr[1],qr[x])):x<48?(y=Lo(r,n,i,s,o,e[Vr[x]],Kr[2],zr[x]),O=Lo(a,c,l,d,g,e[Wr[x]],Yr[2],qr[x])):x<64?(y=No(r,n,i,s,o,e[Vr[x]],Kr[3],zr[x]),O=Co(a,c,l,d,g,e[Wr[x]],Yr[3],qr[x])):(y=Fo(r,n,i,s,o,e[Vr[x]],Kr[4],zr[x]),O=Uo(a,c,l,d,g,e[Wr[x]],Yr[4],qr[x])),r=o,o=s,s=er(i,10),i=n,n=y,a=g,g=d,d=er(l,10),l=c,c=O}var B=this._b+i+d|0;this._b=this._c+s+g|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+l|0,this._a=B};di.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=Wi.alloc?Wi.alloc(20):new Wi(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 er(e,t){return e<<t|e>>>32-t}function Uo(e,t,r,n,i,s,o,a){return er(e+(t^r^n)+s+o|0,a)+i|0}function Co(e,t,r,n,i,s,o,a){return er(e+(t&r|~t&n)+s+o|0,a)+i|0}function Lo(e,t,r,n,i,s,o,a){return er(e+((t|~r)^n)+s+o|0,a)+i|0}function No(e,t,r,n,i,s,o,a){return er(e+(t&n|r&~n)+s+o|0,a)+i|0}function Fo(e,t,r,n,i,s,o,a){return er(e+(t^(r|~n))+s+o|0,a)+i|0}var Gl=di,hf={exports:{}},lf=Ge.Buffer;function pi(e,t){this._block=lf.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}pi.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=lf.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,s=this._len,o=0;o<i;){for(var a=s%n,c=Math.min(i-o,n-a),l=0;l<c;l++)r[a+l]=e[o+l];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};pi.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};pi.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Ur=pi,Vl=Oe,df=Ur,Wl=Ge.Buffer,zl=[1518500249,1859775393,-1894007588,-899497514],ql=new Array(80);function bn(){this.init(),this._w=ql,df.call(this,64,56)}Vl(bn,df);bn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Kl(e){return e<<5|e>>>27}function Yl(e){return e<<30|e>>>2}function Xl(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}bn.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=t[a-3]^t[a-8]^t[a-14]^t[a-16];for(var c=0;c<80;++c){var l=~~(c/20),d=Kl(r)+Xl(l,n,i,s)+o+t[c]+zl[l]|0;o=s,s=i,i=Yl(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};bn.prototype._hash=function(){var e=Wl.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 Jl=bn,Ql=Oe,pf=Ur,Zl=Ge.Buffer,e0=[1518500249,1859775393,-1894007588,-899497514],t0=new Array(80);function wn(){this.init(),this._w=t0,pf.call(this,64,56)}Ql(wn,pf);wn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function r0(e){return e<<1|e>>>31}function n0(e){return e<<5|e>>>27}function i0(e){return e<<30|e>>>2}function s0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}wn.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]=r0(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var l=~~(c/20),d=n0(r)+s0(l,n,i,s)+o+t[c]+e0[l]|0;o=s,s=i,i=i0(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};wn.prototype._hash=function(){var e=Zl.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 o0=wn,a0=Oe,yf=Ur,f0=Ge.Buffer,u0=[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],c0=new Array(64);function gn(){this.init(),this._w=c0,yf.call(this,64,56)}a0(gn,yf);gn.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 h0(e,t,r){return r^e&(t^r)}function l0(e,t,r){return e&t|r&(e|t)}function d0(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function p0(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function y0(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function b0(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}gn.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._f|0,c=this._g|0,l=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=b0(t[d-2])+t[d-7]+y0(t[d-15])+t[d-16]|0;for(var g=0;g<64;++g){var x=l+p0(o)+h0(o,a,c)+u0[g]+t[g]|0,y=d0(r)+l0(r,n,i)|0;l=c,c=a,a=o,o=s+x|0,s=i,i=n,n=r,r=x+y|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=l+this._h|0};gn.prototype._hash=function(){var e=f0.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 bf=gn,w0=Oe,g0=bf,m0=Ur,_0=Ge.Buffer,E0=new Array(64);function yi(){this.init(),this._w=E0,m0.call(this,64,56)}w0(yi,g0);yi.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};yi.prototype._hash=function(){var e=_0.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 v0=yi,x0=Oe,wf=Ur,S0=Ge.Buffer,Mo=[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],B0=new Array(160);function mn(){this.init(),this._w=B0,wf.call(this,128,112)}x0(mn,wf);mn.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 Ho(e,t,r){return r^e&(t^r)}function $o(e,t,r){return e&t|r&(e|t)}function Do(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function jo(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function P0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function T0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function A0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function I0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Te(e,t){return e>>>0<t>>>0?1:0}mn.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,s=this._dh|0,o=this._eh|0,a=this._fh|0,c=this._gh|0,l=this._hh|0,d=this._al|0,g=this._bl|0,x=this._cl|0,y=this._dl|0,O=this._el|0,B=this._fl|0,A=this._gl|0,k=this._hl|0,U=0;U<32;U+=2)t[U]=e.readInt32BE(U*4),t[U+1]=e.readInt32BE(U*4+4);for(;U<160;U+=2){var _=t[U-30],m=t[U-15*2+1],S=P0(_,m),v=T0(m,_);_=t[U-2*2],m=t[U-2*2+1];var $=A0(_,m),j=I0(m,_),R=t[U-7*2],z=t[U-7*2+1],Z=t[U-16*2],C=t[U-16*2+1],H=v+z|0,V=S+R+Te(H,v)|0;H=H+j|0,V=V+$+Te(H,j)|0,H=H+C|0,V=V+Z+Te(H,C)|0,t[U]=V,t[U+1]=H}for(var q=0;q<160;q+=2){V=t[q],H=t[q+1];var oe=$o(r,n,i),ae=$o(d,g,x),Ze=Do(r,d),Ve=Do(d,r),nt=jo(o,O),de=jo(O,o),ve=Mo[q],We=Mo[q+1],Tt=Ho(o,a,c),dt=Ho(O,B,A),T=k+de|0,P=l+nt+Te(T,k)|0;T=T+dt|0,P=P+Tt+Te(T,dt)|0,T=T+We|0,P=P+ve+Te(T,We)|0,T=T+H|0,P=P+V+Te(T,H)|0;var M=Ve+ae|0,G=Ze+oe+Te(M,Ve)|0;l=c,k=A,c=a,A=B,a=o,B=O,O=y+T|0,o=s+P+Te(O,y)|0,s=i,y=x,i=n,x=g,n=r,g=d,d=T+M|0,r=P+G+Te(d,T)|0}this._al=this._al+d|0,this._bl=this._bl+g|0,this._cl=this._cl+x|0,this._dl=this._dl+y|0,this._el=this._el+O|0,this._fl=this._fl+B|0,this._gl=this._gl+A|0,this._hl=this._hl+k|0,this._ah=this._ah+r+Te(this._al,d)|0,this._bh=this._bh+n+Te(this._bl,g)|0,this._ch=this._ch+i+Te(this._cl,x)|0,this._dh=this._dh+s+Te(this._dl,y)|0,this._eh=this._eh+o+Te(this._el,O)|0,this._fh=this._fh+a+Te(this._fl,B)|0,this._gh=this._gh+c+Te(this._gl,A)|0,this._hh=this._hh+l+Te(this._hl,k)|0};mn.prototype._hash=function(){var e=S0.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 gf=mn,O0=Oe,k0=gf,R0=Ur,U0=Ge.Buffer,C0=new Array(160);function bi(){this.init(),this._w=C0,R0.call(this,128,112)}O0(bi,k0);bi.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};bi.prototype._hash=function(){var e=U0.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 L0=bi,fr=hf.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=Jl;fr.sha1=o0;fr.sha224=v0;fr.sha256=bf;fr.sha384=L0;fr.sha512=gf;var N0=hf.exports,mf=Ge.Buffer,_f=Us.Transform,F0=Wn.StringDecoder,M0=Oe;function rt(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}M0(rt,_f);rt.prototype.update=function(e,t,r){typeof e=="string"&&(e=mf.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};rt.prototype.setAutoPadding=function(){};rt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};rt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};rt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};rt.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)}};rt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};rt.prototype._finalOrDigest=function(e){var t=this.__final()||mf.alloc(0);return e&&(t=this._toString(t,e,!0)),t};rt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new F0(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 H0=rt,$0=Oe,D0=Fl,j0=Gl,G0=N0,Ef=H0;function wi(e){Ef.call(this,"digest"),this._hash=e}$0(wi,Ef);wi.prototype._update=function(e){this._hash.update(e)};wi.prototype._final=function(){return this._hash.digest()};var V0=function(t){return t=t.toLowerCase(),t==="md5"?new D0:t==="rmd160"||t==="ripemd160"?new j0:new wi(G0(t))},On=Ge.Buffer;function W0(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if((Array.isArray(y)||y instanceof Uint8Array)&&(y=On.from(y)),!On.isBuffer(y))throw new TypeError("Expected Buffer");if(y.length===0)return"";for(var O=0,B=0,A=0,k=y.length;A!==k&&y[A]===0;)A++,O++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=y[A],S=0,v=U-1;(m!==0||S<B)&&v!==-1;v--,S++)m+=256*_[v]>>>0,_[v]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");B=S,A++}for(var $=U-B;$!==U&&_[$]===0;)$++;for(var j=a.repeat(O);$<U;++$)j+=e.charAt(_[$]);return j}function g(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return On.alloc(0);for(var O=0,B=0,A=0;y[O]===a;)B++,O++;for(var k=(y.length-O)*c+1>>>0,U=new Uint8Array(k);O<y.length;){var _=t[y.charCodeAt(O)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,O++}for(var v=k-A;v!==k&&U[v]===0;)v++;var $=On.allocUnsafe(B+(k-v));$.fill(0,0,B);for(var j=B;v!==k;)$[j++]=U[v++];return $}function x(y){var O=g(y);if(O)return O;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:g,decode:x}}var z0=W0,q0=z0,K0="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Y0=q0(K0),zi=Y0,X0=Ge.Buffer,J0=function(e){function t(s){var o=e(s);return zi.encode(X0.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=zi.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=zi.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},Go=V0,Q0=J0;function Z0(e){var t=Go("sha256").update(e).digest();return Go("sha256").update(t).digest()}var ed=Q0(Z0),as=ed;function vf(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 fs(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 td(e,t){return vf(as.decode(e),t)}function rd(e,t,r){return typeof e=="number"?as.encode(fs(e,t,r)):as.encode(fs(e.version,e.privateKey,e.compressed))}var nd={decode:td,decodeRaw:vf,encode:rd,encodeRaw:fs},gi={};Object.defineProperty(gi,"__esModule",{value:!0});gi.testEcc=void 0;const W=e=>Buffer.from(e,"hex");function id(e){ue(e.isPoint(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(!e.isPoint(W("030000000000000000000000000000000000000000000000000000000000000005"))),ue(e.isPrivate(W("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(e.isPrivate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),ue(!e.isPrivate(W("0000000000000000000000000000000000000000000000000000000000000000"))),ue(!e.isPrivate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),ue(!e.isPrivate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),ue(Buffer.from(e.privateAdd(W("0000000000000000000000000000000000000000000000000000000000000001"),W("0000000000000000000000000000000000000000000000000000000000000000"))).equals(W("0000000000000000000000000000000000000000000000000000000000000001"))),ue(e.privateAdd(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),W("0000000000000000000000000000000000000000000000000000000000000003"))===null),ue(Buffer.from(e.privateAdd(W("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),W("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(W("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),ue(Buffer.from(e.privateNegate(W("0000000000000000000000000000000000000000000000000000000000000001"))).equals(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),ue(Buffer.from(e.privateNegate(W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(W("0000000000000000000000000000000000000000000000000000000000000003"))),ue(Buffer.from(e.privateNegate(W("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(W("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),ue(Buffer.from(e.pointCompress(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(Buffer.from(e.pointCompress(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),ue(Buffer.from(e.pointCompress(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ue(Buffer.from(e.pointCompress(W("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(W("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),ue(Buffer.from(e.pointFromScalar(W("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(W("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),ue(e.xOnlyPointAddTweak(W("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(W("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),W("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));ue(Buffer.from(t.xOnlyPubkey).equals(W("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(W("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),W("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),ue(Buffer.from(t.xOnlyPubkey).equals(W("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),ue(Buffer.from(e.sign(W("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),W("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(W("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),ue(e.verify(W("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),W("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),W("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&ue(Buffer.from(e.signSchnorr(W("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),W("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),W("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(W("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&ue(e.verifySchnorr(W("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),W("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),W("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}gi.testEcc=id;function ue(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(Ir,"__esModule",{value:!0});Ir.ECPairFactory=Ir.networks=void 0;const us=Or;Ir.networks=us;const De=Ha,sd=Ih,Vo=nd,od=gi,qi=De.typeforce.maybe(De.typeforce.compile({compressed:De.maybe(De.Boolean),network:De.maybe(De.Network)})),ad=e=>e.length===32?e:e.slice(1,33);function fd(e){(0,od.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(De.typeforce(De.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return De.typeforce(qi,c),new o(a,void 0,c)}function n(a,c){return De.typeforce(e.isPoint,a),De.typeforce(qi,c),new o(void 0,a,c)}function i(a,c){const l=Vo.decode(a),d=l.version;if(De.Array(c)){if(c=c.filter(g=>d===g.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||us.bitcoin,d!==c.wif)throw new Error("Invalid network version");return r(l.privateKey,{compressed:l.compressed,network:c})}function s(a){De.typeforce(qi,a),a===void 0&&(a={});const c=a.rng||sd;let l;do l=c(32),De.typeforce(De.Buffer256bit,l);while(!e.isPrivate(l));return r(l,a)}class o{constructor(c,l,d){lr(this,"__D");lr(this,"__Q");lr(this,"compressed");lr(this,"network");lr(this,"lowR");this.__D=c,this.__Q=l,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||us.bitcoin,l!==void 0&&(this.__Q=Buffer.from(e.pointCompress(l,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const c=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(c)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return Vo.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,l){if(!this.__D)throw new Error("Missing private key");if(l===void 0&&(l=this.lowR),l===!1)return Buffer.from(e.sign(c,this.__D));{let d=e.sign(c,this.__D);const g=Buffer.alloc(32,0);let x=0;for(;d[0]>127;)x++,g.writeUIntLE(x,0,6),d=e.sign(c,this.__D,g);return Buffer.from(d)}}signSchnorr(c){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(c,this.privateKey))}verify(c,l){return e.verify(c,this.publicKey,l)}verifySchnorr(c,l){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),l)}tweakFromPublicKey(c){const l=ad(this.publicKey),d=e.xOnlyPointAddTweak(l,c);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const g=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([g,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,g=e.privateAdd(d,c);if(!g)throw new Error("Invalid tweaked private key!");return r(Buffer.from(g),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}Ir.ECPairFactory=fd;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=Ir;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}})})(Ma);const ud=hu(Ma);class hn extends ge.EventBroker{get isInitialized(){return!!this.privKey}constructor(t,r){super(),this.privKey=t,this.walletClient=r}static fromPrivKey(t){return new hn(N.trim0x(t))}static fromWalletClient(t){return new hn(void 0,t)}async initialize(){if(this.privKey)return N.Ok("Already initialized");const t=await this.derivePrivKeyFromWalletClient();return t.error?N.Err(t.error):(this.emit("initialized",!0),N.Ok("Initialized"))}async derivePrivKeyFromWalletClient(){if(!this.walletClient)return N.Err("No walletClient found");if(!this.walletClient.account)return N.Err("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.privKey=N.trim0x(lt.sha256(t)),this.emit("initialized",!0),N.Ok(this.privKey)}catch(t){return N.Err("Failed to initialize: "+t)}}async getMasterPrivKey(){if(!this.privKey&&!this.walletClient)return N.Err("No private key or wallet client found");if(!this.privKey&&this.walletClient){const t=await this.derivePrivKeyFromWalletClient();if(t.error)return N.Err(t.error)}return this.privKey?N.Ok(this.privKey):N.Err("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return N.Err(r.error);const n=lt.sha256(ge.with0x(r.val)),i=lt.sha256(n);return N.Ok({secret:n,secretHash:i})}async signMessage(t){if(!this.privKey){const l=await this.getMasterPrivKey();if(l.error)return N.Err(l.error);this.privKey=l.val}const r=ud(Jt),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=lt.sha256(i),o=Buffer.from(N.trim0x(this.privKey),"hex");if(o.length!==32)return N.Err("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(N.trim0x(s),"hex"));return N.Ok(c.toString("hex"))}}class cd extends ge.EventBroker{constructor(t){super(),this.getOrderThreshold=20,this.refundSacpCache=new Map,this.environment=t.environment;const r=t.environment===ge.Environment.MAINNET?ts.mainnet:t.environment===ge.Environment.TESTNET?ts.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);if(this._auth=new ge.Siwe(new ge.Url(t.orderbookURl??r.orderbook),t.evmWallet,t.siweOpts),this._quote=t.quote??new Fa(r.quote),this._orderBook=new ce.Orderbook({url:t.orderbookURl??r.orderbook,walletClient:t.evmWallet,auth:this._auth}),this._orderbookUrl=new ge.Url(t.orderbookURl??r.orderbook),this._evmRelay=new ra(this._orderbookUrl,this._auth),this._secretManager=t.secretManager??hn.fromWalletClient(t.evmWallet),this.orderExecutorCache=new Sh,this._evmWallet=t.evmWallet,!t.evmWallet.account)throw new Error("Account not found in evmWallet");this._blockNumberFetcher=t.blockNumberFetcher??new Na(r.info,t.environment)}get orderbookUrl(){return this._orderbookUrl.toString()}get evmRelay(){return this._evmRelay}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderBook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return N.Ok(this._btcWallet);const t=await this._secretManager.getMasterPrivKey();if(t.error)return N.Err(t.error);const r=new Br.BitcoinProvider(ru(this.environment));return this._btcWallet=Br.BitcoinWallet.fromPrivateKey(t.val,r),N.Ok(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return N.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val;let o=t.nonce;if(!o){if(!this._evmWallet.account)return N.Err("EVM Wallet not found");const B=await this._orderBook.getOrdersCount(this._evmWallet.account.address);if(B.error)return N.Err(B.error);o=B.val+1}const a=await this._secretManager.generateSecret(o);if(a.error)return N.Err(a.error);const{strategyId:c,btcAddress:l}=t.additionalData,d={strategy_id:c,...l&&{bitcoin_optional_recipient:l}},g={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o.toString(),timelock:s,secret_hash:N.trim0x(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},x=await this._quote.getAttestedQuote(g);if(x.error)return N.Err(x.error);const y=await this._orderBook.createOrder(x.val);if(y.error)return N.Err(y.error);const O=await this.pollOrder(y.val);return O.error?N.Err(O.error):N.Ok(O.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return N.Err("StrategyId is required");if(!t.fromAsset||!t.toAsset)return N.Err("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return N.Err("Source and destination assets cannot be the same");if(ce.isMainnet(t.fromAsset.chain)&&!ce.isMainnet(t.toAsset.chain)||!ce.isMainnet(t.fromAsset.chain)&&ce.isMainnet(t.toAsset.chain))return N.Err("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return N.Err(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return N.Err(n.error);if(r<n)return N.Err("Send amount should be greater than receive amount");const i=ce.getTimeLock(t.fromAsset.chain);if(!i)return N.Err("Unsupported chain for timelock");if(ce.isBitcoin(t.fromAsset.chain)||ce.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return N.Err("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 N.Err(a.error);if(!this._btcWallet)return N.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return N.Err(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?N.Err(o.error):N.Ok({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(ce.getBlockchainType(t)){case ce.BlockchainType.EVM:return this._evmWallet.account?N.Ok(this._evmWallet.account.address):N.Err("EVM Wallet not found");case ce.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!eu(i)?N.Err("Invalid btc public key"):N.Ok(qt(i))}default:return N.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return N.Err("Invalid amount ",t);const r=new Xf(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?N.Err("Invalid amount ",t):N.Ok(r)}async pollOrder(t){let r=await this._orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ge.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return N.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return N.Ok(r.val);r=await this._orderBook.getOrder(t,!0)}return N.Err(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderBook.subscribeToOrders(t,async r=>{if(r.data.length===0)return;const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val);for(let i=0;i<n.val.length;i++){const s=n.val[i],o=ds(s.status);if(ce.isBitcoin(s.source_swap.chain)&&s.status===he.InitiateDetected){const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);continue}await this.postRefundSACP(s,a.val)}switch(o){case Pe.Redeem:{const a=await this._secretManager.generateSecret(Number(s.create_order.nonce));if(a.error){this.emit("error",s,a.error);return}switch(ce.getBlockchainType(s.destination_swap.chain)){case ce.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case ce.BlockchainType.Bitcoin:{const c=this.getWallet(s.destination_swap.chain);if(c.error){this.emit("error",s,c.error);return}await this.btcRedeem(c.val,s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Pe.Refund:{switch(ce.getBlockchainType(s.source_swap.chain)){case ce.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case ce.BlockchainType.Bitcoin:{const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);return}await this.btcRefund(a.val,s);break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Pe.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const i=await this._evmRelay.redeem(t.create_order.create_id,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Pe.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Pe.Redeem,i.val),this.emit("success",t,Pe.Redeem,i.val)}async btcRedeem(t,r,n){var a,c;const i=this.orderExecutorCache.get(r,Pe.Redeem),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const l=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const g of l.vin)if(g.txid===s){d=!0;break}if(d){this.orderExecutorCache.set(r,Pe.Redeem,r.destination_swap.redeem_tx_hash,s),this.emit("log",r.create_order.create_id,"already a valid redeem");return}o=!0}catch(l){if(l.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+l);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const d=await(await on.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,qt(r.destination_swap.initiator),qt(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).redeem(N.trim0x(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient);o?this.emit("log",r.create_order.create_id,"rbf: btc redeem success"):this.emit("success",r,Pe.Redeem,d),this.orderExecutorCache.set(r,Pe.Redeem,d,s)}catch(l){this.emit("error",r,"Failed btc redeem: "+l)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Pe.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await on.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,qt(r.source_swap.initiator),qt(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,Pe.Refund,s),this.emit("success",r,Pe.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(ce.getBlockchainType(t)){case ce.BlockchainType.EVM:return N.Ok(this._evmWallet);case ce.BlockchainType.Bitcoin:return N.Ok(this._btcWallet);default:return N.Err("Unsupported chain for wallet")}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await on.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,qt(t.source_swap.initiator),qt(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 N.Fetcher.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 fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return N.Err("Provide wallets to fetch the current block number");const n=ce.isBitcoin(t.source_swap.chain)?await ge.fetchBitcoinBlockNumber(await r.source.getProvider()):await ge.fetchEVMBlockNumber(r.source);if(n.error)return N.Err(n.error);const i=ce.isBitcoin(t.destination_swap.chain)?await ge.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ge.fetchEVMBlockNumber(r.destination);return i.error?N.Err(i.error):N.Ok({source:n.val,destination:i.val})}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return N.Ok([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return N.Err(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(ta(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,l=r==null?void 0:r.val[a],d=r==null?void 0:r.val[c];if(!l||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const g=ls(o,l,d);n.push({...o,status:g})}return N.Ok(n)}}function ur(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const xf="2.21.41";let Xr={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${xf}`};class le extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof le?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof le&&r.cause.docsPath||r.docsPath,s=(a=Xr.getDocsUrl)==null?void 0:a.call(Xr,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...Xr.version?[`Version: ${Xr.version}`]:[]].join(`
|
|
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=xf}walk(t){return Sf(this,t)}}function Sf(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?Sf(e.cause,t):t?null:e}class hd extends le{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 ld extends le{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function _n(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Rr(e){return _n(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function Kn(e,{dir:t="left"}={}){let r=typeof e=="string"?e.replace("0x",""):e,n=0;for(let i=0;i<r.length-1&&r[t==="left"?i:r.length-i-1].toString()==="0";i++)n++;return r=t==="left"?r.slice(n):r.slice(0,r.length-n),typeof e=="string"?(r.length===1&&t==="right"&&(r=`${r}0`),`0x${r.length%2===1?`0${r}`:r}`):r}class dd extends le{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 Bf extends le{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 Cr(e,{dir:t,size:r=32}={}){return typeof e=="string"?pd(e,{dir:t,size:r}):yd(e,{dir:t,size:r})}function pd(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Bf({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function yd(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Bf({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const s=t==="right";n[s?i:r-i-1]=e[s?i:e.length-i-1]}return n}const bd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function J(e,t={}){return typeof e=="number"||typeof e=="bigint"?Pf(e,t):typeof e=="string"?md(e,t):typeof e=="boolean"?wd(e,t):Vt(e,t)}function wd(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Lr(r,{size:t.size}),Cr(r,{size:t.size})):r}function Vt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=bd[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Lr(n,{size:t.size}),Cr(n,{dir:"right",size:t.size})):n}function Pf(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const c=typeof e=="bigint"?"n":"";throw new hd({max:s?`${s}${c}`:void 0,min:`${o}${c}`,signed:r,size:n,value:`${e}${c}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Cr(a,{size:n}):a}const gd=new TextEncoder;function md(e,t={}){const r=gd.encode(e);return Vt(r,t)}const _d=new TextEncoder;function Tf(e,t={}){return typeof e=="number"||typeof e=="bigint"?vd(e,t):typeof e=="boolean"?Ed(e,t):_n(e)?tr(e,t):Af(e,t)}function Ed(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Lr(r,{size:t.size}),Cr(r,{size:t.size})):r}const gt={zero:48,nine:57,A:65,F:70,a:97,f:102};function Wo(e){if(e>=gt.zero&&e<=gt.nine)return e-gt.zero;if(e>=gt.A&&e<=gt.F)return e-(gt.A-10);if(e>=gt.a&&e<=gt.f)return e-(gt.a-10)}function tr(e,t={}){let r=e;t.size&&(Lr(r,{size:t.size}),r=Cr(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,s=new Uint8Array(i);for(let o=0,a=0;o<i;o++){const c=Wo(n.charCodeAt(a++)),l=Wo(n.charCodeAt(a++));if(c===void 0||l===void 0)throw new le(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+l}return s}function vd(e,t){const r=Pf(e,t);return tr(r)}function Af(e,t={}){const r=_d.encode(e);return typeof t.size=="number"?(Lr(r,{size:t.size}),Cr(r,{dir:"right",size:t.size})):r}function Lr(e,{size:t}){if(Rr(e)>t)throw new ld({givenSize:Rr(e),maxSize:t})}function _r(e,t={}){const{signed:r}=t;t.size&&Lr(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 Yn(e,t={}){return Number(_r(e,t))}function Ns(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 If={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Fs(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?Yn(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?Yn(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?If[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=Sd(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 xd=Ns("transaction",Fs);function Sd(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 Bd(e){var r;const t=(r=e.transactions)==null?void 0:r.map(n=>typeof n=="string"?n:Fs(n));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const Pd=Ns("block",Bd);function Td(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 Ad={"0x0":"reverted","0x1":"success"};function Id(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=>Td(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Yn(e.transactionIndex):null,status:e.status?Ad[e.status]:null,type:e.type?If[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const Od=Ns("transactionReceipt",Id),Ms=2n**256n-1n;function En(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class zo extends le{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class kd extends le{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class Rd extends le{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Ud={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 Rd({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new kd({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new zo({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 zo({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 Of(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(Ud);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function rr(e,t="hex"){const r=kf(e),n=Of(new Uint8Array(r.length));return r.encode(n),t==="hex"?Vt(n.bytes):n.bytes}function kf(e){return Array.isArray(e)?Cd(e.map(t=>kf(t))):Ld(e)}function Cd(e){const t=e.reduce((i,s)=>i+s.length,0),r=Rf(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 Ld(e){const t=typeof e=="string"?tr(e):e,r=Rf(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 Rf(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 le("Length is too large.")}const Nd={ether:-9,wei:9};function Fd(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 cs(e,t="wei"){return Fd(e,Nd[t])}function Md(e){const t=Object.entries(e).map(([n,i])=>i===void 0||i===!1?null:[n,i]).filter(Boolean),r=t.reduce((n,[i])=>Math.max(n,i.length),0);return t.map(([n,i])=>` ${`${n}:`.padEnd(r+1)} ${i}`).join(`
|
|
33
|
-
`)}class
|
|
34
|
-
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Hf,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class $f 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 kn=BigInt(2**32-1),Yo=BigInt(32);function Jd(e,t=!1){return t?{h:Number(e&kn),l:Number(e>>Yo&kn)}:{h:Number(e>>Yo&kn)|0,l:Number(e&kn)|0}}function Qd(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}=Jd(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const Zd=(e,t,r)=>e<<r|t>>>32-r,ep=(e,t,r)=>t<<r|e>>>32-r,tp=(e,t,r)=>t<<r-32|e>>>64-r,rp=(e,t,r)=>e<<r-32|t>>>64-r,Df=[],jf=[],Gf=[],np=BigInt(0),Jr=BigInt(1),ip=BigInt(2),sp=BigInt(7),op=BigInt(256),ap=BigInt(113);for(let e=0,t=Jr,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Df.push(2*(5*n+r)),jf.push((e+1)*(e+2)/2%64);let i=np;for(let s=0;s<7;s++)t=(t<<Jr^(t>>sp)*ap)%op,t&ip&&(i^=Jr<<(Jr<<BigInt(s))-Jr);Gf.push(i)}const[fp,up]=Qd(Gf,!0),Xo=(e,t,r)=>r>32?tp(e,t,r):Zd(e,t,r),Jo=(e,t,r)=>r>32?rp(e,t,r):ep(e,t,r);function cp(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)r[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,l=r[c],d=r[c+1],g=Xo(l,d,1)^r[a],x=Jo(l,d,1)^r[a+1];for(let y=0;y<50;y+=10)e[o+y]^=g,e[o+y+1]^=x}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=jf[o],c=Xo(i,s,a),l=Jo(i,s,a),d=Df[o];i=e[d],s=e[d+1],e[d]=c,e[d+1]=l}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=fp[n],e[1]^=up[n]}r.fill(0)}class $s extends Ba{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,Ks(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=ju(this.state)}keccak(){Ys||Xs(this.state32),cp(this.state32,this.rounds),Ys||Xs(this.state32),this.posOut=0,this.pos=0}update(t){jn(this);const{blockLen:r,state:n}=this;t=xs(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){jn(this,!1),vs(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 Ks(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Sa(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 $s(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 hp=(e,t,r)=>Ss(()=>new $s(t,e,r)),lp=hp(1,136,256/8);function dp(e,t){return lp(_n(e,{strict:!1})?Tf(e):e)}const Ki=new $f(8192);function pp(e,t){if(Ki.has(`${e}.${t}`))return Ki.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=dp(Af(r)),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return Ki.set(`${e}.${t}`,s),s}const yp=/^0x[a-fA-F0-9]{40}$/,Yi=new $f(8192);function ir(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Yi.has(n))return Yi.get(n);const i=yp.test(e)?e.toLowerCase()===e?!0:r?pp(e)===e:!0:!1;return Yi.set(n,i),i}function bp(e,t,r,{strict:n}={}){return _n(e,{strict:!1})?gp(e,t,r,{strict:n}):wp(e,t,r,{strict:n})}function Vf(e,t,r){if(Rr(e)!==r-t)throw new dd({offset:r,position:"end",size:Rr(e)})}function wp(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&Vf(i,t,r),i}function gp(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&Vf(i,t,r),i}function mp(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!ir(n))throw new nr({address:n});if(i<0)throw new mi({chainId:i})}Ds(e)}function _p(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Mf;for(const r of t){const n=Rr(r),i=Yn(bp(r,0,1));if(n!==32)throw new zd({hash:r,size:n});if(i!==Ff)throw new qd({hash:r,version:i})}}Ds(e)}function Ds(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new mi({chainId:t});if(i&&!ir(i))throw new nr({address:i});if(n&&n>Ms)throw new _i({maxFeePerGas:n});if(r&&n&&r>n)throw new Hf({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Ep(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new mi({chainId:t});if(s&&!ir(s))throw new nr({address:s});if(r||i)throw new le("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ms)throw new _i({maxFeePerGas:n})}function vp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!ir(s))throw new nr({address:s});if(typeof t<"u"&&t<=0)throw new mi({chainId:t});if(r||i)throw new le("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ms)throw new _i({maxFeePerGas:n})}function xp(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new $d({transaction:e})}function Ei(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let s=0;s<i.length;s++)if(i[s].length-2!==64)throw new Dd({storageKey:i[s]});if(!ir(n,{strict:!1}))throw new nr({address:n});t.push([n,i])}return t}function Sp(e,t){const r=xp(e);return r==="eip1559"?Tp(e,t):r==="eip2930"?Ap(e,t):r==="eip4844"?Pp(e,t):r==="eip7702"?Bp(e,t):Ip(e,t)}function Bp(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:c,maxPriorityFeePerGas:l,accessList:d,data:g}=e;mp(e);const x=Ei(d),y=Xd(r);return En(["0x04",rr([J(n),s?J(s):"0x",l?J(l):"0x",c?J(c):"0x",i?J(i):"0x",o??"0x",a?J(a):"0x",g??"0x",x,y,...vn(e,t)])])}function Pp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:l,accessList:d,data:g}=e;_p(e);let x=e.blobVersionedHashes,y=e.sidecars;if(e.blobs&&(typeof x>"u"||typeof y>"u")){const _=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(v=>Vt(v)),m=e.kzg,S=Uf({blobs:_,kzg:m});if(typeof x>"u"&&(x=Vd({commitments:S})),typeof y>"u"){const v=Cf({blobs:_,commitments:S,kzg:m});y=Yd({blobs:_,commitments:S,proofs:v})}}const O=Ei(d),B=[J(r),i?J(i):"0x",l?J(l):"0x",c?J(c):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",g??"0x",O,a?J(a):"0x",x??[],...vn(e,t)],A=[],k=[],U=[];if(y)for(let _=0;_<y.length;_++){const{blob:m,commitment:S,proof:v}=y[_];A.push(m),k.push(S),U.push(v)}return En(["0x03",rr(y?[B,A,k,U]:B)])}function Tp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:l,data:d}=e;Ds(e);const g=Ei(l),x=[J(r),i?J(i):"0x",c?J(c):"0x",a?J(a):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",d??"0x",g,...vn(e,t)];return En(["0x02",rr(x)])}function Ap(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:c,gasPrice:l}=e;Ep(e);const d=Ei(c),g=[J(r),s?J(s):"0x",l?J(l):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x",d,...vn(e,t)];return En(["0x01",rr(g)])}function Ip(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:c}=e;vp(e);let l=[s?J(s):"0x",c?J(c):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x"];if(t){const d=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const y=27n+(t.v===27n?0n:1n);if(t.v!==y)throw new Hd({v:t.v});return y})(),g=Kn(t.r),x=Kn(t.s);l=[...l,J(d),g==="0x00"?"0x":g,x==="0x00"?"0x":x]}else r>0&&(l=[...l,J(r),"0x","0x"]);return rr(l)}function vn(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const s=Kn(r.r),o=Kn(r.s);return[typeof i=="number"?i?J(1):"0x":n===0n?"0x":n===1n?J(1):n===27n?"0x":J(1),s==="0x00"?"0x":s,o==="0x00"?"0x":o]}const Op={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},kp={block:Pd({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Fs(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?_r(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:xd({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?_r(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Od({format(e){return{l1GasPrice:e.l1GasPrice?_r(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?_r(e.l1GasUsed):null,l1Fee:e.l1Fee?_r(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function Rp(e,t){return Lp(e)?Cp(e):Sp(e,t)}const Up={transaction:Rp};function Cp(e){Np(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:c}=e,l=[t,n,a??"0x",o?J(o):"0x",c?J(c):"0x",i?J(i):"0x",s?"0x1":"0x",r??"0x"];return En(["0x7e",rr(l)])}function Lp(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Np(e){const{from:t,to:r}=e;if(t&&!ir(t))throw new nr({address:t});if(r&&!ir(r))throw new nr({address:r})}const Xn={contracts:Op,formatters:kp,serializers:Up},Fp=ur({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}}}),Mp=ur({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}),Qr=1,Hp=ur({...Xn,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:{...Xn.contracts,disputeGameFactory:{[Qr]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Qr]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Qr]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Qr]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Qr}),Zr=11155111,$p=ur({...Xn,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:{...Xn.contracts,disputeGameFactory:{[Zr]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Zr]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Zr]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Zr]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Zr}),Dp=ur({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),jp=ur({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),Gp=ur({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}),Vp={...Gp,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Wf=lt.defineChain({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api/v2/"}},testnet:!0}),zf={ethereum:jp,arbitrum:Fp,ethereum_sepolia:Vp,arbitrum_sepolia:Mp,ethereum_localnet:ce.EthereumLocalnet,arbitrum_localnet:ce.ArbitrumLocalnet,base_sepolia:$p,base:Hp,bera_testnet:Dp,citrea_testnet:Wf},Wp=async(e,t)=>{var n;const r=zf[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return N.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=lt.createWalletClient({account:t.account,chain:r,transport:lt.custom(window.ethereum)});return N.Ok({message:"Switched chain",walletClient:i})}catch(i){if(zp(i))try{await t.addChain({chain:r});const s=lt.createWalletClient({account:t.account,chain:r,transport:lt.custom(window.ethereum)});return N.Ok({message:"Added network",walletClient:s})}catch{return N.Err("Failed to add network")}else return N.Err("Failed to switch network")}else return N.Err("Chain not supported")},zp=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.API=ts;exports.BlockNumberFetcher=Na;exports.EvmRelay=ra;exports.Garden=cd;exports.OrderActions=Pe;exports.OrderStatus=he;exports.ParseOrderStatus=ls;exports.ParseSwapStatus=Ji;exports.Quote=Fa;exports.SecretManager=hn;exports.SwapStatus=we;exports.citreaTestnet=Wf;exports.constructOrderPair=ea;exports.evmToViemChainMap=zf;exports.filterDeadlineExpiredOrders=iu;exports.isExpired=an;exports.parseAction=nu;exports.parseActionFromStatus=ds;exports.switchOrAddNetwork=Wp;exports.validateBTCAddress=tu;
|
|
28
|
+
`.trim().replace(/\s+/g," "))}leaves(){return[{version:Un,output:this.redeemLeaf()},[{version:Un,output:this.refundLeaf()},{version:Un,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const s=yu(i,n);return[de.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(De.invalidLeaf)}}}function zr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class $h{constructor(){this.cache={}}set(t,r,n,i){const s={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=s}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class Ya{constructor(t,r){this.url=new ae.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){try{const t=await Jt.get(this.url);return re(t)}catch(t){return j("Failed to fetch block numbers",t)}}}const ls={mainnet:{orderbook:"https://orderbookv2.garden.finance",quote:"https://pricev2.garden.finance",info:"https://infov2.garden.finance"},testnet:{orderbook:"https://orderbook.garden.finance",quote:"https://price.garden.finance",info:"https://info.garden.finance"},localnet:{orderbook:"",quote:"",info:""}};class Xa{constructor(t){this.quoteUrl=new ae.Url("/quote",t)}async getQuote(t,r,n=!1,i){try{const s=this.quoteUrl.addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),o=await Jt.get(s,i);return o.error?j(o.error):o.result?re(o.result):j("GetQuote: Unexpected error, result is undefined")}catch(s){return j("GetQuote:",String(s))}}async getAttestedQuote(t){try{const r=await Jt.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?j(r.error):r.result?re(r.result):j("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),j("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await Jt.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return j(t.error);if(!t.result)return j("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=da(n.source_chain,n.source_asset.asset,n.dest_chain,n.dest_asset.asset);r[i]={id:n.id,minAmount:n.min_amount,maxAmount:n.max_amount,fee:n.fee}}return re(r)}catch(t){return j("GetStrategies:",String(t))}}}var Ja={},Rr={},Ur={};Object.defineProperty(Ur,"__esModule",{value:!0});Ur.testnet=Ur.bitcoin=void 0;Ur.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
29
|
+
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Ur.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
30
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Qa={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=xa,e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe})(Qa);var ds={exports:{}},ps={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Tt,n=r.Buffer;function i(o,a){for(var c in o)a[c]=o[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=s);function s(o,a,c){return n(o,a,c)}s.prototype=Object.create(n.prototype),i(n,s),s.from=function(o,a,c){if(typeof o=="number")throw new TypeError("Argument must not be a number");return n(o,a,c)},s.alloc=function(o,a,c){if(typeof o!="number")throw new TypeError("Argument must be a number");var l=n(o);return a!==void 0?typeof c=="string"?l.fill(a,c):l.fill(a):l.fill(0),l},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(o)}})(ps,ps.exports);var We=ps.exports,Vi=65536,Dh=4294967295;function jh(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
31
|
+
Use Chrome, Firefox or Internet Explorer 11`)}var Gh=We.Buffer,Jn=$t.crypto||$t.msCrypto;Jn&&Jn.getRandomValues?ds.exports=Wh:ds.exports=jh;function Wh(e,t){if(e>Dh)throw new RangeError("requested too many random bytes");var r=Gh.allocUnsafe(e);if(e>0)if(e>Vi)for(var n=0;n<e;n+=Vi)Jn.getRandomValues(r.slice(n,n+Vi));else Jn.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Vh=ds.exports,ys={exports:{}};typeof Object.create=="function"?ys.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:ys.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}};var ke=ys.exports,bs={exports:{}},Gs={exports:{}},Tr=typeof Reflect=="object"?Reflect:null,Oo=Tr&&typeof Tr.apply=="function"?Tr.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Vn;Tr&&typeof Tr.ownKeys=="function"?Vn=Tr.ownKeys:Object.getOwnPropertySymbols?Vn=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Vn=function(t){return Object.getOwnPropertyNames(t)};function zh(e){console&&console.warn&&console.warn(e)}var Za=Number.isNaN||function(t){return t!==t};function ne(){ne.init.call(this)}Gs.exports=ne;Gs.exports.once=Xh;ne.EventEmitter=ne;ne.prototype._events=void 0;ne.prototype._eventsCount=0;ne.prototype._maxListeners=void 0;var ko=10;function yi(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(ne,"defaultMaxListeners",{enumerable:!0,get:function(){return ko},set:function(e){if(typeof e!="number"||e<0||Za(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ko=e}});ne.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};ne.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Za(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function ef(e){return e._maxListeners===void 0?ne.defaultMaxListeners:e._maxListeners}ne.prototype.getMaxListeners=function(){return ef(this)};ne.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=s[t];if(c===void 0)return!1;if(typeof c=="function")Oo(c,this,r);else for(var l=c.length,d=of(c,l),n=0;n<l;++n)Oo(d[n],this,r);return!0};function tf(e,t,r,n){var i,s,o;if(yi(r),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),o=s[t]),o===void 0)o=s[t]=r,++e._eventsCount;else if(typeof o=="function"?o=s[t]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),i=ef(e),i>0&&o.length>i&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=o.length,zh(a)}return e}ne.prototype.addListener=function(t,r){return tf(this,t,r,!1)};ne.prototype.on=ne.prototype.addListener;ne.prototype.prependListener=function(t,r){return tf(this,t,r,!0)};function qh(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function rf(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=qh.bind(n);return i.listener=r,n.wrapFn=i,i}ne.prototype.once=function(t,r){return yi(r),this.on(t,rf(this,t,r)),this};ne.prototype.prependOnceListener=function(t,r){return yi(r),this.prependListener(t,rf(this,t,r)),this};ne.prototype.removeListener=function(t,r){var n,i,s,o,a;if(yi(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(s=-1,o=n.length-1;o>=0;o--)if(n[o]===r||n[o].listener===r){a=n[o].listener,s=o;break}if(s<0)return this;s===0?n.shift():Kh(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};ne.prototype.off=ne.prototype.removeListener;ne.prototype.removeAllListeners=function(t){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var s=Object.keys(n),o;for(i=0;i<s.length;++i)o=s[i],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(t,r[i]);return this};function nf(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Yh(i):of(i,i.length)}ne.prototype.listeners=function(t){return nf(this,t,!0)};ne.prototype.rawListeners=function(t){return nf(this,t,!1)};ne.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):sf.call(e,t)};ne.prototype.listenerCount=sf;function sf(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}ne.prototype.eventNames=function(){return this._eventsCount>0?Vn(this._events):[]};function of(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Kh(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Yh(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Xh(e,t){return new Promise(function(r,n){function i(o){e.removeListener(t,s),n(o)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}af(e,t,s,{once:!0}),t!=="error"&&Jh(e,i,{once:!0})})}function Jh(e,t,r){typeof e.on=="function"&&af(e,"error",t,r)}function af(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function i(s){n.once&&e.removeEventListener(t,i),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var ff=Gs.exports,uf=ff.EventEmitter;const Qh={},Zh=Object.freeze(Object.defineProperty({__proto__:null,default:Qh},Symbol.toStringTag,{value:"Module"})),Ws=ba(Zh);var zi,Ro;function el(){if(Ro)return zi;Ro=1;function e(O,B){var A=Object.keys(O);if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(O);B&&(k=k.filter(function(U){return Object.getOwnPropertyDescriptor(O,U).enumerable})),A.push.apply(A,k)}return A}function t(O){for(var B=1;B<arguments.length;B++){var A=arguments[B]!=null?arguments[B]:{};B%2?e(Object(A),!0).forEach(function(k){r(O,k,A[k])}):Object.getOwnPropertyDescriptors?Object.defineProperties(O,Object.getOwnPropertyDescriptors(A)):e(Object(A)).forEach(function(k){Object.defineProperty(O,k,Object.getOwnPropertyDescriptor(A,k))})}return O}function r(O,B,A){return B=o(B),B in O?Object.defineProperty(O,B,{value:A,enumerable:!0,configurable:!0,writable:!0}):O[B]=A,O}function n(O,B){if(!(O instanceof B))throw new TypeError("Cannot call a class as a function")}function i(O,B){for(var A=0;A<B.length;A++){var k=B[A];k.enumerable=k.enumerable||!1,k.configurable=!0,"value"in k&&(k.writable=!0),Object.defineProperty(O,o(k.key),k)}}function s(O,B,A){return B&&i(O.prototype,B),Object.defineProperty(O,"prototype",{writable:!1}),O}function o(O){var B=a(O,"string");return typeof B=="symbol"?B:String(B)}function a(O,B){if(typeof O!="object"||O===null)return O;var A=O[Symbol.toPrimitive];if(A!==void 0){var k=A.call(O,B||"default");if(typeof k!="object")return k;throw new TypeError("@@toPrimitive must return a primitive value.")}return(B==="string"?String:Number)(O)}var c=Tt,l=c.Buffer,d=Ws,g=d.inspect,x=g&&g.custom||"inspect";function y(O,B,A){l.prototype.copy.call(O,B,A)}return zi=function(){function O(){n(this,O),this.head=null,this.tail=null,this.length=0}return s(O,[{key:"push",value:function(A){var k={data:A,next:null};this.length>0?this.tail.next=k:this.head=k,this.tail=k,++this.length}},{key:"unshift",value:function(A){var k={data:A,next:this.head};this.length===0&&(this.tail=k),this.head=k,++this.length}},{key:"shift",value:function(){if(this.length!==0){var A=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,A}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(A){if(this.length===0)return"";for(var k=this.head,U=""+k.data;k=k.next;)U+=A+k.data;return U}},{key:"concat",value:function(A){if(this.length===0)return l.alloc(0);for(var k=l.allocUnsafe(A>>>0),U=this.head,_=0;U;)y(U.data,k,_),_+=U.data.length,U=U.next;return k}},{key:"consume",value:function(A,k){var U;return A<this.head.data.length?(U=this.head.data.slice(0,A),this.head.data=this.head.data.slice(A)):A===this.head.data.length?U=this.shift():U=k?this._getString(A):this._getBuffer(A),U}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(A){var k=this.head,U=1,_=k.data;for(A-=_.length;k=k.next;){var m=k.data,S=A>m.length?m.length:A;if(S===m.length?_+=m:_+=m.slice(0,A),A-=S,A===0){S===m.length?(++U,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=m.slice(S));break}++U}return this.length-=U,_}},{key:"_getBuffer",value:function(A){var k=l.allocUnsafe(A),U=this.head,_=1;for(U.data.copy(k),A-=U.data.length;U=U.next;){var m=U.data,S=A>m.length?m.length:A;if(m.copy(k,k.length-A,0,S),A-=S,A===0){S===m.length?(++_,U.next?this.head=U.next:this.head=this.tail=null):(this.head=U,U.data=m.slice(S));break}++_}return this.length-=_,k}},{key:x,value:function(A,k){return g(this,t(t({},k),{},{depth:0,customInspect:!1}))}}]),O}(),zi}function tl(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return n||i?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(ws,this,e)):process.nextTick(ws,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted?process.nextTick(zn,r):(r._writableState.errorEmitted=!0,process.nextTick(Uo,r,s)):process.nextTick(Uo,r,s):t?(process.nextTick(zn,r),t(s)):process.nextTick(zn,r)}),this)}function Uo(e,t){ws(e,t),zn(e)}function zn(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function rl(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function ws(e,t){e.emit("error",t)}function nl(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var cf={destroy:tl,undestroy:rl,errorOrDestroy:nl},cr={};function il(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var hf={};function Ze(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){il(o,s);function o(a,c,l){return s.call(this,n(a,c,l))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,hf[e]=i}function Co(e,t){if(Array.isArray(e)){var r=e.length;return e=e.map(function(n){return String(n)}),r>2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:r===2?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}else return"of ".concat(t," ").concat(String(e))}function sl(e,t,r){return e.substr(0,t.length)===t}function ol(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function al(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Ze("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Ze("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&sl(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(ol(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Co(t,"type"));else{var s=al(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Co(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Ze("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Ze("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Ze("ERR_STREAM_PREMATURE_CLOSE","Premature close");Ze("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Ze("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Ze("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Ze("ERR_STREAM_WRITE_AFTER_END","write after end");Ze("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Ze("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Ze("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");cr.codes=hf;var fl=cr.codes.ERR_INVALID_OPT_VALUE;function ul(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function cl(e,t,r,n){var i=ul(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new fl(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var lf={getHighWaterMark:cl},hl=ll;function ll(e,t){if(qi("noDeprecation"))return e;var r=!1;function n(){if(!r){if(qi("throwDeprecation"))throw new Error(t);qi("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function qi(e){try{if(!$t.localStorage)return!1}catch{return!1}var t=$t.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Ki,Lo;function df(){if(Lo)return Ki;Lo=1,Ki=D;function e(T){var P=this;this.next=null,this.entry=null,this.finish=function(){pt(P,T)}}var t;D.WritableState=E;var r={deprecate:hl},n=uf,i=Tt.Buffer,s=(typeof $t<"u"?$t:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(T){return i.from(T)}function a(T){return i.isBuffer(T)||T instanceof s}var c=cf,l=lf,d=l.getHighWaterMark,g=cr.codes,x=g.ERR_INVALID_ARG_TYPE,y=g.ERR_METHOD_NOT_IMPLEMENTED,O=g.ERR_MULTIPLE_CALLBACK,B=g.ERR_STREAM_CANNOT_PIPE,A=g.ERR_STREAM_DESTROYED,k=g.ERR_STREAM_NULL_VALUES,U=g.ERR_STREAM_WRITE_AFTER_END,_=g.ERR_UNKNOWN_ENCODING,m=c.errorOrDestroy;ke(D,n);function S(){}function E(T,P,F){t=t||Cr(),T=T||{},typeof F!="boolean"&&(F=P instanceof t),this.objectMode=!!T.objectMode,F&&(this.objectMode=this.objectMode||!!T.writableObjectMode),this.highWaterMark=d(this,T,"writableHighWaterMark",F),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var G=T.decodeStrings===!1;this.decodeStrings=!G,this.defaultEncoding=T.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(K){fe(P,K)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=T.emitClose!==!1,this.autoDestroy=!!T.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}E.prototype.getBuffer=function(){for(var P=this.bufferedRequest,F=[];P;)F.push(P),P=P.next;return F},function(){try{Object.defineProperty(E.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var H;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(H=Function.prototype[Symbol.hasInstance],Object.defineProperty(D,Symbol.hasInstance,{value:function(P){return H.call(this,P)?!0:this!==D?!1:P&&P._writableState instanceof E}})):H=function(P){return P instanceof this};function D(T){t=t||Cr();var P=this instanceof t;if(!P&&!H.call(D,this))return new D(T);this._writableState=new E(T,this,P),this.writable=!0,T&&(typeof T.write=="function"&&(this._write=T.write),typeof T.writev=="function"&&(this._writev=T.writev),typeof T.destroy=="function"&&(this._destroy=T.destroy),typeof T.final=="function"&&(this._final=T.final)),n.call(this)}D.prototype.pipe=function(){m(this,new B)};function R(T,P){var F=new U;m(T,F),process.nextTick(P,F)}function z(T,P,F,G){var K;return F===null?K=new k:typeof F!="string"&&!P.objectMode&&(K=new x("chunk",["string","Buffer"],F)),K?(m(T,K),process.nextTick(G,K),!1):!0}D.prototype.write=function(T,P,F){var G=this._writableState,K=!1,b=!G.objectMode&&a(T);return b&&!i.isBuffer(T)&&(T=o(T)),typeof P=="function"&&(F=P,P=null),b?P="buffer":P||(P=G.defaultEncoding),typeof F!="function"&&(F=S),G.ending?R(this,F):(b||z(this,G,T,F))&&(G.pendingcb++,K=C(this,G,b,T,P,F)),K},D.prototype.cork=function(){this._writableState.corked++},D.prototype.uncork=function(){var T=this._writableState;T.corked&&(T.corked--,!T.writing&&!T.corked&&!T.bufferProcessing&&T.bufferedRequest&&Ve(this,T))},D.prototype.setDefaultEncoding=function(P){if(typeof P=="string"&&(P=P.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((P+"").toLowerCase())>-1))throw new _(P);return this._writableState.defaultEncoding=P,this},Object.defineProperty(D.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Z(T,P,F){return!T.objectMode&&T.decodeStrings!==!1&&typeof P=="string"&&(P=i.from(P,F)),P}Object.defineProperty(D.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function C(T,P,F,G,K,b){if(!F){var w=Z(P,G,K);G!==w&&(F=!0,K="buffer",G=w)}var N=P.objectMode?1:G.length;P.length+=N;var $=P.length<P.highWaterMark;if($||(P.needDrain=!0),P.writing||P.corked){var we=P.lastBufferedRequest;P.lastBufferedRequest={chunk:G,encoding:K,isBuf:F,callback:b,next:null},we?we.next=P.lastBufferedRequest:P.bufferedRequest=P.lastBufferedRequest,P.bufferedRequestCount+=1}else M(T,P,!1,N,G,K,b);return $}function M(T,P,F,G,K,b,w){P.writelen=G,P.writecb=w,P.writing=!0,P.sync=!0,P.destroyed?P.onwrite(new A("write")):F?T._writev(K,P.onwrite):T._write(K,b,P.onwrite),P.sync=!1}function W(T,P,F,G,K){--P.pendingcb,F?(process.nextTick(K,G),process.nextTick(ze,T,P),T._writableState.errorEmitted=!0,m(T,G)):(K(G),T._writableState.errorEmitted=!0,m(T,G),ze(T,P))}function q(T){T.writing=!1,T.writecb=null,T.length-=T.writelen,T.writelen=0}function fe(T,P){var F=T._writableState,G=F.sync,K=F.writecb;if(typeof K!="function")throw new O;if(q(F),P)W(T,F,G,P,K);else{var b=it(F)||T.destroyed;!b&&!F.corked&&!F.bufferProcessing&&F.bufferedRequest&&Ve(T,F),G?process.nextTick(ue,T,F,b,K):ue(T,F,b,K)}}function ue(T,P,F,G){F||et(T,P),P.pendingcb--,G(),ze(T,P)}function et(T,P){P.length===0&&P.needDrain&&(P.needDrain=!1,T.emit("drain"))}function Ve(T,P){P.bufferProcessing=!0;var F=P.bufferedRequest;if(T._writev&&F&&F.next){var G=P.bufferedRequestCount,K=new Array(G),b=P.corkedRequestsFree;b.entry=F;for(var w=0,N=!0;F;)K[w]=F,F.isBuf||(N=!1),F=F.next,w+=1;K.allBuffers=N,M(T,P,!0,P.length,K,"",b.finish),P.pendingcb++,P.lastBufferedRequest=null,b.next?(P.corkedRequestsFree=b.next,b.next=null):P.corkedRequestsFree=new e(P),P.bufferedRequestCount=0}else{for(;F;){var $=F.chunk,we=F.encoding,Y=F.callback,te=P.objectMode?1:$.length;if(M(T,P,!1,te,$,we,Y),F=F.next,P.bufferedRequestCount--,P.writing)break}F===null&&(P.lastBufferedRequest=null)}P.bufferedRequest=F,P.bufferProcessing=!1}D.prototype._write=function(T,P,F){F(new y("_write()"))},D.prototype._writev=null,D.prototype.end=function(T,P,F){var G=this._writableState;return typeof T=="function"?(F=T,T=null,P=null):typeof P=="function"&&(F=P,P=null),T!=null&&this.write(T,P),G.corked&&(G.corked=1,this.uncork()),G.ending||At(this,G,F),this},Object.defineProperty(D.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function it(T){return T.ending&&T.length===0&&T.bufferedRequest===null&&!T.finished&&!T.writing}function be(T,P){T._final(function(F){P.pendingcb--,F&&m(T,F),P.prefinished=!0,T.emit("prefinish"),ze(T,P)})}function xe(T,P){!P.prefinished&&!P.finalCalled&&(typeof T._final=="function"&&!P.destroyed?(P.pendingcb++,P.finalCalled=!0,process.nextTick(be,T,P)):(P.prefinished=!0,T.emit("prefinish")))}function ze(T,P){var F=it(P);if(F&&(xe(T,P),P.pendingcb===0&&(P.finished=!0,T.emit("finish"),P.autoDestroy))){var G=T._readableState;(!G||G.autoDestroy&&G.endEmitted)&&T.destroy()}return F}function At(T,P,F){P.ending=!0,ze(T,P),F&&(P.finished?process.nextTick(F):T.once("finish",F)),P.ended=!0,T.writable=!1}function pt(T,P,F){var G=T.entry;for(T.entry=null;G;){var K=G.callback;P.pendingcb--,K(F),G=G.next}P.corkedRequestsFree.next=T}return Object.defineProperty(D.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(P){this._writableState&&(this._writableState.destroyed=P)}}),D.prototype.destroy=c.destroy,D.prototype._undestroy=c.undestroy,D.prototype._destroy=function(T,P){P(T)},Ki}var Yi,No;function Cr(){if(No)return Yi;No=1;var e=Object.keys||function(l){var d=[];for(var g in l)d.push(g);return d};Yi=o;var t=yf(),r=df();ke(o,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var s=n[i];o.prototype[s]||(o.prototype[s]=r.prototype[s])}function o(l){if(!(this instanceof o))return new o(l);t.call(this,l),r.call(this,l),this.allowHalfOpen=!0,l&&(l.readable===!1&&(this.readable=!1),l.writable===!1&&(this.writable=!1),l.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",a)))}Object.defineProperty(o.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(o.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(o.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function a(){this._writableState.ended||process.nextTick(c,this)}function c(l){l.end()}return Object.defineProperty(o.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(d){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=d,this._writableState.destroyed=d)}}),Yi}var Qn={},Vs=We.Buffer,Fo=Vs.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function dl(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function pl(e){var t=dl(e);if(typeof t!="string"&&(Vs.isEncoding===Fo||!Fo(e)))throw new Error("Unknown encoding: "+e);return t||e}Qn.StringDecoder=gn;function gn(e){this.encoding=pl(e);var t;switch(this.encoding){case"utf16le":this.text=_l,this.end=vl,t=4;break;case"utf8":this.fillLast=wl,t=4;break;case"base64":this.text=El,this.end=xl,t=3;break;default:this.write=Sl,this.end=Bl;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Vs.allocUnsafe(t)}gn.prototype.write=function(e){if(e.length===0)return"";var t,r;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""};gn.prototype.end=ml;gn.prototype.text=gl;gn.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function Xi(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function yl(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Xi(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Xi(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Xi(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function bl(e,t,r){if((t[0]&192)!==128)return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if((t[1]&192)!==128)return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&(t[2]&192)!==128)return e.lastNeed=2,"�"}}function wl(e){var t=this.lastTotal-this.lastNeed,r=bl(this,e);if(r!==void 0)return r;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function gl(e,t){var r=yl(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)}function ml(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function _l(e,t){if((e.length-t)%2===0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function vl(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function El(e,t){var r=(e.length-t)%3;return r===0?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function xl(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Sl(e){return e.toString(this.encoding)}function Bl(e){return e&&e.length?this.write(e):""}var Mo=cr.codes.ERR_STREAM_PREMATURE_CLOSE;function Pl(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];e.apply(this,n)}}}function Tl(){}function Al(e){return e.setHeader&&typeof e.abort=="function"}function pf(e,t,r){if(typeof t=="function")return pf(e,null,t);t||(t={}),r=Pl(r||Tl);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||a()},o=e._writableState&&e._writableState.finished,a=function(){i=!1,o=!0,n||r.call(e)},c=e._readableState&&e._readableState.endEmitted,l=function(){n=!1,c=!0,i||r.call(e)},d=function(O){r.call(e,O)},g=function(){var O;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(O=new Mo),r.call(e,O);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(O=new Mo),r.call(e,O)},x=function(){e.req.on("finish",a)};return Al(e)?(e.on("complete",a),e.on("abort",g),e.req?x():e.on("request",x)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",l),e.on("finish",a),t.error!==!1&&e.on("error",d),e.on("close",g),function(){e.removeListener("complete",a),e.removeListener("abort",g),e.removeListener("request",x),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",l),e.removeListener("error",d),e.removeListener("close",g)}}var zs=pf,Ji,Ho;function Il(){if(Ho)return Ji;Ho=1;var e;function t(_,m,S){return m=r(m),m in _?Object.defineProperty(_,m,{value:S,enumerable:!0,configurable:!0,writable:!0}):_[m]=S,_}function r(_){var m=n(_,"string");return typeof m=="symbol"?m:String(m)}function n(_,m){if(typeof _!="object"||_===null)return _;var S=_[Symbol.toPrimitive];if(S!==void 0){var E=S.call(_,m||"default");if(typeof E!="object")return E;throw new TypeError("@@toPrimitive must return a primitive value.")}return(m==="string"?String:Number)(_)}var i=zs,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),l=Symbol("lastPromise"),d=Symbol("handlePromise"),g=Symbol("stream");function x(_,m){return{value:_,done:m}}function y(_){var m=_[s];if(m!==null){var S=_[g].read();S!==null&&(_[l]=null,_[s]=null,_[o]=null,m(x(S,!1)))}}function O(_){process.nextTick(y,_)}function B(_,m){return function(S,E){_.then(function(){if(m[c]){S(x(void 0,!0));return}m[d](S,E)},E)}}var A=Object.getPrototypeOf(function(){}),k=Object.setPrototypeOf((e={get stream(){return this[g]},next:function(){var m=this,S=this[a];if(S!==null)return Promise.reject(S);if(this[c])return Promise.resolve(x(void 0,!0));if(this[g].destroyed)return new Promise(function(R,z){process.nextTick(function(){m[a]?z(m[a]):R(x(void 0,!0))})});var E=this[l],H;if(E)H=new Promise(B(E,this));else{var D=this[g].read();if(D!==null)return Promise.resolve(x(D,!1));H=new Promise(this[d])}return this[l]=H,H}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var m=this;return new Promise(function(S,E){m[g].destroy(null,function(H){if(H){E(H);return}S(x(void 0,!0))})})}),e),A),U=function(m){var S,E=Object.create(k,(S={},t(S,g,{value:m,writable:!0}),t(S,s,{value:null,writable:!0}),t(S,o,{value:null,writable:!0}),t(S,a,{value:null,writable:!0}),t(S,c,{value:m._readableState.endEmitted,writable:!0}),t(S,d,{value:function(D,R){var z=E[g].read();z?(E[l]=null,E[s]=null,E[o]=null,D(x(z,!1))):(E[s]=D,E[o]=R)},writable:!0}),S));return E[l]=null,i(m,function(H){if(H&&H.code!=="ERR_STREAM_PREMATURE_CLOSE"){var D=E[o];D!==null&&(E[l]=null,E[s]=null,E[o]=null,D(H)),E[a]=H;return}var R=E[s];R!==null&&(E[l]=null,E[s]=null,E[o]=null,R(x(void 0,!0))),E[c]=!0}),m.on("readable",O.bind(null,E)),E};return Ji=U,Ji}var Qi,$o;function Ol(){return $o||($o=1,Qi=function(){throw new Error("Readable.from is not available in the browser")}),Qi}var Zi,Do;function yf(){if(Do)return Zi;Do=1,Zi=R;var e;R.ReadableState=D,ff.EventEmitter;var t=function(w,N){return w.listeners(N).length},r=uf,n=Tt.Buffer,i=(typeof $t<"u"?$t:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(b){return n.from(b)}function o(b){return n.isBuffer(b)||b instanceof i}var a=Ws,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var l=el(),d=cf,g=lf,x=g.getHighWaterMark,y=cr.codes,O=y.ERR_INVALID_ARG_TYPE,B=y.ERR_STREAM_PUSH_AFTER_EOF,A=y.ERR_METHOD_NOT_IMPLEMENTED,k=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,U,_,m;ke(R,r);var S=d.errorOrDestroy,E=["error","close","destroy","pause","resume"];function H(b,w,N){if(typeof b.prependListener=="function")return b.prependListener(w,N);!b._events||!b._events[w]?b.on(w,N):Array.isArray(b._events[w])?b._events[w].unshift(N):b._events[w]=[N,b._events[w]]}function D(b,w,N){e=e||Cr(),b=b||{},typeof N!="boolean"&&(N=w instanceof e),this.objectMode=!!b.objectMode,N&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=x(this,b,"readableHighWaterMark",N),this.buffer=new l,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=b.emitClose!==!1,this.autoDestroy=!!b.autoDestroy,this.destroyed=!1,this.defaultEncoding=b.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,b.encoding&&(U||(U=Qn.StringDecoder),this.decoder=new U(b.encoding),this.encoding=b.encoding)}function R(b){if(e=e||Cr(),!(this instanceof R))return new R(b);var w=this instanceof e;this._readableState=new D(b,this,w),this.readable=!0,b&&(typeof b.read=="function"&&(this._read=b.read),typeof b.destroy=="function"&&(this._destroy=b.destroy)),r.call(this)}Object.defineProperty(R.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(w){this._readableState&&(this._readableState.destroyed=w)}}),R.prototype.destroy=d.destroy,R.prototype._undestroy=d.undestroy,R.prototype._destroy=function(b,w){w(b)},R.prototype.push=function(b,w){var N=this._readableState,$;return N.objectMode?$=!0:typeof b=="string"&&(w=w||N.defaultEncoding,w!==N.encoding&&(b=n.from(b,w),w=""),$=!0),z(this,b,w,!1,$)},R.prototype.unshift=function(b){return z(this,b,null,!0,!1)};function z(b,w,N,$,we){c("readableAddChunk",w);var Y=b._readableState;if(w===null)Y.reading=!1,fe(b,Y);else{var te;if(we||(te=C(Y,w)),te)S(b,te);else if(Y.objectMode||w&&w.length>0)if(typeof w!="string"&&!Y.objectMode&&Object.getPrototypeOf(w)!==n.prototype&&(w=s(w)),$)Y.endEmitted?S(b,new k):Z(b,Y,w,!0);else if(Y.ended)S(b,new B);else{if(Y.destroyed)return!1;Y.reading=!1,Y.decoder&&!N?(w=Y.decoder.write(w),Y.objectMode||w.length!==0?Z(b,Y,w,!1):Ve(b,Y)):Z(b,Y,w,!1)}else $||(Y.reading=!1,Ve(b,Y))}return!Y.ended&&(Y.length<Y.highWaterMark||Y.length===0)}function Z(b,w,N,$){w.flowing&&w.length===0&&!w.sync?(w.awaitDrain=0,b.emit("data",N)):(w.length+=w.objectMode?1:N.length,$?w.buffer.unshift(N):w.buffer.push(N),w.needReadable&&ue(b)),Ve(b,w)}function C(b,w){var N;return!o(w)&&typeof w!="string"&&w!==void 0&&!b.objectMode&&(N=new O("chunk",["string","Buffer","Uint8Array"],w)),N}R.prototype.isPaused=function(){return this._readableState.flowing===!1},R.prototype.setEncoding=function(b){U||(U=Qn.StringDecoder);var w=new U(b);this._readableState.decoder=w,this._readableState.encoding=this._readableState.decoder.encoding;for(var N=this._readableState.buffer.head,$="";N!==null;)$+=w.write(N.data),N=N.next;return this._readableState.buffer.clear(),$!==""&&this._readableState.buffer.push($),this._readableState.length=$.length,this};var M=1073741824;function W(b){return b>=M?b=M:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function q(b,w){return b<=0||w.length===0&&w.ended?0:w.objectMode?1:b!==b?w.flowing&&w.length?w.buffer.head.data.length:w.length:(b>w.highWaterMark&&(w.highWaterMark=W(b)),b<=w.length?b:w.ended?w.length:(w.needReadable=!0,0))}R.prototype.read=function(b){c("read",b),b=parseInt(b,10);var w=this._readableState,N=b;if(b!==0&&(w.emittedReadable=!1),b===0&&w.needReadable&&((w.highWaterMark!==0?w.length>=w.highWaterMark:w.length>0)||w.ended))return c("read: emitReadable",w.length,w.ended),w.length===0&&w.ended?F(this):ue(this),null;if(b=q(b,w),b===0&&w.ended)return w.length===0&&F(this),null;var $=w.needReadable;c("need readable",$),(w.length===0||w.length-b<w.highWaterMark)&&($=!0,c("length less than watermark",$)),w.ended||w.reading?($=!1,c("reading or ended",$)):$&&(c("do read"),w.reading=!0,w.sync=!0,w.length===0&&(w.needReadable=!0),this._read(w.highWaterMark),w.sync=!1,w.reading||(b=q(N,w)));var we;return b>0?we=P(b,w):we=null,we===null?(w.needReadable=w.length<=w.highWaterMark,b=0):(w.length-=b,w.awaitDrain=0),w.length===0&&(w.ended||(w.needReadable=!0),N!==b&&w.ended&&F(this)),we!==null&&this.emit("data",we),we};function fe(b,w){if(c("onEofChunk"),!w.ended){if(w.decoder){var N=w.decoder.end();N&&N.length&&(w.buffer.push(N),w.length+=w.objectMode?1:N.length)}w.ended=!0,w.sync?ue(b):(w.needReadable=!1,w.emittedReadable||(w.emittedReadable=!0,et(b)))}}function ue(b){var w=b._readableState;c("emitReadable",w.needReadable,w.emittedReadable),w.needReadable=!1,w.emittedReadable||(c("emitReadable",w.flowing),w.emittedReadable=!0,process.nextTick(et,b))}function et(b){var w=b._readableState;c("emitReadable_",w.destroyed,w.length,w.ended),!w.destroyed&&(w.length||w.ended)&&(b.emit("readable"),w.emittedReadable=!1),w.needReadable=!w.flowing&&!w.ended&&w.length<=w.highWaterMark,T(b)}function Ve(b,w){w.readingMore||(w.readingMore=!0,process.nextTick(it,b,w))}function it(b,w){for(;!w.reading&&!w.ended&&(w.length<w.highWaterMark||w.flowing&&w.length===0);){var N=w.length;if(c("maybeReadMore read 0"),b.read(0),N===w.length)break}w.readingMore=!1}R.prototype._read=function(b){S(this,new A("_read()"))},R.prototype.pipe=function(b,w){var N=this,$=this._readableState;switch($.pipesCount){case 0:$.pipes=b;break;case 1:$.pipes=[$.pipes,b];break;default:$.pipes.push(b);break}$.pipesCount+=1,c("pipe count=%d opts=%j",$.pipesCount,w);var we=(!w||w.end!==!1)&&b!==process.stdout&&b!==process.stderr,Y=we?It:qt;$.endEmitted?process.nextTick(Y):N.once("end",Y),b.on("unpipe",te);function te(h,f){c("onunpipe"),h===N&&f&&f.hasUnpiped===!1&&(f.hasUnpiped=!0,pr())}function It(){c("onend"),b.end()}var dr=be(N);b.on("drain",dr);var Hr=!1;function pr(){c("cleanup"),b.removeListener("close",$r),b.removeListener("finish",Xe),b.removeListener("drain",dr),b.removeListener("error",zt),b.removeListener("unpipe",te),N.removeListener("end",It),N.removeListener("end",qt),N.removeListener("data",qe),Hr=!0,$.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&dr()}N.on("data",qe);function qe(h){c("ondata");var f=b.write(h);c("dest.write",f),f===!1&&(($.pipesCount===1&&$.pipes===b||$.pipesCount>1&&K($.pipes,b)!==-1)&&!Hr&&(c("false write response, pause",$.awaitDrain),$.awaitDrain++),N.pause())}function zt(h){c("onerror",h),qt(),b.removeListener("error",zt),t(b,"error")===0&&S(b,h)}H(b,"error",zt);function $r(){b.removeListener("finish",Xe),qt()}b.once("close",$r);function Xe(){c("onfinish"),b.removeListener("close",$r),qt()}b.once("finish",Xe);function qt(){c("unpipe"),N.unpipe(b)}return b.emit("pipe",N),$.flowing||(c("pipe resume"),N.resume()),b};function be(b){return function(){var N=b._readableState;c("pipeOnDrain",N.awaitDrain),N.awaitDrain&&N.awaitDrain--,N.awaitDrain===0&&t(b,"data")&&(N.flowing=!0,T(b))}}R.prototype.unpipe=function(b){var w=this._readableState,N={hasUnpiped:!1};if(w.pipesCount===0)return this;if(w.pipesCount===1)return b&&b!==w.pipes?this:(b||(b=w.pipes),w.pipes=null,w.pipesCount=0,w.flowing=!1,b&&b.emit("unpipe",this,N),this);if(!b){var $=w.pipes,we=w.pipesCount;w.pipes=null,w.pipesCount=0,w.flowing=!1;for(var Y=0;Y<we;Y++)$[Y].emit("unpipe",this,{hasUnpiped:!1});return this}var te=K(w.pipes,b);return te===-1?this:(w.pipes.splice(te,1),w.pipesCount-=1,w.pipesCount===1&&(w.pipes=w.pipes[0]),b.emit("unpipe",this,N),this)},R.prototype.on=function(b,w){var N=r.prototype.on.call(this,b,w),$=this._readableState;return b==="data"?($.readableListening=this.listenerCount("readable")>0,$.flowing!==!1&&this.resume()):b==="readable"&&!$.endEmitted&&!$.readableListening&&($.readableListening=$.needReadable=!0,$.flowing=!1,$.emittedReadable=!1,c("on readable",$.length,$.reading),$.length?ue(this):$.reading||process.nextTick(ze,this)),N},R.prototype.addListener=R.prototype.on,R.prototype.removeListener=function(b,w){var N=r.prototype.removeListener.call(this,b,w);return b==="readable"&&process.nextTick(xe,this),N},R.prototype.removeAllListeners=function(b){var w=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&process.nextTick(xe,this),w};function xe(b){var w=b._readableState;w.readableListening=b.listenerCount("readable")>0,w.resumeScheduled&&!w.paused?w.flowing=!0:b.listenerCount("data")>0&&b.resume()}function ze(b){c("readable nexttick read 0"),b.read(0)}R.prototype.resume=function(){var b=this._readableState;return b.flowing||(c("resume"),b.flowing=!b.readableListening,At(this,b)),b.paused=!1,this};function At(b,w){w.resumeScheduled||(w.resumeScheduled=!0,process.nextTick(pt,b,w))}function pt(b,w){c("resume",w.reading),w.reading||b.read(0),w.resumeScheduled=!1,b.emit("resume"),T(b),w.flowing&&!w.reading&&b.read(0)}R.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function T(b){var w=b._readableState;for(c("flow",w.flowing);w.flowing&&b.read()!==null;);}R.prototype.wrap=function(b){var w=this,N=this._readableState,$=!1;b.on("end",function(){if(c("wrapped end"),N.decoder&&!N.ended){var te=N.decoder.end();te&&te.length&&w.push(te)}w.push(null)}),b.on("data",function(te){if(c("wrapped data"),N.decoder&&(te=N.decoder.write(te)),!(N.objectMode&&te==null)&&!(!N.objectMode&&(!te||!te.length))){var It=w.push(te);It||($=!0,b.pause())}});for(var we in b)this[we]===void 0&&typeof b[we]=="function"&&(this[we]=function(It){return function(){return b[It].apply(b,arguments)}}(we));for(var Y=0;Y<E.length;Y++)b.on(E[Y],this.emit.bind(this,E[Y]));return this._read=function(te){c("wrapped _read",te),$&&($=!1,b.resume())},this},typeof Symbol=="function"&&(R.prototype[Symbol.asyncIterator]=function(){return _===void 0&&(_=Il()),_(this)}),Object.defineProperty(R.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(R.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(R.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(w){this._readableState&&(this._readableState.flowing=w)}}),R._fromList=P,Object.defineProperty(R.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function P(b,w){if(w.length===0)return null;var N;return w.objectMode?N=w.buffer.shift():!b||b>=w.length?(w.decoder?N=w.buffer.join(""):w.buffer.length===1?N=w.buffer.first():N=w.buffer.concat(w.length),w.buffer.clear()):N=w.buffer.consume(b,w.decoder),N}function F(b){var w=b._readableState;c("endReadable",w.endEmitted),w.endEmitted||(w.ended=!0,process.nextTick(G,w,b))}function G(b,w){if(c("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,w.readable=!1,w.emit("end"),b.autoDestroy)){var N=w._writableState;(!N||N.autoDestroy&&N.finished)&&w.destroy()}}typeof Symbol=="function"&&(R.from=function(b,w){return m===void 0&&(m=Ol()),m(R,b,w)});function K(b,w){for(var N=0,$=b.length;N<$;N++)if(b[N]===w)return N;return-1}return Zi}var bf=Pt,bi=cr.codes,kl=bi.ERR_METHOD_NOT_IMPLEMENTED,Rl=bi.ERR_MULTIPLE_CALLBACK,Ul=bi.ERR_TRANSFORM_ALREADY_TRANSFORMING,Cl=bi.ERR_TRANSFORM_WITH_LENGTH_0,wi=Cr();ke(Pt,wi);function Ll(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new Rl);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Pt(e){if(!(this instanceof Pt))return new Pt(e);wi.call(this,e),this._transformState={afterTransform:Ll.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.on("prefinish",Nl)}function Nl(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){jo(e,t,r)}):jo(this,null,null)}Pt.prototype.push=function(e,t){return this._transformState.needTransform=!1,wi.prototype.push.call(this,e,t)};Pt.prototype._transform=function(e,t,r){r(new kl("_transform()"))};Pt.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)}};Pt.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};Pt.prototype._destroy=function(e,t){wi.prototype._destroy.call(this,e,function(r){t(r)})};function jo(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Cl;if(e._transformState.transforming)throw new Ul;return e.push(null)}var Fl=dn,wf=bf;ke(dn,wf);function dn(e){if(!(this instanceof dn))return new dn(e);wf.call(this,e)}dn.prototype._transform=function(e,t,r){r(null,e)};var es;function Ml(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var gf=cr.codes,Hl=gf.ERR_MISSING_ARGS,$l=gf.ERR_STREAM_DESTROYED;function Go(e){if(e)throw e}function Dl(e){return e.setHeader&&typeof e.abort=="function"}function jl(e,t,r,n){n=Ml(n);var i=!1;e.on("close",function(){i=!0}),es===void 0&&(es=zs),es(e,{readable:t,writable:r},function(o){if(o)return n(o);i=!0,n()});var s=!1;return function(o){if(!i&&!s){if(s=!0,Dl(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new $l("pipe"))}}}function Wo(e){e()}function Gl(e,t){return e.pipe(t)}function Wl(e){return!e.length||typeof e[e.length-1]!="function"?Go:e.pop()}function Vl(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=Wl(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Hl("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,l=a>0;return jl(o,c,l,function(d){i||(i=d),d&&s.forEach(Wo),!c&&(s.forEach(Wo),n(i))})});return t.reduce(Gl)}var zl=Vl;(function(e,t){t=e.exports=yf(),t.Stream=t,t.Readable=t,t.Writable=df(),t.Duplex=Cr(),t.Transform=bf,t.PassThrough=Fl,t.finished=zs,t.pipeline=zl})(bs,bs.exports);var mf=bs.exports,Zn=We.Buffer,_f=mf.Transform,ql=ke;function Kl(e,t){if(!Zn.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Gt(e){_f.call(this),this._block=Zn.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}ql(Gt,_f);Gt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Gt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Gt.prototype.update=function(e,t){if(Kl(e,"Data"),this._finalized)throw new Error("Digest already called");Zn.isBuffer(e)||(e=Zn.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};Gt.prototype._update=function(){throw new Error("_update is not implemented")};Gt.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};Gt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Yl=Gt,Xl=ke,vf=Yl,Jl=We.Buffer,Ql=new Array(16);function gi(){vf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}Xl(gi,vf);gi.prototype._update=function(){for(var e=Ql,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,s=this._d;r=Re(r,n,i,s,e[0],3614090360,7),s=Re(s,r,n,i,e[1],3905402710,12),i=Re(i,s,r,n,e[2],606105819,17),n=Re(n,i,s,r,e[3],3250441966,22),r=Re(r,n,i,s,e[4],4118548399,7),s=Re(s,r,n,i,e[5],1200080426,12),i=Re(i,s,r,n,e[6],2821735955,17),n=Re(n,i,s,r,e[7],4249261313,22),r=Re(r,n,i,s,e[8],1770035416,7),s=Re(s,r,n,i,e[9],2336552879,12),i=Re(i,s,r,n,e[10],4294925233,17),n=Re(n,i,s,r,e[11],2304563134,22),r=Re(r,n,i,s,e[12],1804603682,7),s=Re(s,r,n,i,e[13],4254626195,12),i=Re(i,s,r,n,e[14],2792965006,17),n=Re(n,i,s,r,e[15],1236535329,22),r=Ue(r,n,i,s,e[1],4129170786,5),s=Ue(s,r,n,i,e[6],3225465664,9),i=Ue(i,s,r,n,e[11],643717713,14),n=Ue(n,i,s,r,e[0],3921069994,20),r=Ue(r,n,i,s,e[5],3593408605,5),s=Ue(s,r,n,i,e[10],38016083,9),i=Ue(i,s,r,n,e[15],3634488961,14),n=Ue(n,i,s,r,e[4],3889429448,20),r=Ue(r,n,i,s,e[9],568446438,5),s=Ue(s,r,n,i,e[14],3275163606,9),i=Ue(i,s,r,n,e[3],4107603335,14),n=Ue(n,i,s,r,e[8],1163531501,20),r=Ue(r,n,i,s,e[13],2850285829,5),s=Ue(s,r,n,i,e[2],4243563512,9),i=Ue(i,s,r,n,e[7],1735328473,14),n=Ue(n,i,s,r,e[12],2368359562,20),r=Ce(r,n,i,s,e[5],4294588738,4),s=Ce(s,r,n,i,e[8],2272392833,11),i=Ce(i,s,r,n,e[11],1839030562,16),n=Ce(n,i,s,r,e[14],4259657740,23),r=Ce(r,n,i,s,e[1],2763975236,4),s=Ce(s,r,n,i,e[4],1272893353,11),i=Ce(i,s,r,n,e[7],4139469664,16),n=Ce(n,i,s,r,e[10],3200236656,23),r=Ce(r,n,i,s,e[13],681279174,4),s=Ce(s,r,n,i,e[0],3936430074,11),i=Ce(i,s,r,n,e[3],3572445317,16),n=Ce(n,i,s,r,e[6],76029189,23),r=Ce(r,n,i,s,e[9],3654602809,4),s=Ce(s,r,n,i,e[12],3873151461,11),i=Ce(i,s,r,n,e[15],530742520,16),n=Ce(n,i,s,r,e[2],3299628645,23),r=Le(r,n,i,s,e[0],4096336452,6),s=Le(s,r,n,i,e[7],1126891415,10),i=Le(i,s,r,n,e[14],2878612391,15),n=Le(n,i,s,r,e[5],4237533241,21),r=Le(r,n,i,s,e[12],1700485571,6),s=Le(s,r,n,i,e[3],2399980690,10),i=Le(i,s,r,n,e[10],4293915773,15),n=Le(n,i,s,r,e[1],2240044497,21),r=Le(r,n,i,s,e[8],1873313359,6),s=Le(s,r,n,i,e[15],4264355552,10),i=Le(i,s,r,n,e[6],2734768916,15),n=Le(n,i,s,r,e[13],1309151649,21),r=Le(r,n,i,s,e[4],4149444226,6),s=Le(s,r,n,i,e[11],3174756917,10),i=Le(i,s,r,n,e[2],718787259,15),n=Le(n,i,s,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+s|0};gi.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Jl.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};function mi(e,t){return e<<t|e>>>32-t}function Re(e,t,r,n,i,s,o){return mi(e+(t&r|~t&n)+i+s|0,o)+t|0}function Ue(e,t,r,n,i,s,o){return mi(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ce(e,t,r,n,i,s,o){return mi(e+(t^r^n)+i+s|0,o)+t|0}function Le(e,t,r,n,i,s,o){return mi(e+(r^(t|~n))+i+s|0,o)+t|0}var Zl=gi,ei=We.Buffer,Ef=mf.Transform,e0=ke;function t0(e,t){if(!ei.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Wt(e){Ef.call(this),this._block=ei.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}e0(Wt,Ef);Wt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Wt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Wt.prototype.update=function(e,t){if(t0(e,"Data"),this._finalized)throw new Error("Digest already called");ei.isBuffer(e)||(e=ei.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};Wt.prototype._update=function(){throw new Error("_update is not implemented")};Wt.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};Wt.prototype._digest=function(){throw new Error("_digest is not implemented")};var r0=Wt,ts=Tt.Buffer,n0=ke,xf=r0,i0=new Array(16),qr=[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],Kr=[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],Yr=[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],Xr=[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],Jr=[0,1518500249,1859775393,2400959708,2840853838],Qr=[1352829926,1548603684,1836072691,2053994217,0];function _i(){xf.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}n0(_i,xf);_i.prototype._update=function(){for(var e=i0,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._a|0,c=this._b|0,l=this._c|0,d=this._d|0,g=this._e|0,x=0;x<80;x+=1){var y,O;x<16?(y=Vo(r,n,i,s,o,e[qr[x]],Jr[0],Yr[x]),O=Yo(a,c,l,d,g,e[Kr[x]],Qr[0],Xr[x])):x<32?(y=zo(r,n,i,s,o,e[qr[x]],Jr[1],Yr[x]),O=Ko(a,c,l,d,g,e[Kr[x]],Qr[1],Xr[x])):x<48?(y=qo(r,n,i,s,o,e[qr[x]],Jr[2],Yr[x]),O=qo(a,c,l,d,g,e[Kr[x]],Qr[2],Xr[x])):x<64?(y=Ko(r,n,i,s,o,e[qr[x]],Jr[3],Yr[x]),O=zo(a,c,l,d,g,e[Kr[x]],Qr[3],Xr[x])):(y=Yo(r,n,i,s,o,e[qr[x]],Jr[4],Yr[x]),O=Vo(a,c,l,d,g,e[Kr[x]],Qr[4],Xr[x])),r=o,o=s,s=nr(i,10),i=n,n=y,a=g,g=d,d=nr(l,10),l=c,c=O}var B=this._b+i+d|0;this._b=this._c+s+g|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+l|0,this._a=B};_i.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=ts.alloc?ts.alloc(20):new ts(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};function nr(e,t){return e<<t|e>>>32-t}function Vo(e,t,r,n,i,s,o,a){return nr(e+(t^r^n)+s+o|0,a)+i|0}function zo(e,t,r,n,i,s,o,a){return nr(e+(t&r|~t&n)+s+o|0,a)+i|0}function qo(e,t,r,n,i,s,o,a){return nr(e+((t|~r)^n)+s+o|0,a)+i|0}function Ko(e,t,r,n,i,s,o,a){return nr(e+(t&n|r&~n)+s+o|0,a)+i|0}function Yo(e,t,r,n,i,s,o,a){return nr(e+(t^(r|~n))+s+o|0,a)+i|0}var s0=_i,Sf={exports:{}},Bf=We.Buffer;function vi(e,t){this._block=Bf.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}vi.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Bf.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,s=this._len,o=0;o<i;){for(var a=s%n,c=Math.min(i-o,n-a),l=0;l<c;l++)r[a+l]=e[o+l];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};vi.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=this._len*8;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(r&4294967295)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var s=this._hash();return e?s.toString(e):s};vi.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Nr=vi,o0=ke,Pf=Nr,a0=We.Buffer,f0=[1518500249,1859775393,-1894007588,-899497514],u0=new Array(80);function mn(){this.init(),this._w=u0,Pf.call(this,64,56)}o0(mn,Pf);mn.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function c0(e){return e<<5|e>>>27}function h0(e){return e<<30|e>>>2}function l0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}mn.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=t[a-3]^t[a-8]^t[a-14]^t[a-16];for(var c=0;c<80;++c){var l=~~(c/20),d=c0(r)+l0(l,n,i,s)+o+t[c]+f0[l]|0;o=s,s=i,i=h0(n),n=r,r=d}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0};mn.prototype._hash=function(){var e=a0.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var d0=mn,p0=ke,Tf=Nr,y0=We.Buffer,b0=[1518500249,1859775393,-1894007588,-899497514],w0=new Array(80);function _n(){this.init(),this._w=w0,Tf.call(this,64,56)}p0(_n,Tf);_n.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function g0(e){return e<<1|e>>>31}function m0(e){return e<<5|e>>>27}function _0(e){return e<<30|e>>>2}function v0(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}_n.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=g0(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var l=~~(c/20),d=m0(r)+v0(l,n,i,s)+o+t[c]+b0[l]|0;o=s,s=i,i=_0(n),n=r,r=d}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0};_n.prototype._hash=function(){var e=y0.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var E0=_n,x0=ke,Af=Nr,S0=We.Buffer,B0=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],P0=new Array(64);function vn(){this.init(),this._w=P0,Af.call(this,64,56)}x0(vn,Af);vn.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this};function T0(e,t,r){return r^e&(t^r)}function A0(e,t,r){return e&t|r&(e|t)}function I0(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function O0(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function k0(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function R0(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}vn.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._f|0,c=this._g|0,l=this._h|0,d=0;d<16;++d)t[d]=e.readInt32BE(d*4);for(;d<64;++d)t[d]=R0(t[d-2])+t[d-7]+k0(t[d-15])+t[d-16]|0;for(var g=0;g<64;++g){var x=l+O0(o)+T0(o,a,c)+B0[g]+t[g]|0,y=I0(r)+A0(r,n,i)|0;l=c,c=a,a=o,o=s+x|0,s=i,i=n,n=r,r=x+y|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=l+this._h|0};vn.prototype._hash=function(){var e=S0.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var If=vn,U0=ke,C0=If,L0=Nr,N0=We.Buffer,F0=new Array(64);function Ei(){this.init(),this._w=F0,L0.call(this,64,56)}U0(Ei,C0);Ei.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this};Ei.prototype._hash=function(){var e=N0.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var M0=Ei,H0=ke,Of=Nr,$0=We.Buffer,Xo=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],D0=new Array(160);function En(){this.init(),this._w=D0,Of.call(this,128,112)}H0(En,Of);En.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this};function Jo(e,t,r){return r^e&(t^r)}function Qo(e,t,r){return e&t|r&(e|t)}function Zo(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function ea(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function j0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function G0(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function W0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function V0(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ae(e,t){return e>>>0<t>>>0?1:0}En.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,s=this._dh|0,o=this._eh|0,a=this._fh|0,c=this._gh|0,l=this._hh|0,d=this._al|0,g=this._bl|0,x=this._cl|0,y=this._dl|0,O=this._el|0,B=this._fl|0,A=this._gl|0,k=this._hl|0,U=0;U<32;U+=2)t[U]=e.readInt32BE(U*4),t[U+1]=e.readInt32BE(U*4+4);for(;U<160;U+=2){var _=t[U-30],m=t[U-15*2+1],S=j0(_,m),E=G0(m,_);_=t[U-2*2],m=t[U-2*2+1];var H=W0(_,m),D=V0(m,_),R=t[U-7*2],z=t[U-7*2+1],Z=t[U-16*2],C=t[U-16*2+1],M=E+z|0,W=S+R+Ae(M,E)|0;M=M+D|0,W=W+H+Ae(M,D)|0,M=M+C|0,W=W+Z+Ae(M,C)|0,t[U]=W,t[U+1]=M}for(var q=0;q<160;q+=2){W=t[q],M=t[q+1];var fe=Qo(r,n,i),ue=Qo(d,g,x),et=Zo(r,d),Ve=Zo(d,r),it=ea(o,O),be=ea(O,o),xe=Xo[q],ze=Xo[q+1],At=Jo(o,a,c),pt=Jo(O,B,A),T=k+be|0,P=l+it+Ae(T,k)|0;T=T+pt|0,P=P+At+Ae(T,pt)|0,T=T+ze|0,P=P+xe+Ae(T,ze)|0,T=T+M|0,P=P+W+Ae(T,M)|0;var F=Ve+ue|0,G=et+fe+Ae(F,Ve)|0;l=c,k=A,c=a,A=B,a=o,B=O,O=y+T|0,o=s+P+Ae(O,y)|0,s=i,y=x,i=n,x=g,n=r,g=d,d=T+F|0,r=P+G+Ae(d,T)|0}this._al=this._al+d|0,this._bl=this._bl+g|0,this._cl=this._cl+x|0,this._dl=this._dl+y|0,this._el=this._el+O|0,this._fl=this._fl+B|0,this._gl=this._gl+A|0,this._hl=this._hl+k|0,this._ah=this._ah+r+Ae(this._al,d)|0,this._bh=this._bh+n+Ae(this._bl,g)|0,this._ch=this._ch+i+Ae(this._cl,x)|0,this._dh=this._dh+s+Ae(this._dl,y)|0,this._eh=this._eh+o+Ae(this._el,O)|0,this._fh=this._fh+a+Ae(this._fl,B)|0,this._gh=this._gh+c+Ae(this._gl,A)|0,this._hh=this._hh+l+Ae(this._hl,k)|0};En.prototype._hash=function(){var e=$0.allocUnsafe(64);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var kf=En,z0=ke,q0=kf,K0=Nr,Y0=We.Buffer,X0=new Array(160);function xi(){this.init(),this._w=X0,K0.call(this,128,112)}z0(xi,q0);xi.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this};xi.prototype._hash=function(){var e=Y0.allocUnsafe(48);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var J0=xi,hr=Sf.exports=function(t){t=t.toLowerCase();var r=hr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};hr.sha=d0;hr.sha1=E0;hr.sha224=M0;hr.sha256=If;hr.sha384=J0;hr.sha512=kf;var Q0=Sf.exports,Rf=We.Buffer,Uf=Ws.Transform,Z0=Qn.StringDecoder,ed=ke;function nt(e){Uf.call(this),this.hashMode=typeof e=="string",this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}ed(nt,Uf);nt.prototype.update=function(e,t,r){typeof e=="string"&&(e=Rf.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};nt.prototype.setAutoPadding=function(){};nt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};nt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};nt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};nt.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(i){n=i}finally{r(n)}};nt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};nt.prototype._finalOrDigest=function(e){var t=this.__final()||Rf.alloc(0);return e&&(t=this._toString(t,e,!0)),t};nt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Z0(t),this._encoding=t),this._encoding!==t)throw new Error("can't switch encodings");var n=this._decoder.write(e);return r&&(n+=this._decoder.end()),n};var td=nt,rd=ke,nd=Zl,id=s0,sd=Q0,Cf=td;function Si(e){Cf.call(this,"digest"),this._hash=e}rd(Si,Cf);Si.prototype._update=function(e){this._hash.update(e)};Si.prototype._final=function(){return this._hash.digest()};var od=function(t){return t=t.toLowerCase(),t==="md5"?new nd:t==="rmd160"||t==="ripemd160"?new id:new Si(sd(t))},Cn=We.Buffer;function ad(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(y){if((Array.isArray(y)||y instanceof Uint8Array)&&(y=Cn.from(y)),!Cn.isBuffer(y))throw new TypeError("Expected Buffer");if(y.length===0)return"";for(var O=0,B=0,A=0,k=y.length;A!==k&&y[A]===0;)A++,O++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=y[A],S=0,E=U-1;(m!==0||S<B)&&E!==-1;E--,S++)m+=256*_[E]>>>0,_[E]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");B=S,A++}for(var H=U-B;H!==U&&_[H]===0;)H++;for(var D=a.repeat(O);H<U;++H)D+=e.charAt(_[H]);return D}function g(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return Cn.alloc(0);for(var O=0,B=0,A=0;y[O]===a;)B++,O++;for(var k=(y.length-O)*c+1>>>0,U=new Uint8Array(k);O<y.length;){var _=t[y.charCodeAt(O)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,O++}for(var E=k-A;E!==k&&U[E]===0;)E++;var H=Cn.allocUnsafe(B+(k-E));H.fill(0,0,B);for(var D=B;E!==k;)H[D++]=U[E++];return H}function x(y){var O=g(y);if(O)return O;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:g,decode:x}}var fd=ad,ud=fd,cd="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",hd=ud(cd),rs=hd,ld=We.Buffer,dd=function(e){function t(s){var o=e(s);return rs.encode(ld.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=rs.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=rs.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},ta=od,pd=dd;function yd(e){var t=ta("sha256").update(e).digest();return ta("sha256").update(t).digest()}var bd=pd(yd),gs=bd;function Lf(e,t){if(t!==void 0&&e[0]!==t)throw new Error("Invalid network version");if(e.length===33)return{version:e[0],privateKey:e.slice(1,33),compressed:!1};if(e.length!==34)throw new Error("Invalid WIF length");if(e[33]!==1)throw new Error("Invalid compression flag");return{version:e[0],privateKey:e.slice(1,33),compressed:!0}}function ms(e,t,r){var n=new Buffer(r?34:33);return n.writeUInt8(e,0),t.copy(n,1),r&&(n[33]=1),n}function wd(e,t){return Lf(gs.decode(e),t)}function gd(e,t,r){return typeof e=="number"?gs.encode(ms(e,t,r)):gs.encode(ms(e.version,e.privateKey,e.compressed))}var md={decode:wd,decodeRaw:Lf,encode:gd,encodeRaw:ms},Bi={};Object.defineProperty(Bi,"__esModule",{value:!0});Bi.testEcc=void 0;const V=e=>Buffer.from(e,"hex");function _d(e){he(e.isPoint(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(!e.isPoint(V("030000000000000000000000000000000000000000000000000000000000000005"))),he(e.isPrivate(V("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),he(!e.isPrivate(V("0000000000000000000000000000000000000000000000000000000000000000"))),he(!e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),he(!e.isPrivate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),he(Buffer.from(e.privateAdd(V("0000000000000000000000000000000000000000000000000000000000000001"),V("0000000000000000000000000000000000000000000000000000000000000000"))).equals(V("0000000000000000000000000000000000000000000000000000000000000001"))),he(e.privateAdd(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),V("0000000000000000000000000000000000000000000000000000000000000003"))===null),he(Buffer.from(e.privateAdd(V("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),V("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(V("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),he(Buffer.from(e.privateNegate(V("0000000000000000000000000000000000000000000000000000000000000001"))).equals(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),he(Buffer.from(e.privateNegate(V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(V("0000000000000000000000000000000000000000000000000000000000000003"))),he(Buffer.from(e.privateNegate(V("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(V("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),he(Buffer.from(e.pointCompress(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(Buffer.from(e.pointCompress(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),he(Buffer.from(e.pointCompress(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),he(Buffer.from(e.pointCompress(V("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(V("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),he(Buffer.from(e.pointFromScalar(V("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(V("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),he(e.xOnlyPointAddTweak(V("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(V("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),V("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));he(Buffer.from(t.xOnlyPubkey).equals(V("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(V("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),V("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),he(Buffer.from(t.xOnlyPubkey).equals(V("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),he(Buffer.from(e.sign(V("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),V("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(V("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),he(e.verify(V("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),V("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),V("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&he(Buffer.from(e.signSchnorr(V("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),V("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),V("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(V("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&he(e.verifySchnorr(V("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),V("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),V("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}Bi.testEcc=_d;function he(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(Rr,"__esModule",{value:!0});Rr.ECPairFactory=Rr.networks=void 0;const _s=Ur;Rr.networks=_s;const je=Qa,vd=Vh,ra=md,Ed=Bi,ns=je.typeforce.maybe(je.typeforce.compile({compressed:je.maybe(je.Boolean),network:je.maybe(je.Network)})),xd=e=>e.length===32?e:e.slice(1,33);function Sd(e){(0,Ed.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(je.typeforce(je.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return je.typeforce(ns,c),new o(a,void 0,c)}function n(a,c){return je.typeforce(e.isPoint,a),je.typeforce(ns,c),new o(void 0,a,c)}function i(a,c){const l=ra.decode(a),d=l.version;if(je.Array(c)){if(c=c.filter(g=>d===g.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||_s.bitcoin,d!==c.wif)throw new Error("Invalid network version");return r(l.privateKey,{compressed:l.compressed,network:c})}function s(a){je.typeforce(ns,a),a===void 0&&(a={});const c=a.rng||vd;let l;do l=c(32),je.typeforce(je.Buffer256bit,l);while(!e.isPrivate(l));return r(l,a)}class o{constructor(c,l,d){yr(this,"__D");yr(this,"__Q");yr(this,"compressed");yr(this,"network");yr(this,"lowR");this.__D=c,this.__Q=l,this.lowR=!1,d===void 0&&(d={}),this.compressed=d.compressed===void 0?!0:d.compressed,this.network=d.network||_s.bitcoin,l!==void 0&&(this.__Q=Buffer.from(e.pointCompress(l,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const c=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(c)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return ra.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,l){if(!this.__D)throw new Error("Missing private key");if(l===void 0&&(l=this.lowR),l===!1)return Buffer.from(e.sign(c,this.__D));{let d=e.sign(c,this.__D);const g=Buffer.alloc(32,0);let x=0;for(;d[0]>127;)x++,g.writeUIntLE(x,0,6),d=e.sign(c,this.__D,g);return Buffer.from(d)}}signSchnorr(c){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(c,this.privateKey))}verify(c,l){return e.verify(c,this.publicKey,l)}verifySchnorr(c,l){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),l)}tweakFromPublicKey(c){const l=xd(this.publicKey),d=e.xOnlyPointAddTweak(l,c);if(!d||d.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const g=Buffer.from([d.parity===0?2:3]);return n(Buffer.concat([g,d.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const d=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,g=e.privateAdd(d,c);if(!g)throw new Error("Invalid tweaked private key!");return r(Buffer.from(g),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}Rr.ECPairFactory=Sd;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=Rr;Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"ECPairFactory",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"networks",{enumerable:!0,get:function(){return t.networks}})})(Ja);const Bd=Tu(Ja);class pn extends ae.EventBroker{get isInitialized(){return!!this.privKey}constructor(t,r){super(),this.privKey=t,this.walletClient=r}static fromPrivKey(t){return new pn(Xt(t))}static fromWalletClient(t){return new pn(void 0,t)}async initialize(){if(this.privKey)return re("Already initialized");const t=await this.derivePrivKeyFromWalletClient();return t.error?j(t.error):(this.emit("initialized",!0),re("Initialized"))}async derivePrivKeyFromWalletClient(){if(!this.walletClient)return j("No walletClient found");if(!this.walletClient.account)return j("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.privKey=Xt(dt.sha256(t)),this.emit("initialized",!0),re(this.privKey)}catch(t){return j("Failed to initialize: "+t)}}async getMasterPrivKey(){if(!this.privKey&&!this.walletClient)return j("No private key or wallet client found");if(!this.privKey&&this.walletClient){const t=await this.derivePrivKeyFromWalletClient();if(t.error)return j(t.error)}return this.privKey?re(this.privKey):j("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return j(r.error);const n=dt.sha256(ae.with0x(r.val)),i=dt.sha256(n);return re({secret:n,secretHash:i})}async signMessage(t){if(!this.privKey){const l=await this.getMasterPrivKey();if(l.error)return j(l.error);this.privKey=l.val}const r=Bd(er),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=dt.sha256(i),o=Buffer.from(Xt(this.privKey),"hex");if(o.length!==32)return j("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(Xt(s),"hex"));return re(c.toString("hex"))}}class Pd extends ae.EventBroker{constructor(t){super(),this.getOrderThreshold=20,this.refundSacpCache=new Map,this.environment=t.environment;const r=t.environment===ae.Environment.MAINNET?ls.mainnet:t.environment===ae.Environment.TESTNET?ls.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);if(this._auth=new ae.Siwe(new ae.Url(t.orderbookURl??r.orderbook),t.evmWallet,t.siweOpts),this._quote=t.quote??new Xa(r.quote),this._orderBook=new le.Orderbook({url:t.orderbookURl??r.orderbook,walletClient:t.evmWallet,auth:this._auth}),this._orderbookUrl=new ae.Url(t.orderbookURl??r.orderbook),this._evmRelay=new ya(this._orderbookUrl,this._auth),this._secretManager=t.secretManager??pn.fromWalletClient(t.evmWallet),this.orderExecutorCache=new $h,this._evmWallet=t.evmWallet,!t.evmWallet.account)throw new Error("Account not found in evmWallet");this._blockNumberFetcher=t.blockNumberFetcher??new Ya(r.info,t.environment)}get orderbookUrl(){return this._orderbookUrl.toString()}get evmRelay(){return this._evmRelay}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderBook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return re(this._btcWallet);const t=await this._secretManager.getMasterPrivKey();if(t.error)return j(t.error);const r=new Ar.BitcoinProvider(gu(this.environment));return this._btcWallet=Ar.BitcoinWallet.fromPrivateKey(t.val,r),re(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return j(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val;let o=t.nonce;if(!o){if(!this._evmWallet.account)return j("EVM Wallet not found");const B=await this._orderBook.getOrdersCount(this._evmWallet.account.address);if(B.error)return j(B.error);o=B.val+1}const a=await this._secretManager.generateSecret(o);if(a.error)return j(a.error);const{strategyId:c,btcAddress:l}=t.additionalData,d={strategy_id:c,...l&&{bitcoin_optional_recipient:l}},g={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o.toString(),timelock:s,secret_hash:Xt(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:d},x=await this._quote.getAttestedQuote(g);if(x.error)return j(x.error);const y=await this._orderBook.createOrder(x.val);if(y.error)return j(y.error);const O=await this.pollOrder(y.val);return O.error?j(O.error):re(O.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return j("StrategyId is required");if(!t.fromAsset||!t.toAsset)return j("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return j("Source and destination assets cannot be the same");if(le.isMainnet(t.fromAsset.chain)&&!le.isMainnet(t.toAsset.chain)||!le.isMainnet(t.fromAsset.chain)&&le.isMainnet(t.toAsset.chain))return j("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return j(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return j(n.error);if(r<n)return j("Send amount should be greater than receive amount");const i=le.getTimeLock(t.fromAsset.chain);if(!i)return j("Unsupported chain for timelock");if(le.isBitcoin(t.fromAsset.chain)||le.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return j("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const a=await this.initializeSMandBTCWallet();if(a.error)return j(a.error);if(!this._btcWallet)return j("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return j(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?j(o.error):re({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(le.getBlockchainType(t)){case le.BlockchainType.EVM:return this._evmWallet.account?re(this._evmWallet.account.address):j("EVM Wallet not found");case le.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!bu(i)?j("Invalid btc public key"):re(Kt(i))}default:return j("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return j("Invalid amount ",t);const r=new uu(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?j("Invalid amount ",t):re(r)}async pollOrder(t){let r=await this._orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ae.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return j(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return re(r.val);r=await this._orderBook.getOrder(t,!0)}return j(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderBook.subscribeToOrders(t,async r=>{if(r.data.length===0)return;const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val);for(let i=0;i<n.val.length;i++){const s=n.val[i],o=Ss(s.status);if(le.isBitcoin(s.source_swap.chain)&&s.status===pe.InitiateDetected){const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);continue}await this.postRefundSACP(s,a.val)}switch(o){case Te.Redeem:{const a=await this._secretManager.generateSecret(Number(s.create_order.nonce));if(a.error){this.emit("error",s,a.error);return}switch(le.getBlockchainType(s.destination_swap.chain)){case le.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case le.BlockchainType.Bitcoin:{const c=this.getWallet(s.destination_swap.chain);if(c.error){this.emit("error",s,c.error);return}await this.btcRedeem(c.val,s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Te.Refund:{switch(le.getBlockchainType(s.source_swap.chain)){case le.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case le.BlockchainType.Bitcoin:{const a=this.getWallet(s.source_swap.chain);if(a.error){this.emit("error",s,a.error);return}await this.btcRefund(a.val,s);break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Te.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const i=await this._evmRelay.redeem(t.create_order.create_id,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Te.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Te.Redeem,i.val),this.emit("success",t,Te.Redeem,i.val)}async btcRedeem(t,r,n){var a,c;const i=this.orderExecutorCache.get(r,Te.Redeem),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const l=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let d=!1;for(const g of l.vin)if(g.txid===s){d=!0;break}if(d){this.orderExecutorCache.set(r,Te.Redeem,r.destination_swap.redeem_tx_hash,s),this.emit("log",r.create_order.create_id,"already a valid redeem");return}o=!0}catch(l){if(l.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+l);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const d=await(await un.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Kt(r.destination_swap.initiator),Kt(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).redeem(Xt(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient);o?this.emit("log",r.create_order.create_id,"rbf: btc redeem success"):this.emit("success",r,Te.Redeem,d),this.orderExecutorCache.set(r,Te.Redeem,d,s)}catch(l){this.emit("error",r,"Failed btc redeem: "+l)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Te.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await un.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Kt(r.source_swap.initiator),Kt(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,Te.Refund,s),this.emit("success",r,Te.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(le.getBlockchainType(t)){case le.BlockchainType.EVM:return re(this._evmWallet);case le.BlockchainType.Bitcoin:return re(this._btcWallet);default:return j("Unsupported chain for wallet")}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await un.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,Kt(t.source_swap.initiator),Kt(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 fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return j("Provide wallets to fetch the current block number");const n=le.isBitcoin(t.source_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.source.getProvider()):await ae.fetchEVMBlockNumber(r.source);if(n.error)return j(n.error);const i=le.isBitcoin(t.destination_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ae.fetchEVMBlockNumber(r.destination);return i.error?j(i.error):re({source:n.val,destination:i.val})}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return re([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return j(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(pa(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,l=r==null?void 0:r.val[a],d=r==null?void 0:r.val[c];if(!l||!d){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const g=xs(o,l,d);n.push({...o,status:g})}return re(n)}}function lr(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const Nf="2.21.41";let Zr={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Nf}`};class ye extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof ye?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof ye&&r.cause.docsPath||r.docsPath,s=(a=Zr.getDocsUrl)==null?void 0:a.call(Zr,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...Zr.version?[`Version: ${Zr.version}`]:[]].join(`
|
|
32
|
+
`);super(o,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=Nf}walk(t){return Ff(this,t)}}function Ff(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?Ff(e.cause,t):t?null:e}class Td extends ye{constructor({max:t,min:r,signed:n,size:i,value:s}){super(`Number "${s}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class Ad extends ye{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function xn(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Lr(e){return xn(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function ti(e,{dir:t="left"}={}){let r=typeof e=="string"?e.replace("0x",""):e,n=0;for(let i=0;i<r.length-1&&r[t==="left"?i:r.length-i-1].toString()==="0";i++)n++;return r=t==="left"?r.slice(n):r.slice(0,r.length-n),typeof e=="string"?(r.length===1&&t==="right"&&(r=`${r}0`),`0x${r.length%2===1?`0${r}`:r}`):r}class Id extends ye{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class Mf extends ye{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function Fr(e,{dir:t,size:r=32}={}){return typeof e=="string"?Od(e,{dir:t,size:r}):kd(e,{dir:t,size:r})}function Od(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Mf({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function kd(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Mf({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const s=t==="right";n[s?i:r-i-1]=e[s?i:e.length-i-1]}return n}const Rd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function J(e,t={}){return typeof e=="number"||typeof e=="bigint"?Hf(e,t):typeof e=="string"?Ld(e,t):typeof e=="boolean"?Ud(e,t):Vt(e,t)}function Ud(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Mr(r,{size:t.size}),Fr(r,{size:t.size})):r}function Vt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=Rd[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Mr(n,{size:t.size}),Fr(n,{dir:"right",size:t.size})):n}function Hf(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const c=typeof e=="bigint"?"n":"";throw new Td({max:s?`${s}${c}`:void 0,min:`${o}${c}`,signed:r,size:n,value:`${e}${c}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Fr(a,{size:n}):a}const Cd=new TextEncoder;function Ld(e,t={}){const r=Cd.encode(e);return Vt(r,t)}const Nd=new TextEncoder;function $f(e,t={}){return typeof e=="number"||typeof e=="bigint"?Md(e,t):typeof e=="boolean"?Fd(e,t):xn(e)?ir(e,t):Df(e,t)}function Fd(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Mr(r,{size:t.size}),Fr(r,{size:t.size})):r}const mt={zero:48,nine:57,A:65,F:70,a:97,f:102};function na(e){if(e>=mt.zero&&e<=mt.nine)return e-mt.zero;if(e>=mt.A&&e<=mt.F)return e-(mt.A-10);if(e>=mt.a&&e<=mt.f)return e-(mt.a-10)}function ir(e,t={}){let r=e;t.size&&(Mr(r,{size:t.size}),r=Fr(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,s=new Uint8Array(i);for(let o=0,a=0;o<i;o++){const c=na(n.charCodeAt(a++)),l=na(n.charCodeAt(a++));if(c===void 0||l===void 0)throw new ye(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+l}return s}function Md(e,t){const r=Hf(e,t);return ir(r)}function Df(e,t={}){const r=Nd.encode(e);return typeof t.size=="number"?(Mr(r,{size:t.size}),Fr(r,{dir:"right",size:t.size})):r}function Mr(e,{size:t}){if(Lr(e)>t)throw new Ad({givenSize:Lr(e),maxSize:t})}function xr(e,t={}){const{signed:r}=t;t.size&&Mr(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,s=(1n<<BigInt(i)*8n-1n)-1n;return n<=s?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function ri(e,t={}){return Number(xr(e,t))}function qs(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const s=t(i);if(r)for(const o of r)delete s[o];return{...s,...n(i)}},type:e})}const jf={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Ks(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?ri(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?ri(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?jf[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(t.authorizationList=$d(e.authorizationList)),t.yParity=(()=>{if(e.yParity)return Number(e.yParity);if(typeof t.v=="bigint"){if(t.v===0n||t.v===27n)return 0;if(t.v===1n||t.v===28n)return 1;if(t.v>=35n)return t.v%2n===0n?1:0}})(),t.type==="legacy"&&(delete t.accessList,delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas,delete t.yParity),t.type==="eip2930"&&(delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas),t.type==="eip1559"&&delete t.maxFeePerBlobGas,t}const Hd=qs("transaction",Ks);function $d(e){return e.map(t=>({contractAddress:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function Dd(e){var r;const t=(r=e.transactions)==null?void 0:r.map(n=>typeof n=="string"?n:Ks(n));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const jd=qs("block",Dd);function Gd(e,{args:t,eventName:r}={}){return{...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,logIndex:e.logIndex?Number(e.logIndex):null,transactionHash:e.transactionHash?e.transactionHash:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,...r?{args:t,eventName:r}:{}}}const Wd={"0x0":"reverted","0x1":"success"};function Vd(e){const t={...e,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,contractAddress:e.contractAddress?e.contractAddress:null,cumulativeGasUsed:e.cumulativeGasUsed?BigInt(e.cumulativeGasUsed):null,effectiveGasPrice:e.effectiveGasPrice?BigInt(e.effectiveGasPrice):null,gasUsed:e.gasUsed?BigInt(e.gasUsed):null,logs:e.logs?e.logs.map(r=>Gd(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?ri(e.transactionIndex):null,status:e.status?Wd[e.status]:null,type:e.type?jf[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const zd=qs("transactionReceipt",Vd),Ys=2n**256n-1n;function Sn(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class ia extends ye{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class qd extends ye{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class Kd extends ye{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Yd={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new Kd({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new qd({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ia({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new ia({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const r=t??this.position;return this.assertPosition(r+e-1),this.bytes.subarray(r,r+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const r=this.inspectBytes(e);return this.position+=t??e,r},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Gf(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(Yd);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function sr(e,t="hex"){const r=Wf(e),n=Gf(new Uint8Array(r.length));return r.encode(n),t==="hex"?Vt(n.bytes):n.bytes}function Wf(e){return Array.isArray(e)?Xd(e.map(t=>Wf(t))):Jd(e)}function Xd(e){const t=e.reduce((i,s)=>i+s.length,0),r=Vf(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:s}of e)s(i)}}}function Jd(e){const t=typeof e=="string"?ir(e):e,r=Vf(t.length);return{length:t.length===1&&t[0]<128?1:t.length<=55?1+t.length:1+r+t.length,encode(i){t.length===1&&t[0]<128?i.pushBytes(t):t.length<=55?(i.pushByte(128+t.length),i.pushBytes(t)):(i.pushByte(183+r),r===1?i.pushUint8(t.length):r===2?i.pushUint16(t.length):r===3?i.pushUint24(t.length):i.pushUint32(t.length),i.pushBytes(t))}}}function Vf(e){if(e<2**8)return 1;if(e<2**16)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new ye("Length is too large.")}const Qd={ether:-9,wei:9};function Zd(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,s]=[r.slice(0,r.length-t),r.slice(r.length-t)];return s=s.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${s?`.${s}`:""}`}function vs(e,t="wei"){return Zd(e,Qd[t])}function ep(e){const t=Object.entries(e).map(([n,i])=>i===void 0||i===!1?null:[n,i]).filter(Boolean),r=t.reduce((n,[i])=>Math.max(n,i.length),0);return t.map(([n,i])=>` ${`${n}:`.padEnd(r+1)} ${i}`).join(`
|
|
33
|
+
`)}class tp extends ye{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class rp extends ye{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",ep(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:"InvalidSerializableTransactionError"})}}class np extends ye{constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}function zf(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(s=>ir(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>Vt(s))}function qf(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(o=>ir(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>ir(o)):e.commitments,s=[];for(let o=0;o<n.length;o++){const a=n[o],c=i[o];s.push(Uint8Array.from(t.computeBlobKzgProof(a,c)))}return r==="bytes"?s:s.map(o=>Vt(o))}function ip(e,t){return Ha(xn(e,{strict:!1})?$f(e):e)}function sp(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=ip(t);return i.set([r],0),n==="bytes"?i:Vt(i)}function op(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const s of t)i.push(sp({commitment:s,to:n,version:r}));return i}const sa=6,Kf=32,Xs=4096,Yf=Kf*Xs,oa=Yf*sa-1-1*Xs*sa,Xf=1;class ap extends ye{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Jf extends ye{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class fp extends ye{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class up extends ye{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Xf}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function cp(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?ir(e.data):e.data,n=Lr(r);if(!n)throw new Jf;if(n>oa)throw new ap({maxSize:oa,size:n});const i=[];let s=!0,o=0;for(;s;){const a=Gf(new Uint8Array(Yf));let c=0;for(;c<Xs;){const l=r.slice(o,o+(Kf-1));if(a.pushByte(0),a.pushBytes(l),l.length<31){a.pushByte(128),s=!1;break}c++,o+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>Vt(a.bytes))}function hp(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??cp({data:t,to:n}),s=e.commitments??zf({blobs:i,kzg:r,to:n}),o=e.proofs??qf({blobs:i,commitments:s,kzg:r,to:n}),a=[];for(let c=0;c<i.length;c++)a.push({blob:i[c],commitment:s[c],proof:o[c]});return a}function lp(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{contractAddress:n,chainId:i,nonce:s,...o}=r;t.push([i?J(i):"0x",n,s?J(s):"0x",...Bn({},o)])}return t}class or extends ye{constructor({address:t}){super(`Address "${t}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class Pi extends ye{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class Ti extends ye{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${vs(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Ti,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class Qf extends ye{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${vs(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${vs(n)} gwei`:""}).`].join(`
|
|
34
|
+
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Qf,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class Zf extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const Ln=BigInt(2**32-1),aa=BigInt(32);function dp(e,t=!1){return t?{h:Number(e&Ln),l:Number(e>>aa&Ln)}:{h:Number(e>>aa&Ln)|0,l:Number(e&Ln)|0}}function pp(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:s,l:o}=dp(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const yp=(e,t,r)=>e<<r|t>>>32-r,bp=(e,t,r)=>t<<r|e>>>32-r,wp=(e,t,r)=>t<<r-32|e>>>64-r,gp=(e,t,r)=>e<<r-32|t>>>64-r,eu=[],tu=[],ru=[],mp=BigInt(0),en=BigInt(1),_p=BigInt(2),vp=BigInt(7),Ep=BigInt(256),xp=BigInt(113);for(let e=0,t=en,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],eu.push(2*(5*n+r)),tu.push((e+1)*(e+2)/2%64);let i=mp;for(let s=0;s<7;s++)t=(t<<en^(t>>vp)*xp)%Ep,t&_p&&(i^=en<<(en<<BigInt(s))-en);ru.push(i)}const[Sp,Bp]=pp(ru,!0),fa=(e,t,r)=>r>32?wp(e,t,r):yp(e,t,r),ua=(e,t,r)=>r>32?gp(e,t,r):bp(e,t,r);function Pp(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)r[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,l=r[c],d=r[c+1],g=fa(l,d,1)^r[a],x=ua(l,d,1)^r[a+1];for(let y=0;y<50;y+=10)e[o+y]^=g,e[o+y+1]^=x}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=tu[o],c=fa(i,s,a),l=ua(i,s,a),d=eu[o];i=e[d],s=e[d+1],e[d]=c,e[d+1]=l}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=Sp[n],e[1]^=Bp[n]}r.fill(0)}class Js extends Ma{constructor(t,r,n,i=!1,s=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,oo(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=ic(this.state)}keccak(){ao||fo(this.state32),Pp(this.state32,this.rounds),ao||fo(this.state32),this.posOut=0,this.pos=0}update(t){Yn(this);const{blockLen:r,state:n}=this;t=Cs(t);const i=t.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=t[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){Yn(this,!1),Us(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=t.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);t.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return oo(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Fa(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return t||(t=new Js(r,n,i,o,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}}const Tp=(e,t,r)=>Ls(()=>new Js(t,e,r)),Ap=Tp(1,136,256/8);function Ip(e,t){return Ap(xn(e,{strict:!1})?$f(e):e)}const is=new Zf(8192);function Op(e,t){if(is.has(`${e}.${t}`))return is.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Ip(Df(r)),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return is.set(`${e}.${t}`,s),s}const kp=/^0x[a-fA-F0-9]{40}$/,ss=new Zf(8192);function ar(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(ss.has(n))return ss.get(n);const i=kp.test(e)?e.toLowerCase()===e?!0:r?Op(e)===e:!0:!1;return ss.set(n,i),i}function Rp(e,t,r,{strict:n}={}){return xn(e,{strict:!1})?Cp(e,t,r,{strict:n}):Up(e,t,r,{strict:n})}function nu(e,t,r){if(Lr(e)!==r-t)throw new Id({offset:r,position:"end",size:Lr(e)})}function Up(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&nu(i,t,r),i}function Cp(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&nu(i,t,r),i}function Lp(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!ar(n))throw new or({address:n});if(i<0)throw new Pi({chainId:i})}Qs(e)}function Np(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Jf;for(const r of t){const n=Lr(r),i=ri(Rp(r,0,1));if(n!==32)throw new fp({hash:r,size:n});if(i!==Xf)throw new up({hash:r,version:i})}}Qs(e)}function Qs(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Pi({chainId:t});if(i&&!ar(i))throw new or({address:i});if(n&&n>Ys)throw new Ti({maxFeePerGas:n});if(r&&n&&r>n)throw new Qf({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Fp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new Pi({chainId:t});if(s&&!ar(s))throw new or({address:s});if(r||i)throw new ye("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ys)throw new Ti({maxFeePerGas:n})}function Mp(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!ar(s))throw new or({address:s});if(typeof t<"u"&&t<=0)throw new Pi({chainId:t});if(r||i)throw new ye("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ys)throw new Ti({maxFeePerGas:n})}function Hp(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new rp({transaction:e})}function Ai(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let s=0;s<i.length;s++)if(i[s].length-2!==64)throw new np({storageKey:i[s]});if(!ar(n,{strict:!1}))throw new or({address:n});t.push([n,i])}return t}function $p(e,t){const r=Hp(e);return r==="eip1559"?Gp(e,t):r==="eip2930"?Wp(e,t):r==="eip4844"?jp(e,t):r==="eip7702"?Dp(e,t):Vp(e,t)}function Dp(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:c,maxPriorityFeePerGas:l,accessList:d,data:g}=e;Lp(e);const x=Ai(d),y=lp(r);return Sn(["0x04",sr([J(n),s?J(s):"0x",l?J(l):"0x",c?J(c):"0x",i?J(i):"0x",o??"0x",a?J(a):"0x",g??"0x",x,y,...Bn(e,t)])])}function jp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:l,accessList:d,data:g}=e;Np(e);let x=e.blobVersionedHashes,y=e.sidecars;if(e.blobs&&(typeof x>"u"||typeof y>"u")){const _=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(E=>Vt(E)),m=e.kzg,S=zf({blobs:_,kzg:m});if(typeof x>"u"&&(x=op({commitments:S})),typeof y>"u"){const E=qf({blobs:_,commitments:S,kzg:m});y=hp({blobs:_,commitments:S,proofs:E})}}const O=Ai(d),B=[J(r),i?J(i):"0x",l?J(l):"0x",c?J(c):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",g??"0x",O,a?J(a):"0x",x??[],...Bn(e,t)],A=[],k=[],U=[];if(y)for(let _=0;_<y.length;_++){const{blob:m,commitment:S,proof:E}=y[_];A.push(m),k.push(S),U.push(E)}return Sn(["0x03",sr(y?[B,A,k,U]:B)])}function Gp(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:l,data:d}=e;Qs(e);const g=Ai(l),x=[J(r),i?J(i):"0x",c?J(c):"0x",a?J(a):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",d??"0x",g,...Bn(e,t)];return Sn(["0x02",sr(x)])}function Wp(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:c,gasPrice:l}=e;Fp(e);const d=Ai(c),g=[J(r),s?J(s):"0x",l?J(l):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x",d,...Bn(e,t)];return Sn(["0x01",sr(g)])}function Vp(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:c}=e;Mp(e);let l=[s?J(s):"0x",c?J(c):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x"];if(t){const d=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const y=27n+(t.v===27n?0n:1n);if(t.v!==y)throw new tp({v:t.v});return y})(),g=ti(t.r),x=ti(t.s);l=[...l,J(d),g==="0x00"?"0x":g,x==="0x00"?"0x":x]}else r>0&&(l=[...l,J(r),"0x","0x"]);return sr(l)}function Bn(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const s=ti(r.r),o=ti(r.s);return[typeof i=="number"?i?J(1):"0x":n===0n?"0x":n===1n?J(1):n===27n?"0x":J(1),s==="0x00"?"0x":s,o==="0x00"?"0x":o]}const zp={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},qp={block:jd({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Ks(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?xr(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Hd({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?xr(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:zd({format(e){return{l1GasPrice:e.l1GasPrice?xr(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?xr(e.l1GasUsed):null,l1Fee:e.l1Fee?xr(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function Kp(e,t){return Jp(e)?Xp(e):$p(e,t)}const Yp={transaction:Kp};function Xp(e){Qp(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:c}=e,l=[t,n,a??"0x",o?J(o):"0x",c?J(c):"0x",i?J(i):"0x",s?"0x1":"0x",r??"0x"];return Sn(["0x7e",sr(l)])}function Jp(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Qp(e){const{from:t,to:r}=e;if(t&&!ar(t))throw new or({address:t});if(r&&!ar(r))throw new or({address:r})}const ni={contracts:zp,formatters:qp,serializers:Yp},Zp=lr({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),ey=lr({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),tn=1,ty=lr({...ni,id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://basescan.org",apiUrl:"https://api.basescan.org/api"}},contracts:{...ni.contracts,disputeGameFactory:{[tn]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[tn]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[tn]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[tn]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:tn}),rn=11155111,ry=lr({...ni,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...ni.contracts,disputeGameFactory:{[rn]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[rn]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[rn]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[rn]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:rn}),ny=lr({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),iy=lr({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),sy=lr({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.drpc.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0}),oy={...sy,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},iu=dt.defineChain({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api/v2/"}},testnet:!0}),su={ethereum:iy,arbitrum:Zp,ethereum_sepolia:oy,arbitrum_sepolia:ey,ethereum_localnet:le.EthereumLocalnet,arbitrum_localnet:le.ArbitrumLocalnet,base_sepolia:ry,base:ty,bera_testnet:ny,citrea_testnet:iu},ay=async(e,t)=>{var n;const r=su[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return re({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=dt.createWalletClient({account:t.account,chain:r,transport:dt.custom(window.ethereum)});return re({message:"Switched chain",walletClient:i})}catch(i){if(fy(i))try{await t.addChain({chain:r});const s=dt.createWalletClient({account:t.account,chain:r,transport:dt.custom(window.ethereum)});return re({message:"Added network",walletClient:s})}catch{return j("Failed to add network")}else return j("Failed to switch network")}else return j("Chain not supported")},fy=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.API=ls;exports.BlockNumberFetcher=Ya;exports.EvmRelay=ya;exports.Garden=Pd;exports.OrderActions=Te;exports.OrderStatus=pe;exports.ParseOrderStatus=xs;exports.ParseSwapStatus=fs;exports.Quote=Xa;exports.SecretManager=pn;exports.SwapStatus=me;exports.citreaTestnet=iu;exports.constructOrderPair=da;exports.evmToViemChainMap=su;exports.filterDeadlineExpiredOrders=_u;exports.isExpired=cn;exports.parseAction=mu;exports.parseActionFromStatus=Ss;exports.switchOrAddNetwork=ay;exports.validateBTCAddress=wu;
|