@gardenfi/core 2.1.3-beta.44 → 2.1.3-beta.45
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/{ccip-CvElG6nD.js → ccip-BQ2SmYhi.js} +1 -1
- package/dist/{ccip-CP_8Dw5B.cjs → ccip-DWt0iM5p.cjs} +1 -1
- package/dist/{index-DX2aorDe.js → index-7EmN20ut.js} +603 -590
- package/dist/{index-DRMi2irD.cjs → index-CpT0ssxQ.cjs} +22 -22
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{secp256k1-CYp-t-jb.js → secp256k1-COkOPbFq.js} +1 -1
- package/dist/{secp256k1-B5eOuBnI.cjs → secp256k1-Cbj-hmMq.cjs} +1 -1
- package/package.json +3 -3
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";var Yl=Object.defineProperty;var Xl=(e,t,r)=>t in e?Yl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Vr=(e,t,r)=>Xl(e,typeof t!="symbol"?t+"":t,r);const ge=require("@gardenfi/orderbook"),z=require("@gardenfi/utils"),fn=require("@catalogfi/wallets"),Zu=require("varuint-bitcoin"),Jl=require("tiny-secp256k1"),ef=require("bitcoinjs-lib"),Ql=require("bignumber.js"),Oe=require("starknet");function
|
|
2
|
-
`);super(s),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,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),r.cause&&(this.cause=r.cause),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.shortMessage=t}};function Xt(e,t){const r=e.exec(t);return r==null?void 0:r.groups}const rf=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,nf=/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/,sf=/^\(.+?\).*?$/,Tc=/^tuple(?<array>(\[(\d*)\])*)$/;function Xo(e){let t=e.type;if(Tc.test(e.type)&&"components"in e){t="(";const r=e.components.length;for(let i=0;i<r;i++){const s=e.components[i];t+=Xo(s),i<r-1&&(t+=", ")}const n=Xt(Tc,e.type);return t+=`)${(n==null?void 0:n.array)??""}`,Xo({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Tn(e){let t="";const r=e.length;for(let n=0;n<r;n++){const i=e[n];t+=Xo(i),n!==r-1&&(t+=", ")}return t}function nh(e){var t;return e.type==="function"?`function ${e.name}(${Tn(e.inputs)})${e.stateMutability&&e.stateMutability!=="nonpayable"?` ${e.stateMutability}`:""}${(t=e.outputs)!=null&&t.length?` returns (${Tn(e.outputs)})`:""}`:e.type==="event"?`event ${e.name}(${Tn(e.inputs)})`:e.type==="error"?`error ${e.name}(${Tn(e.inputs)})`:e.type==="constructor"?`constructor(${Tn(e.inputs)})${e.stateMutability==="payable"?" payable":""}`:e.type==="fallback"?`fallback() external${e.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const of=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function ih(e){return of.test(e)}function sh(e){return Xt(of,e)}const af=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function oh(e){return af.test(e)}function ah(e){return Xt(af,e)}const cf=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function ch(e){return cf.test(e)}function uh(e){return Xt(cf,e)}const uf=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function ff(e){return uf.test(e)}function fh(e){return Xt(uf,e)}const df=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function dh(e){return df.test(e)}function lh(e){return Xt(df,e)}const lf=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function hh(e){return lf.test(e)}function ph(e){return Xt(lf,e)}const yh=/^receive\(\) external payable$/;function mh(e){return yh.test(e)}const bh=new Set(["indexed"]),Jo=new Set(["calldata","memory","storage"]);class gh extends ht{constructor({type:t}){super("Unknown type.",{metaMessages:[`Type "${t}" is not a valid ABI type. Perhaps you forgot to include a struct signature?`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownTypeError"})}}class wh extends ht{constructor({type:t}){super("Unknown type.",{metaMessages:[`Type "${t}" is not a valid ABI type.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSolidityTypeError"})}}class _h extends ht{constructor({param:t}){super("Invalid ABI parameter.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class vh extends ht{constructor({param:t,name:r}){super("Invalid ABI parameter.",{details:t,metaMessages:[`"${r}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SolidityProtectedKeywordError"})}}class Eh extends ht{constructor({param:t,type:r,modifier:n}){super("Invalid ABI parameter.",{details:t,metaMessages:[`Modifier "${n}" not allowed${r?` in "${r}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class xh extends ht{constructor({param:t,type:r,modifier:n}){super("Invalid ABI parameter.",{details:t,metaMessages:[`Modifier "${n}" not allowed${r?` in "${r}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${n}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class Ah extends ht{constructor({abiParameter:t}){super("Invalid ABI parameter.",{details:JSON.stringify(t,null,2),metaMessages:["ABI parameter type is invalid."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiTypeParameterError"})}}class wn extends ht{constructor({signature:t,type:r}){super(`Invalid ${r} signature.`,{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class Sh extends ht{constructor({signature:t}){super("Unknown signature.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class Ph extends ht{constructor({signature:t}){super("Invalid struct signature.",{details:t,metaMessages:["No properties exist."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidStructSignatureError"})}}class Th extends ht{constructor({type:t}){super("Circular reference detected.",{metaMessages:[`Struct "${t}" is a circular reference.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"CircularReferenceError"})}}class kh extends ht{constructor({current:t,depth:r}){super("Unbalanced parentheses.",{metaMessages:[`"${t.trim()}" has too many ${r>0?"opening":"closing"} parentheses.`],details:`Depth "${r}"`}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParenthesisError"})}}function Ih(e,t,r){let n="";if(r)for(const i of Object.entries(r)){if(!i)continue;let s="";for(const o of i[1])s+=`[${o.type}${o.name?`:${o.name}`:""}]`;n+=`(${i[0]}{${s}})`}return t?`${t}:${e}${n}`:e}const uo=new Map([["address",{type:"address"}],["bool",{type:"bool"}],["bytes",{type:"bytes"}],["bytes32",{type:"bytes32"}],["int",{type:"int256"}],["int256",{type:"int256"}],["string",{type:"string"}],["uint",{type:"uint256"}],["uint8",{type:"uint8"}],["uint16",{type:"uint16"}],["uint24",{type:"uint24"}],["uint32",{type:"uint32"}],["uint64",{type:"uint64"}],["uint96",{type:"uint96"}],["uint112",{type:"uint112"}],["uint160",{type:"uint160"}],["uint192",{type:"uint192"}],["uint256",{type:"uint256"}],["address owner",{type:"address",name:"owner"}],["address to",{type:"address",name:"to"}],["bool approved",{type:"bool",name:"approved"}],["bytes _data",{type:"bytes",name:"_data"}],["bytes data",{type:"bytes",name:"data"}],["bytes signature",{type:"bytes",name:"signature"}],["bytes32 hash",{type:"bytes32",name:"hash"}],["bytes32 r",{type:"bytes32",name:"r"}],["bytes32 root",{type:"bytes32",name:"root"}],["bytes32 s",{type:"bytes32",name:"s"}],["string name",{type:"string",name:"name"}],["string symbol",{type:"string",name:"symbol"}],["string tokenURI",{type:"string",name:"tokenURI"}],["uint tokenId",{type:"uint256",name:"tokenId"}],["uint8 v",{type:"uint8",name:"v"}],["uint256 balance",{type:"uint256",name:"balance"}],["uint256 tokenId",{type:"uint256",name:"tokenId"}],["uint256 value",{type:"uint256",name:"value"}],["event:address indexed from",{type:"address",name:"from",indexed:!0}],["event:address indexed to",{type:"address",name:"to",indexed:!0}],["event:uint indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}],["event:uint256 indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}]]);function Bh(e,t={}){if(ch(e))return Ch(e,t);if(oh(e))return Oh(e,t);if(ih(e))return Rh(e,t);if(dh(e))return Uh(e,t);if(hh(e))return Lh(e);if(mh(e))return{type:"receive",stateMutability:"payable"};throw new Sh({signature:e})}function Ch(e,t={}){const r=uh(e);if(!r)throw new wn({signature:e,type:"function"});const n=mt(r.parameters),i=[],s=n.length;for(let a=0;a<s;a++)i.push(Cr(n[a],{modifiers:Jo,structs:t,type:"function"}));const o=[];if(r.returns){const a=mt(r.returns),c=a.length;for(let f=0;f<c;f++)o.push(Cr(a[f],{modifiers:Jo,structs:t,type:"function"}))}return{name:r.name,type:"function",stateMutability:r.stateMutability??"nonpayable",inputs:i,outputs:o}}function Oh(e,t={}){const r=ah(e);if(!r)throw new wn({signature:e,type:"event"});const n=mt(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(Cr(n[o],{modifiers:bh,structs:t,type:"event"}));return{name:r.name,type:"event",inputs:i}}function Rh(e,t={}){const r=sh(e);if(!r)throw new wn({signature:e,type:"error"});const n=mt(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(Cr(n[o],{structs:t,type:"error"}));return{name:r.name,type:"error",inputs:i}}function Uh(e,t={}){const r=lh(e);if(!r)throw new wn({signature:e,type:"constructor"});const n=mt(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(Cr(n[o],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:r.stateMutability??"nonpayable",inputs:i}}function Lh(e){const t=ph(e);if(!t)throw new wn({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}const Nh=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Fh=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,$h=/^u?int$/;function Cr(e,t){var h,m;const r=Ih(e,t==null?void 0:t.type,t==null?void 0:t.structs);if(uo.has(r))return uo.get(r);const n=sf.test(e),i=Xt(n?Fh:Nh,e);if(!i)throw new _h({param:e});if(i.name&&Hh(i.name))throw new vh({param:e,name:i.name});const s=i.name?{name:i.name}:{},o=i.modifier==="indexed"?{indexed:!0}:{},a=(t==null?void 0:t.structs)??{};let c,f={};if(n){c="tuple";const p=mt(i.type),g=[],v=p.length;for(let x=0;x<v;x++)g.push(Cr(p[x],{structs:a}));f={components:g}}else if(i.type in a)c="tuple",f={components:a[i.type]};else if($h.test(i.type))c=`${i.type}256`;else if(c=i.type,(t==null?void 0:t.type)!=="struct"&&!hf(c))throw new wh({type:c});if(i.modifier){if(!((m=(h=t==null?void 0:t.modifiers)==null?void 0:h.has)!=null&&m.call(h,i.modifier)))throw new Eh({param:e,type:t==null?void 0:t.type,modifier:i.modifier});if(Jo.has(i.modifier)&&!Dh(c,!!i.array))throw new xh({param:e,type:t==null?void 0:t.type,modifier:i.modifier})}const l={type:`${c}${i.array??""}`,...s,...o,...f};return uo.set(r,l),l}function mt(e,t=[],r="",n=0){const i=e.trim().length;for(let s=0;s<i;s++){const o=e[s],a=e.slice(s+1);switch(o){case",":return n===0?mt(a,[...t,r.trim()]):mt(a,t,`${r}${o}`,n);case"(":return mt(a,t,`${r}${o}`,n+1);case")":return mt(a,t,`${r}${o}`,n-1);default:return mt(a,t,`${r}${o}`,n)}}if(r==="")return t;if(n!==0)throw new kh({current:r,depth:n});return t.push(r.trim()),t}function hf(e){return e==="address"||e==="bool"||e==="function"||e==="string"||rf.test(e)||nf.test(e)}const Mh=/^(?:after|alias|anonymous|apply|auto|byte|calldata|case|catch|constant|copyof|default|defined|error|event|external|false|final|function|immutable|implements|in|indexed|inline|internal|let|mapping|match|memory|mutable|null|of|override|partial|private|promise|public|pure|reference|relocatable|return|returns|sizeof|static|storage|struct|super|supports|switch|this|true|try|typedef|typeof|var|view|virtual)$/;function Hh(e){return e==="address"||e==="bool"||e==="function"||e==="string"||e==="tuple"||rf.test(e)||nf.test(e)||Mh.test(e)}function Dh(e,t){return t||e==="bytes"||e==="string"||e==="tuple"}function jh(e){const t={},r=e.length;for(let o=0;o<r;o++){const a=e[o];if(!ff(a))continue;const c=fh(a);if(!c)throw new wn({signature:a,type:"struct"});const f=c.properties.split(";"),l=[],h=f.length;for(let m=0;m<h;m++){const g=f[m].trim();if(!g)continue;const v=Cr(g,{type:"struct"});l.push(v)}if(!l.length)throw new Ph({signature:a});t[c.name]=l}const n={},i=Object.entries(t),s=i.length;for(let o=0;o<s;o++){const[a,c]=i[o];n[a]=pf(c,t)}return n}const Gh=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function pf(e,t,r=new Set){const n=[],i=e.length;for(let s=0;s<i;s++){const o=e[s];if(sf.test(o.type))n.push(o);else{const c=Xt(Gh,o.type);if(!(c!=null&&c.type))throw new Ah({abiParameter:o});const{array:f,type:l}=c;if(l in t){if(r.has(l))throw new Th({type:l});n.push({...o,type:`tuple${f??""}`,components:pf(t[l]??[],t,new Set([...r,l]))})}else if(hf(l))n.push(o);else throw new gh({type:l})}}return n}function yf(e){const t=jh(e),r=[],n=e.length;for(let i=0;i<n;i++){const s=e[i];ff(s)||r.push(Bh(s,t))}return r}function oe(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const i=e[r];return typeof i=="function"?i:s=>t(e,s)}function kt(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new n0(e.type);return`${e.name}(${Ps(e.inputs,{includeName:t})})`}function Ps(e,{includeName:t=!1}={}){return e?e.map(r=>zh(r,{includeName:t})).join(t?", ":","):""}function zh(e,{includeName:t}){return e.type.startsWith("tuple")?`(${Ps(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}function zt(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Ie(e){return zt(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const mf="2.28.0";let kn={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${mf}`};class $ extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof $?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof $&&r.cause.docsPath||r.docsPath,s=(a=kn.getDocsUrl)==null?void 0:a.call(kn,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...kn.version?[`Version: ${kn.version}`]:[]].join(`
|
|
1
|
+
"use strict";var Yl=Object.defineProperty;var Xl=(e,t,r)=>t in e?Yl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Vr=(e,t,r)=>Xl(e,typeof t!="symbol"?t+"":t,r);const ge=require("@gardenfi/orderbook"),z=require("@gardenfi/utils"),fn=require("@catalogfi/wallets"),Zu=require("varuint-bitcoin"),Jl=require("tiny-secp256k1"),ef=require("bitcoinjs-lib"),Ql=require("bignumber.js"),Oe=require("starknet");function Ia(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 Tc=Ia(Zu),Br=Ia(Jl),ce=Ia(ef);var tf=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},oo=(e,t,r)=>(tf(e,t,"read from private field"),r?r.call(e):t.get(e)),ao=(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)},co=(e,t,r,n)=>(tf(e,t,"write to private field"),t.set(e,r),r);const Zl=e=>new Promise(t=>setTimeout(t,e));class eh{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 Zl(this.delay*r)}throw n}}const th=e=>{try{return JSON.parse(e)}catch{return e}};class Dt{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=kc(s);continue}throw new Error(n||"All APIs failed")}static async postWithFallback(t,r){return await ji(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=kc(s);continue}throw new Error(n||"All APIs failed")}static async getWithFallback(t,r){return await ji(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 ji(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 ji(r).retry(()=>this._post(t,r))}static async parse(t){const r=await t.text();if(t.status>=200&&t.status<300)return th(r);throw new Error(r)}}function kc(e){return(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"unknown error"}const ji=e=>new eh((e==null?void 0:e.retryCount)??2,(e==null?void 0:e.retryDelay)??1e3),rn=e=>e.startsWith("0x")?e:`0x${e}`,Pr=e=>e.startsWith("0x")?e.slice(2):e;var ns,is,ss;let Xo=class{constructor(t,r,n=void 0){ao(this,ns,void 0),ao(this,is,void 0),ao(this,ss,void 0),co(this,ns,t),co(this,ss,n),co(this,is,r)}get ok(){return oo(this,ns)}get error(){return oo(this,ss)}get val(){return oo(this,is)}};ns=new WeakMap,is=new WeakMap,ss=new WeakMap;const ie=e=>new Xo(!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 Xo(!1,null,r.filter(n=>n!==void 0).join(" "))}return new Xo(!1,null,e)};var Ce=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Ce||{});const rh="1.0.8";let ht=class Jo extends Error{constructor(t,r={}){var o;const n=r.cause instanceof Jo?r.cause.details:(o=r.cause)!=null&&o.message?r.cause.message:r.details,i=r.cause instanceof Jo&&r.cause.docsPath||r.docsPath,s=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...i?[`Docs: https://abitype.dev${i}`]:[],...n?[`Details: ${n}`]:[],`Version: abitype@${rh}`].join(`
|
|
2
|
+
`);super(s),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,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),r.cause&&(this.cause=r.cause),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.shortMessage=t}};function Xt(e,t){const r=e.exec(t);return r==null?void 0:r.groups}const rf=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,nf=/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/,sf=/^\(.+?\).*?$/,Ic=/^tuple(?<array>(\[(\d*)\])*)$/;function Qo(e){let t=e.type;if(Ic.test(e.type)&&"components"in e){t="(";const r=e.components.length;for(let i=0;i<r;i++){const s=e.components[i];t+=Qo(s),i<r-1&&(t+=", ")}const n=Xt(Ic,e.type);return t+=`)${(n==null?void 0:n.array)??""}`,Qo({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Tn(e){let t="";const r=e.length;for(let n=0;n<r;n++){const i=e[n];t+=Qo(i),n!==r-1&&(t+=", ")}return t}function nh(e){var t;return e.type==="function"?`function ${e.name}(${Tn(e.inputs)})${e.stateMutability&&e.stateMutability!=="nonpayable"?` ${e.stateMutability}`:""}${(t=e.outputs)!=null&&t.length?` returns (${Tn(e.outputs)})`:""}`:e.type==="event"?`event ${e.name}(${Tn(e.inputs)})`:e.type==="error"?`error ${e.name}(${Tn(e.inputs)})`:e.type==="constructor"?`constructor(${Tn(e.inputs)})${e.stateMutability==="payable"?" payable":""}`:e.type==="fallback"?`fallback() external${e.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const of=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function ih(e){return of.test(e)}function sh(e){return Xt(of,e)}const af=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function oh(e){return af.test(e)}function ah(e){return Xt(af,e)}const cf=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function ch(e){return cf.test(e)}function uh(e){return Xt(cf,e)}const uf=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function ff(e){return uf.test(e)}function fh(e){return Xt(uf,e)}const df=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function dh(e){return df.test(e)}function lh(e){return Xt(df,e)}const lf=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function hh(e){return lf.test(e)}function ph(e){return Xt(lf,e)}const yh=/^receive\(\) external payable$/;function mh(e){return yh.test(e)}const bh=new Set(["indexed"]),Zo=new Set(["calldata","memory","storage"]);class gh extends ht{constructor({type:t}){super("Unknown type.",{metaMessages:[`Type "${t}" is not a valid ABI type. Perhaps you forgot to include a struct signature?`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownTypeError"})}}class wh extends ht{constructor({type:t}){super("Unknown type.",{metaMessages:[`Type "${t}" is not a valid ABI type.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSolidityTypeError"})}}class _h extends ht{constructor({param:t}){super("Invalid ABI parameter.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class vh extends ht{constructor({param:t,name:r}){super("Invalid ABI parameter.",{details:t,metaMessages:[`"${r}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SolidityProtectedKeywordError"})}}class Eh extends ht{constructor({param:t,type:r,modifier:n}){super("Invalid ABI parameter.",{details:t,metaMessages:[`Modifier "${n}" not allowed${r?` in "${r}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class xh extends ht{constructor({param:t,type:r,modifier:n}){super("Invalid ABI parameter.",{details:t,metaMessages:[`Modifier "${n}" not allowed${r?` in "${r}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${n}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class Ah extends ht{constructor({abiParameter:t}){super("Invalid ABI parameter.",{details:JSON.stringify(t,null,2),metaMessages:["ABI parameter type is invalid."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiTypeParameterError"})}}class wn extends ht{constructor({signature:t,type:r}){super(`Invalid ${r} signature.`,{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class Sh extends ht{constructor({signature:t}){super("Unknown signature.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class Ph extends ht{constructor({signature:t}){super("Invalid struct signature.",{details:t,metaMessages:["No properties exist."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidStructSignatureError"})}}class Th extends ht{constructor({type:t}){super("Circular reference detected.",{metaMessages:[`Struct "${t}" is a circular reference.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"CircularReferenceError"})}}class kh extends ht{constructor({current:t,depth:r}){super("Unbalanced parentheses.",{metaMessages:[`"${t.trim()}" has too many ${r>0?"opening":"closing"} parentheses.`],details:`Depth "${r}"`}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParenthesisError"})}}function Ih(e,t,r){let n="";if(r)for(const i of Object.entries(r)){if(!i)continue;let s="";for(const o of i[1])s+=`[${o.type}${o.name?`:${o.name}`:""}]`;n+=`(${i[0]}{${s}})`}return t?`${t}:${e}${n}`:e}const uo=new Map([["address",{type:"address"}],["bool",{type:"bool"}],["bytes",{type:"bytes"}],["bytes32",{type:"bytes32"}],["int",{type:"int256"}],["int256",{type:"int256"}],["string",{type:"string"}],["uint",{type:"uint256"}],["uint8",{type:"uint8"}],["uint16",{type:"uint16"}],["uint24",{type:"uint24"}],["uint32",{type:"uint32"}],["uint64",{type:"uint64"}],["uint96",{type:"uint96"}],["uint112",{type:"uint112"}],["uint160",{type:"uint160"}],["uint192",{type:"uint192"}],["uint256",{type:"uint256"}],["address owner",{type:"address",name:"owner"}],["address to",{type:"address",name:"to"}],["bool approved",{type:"bool",name:"approved"}],["bytes _data",{type:"bytes",name:"_data"}],["bytes data",{type:"bytes",name:"data"}],["bytes signature",{type:"bytes",name:"signature"}],["bytes32 hash",{type:"bytes32",name:"hash"}],["bytes32 r",{type:"bytes32",name:"r"}],["bytes32 root",{type:"bytes32",name:"root"}],["bytes32 s",{type:"bytes32",name:"s"}],["string name",{type:"string",name:"name"}],["string symbol",{type:"string",name:"symbol"}],["string tokenURI",{type:"string",name:"tokenURI"}],["uint tokenId",{type:"uint256",name:"tokenId"}],["uint8 v",{type:"uint8",name:"v"}],["uint256 balance",{type:"uint256",name:"balance"}],["uint256 tokenId",{type:"uint256",name:"tokenId"}],["uint256 value",{type:"uint256",name:"value"}],["event:address indexed from",{type:"address",name:"from",indexed:!0}],["event:address indexed to",{type:"address",name:"to",indexed:!0}],["event:uint indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}],["event:uint256 indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}]]);function Bh(e,t={}){if(ch(e))return Ch(e,t);if(oh(e))return Oh(e,t);if(ih(e))return Rh(e,t);if(dh(e))return Uh(e,t);if(hh(e))return Lh(e);if(mh(e))return{type:"receive",stateMutability:"payable"};throw new Sh({signature:e})}function Ch(e,t={}){const r=uh(e);if(!r)throw new wn({signature:e,type:"function"});const n=mt(r.parameters),i=[],s=n.length;for(let a=0;a<s;a++)i.push(Cr(n[a],{modifiers:Zo,structs:t,type:"function"}));const o=[];if(r.returns){const a=mt(r.returns),c=a.length;for(let f=0;f<c;f++)o.push(Cr(a[f],{modifiers:Zo,structs:t,type:"function"}))}return{name:r.name,type:"function",stateMutability:r.stateMutability??"nonpayable",inputs:i,outputs:o}}function Oh(e,t={}){const r=ah(e);if(!r)throw new wn({signature:e,type:"event"});const n=mt(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(Cr(n[o],{modifiers:bh,structs:t,type:"event"}));return{name:r.name,type:"event",inputs:i}}function Rh(e,t={}){const r=sh(e);if(!r)throw new wn({signature:e,type:"error"});const n=mt(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(Cr(n[o],{structs:t,type:"error"}));return{name:r.name,type:"error",inputs:i}}function Uh(e,t={}){const r=lh(e);if(!r)throw new wn({signature:e,type:"constructor"});const n=mt(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(Cr(n[o],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:r.stateMutability??"nonpayable",inputs:i}}function Lh(e){const t=ph(e);if(!t)throw new wn({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}const Nh=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Fh=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,$h=/^u?int$/;function Cr(e,t){var h,m;const r=Ih(e,t==null?void 0:t.type,t==null?void 0:t.structs);if(uo.has(r))return uo.get(r);const n=sf.test(e),i=Xt(n?Fh:Nh,e);if(!i)throw new _h({param:e});if(i.name&&Hh(i.name))throw new vh({param:e,name:i.name});const s=i.name?{name:i.name}:{},o=i.modifier==="indexed"?{indexed:!0}:{},a=(t==null?void 0:t.structs)??{};let c,f={};if(n){c="tuple";const p=mt(i.type),g=[],v=p.length;for(let x=0;x<v;x++)g.push(Cr(p[x],{structs:a}));f={components:g}}else if(i.type in a)c="tuple",f={components:a[i.type]};else if($h.test(i.type))c=`${i.type}256`;else if(c=i.type,(t==null?void 0:t.type)!=="struct"&&!hf(c))throw new wh({type:c});if(i.modifier){if(!((m=(h=t==null?void 0:t.modifiers)==null?void 0:h.has)!=null&&m.call(h,i.modifier)))throw new Eh({param:e,type:t==null?void 0:t.type,modifier:i.modifier});if(Zo.has(i.modifier)&&!Dh(c,!!i.array))throw new xh({param:e,type:t==null?void 0:t.type,modifier:i.modifier})}const l={type:`${c}${i.array??""}`,...s,...o,...f};return uo.set(r,l),l}function mt(e,t=[],r="",n=0){const i=e.trim().length;for(let s=0;s<i;s++){const o=e[s],a=e.slice(s+1);switch(o){case",":return n===0?mt(a,[...t,r.trim()]):mt(a,t,`${r}${o}`,n);case"(":return mt(a,t,`${r}${o}`,n+1);case")":return mt(a,t,`${r}${o}`,n-1);default:return mt(a,t,`${r}${o}`,n)}}if(r==="")return t;if(n!==0)throw new kh({current:r,depth:n});return t.push(r.trim()),t}function hf(e){return e==="address"||e==="bool"||e==="function"||e==="string"||rf.test(e)||nf.test(e)}const Mh=/^(?:after|alias|anonymous|apply|auto|byte|calldata|case|catch|constant|copyof|default|defined|error|event|external|false|final|function|immutable|implements|in|indexed|inline|internal|let|mapping|match|memory|mutable|null|of|override|partial|private|promise|public|pure|reference|relocatable|return|returns|sizeof|static|storage|struct|super|supports|switch|this|true|try|typedef|typeof|var|view|virtual)$/;function Hh(e){return e==="address"||e==="bool"||e==="function"||e==="string"||e==="tuple"||rf.test(e)||nf.test(e)||Mh.test(e)}function Dh(e,t){return t||e==="bytes"||e==="string"||e==="tuple"}function jh(e){const t={},r=e.length;for(let o=0;o<r;o++){const a=e[o];if(!ff(a))continue;const c=fh(a);if(!c)throw new wn({signature:a,type:"struct"});const f=c.properties.split(";"),l=[],h=f.length;for(let m=0;m<h;m++){const g=f[m].trim();if(!g)continue;const v=Cr(g,{type:"struct"});l.push(v)}if(!l.length)throw new Ph({signature:a});t[c.name]=l}const n={},i=Object.entries(t),s=i.length;for(let o=0;o<s;o++){const[a,c]=i[o];n[a]=pf(c,t)}return n}const Gh=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function pf(e,t,r=new Set){const n=[],i=e.length;for(let s=0;s<i;s++){const o=e[s];if(sf.test(o.type))n.push(o);else{const c=Xt(Gh,o.type);if(!(c!=null&&c.type))throw new Ah({abiParameter:o});const{array:f,type:l}=c;if(l in t){if(r.has(l))throw new Th({type:l});n.push({...o,type:`tuple${f??""}`,components:pf(t[l]??[],t,new Set([...r,l]))})}else if(hf(l))n.push(o);else throw new gh({type:l})}}return n}function yf(e){const t=jh(e),r=[],n=e.length;for(let i=0;i<n;i++){const s=e[i];ff(s)||r.push(Bh(s,t))}return r}function oe(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const i=e[r];return typeof i=="function"?i:s=>t(e,s)}function kt(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new n0(e.type);return`${e.name}(${Ps(e.inputs,{includeName:t})})`}function Ps(e,{includeName:t=!1}={}){return e?e.map(r=>zh(r,{includeName:t})).join(t?", ":","):""}function zh(e,{includeName:t}){return e.type.startsWith("tuple")?`(${Ps(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}function zt(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Ie(e){return zt(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const mf="2.28.0";let kn={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${mf}`};class $ extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof $?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof $&&r.cause.docsPath||r.docsPath,s=(a=kn.getDocsUrl)==null?void 0:a.call(kn,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...kn.version?[`Version: ${kn.version}`]:[]].join(`
|
|
3
3
|
`);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=mf}walk(t){return bf(this,t)}}function bf(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?bf(e.cause,t):t?null:e}class qh extends ${constructor({docsPath:t}){super(["A constructor was not found on the ABI.","Make sure you are using the correct ABI and that the constructor exists on it."].join(`
|
|
4
|
-
`),{docsPath:t,name:"AbiConstructorNotFoundError"})}}class
|
|
4
|
+
`),{docsPath:t,name:"AbiConstructorNotFoundError"})}}class Bc extends ${constructor({docsPath:t}){super(["Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.","Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists."].join(`
|
|
5
5
|
`),{docsPath:t,name:"AbiConstructorParamsNotFoundError"})}}class gf extends ${constructor({data:t,params:r,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join(`
|
|
6
|
-
`),{metaMessages:[`Params: (${Ps(r,{includeName:!0})})`,`Data: ${t} (${n} bytes)`],name:"AbiDecodingDataSizeTooSmallError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t,this.params=r,this.size=n}}class
|
|
6
|
+
`),{metaMessages:[`Params: (${Ps(r,{includeName:!0})})`,`Data: ${t} (${n} bytes)`],name:"AbiDecodingDataSizeTooSmallError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t,this.params=r,this.size=n}}class Ba extends ${constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class Vh extends ${constructor({expectedLength:t,givenLength:r,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${t}`,`Given length: ${r}`].join(`
|
|
7
7
|
`),{name:"AbiEncodingArrayLengthMismatchError"})}}class Wh extends ${constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${Ie(r)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class Kh extends ${constructor({expectedLength:t,givenLength:r}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${t}`,`Given length (values): ${r}`].join(`
|
|
8
8
|
`),{name:"AbiEncodingLengthMismatchError"})}}class Yh extends ${constructor(t,{docsPath:r}){super([`Arguments (\`args\`) were provided to "${t}", but "${t}" on the ABI does not contain any parameters (\`inputs\`).`,"Cannot encode error result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the inputs exist on it."].join(`
|
|
9
9
|
`),{docsPath:r,name:"AbiErrorInputsNotFoundError"})}}class Xh extends ${constructor(t,{docsPath:r}={}){super([`Error ${t?`"${t}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it."].join(`
|
|
10
10
|
`),{docsPath:r,name:"AbiErrorNotFoundError"})}}class wf extends ${constructor(t,{docsPath:r}){super([`Encoded error signature "${t}" not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it.",`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${t}.`].join(`
|
|
11
11
|
`),{docsPath:r,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=t}}class Jh extends ${constructor({docsPath:t}){super("Cannot extract event signature from empty topics.",{docsPath:t,name:"AbiEventSignatureEmptyTopicsError"})}}class _f extends ${constructor(t,{docsPath:r}){super([`Encoded event signature "${t}" not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${t}.`].join(`
|
|
12
|
-
`),{docsPath:r,name:"AbiEventSignatureNotFoundError"})}}class
|
|
12
|
+
`),{docsPath:r,name:"AbiEventSignatureNotFoundError"})}}class Cc extends ${constructor(t,{docsPath:r}={}){super([`Event ${t?`"${t}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it."].join(`
|
|
13
13
|
`),{docsPath:r,name:"AbiEventNotFoundError"})}}class Xn extends ${constructor(t,{docsPath:r}={}){super([`Function ${t?`"${t}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join(`
|
|
14
14
|
`),{docsPath:r,name:"AbiFunctionNotFoundError"})}}class vf extends ${constructor(t,{docsPath:r}){super([`Function "${t}" does not contain any \`outputs\` on ABI.`,"Cannot decode function result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the function exists on it."].join(`
|
|
15
15
|
`),{docsPath:r,name:"AbiFunctionOutputsNotFoundError"})}}class Qh extends ${constructor(t,{docsPath:r}){super([`Encoded function signature "${t}" not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${t}.`].join(`
|
|
16
16
|
`),{docsPath:r,name:"AbiFunctionSignatureNotFoundError"})}}class Zh extends ${constructor(t,r){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${t.type}\` in \`${kt(t.abiItem)}\`, and`,`\`${r.type}\` in \`${kt(r.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class e0 extends ${constructor({expectedSize:t,givenSize:r}){super(`Expected bytes${t}, got bytes${r}.`,{name:"BytesSizeMismatchError"})}}class ys extends ${constructor({abiItem:t,data:r,params:n,size:i}){super([`Data size of ${i} bytes is too small for non-indexed event parameters.`].join(`
|
|
17
|
-
`),{metaMessages:[`Params: (${Ps(n,{includeName:!0})})`,`Data: ${r} (${i} bytes)`],name:"DecodeLogDataMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t,this.data=r,this.params=n,this.size=i}}class
|
|
17
|
+
`),{metaMessages:[`Params: (${Ps(n,{includeName:!0})})`,`Data: ${r} (${i} bytes)`],name:"DecodeLogDataMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t,this.data=r,this.params=n,this.size=i}}class Ca extends ${constructor({abiItem:t,param:r}){super([`Expected a topic for indexed event parameter${r.name?` "${r.name}"`:""} on event "${kt(t,{includeName:!0})}".`].join(`
|
|
18
18
|
`),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t}}class t0 extends ${constructor(t,{docsPath:r}){super([`Type "${t}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(`
|
|
19
19
|
`),{docsPath:r,name:"InvalidAbiEncodingType"})}}class r0 extends ${constructor(t,{docsPath:r}){super([`Type "${t}" is not a valid decoding type.`,"Please provide a valid ABI type."].join(`
|
|
20
20
|
`),{docsPath:r,name:"InvalidAbiDecodingType"})}}class Ef extends ${constructor(t){super([`Value "${t}" is not a valid array.`].join(`
|
|
21
21
|
`),{name:"InvalidArrayError"})}}class n0 extends ${constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(`
|
|
22
|
-
`),{name:"InvalidDefinitionTypeError"})}}class i0 extends ${constructor(t){super(`Filter type "${t}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}class xf extends ${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 Af extends ${constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}class Bc extends ${constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} is expected to be ${r} ${n} long, but is ${t} ${n} long.`,{name:"InvalidBytesLengthError"})}}function _n(e,{dir:t,size:r=32}={}){return typeof e=="string"?dr(e,{dir:t,size:r}):s0(e,{dir:t,size:r})}function dr(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Af({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function s0(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Af({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}class Sf extends ${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 o0 extends ${constructor(t){super(`Bytes value "${t}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class a0 extends ${constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function Or(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}function Bt(e,{size:t}){if(Ie(e)>t)throw new a0({givenSize:Ie(e),maxSize:t})}function lt(e,t={}){const{signed:r}=t;t.size&&Bt(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 qt(e,t={}){return Number(lt(e,t))}const c0=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function J(e,t={}){return typeof e=="number"||typeof e=="bigint"?Q(e,t):typeof e=="string"?Ts(e,t):typeof e=="boolean"?Pf(e,t):Ze(e,t)}function Pf(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Bt(r,{size:t.size}),_n(r,{size:t.size})):r}function Ze(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=c0[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Bt(n,{size:t.size}),_n(n,{dir:"right",size:t.size})):n}function Q(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 Sf({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?_n(a,{size:n}):a}const u0=new TextEncoder;function Ts(e,t={}){const r=u0.encode(e);return Ze(r,t)}const f0=new TextEncoder;function Pi(e,t={}){return typeof e=="number"||typeof e=="bigint"?l0(e,t):typeof e=="boolean"?d0(e,t):zt(e)?Vt(e,t):Tf(e,t)}function d0(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Bt(r,{size:t.size}),_n(r,{size:t.size})):r}const Ut={zero:48,nine:57,A:65,F:70,a:97,f:102};function Cc(e){if(e>=Ut.zero&&e<=Ut.nine)return e-Ut.zero;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function Vt(e,t={}){let r=e;t.size&&(Bt(r,{size:t.size}),r=_n(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=Cc(n.charCodeAt(a++)),f=Cc(n.charCodeAt(a++));if(c===void 0||f===void 0)throw new $(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+f}return s}function l0(e,t){const r=Q(e,t);return Vt(r)}function Tf(e,t={}){const r=f0.encode(e);return typeof t.size=="number"?(Bt(r,{size:t.size}),_n(r,{dir:"right",size:t.size})):r}function ms(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function h0(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ti(e,...t){if(!h0(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function p0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ms(e.outputLen),ms(e.blockLen)}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 kf(e,t){Ti(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Gi=BigInt(2**32-1),Oc=BigInt(32);function y0(e,t=!1){return t?{h:Number(e&Gi),l:Number(e>>Oc&Gi)}:{h:Number(e>>Oc&Gi)|0,l:Number(e&Gi)|0}}function m0(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}=y0(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const b0=(e,t,r)=>e<<r|t>>>32-r,g0=(e,t,r)=>t<<r|e>>>32-r,w0=(e,t,r)=>t<<r-32|e>>>64-r,_0=(e,t,r)=>e<<r-32|t>>>64-r,Wr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function v0(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function fo(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function gt(e,t){return e<<32-t|e>>>t}const Rc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function E0(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Uc(e){for(let t=0;t<e.length;t++)e[t]=E0(e[t])}typeof Uint8Array.from([]).toHex=="function"&&Uint8Array.fromHex;function x0(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function ks(e){return typeof e=="string"&&(e=x0(e)),Ti(e),e}function A0(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];Ti(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}let Ba=class{clone(){return this._cloneInto()}};function If(e){const t=n=>e().update(ks(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function S0(e=32){if(Wr&&typeof Wr.getRandomValues=="function")return Wr.getRandomValues(new Uint8Array(e));if(Wr&&typeof Wr.randomBytes=="function")return Uint8Array.from(Wr.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Bf=[],Cf=[],Of=[],P0=BigInt(0),In=BigInt(1),T0=BigInt(2),k0=BigInt(7),I0=BigInt(256),B0=BigInt(113);for(let e=0,t=In,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Bf.push(2*(5*n+r)),Cf.push((e+1)*(e+2)/2%64);let i=P0;for(let s=0;s<7;s++)t=(t<<In^(t>>k0)*B0)%I0,t&T0&&(i^=In<<(In<<BigInt(s))-In);Of.push(i)}const[C0,O0]=m0(Of,!0),Lc=(e,t,r)=>r>32?w0(e,t,r):b0(e,t,r),Nc=(e,t,r)=>r>32?_0(e,t,r):g0(e,t,r);function R0(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,f=r[c],l=r[c+1],h=Lc(f,l,1)^r[a],m=Nc(f,l,1)^r[a+1];for(let p=0;p<50;p+=10)e[o+p]^=h,e[o+p+1]^=m}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=Cf[o],c=Lc(i,s,a),f=Nc(i,s,a),l=Bf[o];i=e[l],s=e[l+1],e[l]=c,e[l+1]=f}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]^=C0[n],e[1]^=O0[n]}r.fill(0)}class Ca extends Ba{constructor(t,r,n,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,ms(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=v0(this.state)}keccak(){Rc||Uc(this.state32),R0(this.state32,this.rounds),Rc||Uc(this.state32),this.posOut=0,this.pos=0}update(t){Jn(this);const{blockLen:r,state:n}=this;t=ks(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),Ti(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 ms(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(kf(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 Ca(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 U0=(e,t,r)=>If(()=>new Ca(t,e,r)),L0=U0(1,136,256/8);function vn(e,t){const r=t||"hex",n=L0(zt(e,{strict:!1})?Pi(e):e);return r==="bytes"?n:J(n)}const N0=e=>vn(Pi(e));function F0(e){return N0(e)}function $0(e){let t=!0,r="",n=0,i="",s=!1;for(let o=0;o<e.length;o++){const a=e[o];if(["(",")",","].includes(a)&&(t=!0),a==="("&&n++,a===")"&&n--,!!t){if(n===0){if(a===" "&&["event","function",""].includes(i))i="";else if(i+=a,a===")"){s=!0;break}continue}if(a===" "){e[o-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!s)throw new $("Unable to normalize signature.");return i}const M0=e=>{const t=typeof e=="string"?e:nh(e);return $0(t)};function Rf(e){return F0(M0(e))}const Is=Rf;class et extends ${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 Bs 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 lo=new Bs(8192);function ki(e,t){if(lo.has(`${e}.${t}`))return lo.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=vn(Tf(r),"bytes"),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return lo.set(`${e}.${t}`,s),s}function H0(e,t){if(!Le(e,{strict:!1}))throw new et({address:e});return ki(e,t)}const D0=/^0x[a-fA-F0-9]{40}$/,ho=new Bs(8192);function Le(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(ho.has(n))return ho.get(n);const i=D0.test(e)?e.toLowerCase()===e?!0:r?ki(e)===e:!0:!1;return ho.set(n,i),i}function Rr(e){return typeof e[0]=="string"?Ct(e):j0(e)}function j0(e){let t=0;for(const i of e)t+=i.length;const r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.length;return r}function Ct(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function dn(e,t,r,{strict:n}={}){return zt(e,{strict:!1})?G0(e,t,r,{strict:n}):Nf(e,t,r,{strict:n})}function Uf(e,t){if(typeof t=="number"&&t>0&&t>Ie(e)-1)throw new xf({offset:t,position:"start",size:Ie(e)})}function Lf(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Ie(e)!==r-t)throw new xf({offset:r,position:"end",size:Ie(e)})}function Nf(e,t,r,{strict:n}={}){Uf(e,t);const i=e.slice(t,r);return n&&Lf(i,t,r),i}function G0(e,t,r,{strict:n}={}){Uf(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return n&&Lf(i,t,r),i}const z0=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Ff=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function Cs(e,t){if(e.length!==t.length)throw new Kh({expectedLength:e.length,givenLength:t.length});const r=q0({params:e,values:t}),n=Ra(r);return n.length===0?"0x":n}function q0({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(Oa({param:e[n],value:t[n]}));return r}function Oa({param:e,value:t}){const r=Ua(e.type);if(r){const[n,i]=r;return W0(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return Q0(t,{param:e});if(e.type==="address")return V0(t);if(e.type==="bool")return Y0(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=Ff.exec(e.type)??[];return X0(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return K0(t,{param:e});if(e.type==="string")return J0(t);throw new t0(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function Ra(e){let t=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?t+=32:t+=Ie(a)}const r=[],n=[];let i=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?(r.push(Q(t+i,{size:32})),n.push(a),i+=Ie(a)):r.push(a)}return Rr([...r,...n])}function V0(e){if(!Le(e))throw new et({address:e});return{dynamic:!1,encoded:dr(e.toLowerCase())}}function W0(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new Ef(e);if(!n&&e.length!==t)throw new Vh({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const s=[];for(let o=0;o<e.length;o++){const a=Oa({param:r,value:e[o]});a.dynamic&&(i=!0),s.push(a)}if(n||i){const o=Ra(s);if(n){const a=Q(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?Rr([a,o]):a}}if(i)return{dynamic:!0,encoded:o}}return{dynamic:!1,encoded:Rr(s.map(({encoded:o})=>o))}}function K0(e,{param:t}){const[,r]=t.type.split("bytes"),n=Ie(e);if(!r){let i=e;return n%32!==0&&(i=dr(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:Rr([dr(Q(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new Wh({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:dr(e,{dir:"right"})}}function Y0(e){if(typeof e!="boolean")throw new $(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:dr(Pf(e))}}function X0(e,{signed:t,size:r=256}){if(typeof r=="number"){const n=2n**(BigInt(r)-(t?1n:0n))-1n,i=t?-n-1n:0n;if(e>n||e<i)throw new Sf({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:Q(e,{size:32,signed:t})}}function J0(e){const t=Ts(e),r=Math.ceil(Ie(t)/32),n=[];for(let i=0;i<r;i++)n.push(dr(dn(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:Rr([dr(Q(Ie(t),{size:32})),...n])}}function Q0(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const s=t.components[i],o=Array.isArray(e)?i:s.name,a=Oa({param:s,value:e[o]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?Ra(n):Rr(n.map(({encoded:i})=>i))}}function Ua(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Os=e=>dn(Rf(e),0,4);function En(e){const{abi:t,args:r=[],name:n}=e,i=zt(n,{strict:!1}),s=t.filter(a=>i?a.type==="function"?Os(a)===n:a.type==="event"?Is(a)===n:!1:"name"in a&&a.name===n);if(s.length===0)return;if(s.length===1)return s[0];let o;for(const a of s){if(!("inputs"in a))continue;if(!r||r.length===0){if(!a.inputs||a.inputs.length===0)return a;continue}if(!a.inputs||a.inputs.length===0||a.inputs.length!==r.length)continue;if(r.every((f,l)=>{const h="inputs"in a&&a.inputs[l];return h?Qo(f,h):!1})){if(o&&"inputs"in o&&o.inputs){const f=$f(a.inputs,o.inputs,r);if(f)throw new Zh({abiItem:a,type:f[0]},{abiItem:o,type:f[1]})}o=a}}return o||s[0]}function Qo(e,t){const r=typeof e,n=t.type;switch(n){case"address":return Le(e,{strict:!1});case"bool":return r==="boolean";case"function":return r==="string";case"string":return r==="string";default:return n==="tuple"&&"components"in t?Object.values(t.components).every((i,s)=>Qo(Object.values(e)[s],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?r==="number"||r==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?r==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(e)&&e.every(i=>Qo(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function $f(e,t,r){for(const n in e){const i=e[n],s=t[n];if(i.type==="tuple"&&s.type==="tuple"&&"components"in i&&"components"in s)return $f(i.components,s.components,r[n]);const o=[i.type,s.type];if(o.includes("address")&&o.includes("bytes20")?!0:o.includes("address")&&o.includes("string")?Le(r[n],{strict:!1}):o.includes("address")&&o.includes("bytes")?Le(r[n],{strict:!1}):!1)return o}}const Fc="/docs/contract/encodeEventTopics";function La(e){var c;const{abi:t,eventName:r,args:n}=e;let i=t[0];if(r){const f=En({abi:t,name:r});if(!f)throw new Ic(r,{docsPath:Fc});i=f}if(i.type!=="event")throw new Ic(void 0,{docsPath:Fc});const s=kt(i),o=Is(s);let a=[];if(n&&"inputs"in i){const f=(c=i.inputs)==null?void 0:c.filter(h=>"indexed"in h&&h.indexed),l=Array.isArray(n)?n:Object.values(n).length>0?(f==null?void 0:f.map(h=>n[h.name]))??[]:[];l.length>0&&(a=(f==null?void 0:f.map((h,m)=>Array.isArray(l[m])?l[m].map((p,g)=>$c({param:h,value:l[m][g]})):typeof l[m]<"u"&&l[m]!==null?$c({param:h,value:l[m]}):null))??[])}return[o,...a]}function $c({param:e,value:t}){if(e.type==="string"||e.type==="bytes")return vn(Pi(t));if(e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/))throw new i0(e.type);return Cs([e],[t])}function Z0(e,{method:t}){var n,i;const r={};return e.transport.type==="fallback"&&((i=(n=e.transport).onResponse)==null||i.call(n,({method:s,response:o,status:a,transport:c})=>{a==="success"&&t===s&&(r[o]=c.request)})),s=>r[s]||e.request}async function Mf(e,t){const{address:r,abi:n,args:i,eventName:s,fromBlock:o,strict:a,toBlock:c}=t,f=Z0(e,{method:"eth_newFilter"}),l=s?La({abi:n,args:i,eventName:s}):void 0,h=await e.request({method:"eth_newFilter",params:[{address:r,fromBlock:typeof o=="bigint"?Q(o):o,toBlock:typeof c=="bigint"?Q(c):c,topics:l}]});return{abi:n,args:i,eventName:s,id:h,request:f(h),strict:!!a,type:"event"}}function Ne(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}const Mc="/docs/contract/encodeFunctionData";function ep(e){const{abi:t,args:r,functionName:n}=e;let i=t[0];if(n){const s=En({abi:t,args:r,name:n});if(!s)throw new Xn(n,{docsPath:Mc});i=s}if(i.type!=="function")throw new Xn(void 0,{docsPath:Mc});return{abi:[i],functionName:Os(kt(i))}}function xn(e){const{args:t}=e,{abi:r,functionName:n}=(()=>{var a;return e.abi.length===1&&((a=e.functionName)!=null&&a.startsWith("0x"))?e:ep(e)})(),i=r[0],s=n,o="inputs"in i&&i.inputs?Cs(i.inputs,t??[]):void 0;return Ct([s,o??"0x"])}const tp={1:"An `assert` condition failed.",17:"Arithmetic operation resulted in underflow or overflow.",18:"Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",33:"Attempted to convert to an invalid type.",34:"Attempted to access a storage byte array that is incorrectly encoded.",49:"Performed `.pop()` on an empty array",50:"Array index is out of bounds.",65:"Allocated too much memory or created an array which is too large.",81:"Attempted to call a zero-initialized variable of internal function type."},Hf={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},rp={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class Hc extends ${constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Df extends ${constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class np extends ${constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const ip={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 np({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new Df({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new Hc({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 Hc({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 Na(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(ip);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function sp(e,t={}){typeof t.size<"u"&&Bt(e,{size:t.size});const r=Ze(e,t);return lt(r,t)}function op(e,t={}){let r=e;if(typeof t.size<"u"&&(Bt(r,{size:t.size}),r=Or(r)),r.length>1||r[0]>1)throw new o0(r);return!!r[0]}function jt(e,t={}){typeof t.size<"u"&&Bt(e,{size:t.size});const r=Ze(e,t);return qt(r,t)}function ap(e,t={}){let r=e;return typeof t.size<"u"&&(Bt(r,{size:t.size}),r=Or(r,{dir:"right"})),new TextDecoder().decode(r)}function Ii(e,t){const r=typeof t=="string"?Vt(t):t,n=Na(r);if(Ie(r)===0&&e.length>0)throw new ka;if(Ie(t)&&Ie(t)<32)throw new gf({data:typeof t=="string"?t:Ze(t),params:e,size:Ie(t)});let i=0;const s=[];for(let o=0;o<e.length;++o){const a=e[o];n.setPosition(i);const[c,f]=nn(n,a,{staticPosition:0});i+=f,s.push(c)}return s}function nn(e,t,{staticPosition:r}){const n=Ua(t.type);if(n){const[i,s]=n;return up(e,{...t,type:s},{length:i,staticPosition:r})}if(t.type==="tuple")return hp(e,t,{staticPosition:r});if(t.type==="address")return cp(e);if(t.type==="bool")return fp(e);if(t.type.startsWith("bytes"))return dp(e,t,{staticPosition:r});if(t.type.startsWith("uint")||t.type.startsWith("int"))return lp(e,t);if(t.type==="string")return pp(e,{staticPosition:r});throw new r0(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const Dc=32,Zo=32;function cp(e){const t=e.readBytes(32);return[ki(Ze(Nf(t,-20))),32]}function up(e,t,{length:r,staticPosition:n}){if(!r){const o=jt(e.readBytes(Zo)),a=n+o,c=a+Dc;e.setPosition(a);const f=jt(e.readBytes(Dc)),l=Qn(t);let h=0;const m=[];for(let p=0;p<f;++p){e.setPosition(c+(l?p*32:h));const[g,v]=nn(e,t,{staticPosition:c});h+=v,m.push(g)}return e.setPosition(n+32),[m,32]}if(Qn(t)){const o=jt(e.readBytes(Zo)),a=n+o,c=[];for(let f=0;f<r;++f){e.setPosition(a+f*32);const[l]=nn(e,t,{staticPosition:a});c.push(l)}return e.setPosition(n+32),[c,32]}let i=0;const s=[];for(let o=0;o<r;++o){const[a,c]=nn(e,t,{staticPosition:n+i});i+=c,s.push(a)}return[s,i]}function fp(e){return[op(e.readBytes(32),{size:32}),32]}function dp(e,t,{staticPosition:r}){const[n,i]=t.type.split("bytes");if(!i){const o=jt(e.readBytes(32));e.setPosition(r+o);const a=jt(e.readBytes(32));if(a===0)return e.setPosition(r+32),["0x",32];const c=e.readBytes(a);return e.setPosition(r+32),[Ze(c),32]}return[Ze(e.readBytes(Number.parseInt(i),32)),32]}function lp(e,t){const r=t.type.startsWith("int"),n=Number.parseInt(t.type.split("int")[1]||"256"),i=e.readBytes(32);return[n>48?sp(i,{signed:r}):jt(i,{signed:r}),32]}function hp(e,t,{staticPosition:r}){const n=t.components.length===0||t.components.some(({name:o})=>!o),i=n?[]:{};let s=0;if(Qn(t)){const o=jt(e.readBytes(Zo)),a=r+o;for(let c=0;c<t.components.length;++c){const f=t.components[c];e.setPosition(a+s);const[l,h]=nn(e,f,{staticPosition:a});s+=h,i[n?c:f==null?void 0:f.name]=l}return e.setPosition(r+32),[i,32]}for(let o=0;o<t.components.length;++o){const a=t.components[o],[c,f]=nn(e,a,{staticPosition:r});i[n?o:a==null?void 0:a.name]=c,s+=f}return[i,s]}function pp(e,{staticPosition:t}){const r=jt(e.readBytes(32)),n=t+r;e.setPosition(n);const i=jt(e.readBytes(32));if(i===0)return e.setPosition(t+32),["",32];const s=e.readBytes(i,32),o=ap(Or(s));return e.setPosition(t+32),[o,32]}function Qn(e){var n;const{type:t}=e;if(t==="string"||t==="bytes"||t.endsWith("[]"))return!0;if(t==="tuple")return(n=e.components)==null?void 0:n.some(Qn);const r=Ua(e.type);return!!(r&&Qn({...e,type:r[1]}))}function jf(e){const{abi:t,data:r}=e,n=dn(r,0,4);if(n==="0x")throw new ka;const s=[...t||[],Hf,rp].find(o=>o.type==="error"&&n===Os(kt(o)));if(!s)throw new wf(n,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:s,args:"inputs"in s&&s.inputs&&s.inputs.length>0?Ii(s.inputs,dn(r,4)):void 0,errorName:s.name}}const It=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);function Gf({abiItem:e,args:t,includeFunctionName:r=!0,includeName:n=!1}){if("name"in e&&"inputs"in e&&e.inputs)return`${r?e.name:""}(${e.inputs.map((i,s)=>`${n&&i.name?`${i.name}: `:""}${typeof t[s]=="object"?It(t[s]):t[s]}`).join(", ")})`}const yp={gwei:9,wei:18},mp={ether:-9,wei:9};function zf(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 Fa(e,t="wei"){return zf(e,yp[t])}function rt(e,t="wei"){return zf(e,mp[t])}class bp extends ${constructor({address:t}){super(`State for account "${t}" is set multiple times.`,{name:"AccountStateConflictError"})}}class gp extends ${constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function jc(e){return e.reduce((t,{slot:r,value:n})=>`${t} ${r}: ${n}
|
|
22
|
+
`),{name:"InvalidDefinitionTypeError"})}}class i0 extends ${constructor(t){super(`Filter type "${t}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}class xf extends ${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 Af extends ${constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}class Oc extends ${constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} is expected to be ${r} ${n} long, but is ${t} ${n} long.`,{name:"InvalidBytesLengthError"})}}function _n(e,{dir:t,size:r=32}={}){return typeof e=="string"?dr(e,{dir:t,size:r}):s0(e,{dir:t,size:r})}function dr(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Af({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function s0(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Af({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}class Sf extends ${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 o0 extends ${constructor(t){super(`Bytes value "${t}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class a0 extends ${constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function Or(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}function Bt(e,{size:t}){if(Ie(e)>t)throw new a0({givenSize:Ie(e),maxSize:t})}function lt(e,t={}){const{signed:r}=t;t.size&&Bt(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 qt(e,t={}){return Number(lt(e,t))}const c0=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function J(e,t={}){return typeof e=="number"||typeof e=="bigint"?Q(e,t):typeof e=="string"?Ts(e,t):typeof e=="boolean"?Pf(e,t):Ze(e,t)}function Pf(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Bt(r,{size:t.size}),_n(r,{size:t.size})):r}function Ze(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=c0[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Bt(n,{size:t.size}),_n(n,{dir:"right",size:t.size})):n}function Q(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 Sf({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?_n(a,{size:n}):a}const u0=new TextEncoder;function Ts(e,t={}){const r=u0.encode(e);return Ze(r,t)}const f0=new TextEncoder;function Pi(e,t={}){return typeof e=="number"||typeof e=="bigint"?l0(e,t):typeof e=="boolean"?d0(e,t):zt(e)?Vt(e,t):Tf(e,t)}function d0(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Bt(r,{size:t.size}),_n(r,{size:t.size})):r}const Ut={zero:48,nine:57,A:65,F:70,a:97,f:102};function Rc(e){if(e>=Ut.zero&&e<=Ut.nine)return e-Ut.zero;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function Vt(e,t={}){let r=e;t.size&&(Bt(r,{size:t.size}),r=_n(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=Rc(n.charCodeAt(a++)),f=Rc(n.charCodeAt(a++));if(c===void 0||f===void 0)throw new $(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+f}return s}function l0(e,t){const r=Q(e,t);return Vt(r)}function Tf(e,t={}){const r=f0.encode(e);return typeof t.size=="number"?(Bt(r,{size:t.size}),_n(r,{dir:"right",size:t.size})):r}function ms(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function h0(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ti(e,...t){if(!h0(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function p0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ms(e.outputLen),ms(e.blockLen)}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 kf(e,t){Ti(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Gi=BigInt(2**32-1),Uc=BigInt(32);function y0(e,t=!1){return t?{h:Number(e&Gi),l:Number(e>>Uc&Gi)}:{h:Number(e>>Uc&Gi)|0,l:Number(e&Gi)|0}}function m0(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}=y0(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const b0=(e,t,r)=>e<<r|t>>>32-r,g0=(e,t,r)=>t<<r|e>>>32-r,w0=(e,t,r)=>t<<r-32|e>>>64-r,_0=(e,t,r)=>e<<r-32|t>>>64-r,Wr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function v0(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function fo(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function gt(e,t){return e<<32-t|e>>>t}const Lc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function E0(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Nc(e){for(let t=0;t<e.length;t++)e[t]=E0(e[t])}typeof Uint8Array.from([]).toHex=="function"&&Uint8Array.fromHex;function x0(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function ks(e){return typeof e=="string"&&(e=x0(e)),Ti(e),e}function A0(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];Ti(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}let Oa=class{clone(){return this._cloneInto()}};function If(e){const t=n=>e().update(ks(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function S0(e=32){if(Wr&&typeof Wr.getRandomValues=="function")return Wr.getRandomValues(new Uint8Array(e));if(Wr&&typeof Wr.randomBytes=="function")return Uint8Array.from(Wr.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Bf=[],Cf=[],Of=[],P0=BigInt(0),In=BigInt(1),T0=BigInt(2),k0=BigInt(7),I0=BigInt(256),B0=BigInt(113);for(let e=0,t=In,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Bf.push(2*(5*n+r)),Cf.push((e+1)*(e+2)/2%64);let i=P0;for(let s=0;s<7;s++)t=(t<<In^(t>>k0)*B0)%I0,t&T0&&(i^=In<<(In<<BigInt(s))-In);Of.push(i)}const[C0,O0]=m0(Of,!0),Fc=(e,t,r)=>r>32?w0(e,t,r):b0(e,t,r),$c=(e,t,r)=>r>32?_0(e,t,r):g0(e,t,r);function R0(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,f=r[c],l=r[c+1],h=Fc(f,l,1)^r[a],m=$c(f,l,1)^r[a+1];for(let p=0;p<50;p+=10)e[o+p]^=h,e[o+p+1]^=m}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=Cf[o],c=Fc(i,s,a),f=$c(i,s,a),l=Bf[o];i=e[l],s=e[l+1],e[l]=c,e[l+1]=f}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]^=C0[n],e[1]^=O0[n]}r.fill(0)}class Ra extends Oa{constructor(t,r,n,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,ms(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=v0(this.state)}keccak(){Lc||Nc(this.state32),R0(this.state32,this.rounds),Lc||Nc(this.state32),this.posOut=0,this.pos=0}update(t){Jn(this);const{blockLen:r,state:n}=this;t=ks(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),Ti(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 ms(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(kf(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 Ra(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 U0=(e,t,r)=>If(()=>new Ra(t,e,r)),L0=U0(1,136,256/8);function vn(e,t){const r=t||"hex",n=L0(zt(e,{strict:!1})?Pi(e):e);return r==="bytes"?n:J(n)}const N0=e=>vn(Pi(e));function F0(e){return N0(e)}function $0(e){let t=!0,r="",n=0,i="",s=!1;for(let o=0;o<e.length;o++){const a=e[o];if(["(",")",","].includes(a)&&(t=!0),a==="("&&n++,a===")"&&n--,!!t){if(n===0){if(a===" "&&["event","function",""].includes(i))i="";else if(i+=a,a===")"){s=!0;break}continue}if(a===" "){e[o-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!s)throw new $("Unable to normalize signature.");return i}const M0=e=>{const t=typeof e=="string"?e:nh(e);return $0(t)};function Rf(e){return F0(M0(e))}const Is=Rf;class et extends ${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 Bs 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 lo=new Bs(8192);function ki(e,t){if(lo.has(`${e}.${t}`))return lo.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=vn(Tf(r),"bytes"),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return lo.set(`${e}.${t}`,s),s}function H0(e,t){if(!Le(e,{strict:!1}))throw new et({address:e});return ki(e,t)}const D0=/^0x[a-fA-F0-9]{40}$/,ho=new Bs(8192);function Le(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(ho.has(n))return ho.get(n);const i=D0.test(e)?e.toLowerCase()===e?!0:r?ki(e)===e:!0:!1;return ho.set(n,i),i}function Rr(e){return typeof e[0]=="string"?Ct(e):j0(e)}function j0(e){let t=0;for(const i of e)t+=i.length;const r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.length;return r}function Ct(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function dn(e,t,r,{strict:n}={}){return zt(e,{strict:!1})?G0(e,t,r,{strict:n}):Nf(e,t,r,{strict:n})}function Uf(e,t){if(typeof t=="number"&&t>0&&t>Ie(e)-1)throw new xf({offset:t,position:"start",size:Ie(e)})}function Lf(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Ie(e)!==r-t)throw new xf({offset:r,position:"end",size:Ie(e)})}function Nf(e,t,r,{strict:n}={}){Uf(e,t);const i=e.slice(t,r);return n&&Lf(i,t,r),i}function G0(e,t,r,{strict:n}={}){Uf(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return n&&Lf(i,t,r),i}const z0=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Ff=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function Cs(e,t){if(e.length!==t.length)throw new Kh({expectedLength:e.length,givenLength:t.length});const r=q0({params:e,values:t}),n=La(r);return n.length===0?"0x":n}function q0({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(Ua({param:e[n],value:t[n]}));return r}function Ua({param:e,value:t}){const r=Na(e.type);if(r){const[n,i]=r;return W0(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return Q0(t,{param:e});if(e.type==="address")return V0(t);if(e.type==="bool")return Y0(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=Ff.exec(e.type)??[];return X0(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return K0(t,{param:e});if(e.type==="string")return J0(t);throw new t0(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function La(e){let t=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?t+=32:t+=Ie(a)}const r=[],n=[];let i=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?(r.push(Q(t+i,{size:32})),n.push(a),i+=Ie(a)):r.push(a)}return Rr([...r,...n])}function V0(e){if(!Le(e))throw new et({address:e});return{dynamic:!1,encoded:dr(e.toLowerCase())}}function W0(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new Ef(e);if(!n&&e.length!==t)throw new Vh({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const s=[];for(let o=0;o<e.length;o++){const a=Ua({param:r,value:e[o]});a.dynamic&&(i=!0),s.push(a)}if(n||i){const o=La(s);if(n){const a=Q(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?Rr([a,o]):a}}if(i)return{dynamic:!0,encoded:o}}return{dynamic:!1,encoded:Rr(s.map(({encoded:o})=>o))}}function K0(e,{param:t}){const[,r]=t.type.split("bytes"),n=Ie(e);if(!r){let i=e;return n%32!==0&&(i=dr(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:Rr([dr(Q(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new Wh({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:dr(e,{dir:"right"})}}function Y0(e){if(typeof e!="boolean")throw new $(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:dr(Pf(e))}}function X0(e,{signed:t,size:r=256}){if(typeof r=="number"){const n=2n**(BigInt(r)-(t?1n:0n))-1n,i=t?-n-1n:0n;if(e>n||e<i)throw new Sf({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:Q(e,{size:32,signed:t})}}function J0(e){const t=Ts(e),r=Math.ceil(Ie(t)/32),n=[];for(let i=0;i<r;i++)n.push(dr(dn(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:Rr([dr(Q(Ie(t),{size:32})),...n])}}function Q0(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const s=t.components[i],o=Array.isArray(e)?i:s.name,a=Ua({param:s,value:e[o]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?La(n):Rr(n.map(({encoded:i})=>i))}}function Na(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Os=e=>dn(Rf(e),0,4);function En(e){const{abi:t,args:r=[],name:n}=e,i=zt(n,{strict:!1}),s=t.filter(a=>i?a.type==="function"?Os(a)===n:a.type==="event"?Is(a)===n:!1:"name"in a&&a.name===n);if(s.length===0)return;if(s.length===1)return s[0];let o;for(const a of s){if(!("inputs"in a))continue;if(!r||r.length===0){if(!a.inputs||a.inputs.length===0)return a;continue}if(!a.inputs||a.inputs.length===0||a.inputs.length!==r.length)continue;if(r.every((f,l)=>{const h="inputs"in a&&a.inputs[l];return h?ea(f,h):!1})){if(o&&"inputs"in o&&o.inputs){const f=$f(a.inputs,o.inputs,r);if(f)throw new Zh({abiItem:a,type:f[0]},{abiItem:o,type:f[1]})}o=a}}return o||s[0]}function ea(e,t){const r=typeof e,n=t.type;switch(n){case"address":return Le(e,{strict:!1});case"bool":return r==="boolean";case"function":return r==="string";case"string":return r==="string";default:return n==="tuple"&&"components"in t?Object.values(t.components).every((i,s)=>ea(Object.values(e)[s],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?r==="number"||r==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?r==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(e)&&e.every(i=>ea(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function $f(e,t,r){for(const n in e){const i=e[n],s=t[n];if(i.type==="tuple"&&s.type==="tuple"&&"components"in i&&"components"in s)return $f(i.components,s.components,r[n]);const o=[i.type,s.type];if(o.includes("address")&&o.includes("bytes20")?!0:o.includes("address")&&o.includes("string")?Le(r[n],{strict:!1}):o.includes("address")&&o.includes("bytes")?Le(r[n],{strict:!1}):!1)return o}}const Mc="/docs/contract/encodeEventTopics";function Fa(e){var c;const{abi:t,eventName:r,args:n}=e;let i=t[0];if(r){const f=En({abi:t,name:r});if(!f)throw new Cc(r,{docsPath:Mc});i=f}if(i.type!=="event")throw new Cc(void 0,{docsPath:Mc});const s=kt(i),o=Is(s);let a=[];if(n&&"inputs"in i){const f=(c=i.inputs)==null?void 0:c.filter(h=>"indexed"in h&&h.indexed),l=Array.isArray(n)?n:Object.values(n).length>0?(f==null?void 0:f.map(h=>n[h.name]))??[]:[];l.length>0&&(a=(f==null?void 0:f.map((h,m)=>Array.isArray(l[m])?l[m].map((p,g)=>Hc({param:h,value:l[m][g]})):typeof l[m]<"u"&&l[m]!==null?Hc({param:h,value:l[m]}):null))??[])}return[o,...a]}function Hc({param:e,value:t}){if(e.type==="string"||e.type==="bytes")return vn(Pi(t));if(e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/))throw new i0(e.type);return Cs([e],[t])}function Z0(e,{method:t}){var n,i;const r={};return e.transport.type==="fallback"&&((i=(n=e.transport).onResponse)==null||i.call(n,({method:s,response:o,status:a,transport:c})=>{a==="success"&&t===s&&(r[o]=c.request)})),s=>r[s]||e.request}async function Mf(e,t){const{address:r,abi:n,args:i,eventName:s,fromBlock:o,strict:a,toBlock:c}=t,f=Z0(e,{method:"eth_newFilter"}),l=s?Fa({abi:n,args:i,eventName:s}):void 0,h=await e.request({method:"eth_newFilter",params:[{address:r,fromBlock:typeof o=="bigint"?Q(o):o,toBlock:typeof c=="bigint"?Q(c):c,topics:l}]});return{abi:n,args:i,eventName:s,id:h,request:f(h),strict:!!a,type:"event"}}function Ne(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}const Dc="/docs/contract/encodeFunctionData";function ep(e){const{abi:t,args:r,functionName:n}=e;let i=t[0];if(n){const s=En({abi:t,args:r,name:n});if(!s)throw new Xn(n,{docsPath:Dc});i=s}if(i.type!=="function")throw new Xn(void 0,{docsPath:Dc});return{abi:[i],functionName:Os(kt(i))}}function xn(e){const{args:t}=e,{abi:r,functionName:n}=(()=>{var a;return e.abi.length===1&&((a=e.functionName)!=null&&a.startsWith("0x"))?e:ep(e)})(),i=r[0],s=n,o="inputs"in i&&i.inputs?Cs(i.inputs,t??[]):void 0;return Ct([s,o??"0x"])}const tp={1:"An `assert` condition failed.",17:"Arithmetic operation resulted in underflow or overflow.",18:"Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",33:"Attempted to convert to an invalid type.",34:"Attempted to access a storage byte array that is incorrectly encoded.",49:"Performed `.pop()` on an empty array",50:"Array index is out of bounds.",65:"Allocated too much memory or created an array which is too large.",81:"Attempted to call a zero-initialized variable of internal function type."},Hf={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},rp={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class jc extends ${constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Df extends ${constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class np extends ${constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const ip={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 np({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new Df({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new jc({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 jc({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 $a(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(ip);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function sp(e,t={}){typeof t.size<"u"&&Bt(e,{size:t.size});const r=Ze(e,t);return lt(r,t)}function op(e,t={}){let r=e;if(typeof t.size<"u"&&(Bt(r,{size:t.size}),r=Or(r)),r.length>1||r[0]>1)throw new o0(r);return!!r[0]}function jt(e,t={}){typeof t.size<"u"&&Bt(e,{size:t.size});const r=Ze(e,t);return qt(r,t)}function ap(e,t={}){let r=e;return typeof t.size<"u"&&(Bt(r,{size:t.size}),r=Or(r,{dir:"right"})),new TextDecoder().decode(r)}function Ii(e,t){const r=typeof t=="string"?Vt(t):t,n=$a(r);if(Ie(r)===0&&e.length>0)throw new Ba;if(Ie(t)&&Ie(t)<32)throw new gf({data:typeof t=="string"?t:Ze(t),params:e,size:Ie(t)});let i=0;const s=[];for(let o=0;o<e.length;++o){const a=e[o];n.setPosition(i);const[c,f]=nn(n,a,{staticPosition:0});i+=f,s.push(c)}return s}function nn(e,t,{staticPosition:r}){const n=Na(t.type);if(n){const[i,s]=n;return up(e,{...t,type:s},{length:i,staticPosition:r})}if(t.type==="tuple")return hp(e,t,{staticPosition:r});if(t.type==="address")return cp(e);if(t.type==="bool")return fp(e);if(t.type.startsWith("bytes"))return dp(e,t,{staticPosition:r});if(t.type.startsWith("uint")||t.type.startsWith("int"))return lp(e,t);if(t.type==="string")return pp(e,{staticPosition:r});throw new r0(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const Gc=32,ta=32;function cp(e){const t=e.readBytes(32);return[ki(Ze(Nf(t,-20))),32]}function up(e,t,{length:r,staticPosition:n}){if(!r){const o=jt(e.readBytes(ta)),a=n+o,c=a+Gc;e.setPosition(a);const f=jt(e.readBytes(Gc)),l=Qn(t);let h=0;const m=[];for(let p=0;p<f;++p){e.setPosition(c+(l?p*32:h));const[g,v]=nn(e,t,{staticPosition:c});h+=v,m.push(g)}return e.setPosition(n+32),[m,32]}if(Qn(t)){const o=jt(e.readBytes(ta)),a=n+o,c=[];for(let f=0;f<r;++f){e.setPosition(a+f*32);const[l]=nn(e,t,{staticPosition:a});c.push(l)}return e.setPosition(n+32),[c,32]}let i=0;const s=[];for(let o=0;o<r;++o){const[a,c]=nn(e,t,{staticPosition:n+i});i+=c,s.push(a)}return[s,i]}function fp(e){return[op(e.readBytes(32),{size:32}),32]}function dp(e,t,{staticPosition:r}){const[n,i]=t.type.split("bytes");if(!i){const o=jt(e.readBytes(32));e.setPosition(r+o);const a=jt(e.readBytes(32));if(a===0)return e.setPosition(r+32),["0x",32];const c=e.readBytes(a);return e.setPosition(r+32),[Ze(c),32]}return[Ze(e.readBytes(Number.parseInt(i),32)),32]}function lp(e,t){const r=t.type.startsWith("int"),n=Number.parseInt(t.type.split("int")[1]||"256"),i=e.readBytes(32);return[n>48?sp(i,{signed:r}):jt(i,{signed:r}),32]}function hp(e,t,{staticPosition:r}){const n=t.components.length===0||t.components.some(({name:o})=>!o),i=n?[]:{};let s=0;if(Qn(t)){const o=jt(e.readBytes(ta)),a=r+o;for(let c=0;c<t.components.length;++c){const f=t.components[c];e.setPosition(a+s);const[l,h]=nn(e,f,{staticPosition:a});s+=h,i[n?c:f==null?void 0:f.name]=l}return e.setPosition(r+32),[i,32]}for(let o=0;o<t.components.length;++o){const a=t.components[o],[c,f]=nn(e,a,{staticPosition:r});i[n?o:a==null?void 0:a.name]=c,s+=f}return[i,s]}function pp(e,{staticPosition:t}){const r=jt(e.readBytes(32)),n=t+r;e.setPosition(n);const i=jt(e.readBytes(32));if(i===0)return e.setPosition(t+32),["",32];const s=e.readBytes(i,32),o=ap(Or(s));return e.setPosition(t+32),[o,32]}function Qn(e){var n;const{type:t}=e;if(t==="string"||t==="bytes"||t.endsWith("[]"))return!0;if(t==="tuple")return(n=e.components)==null?void 0:n.some(Qn);const r=Na(e.type);return!!(r&&Qn({...e,type:r[1]}))}function jf(e){const{abi:t,data:r}=e,n=dn(r,0,4);if(n==="0x")throw new Ba;const s=[...t||[],Hf,rp].find(o=>o.type==="error"&&n===Os(kt(o)));if(!s)throw new wf(n,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:s,args:"inputs"in s&&s.inputs&&s.inputs.length>0?Ii(s.inputs,dn(r,4)):void 0,errorName:s.name}}const It=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);function Gf({abiItem:e,args:t,includeFunctionName:r=!0,includeName:n=!1}){if("name"in e&&"inputs"in e&&e.inputs)return`${r?e.name:""}(${e.inputs.map((i,s)=>`${n&&i.name?`${i.name}: `:""}${typeof t[s]=="object"?It(t[s]):t[s]}`).join(", ")})`}const yp={gwei:9,wei:18},mp={ether:-9,wei:9};function zf(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 Ma(e,t="wei"){return zf(e,yp[t])}function rt(e,t="wei"){return zf(e,mp[t])}class bp extends ${constructor({address:t}){super(`State for account "${t}" is set multiple times.`,{name:"AccountStateConflictError"})}}class gp extends ${constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function zc(e){return e.reduce((t,{slot:r,value:n})=>`${t} ${r}: ${n}
|
|
23
23
|
`,"")}function wp(e){return e.reduce((t,{address:r,...n})=>{let i=`${t} ${r}:
|
|
24
24
|
`;return n.nonce&&(i+=` nonce: ${n.nonce}
|
|
25
25
|
`),n.balance&&(i+=` balance: ${n.balance}
|
|
26
26
|
`),n.code&&(i+=` code: ${n.code}
|
|
27
27
|
`),n.state&&(i+=` state:
|
|
28
|
-
`,i+=
|
|
29
|
-
`,i+=
|
|
28
|
+
`,i+=zc(n.state)),n.stateDiff&&(i+=` stateDiff:
|
|
29
|
+
`,i+=zc(n.stateDiff)),i},` State Override:
|
|
30
30
|
`).slice(0,-1)}function Bi(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(`
|
|
31
31
|
`)}class _p extends ${constructor(){super(["Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.","Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."].join(`
|
|
32
|
-
`),{name:"FeeConflictError"})}}class vp extends ${constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class Ep extends ${constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Bi(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 xp extends ${constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}class Ap extends ${constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:l,to:h,value:m}){var g;const p=Bi({chain:i&&`${i==null?void 0:i.name} (id: ${i==null?void 0:i.id})`,from:r==null?void 0:r.address,to:h,value:typeof m<"u"&&`${
|
|
32
|
+
`),{name:"FeeConflictError"})}}class vp extends ${constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class Ep extends ${constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Bi(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 xp extends ${constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}class Ap extends ${constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:l,to:h,value:m}){var g;const p=Bi({chain:i&&`${i==null?void 0:i.name} (id: ${i==null?void 0:i.id})`,from:r==null?void 0:r.address,to:h,value:typeof m<"u"&&`${Ma(m)} ${((g=i==null?void 0:i.nativeCurrency)==null?void 0:g.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${rt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${rt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${rt(f)} gwei`,nonce:l});super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Request Arguments:",p].filter(Boolean),name:"TransactionExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}const Sp=e=>e,Ha=e=>e;class Pp extends ${constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:l,to:h,value:m,stateOverride:p}){var x;const g=r?Ne(r):void 0;let v=Bi({from:g==null?void 0:g.address,to:h,value:typeof m<"u"&&`${Ma(m)} ${((x=i==null?void 0:i.nativeCurrency)==null?void 0:x.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${rt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${rt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${rt(f)} gwei`,nonce:l});p&&(v+=`
|
|
33
33
|
${wp(p)}`),super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Raw Call Arguments:",v].filter(Boolean),name:"CallExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class Tp extends ${constructor(t,{abi:r,args:n,contractAddress:i,docsPath:s,functionName:o,sender:a}){const c=En({abi:r,args:n,name:o}),f=c?Gf({abiItem:c,args:n,includeFunctionName:!1,includeName:!1}):void 0,l=c?kt(c,{includeName:!0}):void 0,h=Bi({address:i&&Sp(i),function:l,args:f&&f!=="()"&&`${[...Array((o==null?void 0:o.length)??0).keys()].map(()=>" ").join("")}${f}`,sender:a});super(t.shortMessage||`An unknown error occurred while executing the contract function "${o}".`,{cause:t,docsPath:s,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],h&&"Contract Call:",h].filter(Boolean),name:"ContractFunctionExecutionError"}),Object.defineProperty(this,"abi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"args",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"contractAddress",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"formattedArgs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"functionName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sender",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abi=r,this.args=n,this.cause=t,this.contractAddress=i,this.functionName=o,this.sender=a}}class kp extends ${constructor({abi:t,data:r,functionName:n,message:i}){let s,o,a,c;if(r&&r!=="0x")try{o=jf({abi:t,data:r});const{abiItem:l,errorName:h,args:m}=o;if(h==="Error")c=m[0];else if(h==="Panic"){const[p]=m;c=tp[p]}else{const p=l?kt(l,{includeName:!0}):void 0,g=l&&m?Gf({abiItem:l,args:m,includeFunctionName:!1,includeName:!1}):void 0;a=[p?`Error: ${p}`:"",g&&g!=="()"?` ${[...Array((h==null?void 0:h.length)??0).keys()].map(()=>" ").join("")}${g}`:""]}}catch(l){s=l}else i&&(c=i);let f;s instanceof wf&&(f=s.signature,a=[`Unable to decode signature "${f}" as it was not found on the provided ABI.`,"Make sure you are using the correct ABI and that the error exists on it.",`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${f}.`]),super(c&&c!=="execution reverted"||f?[`The contract function "${n}" reverted with the following ${f?"signature":"reason"}:`,c||f].join(`
|
|
34
|
-
`):`The contract function "${n}" reverted.`,{cause:s,metaMessages:a,name:"ContractFunctionRevertedError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"reason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=o,this.raw=r,this.reason=c,this.signature=f}}class Ip extends ${constructor({functionName:t}){super(`The contract function "${t}" returned no data ("0x").`,{metaMessages:["This could be due to any of the following:",` - The contract does not have the function "${t}",`," - The parameters passed to the contract function may be invalid, or"," - The address is not a contract."],name:"ContractFunctionZeroDataError"})}}class Bp extends ${constructor({factory:t}){super(`Deployment for counterfactual contract call failed${t?` for factory "${t}".`:""}`,{metaMessages:["Please ensure:","- The `factory` is a valid contract deployment factory (ie. Create2 Factory, ERC-4337 Factory, etc).","- The `factoryData` is a valid encoded function call for contract deployment function on the factory."],name:"CounterfactualDeploymentFailedError"})}}class qf extends ${constructor({data:t,message:r}){super(r||"",{name:"RawContractError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t}}class
|
|
34
|
+
`):`The contract function "${n}" reverted.`,{cause:s,metaMessages:a,name:"ContractFunctionRevertedError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"reason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=o,this.raw=r,this.reason=c,this.signature=f}}class Ip extends ${constructor({functionName:t}){super(`The contract function "${t}" returned no data ("0x").`,{metaMessages:["This could be due to any of the following:",` - The contract does not have the function "${t}",`," - The parameters passed to the contract function may be invalid, or"," - The address is not a contract."],name:"ContractFunctionZeroDataError"})}}class Bp extends ${constructor({factory:t}){super(`Deployment for counterfactual contract call failed${t?` for factory "${t}".`:""}`,{metaMessages:["Please ensure:","- The `factory` is a valid contract deployment factory (ie. Create2 Factory, ERC-4337 Factory, etc).","- The `factoryData` is a valid encoded function call for contract deployment function on the factory."],name:"CounterfactualDeploymentFailedError"})}}class qf extends ${constructor({data:t,message:r}){super(r||"",{name:"RawContractError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t}}class Da extends ${constructor({body:t,cause:r,details:n,headers:i,status:s,url:o}){super("HTTP request failed.",{cause:r,details:n,metaMessages:[s&&`Status: ${s}`,`URL: ${Ha(o)}`,t&&`Request body: ${It(t)}`].filter(Boolean),name:"HttpRequestError"}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"url",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.body=t,this.headers=i,this.status=s,this.url=o}}class Vf extends ${constructor({body:t,error:r,url:n}){super("RPC Request failed.",{cause:r,details:r.message,metaMessages:[`URL: ${Ha(n)}`,`Request body: ${It(t)}`],name:"RpcRequestError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.code=r.code,this.data=r.data}}const Cp=-1;class nt extends ${constructor(t,{code:r,docsPath:n,metaMessages:i,name:s,shortMessage:o}){super(o,{cause:t,docsPath:n,metaMessages:i||(t==null?void 0:t.metaMessages),name:s||"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=s||t.name,this.code=t instanceof Vf?t.code:r??Cp}}class at extends nt{constructor(t,r){super(t,r),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=r.data}}class Zn extends nt{constructor(t){super(t,{code:Zn.code,name:"ParseRpcError",shortMessage:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."})}}Object.defineProperty(Zn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32700});class ei extends nt{constructor(t){super(t,{code:ei.code,name:"InvalidRequestRpcError",shortMessage:"JSON is not a valid request object."})}}Object.defineProperty(ei,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32600});class ti extends nt{constructor(t,{method:r}={}){super(t,{code:ti.code,name:"MethodNotFoundRpcError",shortMessage:`The method${r?` "${r}"`:""} does not exist / is not available.`})}}Object.defineProperty(ti,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32601});class ri extends nt{constructor(t){super(t,{code:ri.code,name:"InvalidParamsRpcError",shortMessage:["Invalid parameters were provided to the RPC method.","Double check you have provided the correct parameters."].join(`
|
|
35
35
|
`)})}}Object.defineProperty(ri,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32602});class Ur extends nt{constructor(t){super(t,{code:Ur.code,name:"InternalRpcError",shortMessage:"An internal error was received."})}}Object.defineProperty(Ur,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32603});class ln extends nt{constructor(t){super(t,{code:ln.code,name:"InvalidInputRpcError",shortMessage:["Missing or invalid parameters.","Double check you have provided the correct parameters."].join(`
|
|
36
|
-
`)})}}Object.defineProperty(ln,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32e3});class ni extends nt{constructor(t){super(t,{code:ni.code,name:"ResourceNotFoundRpcError",shortMessage:"Requested resource not found."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceNotFoundRpcError"})}}Object.defineProperty(ni,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32001});class ii extends nt{constructor(t){super(t,{code:ii.code,name:"ResourceUnavailableRpcError",shortMessage:"Requested resource not available."})}}Object.defineProperty(ii,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32002});class si extends nt{constructor(t){super(t,{code:si.code,name:"TransactionRejectedRpcError",shortMessage:"Transaction creation failed."})}}Object.defineProperty(si,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32003});class Tr extends nt{constructor(t,{method:r}={}){super(t,{code:Tr.code,name:"MethodNotSupportedRpcError",shortMessage:`Method${r?` "${r}"`:""} is not supported.`})}}Object.defineProperty(Tr,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32004});class hn extends nt{constructor(t){super(t,{code:hn.code,name:"LimitExceededRpcError",shortMessage:"Request exceeds defined limit."})}}Object.defineProperty(hn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32005});class oi extends nt{constructor(t){super(t,{code:oi.code,name:"JsonRpcVersionUnsupportedError",shortMessage:"Version of JSON-RPC protocol is not supported."})}}Object.defineProperty(oi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32006});class sn extends at{constructor(t){super(t,{code:sn.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(sn,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class ai extends at{constructor(t){super(t,{code:ai.code,name:"UnauthorizedProviderError",shortMessage:"The requested method and/or account has not been authorized by the user."})}}Object.defineProperty(ai,"code",{enumerable:!0,configurable:!0,writable:!0,value:4100});class ci extends at{constructor(t,{method:r}={}){super(t,{code:ci.code,name:"UnsupportedProviderMethodError",shortMessage:`The Provider does not support the requested method${r?` " ${r}"`:""}.`})}}Object.defineProperty(ci,"code",{enumerable:!0,configurable:!0,writable:!0,value:4200});class ui extends at{constructor(t){super(t,{code:ui.code,name:"ProviderDisconnectedError",shortMessage:"The Provider is disconnected from all chains."})}}Object.defineProperty(ui,"code",{enumerable:!0,configurable:!0,writable:!0,value:4900});class fi extends at{constructor(t){super(t,{code:fi.code,name:"ChainDisconnectedError",shortMessage:"The Provider is not connected to the requested chain."})}}Object.defineProperty(fi,"code",{enumerable:!0,configurable:!0,writable:!0,value:4901});class di extends at{constructor(t){super(t,{code:di.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(di,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class li extends at{constructor(t){super(t,{code:li.code,name:"UnsupportedNonOptionalCapabilityError",shortMessage:"This Wallet does not support a capability that was not marked as optional."})}}Object.defineProperty(li,"code",{enumerable:!0,configurable:!0,writable:!0,value:5700});class hi extends at{constructor(t){super(t,{code:hi.code,name:"UnsupportedChainIdError",shortMessage:"This Wallet does not support the requested chain ID."})}}Object.defineProperty(hi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5710});class pi extends at{constructor(t){super(t,{code:pi.code,name:"DuplicateIdError",shortMessage:"There is already a bundle submitted with this ID."})}}Object.defineProperty(pi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5720});class yi extends at{constructor(t){super(t,{code:yi.code,name:"UnknownBundleIdError",shortMessage:"This bundle id is unknown / has not been submitted"})}}Object.defineProperty(yi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5730});class mi extends at{constructor(t){super(t,{code:mi.code,name:"BundleTooLargeError",shortMessage:"The call bundle is too large for the Wallet to process."})}}Object.defineProperty(mi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5740});class bi extends at{constructor(t){super(t,{code:bi.code,name:"AtomicReadyWalletRejectedUpgradeError",shortMessage:"The Wallet can support atomicity after an upgrade, but the user rejected the upgrade."})}}Object.defineProperty(bi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5750});class gi extends at{constructor(t){super(t,{code:gi.code,name:"AtomicityNotSupportedError",shortMessage:"The wallet does not support atomic execution but the request requires it."})}}Object.defineProperty(gi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5760});class Op extends nt{constructor(t){super(t,{name:"UnknownRpcError",shortMessage:"An unknown RPC error occurred."})}}const Rp=3;function Rs(e,{abi:t,address:r,args:n,docsPath:i,functionName:s,sender:o}){const a=e instanceof qf?e:e instanceof $?e.walk(g=>"data"in g)||e.walk():{},{code:c,data:f,details:l,message:h,shortMessage:m}=a,p=e instanceof ka?new Ip({functionName:s}):[Rp,Ur.code].includes(c)&&(f||l||h||m)?new kp({abi:t,data:typeof f=="object"?f.data:f,functionName:s,message:a instanceof Vf?l:m??h}):e;return new Tp(p,{abi:t,args:n,contractAddress:r,docsPath:i,functionName:s,sender:o})}function Up(e){const t=vn(`0x${e.substring(4)}`).substring(26);return ki(`0x${t}`)}async function Lp({hash:e,signature:t}){const r=zt(e)?e:J(e),{secp256k1:n}=await Promise.resolve().then(()=>require("./secp256k1-B5eOuBnI.cjs"));return`0x${(()=>{if(typeof t=="object"&&"r"in t&&"s"in t){const{r:f,s:l,v:h,yParity:m}=t,p=Number(m??h),g=Gc(p);return new n.Signature(lt(f),lt(l)).addRecoveryBit(g)}const o=zt(t)?t:J(t),a=qt(`0x${o.slice(130)}`),c=Gc(a);return n.Signature.fromCompact(o.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function Gc(e){if(e===0||e===1)return e;if(e===27)return 0;if(e===28)return 1;throw new Error("Invalid yParityOrV value")}async function Np({hash:e,signature:t}){return Up(await Lp({hash:e,signature:t}))}function pr(e,t="hex"){const r=Wf(e),n=Na(new Uint8Array(r.length));return r.encode(n),t==="hex"?Ze(n.bytes):n.bytes}function Wf(e){return Array.isArray(e)?Fp(e.map(t=>Wf(t))):$p(e)}function Fp(e){const t=e.reduce((i,s)=>i+s.length,0),r=Kf(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 $p(e){const t=typeof e=="string"?Vt(e):e,r=Kf(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 Kf(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 $("Length is too large.")}function Mp(e){const{chainId:t,nonce:r,to:n}=e,i=e.contractAddress??e.address,s=vn(Ct(["0x05",pr([t?Q(t):"0x",i,r?Q(r):"0x"])]));return n==="bytes"?Vt(s):s}async function Yf(e){const{authorization:t,signature:r}=e;return Np({hash:Mp(t),signature:r??t})}class Hp extends ${constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:l,to:h,value:m}){var g;const p=Bi({from:r==null?void 0:r.address,to:h,value:typeof m<"u"&&`${Fa(m)} ${((g=i==null?void 0:i.nativeCurrency)==null?void 0:g.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${rt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${rt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${rt(f)} gwei`,nonce:l});super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Estimate Gas Arguments:",p].filter(Boolean),name:"EstimateGasExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class tn extends ${constructor({cause:t,message:r}={}){var i;const n=(i=r==null?void 0:r.replace("execution reverted: ",""))==null?void 0:i.replace("execution reverted","");super(`Execution reverted ${n?`with reason: ${n}`:"for an unknown reason"}.`,{cause:t,name:"ExecutionRevertedError"})}}Object.defineProperty(tn,"code",{enumerable:!0,configurable:!0,writable:!0,value:3});Object.defineProperty(tn,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class Lr extends ${constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${rt(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Lr,"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 ea extends ${constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${rt(r)}`:""} gwei) cannot be lower than the block base fee.`,{cause:t,name:"FeeCapTooLowError"})}}Object.defineProperty(ea,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/});class ta extends ${constructor({cause:t,nonce:r}={}){super(`Nonce provided for the transaction ${r?`(${r}) `:""}is higher than the next one expected.`,{cause:t,name:"NonceTooHighError"})}}Object.defineProperty(ta,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class ra extends ${constructor({cause:t,nonce:r}={}){super([`Nonce provided for the transaction ${r?`(${r}) `:""}is lower than the current nonce of the account.`,"Try increasing the nonce or find the latest nonce with `getTransactionCount`."].join(`
|
|
37
|
-
`),{cause:t,name:"NonceTooLowError"})}}Object.defineProperty(
|
|
38
|
-
`),{cause:t,metaMessages:["This error could arise when the account does not have enough funds to:"," - pay for the total gas fee,"," - pay for the value to send."," ","The cost of the transaction is calculated as `gas * gas fee + value`, where:"," - `gas` is the amount of gas needed for transaction to execute,"," - `gas fee` is the gas fee,"," - `value` is the amount of ether to send to the recipient."],name:"InsufficientFundsError"})}}Object.defineProperty(
|
|
39
|
-
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(wi,"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 Us extends ${constructor({cause:t}){super(`An error occurred while executing: ${t==null?void 0:t.shortMessage}`,{cause:t,name:"UnknownNodeError"})}}function Ha(e,t){const r=(e.details||"").toLowerCase(),n=e instanceof $?e.walk(i=>(i==null?void 0:i.code)===tn.code):e;return n instanceof $?new tn({cause:e,message:n.details}):tn.nodeMessage.test(r)?new tn({cause:e,message:e.details}):Lr.nodeMessage.test(r)?new Lr({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):ea.nodeMessage.test(r)?new ea({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):ta.nodeMessage.test(r)?new ta({cause:e,nonce:t==null?void 0:t.nonce}):ra.nodeMessage.test(r)?new ra({cause:e,nonce:t==null?void 0:t.nonce}):na.nodeMessage.test(r)?new na({cause:e,nonce:t==null?void 0:t.nonce}):ia.nodeMessage.test(r)?new ia({cause:e}):sa.nodeMessage.test(r)?new sa({cause:e,gas:t==null?void 0:t.gas}):oa.nodeMessage.test(r)?new oa({cause:e,gas:t==null?void 0:t.gas}):aa.nodeMessage.test(r)?new aa({cause:e}):wi.nodeMessage.test(r)?new wi({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas,maxPriorityFeePerGas:t==null?void 0:t.maxPriorityFeePerGas}):new Us({cause:e})}function Dp(e,{docsPath:t,...r}){const n=(()=>{const i=Ha(e,r);return i instanceof Us?e:i})();return new Hp(n,{docsPath:t,...r})}function Da(e,{format:t}){if(!t)return{};const r={};function n(s){const o=Object.keys(s);for(const a of o)a in e&&(r[a]=e[a]),s[a]&&typeof s[a]=="object"&&!Array.isArray(s[a])&&n(s[a])}const i=t(e||{});return n(i),r}function ja(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 jp={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function Ls(e){const t={};return typeof e.authorizationList<"u"&&(t.authorizationList=Gp(e.authorizationList)),typeof e.accessList<"u"&&(t.accessList=e.accessList),typeof e.blobVersionedHashes<"u"&&(t.blobVersionedHashes=e.blobVersionedHashes),typeof e.blobs<"u"&&(typeof e.blobs[0]!="string"?t.blobs=e.blobs.map(r=>Ze(r)):t.blobs=e.blobs),typeof e.data<"u"&&(t.data=e.data),typeof e.from<"u"&&(t.from=e.from),typeof e.gas<"u"&&(t.gas=Q(e.gas)),typeof e.gasPrice<"u"&&(t.gasPrice=Q(e.gasPrice)),typeof e.maxFeePerBlobGas<"u"&&(t.maxFeePerBlobGas=Q(e.maxFeePerBlobGas)),typeof e.maxFeePerGas<"u"&&(t.maxFeePerGas=Q(e.maxFeePerGas)),typeof e.maxPriorityFeePerGas<"u"&&(t.maxPriorityFeePerGas=Q(e.maxPriorityFeePerGas)),typeof e.nonce<"u"&&(t.nonce=Q(e.nonce)),typeof e.to<"u"&&(t.to=e.to),typeof e.type<"u"&&(t.type=jp[e.type]),typeof e.value<"u"&&(t.value=Q(e.value)),t}function Gp(e){return e.map(t=>({address:t.address,r:t.r?Q(BigInt(t.r)):t.r,s:t.s?Q(BigInt(t.s)):t.s,chainId:Q(t.chainId),nonce:Q(t.nonce),...typeof t.yParity<"u"?{yParity:Q(t.yParity)}:{},...typeof t.v<"u"&&typeof t.yParity>"u"?{v:Q(t.v)}:{}}))}function zc(e){if(!(!e||e.length===0))return e.reduce((t,{slot:r,value:n})=>{if(r.length!==66)throw new Bc({size:r.length,targetSize:66,type:"hex"});if(n.length!==66)throw new Bc({size:n.length,targetSize:66,type:"hex"});return t[r]=n,t},{})}function zp(e){const{balance:t,nonce:r,state:n,stateDiff:i,code:s}=e,o={};if(s!==void 0&&(o.code=s),t!==void 0&&(o.balance=Q(t)),r!==void 0&&(o.nonce=Q(r)),n!==void 0&&(o.state=zc(n)),i!==void 0){if(o.state)throw new gp;o.stateDiff=zc(i)}return o}function Xf(e){if(!e)return;const t={};for(const{address:r,...n}of e){if(!Le(r,{strict:!1}))throw new et({address:r});if(t[r])throw new bp({address:r});t[r]=zp(n)}return t}const Ns=2n**256n-1n;function Ci(e){const{account:t,gasPrice:r,maxFeePerGas:n,maxPriorityFeePerGas:i,to:s}=e,o=t?Ne(t):void 0;if(o&&!Le(o.address))throw new et({address:o.address});if(s&&!Le(s))throw new et({address:s});if(typeof r<"u"&&(typeof n<"u"||typeof i<"u"))throw new _p;if(n&&n>Ns)throw new Lr({maxFeePerGas:n});if(i&&n&&i>n)throw new wi({maxFeePerGas:n,maxPriorityFeePerGas:i})}class qp extends ${constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class Ga extends ${constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class Vp extends ${constructor({maxPriorityFeePerGas:t}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${rt(t)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class Wp extends ${constructor({blockHash:t,blockNumber:r}){let n="Block";t&&(n=`Block at hash "${t}"`),r&&(n=`Block at number "${r}"`),super(`${n} could not be found.`,{name:"BlockNotFoundError"})}}const Jf={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function za(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?qt(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?qt(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=Yp(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 Kp=ja("transaction",za);function Yp(e){return e.map(t=>({address:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function Qf(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:za(r));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const Xp=ja("block",Qf);async function bs(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:i}={}){var l,h,m;const s=n??"latest",o=i??!1,a=r!==void 0?Q(r):void 0;let c=null;if(t?c=await e.request({method:"eth_getBlockByHash",params:[t,o]},{dedupe:!0}):c=await e.request({method:"eth_getBlockByNumber",params:[a||s,o]},{dedupe:!!a}),!c)throw new Wp({blockHash:t,blockNumber:r});return(((m=(h=(l=e.chain)==null?void 0:l.formatters)==null?void 0:h.block)==null?void 0:m.format)||Qf)(c)}async function Zf(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function Jp(e,t){var s,o;const{block:r,chain:n=e.chain,request:i}=t||{};try{const a=((s=n==null?void 0:n.fees)==null?void 0:s.maxPriorityFeePerGas)??((o=n==null?void 0:n.fees)==null?void 0:o.defaultPriorityFee);if(typeof a=="function"){const f=r||await oe(e,bs,"getBlock")({}),l=await a({block:f,client:e,request:i});if(l===null)throw new Error;return l}if(typeof a<"u")return a;const c=await e.request({method:"eth_maxPriorityFeePerGas"});return lt(c)}catch{const[a,c]=await Promise.all([r?Promise.resolve(r):oe(e,bs,"getBlock")({}),oe(e,Zf,"getGasPrice")({})]);if(typeof a.baseFeePerGas!="bigint")throw new Ga;const f=c-a.baseFeePerGas;return f<0n?0n:f}}async function qc(e,t){var m,p;const{block:r,chain:n=e.chain,request:i,type:s="eip1559"}=t||{},o=await(async()=>{var g,v;return typeof((g=n==null?void 0:n.fees)==null?void 0:g.baseFeeMultiplier)=="function"?n.fees.baseFeeMultiplier({block:r,client:e,request:i}):((v=n==null?void 0:n.fees)==null?void 0:v.baseFeeMultiplier)??1.2})();if(o<1)throw new qp;const c=10**(((m=o.toString().split(".")[1])==null?void 0:m.length)??0),f=g=>g*BigInt(Math.ceil(o*c))/BigInt(c),l=r||await oe(e,bs,"getBlock")({});if(typeof((p=n==null?void 0:n.fees)==null?void 0:p.estimateFeesPerGas)=="function"){const g=await n.fees.estimateFeesPerGas({block:r,client:e,multiply:f,request:i,type:s});if(g!==null)return g}if(s==="eip1559"){if(typeof l.baseFeePerGas!="bigint")throw new Ga;const g=typeof(i==null?void 0:i.maxPriorityFeePerGas)=="bigint"?i.maxPriorityFeePerGas:await Jp(e,{block:l,chain:n,request:i}),v=f(l.baseFeePerGas);return{maxFeePerGas:(i==null?void 0:i.maxFeePerGas)??v+g,maxPriorityFeePerGas:g}}return{gasPrice:(i==null?void 0:i.gasPrice)??f(await oe(e,Zf,"getGasPrice")({}))}}async function ed(e,{address:t,blockTag:r="latest",blockNumber:n}){const i=await e.request({method:"eth_getTransactionCount",params:[t,n?Q(n):r]},{dedupe:!!n});return qt(i)}function qa(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=>Vt(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>Ze(s))}function Va(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=>Vt(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>Vt(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=>Ze(o))}function Qp(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,f=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+f,a,n)}function Zp(e,t,r){return e&t^~e&r}function ey(e,t,r){return e&t^e&r^t&r}let ty=class extends Ba{constructor(t,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=fo(this.buffer)}update(t){Jn(this);const{view:r,buffer:n,blockLen:i}=this;t=ks(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=fo(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),kf(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 h=o;h<i;h++)r[h]=0;Qp(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=fo(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],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 ry=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]),er=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),tr=new Uint32Array(64);let ny=class extends ty{constructor(t=32){super(64,t,8,!1),this.A=er[0]|0,this.B=er[1]|0,this.C=er[2]|0,this.D=er[3]|0,this.E=er[4]|0,this.F=er[5]|0,this.G=er[6]|0,this.H=er[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 h=0;h<16;h++,r+=4)tr[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const m=tr[h-15],p=tr[h-2],g=gt(m,7)^gt(m,18)^m>>>3,v=gt(p,17)^gt(p,19)^p>>>10;tr[h]=v+tr[h-7]+g+tr[h-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const m=gt(a,6)^gt(a,11)^gt(a,25),p=l+m+Zp(a,c,f)+ry[h]+tr[h]|0,v=(gt(n,2)^gt(n,13)^gt(n,22))+ey(n,i,s)|0;l=f,f=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+v|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,f=f+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,f,l)}roundClean(){tr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const td=If(()=>new ny);function Gn(e,t){const r=t||"hex",n=td(zt(e,{strict:!1})?Pi(e):e);return r==="bytes"?n:J(n)}function iy(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=Gn(t,"bytes");return i.set([r],0),n==="bytes"?i:Ze(i)}function rd(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const s of t)i.push(iy({commitment:s,to:n,version:r}));return i}const Vc=6,nd=32,Wa=4096,id=nd*Wa,Wc=id*Vc-1-1*Wa*Vc,sd=1;class sy extends ${constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class od extends ${constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class oy extends ${constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class ay extends ${constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${sd}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function cy(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?Vt(e.data):e.data,n=Ie(r);if(!n)throw new od;if(n>Wc)throw new sy({maxSize:Wc,size:n});const i=[];let s=!0,o=0;for(;s;){const a=Na(new Uint8Array(id));let c=0;for(;c<Wa;){const f=r.slice(o,o+(nd-1));if(a.pushByte(0),a.pushBytes(f),f.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=>Ze(a.bytes))}function ad(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??cy({data:t,to:n}),s=e.commitments??qa({blobs:i,kzg:r,to:n}),o=e.proofs??Va({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 cd(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 Ep({transaction:e})}async function Oi(e){const t=await e.request({method:"eth_chainId"},{dedupe:!0});return qt(t)}const ud=["blobVersionedHashes","chainId","fees","gas","nonce","type"],Kc=new Map;async function Ka(e,t){const{account:r=e.account,blobs:n,chain:i,gas:s,kzg:o,nonce:a,nonceManager:c,parameters:f=ud,type:l}=t,h=r&&Ne(r),m={...t,...h?{from:h==null?void 0:h.address}:{}};let p;async function g(){return p||(p=await oe(e,bs,"getBlock")({blockTag:"latest"}),p)}let v;async function x(){return v||(i?i.id:typeof t.chainId<"u"?t.chainId:(v=await oe(e,Oi,"getChainId")({}),v))}if(f.includes("nonce")&&typeof a>"u"&&h)if(c){const I=await x();m.nonce=await c.consume({address:h.address,chainId:I,client:e})}else m.nonce=await oe(e,ed,"getTransactionCount")({address:h.address,blockTag:"pending"});if((f.includes("blobVersionedHashes")||f.includes("sidecars"))&&n&&o){const I=qa({blobs:n,kzg:o});if(f.includes("blobVersionedHashes")){const k=rd({commitments:I,to:"hex"});m.blobVersionedHashes=k}if(f.includes("sidecars")){const k=Va({blobs:n,commitments:I,kzg:o}),A=ad({blobs:n,commitments:I,proofs:k,to:"hex"});m.sidecars=A}}if(f.includes("chainId")&&(m.chainId=await x()),(f.includes("fees")||f.includes("type"))&&typeof l>"u")try{m.type=cd(m)}catch{let I=Kc.get(e.uid);if(typeof I>"u"){const k=await g();I=typeof(k==null?void 0:k.baseFeePerGas)=="bigint",Kc.set(e.uid,I)}m.type=I?"eip1559":"legacy"}if(f.includes("fees"))if(m.type!=="legacy"&&m.type!=="eip2930"){if(typeof m.maxFeePerGas>"u"||typeof m.maxPriorityFeePerGas>"u"){const I=await g(),{maxFeePerGas:k,maxPriorityFeePerGas:A}=await qc(e,{block:I,chain:i,request:m});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas<A)throw new Vp({maxPriorityFeePerGas:A});m.maxPriorityFeePerGas=A,m.maxFeePerGas=k}}else{if(typeof t.maxFeePerGas<"u"||typeof t.maxPriorityFeePerGas<"u")throw new Ga;if(typeof t.gasPrice>"u"){const I=await g(),{gasPrice:k}=await qc(e,{block:I,chain:i,request:m,type:"legacy"});m.gasPrice=k}}return f.includes("gas")&&typeof s>"u"&&(m.gas=await oe(e,fd,"estimateGas")({...m,account:h&&{address:h.address,type:"json-rpc"}})),Ci(m),delete m.parameters,m}async function uy(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=r?Q(r):void 0,s=await e.request({method:"eth_getBalance",params:[t,i||n]});return BigInt(s)}async function fd(e,t){var i,s,o;const{account:r=e.account}=t,n=r?Ne(r):void 0;try{let V=function(ne){const{block:he,request:_e,rpcStateOverride:Te}=ne;return e.request({method:"eth_estimateGas",params:Te?[_e,he??"latest",Te]:he?[_e,he]:[_e]})};const{accessList:a,authorizationList:c,blobs:f,blobVersionedHashes:l,blockNumber:h,blockTag:m,data:p,gas:g,gasPrice:v,maxFeePerBlobGas:x,maxFeePerGas:I,maxPriorityFeePerGas:k,nonce:A,value:E,stateOverride:T,...S}=await Ka(e,{...t,parameters:(n==null?void 0:n.type)==="local"?void 0:["blobVersionedHashes"]}),M=(h?Q(h):void 0)||m,B=Xf(T),W=await(async()=>{if(S.to)return S.to;if(c&&c.length>0)return await Yf({authorization:c[0]}).catch(()=>{throw new $("`to` is required. Could not infer from `authorizationList`")})})();Ci(t);const U=(o=(s=(i=e.chain)==null?void 0:i.formatters)==null?void 0:s.transactionRequest)==null?void 0:o.format,j=(U||Ls)({...Da(S,{format:U}),from:n==null?void 0:n.address,accessList:a,authorizationList:c,blobs:f,blobVersionedHashes:l,data:p,gas:g,gasPrice:v,maxFeePerBlobGas:x,maxFeePerGas:I,maxPriorityFeePerGas:k,nonce:A,to:W,value:E});let X=BigInt(await V({block:M,request:j,rpcStateOverride:B}));if(c){const ne=await uy(e,{address:j.from}),he=await Promise.all(c.map(async _e=>{const{address:Te}=_e,We=await V({block:M,request:{authorizationList:void 0,data:p,from:n==null?void 0:n.address,to:Te,value:Q(ne)},rpcStateOverride:B}).catch(()=>100000n);return 2n*BigInt(We)}));X+=he.reduce((_e,Te)=>_e+Te,0n)}return X}catch(a){throw Dp(a,{...t,account:n,chain:e.chain})}}async function fy(e,t){const{abi:r,address:n,args:i,functionName:s,dataSuffix:o,...a}=t,c=xn({abi:r,args:i,functionName:s});try{return await oe(e,fd,"estimateGas")({data:`${c}${o?o.replace("0x",""):""}`,to:n,...a})}catch(f){const l=a.account?Ne(a.account):void 0;throw Rs(f,{abi:r,address:n,args:i,docsPath:"/docs/contract/estimateContractGas",functionName:s,sender:l==null?void 0:l.address})}}function Ya(e,t){if(!Le(e,{strict:!1}))throw new et({address:e});if(!Le(t,{strict:!1}))throw new et({address:t});return e.toLowerCase()===t.toLowerCase()}const Yc="/docs/contract/decodeEventLog";function dd(e){const{abi:t,data:r,strict:n,topics:i}=e,s=n??!0,[o,...a]=i;if(!o)throw new Jh({docsPath:Yc});const c=t.length===1?t[0]:t.find(v=>v.type==="event"&&o===Is(kt(v)));if(!(c&&"name"in c)||c.type!=="event")throw new _f(o,{docsPath:Yc});const{name:f,inputs:l}=c,h=l==null?void 0:l.some(v=>!("name"in v&&v.name));let m=h?[]:{};const p=l.filter(v=>"indexed"in v&&v.indexed);for(let v=0;v<p.length;v++){const x=p[v],I=a[v];if(!I)throw new Ia({abiItem:c,param:x});m[h?v:x.name||v]=dy({param:x,value:I})}const g=l.filter(v=>!("indexed"in v&&v.indexed));if(g.length>0){if(r&&r!=="0x")try{const v=Ii(g,r);if(v)if(h)m=[...m,...v];else for(let x=0;x<g.length;x++)m[g[x].name]=v[x]}catch(v){if(s)throw v instanceof gf||v instanceof Df?new ys({abiItem:c,data:r,params:g,size:Ie(r)}):v}else if(s)throw new ys({abiItem:c,data:"0x",params:g,size:0})}return{eventName:f,args:Object.values(m).length>0?m:void 0}}function dy({param:e,value:t}){return e.type==="string"||e.type==="bytes"||e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/)?t:(Ii([e],t)||[])[0]}function ld(e){const{abi:t,args:r,logs:n,strict:i=!0}=e,s=(()=>{if(e.eventName)return Array.isArray(e.eventName)?e.eventName:[e.eventName]})();return n.map(o=>{var a;try{const c=t.find(l=>l.type==="event"&&o.topics[0]===Is(l));if(!c)return null;const f=dd({...o,abi:[c],strict:i});return s&&!s.includes(f.eventName)||!ly({args:f.args,inputs:c.inputs,matchArgs:r})?null:{...f,...o}}catch(c){let f,l;if(c instanceof _f)return null;if(c instanceof ys||c instanceof Ia){if(i)return null;f=c.abiItem.name,l=(a=c.abiItem.inputs)==null?void 0:a.some(h=>!("name"in h&&h.name))}return{...o,args:l?[]:{},eventName:f}}}).filter(Boolean)}function ly(e){const{args:t,inputs:r,matchArgs:n}=e;if(!n)return!0;if(!t)return!1;function i(s,o,a){try{return s.type==="address"?Ya(o,a):s.type==="string"||s.type==="bytes"?vn(Pi(o))===a:o===a}catch{return!1}}return Array.isArray(t)&&Array.isArray(n)?n.every((s,o)=>{if(s==null)return!0;const a=r[o];return a?(Array.isArray(s)?s:[s]).some(f=>i(a,f,t[o])):!1}):typeof t=="object"&&!Array.isArray(t)&&typeof n=="object"&&!Array.isArray(n)?Object.entries(n).every(([s,o])=>{if(o==null)return!0;const a=r.find(f=>f.name===s);return a?(Array.isArray(o)?o:[o]).some(f=>i(a,f,t[s])):!1}):!1}function _i(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}:{}}}async function hy(e,{address:t,blockHash:r,fromBlock:n,toBlock:i,event:s,events:o,args:a,strict:c}={}){const f=c??!1,l=o??(s?[s]:void 0);let h=[];l&&(h=[l.flatMap(v=>La({abi:[v],eventName:v.name,args:o?void 0:a}))],s&&(h=h[0]));let m;r?m=await e.request({method:"eth_getLogs",params:[{address:t,topics:h,blockHash:r}]}):m=await e.request({method:"eth_getLogs",params:[{address:t,topics:h,fromBlock:typeof n=="bigint"?Q(n):n,toBlock:typeof i=="bigint"?Q(i):i}]});const p=m.map(g=>_i(g));return l?ld({abi:l,args:a,logs:p,strict:f}):p}async function hd(e,t){const{abi:r,address:n,args:i,blockHash:s,eventName:o,fromBlock:a,toBlock:c,strict:f}=t,l=o?En({abi:r,name:o}):void 0,h=l?void 0:r.filter(m=>m.type==="event");return oe(e,hy,"getLogs")({address:n,args:i,blockHash:s,event:l,events:h,fromBlock:a,toBlock:c,strict:f})}const po="/docs/contract/decodeFunctionResult";function Xa(e){const{abi:t,args:r,functionName:n,data:i}=e;let s=t[0];if(n){const a=En({abi:t,args:r,name:n});if(!a)throw new Xn(n,{docsPath:po});s=a}if(s.type!=="function")throw new Xn(void 0,{docsPath:po});if(!s.outputs)throw new vf(s.name,{docsPath:po});const o=Ii(s.outputs,i);if(o&&o.length>1)return o;if(o&&o.length===1)return o[0]}const Xc=[{inputs:[{components:[{name:"target",type:"address"},{name:"allowFailure",type:"bool"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate3",outputs:[{components:[{name:"success",type:"bool"},{name:"returnData",type:"bytes"}],name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"}],py=[{name:"query",type:"function",stateMutability:"view",inputs:[{type:"tuple[]",name:"queries",components:[{type:"address",name:"sender"},{type:"string[]",name:"urls"},{type:"bytes",name:"data"}]}],outputs:[{type:"bool[]",name:"failures"},{type:"bytes[]",name:"responses"}]},{name:"HttpError",type:"error",inputs:[{type:"uint16",name:"status"},{type:"string",name:"message"}]}],yy="0x82ad56cb",my="0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe",by="0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe";class ca extends ${constructor({blockNumber:t,chain:r,contract:n}){super(`Chain "${r.name}" does not support contract "${n.name}".`,{metaMessages:["This could be due to any of the following:",...t&&n.blockCreated&&n.blockCreated>t?[`- The contract "${n.name}" was not deployed until block ${n.blockCreated} (current block ${t}).`]:[`- The chain does not have the contract "${n.name}" configured.`]],name:"ChainDoesNotSupportContract"})}}class gy extends ${constructor({chain:t,currentChainId:r}){super(`The current chain of the wallet (id: ${r}) does not match the target chain for the transaction (id: ${t.id} – ${t.name}).`,{metaMessages:[`Current Chain ID: ${r}`,`Expected Chain ID: ${t.id} – ${t.name}`],name:"ChainMismatchError"})}}class wy extends ${constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join(`
|
|
40
|
-
`),{name:"ChainNotFoundError"})}}class pd extends ${constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class Fs extends ${constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const yo="/docs/contract/encodeDeployData";function
|
|
41
|
-
`),{docsPath:t,docsSlug:"account",name:"AccountNotFoundError"})}}class os extends ${constructor({docsPath:t,metaMessages:r,type:n}){super(`Account type "${n}" is not supported.`,{docsPath:t,metaMessages:r,name:"AccountTypeNotSupportedError"})}}function bd({chain:e,currentChainId:t}){if(!e)throw new wy;if(t!==e.id)throw new gy({chain:e,currentChainId:t})}function gd(e,{docsPath:t,...r}){const n=(()=>{const i=Ha(e,r);return i instanceof Us?e:i})();return new Ap(n,{docsPath:t,...r})}async function wd(e,{serializedTransaction:t}){return e.request({method:"eth_sendRawTransaction",params:[t]},{retryCount:0})}const go=new Bs(128);async function Za(e,t){var I,k,A,E;const{account:r=e.account,chain:n=e.chain,accessList:i,authorizationList:s,blobs:o,data:a,gas:c,gasPrice:f,maxFeePerBlobGas:l,maxFeePerGas:h,maxPriorityFeePerGas:m,nonce:p,value:g,...v}=t;if(typeof r>"u")throw new br({docsPath:"/docs/actions/wallet/sendTransaction"});const x=r?Ne(r):null;try{Ci(t);const T=await(async()=>{if(t.to)return t.to;if(t.to!==null&&s&&s.length>0)return await Yf({authorization:s[0]}).catch(()=>{throw new $("`to` is required. Could not infer from `authorizationList`.")})})();if((x==null?void 0:x.type)==="json-rpc"||x===null){let S;n!==null&&(S=await oe(e,Oi,"getChainId")({}),bd({currentChainId:S,chain:n}));const N=(A=(k=(I=e.chain)==null?void 0:I.formatters)==null?void 0:k.transactionRequest)==null?void 0:A.format,B=(N||Ls)({...Da(v,{format:N}),accessList:i,authorizationList:s,blobs:o,chainId:S,data:a,from:x==null?void 0:x.address,gas:c,gasPrice:f,maxFeePerBlobGas:l,maxFeePerGas:h,maxPriorityFeePerGas:m,nonce:p,to:T,value:g}),W=go.get(e.uid),U=W?"wallet_sendTransaction":"eth_sendTransaction";try{return await e.request({method:U,params:[B]},{retryCount:0})}catch(D){if(W===!1)throw D;const j=D;if(j.name==="InvalidInputRpcError"||j.name==="InvalidParamsRpcError"||j.name==="MethodNotFoundRpcError"||j.name==="MethodNotSupportedRpcError")return await e.request({method:"wallet_sendTransaction",params:[B]},{retryCount:0}).then(V=>(go.set(e.uid,!0),V)).catch(V=>{const X=V;throw X.name==="MethodNotFoundRpcError"||X.name==="MethodNotSupportedRpcError"?(go.set(e.uid,!1),j):X});throw j}}if((x==null?void 0:x.type)==="local"){const S=await oe(e,Ka,"prepareTransactionRequest")({account:x,accessList:i,authorizationList:s,blobs:o,chain:n,data:a,gas:c,gasPrice:f,maxFeePerBlobGas:l,maxFeePerGas:h,maxPriorityFeePerGas:m,nonce:p,nonceManager:x.nonceManager,parameters:[...ud,"sidecars"],value:g,...v,to:T}),N=(E=n==null?void 0:n.serializers)==null?void 0:E.transaction,M=await x.signTransaction(S,{serializer:N});return await oe(e,wd,"sendRawTransaction")({serializedTransaction:M})}throw(x==null?void 0:x.type)==="smart"?new os({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:"/docs/actions/bundler/sendUserOperation",type:"smart"}):new os({docsPath:"/docs/actions/wallet/sendTransaction",type:x==null?void 0:x.type})}catch(T){throw T instanceof os?T:gd(T,{...t,account:x,chain:t.chain||void 0})}}async function _d(e,t){const{abi:r,account:n=e.account,address:i,args:s,dataSuffix:o,functionName:a,...c}=t;if(typeof n>"u")throw new br({docsPath:"/docs/contract/writeContract"});const f=n?Ne(n):null,l=xn({abi:r,args:s,functionName:a});try{return await oe(e,Za,"sendTransaction")({data:`${l}${o?o.replace("0x",""):""}`,to:i,account:f,...c})}catch(h){throw Rs(h,{abi:r,address:i,args:s,docsPath:"/docs/contract/writeContract",functionName:a,sender:f==null?void 0:f.address})}}function wo({abi:e,address:t,client:r}){const n=r,[i,s]=n?"public"in n&&"wallet"in n?[n.public,n.wallet]:"public"in n?[n.public,void 0]:"wallet"in n?[void 0,n.wallet]:[n,n]:[void 0,void 0],o=i!=null,a=s!=null,c={};let f=!1,l=!1,h=!1;for(const m of e)if(m.type==="function"?m.stateMutability==="view"||m.stateMutability==="pure"?f=!0:l=!0:m.type==="event"&&(h=!0),f&&l&&h)break;return o&&(f&&(c.read=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(i,ky,"readContract")({abi:e,address:t,functionName:p,args:v,...x})}}})),l&&(c.simulate=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(i,Iy,"simulateContract")({abi:e,address:t,functionName:p,args:v,...x})}}})),h&&(c.createEventFilter=new Proxy({},{get(m,p){return(...g)=>{const v=e.find(k=>k.type==="event"&&k.name===p),{args:x,options:I}=_o(g,v);return oe(i,Mf,"createContractEventFilter")({abi:e,address:t,eventName:p,args:x,...I})}}}),c.getEvents=new Proxy({},{get(m,p){return(...g)=>{const v=e.find(k=>k.type==="event"&&k.name===p),{args:x,options:I}=_o(g,v);return oe(i,hd,"getContractEvents")({abi:e,address:t,eventName:p,args:x,...I})}}}),c.watchEvent=new Proxy({},{get(m,p){return(...g)=>{const v=e.find(k=>k.type==="event"&&k.name===p),{args:x,options:I}=_o(g,v);return oe(i,My,"watchContractEvent")({abi:e,address:t,eventName:p,args:x,...I})}}}))),a&&l&&(c.write=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(s,_d,"writeContract")({abi:e,address:t,functionName:p,args:v,...x})}}})),(o||a)&&l&&(c.estimateGas=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(i??s,fy,"estimateContractGas")({abi:e,address:t,functionName:p,args:v,...x,account:x.account??s.account})}}})),c.address=t,c.abi=e,c}function zi(e){const t=e.length&&Array.isArray(e[0]),r=t?e[0]:[],n=(t?e[1]:e[0])??{};return{args:r,options:n}}function _o(e,t){let r=!1;Array.isArray(e[0])?r=!0:e.length===1?r=t.inputs.some(s=>s.indexed):e.length===2&&(r=!0);const n=r?e[0]:void 0,i=(r?e[1]:e[0])??{};return{args:n,options:i}}const vd={"0x0":"reverted","0x1":"success"};function Hy(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=>_i(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?qt(e.transactionIndex):null,status:e.status?vd[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 Dy=ja("transactionReceipt",Hy);async function Ed(e,t){const{atomic:r=!1,chainId:n,receipts:i,version:s="2.0.0",...o}=await e.request({method:"wallet_getCallsStatus",params:[t.id]}),[a,c]=(()=>{const f=o.status;return f>=100&&f<200?["pending",f]:f>=200&&f<300?["success",f]:f>=300&&f<700?["failure",f]:f==="CONFIRMED"?["success",200]:f==="PENDING"?["pending",100]:[void 0,f]})();return{...o,atomic:r,chainId:n?qt(n):void 0,receipts:(i==null?void 0:i.map(f=>({...f,blockNumber:lt(f.blockNumber),gasUsed:lt(f.gasUsed),status:vd[f.status]})))??[],statusCode:c,status:a,version:s}}async function jy(e,t){const{id:r,pollingInterval:n=e.pollingInterval,status:i=({statusCode:m})=>m>=200,timeout:s=6e4}=t,o=It(["waitForCallsStatus",e.uid,r]),{promise:a,resolve:c,reject:f}=yd();let l;const h=ua(o,{resolve:c,reject:f},m=>{const p=md(async()=>{const g=v=>{clearTimeout(l),p(),v(),h()};try{const v=await Ed(e,{id:r});if(!i(v))return;g(()=>m.resolve(v))}catch(v){g(()=>m.reject(v))}},{interval:n,emitOnBegin:!0});return p});return l=s?setTimeout(()=>{h(),clearTimeout(l),f(new Gy({id:r}))},s):void 0,await a}class Gy extends ${constructor({id:t}){super(`Timed out while waiting for call bundle with id "${t}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}const da=256;let qi=da,Vi;function xd(e=11){if(!Vi||qi+e>da*2){Vi="",qi=0;for(let t=0;t<da;t++)Vi+=(256+Math.random()*256|0).toString(16).substring(1)}return Vi.substring(qi,qi+++e)}function zy(e){const{batch:t,cacheTime:r=e.pollingInterval??4e3,ccipRead:n,key:i="base",name:s="Base Client",pollingInterval:o=4e3,type:a="base"}=e,c=e.chain,f=e.account?Ne(e.account):void 0,{config:l,request:h,value:m}=e.transport({chain:c,pollingInterval:o}),p={...l,...m},g={account:f,batch:t,cacheTime:r,ccipRead:n,chain:c,key:i,name:s,pollingInterval:o,request:h,transport:p,type:a,uid:xd()};function v(x){return I=>{const k=I(x);for(const E in g)delete k[E];const A={...x,...k};return Object.assign(A,{extend:v(A)})}}return Object.assign(g,{extend:v(g)})}const Wi=new Bs(8192);function qy(e,{enabled:t=!0,id:r}){if(!t||!r)return e();if(Wi.get(r))return Wi.get(r);const n=e().finally(()=>Wi.delete(r));return Wi.set(r,n),n}function Vy(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((i,s)=>{const o=async({count:a=0}={})=>{const c=async({error:f})=>{const l=typeof t=="function"?t({count:a,error:f}):t;l&&await fa(l),o({count:a+1})};try{const f=await e();i(f)}catch(f){if(a<r&&await n({count:a,error:f}))return c({error:f});s(f)}};o()})}function Wy(e,t={}){return async(r,n={})=>{var h;const{dedupe:i=!1,methods:s,retryDelay:o=150,retryCount:a=3,uid:c}={...t,...n},{method:f}=r;if((h=s==null?void 0:s.exclude)!=null&&h.includes(f))throw new Tr(new Error("method not supported"),{method:f});if(s!=null&&s.include&&!s.include.includes(f))throw new Tr(new Error("method not supported"),{method:f});const l=i?Ts(`${c}.${It(r)}`):void 0;return qy(()=>Vy(async()=>{try{return await e(r)}catch(m){const p=m;switch(p.code){case Zn.code:throw new Zn(p);case ei.code:throw new ei(p);case ti.code:throw new ti(p,{method:r.method});case ri.code:throw new ri(p);case Ur.code:throw new Ur(p);case ln.code:throw new ln(p);case ni.code:throw new ni(p);case ii.code:throw new ii(p);case si.code:throw new si(p);case Tr.code:throw new Tr(p,{method:r.method});case hn.code:throw new hn(p);case oi.code:throw new oi(p);case sn.code:throw new sn(p);case ai.code:throw new ai(p);case ci.code:throw new ci(p);case ui.code:throw new ui(p);case fi.code:throw new fi(p);case di.code:throw new di(p);case li.code:throw new li(p);case hi.code:throw new hi(p);case pi.code:throw new pi(p);case yi.code:throw new yi(p);case mi.code:throw new mi(p);case bi.code:throw new bi(p);case gi.code:throw new gi(p);case 5e3:throw new sn(p);default:throw m instanceof $?m:new Op(p)}}},{delay:({count:m,error:p})=>{var g;if(p&&p instanceof Ma){const v=(g=p==null?void 0:p.headers)==null?void 0:g.get("Retry-After");if(v!=null&&v.match(/\d/))return Number.parseInt(v)*1e3}return~~(1<<m)*o},retryCount:a,shouldRetry:({error:m})=>Ky(m)}),{enabled:i,id:l})}}function Ky(e){return"code"in e&&typeof e.code=="number"?e.code===-1||e.code===hn.code||e.code===Ur.code:e instanceof Ma&&e.status?e.status===403||e.status===408||e.status===413||e.status===429||e.status===500||e.status===502||e.status===503||e.status===504:!0}function Yy({key:e,methods:t,name:r,request:n,retryCount:i=3,retryDelay:s=150,timeout:o,type:a},c){const f=xd();return{config:{key:e,methods:t,name:r,request:n,retryCount:i,retryDelay:s,timeout:o,type:a},request:Wy(n,{methods:t,retryCount:i,retryDelay:s,uid:f}),value:c}}function Qc(e,t={}){const{key:r="custom",methods:n,name:i="Custom Provider",retryDelay:s}=t;return({retryCount:o})=>Yy({key:r,methods:n,name:i,request:e.request.bind(e),retryCount:t.retryCount??o,retryDelay:s,type:"custom"})}function Ot(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}class Xy extends ${constructor({domain:t}){super(`Invalid domain "${It(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class Jy extends ${constructor({primaryType:t,types:r}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(r))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class Qy extends ${constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function Zy(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(c,f)=>{const l={...f};for(const h of c){const{name:m,type:p}=h;p==="address"&&(l[m]=l[m].toLowerCase())}return l},o=i.EIP712Domain?t?s(i.EIP712Domain,t):{}:{},a=(()=>{if(n!=="EIP712Domain")return s(i[n],r)})();return It({domain:o,message:a,primaryType:n,types:i})}function em(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(o,a)=>{for(const c of o){const{name:f,type:l}=c,h=a[f],m=l.match(Ff);if(m&&(typeof h=="number"||typeof h=="bigint")){const[v,x,I]=m;Q(h,{signed:x==="int",size:Number.parseInt(I)/8})}if(l==="address"&&typeof h=="string"&&!Le(h))throw new et({address:h});const p=l.match(z0);if(p){const[v,x]=p;if(x&&Ie(h)!==Number.parseInt(x))throw new e0({expectedSize:Number.parseInt(x),givenSize:Ie(h)})}const g=i[l];g&&(rm(l),s(g,h))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new Xy({domain:t});s(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])s(i[n],r);else throw new Jy({primaryType:n,types:i})}function tm({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},(typeof(e==null?void 0:e.chainId)=="number"||typeof(e==null?void 0:e.chainId)=="bigint")&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}function rm(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new Qy({type:e})}function nm(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!Le(i))throw new et({address:i});if(n<0)throw new Fs({chainId:n})}ec(e)}function im(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new od;for(const r of t){const n=Ie(r),i=qt(dn(r,0,1));if(n!==32)throw new oy({hash:r,size:n});if(i!==sd)throw new ay({hash:r,version:i})}}ec(e)}function ec(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Fs({chainId:t});if(i&&!Le(i))throw new et({address:i});if(n&&n>Ns)throw new Lr({maxFeePerGas:n});if(r&&n&&r>n)throw new wi({maxFeePerGas:n,maxPriorityFeePerGas:r})}function sm(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new Fs({chainId:t});if(s&&!Le(s))throw new et({address:s});if(r||i)throw new $("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ns)throw new Lr({maxFeePerGas:n})}function om(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!Le(s))throw new et({address:s});if(typeof t<"u"&&t<=0)throw new Fs({chainId:t});if(r||i)throw new $("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ns)throw new Lr({maxFeePerGas:n})}function $s(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 xp({storageKey:i[s]});if(!Le(n,{strict:!1}))throw new et({address:n});t.push([n,i])}return t}function am(e,t){const r=cd(e);return r==="eip1559"?fm(e,t):r==="eip2930"?dm(e,t):r==="eip4844"?um(e,t):r==="eip7702"?cm(e,t):lm(e,t)}function cm(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:c,maxPriorityFeePerGas:f,accessList:l,data:h}=e;nm(e);const m=$s(l),p=hm(r);return Ct(["0x04",pr([J(n),s?J(s):"0x",f?J(f):"0x",c?J(c):"0x",i?J(i):"0x",o??"0x",a?J(a):"0x",h??"0x",m,p,...Ri(e,t)])])}function um(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:f,accessList:l,data:h}=e;im(e);let m=e.blobVersionedHashes,p=e.sidecars;if(e.blobs&&(typeof m>"u"||typeof p>"u")){const A=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(S=>Ze(S)),E=e.kzg,T=qa({blobs:A,kzg:E});if(typeof m>"u"&&(m=rd({commitments:T})),typeof p>"u"){const S=Va({blobs:A,commitments:T,kzg:E});p=ad({blobs:A,commitments:T,proofs:S})}}const g=$s(l),v=[J(r),i?J(i):"0x",f?J(f):"0x",c?J(c):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",h??"0x",g,a?J(a):"0x",m??[],...Ri(e,t)],x=[],I=[],k=[];if(p)for(let A=0;A<p.length;A++){const{blob:E,commitment:T,proof:S}=p[A];x.push(E),I.push(T),k.push(S)}return Ct(["0x03",pr(p?[v,x,I,k]:v)])}function fm(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:f,data:l}=e;ec(e);const h=$s(f),m=[J(r),i?J(i):"0x",c?J(c):"0x",a?J(a):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",l??"0x",h,...Ri(e,t)];return Ct(["0x02",pr(m)])}function dm(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:c,gasPrice:f}=e;sm(e);const l=$s(c),h=[J(r),s?J(s):"0x",f?J(f):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x",l,...Ri(e,t)];return Ct(["0x01",pr(h)])}function lm(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:c}=e;om(e);let f=[s?J(s):"0x",c?J(c):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x"];if(t){const l=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const p=27n+(t.v===27n?0n:1n);if(t.v!==p)throw new vp({v:t.v});return p})(),h=Or(t.r),m=Or(t.s);f=[...f,J(l),h==="0x00"?"0x":h,m==="0x00"?"0x":m]}else r>0&&(f=[...f,J(r),"0x","0x"]);return pr(f)}function Ri(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=Or(r.r),o=Or(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]}function hm(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{chainId:n,nonce:i,...s}=r,o=r.address;t.push([n?J(n):"0x",o,i?J(i):"0x",...Ri({},s)])}return t}function pm(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ad(e,...t){if(!pm(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Zc(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ym(e,t){Ad(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) */function vo(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}function Ki(e,t){return e<<t|e>>>32-t>>>0}function mm(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function Sd(e){return typeof e=="string"&&(e=mm(e)),Ad(e),e}let bm=class{clone(){return this._cloneInto()}};function tc(e){const t=n=>e().update(Sd(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function gm(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,f=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+f,a,n)}function wm(e,t,r){return e&t^~e&r}function _m(e,t,r){return e&t^e&r^t&r}let Pd=class extends bm{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=vo(this.buffer)}update(t){Zc(this);const{view:r,buffer:n,blockLen:i}=this;t=Sd(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=vo(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){Zc(this),ym(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 h=o;h<i;h++)r[h]=0;gm(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=vo(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],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 vm=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Td=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Em=Td.map(e=>(9*e+5)%16);let rc=[Td],nc=[Em];for(let e=0;e<4;e++)for(let t of[rc,nc])t.push(t[e].map(r=>vm[r]));const kd=[[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)),xm=rc.map((e,t)=>e.map(r=>kd[t][r])),Am=nc.map((e,t)=>e.map(r=>kd[t][r])),Sm=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Pm=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function eu(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 Yi=new Uint32Array(16);let Id=class extends Pd{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 p=0;p<16;p++,r+=4)Yi[p]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,f=this.h3|0,l=f,h=this.h4|0,m=h;for(let p=0;p<5;p++){const g=4-p,v=Sm[p],x=Pm[p],I=rc[p],k=nc[p],A=xm[p],E=Am[p];for(let T=0;T<16;T++){const S=Ki(n+eu(p,s,a,f)+Yi[I[T]]+v,A[T])+h|0;n=h,h=f,f=Ki(a,10)|0,a=s,s=S}for(let T=0;T<16;T++){const S=Ki(i+eu(g,o,c,l)+Yi[k[T]]+x,E[T])+m|0;i=m,m=l,l=Ki(c,10)|0,c=o,o=S}}this.set(this.h1+a+l|0,this.h2+f+m|0,this.h3+h+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){Yi.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const Tm=tc(()=>new Id),km=Object.freeze(Object.defineProperty({__proto__:null,RIPEMD160:Id,ripemd160:Tm},Symbol.toStringTag,{value:"Module"})),Im=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]),rr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nr=new Uint32Array(64);class ic extends Pd{constructor(){super(64,32,8,!1),this.A=rr[0]|0,this.B=rr[1]|0,this.C=rr[2]|0,this.D=rr[3]|0,this.E=rr[4]|0,this.F=rr[5]|0,this.G=rr[6]|0,this.H=rr[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 h=0;h<16;h++,r+=4)nr[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const m=nr[h-15],p=nr[h-2],g=wt(m,7)^wt(m,18)^m>>>3,v=wt(p,17)^wt(p,19)^p>>>10;nr[h]=v+nr[h-7]+g+nr[h-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const m=wt(a,6)^wt(a,11)^wt(a,25),p=l+m+wm(a,c,f)+Im[h]+nr[h]|0,v=(wt(n,2)^wt(n,13)^wt(n,22))+_m(n,i,s)|0;l=f,f=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+v|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,f=f+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,f,l)}roundClean(){nr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Bm extends ic{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 Cm=tc(()=>new ic),Om=tc(()=>new Bm),Rm=Object.freeze(Object.defineProperty({__proto__:null,SHA256:ic,sha224:Om,sha256:Cm},Symbol.toStringTag,{value:"Module"}));async function Um(e,{chain:t}){const{id:r,name:n,nativeCurrency:i,rpcUrls:s,blockExplorers:o}=t;await e.request({method:"wallet_addEthereumChain",params:[{chainId:Q(r),chainName:n,nativeCurrency:i,rpcUrls:s.default.http,blockExplorerUrls:o?Object.values(o).map(({url:a})=>a):void 0}]},{dedupe:!0,retryCount:0})}function Lm(e,t){const{abi:r,args:n,bytecode:i,...s}=t,o=Ja({abi:r,args:n,bytecode:i});return Za(e,{...s,...s.authorizationList?{to:null}:{},data:o})}async function Nm(e){var r;return((r=e.account)==null?void 0:r.type)==="local"?[e.account.address]:(await e.request({method:"eth_accounts"},{dedupe:!0})).map(n=>ki(n))}async function Fm(e,t={}){const{account:r=e.account,chainId:n}=t,i=r?Ne(r):void 0,s=await e.request({method:"wallet_getCapabilities",params:[i==null?void 0:i.address]}),o={};for(const[a,c]of Object.entries(s))o[Number(a)]=c;return typeof n=="number"?o[n]:o}async function $m(e){return await e.request({method:"wallet_getPermissions"},{dedupe:!0})}async function Bd(e,t){var c;const{account:r=e.account,chainId:n,nonce:i}=t;if(!r)throw new br({docsPath:"/docs/eip7702/prepareAuthorization"});const s=Ne(r),o=(()=>{if(t.executor)return t.executor==="self"?t.executor:Ne(t.executor)})(),a={address:t.contractAddress??t.address,chainId:n,nonce:i};return typeof a.chainId>"u"&&(a.chainId=((c=e.chain)==null?void 0:c.id)??await oe(e,Oi,"getChainId")({})),typeof a.nonce>"u"&&(a.nonce=await oe(e,ed,"getTransactionCount")({address:s.address,blockTag:"pending"}),(o==="self"||o!=null&&o.address&&Ya(o.address,s.address))&&(a.nonce+=1)),a}async function Mm(e){return(await e.request({method:"eth_requestAccounts"},{dedupe:!0,retryCount:0})).map(r=>H0(r))}async function Hm(e,t){return e.request({method:"wallet_requestPermissions",params:[t]},{retryCount:0})}async function Dm(e,t){const{account:r=e.account,capabilities:n,chain:i=e.chain,forceAtomic:s=!1,id:o,version:a="2.0.0"}=t;if(typeof r>"u")throw new br({docsPath:"/experimental/eip5792/sendCalls"});const c=r?Ne(r):null,f=t.calls.map(l=>{const h=l;return{data:h.abi?xn({abi:h.abi,functionName:h.functionName,args:h.args}):h.data,to:h.to,value:h.value?Q(h.value):void 0}});try{const l=await e.request({method:"wallet_sendCalls",params:[{atomicRequired:s,calls:f,capabilities:n,chainId:Q(i.id),from:c==null?void 0:c.address,id:o,version:a}]},{retryCount:0});return typeof l=="string"?{id:l}:l}catch(l){throw gd(l,{...t,account:c,chain:t.chain})}}async function jm(e,t){const{id:r}=t;await e.request({method:"wallet_showCallsStatus",params:[r]})}async function Gm(e,t){const{account:r=e.account}=t;if(!r)throw new br({docsPath:"/docs/eip7702/signAuthorization"});const n=Ne(r);if(!n.signAuthorization)throw new os({docsPath:"/docs/eip7702/signAuthorization",metaMessages:["The `signAuthorization` Action does not support JSON-RPC Accounts."],type:n.type});const i=await Bd(e,t);return n.signAuthorization(i)}async function zm(e,{account:t=e.account,message:r}){if(!t)throw new br({docsPath:"/docs/actions/wallet/signMessage"});const n=Ne(t);if(n.signMessage)return n.signMessage({message:r});const i=typeof r=="string"?Ts(r):r.raw instanceof Uint8Array?J(r.raw):r.raw;return e.request({method:"personal_sign",params:[i,n.address]},{retryCount:0})}async function qm(e,t){var f,l,h,m;const{account:r=e.account,chain:n=e.chain,...i}=t;if(!r)throw new br({docsPath:"/docs/actions/wallet/signTransaction"});const s=Ne(r);Ci({account:s,...t});const o=await oe(e,Oi,"getChainId")({});n!==null&&bd({currentChainId:o,chain:n});const a=(n==null?void 0:n.formatters)||((f=e.chain)==null?void 0:f.formatters),c=((l=a==null?void 0:a.transactionRequest)==null?void 0:l.format)||Ls;return s.signTransaction?s.signTransaction({...i,chainId:o},{serializer:(m=(h=e.chain)==null?void 0:h.serializers)==null?void 0:m.transaction}):await e.request({method:"eth_signTransaction",params:[{...c(i),chainId:Q(o),from:s.address}]},{retryCount:0})}async function Vm(e,t){const{account:r=e.account,domain:n,message:i,primaryType:s}=t;if(!r)throw new br({docsPath:"/docs/actions/wallet/signTypedData"});const o=Ne(r),a={EIP712Domain:tm({domain:n}),...t.types};if(em({domain:n,message:i,primaryType:s,types:a}),o.signTypedData)return o.signTypedData({domain:n,message:i,primaryType:s,types:a});const c=Zy({domain:n,message:i,primaryType:s,types:a});return e.request({method:"eth_signTypedData_v4",params:[o.address,c]},{retryCount:0})}async function Wm(e,{id:t}){await e.request({method:"wallet_switchEthereumChain",params:[{chainId:Q(t)}]},{retryCount:0})}async function Km(e,t){return await e.request({method:"wallet_watchAsset",params:t},{retryCount:0})}function Ym(e){return{addChain:t=>Um(e,t),deployContract:t=>Lm(e,t),getAddresses:()=>Nm(e),getCallsStatus:t=>Ed(e,t),getCapabilities:()=>Fm(e),getChainId:()=>Oi(e),getPermissions:()=>$m(e),prepareAuthorization:t=>Bd(e,t),prepareTransactionRequest:t=>Ka(e,t),requestAddresses:()=>Mm(e),requestPermissions:t=>Hm(e,t),sendCalls:t=>Dm(e,t),sendRawTransaction:t=>wd(e,t),sendTransaction:t=>Za(e,t),showCallsStatus:t=>jm(e,t),signAuthorization:t=>Gm(e,t),signMessage:t=>zm(e,t),signTransaction:t=>qm(e,t),signTypedData:t=>Vm(e,t),switchChain:t=>Wm(e,t),waitForCallsStatus:t=>jy(e,t),watchAsset:t=>Km(e,t),writeContract:t=>_d(e,t)}}function tu(e){const{key:t="wallet",name:r="Wallet Client",transport:n}=e;return zy({...e,key:t,name:r,transport:n,type:"walletClient"}).extend(Ym)}function la(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function Ar(e,t){if(!e)throw new Error(t)}function Xm(e){return Buffer.concat([Uint8Array.from([192]),Jm(e)])}function Jm(e){const t=Sc.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Sc.encode(e.length,r),Buffer.concat([r,e])}function Qm(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const cr=e=>e.length===64?e:e.slice(2),Zm=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return Br.isPoint(t)}catch{return!1}},Cd=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function eb(e,t){if(!e)return!1;const r=t===z.Environment.MAINNET?ce.networks.bitcoin:t===z.Environment.TESTNET?ce.networks.testnet:ce.networks.regtest;if(!r)return!1;ce.initEccLib(Br);try{return ce.address.toOutputScript(e,r),!0}catch{return!1}}const tb=e=>{switch(e){case z.Environment.MAINNET:return fn.BitcoinNetwork.Mainnet;case z.Environment.TESTNET:return fn.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}},rb=e=>{const t=e.toLowerCase().replace("0x","");return/^[0-9a-f]+$/.test(t)},nb=e=>{if(typeof e=="object"&&"r"in e&&"s"in e)return z.Ok([e.r.toString(),e.s.toString()]);if(Array.isArray(e)){const t=e.map(r=>typeof r=="string"&&r.startsWith("0x")&&rb(r)?BigInt(r).toString():r);return z.Ok(t)}return z.Err("Invalid signature format")};var we=(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))(we||{}),xe=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(xe||{});const sc=(e,t,r)=>{const n=ha(e.source_swap,t),i=ha(e.destination_swap,r);if(i===xe.RedeemDetected)return we.RedeemDetected;if(i===xe.Redeemed)return we.Redeemed;if(n===xe.Refunded)return we.Refunded;if(n===xe.RefundDetected)return we.RefundDetected;if(i===xe.Expired)return we.CounterPartySwapExpired;if(n===xe.Expired)return we.Expired;if(i===xe.Refunded)return we.CounterPartyRefunded;if(i===xe.RefundDetected)return we.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===xe.Initiated?we.CounterPartyInitiated:i===xe.InitiateDetected?we.CounterPartyInitiateDetected:vi(s,12)?we.DeadLineExceeded:n===xe.Initiated?we.Initiated:vi(s,1)?we.DeadLineExceeded:n===xe.InitiateDetected?we.InitiateDetected:n===xe.Redeemed?we.CounterPartyRedeemed:n===xe.RedeemDetected?we.CounterPartyRedeemDetected:we.Matched},ha=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?xe.Redeemed:xe.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?xe.Refunded:xe.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return xe.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?xe.Initiated:xe.InitiateDetected:xe.Idle},ib=(e,t,r)=>{const n=sc(e,t,r);return oc(n)},oc=e=>{switch(e){case we.Matched:return Ce.Initiate;case we.CounterPartyInitiated:case we.CounterPartyInitiateDetected:case we.RedeemDetected:return Ce.Redeem;case we.Expired:return Ce.Refund;default:return Ce.Idle}},vi=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},sb=e=>e.filter(t=>!Od(t)),Od=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)?vi(Number(s),12):n?!1:vi(Number(s),1)},ob=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),ab=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),cb=Buffer.concat([ob,ab]),ub=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),ru={failedToCreateInternalPubkey:"failed to create internal pubkey"};function fb(){const e=ef.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=Br.pointMultiply(Buffer.concat([Buffer.from("04","hex"),cb]),e);if(!t)throw new Error(ru.failedToCreateInternalPubkey);const r=Br.pointAdd(ub,t);if(!r)throw new Error(ru.failedToCreateInternalPubkey);return la(Buffer.from(r))}var yr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function db(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ac(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 Ae={},Ve={},Jt={},Ms={};Ms.byteLength=pb;Ms.toByteArray=mb;Ms.fromByteArray=wb;var Tt=[],dt=[],lb=typeof Uint8Array<"u"?Uint8Array:Array,Eo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Kr=0,hb=Eo.length;Kr<hb;++Kr)Tt[Kr]=Eo[Kr],dt[Eo.charCodeAt(Kr)]=Kr;dt[45]=62;dt[95]=63;function Rd(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 pb(e){var t=Rd(e),r=t[0],n=t[1];return(r+n)*3/4-n}function yb(e,t,r){return(t+r)*3/4-r}function mb(e){var t,r=Rd(e),n=r[0],i=r[1],s=new lb(yb(e,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=dt[e.charCodeAt(c)]<<18|dt[e.charCodeAt(c+1)]<<12|dt[e.charCodeAt(c+2)]<<6|dt[e.charCodeAt(c+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=dt[e.charCodeAt(c)]<<2|dt[e.charCodeAt(c+1)]>>4,s[o++]=t&255),i===1&&(t=dt[e.charCodeAt(c)]<<10|dt[e.charCodeAt(c+1)]<<4|dt[e.charCodeAt(c+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function bb(e){return Tt[e>>18&63]+Tt[e>>12&63]+Tt[e>>6&63]+Tt[e&63]}function gb(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(bb(n));return i.join("")}function wb(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(gb(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(Tt[t>>2]+Tt[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Tt[t>>10]+Tt[t>>4&63]+Tt[t<<2&63]+"=")),i.join("")}var cc={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */cc.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,c=(1<<a)-1,f=c>>1,l=-7,h=r?i-1:0,m=r?-1:1,p=e[t+h];for(h+=m,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=s*256+e[t+h],h+=m,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=n;l>0;o=o*256+e[t+h],h+=m,l-=8);if(s===0)s=1-f;else{if(s===c)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-f}return(p?-1:1)*o*Math.pow(2,s-n)};cc.write=function(e,t,r,n,i,s){var o,a,c,f=s*8-i-1,l=(1<<f)-1,h=l>>1,m=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,g=n?1:-1,v=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=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+h>=1?t+=m/c:t+=m*Math.pow(2,1-h),t*c>=2&&(o++,c/=2),o+h>=l?(a=0,o=l):o+h>=1?(a=(t*c-1)*Math.pow(2,i),o=o+h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=a&255,p+=g,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=o&255,p+=g,o/=256,f-=8);e[r+p-g]|=v*128};/*!
|
|
36
|
+
`)})}}Object.defineProperty(ln,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32e3});class ni extends nt{constructor(t){super(t,{code:ni.code,name:"ResourceNotFoundRpcError",shortMessage:"Requested resource not found."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceNotFoundRpcError"})}}Object.defineProperty(ni,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32001});class ii extends nt{constructor(t){super(t,{code:ii.code,name:"ResourceUnavailableRpcError",shortMessage:"Requested resource not available."})}}Object.defineProperty(ii,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32002});class si extends nt{constructor(t){super(t,{code:si.code,name:"TransactionRejectedRpcError",shortMessage:"Transaction creation failed."})}}Object.defineProperty(si,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32003});class Tr extends nt{constructor(t,{method:r}={}){super(t,{code:Tr.code,name:"MethodNotSupportedRpcError",shortMessage:`Method${r?` "${r}"`:""} is not supported.`})}}Object.defineProperty(Tr,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32004});class hn extends nt{constructor(t){super(t,{code:hn.code,name:"LimitExceededRpcError",shortMessage:"Request exceeds defined limit."})}}Object.defineProperty(hn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32005});class oi extends nt{constructor(t){super(t,{code:oi.code,name:"JsonRpcVersionUnsupportedError",shortMessage:"Version of JSON-RPC protocol is not supported."})}}Object.defineProperty(oi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32006});class sn extends at{constructor(t){super(t,{code:sn.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(sn,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class ai extends at{constructor(t){super(t,{code:ai.code,name:"UnauthorizedProviderError",shortMessage:"The requested method and/or account has not been authorized by the user."})}}Object.defineProperty(ai,"code",{enumerable:!0,configurable:!0,writable:!0,value:4100});class ci extends at{constructor(t,{method:r}={}){super(t,{code:ci.code,name:"UnsupportedProviderMethodError",shortMessage:`The Provider does not support the requested method${r?` " ${r}"`:""}.`})}}Object.defineProperty(ci,"code",{enumerable:!0,configurable:!0,writable:!0,value:4200});class ui extends at{constructor(t){super(t,{code:ui.code,name:"ProviderDisconnectedError",shortMessage:"The Provider is disconnected from all chains."})}}Object.defineProperty(ui,"code",{enumerable:!0,configurable:!0,writable:!0,value:4900});class fi extends at{constructor(t){super(t,{code:fi.code,name:"ChainDisconnectedError",shortMessage:"The Provider is not connected to the requested chain."})}}Object.defineProperty(fi,"code",{enumerable:!0,configurable:!0,writable:!0,value:4901});class di extends at{constructor(t){super(t,{code:di.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(di,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class li extends at{constructor(t){super(t,{code:li.code,name:"UnsupportedNonOptionalCapabilityError",shortMessage:"This Wallet does not support a capability that was not marked as optional."})}}Object.defineProperty(li,"code",{enumerable:!0,configurable:!0,writable:!0,value:5700});class hi extends at{constructor(t){super(t,{code:hi.code,name:"UnsupportedChainIdError",shortMessage:"This Wallet does not support the requested chain ID."})}}Object.defineProperty(hi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5710});class pi extends at{constructor(t){super(t,{code:pi.code,name:"DuplicateIdError",shortMessage:"There is already a bundle submitted with this ID."})}}Object.defineProperty(pi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5720});class yi extends at{constructor(t){super(t,{code:yi.code,name:"UnknownBundleIdError",shortMessage:"This bundle id is unknown / has not been submitted"})}}Object.defineProperty(yi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5730});class mi extends at{constructor(t){super(t,{code:mi.code,name:"BundleTooLargeError",shortMessage:"The call bundle is too large for the Wallet to process."})}}Object.defineProperty(mi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5740});class bi extends at{constructor(t){super(t,{code:bi.code,name:"AtomicReadyWalletRejectedUpgradeError",shortMessage:"The Wallet can support atomicity after an upgrade, but the user rejected the upgrade."})}}Object.defineProperty(bi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5750});class gi extends at{constructor(t){super(t,{code:gi.code,name:"AtomicityNotSupportedError",shortMessage:"The wallet does not support atomic execution but the request requires it."})}}Object.defineProperty(gi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5760});class Op extends nt{constructor(t){super(t,{name:"UnknownRpcError",shortMessage:"An unknown RPC error occurred."})}}const Rp=3;function Rs(e,{abi:t,address:r,args:n,docsPath:i,functionName:s,sender:o}){const a=e instanceof qf?e:e instanceof $?e.walk(g=>"data"in g)||e.walk():{},{code:c,data:f,details:l,message:h,shortMessage:m}=a,p=e instanceof Ba?new Ip({functionName:s}):[Rp,Ur.code].includes(c)&&(f||l||h||m)?new kp({abi:t,data:typeof f=="object"?f.data:f,functionName:s,message:a instanceof Vf?l:m??h}):e;return new Tp(p,{abi:t,args:n,contractAddress:r,docsPath:i,functionName:s,sender:o})}function Up(e){const t=vn(`0x${e.substring(4)}`).substring(26);return ki(`0x${t}`)}async function Lp({hash:e,signature:t}){const r=zt(e)?e:J(e),{secp256k1:n}=await Promise.resolve().then(()=>require("./secp256k1-Cbj-hmMq.cjs"));return`0x${(()=>{if(typeof t=="object"&&"r"in t&&"s"in t){const{r:f,s:l,v:h,yParity:m}=t,p=Number(m??h),g=qc(p);return new n.Signature(lt(f),lt(l)).addRecoveryBit(g)}const o=zt(t)?t:J(t),a=qt(`0x${o.slice(130)}`),c=qc(a);return n.Signature.fromCompact(o.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function qc(e){if(e===0||e===1)return e;if(e===27)return 0;if(e===28)return 1;throw new Error("Invalid yParityOrV value")}async function Np({hash:e,signature:t}){return Up(await Lp({hash:e,signature:t}))}function pr(e,t="hex"){const r=Wf(e),n=$a(new Uint8Array(r.length));return r.encode(n),t==="hex"?Ze(n.bytes):n.bytes}function Wf(e){return Array.isArray(e)?Fp(e.map(t=>Wf(t))):$p(e)}function Fp(e){const t=e.reduce((i,s)=>i+s.length,0),r=Kf(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 $p(e){const t=typeof e=="string"?Vt(e):e,r=Kf(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 Kf(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 $("Length is too large.")}function Mp(e){const{chainId:t,nonce:r,to:n}=e,i=e.contractAddress??e.address,s=vn(Ct(["0x05",pr([t?Q(t):"0x",i,r?Q(r):"0x"])]));return n==="bytes"?Vt(s):s}async function Yf(e){const{authorization:t,signature:r}=e;return Np({hash:Mp(t),signature:r??t})}class Hp extends ${constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:l,to:h,value:m}){var g;const p=Bi({from:r==null?void 0:r.address,to:h,value:typeof m<"u"&&`${Ma(m)} ${((g=i==null?void 0:i.nativeCurrency)==null?void 0:g.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${rt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${rt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${rt(f)} gwei`,nonce:l});super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Estimate Gas Arguments:",p].filter(Boolean),name:"EstimateGasExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class tn extends ${constructor({cause:t,message:r}={}){var i;const n=(i=r==null?void 0:r.replace("execution reverted: ",""))==null?void 0:i.replace("execution reverted","");super(`Execution reverted ${n?`with reason: ${n}`:"for an unknown reason"}.`,{cause:t,name:"ExecutionRevertedError"})}}Object.defineProperty(tn,"code",{enumerable:!0,configurable:!0,writable:!0,value:3});Object.defineProperty(tn,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class Lr extends ${constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${rt(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Lr,"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 ra extends ${constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${rt(r)}`:""} gwei) cannot be lower than the block base fee.`,{cause:t,name:"FeeCapTooLowError"})}}Object.defineProperty(ra,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/});class na extends ${constructor({cause:t,nonce:r}={}){super(`Nonce provided for the transaction ${r?`(${r}) `:""}is higher than the next one expected.`,{cause:t,name:"NonceTooHighError"})}}Object.defineProperty(na,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class ia extends ${constructor({cause:t,nonce:r}={}){super([`Nonce provided for the transaction ${r?`(${r}) `:""}is lower than the current nonce of the account.`,"Try increasing the nonce or find the latest nonce with `getTransactionCount`."].join(`
|
|
37
|
+
`),{cause:t,name:"NonceTooLowError"})}}Object.defineProperty(ia,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class sa extends ${constructor({cause:t,nonce:r}={}){super(`Nonce provided for the transaction ${r?`(${r}) `:""}exceeds the maximum allowed nonce.`,{cause:t,name:"NonceMaxValueError"})}}Object.defineProperty(sa,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/});class oa extends ${constructor({cause:t}={}){super(["The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."].join(`
|
|
38
|
+
`),{cause:t,metaMessages:["This error could arise when the account does not have enough funds to:"," - pay for the total gas fee,"," - pay for the value to send."," ","The cost of the transaction is calculated as `gas * gas fee + value`, where:"," - `gas` is the amount of gas needed for transaction to execute,"," - `gas fee` is the gas fee,"," - `value` is the amount of ether to send to the recipient."],name:"InsufficientFundsError"})}}Object.defineProperty(oa,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class aa extends ${constructor({cause:t,gas:r}={}){super(`The amount of gas ${r?`(${r}) `:""}provided for the transaction exceeds the limit allowed for the block.`,{cause:t,name:"IntrinsicGasTooHighError"})}}Object.defineProperty(aa,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class ca extends ${constructor({cause:t,gas:r}={}){super(`The amount of gas ${r?`(${r}) `:""}provided for the transaction is too low.`,{cause:t,name:"IntrinsicGasTooLowError"})}}Object.defineProperty(ca,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class ua extends ${constructor({cause:t}){super("The transaction type is not supported for this chain.",{cause:t,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty(ua,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class wi extends ${constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${rt(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${rt(n)} gwei`:""}).`].join(`
|
|
39
|
+
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(wi,"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 Us extends ${constructor({cause:t}){super(`An error occurred while executing: ${t==null?void 0:t.shortMessage}`,{cause:t,name:"UnknownNodeError"})}}function ja(e,t){const r=(e.details||"").toLowerCase(),n=e instanceof $?e.walk(i=>(i==null?void 0:i.code)===tn.code):e;return n instanceof $?new tn({cause:e,message:n.details}):tn.nodeMessage.test(r)?new tn({cause:e,message:e.details}):Lr.nodeMessage.test(r)?new Lr({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):ra.nodeMessage.test(r)?new ra({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):na.nodeMessage.test(r)?new na({cause:e,nonce:t==null?void 0:t.nonce}):ia.nodeMessage.test(r)?new ia({cause:e,nonce:t==null?void 0:t.nonce}):sa.nodeMessage.test(r)?new sa({cause:e,nonce:t==null?void 0:t.nonce}):oa.nodeMessage.test(r)?new oa({cause:e}):aa.nodeMessage.test(r)?new aa({cause:e,gas:t==null?void 0:t.gas}):ca.nodeMessage.test(r)?new ca({cause:e,gas:t==null?void 0:t.gas}):ua.nodeMessage.test(r)?new ua({cause:e}):wi.nodeMessage.test(r)?new wi({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas,maxPriorityFeePerGas:t==null?void 0:t.maxPriorityFeePerGas}):new Us({cause:e})}function Dp(e,{docsPath:t,...r}){const n=(()=>{const i=ja(e,r);return i instanceof Us?e:i})();return new Hp(n,{docsPath:t,...r})}function Ga(e,{format:t}){if(!t)return{};const r={};function n(s){const o=Object.keys(s);for(const a of o)a in e&&(r[a]=e[a]),s[a]&&typeof s[a]=="object"&&!Array.isArray(s[a])&&n(s[a])}const i=t(e||{});return n(i),r}function za(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 jp={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function Ls(e){const t={};return typeof e.authorizationList<"u"&&(t.authorizationList=Gp(e.authorizationList)),typeof e.accessList<"u"&&(t.accessList=e.accessList),typeof e.blobVersionedHashes<"u"&&(t.blobVersionedHashes=e.blobVersionedHashes),typeof e.blobs<"u"&&(typeof e.blobs[0]!="string"?t.blobs=e.blobs.map(r=>Ze(r)):t.blobs=e.blobs),typeof e.data<"u"&&(t.data=e.data),typeof e.from<"u"&&(t.from=e.from),typeof e.gas<"u"&&(t.gas=Q(e.gas)),typeof e.gasPrice<"u"&&(t.gasPrice=Q(e.gasPrice)),typeof e.maxFeePerBlobGas<"u"&&(t.maxFeePerBlobGas=Q(e.maxFeePerBlobGas)),typeof e.maxFeePerGas<"u"&&(t.maxFeePerGas=Q(e.maxFeePerGas)),typeof e.maxPriorityFeePerGas<"u"&&(t.maxPriorityFeePerGas=Q(e.maxPriorityFeePerGas)),typeof e.nonce<"u"&&(t.nonce=Q(e.nonce)),typeof e.to<"u"&&(t.to=e.to),typeof e.type<"u"&&(t.type=jp[e.type]),typeof e.value<"u"&&(t.value=Q(e.value)),t}function Gp(e){return e.map(t=>({address:t.address,r:t.r?Q(BigInt(t.r)):t.r,s:t.s?Q(BigInt(t.s)):t.s,chainId:Q(t.chainId),nonce:Q(t.nonce),...typeof t.yParity<"u"?{yParity:Q(t.yParity)}:{},...typeof t.v<"u"&&typeof t.yParity>"u"?{v:Q(t.v)}:{}}))}function Vc(e){if(!(!e||e.length===0))return e.reduce((t,{slot:r,value:n})=>{if(r.length!==66)throw new Oc({size:r.length,targetSize:66,type:"hex"});if(n.length!==66)throw new Oc({size:n.length,targetSize:66,type:"hex"});return t[r]=n,t},{})}function zp(e){const{balance:t,nonce:r,state:n,stateDiff:i,code:s}=e,o={};if(s!==void 0&&(o.code=s),t!==void 0&&(o.balance=Q(t)),r!==void 0&&(o.nonce=Q(r)),n!==void 0&&(o.state=Vc(n)),i!==void 0){if(o.state)throw new gp;o.stateDiff=Vc(i)}return o}function Xf(e){if(!e)return;const t={};for(const{address:r,...n}of e){if(!Le(r,{strict:!1}))throw new et({address:r});if(t[r])throw new bp({address:r});t[r]=zp(n)}return t}const Ns=2n**256n-1n;function Ci(e){const{account:t,gasPrice:r,maxFeePerGas:n,maxPriorityFeePerGas:i,to:s}=e,o=t?Ne(t):void 0;if(o&&!Le(o.address))throw new et({address:o.address});if(s&&!Le(s))throw new et({address:s});if(typeof r<"u"&&(typeof n<"u"||typeof i<"u"))throw new _p;if(n&&n>Ns)throw new Lr({maxFeePerGas:n});if(i&&n&&i>n)throw new wi({maxFeePerGas:n,maxPriorityFeePerGas:i})}class qp extends ${constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class qa extends ${constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class Vp extends ${constructor({maxPriorityFeePerGas:t}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${rt(t)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class Wp extends ${constructor({blockHash:t,blockNumber:r}){let n="Block";t&&(n=`Block at hash "${t}"`),r&&(n=`Block at number "${r}"`),super(`${n} could not be found.`,{name:"BlockNotFoundError"})}}const Jf={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Va(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?qt(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?qt(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=Yp(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 Kp=za("transaction",Va);function Yp(e){return e.map(t=>({address:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function Qf(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:Va(r));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const Xp=za("block",Qf);async function bs(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:i}={}){var l,h,m;const s=n??"latest",o=i??!1,a=r!==void 0?Q(r):void 0;let c=null;if(t?c=await e.request({method:"eth_getBlockByHash",params:[t,o]},{dedupe:!0}):c=await e.request({method:"eth_getBlockByNumber",params:[a||s,o]},{dedupe:!!a}),!c)throw new Wp({blockHash:t,blockNumber:r});return(((m=(h=(l=e.chain)==null?void 0:l.formatters)==null?void 0:h.block)==null?void 0:m.format)||Qf)(c)}async function Zf(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function Jp(e,t){var s,o;const{block:r,chain:n=e.chain,request:i}=t||{};try{const a=((s=n==null?void 0:n.fees)==null?void 0:s.maxPriorityFeePerGas)??((o=n==null?void 0:n.fees)==null?void 0:o.defaultPriorityFee);if(typeof a=="function"){const f=r||await oe(e,bs,"getBlock")({}),l=await a({block:f,client:e,request:i});if(l===null)throw new Error;return l}if(typeof a<"u")return a;const c=await e.request({method:"eth_maxPriorityFeePerGas"});return lt(c)}catch{const[a,c]=await Promise.all([r?Promise.resolve(r):oe(e,bs,"getBlock")({}),oe(e,Zf,"getGasPrice")({})]);if(typeof a.baseFeePerGas!="bigint")throw new qa;const f=c-a.baseFeePerGas;return f<0n?0n:f}}async function Wc(e,t){var m,p;const{block:r,chain:n=e.chain,request:i,type:s="eip1559"}=t||{},o=await(async()=>{var g,v;return typeof((g=n==null?void 0:n.fees)==null?void 0:g.baseFeeMultiplier)=="function"?n.fees.baseFeeMultiplier({block:r,client:e,request:i}):((v=n==null?void 0:n.fees)==null?void 0:v.baseFeeMultiplier)??1.2})();if(o<1)throw new qp;const c=10**(((m=o.toString().split(".")[1])==null?void 0:m.length)??0),f=g=>g*BigInt(Math.ceil(o*c))/BigInt(c),l=r||await oe(e,bs,"getBlock")({});if(typeof((p=n==null?void 0:n.fees)==null?void 0:p.estimateFeesPerGas)=="function"){const g=await n.fees.estimateFeesPerGas({block:r,client:e,multiply:f,request:i,type:s});if(g!==null)return g}if(s==="eip1559"){if(typeof l.baseFeePerGas!="bigint")throw new qa;const g=typeof(i==null?void 0:i.maxPriorityFeePerGas)=="bigint"?i.maxPriorityFeePerGas:await Jp(e,{block:l,chain:n,request:i}),v=f(l.baseFeePerGas);return{maxFeePerGas:(i==null?void 0:i.maxFeePerGas)??v+g,maxPriorityFeePerGas:g}}return{gasPrice:(i==null?void 0:i.gasPrice)??f(await oe(e,Zf,"getGasPrice")({}))}}async function ed(e,{address:t,blockTag:r="latest",blockNumber:n}){const i=await e.request({method:"eth_getTransactionCount",params:[t,n?Q(n):r]},{dedupe:!!n});return qt(i)}function Wa(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=>Vt(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>Ze(s))}function Ka(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=>Vt(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>Vt(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=>Ze(o))}function Qp(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,f=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+f,a,n)}function Zp(e,t,r){return e&t^~e&r}function ey(e,t,r){return e&t^e&r^t&r}let ty=class extends Oa{constructor(t,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=fo(this.buffer)}update(t){Jn(this);const{view:r,buffer:n,blockLen:i}=this;t=ks(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=fo(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),kf(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 h=o;h<i;h++)r[h]=0;Qp(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=fo(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],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 ry=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]),er=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),tr=new Uint32Array(64);let ny=class extends ty{constructor(t=32){super(64,t,8,!1),this.A=er[0]|0,this.B=er[1]|0,this.C=er[2]|0,this.D=er[3]|0,this.E=er[4]|0,this.F=er[5]|0,this.G=er[6]|0,this.H=er[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 h=0;h<16;h++,r+=4)tr[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const m=tr[h-15],p=tr[h-2],g=gt(m,7)^gt(m,18)^m>>>3,v=gt(p,17)^gt(p,19)^p>>>10;tr[h]=v+tr[h-7]+g+tr[h-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const m=gt(a,6)^gt(a,11)^gt(a,25),p=l+m+Zp(a,c,f)+ry[h]+tr[h]|0,v=(gt(n,2)^gt(n,13)^gt(n,22))+ey(n,i,s)|0;l=f,f=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+v|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,f=f+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,f,l)}roundClean(){tr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const td=If(()=>new ny);function Gn(e,t){const r=t||"hex",n=td(zt(e,{strict:!1})?Pi(e):e);return r==="bytes"?n:J(n)}function iy(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=Gn(t,"bytes");return i.set([r],0),n==="bytes"?i:Ze(i)}function rd(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const s of t)i.push(iy({commitment:s,to:n,version:r}));return i}const Kc=6,nd=32,Ya=4096,id=nd*Ya,Yc=id*Kc-1-1*Ya*Kc,sd=1;class sy extends ${constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class od extends ${constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class oy extends ${constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class ay extends ${constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${sd}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function cy(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?Vt(e.data):e.data,n=Ie(r);if(!n)throw new od;if(n>Yc)throw new sy({maxSize:Yc,size:n});const i=[];let s=!0,o=0;for(;s;){const a=$a(new Uint8Array(id));let c=0;for(;c<Ya;){const f=r.slice(o,o+(nd-1));if(a.pushByte(0),a.pushBytes(f),f.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=>Ze(a.bytes))}function ad(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??cy({data:t,to:n}),s=e.commitments??Wa({blobs:i,kzg:r,to:n}),o=e.proofs??Ka({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 cd(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 Ep({transaction:e})}async function Oi(e){const t=await e.request({method:"eth_chainId"},{dedupe:!0});return qt(t)}const ud=["blobVersionedHashes","chainId","fees","gas","nonce","type"],Xc=new Map;async function Xa(e,t){const{account:r=e.account,blobs:n,chain:i,gas:s,kzg:o,nonce:a,nonceManager:c,parameters:f=ud,type:l}=t,h=r&&Ne(r),m={...t,...h?{from:h==null?void 0:h.address}:{}};let p;async function g(){return p||(p=await oe(e,bs,"getBlock")({blockTag:"latest"}),p)}let v;async function x(){return v||(i?i.id:typeof t.chainId<"u"?t.chainId:(v=await oe(e,Oi,"getChainId")({}),v))}if(f.includes("nonce")&&typeof a>"u"&&h)if(c){const I=await x();m.nonce=await c.consume({address:h.address,chainId:I,client:e})}else m.nonce=await oe(e,ed,"getTransactionCount")({address:h.address,blockTag:"pending"});if((f.includes("blobVersionedHashes")||f.includes("sidecars"))&&n&&o){const I=Wa({blobs:n,kzg:o});if(f.includes("blobVersionedHashes")){const k=rd({commitments:I,to:"hex"});m.blobVersionedHashes=k}if(f.includes("sidecars")){const k=Ka({blobs:n,commitments:I,kzg:o}),A=ad({blobs:n,commitments:I,proofs:k,to:"hex"});m.sidecars=A}}if(f.includes("chainId")&&(m.chainId=await x()),(f.includes("fees")||f.includes("type"))&&typeof l>"u")try{m.type=cd(m)}catch{let I=Xc.get(e.uid);if(typeof I>"u"){const k=await g();I=typeof(k==null?void 0:k.baseFeePerGas)=="bigint",Xc.set(e.uid,I)}m.type=I?"eip1559":"legacy"}if(f.includes("fees"))if(m.type!=="legacy"&&m.type!=="eip2930"){if(typeof m.maxFeePerGas>"u"||typeof m.maxPriorityFeePerGas>"u"){const I=await g(),{maxFeePerGas:k,maxPriorityFeePerGas:A}=await Wc(e,{block:I,chain:i,request:m});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas<A)throw new Vp({maxPriorityFeePerGas:A});m.maxPriorityFeePerGas=A,m.maxFeePerGas=k}}else{if(typeof t.maxFeePerGas<"u"||typeof t.maxPriorityFeePerGas<"u")throw new qa;if(typeof t.gasPrice>"u"){const I=await g(),{gasPrice:k}=await Wc(e,{block:I,chain:i,request:m,type:"legacy"});m.gasPrice=k}}return f.includes("gas")&&typeof s>"u"&&(m.gas=await oe(e,fd,"estimateGas")({...m,account:h&&{address:h.address,type:"json-rpc"}})),Ci(m),delete m.parameters,m}async function uy(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=r?Q(r):void 0,s=await e.request({method:"eth_getBalance",params:[t,i||n]});return BigInt(s)}async function fd(e,t){var i,s,o;const{account:r=e.account}=t,n=r?Ne(r):void 0;try{let V=function(ne){const{block:he,request:_e,rpcStateOverride:Te}=ne;return e.request({method:"eth_estimateGas",params:Te?[_e,he??"latest",Te]:he?[_e,he]:[_e]})};const{accessList:a,authorizationList:c,blobs:f,blobVersionedHashes:l,blockNumber:h,blockTag:m,data:p,gas:g,gasPrice:v,maxFeePerBlobGas:x,maxFeePerGas:I,maxPriorityFeePerGas:k,nonce:A,value:E,stateOverride:T,...S}=await Xa(e,{...t,parameters:(n==null?void 0:n.type)==="local"?void 0:["blobVersionedHashes"]}),M=(h?Q(h):void 0)||m,B=Xf(T),W=await(async()=>{if(S.to)return S.to;if(c&&c.length>0)return await Yf({authorization:c[0]}).catch(()=>{throw new $("`to` is required. Could not infer from `authorizationList`")})})();Ci(t);const U=(o=(s=(i=e.chain)==null?void 0:i.formatters)==null?void 0:s.transactionRequest)==null?void 0:o.format,G=(U||Ls)({...Ga(S,{format:U}),from:n==null?void 0:n.address,accessList:a,authorizationList:c,blobs:f,blobVersionedHashes:l,data:p,gas:g,gasPrice:v,maxFeePerBlobGas:x,maxFeePerGas:I,maxPriorityFeePerGas:k,nonce:A,to:W,value:E});let X=BigInt(await V({block:M,request:G,rpcStateOverride:B}));if(c){const ne=await uy(e,{address:G.from}),he=await Promise.all(c.map(async _e=>{const{address:Te}=_e,We=await V({block:M,request:{authorizationList:void 0,data:p,from:n==null?void 0:n.address,to:Te,value:Q(ne)},rpcStateOverride:B}).catch(()=>100000n);return 2n*BigInt(We)}));X+=he.reduce((_e,Te)=>_e+Te,0n)}return X}catch(a){throw Dp(a,{...t,account:n,chain:e.chain})}}async function fy(e,t){const{abi:r,address:n,args:i,functionName:s,dataSuffix:o,...a}=t,c=xn({abi:r,args:i,functionName:s});try{return await oe(e,fd,"estimateGas")({data:`${c}${o?o.replace("0x",""):""}`,to:n,...a})}catch(f){const l=a.account?Ne(a.account):void 0;throw Rs(f,{abi:r,address:n,args:i,docsPath:"/docs/contract/estimateContractGas",functionName:s,sender:l==null?void 0:l.address})}}function Ja(e,t){if(!Le(e,{strict:!1}))throw new et({address:e});if(!Le(t,{strict:!1}))throw new et({address:t});return e.toLowerCase()===t.toLowerCase()}const Jc="/docs/contract/decodeEventLog";function dd(e){const{abi:t,data:r,strict:n,topics:i}=e,s=n??!0,[o,...a]=i;if(!o)throw new Jh({docsPath:Jc});const c=t.length===1?t[0]:t.find(v=>v.type==="event"&&o===Is(kt(v)));if(!(c&&"name"in c)||c.type!=="event")throw new _f(o,{docsPath:Jc});const{name:f,inputs:l}=c,h=l==null?void 0:l.some(v=>!("name"in v&&v.name));let m=h?[]:{};const p=l.filter(v=>"indexed"in v&&v.indexed);for(let v=0;v<p.length;v++){const x=p[v],I=a[v];if(!I)throw new Ca({abiItem:c,param:x});m[h?v:x.name||v]=dy({param:x,value:I})}const g=l.filter(v=>!("indexed"in v&&v.indexed));if(g.length>0){if(r&&r!=="0x")try{const v=Ii(g,r);if(v)if(h)m=[...m,...v];else for(let x=0;x<g.length;x++)m[g[x].name]=v[x]}catch(v){if(s)throw v instanceof gf||v instanceof Df?new ys({abiItem:c,data:r,params:g,size:Ie(r)}):v}else if(s)throw new ys({abiItem:c,data:"0x",params:g,size:0})}return{eventName:f,args:Object.values(m).length>0?m:void 0}}function dy({param:e,value:t}){return e.type==="string"||e.type==="bytes"||e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/)?t:(Ii([e],t)||[])[0]}function ld(e){const{abi:t,args:r,logs:n,strict:i=!0}=e,s=(()=>{if(e.eventName)return Array.isArray(e.eventName)?e.eventName:[e.eventName]})();return n.map(o=>{var a;try{const c=t.find(l=>l.type==="event"&&o.topics[0]===Is(l));if(!c)return null;const f=dd({...o,abi:[c],strict:i});return s&&!s.includes(f.eventName)||!ly({args:f.args,inputs:c.inputs,matchArgs:r})?null:{...f,...o}}catch(c){let f,l;if(c instanceof _f)return null;if(c instanceof ys||c instanceof Ca){if(i)return null;f=c.abiItem.name,l=(a=c.abiItem.inputs)==null?void 0:a.some(h=>!("name"in h&&h.name))}return{...o,args:l?[]:{},eventName:f}}}).filter(Boolean)}function ly(e){const{args:t,inputs:r,matchArgs:n}=e;if(!n)return!0;if(!t)return!1;function i(s,o,a){try{return s.type==="address"?Ja(o,a):s.type==="string"||s.type==="bytes"?vn(Pi(o))===a:o===a}catch{return!1}}return Array.isArray(t)&&Array.isArray(n)?n.every((s,o)=>{if(s==null)return!0;const a=r[o];return a?(Array.isArray(s)?s:[s]).some(f=>i(a,f,t[o])):!1}):typeof t=="object"&&!Array.isArray(t)&&typeof n=="object"&&!Array.isArray(n)?Object.entries(n).every(([s,o])=>{if(o==null)return!0;const a=r.find(f=>f.name===s);return a?(Array.isArray(o)?o:[o]).some(f=>i(a,f,t[s])):!1}):!1}function _i(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}:{}}}async function hy(e,{address:t,blockHash:r,fromBlock:n,toBlock:i,event:s,events:o,args:a,strict:c}={}){const f=c??!1,l=o??(s?[s]:void 0);let h=[];l&&(h=[l.flatMap(v=>Fa({abi:[v],eventName:v.name,args:o?void 0:a}))],s&&(h=h[0]));let m;r?m=await e.request({method:"eth_getLogs",params:[{address:t,topics:h,blockHash:r}]}):m=await e.request({method:"eth_getLogs",params:[{address:t,topics:h,fromBlock:typeof n=="bigint"?Q(n):n,toBlock:typeof i=="bigint"?Q(i):i}]});const p=m.map(g=>_i(g));return l?ld({abi:l,args:a,logs:p,strict:f}):p}async function hd(e,t){const{abi:r,address:n,args:i,blockHash:s,eventName:o,fromBlock:a,toBlock:c,strict:f}=t,l=o?En({abi:r,name:o}):void 0,h=l?void 0:r.filter(m=>m.type==="event");return oe(e,hy,"getLogs")({address:n,args:i,blockHash:s,event:l,events:h,fromBlock:a,toBlock:c,strict:f})}const po="/docs/contract/decodeFunctionResult";function Qa(e){const{abi:t,args:r,functionName:n,data:i}=e;let s=t[0];if(n){const a=En({abi:t,args:r,name:n});if(!a)throw new Xn(n,{docsPath:po});s=a}if(s.type!=="function")throw new Xn(void 0,{docsPath:po});if(!s.outputs)throw new vf(s.name,{docsPath:po});const o=Ii(s.outputs,i);if(o&&o.length>1)return o;if(o&&o.length===1)return o[0]}const Qc=[{inputs:[{components:[{name:"target",type:"address"},{name:"allowFailure",type:"bool"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate3",outputs:[{components:[{name:"success",type:"bool"},{name:"returnData",type:"bytes"}],name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"}],py=[{name:"query",type:"function",stateMutability:"view",inputs:[{type:"tuple[]",name:"queries",components:[{type:"address",name:"sender"},{type:"string[]",name:"urls"},{type:"bytes",name:"data"}]}],outputs:[{type:"bool[]",name:"failures"},{type:"bytes[]",name:"responses"}]},{name:"HttpError",type:"error",inputs:[{type:"uint16",name:"status"},{type:"string",name:"message"}]}],yy="0x82ad56cb",my="0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe",by="0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe";class fa extends ${constructor({blockNumber:t,chain:r,contract:n}){super(`Chain "${r.name}" does not support contract "${n.name}".`,{metaMessages:["This could be due to any of the following:",...t&&n.blockCreated&&n.blockCreated>t?[`- The contract "${n.name}" was not deployed until block ${n.blockCreated} (current block ${t}).`]:[`- The chain does not have the contract "${n.name}" configured.`]],name:"ChainDoesNotSupportContract"})}}class gy extends ${constructor({chain:t,currentChainId:r}){super(`The current chain of the wallet (id: ${r}) does not match the target chain for the transaction (id: ${t.id} – ${t.name}).`,{metaMessages:[`Current Chain ID: ${r}`,`Expected Chain ID: ${t.id} – ${t.name}`],name:"ChainMismatchError"})}}class wy extends ${constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join(`
|
|
40
|
+
`),{name:"ChainNotFoundError"})}}class pd extends ${constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class Fs extends ${constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const yo="/docs/contract/encodeDeployData";function Za(e){const{abi:t,args:r,bytecode:n}=e;if(!r||r.length===0)return n;const i=t.find(o=>"type"in o&&o.type==="constructor");if(!i)throw new qh({docsPath:yo});if(!("inputs"in i))throw new Bc({docsPath:yo});if(!i.inputs||i.inputs.length===0)throw new Bc({docsPath:yo});const s=Cs(i.inputs,r);return Ct([n,s])}function _y({blockNumber:e,chain:t,contract:r}){var i;const n=(i=t==null?void 0:t.contracts)==null?void 0:i[r];if(!n)throw new fa({chain:t,contract:{name:r}});if(e&&n.blockCreated&&n.blockCreated>e)throw new fa({blockNumber:e,chain:t,contract:{name:r,blockCreated:n.blockCreated}});return n.address}function vy(e,{docsPath:t,...r}){const n=(()=>{const i=ja(e,r);return i instanceof Us?e:i})();return new Pp(n,{docsPath:t,...r})}function yd(){let e=()=>{},t=()=>{};return{promise:new Promise((n,i)=>{e=n,t=i}),resolve:e,reject:t}}const mo=new Map;function Ey({fn:e,id:t,shouldSplitBatch:r,wait:n=0,sort:i}){const s=async()=>{const l=c();o();const h=l.map(({args:m})=>m);h.length!==0&&e(h).then(m=>{i&&Array.isArray(m)&&m.sort(i);for(let p=0;p<l.length;p++){const{resolve:g}=l[p];g==null||g([m[p],m])}}).catch(m=>{for(let p=0;p<l.length;p++){const{reject:g}=l[p];g==null||g(m)}})},o=()=>mo.delete(t),a=()=>c().map(({args:l})=>l),c=()=>mo.get(t)||[],f=l=>mo.set(t,[...c(),l]);return{flush:o,async schedule(l){const{promise:h,resolve:m,reject:p}=yd();return(r==null?void 0:r([...a(),l]))&&s(),c().length>0?(f({args:l,resolve:m,reject:p}),h):(f({args:l,resolve:m,reject:p}),setTimeout(s,n),h)}}}async function ec(e,t){var U,D,G,V;const{account:r=e.account,batch:n=!!((U=e.batch)!=null&&U.multicall),blockNumber:i,blockTag:s="latest",accessList:o,blobs:a,code:c,data:f,factory:l,factoryData:h,gas:m,gasPrice:p,maxFeePerBlobGas:g,maxFeePerGas:v,maxPriorityFeePerGas:x,nonce:I,to:k,value:A,stateOverride:E,...T}=t,S=r?Ne(r):void 0;if(c&&(l||h))throw new $("Cannot provide both `code` & `factory`/`factoryData` as parameters.");if(c&&k)throw new $("Cannot provide both `code` & `to` as parameters.");const N=c&&f,M=l&&h&&k&&f,B=N||M,W=N?Sy({code:c,data:f}):M?Py({data:f,factory:l,factoryData:h,to:k}):f;try{Ci(t);const ne=(i?Q(i):void 0)||s,he=Xf(E),_e=(V=(G=(D=e.chain)==null?void 0:D.formatters)==null?void 0:G.transactionRequest)==null?void 0:V.format,We=(_e||Ls)({...Ga(T,{format:_e}),from:S==null?void 0:S.address,accessList:o,blobs:a,data:W,gas:m,gasPrice:p,maxFeePerBlobGas:g,maxFeePerGas:v,maxPriorityFeePerGas:x,nonce:I,to:B?void 0:k,value:A});if(n&&xy({request:We})&&!he)try{return await Ay(e,{...We,blockNumber:i,blockTag:s})}catch(ye){if(!(ye instanceof pd)&&!(ye instanceof fa))throw ye}const fe=await e.request({method:"eth_call",params:he?[We,ne,he]:[We,ne]});return fe==="0x"?{data:void 0}:{data:fe}}catch(X){const ne=Ty(X),{offchainLookup:he,offchainLookupSignature:_e}=await Promise.resolve().then(()=>require("./ccip-DWt0iM5p.cjs"));if(e.ccipRead!==!1&&(ne==null?void 0:ne.slice(0,10))===_e&&k)return{data:await he(e,{data:ne,to:k})};throw B&&(ne==null?void 0:ne.slice(0,10))==="0x101bb98d"?new Bp({factory:l}):vy(X,{...t,account:S,chain:e.chain})}}function xy({request:e}){const{data:t,to:r,...n}=e;return!(!t||t.startsWith(yy)||!r||Object.values(n).filter(i=>typeof i<"u").length>0)}async function Ay(e,t){var v;const{batchSize:r=1024,wait:n=0}=typeof((v=e.batch)==null?void 0:v.multicall)=="object"?e.batch.multicall:{},{blockNumber:i,blockTag:s="latest",data:o,multicallAddress:a,to:c}=t;let f=a;if(!f){if(!e.chain)throw new pd;f=_y({blockNumber:i,chain:e.chain,contract:"multicall3"})}const h=(i?Q(i):void 0)||s,{schedule:m}=Ey({id:`${e.uid}.${h}`,wait:n,shouldSplitBatch(x){return x.reduce((k,{data:A})=>k+(A.length-2),0)>r*2},fn:async x=>{const I=x.map(E=>({allowFailure:!0,callData:E.data,target:E.to})),k=xn({abi:Qc,args:[I],functionName:"aggregate3"}),A=await e.request({method:"eth_call",params:[{data:k,to:f},h]});return Qa({abi:Qc,args:[I],functionName:"aggregate3",data:A||"0x"})}}),[{returnData:p,success:g}]=await m({data:o,to:c});if(!g)throw new qf({data:p});return p==="0x"?{data:void 0}:{data:p}}function Sy(e){const{code:t,data:r}=e;return Za({abi:yf(["constructor(bytes, bytes)"]),bytecode:my,args:[t,r]})}function Py(e){const{data:t,factory:r,factoryData:n,to:i}=e;return Za({abi:yf(["constructor(address, bytes, address, bytes)"]),bytecode:by,args:[i,t,r,n]})}function Ty(e){var r;if(!(e instanceof $))return;const t=e.walk();return typeof(t==null?void 0:t.data)=="object"?(r=t.data)==null?void 0:r.data:t.data}async function ky(e,t){const{abi:r,address:n,args:i,functionName:s,...o}=t,a=xn({abi:r,args:i,functionName:s});try{const{data:c}=await oe(e,ec,"call")({...o,data:a,to:n});return Qa({abi:r,args:i,functionName:s,data:c||"0x"})}catch(c){throw Rs(c,{abi:r,address:n,args:i,docsPath:"/docs/contract/readContract",functionName:s})}}async function Iy(e,t){const{abi:r,address:n,args:i,dataSuffix:s,functionName:o,...a}=t,c=a.account?Ne(a.account):e.account,f=xn({abi:r,args:i,functionName:o});try{const{data:l}=await oe(e,ec,"call")({batch:!1,data:`${f}${s?s.replace("0x",""):""}`,to:n,...a,account:c}),h=Qa({abi:r,args:i,functionName:o,data:l||"0x"}),m=r.filter(p=>"name"in p&&p.name===t.functionName);return{result:h,request:{abi:m,address:n,args:i,dataSuffix:s,functionName:o,...a,account:c}}}catch(l){throw Rs(l,{abi:r,address:n,args:i,docsPath:"/docs/contract/simulateContract",functionName:o,sender:c==null?void 0:c.address})}}const bo=new Map,Zc=new Map;let By=0;function da(e,t,r){const n=++By,i=()=>bo.get(e)||[],s=()=>{const l=i();bo.set(e,l.filter(h=>h.id!==n))},o=()=>{const l=i();if(!l.some(m=>m.id===n))return;const h=Zc.get(e);l.length===1&&h&&h(),s()},a=i();if(bo.set(e,[...a,{id:n,fns:t}]),a&&a.length>0)return o;const c={};for(const l in t)c[l]=(...h)=>{var p,g;const m=i();if(m.length!==0)for(const v of m)(g=(p=v.fns)[l])==null||g.call(p,...h)};const f=r(c);return typeof f=="function"&&Zc.set(e,f),o}async function la(e){return new Promise(t=>setTimeout(t,e))}function md(e,{emitOnBegin:t,initialWaitTime:r,interval:n}){let i=!0;const s=()=>i=!1;return(async()=>{let a;a=await e({unpoll:s});const c=await(r==null?void 0:r(a))??n;await la(c);const f=async()=>{i&&(await e({unpoll:s}),await la(n),f())};f()})(),s}const Cy=new Map,Oy=new Map;function Ry(e){const t=(i,s)=>({clear:()=>s.delete(i),get:()=>s.get(i),set:o=>s.set(i,o)}),r=t(e,Cy),n=t(e,Oy);return{clear:()=>{r.clear(),n.clear()},promise:r,response:n}}async function Uy(e,{cacheKey:t,cacheTime:r=Number.POSITIVE_INFINITY}){const n=Ry(t),i=n.response.get();if(i&&r>0&&new Date().getTime()-i.created.getTime()<r)return i.data;let s=n.promise.get();s||(s=e(),n.promise.set(s));try{const o=await s;return n.response.set({created:new Date,data:o}),o}finally{n.promise.clear()}}const Ly=e=>`blockNumber.${e}`;async function Ny(e,{cacheTime:t=e.cacheTime}={}){const r=await Uy(()=>e.request({method:"eth_blockNumber"}),{cacheKey:Ly(e.uid),cacheTime:t});return BigInt(r)}async function Fy(e,{filter:t}){const r="strict"in t&&t.strict,n=await t.request({method:"eth_getFilterChanges",params:[t.id]});if(typeof n[0]=="string")return n;const i=n.map(s=>_i(s));return!("abi"in t)||!t.abi?i:ld({abi:t.abi,logs:i,strict:r})}async function $y(e,{filter:t}){return t.request({method:"eth_uninstallFilter",params:[t.id]})}function My(e,t){const{abi:r,address:n,args:i,batch:s=!0,eventName:o,fromBlock:a,onError:c,onLogs:f,poll:l,pollingInterval:h=e.pollingInterval,strict:m}=t;return(typeof l<"u"?l:typeof a=="bigint"?!0:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket"))?(()=>{const x=m??!1,I=It(["watchContractEvent",n,i,s,e.uid,o,h,x,a]);return da(I,{onLogs:f,onError:c},k=>{let A;a!==void 0&&(A=a-1n);let E,T=!1;const S=md(async()=>{var N;if(!T){try{E=await oe(e,Mf,"createContractEventFilter")({abi:r,address:n,args:i,eventName:o,strict:x,fromBlock:a})}catch{}T=!0;return}try{let M;if(E)M=await oe(e,Fy,"getFilterChanges")({filter:E});else{const B=await oe(e,Ny,"getBlockNumber")({});A&&A<B?M=await oe(e,hd,"getContractEvents")({abi:r,address:n,args:i,eventName:o,fromBlock:A+1n,toBlock:B,strict:x}):M=[],A=B}if(M.length===0)return;if(s)k.onLogs(M);else for(const B of M)k.onLogs([B])}catch(M){E&&M instanceof ln&&(T=!1),(N=k.onError)==null||N.call(k,M)}},{emitOnBegin:!0,interval:h});return async()=>{E&&await oe(e,$y,"uninstallFilter")({filter:E}),S()}})})():(()=>{const x=m??!1,I=It(["watchContractEvent",n,i,s,e.uid,o,h,x]);let k=!0,A=()=>k=!1;return da(I,{onLogs:f,onError:c},E=>((async()=>{try{const T=(()=>{if(e.transport.type==="fallback"){const M=e.transport.transports.find(B=>B.config.type==="webSocket");return M?M.value:e.transport}return e.transport})(),S=o?Fa({abi:r,eventName:o,args:i}):[],{unsubscribe:N}=await T.subscribe({params:["logs",{address:n,topics:S}],onData(M){var W;if(!k)return;const B=M.result;try{const{eventName:U,args:D}=dd({abi:r,data:B.data,topics:B.topics,strict:m}),G=_i(B,{args:D,eventName:U});E.onLogs([G])}catch(U){let D,G;if(U instanceof ys||U instanceof Ca){if(m)return;D=U.abiItem.name,G=(W=U.abiItem.inputs)==null?void 0:W.some(X=>!("name"in X&&X.name))}const V=_i(B,{args:G?[]:{},eventName:D});E.onLogs([V])}},onError(M){var B;(B=E.onError)==null||B.call(E,M)}});A=N,k||A()}catch(T){c==null||c(T)}})(),()=>A()))})()}class br extends ${constructor({docsPath:t}={}){super(["Could not find an Account to execute with this Action.","Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client."].join(`
|
|
41
|
+
`),{docsPath:t,docsSlug:"account",name:"AccountNotFoundError"})}}class os extends ${constructor({docsPath:t,metaMessages:r,type:n}){super(`Account type "${n}" is not supported.`,{docsPath:t,metaMessages:r,name:"AccountTypeNotSupportedError"})}}function bd({chain:e,currentChainId:t}){if(!e)throw new wy;if(t!==e.id)throw new gy({chain:e,currentChainId:t})}function gd(e,{docsPath:t,...r}){const n=(()=>{const i=ja(e,r);return i instanceof Us?e:i})();return new Ap(n,{docsPath:t,...r})}async function wd(e,{serializedTransaction:t}){return e.request({method:"eth_sendRawTransaction",params:[t]},{retryCount:0})}const go=new Bs(128);async function tc(e,t){var I,k,A,E;const{account:r=e.account,chain:n=e.chain,accessList:i,authorizationList:s,blobs:o,data:a,gas:c,gasPrice:f,maxFeePerBlobGas:l,maxFeePerGas:h,maxPriorityFeePerGas:m,nonce:p,value:g,...v}=t;if(typeof r>"u")throw new br({docsPath:"/docs/actions/wallet/sendTransaction"});const x=r?Ne(r):null;try{Ci(t);const T=await(async()=>{if(t.to)return t.to;if(t.to!==null&&s&&s.length>0)return await Yf({authorization:s[0]}).catch(()=>{throw new $("`to` is required. Could not infer from `authorizationList`.")})})();if((x==null?void 0:x.type)==="json-rpc"||x===null){let S;n!==null&&(S=await oe(e,Oi,"getChainId")({}),bd({currentChainId:S,chain:n}));const N=(A=(k=(I=e.chain)==null?void 0:I.formatters)==null?void 0:k.transactionRequest)==null?void 0:A.format,B=(N||Ls)({...Ga(v,{format:N}),accessList:i,authorizationList:s,blobs:o,chainId:S,data:a,from:x==null?void 0:x.address,gas:c,gasPrice:f,maxFeePerBlobGas:l,maxFeePerGas:h,maxPriorityFeePerGas:m,nonce:p,to:T,value:g}),W=go.get(e.uid),U=W?"wallet_sendTransaction":"eth_sendTransaction";try{return await e.request({method:U,params:[B]},{retryCount:0})}catch(D){if(W===!1)throw D;const G=D;if(G.name==="InvalidInputRpcError"||G.name==="InvalidParamsRpcError"||G.name==="MethodNotFoundRpcError"||G.name==="MethodNotSupportedRpcError")return await e.request({method:"wallet_sendTransaction",params:[B]},{retryCount:0}).then(V=>(go.set(e.uid,!0),V)).catch(V=>{const X=V;throw X.name==="MethodNotFoundRpcError"||X.name==="MethodNotSupportedRpcError"?(go.set(e.uid,!1),G):X});throw G}}if((x==null?void 0:x.type)==="local"){const S=await oe(e,Xa,"prepareTransactionRequest")({account:x,accessList:i,authorizationList:s,blobs:o,chain:n,data:a,gas:c,gasPrice:f,maxFeePerBlobGas:l,maxFeePerGas:h,maxPriorityFeePerGas:m,nonce:p,nonceManager:x.nonceManager,parameters:[...ud,"sidecars"],value:g,...v,to:T}),N=(E=n==null?void 0:n.serializers)==null?void 0:E.transaction,M=await x.signTransaction(S,{serializer:N});return await oe(e,wd,"sendRawTransaction")({serializedTransaction:M})}throw(x==null?void 0:x.type)==="smart"?new os({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:"/docs/actions/bundler/sendUserOperation",type:"smart"}):new os({docsPath:"/docs/actions/wallet/sendTransaction",type:x==null?void 0:x.type})}catch(T){throw T instanceof os?T:gd(T,{...t,account:x,chain:t.chain||void 0})}}async function _d(e,t){const{abi:r,account:n=e.account,address:i,args:s,dataSuffix:o,functionName:a,...c}=t;if(typeof n>"u")throw new br({docsPath:"/docs/contract/writeContract"});const f=n?Ne(n):null,l=xn({abi:r,args:s,functionName:a});try{return await oe(e,tc,"sendTransaction")({data:`${l}${o?o.replace("0x",""):""}`,to:i,account:f,...c})}catch(h){throw Rs(h,{abi:r,address:i,args:s,docsPath:"/docs/contract/writeContract",functionName:a,sender:f==null?void 0:f.address})}}function wo({abi:e,address:t,client:r}){const n=r,[i,s]=n?"public"in n&&"wallet"in n?[n.public,n.wallet]:"public"in n?[n.public,void 0]:"wallet"in n?[void 0,n.wallet]:[n,n]:[void 0,void 0],o=i!=null,a=s!=null,c={};let f=!1,l=!1,h=!1;for(const m of e)if(m.type==="function"?m.stateMutability==="view"||m.stateMutability==="pure"?f=!0:l=!0:m.type==="event"&&(h=!0),f&&l&&h)break;return o&&(f&&(c.read=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(i,ky,"readContract")({abi:e,address:t,functionName:p,args:v,...x})}}})),l&&(c.simulate=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(i,Iy,"simulateContract")({abi:e,address:t,functionName:p,args:v,...x})}}})),h&&(c.createEventFilter=new Proxy({},{get(m,p){return(...g)=>{const v=e.find(k=>k.type==="event"&&k.name===p),{args:x,options:I}=_o(g,v);return oe(i,Mf,"createContractEventFilter")({abi:e,address:t,eventName:p,args:x,...I})}}}),c.getEvents=new Proxy({},{get(m,p){return(...g)=>{const v=e.find(k=>k.type==="event"&&k.name===p),{args:x,options:I}=_o(g,v);return oe(i,hd,"getContractEvents")({abi:e,address:t,eventName:p,args:x,...I})}}}),c.watchEvent=new Proxy({},{get(m,p){return(...g)=>{const v=e.find(k=>k.type==="event"&&k.name===p),{args:x,options:I}=_o(g,v);return oe(i,My,"watchContractEvent")({abi:e,address:t,eventName:p,args:x,...I})}}}))),a&&l&&(c.write=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(s,_d,"writeContract")({abi:e,address:t,functionName:p,args:v,...x})}}})),(o||a)&&l&&(c.estimateGas=new Proxy({},{get(m,p){return(...g)=>{const{args:v,options:x}=zi(g);return oe(i??s,fy,"estimateContractGas")({abi:e,address:t,functionName:p,args:v,...x,account:x.account??s.account})}}})),c.address=t,c.abi=e,c}function zi(e){const t=e.length&&Array.isArray(e[0]),r=t?e[0]:[],n=(t?e[1]:e[0])??{};return{args:r,options:n}}function _o(e,t){let r=!1;Array.isArray(e[0])?r=!0:e.length===1?r=t.inputs.some(s=>s.indexed):e.length===2&&(r=!0);const n=r?e[0]:void 0,i=(r?e[1]:e[0])??{};return{args:n,options:i}}const vd={"0x0":"reverted","0x1":"success"};function Hy(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=>_i(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?qt(e.transactionIndex):null,status:e.status?vd[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 Dy=za("transactionReceipt",Hy);async function Ed(e,t){const{atomic:r=!1,chainId:n,receipts:i,version:s="2.0.0",...o}=await e.request({method:"wallet_getCallsStatus",params:[t.id]}),[a,c]=(()=>{const f=o.status;return f>=100&&f<200?["pending",f]:f>=200&&f<300?["success",f]:f>=300&&f<700?["failure",f]:f==="CONFIRMED"?["success",200]:f==="PENDING"?["pending",100]:[void 0,f]})();return{...o,atomic:r,chainId:n?qt(n):void 0,receipts:(i==null?void 0:i.map(f=>({...f,blockNumber:lt(f.blockNumber),gasUsed:lt(f.gasUsed),status:vd[f.status]})))??[],statusCode:c,status:a,version:s}}async function jy(e,t){const{id:r,pollingInterval:n=e.pollingInterval,status:i=({statusCode:m})=>m>=200,timeout:s=6e4}=t,o=It(["waitForCallsStatus",e.uid,r]),{promise:a,resolve:c,reject:f}=yd();let l;const h=da(o,{resolve:c,reject:f},m=>{const p=md(async()=>{const g=v=>{clearTimeout(l),p(),v(),h()};try{const v=await Ed(e,{id:r});if(!i(v))return;g(()=>m.resolve(v))}catch(v){g(()=>m.reject(v))}},{interval:n,emitOnBegin:!0});return p});return l=s?setTimeout(()=>{h(),clearTimeout(l),f(new Gy({id:r}))},s):void 0,await a}class Gy extends ${constructor({id:t}){super(`Timed out while waiting for call bundle with id "${t}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}const ha=256;let qi=ha,Vi;function xd(e=11){if(!Vi||qi+e>ha*2){Vi="",qi=0;for(let t=0;t<ha;t++)Vi+=(256+Math.random()*256|0).toString(16).substring(1)}return Vi.substring(qi,qi+++e)}function zy(e){const{batch:t,cacheTime:r=e.pollingInterval??4e3,ccipRead:n,key:i="base",name:s="Base Client",pollingInterval:o=4e3,type:a="base"}=e,c=e.chain,f=e.account?Ne(e.account):void 0,{config:l,request:h,value:m}=e.transport({chain:c,pollingInterval:o}),p={...l,...m},g={account:f,batch:t,cacheTime:r,ccipRead:n,chain:c,key:i,name:s,pollingInterval:o,request:h,transport:p,type:a,uid:xd()};function v(x){return I=>{const k=I(x);for(const E in g)delete k[E];const A={...x,...k};return Object.assign(A,{extend:v(A)})}}return Object.assign(g,{extend:v(g)})}const Wi=new Bs(8192);function qy(e,{enabled:t=!0,id:r}){if(!t||!r)return e();if(Wi.get(r))return Wi.get(r);const n=e().finally(()=>Wi.delete(r));return Wi.set(r,n),n}function Vy(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((i,s)=>{const o=async({count:a=0}={})=>{const c=async({error:f})=>{const l=typeof t=="function"?t({count:a,error:f}):t;l&&await la(l),o({count:a+1})};try{const f=await e();i(f)}catch(f){if(a<r&&await n({count:a,error:f}))return c({error:f});s(f)}};o()})}function Wy(e,t={}){return async(r,n={})=>{var h;const{dedupe:i=!1,methods:s,retryDelay:o=150,retryCount:a=3,uid:c}={...t,...n},{method:f}=r;if((h=s==null?void 0:s.exclude)!=null&&h.includes(f))throw new Tr(new Error("method not supported"),{method:f});if(s!=null&&s.include&&!s.include.includes(f))throw new Tr(new Error("method not supported"),{method:f});const l=i?Ts(`${c}.${It(r)}`):void 0;return qy(()=>Vy(async()=>{try{return await e(r)}catch(m){const p=m;switch(p.code){case Zn.code:throw new Zn(p);case ei.code:throw new ei(p);case ti.code:throw new ti(p,{method:r.method});case ri.code:throw new ri(p);case Ur.code:throw new Ur(p);case ln.code:throw new ln(p);case ni.code:throw new ni(p);case ii.code:throw new ii(p);case si.code:throw new si(p);case Tr.code:throw new Tr(p,{method:r.method});case hn.code:throw new hn(p);case oi.code:throw new oi(p);case sn.code:throw new sn(p);case ai.code:throw new ai(p);case ci.code:throw new ci(p);case ui.code:throw new ui(p);case fi.code:throw new fi(p);case di.code:throw new di(p);case li.code:throw new li(p);case hi.code:throw new hi(p);case pi.code:throw new pi(p);case yi.code:throw new yi(p);case mi.code:throw new mi(p);case bi.code:throw new bi(p);case gi.code:throw new gi(p);case 5e3:throw new sn(p);default:throw m instanceof $?m:new Op(p)}}},{delay:({count:m,error:p})=>{var g;if(p&&p instanceof Da){const v=(g=p==null?void 0:p.headers)==null?void 0:g.get("Retry-After");if(v!=null&&v.match(/\d/))return Number.parseInt(v)*1e3}return~~(1<<m)*o},retryCount:a,shouldRetry:({error:m})=>Ky(m)}),{enabled:i,id:l})}}function Ky(e){return"code"in e&&typeof e.code=="number"?e.code===-1||e.code===hn.code||e.code===Ur.code:e instanceof Da&&e.status?e.status===403||e.status===408||e.status===413||e.status===429||e.status===500||e.status===502||e.status===503||e.status===504:!0}function Yy({key:e,methods:t,name:r,request:n,retryCount:i=3,retryDelay:s=150,timeout:o,type:a},c){const f=xd();return{config:{key:e,methods:t,name:r,request:n,retryCount:i,retryDelay:s,timeout:o,type:a},request:Wy(n,{methods:t,retryCount:i,retryDelay:s,uid:f}),value:c}}function vo(e,t={}){const{key:r="custom",methods:n,name:i="Custom Provider",retryDelay:s}=t;return({retryCount:o})=>Yy({key:r,methods:n,name:i,request:e.request.bind(e),retryCount:t.retryCount??o,retryDelay:s,type:"custom"})}function Ot(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}class Xy extends ${constructor({domain:t}){super(`Invalid domain "${It(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class Jy extends ${constructor({primaryType:t,types:r}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(r))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class Qy extends ${constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function Zy(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(c,f)=>{const l={...f};for(const h of c){const{name:m,type:p}=h;p==="address"&&(l[m]=l[m].toLowerCase())}return l},o=i.EIP712Domain?t?s(i.EIP712Domain,t):{}:{},a=(()=>{if(n!=="EIP712Domain")return s(i[n],r)})();return It({domain:o,message:a,primaryType:n,types:i})}function em(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(o,a)=>{for(const c of o){const{name:f,type:l}=c,h=a[f],m=l.match(Ff);if(m&&(typeof h=="number"||typeof h=="bigint")){const[v,x,I]=m;Q(h,{signed:x==="int",size:Number.parseInt(I)/8})}if(l==="address"&&typeof h=="string"&&!Le(h))throw new et({address:h});const p=l.match(z0);if(p){const[v,x]=p;if(x&&Ie(h)!==Number.parseInt(x))throw new e0({expectedSize:Number.parseInt(x),givenSize:Ie(h)})}const g=i[l];g&&(rm(l),s(g,h))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new Xy({domain:t});s(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])s(i[n],r);else throw new Jy({primaryType:n,types:i})}function tm({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},(typeof(e==null?void 0:e.chainId)=="number"||typeof(e==null?void 0:e.chainId)=="bigint")&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}function rm(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new Qy({type:e})}function nm(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!Le(i))throw new et({address:i});if(n<0)throw new Fs({chainId:n})}rc(e)}function im(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new od;for(const r of t){const n=Ie(r),i=qt(dn(r,0,1));if(n!==32)throw new oy({hash:r,size:n});if(i!==sd)throw new ay({hash:r,version:i})}}rc(e)}function rc(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Fs({chainId:t});if(i&&!Le(i))throw new et({address:i});if(n&&n>Ns)throw new Lr({maxFeePerGas:n});if(r&&n&&r>n)throw new wi({maxFeePerGas:n,maxPriorityFeePerGas:r})}function sm(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new Fs({chainId:t});if(s&&!Le(s))throw new et({address:s});if(r||i)throw new $("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Ns)throw new Lr({maxFeePerGas:n})}function om(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!Le(s))throw new et({address:s});if(typeof t<"u"&&t<=0)throw new Fs({chainId:t});if(r||i)throw new $("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Ns)throw new Lr({maxFeePerGas:n})}function $s(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 xp({storageKey:i[s]});if(!Le(n,{strict:!1}))throw new et({address:n});t.push([n,i])}return t}function am(e,t){const r=cd(e);return r==="eip1559"?fm(e,t):r==="eip2930"?dm(e,t):r==="eip4844"?um(e,t):r==="eip7702"?cm(e,t):lm(e,t)}function cm(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:c,maxPriorityFeePerGas:f,accessList:l,data:h}=e;nm(e);const m=$s(l),p=hm(r);return Ct(["0x04",pr([J(n),s?J(s):"0x",f?J(f):"0x",c?J(c):"0x",i?J(i):"0x",o??"0x",a?J(a):"0x",h??"0x",m,p,...Ri(e,t)])])}function um(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:f,accessList:l,data:h}=e;im(e);let m=e.blobVersionedHashes,p=e.sidecars;if(e.blobs&&(typeof m>"u"||typeof p>"u")){const A=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(S=>Ze(S)),E=e.kzg,T=Wa({blobs:A,kzg:E});if(typeof m>"u"&&(m=rd({commitments:T})),typeof p>"u"){const S=Ka({blobs:A,commitments:T,kzg:E});p=ad({blobs:A,commitments:T,proofs:S})}}const g=$s(l),v=[J(r),i?J(i):"0x",f?J(f):"0x",c?J(c):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",h??"0x",g,a?J(a):"0x",m??[],...Ri(e,t)],x=[],I=[],k=[];if(p)for(let A=0;A<p.length;A++){const{blob:E,commitment:T,proof:S}=p[A];x.push(E),I.push(T),k.push(S)}return Ct(["0x03",pr(p?[v,x,I,k]:v)])}function fm(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:f,data:l}=e;rc(e);const h=$s(f),m=[J(r),i?J(i):"0x",c?J(c):"0x",a?J(a):"0x",n?J(n):"0x",s??"0x",o?J(o):"0x",l??"0x",h,...Ri(e,t)];return Ct(["0x02",pr(m)])}function dm(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:c,gasPrice:f}=e;sm(e);const l=$s(c),h=[J(r),s?J(s):"0x",f?J(f):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x",l,...Ri(e,t)];return Ct(["0x01",pr(h)])}function lm(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:c}=e;om(e);let f=[s?J(s):"0x",c?J(c):"0x",n?J(n):"0x",o??"0x",a?J(a):"0x",i??"0x"];if(t){const l=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const p=27n+(t.v===27n?0n:1n);if(t.v!==p)throw new vp({v:t.v});return p})(),h=Or(t.r),m=Or(t.s);f=[...f,J(l),h==="0x00"?"0x":h,m==="0x00"?"0x":m]}else r>0&&(f=[...f,J(r),"0x","0x"]);return pr(f)}function Ri(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=Or(r.r),o=Or(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]}function hm(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{chainId:n,nonce:i,...s}=r,o=r.address;t.push([n?J(n):"0x",o,i?J(i):"0x",...Ri({},s)])}return t}function pm(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ad(e,...t){if(!pm(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function eu(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 ym(e,t){Ad(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) */function Eo(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}function Ki(e,t){return e<<t|e>>>32-t>>>0}function mm(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function Sd(e){return typeof e=="string"&&(e=mm(e)),Ad(e),e}let bm=class{clone(){return this._cloneInto()}};function nc(e){const t=n=>e().update(Sd(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function gm(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,f=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+f,a,n)}function wm(e,t,r){return e&t^~e&r}function _m(e,t,r){return e&t^e&r^t&r}let Pd=class extends bm{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=Eo(this.buffer)}update(t){eu(this);const{view:r,buffer:n,blockLen:i}=this;t=Sd(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=Eo(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){eu(this),ym(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 h=o;h<i;h++)r[h]=0;gm(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Eo(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],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 vm=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Td=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Em=Td.map(e=>(9*e+5)%16);let ic=[Td],sc=[Em];for(let e=0;e<4;e++)for(let t of[ic,sc])t.push(t[e].map(r=>vm[r]));const kd=[[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)),xm=ic.map((e,t)=>e.map(r=>kd[t][r])),Am=sc.map((e,t)=>e.map(r=>kd[t][r])),Sm=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Pm=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function tu(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 Yi=new Uint32Array(16);let Id=class extends Pd{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 p=0;p<16;p++,r+=4)Yi[p]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,f=this.h3|0,l=f,h=this.h4|0,m=h;for(let p=0;p<5;p++){const g=4-p,v=Sm[p],x=Pm[p],I=ic[p],k=sc[p],A=xm[p],E=Am[p];for(let T=0;T<16;T++){const S=Ki(n+tu(p,s,a,f)+Yi[I[T]]+v,A[T])+h|0;n=h,h=f,f=Ki(a,10)|0,a=s,s=S}for(let T=0;T<16;T++){const S=Ki(i+tu(g,o,c,l)+Yi[k[T]]+x,E[T])+m|0;i=m,m=l,l=Ki(c,10)|0,c=o,o=S}}this.set(this.h1+a+l|0,this.h2+f+m|0,this.h3+h+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){Yi.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const Tm=nc(()=>new Id),km=Object.freeze(Object.defineProperty({__proto__:null,RIPEMD160:Id,ripemd160:Tm},Symbol.toStringTag,{value:"Module"})),Im=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]),rr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nr=new Uint32Array(64);class oc extends Pd{constructor(){super(64,32,8,!1),this.A=rr[0]|0,this.B=rr[1]|0,this.C=rr[2]|0,this.D=rr[3]|0,this.E=rr[4]|0,this.F=rr[5]|0,this.G=rr[6]|0,this.H=rr[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 h=0;h<16;h++,r+=4)nr[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const m=nr[h-15],p=nr[h-2],g=wt(m,7)^wt(m,18)^m>>>3,v=wt(p,17)^wt(p,19)^p>>>10;nr[h]=v+nr[h-7]+g+nr[h-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const m=wt(a,6)^wt(a,11)^wt(a,25),p=l+m+wm(a,c,f)+Im[h]+nr[h]|0,v=(wt(n,2)^wt(n,13)^wt(n,22))+_m(n,i,s)|0;l=f,f=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+v|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,f=f+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,f,l)}roundClean(){nr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Bm extends oc{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 Cm=nc(()=>new oc),Om=nc(()=>new Bm),Rm=Object.freeze(Object.defineProperty({__proto__:null,SHA256:oc,sha224:Om,sha256:Cm},Symbol.toStringTag,{value:"Module"}));async function Um(e,{chain:t}){const{id:r,name:n,nativeCurrency:i,rpcUrls:s,blockExplorers:o}=t;await e.request({method:"wallet_addEthereumChain",params:[{chainId:Q(r),chainName:n,nativeCurrency:i,rpcUrls:s.default.http,blockExplorerUrls:o?Object.values(o).map(({url:a})=>a):void 0}]},{dedupe:!0,retryCount:0})}function Lm(e,t){const{abi:r,args:n,bytecode:i,...s}=t,o=Za({abi:r,args:n,bytecode:i});return tc(e,{...s,...s.authorizationList?{to:null}:{},data:o})}async function Nm(e){var r;return((r=e.account)==null?void 0:r.type)==="local"?[e.account.address]:(await e.request({method:"eth_accounts"},{dedupe:!0})).map(n=>ki(n))}async function Fm(e,t={}){const{account:r=e.account,chainId:n}=t,i=r?Ne(r):void 0,s=await e.request({method:"wallet_getCapabilities",params:[i==null?void 0:i.address]}),o={};for(const[a,c]of Object.entries(s))o[Number(a)]=c;return typeof n=="number"?o[n]:o}async function $m(e){return await e.request({method:"wallet_getPermissions"},{dedupe:!0})}async function Bd(e,t){var c;const{account:r=e.account,chainId:n,nonce:i}=t;if(!r)throw new br({docsPath:"/docs/eip7702/prepareAuthorization"});const s=Ne(r),o=(()=>{if(t.executor)return t.executor==="self"?t.executor:Ne(t.executor)})(),a={address:t.contractAddress??t.address,chainId:n,nonce:i};return typeof a.chainId>"u"&&(a.chainId=((c=e.chain)==null?void 0:c.id)??await oe(e,Oi,"getChainId")({})),typeof a.nonce>"u"&&(a.nonce=await oe(e,ed,"getTransactionCount")({address:s.address,blockTag:"pending"}),(o==="self"||o!=null&&o.address&&Ja(o.address,s.address))&&(a.nonce+=1)),a}async function Mm(e){return(await e.request({method:"eth_requestAccounts"},{dedupe:!0,retryCount:0})).map(r=>H0(r))}async function Hm(e,t){return e.request({method:"wallet_requestPermissions",params:[t]},{retryCount:0})}async function Dm(e,t){const{account:r=e.account,capabilities:n,chain:i=e.chain,forceAtomic:s=!1,id:o,version:a="2.0.0"}=t;if(typeof r>"u")throw new br({docsPath:"/experimental/eip5792/sendCalls"});const c=r?Ne(r):null,f=t.calls.map(l=>{const h=l;return{data:h.abi?xn({abi:h.abi,functionName:h.functionName,args:h.args}):h.data,to:h.to,value:h.value?Q(h.value):void 0}});try{const l=await e.request({method:"wallet_sendCalls",params:[{atomicRequired:s,calls:f,capabilities:n,chainId:Q(i.id),from:c==null?void 0:c.address,id:o,version:a}]},{retryCount:0});return typeof l=="string"?{id:l}:l}catch(l){throw gd(l,{...t,account:c,chain:t.chain})}}async function jm(e,t){const{id:r}=t;await e.request({method:"wallet_showCallsStatus",params:[r]})}async function Gm(e,t){const{account:r=e.account}=t;if(!r)throw new br({docsPath:"/docs/eip7702/signAuthorization"});const n=Ne(r);if(!n.signAuthorization)throw new os({docsPath:"/docs/eip7702/signAuthorization",metaMessages:["The `signAuthorization` Action does not support JSON-RPC Accounts."],type:n.type});const i=await Bd(e,t);return n.signAuthorization(i)}async function zm(e,{account:t=e.account,message:r}){if(!t)throw new br({docsPath:"/docs/actions/wallet/signMessage"});const n=Ne(t);if(n.signMessage)return n.signMessage({message:r});const i=typeof r=="string"?Ts(r):r.raw instanceof Uint8Array?J(r.raw):r.raw;return e.request({method:"personal_sign",params:[i,n.address]},{retryCount:0})}async function qm(e,t){var f,l,h,m;const{account:r=e.account,chain:n=e.chain,...i}=t;if(!r)throw new br({docsPath:"/docs/actions/wallet/signTransaction"});const s=Ne(r);Ci({account:s,...t});const o=await oe(e,Oi,"getChainId")({});n!==null&&bd({currentChainId:o,chain:n});const a=(n==null?void 0:n.formatters)||((f=e.chain)==null?void 0:f.formatters),c=((l=a==null?void 0:a.transactionRequest)==null?void 0:l.format)||Ls;return s.signTransaction?s.signTransaction({...i,chainId:o},{serializer:(m=(h=e.chain)==null?void 0:h.serializers)==null?void 0:m.transaction}):await e.request({method:"eth_signTransaction",params:[{...c(i),chainId:Q(o),from:s.address}]},{retryCount:0})}async function Vm(e,t){const{account:r=e.account,domain:n,message:i,primaryType:s}=t;if(!r)throw new br({docsPath:"/docs/actions/wallet/signTypedData"});const o=Ne(r),a={EIP712Domain:tm({domain:n}),...t.types};if(em({domain:n,message:i,primaryType:s,types:a}),o.signTypedData)return o.signTypedData({domain:n,message:i,primaryType:s,types:a});const c=Zy({domain:n,message:i,primaryType:s,types:a});return e.request({method:"eth_signTypedData_v4",params:[o.address,c]},{retryCount:0})}async function Wm(e,{id:t}){await e.request({method:"wallet_switchEthereumChain",params:[{chainId:Q(t)}]},{retryCount:0})}async function Km(e,t){return await e.request({method:"wallet_watchAsset",params:t},{retryCount:0})}function Ym(e){return{addChain:t=>Um(e,t),deployContract:t=>Lm(e,t),getAddresses:()=>Nm(e),getCallsStatus:t=>Ed(e,t),getCapabilities:()=>Fm(e),getChainId:()=>Oi(e),getPermissions:()=>$m(e),prepareAuthorization:t=>Bd(e,t),prepareTransactionRequest:t=>Xa(e,t),requestAddresses:()=>Mm(e),requestPermissions:t=>Hm(e,t),sendCalls:t=>Dm(e,t),sendRawTransaction:t=>wd(e,t),sendTransaction:t=>tc(e,t),showCallsStatus:t=>jm(e,t),signAuthorization:t=>Gm(e,t),signMessage:t=>zm(e,t),signTransaction:t=>qm(e,t),signTypedData:t=>Vm(e,t),switchChain:t=>Wm(e,t),waitForCallsStatus:t=>jy(e,t),watchAsset:t=>Km(e,t),writeContract:t=>_d(e,t)}}function xo(e){const{key:t="wallet",name:r="Wallet Client",transport:n}=e;return zy({...e,key:t,name:r,transport:n,type:"walletClient"}).extend(Ym)}function pa(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function Ar(e,t){if(!e)throw new Error(t)}function Xm(e){return Buffer.concat([Uint8Array.from([192]),Jm(e)])}function Jm(e){const t=Tc.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Tc.encode(e.length,r),Buffer.concat([r,e])}function Qm(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const cr=e=>e.length===64?e:e.slice(2),Zm=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return Br.isPoint(t)}catch{return!1}},Cd=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function eb(e,t){if(!e)return!1;const r=t===z.Environment.MAINNET?ce.networks.bitcoin:t===z.Environment.TESTNET?ce.networks.testnet:ce.networks.regtest;if(!r)return!1;ce.initEccLib(Br);try{return ce.address.toOutputScript(e,r),!0}catch{return!1}}const tb=e=>{switch(e){case z.Environment.MAINNET:return fn.BitcoinNetwork.Mainnet;case z.Environment.TESTNET:return fn.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}},rb=e=>{const t=e.toLowerCase().replace("0x","");return/^[0-9a-f]+$/.test(t)},nb=e=>{if(typeof e=="object"&&"r"in e&&"s"in e)return z.Ok([e.r.toString(),e.s.toString()]);if(Array.isArray(e)){const t=e.map(r=>typeof r=="string"&&r.startsWith("0x")&&rb(r)?BigInt(r).toString():r);return z.Ok(t)}return z.Err("Invalid signature format")};var we=(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))(we||{}),xe=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(xe||{});const ac=(e,t,r)=>{const n=ya(e.source_swap,t),i=ya(e.destination_swap,r);if(i===xe.RedeemDetected)return we.RedeemDetected;if(i===xe.Redeemed)return we.Redeemed;if(n===xe.Refunded)return we.Refunded;if(n===xe.RefundDetected)return we.RefundDetected;if(i===xe.Expired)return we.CounterPartySwapExpired;if(n===xe.Expired)return we.Expired;if(i===xe.Refunded)return we.CounterPartyRefunded;if(i===xe.RefundDetected)return we.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===xe.Initiated?we.CounterPartyInitiated:i===xe.InitiateDetected?we.CounterPartyInitiateDetected:vi(s,12)?we.DeadLineExceeded:n===xe.Initiated?we.Initiated:vi(s,1)?we.DeadLineExceeded:n===xe.InitiateDetected?we.InitiateDetected:n===xe.Redeemed?we.CounterPartyRedeemed:n===xe.RedeemDetected?we.CounterPartyRedeemDetected:we.Matched},ya=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?xe.Redeemed:xe.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?xe.Refunded:xe.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return xe.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?xe.Initiated:xe.InitiateDetected:xe.Idle},ib=(e,t,r)=>{const n=ac(e,t,r);return cc(n)},cc=e=>{switch(e){case we.Matched:return Ce.Initiate;case we.CounterPartyInitiated:case we.CounterPartyInitiateDetected:case we.RedeemDetected:return Ce.Redeem;case we.Expired:return Ce.Refund;default:return Ce.Idle}},vi=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},sb=e=>e.filter(t=>!Od(t)),Od=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)?vi(Number(s),12):n?!1:vi(Number(s),1)},ob=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),ab=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),cb=Buffer.concat([ob,ab]),ub=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),ru={failedToCreateInternalPubkey:"failed to create internal pubkey"};function fb(){const e=ef.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=Br.pointMultiply(Buffer.concat([Buffer.from("04","hex"),cb]),e);if(!t)throw new Error(ru.failedToCreateInternalPubkey);const r=Br.pointAdd(ub,t);if(!r)throw new Error(ru.failedToCreateInternalPubkey);return pa(Buffer.from(r))}var yr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function db(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function uc(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 Ae={},Ve={},Jt={},Ms={};Ms.byteLength=pb;Ms.toByteArray=mb;Ms.fromByteArray=wb;var Tt=[],dt=[],lb=typeof Uint8Array<"u"?Uint8Array:Array,Ao="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Kr=0,hb=Ao.length;Kr<hb;++Kr)Tt[Kr]=Ao[Kr],dt[Ao.charCodeAt(Kr)]=Kr;dt[45]=62;dt[95]=63;function Rd(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 pb(e){var t=Rd(e),r=t[0],n=t[1];return(r+n)*3/4-n}function yb(e,t,r){return(t+r)*3/4-r}function mb(e){var t,r=Rd(e),n=r[0],i=r[1],s=new lb(yb(e,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=dt[e.charCodeAt(c)]<<18|dt[e.charCodeAt(c+1)]<<12|dt[e.charCodeAt(c+2)]<<6|dt[e.charCodeAt(c+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=dt[e.charCodeAt(c)]<<2|dt[e.charCodeAt(c+1)]>>4,s[o++]=t&255),i===1&&(t=dt[e.charCodeAt(c)]<<10|dt[e.charCodeAt(c+1)]<<4|dt[e.charCodeAt(c+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function bb(e){return Tt[e>>18&63]+Tt[e>>12&63]+Tt[e>>6&63]+Tt[e&63]}function gb(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(bb(n));return i.join("")}function wb(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(gb(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(Tt[t>>2]+Tt[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Tt[t>>10]+Tt[t>>4&63]+Tt[t<<2&63]+"=")),i.join("")}var fc={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */fc.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,c=(1<<a)-1,f=c>>1,l=-7,h=r?i-1:0,m=r?-1:1,p=e[t+h];for(h+=m,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=s*256+e[t+h],h+=m,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=n;l>0;o=o*256+e[t+h],h+=m,l-=8);if(s===0)s=1-f;else{if(s===c)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-f}return(p?-1:1)*o*Math.pow(2,s-n)};fc.write=function(e,t,r,n,i,s){var o,a,c,f=s*8-i-1,l=(1<<f)-1,h=l>>1,m=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,g=n?1:-1,v=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=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+h>=1?t+=m/c:t+=m*Math.pow(2,1-h),t*c>=2&&(o++,c/=2),o+h>=l?(a=0,o=l):o+h>=1?(a=(t*c-1)*Math.pow(2,i),o=o+h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=a&255,p+=g,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=o&255,p+=g,o/=256,f-=8);e[r+p-g]|=v*128};/*!
|
|
42
42
|
* The buffer module from node.js, for the browser.
|
|
43
43
|
*
|
|
44
44
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
45
45
|
* @license MIT
|
|
46
|
-
*/(function(e){const t=Ms,r=cc,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=k,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=s(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const y=new Uint8Array(1),u={foo:function(){return 42}};return Object.setPrototypeOf(u,Uint8Array.prototype),Object.setPrototypeOf(y,u),y.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(y){if(y>i)throw new RangeError('The value "'+y+'" is invalid for option "size"');const u=new Uint8Array(y);return Object.setPrototypeOf(u,a.prototype),u}function a(y,u,d){if(typeof y=="number"){if(typeof u=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return h(y)}return c(y,u,d)}a.poolSize=8192;function c(y,u,d){if(typeof y=="string")return m(y,u);if(ArrayBuffer.isView(y))return g(y);if(y==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y);if(st(y,ArrayBuffer)||y&&st(y.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(st(y,SharedArrayBuffer)||y&&st(y.buffer,SharedArrayBuffer)))return v(y,u,d);if(typeof y=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const b=y.valueOf&&y.valueOf();if(b!=null&&b!==y)return a.from(b,u,d);const P=x(y);if(P)return P;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof y[Symbol.toPrimitive]=="function")return a.from(y[Symbol.toPrimitive]("string"),u,d);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y)}a.from=function(y,u,d){return c(y,u,d)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function f(y){if(typeof y!="number")throw new TypeError('"size" argument must be of type number');if(y<0)throw new RangeError('The value "'+y+'" is invalid for option "size"')}function l(y,u,d){return f(y),y<=0?o(y):u!==void 0?typeof d=="string"?o(y).fill(u,d):o(y).fill(u):o(y)}a.alloc=function(y,u,d){return l(y,u,d)};function h(y){return f(y),o(y<0?0:I(y)|0)}a.allocUnsafe=function(y){return h(y)},a.allocUnsafeSlow=function(y){return h(y)};function m(y,u){if((typeof u!="string"||u==="")&&(u="utf8"),!a.isEncoding(u))throw new TypeError("Unknown encoding: "+u);const d=A(y,u)|0;let b=o(d);const P=b.write(y,u);return P!==d&&(b=b.slice(0,P)),b}function p(y){const u=y.length<0?0:I(y.length)|0,d=o(u);for(let b=0;b<u;b+=1)d[b]=y[b]&255;return d}function g(y){if(st(y,Uint8Array)){const u=new Uint8Array(y);return v(u.buffer,u.byteOffset,u.byteLength)}return p(y)}function v(y,u,d){if(u<0||y.byteLength<u)throw new RangeError('"offset" is outside of buffer bounds');if(y.byteLength<u+(d||0))throw new RangeError('"length" is outside of buffer bounds');let b;return u===void 0&&d===void 0?b=new Uint8Array(y):d===void 0?b=new Uint8Array(y,u):b=new Uint8Array(y,u,d),Object.setPrototypeOf(b,a.prototype),b}function x(y){if(a.isBuffer(y)){const u=I(y.length)|0,d=o(u);return d.length===0||y.copy(d,0,0,u),d}if(y.length!==void 0)return typeof y.length!="number"||Er(y.length)?o(0):p(y);if(y.type==="Buffer"&&Array.isArray(y.data))return p(y.data)}function I(y){if(y>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return y|0}function k(y){return+y!=y&&(y=0),a.alloc(+y)}a.isBuffer=function(u){return u!=null&&u._isBuffer===!0&&u!==a.prototype},a.compare=function(u,d){if(st(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),st(d,Uint8Array)&&(d=a.from(d,d.offset,d.byteLength)),!a.isBuffer(u)||!a.isBuffer(d))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(u===d)return 0;let b=u.length,P=d.length;for(let R=0,L=Math.min(b,P);R<L;++R)if(u[R]!==d[R]){b=u[R],P=d[R];break}return b<P?-1:P<b?1:0},a.isEncoding=function(u){switch(String(u).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(u,d){if(!Array.isArray(u))throw new TypeError('"list" argument must be an Array of Buffers');if(u.length===0)return a.alloc(0);let b;if(d===void 0)for(d=0,b=0;b<u.length;++b)d+=u[b].length;const P=a.allocUnsafe(d);let R=0;for(b=0;b<u.length;++b){let L=u[b];if(st(L,Uint8Array))R+L.length>P.length?(a.isBuffer(L)||(L=a.from(L)),L.copy(P,R)):Uint8Array.prototype.set.call(P,L,R);else if(a.isBuffer(L))L.copy(P,R);else throw new TypeError('"list" argument must be an Array of Buffers');R+=L.length}return P};function A(y,u){if(a.isBuffer(y))return y.length;if(ArrayBuffer.isView(y)||st(y,ArrayBuffer))return y.byteLength;if(typeof y!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof y);const d=y.length,b=arguments.length>2&&arguments[2]===!0;if(!b&&d===0)return 0;let P=!1;for(;;)switch(u){case"ascii":case"latin1":case"binary":return d;case"utf8":case"utf-8":return ae(y).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return d*2;case"hex":return d>>>1;case"base64":return Sn(y).length;default:if(P)return b?-1:ae(y).length;u=(""+u).toLowerCase(),P=!0}}a.byteLength=A;function E(y,u,d){let b=!1;if((u===void 0||u<0)&&(u=0),u>this.length||((d===void 0||d>this.length)&&(d=this.length),d<=0)||(d>>>=0,u>>>=0,d<=u))return"";for(y||(y="utf8");;)switch(y){case"hex":return Te(this,u,d);case"utf8":case"utf-8":return V(this,u,d);case"ascii":return he(this,u,d);case"latin1":case"binary":return _e(this,u,d);case"base64":return j(this,u,d);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return We(this,u,d);default:if(b)throw new TypeError("Unknown encoding: "+y);y=(y+"").toLowerCase(),b=!0}}a.prototype._isBuffer=!0;function T(y,u,d){const b=y[u];y[u]=y[d],y[d]=b}a.prototype.swap16=function(){const u=this.length;if(u%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let d=0;d<u;d+=2)T(this,d,d+1);return this},a.prototype.swap32=function(){const u=this.length;if(u%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let d=0;d<u;d+=4)T(this,d,d+3),T(this,d+1,d+2);return this},a.prototype.swap64=function(){const u=this.length;if(u%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let d=0;d<u;d+=8)T(this,d,d+7),T(this,d+1,d+6),T(this,d+2,d+5),T(this,d+3,d+4);return this},a.prototype.toString=function(){const u=this.length;return u===0?"":arguments.length===0?V(this,0,u):E.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(u){if(!a.isBuffer(u))throw new TypeError("Argument must be a Buffer");return this===u?!0:a.compare(this,u)===0},a.prototype.inspect=function(){let u="";const d=e.INSPECT_MAX_BYTES;return u=this.toString("hex",0,d).replace(/(.{2})/g,"$1 ").trim(),this.length>d&&(u+=" ... "),"<Buffer "+u+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(u,d,b,P,R){if(st(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(u))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof u);if(d===void 0&&(d=0),b===void 0&&(b=u?u.length:0),P===void 0&&(P=0),R===void 0&&(R=this.length),d<0||b>u.length||P<0||R>this.length)throw new RangeError("out of range index");if(P>=R&&d>=b)return 0;if(P>=R)return-1;if(d>=b)return 1;if(d>>>=0,b>>>=0,P>>>=0,R>>>=0,this===u)return 0;let L=R-P,re=b-d;const Se=Math.min(L,re),Ee=this.slice(P,R),Pe=u.slice(d,b);for(let de=0;de<Se;++de)if(Ee[de]!==Pe[de]){L=Ee[de],re=Pe[de];break}return L<re?-1:re<L?1:0};function S(y,u,d,b,P){if(y.length===0)return-1;if(typeof d=="string"?(b=d,d=0):d>2147483647?d=2147483647:d<-2147483648&&(d=-2147483648),d=+d,Er(d)&&(d=P?0:y.length-1),d<0&&(d=y.length+d),d>=y.length){if(P)return-1;d=y.length-1}else if(d<0)if(P)d=0;else return-1;if(typeof u=="string"&&(u=a.from(u,b)),a.isBuffer(u))return u.length===0?-1:N(y,u,d,b,P);if(typeof u=="number")return u=u&255,typeof Uint8Array.prototype.indexOf=="function"?P?Uint8Array.prototype.indexOf.call(y,u,d):Uint8Array.prototype.lastIndexOf.call(y,u,d):N(y,[u],d,b,P);throw new TypeError("val must be string, number or Buffer")}function N(y,u,d,b,P){let R=1,L=y.length,re=u.length;if(b!==void 0&&(b=String(b).toLowerCase(),b==="ucs2"||b==="ucs-2"||b==="utf16le"||b==="utf-16le")){if(y.length<2||u.length<2)return-1;R=2,L/=2,re/=2,d/=2}function Se(Pe,de){return R===1?Pe[de]:Pe.readUInt16BE(de*R)}let Ee;if(P){let Pe=-1;for(Ee=d;Ee<L;Ee++)if(Se(y,Ee)===Se(u,Pe===-1?0:Ee-Pe)){if(Pe===-1&&(Pe=Ee),Ee-Pe+1===re)return Pe*R}else Pe!==-1&&(Ee-=Ee-Pe),Pe=-1}else for(d+re>L&&(d=L-re),Ee=d;Ee>=0;Ee--){let Pe=!0;for(let de=0;de<re;de++)if(Se(y,Ee+de)!==Se(u,de)){Pe=!1;break}if(Pe)return Ee}return-1}a.prototype.includes=function(u,d,b){return this.indexOf(u,d,b)!==-1},a.prototype.indexOf=function(u,d,b){return S(this,u,d,b,!0)},a.prototype.lastIndexOf=function(u,d,b){return S(this,u,d,b,!1)};function M(y,u,d,b){d=Number(d)||0;const P=y.length-d;b?(b=Number(b),b>P&&(b=P)):b=P;const R=u.length;b>R/2&&(b=R/2);let L;for(L=0;L<b;++L){const re=parseInt(u.substr(L*2,2),16);if(Er(re))return L;y[d+L]=re}return L}function B(y,u,d,b){return qr(ae(u,y.length-d),y,d,b)}function W(y,u,d,b){return qr(Zt(u),y,d,b)}function U(y,u,d,b){return qr(Sn(u),y,d,b)}function D(y,u,d,b){return qr(zr(u,y.length-d),y,d,b)}a.prototype.write=function(u,d,b,P){if(d===void 0)P="utf8",b=this.length,d=0;else if(b===void 0&&typeof d=="string")P=d,b=this.length,d=0;else if(isFinite(d))d=d>>>0,isFinite(b)?(b=b>>>0,P===void 0&&(P="utf8")):(P=b,b=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const R=this.length-d;if((b===void 0||b>R)&&(b=R),u.length>0&&(b<0||d<0)||d>this.length)throw new RangeError("Attempt to write outside buffer bounds");P||(P="utf8");let L=!1;for(;;)switch(P){case"hex":return M(this,u,d,b);case"utf8":case"utf-8":return B(this,u,d,b);case"ascii":case"latin1":case"binary":return W(this,u,d,b);case"base64":return U(this,u,d,b);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,u,d,b);default:if(L)throw new TypeError("Unknown encoding: "+P);P=(""+P).toLowerCase(),L=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function j(y,u,d){return u===0&&d===y.length?t.fromByteArray(y):t.fromByteArray(y.slice(u,d))}function V(y,u,d){d=Math.min(y.length,d);const b=[];let P=u;for(;P<d;){const R=y[P];let L=null,re=R>239?4:R>223?3:R>191?2:1;if(P+re<=d){let Se,Ee,Pe,de;switch(re){case 1:R<128&&(L=R);break;case 2:Se=y[P+1],(Se&192)===128&&(de=(R&31)<<6|Se&63,de>127&&(L=de));break;case 3:Se=y[P+1],Ee=y[P+2],(Se&192)===128&&(Ee&192)===128&&(de=(R&15)<<12|(Se&63)<<6|Ee&63,de>2047&&(de<55296||de>57343)&&(L=de));break;case 4:Se=y[P+1],Ee=y[P+2],Pe=y[P+3],(Se&192)===128&&(Ee&192)===128&&(Pe&192)===128&&(de=(R&15)<<18|(Se&63)<<12|(Ee&63)<<6|Pe&63,de>65535&&de<1114112&&(L=de))}}L===null?(L=65533,re=1):L>65535&&(L-=65536,b.push(L>>>10&1023|55296),L=56320|L&1023),b.push(L),P+=re}return ne(b)}const X=4096;function ne(y){const u=y.length;if(u<=X)return String.fromCharCode.apply(String,y);let d="",b=0;for(;b<u;)d+=String.fromCharCode.apply(String,y.slice(b,b+=X));return d}function he(y,u,d){let b="";d=Math.min(y.length,d);for(let P=u;P<d;++P)b+=String.fromCharCode(y[P]&127);return b}function _e(y,u,d){let b="";d=Math.min(y.length,d);for(let P=u;P<d;++P)b+=String.fromCharCode(y[P]);return b}function Te(y,u,d){const b=y.length;(!u||u<0)&&(u=0),(!d||d<0||d>b)&&(d=b);let P="";for(let R=u;R<d;++R)P+=Pn[y[R]];return P}function We(y,u,d){const b=y.slice(u,d);let P="";for(let R=0;R<b.length-1;R+=2)P+=String.fromCharCode(b[R]+b[R+1]*256);return P}a.prototype.slice=function(u,d){const b=this.length;u=~~u,d=d===void 0?b:~~d,u<0?(u+=b,u<0&&(u=0)):u>b&&(u=b),d<0?(d+=b,d<0&&(d=0)):d>b&&(d=b),d<u&&(d=u);const P=this.subarray(u,d);return Object.setPrototypeOf(P,a.prototype),P};function fe(y,u,d){if(y%1!==0||y<0)throw new RangeError("offset is not uint");if(y+u>d)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=this[u],R=1,L=0;for(;++L<d&&(R*=256);)P+=this[u+L]*R;return P},a.prototype.readUintBE=a.prototype.readUIntBE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=this[u+--d],R=1;for(;d>0&&(R*=256);)P+=this[u+--d]*R;return P},a.prototype.readUint8=a.prototype.readUInt8=function(u,d){return u=u>>>0,d||fe(u,1,this.length),this[u]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(u,d){return u=u>>>0,d||fe(u,2,this.length),this[u]|this[u+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(u,d){return u=u>>>0,d||fe(u,2,this.length),this[u]<<8|this[u+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),(this[u]|this[u+1]<<8|this[u+2]<<16)+this[u+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),this[u]*16777216+(this[u+1]<<16|this[u+2]<<8|this[u+3])},a.prototype.readBigUInt64LE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=d+this[++u]*2**8+this[++u]*2**16+this[++u]*2**24,R=this[++u]+this[++u]*2**8+this[++u]*2**16+b*2**24;return BigInt(P)+(BigInt(R)<<BigInt(32))}),a.prototype.readBigUInt64BE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=d*2**24+this[++u]*2**16+this[++u]*2**8+this[++u],R=this[++u]*2**24+this[++u]*2**16+this[++u]*2**8+b;return(BigInt(P)<<BigInt(32))+BigInt(R)}),a.prototype.readIntLE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=this[u],R=1,L=0;for(;++L<d&&(R*=256);)P+=this[u+L]*R;return R*=128,P>=R&&(P-=Math.pow(2,8*d)),P},a.prototype.readIntBE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=d,R=1,L=this[u+--P];for(;P>0&&(R*=256);)L+=this[u+--P]*R;return R*=128,L>=R&&(L-=Math.pow(2,8*d)),L},a.prototype.readInt8=function(u,d){return u=u>>>0,d||fe(u,1,this.length),this[u]&128?(255-this[u]+1)*-1:this[u]},a.prototype.readInt16LE=function(u,d){u=u>>>0,d||fe(u,2,this.length);const b=this[u]|this[u+1]<<8;return b&32768?b|4294901760:b},a.prototype.readInt16BE=function(u,d){u=u>>>0,d||fe(u,2,this.length);const b=this[u+1]|this[u]<<8;return b&32768?b|4294901760:b},a.prototype.readInt32LE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),this[u]|this[u+1]<<8|this[u+2]<<16|this[u+3]<<24},a.prototype.readInt32BE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),this[u]<<24|this[u+1]<<16|this[u+2]<<8|this[u+3]},a.prototype.readBigInt64LE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=this[u+4]+this[u+5]*2**8+this[u+6]*2**16+(b<<24);return(BigInt(P)<<BigInt(32))+BigInt(d+this[++u]*2**8+this[++u]*2**16+this[++u]*2**24)}),a.prototype.readBigInt64BE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=(d<<24)+this[++u]*2**16+this[++u]*2**8+this[++u];return(BigInt(P)<<BigInt(32))+BigInt(this[++u]*2**24+this[++u]*2**16+this[++u]*2**8+b)}),a.prototype.readFloatLE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),r.read(this,u,!0,23,4)},a.prototype.readFloatBE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),r.read(this,u,!1,23,4)},a.prototype.readDoubleLE=function(u,d){return u=u>>>0,d||fe(u,8,this.length),r.read(this,u,!0,52,8)},a.prototype.readDoubleBE=function(u,d){return u=u>>>0,d||fe(u,8,this.length),r.read(this,u,!1,52,8)};function ye(y,u,d,b,P,R){if(!a.isBuffer(y))throw new TypeError('"buffer" argument must be a Buffer instance');if(u>P||u<R)throw new RangeError('"value" argument is out of bounds');if(d+b>y.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(u,d,b,P){if(u=+u,d=d>>>0,b=b>>>0,!P){const re=Math.pow(2,8*b)-1;ye(this,u,d,b,re,0)}let R=1,L=0;for(this[d]=u&255;++L<b&&(R*=256);)this[d+L]=u/R&255;return d+b},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(u,d,b,P){if(u=+u,d=d>>>0,b=b>>>0,!P){const re=Math.pow(2,8*b)-1;ye(this,u,d,b,re,0)}let R=b-1,L=1;for(this[d+R]=u&255;--R>=0&&(L*=256);)this[d+R]=u/L&255;return d+b},a.prototype.writeUint8=a.prototype.writeUInt8=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,1,255,0),this[d]=u&255,d+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,65535,0),this[d]=u&255,this[d+1]=u>>>8,d+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,65535,0),this[d]=u>>>8,this[d+1]=u&255,d+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,4294967295,0),this[d+3]=u>>>24,this[d+2]=u>>>16,this[d+1]=u>>>8,this[d]=u&255,d+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,4294967295,0),this[d]=u>>>24,this[d+1]=u>>>16,this[d+2]=u>>>8,this[d+3]=u&255,d+4};function it(y,u,d,b,P){_(u,b,P,y,d,7);let R=Number(u&BigInt(4294967295));y[d++]=R,R=R>>8,y[d++]=R,R=R>>8,y[d++]=R,R=R>>8,y[d++]=R;let L=Number(u>>BigInt(32)&BigInt(4294967295));return y[d++]=L,L=L>>8,y[d++]=L,L=L>>8,y[d++]=L,L=L>>8,y[d++]=L,d}function Qt(y,u,d,b,P){_(u,b,P,y,d,7);let R=Number(u&BigInt(4294967295));y[d+7]=R,R=R>>8,y[d+6]=R,R=R>>8,y[d+5]=R,R=R>>8,y[d+4]=R;let L=Number(u>>BigInt(32)&BigInt(4294967295));return y[d+3]=L,L=L>>8,y[d+2]=L,L=L>>8,y[d+1]=L,L=L>>8,y[d]=L,d+8}a.prototype.writeBigUInt64LE=ut(function(u,d=0){return it(this,u,d,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=ut(function(u,d=0){return Qt(this,u,d,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(u,d,b,P){if(u=+u,d=d>>>0,!P){const Se=Math.pow(2,8*b-1);ye(this,u,d,b,Se-1,-Se)}let R=0,L=1,re=0;for(this[d]=u&255;++R<b&&(L*=256);)u<0&&re===0&&this[d+R-1]!==0&&(re=1),this[d+R]=(u/L>>0)-re&255;return d+b},a.prototype.writeIntBE=function(u,d,b,P){if(u=+u,d=d>>>0,!P){const Se=Math.pow(2,8*b-1);ye(this,u,d,b,Se-1,-Se)}let R=b-1,L=1,re=0;for(this[d+R]=u&255;--R>=0&&(L*=256);)u<0&&re===0&&this[d+R+1]!==0&&(re=1),this[d+R]=(u/L>>0)-re&255;return d+b},a.prototype.writeInt8=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,1,127,-128),u<0&&(u=255+u+1),this[d]=u&255,d+1},a.prototype.writeInt16LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,32767,-32768),this[d]=u&255,this[d+1]=u>>>8,d+2},a.prototype.writeInt16BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,32767,-32768),this[d]=u>>>8,this[d+1]=u&255,d+2},a.prototype.writeInt32LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,2147483647,-2147483648),this[d]=u&255,this[d+1]=u>>>8,this[d+2]=u>>>16,this[d+3]=u>>>24,d+4},a.prototype.writeInt32BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,2147483647,-2147483648),u<0&&(u=4294967295+u+1),this[d]=u>>>24,this[d+1]=u>>>16,this[d+2]=u>>>8,this[d+3]=u&255,d+4},a.prototype.writeBigInt64LE=ut(function(u,d=0){return it(this,u,d,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=ut(function(u,d=0){return Qt(this,u,d,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Rt(y,u,d,b,P,R){if(d+b>y.length)throw new RangeError("Index out of range");if(d<0)throw new RangeError("Index out of range")}function O(y,u,d,b,P){return u=+u,d=d>>>0,P||Rt(y,u,d,4),r.write(y,u,d,b,23,4),d+4}a.prototype.writeFloatLE=function(u,d,b){return O(this,u,d,!0,b)},a.prototype.writeFloatBE=function(u,d,b){return O(this,u,d,!1,b)};function C(y,u,d,b,P){return u=+u,d=d>>>0,P||Rt(y,u,d,8),r.write(y,u,d,b,52,8),d+8}a.prototype.writeDoubleLE=function(u,d,b){return C(this,u,d,!0,b)},a.prototype.writeDoubleBE=function(u,d,b){return C(this,u,d,!1,b)},a.prototype.copy=function(u,d,b,P){if(!a.isBuffer(u))throw new TypeError("argument should be a Buffer");if(b||(b=0),!P&&P!==0&&(P=this.length),d>=u.length&&(d=u.length),d||(d=0),P>0&&P<b&&(P=b),P===b||u.length===0||this.length===0)return 0;if(d<0)throw new RangeError("targetStart out of bounds");if(b<0||b>=this.length)throw new RangeError("Index out of range");if(P<0)throw new RangeError("sourceEnd out of bounds");P>this.length&&(P=this.length),u.length-d<P-b&&(P=u.length-d+b);const R=P-b;return this===u&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(d,b,P):Uint8Array.prototype.set.call(u,this.subarray(b,P),d),R},a.prototype.fill=function(u,d,b,P){if(typeof u=="string"){if(typeof d=="string"?(P=d,d=0,b=this.length):typeof b=="string"&&(P=b,b=this.length),P!==void 0&&typeof P!="string")throw new TypeError("encoding must be a string");if(typeof P=="string"&&!a.isEncoding(P))throw new TypeError("Unknown encoding: "+P);if(u.length===1){const L=u.charCodeAt(0);(P==="utf8"&&L<128||P==="latin1")&&(u=L)}}else typeof u=="number"?u=u&255:typeof u=="boolean"&&(u=Number(u));if(d<0||this.length<d||this.length<b)throw new RangeError("Out of range index");if(b<=d)return this;d=d>>>0,b=b===void 0?this.length:b>>>0,u||(u=0);let R;if(typeof u=="number")for(R=d;R<b;++R)this[R]=u;else{const L=a.isBuffer(u)?u:a.from(u,P),re=L.length;if(re===0)throw new TypeError('The value "'+u+'" is invalid for argument "value"');for(R=0;R<b-d;++R)this[R+d]=L[R%re]}return this};const H={};function K(y,u,d){H[y]=class extends d{constructor(){super(),Object.defineProperty(this,"message",{value:u.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${y}]`,this.stack,delete this.name}get code(){return y}set code(P){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:P,writable:!0})}toString(){return`${this.name} [${y}]: ${this.message}`}}}K("ERR_BUFFER_OUT_OF_BOUNDS",function(y){return y?`${y} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),K("ERR_INVALID_ARG_TYPE",function(y,u){return`The "${y}" argument must be of type number. Received type ${typeof u}`},TypeError),K("ERR_OUT_OF_RANGE",function(y,u,d){let b=`The value of "${y}" is out of range.`,P=d;return Number.isInteger(d)&&Math.abs(d)>2**32?P=Z(String(d)):typeof d=="bigint"&&(P=String(d),(d>BigInt(2)**BigInt(32)||d<-(BigInt(2)**BigInt(32)))&&(P=Z(P)),P+="n"),b+=` It must be ${u}. Received ${P}`,b},RangeError);function Z(y){let u="",d=y.length;const b=y[0]==="-"?1:0;for(;d>=b+4;d-=3)u=`_${y.slice(d-3,d)}${u}`;return`${y.slice(0,d)}${u}`}function w(y,u,d){F(u,"offset"),(y[u]===void 0||y[u+d]===void 0)&&q(u,y.length-(d+1))}function _(y,u,d,b,P,R){if(y>d||y<u){const L=typeof u=="bigint"?"n":"";let re;throw u===0||u===BigInt(0)?re=`>= 0${L} and < 2${L} ** ${(R+1)*8}${L}`:re=`>= -(2${L} ** ${(R+1)*8-1}${L}) and < 2 ** ${(R+1)*8-1}${L}`,new H.ERR_OUT_OF_RANGE("value",re,y)}w(b,P,R)}function F(y,u){if(typeof y!="number")throw new H.ERR_INVALID_ARG_TYPE(u,"number",y)}function q(y,u,d){throw Math.floor(y)!==y?(F(y,d),new H.ERR_OUT_OF_RANGE("offset","an integer",y)):u<0?new H.ERR_BUFFER_OUT_OF_BOUNDS:new H.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${u}`,y)}const ve=/[^+/0-9A-Za-z-_]/g;function ee(y){if(y=y.split("=")[0],y=y.trim().replace(ve,""),y.length<2)return"";for(;y.length%4!==0;)y=y+"=";return y}function ae(y,u){u=u||1/0;let d;const b=y.length;let P=null;const R=[];for(let L=0;L<b;++L){if(d=y.charCodeAt(L),d>55295&&d<57344){if(!P){if(d>56319){(u-=3)>-1&&R.push(239,191,189);continue}else if(L+1===b){(u-=3)>-1&&R.push(239,191,189);continue}P=d;continue}if(d<56320){(u-=3)>-1&&R.push(239,191,189),P=d;continue}d=(P-55296<<10|d-56320)+65536}else P&&(u-=3)>-1&&R.push(239,191,189);if(P=null,d<128){if((u-=1)<0)break;R.push(d)}else if(d<2048){if((u-=2)<0)break;R.push(d>>6|192,d&63|128)}else if(d<65536){if((u-=3)<0)break;R.push(d>>12|224,d>>6&63|128,d&63|128)}else if(d<1114112){if((u-=4)<0)break;R.push(d>>18|240,d>>12&63|128,d>>6&63|128,d&63|128)}else throw new Error("Invalid code point")}return R}function Zt(y){const u=[];for(let d=0;d<y.length;++d)u.push(y.charCodeAt(d)&255);return u}function zr(y,u){let d,b,P;const R=[];for(let L=0;L<y.length&&!((u-=2)<0);++L)d=y.charCodeAt(L),b=d>>8,P=d%256,R.push(P),R.push(b);return R}function Sn(y){return t.toByteArray(ee(y))}function qr(y,u,d,b){let P;for(P=0;P<b&&!(P+d>=u.length||P>=y.length);++P)u[P+d]=y[P];return P}function st(y,u){return y instanceof u||y!=null&&y.constructor!=null&&y.constructor.name!=null&&y.constructor.name===u.name}function Er(y){return y!==y}const Pn=function(){const y="0123456789abcdef",u=new Array(256);for(let d=0;d<16;++d){const b=d*16;for(let P=0;P<16;++P)u[b+P]=y[d]+y[P]}return u}();function ut(y){return typeof BigInt>"u"?xr:y}function xr(){throw new Error("BigInt not supported")}})(Jt);var Ei={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}};Ei.Null=Ei.Nil;for(var nu in Ei)Ei[nu].toJSON=(function(e){return e}).bind(null,nu);var uc=Ei,kr=uc;function Ud(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function fc(e){return kr.Nil(e)?"":Ud(e.constructor)}function _b(e){return kr.Function(e)?"":kr.String(e)?JSON.stringify(e):e&&kr.Object(e)?"":e}function dc(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function gs(e){return kr.Function(e)?e.toJSON?e.toJSON():Ud(e):kr.Array(e)?"Array":e&&kr.Object(e)?"Object":e!==void 0?e:""}function Ld(e,t,r){var n=_b(t);return"Expected "+gs(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Wt(e,t,r){r=r||fc(t),this.message=Ld(e,t,r),dc(this,Wt),this.__type=e,this.__value=t,this.__valueTypeName=r}Wt.prototype=Object.create(Error.prototype);Wt.prototype.constructor=Wt;function vb(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),Ld('property "'+gs(r)+s+gs(e),n,i)}function on(e,t,r,n,i){e?(i=i||fc(n),this.message=vb(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',dc(this,Wt),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}on.prototype=Object.create(Error.prototype);on.prototype.constructor=Wt;function Eb(e,t){return new Wt(e,{},t)}function xb(e,t,r){return e instanceof on?(t=t+"."+e.__property,e=new on(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Wt&&(e=new on(e.__type,t,r,e.__value,e.__valueTypeName)),dc(e),e}var Nd={TfTypeError:Wt,TfPropertyTypeError:on,tfCustomError:Eb,tfSubError:xb,tfJSON:gs,getValueTypeName:fc},xo,iu;function Ab(){if(iu)return xo;iu=1;var e=uc,t=Nd;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function i(S,N){var M=S.toJSON();function B(W){if(!S(W))return!1;if(W.length===N)return!0;throw t.tfCustomError(M+"(Length: "+N+")",M+"(Length: "+W.length+")")}return B.toJSON=function(){return M},B}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function f(S,N,M){M=M||e.Number;function B(W,U){return M(W,U)&&W>S&&W<N}return B.toJSON=function(){return`${M.toJSON()} between [${S}, ${N}]`},B}var l=Math.pow(2,53)-1;function h(S){return typeof S=="number"&&isFinite(S)}function m(S){return S<<24>>24===S}function p(S){return S<<16>>16===S}function g(S){return(S|0)===S}function v(S){return typeof S=="number"&&S>=-l&&S<=l&&Math.floor(S)===S}function x(S){return(S&255)===S}function I(S){return(S&65535)===S}function k(S){return S>>>0===S}function A(S){return typeof S=="number"&&S>=0&&S<=l&&Math.floor(S)===S}var E={ArrayN:s,Buffer:r,BufferN:o,Finite:h,Hex:n,HexN:a,Int8:m,Int16:p,Int32:g,Int53:v,Range:f,StringN:c,UInt8:x,UInt16:I,UInt32:k,UInt53:A};for(var T in E)E[T].toJSON=(function(S){return S}).bind(null,T);return xo=E,xo}var Ui=Nd,$e=uc,Lt=Ui.tfJSON,Fd=Ui.TfTypeError,$d=Ui.TfPropertyTypeError,Bn=Ui.tfSubError,Sb=Ui.getValueTypeName,Ht={arrayOf:function(t,r){t=St(t),r=r||{};function n(i,s){return!$e.Array(i)||$e.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(o,a){try{return Qe(t,o,s)}catch(c){throw Bn(c,a)}})}return n.toJSON=function(){var i="["+Lt(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=St(t);function r(n,i){return $e.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+Lt(t)},r},map:function(t,r){t=St(t),r&&(r=St(r));function n(i,s){if(!$e.Object(i)||$e.Nil(i))return!1;for(var o in i){try{r&&Qe(r,o,s)}catch(c){throw Bn(c,o,"key")}try{var a=i[o];Qe(t,a,s)}catch(c){throw Bn(c,o)}}return!0}return r?n.toJSON=function(){return"{"+Lt(r)+": "+Lt(t)+"}"}:n.toJSON=function(){return"{"+Lt(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=St(t[n]);function i(s,o){if(!$e.Object(s)||$e.Nil(s))return!1;var a;try{for(a in r){var c=r[a],f=s[a];Qe(c,f,o)}}catch(l){throw Bn(l,a)}if(o){for(a in s)if(!r[a])throw new $d(void 0,a)}return!0}return i.toJSON=function(){return Lt(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(St);function r(n,i){return t.some(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Lt).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(St);function r(n,i){return t.every(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Lt).join(" & ")},r},quacksLike:function(t){function r(n){return t===Sb(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(St);function r(n,i){return $e.Nil(n)||$e.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return Qe(s,n[o],i)}catch(a){throw Bn(a,o)}})}return r.toJSON=function(){return"("+t.map(Lt).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Ht.oneOf=Ht.anyOf;function St(e){if($e.String(e))return e[0]==="?"?Ht.maybe(e.slice(1)):$e[e]||Ht.quacksLike(e);if(e&&$e.Object(e)){if($e.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Ht.arrayOf(e[0])}return Ht.object(e)}else if($e.Function(e))return e;return Ht.value(e)}function Qe(e,t,r,n){if($e.Function(e)){if(e(t,r))return!0;throw new Fd(n||e,t)}return Qe(St(e),t,r)}for(var lr in $e)Qe[lr]=$e[lr];for(lr in Ht)Qe[lr]=Ht[lr];var su=Ab();for(lr in su)Qe[lr]=su[lr];Qe.compile=St;Qe.TfTypeError=Fd;Qe.TfPropertyTypeError=$d;var Md=Qe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Jt;e.typeforce=Md;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(l,h){return l.length!==h.length?!1:l.every((m,p)=>m.equals(h[p]))}e.stacksEqual=i;function s(l){if(!t.Buffer.isBuffer(l)||l.length<33)return!1;const h=l[0],m=l.slice(1,33);if(m.compare(r)===0||m.compare(n)>=0)return!1;if((h===2||h===3)&&l.length===33)return!0;const p=l.slice(33);return p.compare(r)===0||p.compare(n)>=0?!1:h===4&&l.length===65}e.isPoint=s;const o=21*1e14;function a(l){return e.typeforce.UInt53(l)&&l<=o}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function c(l){return!l||!("output"in l)||!t.Buffer.isBuffer(l.output)?!1:l.version!==void 0?(l.version&e.TAPLEAF_VERSION_MASK)===l.version:!0}e.isTapleaf=c;function f(l){return(0,e.Array)(l)?l.length!==2?!1:l.every(h=>f(h)):c(l)}e.isTaptree=f,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})(Ve);var Li={},Me={};Object.defineProperty(Me,"__esModule",{value:!0});Me.BufferReader=Me.BufferWriter=Me.cloneBuffer=Me.reverseBuffer=Me.writeUInt64LE=Me.readUInt64LE=Me.varuint=void 0;const Ir=Ve,{typeforce:Hd}=Ir,xi=Zu;Me.varuint=xi;function Dd(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 jd(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Dd(n+r,9007199254740991),n+r}Me.readUInt64LE=jd;function Gd(e,t,r){return Dd(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Me.writeUInt64LE=Gd;function Pb(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}Me.reverseBuffer=Pb;function Tb(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Me.cloneBuffer=Tb;class lc{static withCapacity(t){return new lc(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Hd(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=Gd(this.buffer,t,this.offset)}writeVarInt(t){xi.encode(t,this.buffer,this.offset),this.offset+=xi.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}Me.BufferWriter=lc;class kb{constructor(t,r=0){this.buffer=t,this.offset=r,Hd(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=jd(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=xi.decode(this.buffer,this.offset);return this.offset+=xi.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}Me.BufferReader=kb;var gr={};const Ib=ac(km);var pn={},Mr={},wr={};Object.defineProperty(wr,"__esModule",{value:!0});wr.anumber=pa;wr.abytes=zd;wr.ahash=Cb;wr.aexists=Ob;wr.aoutput=Rb;function pa(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Bb(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function zd(e,...t){if(!Bb(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Cb(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");pa(e.outputLen),pa(e.blockLen)}function Ob(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 Rb(e,t){zd(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var hc={},Hs={};Object.defineProperty(Hs,"__esModule",{value:!0});Hs.crypto=void 0;Hs.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.isLE=void 0,e.isBytes=n,e.u8=i,e.u32=s,e.createView=o,e.rotr=a,e.rotl=c,e.byteSwap=f,e.byteSwap32=l,e.bytesToHex=m,e.hexToBytes=v,e.asyncLoop=I,e.utf8ToBytes=k,e.toBytes=A,e.concatBytes=E,e.checkOpts=S,e.wrapConstructor=N,e.wrapConstructorWithOpts=M,e.wrapXOFConstructorWithOpts=B,e.randomBytes=W;const t=Hs,r=wr;function n(U){return U instanceof Uint8Array||ArrayBuffer.isView(U)&&U.constructor.name==="Uint8Array"}function i(U){return new Uint8Array(U.buffer,U.byteOffset,U.byteLength)}function s(U){return new Uint32Array(U.buffer,U.byteOffset,Math.floor(U.byteLength/4))}function o(U){return new DataView(U.buffer,U.byteOffset,U.byteLength)}function a(U,D){return U<<32-D|U>>>D}function c(U,D){return U<<D|U>>>32-D>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function f(U){return U<<24&4278190080|U<<8&16711680|U>>>8&65280|U>>>24&255}e.byteSwapIfBE=e.isLE?U=>U:U=>f(U);function l(U){for(let D=0;D<U.length;D++)U[D]=f(U[D])}const h=Array.from({length:256},(U,D)=>D.toString(16).padStart(2,"0"));function m(U){(0,r.abytes)(U);let D="";for(let j=0;j<U.length;j++)D+=h[U[j]];return D}const p={_0:48,_9:57,A:65,F:70,a:97,f:102};function g(U){if(U>=p._0&&U<=p._9)return U-p._0;if(U>=p.A&&U<=p.F)return U-(p.A-10);if(U>=p.a&&U<=p.f)return U-(p.a-10)}function v(U){if(typeof U!="string")throw new Error("hex string expected, got "+typeof U);const D=U.length,j=D/2;if(D%2)throw new Error("hex string expected, got unpadded hex of length "+D);const V=new Uint8Array(j);for(let X=0,ne=0;X<j;X++,ne+=2){const he=g(U.charCodeAt(ne)),_e=g(U.charCodeAt(ne+1));if(he===void 0||_e===void 0){const Te=U[ne]+U[ne+1];throw new Error('hex string expected, got non-hex character "'+Te+'" at index '+ne)}V[X]=he*16+_e}return V}const x=async()=>{};e.nextTick=x;async function I(U,D,j){let V=Date.now();for(let X=0;X<U;X++){j(X);const ne=Date.now()-V;ne>=0&&ne<D||(await(0,e.nextTick)(),V+=ne)}}function k(U){if(typeof U!="string")throw new Error("utf8ToBytes expected string, got "+typeof U);return new Uint8Array(new TextEncoder().encode(U))}function A(U){return typeof U=="string"&&(U=k(U)),(0,r.abytes)(U),U}function E(...U){let D=0;for(let V=0;V<U.length;V++){const X=U[V];(0,r.abytes)(X),D+=X.length}const j=new Uint8Array(D);for(let V=0,X=0;V<U.length;V++){const ne=U[V];j.set(ne,X),X+=ne.length}return j}class T{clone(){return this._cloneInto()}}e.Hash=T;function S(U,D){if(D!==void 0&&{}.toString.call(D)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(U,D)}function N(U){const D=V=>U().update(A(V)).digest(),j=U();return D.outputLen=j.outputLen,D.blockLen=j.blockLen,D.create=()=>U(),D}function M(U){const D=(V,X)=>U(X).update(A(V)).digest(),j=U({});return D.outputLen=j.outputLen,D.blockLen=j.blockLen,D.create=V=>U(V),D}function B(U){const D=(V,X)=>U(X).update(A(V)).digest(),j=U({});return D.outputLen=j.outputLen,D.blockLen=j.blockLen,D.create=V=>U(V),D}function W(U=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(U));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(U);throw new Error("crypto.getRandomValues must be defined")}})(hc);Object.defineProperty(Mr,"__esModule",{value:!0});Mr.HashMD=void 0;Mr.setBigUint64=qd;Mr.Chi=Ub;Mr.Maj=Lb;const Ao=wr,Cn=hc;function qd(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,f=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+f,a,n)}function Ub(e,t,r){return e&t^~e&r}function Lb(e,t,r){return e&t^e&r^t&r}class Nb extends Cn.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,Cn.createView)(this.buffer)}update(t){(0,Ao.aexists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,Cn.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,Cn.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,Ao.aexists)(this),(0,Ao.aoutput)(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 h=o;h<i;h++)r[h]=0;qd(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,Cn.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],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}}Mr.HashMD=Nb;Object.defineProperty(pn,"__esModule",{value:!0});pn.sha1=pn.SHA1=void 0;const So=Mr,as=hc,On=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),ir=new Uint32Array(80);class Vd extends So.HashMD{constructor(){super(64,20,8,!1),this.A=On[0]|0,this.B=On[1]|0,this.C=On[2]|0,this.D=On[3]|0,this.E=On[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)ir[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)ir[c]=(0,as.rotl)(ir[c-3]^ir[c-8]^ir[c-14]^ir[c-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let c=0;c<80;c++){let f,l;c<20?(f=(0,So.Chi)(i,s,o),l=1518500249):c<40?(f=i^s^o,l=1859775393):c<60?(f=(0,So.Maj)(i,s,o),l=2400959708):(f=i^s^o,l=3395469782);const h=(0,as.rotl)(n,5)+f+a+l+ir[c]|0;a=o,o=s,s=(0,as.rotl)(i,30),i=n,n=h}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(){ir.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}pn.SHA1=Vd;pn.sha1=(0,as.wrapConstructor)(()=>new Vd);const Wd=ac(Rm);(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=Ib,r=pn,n=Wd;function i(l){return Buffer.from((0,t.ripemd160)(Uint8Array.from(l)))}e.ripemd160=i;function s(l){return Buffer.from((0,r.sha1)(Uint8Array.from(l)))}e.sha1=s;function o(l){return Buffer.from((0,n.sha256)(Uint8Array.from(l)))}e.sha256=o;function a(l){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(l))))}e.hash160=a;function c(l){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(l))))}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 f(l,h){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[l],h]))}e.taggedHash=f})(gr);var Po={},Gt={};Object.defineProperty(Gt,"__esModule",{value:!0});Gt.encode=Gt.decode=Gt.check=void 0;function Fb(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))}Gt.check=Fb;function $b(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)}}Gt.decode=$b;function Mb(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}Gt.encode=Mb;var Nr={};Object.defineProperty(Nr,"__esModule",{value:!0});Nr.REVERSE_OPS=Nr.OPS=void 0;const ya={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};Nr.OPS=ya;const Kd={};Nr.REVERSE_OPS=Kd;for(const e of Object.keys(ya)){const t=ya[e];Kd[t]=e}var hr={};Object.defineProperty(hr,"__esModule",{value:!0});hr.decode=hr.encode=hr.encodingLength=void 0;const fr=Nr;function Yd(e){return e<fr.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}hr.encodingLength=Yd;function Hb(e,t,r){const n=Yd(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(fr.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(fr.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(fr.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}hr.encode=Hb;function Db(e,t){const r=e.readUInt8(t);let n,i;if(r<fr.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===fr.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===fr.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==fr.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}hr.decode=Db;var yn={};Object.defineProperty(yn,"__esModule",{value:!0});yn.encode=yn.decode=void 0;function jb(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}yn.decode=jb;function Gb(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function zb(e){let t=Math.abs(e);const r=Gb(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}yn.encode=zb;var Sr={},ou;function qb(){if(ou)return Sr;ou=1,Object.defineProperty(Sr,"__esModule",{value:!0}),Sr.encode=Sr.decode=void 0;const e=Gt,t=ct(),r=Ve,{typeforce:n}=r,i=Buffer.alloc(1,0);function s(f){let l=0;for(;f[l]===0;)++l;return l===f.length?i:(f=f.slice(l),f[0]&128?Buffer.concat([i,f],1+f.length):f)}function o(f){f[0]===0&&(f=f.slice(1));const l=Buffer.alloc(32,0),h=Math.max(0,32-f.length);return f.copy(l,h),l}function a(f){const l=f.readUInt8(f.length-1);if(!(0,t.isDefinedHashType)(l))throw new Error("Invalid hashType "+l);const h=e.decode(f.slice(0,-1)),m=o(h.r),p=o(h.s);return{signature:Buffer.concat([m,p],64),hashType:l}}Sr.decode=a;function c(f,l){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:f,hashType:l}),!(0,t.isDefinedHashType)(l))throw new Error("Invalid hashType "+l);const h=Buffer.allocUnsafe(1);h.writeUInt8(l,0);const m=s(f.slice(0,32)),p=s(f.slice(32,64));return Buffer.concat([e.encode(m,p),h])}return Sr.encode=c,Sr}var au;function ct(){return au||(au=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=Gt,r=Nr;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=hr,i=yn,s=qb(),o=Ve,{typeforce:a}=o,c=r.OPS.OP_RESERVED;function f(B){return o.Number(B)&&(B===r.OPS.OP_0||B>=r.OPS.OP_1&&B<=r.OPS.OP_16||B===r.OPS.OP_1NEGATE)}function l(B){return o.Buffer(B)||f(B)}function h(B){return o.Array(B)&&B.every(l)}e.isPushOnly=h;function m(B){return B.length-B.filter(l).length}e.countNonPushOnlyOPs=m;function p(B){if(B.length===0)return r.OPS.OP_0;if(B.length===1){if(B[0]>=1&&B[0]<=16)return c+B[0];if(B[0]===129)return r.OPS.OP_1NEGATE}}function g(B){return Buffer.isBuffer(B)}function v(B){return o.Array(B)}function x(B){return Buffer.isBuffer(B)}function I(B){if(g(B))return B;a(o.Array,B);const W=B.reduce((j,V)=>x(V)?V.length===1&&p(V)!==void 0?j+1:j+n.encodingLength(V.length)+V.length:j+1,0),U=Buffer.allocUnsafe(W);let D=0;if(B.forEach(j=>{if(x(j)){const V=p(j);if(V!==void 0){U.writeUInt8(V,D),D+=1;return}D+=n.encode(U,j.length,D),j.copy(U,D),D+=j.length}else U.writeUInt8(j,D),D+=1}),D!==U.length)throw new Error("Could not decode chunks");return U}e.compile=I;function k(B){if(v(B))return B;a(o.Buffer,B);const W=[];let U=0;for(;U<B.length;){const D=B[U];if(D>r.OPS.OP_0&&D<=r.OPS.OP_PUSHDATA4){const j=n.decode(B,U);if(j===null||(U+=j.size,U+j.number>B.length))return null;const V=B.slice(U,U+j.number);U+=j.number;const X=p(V);X!==void 0?W.push(X):W.push(V)}else W.push(D),U+=1}return W}e.decompile=k;function A(B){if(g(B)&&(B=k(B)),!B)throw new Error("Could not convert invalid chunks to ASM");return B.map(W=>{if(x(W)){const U=p(W);if(U===void 0)return W.toString("hex");W=U}return r.REVERSE_OPS[W]}).join(" ")}e.toASM=A;function E(B){return a(o.String,B),I(B.split(" ").map(W=>r.OPS[W]!==void 0?r.OPS[W]:(a(o.Hex,W),Buffer.from(W,"hex"))))}e.fromASM=E;function T(B){return B=k(B),a(h,B),B.map(W=>x(W)?W:W===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(W-c))}e.toStack=T;function S(B){return o.isPoint(B)}e.isCanonicalPubKey=S;function N(B){const W=B&-129;return W>0&&W<4}e.isDefinedHashType=N;function M(B){return!Buffer.isBuffer(B)||!N(B[B.length-1])?!1:t.check(B.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s}(Po)),Po}Object.defineProperty(Li,"__esModule",{value:!0});Li.Transaction=void 0;const Be=Me,Ke=gr,cu=ct(),Vb=ct(),se=Ve,{typeforce:_t}=se;function xt(e){const t=e.length;return Be.varuint.encodingLength(t)+t}function Wb(e){const t=e.length;return Be.varuint.encodingLength(t)+e.reduce((r,n)=>r+xt(n),0)}const ur=Buffer.allocUnsafe(0),To=[],ko=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),uu=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Kb=Buffer.from("ffffffffffffffff","hex"),Yb={script:ur,valueBuffer:Kb};function Xb(e){return e.value!==void 0}class te{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Be.BufferReader(t),i=new te;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===te.ADVANCED_TRANSACTION_MARKER&&o===te.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let l=0;l<c;++l)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:To});const f=n.readVarInt();for(let l=0;l<f;++l)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let l=0;l<c;++l)i.ins[l].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 te.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){_t(se.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&te.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return _t(se.tuple(se.Hash256bit,se.UInt32,se.maybe(se.UInt32),se.maybe(se.Buffer)),arguments),se.Null(n)&&(n=te.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||ur,sequence:n,witness:To})-1}addOutput(t,r){return _t(se.tuple(se.Buffer,se.Satoshi),arguments),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}stripWitnesses(){this.ins.forEach(t=>{t.witness=To})}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+xt(i.script),0)+this.outs.reduce((n,i)=>n+8+xt(i.script),0)+(r?this.ins.reduce((n,i)=>n+Wb(i.witness),0):0)}clone(){const t=new te;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(_t(se.tuple(se.UInt32,se.Buffer,se.Number),arguments),t>=this.ins.length)return uu;const i=cu.compile(cu.decompile(r).filter(a=>a!==Vb.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===te.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===te.SIGHASH_SINGLE){if(t>=this.outs.length)return uu;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=Yb;s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&te.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=ur}),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),Ke.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(_t(se.tuple(se.UInt32,_t.arrayOf(se.Buffer),_t.arrayOf(se.Satoshi),se.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===te.SIGHASH_DEFAULT?te.SIGHASH_ALL:i&te.SIGHASH_OUTPUT_MASK,f=(i&te.SIGHASH_INPUT_MASK)===te.SIGHASH_ANYONECANPAY,l=a===te.SIGHASH_NONE,h=a===te.SIGHASH_SINGLE;let m=ur,p=ur,g=ur,v=ur,x=ur;if(!f){let E=Be.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(T=>{E.writeSlice(T.hash),E.writeUInt32(T.index)}),m=Ke.sha256(E.end()),E=Be.BufferWriter.withCapacity(8*this.ins.length),n.forEach(T=>E.writeUInt64(T)),p=Ke.sha256(E.end()),E=Be.BufferWriter.withCapacity(r.map(xt).reduce((T,S)=>T+S)),r.forEach(T=>E.writeVarSlice(T)),g=Ke.sha256(E.end()),E=Be.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(T=>E.writeUInt32(T.sequence)),v=Ke.sha256(E.end())}if(l||h){if(h&&t<this.outs.length){const E=this.outs[t],T=Be.BufferWriter.withCapacity(8+xt(E.script));T.writeUInt64(E.value),T.writeVarSlice(E.script),x=Ke.sha256(T.end())}}else{const E=this.outs.map(S=>8+xt(S.script)).reduce((S,N)=>S+N),T=Be.BufferWriter.withCapacity(E);this.outs.forEach(S=>{T.writeUInt64(S.value),T.writeVarSlice(S.script)}),x=Ke.sha256(T.end())}const I=(s?2:0)+(o?1:0),k=174-(f?49:0)-(l?32:0)+(o?32:0)+(s?37:0),A=Be.BufferWriter.withCapacity(k);if(A.writeUInt8(i),A.writeInt32(this.version),A.writeUInt32(this.locktime),A.writeSlice(m),A.writeSlice(p),A.writeSlice(g),A.writeSlice(v),l||h||A.writeSlice(x),A.writeUInt8(I),f){const E=this.ins[t];A.writeSlice(E.hash),A.writeUInt32(E.index),A.writeUInt64(n[t]),A.writeVarSlice(r[t]),A.writeUInt32(E.sequence)}else A.writeUInt32(t);if(o){const E=Be.BufferWriter.withCapacity(xt(o));E.writeVarSlice(o),A.writeSlice(Ke.sha256(E.end()))}return h&&A.writeSlice(x),s&&(A.writeSlice(s),A.writeUInt8(0),A.writeUInt32(4294967295)),Ke.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),A.end()]))}hashForWitnessV0(t,r,n,i){_t(se.tuple(se.UInt32,se.Buffer,se.Satoshi,se.UInt32),arguments);let s=Buffer.from([]),o,a=ko,c=ko,f=ko;if(i&te.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(h=>{o.writeSlice(h.hash),o.writeUInt32(h.index)}),c=Ke.hash256(s)),!(i&te.SIGHASH_ANYONECANPAY)&&(i&31)!==te.SIGHASH_SINGLE&&(i&31)!==te.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(h=>{o.writeUInt32(h.sequence)}),f=Ke.hash256(s)),(i&31)!==te.SIGHASH_SINGLE&&(i&31)!==te.SIGHASH_NONE){const h=this.outs.reduce((m,p)=>m+8+xt(p.script),0);s=Buffer.allocUnsafe(h),o=new Be.BufferWriter(s,0),this.outs.forEach(m=>{o.writeUInt64(m.value),o.writeVarSlice(m.script)}),a=Ke.hash256(s)}else if((i&31)===te.SIGHASH_SINGLE&&t<this.outs.length){const h=this.outs[t];s=Buffer.allocUnsafe(8+xt(h.script)),o=new Be.BufferWriter(s,0),o.writeUInt64(h.value),o.writeVarSlice(h.script),a=Ke.hash256(s)}s=Buffer.allocUnsafe(156+xt(r)),o=new Be.BufferWriter(s,0);const l=this.ins[t];return o.writeInt32(this.version),o.writeSlice(c),o.writeSlice(f),o.writeSlice(l.hash),o.writeUInt32(l.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(l.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Ke.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):Ke.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){_t(se.tuple(se.Number,se.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){_t(se.tuple(se.Number,[se.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(te.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(te.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=>{Xb(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}}Li.Transaction=te;te.DEFAULT_SEQUENCE=4294967295;te.SIGHASH_DEFAULT=0;te.SIGHASH_ALL=1;te.SIGHASH_NONE=2;te.SIGHASH_SINGLE=3;te.SIGHASH_ANYONECANPAY=128;te.SIGHASH_OUTPUT_MASK=3;te.SIGHASH_INPUT_MASK=128;te.ADVANCED_TRANSACTION_MARKER=0;te.ADVANCED_TRANSACTION_FLAG=1;var le={},Ni={};Object.defineProperty(Ni,"__esModule",{value:!0});const Jb=9007199254740991;function pc(e){if(e<0||e>Jb||e%1!==0)throw new RangeError("value out of range")}function zn(e,t,r){if(pc(e),t||(t=Buffer.allocUnsafe(Xd(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(zn,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(zn,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(zn,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(zn,{bytes:9})),t}Ni.encode=zn;function qn(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(qn,{bytes:1}),r;if(r===253)return Object.assign(qn,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(qn,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(qn,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return pc(s),s}}Ni.decode=qn;function Xd(e){return pc(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Ni.encodingLength=Xd;var Io={},Ds={},qe={};Object.defineProperty(qe,"__esModule",{value:!0});qe.testnet=qe.regtest=qe.bitcoin=void 0;qe.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
46
|
+
*/(function(e){const t=Ms,r=fc,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=k,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=s(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const y=new Uint8Array(1),u={foo:function(){return 42}};return Object.setPrototypeOf(u,Uint8Array.prototype),Object.setPrototypeOf(y,u),y.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(y){if(y>i)throw new RangeError('The value "'+y+'" is invalid for option "size"');const u=new Uint8Array(y);return Object.setPrototypeOf(u,a.prototype),u}function a(y,u,d){if(typeof y=="number"){if(typeof u=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return h(y)}return c(y,u,d)}a.poolSize=8192;function c(y,u,d){if(typeof y=="string")return m(y,u);if(ArrayBuffer.isView(y))return g(y);if(y==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y);if(st(y,ArrayBuffer)||y&&st(y.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(st(y,SharedArrayBuffer)||y&&st(y.buffer,SharedArrayBuffer)))return v(y,u,d);if(typeof y=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const b=y.valueOf&&y.valueOf();if(b!=null&&b!==y)return a.from(b,u,d);const P=x(y);if(P)return P;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof y[Symbol.toPrimitive]=="function")return a.from(y[Symbol.toPrimitive]("string"),u,d);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y)}a.from=function(y,u,d){return c(y,u,d)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function f(y){if(typeof y!="number")throw new TypeError('"size" argument must be of type number');if(y<0)throw new RangeError('The value "'+y+'" is invalid for option "size"')}function l(y,u,d){return f(y),y<=0?o(y):u!==void 0?typeof d=="string"?o(y).fill(u,d):o(y).fill(u):o(y)}a.alloc=function(y,u,d){return l(y,u,d)};function h(y){return f(y),o(y<0?0:I(y)|0)}a.allocUnsafe=function(y){return h(y)},a.allocUnsafeSlow=function(y){return h(y)};function m(y,u){if((typeof u!="string"||u==="")&&(u="utf8"),!a.isEncoding(u))throw new TypeError("Unknown encoding: "+u);const d=A(y,u)|0;let b=o(d);const P=b.write(y,u);return P!==d&&(b=b.slice(0,P)),b}function p(y){const u=y.length<0?0:I(y.length)|0,d=o(u);for(let b=0;b<u;b+=1)d[b]=y[b]&255;return d}function g(y){if(st(y,Uint8Array)){const u=new Uint8Array(y);return v(u.buffer,u.byteOffset,u.byteLength)}return p(y)}function v(y,u,d){if(u<0||y.byteLength<u)throw new RangeError('"offset" is outside of buffer bounds');if(y.byteLength<u+(d||0))throw new RangeError('"length" is outside of buffer bounds');let b;return u===void 0&&d===void 0?b=new Uint8Array(y):d===void 0?b=new Uint8Array(y,u):b=new Uint8Array(y,u,d),Object.setPrototypeOf(b,a.prototype),b}function x(y){if(a.isBuffer(y)){const u=I(y.length)|0,d=o(u);return d.length===0||y.copy(d,0,0,u),d}if(y.length!==void 0)return typeof y.length!="number"||Er(y.length)?o(0):p(y);if(y.type==="Buffer"&&Array.isArray(y.data))return p(y.data)}function I(y){if(y>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return y|0}function k(y){return+y!=y&&(y=0),a.alloc(+y)}a.isBuffer=function(u){return u!=null&&u._isBuffer===!0&&u!==a.prototype},a.compare=function(u,d){if(st(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),st(d,Uint8Array)&&(d=a.from(d,d.offset,d.byteLength)),!a.isBuffer(u)||!a.isBuffer(d))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(u===d)return 0;let b=u.length,P=d.length;for(let R=0,L=Math.min(b,P);R<L;++R)if(u[R]!==d[R]){b=u[R],P=d[R];break}return b<P?-1:P<b?1:0},a.isEncoding=function(u){switch(String(u).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(u,d){if(!Array.isArray(u))throw new TypeError('"list" argument must be an Array of Buffers');if(u.length===0)return a.alloc(0);let b;if(d===void 0)for(d=0,b=0;b<u.length;++b)d+=u[b].length;const P=a.allocUnsafe(d);let R=0;for(b=0;b<u.length;++b){let L=u[b];if(st(L,Uint8Array))R+L.length>P.length?(a.isBuffer(L)||(L=a.from(L)),L.copy(P,R)):Uint8Array.prototype.set.call(P,L,R);else if(a.isBuffer(L))L.copy(P,R);else throw new TypeError('"list" argument must be an Array of Buffers');R+=L.length}return P};function A(y,u){if(a.isBuffer(y))return y.length;if(ArrayBuffer.isView(y)||st(y,ArrayBuffer))return y.byteLength;if(typeof y!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof y);const d=y.length,b=arguments.length>2&&arguments[2]===!0;if(!b&&d===0)return 0;let P=!1;for(;;)switch(u){case"ascii":case"latin1":case"binary":return d;case"utf8":case"utf-8":return ae(y).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return d*2;case"hex":return d>>>1;case"base64":return Sn(y).length;default:if(P)return b?-1:ae(y).length;u=(""+u).toLowerCase(),P=!0}}a.byteLength=A;function E(y,u,d){let b=!1;if((u===void 0||u<0)&&(u=0),u>this.length||((d===void 0||d>this.length)&&(d=this.length),d<=0)||(d>>>=0,u>>>=0,d<=u))return"";for(y||(y="utf8");;)switch(y){case"hex":return Te(this,u,d);case"utf8":case"utf-8":return V(this,u,d);case"ascii":return he(this,u,d);case"latin1":case"binary":return _e(this,u,d);case"base64":return G(this,u,d);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return We(this,u,d);default:if(b)throw new TypeError("Unknown encoding: "+y);y=(y+"").toLowerCase(),b=!0}}a.prototype._isBuffer=!0;function T(y,u,d){const b=y[u];y[u]=y[d],y[d]=b}a.prototype.swap16=function(){const u=this.length;if(u%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let d=0;d<u;d+=2)T(this,d,d+1);return this},a.prototype.swap32=function(){const u=this.length;if(u%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let d=0;d<u;d+=4)T(this,d,d+3),T(this,d+1,d+2);return this},a.prototype.swap64=function(){const u=this.length;if(u%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let d=0;d<u;d+=8)T(this,d,d+7),T(this,d+1,d+6),T(this,d+2,d+5),T(this,d+3,d+4);return this},a.prototype.toString=function(){const u=this.length;return u===0?"":arguments.length===0?V(this,0,u):E.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(u){if(!a.isBuffer(u))throw new TypeError("Argument must be a Buffer");return this===u?!0:a.compare(this,u)===0},a.prototype.inspect=function(){let u="";const d=e.INSPECT_MAX_BYTES;return u=this.toString("hex",0,d).replace(/(.{2})/g,"$1 ").trim(),this.length>d&&(u+=" ... "),"<Buffer "+u+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(u,d,b,P,R){if(st(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(u))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof u);if(d===void 0&&(d=0),b===void 0&&(b=u?u.length:0),P===void 0&&(P=0),R===void 0&&(R=this.length),d<0||b>u.length||P<0||R>this.length)throw new RangeError("out of range index");if(P>=R&&d>=b)return 0;if(P>=R)return-1;if(d>=b)return 1;if(d>>>=0,b>>>=0,P>>>=0,R>>>=0,this===u)return 0;let L=R-P,re=b-d;const Se=Math.min(L,re),Ee=this.slice(P,R),Pe=u.slice(d,b);for(let de=0;de<Se;++de)if(Ee[de]!==Pe[de]){L=Ee[de],re=Pe[de];break}return L<re?-1:re<L?1:0};function S(y,u,d,b,P){if(y.length===0)return-1;if(typeof d=="string"?(b=d,d=0):d>2147483647?d=2147483647:d<-2147483648&&(d=-2147483648),d=+d,Er(d)&&(d=P?0:y.length-1),d<0&&(d=y.length+d),d>=y.length){if(P)return-1;d=y.length-1}else if(d<0)if(P)d=0;else return-1;if(typeof u=="string"&&(u=a.from(u,b)),a.isBuffer(u))return u.length===0?-1:N(y,u,d,b,P);if(typeof u=="number")return u=u&255,typeof Uint8Array.prototype.indexOf=="function"?P?Uint8Array.prototype.indexOf.call(y,u,d):Uint8Array.prototype.lastIndexOf.call(y,u,d):N(y,[u],d,b,P);throw new TypeError("val must be string, number or Buffer")}function N(y,u,d,b,P){let R=1,L=y.length,re=u.length;if(b!==void 0&&(b=String(b).toLowerCase(),b==="ucs2"||b==="ucs-2"||b==="utf16le"||b==="utf-16le")){if(y.length<2||u.length<2)return-1;R=2,L/=2,re/=2,d/=2}function Se(Pe,de){return R===1?Pe[de]:Pe.readUInt16BE(de*R)}let Ee;if(P){let Pe=-1;for(Ee=d;Ee<L;Ee++)if(Se(y,Ee)===Se(u,Pe===-1?0:Ee-Pe)){if(Pe===-1&&(Pe=Ee),Ee-Pe+1===re)return Pe*R}else Pe!==-1&&(Ee-=Ee-Pe),Pe=-1}else for(d+re>L&&(d=L-re),Ee=d;Ee>=0;Ee--){let Pe=!0;for(let de=0;de<re;de++)if(Se(y,Ee+de)!==Se(u,de)){Pe=!1;break}if(Pe)return Ee}return-1}a.prototype.includes=function(u,d,b){return this.indexOf(u,d,b)!==-1},a.prototype.indexOf=function(u,d,b){return S(this,u,d,b,!0)},a.prototype.lastIndexOf=function(u,d,b){return S(this,u,d,b,!1)};function M(y,u,d,b){d=Number(d)||0;const P=y.length-d;b?(b=Number(b),b>P&&(b=P)):b=P;const R=u.length;b>R/2&&(b=R/2);let L;for(L=0;L<b;++L){const re=parseInt(u.substr(L*2,2),16);if(Er(re))return L;y[d+L]=re}return L}function B(y,u,d,b){return qr(ae(u,y.length-d),y,d,b)}function W(y,u,d,b){return qr(Zt(u),y,d,b)}function U(y,u,d,b){return qr(Sn(u),y,d,b)}function D(y,u,d,b){return qr(zr(u,y.length-d),y,d,b)}a.prototype.write=function(u,d,b,P){if(d===void 0)P="utf8",b=this.length,d=0;else if(b===void 0&&typeof d=="string")P=d,b=this.length,d=0;else if(isFinite(d))d=d>>>0,isFinite(b)?(b=b>>>0,P===void 0&&(P="utf8")):(P=b,b=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const R=this.length-d;if((b===void 0||b>R)&&(b=R),u.length>0&&(b<0||d<0)||d>this.length)throw new RangeError("Attempt to write outside buffer bounds");P||(P="utf8");let L=!1;for(;;)switch(P){case"hex":return M(this,u,d,b);case"utf8":case"utf-8":return B(this,u,d,b);case"ascii":case"latin1":case"binary":return W(this,u,d,b);case"base64":return U(this,u,d,b);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,u,d,b);default:if(L)throw new TypeError("Unknown encoding: "+P);P=(""+P).toLowerCase(),L=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function G(y,u,d){return u===0&&d===y.length?t.fromByteArray(y):t.fromByteArray(y.slice(u,d))}function V(y,u,d){d=Math.min(y.length,d);const b=[];let P=u;for(;P<d;){const R=y[P];let L=null,re=R>239?4:R>223?3:R>191?2:1;if(P+re<=d){let Se,Ee,Pe,de;switch(re){case 1:R<128&&(L=R);break;case 2:Se=y[P+1],(Se&192)===128&&(de=(R&31)<<6|Se&63,de>127&&(L=de));break;case 3:Se=y[P+1],Ee=y[P+2],(Se&192)===128&&(Ee&192)===128&&(de=(R&15)<<12|(Se&63)<<6|Ee&63,de>2047&&(de<55296||de>57343)&&(L=de));break;case 4:Se=y[P+1],Ee=y[P+2],Pe=y[P+3],(Se&192)===128&&(Ee&192)===128&&(Pe&192)===128&&(de=(R&15)<<18|(Se&63)<<12|(Ee&63)<<6|Pe&63,de>65535&&de<1114112&&(L=de))}}L===null?(L=65533,re=1):L>65535&&(L-=65536,b.push(L>>>10&1023|55296),L=56320|L&1023),b.push(L),P+=re}return ne(b)}const X=4096;function ne(y){const u=y.length;if(u<=X)return String.fromCharCode.apply(String,y);let d="",b=0;for(;b<u;)d+=String.fromCharCode.apply(String,y.slice(b,b+=X));return d}function he(y,u,d){let b="";d=Math.min(y.length,d);for(let P=u;P<d;++P)b+=String.fromCharCode(y[P]&127);return b}function _e(y,u,d){let b="";d=Math.min(y.length,d);for(let P=u;P<d;++P)b+=String.fromCharCode(y[P]);return b}function Te(y,u,d){const b=y.length;(!u||u<0)&&(u=0),(!d||d<0||d>b)&&(d=b);let P="";for(let R=u;R<d;++R)P+=Pn[y[R]];return P}function We(y,u,d){const b=y.slice(u,d);let P="";for(let R=0;R<b.length-1;R+=2)P+=String.fromCharCode(b[R]+b[R+1]*256);return P}a.prototype.slice=function(u,d){const b=this.length;u=~~u,d=d===void 0?b:~~d,u<0?(u+=b,u<0&&(u=0)):u>b&&(u=b),d<0?(d+=b,d<0&&(d=0)):d>b&&(d=b),d<u&&(d=u);const P=this.subarray(u,d);return Object.setPrototypeOf(P,a.prototype),P};function fe(y,u,d){if(y%1!==0||y<0)throw new RangeError("offset is not uint");if(y+u>d)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=this[u],R=1,L=0;for(;++L<d&&(R*=256);)P+=this[u+L]*R;return P},a.prototype.readUintBE=a.prototype.readUIntBE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=this[u+--d],R=1;for(;d>0&&(R*=256);)P+=this[u+--d]*R;return P},a.prototype.readUint8=a.prototype.readUInt8=function(u,d){return u=u>>>0,d||fe(u,1,this.length),this[u]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(u,d){return u=u>>>0,d||fe(u,2,this.length),this[u]|this[u+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(u,d){return u=u>>>0,d||fe(u,2,this.length),this[u]<<8|this[u+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),(this[u]|this[u+1]<<8|this[u+2]<<16)+this[u+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),this[u]*16777216+(this[u+1]<<16|this[u+2]<<8|this[u+3])},a.prototype.readBigUInt64LE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=d+this[++u]*2**8+this[++u]*2**16+this[++u]*2**24,R=this[++u]+this[++u]*2**8+this[++u]*2**16+b*2**24;return BigInt(P)+(BigInt(R)<<BigInt(32))}),a.prototype.readBigUInt64BE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=d*2**24+this[++u]*2**16+this[++u]*2**8+this[++u],R=this[++u]*2**24+this[++u]*2**16+this[++u]*2**8+b;return(BigInt(P)<<BigInt(32))+BigInt(R)}),a.prototype.readIntLE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=this[u],R=1,L=0;for(;++L<d&&(R*=256);)P+=this[u+L]*R;return R*=128,P>=R&&(P-=Math.pow(2,8*d)),P},a.prototype.readIntBE=function(u,d,b){u=u>>>0,d=d>>>0,b||fe(u,d,this.length);let P=d,R=1,L=this[u+--P];for(;P>0&&(R*=256);)L+=this[u+--P]*R;return R*=128,L>=R&&(L-=Math.pow(2,8*d)),L},a.prototype.readInt8=function(u,d){return u=u>>>0,d||fe(u,1,this.length),this[u]&128?(255-this[u]+1)*-1:this[u]},a.prototype.readInt16LE=function(u,d){u=u>>>0,d||fe(u,2,this.length);const b=this[u]|this[u+1]<<8;return b&32768?b|4294901760:b},a.prototype.readInt16BE=function(u,d){u=u>>>0,d||fe(u,2,this.length);const b=this[u+1]|this[u]<<8;return b&32768?b|4294901760:b},a.prototype.readInt32LE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),this[u]|this[u+1]<<8|this[u+2]<<16|this[u+3]<<24},a.prototype.readInt32BE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),this[u]<<24|this[u+1]<<16|this[u+2]<<8|this[u+3]},a.prototype.readBigInt64LE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=this[u+4]+this[u+5]*2**8+this[u+6]*2**16+(b<<24);return(BigInt(P)<<BigInt(32))+BigInt(d+this[++u]*2**8+this[++u]*2**16+this[++u]*2**24)}),a.prototype.readBigInt64BE=ut(function(u){u=u>>>0,F(u,"offset");const d=this[u],b=this[u+7];(d===void 0||b===void 0)&&q(u,this.length-8);const P=(d<<24)+this[++u]*2**16+this[++u]*2**8+this[++u];return(BigInt(P)<<BigInt(32))+BigInt(this[++u]*2**24+this[++u]*2**16+this[++u]*2**8+b)}),a.prototype.readFloatLE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),r.read(this,u,!0,23,4)},a.prototype.readFloatBE=function(u,d){return u=u>>>0,d||fe(u,4,this.length),r.read(this,u,!1,23,4)},a.prototype.readDoubleLE=function(u,d){return u=u>>>0,d||fe(u,8,this.length),r.read(this,u,!0,52,8)},a.prototype.readDoubleBE=function(u,d){return u=u>>>0,d||fe(u,8,this.length),r.read(this,u,!1,52,8)};function ye(y,u,d,b,P,R){if(!a.isBuffer(y))throw new TypeError('"buffer" argument must be a Buffer instance');if(u>P||u<R)throw new RangeError('"value" argument is out of bounds');if(d+b>y.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(u,d,b,P){if(u=+u,d=d>>>0,b=b>>>0,!P){const re=Math.pow(2,8*b)-1;ye(this,u,d,b,re,0)}let R=1,L=0;for(this[d]=u&255;++L<b&&(R*=256);)this[d+L]=u/R&255;return d+b},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(u,d,b,P){if(u=+u,d=d>>>0,b=b>>>0,!P){const re=Math.pow(2,8*b)-1;ye(this,u,d,b,re,0)}let R=b-1,L=1;for(this[d+R]=u&255;--R>=0&&(L*=256);)this[d+R]=u/L&255;return d+b},a.prototype.writeUint8=a.prototype.writeUInt8=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,1,255,0),this[d]=u&255,d+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,65535,0),this[d]=u&255,this[d+1]=u>>>8,d+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,65535,0),this[d]=u>>>8,this[d+1]=u&255,d+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,4294967295,0),this[d+3]=u>>>24,this[d+2]=u>>>16,this[d+1]=u>>>8,this[d]=u&255,d+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,4294967295,0),this[d]=u>>>24,this[d+1]=u>>>16,this[d+2]=u>>>8,this[d+3]=u&255,d+4};function it(y,u,d,b,P){_(u,b,P,y,d,7);let R=Number(u&BigInt(4294967295));y[d++]=R,R=R>>8,y[d++]=R,R=R>>8,y[d++]=R,R=R>>8,y[d++]=R;let L=Number(u>>BigInt(32)&BigInt(4294967295));return y[d++]=L,L=L>>8,y[d++]=L,L=L>>8,y[d++]=L,L=L>>8,y[d++]=L,d}function Qt(y,u,d,b,P){_(u,b,P,y,d,7);let R=Number(u&BigInt(4294967295));y[d+7]=R,R=R>>8,y[d+6]=R,R=R>>8,y[d+5]=R,R=R>>8,y[d+4]=R;let L=Number(u>>BigInt(32)&BigInt(4294967295));return y[d+3]=L,L=L>>8,y[d+2]=L,L=L>>8,y[d+1]=L,L=L>>8,y[d]=L,d+8}a.prototype.writeBigUInt64LE=ut(function(u,d=0){return it(this,u,d,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=ut(function(u,d=0){return Qt(this,u,d,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(u,d,b,P){if(u=+u,d=d>>>0,!P){const Se=Math.pow(2,8*b-1);ye(this,u,d,b,Se-1,-Se)}let R=0,L=1,re=0;for(this[d]=u&255;++R<b&&(L*=256);)u<0&&re===0&&this[d+R-1]!==0&&(re=1),this[d+R]=(u/L>>0)-re&255;return d+b},a.prototype.writeIntBE=function(u,d,b,P){if(u=+u,d=d>>>0,!P){const Se=Math.pow(2,8*b-1);ye(this,u,d,b,Se-1,-Se)}let R=b-1,L=1,re=0;for(this[d+R]=u&255;--R>=0&&(L*=256);)u<0&&re===0&&this[d+R+1]!==0&&(re=1),this[d+R]=(u/L>>0)-re&255;return d+b},a.prototype.writeInt8=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,1,127,-128),u<0&&(u=255+u+1),this[d]=u&255,d+1},a.prototype.writeInt16LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,32767,-32768),this[d]=u&255,this[d+1]=u>>>8,d+2},a.prototype.writeInt16BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,2,32767,-32768),this[d]=u>>>8,this[d+1]=u&255,d+2},a.prototype.writeInt32LE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,2147483647,-2147483648),this[d]=u&255,this[d+1]=u>>>8,this[d+2]=u>>>16,this[d+3]=u>>>24,d+4},a.prototype.writeInt32BE=function(u,d,b){return u=+u,d=d>>>0,b||ye(this,u,d,4,2147483647,-2147483648),u<0&&(u=4294967295+u+1),this[d]=u>>>24,this[d+1]=u>>>16,this[d+2]=u>>>8,this[d+3]=u&255,d+4},a.prototype.writeBigInt64LE=ut(function(u,d=0){return it(this,u,d,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=ut(function(u,d=0){return Qt(this,u,d,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Rt(y,u,d,b,P,R){if(d+b>y.length)throw new RangeError("Index out of range");if(d<0)throw new RangeError("Index out of range")}function O(y,u,d,b,P){return u=+u,d=d>>>0,P||Rt(y,u,d,4),r.write(y,u,d,b,23,4),d+4}a.prototype.writeFloatLE=function(u,d,b){return O(this,u,d,!0,b)},a.prototype.writeFloatBE=function(u,d,b){return O(this,u,d,!1,b)};function C(y,u,d,b,P){return u=+u,d=d>>>0,P||Rt(y,u,d,8),r.write(y,u,d,b,52,8),d+8}a.prototype.writeDoubleLE=function(u,d,b){return C(this,u,d,!0,b)},a.prototype.writeDoubleBE=function(u,d,b){return C(this,u,d,!1,b)},a.prototype.copy=function(u,d,b,P){if(!a.isBuffer(u))throw new TypeError("argument should be a Buffer");if(b||(b=0),!P&&P!==0&&(P=this.length),d>=u.length&&(d=u.length),d||(d=0),P>0&&P<b&&(P=b),P===b||u.length===0||this.length===0)return 0;if(d<0)throw new RangeError("targetStart out of bounds");if(b<0||b>=this.length)throw new RangeError("Index out of range");if(P<0)throw new RangeError("sourceEnd out of bounds");P>this.length&&(P=this.length),u.length-d<P-b&&(P=u.length-d+b);const R=P-b;return this===u&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(d,b,P):Uint8Array.prototype.set.call(u,this.subarray(b,P),d),R},a.prototype.fill=function(u,d,b,P){if(typeof u=="string"){if(typeof d=="string"?(P=d,d=0,b=this.length):typeof b=="string"&&(P=b,b=this.length),P!==void 0&&typeof P!="string")throw new TypeError("encoding must be a string");if(typeof P=="string"&&!a.isEncoding(P))throw new TypeError("Unknown encoding: "+P);if(u.length===1){const L=u.charCodeAt(0);(P==="utf8"&&L<128||P==="latin1")&&(u=L)}}else typeof u=="number"?u=u&255:typeof u=="boolean"&&(u=Number(u));if(d<0||this.length<d||this.length<b)throw new RangeError("Out of range index");if(b<=d)return this;d=d>>>0,b=b===void 0?this.length:b>>>0,u||(u=0);let R;if(typeof u=="number")for(R=d;R<b;++R)this[R]=u;else{const L=a.isBuffer(u)?u:a.from(u,P),re=L.length;if(re===0)throw new TypeError('The value "'+u+'" is invalid for argument "value"');for(R=0;R<b-d;++R)this[R+d]=L[R%re]}return this};const H={};function K(y,u,d){H[y]=class extends d{constructor(){super(),Object.defineProperty(this,"message",{value:u.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${y}]`,this.stack,delete this.name}get code(){return y}set code(P){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:P,writable:!0})}toString(){return`${this.name} [${y}]: ${this.message}`}}}K("ERR_BUFFER_OUT_OF_BOUNDS",function(y){return y?`${y} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),K("ERR_INVALID_ARG_TYPE",function(y,u){return`The "${y}" argument must be of type number. Received type ${typeof u}`},TypeError),K("ERR_OUT_OF_RANGE",function(y,u,d){let b=`The value of "${y}" is out of range.`,P=d;return Number.isInteger(d)&&Math.abs(d)>2**32?P=Z(String(d)):typeof d=="bigint"&&(P=String(d),(d>BigInt(2)**BigInt(32)||d<-(BigInt(2)**BigInt(32)))&&(P=Z(P)),P+="n"),b+=` It must be ${u}. Received ${P}`,b},RangeError);function Z(y){let u="",d=y.length;const b=y[0]==="-"?1:0;for(;d>=b+4;d-=3)u=`_${y.slice(d-3,d)}${u}`;return`${y.slice(0,d)}${u}`}function w(y,u,d){F(u,"offset"),(y[u]===void 0||y[u+d]===void 0)&&q(u,y.length-(d+1))}function _(y,u,d,b,P,R){if(y>d||y<u){const L=typeof u=="bigint"?"n":"";let re;throw u===0||u===BigInt(0)?re=`>= 0${L} and < 2${L} ** ${(R+1)*8}${L}`:re=`>= -(2${L} ** ${(R+1)*8-1}${L}) and < 2 ** ${(R+1)*8-1}${L}`,new H.ERR_OUT_OF_RANGE("value",re,y)}w(b,P,R)}function F(y,u){if(typeof y!="number")throw new H.ERR_INVALID_ARG_TYPE(u,"number",y)}function q(y,u,d){throw Math.floor(y)!==y?(F(y,d),new H.ERR_OUT_OF_RANGE("offset","an integer",y)):u<0?new H.ERR_BUFFER_OUT_OF_BOUNDS:new H.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${u}`,y)}const ve=/[^+/0-9A-Za-z-_]/g;function ee(y){if(y=y.split("=")[0],y=y.trim().replace(ve,""),y.length<2)return"";for(;y.length%4!==0;)y=y+"=";return y}function ae(y,u){u=u||1/0;let d;const b=y.length;let P=null;const R=[];for(let L=0;L<b;++L){if(d=y.charCodeAt(L),d>55295&&d<57344){if(!P){if(d>56319){(u-=3)>-1&&R.push(239,191,189);continue}else if(L+1===b){(u-=3)>-1&&R.push(239,191,189);continue}P=d;continue}if(d<56320){(u-=3)>-1&&R.push(239,191,189),P=d;continue}d=(P-55296<<10|d-56320)+65536}else P&&(u-=3)>-1&&R.push(239,191,189);if(P=null,d<128){if((u-=1)<0)break;R.push(d)}else if(d<2048){if((u-=2)<0)break;R.push(d>>6|192,d&63|128)}else if(d<65536){if((u-=3)<0)break;R.push(d>>12|224,d>>6&63|128,d&63|128)}else if(d<1114112){if((u-=4)<0)break;R.push(d>>18|240,d>>12&63|128,d>>6&63|128,d&63|128)}else throw new Error("Invalid code point")}return R}function Zt(y){const u=[];for(let d=0;d<y.length;++d)u.push(y.charCodeAt(d)&255);return u}function zr(y,u){let d,b,P;const R=[];for(let L=0;L<y.length&&!((u-=2)<0);++L)d=y.charCodeAt(L),b=d>>8,P=d%256,R.push(P),R.push(b);return R}function Sn(y){return t.toByteArray(ee(y))}function qr(y,u,d,b){let P;for(P=0;P<b&&!(P+d>=u.length||P>=y.length);++P)u[P+d]=y[P];return P}function st(y,u){return y instanceof u||y!=null&&y.constructor!=null&&y.constructor.name!=null&&y.constructor.name===u.name}function Er(y){return y!==y}const Pn=function(){const y="0123456789abcdef",u=new Array(256);for(let d=0;d<16;++d){const b=d*16;for(let P=0;P<16;++P)u[b+P]=y[d]+y[P]}return u}();function ut(y){return typeof BigInt>"u"?xr:y}function xr(){throw new Error("BigInt not supported")}})(Jt);var Ei={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}};Ei.Null=Ei.Nil;for(var nu in Ei)Ei[nu].toJSON=(function(e){return e}).bind(null,nu);var dc=Ei,kr=dc;function Ud(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function lc(e){return kr.Nil(e)?"":Ud(e.constructor)}function _b(e){return kr.Function(e)?"":kr.String(e)?JSON.stringify(e):e&&kr.Object(e)?"":e}function hc(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function gs(e){return kr.Function(e)?e.toJSON?e.toJSON():Ud(e):kr.Array(e)?"Array":e&&kr.Object(e)?"Object":e!==void 0?e:""}function Ld(e,t,r){var n=_b(t);return"Expected "+gs(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Wt(e,t,r){r=r||lc(t),this.message=Ld(e,t,r),hc(this,Wt),this.__type=e,this.__value=t,this.__valueTypeName=r}Wt.prototype=Object.create(Error.prototype);Wt.prototype.constructor=Wt;function vb(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),Ld('property "'+gs(r)+s+gs(e),n,i)}function on(e,t,r,n,i){e?(i=i||lc(n),this.message=vb(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',hc(this,Wt),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}on.prototype=Object.create(Error.prototype);on.prototype.constructor=Wt;function Eb(e,t){return new Wt(e,{},t)}function xb(e,t,r){return e instanceof on?(t=t+"."+e.__property,e=new on(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Wt&&(e=new on(e.__type,t,r,e.__value,e.__valueTypeName)),hc(e),e}var Nd={TfTypeError:Wt,TfPropertyTypeError:on,tfCustomError:Eb,tfSubError:xb,tfJSON:gs,getValueTypeName:lc},So,iu;function Ab(){if(iu)return So;iu=1;var e=dc,t=Nd;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function i(S,N){var M=S.toJSON();function B(W){if(!S(W))return!1;if(W.length===N)return!0;throw t.tfCustomError(M+"(Length: "+N+")",M+"(Length: "+W.length+")")}return B.toJSON=function(){return M},B}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function f(S,N,M){M=M||e.Number;function B(W,U){return M(W,U)&&W>S&&W<N}return B.toJSON=function(){return`${M.toJSON()} between [${S}, ${N}]`},B}var l=Math.pow(2,53)-1;function h(S){return typeof S=="number"&&isFinite(S)}function m(S){return S<<24>>24===S}function p(S){return S<<16>>16===S}function g(S){return(S|0)===S}function v(S){return typeof S=="number"&&S>=-l&&S<=l&&Math.floor(S)===S}function x(S){return(S&255)===S}function I(S){return(S&65535)===S}function k(S){return S>>>0===S}function A(S){return typeof S=="number"&&S>=0&&S<=l&&Math.floor(S)===S}var E={ArrayN:s,Buffer:r,BufferN:o,Finite:h,Hex:n,HexN:a,Int8:m,Int16:p,Int32:g,Int53:v,Range:f,StringN:c,UInt8:x,UInt16:I,UInt32:k,UInt53:A};for(var T in E)E[T].toJSON=(function(S){return S}).bind(null,T);return So=E,So}var Ui=Nd,$e=dc,Lt=Ui.tfJSON,Fd=Ui.TfTypeError,$d=Ui.TfPropertyTypeError,Bn=Ui.tfSubError,Sb=Ui.getValueTypeName,Ht={arrayOf:function(t,r){t=St(t),r=r||{};function n(i,s){return!$e.Array(i)||$e.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(o,a){try{return Qe(t,o,s)}catch(c){throw Bn(c,a)}})}return n.toJSON=function(){var i="["+Lt(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=St(t);function r(n,i){return $e.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+Lt(t)},r},map:function(t,r){t=St(t),r&&(r=St(r));function n(i,s){if(!$e.Object(i)||$e.Nil(i))return!1;for(var o in i){try{r&&Qe(r,o,s)}catch(c){throw Bn(c,o,"key")}try{var a=i[o];Qe(t,a,s)}catch(c){throw Bn(c,o)}}return!0}return r?n.toJSON=function(){return"{"+Lt(r)+": "+Lt(t)+"}"}:n.toJSON=function(){return"{"+Lt(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=St(t[n]);function i(s,o){if(!$e.Object(s)||$e.Nil(s))return!1;var a;try{for(a in r){var c=r[a],f=s[a];Qe(c,f,o)}}catch(l){throw Bn(l,a)}if(o){for(a in s)if(!r[a])throw new $d(void 0,a)}return!0}return i.toJSON=function(){return Lt(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(St);function r(n,i){return t.some(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Lt).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(St);function r(n,i){return t.every(function(s){try{return Qe(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(Lt).join(" & ")},r},quacksLike:function(t){function r(n){return t===Sb(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(St);function r(n,i){return $e.Nil(n)||$e.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return Qe(s,n[o],i)}catch(a){throw Bn(a,o)}})}return r.toJSON=function(){return"("+t.map(Lt).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Ht.oneOf=Ht.anyOf;function St(e){if($e.String(e))return e[0]==="?"?Ht.maybe(e.slice(1)):$e[e]||Ht.quacksLike(e);if(e&&$e.Object(e)){if($e.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Ht.arrayOf(e[0])}return Ht.object(e)}else if($e.Function(e))return e;return Ht.value(e)}function Qe(e,t,r,n){if($e.Function(e)){if(e(t,r))return!0;throw new Fd(n||e,t)}return Qe(St(e),t,r)}for(var lr in $e)Qe[lr]=$e[lr];for(lr in Ht)Qe[lr]=Ht[lr];var su=Ab();for(lr in su)Qe[lr]=su[lr];Qe.compile=St;Qe.TfTypeError=Fd;Qe.TfPropertyTypeError=$d;var Md=Qe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Jt;e.typeforce=Md;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(l,h){return l.length!==h.length?!1:l.every((m,p)=>m.equals(h[p]))}e.stacksEqual=i;function s(l){if(!t.Buffer.isBuffer(l)||l.length<33)return!1;const h=l[0],m=l.slice(1,33);if(m.compare(r)===0||m.compare(n)>=0)return!1;if((h===2||h===3)&&l.length===33)return!0;const p=l.slice(33);return p.compare(r)===0||p.compare(n)>=0?!1:h===4&&l.length===65}e.isPoint=s;const o=21*1e14;function a(l){return e.typeforce.UInt53(l)&&l<=o}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function c(l){return!l||!("output"in l)||!t.Buffer.isBuffer(l.output)?!1:l.version!==void 0?(l.version&e.TAPLEAF_VERSION_MASK)===l.version:!0}e.isTapleaf=c;function f(l){return(0,e.Array)(l)?l.length!==2?!1:l.every(h=>f(h)):c(l)}e.isTaptree=f,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})(Ve);var Li={},Me={};Object.defineProperty(Me,"__esModule",{value:!0});Me.BufferReader=Me.BufferWriter=Me.cloneBuffer=Me.reverseBuffer=Me.writeUInt64LE=Me.readUInt64LE=Me.varuint=void 0;const Ir=Ve,{typeforce:Hd}=Ir,xi=Zu;Me.varuint=xi;function Dd(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 jd(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Dd(n+r,9007199254740991),n+r}Me.readUInt64LE=jd;function Gd(e,t,r){return Dd(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Me.writeUInt64LE=Gd;function Pb(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}Me.reverseBuffer=Pb;function Tb(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Me.cloneBuffer=Tb;class pc{static withCapacity(t){return new pc(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Hd(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=Gd(this.buffer,t,this.offset)}writeVarInt(t){xi.encode(t,this.buffer,this.offset),this.offset+=xi.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}Me.BufferWriter=pc;class kb{constructor(t,r=0){this.buffer=t,this.offset=r,Hd(Ir.tuple(Ir.Buffer,Ir.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=jd(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=xi.decode(this.buffer,this.offset);return this.offset+=xi.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}Me.BufferReader=kb;var gr={};const Ib=uc(km);var pn={},Mr={},wr={};Object.defineProperty(wr,"__esModule",{value:!0});wr.anumber=ma;wr.abytes=zd;wr.ahash=Cb;wr.aexists=Ob;wr.aoutput=Rb;function ma(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Bb(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function zd(e,...t){if(!Bb(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Cb(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ma(e.outputLen),ma(e.blockLen)}function Ob(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 Rb(e,t){zd(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var yc={},Hs={};Object.defineProperty(Hs,"__esModule",{value:!0});Hs.crypto=void 0;Hs.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.isLE=void 0,e.isBytes=n,e.u8=i,e.u32=s,e.createView=o,e.rotr=a,e.rotl=c,e.byteSwap=f,e.byteSwap32=l,e.bytesToHex=m,e.hexToBytes=v,e.asyncLoop=I,e.utf8ToBytes=k,e.toBytes=A,e.concatBytes=E,e.checkOpts=S,e.wrapConstructor=N,e.wrapConstructorWithOpts=M,e.wrapXOFConstructorWithOpts=B,e.randomBytes=W;const t=Hs,r=wr;function n(U){return U instanceof Uint8Array||ArrayBuffer.isView(U)&&U.constructor.name==="Uint8Array"}function i(U){return new Uint8Array(U.buffer,U.byteOffset,U.byteLength)}function s(U){return new Uint32Array(U.buffer,U.byteOffset,Math.floor(U.byteLength/4))}function o(U){return new DataView(U.buffer,U.byteOffset,U.byteLength)}function a(U,D){return U<<32-D|U>>>D}function c(U,D){return U<<D|U>>>32-D>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function f(U){return U<<24&4278190080|U<<8&16711680|U>>>8&65280|U>>>24&255}e.byteSwapIfBE=e.isLE?U=>U:U=>f(U);function l(U){for(let D=0;D<U.length;D++)U[D]=f(U[D])}const h=Array.from({length:256},(U,D)=>D.toString(16).padStart(2,"0"));function m(U){(0,r.abytes)(U);let D="";for(let G=0;G<U.length;G++)D+=h[U[G]];return D}const p={_0:48,_9:57,A:65,F:70,a:97,f:102};function g(U){if(U>=p._0&&U<=p._9)return U-p._0;if(U>=p.A&&U<=p.F)return U-(p.A-10);if(U>=p.a&&U<=p.f)return U-(p.a-10)}function v(U){if(typeof U!="string")throw new Error("hex string expected, got "+typeof U);const D=U.length,G=D/2;if(D%2)throw new Error("hex string expected, got unpadded hex of length "+D);const V=new Uint8Array(G);for(let X=0,ne=0;X<G;X++,ne+=2){const he=g(U.charCodeAt(ne)),_e=g(U.charCodeAt(ne+1));if(he===void 0||_e===void 0){const Te=U[ne]+U[ne+1];throw new Error('hex string expected, got non-hex character "'+Te+'" at index '+ne)}V[X]=he*16+_e}return V}const x=async()=>{};e.nextTick=x;async function I(U,D,G){let V=Date.now();for(let X=0;X<U;X++){G(X);const ne=Date.now()-V;ne>=0&&ne<D||(await(0,e.nextTick)(),V+=ne)}}function k(U){if(typeof U!="string")throw new Error("utf8ToBytes expected string, got "+typeof U);return new Uint8Array(new TextEncoder().encode(U))}function A(U){return typeof U=="string"&&(U=k(U)),(0,r.abytes)(U),U}function E(...U){let D=0;for(let V=0;V<U.length;V++){const X=U[V];(0,r.abytes)(X),D+=X.length}const G=new Uint8Array(D);for(let V=0,X=0;V<U.length;V++){const ne=U[V];G.set(ne,X),X+=ne.length}return G}class T{clone(){return this._cloneInto()}}e.Hash=T;function S(U,D){if(D!==void 0&&{}.toString.call(D)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(U,D)}function N(U){const D=V=>U().update(A(V)).digest(),G=U();return D.outputLen=G.outputLen,D.blockLen=G.blockLen,D.create=()=>U(),D}function M(U){const D=(V,X)=>U(X).update(A(V)).digest(),G=U({});return D.outputLen=G.outputLen,D.blockLen=G.blockLen,D.create=V=>U(V),D}function B(U){const D=(V,X)=>U(X).update(A(V)).digest(),G=U({});return D.outputLen=G.outputLen,D.blockLen=G.blockLen,D.create=V=>U(V),D}function W(U=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(U));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(U);throw new Error("crypto.getRandomValues must be defined")}})(yc);Object.defineProperty(Mr,"__esModule",{value:!0});Mr.HashMD=void 0;Mr.setBigUint64=qd;Mr.Chi=Ub;Mr.Maj=Lb;const Po=wr,Cn=yc;function qd(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,f=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+f,a,n)}function Ub(e,t,r){return e&t^~e&r}function Lb(e,t,r){return e&t^e&r^t&r}class Nb extends Cn.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,Cn.createView)(this.buffer)}update(t){(0,Po.aexists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,Cn.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,Cn.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,Po.aexists)(this),(0,Po.aoutput)(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 h=o;h<i;h++)r[h]=0;qd(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,Cn.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],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}}Mr.HashMD=Nb;Object.defineProperty(pn,"__esModule",{value:!0});pn.sha1=pn.SHA1=void 0;const To=Mr,as=yc,On=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),ir=new Uint32Array(80);class Vd extends To.HashMD{constructor(){super(64,20,8,!1),this.A=On[0]|0,this.B=On[1]|0,this.C=On[2]|0,this.D=On[3]|0,this.E=On[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)ir[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)ir[c]=(0,as.rotl)(ir[c-3]^ir[c-8]^ir[c-14]^ir[c-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let c=0;c<80;c++){let f,l;c<20?(f=(0,To.Chi)(i,s,o),l=1518500249):c<40?(f=i^s^o,l=1859775393):c<60?(f=(0,To.Maj)(i,s,o),l=2400959708):(f=i^s^o,l=3395469782);const h=(0,as.rotl)(n,5)+f+a+l+ir[c]|0;a=o,o=s,s=(0,as.rotl)(i,30),i=n,n=h}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(){ir.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}pn.SHA1=Vd;pn.sha1=(0,as.wrapConstructor)(()=>new Vd);const Wd=uc(Rm);(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=Ib,r=pn,n=Wd;function i(l){return Buffer.from((0,t.ripemd160)(Uint8Array.from(l)))}e.ripemd160=i;function s(l){return Buffer.from((0,r.sha1)(Uint8Array.from(l)))}e.sha1=s;function o(l){return Buffer.from((0,n.sha256)(Uint8Array.from(l)))}e.sha256=o;function a(l){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(l))))}e.hash160=a;function c(l){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(l))))}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 f(l,h){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[l],h]))}e.taggedHash=f})(gr);var ko={},Gt={};Object.defineProperty(Gt,"__esModule",{value:!0});Gt.encode=Gt.decode=Gt.check=void 0;function Fb(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))}Gt.check=Fb;function $b(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)}}Gt.decode=$b;function Mb(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}Gt.encode=Mb;var Nr={};Object.defineProperty(Nr,"__esModule",{value:!0});Nr.REVERSE_OPS=Nr.OPS=void 0;const ba={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};Nr.OPS=ba;const Kd={};Nr.REVERSE_OPS=Kd;for(const e of Object.keys(ba)){const t=ba[e];Kd[t]=e}var hr={};Object.defineProperty(hr,"__esModule",{value:!0});hr.decode=hr.encode=hr.encodingLength=void 0;const fr=Nr;function Yd(e){return e<fr.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}hr.encodingLength=Yd;function Hb(e,t,r){const n=Yd(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(fr.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(fr.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(fr.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}hr.encode=Hb;function Db(e,t){const r=e.readUInt8(t);let n,i;if(r<fr.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===fr.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===fr.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==fr.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}hr.decode=Db;var yn={};Object.defineProperty(yn,"__esModule",{value:!0});yn.encode=yn.decode=void 0;function jb(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}yn.decode=jb;function Gb(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function zb(e){let t=Math.abs(e);const r=Gb(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}yn.encode=zb;var Sr={},ou;function qb(){if(ou)return Sr;ou=1,Object.defineProperty(Sr,"__esModule",{value:!0}),Sr.encode=Sr.decode=void 0;const e=Gt,t=ct(),r=Ve,{typeforce:n}=r,i=Buffer.alloc(1,0);function s(f){let l=0;for(;f[l]===0;)++l;return l===f.length?i:(f=f.slice(l),f[0]&128?Buffer.concat([i,f],1+f.length):f)}function o(f){f[0]===0&&(f=f.slice(1));const l=Buffer.alloc(32,0),h=Math.max(0,32-f.length);return f.copy(l,h),l}function a(f){const l=f.readUInt8(f.length-1);if(!(0,t.isDefinedHashType)(l))throw new Error("Invalid hashType "+l);const h=e.decode(f.slice(0,-1)),m=o(h.r),p=o(h.s);return{signature:Buffer.concat([m,p],64),hashType:l}}Sr.decode=a;function c(f,l){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:f,hashType:l}),!(0,t.isDefinedHashType)(l))throw new Error("Invalid hashType "+l);const h=Buffer.allocUnsafe(1);h.writeUInt8(l,0);const m=s(f.slice(0,32)),p=s(f.slice(32,64));return Buffer.concat([e.encode(m,p),h])}return Sr.encode=c,Sr}var au;function ct(){return au||(au=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=Gt,r=Nr;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=hr,i=yn,s=qb(),o=Ve,{typeforce:a}=o,c=r.OPS.OP_RESERVED;function f(B){return o.Number(B)&&(B===r.OPS.OP_0||B>=r.OPS.OP_1&&B<=r.OPS.OP_16||B===r.OPS.OP_1NEGATE)}function l(B){return o.Buffer(B)||f(B)}function h(B){return o.Array(B)&&B.every(l)}e.isPushOnly=h;function m(B){return B.length-B.filter(l).length}e.countNonPushOnlyOPs=m;function p(B){if(B.length===0)return r.OPS.OP_0;if(B.length===1){if(B[0]>=1&&B[0]<=16)return c+B[0];if(B[0]===129)return r.OPS.OP_1NEGATE}}function g(B){return Buffer.isBuffer(B)}function v(B){return o.Array(B)}function x(B){return Buffer.isBuffer(B)}function I(B){if(g(B))return B;a(o.Array,B);const W=B.reduce((G,V)=>x(V)?V.length===1&&p(V)!==void 0?G+1:G+n.encodingLength(V.length)+V.length:G+1,0),U=Buffer.allocUnsafe(W);let D=0;if(B.forEach(G=>{if(x(G)){const V=p(G);if(V!==void 0){U.writeUInt8(V,D),D+=1;return}D+=n.encode(U,G.length,D),G.copy(U,D),D+=G.length}else U.writeUInt8(G,D),D+=1}),D!==U.length)throw new Error("Could not decode chunks");return U}e.compile=I;function k(B){if(v(B))return B;a(o.Buffer,B);const W=[];let U=0;for(;U<B.length;){const D=B[U];if(D>r.OPS.OP_0&&D<=r.OPS.OP_PUSHDATA4){const G=n.decode(B,U);if(G===null||(U+=G.size,U+G.number>B.length))return null;const V=B.slice(U,U+G.number);U+=G.number;const X=p(V);X!==void 0?W.push(X):W.push(V)}else W.push(D),U+=1}return W}e.decompile=k;function A(B){if(g(B)&&(B=k(B)),!B)throw new Error("Could not convert invalid chunks to ASM");return B.map(W=>{if(x(W)){const U=p(W);if(U===void 0)return W.toString("hex");W=U}return r.REVERSE_OPS[W]}).join(" ")}e.toASM=A;function E(B){return a(o.String,B),I(B.split(" ").map(W=>r.OPS[W]!==void 0?r.OPS[W]:(a(o.Hex,W),Buffer.from(W,"hex"))))}e.fromASM=E;function T(B){return B=k(B),a(h,B),B.map(W=>x(W)?W:W===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(W-c))}e.toStack=T;function S(B){return o.isPoint(B)}e.isCanonicalPubKey=S;function N(B){const W=B&-129;return W>0&&W<4}e.isDefinedHashType=N;function M(B){return!Buffer.isBuffer(B)||!N(B[B.length-1])?!1:t.check(B.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s}(ko)),ko}Object.defineProperty(Li,"__esModule",{value:!0});Li.Transaction=void 0;const Be=Me,Ke=gr,cu=ct(),Vb=ct(),se=Ve,{typeforce:_t}=se;function xt(e){const t=e.length;return Be.varuint.encodingLength(t)+t}function Wb(e){const t=e.length;return Be.varuint.encodingLength(t)+e.reduce((r,n)=>r+xt(n),0)}const ur=Buffer.allocUnsafe(0),Io=[],Bo=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),uu=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Kb=Buffer.from("ffffffffffffffff","hex"),Yb={script:ur,valueBuffer:Kb};function Xb(e){return e.value!==void 0}class te{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Be.BufferReader(t),i=new te;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===te.ADVANCED_TRANSACTION_MARKER&&o===te.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let l=0;l<c;++l)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:Io});const f=n.readVarInt();for(let l=0;l<f;++l)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let l=0;l<c;++l)i.ins[l].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 te.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){_t(se.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&te.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return _t(se.tuple(se.Hash256bit,se.UInt32,se.maybe(se.UInt32),se.maybe(se.Buffer)),arguments),se.Null(n)&&(n=te.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||ur,sequence:n,witness:Io})-1}addOutput(t,r){return _t(se.tuple(se.Buffer,se.Satoshi),arguments),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}stripWitnesses(){this.ins.forEach(t=>{t.witness=Io})}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+xt(i.script),0)+this.outs.reduce((n,i)=>n+8+xt(i.script),0)+(r?this.ins.reduce((n,i)=>n+Wb(i.witness),0):0)}clone(){const t=new te;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(_t(se.tuple(se.UInt32,se.Buffer,se.Number),arguments),t>=this.ins.length)return uu;const i=cu.compile(cu.decompile(r).filter(a=>a!==Vb.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===te.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===te.SIGHASH_SINGLE){if(t>=this.outs.length)return uu;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=Yb;s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&te.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=ur}),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),Ke.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(_t(se.tuple(se.UInt32,_t.arrayOf(se.Buffer),_t.arrayOf(se.Satoshi),se.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===te.SIGHASH_DEFAULT?te.SIGHASH_ALL:i&te.SIGHASH_OUTPUT_MASK,f=(i&te.SIGHASH_INPUT_MASK)===te.SIGHASH_ANYONECANPAY,l=a===te.SIGHASH_NONE,h=a===te.SIGHASH_SINGLE;let m=ur,p=ur,g=ur,v=ur,x=ur;if(!f){let E=Be.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(T=>{E.writeSlice(T.hash),E.writeUInt32(T.index)}),m=Ke.sha256(E.end()),E=Be.BufferWriter.withCapacity(8*this.ins.length),n.forEach(T=>E.writeUInt64(T)),p=Ke.sha256(E.end()),E=Be.BufferWriter.withCapacity(r.map(xt).reduce((T,S)=>T+S)),r.forEach(T=>E.writeVarSlice(T)),g=Ke.sha256(E.end()),E=Be.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(T=>E.writeUInt32(T.sequence)),v=Ke.sha256(E.end())}if(l||h){if(h&&t<this.outs.length){const E=this.outs[t],T=Be.BufferWriter.withCapacity(8+xt(E.script));T.writeUInt64(E.value),T.writeVarSlice(E.script),x=Ke.sha256(T.end())}}else{const E=this.outs.map(S=>8+xt(S.script)).reduce((S,N)=>S+N),T=Be.BufferWriter.withCapacity(E);this.outs.forEach(S=>{T.writeUInt64(S.value),T.writeVarSlice(S.script)}),x=Ke.sha256(T.end())}const I=(s?2:0)+(o?1:0),k=174-(f?49:0)-(l?32:0)+(o?32:0)+(s?37:0),A=Be.BufferWriter.withCapacity(k);if(A.writeUInt8(i),A.writeInt32(this.version),A.writeUInt32(this.locktime),A.writeSlice(m),A.writeSlice(p),A.writeSlice(g),A.writeSlice(v),l||h||A.writeSlice(x),A.writeUInt8(I),f){const E=this.ins[t];A.writeSlice(E.hash),A.writeUInt32(E.index),A.writeUInt64(n[t]),A.writeVarSlice(r[t]),A.writeUInt32(E.sequence)}else A.writeUInt32(t);if(o){const E=Be.BufferWriter.withCapacity(xt(o));E.writeVarSlice(o),A.writeSlice(Ke.sha256(E.end()))}return h&&A.writeSlice(x),s&&(A.writeSlice(s),A.writeUInt8(0),A.writeUInt32(4294967295)),Ke.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),A.end()]))}hashForWitnessV0(t,r,n,i){_t(se.tuple(se.UInt32,se.Buffer,se.Satoshi,se.UInt32),arguments);let s=Buffer.from([]),o,a=Bo,c=Bo,f=Bo;if(i&te.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(h=>{o.writeSlice(h.hash),o.writeUInt32(h.index)}),c=Ke.hash256(s)),!(i&te.SIGHASH_ANYONECANPAY)&&(i&31)!==te.SIGHASH_SINGLE&&(i&31)!==te.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(h=>{o.writeUInt32(h.sequence)}),f=Ke.hash256(s)),(i&31)!==te.SIGHASH_SINGLE&&(i&31)!==te.SIGHASH_NONE){const h=this.outs.reduce((m,p)=>m+8+xt(p.script),0);s=Buffer.allocUnsafe(h),o=new Be.BufferWriter(s,0),this.outs.forEach(m=>{o.writeUInt64(m.value),o.writeVarSlice(m.script)}),a=Ke.hash256(s)}else if((i&31)===te.SIGHASH_SINGLE&&t<this.outs.length){const h=this.outs[t];s=Buffer.allocUnsafe(8+xt(h.script)),o=new Be.BufferWriter(s,0),o.writeUInt64(h.value),o.writeVarSlice(h.script),a=Ke.hash256(s)}s=Buffer.allocUnsafe(156+xt(r)),o=new Be.BufferWriter(s,0);const l=this.ins[t];return o.writeInt32(this.version),o.writeSlice(c),o.writeSlice(f),o.writeSlice(l.hash),o.writeUInt32(l.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(l.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Ke.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):Ke.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){_t(se.tuple(se.Number,se.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){_t(se.tuple(se.Number,[se.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(te.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(te.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=>{Xb(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}}Li.Transaction=te;te.DEFAULT_SEQUENCE=4294967295;te.SIGHASH_DEFAULT=0;te.SIGHASH_ALL=1;te.SIGHASH_NONE=2;te.SIGHASH_SINGLE=3;te.SIGHASH_ANYONECANPAY=128;te.SIGHASH_OUTPUT_MASK=3;te.SIGHASH_INPUT_MASK=128;te.ADVANCED_TRANSACTION_MARKER=0;te.ADVANCED_TRANSACTION_FLAG=1;var le={},Ni={};Object.defineProperty(Ni,"__esModule",{value:!0});const Jb=9007199254740991;function mc(e){if(e<0||e>Jb||e%1!==0)throw new RangeError("value out of range")}function zn(e,t,r){if(mc(e),t||(t=Buffer.allocUnsafe(Xd(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(zn,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(zn,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(zn,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(zn,{bytes:9})),t}Ni.encode=zn;function qn(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(qn,{bytes:1}),r;if(r===253)return Object.assign(qn,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(qn,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(qn,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return mc(s),s}}Ni.decode=qn;function Xd(e){return mc(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Ni.encodingLength=Xd;var Co={},Ds={},qe={};Object.defineProperty(qe,"__esModule",{value:!0});qe.testnet=qe.regtest=qe.bitcoin=void 0;qe.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
47
47
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};qe.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
48
48
|
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};qe.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
49
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var ot={};Object.defineProperty(ot,"__esModule",{value:!0});ot.value=ot.prop=void 0;function Qb(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})}})}ot.prop=Qb;function Zb(e){let t;return()=>(t!==void 0||(t=e()),t)}ot.value=Zb;Object.defineProperty(Ds,"__esModule",{value:!0});Ds.p2data=void 0;const eg=qe,cs=ct(),vt=Ve,fu=ot,du=cs.OPS;function tg(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,vt.typeforce)({network:vt.typeforce.maybe(vt.typeforce.Object),output:vt.typeforce.maybe(vt.typeforce.Buffer),data:vt.typeforce.maybe(vt.typeforce.arrayOf(vt.typeforce.Buffer))},e);const n={name:"embed",network:e.network||eg.bitcoin};if(fu.prop(n,"output",()=>{if(e.data)return cs.compile([du.OP_RETURN].concat(e.data))}),fu.prop(n,"data",()=>{if(e.output)return cs.decompile(e.output).slice(1)}),t.validate&&e.output){const i=cs.decompile(e.output);if(i[0]!==du.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(vt.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,vt.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}Ds.p2data=tg;var js={};Object.defineProperty(js,"__esModule",{value:!0});js.p2ms=void 0;const rg=qe,Jr=ct(),ke=Ve,sr=ot,Qr=Jr.OPS,Xi=Qr.OP_RESERVED;function ng(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 Jr.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===Qr.OP_0)!==void 0}(0,ke.typeforce)({network:ke.typeforce.maybe(ke.typeforce.Object),m:ke.typeforce.maybe(ke.typeforce.Number),n:ke.typeforce.maybe(ke.typeforce.Number),output:ke.typeforce.maybe(ke.typeforce.Buffer),pubkeys:ke.typeforce.maybe(ke.typeforce.arrayOf(ke.isPoint)),signatures:ke.typeforce.maybe(ke.typeforce.arrayOf(r)),input:ke.typeforce.maybe(ke.typeforce.Buffer)},e);const i={network:e.network||rg.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=Jr.decompile(c),i.m=s[0]-Xi,i.n=s[s.length-2]-Xi,i.pubkeys=s.slice(1,-2))}if(sr.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Jr.compile([].concat(Xi+e.m,e.pubkeys,Xi+i.n,Qr.OP_CHECKMULTISIG))}),sr.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),sr.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),sr.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),sr.prop(i,"signatures",()=>{if(e.input)return Jr.decompile(e.input).slice(1)}),sr.prop(i,"input",()=>{if(e.signatures)return Jr.compile([Qr.OP_0].concat(e.signatures))}),sr.prop(i,"witness",()=>{if(i.input)return[]}),sr.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!ke.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!ke.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==Qr.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,ke.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,ke.stacksEqual)(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==Qr.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,ke.stacksEqual)(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}js.p2ms=ng;var Gs={};Object.defineProperty(Gs,"__esModule",{value:!0});Gs.p2pk=void 0;const ig=qe,Zr=ct(),yt=Ve,Yr=ot,lu=Zr.OPS;function sg(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,yt.typeforce)({network:yt.typeforce.maybe(yt.typeforce.Object),output:yt.typeforce.maybe(yt.typeforce.Buffer),pubkey:yt.typeforce.maybe(yt.isPoint),signature:yt.typeforce.maybe(Zr.isCanonicalScriptSignature),input:yt.typeforce.maybe(yt.typeforce.Buffer)},e);const r=Yr.value(()=>Zr.decompile(e.input)),i={name:"p2pk",network:e.network||ig.bitcoin};if(Yr.prop(i,"output",()=>{if(e.pubkey)return Zr.compile([e.pubkey,lu.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 Zr.compile([e.signature])}),Yr.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==lu.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,yt.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(!Zr.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}Gs.p2pk=sg;var zs={};function og(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),f=Math.log(256)/Math.log(o);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,x=0,I=p.length;x!==I&&p[x]===0;)x++,g++;for(var k=(I-x)*f+1>>>0,A=new Uint8Array(k);x!==I;){for(var E=p[x],T=0,S=k-1;(E!==0||T<v)&&S!==-1;S--,T++)E+=256*A[S]>>>0,A[S]=E%o>>>0,E=E/o>>>0;if(E!==0)throw new Error("Non-zero carry");v=T,x++}for(var N=k-v;N!==k&&A[N]===0;)N++;for(var M=a.repeat(g);N<k;++N)M+=e.charAt(A[N]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;for(var g=0,v=0,x=0;p[g]===a;)v++,g++;for(var I=(p.length-g)*c+1>>>0,k=new Uint8Array(I);p[g];){var A=p.charCodeAt(g);if(A>255)return;var E=t[A];if(E===255)return;for(var T=0,S=I-1;(E!==0||T<x)&&S!==-1;S--,T++)E+=o*k[S]>>>0,k[S]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");x=T,g++}for(var N=I-x;N!==I&&k[N]===0;)N++;for(var M=new Uint8Array(v+(I-N)),B=v;N!==I;)M[B++]=k[N++];return M}function m(p){var g=h(p);if(g)return g;throw new Error("Non-base"+o+" character")}return{encode:l,decodeUnsafe:h,decode:m}}var ag=og;const cg=ag,ug="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var fg=cg(ug),Bo=fg,dg=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,f=new Uint8Array(c);return f.set(o,0),f.set(a.subarray(0,4),o.length),Bo.encode(f,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=Bo.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Bo.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:hu}=Wd,lg=dg;function hg(e){return hu(hu(e))}var yc=lg(hg);Object.defineProperty(zs,"__esModule",{value:!0});zs.p2pkh=void 0;const Co=gr,pg=qe,en=ct(),Ye=Ve,Nt=ot,pu=yc,or=en.OPS;function yg(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,Ye.typeforce)({network:Ye.typeforce.maybe(Ye.typeforce.Object),address:Ye.typeforce.maybe(Ye.typeforce.String),hash:Ye.typeforce.maybe(Ye.typeforce.BufferN(20)),output:Ye.typeforce.maybe(Ye.typeforce.BufferN(25)),pubkey:Ye.typeforce.maybe(Ye.isPoint),signature:Ye.typeforce.maybe(en.isCanonicalScriptSignature),input:Ye.typeforce.maybe(Ye.typeforce.Buffer)},e);const r=Nt.value(()=>{const o=Buffer.from(pu.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=Nt.value(()=>en.decompile(e.input)),i=e.network||pg.bitcoin,s={name:"p2pkh",network:i};if(Nt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),pu.encode(o)}),Nt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Co.hash160(e.pubkey||s.pubkey)}),Nt.prop(s,"output",()=>{if(s.hash)return en.compile([or.OP_DUP,or.OP_HASH160,s.hash,or.OP_EQUALVERIFY,or.OP_CHECKSIG])}),Nt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),Nt.prop(s,"signature",()=>{if(e.input)return n()[0]}),Nt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return en.compile([e.signature,e.pubkey])}),Nt.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]!==or.OP_DUP||e.output[1]!==or.OP_HASH160||e.output[2]!==20||e.output[23]!==or.OP_EQUALVERIFY||e.output[24]!==or.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=Co.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(!en.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,Ye.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=Co.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}zs.p2pkh=yg;var qs={};Object.defineProperty(qs,"__esModule",{value:!0});qs.p2sh=void 0;const yu=gr,mg=qe,At=ct(),me=Ve,Et=ot,mu=yc,Rn=At.OPS;function bg(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,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(23)),redeem:me.typeforce.maybe({network:me.typeforce.maybe(me.typeforce.Object),output:me.typeforce.maybe(me.typeforce.Buffer),input:me.typeforce.maybe(me.typeforce.Buffer),witness:me.typeforce.maybe(me.typeforce.arrayOf(me.typeforce.Buffer))}),input:me.typeforce.maybe(me.typeforce.Buffer),witness:me.typeforce.maybe(me.typeforce.arrayOf(me.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||mg.bitcoin);const n={network:r},i=Et.value(()=>{const a=Buffer.from(mu.decode(e.address)),c=a.readUInt8(0),f=a.slice(1);return{version:c,hash:f}}),s=Et.value(()=>At.decompile(e.input)),o=Et.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Rn.OP_FALSE?Buffer.from([]):c,input:At.compile(a.slice(0,-1)),witness:e.witness||[]}});if(Et.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),mu.encode(a)}),Et.prop(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return yu.hash160(n.redeem.output)}),Et.prop(n,"output",()=>{if(n.hash)return At.compile([Rn.OP_HASH160,n.hash,Rn.OP_EQUAL])}),Et.prop(n,"redeem",()=>{if(e.input)return o()}),Et.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return At.compile([].concat(At.decompile(e.redeem.input),e.redeem.output))}),Et.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),Et.prop(n,"name",()=>{const a=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");a=i().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Rn.OP_HASH160||e.output[1]!==20||e.output[22]!==Rn.OP_EQUAL)throw new TypeError("Output is invalid");const f=e.output.slice(2,22);if(a.length>0&&!a.equals(f))throw new TypeError("Hash mismatch");a=f}const c=f=>{if(f.output){const l=At.decompile(f.output);if(!l||l.length<1)throw new TypeError("Redeem.output too short");if(f.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(At.countNonPushOnlyOPs(l)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const h=yu.hash160(f.output);if(a.length>0&&!a.equals(h))throw new TypeError("Hash mismatch");a=h}if(f.input){const l=f.input.length>0,h=f.witness&&f.witness.length>0;if(!l&&!h)throw new TypeError("Empty input");if(l&&h)throw new TypeError("Input and witness provided");if(l){const m=At.decompile(f.input);if(!At.isPushOnly(m))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const f=s();if(!f||f.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 f=o();if(e.redeem.output&&!e.redeem.output.equals(f.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(f.input))throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,me.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}qs.p2sh=bg;var Vs={},Kt={};Object.defineProperty(Kt,"__esModule",{value:!0});Kt.bech32m=Kt.bech32=void 0;const ws="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Jd={};for(let e=0;e<ws.length;e++){const t=ws.charAt(e);Jd[t]=e}function an(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 bu(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=an(t)^n>>5}t=an(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=an(t)^n&31}return t}function mc(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 gg(e){return mc(e,8,5,!0)}function wg(e){const t=mc(e,5,8,!1);if(Array.isArray(t))return t}function _g(e){const t=mc(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Qd(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 f=bu(o);if(typeof f=="string")throw new Error(f);let l=o+"1";for(let h=0;h<a.length;++h){const m=a[h];if(m>>5)throw new Error("Non 5-bit word");f=an(f)^m,l+=ws.charAt(m)}for(let h=0;h<6;++h)f=an(f);f^=t;for(let h=0;h<6;++h){const m=f>>(5-h)*5&31;l+=ws.charAt(m)}return l}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(),f=o.toUpperCase();if(o!==c&&o!==f)return"Mixed-case string "+o;o=c;const l=o.lastIndexOf("1");if(l===-1)return"No separator character for "+o;if(l===0)return"Missing prefix for "+o;const h=o.slice(0,l),m=o.slice(l+1);if(m.length<6)return"Data too short";let p=bu(h);if(typeof p=="string")return p;const g=[];for(let v=0;v<m.length;++v){const x=m.charAt(v),I=Jd[x];if(I===void 0)return"Unknown character "+x;p=an(p)^I,!(v+6>=m.length)&&g.push(I)}return p!==t?"Invalid checksum for "+o:{prefix:h,words:g}}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:gg,fromWordsUnsafe:wg,fromWords:_g}}Kt.bech32=Qd("bech32");Kt.bech32m=Qd("bech32m");Object.defineProperty(Vs,"__esModule",{value:!0});Vs.p2wpkh=void 0;const Oo=gr,vg=qe,us=ct(),Re=Ve,ar=ot,Ji=Kt,gu=us.OPS,Eg=Buffer.alloc(0);function xg(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,Re.typeforce)({address:Re.typeforce.maybe(Re.typeforce.String),hash:Re.typeforce.maybe(Re.typeforce.BufferN(20)),input:Re.typeforce.maybe(Re.typeforce.BufferN(0)),network:Re.typeforce.maybe(Re.typeforce.Object),output:Re.typeforce.maybe(Re.typeforce.BufferN(22)),pubkey:Re.typeforce.maybe(Re.isPoint),signature:Re.typeforce.maybe(us.isCanonicalScriptSignature),witness:Re.typeforce.maybe(Re.typeforce.arrayOf(Re.typeforce.Buffer))},e);const r=ar.value(()=>{const s=Ji.bech32.decode(e.address),o=s.words.shift(),a=Ji.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||vg.bitcoin,i={name:"p2wpkh",network:n};if(ar.prop(i,"address",()=>{if(!i.hash)return;const s=Ji.bech32.toWords(i.hash);return s.unshift(0),Ji.bech32.encode(n.bech32,s)}),ar.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return Oo.hash160(e.pubkey||i.pubkey)}),ar.prop(i,"output",()=>{if(i.hash)return us.compile([gu.OP_0,i.hash])}),ar.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),ar.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),ar.prop(i,"input",()=>{if(i.witness)return Eg}),ar.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]!==gu.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=Oo.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Re.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(!us.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Re.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=Oo.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}Vs.p2wpkh=xg;var Ws={};Object.defineProperty(Ws,"__esModule",{value:!0});Ws.p2wsh=void 0;const wu=gr,Ag=qe,Mt=ct(),pe=Ve,Ft=ot,Qi=Kt,_u=Mt.OPS,Ro=Buffer.alloc(0);function Zi(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,pe.isPoint)(e))}function Sg(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,pe.typeforce)({network:pe.typeforce.maybe(pe.typeforce.Object),address:pe.typeforce.maybe(pe.typeforce.String),hash:pe.typeforce.maybe(pe.typeforce.BufferN(32)),output:pe.typeforce.maybe(pe.typeforce.BufferN(34)),redeem:pe.typeforce.maybe({input:pe.typeforce.maybe(pe.typeforce.Buffer),network:pe.typeforce.maybe(pe.typeforce.Object),output:pe.typeforce.maybe(pe.typeforce.Buffer),witness:pe.typeforce.maybe(pe.typeforce.arrayOf(pe.typeforce.Buffer))}),input:pe.typeforce.maybe(pe.typeforce.BufferN(0)),witness:pe.typeforce.maybe(pe.typeforce.arrayOf(pe.typeforce.Buffer))},e);const r=Ft.value(()=>{const o=Qi.bech32.decode(e.address),a=o.words.shift(),c=Qi.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=Ft.value(()=>Mt.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Ag.bitcoin);const s={network:i};if(Ft.prop(s,"address",()=>{if(!s.hash)return;const o=Qi.bech32.toWords(s.hash);return o.unshift(0),Qi.bech32.encode(i.bech32,o)}),Ft.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return wu.sha256(s.redeem.output)}),Ft.prop(s,"output",()=>{if(s.hash)return Mt.compile([_u.OP_0,s.hash])}),Ft.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Ro,witness:e.witness.slice(0,-1)}}),Ft.prop(s,"input",()=>{if(s.witness)return Ro}),Ft.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=Ro,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Ft.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]!==_u.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=wu.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,pe.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Zi)||e.redeem.output&&(Mt.decompile(e.redeem.output)||[]).some(Zi))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(Zi)||(Mt.decompile(a)||[]).some(Zi))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}Ws.p2wsh=Sg;var Un={},Fr={};Object.defineProperty(Fr,"__esModule",{value:!0});Fr.getEccLib=Fr.initEccLib=void 0;const Wn={};function Pg(e,t){e?e!==Wn.eccLib&&(t!=null&&t.DANGER_DO_NOT_VERIFY_ECCLIB||kg(e),Wn.eccLib=e):Wn.eccLib=e}Fr.initEccLib=Pg;function Tg(){if(!Wn.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Wn.eccLib}Fr.getEccLib=Tg;const $t=e=>Buffer.from(e,"hex");function kg(e){ft(typeof e.isXOnlyPoint=="function"),ft(e.isXOnlyPoint($t("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ft(e.isXOnlyPoint($t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),ft(e.isXOnlyPoint($t("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),ft(e.isXOnlyPoint($t("0000000000000000000000000000000000000000000000000000000000000001"))),ft(!e.isXOnlyPoint($t("0000000000000000000000000000000000000000000000000000000000000000"))),ft(!e.isXOnlyPoint($t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),ft(typeof e.xOnlyPointAddTweak=="function"),Ig.forEach(t=>{const r=e.xOnlyPointAddTweak($t(t.pubkey),$t(t.tweak));t.result===null?ft(r===null):(ft(r!==null),ft(r.parity===t.parity),ft(Buffer.from(r.xOnlyPubkey).equals($t(t.result))))})}function ft(e){if(!e)throw new Error("ecc library invalid")}const Ig=[{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 bc={};(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=Jt,r=Fr,n=gr,i=Me,s=Ve;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=v=>"left"in v&&"right"in v;function a(v,x){if(v.length<33)throw new TypeError(`The control-block length is too small. Got ${v.length}, expected min 33.`);const I=(v.length-33)/32;let k=x;for(let A=0;A<I;A++){const E=v.slice(33+32*A,65+32*A);k.compare(E)<0?k=p(k,E):k=p(E,k)}return k}e.rootHashFromPath=a;function c(v){if((0,s.isTapleaf)(v))return{hash:l(v)};const x=[c(v[0]),c(v[1])];x.sort((A,E)=>A.hash.compare(E.hash));const[I,k]=x;return{hash:p(I.hash,k.hash),left:I,right:k}}e.toHashTree=c;function f(v,x){if(o(v)){const I=f(v.left,x);if(I!==void 0)return[...I,v.right.hash];const k=f(v.right,x);if(k!==void 0)return[...k,v.left.hash]}else if(v.hash.equals(x))return[]}e.findScriptPath=f;function l(v){const x=v.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([x]),g(v.output)]))}e.tapleafHash=l;function h(v,x){return n.taggedHash("TapTweak",t.Buffer.concat(x?[v,x]:[v]))}e.tapTweakHash=h;function m(v,x){if(!t.Buffer.isBuffer(v)||v.length!==32||x&&x.length!==32)return null;const I=h(v,x),k=(0,r.getEccLib)().xOnlyPointAddTweak(v,I);return!k||k.xOnlyPubkey===null?null:{parity:k.parity,x:t.Buffer.from(k.xOnlyPubkey)}}e.tweakKey=m;function p(v,x){return n.taggedHash("TapBranch",t.Buffer.concat([v,x]))}function g(v){const x=i.varuint.encodingLength(v.length),I=t.Buffer.allocUnsafe(x);return i.varuint.encode(v.length,I),t.Buffer.concat([I,v])}})(bc);var Xe={},vu;function Bg(){if(vu)return Xe;vu=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.toOutputScript=Xe.fromOutputScript=Xe.toBech32=Xe.toBase58Check=Xe.fromBech32=Xe.fromBase58Check=void 0;const e=qe,t=gc(),r=ct(),n=Ve,i=Kt,s=yc,o=40,a=2,c=16,f=2,l=80,h="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 m(A,E){const T=A.slice(2);if(T.length<a||T.length>o)throw new TypeError("Invalid program length for segwit address");const S=A[0]-l;if(S<f||S>c)throw new TypeError("Invalid version for segwit address");if(A[1]!==T.length)throw new TypeError("Invalid script for segwit address");return console.warn(h),x(T,S,E.bech32)}function p(A){const E=Buffer.from(s.decode(A));if(E.length<21)throw new TypeError(A+" is too short");if(E.length>21)throw new TypeError(A+" is too long");const T=E.readUInt8(0),S=E.slice(1);return{version:T,hash:S}}Xe.fromBase58Check=p;function g(A){let E,T;try{E=i.bech32.decode(A)}catch{}if(E){if(T=E.words[0],T!==0)throw new TypeError(A+" uses wrong encoding")}else if(E=i.bech32m.decode(A),T=E.words[0],T===0)throw new TypeError(A+" uses wrong encoding");const S=i.bech32.fromWords(E.words.slice(1));return{version:T,prefix:E.prefix,data:Buffer.from(S)}}Xe.fromBech32=g;function v(A,E){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const T=Buffer.allocUnsafe(21);return T.writeUInt8(E,0),A.copy(T,1),s.encode(T)}Xe.toBase58Check=v;function x(A,E,T){const S=i.bech32.toWords(A);return S.unshift(E),E===0?i.bech32.encode(T,S):i.bech32m.encode(T,S)}Xe.toBech32=x;function I(A,E){E=E||e.bitcoin;try{return t.p2pkh({output:A,network:E}).address}catch{}try{return t.p2sh({output:A,network:E}).address}catch{}try{return t.p2wpkh({output:A,network:E}).address}catch{}try{return t.p2wsh({output:A,network:E}).address}catch{}try{return t.p2tr({output:A,network:E}).address}catch{}try{return m(A,E)}catch{}throw new Error(r.toASM(A)+" has no matching Address")}Xe.fromOutputScript=I;function k(A,E){E=E||e.bitcoin;let T,S;try{T=p(A)}catch{}if(T){if(T.version===E.pubKeyHash)return t.p2pkh({hash:T.hash}).output;if(T.version===E.scriptHash)return t.p2sh({hash:T.hash}).output}else{try{S=g(A)}catch{}if(S){if(S.prefix!==E.bech32)throw new Error(A+" has an invalid prefix");if(S.version===0){if(S.data.length===20)return t.p2wpkh({hash:S.data}).output;if(S.data.length===32)return t.p2wsh({hash:S.data}).output}else if(S.version===1){if(S.data.length===32)return t.p2tr({pubkey:S.data}).output}else if(S.version>=f&&S.version<=c&&S.data.length>=a&&S.data.length<=o)return console.warn(h),r.compile([S.version+l,S.data])}}throw new Error(A+" has no matching Script")}return Xe.toOutputScript=k,Xe}var Eu;function Cg(){if(Eu)return Un;Eu=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.p2tr=void 0;const e=Jt,t=qe,r=ct(),n=Ve,i=Fr,s=bc,o=ot,a=Kt,c=Bg(),f=r.OPS,l=1,h=80;function m(p,g){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");g=Object.assign({validate:!0},g||{}),(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)},p);const v=o.value(()=>(0,c.fromBech32)(p.address)),x=o.value(()=>{if(!(!p.witness||!p.witness.length))return p.witness.length>=2&&p.witness[p.witness.length-1][0]===h?p.witness.slice(0,-1):p.witness.slice()}),I=o.value(()=>{if(p.scriptTree)return(0,s.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),k=p.network||t.bitcoin,A={name:"p2tr",network:k};if(o.prop(A,"address",()=>{if(!A.pubkey)return;const E=a.bech32m.toWords(A.pubkey);return E.unshift(l),a.bech32m.encode(k.bech32,E)}),o.prop(A,"hash",()=>{const E=I();if(E)return E.hash;const T=x();if(T&&T.length>1){const S=T[T.length-1],N=S[0]&n.TAPLEAF_VERSION_MASK,M=T[T.length-2],B=(0,s.tapleafHash)({output:M,version:N});return(0,s.rootHashFromPath)(S,B)}return null}),o.prop(A,"output",()=>{if(A.pubkey)return r.compile([f.OP_1,A.pubkey])}),o.prop(A,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(A,"redeem",()=>{const E=x();if(!(!E||E.length<2))return{output:E[E.length-2],witness:E.slice(0,-2),redeemVersion:E[E.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(A,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return v().data;if(A.internalPubkey){const E=(0,s.tweakKey)(A.internalPubkey,A.hash);if(E)return E.x}}),o.prop(A,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const E=x();if(E&&E.length>1)return E[E.length-1].slice(1,33)}),o.prop(A,"signature",()=>{if(p.signature)return p.signature;const E=x();if(!(!E||E.length!==1))return E[0]}),o.prop(A,"witness",()=>{if(p.witness)return p.witness;const E=I();if(E&&p.redeem&&p.redeem.output&&p.internalPubkey){const T=(0,s.tapleafHash)({output:p.redeem.output,version:A.redeemVersion}),S=(0,s.findScriptPath)(E,T);if(!S)return;const N=(0,s.tweakKey)(p.internalPubkey,E.hash);if(!N)return;const M=e.Buffer.concat([e.Buffer.from([A.redeemVersion|N.parity]),p.internalPubkey].concat(S));return[p.redeem.output,M]}if(p.signature)return[p.signature]}),g.validate){let E=e.Buffer.from([]);if(p.address){if(k&&k.bech32!==v().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(v().version!==l)throw new TypeError("Invalid address version");if(v().data.length!==32)throw new TypeError("Invalid address data");E=v().data}if(p.pubkey){if(E.length>0&&!E.equals(p.pubkey))throw new TypeError("Pubkey mismatch");E=p.pubkey}if(p.output){if(p.output.length!==34||p.output[0]!==f.OP_1||p.output[1]!==32)throw new TypeError("Output is invalid");if(E.length>0&&!E.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");E=p.output.slice(2)}if(p.internalPubkey){const N=(0,s.tweakKey)(p.internalPubkey,A.hash);if(E.length>0&&!E.equals(N.x))throw new TypeError("Pubkey mismatch");E=N.x}if(E&&E.length&&!(0,i.getEccLib)().isXOnlyPoint(E))throw new TypeError("Invalid pubkey for p2tr");const T=I();if(p.hash&&T&&!p.hash.equals(T.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&T){const N=(0,s.tapleafHash)({output:p.redeem.output,version:A.redeemVersion});if(!(0,s.findScriptPath)(T,N))throw new TypeError("Redeem script not in tree")}const S=x();if(p.redeem&&A.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==A.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(p.redeem.output){if(r.decompile(p.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(A.redeem.output&&!p.redeem.output.equals(A.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&A.redeem.witness&&!(0,n.stacksEqual)(p.redeem.witness,A.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(S&&S.length)if(S.length===1){if(p.signature&&!p.signature.equals(S[0]))throw new TypeError("Signature mismatch")}else{const N=S[S.length-1];if(N.length<33)throw new TypeError(`The control-block length is too small. Got ${N.length}, expected min 33.`);if((N.length-33)%32!==0)throw new TypeError(`The control-block length of ${N.length} is incorrect!`);const M=(N.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const B=N.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(B))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(B))throw new TypeError("Invalid internalPubkey for p2tr witness");const W=N[0]&n.TAPLEAF_VERSION_MASK,U=S[S.length-2],D=(0,s.tapleafHash)({output:U,version:W}),j=(0,s.rootHashFromPath)(N,D),V=(0,s.tweakKey)(B,j);if(!V)throw new TypeError("Invalid outputKey for p2tr witness");if(E.length&&!E.equals(V.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(V.parity!==(N[0]&1))throw new Error("Incorrect parity")}}return Object.assign(A,p)}return Un.p2tr=m,Un}var xu;function gc(){return xu||(xu=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=Ds;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=js;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=Gs;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=zs;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=qs;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=Vs;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=Ws;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=Cg();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Io)),Io}Object.defineProperty(le,"__esModule",{value:!0});le.signatureBlocksAction=le.checkInputForSig=le.pubkeyInScript=le.pubkeyPositionInScript=le.witnessStackToScriptWitness=le.isP2TR=le.isP2SHScript=le.isP2WSHScript=le.isP2WPKH=le.isP2PKH=le.isP2PK=le.isP2MS=void 0;const Au=Ni,Kn=ct(),es=Li,Og=gr,Hr=gc();function Dr(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}le.isP2MS=Dr(Hr.p2ms);le.isP2PK=Dr(Hr.p2pk);le.isP2PKH=Dr(Hr.p2pkh);le.isP2WPKH=Dr(Hr.p2wpkh);le.isP2WSHScript=Dr(Hr.p2wsh);le.isP2SHScript=Dr(Hr.p2sh);le.isP2TR=Dr(Hr.p2tr);function Rg(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=Au.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Au.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}le.witnessStackToScriptWitness=Rg;function Zd(e,t){const r=(0,Og.hash160)(e),n=e.slice(1,33),i=Kn.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))}le.pubkeyPositionInScript=Zd;function Ug(e,t){return Zd(e,t)!==-1}le.pubkeyInScript=Ug;function Lg(e,t){return Ng(e).some(n=>el(n,Kn.signature.decode,t))}le.checkInputForSig=Lg;function el(e,t,r){const{hashType:n}=t(e),i=[];switch(n&es.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case es.Transaction.SIGHASH_ALL:break;case es.Transaction.SIGHASH_SINGLE:case es.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}le.signatureBlocksAction=el;function Ng(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=Fg(e)}else t=e.partialSig;return t.map(r=>r.signature)}function Fg(e){const t=e.finalScriptSig?Kn.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?Kn.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&Kn.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(Ae,"__esModule",{value:!0});Ae.checkTaprootInputForSigs=Ae.tapTreeFromList=Ae.tapTreeToList=Ae.tweakInternalPubKey=Ae.checkTaprootOutputFields=Ae.checkTaprootInputFields=Ae.isTaprootOutput=Ae.isTaprootInput=fs=Ae.serializeTaprootSignature=Ae.tapScriptFinalizer=Ae.toXOnly=void 0;const wc=Ve,$g=Li,Ks=le,mr=bc,Mg=gc(),Hg=le,Dg=e=>e.length===32?e:e.slice(1,33);Ae.toXOnly=Dg;function jg(e,t,r){const n=o1(t,e,r);try{const s=i1(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,Ks.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}Ae.tapScriptFinalizer=jg;function Gg(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var fs=Ae.serializeTaprootSignature=Gg;function ds(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,Ks.isP2TR)(e.witnessUtxo.script))}Ae.isTaprootInput=ds;function ls(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,Ks.isP2TR)(t))}Ae.isTaprootOutput=ls;function zg(e,t,r){t1(e,t,r),n1(e,t,r)}Ae.checkTaprootInputFields=zg;function qg(e,t,r){r1(e,t,r),Vg(e,t)}Ae.checkTaprootOutputFields=qg;function Vg(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=Wg(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function Wg(e,t){const r=t&&tl(t.leaves),{output:n}=(0,Mg.p2tr)({internalPubkey:e,scriptTree:r});return n}function Kg(e,t){const r=t.tapInternalKey,n=r&&(0,mr.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}Ae.tweakInternalPubKey=Kg;function Yg(e){if(!(0,wc.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ma(e)}Ae.tapTreeToList=Yg;function tl(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:e1(e)}Ae.tapTreeFromList=tl;function Xg(e,t){return Qg(e).some(n=>(0,Hg.signatureBlocksAction)(n,Jg,t))}Ae.checkTaprootInputForSigs=Xg;function Jg(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||$g.Transaction.SIGHASH_DEFAULT}}function Qg(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=Zg(e.finalScriptWitness);r&&t.push(r)}return t}function Zg(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function ma(e,t=[],r=0){if(r>mr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,wc.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||mr.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&ma(e[0],t,r+1),e[1]&&ma(e[1],t,r+1),t):[]}function e1(e){let t;for(const r of e)if(t=ba(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function ba(e,t,r=0){if(r>mr.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,wc.isTapleaf)(t))return;const n=ba(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=ba(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function t1(e,t,r){const n=ds(e)&&cn(t),i=cn(e)&&ds(t),s=e===t&&ds(t)&&cn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function r1(e,t,r){const n=ls(e)&&cn(t),i=cn(e)&&ls(t),s=e===t&&ls(t)&&cn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function n1(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>Uo(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Uo(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=>Uo(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Uo(e,t){if(!t)return!0;const r=(0,mr.tapleafHash)({output:e.script,version:e.leafVersion});return(0,mr.rootHashFromPath)(e.controlBlock,r).equals(t)}function i1(e,t){const r=(0,mr.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>s1(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function s1(e,t){return Object.assign({positionInScript:(0,Ks.pubkeyPositionInScript)(t.pubkey,e)},t)}function o1(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=>a1(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function a1(e,t,r){const n=(0,mr.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function cn(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const Fe={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"},ts=192;ce.initEccLib(Br);class Yn{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=fb(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,Ar(n.length===64,Fe.secretHashLenMismatch),Ar(i.length===64||i.length===66,`initiator ${Fe.pubkeyLenMismatch}`),Ar(s.length===64||s.length===66,`redeemer ${Fe.pubkeyLenMismatch}`),Ar(o>0,Fe.zeroOrNegativeExpiry);const c=await t.getNetwork();return new Yn(t,r,n,la(s).toString("hex"),la(i).toString("hex"),o,c,a)}address(){const{address:t}=ce.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(Fe.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new ce.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 f=await s.getTransaction(c);for(let l=0;l<f.vout.length;l++){const h=f.vout[l];h.scriptpubkey_address===i&&o.push({txid:f.txid,vout:l,value:h.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,f)=>c+f.value,0);if(a===0)throw new Error(`${i} ${Fe.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,fn.Urgency.MEDIUM)),n.addOutput(ce.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async _tempBuildRawTx(t,r){const n=new ce.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 f=await s.getTransaction(c);for(let l=0;l<f.vout.length;l++){const h=f.vout[l];h.scriptpubkey_address===i&&o.push({txid:f.txid,vout:l,value:h.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,f)=>c+f.value,0);if(a===0)throw new Error(`${i} ${Fe.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);if(n.addOutput(ce.address.toOutputScript(t,this.network),a),r){const c=await s.getFeeRates(),f=Math.ceil(c.hourFee*r),l=a-f;n.outs[0].value=l}return{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return ce.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,fn.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=ce.Transaction.SIGHASH_SINGLE|ce.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),f=s.map(h=>h.value),l=Xr(o,s.length);for(let h=0;h<i.ins.length;h++){const m=i.hashForWitnessV1(h,l,f,a,c),p=await this.signer.signSchnorr(m);i.setWitness(h,[fs(p,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=ce.Transaction.SIGHASH_SINGLE|ce.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(l=>l.value),f=Xr(s,i.length);for(let l=0;l<n.ins.length;l++){const h=n.hashForWitnessV1(l,f,c,o,a),m=await this.signer.signSchnorr(h);n.setWitness(l,[fs(m,o),fs(m,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){Ar(t.length>0,Fe.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const h of i)if(!t.find(m=>m.utxo===h.txid))throw new Error(Fe.counterPartySigNotFound(h.txid));const s=this.getOutputScript(),o=ce.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(h=>h.value),f=Xr(s,i.length);for(let h=0;h<n.ins.length;h++){const m=n.hashForWitnessV1(h,f,c,o,a);if(!Br.verifySchnorr(m,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[h].sig,"hex")))throw new Error(Fe.invalidCounterpartySigForUTXO(t[h].utxo));const p=await this.signer.signSchnorr(m),g=Buffer.from(n.ins[h].hash).reverse().toString("hex"),v=t.find(x=>x.utxo===g);if(!v)throw new Error(Fe.counterPartySigNotFound(g));n.setWitness(h,[Buffer.from(v.sig,"hex"),p,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){Ar(ce.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Fe.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(m=>m.value),c=Xr(this.getOutputScript(),s.length),f=ce.Transaction.SIGHASH_DEFAULT;for(let m=0;m<i.ins.length;m++){const p=i.hashForWitnessV1(m,c,a,f,o),g=await this.signer.signSchnorr(p);i.setWitness(m,[g,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:l}=await this._tempBuildRawTx(n,i.virtualSize());for(let m=0;m<l.ins.length;m++){const p=l.hashForWitnessV1(m,c,a,f,o),g=await this.signer.signSchnorr(p);l.setWitness(m,[g,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(l.toHex())}async getRedeemHex(t,r){Ar(ce.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Fe.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(h=>h.value),c=Xr(this.getOutputScript(),s.length),f=ce.Transaction.SIGHASH_DEFAULT;for(let h=0;h<i.ins.length;h++){const m=i.hashForWitnessV1(h,c,a,f,o),p=await this.signer.signSchnorr(m);i.setWitness(h,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:l}=await this._tempBuildRawTx(n,i.virtualSize());for(let h=0;h<l.ins.length;h++){const m=l.hashForWitnessV1(h,c,a,f,o),p=await this.signer.signSchnorr(m);l.setWitness(h,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return l.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(Fe.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(m=>m.value),f=Xr(this.getOutputScript(),i.length),l=ce.Transaction.SIGHASH_DEFAULT;for(let m=0;m<n.ins.length;m++){n.ins[m].sequence=this.expiry;const p=n.hashForWitnessV1(m,f,c,l,a),g=await this.signer.signSchnorr(p);n.setWitness(m,[g,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(Fe.invalidLeaf)}const n=ce.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:ts}});if(!n.witness)throw new Error(Fe.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()),ce.crypto.taggedHash("TapLeaf",Xm(r))}refundLeaf(){return ce.script.fromASM(`
|
|
49
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var ot={};Object.defineProperty(ot,"__esModule",{value:!0});ot.value=ot.prop=void 0;function Qb(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})}})}ot.prop=Qb;function Zb(e){let t;return()=>(t!==void 0||(t=e()),t)}ot.value=Zb;Object.defineProperty(Ds,"__esModule",{value:!0});Ds.p2data=void 0;const eg=qe,cs=ct(),vt=Ve,fu=ot,du=cs.OPS;function tg(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,vt.typeforce)({network:vt.typeforce.maybe(vt.typeforce.Object),output:vt.typeforce.maybe(vt.typeforce.Buffer),data:vt.typeforce.maybe(vt.typeforce.arrayOf(vt.typeforce.Buffer))},e);const n={name:"embed",network:e.network||eg.bitcoin};if(fu.prop(n,"output",()=>{if(e.data)return cs.compile([du.OP_RETURN].concat(e.data))}),fu.prop(n,"data",()=>{if(e.output)return cs.decompile(e.output).slice(1)}),t.validate&&e.output){const i=cs.decompile(e.output);if(i[0]!==du.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(vt.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,vt.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}Ds.p2data=tg;var js={};Object.defineProperty(js,"__esModule",{value:!0});js.p2ms=void 0;const rg=qe,Jr=ct(),ke=Ve,sr=ot,Qr=Jr.OPS,Xi=Qr.OP_RESERVED;function ng(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 Jr.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===Qr.OP_0)!==void 0}(0,ke.typeforce)({network:ke.typeforce.maybe(ke.typeforce.Object),m:ke.typeforce.maybe(ke.typeforce.Number),n:ke.typeforce.maybe(ke.typeforce.Number),output:ke.typeforce.maybe(ke.typeforce.Buffer),pubkeys:ke.typeforce.maybe(ke.typeforce.arrayOf(ke.isPoint)),signatures:ke.typeforce.maybe(ke.typeforce.arrayOf(r)),input:ke.typeforce.maybe(ke.typeforce.Buffer)},e);const i={network:e.network||rg.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=Jr.decompile(c),i.m=s[0]-Xi,i.n=s[s.length-2]-Xi,i.pubkeys=s.slice(1,-2))}if(sr.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Jr.compile([].concat(Xi+e.m,e.pubkeys,Xi+i.n,Qr.OP_CHECKMULTISIG))}),sr.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),sr.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),sr.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),sr.prop(i,"signatures",()=>{if(e.input)return Jr.decompile(e.input).slice(1)}),sr.prop(i,"input",()=>{if(e.signatures)return Jr.compile([Qr.OP_0].concat(e.signatures))}),sr.prop(i,"witness",()=>{if(i.input)return[]}),sr.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!ke.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!ke.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==Qr.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,ke.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,ke.stacksEqual)(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==Qr.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,ke.stacksEqual)(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}js.p2ms=ng;var Gs={};Object.defineProperty(Gs,"__esModule",{value:!0});Gs.p2pk=void 0;const ig=qe,Zr=ct(),yt=Ve,Yr=ot,lu=Zr.OPS;function sg(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,yt.typeforce)({network:yt.typeforce.maybe(yt.typeforce.Object),output:yt.typeforce.maybe(yt.typeforce.Buffer),pubkey:yt.typeforce.maybe(yt.isPoint),signature:yt.typeforce.maybe(Zr.isCanonicalScriptSignature),input:yt.typeforce.maybe(yt.typeforce.Buffer)},e);const r=Yr.value(()=>Zr.decompile(e.input)),i={name:"p2pk",network:e.network||ig.bitcoin};if(Yr.prop(i,"output",()=>{if(e.pubkey)return Zr.compile([e.pubkey,lu.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 Zr.compile([e.signature])}),Yr.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==lu.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,yt.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(!Zr.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}Gs.p2pk=sg;var zs={};function og(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),f=Math.log(256)/Math.log(o);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,x=0,I=p.length;x!==I&&p[x]===0;)x++,g++;for(var k=(I-x)*f+1>>>0,A=new Uint8Array(k);x!==I;){for(var E=p[x],T=0,S=k-1;(E!==0||T<v)&&S!==-1;S--,T++)E+=256*A[S]>>>0,A[S]=E%o>>>0,E=E/o>>>0;if(E!==0)throw new Error("Non-zero carry");v=T,x++}for(var N=k-v;N!==k&&A[N]===0;)N++;for(var M=a.repeat(g);N<k;++N)M+=e.charAt(A[N]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;for(var g=0,v=0,x=0;p[g]===a;)v++,g++;for(var I=(p.length-g)*c+1>>>0,k=new Uint8Array(I);p[g];){var A=p.charCodeAt(g);if(A>255)return;var E=t[A];if(E===255)return;for(var T=0,S=I-1;(E!==0||T<x)&&S!==-1;S--,T++)E+=o*k[S]>>>0,k[S]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");x=T,g++}for(var N=I-x;N!==I&&k[N]===0;)N++;for(var M=new Uint8Array(v+(I-N)),B=v;N!==I;)M[B++]=k[N++];return M}function m(p){var g=h(p);if(g)return g;throw new Error("Non-base"+o+" character")}return{encode:l,decodeUnsafe:h,decode:m}}var ag=og;const cg=ag,ug="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var fg=cg(ug),Oo=fg,dg=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,f=new Uint8Array(c);return f.set(o,0),f.set(a.subarray(0,4),o.length),Oo.encode(f,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=Oo.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Oo.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:hu}=Wd,lg=dg;function hg(e){return hu(hu(e))}var bc=lg(hg);Object.defineProperty(zs,"__esModule",{value:!0});zs.p2pkh=void 0;const Ro=gr,pg=qe,en=ct(),Ye=Ve,Nt=ot,pu=bc,or=en.OPS;function yg(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,Ye.typeforce)({network:Ye.typeforce.maybe(Ye.typeforce.Object),address:Ye.typeforce.maybe(Ye.typeforce.String),hash:Ye.typeforce.maybe(Ye.typeforce.BufferN(20)),output:Ye.typeforce.maybe(Ye.typeforce.BufferN(25)),pubkey:Ye.typeforce.maybe(Ye.isPoint),signature:Ye.typeforce.maybe(en.isCanonicalScriptSignature),input:Ye.typeforce.maybe(Ye.typeforce.Buffer)},e);const r=Nt.value(()=>{const o=Buffer.from(pu.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=Nt.value(()=>en.decompile(e.input)),i=e.network||pg.bitcoin,s={name:"p2pkh",network:i};if(Nt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),pu.encode(o)}),Nt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Ro.hash160(e.pubkey||s.pubkey)}),Nt.prop(s,"output",()=>{if(s.hash)return en.compile([or.OP_DUP,or.OP_HASH160,s.hash,or.OP_EQUALVERIFY,or.OP_CHECKSIG])}),Nt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),Nt.prop(s,"signature",()=>{if(e.input)return n()[0]}),Nt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return en.compile([e.signature,e.pubkey])}),Nt.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]!==or.OP_DUP||e.output[1]!==or.OP_HASH160||e.output[2]!==20||e.output[23]!==or.OP_EQUALVERIFY||e.output[24]!==or.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=Ro.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(!en.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,Ye.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=Ro.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}zs.p2pkh=yg;var qs={};Object.defineProperty(qs,"__esModule",{value:!0});qs.p2sh=void 0;const yu=gr,mg=qe,At=ct(),me=Ve,Et=ot,mu=bc,Rn=At.OPS;function bg(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,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(23)),redeem:me.typeforce.maybe({network:me.typeforce.maybe(me.typeforce.Object),output:me.typeforce.maybe(me.typeforce.Buffer),input:me.typeforce.maybe(me.typeforce.Buffer),witness:me.typeforce.maybe(me.typeforce.arrayOf(me.typeforce.Buffer))}),input:me.typeforce.maybe(me.typeforce.Buffer),witness:me.typeforce.maybe(me.typeforce.arrayOf(me.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||mg.bitcoin);const n={network:r},i=Et.value(()=>{const a=Buffer.from(mu.decode(e.address)),c=a.readUInt8(0),f=a.slice(1);return{version:c,hash:f}}),s=Et.value(()=>At.decompile(e.input)),o=Et.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Rn.OP_FALSE?Buffer.from([]):c,input:At.compile(a.slice(0,-1)),witness:e.witness||[]}});if(Et.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),mu.encode(a)}),Et.prop(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return yu.hash160(n.redeem.output)}),Et.prop(n,"output",()=>{if(n.hash)return At.compile([Rn.OP_HASH160,n.hash,Rn.OP_EQUAL])}),Et.prop(n,"redeem",()=>{if(e.input)return o()}),Et.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return At.compile([].concat(At.decompile(e.redeem.input),e.redeem.output))}),Et.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),Et.prop(n,"name",()=>{const a=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");a=i().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Rn.OP_HASH160||e.output[1]!==20||e.output[22]!==Rn.OP_EQUAL)throw new TypeError("Output is invalid");const f=e.output.slice(2,22);if(a.length>0&&!a.equals(f))throw new TypeError("Hash mismatch");a=f}const c=f=>{if(f.output){const l=At.decompile(f.output);if(!l||l.length<1)throw new TypeError("Redeem.output too short");if(f.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(At.countNonPushOnlyOPs(l)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const h=yu.hash160(f.output);if(a.length>0&&!a.equals(h))throw new TypeError("Hash mismatch");a=h}if(f.input){const l=f.input.length>0,h=f.witness&&f.witness.length>0;if(!l&&!h)throw new TypeError("Empty input");if(l&&h)throw new TypeError("Input and witness provided");if(l){const m=At.decompile(f.input);if(!At.isPushOnly(m))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const f=s();if(!f||f.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 f=o();if(e.redeem.output&&!e.redeem.output.equals(f.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(f.input))throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,me.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}qs.p2sh=bg;var Vs={},Kt={};Object.defineProperty(Kt,"__esModule",{value:!0});Kt.bech32m=Kt.bech32=void 0;const ws="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Jd={};for(let e=0;e<ws.length;e++){const t=ws.charAt(e);Jd[t]=e}function an(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 bu(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=an(t)^n>>5}t=an(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=an(t)^n&31}return t}function gc(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 gg(e){return gc(e,8,5,!0)}function wg(e){const t=gc(e,5,8,!1);if(Array.isArray(t))return t}function _g(e){const t=gc(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Qd(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 f=bu(o);if(typeof f=="string")throw new Error(f);let l=o+"1";for(let h=0;h<a.length;++h){const m=a[h];if(m>>5)throw new Error("Non 5-bit word");f=an(f)^m,l+=ws.charAt(m)}for(let h=0;h<6;++h)f=an(f);f^=t;for(let h=0;h<6;++h){const m=f>>(5-h)*5&31;l+=ws.charAt(m)}return l}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(),f=o.toUpperCase();if(o!==c&&o!==f)return"Mixed-case string "+o;o=c;const l=o.lastIndexOf("1");if(l===-1)return"No separator character for "+o;if(l===0)return"Missing prefix for "+o;const h=o.slice(0,l),m=o.slice(l+1);if(m.length<6)return"Data too short";let p=bu(h);if(typeof p=="string")return p;const g=[];for(let v=0;v<m.length;++v){const x=m.charAt(v),I=Jd[x];if(I===void 0)return"Unknown character "+x;p=an(p)^I,!(v+6>=m.length)&&g.push(I)}return p!==t?"Invalid checksum for "+o:{prefix:h,words:g}}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:gg,fromWordsUnsafe:wg,fromWords:_g}}Kt.bech32=Qd("bech32");Kt.bech32m=Qd("bech32m");Object.defineProperty(Vs,"__esModule",{value:!0});Vs.p2wpkh=void 0;const Uo=gr,vg=qe,us=ct(),Re=Ve,ar=ot,Ji=Kt,gu=us.OPS,Eg=Buffer.alloc(0);function xg(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,Re.typeforce)({address:Re.typeforce.maybe(Re.typeforce.String),hash:Re.typeforce.maybe(Re.typeforce.BufferN(20)),input:Re.typeforce.maybe(Re.typeforce.BufferN(0)),network:Re.typeforce.maybe(Re.typeforce.Object),output:Re.typeforce.maybe(Re.typeforce.BufferN(22)),pubkey:Re.typeforce.maybe(Re.isPoint),signature:Re.typeforce.maybe(us.isCanonicalScriptSignature),witness:Re.typeforce.maybe(Re.typeforce.arrayOf(Re.typeforce.Buffer))},e);const r=ar.value(()=>{const s=Ji.bech32.decode(e.address),o=s.words.shift(),a=Ji.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||vg.bitcoin,i={name:"p2wpkh",network:n};if(ar.prop(i,"address",()=>{if(!i.hash)return;const s=Ji.bech32.toWords(i.hash);return s.unshift(0),Ji.bech32.encode(n.bech32,s)}),ar.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return Uo.hash160(e.pubkey||i.pubkey)}),ar.prop(i,"output",()=>{if(i.hash)return us.compile([gu.OP_0,i.hash])}),ar.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),ar.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),ar.prop(i,"input",()=>{if(i.witness)return Eg}),ar.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]!==gu.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=Uo.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Re.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(!us.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Re.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=Uo.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}Vs.p2wpkh=xg;var Ws={};Object.defineProperty(Ws,"__esModule",{value:!0});Ws.p2wsh=void 0;const wu=gr,Ag=qe,Mt=ct(),pe=Ve,Ft=ot,Qi=Kt,_u=Mt.OPS,Lo=Buffer.alloc(0);function Zi(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,pe.isPoint)(e))}function Sg(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,pe.typeforce)({network:pe.typeforce.maybe(pe.typeforce.Object),address:pe.typeforce.maybe(pe.typeforce.String),hash:pe.typeforce.maybe(pe.typeforce.BufferN(32)),output:pe.typeforce.maybe(pe.typeforce.BufferN(34)),redeem:pe.typeforce.maybe({input:pe.typeforce.maybe(pe.typeforce.Buffer),network:pe.typeforce.maybe(pe.typeforce.Object),output:pe.typeforce.maybe(pe.typeforce.Buffer),witness:pe.typeforce.maybe(pe.typeforce.arrayOf(pe.typeforce.Buffer))}),input:pe.typeforce.maybe(pe.typeforce.BufferN(0)),witness:pe.typeforce.maybe(pe.typeforce.arrayOf(pe.typeforce.Buffer))},e);const r=Ft.value(()=>{const o=Qi.bech32.decode(e.address),a=o.words.shift(),c=Qi.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=Ft.value(()=>Mt.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Ag.bitcoin);const s={network:i};if(Ft.prop(s,"address",()=>{if(!s.hash)return;const o=Qi.bech32.toWords(s.hash);return o.unshift(0),Qi.bech32.encode(i.bech32,o)}),Ft.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return wu.sha256(s.redeem.output)}),Ft.prop(s,"output",()=>{if(s.hash)return Mt.compile([_u.OP_0,s.hash])}),Ft.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Lo,witness:e.witness.slice(0,-1)}}),Ft.prop(s,"input",()=>{if(s.witness)return Lo}),Ft.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=Lo,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Ft.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]!==_u.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=wu.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,pe.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Zi)||e.redeem.output&&(Mt.decompile(e.redeem.output)||[]).some(Zi))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(Zi)||(Mt.decompile(a)||[]).some(Zi))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}Ws.p2wsh=Sg;var Un={},Fr={};Object.defineProperty(Fr,"__esModule",{value:!0});Fr.getEccLib=Fr.initEccLib=void 0;const Wn={};function Pg(e,t){e?e!==Wn.eccLib&&(t!=null&&t.DANGER_DO_NOT_VERIFY_ECCLIB||kg(e),Wn.eccLib=e):Wn.eccLib=e}Fr.initEccLib=Pg;function Tg(){if(!Wn.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Wn.eccLib}Fr.getEccLib=Tg;const $t=e=>Buffer.from(e,"hex");function kg(e){ft(typeof e.isXOnlyPoint=="function"),ft(e.isXOnlyPoint($t("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ft(e.isXOnlyPoint($t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),ft(e.isXOnlyPoint($t("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),ft(e.isXOnlyPoint($t("0000000000000000000000000000000000000000000000000000000000000001"))),ft(!e.isXOnlyPoint($t("0000000000000000000000000000000000000000000000000000000000000000"))),ft(!e.isXOnlyPoint($t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),ft(typeof e.xOnlyPointAddTweak=="function"),Ig.forEach(t=>{const r=e.xOnlyPointAddTweak($t(t.pubkey),$t(t.tweak));t.result===null?ft(r===null):(ft(r!==null),ft(r.parity===t.parity),ft(Buffer.from(r.xOnlyPubkey).equals($t(t.result))))})}function ft(e){if(!e)throw new Error("ecc library invalid")}const Ig=[{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 wc={};(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=Jt,r=Fr,n=gr,i=Me,s=Ve;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=v=>"left"in v&&"right"in v;function a(v,x){if(v.length<33)throw new TypeError(`The control-block length is too small. Got ${v.length}, expected min 33.`);const I=(v.length-33)/32;let k=x;for(let A=0;A<I;A++){const E=v.slice(33+32*A,65+32*A);k.compare(E)<0?k=p(k,E):k=p(E,k)}return k}e.rootHashFromPath=a;function c(v){if((0,s.isTapleaf)(v))return{hash:l(v)};const x=[c(v[0]),c(v[1])];x.sort((A,E)=>A.hash.compare(E.hash));const[I,k]=x;return{hash:p(I.hash,k.hash),left:I,right:k}}e.toHashTree=c;function f(v,x){if(o(v)){const I=f(v.left,x);if(I!==void 0)return[...I,v.right.hash];const k=f(v.right,x);if(k!==void 0)return[...k,v.left.hash]}else if(v.hash.equals(x))return[]}e.findScriptPath=f;function l(v){const x=v.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([x]),g(v.output)]))}e.tapleafHash=l;function h(v,x){return n.taggedHash("TapTweak",t.Buffer.concat(x?[v,x]:[v]))}e.tapTweakHash=h;function m(v,x){if(!t.Buffer.isBuffer(v)||v.length!==32||x&&x.length!==32)return null;const I=h(v,x),k=(0,r.getEccLib)().xOnlyPointAddTweak(v,I);return!k||k.xOnlyPubkey===null?null:{parity:k.parity,x:t.Buffer.from(k.xOnlyPubkey)}}e.tweakKey=m;function p(v,x){return n.taggedHash("TapBranch",t.Buffer.concat([v,x]))}function g(v){const x=i.varuint.encodingLength(v.length),I=t.Buffer.allocUnsafe(x);return i.varuint.encode(v.length,I),t.Buffer.concat([I,v])}})(wc);var Xe={},vu;function Bg(){if(vu)return Xe;vu=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.toOutputScript=Xe.fromOutputScript=Xe.toBech32=Xe.toBase58Check=Xe.fromBech32=Xe.fromBase58Check=void 0;const e=qe,t=_c(),r=ct(),n=Ve,i=Kt,s=bc,o=40,a=2,c=16,f=2,l=80,h="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 m(A,E){const T=A.slice(2);if(T.length<a||T.length>o)throw new TypeError("Invalid program length for segwit address");const S=A[0]-l;if(S<f||S>c)throw new TypeError("Invalid version for segwit address");if(A[1]!==T.length)throw new TypeError("Invalid script for segwit address");return console.warn(h),x(T,S,E.bech32)}function p(A){const E=Buffer.from(s.decode(A));if(E.length<21)throw new TypeError(A+" is too short");if(E.length>21)throw new TypeError(A+" is too long");const T=E.readUInt8(0),S=E.slice(1);return{version:T,hash:S}}Xe.fromBase58Check=p;function g(A){let E,T;try{E=i.bech32.decode(A)}catch{}if(E){if(T=E.words[0],T!==0)throw new TypeError(A+" uses wrong encoding")}else if(E=i.bech32m.decode(A),T=E.words[0],T===0)throw new TypeError(A+" uses wrong encoding");const S=i.bech32.fromWords(E.words.slice(1));return{version:T,prefix:E.prefix,data:Buffer.from(S)}}Xe.fromBech32=g;function v(A,E){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const T=Buffer.allocUnsafe(21);return T.writeUInt8(E,0),A.copy(T,1),s.encode(T)}Xe.toBase58Check=v;function x(A,E,T){const S=i.bech32.toWords(A);return S.unshift(E),E===0?i.bech32.encode(T,S):i.bech32m.encode(T,S)}Xe.toBech32=x;function I(A,E){E=E||e.bitcoin;try{return t.p2pkh({output:A,network:E}).address}catch{}try{return t.p2sh({output:A,network:E}).address}catch{}try{return t.p2wpkh({output:A,network:E}).address}catch{}try{return t.p2wsh({output:A,network:E}).address}catch{}try{return t.p2tr({output:A,network:E}).address}catch{}try{return m(A,E)}catch{}throw new Error(r.toASM(A)+" has no matching Address")}Xe.fromOutputScript=I;function k(A,E){E=E||e.bitcoin;let T,S;try{T=p(A)}catch{}if(T){if(T.version===E.pubKeyHash)return t.p2pkh({hash:T.hash}).output;if(T.version===E.scriptHash)return t.p2sh({hash:T.hash}).output}else{try{S=g(A)}catch{}if(S){if(S.prefix!==E.bech32)throw new Error(A+" has an invalid prefix");if(S.version===0){if(S.data.length===20)return t.p2wpkh({hash:S.data}).output;if(S.data.length===32)return t.p2wsh({hash:S.data}).output}else if(S.version===1){if(S.data.length===32)return t.p2tr({pubkey:S.data}).output}else if(S.version>=f&&S.version<=c&&S.data.length>=a&&S.data.length<=o)return console.warn(h),r.compile([S.version+l,S.data])}}throw new Error(A+" has no matching Script")}return Xe.toOutputScript=k,Xe}var Eu;function Cg(){if(Eu)return Un;Eu=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.p2tr=void 0;const e=Jt,t=qe,r=ct(),n=Ve,i=Fr,s=wc,o=ot,a=Kt,c=Bg(),f=r.OPS,l=1,h=80;function m(p,g){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");g=Object.assign({validate:!0},g||{}),(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)},p);const v=o.value(()=>(0,c.fromBech32)(p.address)),x=o.value(()=>{if(!(!p.witness||!p.witness.length))return p.witness.length>=2&&p.witness[p.witness.length-1][0]===h?p.witness.slice(0,-1):p.witness.slice()}),I=o.value(()=>{if(p.scriptTree)return(0,s.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),k=p.network||t.bitcoin,A={name:"p2tr",network:k};if(o.prop(A,"address",()=>{if(!A.pubkey)return;const E=a.bech32m.toWords(A.pubkey);return E.unshift(l),a.bech32m.encode(k.bech32,E)}),o.prop(A,"hash",()=>{const E=I();if(E)return E.hash;const T=x();if(T&&T.length>1){const S=T[T.length-1],N=S[0]&n.TAPLEAF_VERSION_MASK,M=T[T.length-2],B=(0,s.tapleafHash)({output:M,version:N});return(0,s.rootHashFromPath)(S,B)}return null}),o.prop(A,"output",()=>{if(A.pubkey)return r.compile([f.OP_1,A.pubkey])}),o.prop(A,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(A,"redeem",()=>{const E=x();if(!(!E||E.length<2))return{output:E[E.length-2],witness:E.slice(0,-2),redeemVersion:E[E.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(A,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return v().data;if(A.internalPubkey){const E=(0,s.tweakKey)(A.internalPubkey,A.hash);if(E)return E.x}}),o.prop(A,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const E=x();if(E&&E.length>1)return E[E.length-1].slice(1,33)}),o.prop(A,"signature",()=>{if(p.signature)return p.signature;const E=x();if(!(!E||E.length!==1))return E[0]}),o.prop(A,"witness",()=>{if(p.witness)return p.witness;const E=I();if(E&&p.redeem&&p.redeem.output&&p.internalPubkey){const T=(0,s.tapleafHash)({output:p.redeem.output,version:A.redeemVersion}),S=(0,s.findScriptPath)(E,T);if(!S)return;const N=(0,s.tweakKey)(p.internalPubkey,E.hash);if(!N)return;const M=e.Buffer.concat([e.Buffer.from([A.redeemVersion|N.parity]),p.internalPubkey].concat(S));return[p.redeem.output,M]}if(p.signature)return[p.signature]}),g.validate){let E=e.Buffer.from([]);if(p.address){if(k&&k.bech32!==v().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(v().version!==l)throw new TypeError("Invalid address version");if(v().data.length!==32)throw new TypeError("Invalid address data");E=v().data}if(p.pubkey){if(E.length>0&&!E.equals(p.pubkey))throw new TypeError("Pubkey mismatch");E=p.pubkey}if(p.output){if(p.output.length!==34||p.output[0]!==f.OP_1||p.output[1]!==32)throw new TypeError("Output is invalid");if(E.length>0&&!E.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");E=p.output.slice(2)}if(p.internalPubkey){const N=(0,s.tweakKey)(p.internalPubkey,A.hash);if(E.length>0&&!E.equals(N.x))throw new TypeError("Pubkey mismatch");E=N.x}if(E&&E.length&&!(0,i.getEccLib)().isXOnlyPoint(E))throw new TypeError("Invalid pubkey for p2tr");const T=I();if(p.hash&&T&&!p.hash.equals(T.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&T){const N=(0,s.tapleafHash)({output:p.redeem.output,version:A.redeemVersion});if(!(0,s.findScriptPath)(T,N))throw new TypeError("Redeem script not in tree")}const S=x();if(p.redeem&&A.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==A.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(p.redeem.output){if(r.decompile(p.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(A.redeem.output&&!p.redeem.output.equals(A.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&A.redeem.witness&&!(0,n.stacksEqual)(p.redeem.witness,A.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(S&&S.length)if(S.length===1){if(p.signature&&!p.signature.equals(S[0]))throw new TypeError("Signature mismatch")}else{const N=S[S.length-1];if(N.length<33)throw new TypeError(`The control-block length is too small. Got ${N.length}, expected min 33.`);if((N.length-33)%32!==0)throw new TypeError(`The control-block length of ${N.length} is incorrect!`);const M=(N.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const B=N.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(B))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(B))throw new TypeError("Invalid internalPubkey for p2tr witness");const W=N[0]&n.TAPLEAF_VERSION_MASK,U=S[S.length-2],D=(0,s.tapleafHash)({output:U,version:W}),G=(0,s.rootHashFromPath)(N,D),V=(0,s.tweakKey)(B,G);if(!V)throw new TypeError("Invalid outputKey for p2tr witness");if(E.length&&!E.equals(V.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(V.parity!==(N[0]&1))throw new Error("Incorrect parity")}}return Object.assign(A,p)}return Un.p2tr=m,Un}var xu;function _c(){return xu||(xu=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=Ds;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=js;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=Gs;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=zs;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=qs;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=Vs;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=Ws;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=Cg();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Co)),Co}Object.defineProperty(le,"__esModule",{value:!0});le.signatureBlocksAction=le.checkInputForSig=le.pubkeyInScript=le.pubkeyPositionInScript=le.witnessStackToScriptWitness=le.isP2TR=le.isP2SHScript=le.isP2WSHScript=le.isP2WPKH=le.isP2PKH=le.isP2PK=le.isP2MS=void 0;const Au=Ni,Kn=ct(),es=Li,Og=gr,Hr=_c();function Dr(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}le.isP2MS=Dr(Hr.p2ms);le.isP2PK=Dr(Hr.p2pk);le.isP2PKH=Dr(Hr.p2pkh);le.isP2WPKH=Dr(Hr.p2wpkh);le.isP2WSHScript=Dr(Hr.p2wsh);le.isP2SHScript=Dr(Hr.p2sh);le.isP2TR=Dr(Hr.p2tr);function Rg(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=Au.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Au.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}le.witnessStackToScriptWitness=Rg;function Zd(e,t){const r=(0,Og.hash160)(e),n=e.slice(1,33),i=Kn.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))}le.pubkeyPositionInScript=Zd;function Ug(e,t){return Zd(e,t)!==-1}le.pubkeyInScript=Ug;function Lg(e,t){return Ng(e).some(n=>el(n,Kn.signature.decode,t))}le.checkInputForSig=Lg;function el(e,t,r){const{hashType:n}=t(e),i=[];switch(n&es.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case es.Transaction.SIGHASH_ALL:break;case es.Transaction.SIGHASH_SINGLE:case es.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}le.signatureBlocksAction=el;function Ng(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=Fg(e)}else t=e.partialSig;return t.map(r=>r.signature)}function Fg(e){const t=e.finalScriptSig?Kn.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?Kn.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&Kn.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(Ae,"__esModule",{value:!0});Ae.checkTaprootInputForSigs=Ae.tapTreeFromList=Ae.tapTreeToList=Ae.tweakInternalPubKey=Ae.checkTaprootOutputFields=Ae.checkTaprootInputFields=Ae.isTaprootOutput=Ae.isTaprootInput=fs=Ae.serializeTaprootSignature=Ae.tapScriptFinalizer=Ae.toXOnly=void 0;const vc=Ve,$g=Li,Ks=le,mr=wc,Mg=_c(),Hg=le,Dg=e=>e.length===32?e:e.slice(1,33);Ae.toXOnly=Dg;function jg(e,t,r){const n=o1(t,e,r);try{const s=i1(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,Ks.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}Ae.tapScriptFinalizer=jg;function Gg(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var fs=Ae.serializeTaprootSignature=Gg;function ds(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,Ks.isP2TR)(e.witnessUtxo.script))}Ae.isTaprootInput=ds;function ls(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,Ks.isP2TR)(t))}Ae.isTaprootOutput=ls;function zg(e,t,r){t1(e,t,r),n1(e,t,r)}Ae.checkTaprootInputFields=zg;function qg(e,t,r){r1(e,t,r),Vg(e,t)}Ae.checkTaprootOutputFields=qg;function Vg(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=Wg(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function Wg(e,t){const r=t&&tl(t.leaves),{output:n}=(0,Mg.p2tr)({internalPubkey:e,scriptTree:r});return n}function Kg(e,t){const r=t.tapInternalKey,n=r&&(0,mr.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}Ae.tweakInternalPubKey=Kg;function Yg(e){if(!(0,vc.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ga(e)}Ae.tapTreeToList=Yg;function tl(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:e1(e)}Ae.tapTreeFromList=tl;function Xg(e,t){return Qg(e).some(n=>(0,Hg.signatureBlocksAction)(n,Jg,t))}Ae.checkTaprootInputForSigs=Xg;function Jg(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||$g.Transaction.SIGHASH_DEFAULT}}function Qg(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=Zg(e.finalScriptWitness);r&&t.push(r)}return t}function Zg(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function ga(e,t=[],r=0){if(r>mr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,vc.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||mr.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&ga(e[0],t,r+1),e[1]&&ga(e[1],t,r+1),t):[]}function e1(e){let t;for(const r of e)if(t=wa(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function wa(e,t,r=0){if(r>mr.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,vc.isTapleaf)(t))return;const n=wa(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=wa(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function t1(e,t,r){const n=ds(e)&&cn(t),i=cn(e)&&ds(t),s=e===t&&ds(t)&&cn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function r1(e,t,r){const n=ls(e)&&cn(t),i=cn(e)&&ls(t),s=e===t&&ls(t)&&cn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function n1(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>No(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>No(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=>No(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function No(e,t){if(!t)return!0;const r=(0,mr.tapleafHash)({output:e.script,version:e.leafVersion});return(0,mr.rootHashFromPath)(e.controlBlock,r).equals(t)}function i1(e,t){const r=(0,mr.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>s1(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function s1(e,t){return Object.assign({positionInScript:(0,Ks.pubkeyPositionInScript)(t.pubkey,e)},t)}function o1(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=>a1(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function a1(e,t,r){const n=(0,mr.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function cn(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const Fe={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"},ts=192;ce.initEccLib(Br);class Yn{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=fb(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,Ar(n.length===64,Fe.secretHashLenMismatch),Ar(i.length===64||i.length===66,`initiator ${Fe.pubkeyLenMismatch}`),Ar(s.length===64||s.length===66,`redeemer ${Fe.pubkeyLenMismatch}`),Ar(o>0,Fe.zeroOrNegativeExpiry);const c=await t.getNetwork();return new Yn(t,r,n,pa(s).toString("hex"),pa(i).toString("hex"),o,c,a)}address(){const{address:t}=ce.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(Fe.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new ce.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 f=await s.getTransaction(c);for(let l=0;l<f.vout.length;l++){const h=f.vout[l];h.scriptpubkey_address===i&&o.push({txid:f.txid,vout:l,value:h.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,f)=>c+f.value,0);if(a===0)throw new Error(`${i} ${Fe.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,fn.Urgency.MEDIUM)),n.addOutput(ce.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async _tempBuildRawTx(t,r){const n=new ce.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 f=await s.getTransaction(c);for(let l=0;l<f.vout.length;l++){const h=f.vout[l];h.scriptpubkey_address===i&&o.push({txid:f.txid,vout:l,value:h.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,f)=>c+f.value,0);if(a===0)throw new Error(`${i} ${Fe.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);if(n.addOutput(ce.address.toOutputScript(t,this.network),a),r){const c=await s.getFeeRates(),f=Math.ceil(c.hourFee*r),l=a-f;n.outs[0].value=l}return{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return ce.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,fn.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=ce.Transaction.SIGHASH_SINGLE|ce.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),f=s.map(h=>h.value),l=Xr(o,s.length);for(let h=0;h<i.ins.length;h++){const m=i.hashForWitnessV1(h,l,f,a,c),p=await this.signer.signSchnorr(m);i.setWitness(h,[fs(p,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=ce.Transaction.SIGHASH_SINGLE|ce.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(l=>l.value),f=Xr(s,i.length);for(let l=0;l<n.ins.length;l++){const h=n.hashForWitnessV1(l,f,c,o,a),m=await this.signer.signSchnorr(h);n.setWitness(l,[fs(m,o),fs(m,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){Ar(t.length>0,Fe.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const h of i)if(!t.find(m=>m.utxo===h.txid))throw new Error(Fe.counterPartySigNotFound(h.txid));const s=this.getOutputScript(),o=ce.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(h=>h.value),f=Xr(s,i.length);for(let h=0;h<n.ins.length;h++){const m=n.hashForWitnessV1(h,f,c,o,a);if(!Br.verifySchnorr(m,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[h].sig,"hex")))throw new Error(Fe.invalidCounterpartySigForUTXO(t[h].utxo));const p=await this.signer.signSchnorr(m),g=Buffer.from(n.ins[h].hash).reverse().toString("hex"),v=t.find(x=>x.utxo===g);if(!v)throw new Error(Fe.counterPartySigNotFound(g));n.setWitness(h,[Buffer.from(v.sig,"hex"),p,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){Ar(ce.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Fe.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(m=>m.value),c=Xr(this.getOutputScript(),s.length),f=ce.Transaction.SIGHASH_DEFAULT;for(let m=0;m<i.ins.length;m++){const p=i.hashForWitnessV1(m,c,a,f,o),g=await this.signer.signSchnorr(p);i.setWitness(m,[g,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:l}=await this._tempBuildRawTx(n,i.virtualSize());for(let m=0;m<l.ins.length;m++){const p=l.hashForWitnessV1(m,c,a,f,o),g=await this.signer.signSchnorr(p);l.setWitness(m,[g,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(l.toHex())}async getRedeemHex(t,r){Ar(ce.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Fe.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(h=>h.value),c=Xr(this.getOutputScript(),s.length),f=ce.Transaction.SIGHASH_DEFAULT;for(let h=0;h<i.ins.length;h++){const m=i.hashForWitnessV1(h,c,a,f,o),p=await this.signer.signSchnorr(m);i.setWitness(h,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:l}=await this._tempBuildRawTx(n,i.virtualSize());for(let h=0;h<l.ins.length;h++){const m=l.hashForWitnessV1(h,c,a,f,o),p=await this.signer.signSchnorr(m);l.setWitness(h,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return l.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(Fe.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(m=>m.value),f=Xr(this.getOutputScript(),i.length),l=ce.Transaction.SIGHASH_DEFAULT;for(let m=0;m<n.ins.length;m++){n.ins[m].sequence=this.expiry;const p=n.hashForWitnessV1(m,f,c,l,a),g=await this.signer.signSchnorr(p);n.setWitness(m,[g,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(Fe.invalidLeaf)}const n=ce.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:ts}});if(!n.witness)throw new Error(Fe.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()),ce.crypto.taggedHash("TapLeaf",Xm(r))}refundLeaf(){return ce.script.fromASM(`
|
|
50
50
|
${ce.script.number.encode(this.expiry).toString("hex")}
|
|
51
51
|
OP_CHECKSEQUENCEVERIFY
|
|
52
52
|
OP_DROP
|
|
@@ -65,7 +65,7 @@ ${wp(p)}`),super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessa
|
|
|
65
65
|
OP_CHECKSIGADD
|
|
66
66
|
OP_2
|
|
67
67
|
OP_NUMEQUAL
|
|
68
|
-
`.trim().replace(/\s+/g," "))}leaves(){return[{version:ts,output:this.redeemLeaf()},[{version:ts,output:this.refundLeaf()},{version:ts,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const s=Qm(i,n);return[ce.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(Fe.invalidLeaf)}}}function Xr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class c1{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 u1{constructor(){this.cache={}}set(t,r){this.cache[t]=r}get(t){return this.cache[t]||null}}class rl{constructor(t,r){this.url=new z.Url(t).endpoint("blocknumbers").endpoint(r)}async fetchBlockNumbers(){try{const t=await Dt.get(this.url);return ie(t)}catch(t){return
|
|
68
|
+
`.trim().replace(/\s+/g," "))}leaves(){return[{version:ts,output:this.redeemLeaf()},[{version:ts,output:this.refundLeaf()},{version:ts,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const s=Qm(i,n);return[ce.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(Fe.invalidLeaf)}}}function Xr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class c1{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 u1{constructor(){this.cache={}}set(t,r){this.cache[t]=r}get(t){return this.cache[t]||null}}class rl{constructor(t,r){this.url=new z.Url(t).endpoint("blocknumbers").endpoint(r)}async fetchBlockNumbers(){try{const t=await Dt.get(this.url);return ie(t)}catch(t){return j("Failed to fetch block numbers",t)}}}const Vn={mainnet:{orderbook:"https://api.garden.finance",auth:"https://api.garden.finance/auth",quote:"https://api.garden.finance/quote",info:"https://api.garden.finance/info",evmRelay:"https://api.garden.finance/relayer",starknetRelay:"https://api.garden.finance/starknet"},testnet:{orderbook:"https://testnet.api.garden.finance",auth:"https://testnet.api.garden.finance/auth",quote:"https://testnet.api.garden.finance/quote",info:"https://testnet.api.garden.finance/info",evmRelay:"https://testnet.api.garden.finance/relayer",starknetRelay:"https://testnet.api.garden.finance/starknet"},localnet:{orderbook:"",auth:"",quote:"",info:"",evmRelay:"",starknetRelay:""}},_s={[z.Network.MAINNET]:{chainId:"0x534e5f4d41494e",nodeUrl:"https://starknet-mainnet.public.blastapi.io/rpc/v0_8"},[z.Network.TESTNET]:{chainId:"0x534e5f5345504f4c4941",nodeUrl:"https://starknet-sepolia.public.blastapi.io/rpc/v0_8"}};class nl{constructor(t){this.quoteUrl=new z.Url(t)}async getQuote(t,r,n=!1,i){try{const s=this.quoteUrl.endpoint("/").addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),o=await Dt.get(s,{retryCount:0,...i});return o.error?j(o.error):o.result?ie(o.result):j("GetQuote: Unexpected error, result is undefined")}catch(s){return j("GetQuote:",String(s))}}async getAttestedQuote(t){try{const r=await Dt.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?j(r.error):r.result?ie(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 Dt.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=Cd(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 ie(r)}catch(t){return j("GetStrategies:",String(t))}}}var il={},mn={},bn={};Object.defineProperty(bn,"__esModule",{value:!0});bn.testnet=bn.bitcoin=void 0;bn.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
69
69
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};bn.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
70
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var sl={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Md,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})(sl);var
|
|
71
|
-
Use Chrome, Firefox or Internet Explorer 11`)}var l1=tt.Buffer,vs=yr.crypto||yr.msCrypto;vs&&vs.getRandomValues?ga.exports=h1:ga.exports=d1;function h1(e,t){if(e>f1)throw new RangeError("requested too many random bytes");var r=l1.allocUnsafe(e);if(e>0)if(e>Lo)for(var n=0;n<e;n+=Lo)vs.getRandomValues(r.slice(n,n+Lo));else vs.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var p1=ga.exports,_a={exports:{}};typeof Object.create=="function"?_a.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:_a.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 He=_a.exports,va={exports:{}},_c={exports:{}},un=typeof Reflect=="object"?Reflect:null,Su=un&&typeof un.apply=="function"?un.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},hs;un&&typeof un.ownKeys=="function"?hs=un.ownKeys:Object.getOwnPropertySymbols?hs=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:hs=function(t){return Object.getOwnPropertyNames(t)};function y1(e){console&&console.warn&&console.warn(e)}var ol=Number.isNaN||function(t){return t!==t};function ue(){ue.init.call(this)}_c.exports=ue;_c.exports.once=w1;ue.EventEmitter=ue;ue.prototype._events=void 0;ue.prototype._eventsCount=0;ue.prototype._maxListeners=void 0;var Pu=10;function Ys(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(ue,"defaultMaxListeners",{enumerable:!0,get:function(){return Pu},set:function(e){if(typeof e!="number"||e<0||ol(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Pu=e}});ue.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};ue.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ol(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 al(e){return e._maxListeners===void 0?ue.defaultMaxListeners:e._maxListeners}ue.prototype.getMaxListeners=function(){return al(this)};ue.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")Su(c,this,r);else for(var f=c.length,l=ll(c,f),n=0;n<f;++n)Su(l[n],this,r);return!0};function cl(e,t,r,n){var i,s,o;if(Ys(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=al(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,y1(a)}return e}ue.prototype.addListener=function(t,r){return cl(this,t,r,!1)};ue.prototype.on=ue.prototype.addListener;ue.prototype.prependListener=function(t,r){return cl(this,t,r,!0)};function m1(){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 ul(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=m1.bind(n);return i.listener=r,n.wrapFn=i,i}ue.prototype.once=function(t,r){return Ys(r),this.on(t,ul(this,t,r)),this};ue.prototype.prependOnceListener=function(t,r){return Ys(r),this.prependListener(t,ul(this,t,r)),this};ue.prototype.removeListener=function(t,r){var n,i,s,o,a;if(Ys(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():b1(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};ue.prototype.off=ue.prototype.removeListener;ue.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 fl(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?g1(i):ll(i,i.length)}ue.prototype.listeners=function(t){return fl(this,t,!0)};ue.prototype.rawListeners=function(t){return fl(this,t,!1)};ue.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):dl.call(e,t)};ue.prototype.listenerCount=dl;function dl(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}ue.prototype.eventNames=function(){return this._eventsCount>0?hs(this._events):[]};function ll(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function b1(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function g1(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function w1(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))}hl(e,t,s,{once:!0}),t!=="error"&&_1(e,i,{once:!0})})}function _1(e,t,r){typeof e.on=="function"&&hl(e,"error",t,r)}function hl(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 pl=_c.exports,yl=pl.EventEmitter;const v1={},E1=Object.freeze(Object.defineProperty({__proto__:null,default:v1},Symbol.toStringTag,{value:"Module"})),vc=ac(E1);var No,Tu;function x1(){if(Tu)return No;Tu=1;function e(g,v){var x=Object.keys(g);if(Object.getOwnPropertySymbols){var I=Object.getOwnPropertySymbols(g);v&&(I=I.filter(function(k){return Object.getOwnPropertyDescriptor(g,k).enumerable})),x.push.apply(x,I)}return x}function t(g){for(var v=1;v<arguments.length;v++){var x=arguments[v]!=null?arguments[v]:{};v%2?e(Object(x),!0).forEach(function(I){r(g,I,x[I])}):Object.getOwnPropertyDescriptors?Object.defineProperties(g,Object.getOwnPropertyDescriptors(x)):e(Object(x)).forEach(function(I){Object.defineProperty(g,I,Object.getOwnPropertyDescriptor(x,I))})}return g}function r(g,v,x){return v=o(v),v in g?Object.defineProperty(g,v,{value:x,enumerable:!0,configurable:!0,writable:!0}):g[v]=x,g}function n(g,v){if(!(g instanceof v))throw new TypeError("Cannot call a class as a function")}function i(g,v){for(var x=0;x<v.length;x++){var I=v[x];I.enumerable=I.enumerable||!1,I.configurable=!0,"value"in I&&(I.writable=!0),Object.defineProperty(g,o(I.key),I)}}function s(g,v,x){return v&&i(g.prototype,v),Object.defineProperty(g,"prototype",{writable:!1}),g}function o(g){var v=a(g,"string");return typeof v=="symbol"?v:String(v)}function a(g,v){if(typeof g!="object"||g===null)return g;var x=g[Symbol.toPrimitive];if(x!==void 0){var I=x.call(g,v);if(typeof I!="object")return I;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(g)}var c=Jt,f=c.Buffer,l=vc,h=l.inspect,m=h&&h.custom||"inspect";function p(g,v,x){f.prototype.copy.call(g,v,x)}return No=function(){function g(){n(this,g),this.head=null,this.tail=null,this.length=0}return s(g,[{key:"push",value:function(x){var I={data:x,next:null};this.length>0?this.tail.next=I:this.head=I,this.tail=I,++this.length}},{key:"unshift",value:function(x){var I={data:x,next:this.head};this.length===0&&(this.tail=I),this.head=I,++this.length}},{key:"shift",value:function(){if(this.length!==0){var x=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,x}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(x){if(this.length===0)return"";for(var I=this.head,k=""+I.data;I=I.next;)k+=x+I.data;return k}},{key:"concat",value:function(x){if(this.length===0)return f.alloc(0);for(var I=f.allocUnsafe(x>>>0),k=this.head,A=0;k;)p(k.data,I,A),A+=k.data.length,k=k.next;return I}},{key:"consume",value:function(x,I){var k;return x<this.head.data.length?(k=this.head.data.slice(0,x),this.head.data=this.head.data.slice(x)):x===this.head.data.length?k=this.shift():k=I?this._getString(x):this._getBuffer(x),k}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(x){var I=this.head,k=1,A=I.data;for(x-=A.length;I=I.next;){var E=I.data,T=x>E.length?E.length:x;if(T===E.length?A+=E:A+=E.slice(0,x),x-=T,x===0){T===E.length?(++k,I.next?this.head=I.next:this.head=this.tail=null):(this.head=I,I.data=E.slice(T));break}++k}return this.length-=k,A}},{key:"_getBuffer",value:function(x){var I=f.allocUnsafe(x),k=this.head,A=1;for(k.data.copy(I),x-=k.data.length;k=k.next;){var E=k.data,T=x>E.length?E.length:x;if(E.copy(I,I.length-x,0,T),x-=T,x===0){T===E.length?(++A,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=E.slice(T));break}++A}return this.length-=A,I}},{key:m,value:function(x,I){return h(this,t(t({},I),{},{depth:0,customInspect:!1}))}}]),g}(),No}function A1(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(Ea,this,e)):process.nextTick(Ea,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(ps,r):(r._writableState.errorEmitted=!0,process.nextTick(ku,r,s)):process.nextTick(ku,r,s):t?(process.nextTick(ps,r),t(s)):process.nextTick(ps,r)}),this)}function ku(e,t){Ea(e,t),ps(e)}function ps(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function S1(){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 Ea(e,t){e.emit("error",t)}function P1(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var ml={destroy:A1,undestroy:S1,errorOrDestroy:P1},jr={};function T1(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var bl={};function pt(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){T1(o,s);function o(a,c,f){return s.call(this,n(a,c,f))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,bl[e]=i}function Iu(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 k1(e,t,r){return e.substr(0,t.length)===t}function I1(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function B1(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}pt("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);pt("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&k1(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(I1(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Iu(t,"type"));else{var s=B1(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Iu(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);pt("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");pt("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});pt("ERR_STREAM_PREMATURE_CLOSE","Premature close");pt("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});pt("ERR_MULTIPLE_CALLBACK","Callback called multiple times");pt("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");pt("ERR_STREAM_WRITE_AFTER_END","write after end");pt("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);pt("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);pt("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");jr.codes=bl;var C1=jr.codes.ERR_INVALID_OPT_VALUE;function O1(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function R1(e,t,r,n){var i=O1(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new C1(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var gl={getHighWaterMark:R1},U1=L1;function L1(e,t){if(Fo("noDeprecation"))return e;var r=!1;function n(){if(!r){if(Fo("throwDeprecation"))throw new Error(t);Fo("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function Fo(e){try{if(!yr.localStorage)return!1}catch{return!1}var t=yr.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var $o,Bu;function wl(){if(Bu)return $o;Bu=1,$o=M;function e(O){var C=this;this.next=null,this.entry=null,this.finish=function(){Rt(C,O)}}var t;M.WritableState=S;var r={deprecate:U1},n=yl,i=Jt.Buffer,s=(typeof yr<"u"?yr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(O){return i.from(O)}function a(O){return i.isBuffer(O)||O instanceof s}var c=ml,f=gl,l=f.getHighWaterMark,h=jr.codes,m=h.ERR_INVALID_ARG_TYPE,p=h.ERR_METHOD_NOT_IMPLEMENTED,g=h.ERR_MULTIPLE_CALLBACK,v=h.ERR_STREAM_CANNOT_PIPE,x=h.ERR_STREAM_DESTROYED,I=h.ERR_STREAM_NULL_VALUES,k=h.ERR_STREAM_WRITE_AFTER_END,A=h.ERR_UNKNOWN_ENCODING,E=c.errorOrDestroy;He(M,n);function T(){}function S(O,C,H){t=t||gn(),O=O||{},typeof H!="boolean"&&(H=C instanceof t),this.objectMode=!!O.objectMode,H&&(this.objectMode=this.objectMode||!!O.writableObjectMode),this.highWaterMark=l(this,O,"writableHighWaterMark",H),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var K=O.decodeStrings===!1;this.decodeStrings=!K,this.defaultEncoding=O.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(Z){ne(C,Z)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=O.emitClose!==!1,this.autoDestroy=!!O.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}S.prototype.getBuffer=function(){for(var C=this.bufferedRequest,H=[];C;)H.push(C),C=C.next;return H},function(){try{Object.defineProperty(S.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var N;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(N=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(C){return N.call(this,C)?!0:this!==M?!1:C&&C._writableState instanceof S}})):N=function(C){return C instanceof this};function M(O){t=t||gn();var C=this instanceof t;if(!C&&!N.call(M,this))return new M(O);this._writableState=new S(O,this,C),this.writable=!0,O&&(typeof O.write=="function"&&(this._write=O.write),typeof O.writev=="function"&&(this._writev=O.writev),typeof O.destroy=="function"&&(this._destroy=O.destroy),typeof O.final=="function"&&(this._final=O.final)),n.call(this)}M.prototype.pipe=function(){E(this,new v)};function B(O,C){var H=new k;E(O,H),process.nextTick(C,H)}function W(O,C,H,K){var Z;return H===null?Z=new I:typeof H!="string"&&!C.objectMode&&(Z=new m("chunk",["string","Buffer"],H)),Z?(E(O,Z),process.nextTick(K,Z),!1):!0}M.prototype.write=function(O,C,H){var K=this._writableState,Z=!1,w=!K.objectMode&&a(O);return w&&!i.isBuffer(O)&&(O=o(O)),typeof C=="function"&&(H=C,C=null),w?C="buffer":C||(C=K.defaultEncoding),typeof H!="function"&&(H=T),K.ending?B(this,H):(w||W(this,K,O,H))&&(K.pendingcb++,Z=D(this,K,w,O,C,H)),Z},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var O=this._writableState;O.corked&&(O.corked--,!O.writing&&!O.corked&&!O.bufferProcessing&&O.bufferedRequest&&Te(this,O))},M.prototype.setDefaultEncoding=function(C){if(typeof C=="string"&&(C=C.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((C+"").toLowerCase())>-1))throw new A(C);return this._writableState.defaultEncoding=C,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function U(O,C,H){return!O.objectMode&&O.decodeStrings!==!1&&typeof C=="string"&&(C=i.from(C,H)),C}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function D(O,C,H,K,Z,w){if(!H){var _=U(C,K,Z);K!==_&&(H=!0,Z="buffer",K=_)}var F=C.objectMode?1:K.length;C.length+=F;var q=C.length<C.highWaterMark;if(q||(C.needDrain=!0),C.writing||C.corked){var ve=C.lastBufferedRequest;C.lastBufferedRequest={chunk:K,encoding:Z,isBuf:H,callback:w,next:null},ve?ve.next=C.lastBufferedRequest:C.bufferedRequest=C.lastBufferedRequest,C.bufferedRequestCount+=1}else j(O,C,!1,F,K,Z,w);return q}function j(O,C,H,K,Z,w,_){C.writelen=K,C.writecb=_,C.writing=!0,C.sync=!0,C.destroyed?C.onwrite(new x("write")):H?O._writev(Z,C.onwrite):O._write(Z,w,C.onwrite),C.sync=!1}function V(O,C,H,K,Z){--C.pendingcb,H?(process.nextTick(Z,K),process.nextTick(it,O,C),O._writableState.errorEmitted=!0,E(O,K)):(Z(K),O._writableState.errorEmitted=!0,E(O,K),it(O,C))}function X(O){O.writing=!1,O.writecb=null,O.length-=O.writelen,O.writelen=0}function ne(O,C){var H=O._writableState,K=H.sync,Z=H.writecb;if(typeof Z!="function")throw new g;if(X(H),C)V(O,H,K,C,Z);else{var w=We(H)||O.destroyed;!w&&!H.corked&&!H.bufferProcessing&&H.bufferedRequest&&Te(O,H),K?process.nextTick(he,O,H,w,Z):he(O,H,w,Z)}}function he(O,C,H,K){H||_e(O,C),C.pendingcb--,K(),it(O,C)}function _e(O,C){C.length===0&&C.needDrain&&(C.needDrain=!1,O.emit("drain"))}function Te(O,C){C.bufferProcessing=!0;var H=C.bufferedRequest;if(O._writev&&H&&H.next){var K=C.bufferedRequestCount,Z=new Array(K),w=C.corkedRequestsFree;w.entry=H;for(var _=0,F=!0;H;)Z[_]=H,H.isBuf||(F=!1),H=H.next,_+=1;Z.allBuffers=F,j(O,C,!0,C.length,Z,"",w.finish),C.pendingcb++,C.lastBufferedRequest=null,w.next?(C.corkedRequestsFree=w.next,w.next=null):C.corkedRequestsFree=new e(C),C.bufferedRequestCount=0}else{for(;H;){var q=H.chunk,ve=H.encoding,ee=H.callback,ae=C.objectMode?1:q.length;if(j(O,C,!1,ae,q,ve,ee),H=H.next,C.bufferedRequestCount--,C.writing)break}H===null&&(C.lastBufferedRequest=null)}C.bufferedRequest=H,C.bufferProcessing=!1}M.prototype._write=function(O,C,H){H(new p("_write()"))},M.prototype._writev=null,M.prototype.end=function(O,C,H){var K=this._writableState;return typeof O=="function"?(H=O,O=null,C=null):typeof C=="function"&&(H=C,C=null),O!=null&&this.write(O,C),K.corked&&(K.corked=1,this.uncork()),K.ending||Qt(this,K,H),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function We(O){return O.ending&&O.length===0&&O.bufferedRequest===null&&!O.finished&&!O.writing}function fe(O,C){O._final(function(H){C.pendingcb--,H&&E(O,H),C.prefinished=!0,O.emit("prefinish"),it(O,C)})}function ye(O,C){!C.prefinished&&!C.finalCalled&&(typeof O._final=="function"&&!C.destroyed?(C.pendingcb++,C.finalCalled=!0,process.nextTick(fe,O,C)):(C.prefinished=!0,O.emit("prefinish")))}function it(O,C){var H=We(C);if(H&&(ye(O,C),C.pendingcb===0&&(C.finished=!0,O.emit("finish"),C.autoDestroy))){var K=O._readableState;(!K||K.autoDestroy&&K.endEmitted)&&O.destroy()}return H}function Qt(O,C,H){C.ending=!0,it(O,C),H&&(C.finished?process.nextTick(H):O.once("finish",H)),C.ended=!0,O.writable=!1}function Rt(O,C,H){var K=O.entry;for(O.entry=null;K;){var Z=K.callback;C.pendingcb--,Z(H),K=K.next}C.corkedRequestsFree.next=O}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(C){this._writableState&&(this._writableState.destroyed=C)}}),M.prototype.destroy=c.destroy,M.prototype._undestroy=c.undestroy,M.prototype._destroy=function(O,C){C(O)},$o}var Mo,Cu;function gn(){if(Cu)return Mo;Cu=1;var e=Object.keys||function(f){var l=[];for(var h in f)l.push(h);return l};Mo=o;var t=vl(),r=wl();He(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(f){if(!(this instanceof o))return new o(f);t.call(this,f),r.call(this,f),this.allowHalfOpen=!0,f&&(f.readable===!1&&(this.readable=!1),f.writable===!1&&(this.writable=!1),f.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(f){f.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(l){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=l,this._writableState.destroyed=l)}}),Mo}var Es={},Ec=tt.Buffer,Ou=Ec.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 N1(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 F1(e){var t=N1(e);if(typeof t!="string"&&(Ec.isEncoding===Ou||!Ou(e)))throw new Error("Unknown encoding: "+e);return t||e}Es.StringDecoder=Fi;function Fi(e){this.encoding=F1(e);var t;switch(this.encoding){case"utf16le":this.text=G1,this.end=z1,t=4;break;case"utf8":this.fillLast=H1,t=4;break;case"base64":this.text=q1,this.end=V1,t=3;break;default:this.write=W1,this.end=K1;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Ec.allocUnsafe(t)}Fi.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||""};Fi.prototype.end=j1;Fi.prototype.text=D1;Fi.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 Ho(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function $1(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Ho(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Ho(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Ho(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function M1(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 H1(e){var t=this.lastTotal-this.lastNeed,r=M1(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 D1(e,t){var r=$1(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 j1(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function G1(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 z1(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 q1(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 V1(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function W1(e){return e.toString(this.encoding)}function K1(e){return e&&e.length?this.write(e):""}var Ru=jr.codes.ERR_STREAM_PREMATURE_CLOSE;function Y1(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 X1(){}function J1(e){return e.setHeader&&typeof e.abort=="function"}function _l(e,t,r){if(typeof t=="function")return _l(e,null,t);t||(t={}),r=Y1(r||X1);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,f=function(){n=!1,c=!0,i||r.call(e)},l=function(g){r.call(e,g)},h=function(){var g;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(g=new Ru),r.call(e,g);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(g=new Ru),r.call(e,g)},m=function(){e.req.on("finish",a)};return J1(e)?(e.on("complete",a),e.on("abort",h),e.req?m():e.on("request",m)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",f),e.on("finish",a),t.error!==!1&&e.on("error",l),e.on("close",h),function(){e.removeListener("complete",a),e.removeListener("abort",h),e.removeListener("request",m),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",f),e.removeListener("error",l),e.removeListener("close",h)}}var xc=_l,Do,Uu;function Q1(){if(Uu)return Do;Uu=1;var e;function t(A,E,T){return E=r(E),E in A?Object.defineProperty(A,E,{value:T,enumerable:!0,configurable:!0,writable:!0}):A[E]=T,A}function r(A){var E=n(A,"string");return typeof E=="symbol"?E:String(E)}function n(A,E){if(typeof A!="object"||A===null)return A;var T=A[Symbol.toPrimitive];if(T!==void 0){var S=T.call(A,E);if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return(E==="string"?String:Number)(A)}var i=xc,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),f=Symbol("lastPromise"),l=Symbol("handlePromise"),h=Symbol("stream");function m(A,E){return{value:A,done:E}}function p(A){var E=A[s];if(E!==null){var T=A[h].read();T!==null&&(A[f]=null,A[s]=null,A[o]=null,E(m(T,!1)))}}function g(A){process.nextTick(p,A)}function v(A,E){return function(T,S){A.then(function(){if(E[c]){T(m(void 0,!0));return}E[l](T,S)},S)}}var x=Object.getPrototypeOf(function(){}),I=Object.setPrototypeOf((e={get stream(){return this[h]},next:function(){var E=this,T=this[a];if(T!==null)return Promise.reject(T);if(this[c])return Promise.resolve(m(void 0,!0));if(this[h].destroyed)return new Promise(function(B,W){process.nextTick(function(){E[a]?W(E[a]):B(m(void 0,!0))})});var S=this[f],N;if(S)N=new Promise(v(S,this));else{var M=this[h].read();if(M!==null)return Promise.resolve(m(M,!1));N=new Promise(this[l])}return this[f]=N,N}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var E=this;return new Promise(function(T,S){E[h].destroy(null,function(N){if(N){S(N);return}T(m(void 0,!0))})})}),e),x),k=function(E){var T,S=Object.create(I,(T={},t(T,h,{value:E,writable:!0}),t(T,s,{value:null,writable:!0}),t(T,o,{value:null,writable:!0}),t(T,a,{value:null,writable:!0}),t(T,c,{value:E._readableState.endEmitted,writable:!0}),t(T,l,{value:function(M,B){var W=S[h].read();W?(S[f]=null,S[s]=null,S[o]=null,M(m(W,!1))):(S[s]=M,S[o]=B)},writable:!0}),T));return S[f]=null,i(E,function(N){if(N&&N.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=S[o];M!==null&&(S[f]=null,S[s]=null,S[o]=null,M(N)),S[a]=N;return}var B=S[s];B!==null&&(S[f]=null,S[s]=null,S[o]=null,B(m(void 0,!0))),S[c]=!0}),E.on("readable",g.bind(null,S)),S};return Do=k,Do}var jo,Lu;function Z1(){return Lu||(Lu=1,jo=function(){throw new Error("Readable.from is not available in the browser")}),jo}var Go,Nu;function vl(){if(Nu)return Go;Nu=1,Go=B;var e;B.ReadableState=M,pl.EventEmitter;var t=function(_,F){return _.listeners(F).length},r=yl,n=Jt.Buffer,i=(typeof yr<"u"?yr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(w){return n.from(w)}function o(w){return n.isBuffer(w)||w instanceof i}var a=vc,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var f=x1(),l=ml,h=gl,m=h.getHighWaterMark,p=jr.codes,g=p.ERR_INVALID_ARG_TYPE,v=p.ERR_STREAM_PUSH_AFTER_EOF,x=p.ERR_METHOD_NOT_IMPLEMENTED,I=p.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,k,A,E;He(B,r);var T=l.errorOrDestroy,S=["error","close","destroy","pause","resume"];function N(w,_,F){if(typeof w.prependListener=="function")return w.prependListener(_,F);!w._events||!w._events[_]?w.on(_,F):Array.isArray(w._events[_])?w._events[_].unshift(F):w._events[_]=[F,w._events[_]]}function M(w,_,F){e=e||gn(),w=w||{},typeof F!="boolean"&&(F=_ instanceof e),this.objectMode=!!w.objectMode,F&&(this.objectMode=this.objectMode||!!w.readableObjectMode),this.highWaterMark=m(this,w,"readableHighWaterMark",F),this.buffer=new f,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=w.emitClose!==!1,this.autoDestroy=!!w.autoDestroy,this.destroyed=!1,this.defaultEncoding=w.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,w.encoding&&(k||(k=Es.StringDecoder),this.decoder=new k(w.encoding),this.encoding=w.encoding)}function B(w){if(e=e||gn(),!(this instanceof B))return new B(w);var _=this instanceof e;this._readableState=new M(w,this,_),this.readable=!0,w&&(typeof w.read=="function"&&(this._read=w.read),typeof w.destroy=="function"&&(this._destroy=w.destroy)),r.call(this)}Object.defineProperty(B.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(_){this._readableState&&(this._readableState.destroyed=_)}}),B.prototype.destroy=l.destroy,B.prototype._undestroy=l.undestroy,B.prototype._destroy=function(w,_){_(w)},B.prototype.push=function(w,_){var F=this._readableState,q;return F.objectMode?q=!0:typeof w=="string"&&(_=_||F.defaultEncoding,_!==F.encoding&&(w=n.from(w,_),_=""),q=!0),W(this,w,_,!1,q)},B.prototype.unshift=function(w){return W(this,w,null,!0,!1)};function W(w,_,F,q,ve){c("readableAddChunk",_);var ee=w._readableState;if(_===null)ee.reading=!1,ne(w,ee);else{var ae;if(ve||(ae=D(ee,_)),ae)T(w,ae);else if(ee.objectMode||_&&_.length>0)if(typeof _!="string"&&!ee.objectMode&&Object.getPrototypeOf(_)!==n.prototype&&(_=s(_)),q)ee.endEmitted?T(w,new I):U(w,ee,_,!0);else if(ee.ended)T(w,new v);else{if(ee.destroyed)return!1;ee.reading=!1,ee.decoder&&!F?(_=ee.decoder.write(_),ee.objectMode||_.length!==0?U(w,ee,_,!1):Te(w,ee)):U(w,ee,_,!1)}else q||(ee.reading=!1,Te(w,ee))}return!ee.ended&&(ee.length<ee.highWaterMark||ee.length===0)}function U(w,_,F,q){_.flowing&&_.length===0&&!_.sync?(_.awaitDrain=0,w.emit("data",F)):(_.length+=_.objectMode?1:F.length,q?_.buffer.unshift(F):_.buffer.push(F),_.needReadable&&he(w)),Te(w,_)}function D(w,_){var F;return!o(_)&&typeof _!="string"&&_!==void 0&&!w.objectMode&&(F=new g("chunk",["string","Buffer","Uint8Array"],_)),F}B.prototype.isPaused=function(){return this._readableState.flowing===!1},B.prototype.setEncoding=function(w){k||(k=Es.StringDecoder);var _=new k(w);this._readableState.decoder=_,this._readableState.encoding=this._readableState.decoder.encoding;for(var F=this._readableState.buffer.head,q="";F!==null;)q+=_.write(F.data),F=F.next;return this._readableState.buffer.clear(),q!==""&&this._readableState.buffer.push(q),this._readableState.length=q.length,this};var j=1073741824;function V(w){return w>=j?w=j:(w--,w|=w>>>1,w|=w>>>2,w|=w>>>4,w|=w>>>8,w|=w>>>16,w++),w}function X(w,_){return w<=0||_.length===0&&_.ended?0:_.objectMode?1:w!==w?_.flowing&&_.length?_.buffer.head.data.length:_.length:(w>_.highWaterMark&&(_.highWaterMark=V(w)),w<=_.length?w:_.ended?_.length:(_.needReadable=!0,0))}B.prototype.read=function(w){c("read",w),w=parseInt(w,10);var _=this._readableState,F=w;if(w!==0&&(_.emittedReadable=!1),w===0&&_.needReadable&&((_.highWaterMark!==0?_.length>=_.highWaterMark:_.length>0)||_.ended))return c("read: emitReadable",_.length,_.ended),_.length===0&&_.ended?H(this):he(this),null;if(w=X(w,_),w===0&&_.ended)return _.length===0&&H(this),null;var q=_.needReadable;c("need readable",q),(_.length===0||_.length-w<_.highWaterMark)&&(q=!0,c("length less than watermark",q)),_.ended||_.reading?(q=!1,c("reading or ended",q)):q&&(c("do read"),_.reading=!0,_.sync=!0,_.length===0&&(_.needReadable=!0),this._read(_.highWaterMark),_.sync=!1,_.reading||(w=X(F,_)));var ve;return w>0?ve=C(w,_):ve=null,ve===null?(_.needReadable=_.length<=_.highWaterMark,w=0):(_.length-=w,_.awaitDrain=0),_.length===0&&(_.ended||(_.needReadable=!0),F!==w&&_.ended&&H(this)),ve!==null&&this.emit("data",ve),ve};function ne(w,_){if(c("onEofChunk"),!_.ended){if(_.decoder){var F=_.decoder.end();F&&F.length&&(_.buffer.push(F),_.length+=_.objectMode?1:F.length)}_.ended=!0,_.sync?he(w):(_.needReadable=!1,_.emittedReadable||(_.emittedReadable=!0,_e(w)))}}function he(w){var _=w._readableState;c("emitReadable",_.needReadable,_.emittedReadable),_.needReadable=!1,_.emittedReadable||(c("emitReadable",_.flowing),_.emittedReadable=!0,process.nextTick(_e,w))}function _e(w){var _=w._readableState;c("emitReadable_",_.destroyed,_.length,_.ended),!_.destroyed&&(_.length||_.ended)&&(w.emit("readable"),_.emittedReadable=!1),_.needReadable=!_.flowing&&!_.ended&&_.length<=_.highWaterMark,O(w)}function Te(w,_){_.readingMore||(_.readingMore=!0,process.nextTick(We,w,_))}function We(w,_){for(;!_.reading&&!_.ended&&(_.length<_.highWaterMark||_.flowing&&_.length===0);){var F=_.length;if(c("maybeReadMore read 0"),w.read(0),F===_.length)break}_.readingMore=!1}B.prototype._read=function(w){T(this,new x("_read()"))},B.prototype.pipe=function(w,_){var F=this,q=this._readableState;switch(q.pipesCount){case 0:q.pipes=w;break;case 1:q.pipes=[q.pipes,w];break;default:q.pipes.push(w);break}q.pipesCount+=1,c("pipe count=%d opts=%j",q.pipesCount,_);var ve=(!_||_.end!==!1)&&w!==process.stdout&&w!==process.stderr,ee=ve?Zt:xr;q.endEmitted?process.nextTick(ee):F.once("end",ee),w.on("unpipe",ae);function ae(y,u){c("onunpipe"),y===F&&u&&u.hasUnpiped===!1&&(u.hasUnpiped=!0,qr())}function Zt(){c("onend"),w.end()}var zr=fe(F);w.on("drain",zr);var Sn=!1;function qr(){c("cleanup"),w.removeListener("close",Pn),w.removeListener("finish",ut),w.removeListener("drain",zr),w.removeListener("error",Er),w.removeListener("unpipe",ae),F.removeListener("end",Zt),F.removeListener("end",xr),F.removeListener("data",st),Sn=!0,q.awaitDrain&&(!w._writableState||w._writableState.needDrain)&&zr()}F.on("data",st);function st(y){c("ondata");var u=w.write(y);c("dest.write",u),u===!1&&((q.pipesCount===1&&q.pipes===w||q.pipesCount>1&&Z(q.pipes,w)!==-1)&&!Sn&&(c("false write response, pause",q.awaitDrain),q.awaitDrain++),F.pause())}function Er(y){c("onerror",y),xr(),w.removeListener("error",Er),t(w,"error")===0&&T(w,y)}N(w,"error",Er);function Pn(){w.removeListener("finish",ut),xr()}w.once("close",Pn);function ut(){c("onfinish"),w.removeListener("close",Pn),xr()}w.once("finish",ut);function xr(){c("unpipe"),F.unpipe(w)}return w.emit("pipe",F),q.flowing||(c("pipe resume"),F.resume()),w};function fe(w){return function(){var F=w._readableState;c("pipeOnDrain",F.awaitDrain),F.awaitDrain&&F.awaitDrain--,F.awaitDrain===0&&t(w,"data")&&(F.flowing=!0,O(w))}}B.prototype.unpipe=function(w){var _=this._readableState,F={hasUnpiped:!1};if(_.pipesCount===0)return this;if(_.pipesCount===1)return w&&w!==_.pipes?this:(w||(w=_.pipes),_.pipes=null,_.pipesCount=0,_.flowing=!1,w&&w.emit("unpipe",this,F),this);if(!w){var q=_.pipes,ve=_.pipesCount;_.pipes=null,_.pipesCount=0,_.flowing=!1;for(var ee=0;ee<ve;ee++)q[ee].emit("unpipe",this,{hasUnpiped:!1});return this}var ae=Z(_.pipes,w);return ae===-1?this:(_.pipes.splice(ae,1),_.pipesCount-=1,_.pipesCount===1&&(_.pipes=_.pipes[0]),w.emit("unpipe",this,F),this)},B.prototype.on=function(w,_){var F=r.prototype.on.call(this,w,_),q=this._readableState;return w==="data"?(q.readableListening=this.listenerCount("readable")>0,q.flowing!==!1&&this.resume()):w==="readable"&&!q.endEmitted&&!q.readableListening&&(q.readableListening=q.needReadable=!0,q.flowing=!1,q.emittedReadable=!1,c("on readable",q.length,q.reading),q.length?he(this):q.reading||process.nextTick(it,this)),F},B.prototype.addListener=B.prototype.on,B.prototype.removeListener=function(w,_){var F=r.prototype.removeListener.call(this,w,_);return w==="readable"&&process.nextTick(ye,this),F},B.prototype.removeAllListeners=function(w){var _=r.prototype.removeAllListeners.apply(this,arguments);return(w==="readable"||w===void 0)&&process.nextTick(ye,this),_};function ye(w){var _=w._readableState;_.readableListening=w.listenerCount("readable")>0,_.resumeScheduled&&!_.paused?_.flowing=!0:w.listenerCount("data")>0&&w.resume()}function it(w){c("readable nexttick read 0"),w.read(0)}B.prototype.resume=function(){var w=this._readableState;return w.flowing||(c("resume"),w.flowing=!w.readableListening,Qt(this,w)),w.paused=!1,this};function Qt(w,_){_.resumeScheduled||(_.resumeScheduled=!0,process.nextTick(Rt,w,_))}function Rt(w,_){c("resume",_.reading),_.reading||w.read(0),_.resumeScheduled=!1,w.emit("resume"),O(w),_.flowing&&!_.reading&&w.read(0)}B.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 O(w){var _=w._readableState;for(c("flow",_.flowing);_.flowing&&w.read()!==null;);}B.prototype.wrap=function(w){var _=this,F=this._readableState,q=!1;w.on("end",function(){if(c("wrapped end"),F.decoder&&!F.ended){var ae=F.decoder.end();ae&&ae.length&&_.push(ae)}_.push(null)}),w.on("data",function(ae){if(c("wrapped data"),F.decoder&&(ae=F.decoder.write(ae)),!(F.objectMode&&ae==null)&&!(!F.objectMode&&(!ae||!ae.length))){var Zt=_.push(ae);Zt||(q=!0,w.pause())}});for(var ve in w)this[ve]===void 0&&typeof w[ve]=="function"&&(this[ve]=function(Zt){return function(){return w[Zt].apply(w,arguments)}}(ve));for(var ee=0;ee<S.length;ee++)w.on(S[ee],this.emit.bind(this,S[ee]));return this._read=function(ae){c("wrapped _read",ae),q&&(q=!1,w.resume())},this},typeof Symbol=="function"&&(B.prototype[Symbol.asyncIterator]=function(){return A===void 0&&(A=Q1()),A(this)}),Object.defineProperty(B.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(B.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(B.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(_){this._readableState&&(this._readableState.flowing=_)}}),B._fromList=C,Object.defineProperty(B.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function C(w,_){if(_.length===0)return null;var F;return _.objectMode?F=_.buffer.shift():!w||w>=_.length?(_.decoder?F=_.buffer.join(""):_.buffer.length===1?F=_.buffer.first():F=_.buffer.concat(_.length),_.buffer.clear()):F=_.buffer.consume(w,_.decoder),F}function H(w){var _=w._readableState;c("endReadable",_.endEmitted),_.endEmitted||(_.ended=!0,process.nextTick(K,_,w))}function K(w,_){if(c("endReadableNT",w.endEmitted,w.length),!w.endEmitted&&w.length===0&&(w.endEmitted=!0,_.readable=!1,_.emit("end"),w.autoDestroy)){var F=_._writableState;(!F||F.autoDestroy&&F.finished)&&_.destroy()}}typeof Symbol=="function"&&(B.from=function(w,_){return E===void 0&&(E=Z1()),E(B,w,_)});function Z(w,_){for(var F=0,q=w.length;F<q;F++)if(w[F]===_)return F;return-1}return Go}var El=Yt,Xs=jr.codes,ew=Xs.ERR_METHOD_NOT_IMPLEMENTED,tw=Xs.ERR_MULTIPLE_CALLBACK,rw=Xs.ERR_TRANSFORM_ALREADY_TRANSFORMING,nw=Xs.ERR_TRANSFORM_WITH_LENGTH_0,Js=gn();He(Yt,Js);function iw(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new tw);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 Yt(e){if(!(this instanceof Yt))return new Yt(e);Js.call(this,e),this._transformState={afterTransform:iw.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",sw)}function sw(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Fu(e,t,r)}):Fu(this,null,null)}Yt.prototype.push=function(e,t){return this._transformState.needTransform=!1,Js.prototype.push.call(this,e,t)};Yt.prototype._transform=function(e,t,r){r(new ew("_transform()"))};Yt.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)}};Yt.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};Yt.prototype._destroy=function(e,t){Js.prototype._destroy.call(this,e,function(r){t(r)})};function Fu(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new nw;if(e._transformState.transforming)throw new rw;return e.push(null)}var ow=Ai,xl=El;He(Ai,xl);function Ai(e){if(!(this instanceof Ai))return new Ai(e);xl.call(this,e)}Ai.prototype._transform=function(e,t,r){r(null,e)};var zo;function aw(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var Al=jr.codes,cw=Al.ERR_MISSING_ARGS,uw=Al.ERR_STREAM_DESTROYED;function $u(e){if(e)throw e}function fw(e){return e.setHeader&&typeof e.abort=="function"}function dw(e,t,r,n){n=aw(n);var i=!1;e.on("close",function(){i=!0}),zo===void 0&&(zo=xc),zo(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,fw(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new uw("pipe"))}}}function Mu(e){e()}function lw(e,t){return e.pipe(t)}function hw(e){return!e.length||typeof e[e.length-1]!="function"?$u:e.pop()}function pw(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=hw(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new cw("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,f=a>0;return dw(o,c,f,function(l){i||(i=l),l&&s.forEach(Mu),!c&&(s.forEach(Mu),n(i))})});return t.reduce(lw)}var yw=pw;(function(e,t){t=e.exports=vl(),t.Stream=t,t.Readable=t,t.Writable=wl(),t.Duplex=gn(),t.Transform=El,t.PassThrough=ow,t.finished=xc,t.pipeline=yw})(va,va.exports);var Sl=va.exports,xs=tt.Buffer,Pl=Sl.Transform,mw=He;function bw(e,t){if(!xs.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function _r(e){Pl.call(this),this._block=xs.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}mw(_r,Pl);_r.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};_r.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};_r.prototype.update=function(e,t){if(bw(e,"Data"),this._finalized)throw new Error("Digest already called");xs.isBuffer(e)||(e=xs.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};_r.prototype._update=function(){throw new Error("_update is not implemented")};_r.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};_r.prototype._digest=function(){throw new Error("_digest is not implemented")};var gw=_r,ww=He,Tl=gw,_w=tt.Buffer,vw=new Array(16);function Qs(){Tl.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}ww(Qs,Tl);Qs.prototype._update=function(){for(var e=vw,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=De(r,n,i,s,e[0],3614090360,7),s=De(s,r,n,i,e[1],3905402710,12),i=De(i,s,r,n,e[2],606105819,17),n=De(n,i,s,r,e[3],3250441966,22),r=De(r,n,i,s,e[4],4118548399,7),s=De(s,r,n,i,e[5],1200080426,12),i=De(i,s,r,n,e[6],2821735955,17),n=De(n,i,s,r,e[7],4249261313,22),r=De(r,n,i,s,e[8],1770035416,7),s=De(s,r,n,i,e[9],2336552879,12),i=De(i,s,r,n,e[10],4294925233,17),n=De(n,i,s,r,e[11],2304563134,22),r=De(r,n,i,s,e[12],1804603682,7),s=De(s,r,n,i,e[13],4254626195,12),i=De(i,s,r,n,e[14],2792965006,17),n=De(n,i,s,r,e[15],1236535329,22),r=je(r,n,i,s,e[1],4129170786,5),s=je(s,r,n,i,e[6],3225465664,9),i=je(i,s,r,n,e[11],643717713,14),n=je(n,i,s,r,e[0],3921069994,20),r=je(r,n,i,s,e[5],3593408605,5),s=je(s,r,n,i,e[10],38016083,9),i=je(i,s,r,n,e[15],3634488961,14),n=je(n,i,s,r,e[4],3889429448,20),r=je(r,n,i,s,e[9],568446438,5),s=je(s,r,n,i,e[14],3275163606,9),i=je(i,s,r,n,e[3],4107603335,14),n=je(n,i,s,r,e[8],1163531501,20),r=je(r,n,i,s,e[13],2850285829,5),s=je(s,r,n,i,e[2],4243563512,9),i=je(i,s,r,n,e[7],1735328473,14),n=je(n,i,s,r,e[12],2368359562,20),r=Ge(r,n,i,s,e[5],4294588738,4),s=Ge(s,r,n,i,e[8],2272392833,11),i=Ge(i,s,r,n,e[11],1839030562,16),n=Ge(n,i,s,r,e[14],4259657740,23),r=Ge(r,n,i,s,e[1],2763975236,4),s=Ge(s,r,n,i,e[4],1272893353,11),i=Ge(i,s,r,n,e[7],4139469664,16),n=Ge(n,i,s,r,e[10],3200236656,23),r=Ge(r,n,i,s,e[13],681279174,4),s=Ge(s,r,n,i,e[0],3936430074,11),i=Ge(i,s,r,n,e[3],3572445317,16),n=Ge(n,i,s,r,e[6],76029189,23),r=Ge(r,n,i,s,e[9],3654602809,4),s=Ge(s,r,n,i,e[12],3873151461,11),i=Ge(i,s,r,n,e[15],530742520,16),n=Ge(n,i,s,r,e[2],3299628645,23),r=ze(r,n,i,s,e[0],4096336452,6),s=ze(s,r,n,i,e[7],1126891415,10),i=ze(i,s,r,n,e[14],2878612391,15),n=ze(n,i,s,r,e[5],4237533241,21),r=ze(r,n,i,s,e[12],1700485571,6),s=ze(s,r,n,i,e[3],2399980690,10),i=ze(i,s,r,n,e[10],4293915773,15),n=ze(n,i,s,r,e[1],2240044497,21),r=ze(r,n,i,s,e[8],1873313359,6),s=ze(s,r,n,i,e[15],4264355552,10),i=ze(i,s,r,n,e[6],2734768916,15),n=ze(n,i,s,r,e[13],1309151649,21),r=ze(r,n,i,s,e[4],4149444226,6),s=ze(s,r,n,i,e[11],3174756917,10),i=ze(i,s,r,n,e[2],718787259,15),n=ze(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};Qs.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=_w.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 Zs(e,t){return e<<t|e>>>32-t}function De(e,t,r,n,i,s,o){return Zs(e+(t&r|~t&n)+i+s|0,o)+t|0}function je(e,t,r,n,i,s,o){return Zs(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ge(e,t,r,n,i,s,o){return Zs(e+(t^r^n)+i+s|0,o)+t|0}function ze(e,t,r,n,i,s,o){return Zs(e+(r^(t|~n))+i+s|0,o)+t|0}var Ew=Qs,As=tt.Buffer,kl=Sl.Transform,xw=He;function Aw(e,t){if(!As.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function vr(e){kl.call(this),this._block=As.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}xw(vr,kl);vr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};vr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};vr.prototype.update=function(e,t){if(Aw(e,"Data"),this._finalized)throw new Error("Digest already called");As.isBuffer(e)||(e=As.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};vr.prototype._update=function(){throw new Error("_update is not implemented")};vr.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};vr.prototype._digest=function(){throw new Error("_digest is not implemented")};var Sw=vr,qo=Jt.Buffer,Pw=He,Il=Sw,Tw=new Array(16),Ln=[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],Nn=[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],Fn=[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],$n=[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],Mn=[0,1518500249,1859775393,2400959708,2840853838],Hn=[1352829926,1548603684,1836072691,2053994217,0];function eo(){Il.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}Pw(eo,Il);eo.prototype._update=function(){for(var e=Tw,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,f=this._c|0,l=this._d|0,h=this._e|0,m=0;m<80;m+=1){var p,g;m<16?(p=Hu(r,n,i,s,o,e[Ln[m]],Mn[0],Fn[m]),g=zu(a,c,f,l,h,e[Nn[m]],Hn[0],$n[m])):m<32?(p=Du(r,n,i,s,o,e[Ln[m]],Mn[1],Fn[m]),g=Gu(a,c,f,l,h,e[Nn[m]],Hn[1],$n[m])):m<48?(p=ju(r,n,i,s,o,e[Ln[m]],Mn[2],Fn[m]),g=ju(a,c,f,l,h,e[Nn[m]],Hn[2],$n[m])):m<64?(p=Gu(r,n,i,s,o,e[Ln[m]],Mn[3],Fn[m]),g=Du(a,c,f,l,h,e[Nn[m]],Hn[3],$n[m])):(p=zu(r,n,i,s,o,e[Ln[m]],Mn[4],Fn[m]),g=Hu(a,c,f,l,h,e[Nn[m]],Hn[4],$n[m])),r=o,o=s,s=$r(i,10),i=n,n=p,a=h,h=l,l=$r(f,10),f=c,c=g}var v=this._b+i+l|0;this._b=this._c+s+h|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+f|0,this._a=v};eo.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=qo.alloc?qo.alloc(20):new qo(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 $r(e,t){return e<<t|e>>>32-t}function Hu(e,t,r,n,i,s,o,a){return $r(e+(t^r^n)+s+o|0,a)+i|0}function Du(e,t,r,n,i,s,o,a){return $r(e+(t&r|~t&n)+s+o|0,a)+i|0}function ju(e,t,r,n,i,s,o,a){return $r(e+((t|~r)^n)+s+o|0,a)+i|0}function Gu(e,t,r,n,i,s,o,a){return $r(e+(t&n|r&~n)+s+o|0,a)+i|0}function zu(e,t,r,n,i,s,o,a){return $r(e+(t^(r|~n))+s+o|0,a)+i|0}var kw=eo,Bl={exports:{}},Cl=tt.Buffer;function to(e,t){this._block=Cl.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}to.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Cl.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),f=0;f<c;f++)r[a+f]=e[o+f];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};to.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};to.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var An=to,Iw=He,Ol=An,Bw=tt.Buffer,Cw=[1518500249,1859775393,-1894007588,-899497514],Ow=new Array(80);function $i(){this.init(),this._w=Ow,Ol.call(this,64,56)}Iw($i,Ol);$i.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Rw(e){return e<<5|e>>>27}function Uw(e){return e<<30|e>>>2}function Lw(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}$i.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 f=~~(c/20),l=Rw(r)+Lw(f,n,i,s)+o+t[c]+Cw[f]|0;o=s,s=i,i=Uw(n),n=r,r=l}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};$i.prototype._hash=function(){var e=Bw.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 Nw=$i,Fw=He,Rl=An,$w=tt.Buffer,Mw=[1518500249,1859775393,-1894007588,-899497514],Hw=new Array(80);function Mi(){this.init(),this._w=Hw,Rl.call(this,64,56)}Fw(Mi,Rl);Mi.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Dw(e){return e<<1|e>>>31}function jw(e){return e<<5|e>>>27}function Gw(e){return e<<30|e>>>2}function zw(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Mi.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]=Dw(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var f=~~(c/20),l=jw(r)+zw(f,n,i,s)+o+t[c]+Mw[f]|0;o=s,s=i,i=Gw(n),n=r,r=l}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};Mi.prototype._hash=function(){var e=$w.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 qw=Mi,Vw=He,Ul=An,Ww=tt.Buffer,Kw=[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],Yw=new Array(64);function Hi(){this.init(),this._w=Yw,Ul.call(this,64,56)}Vw(Hi,Ul);Hi.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 Xw(e,t,r){return r^e&(t^r)}function Jw(e,t,r){return e&t|r&(e|t)}function Qw(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function Zw(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function e2(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function t2(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}Hi.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,f=this._h|0,l=0;l<16;++l)t[l]=e.readInt32BE(l*4);for(;l<64;++l)t[l]=t2(t[l-2])+t[l-7]+e2(t[l-15])+t[l-16]|0;for(var h=0;h<64;++h){var m=f+Zw(o)+Xw(o,a,c)+Kw[h]+t[h]|0,p=Qw(r)+Jw(r,n,i)|0;f=c,c=a,a=o,o=s+m|0,s=i,i=n,n=r,r=m+p|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=f+this._h|0};Hi.prototype._hash=function(){var e=Ww.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 Ll=Hi,r2=He,n2=Ll,i2=An,s2=tt.Buffer,o2=new Array(64);function ro(){this.init(),this._w=o2,i2.call(this,64,56)}r2(ro,n2);ro.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};ro.prototype._hash=function(){var e=s2.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 a2=ro,c2=He,Nl=An,u2=tt.Buffer,qu=[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],f2=new Array(160);function Di(){this.init(),this._w=f2,Nl.call(this,128,112)}c2(Di,Nl);Di.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 Vu(e,t,r){return r^e&(t^r)}function Wu(e,t,r){return e&t|r&(e|t)}function Ku(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function Yu(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function d2(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function l2(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function h2(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function p2(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ue(e,t){return e>>>0<t>>>0?1:0}Di.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,f=this._hh|0,l=this._al|0,h=this._bl|0,m=this._cl|0,p=this._dl|0,g=this._el|0,v=this._fl|0,x=this._gl|0,I=this._hl|0,k=0;k<32;k+=2)t[k]=e.readInt32BE(k*4),t[k+1]=e.readInt32BE(k*4+4);for(;k<160;k+=2){var A=t[k-30],E=t[k-15*2+1],T=d2(A,E),S=l2(E,A);A=t[k-2*2],E=t[k-2*2+1];var N=h2(A,E),M=p2(E,A),B=t[k-7*2],W=t[k-7*2+1],U=t[k-16*2],D=t[k-16*2+1],j=S+W|0,V=T+B+Ue(j,S)|0;j=j+M|0,V=V+N+Ue(j,M)|0,j=j+D|0,V=V+U+Ue(j,D)|0,t[k]=V,t[k+1]=j}for(var X=0;X<160;X+=2){V=t[X],j=t[X+1];var ne=Wu(r,n,i),he=Wu(l,h,m),_e=Ku(r,l),Te=Ku(l,r),We=Yu(o,g),fe=Yu(g,o),ye=qu[X],it=qu[X+1],Qt=Vu(o,a,c),Rt=Vu(g,v,x),O=I+fe|0,C=f+We+Ue(O,I)|0;O=O+Rt|0,C=C+Qt+Ue(O,Rt)|0,O=O+it|0,C=C+ye+Ue(O,it)|0,O=O+j|0,C=C+V+Ue(O,j)|0;var H=Te+he|0,K=_e+ne+Ue(H,Te)|0;f=c,I=x,c=a,x=v,a=o,v=g,g=p+O|0,o=s+C+Ue(g,p)|0,s=i,p=m,i=n,m=h,n=r,h=l,l=O+H|0,r=C+K+Ue(l,O)|0}this._al=this._al+l|0,this._bl=this._bl+h|0,this._cl=this._cl+m|0,this._dl=this._dl+p|0,this._el=this._el+g|0,this._fl=this._fl+v|0,this._gl=this._gl+x|0,this._hl=this._hl+I|0,this._ah=this._ah+r+Ue(this._al,l)|0,this._bh=this._bh+n+Ue(this._bl,h)|0,this._ch=this._ch+i+Ue(this._cl,m)|0,this._dh=this._dh+s+Ue(this._dl,p)|0,this._eh=this._eh+o+Ue(this._el,g)|0,this._fh=this._fh+a+Ue(this._fl,v)|0,this._gh=this._gh+c+Ue(this._gl,x)|0,this._hh=this._hh+f+Ue(this._hl,I)|0};Di.prototype._hash=function(){var e=u2.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 Fl=Di,y2=He,m2=Fl,b2=An,g2=tt.Buffer,w2=new Array(160);function no(){this.init(),this._w=w2,b2.call(this,128,112)}y2(no,m2);no.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};no.prototype._hash=function(){var e=g2.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 _2=no,Gr=Bl.exports=function(t){t=t.toLowerCase();var r=Gr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};Gr.sha=Nw;Gr.sha1=qw;Gr.sha224=a2;Gr.sha256=Ll;Gr.sha384=_2;Gr.sha512=Fl;var v2=Bl.exports,Pt=tt.Buffer,$l=vc.Transform,E2=Es.StringDecoder,x2=He;function bt(e){$l.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}x2(bt,$l);var A2=typeof Uint8Array<"u",S2=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(Pt.prototype instanceof Uint8Array||Pt.TYPED_ARRAY_SUPPORT);function P2(e,t){if(e instanceof Pt)return e;if(typeof e=="string")return Pt.from(e,t);if(S2&&ArrayBuffer.isView(e)){if(e.byteLength===0)return Pt.alloc(0);var r=Pt.from(e.buffer,e.byteOffset,e.byteLength);if(r.byteLength===e.byteLength)return r}if(A2&&e instanceof Uint8Array||Pt.isBuffer(e)&&e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return Pt.from(e);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}bt.prototype.update=function(e,t,r){var n=P2(e,t),i=this._update(n);return this.hashMode?this:(r&&(i=this._toString(i,r)),i)};bt.prototype.setAutoPadding=function(){};bt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};bt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};bt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};bt.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)}};bt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};bt.prototype._finalOrDigest=function(e){var t=this.__final()||Pt.alloc(0);return e&&(t=this._toString(t,e,!0)),t};bt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new E2(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 T2=bt,k2=He,I2=Ew,B2=kw,C2=v2,Ml=T2;function io(e){Ml.call(this,"digest"),this._hash=e}k2(io,Ml);io.prototype._update=function(e){this._hash.update(e)};io.prototype._final=function(){return this._hash.digest()};var O2=function(t){return t=t.toLowerCase(),t==="md5"?new I2:t==="rmd160"||t==="ripemd160"?new B2:new io(C2(t))},rs=tt.Buffer;function R2(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),f=Math.log(256)/Math.log(o);function l(p){if((Array.isArray(p)||p instanceof Uint8Array)&&(p=rs.from(p)),!rs.isBuffer(p))throw new TypeError("Expected Buffer");if(p.length===0)return"";for(var g=0,v=0,x=0,I=p.length;x!==I&&p[x]===0;)x++,g++;for(var k=(I-x)*f+1>>>0,A=new Uint8Array(k);x!==I;){for(var E=p[x],T=0,S=k-1;(E!==0||T<v)&&S!==-1;S--,T++)E+=256*A[S]>>>0,A[S]=E%o>>>0,E=E/o>>>0;if(E!==0)throw new Error("Non-zero carry");v=T,x++}for(var N=k-v;N!==k&&A[N]===0;)N++;for(var M=a.repeat(g);N<k;++N)M+=e.charAt(A[N]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return rs.alloc(0);for(var g=0,v=0,x=0;p[g]===a;)v++,g++;for(var I=(p.length-g)*c+1>>>0,k=new Uint8Array(I);g<p.length;){var A=p.charCodeAt(g);if(A>255)return;var E=t[A];if(E===255)return;for(var T=0,S=I-1;(E!==0||T<x)&&S!==-1;S--,T++)E+=o*k[S]>>>0,k[S]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");x=T,g++}for(var N=I-x;N!==I&&k[N]===0;)N++;var M=rs.allocUnsafe(v+(I-N));M.fill(0,0,v);for(var B=v;N!==I;)M[B++]=k[N++];return M}function m(p){var g=h(p);if(g)return g;throw new Error("Non-base"+o+" character")}return{encode:l,decodeUnsafe:h,decode:m}}var U2=R2,L2=U2,N2="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",F2=L2(N2),Vo=F2,$2=tt.Buffer,M2=function(e){function t(s){var o=e(s);return Vo.encode($2.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=Vo.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Vo.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},Xu=O2,H2=M2;function D2(e){var t=Xu("sha256").update(e).digest();return Xu("sha256").update(t).digest()}var j2=H2(D2),xa=j2;function Hl(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 Aa(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 G2(e,t){return Hl(xa.decode(e),t)}function z2(e,t,r){return typeof e=="number"?xa.encode(Aa(e,t,r)):xa.encode(Aa(e.version,e.privateKey,e.compressed))}var q2={decode:G2,decodeRaw:Hl,encode:z2,encodeRaw:Aa},so={};Object.defineProperty(so,"__esModule",{value:!0});so.testEcc=void 0;const Y=e=>Buffer.from(e,"hex");function V2(e){be(e.isPoint(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(!e.isPoint(Y("030000000000000000000000000000000000000000000000000000000000000005"))),be(e.isPrivate(Y("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(e.isPrivate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),be(!e.isPrivate(Y("0000000000000000000000000000000000000000000000000000000000000000"))),be(!e.isPrivate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),be(!e.isPrivate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),be(Buffer.from(e.privateAdd(Y("0000000000000000000000000000000000000000000000000000000000000001"),Y("0000000000000000000000000000000000000000000000000000000000000000"))).equals(Y("0000000000000000000000000000000000000000000000000000000000000001"))),be(e.privateAdd(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),Y("0000000000000000000000000000000000000000000000000000000000000003"))===null),be(Buffer.from(e.privateAdd(Y("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),Y("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(Y("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),be(Buffer.from(e.privateNegate(Y("0000000000000000000000000000000000000000000000000000000000000001"))).equals(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),be(Buffer.from(e.privateNegate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(Y("0000000000000000000000000000000000000000000000000000000000000003"))),be(Buffer.from(e.privateNegate(Y("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(Y("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),be(Buffer.from(e.pointCompress(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(Buffer.from(e.pointCompress(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),be(Buffer.from(e.pointCompress(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(Buffer.from(e.pointCompress(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),be(Buffer.from(e.pointFromScalar(Y("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(Y("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),be(e.xOnlyPointAddTweak(Y("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(Y("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),Y("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));be(Buffer.from(t.xOnlyPubkey).equals(Y("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(Y("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),Y("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),be(Buffer.from(t.xOnlyPubkey).equals(Y("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),be(Buffer.from(e.sign(Y("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(Y("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),be(e.verify(Y("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),Y("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Y("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&be(Buffer.from(e.signSchnorr(Y("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),Y("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),Y("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(Y("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&be(e.verifySchnorr(Y("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),Y("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),Y("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}so.testEcc=V2;function be(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(mn,"__esModule",{value:!0});mn.ECPairFactory=mn.networks=void 0;const Sa=bn;mn.networks=Sa;const Je=sl,W2=p1,Ju=q2,K2=so,Wo=Je.typeforce.maybe(Je.typeforce.compile({compressed:Je.maybe(Je.Boolean),network:Je.maybe(Je.Network)})),Y2=e=>e.length===32?e:e.slice(1,33);function X2(e){(0,K2.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(Wo,c),new o(a,void 0,c)}function n(a,c){return Je.typeforce(e.isPoint,a),Je.typeforce(Wo,c),new o(void 0,a,c)}function i(a,c){const f=Ju.decode(a),l=f.version;if(Je.Array(c)){if(c=c.filter(h=>l===h.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||Sa.bitcoin,l!==c.wif)throw new Error("Invalid network version");return r(f.privateKey,{compressed:f.compressed,network:c})}function s(a){Je.typeforce(Wo,a),a===void 0&&(a={});const c=a.rng||W2;let f;do f=c(32),Je.typeforce(Je.Buffer256bit,f);while(!e.isPrivate(f));return r(f,a)}class o{constructor(c,f,l){Vr(this,"__D");Vr(this,"__Q");Vr(this,"compressed");Vr(this,"network");Vr(this,"lowR");this.__D=c,this.__Q=f,this.lowR=!1,l===void 0&&(l={}),this.compressed=l.compressed===void 0?!0:l.compressed,this.network=l.network||Sa.bitcoin,f!==void 0&&(this.__Q=Buffer.from(e.pointCompress(f,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 Ju.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,f){if(!this.__D)throw new Error("Missing private key");if(f===void 0&&(f=this.lowR),f===!1)return Buffer.from(e.sign(c,this.__D));{let l=e.sign(c,this.__D);const h=Buffer.alloc(32,0);let m=0;for(;l[0]>127;)m++,h.writeUIntLE(m,0,6),l=e.sign(c,this.__D,h);return Buffer.from(l)}}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,f){return e.verify(c,this.publicKey,f)}verifySchnorr(c,f){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),f)}tweakFromPublicKey(c){const f=Y2(this.publicKey),l=e.xOnlyPointAddTweak(f,c);if(!l||l.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const h=Buffer.from([l.parity===0?2:3]);return n(Buffer.concat([h,l.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const l=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,h=e.privateAdd(l,c);if(!h)throw new Error("Invalid tweaked private key!");return r(Buffer.from(h),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}mn.ECPairFactory=X2;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=mn;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}})})(il);const J2=db(il);class Si extends z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new Si(Pr(t))}static fromWalletClient(t){return new Si(void 0,t)}async initialize(){if(this.digestKey)return ie("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?G(t.error):(this.emit("initialized",!0),ie("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return G("No walletClient found");if(!this.walletClient.account)return G("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.digestKey=Pr(Gn(t)),this.emit("initialized",!0),ie(this.digestKey)}catch(t){return G("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return G("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return G(t.error)}return this.digestKey?ie(this.digestKey):G("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return G(r.error);const n=Gn(z.with0x(r.val)),i=Gn(n);return ie({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const f=await this.getDigestKey();if(f.error)return G(f.error);this.digestKey=f.val}const r=J2(Br),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=Gn(i),o=Buffer.from(Pr(this.digestKey),"hex");if(o.length!==32)return G("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(Pr(s),"hex"));return ie(c.toString("hex"))}}const Qu=[{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"}],Q2={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},Z2={block:Xp({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=za(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?lt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Kp({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?lt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Dy({format(e){return{l1GasPrice:e.l1GasPrice?lt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?lt(e.l1GasUsed):null,l1Fee:e.l1Fee?lt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function e_(e,t){return n_(e)?r_(e):am(e,t)}const t_={transaction:e_};function r_(e){i_(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:c}=e,f=[t,n,a??"0x",o?J(o):"0x",c?J(c):"0x",i?J(i):"0x",s?"0x1":"0x",r??"0x"];return Ct(["0x7e",pr(f)])}function n_(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function i_(e){const{from:t,to:r}=e;if(t&&!Le(t))throw new et({address:t});if(r&&!Le(r))throw new et({address:r})}const Ss={contracts:Q2,formatters:Z2,serializers:t_},s_=Ot({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}}}),o_=Ot({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}),Dn=1,a_=Ot({...Ss,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:{...Ss.contracts,disputeGameFactory:{[Dn]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Dn]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Dn]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Dn]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Dn}),jn=11155111,c_=Ot({...Ss,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:{...Ss.contracts,disputeGameFactory:{[jn]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[jn]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[jn]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[jn]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:jn}),u_=Ot({id:80094,name:"Berachain",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:0},ensRegistry:{address:"0x5b22280886a2f5e09a49bea7e320eab0e5320e28",blockCreated:877007},ensUniversalResolver:{address:"0xddfb18888a9466688235887dec2a10c4f5effee9",blockCreated:877008}},rpcUrls:{default:{http:["https://rpc.berachain.com"]}},blockExplorers:{default:{name:"Berascan",url:"https://berascan.com"}},ensTlds:[".bera"],testnet:!1}),f_=Ot({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269},ensRegistry:{address:"0xB0eef18971290b333450586D33dcA6cE122651D2",blockCreated:7736794},ensUniversalResolver:{address:"0x41692Ef1EA0C79E6b73077E4A67572D2BDbD7057",blockCreated:7736795}},ensTlds:[".bera"],rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),d_=Ot({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"cBTC",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api"}},testnet:!0}),l_=Ot({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),h_=Ot({id:10143,name:"Monad Testnet",nativeCurrency:{name:"Testnet MON Token",symbol:"MON",decimals:18},rpcUrls:{default:{http:["https://testnet-rpc.monad.xyz"]}},blockExplorers:{default:{name:"Monad Testnet explorer",url:"https://testnet.monadexplorer.com"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:251449}},testnet:!0}),p_=Ot({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}),y_={...p_,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Dl={id:998,name:"Hyperliquid EVM Testnet",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://testnet.purrsec.com/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid-testnet.xyz/evm"]}}},jl={id:999,name:"HyperEVM",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://hyperscan.gas.zip/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid.xyz/evm"]}}},Gl={ethereum:l_,arbitrum:s_,ethereum_sepolia:y_,arbitrum_sepolia:o_,ethereum_localnet:ge.EthereumLocalnet,arbitrum_localnet:ge.ArbitrumLocalnet,base_sepolia:c_,base:a_,bera_testnet:f_,citrea_testnet:d_,bera:u_,monad_testnet:h_,hyperliquid_testnet:Dl,hyperliquid:jl},zl=async(e,t)=>{var n;const r=Gl[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return ie({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=tu({account:t.account,chain:r,transport:Qc(t.transport)});return ie({message:"Switched chain",walletClient:i})}catch(i){if(m_(i))try{await t.addChain({chain:r});const s=tu({account:t.account,chain:r,transport:Qc(t.transport)});return ie({message:"Added network",walletClient:s})}catch(s){return G("Failed to add network",s)}else return G("Failed to switch network")}else return G("Chain not supported")},m_=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902,b_=[{inputs:[{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[],name:"NativeHTLC__DuplicateOrder",type:"error"},{inputs:[],name:"NativeHTLC__IncorrectFundsRecieved",type:"error"},{inputs:[],name:"NativeHTLC__IncorrectSecret",type:"error"},{inputs:[],name:"NativeHTLC__InsufficientBalance",type:"error"},{inputs:[],name:"NativeHTLC__InvalidRedeemerSignature",type:"error"},{inputs:[],name:"NativeHTLC__OrderFulfilled",type:"error"},{inputs:[],name:"NativeHTLC__OrderNotExpired",type:"error"},{inputs:[],name:"NativeHTLC__OrderNotInitiated",type:"error"},{inputs:[],name:"NativeHTLC__SameInitiatorAndRedeemer",type:"error"},{inputs:[],name:"NativeHTLC__ZeroAddressInitiator",type:"error"},{inputs:[],name:"NativeHTLC__ZeroAddressRedeemer",type:"error"},{inputs:[],name:"NativeHTLC__ZeroAmount",type:"error"},{inputs:[],name:"NativeHTLC__ZeroTimelock",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 payable",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:"payable",type:"function"},{inputs:[{internalType:"address payable",name:"initiator",type:"address"},{internalType:"address payable",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiateOnBehalf",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"instantRefundDigest",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address payable",name:"initiator",type:"address"},{internalType:"address payable",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:"address",name:"",type:"address"}],stateMutability:"view",type:"function"}];class ql{constructor(t,r,n){this.url=new z.Url("/relayer",t),this.auth=n,this.wallet=r}get htlcActorAddress(){if(!this.wallet.account)throw new Error("No account found");return this.wallet.account.address}async initiate(t){if(!this.wallet.account)return z.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return z.Err("Account address and order initiator mismatch");if(!ge.isEVM(t.source_swap.chain))return z.Err("Source chain is not an EVM chain");const r=await zl(t.source_swap.chain,this.wallet);if(r.error)return z.Err(r.error);if(this.wallet=r.val.walletClient,!this.wallet.account)return z.Err("No account found");const{create_order:n,source_swap:i}=t;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return z.Err("Invalid order");const s=z.with0x(n.secret_hash),o=BigInt(n.timelock),a=z.with0x(i.redeemer),c=BigInt(i.amount),f=await this.getTokenAddress(t.source_swap.asset);return f.ok?ge.isEvmNativeToken(t.source_swap.chain,f.val)?this._initiateOnNativeHTLC(s,o,c,a,t.source_swap.asset):this._initiateOnErc20HTLC(s,o,c,a,t.source_swap.asset,f.val,n.create_id):z.Err(f.error)}async getTokenAddress(t){try{const n=await wo({address:z.with0x(t),abi:Qu,client:this.wallet}).read.token();return z.Ok(n)}catch(r){return z.Err("Failed to get token address",String(r))}}async _initiateOnNativeHTLC(t,r,n,i,s){if(!this.wallet.account)return z.Err("No account found");try{const a=await wo({address:z.with0x(s),abi:b_,client:this.wallet}).write.initiate([i,r,n,t],{account:this.wallet.account,chain:this.wallet.chain,value:n});return z.Ok(a)}catch(o){return z.Err("Failed to initiate on native HTLC",String(o))}}async _initiateOnErc20HTLC(t,r,n,i,s,o,a){if(!this.wallet.account)return z.Err("No account found");try{const c=await this.auth.getAuthHeaders();if(c.error)return z.Err(c.error);const f=wo({address:z.with0x(s),abi:Qu,client:this.wallet}),l=await z.checkAllowanceAndApprove(Number(n),o,s,this.wallet);if(l.error)return z.Err(l.error);const h=await f.read.eip712Domain(),m=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:h[1],version:h[2],chainId:Number(h[3]),verifyingContract:h[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:i,timelock:r,amount:n,secretHash:t}}),p={...c.val,"Content-Type":"application/json"},g=await Dt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:a,signature:m,perform_on:"Source"}),headers:p});return g.error?z.Err(g.error):g.result?z.Ok(g.result):z.Err("Init: No result found")}catch(c){return console.log("init error :",c),z.Err(String(c))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return z.Err(n.error);const i=await Dt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:Pr(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});return i.error?z.Err(i.error):i.result?z.Ok(i.result):z.Err("Redeem: No result found")}catch(n){return z.Err(String(n))}}async refund(){return z.Err("Refund not supported")}}const Vl=[{name:"LockingContract",type:"impl",interface_name:"src::mintable_lock_interface::ILockingContract"},{name:"src::mintable_lock_interface::ILockingContract",type:"interface",items:[{name:"set_locking_contract",type:"function",inputs:[{name:"locking_contract",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"get_locking_contract",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"}]},{name:"LockAndDelegate",type:"impl",interface_name:"src::mintable_lock_interface::ILockAndDelegate"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"src::mintable_lock_interface::ILockAndDelegate",type:"interface",items:[{name:"lock_and_delegate",type:"function",inputs:[{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"lock_and_delegate_by_sig",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"},{name:"nonce",type:"core::felt252"},{name:"expiry",type:"core::integer::u64"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"MintableToken",type:"impl",interface_name:"src::mintable_token_interface::IMintableToken"},{name:"src::mintable_token_interface::IMintableToken",type:"interface",items:[{name:"permissioned_mint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissioned_burn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"MintableTokenCamelImpl",type:"impl",interface_name:"src::mintable_token_interface::IMintableTokenCamel"},{name:"src::mintable_token_interface::IMintableTokenCamel",type:"interface",items:[{name:"permissionedMint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissionedBurn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"Replaceable",type:"impl",interface_name:"src::replaceability_interface::IReplaceable"},{name:"core::array::Span::<core::felt252>",type:"struct",members:[{name:"snapshot",type:"@core::array::Array::<core::felt252>"}]},{name:"src::replaceability_interface::EICData",type:"struct",members:[{name:"eic_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_init_data",type:"core::array::Span::<core::felt252>"}]},{name:"core::option::Option::<src::replaceability_interface::EICData>",type:"enum",variants:[{name:"Some",type:"src::replaceability_interface::EICData"},{name:"None",type:"()"}]},{name:"core::bool",type:"enum",variants:[{name:"False",type:"()"},{name:"True",type:"()"}]},{name:"src::replaceability_interface::ImplementationData",type:"struct",members:[{name:"impl_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_data",type:"core::option::Option::<src::replaceability_interface::EICData>"},{name:"final",type:"core::bool"}]},{name:"src::replaceability_interface::IReplaceable",type:"interface",items:[{name:"get_upgrade_delay",type:"function",inputs:[],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"get_impl_activation_time",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"add_new_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"remove_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"replace_to",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"}]},{name:"AccessControlImplExternal",type:"impl",interface_name:"src::access_control_interface::IAccessControl"},{name:"src::access_control_interface::IAccessControl",type:"interface",items:[{name:"has_role",type:"function",inputs:[{name:"role",type:"core::felt252"},{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"get_role_admin",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[{type:"core::felt252"}],state_mutability:"view"}]},{name:"RolesImpl",type:"impl",interface_name:"src::roles_interface::IMinimalRoles"},{name:"src::roles_interface::IMinimalRoles",type:"interface",items:[{name:"is_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"is_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"register_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"register_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"renounce",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[],state_mutability:"external"}]},{name:"ERC20Impl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20"},{name:"openzeppelin::token::erc20::interface::IERC20",type:"interface",items:[{name:"name",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"symbol",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"decimals",type:"function",inputs:[],outputs:[{type:"core::integer::u8"}],state_mutability:"view"},{name:"total_supply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balance_of",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"allowance",type:"function",inputs:[{name:"owner",type:"core::starknet::contract_address::ContractAddress"},{name:"spender",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transfer",type:"function",inputs:[{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"transfer_from",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"approve",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"ERC20CamelOnlyImpl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20CamelOnly"},{name:"openzeppelin::token::erc20::interface::IERC20CamelOnly",type:"interface",items:[{name:"totalSupply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balanceOf",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transferFrom",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"name",type:"core::felt252"},{name:"symbol",type:"core::felt252"},{name:"decimals",type:"core::integer::u8"},{name:"initial_supply",type:"core::integer::u256"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"permitted_minter",type:"core::starknet::contract_address::ContractAddress"},{name:"provisional_governance_admin",type:"core::starknet::contract_address::ContractAddress"},{name:"upgrade_delay",type:"core::integer::u64"}]},{name:"increase_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"added_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decrease_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtracted_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"increaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"addedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decreaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtractedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Transfer",type:"event",members:[{kind:"data",name:"from",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"to",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Approval",type:"event",members:[{kind:"data",name:"owner",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"spender",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationAdded",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationRemoved",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationReplaced",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationFinalized",type:"event",members:[{kind:"data",name:"impl_hash",type:"core::starknet::class_hash::ClassHash"}]},{kind:"struct",name:"src::access_control_interface::RoleGranted",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleRevoked",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleAdminChanged",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"previous_admin_role",type:"core::felt252"},{kind:"data",name:"new_admin_role",type:"core::felt252"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"enum",name:"src::strk::erc20_lockable::ERC20Lockable::Event",type:"event",variants:[{kind:"nested",name:"Transfer",type:"src::strk::erc20_lockable::ERC20Lockable::Transfer"},{kind:"nested",name:"Approval",type:"src::strk::erc20_lockable::ERC20Lockable::Approval"},{kind:"nested",name:"ImplementationAdded",type:"src::replaceability_interface::ImplementationAdded"},{kind:"nested",name:"ImplementationRemoved",type:"src::replaceability_interface::ImplementationRemoved"},{kind:"nested",name:"ImplementationReplaced",type:"src::replaceability_interface::ImplementationReplaced"},{kind:"nested",name:"ImplementationFinalized",type:"src::replaceability_interface::ImplementationFinalized"},{kind:"nested",name:"RoleGranted",type:"src::access_control_interface::RoleGranted"},{kind:"nested",name:"RoleRevoked",type:"src::access_control_interface::RoleRevoked"},{kind:"nested",name:"RoleAdminChanged",type:"src::access_control_interface::RoleAdminChanged"},{kind:"nested",name:"GovernanceAdminAdded",type:"src::roles_interface::GovernanceAdminAdded"},{kind:"nested",name:"GovernanceAdminRemoved",type:"src::roles_interface::GovernanceAdminRemoved"},{kind:"nested",name:"UpgradeGovernorAdded",type:"src::roles_interface::UpgradeGovernorAdded"},{kind:"nested",name:"UpgradeGovernorRemoved",type:"src::roles_interface::UpgradeGovernorRemoved"}]}],g_=async(e,t,r,n,i)=>{try{const s=await Pa(e.address,t,r,i);if(s.error)return G(s.error);const o=Oe.cairo.uint256(BigInt(Oe.uint256.UINT_256_MAX));if(s.val<n){const a=await e.execute([{contractAddress:rn(t),entrypoint:"approve",calldata:[r,o.low,o.high]}]);await i.waitForTransaction(a.transaction_hash,{retryInterval:3e3,successStates:[Oe.TransactionExecutionStatus.SUCCEEDED]}),await z.sleep(2e3);let c=0n;for(let f=0;f<20;f++){const l=await Pa(e.address,t,r,i);if(l.error)return G(l.error);if(c=l.val,c>=n)break;await z.sleep(2e3)}return c<n?G("Allowance not approved"):ie(a.transaction_hash)}return ie("Allowance already approved")}catch(s){return G(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},Pa=async(e,t,r,n)=>{try{const s=await new Oe.Contract(Vl,rn(t),n).call("allowance",[rn(e),rn(r)]);return ie(BigInt((s==null?void 0:s.toString())||"0"))}catch(i){return G(`Failed to check allowance: ${i instanceof Error?i.message:String(i)}`)}},w_=async(e,t,r,n,i)=>{const s=await Pa(e,t,r,n);return s.error?G(s.error):ie(s.val>=i)},Wl=[{name:"HTLC",type:"impl",interface_name:"starknet_htlc::interface::IHTLC"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"starknet_htlc::interface::IHTLC",type:"interface",items:[{name:"token",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"},{name:"initiate",type:"function",inputs:[{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_on_behalf",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_with_signature",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"},{name:"redeem",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"secret",type:"core::array::Array::<core::integer::u32>"}],outputs:[],state_mutability:"external"},{name:"refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"}],outputs:[],state_mutability:"external"},{name:"instant_refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"token",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"starknet_htlc::interface::events::Initiated",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"amount",type:"core::integer::u256"}]},{kind:"struct",name:"starknet_htlc::interface::events::Redeemed",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"secret",type:"core::array::Array::<core::integer::u32>"}]},{kind:"struct",name:"starknet_htlc::interface::events::Refunded",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"}]},{kind:"enum",name:"starknet_htlc::htlc::HTLC::Event",type:"event",variants:[{kind:"nested",name:"Initiated",type:"starknet_htlc::interface::events::Initiated"},{kind:"nested",name:"Redeemed",type:"starknet_htlc::interface::events::Redeemed"},{kind:"nested",name:"Refunded",type:"starknet_htlc::interface::events::Refunded"}]}],__={StarknetDomain:[{name:"name",type:"shortstring"},{name:"version",type:"shortstring"},{name:"chainId",type:"shortstring"},{name:"revision",type:"shortstring"}],Initiate:[{name:"redeemer",type:"ContractAddress"},{name:"amount",type:"u256"},{name:"timelock",type:"u128"},{name:"secretHash",type:"u128*"}]};class Kl{constructor(t,r,n,i){this.url=t instanceof z.Url?t:new z.Url(t),this.account=r,this.starknetProvider=new Oe.RpcProvider({nodeUrl:i||_s[n].nodeUrl})}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async getChainId(){try{const t=await this.account.getChainId();return ie(t)}catch(t){return G(String(t))}}async initiate(t){if(!this.account.address)return G("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return G("Invalid order");try{const o=new Oe.Contract(Wl,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),c=Oe.num.toHex(a),f=await w_(this.account.address,c,n.asset,this.starknetProvider,BigInt(s));return f.error?G(f.error):f.val?this.initiateRelay(t):this.approveAndInitiate(c,t)}catch(o){return G(String(o))}}async approveAndInitiate(t,r){const{create_order:n,source_swap:i}=r,{redeemer:s,amount:o}=i,{secret_hash:a,timelock:c}=n,f=i.asset;try{const l=Oe.cairo.uint256(BigInt(Oe.uint256.UINT_256_MAX)),h={contractAddress:rn(t),entrypoint:"approve",calldata:[f,l.low,l.high]},m=Oe.cairo.uint256(o),p={contractAddress:rn(f),entrypoint:"initiate",calldata:[s,c.toString(),m.low.toString(),m.high.toString(),...z.hexToU32Array(a)]},g=await this.account.execute([h,p]);return await this.starknetProvider.waitForTransaction(g.transaction_hash,{retryInterval:2e3,successStates:[Oe.TransactionExecutionStatus.SUCCEEDED]}),ie(g.transaction_hash)}catch(l){return G(`Failed to approve and initiate: ${String(l)}`)}}async initiateRelay(t){const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n,o=await this.getChainId();if(o.error)return G(o.error);const c={domain:{name:"HTLC",version:Oe.shortString.encodeShortString("1"),chainId:o.val,revision:Oe.TypedDataRevision.ACTIVE},primaryType:"Initiate",types:__,message:{redeemer:i,amount:Oe.cairo.uint256(s),timelock:r.timelock,secretHash:z.hexToU32Array(r.secret_hash)}};try{const f=await this.account.signMessage(c),l=nb(f);if(l.error)return G(l.error);const h=await Dt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:l.val,perform_on:"Source"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return h.error?G(h.error):h.result?ie(h.result):G("Init: No result found")}catch(f){return G(`Failed to initiate relayer: ${String(f)}`)}}async redeem(t,r){try{const n=await Dt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return n.error?G(n.error):n.result?ie(n.result):G("Redeem: No result found")}catch(n){return G(String(n))}}async refund(){return G("Refund is taken care of by the relayer")}}class Ac extends z.EventBroker{constructor(t){if(super(),this.environment=z.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new u1,typeof t.digestKey=="string"){const n=z.DigestKey.from(t.digestKey);if(!n.ok)throw new Error(n.error);this._digestKey=n.val}else this._digestKey=t.digestKey;if(typeof t.environment=="string"){if(this.environment=t.environment,this._api=t.environment===z.Environment.MAINNET?Vn.mainnet:t.environment===z.Environment.TESTNET?Vn.testnet:void 0,!this._api)throw new Error("API not found, invalid environment "+t.environment)}else this._api=t.environment;this._quote=t.quote??new nl(this._api.quote),this._auth=t.auth??z.Siwe.fromDigestKey(new z.Url(this._api.auth),this._digestKey),this._orderbook=t.orderbook??new ge.Orderbook(new z.Url(this._api.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._secretManager=t.secretManager??Si.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new c1,this._blockNumberFetcher=t.blockNumberFetcher??new rl(this._api.info,this.environment);const r=new fn.BitcoinProvider(tb(this.environment));this._btcWallet=fn.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,r)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const s=z.DigestKey.from(t.digestKey);if(!s.ok)throw new Error(s.error);r=s.val}else r=t.digestKey;let n;if(typeof t.environment=="string"?n=t.environment===z.Environment.MAINNET?Vn.mainnet:t.environment===z.Environment.TESTNET?Vn.testnet:void 0:n=t.environment,!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new ql(n.evmRelay,t.wallets.evm,z.Siwe.fromDigestKey(new z.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new Kl(n.starknetRelay,t.wallets.starknet,t.environment===z.Environment.MAINNET?z.Network.MAINNET:z.Network.TESTNET):void 0};return new Ac({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return G(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val,o=Date.now().toString(),a=await this._secretManager.generateSecret(o);if(a.error)return G(a.error);const{strategyId:c,btcAddress:f}=t.additionalData,l={strategy_id:c,...f&&{bitcoin_optional_recipient:f}},h={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o,timelock:s,secret_hash:Pr(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:l},m=await this._quote.getAttestedQuote(h);if(m.error)return G(m.error);const p=await this._orderbook.createOrder(m.val,this.auth);if(p.error)return G(p.error);const g=await this.pollOrder(p.val);return g.error?G(g.error):ie(g.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return G("StrategyId is required");if(!t.fromAsset||!t.toAsset)return G("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return G("Source and destination assets cannot be the same");if(ge.isMainnet(t.fromAsset.chain)&&!ge.isMainnet(t.toAsset.chain)||!ge.isMainnet(t.fromAsset.chain)&&ge.isMainnet(t.toAsset.chain))return G("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return G(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return G(n.error);if(r<n)return G("Send amount should be greater than receive amount");const i=ge.getTimeLock(t.fromAsset.chain);if(!i)return G("Unsupported chain for timelock");if((ge.isBitcoin(t.fromAsset.chain)||ge.isBitcoin(t.toAsset.chain))&&!t.additionalData.btcAddress)return G("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return G(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?G(o.error):ie({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(ge.getBlockchainType(t)){case ge.BlockchainType.EVM:return this._evmHTLC?ie(this._evmHTLC.htlcActorAddress):G("Please provide evmHTLC when initializing garden");case ge.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!Zm(i)?G("Invalid btc public key"):ie(cr(i))}case ge.BlockchainType.Starknet:return this._starknetHTLC?ie(this._starknetHTLC.htlcActorAddress):G("Please provide starknetHTLC when initializing garden");default:return G("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return G("Invalid amount ",t);const r=new Ql(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?G("Invalid amount ",t):ie(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return G(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return ie(r.val);r=await this._orderbook.getOrder(t,!0)}return G(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error&&(this.emit("onPendingOrdersChanged",n.val),r.data.length!==0))for(let i=0;i<n.val.length;i++){const s=n.val[i],o=oc(s.status);if(ge.isBitcoin(s.source_swap.chain)&&s.status===we.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Ce.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(ge.getBlockchainType(s.destination_swap.chain)){case ge.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case ge.BlockchainType.Bitcoin:{const c=this.btcWallet;if(!c){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(c,s,a.val.secret);break}case ge.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Ce.Refund:{switch(ge.getBlockchainType(s.source_swap.chain)){case ge.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case ge.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case ge.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}},"pending",{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(!i.ok){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ce.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Ce.Redeem,i.val),this.emit("success",t,Ce.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ce.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Ce.Redeem,i.val),this.emit("success",t,Ce.Redeem,i.val))}async btcRedeem(t,r,n){var a,c;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const f=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let l=!1;for(const h of f.vin)if(h.txid===s){l=!0;break}if(l){this.emit("log",r.create_order.create_id,"already a valid redeem");let h=0;try{const[m]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);m!==0&&(h=m)}catch{h=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:h,redeemTxHash:r.destination_swap.redeem_tx_hash});return}o=!0}catch(f){if(f.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+f);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const l=await(await Yn.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,cr(r.destination_swap.initiator),cr(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(Pr(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient),h=await this.broadcastRedeemTx(l,r.create_order.create_id);if(h.error||!h.val){this.emit("error",r,h.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,h.val)):this.emit("success",r,Ce.Redeem,h.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:h.val})}catch(f){console.log("error",f),this.emit("error",r,"Failed btc redeem: "+f)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Ce.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await Yn.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,cr(r.source_swap.initiator),cr(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,Ce.Refund,s),this.emit("success",r,Ce.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await Yn.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,cr(t.source_swap.initiator),cr(t.source_swap.redeemer),t.source_swap.timelock),s=t.create_order.additional_data.bitcoin_optional_recipient;if(s)try{const o=await i.generateInstantRefundSACP(s);if(!this._api)return;const a=new z.Url(this._api.orderbook).endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await Dt.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:o})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(o){this.emit("error",t,"Failed to generate and post SACP: "+o);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return ie([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return G(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(Od(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,f=r==null?void 0:r.val[a],l=r==null?void 0:r.val[c];if(!f||!l){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const h=sc(o,f,l);n.push({...o,status:h})}return ie(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return G("API not found");const n=new z.Url(this._api.evmRelay).endpoint("/bitcoin/redeem "),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?ie(o.result):G(o.error)}catch(n){return G("Failed to broadcast redeem tx: "+n)}}}class v_{constructor(t,r,n){this.callData=new Oe.CallData(Vl),this.account=t,this.starknetProvider=new Oe.RpcProvider({nodeUrl:r||(n?_s[n].nodeUrl:_s.mainnet.nodeUrl)})}get htlcActorAddress(){return this.account.address}async getHTLCContract(t,r=!1){const n=r?t.destination_swap.asset:t.source_swap.asset;return new Oe.Contract(Wl,n,this.account)}async initiate(t){try{const n=await(await this.getHTLCContract(t)).token();if(!n)throw new Error("Token address retrieval failed");const i=Oe.num.toHex(n),s=Oe.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await g_(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.starknetProvider);if(a.error)return G(a.error)}catch(a){return G(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return ie(o.transaction_hash)}catch(r){return G(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:Oe.CallData.compile({swap_id:i,secret:z.hexToU32Array(r)})});return s.transaction_hash?ie(s.transaction_hash):G("Failed to redeem HTLC transaction")}catch{return G("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?ie(i.transaction_hash):G("Failed to refund HTLC transaction")}catch{return G("HTLC Refund Error")}}}exports.API=Vn;exports.AbiErrorInputsNotFoundError=Yh;exports.AbiErrorNotFoundError=Xh;exports.AbiFunctionNotFoundError=Xn;exports.AbiFunctionOutputsNotFoundError=vf;exports.AbiFunctionSignatureNotFoundError=Qh;exports.BaseError=$;exports.BlockNumberFetcher=rl;exports.EvmRelay=ql;exports.Garden=Ac;exports.Hash=Ba;exports.HttpRequestError=Ma;exports.InvalidArrayError=Ef;exports.OrderActions=Ce;exports.OrderStatus=we;exports.ParseOrderStatus=sc;exports.ParseSwapStatus=ha;exports.Quote=nl;exports.STARKNET_CONFIG=_s;exports.SecretManager=Si;exports.StarknetHTLC=v_;exports.StarknetRelay=Kl;exports.SwapStatus=xe;exports.abytes=Ti;exports.aexists=Jn;exports.ahash=p0;exports.batchGatewayAbi=py;exports.call=Qa;exports.concat=Rr;exports.concatBytes=A0;exports.concatHex=Ct;exports.constructOrderPair=Cd;exports.decodeAbiParameters=Ii;exports.decodeErrorResult=jf;exports.encodeAbiParameters=Cs;exports.evmToViemChainMap=Gl;exports.filterDeadlineExpiredOrders=sb;exports.formatAbiItem=kt;exports.getAbiItem=En;exports.getUrl=$a;exports.hyperliquid=jl;exports.hyperliquidTestnet=Dl;exports.isAddressEqual=Ya;exports.isExpired=vi;exports.isHex=zt;exports.parseAction=ib;exports.parseActionFromStatus=oc;exports.randomBytes=S0;exports.sha256=td;exports.slice=dn;exports.solidityError=Hf;exports.stringify=It;exports.switchOrAddNetwork=zl;exports.toBytes=ks;exports.toFunctionSelector=Os;exports.toXOnly=cr;exports.validateBTCAddress=eb;
|
|
70
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var sl={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Md,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})(sl);var _a={exports:{}},va={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Jt,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 f=n(o);return a!==void 0?typeof c=="string"?f.fill(a,c):f.fill(a):f.fill(0),f},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)}})(va,va.exports);var tt=va.exports,Fo=65536,f1=4294967295;function d1(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
71
|
+
Use Chrome, Firefox or Internet Explorer 11`)}var l1=tt.Buffer,vs=yr.crypto||yr.msCrypto;vs&&vs.getRandomValues?_a.exports=h1:_a.exports=d1;function h1(e,t){if(e>f1)throw new RangeError("requested too many random bytes");var r=l1.allocUnsafe(e);if(e>0)if(e>Fo)for(var n=0;n<e;n+=Fo)vs.getRandomValues(r.slice(n,n+Fo));else vs.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var p1=_a.exports,Ea={exports:{}};typeof Object.create=="function"?Ea.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:Ea.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 He=Ea.exports,xa={exports:{}},Ec={exports:{}},un=typeof Reflect=="object"?Reflect:null,Su=un&&typeof un.apply=="function"?un.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},hs;un&&typeof un.ownKeys=="function"?hs=un.ownKeys:Object.getOwnPropertySymbols?hs=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:hs=function(t){return Object.getOwnPropertyNames(t)};function y1(e){console&&console.warn&&console.warn(e)}var ol=Number.isNaN||function(t){return t!==t};function ue(){ue.init.call(this)}Ec.exports=ue;Ec.exports.once=w1;ue.EventEmitter=ue;ue.prototype._events=void 0;ue.prototype._eventsCount=0;ue.prototype._maxListeners=void 0;var Pu=10;function Ys(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(ue,"defaultMaxListeners",{enumerable:!0,get:function(){return Pu},set:function(e){if(typeof e!="number"||e<0||ol(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Pu=e}});ue.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};ue.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ol(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 al(e){return e._maxListeners===void 0?ue.defaultMaxListeners:e._maxListeners}ue.prototype.getMaxListeners=function(){return al(this)};ue.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")Su(c,this,r);else for(var f=c.length,l=ll(c,f),n=0;n<f;++n)Su(l[n],this,r);return!0};function cl(e,t,r,n){var i,s,o;if(Ys(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=al(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,y1(a)}return e}ue.prototype.addListener=function(t,r){return cl(this,t,r,!1)};ue.prototype.on=ue.prototype.addListener;ue.prototype.prependListener=function(t,r){return cl(this,t,r,!0)};function m1(){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 ul(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=m1.bind(n);return i.listener=r,n.wrapFn=i,i}ue.prototype.once=function(t,r){return Ys(r),this.on(t,ul(this,t,r)),this};ue.prototype.prependOnceListener=function(t,r){return Ys(r),this.prependListener(t,ul(this,t,r)),this};ue.prototype.removeListener=function(t,r){var n,i,s,o,a;if(Ys(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():b1(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};ue.prototype.off=ue.prototype.removeListener;ue.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 fl(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?g1(i):ll(i,i.length)}ue.prototype.listeners=function(t){return fl(this,t,!0)};ue.prototype.rawListeners=function(t){return fl(this,t,!1)};ue.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):dl.call(e,t)};ue.prototype.listenerCount=dl;function dl(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}ue.prototype.eventNames=function(){return this._eventsCount>0?hs(this._events):[]};function ll(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function b1(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function g1(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function w1(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))}hl(e,t,s,{once:!0}),t!=="error"&&_1(e,i,{once:!0})})}function _1(e,t,r){typeof e.on=="function"&&hl(e,"error",t,r)}function hl(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 pl=Ec.exports,yl=pl.EventEmitter;const v1={},E1=Object.freeze(Object.defineProperty({__proto__:null,default:v1},Symbol.toStringTag,{value:"Module"})),xc=uc(E1);var $o,Tu;function x1(){if(Tu)return $o;Tu=1;function e(g,v){var x=Object.keys(g);if(Object.getOwnPropertySymbols){var I=Object.getOwnPropertySymbols(g);v&&(I=I.filter(function(k){return Object.getOwnPropertyDescriptor(g,k).enumerable})),x.push.apply(x,I)}return x}function t(g){for(var v=1;v<arguments.length;v++){var x=arguments[v]!=null?arguments[v]:{};v%2?e(Object(x),!0).forEach(function(I){r(g,I,x[I])}):Object.getOwnPropertyDescriptors?Object.defineProperties(g,Object.getOwnPropertyDescriptors(x)):e(Object(x)).forEach(function(I){Object.defineProperty(g,I,Object.getOwnPropertyDescriptor(x,I))})}return g}function r(g,v,x){return v=o(v),v in g?Object.defineProperty(g,v,{value:x,enumerable:!0,configurable:!0,writable:!0}):g[v]=x,g}function n(g,v){if(!(g instanceof v))throw new TypeError("Cannot call a class as a function")}function i(g,v){for(var x=0;x<v.length;x++){var I=v[x];I.enumerable=I.enumerable||!1,I.configurable=!0,"value"in I&&(I.writable=!0),Object.defineProperty(g,o(I.key),I)}}function s(g,v,x){return v&&i(g.prototype,v),Object.defineProperty(g,"prototype",{writable:!1}),g}function o(g){var v=a(g,"string");return typeof v=="symbol"?v:String(v)}function a(g,v){if(typeof g!="object"||g===null)return g;var x=g[Symbol.toPrimitive];if(x!==void 0){var I=x.call(g,v);if(typeof I!="object")return I;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(g)}var c=Jt,f=c.Buffer,l=xc,h=l.inspect,m=h&&h.custom||"inspect";function p(g,v,x){f.prototype.copy.call(g,v,x)}return $o=function(){function g(){n(this,g),this.head=null,this.tail=null,this.length=0}return s(g,[{key:"push",value:function(x){var I={data:x,next:null};this.length>0?this.tail.next=I:this.head=I,this.tail=I,++this.length}},{key:"unshift",value:function(x){var I={data:x,next:this.head};this.length===0&&(this.tail=I),this.head=I,++this.length}},{key:"shift",value:function(){if(this.length!==0){var x=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,x}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(x){if(this.length===0)return"";for(var I=this.head,k=""+I.data;I=I.next;)k+=x+I.data;return k}},{key:"concat",value:function(x){if(this.length===0)return f.alloc(0);for(var I=f.allocUnsafe(x>>>0),k=this.head,A=0;k;)p(k.data,I,A),A+=k.data.length,k=k.next;return I}},{key:"consume",value:function(x,I){var k;return x<this.head.data.length?(k=this.head.data.slice(0,x),this.head.data=this.head.data.slice(x)):x===this.head.data.length?k=this.shift():k=I?this._getString(x):this._getBuffer(x),k}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(x){var I=this.head,k=1,A=I.data;for(x-=A.length;I=I.next;){var E=I.data,T=x>E.length?E.length:x;if(T===E.length?A+=E:A+=E.slice(0,x),x-=T,x===0){T===E.length?(++k,I.next?this.head=I.next:this.head=this.tail=null):(this.head=I,I.data=E.slice(T));break}++k}return this.length-=k,A}},{key:"_getBuffer",value:function(x){var I=f.allocUnsafe(x),k=this.head,A=1;for(k.data.copy(I),x-=k.data.length;k=k.next;){var E=k.data,T=x>E.length?E.length:x;if(E.copy(I,I.length-x,0,T),x-=T,x===0){T===E.length?(++A,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=E.slice(T));break}++A}return this.length-=A,I}},{key:m,value:function(x,I){return h(this,t(t({},I),{},{depth:0,customInspect:!1}))}}]),g}(),$o}function A1(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(Aa,this,e)):process.nextTick(Aa,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(ps,r):(r._writableState.errorEmitted=!0,process.nextTick(ku,r,s)):process.nextTick(ku,r,s):t?(process.nextTick(ps,r),t(s)):process.nextTick(ps,r)}),this)}function ku(e,t){Aa(e,t),ps(e)}function ps(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function S1(){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 Aa(e,t){e.emit("error",t)}function P1(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var ml={destroy:A1,undestroy:S1,errorOrDestroy:P1},jr={};function T1(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var bl={};function pt(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){T1(o,s);function o(a,c,f){return s.call(this,n(a,c,f))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,bl[e]=i}function Iu(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 k1(e,t,r){return e.substr(0,t.length)===t}function I1(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function B1(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}pt("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);pt("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&k1(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(I1(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Iu(t,"type"));else{var s=B1(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(Iu(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);pt("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");pt("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});pt("ERR_STREAM_PREMATURE_CLOSE","Premature close");pt("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});pt("ERR_MULTIPLE_CALLBACK","Callback called multiple times");pt("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");pt("ERR_STREAM_WRITE_AFTER_END","write after end");pt("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);pt("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);pt("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");jr.codes=bl;var C1=jr.codes.ERR_INVALID_OPT_VALUE;function O1(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function R1(e,t,r,n){var i=O1(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new C1(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var gl={getHighWaterMark:R1},U1=L1;function L1(e,t){if(Mo("noDeprecation"))return e;var r=!1;function n(){if(!r){if(Mo("throwDeprecation"))throw new Error(t);Mo("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function Mo(e){try{if(!yr.localStorage)return!1}catch{return!1}var t=yr.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Ho,Bu;function wl(){if(Bu)return Ho;Bu=1,Ho=M;function e(O){var C=this;this.next=null,this.entry=null,this.finish=function(){Rt(C,O)}}var t;M.WritableState=S;var r={deprecate:U1},n=yl,i=Jt.Buffer,s=(typeof yr<"u"?yr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(O){return i.from(O)}function a(O){return i.isBuffer(O)||O instanceof s}var c=ml,f=gl,l=f.getHighWaterMark,h=jr.codes,m=h.ERR_INVALID_ARG_TYPE,p=h.ERR_METHOD_NOT_IMPLEMENTED,g=h.ERR_MULTIPLE_CALLBACK,v=h.ERR_STREAM_CANNOT_PIPE,x=h.ERR_STREAM_DESTROYED,I=h.ERR_STREAM_NULL_VALUES,k=h.ERR_STREAM_WRITE_AFTER_END,A=h.ERR_UNKNOWN_ENCODING,E=c.errorOrDestroy;He(M,n);function T(){}function S(O,C,H){t=t||gn(),O=O||{},typeof H!="boolean"&&(H=C instanceof t),this.objectMode=!!O.objectMode,H&&(this.objectMode=this.objectMode||!!O.writableObjectMode),this.highWaterMark=l(this,O,"writableHighWaterMark",H),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var K=O.decodeStrings===!1;this.decodeStrings=!K,this.defaultEncoding=O.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(Z){ne(C,Z)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=O.emitClose!==!1,this.autoDestroy=!!O.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}S.prototype.getBuffer=function(){for(var C=this.bufferedRequest,H=[];C;)H.push(C),C=C.next;return H},function(){try{Object.defineProperty(S.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var N;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(N=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(C){return N.call(this,C)?!0:this!==M?!1:C&&C._writableState instanceof S}})):N=function(C){return C instanceof this};function M(O){t=t||gn();var C=this instanceof t;if(!C&&!N.call(M,this))return new M(O);this._writableState=new S(O,this,C),this.writable=!0,O&&(typeof O.write=="function"&&(this._write=O.write),typeof O.writev=="function"&&(this._writev=O.writev),typeof O.destroy=="function"&&(this._destroy=O.destroy),typeof O.final=="function"&&(this._final=O.final)),n.call(this)}M.prototype.pipe=function(){E(this,new v)};function B(O,C){var H=new k;E(O,H),process.nextTick(C,H)}function W(O,C,H,K){var Z;return H===null?Z=new I:typeof H!="string"&&!C.objectMode&&(Z=new m("chunk",["string","Buffer"],H)),Z?(E(O,Z),process.nextTick(K,Z),!1):!0}M.prototype.write=function(O,C,H){var K=this._writableState,Z=!1,w=!K.objectMode&&a(O);return w&&!i.isBuffer(O)&&(O=o(O)),typeof C=="function"&&(H=C,C=null),w?C="buffer":C||(C=K.defaultEncoding),typeof H!="function"&&(H=T),K.ending?B(this,H):(w||W(this,K,O,H))&&(K.pendingcb++,Z=D(this,K,w,O,C,H)),Z},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var O=this._writableState;O.corked&&(O.corked--,!O.writing&&!O.corked&&!O.bufferProcessing&&O.bufferedRequest&&Te(this,O))},M.prototype.setDefaultEncoding=function(C){if(typeof C=="string"&&(C=C.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((C+"").toLowerCase())>-1))throw new A(C);return this._writableState.defaultEncoding=C,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function U(O,C,H){return!O.objectMode&&O.decodeStrings!==!1&&typeof C=="string"&&(C=i.from(C,H)),C}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function D(O,C,H,K,Z,w){if(!H){var _=U(C,K,Z);K!==_&&(H=!0,Z="buffer",K=_)}var F=C.objectMode?1:K.length;C.length+=F;var q=C.length<C.highWaterMark;if(q||(C.needDrain=!0),C.writing||C.corked){var ve=C.lastBufferedRequest;C.lastBufferedRequest={chunk:K,encoding:Z,isBuf:H,callback:w,next:null},ve?ve.next=C.lastBufferedRequest:C.bufferedRequest=C.lastBufferedRequest,C.bufferedRequestCount+=1}else G(O,C,!1,F,K,Z,w);return q}function G(O,C,H,K,Z,w,_){C.writelen=K,C.writecb=_,C.writing=!0,C.sync=!0,C.destroyed?C.onwrite(new x("write")):H?O._writev(Z,C.onwrite):O._write(Z,w,C.onwrite),C.sync=!1}function V(O,C,H,K,Z){--C.pendingcb,H?(process.nextTick(Z,K),process.nextTick(it,O,C),O._writableState.errorEmitted=!0,E(O,K)):(Z(K),O._writableState.errorEmitted=!0,E(O,K),it(O,C))}function X(O){O.writing=!1,O.writecb=null,O.length-=O.writelen,O.writelen=0}function ne(O,C){var H=O._writableState,K=H.sync,Z=H.writecb;if(typeof Z!="function")throw new g;if(X(H),C)V(O,H,K,C,Z);else{var w=We(H)||O.destroyed;!w&&!H.corked&&!H.bufferProcessing&&H.bufferedRequest&&Te(O,H),K?process.nextTick(he,O,H,w,Z):he(O,H,w,Z)}}function he(O,C,H,K){H||_e(O,C),C.pendingcb--,K(),it(O,C)}function _e(O,C){C.length===0&&C.needDrain&&(C.needDrain=!1,O.emit("drain"))}function Te(O,C){C.bufferProcessing=!0;var H=C.bufferedRequest;if(O._writev&&H&&H.next){var K=C.bufferedRequestCount,Z=new Array(K),w=C.corkedRequestsFree;w.entry=H;for(var _=0,F=!0;H;)Z[_]=H,H.isBuf||(F=!1),H=H.next,_+=1;Z.allBuffers=F,G(O,C,!0,C.length,Z,"",w.finish),C.pendingcb++,C.lastBufferedRequest=null,w.next?(C.corkedRequestsFree=w.next,w.next=null):C.corkedRequestsFree=new e(C),C.bufferedRequestCount=0}else{for(;H;){var q=H.chunk,ve=H.encoding,ee=H.callback,ae=C.objectMode?1:q.length;if(G(O,C,!1,ae,q,ve,ee),H=H.next,C.bufferedRequestCount--,C.writing)break}H===null&&(C.lastBufferedRequest=null)}C.bufferedRequest=H,C.bufferProcessing=!1}M.prototype._write=function(O,C,H){H(new p("_write()"))},M.prototype._writev=null,M.prototype.end=function(O,C,H){var K=this._writableState;return typeof O=="function"?(H=O,O=null,C=null):typeof C=="function"&&(H=C,C=null),O!=null&&this.write(O,C),K.corked&&(K.corked=1,this.uncork()),K.ending||Qt(this,K,H),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function We(O){return O.ending&&O.length===0&&O.bufferedRequest===null&&!O.finished&&!O.writing}function fe(O,C){O._final(function(H){C.pendingcb--,H&&E(O,H),C.prefinished=!0,O.emit("prefinish"),it(O,C)})}function ye(O,C){!C.prefinished&&!C.finalCalled&&(typeof O._final=="function"&&!C.destroyed?(C.pendingcb++,C.finalCalled=!0,process.nextTick(fe,O,C)):(C.prefinished=!0,O.emit("prefinish")))}function it(O,C){var H=We(C);if(H&&(ye(O,C),C.pendingcb===0&&(C.finished=!0,O.emit("finish"),C.autoDestroy))){var K=O._readableState;(!K||K.autoDestroy&&K.endEmitted)&&O.destroy()}return H}function Qt(O,C,H){C.ending=!0,it(O,C),H&&(C.finished?process.nextTick(H):O.once("finish",H)),C.ended=!0,O.writable=!1}function Rt(O,C,H){var K=O.entry;for(O.entry=null;K;){var Z=K.callback;C.pendingcb--,Z(H),K=K.next}C.corkedRequestsFree.next=O}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(C){this._writableState&&(this._writableState.destroyed=C)}}),M.prototype.destroy=c.destroy,M.prototype._undestroy=c.undestroy,M.prototype._destroy=function(O,C){C(O)},Ho}var Do,Cu;function gn(){if(Cu)return Do;Cu=1;var e=Object.keys||function(f){var l=[];for(var h in f)l.push(h);return l};Do=o;var t=vl(),r=wl();He(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(f){if(!(this instanceof o))return new o(f);t.call(this,f),r.call(this,f),this.allowHalfOpen=!0,f&&(f.readable===!1&&(this.readable=!1),f.writable===!1&&(this.writable=!1),f.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(f){f.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(l){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=l,this._writableState.destroyed=l)}}),Do}var Es={},Ac=tt.Buffer,Ou=Ac.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 N1(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 F1(e){var t=N1(e);if(typeof t!="string"&&(Ac.isEncoding===Ou||!Ou(e)))throw new Error("Unknown encoding: "+e);return t||e}Es.StringDecoder=Fi;function Fi(e){this.encoding=F1(e);var t;switch(this.encoding){case"utf16le":this.text=G1,this.end=z1,t=4;break;case"utf8":this.fillLast=H1,t=4;break;case"base64":this.text=q1,this.end=V1,t=3;break;default:this.write=W1,this.end=K1;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Ac.allocUnsafe(t)}Fi.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||""};Fi.prototype.end=j1;Fi.prototype.text=D1;Fi.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 jo(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function $1(e,t,r){var n=t.length-1;if(n<r)return 0;var i=jo(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=jo(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=jo(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function M1(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 H1(e){var t=this.lastTotal-this.lastNeed,r=M1(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 D1(e,t){var r=$1(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 j1(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function G1(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 z1(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 q1(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 V1(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function W1(e){return e.toString(this.encoding)}function K1(e){return e&&e.length?this.write(e):""}var Ru=jr.codes.ERR_STREAM_PREMATURE_CLOSE;function Y1(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 X1(){}function J1(e){return e.setHeader&&typeof e.abort=="function"}function _l(e,t,r){if(typeof t=="function")return _l(e,null,t);t||(t={}),r=Y1(r||X1);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,f=function(){n=!1,c=!0,i||r.call(e)},l=function(g){r.call(e,g)},h=function(){var g;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(g=new Ru),r.call(e,g);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(g=new Ru),r.call(e,g)},m=function(){e.req.on("finish",a)};return J1(e)?(e.on("complete",a),e.on("abort",h),e.req?m():e.on("request",m)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",f),e.on("finish",a),t.error!==!1&&e.on("error",l),e.on("close",h),function(){e.removeListener("complete",a),e.removeListener("abort",h),e.removeListener("request",m),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",f),e.removeListener("error",l),e.removeListener("close",h)}}var Sc=_l,Go,Uu;function Q1(){if(Uu)return Go;Uu=1;var e;function t(A,E,T){return E=r(E),E in A?Object.defineProperty(A,E,{value:T,enumerable:!0,configurable:!0,writable:!0}):A[E]=T,A}function r(A){var E=n(A,"string");return typeof E=="symbol"?E:String(E)}function n(A,E){if(typeof A!="object"||A===null)return A;var T=A[Symbol.toPrimitive];if(T!==void 0){var S=T.call(A,E);if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return(E==="string"?String:Number)(A)}var i=Sc,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),f=Symbol("lastPromise"),l=Symbol("handlePromise"),h=Symbol("stream");function m(A,E){return{value:A,done:E}}function p(A){var E=A[s];if(E!==null){var T=A[h].read();T!==null&&(A[f]=null,A[s]=null,A[o]=null,E(m(T,!1)))}}function g(A){process.nextTick(p,A)}function v(A,E){return function(T,S){A.then(function(){if(E[c]){T(m(void 0,!0));return}E[l](T,S)},S)}}var x=Object.getPrototypeOf(function(){}),I=Object.setPrototypeOf((e={get stream(){return this[h]},next:function(){var E=this,T=this[a];if(T!==null)return Promise.reject(T);if(this[c])return Promise.resolve(m(void 0,!0));if(this[h].destroyed)return new Promise(function(B,W){process.nextTick(function(){E[a]?W(E[a]):B(m(void 0,!0))})});var S=this[f],N;if(S)N=new Promise(v(S,this));else{var M=this[h].read();if(M!==null)return Promise.resolve(m(M,!1));N=new Promise(this[l])}return this[f]=N,N}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var E=this;return new Promise(function(T,S){E[h].destroy(null,function(N){if(N){S(N);return}T(m(void 0,!0))})})}),e),x),k=function(E){var T,S=Object.create(I,(T={},t(T,h,{value:E,writable:!0}),t(T,s,{value:null,writable:!0}),t(T,o,{value:null,writable:!0}),t(T,a,{value:null,writable:!0}),t(T,c,{value:E._readableState.endEmitted,writable:!0}),t(T,l,{value:function(M,B){var W=S[h].read();W?(S[f]=null,S[s]=null,S[o]=null,M(m(W,!1))):(S[s]=M,S[o]=B)},writable:!0}),T));return S[f]=null,i(E,function(N){if(N&&N.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=S[o];M!==null&&(S[f]=null,S[s]=null,S[o]=null,M(N)),S[a]=N;return}var B=S[s];B!==null&&(S[f]=null,S[s]=null,S[o]=null,B(m(void 0,!0))),S[c]=!0}),E.on("readable",g.bind(null,S)),S};return Go=k,Go}var zo,Lu;function Z1(){return Lu||(Lu=1,zo=function(){throw new Error("Readable.from is not available in the browser")}),zo}var qo,Nu;function vl(){if(Nu)return qo;Nu=1,qo=B;var e;B.ReadableState=M,pl.EventEmitter;var t=function(_,F){return _.listeners(F).length},r=yl,n=Jt.Buffer,i=(typeof yr<"u"?yr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(w){return n.from(w)}function o(w){return n.isBuffer(w)||w instanceof i}var a=xc,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var f=x1(),l=ml,h=gl,m=h.getHighWaterMark,p=jr.codes,g=p.ERR_INVALID_ARG_TYPE,v=p.ERR_STREAM_PUSH_AFTER_EOF,x=p.ERR_METHOD_NOT_IMPLEMENTED,I=p.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,k,A,E;He(B,r);var T=l.errorOrDestroy,S=["error","close","destroy","pause","resume"];function N(w,_,F){if(typeof w.prependListener=="function")return w.prependListener(_,F);!w._events||!w._events[_]?w.on(_,F):Array.isArray(w._events[_])?w._events[_].unshift(F):w._events[_]=[F,w._events[_]]}function M(w,_,F){e=e||gn(),w=w||{},typeof F!="boolean"&&(F=_ instanceof e),this.objectMode=!!w.objectMode,F&&(this.objectMode=this.objectMode||!!w.readableObjectMode),this.highWaterMark=m(this,w,"readableHighWaterMark",F),this.buffer=new f,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=w.emitClose!==!1,this.autoDestroy=!!w.autoDestroy,this.destroyed=!1,this.defaultEncoding=w.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,w.encoding&&(k||(k=Es.StringDecoder),this.decoder=new k(w.encoding),this.encoding=w.encoding)}function B(w){if(e=e||gn(),!(this instanceof B))return new B(w);var _=this instanceof e;this._readableState=new M(w,this,_),this.readable=!0,w&&(typeof w.read=="function"&&(this._read=w.read),typeof w.destroy=="function"&&(this._destroy=w.destroy)),r.call(this)}Object.defineProperty(B.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(_){this._readableState&&(this._readableState.destroyed=_)}}),B.prototype.destroy=l.destroy,B.prototype._undestroy=l.undestroy,B.prototype._destroy=function(w,_){_(w)},B.prototype.push=function(w,_){var F=this._readableState,q;return F.objectMode?q=!0:typeof w=="string"&&(_=_||F.defaultEncoding,_!==F.encoding&&(w=n.from(w,_),_=""),q=!0),W(this,w,_,!1,q)},B.prototype.unshift=function(w){return W(this,w,null,!0,!1)};function W(w,_,F,q,ve){c("readableAddChunk",_);var ee=w._readableState;if(_===null)ee.reading=!1,ne(w,ee);else{var ae;if(ve||(ae=D(ee,_)),ae)T(w,ae);else if(ee.objectMode||_&&_.length>0)if(typeof _!="string"&&!ee.objectMode&&Object.getPrototypeOf(_)!==n.prototype&&(_=s(_)),q)ee.endEmitted?T(w,new I):U(w,ee,_,!0);else if(ee.ended)T(w,new v);else{if(ee.destroyed)return!1;ee.reading=!1,ee.decoder&&!F?(_=ee.decoder.write(_),ee.objectMode||_.length!==0?U(w,ee,_,!1):Te(w,ee)):U(w,ee,_,!1)}else q||(ee.reading=!1,Te(w,ee))}return!ee.ended&&(ee.length<ee.highWaterMark||ee.length===0)}function U(w,_,F,q){_.flowing&&_.length===0&&!_.sync?(_.awaitDrain=0,w.emit("data",F)):(_.length+=_.objectMode?1:F.length,q?_.buffer.unshift(F):_.buffer.push(F),_.needReadable&&he(w)),Te(w,_)}function D(w,_){var F;return!o(_)&&typeof _!="string"&&_!==void 0&&!w.objectMode&&(F=new g("chunk",["string","Buffer","Uint8Array"],_)),F}B.prototype.isPaused=function(){return this._readableState.flowing===!1},B.prototype.setEncoding=function(w){k||(k=Es.StringDecoder);var _=new k(w);this._readableState.decoder=_,this._readableState.encoding=this._readableState.decoder.encoding;for(var F=this._readableState.buffer.head,q="";F!==null;)q+=_.write(F.data),F=F.next;return this._readableState.buffer.clear(),q!==""&&this._readableState.buffer.push(q),this._readableState.length=q.length,this};var G=1073741824;function V(w){return w>=G?w=G:(w--,w|=w>>>1,w|=w>>>2,w|=w>>>4,w|=w>>>8,w|=w>>>16,w++),w}function X(w,_){return w<=0||_.length===0&&_.ended?0:_.objectMode?1:w!==w?_.flowing&&_.length?_.buffer.head.data.length:_.length:(w>_.highWaterMark&&(_.highWaterMark=V(w)),w<=_.length?w:_.ended?_.length:(_.needReadable=!0,0))}B.prototype.read=function(w){c("read",w),w=parseInt(w,10);var _=this._readableState,F=w;if(w!==0&&(_.emittedReadable=!1),w===0&&_.needReadable&&((_.highWaterMark!==0?_.length>=_.highWaterMark:_.length>0)||_.ended))return c("read: emitReadable",_.length,_.ended),_.length===0&&_.ended?H(this):he(this),null;if(w=X(w,_),w===0&&_.ended)return _.length===0&&H(this),null;var q=_.needReadable;c("need readable",q),(_.length===0||_.length-w<_.highWaterMark)&&(q=!0,c("length less than watermark",q)),_.ended||_.reading?(q=!1,c("reading or ended",q)):q&&(c("do read"),_.reading=!0,_.sync=!0,_.length===0&&(_.needReadable=!0),this._read(_.highWaterMark),_.sync=!1,_.reading||(w=X(F,_)));var ve;return w>0?ve=C(w,_):ve=null,ve===null?(_.needReadable=_.length<=_.highWaterMark,w=0):(_.length-=w,_.awaitDrain=0),_.length===0&&(_.ended||(_.needReadable=!0),F!==w&&_.ended&&H(this)),ve!==null&&this.emit("data",ve),ve};function ne(w,_){if(c("onEofChunk"),!_.ended){if(_.decoder){var F=_.decoder.end();F&&F.length&&(_.buffer.push(F),_.length+=_.objectMode?1:F.length)}_.ended=!0,_.sync?he(w):(_.needReadable=!1,_.emittedReadable||(_.emittedReadable=!0,_e(w)))}}function he(w){var _=w._readableState;c("emitReadable",_.needReadable,_.emittedReadable),_.needReadable=!1,_.emittedReadable||(c("emitReadable",_.flowing),_.emittedReadable=!0,process.nextTick(_e,w))}function _e(w){var _=w._readableState;c("emitReadable_",_.destroyed,_.length,_.ended),!_.destroyed&&(_.length||_.ended)&&(w.emit("readable"),_.emittedReadable=!1),_.needReadable=!_.flowing&&!_.ended&&_.length<=_.highWaterMark,O(w)}function Te(w,_){_.readingMore||(_.readingMore=!0,process.nextTick(We,w,_))}function We(w,_){for(;!_.reading&&!_.ended&&(_.length<_.highWaterMark||_.flowing&&_.length===0);){var F=_.length;if(c("maybeReadMore read 0"),w.read(0),F===_.length)break}_.readingMore=!1}B.prototype._read=function(w){T(this,new x("_read()"))},B.prototype.pipe=function(w,_){var F=this,q=this._readableState;switch(q.pipesCount){case 0:q.pipes=w;break;case 1:q.pipes=[q.pipes,w];break;default:q.pipes.push(w);break}q.pipesCount+=1,c("pipe count=%d opts=%j",q.pipesCount,_);var ve=(!_||_.end!==!1)&&w!==process.stdout&&w!==process.stderr,ee=ve?Zt:xr;q.endEmitted?process.nextTick(ee):F.once("end",ee),w.on("unpipe",ae);function ae(y,u){c("onunpipe"),y===F&&u&&u.hasUnpiped===!1&&(u.hasUnpiped=!0,qr())}function Zt(){c("onend"),w.end()}var zr=fe(F);w.on("drain",zr);var Sn=!1;function qr(){c("cleanup"),w.removeListener("close",Pn),w.removeListener("finish",ut),w.removeListener("drain",zr),w.removeListener("error",Er),w.removeListener("unpipe",ae),F.removeListener("end",Zt),F.removeListener("end",xr),F.removeListener("data",st),Sn=!0,q.awaitDrain&&(!w._writableState||w._writableState.needDrain)&&zr()}F.on("data",st);function st(y){c("ondata");var u=w.write(y);c("dest.write",u),u===!1&&((q.pipesCount===1&&q.pipes===w||q.pipesCount>1&&Z(q.pipes,w)!==-1)&&!Sn&&(c("false write response, pause",q.awaitDrain),q.awaitDrain++),F.pause())}function Er(y){c("onerror",y),xr(),w.removeListener("error",Er),t(w,"error")===0&&T(w,y)}N(w,"error",Er);function Pn(){w.removeListener("finish",ut),xr()}w.once("close",Pn);function ut(){c("onfinish"),w.removeListener("close",Pn),xr()}w.once("finish",ut);function xr(){c("unpipe"),F.unpipe(w)}return w.emit("pipe",F),q.flowing||(c("pipe resume"),F.resume()),w};function fe(w){return function(){var F=w._readableState;c("pipeOnDrain",F.awaitDrain),F.awaitDrain&&F.awaitDrain--,F.awaitDrain===0&&t(w,"data")&&(F.flowing=!0,O(w))}}B.prototype.unpipe=function(w){var _=this._readableState,F={hasUnpiped:!1};if(_.pipesCount===0)return this;if(_.pipesCount===1)return w&&w!==_.pipes?this:(w||(w=_.pipes),_.pipes=null,_.pipesCount=0,_.flowing=!1,w&&w.emit("unpipe",this,F),this);if(!w){var q=_.pipes,ve=_.pipesCount;_.pipes=null,_.pipesCount=0,_.flowing=!1;for(var ee=0;ee<ve;ee++)q[ee].emit("unpipe",this,{hasUnpiped:!1});return this}var ae=Z(_.pipes,w);return ae===-1?this:(_.pipes.splice(ae,1),_.pipesCount-=1,_.pipesCount===1&&(_.pipes=_.pipes[0]),w.emit("unpipe",this,F),this)},B.prototype.on=function(w,_){var F=r.prototype.on.call(this,w,_),q=this._readableState;return w==="data"?(q.readableListening=this.listenerCount("readable")>0,q.flowing!==!1&&this.resume()):w==="readable"&&!q.endEmitted&&!q.readableListening&&(q.readableListening=q.needReadable=!0,q.flowing=!1,q.emittedReadable=!1,c("on readable",q.length,q.reading),q.length?he(this):q.reading||process.nextTick(it,this)),F},B.prototype.addListener=B.prototype.on,B.prototype.removeListener=function(w,_){var F=r.prototype.removeListener.call(this,w,_);return w==="readable"&&process.nextTick(ye,this),F},B.prototype.removeAllListeners=function(w){var _=r.prototype.removeAllListeners.apply(this,arguments);return(w==="readable"||w===void 0)&&process.nextTick(ye,this),_};function ye(w){var _=w._readableState;_.readableListening=w.listenerCount("readable")>0,_.resumeScheduled&&!_.paused?_.flowing=!0:w.listenerCount("data")>0&&w.resume()}function it(w){c("readable nexttick read 0"),w.read(0)}B.prototype.resume=function(){var w=this._readableState;return w.flowing||(c("resume"),w.flowing=!w.readableListening,Qt(this,w)),w.paused=!1,this};function Qt(w,_){_.resumeScheduled||(_.resumeScheduled=!0,process.nextTick(Rt,w,_))}function Rt(w,_){c("resume",_.reading),_.reading||w.read(0),_.resumeScheduled=!1,w.emit("resume"),O(w),_.flowing&&!_.reading&&w.read(0)}B.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 O(w){var _=w._readableState;for(c("flow",_.flowing);_.flowing&&w.read()!==null;);}B.prototype.wrap=function(w){var _=this,F=this._readableState,q=!1;w.on("end",function(){if(c("wrapped end"),F.decoder&&!F.ended){var ae=F.decoder.end();ae&&ae.length&&_.push(ae)}_.push(null)}),w.on("data",function(ae){if(c("wrapped data"),F.decoder&&(ae=F.decoder.write(ae)),!(F.objectMode&&ae==null)&&!(!F.objectMode&&(!ae||!ae.length))){var Zt=_.push(ae);Zt||(q=!0,w.pause())}});for(var ve in w)this[ve]===void 0&&typeof w[ve]=="function"&&(this[ve]=function(Zt){return function(){return w[Zt].apply(w,arguments)}}(ve));for(var ee=0;ee<S.length;ee++)w.on(S[ee],this.emit.bind(this,S[ee]));return this._read=function(ae){c("wrapped _read",ae),q&&(q=!1,w.resume())},this},typeof Symbol=="function"&&(B.prototype[Symbol.asyncIterator]=function(){return A===void 0&&(A=Q1()),A(this)}),Object.defineProperty(B.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(B.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(B.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(_){this._readableState&&(this._readableState.flowing=_)}}),B._fromList=C,Object.defineProperty(B.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function C(w,_){if(_.length===0)return null;var F;return _.objectMode?F=_.buffer.shift():!w||w>=_.length?(_.decoder?F=_.buffer.join(""):_.buffer.length===1?F=_.buffer.first():F=_.buffer.concat(_.length),_.buffer.clear()):F=_.buffer.consume(w,_.decoder),F}function H(w){var _=w._readableState;c("endReadable",_.endEmitted),_.endEmitted||(_.ended=!0,process.nextTick(K,_,w))}function K(w,_){if(c("endReadableNT",w.endEmitted,w.length),!w.endEmitted&&w.length===0&&(w.endEmitted=!0,_.readable=!1,_.emit("end"),w.autoDestroy)){var F=_._writableState;(!F||F.autoDestroy&&F.finished)&&_.destroy()}}typeof Symbol=="function"&&(B.from=function(w,_){return E===void 0&&(E=Z1()),E(B,w,_)});function Z(w,_){for(var F=0,q=w.length;F<q;F++)if(w[F]===_)return F;return-1}return qo}var El=Yt,Xs=jr.codes,ew=Xs.ERR_METHOD_NOT_IMPLEMENTED,tw=Xs.ERR_MULTIPLE_CALLBACK,rw=Xs.ERR_TRANSFORM_ALREADY_TRANSFORMING,nw=Xs.ERR_TRANSFORM_WITH_LENGTH_0,Js=gn();He(Yt,Js);function iw(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new tw);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 Yt(e){if(!(this instanceof Yt))return new Yt(e);Js.call(this,e),this._transformState={afterTransform:iw.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",sw)}function sw(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Fu(e,t,r)}):Fu(this,null,null)}Yt.prototype.push=function(e,t){return this._transformState.needTransform=!1,Js.prototype.push.call(this,e,t)};Yt.prototype._transform=function(e,t,r){r(new ew("_transform()"))};Yt.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)}};Yt.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};Yt.prototype._destroy=function(e,t){Js.prototype._destroy.call(this,e,function(r){t(r)})};function Fu(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new nw;if(e._transformState.transforming)throw new rw;return e.push(null)}var ow=Ai,xl=El;He(Ai,xl);function Ai(e){if(!(this instanceof Ai))return new Ai(e);xl.call(this,e)}Ai.prototype._transform=function(e,t,r){r(null,e)};var Vo;function aw(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var Al=jr.codes,cw=Al.ERR_MISSING_ARGS,uw=Al.ERR_STREAM_DESTROYED;function $u(e){if(e)throw e}function fw(e){return e.setHeader&&typeof e.abort=="function"}function dw(e,t,r,n){n=aw(n);var i=!1;e.on("close",function(){i=!0}),Vo===void 0&&(Vo=Sc),Vo(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,fw(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new uw("pipe"))}}}function Mu(e){e()}function lw(e,t){return e.pipe(t)}function hw(e){return!e.length||typeof e[e.length-1]!="function"?$u:e.pop()}function pw(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=hw(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new cw("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,f=a>0;return dw(o,c,f,function(l){i||(i=l),l&&s.forEach(Mu),!c&&(s.forEach(Mu),n(i))})});return t.reduce(lw)}var yw=pw;(function(e,t){t=e.exports=vl(),t.Stream=t,t.Readable=t,t.Writable=wl(),t.Duplex=gn(),t.Transform=El,t.PassThrough=ow,t.finished=Sc,t.pipeline=yw})(xa,xa.exports);var Sl=xa.exports,xs=tt.Buffer,Pl=Sl.Transform,mw=He;function bw(e,t){if(!xs.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function _r(e){Pl.call(this),this._block=xs.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}mw(_r,Pl);_r.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};_r.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};_r.prototype.update=function(e,t){if(bw(e,"Data"),this._finalized)throw new Error("Digest already called");xs.isBuffer(e)||(e=xs.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};_r.prototype._update=function(){throw new Error("_update is not implemented")};_r.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};_r.prototype._digest=function(){throw new Error("_digest is not implemented")};var gw=_r,ww=He,Tl=gw,_w=tt.Buffer,vw=new Array(16);function Qs(){Tl.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}ww(Qs,Tl);Qs.prototype._update=function(){for(var e=vw,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=De(r,n,i,s,e[0],3614090360,7),s=De(s,r,n,i,e[1],3905402710,12),i=De(i,s,r,n,e[2],606105819,17),n=De(n,i,s,r,e[3],3250441966,22),r=De(r,n,i,s,e[4],4118548399,7),s=De(s,r,n,i,e[5],1200080426,12),i=De(i,s,r,n,e[6],2821735955,17),n=De(n,i,s,r,e[7],4249261313,22),r=De(r,n,i,s,e[8],1770035416,7),s=De(s,r,n,i,e[9],2336552879,12),i=De(i,s,r,n,e[10],4294925233,17),n=De(n,i,s,r,e[11],2304563134,22),r=De(r,n,i,s,e[12],1804603682,7),s=De(s,r,n,i,e[13],4254626195,12),i=De(i,s,r,n,e[14],2792965006,17),n=De(n,i,s,r,e[15],1236535329,22),r=je(r,n,i,s,e[1],4129170786,5),s=je(s,r,n,i,e[6],3225465664,9),i=je(i,s,r,n,e[11],643717713,14),n=je(n,i,s,r,e[0],3921069994,20),r=je(r,n,i,s,e[5],3593408605,5),s=je(s,r,n,i,e[10],38016083,9),i=je(i,s,r,n,e[15],3634488961,14),n=je(n,i,s,r,e[4],3889429448,20),r=je(r,n,i,s,e[9],568446438,5),s=je(s,r,n,i,e[14],3275163606,9),i=je(i,s,r,n,e[3],4107603335,14),n=je(n,i,s,r,e[8],1163531501,20),r=je(r,n,i,s,e[13],2850285829,5),s=je(s,r,n,i,e[2],4243563512,9),i=je(i,s,r,n,e[7],1735328473,14),n=je(n,i,s,r,e[12],2368359562,20),r=Ge(r,n,i,s,e[5],4294588738,4),s=Ge(s,r,n,i,e[8],2272392833,11),i=Ge(i,s,r,n,e[11],1839030562,16),n=Ge(n,i,s,r,e[14],4259657740,23),r=Ge(r,n,i,s,e[1],2763975236,4),s=Ge(s,r,n,i,e[4],1272893353,11),i=Ge(i,s,r,n,e[7],4139469664,16),n=Ge(n,i,s,r,e[10],3200236656,23),r=Ge(r,n,i,s,e[13],681279174,4),s=Ge(s,r,n,i,e[0],3936430074,11),i=Ge(i,s,r,n,e[3],3572445317,16),n=Ge(n,i,s,r,e[6],76029189,23),r=Ge(r,n,i,s,e[9],3654602809,4),s=Ge(s,r,n,i,e[12],3873151461,11),i=Ge(i,s,r,n,e[15],530742520,16),n=Ge(n,i,s,r,e[2],3299628645,23),r=ze(r,n,i,s,e[0],4096336452,6),s=ze(s,r,n,i,e[7],1126891415,10),i=ze(i,s,r,n,e[14],2878612391,15),n=ze(n,i,s,r,e[5],4237533241,21),r=ze(r,n,i,s,e[12],1700485571,6),s=ze(s,r,n,i,e[3],2399980690,10),i=ze(i,s,r,n,e[10],4293915773,15),n=ze(n,i,s,r,e[1],2240044497,21),r=ze(r,n,i,s,e[8],1873313359,6),s=ze(s,r,n,i,e[15],4264355552,10),i=ze(i,s,r,n,e[6],2734768916,15),n=ze(n,i,s,r,e[13],1309151649,21),r=ze(r,n,i,s,e[4],4149444226,6),s=ze(s,r,n,i,e[11],3174756917,10),i=ze(i,s,r,n,e[2],718787259,15),n=ze(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};Qs.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=_w.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 Zs(e,t){return e<<t|e>>>32-t}function De(e,t,r,n,i,s,o){return Zs(e+(t&r|~t&n)+i+s|0,o)+t|0}function je(e,t,r,n,i,s,o){return Zs(e+(t&n|r&~n)+i+s|0,o)+t|0}function Ge(e,t,r,n,i,s,o){return Zs(e+(t^r^n)+i+s|0,o)+t|0}function ze(e,t,r,n,i,s,o){return Zs(e+(r^(t|~n))+i+s|0,o)+t|0}var Ew=Qs,As=tt.Buffer,kl=Sl.Transform,xw=He;function Aw(e,t){if(!As.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function vr(e){kl.call(this),this._block=As.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}xw(vr,kl);vr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};vr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};vr.prototype.update=function(e,t){if(Aw(e,"Data"),this._finalized)throw new Error("Digest already called");As.isBuffer(e)||(e=As.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};vr.prototype._update=function(){throw new Error("_update is not implemented")};vr.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};vr.prototype._digest=function(){throw new Error("_digest is not implemented")};var Sw=vr,Wo=Jt.Buffer,Pw=He,Il=Sw,Tw=new Array(16),Ln=[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],Nn=[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],Fn=[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],$n=[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],Mn=[0,1518500249,1859775393,2400959708,2840853838],Hn=[1352829926,1548603684,1836072691,2053994217,0];function eo(){Il.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}Pw(eo,Il);eo.prototype._update=function(){for(var e=Tw,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,f=this._c|0,l=this._d|0,h=this._e|0,m=0;m<80;m+=1){var p,g;m<16?(p=Hu(r,n,i,s,o,e[Ln[m]],Mn[0],Fn[m]),g=zu(a,c,f,l,h,e[Nn[m]],Hn[0],$n[m])):m<32?(p=Du(r,n,i,s,o,e[Ln[m]],Mn[1],Fn[m]),g=Gu(a,c,f,l,h,e[Nn[m]],Hn[1],$n[m])):m<48?(p=ju(r,n,i,s,o,e[Ln[m]],Mn[2],Fn[m]),g=ju(a,c,f,l,h,e[Nn[m]],Hn[2],$n[m])):m<64?(p=Gu(r,n,i,s,o,e[Ln[m]],Mn[3],Fn[m]),g=Du(a,c,f,l,h,e[Nn[m]],Hn[3],$n[m])):(p=zu(r,n,i,s,o,e[Ln[m]],Mn[4],Fn[m]),g=Hu(a,c,f,l,h,e[Nn[m]],Hn[4],$n[m])),r=o,o=s,s=$r(i,10),i=n,n=p,a=h,h=l,l=$r(f,10),f=c,c=g}var v=this._b+i+l|0;this._b=this._c+s+h|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+f|0,this._a=v};eo.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=Wo.alloc?Wo.alloc(20):new Wo(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 $r(e,t){return e<<t|e>>>32-t}function Hu(e,t,r,n,i,s,o,a){return $r(e+(t^r^n)+s+o|0,a)+i|0}function Du(e,t,r,n,i,s,o,a){return $r(e+(t&r|~t&n)+s+o|0,a)+i|0}function ju(e,t,r,n,i,s,o,a){return $r(e+((t|~r)^n)+s+o|0,a)+i|0}function Gu(e,t,r,n,i,s,o,a){return $r(e+(t&n|r&~n)+s+o|0,a)+i|0}function zu(e,t,r,n,i,s,o,a){return $r(e+(t^(r|~n))+s+o|0,a)+i|0}var kw=eo,Bl={exports:{}},Cl=tt.Buffer;function to(e,t){this._block=Cl.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}to.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Cl.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),f=0;f<c;f++)r[a+f]=e[o+f];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};to.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};to.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var An=to,Iw=He,Ol=An,Bw=tt.Buffer,Cw=[1518500249,1859775393,-1894007588,-899497514],Ow=new Array(80);function $i(){this.init(),this._w=Ow,Ol.call(this,64,56)}Iw($i,Ol);$i.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Rw(e){return e<<5|e>>>27}function Uw(e){return e<<30|e>>>2}function Lw(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}$i.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 f=~~(c/20),l=Rw(r)+Lw(f,n,i,s)+o+t[c]+Cw[f]|0;o=s,s=i,i=Uw(n),n=r,r=l}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};$i.prototype._hash=function(){var e=Bw.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 Nw=$i,Fw=He,Rl=An,$w=tt.Buffer,Mw=[1518500249,1859775393,-1894007588,-899497514],Hw=new Array(80);function Mi(){this.init(),this._w=Hw,Rl.call(this,64,56)}Fw(Mi,Rl);Mi.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Dw(e){return e<<1|e>>>31}function jw(e){return e<<5|e>>>27}function Gw(e){return e<<30|e>>>2}function zw(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Mi.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]=Dw(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var f=~~(c/20),l=jw(r)+zw(f,n,i,s)+o+t[c]+Mw[f]|0;o=s,s=i,i=Gw(n),n=r,r=l}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};Mi.prototype._hash=function(){var e=$w.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 qw=Mi,Vw=He,Ul=An,Ww=tt.Buffer,Kw=[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],Yw=new Array(64);function Hi(){this.init(),this._w=Yw,Ul.call(this,64,56)}Vw(Hi,Ul);Hi.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 Xw(e,t,r){return r^e&(t^r)}function Jw(e,t,r){return e&t|r&(e|t)}function Qw(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function Zw(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function e2(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function t2(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}Hi.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,f=this._h|0,l=0;l<16;++l)t[l]=e.readInt32BE(l*4);for(;l<64;++l)t[l]=t2(t[l-2])+t[l-7]+e2(t[l-15])+t[l-16]|0;for(var h=0;h<64;++h){var m=f+Zw(o)+Xw(o,a,c)+Kw[h]+t[h]|0,p=Qw(r)+Jw(r,n,i)|0;f=c,c=a,a=o,o=s+m|0,s=i,i=n,n=r,r=m+p|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=s+this._d|0,this._e=o+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=f+this._h|0};Hi.prototype._hash=function(){var e=Ww.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 Ll=Hi,r2=He,n2=Ll,i2=An,s2=tt.Buffer,o2=new Array(64);function ro(){this.init(),this._w=o2,i2.call(this,64,56)}r2(ro,n2);ro.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};ro.prototype._hash=function(){var e=s2.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 a2=ro,c2=He,Nl=An,u2=tt.Buffer,qu=[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],f2=new Array(160);function Di(){this.init(),this._w=f2,Nl.call(this,128,112)}c2(Di,Nl);Di.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 Vu(e,t,r){return r^e&(t^r)}function Wu(e,t,r){return e&t|r&(e|t)}function Ku(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function Yu(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function d2(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function l2(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function h2(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function p2(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ue(e,t){return e>>>0<t>>>0?1:0}Di.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,f=this._hh|0,l=this._al|0,h=this._bl|0,m=this._cl|0,p=this._dl|0,g=this._el|0,v=this._fl|0,x=this._gl|0,I=this._hl|0,k=0;k<32;k+=2)t[k]=e.readInt32BE(k*4),t[k+1]=e.readInt32BE(k*4+4);for(;k<160;k+=2){var A=t[k-30],E=t[k-15*2+1],T=d2(A,E),S=l2(E,A);A=t[k-2*2],E=t[k-2*2+1];var N=h2(A,E),M=p2(E,A),B=t[k-7*2],W=t[k-7*2+1],U=t[k-16*2],D=t[k-16*2+1],G=S+W|0,V=T+B+Ue(G,S)|0;G=G+M|0,V=V+N+Ue(G,M)|0,G=G+D|0,V=V+U+Ue(G,D)|0,t[k]=V,t[k+1]=G}for(var X=0;X<160;X+=2){V=t[X],G=t[X+1];var ne=Wu(r,n,i),he=Wu(l,h,m),_e=Ku(r,l),Te=Ku(l,r),We=Yu(o,g),fe=Yu(g,o),ye=qu[X],it=qu[X+1],Qt=Vu(o,a,c),Rt=Vu(g,v,x),O=I+fe|0,C=f+We+Ue(O,I)|0;O=O+Rt|0,C=C+Qt+Ue(O,Rt)|0,O=O+it|0,C=C+ye+Ue(O,it)|0,O=O+G|0,C=C+V+Ue(O,G)|0;var H=Te+he|0,K=_e+ne+Ue(H,Te)|0;f=c,I=x,c=a,x=v,a=o,v=g,g=p+O|0,o=s+C+Ue(g,p)|0,s=i,p=m,i=n,m=h,n=r,h=l,l=O+H|0,r=C+K+Ue(l,O)|0}this._al=this._al+l|0,this._bl=this._bl+h|0,this._cl=this._cl+m|0,this._dl=this._dl+p|0,this._el=this._el+g|0,this._fl=this._fl+v|0,this._gl=this._gl+x|0,this._hl=this._hl+I|0,this._ah=this._ah+r+Ue(this._al,l)|0,this._bh=this._bh+n+Ue(this._bl,h)|0,this._ch=this._ch+i+Ue(this._cl,m)|0,this._dh=this._dh+s+Ue(this._dl,p)|0,this._eh=this._eh+o+Ue(this._el,g)|0,this._fh=this._fh+a+Ue(this._fl,v)|0,this._gh=this._gh+c+Ue(this._gl,x)|0,this._hh=this._hh+f+Ue(this._hl,I)|0};Di.prototype._hash=function(){var e=u2.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 Fl=Di,y2=He,m2=Fl,b2=An,g2=tt.Buffer,w2=new Array(160);function no(){this.init(),this._w=w2,b2.call(this,128,112)}y2(no,m2);no.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};no.prototype._hash=function(){var e=g2.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 _2=no,Gr=Bl.exports=function(t){t=t.toLowerCase();var r=Gr[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};Gr.sha=Nw;Gr.sha1=qw;Gr.sha224=a2;Gr.sha256=Ll;Gr.sha384=_2;Gr.sha512=Fl;var v2=Bl.exports,Pt=tt.Buffer,$l=xc.Transform,E2=Es.StringDecoder,x2=He;function bt(e){$l.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}x2(bt,$l);var A2=typeof Uint8Array<"u",S2=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(Pt.prototype instanceof Uint8Array||Pt.TYPED_ARRAY_SUPPORT);function P2(e,t){if(e instanceof Pt)return e;if(typeof e=="string")return Pt.from(e,t);if(S2&&ArrayBuffer.isView(e)){if(e.byteLength===0)return Pt.alloc(0);var r=Pt.from(e.buffer,e.byteOffset,e.byteLength);if(r.byteLength===e.byteLength)return r}if(A2&&e instanceof Uint8Array||Pt.isBuffer(e)&&e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return Pt.from(e);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}bt.prototype.update=function(e,t,r){var n=P2(e,t),i=this._update(n);return this.hashMode?this:(r&&(i=this._toString(i,r)),i)};bt.prototype.setAutoPadding=function(){};bt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};bt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};bt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};bt.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)}};bt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};bt.prototype._finalOrDigest=function(e){var t=this.__final()||Pt.alloc(0);return e&&(t=this._toString(t,e,!0)),t};bt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new E2(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 T2=bt,k2=He,I2=Ew,B2=kw,C2=v2,Ml=T2;function io(e){Ml.call(this,"digest"),this._hash=e}k2(io,Ml);io.prototype._update=function(e){this._hash.update(e)};io.prototype._final=function(){return this._hash.digest()};var O2=function(t){return t=t.toLowerCase(),t==="md5"?new I2:t==="rmd160"||t==="ripemd160"?new B2:new io(C2(t))},rs=tt.Buffer;function R2(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),f=Math.log(256)/Math.log(o);function l(p){if((Array.isArray(p)||p instanceof Uint8Array)&&(p=rs.from(p)),!rs.isBuffer(p))throw new TypeError("Expected Buffer");if(p.length===0)return"";for(var g=0,v=0,x=0,I=p.length;x!==I&&p[x]===0;)x++,g++;for(var k=(I-x)*f+1>>>0,A=new Uint8Array(k);x!==I;){for(var E=p[x],T=0,S=k-1;(E!==0||T<v)&&S!==-1;S--,T++)E+=256*A[S]>>>0,A[S]=E%o>>>0,E=E/o>>>0;if(E!==0)throw new Error("Non-zero carry");v=T,x++}for(var N=k-v;N!==k&&A[N]===0;)N++;for(var M=a.repeat(g);N<k;++N)M+=e.charAt(A[N]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return rs.alloc(0);for(var g=0,v=0,x=0;p[g]===a;)v++,g++;for(var I=(p.length-g)*c+1>>>0,k=new Uint8Array(I);g<p.length;){var A=p.charCodeAt(g);if(A>255)return;var E=t[A];if(E===255)return;for(var T=0,S=I-1;(E!==0||T<x)&&S!==-1;S--,T++)E+=o*k[S]>>>0,k[S]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");x=T,g++}for(var N=I-x;N!==I&&k[N]===0;)N++;var M=rs.allocUnsafe(v+(I-N));M.fill(0,0,v);for(var B=v;N!==I;)M[B++]=k[N++];return M}function m(p){var g=h(p);if(g)return g;throw new Error("Non-base"+o+" character")}return{encode:l,decodeUnsafe:h,decode:m}}var U2=R2,L2=U2,N2="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",F2=L2(N2),Ko=F2,$2=tt.Buffer,M2=function(e){function t(s){var o=e(s);return Ko.encode($2.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=Ko.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Ko.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},Xu=O2,H2=M2;function D2(e){var t=Xu("sha256").update(e).digest();return Xu("sha256").update(t).digest()}var j2=H2(D2),Sa=j2;function Hl(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 Pa(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 G2(e,t){return Hl(Sa.decode(e),t)}function z2(e,t,r){return typeof e=="number"?Sa.encode(Pa(e,t,r)):Sa.encode(Pa(e.version,e.privateKey,e.compressed))}var q2={decode:G2,decodeRaw:Hl,encode:z2,encodeRaw:Pa},so={};Object.defineProperty(so,"__esModule",{value:!0});so.testEcc=void 0;const Y=e=>Buffer.from(e,"hex");function V2(e){be(e.isPoint(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(!e.isPoint(Y("030000000000000000000000000000000000000000000000000000000000000005"))),be(e.isPrivate(Y("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(e.isPrivate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),be(!e.isPrivate(Y("0000000000000000000000000000000000000000000000000000000000000000"))),be(!e.isPrivate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),be(!e.isPrivate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),be(Buffer.from(e.privateAdd(Y("0000000000000000000000000000000000000000000000000000000000000001"),Y("0000000000000000000000000000000000000000000000000000000000000000"))).equals(Y("0000000000000000000000000000000000000000000000000000000000000001"))),be(e.privateAdd(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),Y("0000000000000000000000000000000000000000000000000000000000000003"))===null),be(Buffer.from(e.privateAdd(Y("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),Y("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(Y("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),be(Buffer.from(e.privateNegate(Y("0000000000000000000000000000000000000000000000000000000000000001"))).equals(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),be(Buffer.from(e.privateNegate(Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(Y("0000000000000000000000000000000000000000000000000000000000000003"))),be(Buffer.from(e.privateNegate(Y("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(Y("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),be(Buffer.from(e.pointCompress(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(Buffer.from(e.pointCompress(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),be(Buffer.from(e.pointCompress(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),be(Buffer.from(e.pointCompress(Y("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(Y("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),be(Buffer.from(e.pointFromScalar(Y("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(Y("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),be(e.xOnlyPointAddTweak(Y("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(Y("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),Y("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));be(Buffer.from(t.xOnlyPubkey).equals(Y("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(Y("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),Y("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),be(Buffer.from(t.xOnlyPubkey).equals(Y("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),be(Buffer.from(e.sign(Y("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),Y("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(Y("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),be(e.verify(Y("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),Y("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Y("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&be(Buffer.from(e.signSchnorr(Y("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),Y("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),Y("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(Y("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&be(e.verifySchnorr(Y("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),Y("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),Y("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}so.testEcc=V2;function be(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(mn,"__esModule",{value:!0});mn.ECPairFactory=mn.networks=void 0;const Ta=bn;mn.networks=Ta;const Je=sl,W2=p1,Ju=q2,K2=so,Yo=Je.typeforce.maybe(Je.typeforce.compile({compressed:Je.maybe(Je.Boolean),network:Je.maybe(Je.Network)})),Y2=e=>e.length===32?e:e.slice(1,33);function X2(e){(0,K2.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(Yo,c),new o(a,void 0,c)}function n(a,c){return Je.typeforce(e.isPoint,a),Je.typeforce(Yo,c),new o(void 0,a,c)}function i(a,c){const f=Ju.decode(a),l=f.version;if(Je.Array(c)){if(c=c.filter(h=>l===h.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||Ta.bitcoin,l!==c.wif)throw new Error("Invalid network version");return r(f.privateKey,{compressed:f.compressed,network:c})}function s(a){Je.typeforce(Yo,a),a===void 0&&(a={});const c=a.rng||W2;let f;do f=c(32),Je.typeforce(Je.Buffer256bit,f);while(!e.isPrivate(f));return r(f,a)}class o{constructor(c,f,l){Vr(this,"__D");Vr(this,"__Q");Vr(this,"compressed");Vr(this,"network");Vr(this,"lowR");this.__D=c,this.__Q=f,this.lowR=!1,l===void 0&&(l={}),this.compressed=l.compressed===void 0?!0:l.compressed,this.network=l.network||Ta.bitcoin,f!==void 0&&(this.__Q=Buffer.from(e.pointCompress(f,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 Ju.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,f){if(!this.__D)throw new Error("Missing private key");if(f===void 0&&(f=this.lowR),f===!1)return Buffer.from(e.sign(c,this.__D));{let l=e.sign(c,this.__D);const h=Buffer.alloc(32,0);let m=0;for(;l[0]>127;)m++,h.writeUIntLE(m,0,6),l=e.sign(c,this.__D,h);return Buffer.from(l)}}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,f){return e.verify(c,this.publicKey,f)}verifySchnorr(c,f){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),f)}tweakFromPublicKey(c){const f=Y2(this.publicKey),l=e.xOnlyPointAddTweak(f,c);if(!l||l.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const h=Buffer.from([l.parity===0?2:3]);return n(Buffer.concat([h,l.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const l=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,h=e.privateAdd(l,c);if(!h)throw new Error("Invalid tweaked private key!");return r(Buffer.from(h),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}mn.ECPairFactory=X2;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=mn;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}})})(il);const J2=db(il);class Si extends z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new Si(Pr(t))}static fromWalletClient(t){return new Si(void 0,t)}async initialize(){if(this.digestKey)return ie("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?j(t.error):(this.emit("initialized",!0),ie("Initialized"))}async deriveDigestKeyFromWalletClient(){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.digestKey=Pr(Gn(t)),this.emit("initialized",!0),ie(this.digestKey)}catch(t){return j("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return j("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return j(t.error)}return this.digestKey?ie(this.digestKey):j("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return j(r.error);const n=Gn(z.with0x(r.val)),i=Gn(n);return ie({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const f=await this.getDigestKey();if(f.error)return j(f.error);this.digestKey=f.val}const r=J2(Br),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=Gn(i),o=Buffer.from(Pr(this.digestKey),"hex");if(o.length!==32)return j("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(Pr(s),"hex"));return ie(c.toString("hex"))}}const Qu=[{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"}],Q2={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},Z2={block:Xp({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Va(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?lt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Kp({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?lt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Dy({format(e){return{l1GasPrice:e.l1GasPrice?lt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?lt(e.l1GasUsed):null,l1Fee:e.l1Fee?lt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function e_(e,t){return n_(e)?r_(e):am(e,t)}const t_={transaction:e_};function r_(e){i_(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:c}=e,f=[t,n,a??"0x",o?J(o):"0x",c?J(c):"0x",i?J(i):"0x",s?"0x1":"0x",r??"0x"];return Ct(["0x7e",pr(f)])}function n_(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function i_(e){const{from:t,to:r}=e;if(t&&!Le(t))throw new et({address:t});if(r&&!Le(r))throw new et({address:r})}const Ss={contracts:Q2,formatters:Z2,serializers:t_},s_=Ot({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}}}),o_=Ot({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}),Dn=1,a_=Ot({...Ss,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:{...Ss.contracts,disputeGameFactory:{[Dn]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Dn]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Dn]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Dn]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Dn}),jn=11155111,c_=Ot({...Ss,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:{...Ss.contracts,disputeGameFactory:{[jn]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[jn]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[jn]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[jn]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:jn}),u_=Ot({id:80094,name:"Berachain",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:0},ensRegistry:{address:"0x5b22280886a2f5e09a49bea7e320eab0e5320e28",blockCreated:877007},ensUniversalResolver:{address:"0xddfb18888a9466688235887dec2a10c4f5effee9",blockCreated:877008}},rpcUrls:{default:{http:["https://rpc.berachain.com"]}},blockExplorers:{default:{name:"Berascan",url:"https://berascan.com"}},ensTlds:[".bera"],testnet:!1}),f_=Ot({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269},ensRegistry:{address:"0xB0eef18971290b333450586D33dcA6cE122651D2",blockCreated:7736794},ensUniversalResolver:{address:"0x41692Ef1EA0C79E6b73077E4A67572D2BDbD7057",blockCreated:7736795}},ensTlds:[".bera"],rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),d_=Ot({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"cBTC",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api"}},testnet:!0}),l_=Ot({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),h_=Ot({id:10143,name:"Monad Testnet",nativeCurrency:{name:"Testnet MON Token",symbol:"MON",decimals:18},rpcUrls:{default:{http:["https://testnet-rpc.monad.xyz"]}},blockExplorers:{default:{name:"Monad Testnet explorer",url:"https://testnet.monadexplorer.com"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:251449}},testnet:!0}),p_=Ot({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}),y_={...p_,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Dl={id:998,name:"Hyperliquid EVM Testnet",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://testnet.purrsec.com/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid-testnet.xyz/evm"]}}},jl={id:999,name:"HyperEVM",nativeCurrency:{name:"Hyperliquid",symbol:"HYPE",decimals:18},blockExplorers:{default:{name:"Hyperliquid Explorer",url:"https://hyperscan.gas.zip/"}},rpcUrls:{default:{http:["https://rpc.hyperliquid.xyz/evm"]}}},Gl={ethereum:l_,arbitrum:s_,ethereum_sepolia:y_,arbitrum_sepolia:o_,ethereum_localnet:ge.EthereumLocalnet,arbitrum_localnet:ge.ArbitrumLocalnet,base_sepolia:c_,base:a_,bera_testnet:f_,citrea_testnet:d_,bera:u_,monad_testnet:h_,hyperliquid_testnet:Dl,hyperliquid:jl},zl=async(e,t)=>{var n,i,s,o;const r=Gl[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return ie({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const a=xo({account:t.account,chain:r,transport:vo(t.transport)});return ie({message:"Switched chain",walletClient:a})}catch(a){if(m_(a))if(a.code===4902)try{await t.addChain({chain:r});const c=xo({account:t.account,chain:r,transport:vo(t.transport)});return ie({message:"Added network",walletClient:c})}catch{return j("Failed to add network")}else if((i=a.message)!=null&&i.includes("method is not available")&&((o=(s=a.body)==null?void 0:s.method)!=null&&o.includes("wallet_switchEthereumChain"))){const c=xo({account:t.account,chain:r,transport:vo(t.transport)});return ie({message:"Added network",walletClient:c})}else return j("Failed to switch network");else return j("Failed to switch network")}else return j("Chain not supported")},m_=e=>typeof e=="object"&&e!=null&&("code"in e||"message"in e||"body"in e),b_=[{inputs:[{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[],name:"NativeHTLC__DuplicateOrder",type:"error"},{inputs:[],name:"NativeHTLC__IncorrectFundsRecieved",type:"error"},{inputs:[],name:"NativeHTLC__IncorrectSecret",type:"error"},{inputs:[],name:"NativeHTLC__InsufficientBalance",type:"error"},{inputs:[],name:"NativeHTLC__InvalidRedeemerSignature",type:"error"},{inputs:[],name:"NativeHTLC__OrderFulfilled",type:"error"},{inputs:[],name:"NativeHTLC__OrderNotExpired",type:"error"},{inputs:[],name:"NativeHTLC__OrderNotInitiated",type:"error"},{inputs:[],name:"NativeHTLC__SameInitiatorAndRedeemer",type:"error"},{inputs:[],name:"NativeHTLC__ZeroAddressInitiator",type:"error"},{inputs:[],name:"NativeHTLC__ZeroAddressRedeemer",type:"error"},{inputs:[],name:"NativeHTLC__ZeroAmount",type:"error"},{inputs:[],name:"NativeHTLC__ZeroTimelock",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 payable",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:"payable",type:"function"},{inputs:[{internalType:"address payable",name:"initiator",type:"address"},{internalType:"address payable",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiateOnBehalf",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"instantRefundDigest",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address payable",name:"initiator",type:"address"},{internalType:"address payable",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:"address",name:"",type:"address"}],stateMutability:"view",type:"function"}];class ql{constructor(t,r,n){this.url=new z.Url("/relayer",t),this.auth=n,this.wallet=r}get htlcActorAddress(){if(!this.wallet.account)throw new Error("No account found");return this.wallet.account.address}async initiate(t){if(!this.wallet.account)return z.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return z.Err("Account address and order initiator mismatch");if(!ge.isEVM(t.source_swap.chain))return z.Err("Source chain is not an EVM chain");const r=await zl(t.source_swap.chain,this.wallet);if(r.error)return z.Err(r.error);if(this.wallet=r.val.walletClient,!this.wallet.account)return z.Err("No account found");const{create_order:n,source_swap:i}=t;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return z.Err("Invalid order");const s=z.with0x(n.secret_hash),o=BigInt(n.timelock),a=z.with0x(i.redeemer),c=BigInt(i.amount),f=await this.getTokenAddress(t.source_swap.asset);return f.ok?ge.isEvmNativeToken(t.source_swap.chain,f.val)?this._initiateOnNativeHTLC(s,o,c,a,t.source_swap.asset):this._initiateOnErc20HTLC(s,o,c,a,t.source_swap.asset,f.val,n.create_id):z.Err(f.error)}async getTokenAddress(t){try{const n=await wo({address:z.with0x(t),abi:Qu,client:this.wallet}).read.token();return z.Ok(n)}catch(r){return z.Err("Failed to get token address",String(r))}}async _initiateOnNativeHTLC(t,r,n,i,s){if(!this.wallet.account)return z.Err("No account found");try{const a=await wo({address:z.with0x(s),abi:b_,client:this.wallet}).write.initiate([i,r,n,t],{account:this.wallet.account,chain:this.wallet.chain,value:n});return z.Ok(a)}catch(o){return z.Err("Failed to initiate on native HTLC",String(o))}}async _initiateOnErc20HTLC(t,r,n,i,s,o,a){if(!this.wallet.account)return z.Err("No account found");try{const c=await this.auth.getAuthHeaders();if(c.error)return z.Err(c.error);const f=wo({address:z.with0x(s),abi:Qu,client:this.wallet}),l=await z.checkAllowanceAndApprove(Number(n),o,s,this.wallet);if(l.error)return z.Err(l.error);const h=await f.read.eip712Domain(),m=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:h[1],version:h[2],chainId:Number(h[3]),verifyingContract:h[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:i,timelock:r,amount:n,secretHash:t}}),p={...c.val,"Content-Type":"application/json"},g=await Dt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:a,signature:m,perform_on:"Source"}),headers:p});return g.error?z.Err(g.error):g.result?z.Ok(g.result):z.Err("Init: No result found")}catch(c){return console.log("init error :",c),z.Err(String(c))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return z.Err(n.error);const i=await Dt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:Pr(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});return i.error?z.Err(i.error):i.result?z.Ok(i.result):z.Err("Redeem: No result found")}catch(n){return z.Err(String(n))}}async refund(){return z.Err("Refund not supported")}}const Vl=[{name:"LockingContract",type:"impl",interface_name:"src::mintable_lock_interface::ILockingContract"},{name:"src::mintable_lock_interface::ILockingContract",type:"interface",items:[{name:"set_locking_contract",type:"function",inputs:[{name:"locking_contract",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"get_locking_contract",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"}]},{name:"LockAndDelegate",type:"impl",interface_name:"src::mintable_lock_interface::ILockAndDelegate"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"src::mintable_lock_interface::ILockAndDelegate",type:"interface",items:[{name:"lock_and_delegate",type:"function",inputs:[{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"lock_and_delegate_by_sig",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"delegatee",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"},{name:"nonce",type:"core::felt252"},{name:"expiry",type:"core::integer::u64"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"MintableToken",type:"impl",interface_name:"src::mintable_token_interface::IMintableToken"},{name:"src::mintable_token_interface::IMintableToken",type:"interface",items:[{name:"permissioned_mint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissioned_burn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"MintableTokenCamelImpl",type:"impl",interface_name:"src::mintable_token_interface::IMintableTokenCamel"},{name:"src::mintable_token_interface::IMintableTokenCamel",type:"interface",items:[{name:"permissionedMint",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"},{name:"permissionedBurn",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[],state_mutability:"external"}]},{name:"Replaceable",type:"impl",interface_name:"src::replaceability_interface::IReplaceable"},{name:"core::array::Span::<core::felt252>",type:"struct",members:[{name:"snapshot",type:"@core::array::Array::<core::felt252>"}]},{name:"src::replaceability_interface::EICData",type:"struct",members:[{name:"eic_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_init_data",type:"core::array::Span::<core::felt252>"}]},{name:"core::option::Option::<src::replaceability_interface::EICData>",type:"enum",variants:[{name:"Some",type:"src::replaceability_interface::EICData"},{name:"None",type:"()"}]},{name:"core::bool",type:"enum",variants:[{name:"False",type:"()"},{name:"True",type:"()"}]},{name:"src::replaceability_interface::ImplementationData",type:"struct",members:[{name:"impl_hash",type:"core::starknet::class_hash::ClassHash"},{name:"eic_data",type:"core::option::Option::<src::replaceability_interface::EICData>"},{name:"final",type:"core::bool"}]},{name:"src::replaceability_interface::IReplaceable",type:"interface",items:[{name:"get_upgrade_delay",type:"function",inputs:[],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"get_impl_activation_time",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[{type:"core::integer::u64"}],state_mutability:"view"},{name:"add_new_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"remove_implementation",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"},{name:"replace_to",type:"function",inputs:[{name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}],outputs:[],state_mutability:"external"}]},{name:"AccessControlImplExternal",type:"impl",interface_name:"src::access_control_interface::IAccessControl"},{name:"src::access_control_interface::IAccessControl",type:"interface",items:[{name:"has_role",type:"function",inputs:[{name:"role",type:"core::felt252"},{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"get_role_admin",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[{type:"core::felt252"}],state_mutability:"view"}]},{name:"RolesImpl",type:"impl",interface_name:"src::roles_interface::IMinimalRoles"},{name:"src::roles_interface::IMinimalRoles",type:"interface",items:[{name:"is_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"is_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::bool"}],state_mutability:"view"},{name:"register_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_governance_admin",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"register_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"remove_upgrade_governor",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[],state_mutability:"external"},{name:"renounce",type:"function",inputs:[{name:"role",type:"core::felt252"}],outputs:[],state_mutability:"external"}]},{name:"ERC20Impl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20"},{name:"openzeppelin::token::erc20::interface::IERC20",type:"interface",items:[{name:"name",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"symbol",type:"function",inputs:[],outputs:[{type:"core::felt252"}],state_mutability:"view"},{name:"decimals",type:"function",inputs:[],outputs:[{type:"core::integer::u8"}],state_mutability:"view"},{name:"total_supply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balance_of",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"allowance",type:"function",inputs:[{name:"owner",type:"core::starknet::contract_address::ContractAddress"},{name:"spender",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transfer",type:"function",inputs:[{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"transfer_from",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"approve",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"ERC20CamelOnlyImpl",type:"impl",interface_name:"openzeppelin::token::erc20::interface::IERC20CamelOnly"},{name:"openzeppelin::token::erc20::interface::IERC20CamelOnly",type:"interface",items:[{name:"totalSupply",type:"function",inputs:[],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"balanceOf",type:"function",inputs:[{name:"account",type:"core::starknet::contract_address::ContractAddress"}],outputs:[{type:"core::integer::u256"}],state_mutability:"view"},{name:"transferFrom",type:"function",inputs:[{name:"sender",type:"core::starknet::contract_address::ContractAddress"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"amount",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"name",type:"core::felt252"},{name:"symbol",type:"core::felt252"},{name:"decimals",type:"core::integer::u8"},{name:"initial_supply",type:"core::integer::u256"},{name:"recipient",type:"core::starknet::contract_address::ContractAddress"},{name:"permitted_minter",type:"core::starknet::contract_address::ContractAddress"},{name:"provisional_governance_admin",type:"core::starknet::contract_address::ContractAddress"},{name:"upgrade_delay",type:"core::integer::u64"}]},{name:"increase_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"added_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decrease_allowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtracted_value",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"increaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"addedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{name:"decreaseAllowance",type:"function",inputs:[{name:"spender",type:"core::starknet::contract_address::ContractAddress"},{name:"subtractedValue",type:"core::integer::u256"}],outputs:[{type:"core::bool"}],state_mutability:"external"},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Transfer",type:"event",members:[{kind:"data",name:"from",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"to",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::strk::erc20_lockable::ERC20Lockable::Approval",type:"event",members:[{kind:"data",name:"owner",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"spender",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"value",type:"core::integer::u256"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationAdded",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationRemoved",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationReplaced",type:"event",members:[{kind:"data",name:"implementation_data",type:"src::replaceability_interface::ImplementationData"}]},{kind:"struct",name:"src::replaceability_interface::ImplementationFinalized",type:"event",members:[{kind:"data",name:"impl_hash",type:"core::starknet::class_hash::ClassHash"}]},{kind:"struct",name:"src::access_control_interface::RoleGranted",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleRevoked",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"sender",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::access_control_interface::RoleAdminChanged",type:"event",members:[{kind:"data",name:"role",type:"core::felt252"},{kind:"data",name:"previous_admin_role",type:"core::felt252"},{kind:"data",name:"new_admin_role",type:"core::felt252"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::GovernanceAdminRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorAdded",type:"event",members:[{kind:"data",name:"added_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"added_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"src::roles_interface::UpgradeGovernorRemoved",type:"event",members:[{kind:"data",name:"removed_account",type:"core::starknet::contract_address::ContractAddress"},{kind:"data",name:"removed_by",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"enum",name:"src::strk::erc20_lockable::ERC20Lockable::Event",type:"event",variants:[{kind:"nested",name:"Transfer",type:"src::strk::erc20_lockable::ERC20Lockable::Transfer"},{kind:"nested",name:"Approval",type:"src::strk::erc20_lockable::ERC20Lockable::Approval"},{kind:"nested",name:"ImplementationAdded",type:"src::replaceability_interface::ImplementationAdded"},{kind:"nested",name:"ImplementationRemoved",type:"src::replaceability_interface::ImplementationRemoved"},{kind:"nested",name:"ImplementationReplaced",type:"src::replaceability_interface::ImplementationReplaced"},{kind:"nested",name:"ImplementationFinalized",type:"src::replaceability_interface::ImplementationFinalized"},{kind:"nested",name:"RoleGranted",type:"src::access_control_interface::RoleGranted"},{kind:"nested",name:"RoleRevoked",type:"src::access_control_interface::RoleRevoked"},{kind:"nested",name:"RoleAdminChanged",type:"src::access_control_interface::RoleAdminChanged"},{kind:"nested",name:"GovernanceAdminAdded",type:"src::roles_interface::GovernanceAdminAdded"},{kind:"nested",name:"GovernanceAdminRemoved",type:"src::roles_interface::GovernanceAdminRemoved"},{kind:"nested",name:"UpgradeGovernorAdded",type:"src::roles_interface::UpgradeGovernorAdded"},{kind:"nested",name:"UpgradeGovernorRemoved",type:"src::roles_interface::UpgradeGovernorRemoved"}]}],g_=async(e,t,r,n,i)=>{try{const s=await ka(e.address,t,r,i);if(s.error)return j(s.error);const o=Oe.cairo.uint256(BigInt(Oe.uint256.UINT_256_MAX));if(s.val<n){const a=await e.execute([{contractAddress:rn(t),entrypoint:"approve",calldata:[r,o.low,o.high]}]);await i.waitForTransaction(a.transaction_hash,{retryInterval:3e3,successStates:[Oe.TransactionExecutionStatus.SUCCEEDED]}),await z.sleep(2e3);let c=0n;for(let f=0;f<20;f++){const l=await ka(e.address,t,r,i);if(l.error)return j(l.error);if(c=l.val,c>=n)break;await z.sleep(2e3)}return c<n?j("Allowance not approved"):ie(a.transaction_hash)}return ie("Allowance already approved")}catch(s){return j(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},ka=async(e,t,r,n)=>{try{const s=await new Oe.Contract(Vl,rn(t),n).call("allowance",[rn(e),rn(r)]);return ie(BigInt((s==null?void 0:s.toString())||"0"))}catch(i){return j(`Failed to check allowance: ${i instanceof Error?i.message:String(i)}`)}},w_=async(e,t,r,n,i)=>{const s=await ka(e,t,r,n);return s.error?j(s.error):ie(s.val>=i)},Wl=[{name:"HTLC",type:"impl",interface_name:"starknet_htlc::interface::IHTLC"},{name:"core::integer::u256",type:"struct",members:[{name:"low",type:"core::integer::u128"},{name:"high",type:"core::integer::u128"}]},{name:"starknet_htlc::interface::IHTLC",type:"interface",items:[{name:"token",type:"function",inputs:[],outputs:[{type:"core::starknet::contract_address::ContractAddress"}],state_mutability:"view"},{name:"initiate",type:"function",inputs:[{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_on_behalf",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"}],outputs:[],state_mutability:"external"},{name:"initiate_with_signature",type:"function",inputs:[{name:"initiator",type:"core::starknet::contract_address::ContractAddress"},{name:"redeemer",type:"core::starknet::contract_address::ContractAddress"},{name:"timelock",type:"core::integer::u128"},{name:"amount",type:"core::integer::u256"},{name:"secret_hash",type:"[core::integer::u32; 8]"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"},{name:"redeem",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"secret",type:"core::array::Array::<core::integer::u32>"}],outputs:[],state_mutability:"external"},{name:"refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"}],outputs:[],state_mutability:"external"},{name:"instant_refund",type:"function",inputs:[{name:"order_id",type:"core::felt252"},{name:"signature",type:"core::array::Array::<core::felt252>"}],outputs:[],state_mutability:"external"}]},{name:"constructor",type:"constructor",inputs:[{name:"token",type:"core::starknet::contract_address::ContractAddress"}]},{kind:"struct",name:"starknet_htlc::interface::events::Initiated",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"amount",type:"core::integer::u256"}]},{kind:"struct",name:"starknet_htlc::interface::events::Redeemed",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"},{kind:"data",name:"secret_hash",type:"[core::integer::u32; 8]"},{kind:"data",name:"secret",type:"core::array::Array::<core::integer::u32>"}]},{kind:"struct",name:"starknet_htlc::interface::events::Refunded",type:"event",members:[{kind:"key",name:"order_id",type:"core::felt252"}]},{kind:"enum",name:"starknet_htlc::htlc::HTLC::Event",type:"event",variants:[{kind:"nested",name:"Initiated",type:"starknet_htlc::interface::events::Initiated"},{kind:"nested",name:"Redeemed",type:"starknet_htlc::interface::events::Redeemed"},{kind:"nested",name:"Refunded",type:"starknet_htlc::interface::events::Refunded"}]}],__={StarknetDomain:[{name:"name",type:"shortstring"},{name:"version",type:"shortstring"},{name:"chainId",type:"shortstring"},{name:"revision",type:"shortstring"}],Initiate:[{name:"redeemer",type:"ContractAddress"},{name:"amount",type:"u256"},{name:"timelock",type:"u128"},{name:"secretHash",type:"u128*"}]};class Kl{constructor(t,r,n,i){this.url=t instanceof z.Url?t:new z.Url(t),this.account=r,this.starknetProvider=new Oe.RpcProvider({nodeUrl:i||_s[n].nodeUrl})}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async getChainId(){try{const t=await this.account.getChainId();return ie(t)}catch(t){return j(String(t))}}async initiate(t){if(!this.account.address)return j("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return j("Invalid order");try{const o=new Oe.Contract(Wl,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),c=Oe.num.toHex(a),f=await w_(this.account.address,c,n.asset,this.starknetProvider,BigInt(s));return f.error?j(f.error):f.val?this.initiateRelay(t):this.approveAndInitiate(c,t)}catch(o){return j(String(o))}}async approveAndInitiate(t,r){const{create_order:n,source_swap:i}=r,{redeemer:s,amount:o}=i,{secret_hash:a,timelock:c}=n,f=i.asset;try{const l=Oe.cairo.uint256(BigInt(Oe.uint256.UINT_256_MAX)),h={contractAddress:rn(t),entrypoint:"approve",calldata:[f,l.low,l.high]},m=Oe.cairo.uint256(o),p={contractAddress:rn(f),entrypoint:"initiate",calldata:[s,c.toString(),m.low.toString(),m.high.toString(),...z.hexToU32Array(a)]},g=await this.account.execute([h,p]);return await this.starknetProvider.waitForTransaction(g.transaction_hash,{retryInterval:2e3,successStates:[Oe.TransactionExecutionStatus.SUCCEEDED]}),ie(g.transaction_hash)}catch(l){return j(`Failed to approve and initiate: ${String(l)}`)}}async initiateRelay(t){const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n,o=await this.getChainId();if(o.error)return j(o.error);const c={domain:{name:"HTLC",version:Oe.shortString.encodeShortString("1"),chainId:o.val,revision:Oe.TypedDataRevision.ACTIVE},primaryType:"Initiate",types:__,message:{redeemer:i,amount:Oe.cairo.uint256(s),timelock:r.timelock,secretHash:z.hexToU32Array(r.secret_hash)}};try{const f=await this.account.signMessage(c),l=nb(f);if(l.error)return j(l.error);const h=await Dt.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:l.val,perform_on:"Source"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return h.error?j(h.error):h.result?ie(h.result):j("Init: No result found")}catch(f){return j(`Failed to initiate relayer: ${String(f)}`)}}async redeem(t,r){try{const n=await Dt.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return n.error?j(n.error):n.result?ie(n.result):j("Redeem: No result found")}catch(n){return j(String(n))}}async refund(){return j("Refund is taken care of by the relayer")}}class Pc extends z.EventBroker{constructor(t){if(super(),this.environment=z.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new u1,typeof t.digestKey=="string"){const n=z.DigestKey.from(t.digestKey);if(!n.ok)throw new Error(n.error);this._digestKey=n.val}else this._digestKey=t.digestKey;if(typeof t.environment=="string"){if(this.environment=t.environment,this._api=t.environment===z.Environment.MAINNET?Vn.mainnet:t.environment===z.Environment.TESTNET?Vn.testnet:void 0,!this._api)throw new Error("API not found, invalid environment "+t.environment)}else this._api=t.environment;this._quote=t.quote??new nl(this._api.quote),this._auth=t.auth??z.Siwe.fromDigestKey(new z.Url(this._api.auth),this._digestKey),this._orderbook=t.orderbook??new ge.Orderbook(new z.Url(this._api.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._secretManager=t.secretManager??Si.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new c1,this._blockNumberFetcher=t.blockNumberFetcher??new rl(this._api.info,this.environment);const r=new fn.BitcoinProvider(tb(this.environment));this._btcWallet=fn.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,r)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const s=z.DigestKey.from(t.digestKey);if(!s.ok)throw new Error(s.error);r=s.val}else r=t.digestKey;let n;if(typeof t.environment=="string"?n=t.environment===z.Environment.MAINNET?Vn.mainnet:t.environment===z.Environment.TESTNET?Vn.testnet:void 0:n=t.environment,!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new ql(n.evmRelay,t.wallets.evm,z.Siwe.fromDigestKey(new z.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new Kl(n.starknetRelay,t.wallets.starknet,t.environment===z.Environment.MAINNET?z.Network.MAINNET:z.Network.TESTNET):void 0};return new Pc({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return j(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val,o=Date.now().toString(),a=await this._secretManager.generateSecret(o);if(a.error)return j(a.error);const{strategyId:c,btcAddress:f}=t.additionalData,l={strategy_id:c,...f&&{bitcoin_optional_recipient:f}},h={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o,timelock:s,secret_hash:Pr(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:l},m=await this._quote.getAttestedQuote(h);if(m.error)return j(m.error);const p=await this._orderbook.createOrder(m.val,this.auth);if(p.error)return j(p.error);const g=await this.pollOrder(p.val);return g.error?j(g.error):ie(g.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(ge.isMainnet(t.fromAsset.chain)&&!ge.isMainnet(t.toAsset.chain)||!ge.isMainnet(t.fromAsset.chain)&&ge.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=ge.getTimeLock(t.fromAsset.chain);if(!i)return j("Unsupported chain for timelock");if((ge.isBitcoin(t.fromAsset.chain)||ge.isBitcoin(t.toAsset.chain))&&!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 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):ie({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(ge.getBlockchainType(t)){case ge.BlockchainType.EVM:return this._evmHTLC?ie(this._evmHTLC.htlcActorAddress):j("Please provide evmHTLC when initializing garden");case ge.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!Zm(i)?j("Invalid btc public key"):ie(cr(i))}case ge.BlockchainType.Starknet:return this._starknetHTLC?ie(this._starknetHTLC.htlcActorAddress):j("Please provide starknetHTLC when initializing garden");default:return j("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return j("Invalid amount ",t);const r=new Ql(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?j("Invalid amount ",t):ie(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return j(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return ie(r.val);r=await this._orderbook.getOrder(t,!0)}return j(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error&&(this.emit("onPendingOrdersChanged",n.val),r.data.length!==0))for(let i=0;i<n.val.length;i++){const s=n.val[i],o=cc(s.status);if(ge.isBitcoin(s.source_swap.chain)&&s.status===we.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Ce.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(ge.getBlockchainType(s.destination_swap.chain)){case ge.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case ge.BlockchainType.Bitcoin:{const c=this.btcWallet;if(!c){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(c,s,a.val.secret);break}case ge.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Ce.Refund:{switch(ge.getBlockchainType(s.source_swap.chain)){case ge.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case ge.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case ge.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}},"pending",{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(!i.ok){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ce.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Ce.Redeem,i.val),this.emit("success",t,Ce.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Ce.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Ce.Redeem,i.val),this.emit("success",t,Ce.Redeem,i.val))}async btcRedeem(t,r,n){var a,c;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const f=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let l=!1;for(const h of f.vin)if(h.txid===s){l=!0;break}if(l){this.emit("log",r.create_order.create_id,"already a valid redeem");let h=0;try{const[m]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);m!==0&&(h=m)}catch{h=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:h,redeemTxHash:r.destination_swap.redeem_tx_hash});return}o=!0}catch(f){if(f.message.includes("Transaction not found"))o=!0;else{this.emit("error",r,"Failed to get redeem tx: "+f);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const l=await(await Yn.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,cr(r.destination_swap.initiator),cr(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(Pr(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient),h=await this.broadcastRedeemTx(l,r.create_order.create_id);if(h.error||!h.val){this.emit("error",r,h.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,h.val)):this.emit("success",r,Ce.Redeem,h.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:h.val})}catch(f){console.log("error",f),this.emit("error",r,"Failed btc redeem: "+f)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Ce.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await Yn.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,cr(r.source_swap.initiator),cr(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,Ce.Refund,s),this.emit("success",r,Ce.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await Yn.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,cr(t.source_swap.initiator),cr(t.source_swap.redeemer),t.source_swap.timelock),s=t.create_order.additional_data.bitcoin_optional_recipient;if(s)try{const o=await i.generateInstantRefundSACP(s);if(!this._api)return;const a=new z.Url(this._api.orderbook).endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await Dt.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:o})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(o){this.emit("error",t,"Failed to generate and post SACP: "+o);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return ie([]);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(Od(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,f=r==null?void 0:r.val[a],l=r==null?void 0:r.val[c];if(!f||!l){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const h=ac(o,f,l);n.push({...o,status:h})}return ie(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return j("API not found");const n=new z.Url(this._api.evmRelay).endpoint("/bitcoin/redeem "),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?ie(o.result):j(o.error)}catch(n){return j("Failed to broadcast redeem tx: "+n)}}}class v_{constructor(t,r,n){this.callData=new Oe.CallData(Vl),this.account=t,this.starknetProvider=new Oe.RpcProvider({nodeUrl:r||(n?_s[n].nodeUrl:_s.mainnet.nodeUrl)})}get htlcActorAddress(){return this.account.address}async getHTLCContract(t,r=!1){const n=r?t.destination_swap.asset:t.source_swap.asset;return new Oe.Contract(Wl,n,this.account)}async initiate(t){try{const n=await(await this.getHTLCContract(t)).token();if(!n)throw new Error("Token address retrieval failed");const i=Oe.num.toHex(n),s=Oe.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await g_(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.starknetProvider);if(a.error)return j(a.error)}catch(a){return j(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return ie(o.transaction_hash)}catch(r){return j(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:Oe.CallData.compile({swap_id:i,secret:z.hexToU32Array(r)})});return s.transaction_hash?ie(s.transaction_hash):j("Failed to redeem HTLC transaction")}catch{return j("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?ie(i.transaction_hash):j("Failed to refund HTLC transaction")}catch{return j("HTLC Refund Error")}}}exports.API=Vn;exports.AbiErrorInputsNotFoundError=Yh;exports.AbiErrorNotFoundError=Xh;exports.AbiFunctionNotFoundError=Xn;exports.AbiFunctionOutputsNotFoundError=vf;exports.AbiFunctionSignatureNotFoundError=Qh;exports.BaseError=$;exports.BlockNumberFetcher=rl;exports.EvmRelay=ql;exports.Garden=Pc;exports.Hash=Oa;exports.HttpRequestError=Da;exports.InvalidArrayError=Ef;exports.OrderActions=Ce;exports.OrderStatus=we;exports.ParseOrderStatus=ac;exports.ParseSwapStatus=ya;exports.Quote=nl;exports.STARKNET_CONFIG=_s;exports.SecretManager=Si;exports.StarknetHTLC=v_;exports.StarknetRelay=Kl;exports.SwapStatus=xe;exports.abytes=Ti;exports.aexists=Jn;exports.ahash=p0;exports.batchGatewayAbi=py;exports.call=ec;exports.concat=Rr;exports.concatBytes=A0;exports.concatHex=Ct;exports.constructOrderPair=Cd;exports.decodeAbiParameters=Ii;exports.decodeErrorResult=jf;exports.encodeAbiParameters=Cs;exports.evmToViemChainMap=Gl;exports.filterDeadlineExpiredOrders=sb;exports.formatAbiItem=kt;exports.getAbiItem=En;exports.getUrl=Ha;exports.hyperliquid=jl;exports.hyperliquidTestnet=Dl;exports.isAddressEqual=Ja;exports.isExpired=vi;exports.isHex=zt;exports.parseAction=ib;exports.parseActionFromStatus=cc;exports.randomBytes=S0;exports.sha256=td;exports.slice=dn;exports.solidityError=Hf;exports.stringify=It;exports.switchOrAddNetwork=zl;exports.toBytes=ks;exports.toFunctionSelector=Os;exports.toXOnly=cr;exports.validateBTCAddress=eb;
|