@gardenfi/core 2.1.5-beta.1 → 2.1.5-beta.2

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.
@@ -1,81 +0,0 @@
1
- "use strict";var cy=Object.defineProperty;var uy=(e,t,r)=>t in e?cy(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var cn=(e,t,r)=>uy(e,typeof t!="symbol"?t+"":t,r);const N=require("@catalogfi/utils"),we=require("@gardenfi/orderbook"),Z=require("@gardenfi/utils"),Gr=require("@catalogfi/wallets"),Td=require("varuint-bitcoin"),fy=require("tiny-secp256k1"),Id=require("bitcoinjs-lib"),ly=require("bignumber.js"),De=require("starknet"),jr=require("@coral-xyz/anchor");function Zc(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 Yu=Zc(Td),Kr=Zc(fy),Ee=Zc(Id);var Re=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Re||{});const dy="1.0.8";let Ot=class mc extends Error{constructor(t,r={}){var s;const n=r.cause instanceof mc?r.cause.details:(s=r.cause)!=null&&s.message?r.cause.message:r.details,i=r.cause instanceof mc&&r.cause.docsPath||r.docsPath,o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...i?[`Docs: https://abitype.dev${i}`]:[],...n?[`Details: ${n}`]:[],`Version: abitype@${dy}`].join(`
2
- `);super(o),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 br(e,t){const r=e.exec(t);return r==null?void 0:r.groups}const Bd=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,kd=/^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)?$/,Od=/^\(.+?\).*?$/,Xu=/^tuple(?<array>(\[(\d*)\])*)$/;function gc(e){let t=e.type;if(Xu.test(e.type)&&"components"in e){t="(";const r=e.components.length;for(let i=0;i<r;i++){const o=e.components[i];t+=gc(o),i<r-1&&(t+=", ")}const n=br(Xu,e.type);return t+=`)${(n==null?void 0:n.array)??""}`,gc({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Vn(e){let t="";const r=e.length;for(let n=0;n<r;n++){const i=e[n];t+=gc(i),n!==r-1&&(t+=", ")}return t}function hy(e){var t;return e.type==="function"?`function ${e.name}(${Vn(e.inputs)})${e.stateMutability&&e.stateMutability!=="nonpayable"?` ${e.stateMutability}`:""}${(t=e.outputs)!=null&&t.length?` returns (${Vn(e.outputs)})`:""}`:e.type==="event"?`event ${e.name}(${Vn(e.inputs)})`:e.type==="error"?`error ${e.name}(${Vn(e.inputs)})`:e.type==="constructor"?`constructor(${Vn(e.inputs)})${e.stateMutability==="payable"?" payable":""}`:e.type==="fallback"?`fallback() external${e.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const Rd=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function py(e){return Rd.test(e)}function yy(e){return br(Rd,e)}const Cd=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function by(e){return Cd.test(e)}function my(e){return br(Cd,e)}const Fd=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function gy(e){return Fd.test(e)}function wy(e){return br(Fd,e)}const Nd=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function Ud(e){return Nd.test(e)}function vy(e){return br(Nd,e)}const Ld=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function _y(e){return Ld.test(e)}function Ey(e){return br(Ld,e)}const Hd=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function xy(e){return Hd.test(e)}function Ay(e){return br(Hd,e)}const Sy=/^receive\(\) external payable$/;function Py(e){return Sy.test(e)}const Ty=new Set(["indexed"]),wc=new Set(["calldata","memory","storage"]);class Iy extends Ot{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 By extends Ot{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 ky extends Ot{constructor({param:t}){super("Invalid ABI parameter.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class Oy extends Ot{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 Ry extends Ot{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 Cy extends Ot{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 Fy extends Ot{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 $n extends Ot{constructor({signature:t,type:r}){super(`Invalid ${r} signature.`,{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class Ny extends Ot{constructor({signature:t}){super("Unknown signature.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class Uy extends Ot{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 Ly extends Ot{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 Hy extends Ot{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 $y(e,t,r){let n="";if(r)for(const i of Object.entries(r)){if(!i)continue;let o="";for(const s of i[1])o+=`[${s.type}${s.name?`:${s.name}`:""}]`;n+=`(${i[0]}{${o}})`}return t?`${t}:${e}${n}`:e}const Cs=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 My(e,t={}){if(gy(e))return Dy(e,t);if(by(e))return jy(e,t);if(py(e))return qy(e,t);if(_y(e))return Gy(e,t);if(xy(e))return zy(e);if(Py(e))return{type:"receive",stateMutability:"payable"};throw new Ny({signature:e})}function Dy(e,t={}){const r=wy(e);if(!r)throw new $n({signature:e,type:"function"});const n=Ft(r.parameters),i=[],o=n.length;for(let a=0;a<o;a++)i.push(Yr(n[a],{modifiers:wc,structs:t,type:"function"}));const s=[];if(r.returns){const a=Ft(r.returns),c=a.length;for(let u=0;u<c;u++)s.push(Yr(a[u],{modifiers:wc,structs:t,type:"function"}))}return{name:r.name,type:"function",stateMutability:r.stateMutability??"nonpayable",inputs:i,outputs:s}}function jy(e,t={}){const r=my(e);if(!r)throw new $n({signature:e,type:"event"});const n=Ft(r.parameters),i=[],o=n.length;for(let s=0;s<o;s++)i.push(Yr(n[s],{modifiers:Ty,structs:t,type:"event"}));return{name:r.name,type:"event",inputs:i}}function qy(e,t={}){const r=yy(e);if(!r)throw new $n({signature:e,type:"error"});const n=Ft(r.parameters),i=[],o=n.length;for(let s=0;s<o;s++)i.push(Yr(n[s],{structs:t,type:"error"}));return{name:r.name,type:"error",inputs:i}}function Gy(e,t={}){const r=Ey(e);if(!r)throw new $n({signature:e,type:"constructor"});const n=Ft(r.parameters),i=[],o=n.length;for(let s=0;s<o;s++)i.push(Yr(n[s],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:r.stateMutability??"nonpayable",inputs:i}}function zy(e){const t=Ay(e);if(!t)throw new $n({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}const Vy=/^(?<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$_]*))?$/,Wy=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Ky=/^u?int$/;function Yr(e,t){var h,y;const r=$y(e,t==null?void 0:t.type,t==null?void 0:t.structs);if(Cs.has(r))return Cs.get(r);const n=Od.test(e),i=br(n?Wy:Vy,e);if(!i)throw new ky({param:e});if(i.name&&Xy(i.name))throw new Oy({param:e,name:i.name});const o=i.name?{name:i.name}:{},s=i.modifier==="indexed"?{indexed:!0}:{},a=(t==null?void 0:t.structs)??{};let c,u={};if(n){c="tuple";const p=Ft(i.type),m=[],g=p.length;for(let A=0;A<g;A++)m.push(Yr(p[A],{structs:a}));u={components:m}}else if(i.type in a)c="tuple",u={components:a[i.type]};else if(Ky.test(i.type))c=`${i.type}256`;else if(c=i.type,(t==null?void 0:t.type)!=="struct"&&!$d(c))throw new By({type:c});if(i.modifier){if(!((y=(h=t==null?void 0:t.modifiers)==null?void 0:h.has)!=null&&y.call(h,i.modifier)))throw new Ry({param:e,type:t==null?void 0:t.type,modifier:i.modifier});if(wc.has(i.modifier)&&!Jy(c,!!i.array))throw new Cy({param:e,type:t==null?void 0:t.type,modifier:i.modifier})}const f={type:`${c}${i.array??""}`,...o,...s,...u};return Cs.set(r,f),f}function Ft(e,t=[],r="",n=0){const i=e.trim().length;for(let o=0;o<i;o++){const s=e[o],a=e.slice(o+1);switch(s){case",":return n===0?Ft(a,[...t,r.trim()]):Ft(a,t,`${r}${s}`,n);case"(":return Ft(a,t,`${r}${s}`,n+1);case")":return Ft(a,t,`${r}${s}`,n-1);default:return Ft(a,t,`${r}${s}`,n)}}if(r==="")return t;if(n!==0)throw new Hy({current:r,depth:n});return t.push(r.trim()),t}function $d(e){return e==="address"||e==="bool"||e==="function"||e==="string"||Bd.test(e)||kd.test(e)}const Yy=/^(?: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 Xy(e){return e==="address"||e==="bool"||e==="function"||e==="string"||e==="tuple"||Bd.test(e)||kd.test(e)||Yy.test(e)}function Jy(e,t){return t||e==="bytes"||e==="string"||e==="tuple"}function Zy(e){const t={},r=e.length;for(let s=0;s<r;s++){const a=e[s];if(!Ud(a))continue;const c=vy(a);if(!c)throw new $n({signature:a,type:"struct"});const u=c.properties.split(";"),f=[],h=u.length;for(let y=0;y<h;y++){const m=u[y].trim();if(!m)continue;const g=Yr(m,{type:"struct"});f.push(g)}if(!f.length)throw new Uy({signature:a});t[c.name]=f}const n={},i=Object.entries(t),o=i.length;for(let s=0;s<o;s++){const[a,c]=i[s];n[a]=Md(c,t)}return n}const Qy=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function Md(e,t,r=new Set){const n=[],i=e.length;for(let o=0;o<i;o++){const s=e[o];if(Od.test(s.type))n.push(s);else{const c=br(Qy,s.type);if(!(c!=null&&c.type))throw new Fy({abiParameter:s});const{array:u,type:f}=c;if(f in t){if(r.has(f))throw new Ly({type:f});n.push({...s,type:`tuple${u??""}`,components:Md(t[f]??[],t,new Set([...r,f]))})}else if($d(f))n.push(s);else throw new Iy({type:f})}}return n}function Dd(e){const t=Zy(e),r=[],n=e.length;for(let i=0;i<n;i++){const o=e[i];Ud(o)||r.push(My(o,t))}return r}function ve(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const i=e[r];return typeof i=="function"?i:o=>t(e,o)}function Yt(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new hb(e.type);return`${e.name}(${Wo(e.inputs,{includeName:t})})`}function Wo(e,{includeName:t=!1}={}){return e?e.map(r=>eb(r,{includeName:t})).join(t?", ":","):""}function eb(e,{includeName:t}){return e.type.startsWith("tuple")?`(${Wo(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}function fr(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Le(e){return fr(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const jd="2.29.2";let Wn={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${jd}`},z=class vc extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof vc?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof vc&&r.cause.docsPath||r.docsPath,o=(a=Wn.getDocsUrl)==null?void 0:a.call(Wn,{...r,docsPath:i}),s=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...o?[`Docs: ${o}`]:[],...n?[`Details: ${n}`]:[],...Wn.version?[`Version: ${Wn.version}`]:[]].join(`
3
- `);super(s,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=jd}walk(t){return qd(this,t)}};function qd(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?qd(e.cause,t):t?null:e}class tb extends z{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 Ju extends z{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
- `),{docsPath:t,name:"AbiConstructorParamsNotFoundError"})}}class Gd extends z{constructor({data:t,params:r,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join(`
6
- `),{metaMessages:[`Params: (${Wo(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 Qc extends z{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class rb extends z{constructor({expectedLength:t,givenLength:r,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${t}`,`Given length: ${r}`].join(`
7
- `),{name:"AbiEncodingArrayLengthMismatchError"})}}class nb extends z{constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${Le(r)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class ib extends z{constructor({expectedLength:t,givenLength:r}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${t}`,`Given length (values): ${r}`].join(`
8
- `),{name:"AbiEncodingLengthMismatchError"})}}class ob extends z{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
- `),{docsPath:r,name:"AbiErrorInputsNotFoundError"})}}class sb extends z{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
- `),{docsPath:r,name:"AbiErrorNotFoundError"})}}class zd extends z{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
- `),{docsPath:r,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=t}}class ab extends z{constructor({docsPath:t}){super("Cannot extract event signature from empty topics.",{docsPath:t,name:"AbiEventSignatureEmptyTopicsError"})}}class Vd extends z{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 Zu extends z{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
- `),{docsPath:r,name:"AbiEventNotFoundError"})}}class di extends z{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
- `),{docsPath:r,name:"AbiFunctionNotFoundError"})}}class Wd extends z{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
- `),{docsPath:r,name:"AbiFunctionOutputsNotFoundError"})}}class cb extends z{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
- `),{docsPath:r,name:"AbiFunctionSignatureNotFoundError"})}}class ub extends z{constructor(t,r){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${t.type}\` in \`${Yt(t.abiItem)}\`, and`,`\`${r.type}\` in \`${Yt(r.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class fb extends z{constructor({expectedSize:t,givenSize:r}){super(`Expected bytes${t}, got bytes${r}.`,{name:"BytesSizeMismatchError"})}}class No extends z{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: (${Wo(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 eu extends z{constructor({abiItem:t,param:r}){super([`Expected a topic for indexed event parameter${r.name?` "${r.name}"`:""} on event "${Yt(t,{includeName:!0})}".`].join(`
18
- `),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t}}class lb extends z{constructor(t,{docsPath:r}){super([`Type "${t}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(`
19
- `),{docsPath:r,name:"InvalidAbiEncodingType"})}}class db extends z{constructor(t,{docsPath:r}){super([`Type "${t}" is not a valid decoding type.`,"Please provide a valid ABI type."].join(`
20
- `),{docsPath:r,name:"InvalidAbiDecodingType"})}}class Kd extends z{constructor(t){super([`Value "${t}" is not a valid array.`].join(`
21
- `),{name:"InvalidArrayError"})}}class hb extends z{constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(`
22
- `),{name:"InvalidDefinitionTypeError"})}}class pb extends z{constructor(t){super(`Filter type "${t}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}class Yd extends z{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}let Xd=class extends z{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 Qu extends z{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 Mn(e,{dir:t,size:r=32}={}){return typeof e=="string"?Br(e,{dir:t,size:r}):yb(e,{dir:t,size:r})}function Br(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Xd({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function yb(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Xd({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const o=t==="right";n[o?i:r-i-1]=e[o?i:e.length-i-1]}return n}let Jd=class extends z{constructor({max:t,min:r,signed:n,size:i,value:o}){super(`Number "${o}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}};class bb extends z{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 mb extends z{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function Xr(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 Xt(e,{size:t}){if(Le(e)>t)throw new mb({givenSize:Le(e),maxSize:t})}function kt(e,t={}){const{signed:r}=t;t.size&&Xt(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,o=(1n<<BigInt(i)*8n-1n)-1n;return n<=o?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function lr(e,t={}){return Number(kt(e,t))}const gb=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ue(e,t={}){return typeof e=="number"||typeof e=="bigint"?fe(e,t):typeof e=="string"?Ko(e,t):typeof e=="boolean"?Zd(e,t):yt(e,t)}function Zd(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Xt(r,{size:t.size}),Mn(r,{size:t.size})):r}function yt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=gb[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Xt(n,{size:t.size}),Mn(n,{dir:"right",size:t.size})):n}function fe(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let o;n?r?o=(1n<<BigInt(n)*8n-1n)-1n:o=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(o=BigInt(Number.MAX_SAFE_INTEGER));const s=typeof o=="bigint"&&r?-o-1n:0;if(o&&i>o||i<s){const c=typeof e=="bigint"?"n":"";throw new Jd({max:o?`${o}${c}`:void 0,min:`${s}${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?Mn(a,{size:n}):a}const wb=new TextEncoder;function Ko(e,t={}){const r=wb.encode(e);return yt(r,t)}const vb=new TextEncoder;function Gi(e,t={}){return typeof e=="number"||typeof e=="bigint"?Eb(e,t):typeof e=="boolean"?_b(e,t):fr(e)?dr(e,t):Qd(e,t)}function _b(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Xt(r,{size:t.size}),Mn(r,{size:t.size})):r}const Qt={zero:48,nine:57,A:65,F:70,a:97,f:102};function ef(e){if(e>=Qt.zero&&e<=Qt.nine)return e-Qt.zero;if(e>=Qt.A&&e<=Qt.F)return e-(Qt.A-10);if(e>=Qt.a&&e<=Qt.f)return e-(Qt.a-10)}function dr(e,t={}){let r=e;t.size&&(Xt(r,{size:t.size}),r=Mn(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,o=new Uint8Array(i);for(let s=0,a=0;s<i;s++){const c=ef(n.charCodeAt(a++)),u=ef(n.charCodeAt(a++));if(c===void 0||u===void 0)throw new z(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);o[s]=c*16+u}return o}function Eb(e,t){const r=fe(e,t);return dr(r)}function Qd(e,t={}){const r=vb.encode(e);return typeof t.size=="number"?(Xt(r,{size:t.size}),Mn(r,{dir:"right",size:t.size})):r}function Uo(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function xb(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function zi(e,...t){if(!xb(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 Ab(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Uo(e.outputLen),Uo(e.blockLen)}function hi(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 eh(e,t){zi(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const fo=BigInt(2**32-1),tf=BigInt(32);function Sb(e,t=!1){return t?{h:Number(e&fo),l:Number(e>>tf&fo)}:{h:Number(e>>tf&fo)|0,l:Number(e&fo)|0}}function Pb(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:o,l:s}=Sb(e[i],t);[r[i],n[i]]=[o,s]}return[r,n]}const Tb=(e,t,r)=>e<<r|t>>>32-r,Ib=(e,t,r)=>t<<r|e>>>32-r,Bb=(e,t,r)=>t<<r-32|e>>>64-r,kb=(e,t,r)=>e<<r-32|t>>>64-r,un=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ob(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Fs(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function $t(e,t){return e<<32-t|e>>>t}const rf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Rb(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function nf(e){for(let t=0;t<e.length;t++)e[t]=Rb(e[t])}typeof Uint8Array.from([]).toHex=="function"&&Uint8Array.fromHex;function Cb(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function Yo(e){return typeof e=="string"&&(e=Cb(e)),zi(e),e}function Fb(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];zi(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const o=e[n];r.set(o,i),i+=o.length}return r}let tu=class{clone(){return this._cloneInto()}};function th(e){const t=n=>e().update(Yo(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Nb(e=32){if(un&&typeof un.getRandomValues=="function")return un.getRandomValues(new Uint8Array(e));if(un&&typeof un.randomBytes=="function")return Uint8Array.from(un.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const rh=[],nh=[],ih=[],Ub=BigInt(0),Kn=BigInt(1),Lb=BigInt(2),Hb=BigInt(7),$b=BigInt(256),Mb=BigInt(113);for(let e=0,t=Kn,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],rh.push(2*(5*n+r)),nh.push((e+1)*(e+2)/2%64);let i=Ub;for(let o=0;o<7;o++)t=(t<<Kn^(t>>Hb)*Mb)%$b,t&Lb&&(i^=Kn<<(Kn<<BigInt(o))-Kn);ih.push(i)}const[Db,jb]=Pb(ih,!0),of=(e,t,r)=>r>32?Bb(e,t,r):Tb(e,t,r),sf=(e,t,r)=>r>32?kb(e,t,r):Ib(e,t,r);function qb(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let s=0;s<10;s++)r[s]=e[s]^e[s+10]^e[s+20]^e[s+30]^e[s+40];for(let s=0;s<10;s+=2){const a=(s+8)%10,c=(s+2)%10,u=r[c],f=r[c+1],h=of(u,f,1)^r[a],y=sf(u,f,1)^r[a+1];for(let p=0;p<50;p+=10)e[s+p]^=h,e[s+p+1]^=y}let i=e[2],o=e[3];for(let s=0;s<24;s++){const a=nh[s],c=of(i,o,a),u=sf(i,o,a),f=rh[s];i=e[f],o=e[f+1],e[f]=c,e[f+1]=u}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)r[a]=e[s+a];for(let a=0;a<10;a++)e[s+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=Db[n],e[1]^=jb[n]}r.fill(0)}class ru extends tu{constructor(t,r,n,i=!1,o=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=o,Uo(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Ob(this.state)}keccak(){rf||nf(this.state32),qb(this.state32,this.rounds),rf||nf(this.state32),this.posOut=0,this.pos=0}update(t){hi(this);const{blockLen:r,state:n}=this;t=Yo(t);const i=t.length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);for(let a=0;a<s;a++)n[this.pos++]^=t[o++];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){hi(this,!1),zi(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,o=t.length;i<o;){this.posOut>=n&&this.keccak();const s=Math.min(n-this.posOut,o-i);t.set(r.subarray(this.posOut,this.posOut+s),i),this.posOut+=s,i+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Uo(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(eh(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:o,enableXOF:s}=this;return t||(t=new ru(r,n,i,s,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=n,t.outputLen=i,t.enableXOF=s,t.destroyed=this.destroyed,t}}const Gb=(e,t,r)=>th(()=>new ru(t,e,r)),zb=Gb(1,136,256/8);function Dn(e,t){const r=t||"hex",n=zb(fr(e,{strict:!1})?Gi(e):e);return r==="bytes"?n:ue(n)}const Vb=e=>Dn(Gi(e));function Wb(e){return Vb(e)}function Kb(e){let t=!0,r="",n=0,i="",o=!1;for(let s=0;s<e.length;s++){const a=e[s];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===")"){o=!0;break}continue}if(a===" "){e[s-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!o)throw new z("Unable to normalize signature.");return i}const Yb=e=>{const t=typeof e=="string"?e:hy(e);return Kb(t)};function oh(e){return Wb(Yb(e))}const Xo=oh;class bt extends z{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 Jo 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 Ns=new Jo(8192);function Vi(e,t){if(Ns.has(`${e}.${t}`))return Ns.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Dn(Qd(r),"bytes"),i=r.split("");for(let s=0;s<40;s+=2)n[s>>1]>>4>=8&&i[s]&&(i[s]=i[s].toUpperCase()),(n[s>>1]&15)>=8&&i[s+1]&&(i[s+1]=i[s+1].toUpperCase());const o=`0x${i.join("")}`;return Ns.set(`${e}.${t}`,o),o}function Xb(e,t){if(!ze(e,{strict:!1}))throw new bt({address:e});return Vi(e,t)}const Jb=/^0x[a-fA-F0-9]{40}$/,Us=new Jo(8192);function ze(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Us.has(n))return Us.get(n);const i=Jb.test(e)?e.toLowerCase()===e?!0:r?Vi(e)===e:!0:!1;return Us.set(n,i),i}function Jr(e){return typeof e[0]=="string"?Jt(e):Zb(e)}function Zb(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 Jt(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function Pn(e,t,r,{strict:n}={}){return fr(e,{strict:!1})?Qb(e,t,r,{strict:n}):ch(e,t,r,{strict:n})}function sh(e,t){if(typeof t=="number"&&t>0&&t>Le(e)-1)throw new Yd({offset:t,position:"start",size:Le(e)})}function ah(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Le(e)!==r-t)throw new Yd({offset:r,position:"end",size:Le(e)})}function ch(e,t,r,{strict:n}={}){sh(e,t);const i=e.slice(t,r);return n&&ah(i,t,r),i}function Qb(e,t,r,{strict:n}={}){sh(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return n&&ah(i,t,r),i}const em=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,uh=/^(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 Zo(e,t){if(e.length!==t.length)throw new ib({expectedLength:e.length,givenLength:t.length});const r=tm({params:e,values:t}),n=iu(r);return n.length===0?"0x":n}function tm({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(nu({param:e[n],value:t[n]}));return r}function nu({param:e,value:t}){const r=ou(e.type);if(r){const[n,i]=r;return nm(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return cm(t,{param:e});if(e.type==="address")return rm(t);if(e.type==="bool")return om(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=uh.exec(e.type)??[];return sm(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return im(t,{param:e});if(e.type==="string")return am(t);throw new lb(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function iu(e){let t=0;for(let o=0;o<e.length;o++){const{dynamic:s,encoded:a}=e[o];s?t+=32:t+=Le(a)}const r=[],n=[];let i=0;for(let o=0;o<e.length;o++){const{dynamic:s,encoded:a}=e[o];s?(r.push(fe(t+i,{size:32})),n.push(a),i+=Le(a)):r.push(a)}return Jr([...r,...n])}function rm(e){if(!ze(e))throw new bt({address:e});return{dynamic:!1,encoded:Br(e.toLowerCase())}}function nm(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new Kd(e);if(!n&&e.length!==t)throw new rb({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const o=[];for(let s=0;s<e.length;s++){const a=nu({param:r,value:e[s]});a.dynamic&&(i=!0),o.push(a)}if(n||i){const s=iu(o);if(n){const a=fe(o.length,{size:32});return{dynamic:!0,encoded:o.length>0?Jr([a,s]):a}}if(i)return{dynamic:!0,encoded:s}}return{dynamic:!1,encoded:Jr(o.map(({encoded:s})=>s))}}function im(e,{param:t}){const[,r]=t.type.split("bytes"),n=Le(e);if(!r){let i=e;return n%32!==0&&(i=Br(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:Jr([Br(fe(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new nb({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:Br(e,{dir:"right"})}}function om(e){if(typeof e!="boolean")throw new z(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:Br(Zd(e))}}function sm(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 Jd({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:fe(e,{size:32,signed:t})}}function am(e){const t=Ko(e),r=Math.ceil(Le(t)/32),n=[];for(let i=0;i<r;i++)n.push(Br(Pn(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:Jr([Br(fe(Le(t),{size:32})),...n])}}function cm(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const o=t.components[i],s=Array.isArray(e)?i:o.name,a=nu({param:o,value:e[s]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?iu(n):Jr(n.map(({encoded:i})=>i))}}function ou(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Qo=e=>Pn(oh(e),0,4);function jn(e){const{abi:t,args:r=[],name:n}=e,i=fr(n,{strict:!1}),o=t.filter(a=>i?a.type==="function"?Qo(a)===n:a.type==="event"?Xo(a)===n:!1:"name"in a&&a.name===n);if(o.length===0)return;if(o.length===1)return o[0];let s;for(const a of o){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((u,f)=>{const h="inputs"in a&&a.inputs[f];return h?_c(u,h):!1})){if(s&&"inputs"in s&&s.inputs){const u=fh(a.inputs,s.inputs,r);if(u)throw new ub({abiItem:a,type:u[0]},{abiItem:s,type:u[1]})}s=a}}return s||o[0]}function _c(e,t){const r=typeof e,n=t.type;switch(n){case"address":return ze(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,o)=>_c(Object.values(e)[o],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=>_c(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function fh(e,t,r){for(const n in e){const i=e[n],o=t[n];if(i.type==="tuple"&&o.type==="tuple"&&"components"in i&&"components"in o)return fh(i.components,o.components,r[n]);const s=[i.type,o.type];if(s.includes("address")&&s.includes("bytes20")?!0:s.includes("address")&&s.includes("string")?ze(r[n],{strict:!1}):s.includes("address")&&s.includes("bytes")?ze(r[n],{strict:!1}):!1)return s}}const af="/docs/contract/encodeEventTopics";function su(e){var c;const{abi:t,eventName:r,args:n}=e;let i=t[0];if(r){const u=jn({abi:t,name:r});if(!u)throw new Zu(r,{docsPath:af});i=u}if(i.type!=="event")throw new Zu(void 0,{docsPath:af});const o=Yt(i),s=Xo(o);let a=[];if(n&&"inputs"in i){const u=(c=i.inputs)==null?void 0:c.filter(h=>"indexed"in h&&h.indexed),f=Array.isArray(n)?n:Object.values(n).length>0?(u==null?void 0:u.map(h=>n[h.name]))??[]:[];f.length>0&&(a=(u==null?void 0:u.map((h,y)=>Array.isArray(f[y])?f[y].map((p,m)=>cf({param:h,value:f[y][m]})):typeof f[y]<"u"&&f[y]!==null?cf({param:h,value:f[y]}):null))??[])}return[s,...a]}function cf({param:e,value:t}){if(e.type==="string"||e.type==="bytes")return Dn(Gi(t));if(e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/))throw new pb(e.type);return Zo([e],[t])}function um(e,{method:t}){var n,i;const r={};return e.transport.type==="fallback"&&((i=(n=e.transport).onResponse)==null||i.call(n,({method:o,response:s,status:a,transport:c})=>{a==="success"&&t===o&&(r[s]=c.request)})),o=>r[o]||e.request}async function lh(e,t){const{address:r,abi:n,args:i,eventName:o,fromBlock:s,strict:a,toBlock:c}=t,u=um(e,{method:"eth_newFilter"}),f=o?su({abi:n,args:i,eventName:o}):void 0,h=await e.request({method:"eth_newFilter",params:[{address:r,fromBlock:typeof s=="bigint"?fe(s):s,toBlock:typeof c=="bigint"?fe(c):c,topics:f}]});return{abi:n,args:i,eventName:o,id:h,request:u(h),strict:!!a,type:"event"}}function Ve(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}const uf="/docs/contract/encodeFunctionData";function fm(e){const{abi:t,args:r,functionName:n}=e;let i=t[0];if(n){const o=jn({abi:t,args:r,name:n});if(!o)throw new di(n,{docsPath:uf});i=o}if(i.type!=="function")throw new di(void 0,{docsPath:uf});return{abi:[i],functionName:Qo(Yt(i))}}function qn(e){const{args:t}=e,{abi:r,functionName:n}=(()=>{var a;return e.abi.length===1&&((a=e.functionName)!=null&&a.startsWith("0x"))?e:fm(e)})(),i=r[0],o=n,s="inputs"in i&&i.inputs?Zo(i.inputs,t??[]):void 0;return Jt([o,s??"0x"])}const lm={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."},dh={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},dm={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class ff extends z{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class hh extends z{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class hm extends z{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const pm={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 hm({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new hh({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ff({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 ff({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 au(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(pm);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function ym(e,t={}){typeof t.size<"u"&&Xt(e,{size:t.size});const r=yt(e,t);return kt(r,t)}function bm(e,t={}){let r=e;if(typeof t.size<"u"&&(Xt(r,{size:t.size}),r=Xr(r)),r.length>1||r[0]>1)throw new bb(r);return!!r[0]}function cr(e,t={}){typeof t.size<"u"&&Xt(e,{size:t.size});const r=yt(e,t);return lr(r,t)}function mm(e,t={}){let r=e;return typeof t.size<"u"&&(Xt(r,{size:t.size}),r=Xr(r,{dir:"right"})),new TextDecoder().decode(r)}function Wi(e,t){const r=typeof t=="string"?dr(t):t,n=au(r);if(Le(r)===0&&e.length>0)throw new Qc;if(Le(t)&&Le(t)<32)throw new Gd({data:typeof t=="string"?t:yt(t),params:e,size:Le(t)});let i=0;const o=[];for(let s=0;s<e.length;++s){const a=e[s];n.setPosition(i);const[c,u]=wn(n,a,{staticPosition:0});i+=u,o.push(c)}return o}function wn(e,t,{staticPosition:r}){const n=ou(t.type);if(n){const[i,o]=n;return wm(e,{...t,type:o},{length:i,staticPosition:r})}if(t.type==="tuple")return xm(e,t,{staticPosition:r});if(t.type==="address")return gm(e);if(t.type==="bool")return vm(e);if(t.type.startsWith("bytes"))return _m(e,t,{staticPosition:r});if(t.type.startsWith("uint")||t.type.startsWith("int"))return Em(e,t);if(t.type==="string")return Am(e,{staticPosition:r});throw new db(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const lf=32,Ec=32;function gm(e){const t=e.readBytes(32);return[Vi(yt(ch(t,-20))),32]}function wm(e,t,{length:r,staticPosition:n}){if(!r){const s=cr(e.readBytes(Ec)),a=n+s,c=a+lf;e.setPosition(a);const u=cr(e.readBytes(lf)),f=pi(t);let h=0;const y=[];for(let p=0;p<u;++p){e.setPosition(c+(f?p*32:h));const[m,g]=wn(e,t,{staticPosition:c});h+=g,y.push(m)}return e.setPosition(n+32),[y,32]}if(pi(t)){const s=cr(e.readBytes(Ec)),a=n+s,c=[];for(let u=0;u<r;++u){e.setPosition(a+u*32);const[f]=wn(e,t,{staticPosition:a});c.push(f)}return e.setPosition(n+32),[c,32]}let i=0;const o=[];for(let s=0;s<r;++s){const[a,c]=wn(e,t,{staticPosition:n+i});i+=c,o.push(a)}return[o,i]}function vm(e){return[bm(e.readBytes(32),{size:32}),32]}function _m(e,t,{staticPosition:r}){const[n,i]=t.type.split("bytes");if(!i){const s=cr(e.readBytes(32));e.setPosition(r+s);const a=cr(e.readBytes(32));if(a===0)return e.setPosition(r+32),["0x",32];const c=e.readBytes(a);return e.setPosition(r+32),[yt(c),32]}return[yt(e.readBytes(Number.parseInt(i),32)),32]}function Em(e,t){const r=t.type.startsWith("int"),n=Number.parseInt(t.type.split("int")[1]||"256"),i=e.readBytes(32);return[n>48?ym(i,{signed:r}):cr(i,{signed:r}),32]}function xm(e,t,{staticPosition:r}){const n=t.components.length===0||t.components.some(({name:s})=>!s),i=n?[]:{};let o=0;if(pi(t)){const s=cr(e.readBytes(Ec)),a=r+s;for(let c=0;c<t.components.length;++c){const u=t.components[c];e.setPosition(a+o);const[f,h]=wn(e,u,{staticPosition:a});o+=h,i[n?c:u==null?void 0:u.name]=f}return e.setPosition(r+32),[i,32]}for(let s=0;s<t.components.length;++s){const a=t.components[s],[c,u]=wn(e,a,{staticPosition:r});i[n?s:a==null?void 0:a.name]=c,o+=u}return[i,o]}function Am(e,{staticPosition:t}){const r=cr(e.readBytes(32)),n=t+r;e.setPosition(n);const i=cr(e.readBytes(32));if(i===0)return e.setPosition(t+32),["",32];const o=e.readBytes(i,32),s=mm(Xr(o));return e.setPosition(t+32),[s,32]}function pi(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(pi);const r=ou(e.type);return!!(r&&pi({...e,type:r[1]}))}function ph(e){const{abi:t,data:r}=e,n=Pn(r,0,4);if(n==="0x")throw new Qc;const o=[...t||[],dh,dm].find(s=>s.type==="error"&&n===Qo(Yt(s)));if(!o)throw new zd(n,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:o,args:"inputs"in o&&o.inputs&&o.inputs.length>0?Wi(o.inputs,Pn(r,4)):void 0,errorName:o.name}}const wt=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);function yh({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,o)=>`${n&&i.name?`${i.name}: `:""}${typeof t[o]=="object"?wt(t[o]):t[o]}`).join(", ")})`}const Sm={gwei:9,wei:18},Pm={ether:-9,wei:9};function bh(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,o]=[r.slice(0,r.length-t),r.slice(r.length-t)];return o=o.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${o?`.${o}`:""}`}function cu(e,t="wei"){return bh(e,Sm[t])}function vt(e,t="wei"){return bh(e,Pm[t])}class Tm extends z{constructor({address:t}){super(`State for account "${t}" is set multiple times.`,{name:"AccountStateConflictError"})}}class Im extends z{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function df(e){return e.reduce((t,{slot:r,value:n})=>`${t} ${r}: ${n}
23
- `,"")}function Bm(e){return e.reduce((t,{address:r,...n})=>{let i=`${t} ${r}:
24
- `;return n.nonce&&(i+=` nonce: ${n.nonce}
25
- `),n.balance&&(i+=` balance: ${n.balance}
26
- `),n.code&&(i+=` code: ${n.code}
27
- `),n.state&&(i+=` state:
28
- `,i+=df(n.state)),n.stateDiff&&(i+=` stateDiff:
29
- `,i+=df(n.stateDiff)),i},` State Override:
30
- `).slice(0,-1)}function Ki(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
- `)}class km extends z{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 Om extends z{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class Rm extends z{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Ki(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 Cm extends z{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 Fm extends z{constructor(t,{account:r,docsPath:n,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:f,to:h,value:y}){var m;const p=Ki({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 y<"u"&&`${cu(y)} ${((m=i==null?void 0:i.nativeCurrency)==null?void 0:m.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${vt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${vt(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${vt(u)} gwei`,nonce:f});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 Nm=e=>e,es=e=>e;class Um extends z{constructor(t,{account:r,docsPath:n,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:f,to:h,value:y,stateOverride:p}){var A;const m=r?Ve(r):void 0;let g=Ki({from:m==null?void 0:m.address,to:h,value:typeof y<"u"&&`${cu(y)} ${((A=i==null?void 0:i.nativeCurrency)==null?void 0:A.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${vt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${vt(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${vt(u)} gwei`,nonce:f});p&&(g+=`
33
- ${Bm(p)}`),super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Raw Call Arguments:",g].filter(Boolean),name:"CallExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class Lm extends z{constructor(t,{abi:r,args:n,contractAddress:i,docsPath:o,functionName:s,sender:a}){const c=jn({abi:r,args:n,name:s}),u=c?yh({abiItem:c,args:n,includeFunctionName:!1,includeName:!1}):void 0,f=c?Yt(c,{includeName:!0}):void 0,h=Ki({address:i&&Nm(i),function:f,args:u&&u!=="()"&&`${[...Array((s==null?void 0:s.length)??0).keys()].map(()=>" ").join("")}${u}`,sender:a});super(t.shortMessage||`An unknown error occurred while executing the contract function "${s}".`,{cause:t,docsPath:o,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=s,this.sender=a}}class Hm extends z{constructor({abi:t,data:r,functionName:n,message:i}){let o,s,a,c;if(r&&r!=="0x")try{s=ph({abi:t,data:r});const{abiItem:f,errorName:h,args:y}=s;if(h==="Error")c=y[0];else if(h==="Panic"){const[p]=y;c=lm[p]}else{const p=f?Yt(f,{includeName:!0}):void 0,m=f&&y?yh({abiItem:f,args:y,includeFunctionName:!1,includeName:!1}):void 0;a=[p?`Error: ${p}`:"",m&&m!=="()"?` ${[...Array((h==null?void 0:h.length)??0).keys()].map(()=>" ").join("")}${m}`:""]}}catch(f){o=f}else i&&(c=i);let u;o instanceof zd&&(u=o.signature,a=[`Unable to decode signature "${u}" 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=${u}.`]),super(c&&c!=="execution reverted"||u?[`The contract function "${n}" reverted with the following ${u?"signature":"reason"}:`,c||u].join(`
34
- `):`The contract function "${n}" reverted.`,{cause:o,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=s,this.raw=r,this.reason=c,this.signature=u}}class $m extends z{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 Mm extends z{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 mh extends z{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 vn extends z{constructor({body:t,cause:r,details:n,headers:i,status:o,url:s}){super("HTTP request failed.",{cause:r,details:n,metaMessages:[o&&`Status: ${o}`,`URL: ${es(s)}`,t&&`Request body: ${wt(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=o,this.url=s}}class uu extends z{constructor({body:t,error:r,url:n}){super("RPC Request failed.",{cause:r,details:r.message,metaMessages:[`URL: ${es(n)}`,`Request body: ${wt(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}}class hf extends z{constructor({body:t,url:r}){super("The request took too long to respond.",{details:"The request timed out.",metaMessages:[`URL: ${es(r)}`,`Request body: ${wt(t)}`],name:"TimeoutError"})}}const Dm=-1;class _t extends z{constructor(t,{code:r,docsPath:n,metaMessages:i,name:o,shortMessage:s}){super(s,{cause:t,docsPath:n,metaMessages:i||(t==null?void 0:t.metaMessages),name:o||"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=o||t.name,this.code=t instanceof uu?t.code:r??Dm}}class At extends _t{constructor(t,r){super(t,r),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=r.data}}class yi extends _t{constructor(t){super(t,{code:yi.code,name:"ParseRpcError",shortMessage:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."})}}Object.defineProperty(yi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32700});class bi extends _t{constructor(t){super(t,{code:bi.code,name:"InvalidRequestRpcError",shortMessage:"JSON is not a valid request object."})}}Object.defineProperty(bi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32600});class mi extends _t{constructor(t,{method:r}={}){super(t,{code:mi.code,name:"MethodNotFoundRpcError",shortMessage:`The method${r?` "${r}"`:""} does not exist / is not available.`})}}Object.defineProperty(mi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32601});class gi extends _t{constructor(t){super(t,{code:gi.code,name:"InvalidParamsRpcError",shortMessage:["Invalid parameters were provided to the RPC method.","Double check you have provided the correct parameters."].join(`
35
- `)})}}Object.defineProperty(gi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32602});class Zr extends _t{constructor(t){super(t,{code:Zr.code,name:"InternalRpcError",shortMessage:"An internal error was received."})}}Object.defineProperty(Zr,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32603});class Tn extends _t{constructor(t){super(t,{code:Tn.code,name:"InvalidInputRpcError",shortMessage:["Missing or invalid parameters.","Double check you have provided the correct parameters."].join(`
36
- `)})}}Object.defineProperty(Tn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32e3});class wi extends _t{constructor(t){super(t,{code:wi.code,name:"ResourceNotFoundRpcError",shortMessage:"Requested resource not found."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceNotFoundRpcError"})}}Object.defineProperty(wi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32001});class vi extends _t{constructor(t){super(t,{code:vi.code,name:"ResourceUnavailableRpcError",shortMessage:"Requested resource not available."})}}Object.defineProperty(vi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32002});class _i extends _t{constructor(t){super(t,{code:_i.code,name:"TransactionRejectedRpcError",shortMessage:"Transaction creation failed."})}}Object.defineProperty(_i,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32003});class qr extends _t{constructor(t,{method:r}={}){super(t,{code:qr.code,name:"MethodNotSupportedRpcError",shortMessage:`Method${r?` "${r}"`:""} is not supported.`})}}Object.defineProperty(qr,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32004});class In extends _t{constructor(t){super(t,{code:In.code,name:"LimitExceededRpcError",shortMessage:"Request exceeds defined limit."})}}Object.defineProperty(In,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32005});class Ei extends _t{constructor(t){super(t,{code:Ei.code,name:"JsonRpcVersionUnsupportedError",shortMessage:"Version of JSON-RPC protocol is not supported."})}}Object.defineProperty(Ei,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32006});class _n extends At{constructor(t){super(t,{code:_n.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(_n,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class xi extends At{constructor(t){super(t,{code:xi.code,name:"UnauthorizedProviderError",shortMessage:"The requested method and/or account has not been authorized by the user."})}}Object.defineProperty(xi,"code",{enumerable:!0,configurable:!0,writable:!0,value:4100});class Ai extends At{constructor(t,{method:r}={}){super(t,{code:Ai.code,name:"UnsupportedProviderMethodError",shortMessage:`The Provider does not support the requested method${r?` " ${r}"`:""}.`})}}Object.defineProperty(Ai,"code",{enumerable:!0,configurable:!0,writable:!0,value:4200});class Si extends At{constructor(t){super(t,{code:Si.code,name:"ProviderDisconnectedError",shortMessage:"The Provider is disconnected from all chains."})}}Object.defineProperty(Si,"code",{enumerable:!0,configurable:!0,writable:!0,value:4900});class Pi extends At{constructor(t){super(t,{code:Pi.code,name:"ChainDisconnectedError",shortMessage:"The Provider is not connected to the requested chain."})}}Object.defineProperty(Pi,"code",{enumerable:!0,configurable:!0,writable:!0,value:4901});class Ti extends At{constructor(t){super(t,{code:Ti.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(Ti,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class Ii extends At{constructor(t){super(t,{code:Ii.code,name:"UnsupportedNonOptionalCapabilityError",shortMessage:"This Wallet does not support a capability that was not marked as optional."})}}Object.defineProperty(Ii,"code",{enumerable:!0,configurable:!0,writable:!0,value:5700});class Bi extends At{constructor(t){super(t,{code:Bi.code,name:"UnsupportedChainIdError",shortMessage:"This Wallet does not support the requested chain ID."})}}Object.defineProperty(Bi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5710});class ki extends At{constructor(t){super(t,{code:ki.code,name:"DuplicateIdError",shortMessage:"There is already a bundle submitted with this ID."})}}Object.defineProperty(ki,"code",{enumerable:!0,configurable:!0,writable:!0,value:5720});class Oi extends At{constructor(t){super(t,{code:Oi.code,name:"UnknownBundleIdError",shortMessage:"This bundle id is unknown / has not been submitted"})}}Object.defineProperty(Oi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5730});class Ri extends At{constructor(t){super(t,{code:Ri.code,name:"BundleTooLargeError",shortMessage:"The call bundle is too large for the Wallet to process."})}}Object.defineProperty(Ri,"code",{enumerable:!0,configurable:!0,writable:!0,value:5740});class Ci extends At{constructor(t){super(t,{code:Ci.code,name:"AtomicReadyWalletRejectedUpgradeError",shortMessage:"The Wallet can support atomicity after an upgrade, but the user rejected the upgrade."})}}Object.defineProperty(Ci,"code",{enumerable:!0,configurable:!0,writable:!0,value:5750});class Fi extends At{constructor(t){super(t,{code:Fi.code,name:"AtomicityNotSupportedError",shortMessage:"The wallet does not support atomic execution but the request requires it."})}}Object.defineProperty(Fi,"code",{enumerable:!0,configurable:!0,writable:!0,value:5760});class jm extends _t{constructor(t){super(t,{name:"UnknownRpcError",shortMessage:"An unknown RPC error occurred."})}}const qm=3;function ts(e,{abi:t,address:r,args:n,docsPath:i,functionName:o,sender:s}){const a=e instanceof mh?e:e instanceof z?e.walk(m=>"data"in m)||e.walk():{},{code:c,data:u,details:f,message:h,shortMessage:y}=a,p=e instanceof Qc?new $m({functionName:o}):[qm,Zr.code].includes(c)&&(u||f||h||y)?new Hm({abi:t,data:typeof u=="object"?u.data:u,functionName:o,message:a instanceof uu?f:y??h}):e;return new Lm(p,{abi:t,args:n,contractAddress:r,docsPath:i,functionName:o,sender:s})}function Gm(e){const t=Dn(`0x${e.substring(4)}`).substring(26);return Vi(`0x${t}`)}async function zm({hash:e,signature:t}){const r=fr(e)?e:ue(e),{secp256k1:n}=await Promise.resolve().then(()=>require("./secp256k1-BTM6DphI.cjs"));return`0x${(()=>{if(typeof t=="object"&&"r"in t&&"s"in t){const{r:u,s:f,v:h,yParity:y}=t,p=Number(y??h),m=pf(p);return new n.Signature(kt(u),kt(f)).addRecoveryBit(m)}const s=fr(t)?t:ue(t);if(Le(s)!==65)throw new Error("invalid signature length");const a=lr(`0x${s.slice(130)}`),c=pf(a);return n.Signature.fromCompact(s.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function pf(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 Vm({hash:e,signature:t}){return Gm(await zm({hash:e,signature:t}))}function Cr(e,t="hex"){const r=gh(e),n=au(new Uint8Array(r.length));return r.encode(n),t==="hex"?yt(n.bytes):n.bytes}function gh(e){return Array.isArray(e)?Wm(e.map(t=>gh(t))):Km(e)}function Wm(e){const t=e.reduce((i,o)=>i+o.length,0),r=wh(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:o}of e)o(i)}}}function Km(e){const t=typeof e=="string"?dr(e):e,r=wh(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 wh(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 z("Length is too large.")}function Ym(e){const{chainId:t,nonce:r,to:n}=e,i=e.contractAddress??e.address,o=Dn(Jt(["0x05",Cr([t?fe(t):"0x",i,r?fe(r):"0x"])]));return n==="bytes"?dr(o):o}async function vh(e){const{authorization:t,signature:r}=e;return Vm({hash:Ym(t),signature:r??t})}class Xm extends z{constructor(t,{account:r,docsPath:n,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:f,to:h,value:y}){var m;const p=Ki({from:r==null?void 0:r.address,to:h,value:typeof y<"u"&&`${cu(y)} ${((m=i==null?void 0:i.nativeCurrency)==null?void 0:m.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${vt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${vt(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${vt(u)} gwei`,nonce:f});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 gn extends z{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(gn,"code",{enumerable:!0,configurable:!0,writable:!0,value:3});Object.defineProperty(gn,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class Qr extends z{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${vt(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Qr,"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 xc extends z{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${vt(r)}`:""} gwei) cannot be lower than the block base fee.`,{cause:t,name:"FeeCapTooLowError"})}}Object.defineProperty(xc,"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 Ac extends z{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(Ac,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class Sc extends z{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(Sc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class Pc extends z{constructor({cause:t,nonce:r}={}){super(`Nonce provided for the transaction ${r?`(${r}) `:""}exceeds the maximum allowed nonce.`,{cause:t,name:"NonceMaxValueError"})}}Object.defineProperty(Pc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/});class Tc extends z{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(Tc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class Ic extends z{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(Ic,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class Bc extends z{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(Bc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class kc extends z{constructor({cause:t}){super("The transaction type is not supported for this chain.",{cause:t,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty(kc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class Ni extends z{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${vt(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${vt(n)} gwei`:""}).`].join(`
39
- `),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Ni,"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 rs extends z{constructor({cause:t}){super(`An error occurred while executing: ${t==null?void 0:t.shortMessage}`,{cause:t,name:"UnknownNodeError"})}}function fu(e,t){const r=(e.details||"").toLowerCase(),n=e instanceof z?e.walk(i=>(i==null?void 0:i.code)===gn.code):e;return n instanceof z?new gn({cause:e,message:n.details}):gn.nodeMessage.test(r)?new gn({cause:e,message:e.details}):Qr.nodeMessage.test(r)?new Qr({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):xc.nodeMessage.test(r)?new xc({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):Ac.nodeMessage.test(r)?new Ac({cause:e,nonce:t==null?void 0:t.nonce}):Sc.nodeMessage.test(r)?new Sc({cause:e,nonce:t==null?void 0:t.nonce}):Pc.nodeMessage.test(r)?new Pc({cause:e,nonce:t==null?void 0:t.nonce}):Tc.nodeMessage.test(r)?new Tc({cause:e}):Ic.nodeMessage.test(r)?new Ic({cause:e,gas:t==null?void 0:t.gas}):Bc.nodeMessage.test(r)?new Bc({cause:e,gas:t==null?void 0:t.gas}):kc.nodeMessage.test(r)?new kc({cause:e}):Ni.nodeMessage.test(r)?new Ni({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas,maxPriorityFeePerGas:t==null?void 0:t.maxPriorityFeePerGas}):new rs({cause:e})}function Jm(e,{docsPath:t,...r}){const n=(()=>{const i=fu(e,r);return i instanceof rs?e:i})();return new Xm(n,{docsPath:t,...r})}function lu(e,{format:t}){if(!t)return{};const r={};function n(o){const s=Object.keys(o);for(const a of s)a in e&&(r[a]=e[a]),o[a]&&typeof o[a]=="object"&&!Array.isArray(o[a])&&n(o[a])}const i=t(e||{});return n(i),r}function du(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const o=t(i);if(r)for(const s of r)delete o[s];return{...o,...n(i)}},type:e})}const Zm={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function ns(e){const t={};return typeof e.authorizationList<"u"&&(t.authorizationList=Qm(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=>yt(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=fe(e.gas)),typeof e.gasPrice<"u"&&(t.gasPrice=fe(e.gasPrice)),typeof e.maxFeePerBlobGas<"u"&&(t.maxFeePerBlobGas=fe(e.maxFeePerBlobGas)),typeof e.maxFeePerGas<"u"&&(t.maxFeePerGas=fe(e.maxFeePerGas)),typeof e.maxPriorityFeePerGas<"u"&&(t.maxPriorityFeePerGas=fe(e.maxPriorityFeePerGas)),typeof e.nonce<"u"&&(t.nonce=fe(e.nonce)),typeof e.to<"u"&&(t.to=e.to),typeof e.type<"u"&&(t.type=Zm[e.type]),typeof e.value<"u"&&(t.value=fe(e.value)),t}function Qm(e){return e.map(t=>({address:t.address,r:t.r?fe(BigInt(t.r)):t.r,s:t.s?fe(BigInt(t.s)):t.s,chainId:fe(t.chainId),nonce:fe(t.nonce),...typeof t.yParity<"u"?{yParity:fe(t.yParity)}:{},...typeof t.v<"u"&&typeof t.yParity>"u"?{v:fe(t.v)}:{}}))}function yf(e){if(!(!e||e.length===0))return e.reduce((t,{slot:r,value:n})=>{if(r.length!==66)throw new Qu({size:r.length,targetSize:66,type:"hex"});if(n.length!==66)throw new Qu({size:n.length,targetSize:66,type:"hex"});return t[r]=n,t},{})}function eg(e){const{balance:t,nonce:r,state:n,stateDiff:i,code:o}=e,s={};if(o!==void 0&&(s.code=o),t!==void 0&&(s.balance=fe(t)),r!==void 0&&(s.nonce=fe(r)),n!==void 0&&(s.state=yf(n)),i!==void 0){if(s.state)throw new Im;s.stateDiff=yf(i)}return s}function _h(e){if(!e)return;const t={};for(const{address:r,...n}of e){if(!ze(r,{strict:!1}))throw new bt({address:r});if(t[r])throw new Tm({address:r});t[r]=eg(n)}return t}const is=2n**256n-1n;function Yi(e){const{account:t,gasPrice:r,maxFeePerGas:n,maxPriorityFeePerGas:i,to:o}=e,s=t?Ve(t):void 0;if(s&&!ze(s.address))throw new bt({address:s.address});if(o&&!ze(o))throw new bt({address:o});if(typeof r<"u"&&(typeof n<"u"||typeof i<"u"))throw new km;if(n&&n>is)throw new Qr({maxFeePerGas:n});if(i&&n&&i>n)throw new Ni({maxFeePerGas:n,maxPriorityFeePerGas:i})}class tg extends z{constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class hu extends z{constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class rg extends z{constructor({maxPriorityFeePerGas:t}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${vt(t)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class ng extends z{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 Eh={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function pu(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?lr(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?lr(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?Eh[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=og(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 ig=du("transaction",pu);function og(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 xh(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:pu(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 sg=du("block",xh);async function Lo(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:i}={}){var f,h,y;const o=n??"latest",s=i??!1,a=r!==void 0?fe(r):void 0;let c=null;if(t?c=await e.request({method:"eth_getBlockByHash",params:[t,s]},{dedupe:!0}):c=await e.request({method:"eth_getBlockByNumber",params:[a||o,s]},{dedupe:!!a}),!c)throw new ng({blockHash:t,blockNumber:r});return(((y=(h=(f=e.chain)==null?void 0:f.formatters)==null?void 0:h.block)==null?void 0:y.format)||xh)(c)}async function Ah(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function ag(e,t){var o,s;const{block:r,chain:n=e.chain,request:i}=t||{};try{const a=((o=n==null?void 0:n.fees)==null?void 0:o.maxPriorityFeePerGas)??((s=n==null?void 0:n.fees)==null?void 0:s.defaultPriorityFee);if(typeof a=="function"){const u=r||await ve(e,Lo,"getBlock")({}),f=await a({block:u,client:e,request:i});if(f===null)throw new Error;return f}if(typeof a<"u")return a;const c=await e.request({method:"eth_maxPriorityFeePerGas"});return kt(c)}catch{const[a,c]=await Promise.all([r?Promise.resolve(r):ve(e,Lo,"getBlock")({}),ve(e,Ah,"getGasPrice")({})]);if(typeof a.baseFeePerGas!="bigint")throw new hu;const u=c-a.baseFeePerGas;return u<0n?0n:u}}async function bf(e,t){var y,p;const{block:r,chain:n=e.chain,request:i,type:o="eip1559"}=t||{},s=await(async()=>{var m,g;return typeof((m=n==null?void 0:n.fees)==null?void 0:m.baseFeeMultiplier)=="function"?n.fees.baseFeeMultiplier({block:r,client:e,request:i}):((g=n==null?void 0:n.fees)==null?void 0:g.baseFeeMultiplier)??1.2})();if(s<1)throw new tg;const c=10**(((y=s.toString().split(".")[1])==null?void 0:y.length)??0),u=m=>m*BigInt(Math.ceil(s*c))/BigInt(c),f=r||await ve(e,Lo,"getBlock")({});if(typeof((p=n==null?void 0:n.fees)==null?void 0:p.estimateFeesPerGas)=="function"){const m=await n.fees.estimateFeesPerGas({block:r,client:e,multiply:u,request:i,type:o});if(m!==null)return m}if(o==="eip1559"){if(typeof f.baseFeePerGas!="bigint")throw new hu;const m=typeof(i==null?void 0:i.maxPriorityFeePerGas)=="bigint"?i.maxPriorityFeePerGas:await ag(e,{block:f,chain:n,request:i}),g=u(f.baseFeePerGas);return{maxFeePerGas:(i==null?void 0:i.maxFeePerGas)??g+m,maxPriorityFeePerGas:m}}return{gasPrice:(i==null?void 0:i.gasPrice)??u(await ve(e,Ah,"getGasPrice")({}))}}async function Sh(e,{address:t,blockTag:r="latest",blockNumber:n}){const i=await e.request({method:"eth_getTransactionCount",params:[t,typeof n=="bigint"?fe(n):r]},{dedupe:!!n});return lr(i)}function yu(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=>dr(o)):e.blobs,i=[];for(const o of n)i.push(Uint8Array.from(t.blobToKzgCommitment(o)));return r==="bytes"?i:i.map(o=>yt(o))}function bu(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=>dr(s)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(s=>dr(s)):e.commitments,o=[];for(let s=0;s<n.length;s++){const a=n[s],c=i[s];o.push(Uint8Array.from(t.computeBlobKzgProof(a,c)))}return r==="bytes"?o:o.map(s=>yt(s))}function cg(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+u,a,n)}function ug(e,t,r){return e&t^~e&r}function fg(e,t,r){return e&t^e&r^t&r}let lg=class extends tu{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=Fs(this.buffer)}update(t){hi(this);const{view:r,buffer:n,blockLen:i}=this;t=Yo(t);const o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=Fs(t);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){hi(this),eh(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:o}=this;let{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let h=s;h<i;h++)r[h]=0;cg(n,i-8,BigInt(this.length*8),o),this.process(n,0);const a=Fs(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}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:o,destroyed:s,pos:a}=this;return t.length=i,t.pos=a,t.finished=o,t.destroyed=s,i%r&&t.buffer.set(n),t}};const dg=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]),mr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),gr=new Uint32Array(64);let hg=class extends lg{constructor(t=32){super(64,t,8,!1),this.A=mr[0]|0,this.B=mr[1]|0,this.C=mr[2]|0,this.D=mr[3]|0,this.E=mr[4]|0,this.F=mr[5]|0,this.G=mr[6]|0,this.H=mr[7]|0}get(){const{A:t,B:r,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[t,r,n,i,o,s,a,c]}set(t,r,n,i,o,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let h=0;h<16;h++,r+=4)gr[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const y=gr[h-15],p=gr[h-2],m=$t(y,7)^$t(y,18)^y>>>3,g=$t(p,17)^$t(p,19)^p>>>10;gr[h]=g+gr[h-7]+m+gr[h-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){const y=$t(a,6)^$t(a,11)^$t(a,25),p=f+y+ug(a,c,u)+dg[h]+gr[h]|0,g=($t(n,2)^$t(n,13)^$t(n,22))+fg(n,i,o)|0;f=u,u=c,c=a,a=s+p|0,s=o,o=i,i=n,n=p+g|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,a,c,u,f)}roundClean(){gr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Ph=th(()=>new hg);function si(e,t){const r=t||"hex",n=Ph(fr(e,{strict:!1})?Gi(e):e);return r==="bytes"?n:ue(n)}function pg(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=si(t,"bytes");return i.set([r],0),n==="bytes"?i:yt(i)}function Th(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const o of t)i.push(pg({commitment:o,to:n,version:r}));return i}const mf=6,Ih=32,mu=4096,Bh=Ih*mu,gf=Bh*mf-1-1*mu*mf,kh=1;class yg extends z{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Oh extends z{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class bg extends z{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class mg extends z{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${kh}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function gg(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?dr(e.data):e.data,n=Le(r);if(!n)throw new Oh;if(n>gf)throw new yg({maxSize:gf,size:n});const i=[];let o=!0,s=0;for(;o;){const a=au(new Uint8Array(Bh));let c=0;for(;c<mu;){const u=r.slice(s,s+(Ih-1));if(a.pushByte(0),a.pushBytes(u),u.length<31){a.pushByte(128),o=!1;break}c++,s+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>yt(a.bytes))}function Rh(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??gg({data:t,to:n}),o=e.commitments??yu({blobs:i,kzg:r,to:n}),s=e.proofs??bu({blobs:i,commitments:o,kzg:r,to:n}),a=[];for(let c=0;c<i.length;c++)a.push({blob:i[c],commitment:o[c],proof:s[c]});return a}function Ch(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 Rm({transaction:e})}async function Xi(e){const t=await e.request({method:"eth_chainId"},{dedupe:!0});return lr(t)}const Fh=["blobVersionedHashes","chainId","fees","gas","nonce","type"],wf=new Map;async function gu(e,t){const{account:r=e.account,blobs:n,chain:i,gas:o,kzg:s,nonce:a,nonceManager:c,parameters:u=Fh,type:f}=t,h=r&&Ve(r),y={...t,...h?{from:h==null?void 0:h.address}:{}};let p;async function m(){return p||(p=await ve(e,Lo,"getBlock")({blockTag:"latest"}),p)}let g;async function A(){return g||(i?i.id:typeof t.chainId<"u"?t.chainId:(g=await ve(e,Xi,"getChainId")({}),g))}if(u.includes("nonce")&&typeof a>"u"&&h)if(c){const S=await A();y.nonce=await c.consume({address:h.address,chainId:S,client:e})}else y.nonce=await ve(e,Sh,"getTransactionCount")({address:h.address,blockTag:"pending"});if((u.includes("blobVersionedHashes")||u.includes("sidecars"))&&n&&s){const S=yu({blobs:n,kzg:s});if(u.includes("blobVersionedHashes")){const P=Th({commitments:S,to:"hex"});y.blobVersionedHashes=P}if(u.includes("sidecars")){const P=bu({blobs:n,commitments:S,kzg:s}),w=Rh({blobs:n,commitments:S,proofs:P,to:"hex"});y.sidecars=w}}if(u.includes("chainId")&&(y.chainId=await A()),(u.includes("fees")||u.includes("type"))&&typeof f>"u")try{y.type=Ch(y)}catch{let S=wf.get(e.uid);if(typeof S>"u"){const P=await m();S=typeof(P==null?void 0:P.baseFeePerGas)=="bigint",wf.set(e.uid,S)}y.type=S?"eip1559":"legacy"}if(u.includes("fees"))if(y.type!=="legacy"&&y.type!=="eip2930"){if(typeof y.maxFeePerGas>"u"||typeof y.maxPriorityFeePerGas>"u"){const S=await m(),{maxFeePerGas:P,maxPriorityFeePerGas:w}=await bf(e,{block:S,chain:i,request:y});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas<w)throw new rg({maxPriorityFeePerGas:w});y.maxPriorityFeePerGas=w,y.maxFeePerGas=P}}else{if(typeof t.maxFeePerGas<"u"||typeof t.maxPriorityFeePerGas<"u")throw new hu;if(typeof t.gasPrice>"u"){const S=await m(),{gasPrice:P}=await bf(e,{block:S,chain:i,request:y,type:"legacy"});y.gasPrice=P}}return u.includes("gas")&&typeof o>"u"&&(y.gas=await ve(e,Nh,"estimateGas")({...y,account:h&&{address:h.address,type:"json-rpc"}})),Yi(y),delete y.parameters,y}async function wg(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=typeof r=="bigint"?fe(r):void 0,o=await e.request({method:"eth_getBalance",params:[t,i||n]});return BigInt(o)}async function Nh(e,t){var i,o,s;const{account:r=e.account}=t,n=r?Ve(r):void 0;try{let Q=function(_e){const{block:pe,request:de,rpcStateOverride:F}=_e;return e.request({method:"eth_estimateGas",params:F?[de,pe??"latest",F]:pe?[de,pe]:[de]})};const{accessList:a,authorizationList:c,blobs:u,blobVersionedHashes:f,blockNumber:h,blockTag:y,data:p,gas:m,gasPrice:g,maxFeePerBlobGas:A,maxFeePerGas:S,maxPriorityFeePerGas:P,nonce:w,value:_,stateOverride:I,...T}=await gu(e,{...t,parameters:(n==null?void 0:n.type)==="local"?void 0:["blobVersionedHashes"]}),M=(typeof h=="bigint"?fe(h):void 0)||y,C=_h(I),Y=await(async()=>{if(T.to)return T.to;if(c&&c.length>0)return await vh({authorization:c[0]}).catch(()=>{throw new z("`to` is required. Could not infer from `authorizationList`")})})();Yi(t);const J=(s=(o=(i=e.chain)==null?void 0:i.formatters)==null?void 0:o.transactionRequest)==null?void 0:s.format,ee=(J||ns)({...lu(T,{format:J}),from:n==null?void 0:n.address,accessList:a,authorizationList:c,blobs:u,blobVersionedHashes:f,data:p,gas:m,gasPrice:g,maxFeePerBlobGas:A,maxFeePerGas:S,maxPriorityFeePerGas:P,nonce:w,to:Y,value:_});let ae=BigInt(await Q({block:M,request:ee,rpcStateOverride:C}));if(c){const _e=await wg(e,{address:ee.from}),pe=await Promise.all(c.map(async de=>{const{address:F}=de,X=await Q({block:M,request:{authorizationList:void 0,data:p,from:n==null?void 0:n.address,to:F,value:fe(_e)},rpcStateOverride:C}).catch(()=>100000n);return 2n*BigInt(X)}));ae+=pe.reduce((de,F)=>de+F,0n)}return ae}catch(a){throw Jm(a,{...t,account:n,chain:e.chain})}}async function vg(e,t){const{abi:r,address:n,args:i,functionName:o,dataSuffix:s,...a}=t,c=qn({abi:r,args:i,functionName:o});try{return await ve(e,Nh,"estimateGas")({data:`${c}${s?s.replace("0x",""):""}`,to:n,...a})}catch(u){const f=a.account?Ve(a.account):void 0;throw ts(u,{abi:r,address:n,args:i,docsPath:"/docs/contract/estimateContractGas",functionName:o,sender:f==null?void 0:f.address})}}function wu(e,t){if(!ze(e,{strict:!1}))throw new bt({address:e});if(!ze(t,{strict:!1}))throw new bt({address:t});return e.toLowerCase()===t.toLowerCase()}const vf="/docs/contract/decodeEventLog";function Uh(e){const{abi:t,data:r,strict:n,topics:i}=e,o=n??!0,[s,...a]=i;if(!s)throw new ab({docsPath:vf});const c=t.length===1?t[0]:t.find(g=>g.type==="event"&&s===Xo(Yt(g)));if(!(c&&"name"in c)||c.type!=="event")throw new Vd(s,{docsPath:vf});const{name:u,inputs:f}=c,h=f==null?void 0:f.some(g=>!("name"in g&&g.name));let y=h?[]:{};const p=f.filter(g=>"indexed"in g&&g.indexed);for(let g=0;g<p.length;g++){const A=p[g],S=a[g];if(!S)throw new eu({abiItem:c,param:A});y[h?g:A.name||g]=_g({param:A,value:S})}const m=f.filter(g=>!("indexed"in g&&g.indexed));if(m.length>0){if(r&&r!=="0x")try{const g=Wi(m,r);if(g)if(h)y=[...y,...g];else for(let A=0;A<m.length;A++)y[m[A].name]=g[A]}catch(g){if(o)throw g instanceof Gd||g instanceof hh?new No({abiItem:c,data:r,params:m,size:Le(r)}):g}else if(o)throw new No({abiItem:c,data:"0x",params:m,size:0})}return{eventName:u,args:Object.values(y).length>0?y:void 0}}function _g({param:e,value:t}){return e.type==="string"||e.type==="bytes"||e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/)?t:(Wi([e],t)||[])[0]}function Lh(e){const{abi:t,args:r,logs:n,strict:i=!0}=e,o=(()=>{if(e.eventName)return Array.isArray(e.eventName)?e.eventName:[e.eventName]})();return n.map(s=>{var a;try{const c=t.find(f=>f.type==="event"&&s.topics[0]===Xo(f));if(!c)return null;const u=Uh({...s,abi:[c],strict:i});return o&&!o.includes(u.eventName)||!Eg({args:u.args,inputs:c.inputs,matchArgs:r})?null:{...u,...s}}catch(c){let u,f;if(c instanceof Vd)return null;if(c instanceof No||c instanceof eu){if(i)return null;u=c.abiItem.name,f=(a=c.abiItem.inputs)==null?void 0:a.some(h=>!("name"in h&&h.name))}return{...s,args:f?[]:{},eventName:u}}}).filter(Boolean)}function Eg(e){const{args:t,inputs:r,matchArgs:n}=e;if(!n)return!0;if(!t)return!1;function i(o,s,a){try{return o.type==="address"?wu(s,a):o.type==="string"||o.type==="bytes"?Dn(Gi(s))===a:s===a}catch{return!1}}return Array.isArray(t)&&Array.isArray(n)?n.every((o,s)=>{if(o==null)return!0;const a=r[s];return a?(Array.isArray(o)?o:[o]).some(u=>i(a,u,t[s])):!1}):typeof t=="object"&&!Array.isArray(t)&&typeof n=="object"&&!Array.isArray(n)?Object.entries(n).every(([o,s])=>{if(s==null)return!0;const a=r.find(u=>u.name===o);return a?(Array.isArray(s)?s:[s]).some(u=>i(a,u,t[o])):!1}):!1}function Ui(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 xg(e,{address:t,blockHash:r,fromBlock:n,toBlock:i,event:o,events:s,args:a,strict:c}={}){const u=c??!1,f=s??(o?[o]:void 0);let h=[];f&&(h=[f.flatMap(g=>su({abi:[g],eventName:g.name,args:s?void 0:a}))],o&&(h=h[0]));let y;r?y=await e.request({method:"eth_getLogs",params:[{address:t,topics:h,blockHash:r}]}):y=await e.request({method:"eth_getLogs",params:[{address:t,topics:h,fromBlock:typeof n=="bigint"?fe(n):n,toBlock:typeof i=="bigint"?fe(i):i}]});const p=y.map(m=>Ui(m));return f?Lh({abi:f,args:a,logs:p,strict:u}):p}async function Hh(e,t){const{abi:r,address:n,args:i,blockHash:o,eventName:s,fromBlock:a,toBlock:c,strict:u}=t,f=s?jn({abi:r,name:s}):void 0,h=f?void 0:r.filter(y=>y.type==="event");return ve(e,xg,"getLogs")({address:n,args:i,blockHash:o,event:f,events:h,fromBlock:a,toBlock:c,strict:u})}const Ls="/docs/contract/decodeFunctionResult";function vu(e){const{abi:t,args:r,functionName:n,data:i}=e;let o=t[0];if(n){const a=jn({abi:t,args:r,name:n});if(!a)throw new di(n,{docsPath:Ls});o=a}if(o.type!=="function")throw new di(void 0,{docsPath:Ls});if(!o.outputs)throw new Wd(o.name,{docsPath:Ls});const s=Wi(o.outputs,i);if(s&&s.length>1)return s;if(s&&s.length===1)return s[0]}const Ag="0.1.1";function Sg(){return Ag}class Li extends Error{constructor(t,r={}){const n=(()=>{var c;if(r.cause instanceof Li){if(r.cause.details)return r.cause.details;if(r.cause.shortMessage)return r.cause.shortMessage}return(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof Li&&r.cause.docsPath||r.docsPath,s=`https://oxlib.sh${i??""}`,a=[t||"An error occurred.",...r.metaMessages?["",...r.metaMessages]:[],...n||i?["",n?`Details: ${n}`:void 0,i?`See: ${s}`:void 0]:[]].filter(c=>typeof c=="string").join(`
40
- `);super(a,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{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,"shortMessage",{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,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:`ox@${Sg()}`}),this.cause=r.cause,this.details=n,this.docs=s,this.docsPath=i,this.shortMessage=t}walk(t){return $h(this,t)}}function $h(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause?$h(e.cause,t):t?null:e}function Pg(e,t={}){const{dir:r,size:n=32}=t;if(n===0)return e;const i=e.replace("0x","");if(i.length>n*2)throw new Bg({size:Math.ceil(i.length/2),targetSize:n,type:"Hex"});return`0x${i[r==="right"?"padEnd":"padStart"](n*2,"0")}`}function or(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let o;n?r?o=(1n<<BigInt(n)*8n-1n)-1n:o=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(o=BigInt(Number.MAX_SAFE_INTEGER));const s=typeof o=="bigint"&&r?-o-1n:0;if(o&&i>o||i<s){const u=typeof e=="bigint"?"n":"";throw new Ig({max:o?`${o}${u}`:void 0,min:`${s}${u}`,signed:r,size:n,value:`${e}${u}`})}const c=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Tg(c,n):c}function Tg(e,t){return Pg(e,{dir:"left",size:t})}class Ig extends Li{constructor({max:t,min:r,signed:n,size:i,value:o}){super(`Number \`${o}\` is not in safe${i?` ${i*8}-bit`:""}${n?" signed":" unsigned"} integer range ${t?`(\`${r}\` to \`${t}\`)`:`(above \`${r}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class Bg extends Li{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${t}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}function kg(e){return{address:e.address,amount:or(e.amount),index:or(e.index),validatorIndex:or(e.validatorIndex)}}function Og(e){return{...typeof e.baseFeePerGas=="bigint"&&{baseFeePerGas:or(e.baseFeePerGas)},...typeof e.blobBaseFee=="bigint"&&{blobBaseFee:or(e.blobBaseFee)},...typeof e.feeRecipient=="string"&&{feeRecipient:e.feeRecipient},...typeof e.gasLimit=="bigint"&&{gasLimit:or(e.gasLimit)},...typeof e.number=="bigint"&&{number:or(e.number)},...typeof e.prevRandao=="bigint"&&{prevRandao:or(e.prevRandao)},...typeof e.time=="bigint"&&{time:or(e.time)},...e.withdrawals&&{withdrawals:e.withdrawals.map(kg)}}}const _f=[{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"}],Rg=[{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"}]}],Cg="0x82ad56cb",Fg="0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe",Ng="0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe";class Oc extends z{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 Ug extends z{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 Lg extends z{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(`
41
- `),{name:"ChainNotFoundError"})}}class Mh extends z{constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class os extends z{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const Hs="/docs/contract/encodeDeployData";function _u(e){const{abi:t,args:r,bytecode:n}=e;if(!r||r.length===0)return n;const i=t.find(s=>"type"in s&&s.type==="constructor");if(!i)throw new tb({docsPath:Hs});if(!("inputs"in i))throw new Ju({docsPath:Hs});if(!i.inputs||i.inputs.length===0)throw new Ju({docsPath:Hs});const o=Zo(i.inputs,r);return Jt([n,o])}function Hg({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 Oc({chain:t,contract:{name:r}});if(e&&n.blockCreated&&n.blockCreated>e)throw new Oc({blockNumber:e,chain:t,contract:{name:r,blockCreated:n.blockCreated}});return n.address}function $g(e,{docsPath:t,...r}){const n=(()=>{const i=fu(e,r);return i instanceof rs?e:i})();return new Um(n,{docsPath:t,...r})}function Dh(){let e=()=>{},t=()=>{};return{promise:new Promise((n,i)=>{e=n,t=i}),resolve:e,reject:t}}const $s=new Map;function jh({fn:e,id:t,shouldSplitBatch:r,wait:n=0,sort:i}){const o=async()=>{const f=c();s();const h=f.map(({args:y})=>y);h.length!==0&&e(h).then(y=>{i&&Array.isArray(y)&&y.sort(i);for(let p=0;p<f.length;p++){const{resolve:m}=f[p];m==null||m([y[p],y])}}).catch(y=>{for(let p=0;p<f.length;p++){const{reject:m}=f[p];m==null||m(y)}})},s=()=>$s.delete(t),a=()=>c().map(({args:f})=>f),c=()=>$s.get(t)||[],u=f=>$s.set(t,[...c(),f]);return{flush:s,async schedule(f){const{promise:h,resolve:y,reject:p}=Dh();return(r==null?void 0:r([...a(),f]))&&o(),c().length>0?(u({args:f,resolve:y,reject:p}),h):(u({args:f,resolve:y,reject:p}),setTimeout(o,n),h)}}}async function Eu(e,t){var re,ee,Q,ae;const{account:r=e.account,batch:n=!!((re=e.batch)!=null&&re.multicall),blockNumber:i,blockTag:o="latest",accessList:s,blobs:a,blockOverrides:c,code:u,data:f,factory:h,factoryData:y,gas:p,gasPrice:m,maxFeePerBlobGas:g,maxFeePerGas:A,maxPriorityFeePerGas:S,nonce:P,to:w,value:_,stateOverride:I,...T}=t,H=r?Ve(r):void 0;if(u&&(h||y))throw new z("Cannot provide both `code` & `factory`/`factoryData` as parameters.");if(u&&w)throw new z("Cannot provide both `code` & `to` as parameters.");const M=u&&f,C=h&&y&&w&&f,Y=M||C,J=M?jg({code:u,data:f}):C?qg({data:f,factory:h,factoryData:y,to:w}):f;try{Yi(t);const pe=(typeof i=="bigint"?fe(i):void 0)||o,de=c?Og(c):void 0,F=_h(I),X=(ae=(Q=(ee=e.chain)==null?void 0:ee.formatters)==null?void 0:Q.transactionRequest)==null?void 0:ae.format,k=(X||ns)({...lu(T,{format:X}),from:H==null?void 0:H.address,accessList:s,blobs:a,data:J,gas:p,gasPrice:m,maxFeePerBlobGas:g,maxFeePerGas:A,maxPriorityFeePerGas:S,nonce:P,to:Y?void 0:w,value:_});if(n&&Mg({request:k})&&!F&&!de)try{return await Dg(e,{...k,blockNumber:i,blockTag:o})}catch(te){if(!(te instanceof Mh)&&!(te instanceof Oc))throw te}const U=(()=>{const te=[k,pe];return F&&de?[...te,F,de]:F?[...te,F]:de?[...te,{},de]:te})(),j=await e.request({method:"eth_call",params:U});return j==="0x"?{data:void 0}:{data:j}}catch(_e){const pe=Gg(_e),{offchainLookup:de,offchainLookupSignature:F}=await Promise.resolve().then(()=>require("./ccip-wfXZPSJa.cjs"));if(e.ccipRead!==!1&&(pe==null?void 0:pe.slice(0,10))===F&&w)return{data:await de(e,{data:pe,to:w})};throw Y&&(pe==null?void 0:pe.slice(0,10))==="0x101bb98d"?new Mm({factory:h}):$g(_e,{...t,account:H,chain:e.chain})}}function Mg({request:e}){const{data:t,to:r,...n}=e;return!(!t||t.startsWith(Cg)||!r||Object.values(n).filter(i=>typeof i<"u").length>0)}async function Dg(e,t){var g;const{batchSize:r=1024,wait:n=0}=typeof((g=e.batch)==null?void 0:g.multicall)=="object"?e.batch.multicall:{},{blockNumber:i,blockTag:o="latest",data:s,multicallAddress:a,to:c}=t;let u=a;if(!u){if(!e.chain)throw new Mh;u=Hg({blockNumber:i,chain:e.chain,contract:"multicall3"})}const h=(typeof i=="bigint"?fe(i):void 0)||o,{schedule:y}=jh({id:`${e.uid}.${h}`,wait:n,shouldSplitBatch(A){return A.reduce((P,{data:w})=>P+(w.length-2),0)>r*2},fn:async A=>{const S=A.map(_=>({allowFailure:!0,callData:_.data,target:_.to})),P=qn({abi:_f,args:[S],functionName:"aggregate3"}),w=await e.request({method:"eth_call",params:[{data:P,to:u},h]});return vu({abi:_f,args:[S],functionName:"aggregate3",data:w||"0x"})}}),[{returnData:p,success:m}]=await y({data:s,to:c});if(!m)throw new mh({data:p});return p==="0x"?{data:void 0}:{data:p}}function jg(e){const{code:t,data:r}=e;return _u({abi:Dd(["constructor(bytes, bytes)"]),bytecode:Fg,args:[t,r]})}function qg(e){const{data:t,factory:r,factoryData:n,to:i}=e;return _u({abi:Dd(["constructor(address, bytes, address, bytes)"]),bytecode:Ng,args:[i,t,r,n]})}function Gg(e){var r;if(!(e instanceof z))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 zg(e,t){const{abi:r,address:n,args:i,functionName:o,...s}=t,a=qn({abi:r,args:i,functionName:o});try{const{data:c}=await ve(e,Eu,"call")({...s,data:a,to:n});return vu({abi:r,args:i,functionName:o,data:c||"0x"})}catch(c){throw ts(c,{abi:r,address:n,args:i,docsPath:"/docs/contract/readContract",functionName:o})}}async function Vg(e,t){const{abi:r,address:n,args:i,dataSuffix:o,functionName:s,...a}=t,c=a.account?Ve(a.account):e.account,u=qn({abi:r,args:i,functionName:s});try{const{data:f}=await ve(e,Eu,"call")({batch:!1,data:`${u}${o?o.replace("0x",""):""}`,to:n,...a,account:c}),h=vu({abi:r,args:i,functionName:s,data:f||"0x"}),y=r.filter(p=>"name"in p&&p.name===t.functionName);return{result:h,request:{abi:y,address:n,args:i,dataSuffix:o,functionName:s,...a,account:c}}}catch(f){throw ts(f,{abi:r,address:n,args:i,docsPath:"/docs/contract/simulateContract",functionName:s,sender:c==null?void 0:c.address})}}const Ms=new Map,Ef=new Map;let Wg=0;function Rc(e,t,r){const n=++Wg,i=()=>Ms.get(e)||[],o=()=>{const f=i();Ms.set(e,f.filter(h=>h.id!==n))},s=()=>{const f=i();if(!f.some(y=>y.id===n))return;const h=Ef.get(e);f.length===1&&h&&h(),o()},a=i();if(Ms.set(e,[...a,{id:n,fns:t}]),a&&a.length>0)return s;const c={};for(const f in t)c[f]=(...h)=>{var p,m;const y=i();if(y.length!==0)for(const g of y)(m=(p=g.fns)[f])==null||m.call(p,...h)};const u=r(c);return typeof u=="function"&&Ef.set(e,u),s}async function Cc(e){return new Promise(t=>setTimeout(t,e))}function qh(e,{emitOnBegin:t,initialWaitTime:r,interval:n}){let i=!0;const o=()=>i=!1;return(async()=>{let a;a=await e({unpoll:o});const c=await(r==null?void 0:r(a))??n;await Cc(c);const u=async()=>{i&&(await e({unpoll:o}),await Cc(n),u())};u()})(),o}const Kg=new Map,Yg=new Map;function Xg(e){const t=(i,o)=>({clear:()=>o.delete(i),get:()=>o.get(i),set:s=>o.set(i,s)}),r=t(e,Kg),n=t(e,Yg);return{clear:()=>{r.clear(),n.clear()},promise:r,response:n}}async function Jg(e,{cacheKey:t,cacheTime:r=Number.POSITIVE_INFINITY}){const n=Xg(t),i=n.response.get();if(i&&r>0&&new Date().getTime()-i.created.getTime()<r)return i.data;let o=n.promise.get();o||(o=e(),n.promise.set(o));try{const s=await o;return n.response.set({created:new Date,data:s}),s}finally{n.promise.clear()}}const Zg=e=>`blockNumber.${e}`;async function Qg(e,{cacheTime:t=e.cacheTime}={}){const r=await Jg(()=>e.request({method:"eth_blockNumber"}),{cacheKey:Zg(e.uid),cacheTime:t});return BigInt(r)}async function e1(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(o=>Ui(o));return!("abi"in t)||!t.abi?i:Lh({abi:t.abi,logs:i,strict:r})}async function t1(e,{filter:t}){return t.request({method:"eth_uninstallFilter",params:[t.id]})}function r1(e,t){const{abi:r,address:n,args:i,batch:o=!0,eventName:s,fromBlock:a,onError:c,onLogs:u,poll:f,pollingInterval:h=e.pollingInterval,strict:y}=t;return(typeof f<"u"?f:typeof a=="bigint"?!0:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket"))?(()=>{const A=y??!1,S=wt(["watchContractEvent",n,i,o,e.uid,s,h,A,a]);return Rc(S,{onLogs:u,onError:c},P=>{let w;a!==void 0&&(w=a-1n);let _,I=!1;const T=qh(async()=>{var H;if(!I){try{_=await ve(e,lh,"createContractEventFilter")({abi:r,address:n,args:i,eventName:s,strict:A,fromBlock:a})}catch{}I=!0;return}try{let M;if(_)M=await ve(e,e1,"getFilterChanges")({filter:_});else{const C=await ve(e,Qg,"getBlockNumber")({});w&&w<C?M=await ve(e,Hh,"getContractEvents")({abi:r,address:n,args:i,eventName:s,fromBlock:w+1n,toBlock:C,strict:A}):M=[],w=C}if(M.length===0)return;if(o)P.onLogs(M);else for(const C of M)P.onLogs([C])}catch(M){_&&M instanceof Tn&&(I=!1),(H=P.onError)==null||H.call(P,M)}},{emitOnBegin:!0,interval:h});return async()=>{_&&await ve(e,t1,"uninstallFilter")({filter:_}),T()}})})():(()=>{const A=y??!1,S=wt(["watchContractEvent",n,i,o,e.uid,s,h,A]);let P=!0,w=()=>P=!1;return Rc(S,{onLogs:u,onError:c},_=>((async()=>{try{const I=(()=>{if(e.transport.type==="fallback"){const M=e.transport.transports.find(C=>C.config.type==="webSocket");return M?M.value:e.transport}return e.transport})(),T=s?su({abi:r,eventName:s,args:i}):[],{unsubscribe:H}=await I.subscribe({params:["logs",{address:n,topics:T}],onData(M){var Y;if(!P)return;const C=M.result;try{const{eventName:J,args:re}=Uh({abi:r,data:C.data,topics:C.topics,strict:y}),ee=Ui(C,{args:re,eventName:J});_.onLogs([ee])}catch(J){let re,ee;if(J instanceof No||J instanceof eu){if(y)return;re=J.abiItem.name,ee=(Y=J.abiItem.inputs)==null?void 0:Y.some(ae=>!("name"in ae&&ae.name))}const Q=Ui(C,{args:ee?[]:{},eventName:re});_.onLogs([Q])}},onError(M){var C;(C=_.onError)==null||C.call(_,M)}});w=H,P||w()}catch(I){c==null||c(I)}})(),()=>w()))})()}class Nr extends z{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(`
42
- `),{docsPath:t,docsSlug:"account",name:"AccountNotFoundError"})}}class Po extends z{constructor({docsPath:t,metaMessages:r,type:n}){super(`Account type "${n}" is not supported.`,{docsPath:t,metaMessages:r,name:"AccountTypeNotSupportedError"})}}function Gh({chain:e,currentChainId:t}){if(!e)throw new Lg;if(t!==e.id)throw new Ug({chain:e,currentChainId:t})}function zh(e,{docsPath:t,...r}){const n=(()=>{const i=fu(e,r);return i instanceof rs?e:i})();return new Fm(n,{docsPath:t,...r})}async function Vh(e,{serializedTransaction:t}){return e.request({method:"eth_sendRawTransaction",params:[t]},{retryCount:0})}const Ds=new Jo(128);async function xu(e,t){var P,w,_,I;const{account:r=e.account,chain:n=e.chain,accessList:i,authorizationList:o,blobs:s,data:a,gas:c,gasPrice:u,maxFeePerBlobGas:f,maxFeePerGas:h,maxPriorityFeePerGas:y,nonce:p,type:m,value:g,...A}=t;if(typeof r>"u")throw new Nr({docsPath:"/docs/actions/wallet/sendTransaction"});const S=r?Ve(r):null;try{Yi(t);const T=await(async()=>{if(t.to)return t.to;if(t.to!==null&&o&&o.length>0)return await vh({authorization:o[0]}).catch(()=>{throw new z("`to` is required. Could not infer from `authorizationList`.")})})();if((S==null?void 0:S.type)==="json-rpc"||S===null){let H;n!==null&&(H=await ve(e,Xi,"getChainId")({}),Gh({currentChainId:H,chain:n}));const M=(_=(w=(P=e.chain)==null?void 0:P.formatters)==null?void 0:w.transactionRequest)==null?void 0:_.format,Y=(M||ns)({...lu(A,{format:M}),accessList:i,authorizationList:o,blobs:s,chainId:H,data:a,from:S==null?void 0:S.address,gas:c,gasPrice:u,maxFeePerBlobGas:f,maxFeePerGas:h,maxPriorityFeePerGas:y,nonce:p,to:T,type:m,value:g}),J=Ds.get(e.uid),re=J?"wallet_sendTransaction":"eth_sendTransaction";try{return await e.request({method:re,params:[Y]},{retryCount:0})}catch(ee){if(J===!1)throw ee;const Q=ee;if(Q.name==="InvalidInputRpcError"||Q.name==="InvalidParamsRpcError"||Q.name==="MethodNotFoundRpcError"||Q.name==="MethodNotSupportedRpcError")return await e.request({method:"wallet_sendTransaction",params:[Y]},{retryCount:0}).then(ae=>(Ds.set(e.uid,!0),ae)).catch(ae=>{const _e=ae;throw _e.name==="MethodNotFoundRpcError"||_e.name==="MethodNotSupportedRpcError"?(Ds.set(e.uid,!1),Q):_e});throw Q}}if((S==null?void 0:S.type)==="local"){const H=await ve(e,gu,"prepareTransactionRequest")({account:S,accessList:i,authorizationList:o,blobs:s,chain:n,data:a,gas:c,gasPrice:u,maxFeePerBlobGas:f,maxFeePerGas:h,maxPriorityFeePerGas:y,nonce:p,nonceManager:S.nonceManager,parameters:[...Fh,"sidecars"],type:m,value:g,...A,to:T}),M=(I=n==null?void 0:n.serializers)==null?void 0:I.transaction,C=await S.signTransaction(H,{serializer:M});return await ve(e,Vh,"sendRawTransaction")({serializedTransaction:C})}throw(S==null?void 0:S.type)==="smart"?new Po({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:"/docs/actions/bundler/sendUserOperation",type:"smart"}):new Po({docsPath:"/docs/actions/wallet/sendTransaction",type:S==null?void 0:S.type})}catch(T){throw T instanceof Po?T:zh(T,{...t,account:S,chain:t.chain||void 0})}}async function Wh(e,t){const{abi:r,account:n=e.account,address:i,args:o,dataSuffix:s,functionName:a,...c}=t;if(typeof n>"u")throw new Nr({docsPath:"/docs/contract/writeContract"});const u=n?Ve(n):null,f=qn({abi:r,args:o,functionName:a});try{return await ve(e,xu,"sendTransaction")({data:`${f}${s?s.replace("0x",""):""}`,to:i,account:u,...c})}catch(h){throw ts(h,{abi:r,address:i,args:o,docsPath:"/docs/contract/writeContract",functionName:a,sender:u==null?void 0:u.address})}}function js({abi:e,address:t,client:r}){const n=r,[i,o]=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],s=i!=null,a=o!=null,c={};let u=!1,f=!1,h=!1;for(const y of e)if(y.type==="function"?y.stateMutability==="view"||y.stateMutability==="pure"?u=!0:f=!0:y.type==="event"&&(h=!0),u&&f&&h)break;return s&&(u&&(c.read=new Proxy({},{get(y,p){return(...m)=>{const{args:g,options:A}=lo(m);return ve(i,zg,"readContract")({abi:e,address:t,functionName:p,args:g,...A})}}})),f&&(c.simulate=new Proxy({},{get(y,p){return(...m)=>{const{args:g,options:A}=lo(m);return ve(i,Vg,"simulateContract")({abi:e,address:t,functionName:p,args:g,...A})}}})),h&&(c.createEventFilter=new Proxy({},{get(y,p){return(...m)=>{const g=e.find(P=>P.type==="event"&&P.name===p),{args:A,options:S}=qs(m,g);return ve(i,lh,"createContractEventFilter")({abi:e,address:t,eventName:p,args:A,...S})}}}),c.getEvents=new Proxy({},{get(y,p){return(...m)=>{const g=e.find(P=>P.type==="event"&&P.name===p),{args:A,options:S}=qs(m,g);return ve(i,Hh,"getContractEvents")({abi:e,address:t,eventName:p,args:A,...S})}}}),c.watchEvent=new Proxy({},{get(y,p){return(...m)=>{const g=e.find(P=>P.type==="event"&&P.name===p),{args:A,options:S}=qs(m,g);return ve(i,r1,"watchContractEvent")({abi:e,address:t,eventName:p,args:A,...S})}}}))),a&&f&&(c.write=new Proxy({},{get(y,p){return(...m)=>{const{args:g,options:A}=lo(m);return ve(o,Wh,"writeContract")({abi:e,address:t,functionName:p,args:g,...A})}}})),(s||a)&&f&&(c.estimateGas=new Proxy({},{get(y,p){return(...m)=>{const{args:g,options:A}=lo(m);return ve(i??o,vg,"estimateContractGas")({abi:e,address:t,functionName:p,args:g,...A,account:A.account??o.account})}}})),c.address=t,c.abi=e,c}function lo(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 qs(e,t){let r=!1;Array.isArray(e[0])?r=!0:e.length===1?r=t.inputs.some(o=>o.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 Kh={"0x0":"reverted","0x1":"success"};function n1(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=>Ui(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?lr(e.transactionIndex):null,status:e.status?Kh[e.status]:null,type:e.type?Eh[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const i1=du("transactionReceipt",n1);async function Yh(e,t){const{atomic:r=!1,chainId:n,receipts:i,version:o="2.0.0",...s}=await e.request({method:"wallet_getCallsStatus",params:[t.id]}),[a,c]=(()=>{const u=s.status;return u>=100&&u<200?["pending",u]:u>=200&&u<300?["success",u]:u>=300&&u<700?["failure",u]:u==="CONFIRMED"?["success",200]:u==="PENDING"?["pending",100]:[void 0,u]})();return{...s,atomic:r,chainId:n?lr(n):void 0,receipts:(i==null?void 0:i.map(u=>({...u,blockNumber:kt(u.blockNumber),gasUsed:kt(u.gasUsed),status:Kh[u.status]})))??[],statusCode:c,status:a,version:o}}async function o1(e,t){const{id:r,pollingInterval:n=e.pollingInterval,status:i=({statusCode:y})=>y>=200,timeout:o=6e4}=t,s=wt(["waitForCallsStatus",e.uid,r]),{promise:a,resolve:c,reject:u}=Dh();let f;const h=Rc(s,{resolve:c,reject:u},y=>{const p=qh(async()=>{const m=g=>{clearTimeout(f),p(),g(),h()};try{const g=await Yh(e,{id:r});if(!i(g))return;m(()=>y.resolve(g))}catch(g){m(()=>y.reject(g))}},{interval:n,emitOnBegin:!0});return p});return f=o?setTimeout(()=>{h(),clearTimeout(f),u(new s1({id:r}))},o):void 0,await a}class s1 extends z{constructor({id:t}){super(`Timed out while waiting for call bundle with id "${t}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}const Fc=256;let ho=Fc,po;function Xh(e=11){if(!po||ho+e>Fc*2){po="",ho=0;for(let t=0;t<Fc;t++)po+=(256+Math.random()*256|0).toString(16).substring(1)}return po.substring(ho,ho+++e)}function a1(e){const{batch:t,cacheTime:r=e.pollingInterval??4e3,ccipRead:n,key:i="base",name:o="Base Client",pollingInterval:s=4e3,type:a="base"}=e,c=e.chain,u=e.account?Ve(e.account):void 0,{config:f,request:h,value:y}=e.transport({chain:c,pollingInterval:s}),p={...f,...y},m={account:u,batch:t,cacheTime:r,ccipRead:n,chain:c,key:i,name:o,pollingInterval:s,request:h,transport:p,type:a,uid:Xh()};function g(A){return S=>{const P=S(A);for(const _ in m)delete P[_];const w={...A,...P};return Object.assign(w,{extend:g(w)})}}return Object.assign(m,{extend:g(m)})}const yo=new Jo(8192);function c1(e,{enabled:t=!0,id:r}){if(!t||!r)return e();if(yo.get(r))return yo.get(r);const n=e().finally(()=>yo.delete(r));return yo.set(r,n),n}function u1(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((i,o)=>{const s=async({count:a=0}={})=>{const c=async({error:u})=>{const f=typeof t=="function"?t({count:a,error:u}):t;f&&await Cc(f),s({count:a+1})};try{const u=await e();i(u)}catch(u){if(a<r&&await n({count:a,error:u}))return c({error:u});o(u)}};s()})}function f1(e,t={}){return async(r,n={})=>{var h;const{dedupe:i=!1,methods:o,retryDelay:s=150,retryCount:a=3,uid:c}={...t,...n},{method:u}=r;if((h=o==null?void 0:o.exclude)!=null&&h.includes(u))throw new qr(new Error("method not supported"),{method:u});if(o!=null&&o.include&&!o.include.includes(u))throw new qr(new Error("method not supported"),{method:u});const f=i?Ko(`${c}.${wt(r)}`):void 0;return c1(()=>u1(async()=>{try{return await e(r)}catch(y){const p=y;switch(p.code){case yi.code:throw new yi(p);case bi.code:throw new bi(p);case mi.code:throw new mi(p,{method:r.method});case gi.code:throw new gi(p);case Zr.code:throw new Zr(p);case Tn.code:throw new Tn(p);case wi.code:throw new wi(p);case vi.code:throw new vi(p);case _i.code:throw new _i(p);case qr.code:throw new qr(p,{method:r.method});case In.code:throw new In(p);case Ei.code:throw new Ei(p);case _n.code:throw new _n(p);case xi.code:throw new xi(p);case Ai.code:throw new Ai(p);case Si.code:throw new Si(p);case Pi.code:throw new Pi(p);case Ti.code:throw new Ti(p);case Ii.code:throw new Ii(p);case Bi.code:throw new Bi(p);case ki.code:throw new ki(p);case Oi.code:throw new Oi(p);case Ri.code:throw new Ri(p);case Ci.code:throw new Ci(p);case Fi.code:throw new Fi(p);case 5e3:throw new _n(p);default:throw y instanceof z?y:new jm(p)}}},{delay:({count:y,error:p})=>{var m;if(p&&p instanceof vn){const g=(m=p==null?void 0:p.headers)==null?void 0:m.get("Retry-After");if(g!=null&&g.match(/\d/))return Number.parseInt(g)*1e3}return~~(1<<y)*s},retryCount:a,shouldRetry:({error:y})=>l1(y)}),{enabled:i,id:f})}}function l1(e){return"code"in e&&typeof e.code=="number"?e.code===-1||e.code===In.code||e.code===Zr.code:e instanceof vn&&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 Jh({key:e,methods:t,name:r,request:n,retryCount:i=3,retryDelay:o=150,timeout:s,type:a},c){const u=Xh();return{config:{key:e,methods:t,name:r,request:n,retryCount:i,retryDelay:o,timeout:s,type:a},request:f1(n,{methods:t,retryCount:i,retryDelay:o,uid:u}),value:c}}function xf(e,t={}){const{key:r="custom",methods:n,name:i="Custom Provider",retryDelay:o}=t;return({retryCount:s})=>Jh({key:r,methods:n,name:i,request:e.request.bind(e),retryCount:t.retryCount??s,retryDelay:o,type:"custom"})}class d1 extends z{constructor(){super("No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.",{docsPath:"/docs/clients/intro",name:"UrlRequiredError"})}}function h1(e,{errorInstance:t=new Error("timed out"),timeout:r,signal:n}){return new Promise((i,o)=>{(async()=>{let s;try{const a=new AbortController;r>0&&(s=setTimeout(()=>{n&&a.abort()},r)),i(await e({signal:(a==null?void 0:a.signal)||null}))}catch(a){(a==null?void 0:a.name)==="AbortError"&&o(t),o(a)}finally{clearTimeout(s)}})()})}function p1(){return{current:0,take(){return this.current++},reset(){this.current=0}}}const Af=p1();function y1(e,t={}){return{async request(r){var h;const{body:n,onRequest:i=t.onRequest,onResponse:o=t.onResponse,timeout:s=t.timeout??1e4}=r,a={...t.fetchOptions??{},...r.fetchOptions??{}},{headers:c,method:u,signal:f}=a;try{const y=await h1(async({signal:m})=>{const g={...a,body:Array.isArray(n)?wt(n.map(w=>({jsonrpc:"2.0",id:w.id??Af.take(),...w}))):wt({jsonrpc:"2.0",id:n.id??Af.take(),...n}),headers:{"Content-Type":"application/json",...c},method:u||"POST",signal:f||(s>0?m:null)},A=new Request(e,g),S=await(i==null?void 0:i(A,g))??{...g,url:e};return await fetch(S.url??e,S)},{errorInstance:new hf({body:n,url:e}),timeout:s,signal:!0});o&&await o(y);let p;if((h=y.headers.get("Content-Type"))!=null&&h.startsWith("application/json"))p=await y.json();else{p=await y.text();try{p=JSON.parse(p||"{}")}catch(m){if(y.ok)throw m;p={error:p}}}if(!y.ok)throw new vn({body:n,details:wt(p.error)||y.statusText,headers:y.headers,status:y.status,url:e});return p}catch(y){throw y instanceof vn||y instanceof hf?y:new vn({body:n,cause:y,url:e})}}}}function b1(e,t={}){const{batch:r,fetchOptions:n,key:i="http",methods:o,name:s="HTTP JSON-RPC",onFetchRequest:a,onFetchResponse:c,retryDelay:u,raw:f}=t;return({chain:h,retryCount:y,timeout:p})=>{const{batchSize:m=1e3,wait:g=0}=typeof r=="object"?r:{},A=t.retryCount??y,S=p??t.timeout??1e4,P=h==null?void 0:h.rpcUrls.default.http[0];if(!P)throw new d1;const w=y1(P,{fetchOptions:n,onRequest:a,onResponse:c,timeout:S});return Jh({key:i,methods:o,name:s,async request({method:_,params:I}){const T={method:_,params:I},{schedule:H}=jh({id:P,wait:g,shouldSplitBatch(J){return J.length>m},fn:J=>w.request({body:J}),sort:(J,re)=>J.id-re.id}),M=async J=>r?H(J):[await w.request({body:J})],[{error:C,result:Y}]=await M(T);if(f)return{error:C,result:Y};if(C)throw new uu({body:T,error:C,url:P});return Y},retryCount:A,retryDelay:u,timeout:S,type:"http"},{fetchOptions:n,url:P})}}function Zt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}class m1 extends z{constructor({domain:t}){super(`Invalid domain "${wt(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class g1 extends z{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 w1 extends z{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function v1(e){const{domain:t,message:r,primaryType:n,types:i}=e,o=(c,u)=>{const f={...u};for(const h of c){const{name:y,type:p}=h;p==="address"&&(f[y]=f[y].toLowerCase())}return f},s=i.EIP712Domain?t?o(i.EIP712Domain,t):{}:{},a=(()=>{if(n!=="EIP712Domain")return o(i[n],r)})();return wt({domain:s,message:a,primaryType:n,types:i})}function _1(e){const{domain:t,message:r,primaryType:n,types:i}=e,o=(s,a)=>{for(const c of s){const{name:u,type:f}=c,h=a[u],y=f.match(uh);if(y&&(typeof h=="number"||typeof h=="bigint")){const[g,A,S]=y;fe(h,{signed:A==="int",size:Number.parseInt(S)/8})}if(f==="address"&&typeof h=="string"&&!ze(h))throw new bt({address:h});const p=f.match(em);if(p){const[g,A]=p;if(A&&Le(h)!==Number.parseInt(A))throw new fb({expectedSize:Number.parseInt(A),givenSize:Le(h)})}const m=i[f];m&&(x1(f),o(m,h))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new m1({domain:t});o(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])o(i[n],r);else throw new g1({primaryType:n,types:i})}function E1({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 x1(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new w1({type:e})}function A1(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!ze(i))throw new bt({address:i});if(n<0)throw new os({chainId:n})}Au(e)}function S1(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Oh;for(const r of t){const n=Le(r),i=lr(Pn(r,0,1));if(n!==32)throw new bg({hash:r,size:n});if(i!==kh)throw new mg({hash:r,version:i})}}Au(e)}function Au(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new os({chainId:t});if(i&&!ze(i))throw new bt({address:i});if(n&&n>is)throw new Qr({maxFeePerGas:n});if(r&&n&&r>n)throw new Ni({maxFeePerGas:n,maxPriorityFeePerGas:r})}function P1(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:o}=e;if(t<=0)throw new os({chainId:t});if(o&&!ze(o))throw new bt({address:o});if(r||i)throw new z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>is)throw new Qr({maxFeePerGas:n})}function T1(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:o}=e;if(o&&!ze(o))throw new bt({address:o});if(typeof t<"u"&&t<=0)throw new os({chainId:t});if(r||i)throw new z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>is)throw new Qr({maxFeePerGas:n})}function ss(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 o=0;o<i.length;o++)if(i[o].length-2!==64)throw new Cm({storageKey:i[o]});if(!ze(n,{strict:!1}))throw new bt({address:n});t.push([n,i])}return t}function I1(e,t){const r=Ch(e);return r==="eip1559"?O1(e,t):r==="eip2930"?R1(e,t):r==="eip4844"?k1(e,t):r==="eip7702"?B1(e,t):C1(e,t)}function B1(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:o,to:s,value:a,maxFeePerGas:c,maxPriorityFeePerGas:u,accessList:f,data:h}=e;A1(e);const y=ss(f),p=F1(r);return Jt(["0x04",Cr([ue(n),o?ue(o):"0x",u?ue(u):"0x",c?ue(c):"0x",i?ue(i):"0x",s??"0x",a?ue(a):"0x",h??"0x",y,p,...Ji(e,t)])])}function k1(e,t){const{chainId:r,gas:n,nonce:i,to:o,value:s,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:u,accessList:f,data:h}=e;S1(e);let y=e.blobVersionedHashes,p=e.sidecars;if(e.blobs&&(typeof y>"u"||typeof p>"u")){const w=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(T=>yt(T)),_=e.kzg,I=yu({blobs:w,kzg:_});if(typeof y>"u"&&(y=Th({commitments:I})),typeof p>"u"){const T=bu({blobs:w,commitments:I,kzg:_});p=Rh({blobs:w,commitments:I,proofs:T})}}const m=ss(f),g=[ue(r),i?ue(i):"0x",u?ue(u):"0x",c?ue(c):"0x",n?ue(n):"0x",o??"0x",s?ue(s):"0x",h??"0x",m,a?ue(a):"0x",y??[],...Ji(e,t)],A=[],S=[],P=[];if(p)for(let w=0;w<p.length;w++){const{blob:_,commitment:I,proof:T}=p[w];A.push(_),S.push(I),P.push(T)}return Jt(["0x03",Cr(p?[g,A,S,P]:g)])}function O1(e,t){const{chainId:r,gas:n,nonce:i,to:o,value:s,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:u,data:f}=e;Au(e);const h=ss(u),y=[ue(r),i?ue(i):"0x",c?ue(c):"0x",a?ue(a):"0x",n?ue(n):"0x",o??"0x",s?ue(s):"0x",f??"0x",h,...Ji(e,t)];return Jt(["0x02",Cr(y)])}function R1(e,t){const{chainId:r,gas:n,data:i,nonce:o,to:s,value:a,accessList:c,gasPrice:u}=e;P1(e);const f=ss(c),h=[ue(r),o?ue(o):"0x",u?ue(u):"0x",n?ue(n):"0x",s??"0x",a?ue(a):"0x",i??"0x",f,...Ji(e,t)];return Jt(["0x01",Cr(h)])}function C1(e,t){const{chainId:r=0,gas:n,data:i,nonce:o,to:s,value:a,gasPrice:c}=e;T1(e);let u=[o?ue(o):"0x",c?ue(c):"0x",n?ue(n):"0x",s??"0x",a?ue(a):"0x",i??"0x"];if(t){const f=(()=>{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 Om({v:t.v});return p})(),h=Xr(t.r),y=Xr(t.s);u=[...u,ue(f),h==="0x00"?"0x":h,y==="0x00"?"0x":y]}else r>0&&(u=[...u,ue(r),"0x","0x"]);return Cr(u)}function Ji(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 o=Xr(r.r),s=Xr(r.s);return[typeof i=="number"?i?ue(1):"0x":n===0n?"0x":n===1n?ue(1):n===27n?"0x":ue(1),o==="0x00"?"0x":o,s==="0x00"?"0x":s]}function F1(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{chainId:n,nonce:i,...o}=r,s=r.address;t.push([n?ue(n):"0x",s,i?ue(i):"0x",...Ji({},o)])}return t}var We=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function N1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function U1(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 Bn={},pt={},st={},as={},cs={};Object.defineProperty(cs,"__esModule",{value:!0});cs.crypto=void 0;cs.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.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=r,e.anumber=n,e.abytes=i,e.ahash=o,e.aexists=s,e.aoutput=a,e.u8=c,e.u32=u,e.clean=f,e.createView=h,e.rotr=y,e.rotl=p,e.byteSwap=m,e.byteSwap32=g,e.bytesToHex=P,e.hexToBytes=I,e.asyncLoop=H,e.utf8ToBytes=M,e.bytesToUtf8=C,e.toBytes=Y,e.kdfInputToBytes=J,e.concatBytes=re,e.checkOpts=ee,e.createHasher=ae,e.createOptHasher=_e,e.createXOFer=pe,e.randomBytes=de;const t=cs;function r(F){return F instanceof Uint8Array||ArrayBuffer.isView(F)&&F.constructor.name==="Uint8Array"}function n(F){if(!Number.isSafeInteger(F)||F<0)throw new Error("positive integer expected, got "+F)}function i(F,...X){if(!r(F))throw new Error("Uint8Array expected");if(X.length>0&&!X.includes(F.length))throw new Error("Uint8Array expected of length "+X+", got length="+F.length)}function o(F){if(typeof F!="function"||typeof F.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");n(F.outputLen),n(F.blockLen)}function s(F,X=!0){if(F.destroyed)throw new Error("Hash instance has been destroyed");if(X&&F.finished)throw new Error("Hash#digest() has already been called")}function a(F,X){i(F);const ne=X.outputLen;if(F.length<ne)throw new Error("digestInto() expects output buffer of length at least "+ne)}function c(F){return new Uint8Array(F.buffer,F.byteOffset,F.byteLength)}function u(F){return new Uint32Array(F.buffer,F.byteOffset,Math.floor(F.byteLength/4))}function f(...F){for(let X=0;X<F.length;X++)F[X].fill(0)}function h(F){return new DataView(F.buffer,F.byteOffset,F.byteLength)}function y(F,X){return F<<32-X|F>>>X}function p(F,X){return F<<X|F>>>32-X>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function m(F){return F<<24&4278190080|F<<8&16711680|F>>>8&65280|F>>>24&255}e.swap8IfBE=e.isLE?F=>F:F=>m(F),e.byteSwapIfBE=e.swap8IfBE;function g(F){for(let X=0;X<F.length;X++)F[X]=m(F[X]);return F}e.swap32IfBE=e.isLE?F=>F:g;const A=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",S=Array.from({length:256},(F,X)=>X.toString(16).padStart(2,"0"));function P(F){if(i(F),A)return F.toHex();let X="";for(let ne=0;ne<F.length;ne++)X+=S[F[ne]];return X}const w={_0:48,_9:57,A:65,F:70,a:97,f:102};function _(F){if(F>=w._0&&F<=w._9)return F-w._0;if(F>=w.A&&F<=w.F)return F-(w.A-10);if(F>=w.a&&F<=w.f)return F-(w.a-10)}function I(F){if(typeof F!="string")throw new Error("hex string expected, got "+typeof F);if(A)return Uint8Array.fromHex(F);const X=F.length,ne=X/2;if(X%2)throw new Error("hex string expected, got unpadded hex of length "+X);const k=new Uint8Array(ne);for(let U=0,j=0;U<ne;U++,j+=2){const te=_(F.charCodeAt(j)),B=_(F.charCodeAt(j+1));if(te===void 0||B===void 0){const O=F[j]+F[j+1];throw new Error('hex string expected, got non-hex character "'+O+'" at index '+j)}k[U]=te*16+B}return k}const T=async()=>{};e.nextTick=T;async function H(F,X,ne){let k=Date.now();for(let U=0;U<F;U++){ne(U);const j=Date.now()-k;j>=0&&j<X||(await(0,e.nextTick)(),k+=j)}}function M(F){if(typeof F!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(F))}function C(F){return new TextDecoder().decode(F)}function Y(F){return typeof F=="string"&&(F=M(F)),i(F),F}function J(F){return typeof F=="string"&&(F=M(F)),i(F),F}function re(...F){let X=0;for(let k=0;k<F.length;k++){const U=F[k];i(U),X+=U.length}const ne=new Uint8Array(X);for(let k=0,U=0;k<F.length;k++){const j=F[k];ne.set(j,U),U+=j.length}return ne}function ee(F,X){if(X!==void 0&&{}.toString.call(X)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(F,X)}class Q{}e.Hash=Q;function ae(F){const X=k=>F().update(Y(k)).digest(),ne=F();return X.outputLen=ne.outputLen,X.blockLen=ne.blockLen,X.create=()=>F(),X}function _e(F){const X=(k,U)=>F(U).update(Y(k)).digest(),ne=F({});return X.outputLen=ne.outputLen,X.blockLen=ne.blockLen,X.create=k=>F(k),X}function pe(F){const X=(k,U)=>F(U).update(Y(k)).digest(),ne=F({});return X.outputLen=ne.outputLen,X.blockLen=ne.blockLen,X.create=k=>F(k),X}e.wrapConstructor=ae,e.wrapConstructorWithOpts=_e,e.wrapXOFConstructorWithOpts=pe;function de(F=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(F));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(F));throw new Error("crypto.getRandomValues must be defined")}})(as);Object.defineProperty(st,"__esModule",{value:!0});st.SHA512_IV=st.SHA384_IV=st.SHA224_IV=st.SHA256_IV=st.HashMD=void 0;st.setBigUint64=Zh;st.Chi=L1;st.Maj=H1;const Mt=as;function Zh(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+u,a,n)}function L1(e,t,r){return e&t^~e&r}function H1(e,t,r){return e&t^e&r^t&r}class $1 extends Mt.Hash{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=(0,Mt.createView)(this.buffer)}update(t){(0,Mt.aexists)(this),t=(0,Mt.toBytes)(t),(0,Mt.abytes)(t);const{view:r,buffer:n,blockLen:i}=this,o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=(0,Mt.createView)(t);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Mt.aexists)(this),(0,Mt.aoutput)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:o}=this;let{pos:s}=this;r[s++]=128,(0,Mt.clean)(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let h=s;h<i;h++)r[h]=0;Zh(n,i-8,BigInt(this.length*8),o),this.process(n,0);const a=(0,Mt.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}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:o,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=o,t.length=i,t.pos=a,i%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}}st.HashMD=$1;st.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);st.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);st.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);st.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);Object.defineProperty(pt,"__esModule",{value:!0});pt.ripemd160=pt.RIPEMD160=pt.md5=pt.MD5=pt.sha1=pt.SHA1=void 0;const zr=st,Qe=as,hn=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),wr=new Uint32Array(80);class Qh extends zr.HashMD{constructor(){super(64,20,8,!1),this.A=hn[0]|0,this.B=hn[1]|0,this.C=hn[2]|0,this.D=hn[3]|0,this.E=hn[4]|0}get(){const{A:t,B:r,C:n,D:i,E:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0}process(t,r){for(let c=0;c<16;c++,r+=4)wr[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)wr[c]=(0,Qe.rotl)(wr[c-3]^wr[c-8]^wr[c-14]^wr[c-16],1);let{A:n,B:i,C:o,D:s,E:a}=this;for(let c=0;c<80;c++){let u,f;c<20?(u=(0,zr.Chi)(i,o,s),f=1518500249):c<40?(u=i^o^s,f=1859775393):c<60?(u=(0,zr.Maj)(i,o,s),f=2400959708):(u=i^o^s,f=3395469782);const h=(0,Qe.rotl)(n,5)+u+a+f+wr[c]|0;a=s,s=o,o=(0,Qe.rotl)(i,30),i=n,n=h}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,this.set(n,i,o,s,a)}roundClean(){(0,Qe.clean)(wr)}destroy(){this.set(0,0,0,0,0),(0,Qe.clean)(this.buffer)}}pt.SHA1=Qh;pt.sha1=(0,Qe.createHasher)(()=>new Qh);const M1=Math.pow(2,32),D1=Array.from({length:64},(e,t)=>Math.floor(M1*Math.abs(Math.sin(t+1)))),bo=hn.slice(0,4),Gs=new Uint32Array(16);let ep=class extends zr.HashMD{constructor(){super(64,16,8,!0),this.A=bo[0]|0,this.B=bo[1]|0,this.C=bo[2]|0,this.D=bo[3]|0}get(){const{A:t,B:r,C:n,D:i}=this;return[t,r,n,i]}set(t,r,n,i){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0}process(t,r){for(let a=0;a<16;a++,r+=4)Gs[a]=t.getUint32(r,!0);let{A:n,B:i,C:o,D:s}=this;for(let a=0;a<64;a++){let c,u,f;a<16?(c=(0,zr.Chi)(i,o,s),u=a,f=[7,12,17,22]):a<32?(c=(0,zr.Chi)(s,i,o),u=(5*a+1)%16,f=[5,9,14,20]):a<48?(c=i^o^s,u=(3*a+5)%16,f=[4,11,16,23]):(c=o^(i|~s),u=7*a%16,f=[6,10,15,21]),c=c+n+D1[a]+Gs[u],n=s,s=o,o=i,i=i+(0,Qe.rotl)(c,f[a%4])}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,this.set(n,i,o,s)}roundClean(){(0,Qe.clean)(Gs)}destroy(){this.set(0,0,0,0),(0,Qe.clean)(this.buffer)}};pt.MD5=ep;pt.md5=(0,Qe.createHasher)(()=>new ep);const j1=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),tp=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),q1=tp.map(e=>(9*e+5)%16),rp=(()=>{const r=[[tp],[q1]];for(let n=0;n<4;n++)for(let i of r)i.push(i[n].map(o=>j1[o]));return r})(),np=rp[0],ip=rp[1],op=[[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=>Uint8Array.from(e)),G1=np.map((e,t)=>e.map(r=>op[t][r])),z1=ip.map((e,t)=>e.map(r=>op[t][r])),V1=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),W1=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Sf(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 mo=new Uint32Array(16);let sp=class extends zr.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(t,r){for(let p=0;p<16;p++,r+=4)mo[p]=t.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,a=this.h2|0,c=a,u=this.h3|0,f=u,h=this.h4|0,y=h;for(let p=0;p<5;p++){const m=4-p,g=V1[p],A=W1[p],S=np[p],P=ip[p],w=G1[p],_=z1[p];for(let I=0;I<16;I++){const T=(0,Qe.rotl)(n+Sf(p,o,a,u)+mo[S[I]]+g,w[I])+h|0;n=h,h=u,u=(0,Qe.rotl)(a,10)|0,a=o,o=T}for(let I=0;I<16;I++){const T=(0,Qe.rotl)(i+Sf(m,s,c,f)+mo[P[I]]+A,_[I])+y|0;i=y,y=f,f=(0,Qe.rotl)(c,10)|0,c=s,s=T}}this.set(this.h1+a+f|0,this.h2+u+y|0,this.h3+h+i|0,this.h4+n+s|0,this.h0+o+c|0)}roundClean(){(0,Qe.clean)(mo)}destroy(){this.destroyed=!0,(0,Qe.clean)(this.buffer),this.set(0,0,0,0,0)}};pt.RIPEMD160=sp;pt.ripemd160=(0,Qe.createHasher)(()=>new sp);Object.defineProperty(Bn,"__esModule",{value:!0});Bn.ripemd160=Bn.RIPEMD160=void 0;const ap=pt;Bn.RIPEMD160=ap.RIPEMD160;Bn.ripemd160=ap.ripemd160;var Nt={},Te={},ce={};Object.defineProperty(ce,"__esModule",{value:!0});ce.toBig=ce.shrSL=ce.shrSH=ce.rotrSL=ce.rotrSH=ce.rotrBL=ce.rotrBH=ce.rotr32L=ce.rotr32H=ce.rotlSL=ce.rotlSH=ce.rotlBL=ce.rotlBH=ce.add5L=ce.add5H=ce.add4L=ce.add4H=ce.add3L=ce.add3H=void 0;ce.add=Ep;ce.fromBig=Su;ce.split=cp;const go=BigInt(2**32-1),Nc=BigInt(32);function Su(e,t=!1){return t?{h:Number(e&go),l:Number(e>>Nc&go)}:{h:Number(e>>Nc&go)|0,l:Number(e&go)|0}}function cp(e,t=!1){const r=e.length;let n=new Uint32Array(r),i=new Uint32Array(r);for(let o=0;o<r;o++){const{h:s,l:a}=Su(e[o],t);[n[o],i[o]]=[s,a]}return[n,i]}const up=(e,t)=>BigInt(e>>>0)<<Nc|BigInt(t>>>0);ce.toBig=up;const fp=(e,t,r)=>e>>>r;ce.shrSH=fp;const lp=(e,t,r)=>e<<32-r|t>>>r;ce.shrSL=lp;const dp=(e,t,r)=>e>>>r|t<<32-r;ce.rotrSH=dp;const hp=(e,t,r)=>e<<32-r|t>>>r;ce.rotrSL=hp;const pp=(e,t,r)=>e<<64-r|t>>>r-32;ce.rotrBH=pp;const yp=(e,t,r)=>e>>>r-32|t<<64-r;ce.rotrBL=yp;const bp=(e,t)=>t;ce.rotr32H=bp;const mp=(e,t)=>e;ce.rotr32L=mp;const gp=(e,t,r)=>e<<r|t>>>32-r;ce.rotlSH=gp;const wp=(e,t,r)=>t<<r|e>>>32-r;ce.rotlSL=wp;const vp=(e,t,r)=>t<<r-32|e>>>64-r;ce.rotlBH=vp;const _p=(e,t,r)=>e<<r-32|t>>>64-r;ce.rotlBL=_p;function Ep(e,t,r,n){const i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:i|0}}const xp=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0);ce.add3L=xp;const Ap=(e,t,r,n)=>t+r+n+(e/2**32|0)|0;ce.add3H=Ap;const Sp=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0);ce.add4L=Sp;const Pp=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0;ce.add4H=Pp;const Tp=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0);ce.add5L=Tp;const Ip=(e,t,r,n,i,o)=>t+r+n+i+o+(e/2**32|0)|0;ce.add5H=Ip;const K1={fromBig:Su,split:cp,toBig:up,shrSH:fp,shrSL:lp,rotrSH:dp,rotrSL:hp,rotrBH:pp,rotrBL:yp,rotr32H:bp,rotr32L:mp,rotlSH:gp,rotlSL:wp,rotlBH:vp,rotlBL:_p,add:Ep,add3L:xp,add3H:Ap,add4L:Sp,add4H:Pp,add5H:Ip,add5L:Tp};ce.default=K1;Object.defineProperty(Te,"__esModule",{value:!0});Te.sha512_224=Te.sha512_256=Te.sha384=Te.sha512=Te.sha224=Te.sha256=Te.SHA512_256=Te.SHA512_224=Te.SHA384=Te.SHA512=Te.SHA224=Te.SHA256=void 0;const se=st,le=ce,Me=as,Y1=Uint32Array.from([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]),vr=new Uint32Array(64);class Pu extends se.HashMD{constructor(t=32){super(64,t,8,!1),this.A=se.SHA256_IV[0]|0,this.B=se.SHA256_IV[1]|0,this.C=se.SHA256_IV[2]|0,this.D=se.SHA256_IV[3]|0,this.E=se.SHA256_IV[4]|0,this.F=se.SHA256_IV[5]|0,this.G=se.SHA256_IV[6]|0,this.H=se.SHA256_IV[7]|0}get(){const{A:t,B:r,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[t,r,n,i,o,s,a,c]}set(t,r,n,i,o,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let h=0;h<16;h++,r+=4)vr[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const y=vr[h-15],p=vr[h-2],m=(0,Me.rotr)(y,7)^(0,Me.rotr)(y,18)^y>>>3,g=(0,Me.rotr)(p,17)^(0,Me.rotr)(p,19)^p>>>10;vr[h]=g+vr[h-7]+m+vr[h-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){const y=(0,Me.rotr)(a,6)^(0,Me.rotr)(a,11)^(0,Me.rotr)(a,25),p=f+y+(0,se.Chi)(a,c,u)+Y1[h]+vr[h]|0,g=((0,Me.rotr)(n,2)^(0,Me.rotr)(n,13)^(0,Me.rotr)(n,22))+(0,se.Maj)(n,i,o)|0;f=u,u=c,c=a,a=s+p|0,s=o,o=i,i=n,n=p+g|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,a,c,u,f)}roundClean(){(0,Me.clean)(vr)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,Me.clean)(this.buffer)}}Te.SHA256=Pu;class Bp extends Pu{constructor(){super(28),this.A=se.SHA224_IV[0]|0,this.B=se.SHA224_IV[1]|0,this.C=se.SHA224_IV[2]|0,this.D=se.SHA224_IV[3]|0,this.E=se.SHA224_IV[4]|0,this.F=se.SHA224_IV[5]|0,this.G=se.SHA224_IV[6]|0,this.H=se.SHA224_IV[7]|0}}Te.SHA224=Bp;const kp=le.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),X1=kp[0],J1=kp[1],_r=new Uint32Array(80),Er=new Uint32Array(80);let Zi=class extends se.HashMD{constructor(t=64){super(128,t,16,!1),this.Ah=se.SHA512_IV[0]|0,this.Al=se.SHA512_IV[1]|0,this.Bh=se.SHA512_IV[2]|0,this.Bl=se.SHA512_IV[3]|0,this.Ch=se.SHA512_IV[4]|0,this.Cl=se.SHA512_IV[5]|0,this.Dh=se.SHA512_IV[6]|0,this.Dl=se.SHA512_IV[7]|0,this.Eh=se.SHA512_IV[8]|0,this.El=se.SHA512_IV[9]|0,this.Fh=se.SHA512_IV[10]|0,this.Fl=se.SHA512_IV[11]|0,this.Gh=se.SHA512_IV[12]|0,this.Gl=se.SHA512_IV[13]|0,this.Hh=se.SHA512_IV[14]|0,this.Hl=se.SHA512_IV[15]|0}get(){const{Ah:t,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:y,Gh:p,Gl:m,Hh:g,Hl:A}=this;return[t,r,n,i,o,s,a,c,u,f,h,y,p,m,g,A]}set(t,r,n,i,o,s,a,c,u,f,h,y,p,m,g,A){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=y|0,this.Gh=p|0,this.Gl=m|0,this.Hh=g|0,this.Hl=A|0}process(t,r){for(let w=0;w<16;w++,r+=4)_r[w]=t.getUint32(r),Er[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){const _=_r[w-15]|0,I=Er[w-15]|0,T=le.rotrSH(_,I,1)^le.rotrSH(_,I,8)^le.shrSH(_,I,7),H=le.rotrSL(_,I,1)^le.rotrSL(_,I,8)^le.shrSL(_,I,7),M=_r[w-2]|0,C=Er[w-2]|0,Y=le.rotrSH(M,C,19)^le.rotrBH(M,C,61)^le.shrSH(M,C,6),J=le.rotrSL(M,C,19)^le.rotrBL(M,C,61)^le.shrSL(M,C,6),re=le.add4L(H,J,Er[w-7],Er[w-16]),ee=le.add4H(re,T,Y,_r[w-7],_r[w-16]);_r[w]=ee|0,Er[w]=re|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:y,Fh:p,Fl:m,Gh:g,Gl:A,Hh:S,Hl:P}=this;for(let w=0;w<80;w++){const _=le.rotrSH(h,y,14)^le.rotrSH(h,y,18)^le.rotrBH(h,y,41),I=le.rotrSL(h,y,14)^le.rotrSL(h,y,18)^le.rotrBL(h,y,41),T=h&p^~h&g,H=y&m^~y&A,M=le.add5L(P,I,H,J1[w],Er[w]),C=le.add5H(M,S,_,T,X1[w],_r[w]),Y=M|0,J=le.rotrSH(n,i,28)^le.rotrBH(n,i,34)^le.rotrBH(n,i,39),re=le.rotrSL(n,i,28)^le.rotrBL(n,i,34)^le.rotrBL(n,i,39),ee=n&o^n&a^o&a,Q=i&s^i&c^s&c;S=g|0,P=A|0,g=p|0,A=m|0,p=h|0,m=y|0,{h,l:y}=le.add(u|0,f|0,C|0,Y|0),u=a|0,f=c|0,a=o|0,c=s|0,o=n|0,s=i|0;const ae=le.add3L(Y,re,Q);n=le.add3H(ae,C,J,ee),i=ae|0}({h:n,l:i}=le.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=le.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=le.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=le.add(this.Dh|0,this.Dl|0,u|0,f|0),{h,l:y}=le.add(this.Eh|0,this.El|0,h|0,y|0),{h:p,l:m}=le.add(this.Fh|0,this.Fl|0,p|0,m|0),{h:g,l:A}=le.add(this.Gh|0,this.Gl|0,g|0,A|0),{h:S,l:P}=le.add(this.Hh|0,this.Hl|0,S|0,P|0),this.set(n,i,o,s,a,c,u,f,h,y,p,m,g,A,S,P)}roundClean(){(0,Me.clean)(_r,Er)}destroy(){(0,Me.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Te.SHA512=Zi;class Op extends Zi{constructor(){super(48),this.Ah=se.SHA384_IV[0]|0,this.Al=se.SHA384_IV[1]|0,this.Bh=se.SHA384_IV[2]|0,this.Bl=se.SHA384_IV[3]|0,this.Ch=se.SHA384_IV[4]|0,this.Cl=se.SHA384_IV[5]|0,this.Dh=se.SHA384_IV[6]|0,this.Dl=se.SHA384_IV[7]|0,this.Eh=se.SHA384_IV[8]|0,this.El=se.SHA384_IV[9]|0,this.Fh=se.SHA384_IV[10]|0,this.Fl=se.SHA384_IV[11]|0,this.Gh=se.SHA384_IV[12]|0,this.Gl=se.SHA384_IV[13]|0,this.Hh=se.SHA384_IV[14]|0,this.Hl=se.SHA384_IV[15]|0}}Te.SHA384=Op;const et=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),tt=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class Rp extends Zi{constructor(){super(28),this.Ah=et[0]|0,this.Al=et[1]|0,this.Bh=et[2]|0,this.Bl=et[3]|0,this.Ch=et[4]|0,this.Cl=et[5]|0,this.Dh=et[6]|0,this.Dl=et[7]|0,this.Eh=et[8]|0,this.El=et[9]|0,this.Fh=et[10]|0,this.Fl=et[11]|0,this.Gh=et[12]|0,this.Gl=et[13]|0,this.Hh=et[14]|0,this.Hl=et[15]|0}}Te.SHA512_224=Rp;class Cp extends Zi{constructor(){super(32),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}}Te.SHA512_256=Cp;Te.sha256=(0,Me.createHasher)(()=>new Pu);Te.sha224=(0,Me.createHasher)(()=>new Bp);Te.sha512=(0,Me.createHasher)(()=>new Zi);Te.sha384=(0,Me.createHasher)(()=>new Op);Te.sha512_256=(0,Me.createHasher)(()=>new Cp);Te.sha512_224=(0,Me.createHasher)(()=>new Rp);Object.defineProperty(Nt,"__esModule",{value:!0});Nt.sha224=Nt.SHA224=Nt.sha256=Nt.SHA256=void 0;const us=Te;Nt.SHA256=us.SHA256;Nt.sha256=us.sha256;Nt.SHA224=us.SHA224;Nt.sha224=us.sha224;async function Z1(e,{chain:t}){const{id:r,name:n,nativeCurrency:i,rpcUrls:o,blockExplorers:s}=t;await e.request({method:"wallet_addEthereumChain",params:[{chainId:fe(r),chainName:n,nativeCurrency:i,rpcUrls:o.default.http,blockExplorerUrls:s?Object.values(s).map(({url:a})=>a):void 0}]},{dedupe:!0,retryCount:0})}function Q1(e,t){const{abi:r,args:n,bytecode:i,...o}=t,s=_u({abi:r,args:n,bytecode:i});return xu(e,{...o,...o.authorizationList?{to:null}:{},data:s})}async function ew(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=>Vi(n))}async function tw(e,t={}){const{account:r=e.account,chainId:n}=t,i=r?Ve(r):void 0,o=n?[i==null?void 0:i.address,[fe(n)]]:[i==null?void 0:i.address],s=await e.request({method:"wallet_getCapabilities",params:o}),a={};for(const[c,u]of Object.entries(s)){a[Number(c)]={};for(let[f,h]of Object.entries(u))f==="addSubAccount"&&(f="unstable_addSubAccount"),a[Number(c)][f]=h}return typeof n=="number"?a[n]:a}async function rw(e){return await e.request({method:"wallet_getPermissions"},{dedupe:!0})}async function Fp(e,t){var c;const{account:r=e.account,chainId:n,nonce:i}=t;if(!r)throw new Nr({docsPath:"/docs/eip7702/prepareAuthorization"});const o=Ve(r),s=(()=>{if(t.executor)return t.executor==="self"?t.executor:Ve(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 ve(e,Xi,"getChainId")({})),typeof a.nonce>"u"&&(a.nonce=await ve(e,Sh,"getTransactionCount")({address:o.address,blockTag:"pending"}),(s==="self"||s!=null&&s.address&&wu(s.address,o.address))&&(a.nonce+=1)),a}async function nw(e){return(await e.request({method:"eth_requestAccounts"},{dedupe:!0,retryCount:0})).map(r=>Xb(r))}async function iw(e,t){return e.request({method:"wallet_requestPermissions",params:[t]},{retryCount:0})}async function ow(e,t){const{account:r=e.account,chain:n=e.chain,forceAtomic:i=!1,id:o,version:s="2.0.0"}=t;if(typeof r>"u")throw new Nr({docsPath:"/docs/actions/wallet/sendCalls"});const a=r?Ve(r):null,c=t.calls.map(u=>{const f=u;return{data:f.abi?qn({abi:f.abi,functionName:f.functionName,args:f.args}):f.data,to:f.to,value:f.value?fe(f.value):void 0}});try{const u=await e.request({method:"wallet_sendCalls",params:[{atomicRequired:i,calls:c,capabilities:sw(t.capabilities),chainId:fe(n.id),from:a==null?void 0:a.address,id:o,version:s}]},{retryCount:0});return typeof u=="string"?{id:u}:u}catch(u){throw zh(u,{...t,account:a,chain:t.chain})}}function sw(e){const t=e!=null&&e.paymasterService?Object.entries(e.paymasterService).reduce((r,[n,i])=>({...r??{},[fe(Number(n))]:i}),{}):void 0;return{...e,...t?{paymasterService:t}:{}}}async function aw(e,t){const{id:r}=t;await e.request({method:"wallet_showCallsStatus",params:[r]})}async function cw(e,t){const{account:r=e.account}=t;if(!r)throw new Nr({docsPath:"/docs/eip7702/signAuthorization"});const n=Ve(r);if(!n.signAuthorization)throw new Po({docsPath:"/docs/eip7702/signAuthorization",metaMessages:["The `signAuthorization` Action does not support JSON-RPC Accounts."],type:n.type});const i=await Fp(e,t);return n.signAuthorization(i)}async function uw(e,{account:t=e.account,message:r}){if(!t)throw new Nr({docsPath:"/docs/actions/wallet/signMessage"});const n=Ve(t);if(n.signMessage)return n.signMessage({message:r});const i=typeof r=="string"?Ko(r):r.raw instanceof Uint8Array?ue(r.raw):r.raw;return e.request({method:"personal_sign",params:[i,n.address]},{retryCount:0})}async function fw(e,t){var u,f,h,y;const{account:r=e.account,chain:n=e.chain,...i}=t;if(!r)throw new Nr({docsPath:"/docs/actions/wallet/signTransaction"});const o=Ve(r);Yi({account:o,...t});const s=await ve(e,Xi,"getChainId")({});n!==null&&Gh({currentChainId:s,chain:n});const a=(n==null?void 0:n.formatters)||((u=e.chain)==null?void 0:u.formatters),c=((f=a==null?void 0:a.transactionRequest)==null?void 0:f.format)||ns;return o.signTransaction?o.signTransaction({...i,chainId:s},{serializer:(y=(h=e.chain)==null?void 0:h.serializers)==null?void 0:y.transaction}):await e.request({method:"eth_signTransaction",params:[{...c(i),chainId:fe(s),from:o.address}]},{retryCount:0})}async function lw(e,t){const{account:r=e.account,domain:n,message:i,primaryType:o}=t;if(!r)throw new Nr({docsPath:"/docs/actions/wallet/signTypedData"});const s=Ve(r),a={EIP712Domain:E1({domain:n}),...t.types};if(_1({domain:n,message:i,primaryType:o,types:a}),s.signTypedData)return s.signTypedData({domain:n,message:i,primaryType:o,types:a});const c=v1({domain:n,message:i,primaryType:o,types:a});return e.request({method:"eth_signTypedData_v4",params:[s.address,c]},{retryCount:0})}async function dw(e,{id:t}){await e.request({method:"wallet_switchEthereumChain",params:[{chainId:fe(t)}]},{retryCount:0})}async function hw(e,t){return await e.request({method:"wallet_watchAsset",params:t},{retryCount:0})}function pw(e){return{addChain:t=>Z1(e,t),deployContract:t=>Q1(e,t),getAddresses:()=>ew(e),getCallsStatus:t=>Yh(e,t),getCapabilities:t=>tw(e,t),getChainId:()=>Xi(e),getPermissions:()=>rw(e),prepareAuthorization:t=>Fp(e,t),prepareTransactionRequest:t=>gu(e,t),requestAddresses:()=>nw(e),requestPermissions:t=>iw(e,t),sendCalls:t=>ow(e,t),sendRawTransaction:t=>Vh(e,t),sendTransaction:t=>xu(e,t),showCallsStatus:t=>aw(e,t),signAuthorization:t=>cw(e,t),signMessage:t=>uw(e,t),signTransaction:t=>fw(e,t),signTypedData:t=>lw(e,t),switchChain:t=>dw(e,t),waitForCallsStatus:t=>o1(e,t),watchAsset:t=>hw(e,t),writeContract:t=>Wh(e,t)}}function zs(e){const{key:t="wallet",name:r="Wallet Client",transport:n}=e;return a1({...e,key:t,name:r,transport:n,type:"walletClient"}).extend(pw)}const To={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",solanaRelay:"https://solana-relayer-staging.hashira.io/relay",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",solanaRelay:"https://solana-relayer-staging.hashira.io/relay",starknetRelay:"https://testnet.api.garden.finance/starknet"},localnet:{orderbook:"",auth:"",quote:"",info:"",evmRelay:"",starknetRelay:"",solanaRelay:""}},Hi={[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"},[Z.Network.LOCALNET]:{chainId:"",nodeUrl:""}},Pf={[Z.Network.MAINNET]:"",[Z.Network.TESTNET]:"ANUVKxeqaec3bf4DVPqLTnG1PT3Fng56wPcE7LXAb46Q",[Z.Network.LOCALNET]:"AKnL4NNf3DGWZJS6cPknBuEGnVsV4A4m5tgebLHaRSZ9"},Tf={chain:we.SupportedAssets.mainnet.base_cbBTC.chain,asset:we.SupportedAssets.mainnet.base_cbBTC.atomicSwapAddress};function If(e){const t=typeof e=="string"?e:e.environment,r=t===Z.Environment.MAINNET?To.mainnet:Z.Environment.TESTNET?To.testnet:To.localnet;return{api:typeof e=="string"?r:{...r,...e},environment:t}}function Uc(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function Mr(e,t){if(!e)throw new Error(t)}function yw(e){return Buffer.concat([Uint8Array.from([192]),bw(e)])}function bw(e){const t=Yu.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Yu.encode(e.length,r),Buffer.concat([r,e])}function mw(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Pr=e=>e.length===64?e:e.slice(2),gw=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return Kr.isPoint(t)}catch{return!1}},Lc=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function ww(e,t){if(!e)return!1;const r=t===Z.Environment.MAINNET?Ee.networks.bitcoin:t===Z.Environment.TESTNET?Ee.networks.testnet:Ee.networks.regtest;if(!r)return!1;Ee.initEccLib(Kr);try{return Ee.address.toOutputScript(e,r),!0}catch{return!1}}const vw=e=>{switch(e){case Z.Environment.MAINNET:return Gr.BitcoinNetwork.Mainnet;case Z.Environment.TESTNET:return Gr.BitcoinNetwork.Testnet;case Z.Environment.LOCALNET:return Gr.BitcoinNetwork.Regtest;default:throw new Error(`Invalid bitcoin network ${e}`)}},_w=e=>{const t=e.toLowerCase().replace("0x","");return/^[0-9a-f]+$/.test(t)},Ew=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")&&_w(r)?BigInt(r).toString():r);return Z.Ok(t)}return Z.Err("Invalid signature format")};var ke=(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))(ke||{}),Ce=(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))(Ce||{});const Tu=(e,t,r)=>{const n=Hc(e.source_swap,t),i=Hc(e.destination_swap,r);if(i===Ce.RedeemDetected)return ke.RedeemDetected;if(i===Ce.Redeemed)return ke.Redeemed;if(n===Ce.Refunded)return ke.Refunded;if(n===Ce.RefundDetected)return ke.RefundDetected;if(i===Ce.Expired)return ke.CounterPartySwapExpired;if(n===Ce.Expired)return ke.Expired;if(i===Ce.Refunded)return ke.CounterPartyRefunded;if(i===Ce.RefundDetected)return ke.CounterPartyRefundDetected;const o=Number(e.create_order.additional_data.deadline);return i===Ce.Initiated?ke.CounterPartyInitiated:i===Ce.InitiateDetected?ke.CounterPartyInitiateDetected:$i(o,12)?ke.DeadLineExceeded:n===Ce.Initiated?ke.Initiated:$i(o,1)?ke.DeadLineExceeded:n===Ce.InitiateDetected?ke.InitiateDetected:n===Ce.Redeemed?ke.CounterPartyRedeemed:n===Ce.RedeemDetected?ke.CounterPartyRedeemDetected:ke.Matched},Hc=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?Ce.Redeemed:Ce.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?Ce.Refunded:Ce.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Ce.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?Ce.Initiated:Ce.InitiateDetected:Ce.Idle},xw=(e,t,r)=>{const n=Tu(e,t,r);return Iu(n)},Iu=e=>{switch(e){case ke.Matched:return Re.Initiate;case ke.CounterPartyInitiated:case ke.CounterPartyInitiateDetected:case ke.RedeemDetected:return Re.Redeem;case ke.Expired:return Re.Refund;default:return Re.Idle}},$i=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},Aw=e=>e.filter(t=>!Np(t)),Np=e=>{const{source_swap:t,create_order:r}=e,{initiate_tx_hash:n,initiate_block_number:i}=t,{deadline:o}=r.additional_data;return n&&Number(i)?!1:n&&!Number(i)?$i(Number(o),12):n?!1:$i(Number(o),1)},Sw=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Pw=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),Tw=Buffer.concat([Sw,Pw]),Iw=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Bf={failedToCreateInternalPubkey:"failed to create internal pubkey"};function Bw(){const e=Id.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=Kr.pointMultiply(Buffer.concat([Buffer.from("04","hex"),Tw]),e);if(!t)throw new Error(Bf.failedToCreateInternalPubkey);const r=Kr.pointAdd(Iw,t);if(!r)throw new Error(Bf.failedToCreateInternalPubkey);return Uc(Buffer.from(r))}var Fe={},ct={},Ut={},fs={};fs.byteLength=Rw;fs.toByteArray=Fw;fs.fromByteArray=Lw;var Kt=[],Bt=[],kw=typeof Uint8Array<"u"?Uint8Array:Array,Vs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var fn=0,Ow=Vs.length;fn<Ow;++fn)Kt[fn]=Vs[fn],Bt[Vs.charCodeAt(fn)]=fn;Bt[45]=62;Bt[95]=63;function Up(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 Rw(e){var t=Up(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Cw(e,t,r){return(t+r)*3/4-r}function Fw(e){var t,r=Up(e),n=r[0],i=r[1],o=new kw(Cw(e,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=Bt[e.charCodeAt(c)]<<18|Bt[e.charCodeAt(c+1)]<<12|Bt[e.charCodeAt(c+2)]<<6|Bt[e.charCodeAt(c+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=t&255;return i===2&&(t=Bt[e.charCodeAt(c)]<<2|Bt[e.charCodeAt(c+1)]>>4,o[s++]=t&255),i===1&&(t=Bt[e.charCodeAt(c)]<<10|Bt[e.charCodeAt(c+1)]<<4|Bt[e.charCodeAt(c+2)]>>2,o[s++]=t>>8&255,o[s++]=t&255),o}function Nw(e){return Kt[e>>18&63]+Kt[e>>12&63]+Kt[e>>6&63]+Kt[e&63]}function Uw(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Nw(n));return i.join("")}function Lw(e){for(var t,r=e.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Uw(e,s,s+o>a?a:s+o));return n===1?(t=e[r-1],i.push(Kt[t>>2]+Kt[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Kt[t>>10]+Kt[t>>4&63]+Kt[t<<2&63]+"=")),i.join("")}var Bu={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Bu.read=function(e,t,r,n,i){var o,s,a=i*8-n-1,c=(1<<a)-1,u=c>>1,f=-7,h=r?i-1:0,y=r?-1:1,p=e[t+h];for(h+=y,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=o*256+e[t+h],h+=y,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=s*256+e[t+h],h+=y,f-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(p?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(p?-1:1)*s*Math.pow(2,o-n)};Bu.write=function(e,t,r,n,i,o){var s,a,c,u=o*8-i-1,f=(1<<u)-1,h=f>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,m=n?1:-1,g=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+h>=1?t+=y/c:t+=y*Math.pow(2,1-h),t*c>=2&&(s++,c/=2),s+h>=f?(a=0,s=f):s+h>=1?(a=(t*c-1)*Math.pow(2,i),s=s+h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=a&255,p+=m,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;e[r+p]=s&255,p+=m,s/=256,u-=8);e[r+p-m]|=g*128};/*!
43
- * The buffer module from node.js, for the browser.
44
- *
45
- * @author Feross Aboukhadijeh <https://feross.org>
46
- * @license MIT
47
- */(function(e){const t=fs,r=Bu,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=P,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=o(),!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 o(){try{const b=new Uint8Array(1),l={foo:function(){return 42}};return Object.setPrototypeOf(l,Uint8Array.prototype),Object.setPrototypeOf(b,l),b.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 s(b){if(b>i)throw new RangeError('The value "'+b+'" is invalid for option "size"');const l=new Uint8Array(b);return Object.setPrototypeOf(l,a.prototype),l}function a(b,l,d){if(typeof b=="number"){if(typeof l=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return h(b)}return c(b,l,d)}a.poolSize=8192;function c(b,l,d){if(typeof b=="string")return y(b,l);if(ArrayBuffer.isView(b))return m(b);if(b==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof b);if(qe(b,ArrayBuffer)||b&&qe(b.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qe(b,SharedArrayBuffer)||b&&qe(b.buffer,SharedArrayBuffer)))return g(b,l,d);if(typeof b=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const x=b.valueOf&&b.valueOf();if(x!=null&&x!==b)return a.from(x,l,d);const R=A(b);if(R)return R;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof b[Symbol.toPrimitive]=="function")return a.from(b[Symbol.toPrimitive]("string"),l,d);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof b)}a.from=function(b,l,d){return c(b,l,d)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function u(b){if(typeof b!="number")throw new TypeError('"size" argument must be of type number');if(b<0)throw new RangeError('The value "'+b+'" is invalid for option "size"')}function f(b,l,d){return u(b),b<=0?s(b):l!==void 0?typeof d=="string"?s(b).fill(l,d):s(b).fill(l):s(b)}a.alloc=function(b,l,d){return f(b,l,d)};function h(b){return u(b),s(b<0?0:S(b)|0)}a.allocUnsafe=function(b){return h(b)},a.allocUnsafeSlow=function(b){return h(b)};function y(b,l){if((typeof l!="string"||l==="")&&(l="utf8"),!a.isEncoding(l))throw new TypeError("Unknown encoding: "+l);const d=w(b,l)|0;let x=s(d);const R=x.write(b,l);return R!==d&&(x=x.slice(0,R)),x}function p(b){const l=b.length<0?0:S(b.length)|0,d=s(l);for(let x=0;x<l;x+=1)d[x]=b[x]&255;return d}function m(b){if(qe(b,Uint8Array)){const l=new Uint8Array(b);return g(l.buffer,l.byteOffset,l.byteLength)}return p(b)}function g(b,l,d){if(l<0||b.byteLength<l)throw new RangeError('"offset" is outside of buffer bounds');if(b.byteLength<l+(d||0))throw new RangeError('"length" is outside of buffer bounds');let x;return l===void 0&&d===void 0?x=new Uint8Array(b):d===void 0?x=new Uint8Array(b,l):x=new Uint8Array(b,l,d),Object.setPrototypeOf(x,a.prototype),x}function A(b){if(a.isBuffer(b)){const l=S(b.length)|0,d=s(l);return d.length===0||b.copy(d,0,0,l),d}if(b.length!==void 0)return typeof b.length!="number"||Pt(b.length)?s(0):p(b);if(b.type==="Buffer"&&Array.isArray(b.data))return p(b.data)}function S(b){if(b>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return b|0}function P(b){return+b!=b&&(b=0),a.alloc(+b)}a.isBuffer=function(l){return l!=null&&l._isBuffer===!0&&l!==a.prototype},a.compare=function(l,d){if(qe(l,Uint8Array)&&(l=a.from(l,l.offset,l.byteLength)),qe(d,Uint8Array)&&(d=a.from(d,d.offset,d.byteLength)),!a.isBuffer(l)||!a.isBuffer(d))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(l===d)return 0;let x=l.length,R=d.length;for(let L=0,G=Math.min(x,R);L<G;++L)if(l[L]!==d[L]){x=l[L],R=d[L];break}return x<R?-1:R<x?1:0},a.isEncoding=function(l){switch(String(l).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(l,d){if(!Array.isArray(l))throw new TypeError('"list" argument must be an Array of Buffers');if(l.length===0)return a.alloc(0);let x;if(d===void 0)for(d=0,x=0;x<l.length;++x)d+=l[x].length;const R=a.allocUnsafe(d);let L=0;for(x=0;x<l.length;++x){let G=l[x];if(qe(G,Uint8Array))L+G.length>R.length?(a.isBuffer(G)||(G=a.from(G)),G.copy(R,L)):Uint8Array.prototype.set.call(R,G,L);else if(a.isBuffer(G))G.copy(R,L);else throw new TypeError('"list" argument must be an Array of Buffers');L+=G.length}return R};function w(b,l){if(a.isBuffer(b))return b.length;if(ArrayBuffer.isView(b)||qe(b,ArrayBuffer))return b.byteLength;if(typeof b!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof b);const d=b.length,x=arguments.length>2&&arguments[2]===!0;if(!x&&d===0)return 0;let R=!1;for(;;)switch(l){case"ascii":case"latin1":case"binary":return d;case"utf8":case"utf-8":return ye(b).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return d*2;case"hex":return d>>>1;case"base64":return Et(b).length;default:if(R)return x?-1:ye(b).length;l=(""+l).toLowerCase(),R=!0}}a.byteLength=w;function _(b,l,d){let x=!1;if((l===void 0||l<0)&&(l=0),l>this.length||((d===void 0||d>this.length)&&(d=this.length),d<=0)||(d>>>=0,l>>>=0,d<=l))return"";for(b||(b="utf8");;)switch(b){case"hex":return F(this,l,d);case"utf8":case"utf-8":return Q(this,l,d);case"ascii":return pe(this,l,d);case"latin1":case"binary":return de(this,l,d);case"base64":return ee(this,l,d);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,l,d);default:if(x)throw new TypeError("Unknown encoding: "+b);b=(b+"").toLowerCase(),x=!0}}a.prototype._isBuffer=!0;function I(b,l,d){const x=b[l];b[l]=b[d],b[d]=x}a.prototype.swap16=function(){const l=this.length;if(l%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let d=0;d<l;d+=2)I(this,d,d+1);return this},a.prototype.swap32=function(){const l=this.length;if(l%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let d=0;d<l;d+=4)I(this,d,d+3),I(this,d+1,d+2);return this},a.prototype.swap64=function(){const l=this.length;if(l%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let d=0;d<l;d+=8)I(this,d,d+7),I(this,d+1,d+6),I(this,d+2,d+5),I(this,d+3,d+4);return this},a.prototype.toString=function(){const l=this.length;return l===0?"":arguments.length===0?Q(this,0,l):_.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(l){if(!a.isBuffer(l))throw new TypeError("Argument must be a Buffer");return this===l?!0:a.compare(this,l)===0},a.prototype.inspect=function(){let l="";const d=e.INSPECT_MAX_BYTES;return l=this.toString("hex",0,d).replace(/(.{2})/g,"$1 ").trim(),this.length>d&&(l+=" ... "),"<Buffer "+l+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(l,d,x,R,L){if(qe(l,Uint8Array)&&(l=a.from(l,l.offset,l.byteLength)),!a.isBuffer(l))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof l);if(d===void 0&&(d=0),x===void 0&&(x=l?l.length:0),R===void 0&&(R=0),L===void 0&&(L=this.length),d<0||x>l.length||R<0||L>this.length)throw new RangeError("out of range index");if(R>=L&&d>=x)return 0;if(R>=L)return-1;if(d>=x)return 1;if(d>>>=0,x>>>=0,R>>>=0,L>>>=0,this===l)return 0;let G=L-R,be=x-d;const Ne=Math.min(G,be),Oe=this.slice(R,L),Ue=l.slice(d,x);for(let Ae=0;Ae<Ne;++Ae)if(Oe[Ae]!==Ue[Ae]){G=Oe[Ae],be=Ue[Ae];break}return G<be?-1:be<G?1:0};function T(b,l,d,x,R){if(b.length===0)return-1;if(typeof d=="string"?(x=d,d=0):d>2147483647?d=2147483647:d<-2147483648&&(d=-2147483648),d=+d,Pt(d)&&(d=R?0:b.length-1),d<0&&(d=b.length+d),d>=b.length){if(R)return-1;d=b.length-1}else if(d<0)if(R)d=0;else return-1;if(typeof l=="string"&&(l=a.from(l,x)),a.isBuffer(l))return l.length===0?-1:H(b,l,d,x,R);if(typeof l=="number")return l=l&255,typeof Uint8Array.prototype.indexOf=="function"?R?Uint8Array.prototype.indexOf.call(b,l,d):Uint8Array.prototype.lastIndexOf.call(b,l,d):H(b,[l],d,x,R);throw new TypeError("val must be string, number or Buffer")}function H(b,l,d,x,R){let L=1,G=b.length,be=l.length;if(x!==void 0&&(x=String(x).toLowerCase(),x==="ucs2"||x==="ucs-2"||x==="utf16le"||x==="utf-16le")){if(b.length<2||l.length<2)return-1;L=2,G/=2,be/=2,d/=2}function Ne(Ue,Ae){return L===1?Ue[Ae]:Ue.readUInt16BE(Ae*L)}let Oe;if(R){let Ue=-1;for(Oe=d;Oe<G;Oe++)if(Ne(b,Oe)===Ne(l,Ue===-1?0:Oe-Ue)){if(Ue===-1&&(Ue=Oe),Oe-Ue+1===be)return Ue*L}else Ue!==-1&&(Oe-=Oe-Ue),Ue=-1}else for(d+be>G&&(d=G-be),Oe=d;Oe>=0;Oe--){let Ue=!0;for(let Ae=0;Ae<be;Ae++)if(Ne(b,Oe+Ae)!==Ne(l,Ae)){Ue=!1;break}if(Ue)return Oe}return-1}a.prototype.includes=function(l,d,x){return this.indexOf(l,d,x)!==-1},a.prototype.indexOf=function(l,d,x){return T(this,l,d,x,!0)},a.prototype.lastIndexOf=function(l,d,x){return T(this,l,d,x,!1)};function M(b,l,d,x){d=Number(d)||0;const R=b.length-d;x?(x=Number(x),x>R&&(x=R)):x=R;const L=l.length;x>L/2&&(x=L/2);let G;for(G=0;G<x;++G){const be=parseInt(l.substr(G*2,2),16);if(Pt(be))return G;b[d+G]=be}return G}function C(b,l,d,x){return Ye(ye(l,b.length-d),b,d,x)}function Y(b,l,d,x){return Ye(gt(l),b,d,x)}function J(b,l,d,x){return Ye(Et(l),b,d,x)}function re(b,l,d,x){return Ye(q(l,b.length-d),b,d,x)}a.prototype.write=function(l,d,x,R){if(d===void 0)R="utf8",x=this.length,d=0;else if(x===void 0&&typeof d=="string")R=d,x=this.length,d=0;else if(isFinite(d))d=d>>>0,isFinite(x)?(x=x>>>0,R===void 0&&(R="utf8")):(R=x,x=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const L=this.length-d;if((x===void 0||x>L)&&(x=L),l.length>0&&(x<0||d<0)||d>this.length)throw new RangeError("Attempt to write outside buffer bounds");R||(R="utf8");let G=!1;for(;;)switch(R){case"hex":return M(this,l,d,x);case"utf8":case"utf-8":return C(this,l,d,x);case"ascii":case"latin1":case"binary":return Y(this,l,d,x);case"base64":return J(this,l,d,x);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return re(this,l,d,x);default:if(G)throw new TypeError("Unknown encoding: "+R);R=(""+R).toLowerCase(),G=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ee(b,l,d){return l===0&&d===b.length?t.fromByteArray(b):t.fromByteArray(b.slice(l,d))}function Q(b,l,d){d=Math.min(b.length,d);const x=[];let R=l;for(;R<d;){const L=b[R];let G=null,be=L>239?4:L>223?3:L>191?2:1;if(R+be<=d){let Ne,Oe,Ue,Ae;switch(be){case 1:L<128&&(G=L);break;case 2:Ne=b[R+1],(Ne&192)===128&&(Ae=(L&31)<<6|Ne&63,Ae>127&&(G=Ae));break;case 3:Ne=b[R+1],Oe=b[R+2],(Ne&192)===128&&(Oe&192)===128&&(Ae=(L&15)<<12|(Ne&63)<<6|Oe&63,Ae>2047&&(Ae<55296||Ae>57343)&&(G=Ae));break;case 4:Ne=b[R+1],Oe=b[R+2],Ue=b[R+3],(Ne&192)===128&&(Oe&192)===128&&(Ue&192)===128&&(Ae=(L&15)<<18|(Ne&63)<<12|(Oe&63)<<6|Ue&63,Ae>65535&&Ae<1114112&&(G=Ae))}}G===null?(G=65533,be=1):G>65535&&(G-=65536,x.push(G>>>10&1023|55296),G=56320|G&1023),x.push(G),R+=be}return _e(x)}const ae=4096;function _e(b){const l=b.length;if(l<=ae)return String.fromCharCode.apply(String,b);let d="",x=0;for(;x<l;)d+=String.fromCharCode.apply(String,b.slice(x,x+=ae));return d}function pe(b,l,d){let x="";d=Math.min(b.length,d);for(let R=l;R<d;++R)x+=String.fromCharCode(b[R]&127);return x}function de(b,l,d){let x="";d=Math.min(b.length,d);for(let R=l;R<d;++R)x+=String.fromCharCode(b[R]);return x}function F(b,l,d){const x=b.length;(!l||l<0)&&(l=0),(!d||d<0||d>x)&&(d=x);let R="";for(let L=l;L<d;++L)R+=Ht[b[L]];return R}function X(b,l,d){const x=b.slice(l,d);let R="";for(let L=0;L<x.length-1;L+=2)R+=String.fromCharCode(x[L]+x[L+1]*256);return R}a.prototype.slice=function(l,d){const x=this.length;l=~~l,d=d===void 0?x:~~d,l<0?(l+=x,l<0&&(l=0)):l>x&&(l=x),d<0?(d+=x,d<0&&(d=0)):d>x&&(d=x),d<l&&(d=l);const R=this.subarray(l,d);return Object.setPrototypeOf(R,a.prototype),R};function ne(b,l,d){if(b%1!==0||b<0)throw new RangeError("offset is not uint");if(b+l>d)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(l,d,x){l=l>>>0,d=d>>>0,x||ne(l,d,this.length);let R=this[l],L=1,G=0;for(;++G<d&&(L*=256);)R+=this[l+G]*L;return R},a.prototype.readUintBE=a.prototype.readUIntBE=function(l,d,x){l=l>>>0,d=d>>>0,x||ne(l,d,this.length);let R=this[l+--d],L=1;for(;d>0&&(L*=256);)R+=this[l+--d]*L;return R},a.prototype.readUint8=a.prototype.readUInt8=function(l,d){return l=l>>>0,d||ne(l,1,this.length),this[l]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(l,d){return l=l>>>0,d||ne(l,2,this.length),this[l]|this[l+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(l,d){return l=l>>>0,d||ne(l,2,this.length),this[l]<<8|this[l+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(l,d){return l=l>>>0,d||ne(l,4,this.length),(this[l]|this[l+1]<<8|this[l+2]<<16)+this[l+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(l,d){return l=l>>>0,d||ne(l,4,this.length),this[l]*16777216+(this[l+1]<<16|this[l+2]<<8|this[l+3])},a.prototype.readBigUInt64LE=Tt(function(l){l=l>>>0,D(l,"offset");const d=this[l],x=this[l+7];(d===void 0||x===void 0)&&K(l,this.length-8);const R=d+this[++l]*2**8+this[++l]*2**16+this[++l]*2**24,L=this[++l]+this[++l]*2**8+this[++l]*2**16+x*2**24;return BigInt(R)+(BigInt(L)<<BigInt(32))}),a.prototype.readBigUInt64BE=Tt(function(l){l=l>>>0,D(l,"offset");const d=this[l],x=this[l+7];(d===void 0||x===void 0)&&K(l,this.length-8);const R=d*2**24+this[++l]*2**16+this[++l]*2**8+this[++l],L=this[++l]*2**24+this[++l]*2**16+this[++l]*2**8+x;return(BigInt(R)<<BigInt(32))+BigInt(L)}),a.prototype.readIntLE=function(l,d,x){l=l>>>0,d=d>>>0,x||ne(l,d,this.length);let R=this[l],L=1,G=0;for(;++G<d&&(L*=256);)R+=this[l+G]*L;return L*=128,R>=L&&(R-=Math.pow(2,8*d)),R},a.prototype.readIntBE=function(l,d,x){l=l>>>0,d=d>>>0,x||ne(l,d,this.length);let R=d,L=1,G=this[l+--R];for(;R>0&&(L*=256);)G+=this[l+--R]*L;return L*=128,G>=L&&(G-=Math.pow(2,8*d)),G},a.prototype.readInt8=function(l,d){return l=l>>>0,d||ne(l,1,this.length),this[l]&128?(255-this[l]+1)*-1:this[l]},a.prototype.readInt16LE=function(l,d){l=l>>>0,d||ne(l,2,this.length);const x=this[l]|this[l+1]<<8;return x&32768?x|4294901760:x},a.prototype.readInt16BE=function(l,d){l=l>>>0,d||ne(l,2,this.length);const x=this[l+1]|this[l]<<8;return x&32768?x|4294901760:x},a.prototype.readInt32LE=function(l,d){return l=l>>>0,d||ne(l,4,this.length),this[l]|this[l+1]<<8|this[l+2]<<16|this[l+3]<<24},a.prototype.readInt32BE=function(l,d){return l=l>>>0,d||ne(l,4,this.length),this[l]<<24|this[l+1]<<16|this[l+2]<<8|this[l+3]},a.prototype.readBigInt64LE=Tt(function(l){l=l>>>0,D(l,"offset");const d=this[l],x=this[l+7];(d===void 0||x===void 0)&&K(l,this.length-8);const R=this[l+4]+this[l+5]*2**8+this[l+6]*2**16+(x<<24);return(BigInt(R)<<BigInt(32))+BigInt(d+this[++l]*2**8+this[++l]*2**16+this[++l]*2**24)}),a.prototype.readBigInt64BE=Tt(function(l){l=l>>>0,D(l,"offset");const d=this[l],x=this[l+7];(d===void 0||x===void 0)&&K(l,this.length-8);const R=(d<<24)+this[++l]*2**16+this[++l]*2**8+this[++l];return(BigInt(R)<<BigInt(32))+BigInt(this[++l]*2**24+this[++l]*2**16+this[++l]*2**8+x)}),a.prototype.readFloatLE=function(l,d){return l=l>>>0,d||ne(l,4,this.length),r.read(this,l,!0,23,4)},a.prototype.readFloatBE=function(l,d){return l=l>>>0,d||ne(l,4,this.length),r.read(this,l,!1,23,4)},a.prototype.readDoubleLE=function(l,d){return l=l>>>0,d||ne(l,8,this.length),r.read(this,l,!0,52,8)},a.prototype.readDoubleBE=function(l,d){return l=l>>>0,d||ne(l,8,this.length),r.read(this,l,!1,52,8)};function k(b,l,d,x,R,L){if(!a.isBuffer(b))throw new TypeError('"buffer" argument must be a Buffer instance');if(l>R||l<L)throw new RangeError('"value" argument is out of bounds');if(d+x>b.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(l,d,x,R){if(l=+l,d=d>>>0,x=x>>>0,!R){const be=Math.pow(2,8*x)-1;k(this,l,d,x,be,0)}let L=1,G=0;for(this[d]=l&255;++G<x&&(L*=256);)this[d+G]=l/L&255;return d+x},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(l,d,x,R){if(l=+l,d=d>>>0,x=x>>>0,!R){const be=Math.pow(2,8*x)-1;k(this,l,d,x,be,0)}let L=x-1,G=1;for(this[d+L]=l&255;--L>=0&&(G*=256);)this[d+L]=l/G&255;return d+x},a.prototype.writeUint8=a.prototype.writeUInt8=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,1,255,0),this[d]=l&255,d+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,2,65535,0),this[d]=l&255,this[d+1]=l>>>8,d+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,2,65535,0),this[d]=l>>>8,this[d+1]=l&255,d+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,4,4294967295,0),this[d+3]=l>>>24,this[d+2]=l>>>16,this[d+1]=l>>>8,this[d]=l&255,d+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,4,4294967295,0),this[d]=l>>>24,this[d+1]=l>>>16,this[d+2]=l>>>8,this[d+3]=l&255,d+4};function U(b,l,d,x,R){E(l,x,R,b,d,7);let L=Number(l&BigInt(4294967295));b[d++]=L,L=L>>8,b[d++]=L,L=L>>8,b[d++]=L,L=L>>8,b[d++]=L;let G=Number(l>>BigInt(32)&BigInt(4294967295));return b[d++]=G,G=G>>8,b[d++]=G,G=G>>8,b[d++]=G,G=G>>8,b[d++]=G,d}function j(b,l,d,x,R){E(l,x,R,b,d,7);let L=Number(l&BigInt(4294967295));b[d+7]=L,L=L>>8,b[d+6]=L,L=L>>8,b[d+5]=L,L=L>>8,b[d+4]=L;let G=Number(l>>BigInt(32)&BigInt(4294967295));return b[d+3]=G,G=G>>8,b[d+2]=G,G=G>>8,b[d+1]=G,G=G>>8,b[d]=G,d+8}a.prototype.writeBigUInt64LE=Tt(function(l,d=0){return U(this,l,d,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Tt(function(l,d=0){return j(this,l,d,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(l,d,x,R){if(l=+l,d=d>>>0,!R){const Ne=Math.pow(2,8*x-1);k(this,l,d,x,Ne-1,-Ne)}let L=0,G=1,be=0;for(this[d]=l&255;++L<x&&(G*=256);)l<0&&be===0&&this[d+L-1]!==0&&(be=1),this[d+L]=(l/G>>0)-be&255;return d+x},a.prototype.writeIntBE=function(l,d,x,R){if(l=+l,d=d>>>0,!R){const Ne=Math.pow(2,8*x-1);k(this,l,d,x,Ne-1,-Ne)}let L=x-1,G=1,be=0;for(this[d+L]=l&255;--L>=0&&(G*=256);)l<0&&be===0&&this[d+L+1]!==0&&(be=1),this[d+L]=(l/G>>0)-be&255;return d+x},a.prototype.writeInt8=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,1,127,-128),l<0&&(l=255+l+1),this[d]=l&255,d+1},a.prototype.writeInt16LE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,2,32767,-32768),this[d]=l&255,this[d+1]=l>>>8,d+2},a.prototype.writeInt16BE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,2,32767,-32768),this[d]=l>>>8,this[d+1]=l&255,d+2},a.prototype.writeInt32LE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,4,2147483647,-2147483648),this[d]=l&255,this[d+1]=l>>>8,this[d+2]=l>>>16,this[d+3]=l>>>24,d+4},a.prototype.writeInt32BE=function(l,d,x){return l=+l,d=d>>>0,x||k(this,l,d,4,2147483647,-2147483648),l<0&&(l=4294967295+l+1),this[d]=l>>>24,this[d+1]=l>>>16,this[d+2]=l>>>8,this[d+3]=l&255,d+4},a.prototype.writeBigInt64LE=Tt(function(l,d=0){return U(this,l,d,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Tt(function(l,d=0){return j(this,l,d,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function te(b,l,d,x,R,L){if(d+x>b.length)throw new RangeError("Index out of range");if(d<0)throw new RangeError("Index out of range")}function B(b,l,d,x,R){return l=+l,d=d>>>0,R||te(b,l,d,4),r.write(b,l,d,x,23,4),d+4}a.prototype.writeFloatLE=function(l,d,x){return B(this,l,d,!0,x)},a.prototype.writeFloatBE=function(l,d,x){return B(this,l,d,!1,x)};function O(b,l,d,x,R){return l=+l,d=d>>>0,R||te(b,l,d,8),r.write(b,l,d,x,52,8),d+8}a.prototype.writeDoubleLE=function(l,d,x){return O(this,l,d,!0,x)},a.prototype.writeDoubleBE=function(l,d,x){return O(this,l,d,!1,x)},a.prototype.copy=function(l,d,x,R){if(!a.isBuffer(l))throw new TypeError("argument should be a Buffer");if(x||(x=0),!R&&R!==0&&(R=this.length),d>=l.length&&(d=l.length),d||(d=0),R>0&&R<x&&(R=x),R===x||l.length===0||this.length===0)return 0;if(d<0)throw new RangeError("targetStart out of bounds");if(x<0||x>=this.length)throw new RangeError("Index out of range");if(R<0)throw new RangeError("sourceEnd out of bounds");R>this.length&&(R=this.length),l.length-d<R-x&&(R=l.length-d+x);const L=R-x;return this===l&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(d,x,R):Uint8Array.prototype.set.call(l,this.subarray(x,R),d),L},a.prototype.fill=function(l,d,x,R){if(typeof l=="string"){if(typeof d=="string"?(R=d,d=0,x=this.length):typeof x=="string"&&(R=x,x=this.length),R!==void 0&&typeof R!="string")throw new TypeError("encoding must be a string");if(typeof R=="string"&&!a.isEncoding(R))throw new TypeError("Unknown encoding: "+R);if(l.length===1){const G=l.charCodeAt(0);(R==="utf8"&&G<128||R==="latin1")&&(l=G)}}else typeof l=="number"?l=l&255:typeof l=="boolean"&&(l=Number(l));if(d<0||this.length<d||this.length<x)throw new RangeError("Out of range index");if(x<=d)return this;d=d>>>0,x=x===void 0?this.length:x>>>0,l||(l=0);let L;if(typeof l=="number")for(L=d;L<x;++L)this[L]=l;else{const G=a.isBuffer(l)?l:a.from(l,R),be=G.length;if(be===0)throw new TypeError('The value "'+l+'" is invalid for argument "value"');for(L=0;L<x-d;++L)this[L+d]=G[L%be]}return this};const $={};function V(b,l,d){$[b]=class extends d{constructor(){super(),Object.defineProperty(this,"message",{value:l.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${b}]`,this.stack,delete this.name}get code(){return b}set code(R){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:R,writable:!0})}toString(){return`${this.name} [${b}]: ${this.message}`}}}V("ERR_BUFFER_OUT_OF_BOUNDS",function(b){return b?`${b} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),V("ERR_INVALID_ARG_TYPE",function(b,l){return`The "${b}" argument must be of type number. Received type ${typeof l}`},TypeError),V("ERR_OUT_OF_RANGE",function(b,l,d){let x=`The value of "${b}" is out of range.`,R=d;return Number.isInteger(d)&&Math.abs(d)>2**32?R=W(String(d)):typeof d=="bigint"&&(R=String(d),(d>BigInt(2)**BigInt(32)||d<-(BigInt(2)**BigInt(32)))&&(R=W(R)),R+="n"),x+=` It must be ${l}. Received ${R}`,x},RangeError);function W(b){let l="",d=b.length;const x=b[0]==="-"?1:0;for(;d>=x+4;d-=3)l=`_${b.slice(d-3,d)}${l}`;return`${b.slice(0,d)}${l}`}function v(b,l,d){D(l,"offset"),(b[l]===void 0||b[l+d]===void 0)&&K(l,b.length-(d+1))}function E(b,l,d,x,R,L){if(b>d||b<l){const G=typeof l=="bigint"?"n":"";let be;throw l===0||l===BigInt(0)?be=`>= 0${G} and < 2${G} ** ${(L+1)*8}${G}`:be=`>= -(2${G} ** ${(L+1)*8-1}${G}) and < 2 ** ${(L+1)*8-1}${G}`,new $.ERR_OUT_OF_RANGE("value",be,b)}v(x,R,L)}function D(b,l){if(typeof b!="number")throw new $.ERR_INVALID_ARG_TYPE(l,"number",b)}function K(b,l,d){throw Math.floor(b)!==b?(D(b,d),new $.ERR_OUT_OF_RANGE("offset","an integer",b)):l<0?new $.ERR_BUFFER_OUT_OF_BOUNDS:new $.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${l}`,b)}const me=/[^+/0-9A-Za-z-_]/g;function ie(b){if(b=b.split("=")[0],b=b.trim().replace(me,""),b.length<2)return"";for(;b.length%4!==0;)b=b+"=";return b}function ye(b,l){l=l||1/0;let d;const x=b.length;let R=null;const L=[];for(let G=0;G<x;++G){if(d=b.charCodeAt(G),d>55295&&d<57344){if(!R){if(d>56319){(l-=3)>-1&&L.push(239,191,189);continue}else if(G+1===x){(l-=3)>-1&&L.push(239,191,189);continue}R=d;continue}if(d<56320){(l-=3)>-1&&L.push(239,191,189),R=d;continue}d=(R-55296<<10|d-56320)+65536}else R&&(l-=3)>-1&&L.push(239,191,189);if(R=null,d<128){if((l-=1)<0)break;L.push(d)}else if(d<2048){if((l-=2)<0)break;L.push(d>>6|192,d&63|128)}else if(d<65536){if((l-=3)<0)break;L.push(d>>12|224,d>>6&63|128,d&63|128)}else if(d<1114112){if((l-=4)<0)break;L.push(d>>18|240,d>>12&63|128,d>>6&63|128,d&63|128)}else throw new Error("Invalid code point")}return L}function gt(b){const l=[];for(let d=0;d<b.length;++d)l.push(b.charCodeAt(d)&255);return l}function q(b,l){let d,x,R;const L=[];for(let G=0;G<b.length&&!((l-=2)<0);++G)d=b.charCodeAt(G),x=d>>8,R=d%256,L.push(R),L.push(x);return L}function Et(b){return t.toByteArray(ie(b))}function Ye(b,l,d,x){let R;for(R=0;R<x&&!(R+d>=l.length||R>=b.length);++R)l[R+d]=b[R];return R}function qe(b,l){return b instanceof l||b!=null&&b.constructor!=null&&b.constructor.name!=null&&b.constructor.name===l.name}function Pt(b){return b!==b}const Ht=function(){const b="0123456789abcdef",l=new Array(256);for(let d=0;d<16;++d){const x=d*16;for(let R=0;R<16;++R)l[x+R]=b[d]+b[R]}return l}();function Tt(b){return typeof BigInt>"u"?$r:b}function $r(){throw new Error("BigInt not supported")}})(Ut);var Mi={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}};Mi.Null=Mi.Nil;for(var kf in Mi)Mi[kf].toJSON=(function(e){return e}).bind(null,kf);var ku=Mi,Vr=ku;function Lp(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function Ou(e){return Vr.Nil(e)?"":Lp(e.constructor)}function Hw(e){return Vr.Function(e)?"":Vr.String(e)?JSON.stringify(e):e&&Vr.Object(e)?"":e}function Ru(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Ho(e){return Vr.Function(e)?e.toJSON?e.toJSON():Lp(e):Vr.Array(e)?"Array":e&&Vr.Object(e)?"Object":e!==void 0?e:""}function Hp(e,t,r){var n=Hw(t);return"Expected "+Ho(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function hr(e,t,r){r=r||Ou(t),this.message=Hp(e,t,r),Ru(this,hr),this.__type=e,this.__value=t,this.__valueTypeName=r}hr.prototype=Object.create(Error.prototype);hr.prototype.constructor=hr;function $w(e,t,r,n,i){var o='" of type ';return t==="key"&&(o='" with key type '),Hp('property "'+Ho(r)+o+Ho(e),n,i)}function En(e,t,r,n,i){e?(i=i||Ou(n),this.message=$w(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',Ru(this,hr),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}En.prototype=Object.create(Error.prototype);En.prototype.constructor=hr;function Mw(e,t){return new hr(e,{},t)}function Dw(e,t,r){return e instanceof En?(t=t+"."+e.__property,e=new En(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof hr&&(e=new En(e.__type,t,r,e.__value,e.__valueTypeName)),Ru(e),e}var $p={TfTypeError:hr,TfPropertyTypeError:En,tfCustomError:Mw,tfSubError:Dw,tfJSON:Ho,getValueTypeName:Ou},Ws,Of;function jw(){if(Of)return Ws;Of=1;var e=ku,t=$p;function r(T){return Buffer.isBuffer(T)}function n(T){return typeof T=="string"&&/^([0-9a-f]{2})+$/i.test(T)}function i(T,H){var M=T.toJSON();function C(Y){if(!T(Y))return!1;if(Y.length===H)return!0;throw t.tfCustomError(M+"(Length: "+H+")",M+"(Length: "+Y.length+")")}return C.toJSON=function(){return M},C}var o=i.bind(null,e.Array),s=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function u(T,H,M){M=M||e.Number;function C(Y,J){return M(Y,J)&&Y>T&&Y<H}return C.toJSON=function(){return`${M.toJSON()} between [${T}, ${H}]`},C}var f=Math.pow(2,53)-1;function h(T){return typeof T=="number"&&isFinite(T)}function y(T){return T<<24>>24===T}function p(T){return T<<16>>16===T}function m(T){return(T|0)===T}function g(T){return typeof T=="number"&&T>=-f&&T<=f&&Math.floor(T)===T}function A(T){return(T&255)===T}function S(T){return(T&65535)===T}function P(T){return T>>>0===T}function w(T){return typeof T=="number"&&T>=0&&T<=f&&Math.floor(T)===T}var _={ArrayN:o,Buffer:r,BufferN:s,Finite:h,Hex:n,HexN:a,Int8:y,Int16:p,Int32:m,Int53:g,Range:u,StringN:c,UInt8:A,UInt16:S,UInt32:P,UInt53:w};for(var I in _)_[I].toJSON=(function(T){return T}).bind(null,I);return Ws=_,Ws}var Qi=$p,Je=ku,er=Qi.tfJSON,Mp=Qi.TfTypeError,Dp=Qi.TfPropertyTypeError,Yn=Qi.tfSubError,qw=Qi.getValueTypeName,sr={arrayOf:function(t,r){t=Vt(t),r=r||{};function n(i,o){return!Je.Array(i)||Je.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(s,a){try{return ht(t,s,o)}catch(c){throw Yn(c,a)}})}return n.toJSON=function(){var i="["+er(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=Vt(t);function r(n,i){return Je.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+er(t)},r},map:function(t,r){t=Vt(t),r&&(r=Vt(r));function n(i,o){if(!Je.Object(i)||Je.Nil(i))return!1;for(var s in i){try{r&&ht(r,s,o)}catch(c){throw Yn(c,s,"key")}try{var a=i[s];ht(t,a,o)}catch(c){throw Yn(c,s)}}return!0}return r?n.toJSON=function(){return"{"+er(r)+": "+er(t)+"}"}:n.toJSON=function(){return"{"+er(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Vt(t[n]);function i(o,s){if(!Je.Object(o)||Je.Nil(o))return!1;var a;try{for(a in r){var c=r[a],u=o[a];ht(c,u,s)}}catch(f){throw Yn(f,a)}if(s){for(a in o)if(!r[a])throw new Dp(void 0,a)}return!0}return i.toJSON=function(){return er(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Vt);function r(n,i){return t.some(function(o){try{return ht(o,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(er).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Vt);function r(n,i){return t.every(function(o){try{return ht(o,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(er).join(" & ")},r},quacksLike:function(t){function r(n){return t===qw(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Vt);function r(n,i){return Je.Nil(n)||Je.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(o,s){try{return ht(o,n[s],i)}catch(a){throw Yn(a,s)}})}return r.toJSON=function(){return"("+t.map(er).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};sr.oneOf=sr.anyOf;function Vt(e){if(Je.String(e))return e[0]==="?"?sr.maybe(e.slice(1)):Je[e]||sr.quacksLike(e);if(e&&Je.Object(e)){if(Je.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return sr.arrayOf(e[0])}return sr.object(e)}else if(Je.Function(e))return e;return sr.value(e)}function ht(e,t,r,n){if(Je.Function(e)){if(e(t,r))return!0;throw new Mp(n||e,t)}return ht(Vt(e),t,r)}for(var kr in Je)ht[kr]=Je[kr];for(kr in sr)ht[kr]=sr[kr];var Rf=jw();for(kr in Rf)ht[kr]=Rf[kr];ht.compile=Vt;ht.TfTypeError=Mp;ht.TfPropertyTypeError=Dp;var jp=ht;(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=Ut;e.typeforce=jp;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(f,h){return f.length!==h.length?!1:f.every((y,p)=>y.equals(h[p]))}e.stacksEqual=i;function o(f){if(!t.Buffer.isBuffer(f)||f.length<33)return!1;const h=f[0],y=f.slice(1,33);if(y.compare(r)===0||y.compare(n)>=0)return!1;if((h===2||h===3)&&f.length===33)return!0;const p=f.slice(33);return p.compare(r)===0||p.compare(n)>=0?!1:h===4&&f.length===65}e.isPoint=o;const s=21*1e14;function a(f){return e.typeforce.UInt53(f)&&f<=s}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function c(f){return!f||!("output"in f)||!t.Buffer.isBuffer(f.output)?!1:f.version!==void 0?(f.version&e.TAPLEAF_VERSION_MASK)===f.version:!0}e.isTapleaf=c;function u(f){return(0,e.Array)(f)?f.length!==2?!1:f.every(h=>u(h)):c(f)}e.isTaptree=u,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})(ct);var eo={},Ze={};Object.defineProperty(Ze,"__esModule",{value:!0});Ze.BufferReader=Ze.BufferWriter=Ze.cloneBuffer=Ze.reverseBuffer=Ze.writeUInt64LE=Ze.readUInt64LE=Ze.varuint=void 0;const Wr=ct,{typeforce:qp}=Wr,Di=Td;Ze.varuint=Di;function Gp(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 zp(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Gp(n+r,9007199254740991),n+r}Ze.readUInt64LE=zp;function Vp(e,t,r){return Gp(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Ze.writeUInt64LE=Vp;function Gw(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}Ze.reverseBuffer=Gw;function zw(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Ze.cloneBuffer=zw;class Cu{static withCapacity(t){return new Cu(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,qp(Wr.tuple(Wr.Buffer,Wr.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=Vp(this.buffer,t,this.offset)}writeVarInt(t){Di.encode(t,this.buffer,this.offset),this.offset+=Di.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}`)}}Ze.BufferWriter=Cu;class Vw{constructor(t,r=0){this.buffer=t,this.offset=r,qp(Wr.tuple(Wr.Buffer,Wr.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=zp(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=Di.decode(this.buffer,this.offset);return this.offset+=Di.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}}Ze.BufferReader=Vw;var Ur={},kn={};Object.defineProperty(kn,"__esModule",{value:!0});kn.sha1=kn.SHA1=void 0;const Wp=pt;kn.SHA1=Wp.SHA1;kn.sha1=Wp.sha1;(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=Bn,r=kn,n=Nt;function i(f){return Buffer.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function o(f){return Buffer.from((0,r.sha1)(Uint8Array.from(f)))}e.sha1=o;function s(f){return Buffer.from((0,n.sha256)(Uint8Array.from(f)))}e.sha256=s;function a(f){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(f))))}e.hash160=a;function c(f){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(f))))}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 u(f,h){return s(Buffer.concat([e.TAGGED_HASH_PREFIXES[f],h]))}e.taggedHash=u})(Ur);var Ks={},ur={};Object.defineProperty(ur,"__esModule",{value:!0});ur.encode=ur.decode=ur.check=void 0;function Ww(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))}ur.check=Ww;function Kw(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)}}ur.decode=Kw;function Yw(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}ur.encode=Yw;var en={};Object.defineProperty(en,"__esModule",{value:!0});en.REVERSE_OPS=en.OPS=void 0;const $c={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};en.OPS=$c;const Kp={};en.REVERSE_OPS=Kp;for(const e of Object.keys($c)){const t=$c[e];Kp[t]=e}var Or={};Object.defineProperty(Or,"__esModule",{value:!0});Or.decode=Or.encode=Or.encodingLength=void 0;const Ir=en;function Yp(e){return e<Ir.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Or.encodingLength=Yp;function Xw(e,t,r){const n=Yp(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(Ir.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(Ir.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(Ir.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Or.encode=Xw;function Jw(e,t){const r=e.readUInt8(t);let n,i;if(r<Ir.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===Ir.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===Ir.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!==Ir.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Or.decode=Jw;var On={};Object.defineProperty(On,"__esModule",{value:!0});On.encode=On.decode=void 0;function Zw(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 o=e.readUInt32LE(0),s=e.readUInt8(4);return s&128?-((s&-129)*4294967296+o):s*4294967296+o}let i=0;for(let o=0;o<n;++o)i|=e[o]<<8*o;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}On.decode=Zw;function Qw(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function e2(e){let t=Math.abs(e);const r=Qw(t),n=Buffer.allocUnsafe(r),i=e<0;for(let o=0;o<r;++o)n.writeUInt8(t&255,o),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}On.encode=e2;var Dr={},Cf;function t2(){if(Cf)return Dr;Cf=1,Object.defineProperty(Dr,"__esModule",{value:!0}),Dr.encode=Dr.decode=void 0;const e=ur,t=St(),r=ct,{typeforce:n}=r,i=Buffer.alloc(1,0);function o(u){let f=0;for(;u[f]===0;)++f;return f===u.length?i:(u=u.slice(f),u[0]&128?Buffer.concat([i,u],1+u.length):u)}function s(u){u[0]===0&&(u=u.slice(1));const f=Buffer.alloc(32,0),h=Math.max(0,32-u.length);return u.copy(f,h),f}function a(u){const f=u.readUInt8(u.length-1);if(!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const h=e.decode(u.slice(0,-1)),y=s(h.r),p=s(h.s);return{signature:Buffer.concat([y,p],64),hashType:f}}Dr.decode=a;function c(u,f){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:u,hashType:f}),!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const h=Buffer.allocUnsafe(1);h.writeUInt8(f,0);const y=o(u.slice(0,32)),p=o(u.slice(32,64));return Buffer.concat([e.encode(y,p),h])}return Dr.encode=c,Dr}var Ff;function St(){return Ff||(Ff=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=ur,r=en;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Or,i=On,o=t2(),s=ct,{typeforce:a}=s,c=r.OPS.OP_RESERVED;function u(C){return s.Number(C)&&(C===r.OPS.OP_0||C>=r.OPS.OP_1&&C<=r.OPS.OP_16||C===r.OPS.OP_1NEGATE)}function f(C){return s.Buffer(C)||u(C)}function h(C){return s.Array(C)&&C.every(f)}e.isPushOnly=h;function y(C){return C.length-C.filter(f).length}e.countNonPushOnlyOPs=y;function p(C){if(C.length===0)return r.OPS.OP_0;if(C.length===1){if(C[0]>=1&&C[0]<=16)return c+C[0];if(C[0]===129)return r.OPS.OP_1NEGATE}}function m(C){return Buffer.isBuffer(C)}function g(C){return s.Array(C)}function A(C){return Buffer.isBuffer(C)}function S(C){if(m(C))return C;a(s.Array,C);const Y=C.reduce((ee,Q)=>A(Q)?Q.length===1&&p(Q)!==void 0?ee+1:ee+n.encodingLength(Q.length)+Q.length:ee+1,0),J=Buffer.allocUnsafe(Y);let re=0;if(C.forEach(ee=>{if(A(ee)){const Q=p(ee);if(Q!==void 0){J.writeUInt8(Q,re),re+=1;return}re+=n.encode(J,ee.length,re),ee.copy(J,re),re+=ee.length}else J.writeUInt8(ee,re),re+=1}),re!==J.length)throw new Error("Could not decode chunks");return J}e.compile=S;function P(C){if(g(C))return C;a(s.Buffer,C);const Y=[];let J=0;for(;J<C.length;){const re=C[J];if(re>r.OPS.OP_0&&re<=r.OPS.OP_PUSHDATA4){const ee=n.decode(C,J);if(ee===null||(J+=ee.size,J+ee.number>C.length))return null;const Q=C.slice(J,J+ee.number);J+=ee.number;const ae=p(Q);ae!==void 0?Y.push(ae):Y.push(Q)}else Y.push(re),J+=1}return Y}e.decompile=P;function w(C){if(m(C)&&(C=P(C)),!C)throw new Error("Could not convert invalid chunks to ASM");return C.map(Y=>{if(A(Y)){const J=p(Y);if(J===void 0)return Y.toString("hex");Y=J}return r.REVERSE_OPS[Y]}).join(" ")}e.toASM=w;function _(C){return a(s.String,C),S(C.split(" ").map(Y=>r.OPS[Y]!==void 0?r.OPS[Y]:(a(s.Hex,Y),Buffer.from(Y,"hex"))))}e.fromASM=_;function I(C){return C=P(C),a(h,C),C.map(Y=>A(Y)?Y:Y===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(Y-c))}e.toStack=I;function T(C){return s.isPoint(C)}e.isCanonicalPubKey=T;function H(C){const Y=C&-129;return Y>0&&Y<4}e.isDefinedHashType=H;function M(C){return!Buffer.isBuffer(C)||!H(C[C.length-1])?!1:t.check(C.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=o}(Ks)),Ks}Object.defineProperty(eo,"__esModule",{value:!0});eo.Transaction=void 0;const $e=Ze,ut=Ur,Nf=St(),r2=St(),ge=ct,{typeforce:Dt}=ge;function Gt(e){const t=e.length;return $e.varuint.encodingLength(t)+t}function n2(e){const t=e.length;return $e.varuint.encodingLength(t)+e.reduce((r,n)=>r+Gt(n),0)}const Tr=Buffer.allocUnsafe(0),Ys=[],Xs=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),Uf=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),i2=Buffer.from("ffffffffffffffff","hex"),o2={script:Tr,valueBuffer:i2};function s2(e){return e.value!==void 0}class he{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new $e.BufferReader(t),i=new he;i.version=n.readInt32();const o=n.readUInt8(),s=n.readUInt8();let a=!1;o===he.ADVANCED_TRANSACTION_MARKER&&s===he.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let f=0;f<c;++f)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:Ys});const u=n.readVarInt();for(let f=0;f<u;++f)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let f=0;f<c;++f)i.ins[f].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 he.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){Dt(ge.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&he.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return Dt(ge.tuple(ge.Hash256bit,ge.UInt32,ge.maybe(ge.UInt32),ge.maybe(ge.Buffer)),arguments),ge.Null(n)&&(n=he.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||Tr,sequence:n,witness:Ys})-1}addOutput(t,r){return Dt(ge.tuple(ge.Buffer,ge.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=Ys})}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)+$e.varuint.encodingLength(this.ins.length)+$e.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+Gt(i.script),0)+this.outs.reduce((n,i)=>n+8+Gt(i.script),0)+(r?this.ins.reduce((n,i)=>n+n2(i.witness),0):0)}clone(){const t=new he;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(Dt(ge.tuple(ge.UInt32,ge.Buffer,ge.Number),arguments),t>=this.ins.length)return Uf;const i=Nf.compile(Nf.decompile(r).filter(a=>a!==r2.OPS.OP_CODESEPARATOR)),o=this.clone();if((n&31)===he.SIGHASH_NONE)o.outs=[],o.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===he.SIGHASH_SINGLE){if(t>=this.outs.length)return Uf;o.outs.length=t+1;for(let a=0;a<t;a++)o.outs[a]=o2;o.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&he.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[t]],o.ins[0].script=i):(o.ins.forEach(a=>{a.script=Tr}),o.ins[t].script=i);const s=Buffer.allocUnsafe(o.byteLength(!1)+4);return s.writeInt32LE(n,s.length-4),o.__toBuffer(s,0,!1),ut.hash256(s)}hashForWitnessV1(t,r,n,i,o,s){if(Dt(ge.tuple(ge.UInt32,Dt.arrayOf(ge.Buffer),Dt.arrayOf(ge.Satoshi),ge.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===he.SIGHASH_DEFAULT?he.SIGHASH_ALL:i&he.SIGHASH_OUTPUT_MASK,u=(i&he.SIGHASH_INPUT_MASK)===he.SIGHASH_ANYONECANPAY,f=a===he.SIGHASH_NONE,h=a===he.SIGHASH_SINGLE;let y=Tr,p=Tr,m=Tr,g=Tr,A=Tr;if(!u){let _=$e.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(I=>{_.writeSlice(I.hash),_.writeUInt32(I.index)}),y=ut.sha256(_.end()),_=$e.BufferWriter.withCapacity(8*this.ins.length),n.forEach(I=>_.writeUInt64(I)),p=ut.sha256(_.end()),_=$e.BufferWriter.withCapacity(r.map(Gt).reduce((I,T)=>I+T)),r.forEach(I=>_.writeVarSlice(I)),m=ut.sha256(_.end()),_=$e.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(I=>_.writeUInt32(I.sequence)),g=ut.sha256(_.end())}if(f||h){if(h&&t<this.outs.length){const _=this.outs[t],I=$e.BufferWriter.withCapacity(8+Gt(_.script));I.writeUInt64(_.value),I.writeVarSlice(_.script),A=ut.sha256(I.end())}}else{const _=this.outs.map(T=>8+Gt(T.script)).reduce((T,H)=>T+H),I=$e.BufferWriter.withCapacity(_);this.outs.forEach(T=>{I.writeUInt64(T.value),I.writeVarSlice(T.script)}),A=ut.sha256(I.end())}const S=(o?2:0)+(s?1:0),P=174-(u?49:0)-(f?32:0)+(s?32:0)+(o?37:0),w=$e.BufferWriter.withCapacity(P);if(w.writeUInt8(i),w.writeInt32(this.version),w.writeUInt32(this.locktime),w.writeSlice(y),w.writeSlice(p),w.writeSlice(m),w.writeSlice(g),f||h||w.writeSlice(A),w.writeUInt8(S),u){const _=this.ins[t];w.writeSlice(_.hash),w.writeUInt32(_.index),w.writeUInt64(n[t]),w.writeVarSlice(r[t]),w.writeUInt32(_.sequence)}else w.writeUInt32(t);if(s){const _=$e.BufferWriter.withCapacity(Gt(s));_.writeVarSlice(s),w.writeSlice(ut.sha256(_.end()))}return h&&w.writeSlice(A),o&&(w.writeSlice(o),w.writeUInt8(0),w.writeUInt32(4294967295)),ut.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),w.end()]))}hashForWitnessV0(t,r,n,i){Dt(ge.tuple(ge.UInt32,ge.Buffer,ge.Satoshi,ge.UInt32),arguments);let o=Buffer.from([]),s,a=Xs,c=Xs,u=Xs;if(i&he.SIGHASH_ANYONECANPAY||(o=Buffer.allocUnsafe(36*this.ins.length),s=new $e.BufferWriter(o,0),this.ins.forEach(h=>{s.writeSlice(h.hash),s.writeUInt32(h.index)}),c=ut.hash256(o)),!(i&he.SIGHASH_ANYONECANPAY)&&(i&31)!==he.SIGHASH_SINGLE&&(i&31)!==he.SIGHASH_NONE&&(o=Buffer.allocUnsafe(4*this.ins.length),s=new $e.BufferWriter(o,0),this.ins.forEach(h=>{s.writeUInt32(h.sequence)}),u=ut.hash256(o)),(i&31)!==he.SIGHASH_SINGLE&&(i&31)!==he.SIGHASH_NONE){const h=this.outs.reduce((y,p)=>y+8+Gt(p.script),0);o=Buffer.allocUnsafe(h),s=new $e.BufferWriter(o,0),this.outs.forEach(y=>{s.writeUInt64(y.value),s.writeVarSlice(y.script)}),a=ut.hash256(o)}else if((i&31)===he.SIGHASH_SINGLE&&t<this.outs.length){const h=this.outs[t];o=Buffer.allocUnsafe(8+Gt(h.script)),s=new $e.BufferWriter(o,0),s.writeUInt64(h.value),s.writeVarSlice(h.script),a=ut.hash256(o)}o=Buffer.allocUnsafe(156+Gt(r)),s=new $e.BufferWriter(o,0);const f=this.ins[t];return s.writeInt32(this.version),s.writeSlice(c),s.writeSlice(u),s.writeSlice(f.hash),s.writeUInt32(f.index),s.writeVarSlice(r),s.writeUInt64(n),s.writeUInt32(f.sequence),s.writeSlice(a),s.writeUInt32(this.locktime),s.writeUInt32(i),ut.hash256(o)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):ut.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,$e.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){Dt(ge.tuple(ge.Number,ge.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){Dt(ge.tuple(ge.Number,[ge.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new $e.BufferWriter(t,r||0);i.writeInt32(this.version);const o=n&&this.hasWitnesses();return o&&(i.writeUInt8(he.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(he.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(s=>{i.writeSlice(s.hash),i.writeUInt32(s.index),i.writeVarSlice(s.script),i.writeUInt32(s.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(s=>{s2(s)?i.writeUInt64(s.value):i.writeSlice(s.valueBuffer),i.writeVarSlice(s.script)}),o&&this.ins.forEach(s=>{i.writeVector(s.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}eo.Transaction=he;he.DEFAULT_SEQUENCE=4294967295;he.SIGHASH_DEFAULT=0;he.SIGHASH_ALL=1;he.SIGHASH_NONE=2;he.SIGHASH_SINGLE=3;he.SIGHASH_ANYONECANPAY=128;he.SIGHASH_OUTPUT_MASK=3;he.SIGHASH_INPUT_MASK=128;he.ADVANCED_TRANSACTION_MARKER=0;he.ADVANCED_TRANSACTION_FLAG=1;var Se={},to={};Object.defineProperty(to,"__esModule",{value:!0});const a2=9007199254740991;function Fu(e){if(e<0||e>a2||e%1!==0)throw new RangeError("value out of range")}function ai(e,t,r){if(Fu(e),t||(t=Buffer.allocUnsafe(Xp(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(ai,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(ai,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(ai,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(ai,{bytes:9})),t}to.encode=ai;function ci(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(ci,{bytes:1}),r;if(r===253)return Object.assign(ci,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(ci,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(ci,{bytes:9});const n=e.readUInt32LE(t+1),o=e.readUInt32LE(t+5)*4294967296+n;return Fu(o),o}}to.decode=ci;function Xp(e){return Fu(e),e<253?1:e<=65535?3:e<=4294967295?5:9}to.encodingLength=Xp;var Js={},ls={},at={};Object.defineProperty(at,"__esModule",{value:!0});at.testnet=at.regtest=at.bitcoin=void 0;at.bitcoin={messagePrefix:`Bitcoin Signed Message:
48
- `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};at.regtest={messagePrefix:`Bitcoin Signed Message:
49
- `,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};at.testnet={messagePrefix:`Bitcoin Signed Message:
50
- `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var xt={};Object.defineProperty(xt,"__esModule",{value:!0});xt.value=xt.prop=void 0;function c2(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})}})}xt.prop=c2;function u2(e){let t;return()=>(t!==void 0||(t=e()),t)}xt.value=u2;Object.defineProperty(ls,"__esModule",{value:!0});ls.p2data=void 0;const f2=at,Io=St(),jt=ct,Lf=xt,Hf=Io.OPS;function l2(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,jt.typeforce)({network:jt.typeforce.maybe(jt.typeforce.Object),output:jt.typeforce.maybe(jt.typeforce.Buffer),data:jt.typeforce.maybe(jt.typeforce.arrayOf(jt.typeforce.Buffer))},e);const n={name:"embed",network:e.network||f2.bitcoin};if(Lf.prop(n,"output",()=>{if(e.data)return Io.compile([Hf.OP_RETURN].concat(e.data))}),Lf.prop(n,"data",()=>{if(e.output)return Io.decompile(e.output).slice(1)}),t.validate&&e.output){const i=Io.decompile(e.output);if(i[0]!==Hf.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(jt.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,jt.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}ls.p2data=l2;var ds={};Object.defineProperty(ds,"__esModule",{value:!0});ds.p2ms=void 0;const d2=at,pn=St(),He=ct,xr=xt,yn=pn.OPS,wo=yn.OP_RESERVED;function h2(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 pn.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===yn.OP_0)!==void 0}(0,He.typeforce)({network:He.typeforce.maybe(He.typeforce.Object),m:He.typeforce.maybe(He.typeforce.Number),n:He.typeforce.maybe(He.typeforce.Number),output:He.typeforce.maybe(He.typeforce.Buffer),pubkeys:He.typeforce.maybe(He.typeforce.arrayOf(He.isPoint)),signatures:He.typeforce.maybe(He.typeforce.arrayOf(r)),input:He.typeforce.maybe(He.typeforce.Buffer)},e);const i={network:e.network||d2.bitcoin};let o=[],s=!1;function a(c){s||(s=!0,o=pn.decompile(c),i.m=o[0]-wo,i.n=o[o.length-2]-wo,i.pubkeys=o.slice(1,-2))}if(xr.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return pn.compile([].concat(wo+e.m,e.pubkeys,wo+i.n,yn.OP_CHECKMULTISIG))}),xr.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),xr.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),xr.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),xr.prop(i,"signatures",()=>{if(e.input)return pn.decompile(e.input).slice(1)}),xr.prop(i,"input",()=>{if(e.signatures)return pn.compile([yn.OP_0].concat(e.signatures))}),xr.prop(i,"witness",()=>{if(i.input)return[]}),xr.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!He.typeforce.Number(o[0]))throw new TypeError("Output is invalid");if(!He.typeforce.Number(o[o.length-2]))throw new TypeError("Output is invalid");if(o[o.length-1]!==yn.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==o.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(c=>(0,He.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,He.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]!==yn.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,He.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)}ds.p2ms=h2;var hs={};Object.defineProperty(hs,"__esModule",{value:!0});hs.p2pk=void 0;const p2=at,bn=St(),Ct=ct,ln=xt,$f=bn.OPS;function y2(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,Ct.typeforce)({network:Ct.typeforce.maybe(Ct.typeforce.Object),output:Ct.typeforce.maybe(Ct.typeforce.Buffer),pubkey:Ct.typeforce.maybe(Ct.isPoint),signature:Ct.typeforce.maybe(bn.isCanonicalScriptSignature),input:Ct.typeforce.maybe(Ct.typeforce.Buffer)},e);const r=ln.value(()=>bn.decompile(e.input)),i={name:"p2pk",network:e.network||p2.bitcoin};if(ln.prop(i,"output",()=>{if(e.pubkey)return bn.compile([e.pubkey,$f.OP_CHECKSIG])}),ln.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),ln.prop(i,"signature",()=>{if(e.input)return r()[0]}),ln.prop(i,"input",()=>{if(e.signature)return bn.compile([e.signature])}),ln.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==$f.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,Ct.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(!bn.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}hs.p2pk=y2;var ps={};function b2(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),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,a=e.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function f(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 m=0,g=0,A=0,S=p.length;A!==S&&p[A]===0;)A++,m++;for(var P=(S-A)*u+1>>>0,w=new Uint8Array(P);A!==S;){for(var _=p[A],I=0,T=P-1;(_!==0||I<g)&&T!==-1;T--,I++)_+=256*w[T]>>>0,w[T]=_%s>>>0,_=_/s>>>0;if(_!==0)throw new Error("Non-zero carry");g=I,A++}for(var H=P-g;H!==P&&w[H]===0;)H++;for(var M=a.repeat(m);H<P;++H)M+=e.charAt(w[H]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;for(var m=0,g=0,A=0;p[m]===a;)g++,m++;for(var S=(p.length-m)*c+1>>>0,P=new Uint8Array(S);p[m];){var w=p.charCodeAt(m);if(w>255)return;var _=t[w];if(_===255)return;for(var I=0,T=S-1;(_!==0||I<A)&&T!==-1;T--,I++)_+=s*P[T]>>>0,P[T]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=I,m++}for(var H=S-A;H!==S&&P[H]===0;)H++;for(var M=new Uint8Array(g+(S-H)),C=g;H!==S;)M[C++]=P[H++];return M}function y(p){var m=h(p);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:f,decodeUnsafe:h,decode:y}}var m2=b2;const g2=m2,w2="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var v2=g2(w2),Zs=v2,_2=function(e){function t(o){var s=Uint8Array.from(o),a=e(s),c=s.length+4,u=new Uint8Array(c);return u.set(s,0),u.set(a.subarray(0,4),s.length),Zs.encode(u,c)}function r(o){var s=o.slice(0,-4),a=o.slice(-4),c=e(s);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return s}function n(o){var s=Zs.decodeUnsafe(o);if(s)return r(s)}function i(o){var s=Zs.decode(o),a=r(s);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:Mf}=Nt,E2=_2;function x2(e){return Mf(Mf(e))}var Nu=E2(x2);Object.defineProperty(ps,"__esModule",{value:!0});ps.p2pkh=void 0;const Qs=Ur,A2=at,mn=St(),ft=ct,tr=xt,Df=Nu,Ar=mn.OPS;function S2(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,ft.typeforce)({network:ft.typeforce.maybe(ft.typeforce.Object),address:ft.typeforce.maybe(ft.typeforce.String),hash:ft.typeforce.maybe(ft.typeforce.BufferN(20)),output:ft.typeforce.maybe(ft.typeforce.BufferN(25)),pubkey:ft.typeforce.maybe(ft.isPoint),signature:ft.typeforce.maybe(mn.isCanonicalScriptSignature),input:ft.typeforce.maybe(ft.typeforce.Buffer)},e);const r=tr.value(()=>{const s=Buffer.from(Df.decode(e.address)),a=s.readUInt8(0),c=s.slice(1);return{version:a,hash:c}}),n=tr.value(()=>mn.decompile(e.input)),i=e.network||A2.bitcoin,o={name:"p2pkh",network:i};if(tr.prop(o,"address",()=>{if(!o.hash)return;const s=Buffer.allocUnsafe(21);return s.writeUInt8(i.pubKeyHash,0),o.hash.copy(s,1),Df.encode(s)}),tr.prop(o,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||o.pubkey)return Qs.hash160(e.pubkey||o.pubkey)}),tr.prop(o,"output",()=>{if(o.hash)return mn.compile([Ar.OP_DUP,Ar.OP_HASH160,o.hash,Ar.OP_EQUALVERIFY,Ar.OP_CHECKSIG])}),tr.prop(o,"pubkey",()=>{if(e.input)return n()[1]}),tr.prop(o,"signature",()=>{if(e.input)return n()[0]}),tr.prop(o,"input",()=>{if(e.pubkey&&e.signature)return mn.compile([e.signature,e.pubkey])}),tr.prop(o,"witness",()=>{if(o.input)return[]}),t.validate){let s=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");s=r().hash}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!==25||e.output[0]!==Ar.OP_DUP||e.output[1]!==Ar.OP_HASH160||e.output[2]!==20||e.output[23]!==Ar.OP_EQUALVERIFY||e.output[24]!==Ar.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.pubkey){const a=Qs.hash160(e.pubkey);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!mn.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,ft.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=Qs.hash160(a[1]);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}ps.p2pkh=S2;var ys={};Object.defineProperty(ys,"__esModule",{value:!0});ys.p2sh=void 0;const jf=Ur,P2=at,zt=St(),Ie=ct,qt=xt,qf=Nu,Xn=zt.OPS;function T2(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,Ie.typeforce)({network:Ie.typeforce.maybe(Ie.typeforce.Object),address:Ie.typeforce.maybe(Ie.typeforce.String),hash:Ie.typeforce.maybe(Ie.typeforce.BufferN(20)),output:Ie.typeforce.maybe(Ie.typeforce.BufferN(23)),redeem:Ie.typeforce.maybe({network:Ie.typeforce.maybe(Ie.typeforce.Object),output:Ie.typeforce.maybe(Ie.typeforce.Buffer),input:Ie.typeforce.maybe(Ie.typeforce.Buffer),witness:Ie.typeforce.maybe(Ie.typeforce.arrayOf(Ie.typeforce.Buffer))}),input:Ie.typeforce.maybe(Ie.typeforce.Buffer),witness:Ie.typeforce.maybe(Ie.typeforce.arrayOf(Ie.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||P2.bitcoin);const n={network:r},i=qt.value(()=>{const a=Buffer.from(qf.decode(e.address)),c=a.readUInt8(0),u=a.slice(1);return{version:c,hash:u}}),o=qt.value(()=>zt.decompile(e.input)),s=qt.value(()=>{const a=o(),c=a[a.length-1];return{network:r,output:c===Xn.OP_FALSE?Buffer.from([]):c,input:zt.compile(a.slice(0,-1)),witness:e.witness||[]}});if(qt.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),qf.encode(a)}),qt.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 jf.hash160(n.redeem.output)}),qt.prop(n,"output",()=>{if(n.hash)return zt.compile([Xn.OP_HASH160,n.hash,Xn.OP_EQUAL])}),qt.prop(n,"redeem",()=>{if(e.input)return s()}),qt.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return zt.compile([].concat(zt.decompile(e.redeem.input),e.redeem.output))}),qt.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),qt.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]!==Xn.OP_HASH160||e.output[1]!==20||e.output[22]!==Xn.OP_EQUAL)throw new TypeError("Output is invalid");const u=e.output.slice(2,22);if(a.length>0&&!a.equals(u))throw new TypeError("Hash mismatch");a=u}const c=u=>{if(u.output){const f=zt.decompile(u.output);if(!f||f.length<1)throw new TypeError("Redeem.output too short");if(u.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(zt.countNonPushOnlyOPs(f)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const h=jf.hash160(u.output);if(a.length>0&&!a.equals(h))throw new TypeError("Hash mismatch");a=h}if(u.input){const f=u.input.length>0,h=u.witness&&u.witness.length>0;if(!f&&!h)throw new TypeError("Empty input");if(f&&h)throw new TypeError("Input and witness provided");if(f){const y=zt.decompile(u.input);if(!zt.isPushOnly(y))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=o();if(!u||u.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(s().output))throw new TypeError("Input is invalid");c(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const u=s();if(e.redeem.output&&!e.redeem.output.equals(u.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(u.input))throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,Ie.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}ys.p2sh=T2;var bs={},pr={};Object.defineProperty(pr,"__esModule",{value:!0});pr.bech32m=pr.bech32=void 0;const $o="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Jp={};for(let e=0;e<$o.length;e++){const t=$o.charAt(e);Jp[t]=e}function xn(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 Gf(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=xn(t)^n>>5}t=xn(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=xn(t)^n&31}return t}function Uu(e,t,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],o+=t;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=t)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function I2(e){return Uu(e,8,5,!0)}function B2(e){const t=Uu(e,5,8,!1);if(Array.isArray(t))return t}function k2(e){const t=Uu(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Zp(e){let t;e==="bech32"?t=1:t=734539939;function r(s,a,c){if(c=c||90,s.length+7+a.length>c)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let u=Gf(s);if(typeof u=="string")throw new Error(u);let f=s+"1";for(let h=0;h<a.length;++h){const y=a[h];if(y>>5)throw new Error("Non 5-bit word");u=xn(u)^y,f+=$o.charAt(y)}for(let h=0;h<6;++h)u=xn(u);u^=t;for(let h=0;h<6;++h){const y=u>>(5-h)*5&31;f+=$o.charAt(y)}return f}function n(s,a){if(a=a||90,s.length<8)return s+" too short";if(s.length>a)return"Exceeds length limit";const c=s.toLowerCase(),u=s.toUpperCase();if(s!==c&&s!==u)return"Mixed-case string "+s;s=c;const f=s.lastIndexOf("1");if(f===-1)return"No separator character for "+s;if(f===0)return"Missing prefix for "+s;const h=s.slice(0,f),y=s.slice(f+1);if(y.length<6)return"Data too short";let p=Gf(h);if(typeof p=="string")return p;const m=[];for(let g=0;g<y.length;++g){const A=y.charAt(g),S=Jp[A];if(S===void 0)return"Unknown character "+A;p=xn(p)^S,!(g+6>=y.length)&&m.push(S)}return p!==t?"Invalid checksum for "+s:{prefix:h,words:m}}function i(s,a){const c=n(s,a);if(typeof c=="object")return c}function o(s,a){const c=n(s,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:o,encode:r,toWords:I2,fromWordsUnsafe:B2,fromWords:k2}}pr.bech32=Zp("bech32");pr.bech32m=Zp("bech32m");Object.defineProperty(bs,"__esModule",{value:!0});bs.p2wpkh=void 0;const ea=Ur,O2=at,Bo=St(),je=ct,Sr=xt,vo=pr,zf=Bo.OPS,R2=Buffer.alloc(0);function C2(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,je.typeforce)({address:je.typeforce.maybe(je.typeforce.String),hash:je.typeforce.maybe(je.typeforce.BufferN(20)),input:je.typeforce.maybe(je.typeforce.BufferN(0)),network:je.typeforce.maybe(je.typeforce.Object),output:je.typeforce.maybe(je.typeforce.BufferN(22)),pubkey:je.typeforce.maybe(je.isPoint),signature:je.typeforce.maybe(Bo.isCanonicalScriptSignature),witness:je.typeforce.maybe(je.typeforce.arrayOf(je.typeforce.Buffer))},e);const r=Sr.value(()=>{const o=vo.bech32.decode(e.address),s=o.words.shift(),a=vo.bech32.fromWords(o.words);return{version:s,prefix:o.prefix,data:Buffer.from(a)}}),n=e.network||O2.bitcoin,i={name:"p2wpkh",network:n};if(Sr.prop(i,"address",()=>{if(!i.hash)return;const o=vo.bech32.toWords(i.hash);return o.unshift(0),vo.bech32.encode(n.bech32,o)}),Sr.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return ea.hash160(e.pubkey||i.pubkey)}),Sr.prop(i,"output",()=>{if(i.hash)return Bo.compile([zf.OP_0,i.hash])}),Sr.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Sr.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Sr.prop(i,"input",()=>{if(i.witness)return R2}),Sr.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let o=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");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!==22||e.output[0]!==zf.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(o.length>0&&!o.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");o=e.output.slice(2)}if(e.pubkey){const s=ea.hash160(e.pubkey);if(o.length>0&&!o.equals(s))throw new TypeError("Hash mismatch");if(o=s,!(0,je.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(!Bo.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,je.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 s=ea.hash160(e.witness[1]);if(o.length>0&&!o.equals(s))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}bs.p2wpkh=C2;var ms={};Object.defineProperty(ms,"__esModule",{value:!0});ms.p2wsh=void 0;const Vf=Ur,F2=at,ir=St(),Pe=ct,rr=xt,_o=pr,Wf=ir.OPS,ta=Buffer.alloc(0);function Eo(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,Pe.isPoint)(e))}function N2(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=rr.value(()=>{const s=_o.bech32.decode(e.address),a=s.words.shift(),c=_o.bech32.fromWords(s.words);return{version:a,prefix:s.prefix,data:Buffer.from(c)}}),n=rr.value(()=>ir.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||F2.bitcoin);const o={network:i};if(rr.prop(o,"address",()=>{if(!o.hash)return;const s=_o.bech32.toWords(o.hash);return s.unshift(0),_o.bech32.encode(i.bech32,s)}),rr.prop(o,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(o.redeem&&o.redeem.output)return Vf.sha256(o.redeem.output)}),rr.prop(o,"output",()=>{if(o.hash)return ir.compile([Wf.OP_0,o.hash])}),rr.prop(o,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:ta,witness:e.witness.slice(0,-1)}}),rr.prop(o,"input",()=>{if(o.witness)return ta}),rr.prop(o,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const s=ir.toStack(n());return o.redeem=Object.assign({witness:s},e.redeem),o.redeem.input=ta,[].concat(s,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),rr.prop(o,"name",()=>{const s=["p2wsh"];return o.redeem!==void 0&&o.redeem.name!==void 0&&s.push(o.redeem.name),s.join("-")}),t.validate){let s=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");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!==34||e.output[0]!==Wf.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=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=ir.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(ir.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=Vf.sha256(e.redeem.output);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch");s=c}if(e.redeem.input&&!ir.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(Eo)||e.redeem.output&&(ir.decompile(e.redeem.output)||[]).some(Eo))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(Eo)||(ir.decompile(a)||[]).some(Eo))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)}ms.p2wsh=N2;var Jn={},tn={};Object.defineProperty(tn,"__esModule",{value:!0});tn.getEccLib=tn.initEccLib=void 0;const ui={};function U2(e,t){e?e!==ui.eccLib&&(t!=null&&t.DANGER_DO_NOT_VERIFY_ECCLIB||H2(e),ui.eccLib=e):ui.eccLib=e}tn.initEccLib=U2;function L2(){if(!ui.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return ui.eccLib}tn.getEccLib=L2;const nr=e=>Buffer.from(e,"hex");function H2(e){It(typeof e.isXOnlyPoint=="function"),It(e.isXOnlyPoint(nr("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),It(e.isXOnlyPoint(nr("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),It(e.isXOnlyPoint(nr("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),It(e.isXOnlyPoint(nr("0000000000000000000000000000000000000000000000000000000000000001"))),It(!e.isXOnlyPoint(nr("0000000000000000000000000000000000000000000000000000000000000000"))),It(!e.isXOnlyPoint(nr("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),It(typeof e.xOnlyPointAddTweak=="function"),$2.forEach(t=>{const r=e.xOnlyPointAddTweak(nr(t.pubkey),nr(t.tweak));t.result===null?It(r===null):(It(r!==null),It(r.parity===t.parity),It(Buffer.from(r.xOnlyPubkey).equals(nr(t.result))))})}function It(e){if(!e)throw new Error("ecc library invalid")}const $2=[{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 Lu={};(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=Ut,r=tn,n=Ur,i=Ze,o=ct;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const s=g=>"left"in g&&"right"in g;function a(g,A){if(g.length<33)throw new TypeError(`The control-block length is too small. Got ${g.length}, expected min 33.`);const S=(g.length-33)/32;let P=A;for(let w=0;w<S;w++){const _=g.slice(33+32*w,65+32*w);P.compare(_)<0?P=p(P,_):P=p(_,P)}return P}e.rootHashFromPath=a;function c(g){if((0,o.isTapleaf)(g))return{hash:f(g)};const A=[c(g[0]),c(g[1])];A.sort((w,_)=>w.hash.compare(_.hash));const[S,P]=A;return{hash:p(S.hash,P.hash),left:S,right:P}}e.toHashTree=c;function u(g,A){if(s(g)){const S=u(g.left,A);if(S!==void 0)return[...S,g.right.hash];const P=u(g.right,A);if(P!==void 0)return[...P,g.left.hash]}else if(g.hash.equals(A))return[]}e.findScriptPath=u;function f(g){const A=g.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([A]),m(g.output)]))}e.tapleafHash=f;function h(g,A){return n.taggedHash("TapTweak",t.Buffer.concat(A?[g,A]:[g]))}e.tapTweakHash=h;function y(g,A){if(!t.Buffer.isBuffer(g)||g.length!==32||A&&A.length!==32)return null;const S=h(g,A),P=(0,r.getEccLib)().xOnlyPointAddTweak(g,S);return!P||P.xOnlyPubkey===null?null:{parity:P.parity,x:t.Buffer.from(P.xOnlyPubkey)}}e.tweakKey=y;function p(g,A){return n.taggedHash("TapBranch",t.Buffer.concat([g,A]))}function m(g){const A=i.varuint.encodingLength(g.length),S=t.Buffer.allocUnsafe(A);return i.varuint.encode(g.length,S),t.Buffer.concat([S,g])}})(Lu);var lt={},Kf;function M2(){if(Kf)return lt;Kf=1,Object.defineProperty(lt,"__esModule",{value:!0}),lt.toOutputScript=lt.fromOutputScript=lt.toBech32=lt.toBase58Check=lt.fromBech32=lt.fromBase58Check=void 0;const e=at,t=Hu(),r=St(),n=ct,i=pr,o=Nu,s=40,a=2,c=16,u=2,f=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 y(w,_){const I=w.slice(2);if(I.length<a||I.length>s)throw new TypeError("Invalid program length for segwit address");const T=w[0]-f;if(T<u||T>c)throw new TypeError("Invalid version for segwit address");if(w[1]!==I.length)throw new TypeError("Invalid script for segwit address");return console.warn(h),A(I,T,_.bech32)}function p(w){const _=Buffer.from(o.decode(w));if(_.length<21)throw new TypeError(w+" is too short");if(_.length>21)throw new TypeError(w+" is too long");const I=_.readUInt8(0),T=_.slice(1);return{version:I,hash:T}}lt.fromBase58Check=p;function m(w){let _,I;try{_=i.bech32.decode(w)}catch{}if(_){if(I=_.words[0],I!==0)throw new TypeError(w+" uses wrong encoding")}else if(_=i.bech32m.decode(w),I=_.words[0],I===0)throw new TypeError(w+" uses wrong encoding");const T=i.bech32.fromWords(_.words.slice(1));return{version:I,prefix:_.prefix,data:Buffer.from(T)}}lt.fromBech32=m;function g(w,_){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const I=Buffer.allocUnsafe(21);return I.writeUInt8(_,0),w.copy(I,1),o.encode(I)}lt.toBase58Check=g;function A(w,_,I){const T=i.bech32.toWords(w);return T.unshift(_),_===0?i.bech32.encode(I,T):i.bech32m.encode(I,T)}lt.toBech32=A;function S(w,_){_=_||e.bitcoin;try{return t.p2pkh({output:w,network:_}).address}catch{}try{return t.p2sh({output:w,network:_}).address}catch{}try{return t.p2wpkh({output:w,network:_}).address}catch{}try{return t.p2wsh({output:w,network:_}).address}catch{}try{return t.p2tr({output:w,network:_}).address}catch{}try{return y(w,_)}catch{}throw new Error(r.toASM(w)+" has no matching Address")}lt.fromOutputScript=S;function P(w,_){_=_||e.bitcoin;let I,T;try{I=p(w)}catch{}if(I){if(I.version===_.pubKeyHash)return t.p2pkh({hash:I.hash}).output;if(I.version===_.scriptHash)return t.p2sh({hash:I.hash}).output}else{try{T=m(w)}catch{}if(T){if(T.prefix!==_.bech32)throw new Error(w+" has an invalid prefix");if(T.version===0){if(T.data.length===20)return t.p2wpkh({hash:T.data}).output;if(T.data.length===32)return t.p2wsh({hash:T.data}).output}else if(T.version===1){if(T.data.length===32)return t.p2tr({pubkey:T.data}).output}else if(T.version>=u&&T.version<=c&&T.data.length>=a&&T.data.length<=s)return console.warn(h),r.compile([T.version+f,T.data])}}throw new Error(w+" has no matching Script")}return lt.toOutputScript=P,lt}var Yf;function D2(){if(Yf)return Jn;Yf=1,Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.p2tr=void 0;const e=Ut,t=at,r=St(),n=ct,i=tn,o=Lu,s=xt,a=pr,c=M2(),u=r.OPS,f=1,h=80;function y(p,m){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");m=Object.assign({validate:!0},m||{}),(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 g=s.value(()=>(0,c.fromBech32)(p.address)),A=s.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()}),S=s.value(()=>{if(p.scriptTree)return(0,o.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),P=p.network||t.bitcoin,w={name:"p2tr",network:P};if(s.prop(w,"address",()=>{if(!w.pubkey)return;const _=a.bech32m.toWords(w.pubkey);return _.unshift(f),a.bech32m.encode(P.bech32,_)}),s.prop(w,"hash",()=>{const _=S();if(_)return _.hash;const I=A();if(I&&I.length>1){const T=I[I.length-1],H=T[0]&n.TAPLEAF_VERSION_MASK,M=I[I.length-2],C=(0,o.tapleafHash)({output:M,version:H});return(0,o.rootHashFromPath)(T,C)}return null}),s.prop(w,"output",()=>{if(w.pubkey)return r.compile([u.OP_1,w.pubkey])}),s.prop(w,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:o.LEAF_VERSION_TAPSCRIPT),s.prop(w,"redeem",()=>{const _=A();if(!(!_||_.length<2))return{output:_[_.length-2],witness:_.slice(0,-2),redeemVersion:_[_.length-1][0]&n.TAPLEAF_VERSION_MASK}}),s.prop(w,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return g().data;if(w.internalPubkey){const _=(0,o.tweakKey)(w.internalPubkey,w.hash);if(_)return _.x}}),s.prop(w,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const _=A();if(_&&_.length>1)return _[_.length-1].slice(1,33)}),s.prop(w,"signature",()=>{if(p.signature)return p.signature;const _=A();if(!(!_||_.length!==1))return _[0]}),s.prop(w,"witness",()=>{if(p.witness)return p.witness;const _=S();if(_&&p.redeem&&p.redeem.output&&p.internalPubkey){const I=(0,o.tapleafHash)({output:p.redeem.output,version:w.redeemVersion}),T=(0,o.findScriptPath)(_,I);if(!T)return;const H=(0,o.tweakKey)(p.internalPubkey,_.hash);if(!H)return;const M=e.Buffer.concat([e.Buffer.from([w.redeemVersion|H.parity]),p.internalPubkey].concat(T));return[p.redeem.output,M]}if(p.signature)return[p.signature]}),m.validate){let _=e.Buffer.from([]);if(p.address){if(P&&P.bech32!==g().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(g().version!==f)throw new TypeError("Invalid address version");if(g().data.length!==32)throw new TypeError("Invalid address data");_=g().data}if(p.pubkey){if(_.length>0&&!_.equals(p.pubkey))throw new TypeError("Pubkey mismatch");_=p.pubkey}if(p.output){if(p.output.length!==34||p.output[0]!==u.OP_1||p.output[1]!==32)throw new TypeError("Output is invalid");if(_.length>0&&!_.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");_=p.output.slice(2)}if(p.internalPubkey){const H=(0,o.tweakKey)(p.internalPubkey,w.hash);if(_.length>0&&!_.equals(H.x))throw new TypeError("Pubkey mismatch");_=H.x}if(_&&_.length&&!(0,i.getEccLib)().isXOnlyPoint(_))throw new TypeError("Invalid pubkey for p2tr");const I=S();if(p.hash&&I&&!p.hash.equals(I.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&I){const H=(0,o.tapleafHash)({output:p.redeem.output,version:w.redeemVersion});if(!(0,o.findScriptPath)(I,H))throw new TypeError("Redeem script not in tree")}const T=A();if(p.redeem&&w.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==w.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(w.redeem.output&&!p.redeem.output.equals(w.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&w.redeem.witness&&!(0,n.stacksEqual)(p.redeem.witness,w.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(T&&T.length)if(T.length===1){if(p.signature&&!p.signature.equals(T[0]))throw new TypeError("Signature mismatch")}else{const H=T[T.length-1];if(H.length<33)throw new TypeError(`The control-block length is too small. Got ${H.length}, expected min 33.`);if((H.length-33)%32!==0)throw new TypeError(`The control-block length of ${H.length} is incorrect!`);const M=(H.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const C=H.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(C))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(C))throw new TypeError("Invalid internalPubkey for p2tr witness");const Y=H[0]&n.TAPLEAF_VERSION_MASK,J=T[T.length-2],re=(0,o.tapleafHash)({output:J,version:Y}),ee=(0,o.rootHashFromPath)(H,re),Q=(0,o.tweakKey)(C,ee);if(!Q)throw new TypeError("Invalid outputKey for p2tr witness");if(_.length&&!_.equals(Q.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(Q.parity!==(H[0]&1))throw new Error("Incorrect parity")}}return Object.assign(w,p)}return Jn.p2tr=y,Jn}var Xf;function Hu(){return Xf||(Xf=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=ls;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=ds;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=hs;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=ps;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const o=ys;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return o.p2sh}});const s=bs;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return s.p2wpkh}});const a=ms;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=D2();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Js)),Js}Object.defineProperty(Se,"__esModule",{value:!0});Se.signatureBlocksAction=Se.checkInputForSig=Se.pubkeyInScript=Se.pubkeyPositionInScript=Se.witnessStackToScriptWitness=Se.isP2TR=Se.isP2SHScript=Se.isP2WSHScript=Se.isP2WPKH=Se.isP2PKH=Se.isP2PK=Se.isP2MS=void 0;const Jf=to,fi=St(),xo=eo,j2=Ur,nn=Hu();function on(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}Se.isP2MS=on(nn.p2ms);Se.isP2PK=on(nn.p2pk);Se.isP2PKH=on(nn.p2pkh);Se.isP2WPKH=on(nn.p2wpkh);Se.isP2WSHScript=on(nn.p2wsh);Se.isP2SHScript=on(nn.p2sh);Se.isP2TR=on(nn.p2tr);function q2(e){let t=Buffer.allocUnsafe(0);function r(s){t=Buffer.concat([t,Buffer.from(s)])}function n(s){const a=t.length,c=Jf.encodingLength(s);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Jf.encode(s,t,a)}function i(s){n(s.length),r(s)}function o(s){n(s.length),s.forEach(i)}return o(e),t}Se.witnessStackToScriptWitness=q2;function Qp(e,t){const r=(0,j2.hash160)(e),n=e.slice(1,33),i=fi.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(o=>typeof o=="number"?!1:o.equals(e)||o.equals(r)||o.equals(n))}Se.pubkeyPositionInScript=Qp;function G2(e,t){return Qp(e,t)!==-1}Se.pubkeyInScript=G2;function z2(e,t){return V2(e).some(n=>e0(n,fi.signature.decode,t))}Se.checkInputForSig=z2;function e0(e,t,r){const{hashType:n}=t(e),i=[];switch(n&xo.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case xo.Transaction.SIGHASH_ALL:break;case xo.Transaction.SIGHASH_SINGLE:case xo.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}Se.signatureBlocksAction=e0;function V2(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=W2(e)}else t=e.partialSig;return t.map(r=>r.signature)}function W2(e){const t=e.finalScriptSig?fi.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?fi.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&fi.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(Fe,"__esModule",{value:!0});Fe.checkTaprootInputForSigs=Fe.tapTreeFromList=Fe.tapTreeToList=Fe.tweakInternalPubKey=Fe.checkTaprootOutputFields=Fe.checkTaprootInputFields=Fe.isTaprootOutput=Fe.isTaprootInput=ko=Fe.serializeTaprootSignature=Fe.tapScriptFinalizer=Fe.toXOnly=void 0;const $u=ct,K2=eo,gs=Se,Fr=Lu,Y2=Hu(),X2=Se,J2=e=>e.length===32?e:e.slice(1,33);Fe.toXOnly=J2;function Z2(e,t,r){const n=bv(t,e,r);try{const o=pv(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,gs.witnessStackToScriptWitness)(o)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}Fe.tapScriptFinalizer=Z2;function Q2(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var ko=Fe.serializeTaprootSignature=Q2;function Oo(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,gs.isP2TR)(e.witnessUtxo.script))}Fe.isTaprootInput=Oo;function Ro(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,gs.isP2TR)(t))}Fe.isTaprootOutput=Ro;function ev(e,t,r){lv(e,t,r),hv(e,t,r)}Fe.checkTaprootInputFields=ev;function tv(e,t,r){dv(e,t,r),rv(e,t)}Fe.checkTaprootOutputFields=tv;function rv(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,o=nv(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}function nv(e,t){const r=t&&t0(t.leaves),{output:n}=(0,Y2.p2tr)({internalPubkey:e,scriptTree:r});return n}function iv(e,t){const r=t.tapInternalKey,n=r&&(0,Fr.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}Fe.tweakInternalPubKey=iv;function ov(e){if(!(0,$u.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return Mc(e)}Fe.tapTreeToList=ov;function t0(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:fv(e)}Fe.tapTreeFromList=t0;function sv(e,t){return cv(e).some(n=>(0,X2.signatureBlocksAction)(n,av,t))}Fe.checkTaprootInputForSigs=sv;function av(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||K2.Transaction.SIGHASH_DEFAULT}}function cv(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=uv(e.finalScriptWitness);r&&t.push(r)}return t}function uv(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function Mc(e,t=[],r=0){if(r>Fr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,$u.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||Fr.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&Mc(e[0],t,r+1),e[1]&&Mc(e[1],t,r+1),t):[]}function fv(e){let t;for(const r of e)if(t=Dc(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function Dc(e,t,r=0){if(r>Fr.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,$u.isTapleaf)(t))return;const n=Dc(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=Dc(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function lv(e,t,r){const n=Oo(e)&&An(t),i=An(e)&&Oo(t),o=e===t&&Oo(t)&&An(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function dv(e,t,r){const n=Ro(e)&&An(t),i=An(e)&&Ro(t),o=e===t&&Ro(t)&&An(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function hv(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(o=>ra(o,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(o=>ra(o,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=>ra(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function ra(e,t){if(!t)return!0;const r=(0,Fr.tapleafHash)({output:e.script,version:e.leafVersion});return(0,Fr.rootHashFromPath)(e.controlBlock,r).equals(t)}function pv(e,t){const r=(0,Fr.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>yv(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function yv(e,t){return Object.assign({positionInScript:(0,gs.pubkeyPositionInScript)(t.pubkey,e)},t)}function bv(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,o)=>i.controlBlock.length-o.controlBlock.length).find(i=>mv(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function mv(e,t,r){const n=(0,Fr.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(o=>o.leafHash.equals(n))!==void 0}function An(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const Xe={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"},Ao=192;Ee.initEccLib(Kr);class li{constructor(t,r,n,i,o,s,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=o,this.expiry=s,this.signer=t,this.network=a,this.internalPubkey=Bw(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,o,s,a){n=n.startsWith("0x")?n.slice(2):n,Mr(n.length===64,Xe.secretHashLenMismatch),Mr(i.length===64||i.length===66,`initiator ${Xe.pubkeyLenMismatch}`),Mr(o.length===64||o.length===66,`redeemer ${Xe.pubkeyLenMismatch}`),Mr(s>0,Xe.zeroOrNegativeExpiry);const c=await t.getNetwork();return new li(t,r,n,Uc(o).toString("hex"),Uc(i).toString("hex"),s,c,a)}address(){const{address:t}=Ee.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(Xe.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new Ee.Transaction;n.version=2;const i=this.address(),o=await this.signer.getProvider();let s=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const u=await o.getTransaction(c);for(let f=0;f<u.vout.length;f++){const h=u.vout[f];h.scriptpubkey_address===i&&s.push({txid:u.txid,vout:f,value:h.value,status:{confirmed:!1}})}}else s=await o.getUTXOs(i);const a=s.reduce((c,u)=>c+u.value,0);if(a===0)throw new Error(`${i} ${Xe.notFunded}`);for(let c=0;c<s.length;c++)n.addInput(Buffer.from(s[c].txid,"hex").reverse(),s[c].vout);return r??(r=await o.suggestFee(i,a,Gr.Urgency.MEDIUM)),n.addOutput(Ee.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:s}}async _tempBuildRawTx(t,r){const n=new Ee.Transaction;n.version=2;const i=this.address(),o=await this.signer.getProvider();let s=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const u=await o.getTransaction(c);for(let f=0;f<u.vout.length;f++){const h=u.vout[f];h.scriptpubkey_address===i&&s.push({txid:u.txid,vout:f,value:h.value,status:{confirmed:!1}})}}else s=await o.getUTXOs(i);const a=s.reduce((c,u)=>c+u.value,0);if(a===0)throw new Error(`${i} ${Xe.notFunded}`);for(let c=0;c<s.length;c++)n.addInput(Buffer.from(s[c].txid,"hex").reverse(),s[c].vout);if(n.addOutput(Ee.address.toOutputScript(t,this.network),a),r){const c=await o.getFeeRates(),u=Math.ceil(c.hourFee*r),f=a-u;n.outs[0].value=f}return{tx:n,usedUtxos:s}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return Ee.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Gr.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateRedeemSACP(t,r,n){const{tx:i,usedUtxos:o}=await this._buildRawTx(r,n),s=this.getOutputScript(),a=Ee.Transaction.SIGHASH_SINGLE|Ee.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),u=o.map(h=>h.value),f=dn(s,o.length);for(let h=0;h<i.ins.length;h++){const y=i.hashForWitnessV1(h,f,u,a,c),p=await this.signer.signSchnorr(y);i.setWitness(h,[ko(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),o=this.getOutputScript(),s=Ee.Transaction.SIGHASH_SINGLE|Ee.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(f=>f.value),u=dn(o,i.length);for(let f=0;f<n.ins.length;f++){const h=n.hashForWitnessV1(f,u,c,s,a),y=await this.signer.signSchnorr(h);n.setWitness(f,[ko(y,s),ko(y,s),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){Mr(t.length>0,Xe.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const h of i)if(!t.find(y=>y.utxo===h.txid))throw new Error(Xe.counterPartySigNotFound(h.txid));const o=this.getOutputScript(),s=Ee.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(h=>h.value),u=dn(o,i.length);for(let h=0;h<n.ins.length;h++){const y=n.hashForWitnessV1(h,u,c,s,a);if(!Kr.verifySchnorr(y,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[h].sig,"hex")))throw new Error(Xe.invalidCounterpartySigForUTXO(t[h].utxo));const p=await this.signer.signSchnorr(y),m=Buffer.from(n.ins[h].hash).reverse().toString("hex"),g=t.find(A=>A.utxo===m);if(!g)throw new Error(Xe.counterPartySigNotFound(m));n.setWitness(h,[Buffer.from(g.sig,"hex"),p,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){Mr(Ee.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Xe.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:o}=await this._tempBuildRawTx(n),s=this.leafHash(1),a=o.map(y=>y.value),c=dn(this.getOutputScript(),o.length),u=Ee.Transaction.SIGHASH_DEFAULT;for(let y=0;y<i.ins.length;y++){const p=i.hashForWitnessV1(y,c,a,u,s),m=await this.signer.signSchnorr(p);i.setWitness(y,[m,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:f}=await this._tempBuildRawTx(n,i.virtualSize());for(let y=0;y<f.ins.length;y++){const p=f.hashForWitnessV1(y,c,a,u,s),m=await this.signer.signSchnorr(p);f.setWitness(y,[m,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(f.toHex())}async getRedeemHex(t,r){Mr(Ee.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Xe.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:o}=await this._tempBuildRawTx(n),s=this.leafHash(1),a=o.map(h=>h.value),c=dn(this.getOutputScript(),o.length),u=Ee.Transaction.SIGHASH_DEFAULT;for(let h=0;h<i.ins.length;h++){const y=i.hashForWitnessV1(h,c,a,u,s),p=await this.signer.signSchnorr(y);i.setWitness(h,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:f}=await this._tempBuildRawTx(n,i.virtualSize());for(let h=0;h<f.ins.length;h++){const y=f.hashForWitnessV1(h,c,a,u,s),p=await this.signer.signSchnorr(y);f.setWitness(h,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return f.toHex()}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[o,s]=await this.canRefund(i);if(!o)throw new Error(Xe.htlcNotExpired(s));const a=this.leafHash(0),c=i.map(y=>y.value),u=dn(this.getOutputScript(),i.length),f=Ee.Transaction.SIGHASH_DEFAULT;for(let y=0;y<n.ins.length;y++){n.ins[y].sequence=this.expiry;const p=n.hashForWitnessV1(y,u,c,f,a),m=await this.signer.signSchnorr(p);n.setWitness(y,[m,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 o=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?o=i.status.block_height+this.expiry-n+1:i.status.confirmed||(o=this.expiry+1),o>0)return[!1,o]}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(Xe.invalidLeaf)}const n=Ee.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:Ao}});if(!n.witness)throw new Error(Xe.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()),Ee.crypto.taggedHash("TapLeaf",yw(r))}refundLeaf(){return Ee.script.fromASM(`
51
- ${Ee.script.number.encode(this.expiry).toString("hex")}
52
- OP_CHECKSEQUENCEVERIFY
53
- OP_DROP
54
- ${this.initiatorPubkey}
55
- OP_CHECKSIG
56
- `.trim().replace(/\s+/g," "))}redeemLeaf(){return Ee.script.fromASM(`
57
- OP_SHA256
58
- ${this.secretHash}
59
- OP_EQUALVERIFY
60
- ${this.redeemerPubkey}
61
- OP_CHECKSIG
62
- `.trim().replace(/\s+/g," "))}instantRefundLeaf(){return Ee.script.fromASM(`
63
- ${this.initiatorPubkey}
64
- OP_CHECKSIG
65
- ${this.redeemerPubkey}
66
- OP_CHECKSIGADD
67
- OP_2
68
- OP_NUMEQUAL
69
- `.trim().replace(/\s+/g," "))}leaves(){return[{version:Ao,output:this.redeemLeaf()},[{version:Ao,output:this.refundLeaf()},{version:Ao,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const o=mw(i,n);return[Ee.crypto.taggedHash("TapBranch",Buffer.concat(o))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(Xe.invalidLeaf)}}}function dn(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class gv{constructor(){this.cache={}}set(t,r,n,i){const o={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=o}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 wv{constructor(){this.cache={}}set(t,r){this.cache[t]=r}get(t){return this.cache[t]||null}}class r0{constructor(t,r){this.url=new Z.Url(t).endpoint("blocknumber"),this.environment=r}async fetchBlockNumbers(){try{const t=await N.Fetcher.get(this.url);return N.Ok(t)}catch(t){return N.Err("Failed to fetch block numbers",t)}}}class n0{constructor(t){this.quoteUrl=new Z.Url(t)}async getQuoteFromAssets(t,r,n,i=!1,o){const s=Lc(t.chain,t.atomicSwapAddress,r.chain,r.atomicSwapAddress);return this.getQuote(s,n,i,o)}async getQuote(t,r,n=!1,i){try{const o={order_pair:t,amount:r.toString(),exact_out:n.toString(),...(i==null?void 0:i.affiliateFee)!==void 0&&{affiliate_fee:i.affiliateFee.toString()}},s=this.quoteUrl.endpoint("/").addSearchParams(o),a=await N.Fetcher.get(s,{retryCount:0,...i==null?void 0:i.request});return a.error?N.Err(a.error):a.result?N.Ok(a.result):N.Err("GetQuote: Unexpected error, result is undefined")}catch(o){return N.Err("GetQuote:",String(o))}}async getAttestedQuote(t){try{const r=await N.Fetcher.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?N.Err(r.error):r.result?N.Ok(r.result):N.Err("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),N.Err("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await N.Fetcher.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return N.Err(t.error);if(!t.result)return N.Err("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=Lc(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 N.Ok(r)}catch(t){return N.Err("GetStrategies:",String(t))}}}var i0={},Rn={},Cn={};Object.defineProperty(Cn,"__esModule",{value:!0});Cn.testnet=Cn.bitcoin=void 0;Cn.bitcoin={messagePrefix:`Bitcoin Signed Message:
70
- `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Cn.testnet={messagePrefix:`Bitcoin Signed Message:
71
- `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var o0={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=jp,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})(o0);var jc={exports:{}},qc={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Ut,n=r.Buffer;function i(s,a){for(var c in s)a[c]=s[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o);function o(s,a,c){return n(s,a,c)}o.prototype=Object.create(n.prototype),i(n,o),o.from=function(s,a,c){if(typeof s=="number")throw new TypeError("Argument must not be a number");return n(s,a,c)},o.alloc=function(s,a,c){if(typeof s!="number")throw new TypeError("Argument must be a number");var u=n(s);return a!==void 0?typeof c=="string"?u.fill(a,c):u.fill(a):u.fill(0),u},o.allocUnsafe=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return n(s)},o.allocUnsafeSlow=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(s)}})(qc,qc.exports);var mt=qc.exports,na=65536,vv=4294967295;function _v(){throw new Error(`Secure random number generation is not supported by this browser.
72
- Use Chrome, Firefox or Internet Explorer 11`)}var Ev=mt.Buffer,Mo=We.crypto||We.msCrypto;Mo&&Mo.getRandomValues?jc.exports=xv:jc.exports=_v;function xv(e,t){if(e>vv)throw new RangeError("requested too many random bytes");var r=Ev.allocUnsafe(e);if(e>0)if(e>na)for(var n=0;n<e;n+=na)Mo.getRandomValues(r.slice(n,n+na));else Mo.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Av=jc.exports,Gc={exports:{}};typeof Object.create=="function"?Gc.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:Gc.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}};var Ke=Gc.exports,zc={exports:{}},Mu={exports:{}},Sn=typeof Reflect=="object"?Reflect:null,Zf=Sn&&typeof Sn.apply=="function"?Sn.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Co;Sn&&typeof Sn.ownKeys=="function"?Co=Sn.ownKeys:Object.getOwnPropertySymbols?Co=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Co=function(t){return Object.getOwnPropertyNames(t)};function Sv(e){console&&console.warn&&console.warn(e)}var s0=Number.isNaN||function(t){return t!==t};function xe(){xe.init.call(this)}Mu.exports=xe;Mu.exports.once=Bv;xe.EventEmitter=xe;xe.prototype._events=void 0;xe.prototype._eventsCount=0;xe.prototype._maxListeners=void 0;var Qf=10;function ws(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(xe,"defaultMaxListeners",{enumerable:!0,get:function(){return Qf},set:function(e){if(typeof e!="number"||e<0||s0(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Qf=e}});xe.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};xe.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||s0(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 a0(e){return e._maxListeners===void 0?xe.defaultMaxListeners:e._maxListeners}xe.prototype.getMaxListeners=function(){return a0(this)};xe.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(r.length>0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var c=o[t];if(c===void 0)return!1;if(typeof c=="function")Zf(c,this,r);else for(var u=c.length,f=d0(c,u),n=0;n<u;++n)Zf(f[n],this,r);return!0};function c0(e,t,r,n){var i,o,s;if(ws(r),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),s=o[t]),s===void 0)s=o[t]=r,++e._eventsCount;else if(typeof s=="function"?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),i=a0(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,Sv(a)}return e}xe.prototype.addListener=function(t,r){return c0(this,t,r,!1)};xe.prototype.on=xe.prototype.addListener;xe.prototype.prependListener=function(t,r){return c0(this,t,r,!0)};function Pv(){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 u0(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Pv.bind(n);return i.listener=r,n.wrapFn=i,i}xe.prototype.once=function(t,r){return ws(r),this.on(t,u0(this,t,r)),this};xe.prototype.prependOnceListener=function(t,r){return ws(r),this.prependListener(t,u0(this,t,r)),this};xe.prototype.removeListener=function(t,r){var n,i,o,s,a;if(ws(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(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Tv(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};xe.prototype.off=xe.prototype.removeListener;xe.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 o=Object.keys(n),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);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 f0(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?Iv(i):d0(i,i.length)}xe.prototype.listeners=function(t){return f0(this,t,!0)};xe.prototype.rawListeners=function(t){return f0(this,t,!1)};xe.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):l0.call(e,t)};xe.prototype.listenerCount=l0;function l0(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}xe.prototype.eventNames=function(){return this._eventsCount>0?Co(this._events):[]};function d0(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Tv(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Iv(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Bv(e,t){return new Promise(function(r,n){function i(s){e.removeListener(t,o),n(s)}function o(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}h0(e,t,o,{once:!0}),t!=="error"&&kv(e,i,{once:!0})})}function kv(e,t,r){typeof e.on=="function"&&h0(e,"error",t,r)}function h0(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(o){n.once&&e.removeEventListener(t,i),r(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var p0=Mu.exports,y0=p0.EventEmitter;const Ov={},Rv=Object.freeze(Object.defineProperty({__proto__:null,default:Ov},Symbol.toStringTag,{value:"Module"})),Du=U1(Rv);var ia,el;function Cv(){if(el)return ia;el=1;function e(m,g){var A=Object.keys(m);if(Object.getOwnPropertySymbols){var S=Object.getOwnPropertySymbols(m);g&&(S=S.filter(function(P){return Object.getOwnPropertyDescriptor(m,P).enumerable})),A.push.apply(A,S)}return A}function t(m){for(var g=1;g<arguments.length;g++){var A=arguments[g]!=null?arguments[g]:{};g%2?e(Object(A),!0).forEach(function(S){r(m,S,A[S])}):Object.getOwnPropertyDescriptors?Object.defineProperties(m,Object.getOwnPropertyDescriptors(A)):e(Object(A)).forEach(function(S){Object.defineProperty(m,S,Object.getOwnPropertyDescriptor(A,S))})}return m}function r(m,g,A){return g=s(g),g in m?Object.defineProperty(m,g,{value:A,enumerable:!0,configurable:!0,writable:!0}):m[g]=A,m}function n(m,g){if(!(m instanceof g))throw new TypeError("Cannot call a class as a function")}function i(m,g){for(var A=0;A<g.length;A++){var S=g[A];S.enumerable=S.enumerable||!1,S.configurable=!0,"value"in S&&(S.writable=!0),Object.defineProperty(m,s(S.key),S)}}function o(m,g,A){return g&&i(m.prototype,g),Object.defineProperty(m,"prototype",{writable:!1}),m}function s(m){var g=a(m,"string");return typeof g=="symbol"?g:String(g)}function a(m,g){if(typeof m!="object"||m===null)return m;var A=m[Symbol.toPrimitive];if(A!==void 0){var S=A.call(m,g);if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(m)}var c=Ut,u=c.Buffer,f=Du,h=f.inspect,y=h&&h.custom||"inspect";function p(m,g,A){u.prototype.copy.call(m,g,A)}return ia=function(){function m(){n(this,m),this.head=null,this.tail=null,this.length=0}return o(m,[{key:"push",value:function(A){var S={data:A,next:null};this.length>0?this.tail.next=S:this.head=S,this.tail=S,++this.length}},{key:"unshift",value:function(A){var S={data:A,next:this.head};this.length===0&&(this.tail=S),this.head=S,++this.length}},{key:"shift",value:function(){if(this.length!==0){var A=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,A}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(A){if(this.length===0)return"";for(var S=this.head,P=""+S.data;S=S.next;)P+=A+S.data;return P}},{key:"concat",value:function(A){if(this.length===0)return u.alloc(0);for(var S=u.allocUnsafe(A>>>0),P=this.head,w=0;P;)p(P.data,S,w),w+=P.data.length,P=P.next;return S}},{key:"consume",value:function(A,S){var P;return A<this.head.data.length?(P=this.head.data.slice(0,A),this.head.data=this.head.data.slice(A)):A===this.head.data.length?P=this.shift():P=S?this._getString(A):this._getBuffer(A),P}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(A){var S=this.head,P=1,w=S.data;for(A-=w.length;S=S.next;){var _=S.data,I=A>_.length?_.length:A;if(I===_.length?w+=_:w+=_.slice(0,A),A-=I,A===0){I===_.length?(++P,S.next?this.head=S.next:this.head=this.tail=null):(this.head=S,S.data=_.slice(I));break}++P}return this.length-=P,w}},{key:"_getBuffer",value:function(A){var S=u.allocUnsafe(A),P=this.head,w=1;for(P.data.copy(S),A-=P.data.length;P=P.next;){var _=P.data,I=A>_.length?_.length:A;if(_.copy(S,S.length-A,0,I),A-=I,A===0){I===_.length?(++w,P.next?this.head=P.next:this.head=this.tail=null):(this.head=P,P.data=_.slice(I));break}++w}return this.length-=w,S}},{key:y,value:function(A,S){return h(this,t(t({},S),{},{depth:0,customInspect:!1}))}}]),m}(),ia}function Fv(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(Vc,this,e)):process.nextTick(Vc,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(o){!t&&o?r._writableState?r._writableState.errorEmitted?process.nextTick(Fo,r):(r._writableState.errorEmitted=!0,process.nextTick(tl,r,o)):process.nextTick(tl,r,o):t?(process.nextTick(Fo,r),t(o)):process.nextTick(Fo,r)}),this)}function tl(e,t){Vc(e,t),Fo(e)}function Fo(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Nv(){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 Vc(e,t){e.emit("error",t)}function Uv(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var b0={destroy:Fv,undestroy:Nv,errorOrDestroy:Uv},sn={};function Lv(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var m0={};function Rt(e,t,r){r||(r=Error);function n(o,s,a){return typeof t=="string"?t:t(o,s,a)}var i=function(o){Lv(s,o);function s(a,c,u){return o.call(this,n(a,c,u))||this}return s}(r);i.prototype.name=r.name,i.prototype.code=e,m0[e]=i}function rl(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 Hv(e,t,r){return e.substr(0,t.length)===t}function $v(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Mv(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Rt("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Rt("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&Hv(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if($v(e," argument"))i="The ".concat(e," ").concat(n," ").concat(rl(t,"type"));else{var o=Mv(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(o," ").concat(n," ").concat(rl(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Rt("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Rt("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Rt("ERR_STREAM_PREMATURE_CLOSE","Premature close");Rt("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Rt("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Rt("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Rt("ERR_STREAM_WRITE_AFTER_END","write after end");Rt("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Rt("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Rt("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");sn.codes=m0;var Dv=sn.codes.ERR_INVALID_OPT_VALUE;function jv(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function qv(e,t,r,n){var i=jv(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var o=n?r:"highWaterMark";throw new Dv(o,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var g0={getHighWaterMark:qv},Gv=zv;function zv(e,t){if(oa("noDeprecation"))return e;var r=!1;function n(){if(!r){if(oa("throwDeprecation"))throw new Error(t);oa("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function oa(e){try{if(!We.localStorage)return!1}catch{return!1}var t=We.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var sa,nl;function w0(){if(nl)return sa;nl=1,sa=M;function e(B){var O=this;this.next=null,this.entry=null,this.finish=function(){te(O,B)}}var t;M.WritableState=T;var r={deprecate:Gv},n=y0,i=Ut.Buffer,o=(typeof We<"u"?We:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(B){return i.from(B)}function a(B){return i.isBuffer(B)||B instanceof o}var c=b0,u=g0,f=u.getHighWaterMark,h=sn.codes,y=h.ERR_INVALID_ARG_TYPE,p=h.ERR_METHOD_NOT_IMPLEMENTED,m=h.ERR_MULTIPLE_CALLBACK,g=h.ERR_STREAM_CANNOT_PIPE,A=h.ERR_STREAM_DESTROYED,S=h.ERR_STREAM_NULL_VALUES,P=h.ERR_STREAM_WRITE_AFTER_END,w=h.ERR_UNKNOWN_ENCODING,_=c.errorOrDestroy;Ke(M,n);function I(){}function T(B,O,$){t=t||Fn(),B=B||{},typeof $!="boolean"&&($=O instanceof t),this.objectMode=!!B.objectMode,$&&(this.objectMode=this.objectMode||!!B.writableObjectMode),this.highWaterMark=f(this,B,"writableHighWaterMark",$),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var V=B.decodeStrings===!1;this.decodeStrings=!V,this.defaultEncoding=B.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(W){_e(O,W)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=B.emitClose!==!1,this.autoDestroy=!!B.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}T.prototype.getBuffer=function(){for(var O=this.bufferedRequest,$=[];O;)$.push(O),O=O.next;return $},function(){try{Object.defineProperty(T.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var H;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(H=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(O){return H.call(this,O)?!0:this!==M?!1:O&&O._writableState instanceof T}})):H=function(O){return O instanceof this};function M(B){t=t||Fn();var O=this instanceof t;if(!O&&!H.call(M,this))return new M(B);this._writableState=new T(B,this,O),this.writable=!0,B&&(typeof B.write=="function"&&(this._write=B.write),typeof B.writev=="function"&&(this._writev=B.writev),typeof B.destroy=="function"&&(this._destroy=B.destroy),typeof B.final=="function"&&(this._final=B.final)),n.call(this)}M.prototype.pipe=function(){_(this,new g)};function C(B,O){var $=new P;_(B,$),process.nextTick(O,$)}function Y(B,O,$,V){var W;return $===null?W=new S:typeof $!="string"&&!O.objectMode&&(W=new y("chunk",["string","Buffer"],$)),W?(_(B,W),process.nextTick(V,W),!1):!0}M.prototype.write=function(B,O,$){var V=this._writableState,W=!1,v=!V.objectMode&&a(B);return v&&!i.isBuffer(B)&&(B=s(B)),typeof O=="function"&&($=O,O=null),v?O="buffer":O||(O=V.defaultEncoding),typeof $!="function"&&($=I),V.ending?C(this,$):(v||Y(this,V,B,$))&&(V.pendingcb++,W=re(this,V,v,B,O,$)),W},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var B=this._writableState;B.corked&&(B.corked--,!B.writing&&!B.corked&&!B.bufferProcessing&&B.bufferedRequest&&F(this,B))},M.prototype.setDefaultEncoding=function(O){if(typeof O=="string"&&(O=O.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((O+"").toLowerCase())>-1))throw new w(O);return this._writableState.defaultEncoding=O,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function J(B,O,$){return!B.objectMode&&B.decodeStrings!==!1&&typeof O=="string"&&(O=i.from(O,$)),O}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function re(B,O,$,V,W,v){if(!$){var E=J(O,V,W);V!==E&&($=!0,W="buffer",V=E)}var D=O.objectMode?1:V.length;O.length+=D;var K=O.length<O.highWaterMark;if(K||(O.needDrain=!0),O.writing||O.corked){var me=O.lastBufferedRequest;O.lastBufferedRequest={chunk:V,encoding:W,isBuf:$,callback:v,next:null},me?me.next=O.lastBufferedRequest:O.bufferedRequest=O.lastBufferedRequest,O.bufferedRequestCount+=1}else ee(B,O,!1,D,V,W,v);return K}function ee(B,O,$,V,W,v,E){O.writelen=V,O.writecb=E,O.writing=!0,O.sync=!0,O.destroyed?O.onwrite(new A("write")):$?B._writev(W,O.onwrite):B._write(W,v,O.onwrite),O.sync=!1}function Q(B,O,$,V,W){--O.pendingcb,$?(process.nextTick(W,V),process.nextTick(U,B,O),B._writableState.errorEmitted=!0,_(B,V)):(W(V),B._writableState.errorEmitted=!0,_(B,V),U(B,O))}function ae(B){B.writing=!1,B.writecb=null,B.length-=B.writelen,B.writelen=0}function _e(B,O){var $=B._writableState,V=$.sync,W=$.writecb;if(typeof W!="function")throw new m;if(ae($),O)Q(B,$,V,O,W);else{var v=X($)||B.destroyed;!v&&!$.corked&&!$.bufferProcessing&&$.bufferedRequest&&F(B,$),V?process.nextTick(pe,B,$,v,W):pe(B,$,v,W)}}function pe(B,O,$,V){$||de(B,O),O.pendingcb--,V(),U(B,O)}function de(B,O){O.length===0&&O.needDrain&&(O.needDrain=!1,B.emit("drain"))}function F(B,O){O.bufferProcessing=!0;var $=O.bufferedRequest;if(B._writev&&$&&$.next){var V=O.bufferedRequestCount,W=new Array(V),v=O.corkedRequestsFree;v.entry=$;for(var E=0,D=!0;$;)W[E]=$,$.isBuf||(D=!1),$=$.next,E+=1;W.allBuffers=D,ee(B,O,!0,O.length,W,"",v.finish),O.pendingcb++,O.lastBufferedRequest=null,v.next?(O.corkedRequestsFree=v.next,v.next=null):O.corkedRequestsFree=new e(O),O.bufferedRequestCount=0}else{for(;$;){var K=$.chunk,me=$.encoding,ie=$.callback,ye=O.objectMode?1:K.length;if(ee(B,O,!1,ye,K,me,ie),$=$.next,O.bufferedRequestCount--,O.writing)break}$===null&&(O.lastBufferedRequest=null)}O.bufferedRequest=$,O.bufferProcessing=!1}M.prototype._write=function(B,O,$){$(new p("_write()"))},M.prototype._writev=null,M.prototype.end=function(B,O,$){var V=this._writableState;return typeof B=="function"?($=B,B=null,O=null):typeof O=="function"&&($=O,O=null),B!=null&&this.write(B,O),V.corked&&(V.corked=1,this.uncork()),V.ending||j(this,V,$),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function X(B){return B.ending&&B.length===0&&B.bufferedRequest===null&&!B.finished&&!B.writing}function ne(B,O){B._final(function($){O.pendingcb--,$&&_(B,$),O.prefinished=!0,B.emit("prefinish"),U(B,O)})}function k(B,O){!O.prefinished&&!O.finalCalled&&(typeof B._final=="function"&&!O.destroyed?(O.pendingcb++,O.finalCalled=!0,process.nextTick(ne,B,O)):(O.prefinished=!0,B.emit("prefinish")))}function U(B,O){var $=X(O);if($&&(k(B,O),O.pendingcb===0&&(O.finished=!0,B.emit("finish"),O.autoDestroy))){var V=B._readableState;(!V||V.autoDestroy&&V.endEmitted)&&B.destroy()}return $}function j(B,O,$){O.ending=!0,U(B,O),$&&(O.finished?process.nextTick($):B.once("finish",$)),O.ended=!0,B.writable=!1}function te(B,O,$){var V=B.entry;for(B.entry=null;V;){var W=V.callback;O.pendingcb--,W($),V=V.next}O.corkedRequestsFree.next=B}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(O){this._writableState&&(this._writableState.destroyed=O)}}),M.prototype.destroy=c.destroy,M.prototype._undestroy=c.undestroy,M.prototype._destroy=function(B,O){O(B)},sa}var aa,il;function Fn(){if(il)return aa;il=1;var e=Object.keys||function(u){var f=[];for(var h in u)f.push(h);return f};aa=s;var t=_0(),r=w0();Ke(s,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var o=n[i];s.prototype[o]||(s.prototype[o]=r.prototype[o])}function s(u){if(!(this instanceof s))return new s(u);t.call(this,u),r.call(this,u),this.allowHalfOpen=!0,u&&(u.readable===!1&&(this.readable=!1),u.writable===!1&&(this.writable=!1),u.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",a)))}Object.defineProperty(s.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(s.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(s.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function a(){this._writableState.ended||process.nextTick(c,this)}function c(u){u.end()}return Object.defineProperty(s.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(f){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=f,this._writableState.destroyed=f)}}),aa}var Do={},ju=mt.Buffer,ol=ju.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 Vv(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 Wv(e){var t=Vv(e);if(typeof t!="string"&&(ju.isEncoding===ol||!ol(e)))throw new Error("Unknown encoding: "+e);return t||e}Do.StringDecoder=ro;function ro(e){this.encoding=Wv(e);var t;switch(this.encoding){case"utf16le":this.text=Qv,this.end=e_,t=4;break;case"utf8":this.fillLast=Xv,t=4;break;case"base64":this.text=t_,this.end=r_,t=3;break;default:this.write=n_,this.end=i_;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=ju.allocUnsafe(t)}ro.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||""};ro.prototype.end=Zv;ro.prototype.text=Jv;ro.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 ca(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Kv(e,t,r){var n=t.length-1;if(n<r)return 0;var i=ca(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=ca(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=ca(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function Yv(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 Xv(e){var t=this.lastTotal-this.lastNeed,r=Yv(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 Jv(e,t){var r=Kv(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 Zv(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function Qv(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 e_(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 t_(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 r_(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function n_(e){return e.toString(this.encoding)}function i_(e){return e&&e.length?this.write(e):""}var sl=sn.codes.ERR_STREAM_PREMATURE_CLOSE;function o_(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 s_(){}function a_(e){return e.setHeader&&typeof e.abort=="function"}function v0(e,t,r){if(typeof t=="function")return v0(e,null,t);t||(t={}),r=o_(r||s_);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,o=function(){e.writable||a()},s=e._writableState&&e._writableState.finished,a=function(){i=!1,s=!0,n||r.call(e)},c=e._readableState&&e._readableState.endEmitted,u=function(){n=!1,c=!0,i||r.call(e)},f=function(m){r.call(e,m)},h=function(){var m;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(m=new sl),r.call(e,m);if(i&&!s)return(!e._writableState||!e._writableState.ended)&&(m=new sl),r.call(e,m)},y=function(){e.req.on("finish",a)};return a_(e)?(e.on("complete",a),e.on("abort",h),e.req?y():e.on("request",y)):i&&!e._writableState&&(e.on("end",o),e.on("close",o)),e.on("end",u),e.on("finish",a),t.error!==!1&&e.on("error",f),e.on("close",h),function(){e.removeListener("complete",a),e.removeListener("abort",h),e.removeListener("request",y),e.req&&e.req.removeListener("finish",a),e.removeListener("end",o),e.removeListener("close",o),e.removeListener("finish",a),e.removeListener("end",u),e.removeListener("error",f),e.removeListener("close",h)}}var qu=v0,ua,al;function c_(){if(al)return ua;al=1;var e;function t(w,_,I){return _=r(_),_ in w?Object.defineProperty(w,_,{value:I,enumerable:!0,configurable:!0,writable:!0}):w[_]=I,w}function r(w){var _=n(w,"string");return typeof _=="symbol"?_:String(_)}function n(w,_){if(typeof w!="object"||w===null)return w;var I=w[Symbol.toPrimitive];if(I!==void 0){var T=I.call(w,_);if(typeof T!="object")return T;throw new TypeError("@@toPrimitive must return a primitive value.")}return(_==="string"?String:Number)(w)}var i=qu,o=Symbol("lastResolve"),s=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),u=Symbol("lastPromise"),f=Symbol("handlePromise"),h=Symbol("stream");function y(w,_){return{value:w,done:_}}function p(w){var _=w[o];if(_!==null){var I=w[h].read();I!==null&&(w[u]=null,w[o]=null,w[s]=null,_(y(I,!1)))}}function m(w){process.nextTick(p,w)}function g(w,_){return function(I,T){w.then(function(){if(_[c]){I(y(void 0,!0));return}_[f](I,T)},T)}}var A=Object.getPrototypeOf(function(){}),S=Object.setPrototypeOf((e={get stream(){return this[h]},next:function(){var _=this,I=this[a];if(I!==null)return Promise.reject(I);if(this[c])return Promise.resolve(y(void 0,!0));if(this[h].destroyed)return new Promise(function(C,Y){process.nextTick(function(){_[a]?Y(_[a]):C(y(void 0,!0))})});var T=this[u],H;if(T)H=new Promise(g(T,this));else{var M=this[h].read();if(M!==null)return Promise.resolve(y(M,!1));H=new Promise(this[f])}return this[u]=H,H}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var _=this;return new Promise(function(I,T){_[h].destroy(null,function(H){if(H){T(H);return}I(y(void 0,!0))})})}),e),A),P=function(_){var I,T=Object.create(S,(I={},t(I,h,{value:_,writable:!0}),t(I,o,{value:null,writable:!0}),t(I,s,{value:null,writable:!0}),t(I,a,{value:null,writable:!0}),t(I,c,{value:_._readableState.endEmitted,writable:!0}),t(I,f,{value:function(M,C){var Y=T[h].read();Y?(T[u]=null,T[o]=null,T[s]=null,M(y(Y,!1))):(T[o]=M,T[s]=C)},writable:!0}),I));return T[u]=null,i(_,function(H){if(H&&H.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=T[s];M!==null&&(T[u]=null,T[o]=null,T[s]=null,M(H)),T[a]=H;return}var C=T[o];C!==null&&(T[u]=null,T[o]=null,T[s]=null,C(y(void 0,!0))),T[c]=!0}),_.on("readable",m.bind(null,T)),T};return ua=P,ua}var fa,cl;function u_(){return cl||(cl=1,fa=function(){throw new Error("Readable.from is not available in the browser")}),fa}var la,ul;function _0(){if(ul)return la;ul=1,la=C;var e;C.ReadableState=M,p0.EventEmitter;var t=function(E,D){return E.listeners(D).length},r=y0,n=Ut.Buffer,i=(typeof We<"u"?We:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(v){return n.from(v)}function s(v){return n.isBuffer(v)||v instanceof i}var a=Du,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var u=Cv(),f=b0,h=g0,y=h.getHighWaterMark,p=sn.codes,m=p.ERR_INVALID_ARG_TYPE,g=p.ERR_STREAM_PUSH_AFTER_EOF,A=p.ERR_METHOD_NOT_IMPLEMENTED,S=p.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,P,w,_;Ke(C,r);var I=f.errorOrDestroy,T=["error","close","destroy","pause","resume"];function H(v,E,D){if(typeof v.prependListener=="function")return v.prependListener(E,D);!v._events||!v._events[E]?v.on(E,D):Array.isArray(v._events[E])?v._events[E].unshift(D):v._events[E]=[D,v._events[E]]}function M(v,E,D){e=e||Fn(),v=v||{},typeof D!="boolean"&&(D=E instanceof e),this.objectMode=!!v.objectMode,D&&(this.objectMode=this.objectMode||!!v.readableObjectMode),this.highWaterMark=y(this,v,"readableHighWaterMark",D),this.buffer=new u,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=v.emitClose!==!1,this.autoDestroy=!!v.autoDestroy,this.destroyed=!1,this.defaultEncoding=v.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,v.encoding&&(P||(P=Do.StringDecoder),this.decoder=new P(v.encoding),this.encoding=v.encoding)}function C(v){if(e=e||Fn(),!(this instanceof C))return new C(v);var E=this instanceof e;this._readableState=new M(v,this,E),this.readable=!0,v&&(typeof v.read=="function"&&(this._read=v.read),typeof v.destroy=="function"&&(this._destroy=v.destroy)),r.call(this)}Object.defineProperty(C.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(E){this._readableState&&(this._readableState.destroyed=E)}}),C.prototype.destroy=f.destroy,C.prototype._undestroy=f.undestroy,C.prototype._destroy=function(v,E){E(v)},C.prototype.push=function(v,E){var D=this._readableState,K;return D.objectMode?K=!0:typeof v=="string"&&(E=E||D.defaultEncoding,E!==D.encoding&&(v=n.from(v,E),E=""),K=!0),Y(this,v,E,!1,K)},C.prototype.unshift=function(v){return Y(this,v,null,!0,!1)};function Y(v,E,D,K,me){c("readableAddChunk",E);var ie=v._readableState;if(E===null)ie.reading=!1,_e(v,ie);else{var ye;if(me||(ye=re(ie,E)),ye)I(v,ye);else if(ie.objectMode||E&&E.length>0)if(typeof E!="string"&&!ie.objectMode&&Object.getPrototypeOf(E)!==n.prototype&&(E=o(E)),K)ie.endEmitted?I(v,new S):J(v,ie,E,!0);else if(ie.ended)I(v,new g);else{if(ie.destroyed)return!1;ie.reading=!1,ie.decoder&&!D?(E=ie.decoder.write(E),ie.objectMode||E.length!==0?J(v,ie,E,!1):F(v,ie)):J(v,ie,E,!1)}else K||(ie.reading=!1,F(v,ie))}return!ie.ended&&(ie.length<ie.highWaterMark||ie.length===0)}function J(v,E,D,K){E.flowing&&E.length===0&&!E.sync?(E.awaitDrain=0,v.emit("data",D)):(E.length+=E.objectMode?1:D.length,K?E.buffer.unshift(D):E.buffer.push(D),E.needReadable&&pe(v)),F(v,E)}function re(v,E){var D;return!s(E)&&typeof E!="string"&&E!==void 0&&!v.objectMode&&(D=new m("chunk",["string","Buffer","Uint8Array"],E)),D}C.prototype.isPaused=function(){return this._readableState.flowing===!1},C.prototype.setEncoding=function(v){P||(P=Do.StringDecoder);var E=new P(v);this._readableState.decoder=E,this._readableState.encoding=this._readableState.decoder.encoding;for(var D=this._readableState.buffer.head,K="";D!==null;)K+=E.write(D.data),D=D.next;return this._readableState.buffer.clear(),K!==""&&this._readableState.buffer.push(K),this._readableState.length=K.length,this};var ee=1073741824;function Q(v){return v>=ee?v=ee:(v--,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v++),v}function ae(v,E){return v<=0||E.length===0&&E.ended?0:E.objectMode?1:v!==v?E.flowing&&E.length?E.buffer.head.data.length:E.length:(v>E.highWaterMark&&(E.highWaterMark=Q(v)),v<=E.length?v:E.ended?E.length:(E.needReadable=!0,0))}C.prototype.read=function(v){c("read",v),v=parseInt(v,10);var E=this._readableState,D=v;if(v!==0&&(E.emittedReadable=!1),v===0&&E.needReadable&&((E.highWaterMark!==0?E.length>=E.highWaterMark:E.length>0)||E.ended))return c("read: emitReadable",E.length,E.ended),E.length===0&&E.ended?$(this):pe(this),null;if(v=ae(v,E),v===0&&E.ended)return E.length===0&&$(this),null;var K=E.needReadable;c("need readable",K),(E.length===0||E.length-v<E.highWaterMark)&&(K=!0,c("length less than watermark",K)),E.ended||E.reading?(K=!1,c("reading or ended",K)):K&&(c("do read"),E.reading=!0,E.sync=!0,E.length===0&&(E.needReadable=!0),this._read(E.highWaterMark),E.sync=!1,E.reading||(v=ae(D,E)));var me;return v>0?me=O(v,E):me=null,me===null?(E.needReadable=E.length<=E.highWaterMark,v=0):(E.length-=v,E.awaitDrain=0),E.length===0&&(E.ended||(E.needReadable=!0),D!==v&&E.ended&&$(this)),me!==null&&this.emit("data",me),me};function _e(v,E){if(c("onEofChunk"),!E.ended){if(E.decoder){var D=E.decoder.end();D&&D.length&&(E.buffer.push(D),E.length+=E.objectMode?1:D.length)}E.ended=!0,E.sync?pe(v):(E.needReadable=!1,E.emittedReadable||(E.emittedReadable=!0,de(v)))}}function pe(v){var E=v._readableState;c("emitReadable",E.needReadable,E.emittedReadable),E.needReadable=!1,E.emittedReadable||(c("emitReadable",E.flowing),E.emittedReadable=!0,process.nextTick(de,v))}function de(v){var E=v._readableState;c("emitReadable_",E.destroyed,E.length,E.ended),!E.destroyed&&(E.length||E.ended)&&(v.emit("readable"),E.emittedReadable=!1),E.needReadable=!E.flowing&&!E.ended&&E.length<=E.highWaterMark,B(v)}function F(v,E){E.readingMore||(E.readingMore=!0,process.nextTick(X,v,E))}function X(v,E){for(;!E.reading&&!E.ended&&(E.length<E.highWaterMark||E.flowing&&E.length===0);){var D=E.length;if(c("maybeReadMore read 0"),v.read(0),D===E.length)break}E.readingMore=!1}C.prototype._read=function(v){I(this,new A("_read()"))},C.prototype.pipe=function(v,E){var D=this,K=this._readableState;switch(K.pipesCount){case 0:K.pipes=v;break;case 1:K.pipes=[K.pipes,v];break;default:K.pipes.push(v);break}K.pipesCount+=1,c("pipe count=%d opts=%j",K.pipesCount,E);var me=(!E||E.end!==!1)&&v!==process.stdout&&v!==process.stderr,ie=me?gt:$r;K.endEmitted?process.nextTick(ie):D.once("end",ie),v.on("unpipe",ye);function ye(b,l){c("onunpipe"),b===D&&l&&l.hasUnpiped===!1&&(l.hasUnpiped=!0,Ye())}function gt(){c("onend"),v.end()}var q=ne(D);v.on("drain",q);var Et=!1;function Ye(){c("cleanup"),v.removeListener("close",Ht),v.removeListener("finish",Tt),v.removeListener("drain",q),v.removeListener("error",Pt),v.removeListener("unpipe",ye),D.removeListener("end",gt),D.removeListener("end",$r),D.removeListener("data",qe),Et=!0,K.awaitDrain&&(!v._writableState||v._writableState.needDrain)&&q()}D.on("data",qe);function qe(b){c("ondata");var l=v.write(b);c("dest.write",l),l===!1&&((K.pipesCount===1&&K.pipes===v||K.pipesCount>1&&W(K.pipes,v)!==-1)&&!Et&&(c("false write response, pause",K.awaitDrain),K.awaitDrain++),D.pause())}function Pt(b){c("onerror",b),$r(),v.removeListener("error",Pt),t(v,"error")===0&&I(v,b)}H(v,"error",Pt);function Ht(){v.removeListener("finish",Tt),$r()}v.once("close",Ht);function Tt(){c("onfinish"),v.removeListener("close",Ht),$r()}v.once("finish",Tt);function $r(){c("unpipe"),D.unpipe(v)}return v.emit("pipe",D),K.flowing||(c("pipe resume"),D.resume()),v};function ne(v){return function(){var D=v._readableState;c("pipeOnDrain",D.awaitDrain),D.awaitDrain&&D.awaitDrain--,D.awaitDrain===0&&t(v,"data")&&(D.flowing=!0,B(v))}}C.prototype.unpipe=function(v){var E=this._readableState,D={hasUnpiped:!1};if(E.pipesCount===0)return this;if(E.pipesCount===1)return v&&v!==E.pipes?this:(v||(v=E.pipes),E.pipes=null,E.pipesCount=0,E.flowing=!1,v&&v.emit("unpipe",this,D),this);if(!v){var K=E.pipes,me=E.pipesCount;E.pipes=null,E.pipesCount=0,E.flowing=!1;for(var ie=0;ie<me;ie++)K[ie].emit("unpipe",this,{hasUnpiped:!1});return this}var ye=W(E.pipes,v);return ye===-1?this:(E.pipes.splice(ye,1),E.pipesCount-=1,E.pipesCount===1&&(E.pipes=E.pipes[0]),v.emit("unpipe",this,D),this)},C.prototype.on=function(v,E){var D=r.prototype.on.call(this,v,E),K=this._readableState;return v==="data"?(K.readableListening=this.listenerCount("readable")>0,K.flowing!==!1&&this.resume()):v==="readable"&&!K.endEmitted&&!K.readableListening&&(K.readableListening=K.needReadable=!0,K.flowing=!1,K.emittedReadable=!1,c("on readable",K.length,K.reading),K.length?pe(this):K.reading||process.nextTick(U,this)),D},C.prototype.addListener=C.prototype.on,C.prototype.removeListener=function(v,E){var D=r.prototype.removeListener.call(this,v,E);return v==="readable"&&process.nextTick(k,this),D},C.prototype.removeAllListeners=function(v){var E=r.prototype.removeAllListeners.apply(this,arguments);return(v==="readable"||v===void 0)&&process.nextTick(k,this),E};function k(v){var E=v._readableState;E.readableListening=v.listenerCount("readable")>0,E.resumeScheduled&&!E.paused?E.flowing=!0:v.listenerCount("data")>0&&v.resume()}function U(v){c("readable nexttick read 0"),v.read(0)}C.prototype.resume=function(){var v=this._readableState;return v.flowing||(c("resume"),v.flowing=!v.readableListening,j(this,v)),v.paused=!1,this};function j(v,E){E.resumeScheduled||(E.resumeScheduled=!0,process.nextTick(te,v,E))}function te(v,E){c("resume",E.reading),E.reading||v.read(0),E.resumeScheduled=!1,v.emit("resume"),B(v),E.flowing&&!E.reading&&v.read(0)}C.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 B(v){var E=v._readableState;for(c("flow",E.flowing);E.flowing&&v.read()!==null;);}C.prototype.wrap=function(v){var E=this,D=this._readableState,K=!1;v.on("end",function(){if(c("wrapped end"),D.decoder&&!D.ended){var ye=D.decoder.end();ye&&ye.length&&E.push(ye)}E.push(null)}),v.on("data",function(ye){if(c("wrapped data"),D.decoder&&(ye=D.decoder.write(ye)),!(D.objectMode&&ye==null)&&!(!D.objectMode&&(!ye||!ye.length))){var gt=E.push(ye);gt||(K=!0,v.pause())}});for(var me in v)this[me]===void 0&&typeof v[me]=="function"&&(this[me]=function(gt){return function(){return v[gt].apply(v,arguments)}}(me));for(var ie=0;ie<T.length;ie++)v.on(T[ie],this.emit.bind(this,T[ie]));return this._read=function(ye){c("wrapped _read",ye),K&&(K=!1,v.resume())},this},typeof Symbol=="function"&&(C.prototype[Symbol.asyncIterator]=function(){return w===void 0&&(w=c_()),w(this)}),Object.defineProperty(C.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(C.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(C.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(E){this._readableState&&(this._readableState.flowing=E)}}),C._fromList=O,Object.defineProperty(C.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function O(v,E){if(E.length===0)return null;var D;return E.objectMode?D=E.buffer.shift():!v||v>=E.length?(E.decoder?D=E.buffer.join(""):E.buffer.length===1?D=E.buffer.first():D=E.buffer.concat(E.length),E.buffer.clear()):D=E.buffer.consume(v,E.decoder),D}function $(v){var E=v._readableState;c("endReadable",E.endEmitted),E.endEmitted||(E.ended=!0,process.nextTick(V,E,v))}function V(v,E){if(c("endReadableNT",v.endEmitted,v.length),!v.endEmitted&&v.length===0&&(v.endEmitted=!0,E.readable=!1,E.emit("end"),v.autoDestroy)){var D=E._writableState;(!D||D.autoDestroy&&D.finished)&&E.destroy()}}typeof Symbol=="function"&&(C.from=function(v,E){return _===void 0&&(_=u_()),_(C,v,E)});function W(v,E){for(var D=0,K=v.length;D<K;D++)if(v[D]===E)return D;return-1}return la}var E0=yr,vs=sn.codes,f_=vs.ERR_METHOD_NOT_IMPLEMENTED,l_=vs.ERR_MULTIPLE_CALLBACK,d_=vs.ERR_TRANSFORM_ALREADY_TRANSFORMING,h_=vs.ERR_TRANSFORM_WITH_LENGTH_0,_s=Fn();Ke(yr,_s);function p_(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new l_);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 yr(e){if(!(this instanceof yr))return new yr(e);_s.call(this,e),this._transformState={afterTransform:p_.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",y_)}function y_(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){fl(e,t,r)}):fl(this,null,null)}yr.prototype.push=function(e,t){return this._transformState.needTransform=!1,_s.prototype.push.call(this,e,t)};yr.prototype._transform=function(e,t,r){r(new f_("_transform()"))};yr.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)}};yr.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};yr.prototype._destroy=function(e,t){_s.prototype._destroy.call(this,e,function(r){t(r)})};function fl(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new h_;if(e._transformState.transforming)throw new d_;return e.push(null)}var b_=ji,x0=E0;Ke(ji,x0);function ji(e){if(!(this instanceof ji))return new ji(e);x0.call(this,e)}ji.prototype._transform=function(e,t,r){r(null,e)};var da;function m_(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var A0=sn.codes,g_=A0.ERR_MISSING_ARGS,w_=A0.ERR_STREAM_DESTROYED;function ll(e){if(e)throw e}function v_(e){return e.setHeader&&typeof e.abort=="function"}function __(e,t,r,n){n=m_(n);var i=!1;e.on("close",function(){i=!0}),da===void 0&&(da=qu),da(e,{readable:t,writable:r},function(s){if(s)return n(s);i=!0,n()});var o=!1;return function(s){if(!i&&!o){if(o=!0,v_(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(s||new w_("pipe"))}}}function dl(e){e()}function E_(e,t){return e.pipe(t)}function x_(e){return!e.length||typeof e[e.length-1]!="function"?ll:e.pop()}function A_(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=x_(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new g_("streams");var i,o=t.map(function(s,a){var c=a<t.length-1,u=a>0;return __(s,c,u,function(f){i||(i=f),f&&o.forEach(dl),!c&&(o.forEach(dl),n(i))})});return t.reduce(E_)}var S_=A_;(function(e,t){t=e.exports=_0(),t.Stream=t,t.Readable=t,t.Writable=w0(),t.Duplex=Fn(),t.Transform=E0,t.PassThrough=b_,t.finished=qu,t.pipeline=S_})(zc,zc.exports);var S0=zc.exports,jo=mt.Buffer,P0=S0.Transform,P_=Ke;function T_(e,t){if(!jo.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Lr(e){P0.call(this),this._block=jo.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}P_(Lr,P0);Lr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Lr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Lr.prototype.update=function(e,t){if(T_(e,"Data"),this._finalized)throw new Error("Digest already called");jo.isBuffer(e)||(e=jo.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 o=0,s=e.length*8;s>0;++o)this._length[o]+=s,s=this._length[o]/4294967296|0,s>0&&(this._length[o]-=4294967296*s);return this};Lr.prototype._update=function(){throw new Error("_update is not implemented")};Lr.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};Lr.prototype._digest=function(){throw new Error("_digest is not implemented")};var I_=Lr,B_=Ke,T0=I_,k_=mt.Buffer,O_=new Array(16);function Es(){T0.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}B_(Es,T0);Es.prototype._update=function(){for(var e=O_,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,o=this._d;r=rt(r,n,i,o,e[0],3614090360,7),o=rt(o,r,n,i,e[1],3905402710,12),i=rt(i,o,r,n,e[2],606105819,17),n=rt(n,i,o,r,e[3],3250441966,22),r=rt(r,n,i,o,e[4],4118548399,7),o=rt(o,r,n,i,e[5],1200080426,12),i=rt(i,o,r,n,e[6],2821735955,17),n=rt(n,i,o,r,e[7],4249261313,22),r=rt(r,n,i,o,e[8],1770035416,7),o=rt(o,r,n,i,e[9],2336552879,12),i=rt(i,o,r,n,e[10],4294925233,17),n=rt(n,i,o,r,e[11],2304563134,22),r=rt(r,n,i,o,e[12],1804603682,7),o=rt(o,r,n,i,e[13],4254626195,12),i=rt(i,o,r,n,e[14],2792965006,17),n=rt(n,i,o,r,e[15],1236535329,22),r=nt(r,n,i,o,e[1],4129170786,5),o=nt(o,r,n,i,e[6],3225465664,9),i=nt(i,o,r,n,e[11],643717713,14),n=nt(n,i,o,r,e[0],3921069994,20),r=nt(r,n,i,o,e[5],3593408605,5),o=nt(o,r,n,i,e[10],38016083,9),i=nt(i,o,r,n,e[15],3634488961,14),n=nt(n,i,o,r,e[4],3889429448,20),r=nt(r,n,i,o,e[9],568446438,5),o=nt(o,r,n,i,e[14],3275163606,9),i=nt(i,o,r,n,e[3],4107603335,14),n=nt(n,i,o,r,e[8],1163531501,20),r=nt(r,n,i,o,e[13],2850285829,5),o=nt(o,r,n,i,e[2],4243563512,9),i=nt(i,o,r,n,e[7],1735328473,14),n=nt(n,i,o,r,e[12],2368359562,20),r=it(r,n,i,o,e[5],4294588738,4),o=it(o,r,n,i,e[8],2272392833,11),i=it(i,o,r,n,e[11],1839030562,16),n=it(n,i,o,r,e[14],4259657740,23),r=it(r,n,i,o,e[1],2763975236,4),o=it(o,r,n,i,e[4],1272893353,11),i=it(i,o,r,n,e[7],4139469664,16),n=it(n,i,o,r,e[10],3200236656,23),r=it(r,n,i,o,e[13],681279174,4),o=it(o,r,n,i,e[0],3936430074,11),i=it(i,o,r,n,e[3],3572445317,16),n=it(n,i,o,r,e[6],76029189,23),r=it(r,n,i,o,e[9],3654602809,4),o=it(o,r,n,i,e[12],3873151461,11),i=it(i,o,r,n,e[15],530742520,16),n=it(n,i,o,r,e[2],3299628645,23),r=ot(r,n,i,o,e[0],4096336452,6),o=ot(o,r,n,i,e[7],1126891415,10),i=ot(i,o,r,n,e[14],2878612391,15),n=ot(n,i,o,r,e[5],4237533241,21),r=ot(r,n,i,o,e[12],1700485571,6),o=ot(o,r,n,i,e[3],2399980690,10),i=ot(i,o,r,n,e[10],4293915773,15),n=ot(n,i,o,r,e[1],2240044497,21),r=ot(r,n,i,o,e[8],1873313359,6),o=ot(o,r,n,i,e[15],4264355552,10),i=ot(i,o,r,n,e[6],2734768916,15),n=ot(n,i,o,r,e[13],1309151649,21),r=ot(r,n,i,o,e[4],4149444226,6),o=ot(o,r,n,i,e[11],3174756917,10),i=ot(i,o,r,n,e[2],718787259,15),n=ot(n,i,o,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+o|0};Es.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=k_.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 xs(e,t){return e<<t|e>>>32-t}function rt(e,t,r,n,i,o,s){return xs(e+(t&r|~t&n)+i+o|0,s)+t|0}function nt(e,t,r,n,i,o,s){return xs(e+(t&n|r&~n)+i+o|0,s)+t|0}function it(e,t,r,n,i,o,s){return xs(e+(t^r^n)+i+o|0,s)+t|0}function ot(e,t,r,n,i,o,s){return xs(e+(r^(t|~n))+i+o|0,s)+t|0}var R_=Es,qo=mt.Buffer,I0=S0.Transform,C_=Ke;function F_(e,t){if(!qo.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Hr(e){I0.call(this),this._block=qo.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}C_(Hr,I0);Hr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Hr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Hr.prototype.update=function(e,t){if(F_(e,"Data"),this._finalized)throw new Error("Digest already called");qo.isBuffer(e)||(e=qo.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 o=0,s=e.length*8;s>0;++o)this._length[o]+=s,s=this._length[o]/4294967296|0,s>0&&(this._length[o]-=4294967296*s);return this};Hr.prototype._update=function(){throw new Error("_update is not implemented")};Hr.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};Hr.prototype._digest=function(){throw new Error("_digest is not implemented")};var N_=Hr,ha=Ut.Buffer,U_=Ke,B0=N_,L_=new Array(16),Zn=[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],Qn=[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],ei=[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],ti=[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],ri=[0,1518500249,1859775393,2400959708,2840853838],ni=[1352829926,1548603684,1836072691,2053994217,0];function As(){B0.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}U_(As,B0);As.prototype._update=function(){for(var e=L_,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,o=this._d|0,s=this._e|0,a=this._a|0,c=this._b|0,u=this._c|0,f=this._d|0,h=this._e|0,y=0;y<80;y+=1){var p,m;y<16?(p=hl(r,n,i,o,s,e[Zn[y]],ri[0],ei[y]),m=ml(a,c,u,f,h,e[Qn[y]],ni[0],ti[y])):y<32?(p=pl(r,n,i,o,s,e[Zn[y]],ri[1],ei[y]),m=bl(a,c,u,f,h,e[Qn[y]],ni[1],ti[y])):y<48?(p=yl(r,n,i,o,s,e[Zn[y]],ri[2],ei[y]),m=yl(a,c,u,f,h,e[Qn[y]],ni[2],ti[y])):y<64?(p=bl(r,n,i,o,s,e[Zn[y]],ri[3],ei[y]),m=pl(a,c,u,f,h,e[Qn[y]],ni[3],ti[y])):(p=ml(r,n,i,o,s,e[Zn[y]],ri[4],ei[y]),m=hl(a,c,u,f,h,e[Qn[y]],ni[4],ti[y])),r=s,s=o,o=rn(i,10),i=n,n=p,a=h,h=f,f=rn(u,10),u=c,c=m}var g=this._b+i+f|0;this._b=this._c+o+h|0,this._c=this._d+s+a|0,this._d=this._e+r+c|0,this._e=this._a+n+u|0,this._a=g};As.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=ha.alloc?ha.alloc(20):new ha(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 rn(e,t){return e<<t|e>>>32-t}function hl(e,t,r,n,i,o,s,a){return rn(e+(t^r^n)+o+s|0,a)+i|0}function pl(e,t,r,n,i,o,s,a){return rn(e+(t&r|~t&n)+o+s|0,a)+i|0}function yl(e,t,r,n,i,o,s,a){return rn(e+((t|~r)^n)+o+s|0,a)+i|0}function bl(e,t,r,n,i,o,s,a){return rn(e+(t&n|r&~n)+o+s|0,a)+i|0}function ml(e,t,r,n,i,o,s,a){return rn(e+(t^(r|~n))+o+s|0,a)+i|0}var H_=As,k0={exports:{}},O0=mt.Buffer;function Ss(e,t){this._block=O0.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}Ss.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=O0.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,o=this._len,s=0;s<i;){for(var a=o%n,c=Math.min(i-s,n-a),u=0;u<c;u++)r[a+u]=e[s+u];o+=c,s+=c,o%n===0&&this._update(r)}return this._len+=i,this};Ss.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 o=this._hash();return e?o.toString(e):o};Ss.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Gn=Ss,$_=Ke,R0=Gn,M_=mt.Buffer,D_=[1518500249,1859775393,-1894007588,-899497514],j_=new Array(80);function no(){this.init(),this._w=j_,R0.call(this,64,56)}$_(no,R0);no.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function q_(e){return e<<5|e>>>27}function G_(e){return e<<30|e>>>2}function z_(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}no.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=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 u=~~(c/20),f=q_(r)+z_(u,n,i,o)+s+t[c]+D_[u]|0;s=o,o=i,i=G_(n),n=r,r=f}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=s+this._e|0};no.prototype._hash=function(){var e=M_.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 V_=no,W_=Ke,C0=Gn,K_=mt.Buffer,Y_=[1518500249,1859775393,-1894007588,-899497514],X_=new Array(80);function io(){this.init(),this._w=X_,C0.call(this,64,56)}W_(io,C0);io.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function J_(e){return e<<1|e>>>31}function Z_(e){return e<<5|e>>>27}function Q_(e){return e<<30|e>>>2}function eE(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}io.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=J_(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var u=~~(c/20),f=Z_(r)+eE(u,n,i,o)+s+t[c]+Y_[u]|0;s=o,o=i,i=Q_(n),n=r,r=f}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=s+this._e|0};io.prototype._hash=function(){var e=K_.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 tE=io,rE=Ke,F0=Gn,nE=mt.Buffer,iE=[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],oE=new Array(64);function oo(){this.init(),this._w=oE,F0.call(this,64,56)}rE(oo,F0);oo.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 sE(e,t,r){return r^e&(t^r)}function aE(e,t,r){return e&t|r&(e|t)}function cE(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function uE(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function fE(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function lE(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}oo.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=this._e|0,a=this._f|0,c=this._g|0,u=this._h|0,f=0;f<16;++f)t[f]=e.readInt32BE(f*4);for(;f<64;++f)t[f]=lE(t[f-2])+t[f-7]+fE(t[f-15])+t[f-16]|0;for(var h=0;h<64;++h){var y=u+uE(s)+sE(s,a,c)+iE[h]+t[h]|0,p=cE(r)+aE(r,n,i)|0;u=c,c=a,a=s,s=o+y|0,o=i,i=n,n=r,r=y+p|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=s+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=u+this._h|0};oo.prototype._hash=function(){var e=nE.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 N0=oo,dE=Ke,hE=N0,pE=Gn,yE=mt.Buffer,bE=new Array(64);function Ps(){this.init(),this._w=bE,pE.call(this,64,56)}dE(Ps,hE);Ps.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};Ps.prototype._hash=function(){var e=yE.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 mE=Ps,gE=Ke,U0=Gn,wE=mt.Buffer,gl=[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],vE=new Array(160);function so(){this.init(),this._w=vE,U0.call(this,128,112)}gE(so,U0);so.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 wl(e,t,r){return r^e&(t^r)}function vl(e,t,r){return e&t|r&(e|t)}function _l(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function El(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function _E(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function EE(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function xE(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function AE(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Ge(e,t){return e>>>0<t>>>0?1:0}so.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,o=this._dh|0,s=this._eh|0,a=this._fh|0,c=this._gh|0,u=this._hh|0,f=this._al|0,h=this._bl|0,y=this._cl|0,p=this._dl|0,m=this._el|0,g=this._fl|0,A=this._gl|0,S=this._hl|0,P=0;P<32;P+=2)t[P]=e.readInt32BE(P*4),t[P+1]=e.readInt32BE(P*4+4);for(;P<160;P+=2){var w=t[P-30],_=t[P-15*2+1],I=_E(w,_),T=EE(_,w);w=t[P-2*2],_=t[P-2*2+1];var H=xE(w,_),M=AE(_,w),C=t[P-7*2],Y=t[P-7*2+1],J=t[P-16*2],re=t[P-16*2+1],ee=T+Y|0,Q=I+C+Ge(ee,T)|0;ee=ee+M|0,Q=Q+H+Ge(ee,M)|0,ee=ee+re|0,Q=Q+J+Ge(ee,re)|0,t[P]=Q,t[P+1]=ee}for(var ae=0;ae<160;ae+=2){Q=t[ae],ee=t[ae+1];var _e=vl(r,n,i),pe=vl(f,h,y),de=_l(r,f),F=_l(f,r),X=El(s,m),ne=El(m,s),k=gl[ae],U=gl[ae+1],j=wl(s,a,c),te=wl(m,g,A),B=S+ne|0,O=u+X+Ge(B,S)|0;B=B+te|0,O=O+j+Ge(B,te)|0,B=B+U|0,O=O+k+Ge(B,U)|0,B=B+ee|0,O=O+Q+Ge(B,ee)|0;var $=F+pe|0,V=de+_e+Ge($,F)|0;u=c,S=A,c=a,A=g,a=s,g=m,m=p+B|0,s=o+O+Ge(m,p)|0,o=i,p=y,i=n,y=h,n=r,h=f,f=B+$|0,r=O+V+Ge(f,B)|0}this._al=this._al+f|0,this._bl=this._bl+h|0,this._cl=this._cl+y|0,this._dl=this._dl+p|0,this._el=this._el+m|0,this._fl=this._fl+g|0,this._gl=this._gl+A|0,this._hl=this._hl+S|0,this._ah=this._ah+r+Ge(this._al,f)|0,this._bh=this._bh+n+Ge(this._bl,h)|0,this._ch=this._ch+i+Ge(this._cl,y)|0,this._dh=this._dh+o+Ge(this._dl,p)|0,this._eh=this._eh+s+Ge(this._el,m)|0,this._fh=this._fh+a+Ge(this._fl,g)|0,this._gh=this._gh+c+Ge(this._gl,A)|0,this._hh=this._hh+u+Ge(this._hl,S)|0};so.prototype._hash=function(){var e=wE.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 L0=so,SE=Ke,PE=L0,TE=Gn,IE=mt.Buffer,BE=new Array(160);function Ts(){this.init(),this._w=BE,TE.call(this,128,112)}SE(Ts,PE);Ts.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};Ts.prototype._hash=function(){var e=IE.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 kE=Ts,an=k0.exports=function(t){t=t.toLowerCase();var r=an[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};an.sha=V_;an.sha1=tE;an.sha224=mE;an.sha256=N0;an.sha384=kE;an.sha512=L0;var OE=k0.exports,Wt=mt.Buffer,H0=Du.Transform,RE=Do.StringDecoder,CE=Ke;function Lt(e){H0.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}CE(Lt,H0);var FE=typeof Uint8Array<"u",NE=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(Wt.prototype instanceof Uint8Array||Wt.TYPED_ARRAY_SUPPORT);function UE(e,t){if(e instanceof Wt)return e;if(typeof e=="string")return Wt.from(e,t);if(NE&&ArrayBuffer.isView(e)){if(e.byteLength===0)return Wt.alloc(0);var r=Wt.from(e.buffer,e.byteOffset,e.byteLength);if(r.byteLength===e.byteLength)return r}if(FE&&e instanceof Uint8Array||Wt.isBuffer(e)&&e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return Wt.from(e);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}Lt.prototype.update=function(e,t,r){var n=UE(e,t),i=this._update(n);return this.hashMode?this:(r&&(i=this._toString(i,r)),i)};Lt.prototype.setAutoPadding=function(){};Lt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Lt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Lt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Lt.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)}};Lt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Lt.prototype._finalOrDigest=function(e){var t=this.__final()||Wt.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Lt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new RE(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 LE=Lt,HE=Ke,$E=R_,ME=H_,DE=OE,$0=LE;function Is(e){$0.call(this,"digest"),this._hash=e}HE(Is,$0);Is.prototype._update=function(e){this._hash.update(e)};Is.prototype._final=function(){return this._hash.digest()};var jE=function(t){return t=t.toLowerCase(),t==="md5"?new $E:t==="rmd160"||t==="ripemd160"?new ME:new Is(DE(t))},So=mt.Buffer;function qE(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),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,a=e.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function f(p){if((Array.isArray(p)||p instanceof Uint8Array)&&(p=So.from(p)),!So.isBuffer(p))throw new TypeError("Expected Buffer");if(p.length===0)return"";for(var m=0,g=0,A=0,S=p.length;A!==S&&p[A]===0;)A++,m++;for(var P=(S-A)*u+1>>>0,w=new Uint8Array(P);A!==S;){for(var _=p[A],I=0,T=P-1;(_!==0||I<g)&&T!==-1;T--,I++)_+=256*w[T]>>>0,w[T]=_%s>>>0,_=_/s>>>0;if(_!==0)throw new Error("Non-zero carry");g=I,A++}for(var H=P-g;H!==P&&w[H]===0;)H++;for(var M=a.repeat(m);H<P;++H)M+=e.charAt(w[H]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return So.alloc(0);for(var m=0,g=0,A=0;p[m]===a;)g++,m++;for(var S=(p.length-m)*c+1>>>0,P=new Uint8Array(S);m<p.length;){var w=p.charCodeAt(m);if(w>255)return;var _=t[w];if(_===255)return;for(var I=0,T=S-1;(_!==0||I<A)&&T!==-1;T--,I++)_+=s*P[T]>>>0,P[T]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=I,m++}for(var H=S-A;H!==S&&P[H]===0;)H++;var M=So.allocUnsafe(g+(S-H));M.fill(0,0,g);for(var C=g;H!==S;)M[C++]=P[H++];return M}function y(p){var m=h(p);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:f,decodeUnsafe:h,decode:y}}var M0=qE,GE=M0,zE="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",VE=GE(zE),pa=VE,WE=mt.Buffer,KE=function(e){function t(o){var s=e(o);return pa.encode(WE.concat([o,s],o.length+4))}function r(o){var s=o.slice(0,-4),a=o.slice(-4),c=e(s);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return s}function n(o){var s=pa.decodeUnsafe(o);if(s)return r(s)}function i(o){var s=pa.decode(o),a=r(s);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},xl=jE,YE=KE;function XE(e){var t=xl("sha256").update(e).digest();return xl("sha256").update(t).digest()}var JE=YE(XE),Wc=JE;function D0(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 Kc(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 ZE(e,t){return D0(Wc.decode(e),t)}function QE(e,t,r){return typeof e=="number"?Wc.encode(Kc(e,t,r)):Wc.encode(Kc(e.version,e.privateKey,e.compressed))}var ex={decode:ZE,decodeRaw:D0,encode:QE,encodeRaw:Kc},Bs={};Object.defineProperty(Bs,"__esModule",{value:!0});Bs.testEcc=void 0;const oe=e=>Buffer.from(e,"hex");function tx(e){Be(e.isPoint(oe("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Be(!e.isPoint(oe("030000000000000000000000000000000000000000000000000000000000000005"))),Be(e.isPrivate(oe("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Be(e.isPrivate(oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),Be(!e.isPrivate(oe("0000000000000000000000000000000000000000000000000000000000000000"))),Be(!e.isPrivate(oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),Be(!e.isPrivate(oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),Be(Buffer.from(e.privateAdd(oe("0000000000000000000000000000000000000000000000000000000000000001"),oe("0000000000000000000000000000000000000000000000000000000000000000"))).equals(oe("0000000000000000000000000000000000000000000000000000000000000001"))),Be(e.privateAdd(oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),oe("0000000000000000000000000000000000000000000000000000000000000003"))===null),Be(Buffer.from(e.privateAdd(oe("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),oe("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(oe("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),Be(Buffer.from(e.privateNegate(oe("0000000000000000000000000000000000000000000000000000000000000001"))).equals(oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),Be(Buffer.from(e.privateNegate(oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(oe("0000000000000000000000000000000000000000000000000000000000000003"))),Be(Buffer.from(e.privateNegate(oe("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(oe("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),Be(Buffer.from(e.pointCompress(oe("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(oe("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Be(Buffer.from(e.pointCompress(oe("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(oe("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),Be(Buffer.from(e.pointCompress(oe("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(oe("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Be(Buffer.from(e.pointCompress(oe("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(oe("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),Be(Buffer.from(e.pointFromScalar(oe("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(oe("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),Be(e.xOnlyPointAddTweak(oe("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(oe("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),oe("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));Be(Buffer.from(t.xOnlyPubkey).equals(oe("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(oe("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),oe("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),Be(Buffer.from(t.xOnlyPubkey).equals(oe("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),Be(Buffer.from(e.sign(oe("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),oe("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(oe("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),Be(e.verify(oe("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),oe("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),oe("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&Be(Buffer.from(e.signSchnorr(oe("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),oe("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),oe("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(oe("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&Be(e.verifySchnorr(oe("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),oe("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),oe("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}Bs.testEcc=tx;function Be(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(Rn,"__esModule",{value:!0});Rn.ECPairFactory=Rn.networks=void 0;const Yc=Cn;Rn.networks=Yc;const dt=o0,rx=Av,Al=ex,nx=Bs,ya=dt.typeforce.maybe(dt.typeforce.compile({compressed:dt.maybe(dt.Boolean),network:dt.maybe(dt.Network)})),ix=e=>e.length===32?e:e.slice(1,33);function ox(e){(0,nx.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(dt.typeforce(dt.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return dt.typeforce(ya,c),new s(a,void 0,c)}function n(a,c){return dt.typeforce(e.isPoint,a),dt.typeforce(ya,c),new s(void 0,a,c)}function i(a,c){const u=Al.decode(a),f=u.version;if(dt.Array(c)){if(c=c.filter(h=>f===h.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||Yc.bitcoin,f!==c.wif)throw new Error("Invalid network version");return r(u.privateKey,{compressed:u.compressed,network:c})}function o(a){dt.typeforce(ya,a),a===void 0&&(a={});const c=a.rng||rx;let u;do u=c(32),dt.typeforce(dt.Buffer256bit,u);while(!e.isPrivate(u));return r(u,a)}class s{constructor(c,u,f){cn(this,"__D");cn(this,"__Q");cn(this,"compressed");cn(this,"network");cn(this,"lowR");this.__D=c,this.__Q=u,this.lowR=!1,f===void 0&&(f={}),this.compressed=f.compressed===void 0?!0:f.compressed,this.network=f.network||Yc.bitcoin,u!==void 0&&(this.__Q=Buffer.from(e.pointCompress(u,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 Al.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,u){if(!this.__D)throw new Error("Missing private key");if(u===void 0&&(u=this.lowR),u===!1)return Buffer.from(e.sign(c,this.__D));{let f=e.sign(c,this.__D);const h=Buffer.alloc(32,0);let y=0;for(;f[0]>127;)y++,h.writeUIntLE(y,0,6),f=e.sign(c,this.__D,h);return Buffer.from(f)}}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,u){return e.verify(c,this.publicKey,u)}verifySchnorr(c,u){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),u)}tweakFromPublicKey(c){const u=ix(this.publicKey),f=e.xOnlyPointAddTweak(u,c);if(!f||f.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const h=Buffer.from([f.parity===0?2:3]);return n(Buffer.concat([h,f.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const f=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,h=e.privateAdd(f,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:o}}Rn.ECPairFactory=ox;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=Rn;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}})})(i0);const sx=N1(i0);class qi extends Z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new qi(N.trim0x(t))}static fromWalletClient(t){return new qi(void 0,t)}async initialize(){if(this.digestKey)return N.Ok("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?N.Err(t.error):(this.emit("initialized",!0),N.Ok("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return N.Err("No walletClient found");if(!this.walletClient.account)return N.Err("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.digestKey=N.trim0x(si(t)),this.emit("initialized",!0),N.Ok(this.digestKey)}catch(t){return N.Err("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return N.Err("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return N.Err(t.error)}return this.digestKey?N.Ok(this.digestKey):N.Err("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return N.Err(r.error);const n=si(Z.with0x(r.val)),i=si(n);return N.Ok({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const u=await this.getDigestKey();if(u.error)return N.Err(u.error);this.digestKey=u.val}const r=sx(Kr),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),o=si(i),s=Buffer.from(N.trim0x(this.digestKey),"hex");if(s.length!==32)return N.Err("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(s).sign(Buffer.from(N.trim0x(o),"hex"));return N.Ok(c.toString("hex"))}}const Sl=[{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"}],ax={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},cx={block:sg({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=pu(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?kt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:ig({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?kt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:i1({format(e){return{l1GasPrice:e.l1GasPrice?kt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?kt(e.l1GasUsed):null,l1Fee:e.l1Fee?kt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function ux(e,t){return dx(e)?lx(e):I1(e,t)}const fx={transaction:ux};function lx(e){hx(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:o,mint:s,to:a,value:c}=e,u=[t,n,a??"0x",s?ue(s):"0x",c?ue(c):"0x",i?ue(i):"0x",o?"0x1":"0x",r??"0x"];return Jt(["0x7e",Cr(u)])}function dx(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function hx(e){const{from:t,to:r}=e;if(t&&!ze(t))throw new bt({address:t});if(r&&!ze(r))throw new bt({address:r})}const Go={contracts:ax,formatters:cx,serializers:fx},px=Zt({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}}}),yx=Zt({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}),ii=1,bx=Zt({...Go,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:{...Go.contracts,disputeGameFactory:{[ii]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[ii]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[ii]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[ii]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:ii}),oi=11155111,mx=Zt({...Go,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:{...Go.contracts,disputeGameFactory:{[oi]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[oi]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[oi]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[oi]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:oi}),gx=Zt({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}),wx=Zt({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}),vx=Zt({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}),_x=Zt({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}}}),Ex=Zt({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}),xx=Zt({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}),Ax={...xx,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},j0={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"]}}},q0={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"]}}},G0={ethereum:_x,arbitrum:px,ethereum_sepolia:Ax,arbitrum_sepolia:yx,ethereum_localnet:we.EthereumLocalnet,arbitrum_localnet:we.ArbitrumLocalnet,base_sepolia:mx,base:bx,bera_testnet:wx,citrea_testnet:vx,bera:gx,monad_testnet:Ex,hyperliquid_testnet:j0,hyperliquid:q0},z0=async(e,t)=>{var n,i,o,s;const r=G0[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return N.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const a=zs({account:t.account,chain:r,transport:xf(t.transport)});return N.Ok({message:"Switched chain",walletClient:a})}catch(a){if(Sx(a))if(a.code===4902)try{await t.addChain({chain:r});const c=zs({account:t.account,chain:r,transport:xf(t.transport)});return N.Ok({message:"Added network",walletClient:c})}catch{return N.Err("Failed to add network")}else if((o=(i=a.body)==null?void 0:i.method)!=null&&o.includes("wallet_switchEthereumChain")||(s=a.message)!=null&&s.includes("wallet_switchEthereumChain")){const c=zs({account:t.account,chain:r,transport:b1()});return N.Ok({message:"Added network",walletClient:c})}else return N.Err("Failed to switch network");else return N.Err("Failed to switch network")}else return N.Err("Chain not supported")},Sx=e=>typeof e=="object"&&e!=null&&("code"in e||"message"in e||"body"in e),Px=[{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 V0{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(!we.isEVM(t.source_swap.chain))return Z.Err("Source chain is not an EVM chain");const r=await z0(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 o=Z.with0x(n.secret_hash),s=BigInt(n.timelock),a=Z.with0x(i.redeemer),c=BigInt(i.amount),u=await this.getTokenAddress(t.source_swap.asset);return u.ok?we.isEvmNativeToken(t.source_swap.chain,u.val)?(console.log("Calling initiate on native htlc"),this._initiateOnNativeHTLC(o,s,c,a,t.source_swap.asset)):(console.log("Calling initiate on ERC 20 htlc"),this._initiateOnErc20HTLC(o,s,c,a,t.source_swap.asset,u.val,n.create_id)):Z.Err(u.error)}async getTokenAddress(t){try{const n=await js({address:Z.with0x(t),abi:Sl,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,o){if(!this.wallet.account)return Z.Err("No account found");try{const a=await js({address:Z.with0x(o),abi:Px,client:this.wallet}).write.initiate([i,r,n,t],{account:this.wallet.account,chain:this.wallet.chain,value:n});return Z.Ok(a)}catch(s){return Z.Err("Failed to initiate on native HTLC",String(s))}}async _initiateOnErc20HTLC(t,r,n,i,o,s,a){if(!this.wallet.account)return Z.Err("No account found");try{const c=await this.auth.getAuthHeaders();if(console.log("header in _initateOnERC20::",c.val),c.error)return Z.Err(c.error);const u=js({address:Z.with0x(o),abi:Sl,client:this.wallet}),f=await Z.checkAllowanceAndApprove(Number(n),s,o,this.wallet);if(f.error)return Z.Err(f.error);const h=await u.read.eip712Domain(),y=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"},m=await N.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:a,signature:y,perform_on:"Source"}),headers:p});return m.error?(console.log("Error in initiating",m.error),Z.Err(m.error)):m.result?Z.Ok(m.result):Z.Err("Init: No result found")}catch(c){return console.log("catch 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 N.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:N.trim0x(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 W0=[{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"}]}],Tx=async(e,t,r,n,i)=>{try{const o=await Xc(e.address,t,r,i);if(o.error)return N.Err(o.error);const s=De.cairo.uint256(BigInt(De.uint256.UINT_256_MAX));if(o.val<n){const a=await e.execute([{contractAddress:N.with0x(t),entrypoint:"approve",calldata:[r,s.low,s.high]}]);await i.waitForTransaction(a.transaction_hash,{retryInterval:3e3,successStates:[De.TransactionExecutionStatus.SUCCEEDED]}),await Z.sleep(2e3);let c=0n;for(let u=0;u<20;u++){const f=await Xc(e.address,t,r,i);if(f.error)return N.Err(f.error);if(c=f.val,c>=n)break;await Z.sleep(2e3)}return c<n?N.Err("Allowance not approved"):N.Ok(a.transaction_hash)}return N.Ok("Allowance already approved")}catch(o){return N.Err(`Failed to check or approve allowance: ${o instanceof Error?o.message:String(o)}`)}},Xc=async(e,t,r,n)=>{try{const o=await new De.Contract(W0,N.with0x(t),n).call("allowance",[N.with0x(e),N.with0x(r)]);return N.Ok(BigInt((o==null?void 0:o.toString())||"0"))}catch(i){return N.Err(`Failed to check allowance: ${i instanceof Error?i.message:String(i)}`)}},Ix=async(e,t,r,n,i)=>{const o=await Xc(e,t,r,n);return o.error?N.Err(o.error):N.Ok(o.val>=i)},K0=[{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"}]}],Bx={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 Y0{constructor(t,r,n,i){this.url=t instanceof Z.Url?t:new Z.Url(t),this.account=r,this.starknetProvider=new De.RpcProvider({nodeUrl:i||Hi[n].nodeUrl}),this.chainId=Hi[n].chainId}get htlcActorAddress(){if(!this.account.address)throw new Error("No account found");return this.account.address}async initiate(t){if(!this.account.address)return N.Err("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:o}=n;if(!o||!i||!r.secret_hash||!r.timelock)return N.Err("Invalid order");try{const s=new De.Contract(K0,t.source_swap.asset,this.account),a=await(s==null?void 0:s.token()),c=De.num.toHex(a),u=await Ix(this.account.address,c,n.asset,this.starknetProvider,BigInt(o));return u.error?N.Err(u.error):u.val?this.initiateRelay(t):this.approveAndInitiate(c,t)}catch(s){return N.Err(String(s))}}async approveAndInitiate(t,r){const{create_order:n,source_swap:i}=r,{redeemer:o,amount:s}=i,{secret_hash:a,timelock:c}=n,u=i.asset;try{const f=De.cairo.uint256(BigInt(De.uint256.UINT_256_MAX)),h={contractAddress:N.with0x(t),entrypoint:"approve",calldata:[u,f.low,f.high]},y=De.cairo.uint256(s),p={contractAddress:N.with0x(u),entrypoint:"initiate",calldata:[o,c.toString(),y.low.toString(),y.high.toString(),...Z.hexToU32Array(a)]},m=await this.account.execute([h,p]);return await this.starknetProvider.waitForTransaction(m.transaction_hash,{retryInterval:2e3,successStates:[De.TransactionExecutionStatus.SUCCEEDED]}),N.Ok(m.transaction_hash)}catch(f){return N.Err(`Failed to approve and initiate: ${String(f)}`)}}async initiateRelay(t){const{create_order:r,source_swap:n}=t,{redeemer:i,amount:o}=n,a={domain:{name:"HTLC",version:De.shortString.encodeShortString("1"),chainId:this.chainId,revision:De.TypedDataRevision.ACTIVE},primaryType:"Initiate",types:Bx,message:{redeemer:i,amount:De.cairo.uint256(o),timelock:r.timelock,secretHash:Z.hexToU32Array(r.secret_hash)}};try{const c=await this.account.signMessage(a),u=Ew(c);if(u.error)return N.Err(u.error);const f=await N.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:u.val,perform_on:"Source"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return f.error?N.Err(f.error):f.result?N.Ok(f.result):N.Err("Init: No result found")}catch(c){return N.Err(`Failed to initiate relayer: ${String(c)}`)}}async redeem(t,r){try{const n=await N.Fetcher.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?N.Err(n.error):n.result?N.Ok(n.result):N.Err("Redeem: No result found")}catch(n){return N.Err(String(n))}}async refund(){return N.Err("Refund is taken care of by the relayer")}}const kx="6eksgdCnSjUaGQWZ6iYvauv1qzvYPF33RTGTM1ZuyENx",Ox={name:"solana_native_swaps",version:"0.2.0",spec:"0.1.0",description:"Created with Anchor"},Rx=[{name:"initiate",discriminator:[5,63,123,113,153,75,148,14],accounts:[{name:"swap_account",writable:!0,pda:{seeds:[{kind:"const",value:[115,119,97,112,95,97,99,99,111,117,110,116]},{kind:"arg",path:"secret_hash"}]}},{name:"initiator",docs:["Initiator must sign this transaction."],writable:!0,signer:!0},{name:"system_program",address:"11111111111111111111111111111111"}],args:[{name:"amount_lamports",type:"u64"},{name:"expires_in_slots",type:"u64"},{name:"redeemer",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]},{name:"instant_refund",discriminator:[211,202,103,41,183,147,59,251],accounts:[{name:"swap_account",writable:!0},{name:"initiator",writable:!0},{name:"redeemer",docs:["Redeemer must sign this transaction."],signer:!0}],args:[]},{name:"redeem",discriminator:[184,12,86,149,70,196,97,225],accounts:[{name:"swap_account",writable:!0},{name:"redeemer",writable:!0}],args:[{name:"secret",type:{array:["u8",32]}}]},{name:"refund",discriminator:[2,96,183,251,63,208,46,46],accounts:[{name:"swap_account",writable:!0},{name:"refundee",writable:!0}],args:[]}],Cx=[{name:"SwapAccount",discriminator:[53,126,9,14,14,197,105,182]}],Fx=[{name:"Initiated",discriminator:[6,108,212,91,67,60,207,221]},{name:"InstantRefunded",discriminator:[220,50,18,207,183,232,218,25]},{name:"Redeemed",discriminator:[14,29,183,71,31,165,107,38]},{name:"Refunded",discriminator:[35,103,149,246,196,123,221,99]}],Nx=[{code:6e3,name:"InvalidRedeemer",msg:"The provided redeemer is not the intended recipient of the swap amount"},{code:6001,name:"InvalidRefundee",msg:"The provided refundee is not the initiator of the given swap account"},{code:6002,name:"InvalidSecret",msg:"The provided secret does not correspond to the secret hash in the PDA"},{code:6003,name:"RefundBeforeExpiry",msg:"Attempt to perform a refund before expiry time"}],Ux=[{name:"Initiated",type:{kind:"struct",fields:[{name:"amount_lamports",type:"u64"},{name:"expires_in_slots",type:"u64"},{name:"initiator",type:"pubkey"},{name:"redeemer",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]}},{name:"InstantRefunded",type:{kind:"struct",fields:[{name:"secret_hash",type:{array:["u8",32]}}]}},{name:"Redeemed",type:{kind:"struct",fields:[{name:"secret",type:{array:["u8",32]}}]}},{name:"Refunded",type:{kind:"struct",fields:[{name:"secret_hash",type:{array:["u8",32]}}]}},{name:"SwapAccount",type:{kind:"struct",fields:[{name:"amount_lamports",type:"u64"},{name:"expiry_slot",type:"u64"},{name:"initiator",type:"pubkey"},{name:"redeemer",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]}}],Lx={address:kx,metadata:Ox,instructions:Rx,accounts:Cx,events:Fx,errors:Nx,types:Ux};var ar={},Nn={};Object.defineProperty(Nn,"__esModule",{value:!0});Nn.decode=Nn.encode=void 0;const Pl=Ut;function Hx(e){return e.reduce((t,r)=>t+r.toString(16).padStart(2,"0"),"0x")}Nn.encode=Hx;function $x(e){e.indexOf("0x")===0&&(e=e.substr(2)),e.length%2===1&&(e="0"+e);let t=e.match(/.{2}/g);return t===null?Pl.Buffer.from([]):Pl.Buffer.from(t.map(r=>parseInt(r,16)))}Nn.decode=$x;var Un={},Rr={},ba;Object.defineProperty(Rr,"__esModule",{value:!0});Rr.isVersionedTransaction=Rr.chunks=Rr.isBrowser=void 0;Rr.isBrowser=process.env.ANCHOR_BROWSER||typeof window<"u"&&!(!((ba=window.process)===null||ba===void 0)&&ba.hasOwnProperty("type"));function Mx(e,t){return Array.apply(0,new Array(Math.ceil(e.length/t))).map((r,n)=>e.slice(n*t,(n+1)*t))}Rr.chunks=Mx;const Dx=e=>"version"in e;Rr.isVersionedTransaction=Dx;var ma={},ga={},wa,Tl;function X0(){return Tl||(Tl=1,wa=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},r=Symbol("test"),n=Object(r);if(typeof r=="string"||Object.prototype.toString.call(r)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var i=42;t[r]=i;for(var o in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var s=Object.getOwnPropertySymbols(t);if(s.length!==1||s[0]!==r||!Object.prototype.propertyIsEnumerable.call(t,r))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var a=Object.getOwnPropertyDescriptor(t,r);if(a.value!==i||a.enumerable!==!0)return!1}return!0}),wa}var va,Il;function ks(){if(Il)return va;Il=1;var e=X0();return va=function(){return e()&&!!Symbol.toStringTag},va}var _a,Bl;function J0(){return Bl||(Bl=1,_a=Object),_a}var Ea,kl;function jx(){return kl||(kl=1,Ea=Error),Ea}var xa,Ol;function qx(){return Ol||(Ol=1,xa=EvalError),xa}var Aa,Rl;function Gx(){return Rl||(Rl=1,Aa=RangeError),Aa}var Sa,Cl;function zx(){return Cl||(Cl=1,Sa=ReferenceError),Sa}var Pa,Fl;function Z0(){return Fl||(Fl=1,Pa=SyntaxError),Pa}var Ta,Nl;function ao(){return Nl||(Nl=1,Ta=TypeError),Ta}var Ia,Ul;function Vx(){return Ul||(Ul=1,Ia=URIError),Ia}var Ba,Ll;function Wx(){return Ll||(Ll=1,Ba=Math.abs),Ba}var ka,Hl;function Kx(){return Hl||(Hl=1,ka=Math.floor),ka}var Oa,$l;function Yx(){return $l||($l=1,Oa=Math.max),Oa}var Ra,Ml;function Xx(){return Ml||(Ml=1,Ra=Math.min),Ra}var Ca,Dl;function Jx(){return Dl||(Dl=1,Ca=Math.pow),Ca}var Fa,jl;function Zx(){return jl||(jl=1,Fa=Math.round),Fa}var Na,ql;function Qx(){return ql||(ql=1,Na=Number.isNaN||function(t){return t!==t}),Na}var Ua,Gl;function e6(){if(Gl)return Ua;Gl=1;var e=Qx();return Ua=function(r){return e(r)||r===0?r:r<0?-1:1},Ua}var La,zl;function t6(){return zl||(zl=1,La=Object.getOwnPropertyDescriptor),La}var Ha,Vl;function zn(){if(Vl)return Ha;Vl=1;var e=t6();if(e)try{e([],"length")}catch{e=null}return Ha=e,Ha}var $a,Wl;function Os(){if(Wl)return $a;Wl=1;var e=Object.defineProperty||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return $a=e,$a}var Ma,Kl;function r6(){if(Kl)return Ma;Kl=1;var e=typeof Symbol<"u"&&Symbol,t=X0();return Ma=function(){return typeof e!="function"||typeof Symbol!="function"||typeof e("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},Ma}var Da,Yl;function Q0(){return Yl||(Yl=1,Da=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),Da}var ja,Xl;function ey(){if(Xl)return ja;Xl=1;var e=J0();return ja=e.getPrototypeOf||null,ja}var qa,Jl;function n6(){if(Jl)return qa;Jl=1;var e="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,r=Math.max,n="[object Function]",i=function(c,u){for(var f=[],h=0;h<c.length;h+=1)f[h]=c[h];for(var y=0;y<u.length;y+=1)f[y+c.length]=u[y];return f},o=function(c,u){for(var f=[],h=u,y=0;h<c.length;h+=1,y+=1)f[y]=c[h];return f},s=function(a,c){for(var u="",f=0;f<a.length;f+=1)u+=a[f],f+1<a.length&&(u+=c);return u};return qa=function(c){var u=this;if(typeof u!="function"||t.apply(u)!==n)throw new TypeError(e+u);for(var f=o(arguments,1),h,y=function(){if(this instanceof h){var S=u.apply(this,i(f,arguments));return Object(S)===S?S:this}return u.apply(c,i(f,arguments))},p=r(0,u.length-f.length),m=[],g=0;g<p;g++)m[g]="$"+g;if(h=Function("binder","return function ("+s(m,",")+"){ return binder.apply(this,arguments); }")(y),u.prototype){var A=function(){};A.prototype=u.prototype,h.prototype=new A,A.prototype=null}return h},qa}var Ga,Zl;function co(){if(Zl)return Ga;Zl=1;var e=n6();return Ga=Function.prototype.bind||e,Ga}var za,Ql;function Gu(){return Ql||(Ql=1,za=Function.prototype.call),za}var Va,ed;function zu(){return ed||(ed=1,Va=Function.prototype.apply),Va}var Wa,td;function i6(){return td||(td=1,Wa=typeof Reflect<"u"&&Reflect&&Reflect.apply),Wa}var Ka,rd;function ty(){if(rd)return Ka;rd=1;var e=co(),t=zu(),r=Gu(),n=i6();return Ka=n||e.call(r,t),Ka}var Ya,nd;function Vu(){if(nd)return Ya;nd=1;var e=co(),t=ao(),r=Gu(),n=ty();return Ya=function(o){if(o.length<1||typeof o[0]!="function")throw new t("a function is required");return n(e,r,o)},Ya}var Xa,id;function o6(){if(id)return Xa;id=1;var e=Vu(),t=zn(),r;try{r=[].__proto__===Array.prototype}catch(s){if(!s||typeof s!="object"||!("code"in s)||s.code!=="ERR_PROTO_ACCESS")throw s}var n=!!r&&t&&t(Object.prototype,"__proto__"),i=Object,o=i.getPrototypeOf;return Xa=n&&typeof n.get=="function"?e([n.get]):typeof o=="function"?function(a){return o(a==null?a:i(a))}:!1,Xa}var Ja,od;function Wu(){if(od)return Ja;od=1;var e=Q0(),t=ey(),r=o6();return Ja=e?function(i){return e(i)}:t?function(i){if(!i||typeof i!="object"&&typeof i!="function")throw new TypeError("getProto: not an object");return t(i)}:r?function(i){return r(i)}:null,Ja}var Za,sd;function ry(){if(sd)return Za;sd=1;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=co();return Za=r.call(e,t),Za}var Qa,ad;function ny(){if(ad)return Qa;ad=1;var e,t=J0(),r=jx(),n=qx(),i=Gx(),o=zx(),s=Z0(),a=ao(),c=Vx(),u=Wx(),f=Kx(),h=Yx(),y=Xx(),p=Jx(),m=Zx(),g=e6(),A=Function,S=function(V){try{return A('"use strict"; return ('+V+").constructor;")()}catch{}},P=zn(),w=Os(),_=function(){throw new a},I=P?function(){try{return arguments.callee,_}catch{try{return P(arguments,"callee").get}catch{return _}}}():_,T=r6()(),H=Wu(),M=ey(),C=Q0(),Y=zu(),J=Gu(),re={},ee=typeof Uint8Array>"u"||!H?e:H(Uint8Array),Q={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":T&&H?H([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":re,"%AsyncGenerator%":re,"%AsyncGeneratorFunction%":re,"%AsyncIteratorPrototype%":re,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":r,"%eval%":eval,"%EvalError%":n,"%Float16Array%":typeof Float16Array>"u"?e:Float16Array,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":A,"%GeneratorFunction%":re,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":T&&H?H(H([][Symbol.iterator]())):e,"%JSON%":typeof JSON=="object"?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!T||!H?e:H(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":t,"%Object.getOwnPropertyDescriptor%":P,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":i,"%ReferenceError%":o,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!T||!H?e:H(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":T&&H?H(""[Symbol.iterator]()):e,"%Symbol%":T?Symbol:e,"%SyntaxError%":s,"%ThrowTypeError%":I,"%TypedArray%":ee,"%TypeError%":a,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":c,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet,"%Function.prototype.call%":J,"%Function.prototype.apply%":Y,"%Object.defineProperty%":w,"%Object.getPrototypeOf%":M,"%Math.abs%":u,"%Math.floor%":f,"%Math.max%":h,"%Math.min%":y,"%Math.pow%":p,"%Math.round%":m,"%Math.sign%":g,"%Reflect.getPrototypeOf%":C};if(H)try{null.error}catch(V){var ae=H(H(V));Q["%Error.prototype%"]=ae}var _e=function V(W){var v;if(W==="%AsyncFunction%")v=S("async function () {}");else if(W==="%GeneratorFunction%")v=S("function* () {}");else if(W==="%AsyncGeneratorFunction%")v=S("async function* () {}");else if(W==="%AsyncGenerator%"){var E=V("%AsyncGeneratorFunction%");E&&(v=E.prototype)}else if(W==="%AsyncIteratorPrototype%"){var D=V("%AsyncGenerator%");D&&H&&(v=H(D.prototype))}return Q[W]=v,v},pe={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},de=co(),F=ry(),X=de.call(J,Array.prototype.concat),ne=de.call(Y,Array.prototype.splice),k=de.call(J,String.prototype.replace),U=de.call(J,String.prototype.slice),j=de.call(J,RegExp.prototype.exec),te=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,B=/\\(\\)?/g,O=function(W){var v=U(W,0,1),E=U(W,-1);if(v==="%"&&E!=="%")throw new s("invalid intrinsic syntax, expected closing `%`");if(E==="%"&&v!=="%")throw new s("invalid intrinsic syntax, expected opening `%`");var D=[];return k(W,te,function(K,me,ie,ye){D[D.length]=ie?k(ye,B,"$1"):me||K}),D},$=function(W,v){var E=W,D;if(F(pe,E)&&(D=pe[E],E="%"+D[0]+"%"),F(Q,E)){var K=Q[E];if(K===re&&(K=_e(E)),typeof K>"u"&&!v)throw new a("intrinsic "+W+" exists, but is not available. Please file an issue!");return{alias:D,name:E,value:K}}throw new s("intrinsic "+W+" does not exist!")};return Qa=function(W,v){if(typeof W!="string"||W.length===0)throw new a("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof v!="boolean")throw new a('"allowMissing" argument must be a boolean');if(j(/^%?[^%]*%?$/,W)===null)throw new s("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var E=O(W),D=E.length>0?E[0]:"",K=$("%"+D+"%",v),me=K.name,ie=K.value,ye=!1,gt=K.alias;gt&&(D=gt[0],ne(E,X([0,1],gt)));for(var q=1,Et=!0;q<E.length;q+=1){var Ye=E[q],qe=U(Ye,0,1),Pt=U(Ye,-1);if((qe==='"'||qe==="'"||qe==="`"||Pt==='"'||Pt==="'"||Pt==="`")&&qe!==Pt)throw new s("property names with quotes must have matching quotes");if((Ye==="constructor"||!Et)&&(ye=!0),D+="."+Ye,me="%"+D+"%",F(Q,me))ie=Q[me];else if(ie!=null){if(!(Ye in ie)){if(!v)throw new a("base intrinsic for "+W+" exists, but the property is not available.");return}if(P&&q+1>=E.length){var Ht=P(ie,Ye);Et=!!Ht,Et&&"get"in Ht&&!("originalValue"in Ht.get)?ie=Ht.get:ie=ie[Ye]}else Et=F(ie,Ye),ie=ie[Ye];Et&&!ye&&(Q[me]=ie)}}return ie},Qa}var ec,cd;function uo(){if(cd)return ec;cd=1;var e=ny(),t=Vu(),r=t([e("%String.prototype.indexOf%")]);return ec=function(i,o){var s=e(i,!!o);return typeof s=="function"&&r(i,".prototype.")>-1?t([s]):s},ec}var tc,ud;function s6(){if(ud)return tc;ud=1;var e=ks()(),t=uo(),r=t("Object.prototype.toString"),n=function(a){return e&&a&&typeof a=="object"&&Symbol.toStringTag in a?!1:r(a)==="[object Arguments]"},i=function(a){return n(a)?!0:a!==null&&typeof a=="object"&&"length"in a&&typeof a.length=="number"&&a.length>=0&&r(a)!=="[object Array]"&&"callee"in a&&r(a.callee)==="[object Function]"},o=function(){return n(arguments)}();return n.isLegacyArguments=i,tc=o?n:i,tc}var rc,fd;function a6(){if(fd)return rc;fd=1;var e=uo(),t=ks()(),r=ry(),n=zn(),i;if(t){var o=e("RegExp.prototype.exec"),s={},a=function(){throw s},c={toString:a,valueOf:a};typeof Symbol.toPrimitive=="symbol"&&(c[Symbol.toPrimitive]=a),i=function(y){if(!y||typeof y!="object")return!1;var p=n(y,"lastIndex"),m=p&&r(p,"value");if(!m)return!1;try{o(y,c)}catch(g){return g===s}}}else{var u=e("Object.prototype.toString"),f="[object RegExp]";i=function(y){return!y||typeof y!="object"&&typeof y!="function"?!1:u(y)===f}}return rc=i,rc}var nc,ld;function c6(){if(ld)return nc;ld=1;var e=uo(),t=a6(),r=e("RegExp.prototype.exec"),n=ao();return nc=function(o){if(!t(o))throw new n("`regex` must be a RegExp");return function(a){return r(o,a)!==null}},nc}var ic,dd;function u6(){if(dd)return ic;dd=1;var e=uo(),t=c6(),r=t(/^\s*(?:function)?\*/),n=ks()(),i=Wu(),o=e("Object.prototype.toString"),s=e("Function.prototype.toString"),a=function(){if(!n)return!1;try{return Function("return function*() {}")()}catch{}},c;return ic=function(f){if(typeof f!="function")return!1;if(r(s(f)))return!0;if(!n){var h=o(f);return h==="[object GeneratorFunction]"}if(!i)return!1;if(typeof c>"u"){var y=a();c=y?i(y):!1}return i(f)===c},ic}var oc,hd;function f6(){if(hd)return oc;hd=1;var e=Function.prototype.toString,t=typeof Reflect=="object"&&Reflect!==null&&Reflect.apply,r,n;if(typeof t=="function"&&typeof Object.defineProperty=="function")try{r=Object.defineProperty({},"length",{get:function(){throw n}}),n={},t(function(){throw 42},null,r)}catch(P){P!==n&&(t=null)}else t=null;var i=/^\s*class\b/,o=function(w){try{var _=e.call(w);return i.test(_)}catch{return!1}},s=function(w){try{return o(w)?!1:(e.call(w),!0)}catch{return!1}},a=Object.prototype.toString,c="[object Object]",u="[object Function]",f="[object GeneratorFunction]",h="[object HTMLAllCollection]",y="[object HTML document.all class]",p="[object HTMLCollection]",m=typeof Symbol=="function"&&!!Symbol.toStringTag,g=!(0 in[,]),A=function(){return!1};if(typeof document=="object"){var S=document.all;a.call(S)===a.call(document.all)&&(A=function(w){if((g||!w)&&(typeof w>"u"||typeof w=="object"))try{var _=a.call(w);return(_===h||_===y||_===p||_===c)&&w("")==null}catch{}return!1})}return oc=t?function(w){if(A(w))return!0;if(!w||typeof w!="function"&&typeof w!="object")return!1;try{t(w,null,r)}catch(_){if(_!==n)return!1}return!o(w)&&s(w)}:function(w){if(A(w))return!0;if(!w||typeof w!="function"&&typeof w!="object")return!1;if(m)return s(w);if(o(w))return!1;var _=a.call(w);return _!==u&&_!==f&&!/^\[object HTML/.test(_)?!1:s(w)},oc}var sc,pd;function l6(){if(pd)return sc;pd=1;var e=f6(),t=Object.prototype.toString,r=Object.prototype.hasOwnProperty,n=function(c,u,f){for(var h=0,y=c.length;h<y;h++)r.call(c,h)&&(f==null?u(c[h],h,c):u.call(f,c[h],h,c))},i=function(c,u,f){for(var h=0,y=c.length;h<y;h++)f==null?u(c.charAt(h),h,c):u.call(f,c.charAt(h),h,c)},o=function(c,u,f){for(var h in c)r.call(c,h)&&(f==null?u(c[h],h,c):u.call(f,c[h],h,c))};function s(a){return t.call(a)==="[object Array]"}return sc=function(c,u,f){if(!e(u))throw new TypeError("iterator must be a function");var h;arguments.length>=3&&(h=f),s(c)?n(c,u,h):typeof c=="string"?i(c,u,h):o(c,u,h)},sc}var ac,yd;function d6(){return yd||(yd=1,ac=["Float16Array","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array"]),ac}var cc,bd;function h6(){if(bd)return cc;bd=1;var e=d6(),t=typeof globalThis>"u"?We:globalThis;return cc=function(){for(var n=[],i=0;i<e.length;i++)typeof t[e[i]]=="function"&&(n[n.length]=e[i]);return n},cc}var uc={exports:{}},fc,md;function p6(){if(md)return fc;md=1;var e=Os(),t=Z0(),r=ao(),n=zn();return fc=function(o,s,a){if(!o||typeof o!="object"&&typeof o!="function")throw new r("`obj` must be an object or a function`");if(typeof s!="string"&&typeof s!="symbol")throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new r("`loose`, if provided, must be a boolean");var c=arguments.length>3?arguments[3]:null,u=arguments.length>4?arguments[4]:null,f=arguments.length>5?arguments[5]:null,h=arguments.length>6?arguments[6]:!1,y=!!n&&n(o,s);if(e)e(o,s,{configurable:f===null&&y?y.configurable:!f,enumerable:c===null&&y?y.enumerable:!c,value:a,writable:u===null&&y?y.writable:!u});else if(h||!c&&!u&&!f)o[s]=a;else throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},fc}var lc,gd;function y6(){if(gd)return lc;gd=1;var e=Os(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return e([],"length",{value:1}).length!==1}catch{return!0}},lc=t,lc}var dc,wd;function b6(){if(wd)return dc;wd=1;var e=ny(),t=p6(),r=y6()(),n=zn(),i=ao(),o=e("%Math.floor%");return dc=function(a,c){if(typeof a!="function")throw new i("`fn` is not a function");if(typeof c!="number"||c<0||c>4294967295||o(c)!==c)throw new i("`length` must be a positive 32-bit integer");var u=arguments.length>2&&!!arguments[2],f=!0,h=!0;if("length"in a&&n){var y=n(a,"length");y&&!y.configurable&&(f=!1),y&&!y.writable&&(h=!1)}return(f||h||!u)&&(r?t(a,"length",c,!0,!0):t(a,"length",c)),a},dc}var hc,vd;function m6(){if(vd)return hc;vd=1;var e=co(),t=zu(),r=ty();return hc=function(){return r(e,t,arguments)},hc}var _d;function g6(){return _d||(_d=1,function(e){var t=b6(),r=Os(),n=Vu(),i=m6();e.exports=function(s){var a=n(arguments),c=s.length-(arguments.length-1);return t(a,1+(c>0?c:0),!0)},r?r(e.exports,"apply",{value:i}):e.exports.apply=i}(uc)),uc.exports}var pc,Ed;function iy(){if(Ed)return pc;Ed=1;var e=l6(),t=h6(),r=g6(),n=uo(),i=zn(),o=Wu(),s=n("Object.prototype.toString"),a=ks()(),c=typeof globalThis>"u"?We:globalThis,u=t(),f=n("String.prototype.slice"),h=n("Array.prototype.indexOf",!0)||function(A,S){for(var P=0;P<A.length;P+=1)if(A[P]===S)return P;return-1},y={__proto__:null};a&&i&&o?e(u,function(g){var A=new c[g];if(Symbol.toStringTag in A&&o){var S=o(A),P=i(S,Symbol.toStringTag);if(!P&&S){var w=o(S);P=i(w,Symbol.toStringTag)}y["$"+g]=r(P.get)}}):e(u,function(g){var A=new c[g],S=A.slice||A.set;S&&(y["$"+g]=r(S))});var p=function(A){var S=!1;return e(y,function(P,w){if(!S)try{"$"+P(A)===w&&(S=f(w,1))}catch{}}),S},m=function(A){var S=!1;return e(y,function(P,w){if(!S)try{P(A),S=f(w,1)}catch{}}),S};return pc=function(A){if(!A||typeof A!="object")return!1;if(!a){var S=f(s(A),8,-1);return h(u,S)>-1?S:S!=="Object"?!1:m(A)}return i?p(A):null},pc}var yc,xd;function w6(){if(xd)return yc;xd=1;var e=iy();return yc=function(r){return!!e(r)},yc}var Ad;function v6(){return Ad||(Ad=1,function(e){var t=s6(),r=u6(),n=iy(),i=w6();function o(q){return q.call.bind(q)}var s=typeof BigInt<"u",a=typeof Symbol<"u",c=o(Object.prototype.toString),u=o(Number.prototype.valueOf),f=o(String.prototype.valueOf),h=o(Boolean.prototype.valueOf);if(s)var y=o(BigInt.prototype.valueOf);if(a)var p=o(Symbol.prototype.valueOf);function m(q,Et){if(typeof q!="object")return!1;try{return Et(q),!0}catch{return!1}}e.isArgumentsObject=t,e.isGeneratorFunction=r,e.isTypedArray=i;function g(q){return typeof Promise<"u"&&q instanceof Promise||q!==null&&typeof q=="object"&&typeof q.then=="function"&&typeof q.catch=="function"}e.isPromise=g;function A(q){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?ArrayBuffer.isView(q):i(q)||U(q)}e.isArrayBufferView=A;function S(q){return n(q)==="Uint8Array"}e.isUint8Array=S;function P(q){return n(q)==="Uint8ClampedArray"}e.isUint8ClampedArray=P;function w(q){return n(q)==="Uint16Array"}e.isUint16Array=w;function _(q){return n(q)==="Uint32Array"}e.isUint32Array=_;function I(q){return n(q)==="Int8Array"}e.isInt8Array=I;function T(q){return n(q)==="Int16Array"}e.isInt16Array=T;function H(q){return n(q)==="Int32Array"}e.isInt32Array=H;function M(q){return n(q)==="Float32Array"}e.isFloat32Array=M;function C(q){return n(q)==="Float64Array"}e.isFloat64Array=C;function Y(q){return n(q)==="BigInt64Array"}e.isBigInt64Array=Y;function J(q){return n(q)==="BigUint64Array"}e.isBigUint64Array=J;function re(q){return c(q)==="[object Map]"}re.working=typeof Map<"u"&&re(new Map);function ee(q){return typeof Map>"u"?!1:re.working?re(q):q instanceof Map}e.isMap=ee;function Q(q){return c(q)==="[object Set]"}Q.working=typeof Set<"u"&&Q(new Set);function ae(q){return typeof Set>"u"?!1:Q.working?Q(q):q instanceof Set}e.isSet=ae;function _e(q){return c(q)==="[object WeakMap]"}_e.working=typeof WeakMap<"u"&&_e(new WeakMap);function pe(q){return typeof WeakMap>"u"?!1:_e.working?_e(q):q instanceof WeakMap}e.isWeakMap=pe;function de(q){return c(q)==="[object WeakSet]"}de.working=typeof WeakSet<"u"&&de(new WeakSet);function F(q){return de(q)}e.isWeakSet=F;function X(q){return c(q)==="[object ArrayBuffer]"}X.working=typeof ArrayBuffer<"u"&&X(new ArrayBuffer);function ne(q){return typeof ArrayBuffer>"u"?!1:X.working?X(q):q instanceof ArrayBuffer}e.isArrayBuffer=ne;function k(q){return c(q)==="[object DataView]"}k.working=typeof ArrayBuffer<"u"&&typeof DataView<"u"&&k(new DataView(new ArrayBuffer(1),0,1));function U(q){return typeof DataView>"u"?!1:k.working?k(q):q instanceof DataView}e.isDataView=U;var j=typeof SharedArrayBuffer<"u"?SharedArrayBuffer:void 0;function te(q){return c(q)==="[object SharedArrayBuffer]"}function B(q){return typeof j>"u"?!1:(typeof te.working>"u"&&(te.working=te(new j)),te.working?te(q):q instanceof j)}e.isSharedArrayBuffer=B;function O(q){return c(q)==="[object AsyncFunction]"}e.isAsyncFunction=O;function $(q){return c(q)==="[object Map Iterator]"}e.isMapIterator=$;function V(q){return c(q)==="[object Set Iterator]"}e.isSetIterator=V;function W(q){return c(q)==="[object Generator]"}e.isGeneratorObject=W;function v(q){return c(q)==="[object WebAssembly.Module]"}e.isWebAssemblyCompiledModule=v;function E(q){return m(q,u)}e.isNumberObject=E;function D(q){return m(q,f)}e.isStringObject=D;function K(q){return m(q,h)}e.isBooleanObject=K;function me(q){return s&&m(q,y)}e.isBigIntObject=me;function ie(q){return a&&m(q,p)}e.isSymbolObject=ie;function ye(q){return E(q)||D(q)||K(q)||me(q)||ie(q)}e.isBoxedPrimitive=ye;function gt(q){return typeof Uint8Array<"u"&&(ne(q)||B(q))}e.isAnyArrayBuffer=gt,["isProxy","isExternal","isModuleNamespaceObject"].forEach(function(q){Object.defineProperty(e,q,{enumerable:!1,value:function(){throw new Error(q+" is not supported in userland")}})})}(ga)),ga}var bc,Sd;function _6(){return Sd||(Sd=1,bc=function(t){return t&&typeof t=="object"&&typeof t.copy=="function"&&typeof t.fill=="function"&&typeof t.readUInt8=="function"}),bc}var Pd;function oy(){return Pd||(Pd=1,function(e){var t=Object.getOwnPropertyDescriptors||function(U){for(var j=Object.keys(U),te={},B=0;B<j.length;B++)te[j[B]]=Object.getOwnPropertyDescriptor(U,j[B]);return te},r=/%[sdj%]/g;e.format=function(k){if(!I(k)){for(var U=[],j=0;j<arguments.length;j++)U.push(s(arguments[j]));return U.join(" ")}for(var j=1,te=arguments,B=te.length,O=String(k).replace(r,function(V){if(V==="%%")return"%";if(j>=B)return V;switch(V){case"%s":return String(te[j++]);case"%d":return Number(te[j++]);case"%j":try{return JSON.stringify(te[j++])}catch{return"[Circular]"}default:return V}}),$=te[j];j<B;$=te[++j])P($)||!C($)?O+=" "+$:O+=" "+s($);return O},e.deprecate=function(k,U){if(typeof process<"u"&&process.noDeprecation===!0)return k;if(typeof process>"u")return function(){return e.deprecate(k,U).apply(this,arguments)};var j=!1;function te(){if(!j){if(process.throwDeprecation)throw new Error(U);process.traceDeprecation?console.trace(U):console.error(U),j=!0}return k.apply(this,arguments)}return te};var n={},i=/^$/;if(process.env.NODE_DEBUG){var o=process.env.NODE_DEBUG;o=o.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".*").replace(/,/g,"$|^").toUpperCase(),i=new RegExp("^"+o+"$","i")}e.debuglog=function(k){if(k=k.toUpperCase(),!n[k])if(i.test(k)){var U=process.pid;n[k]=function(){var j=e.format.apply(e,arguments);console.error("%s %d: %s",k,U,j)}}else n[k]=function(){};return n[k]};function s(k,U){var j={seen:[],stylize:c};return arguments.length>=3&&(j.depth=arguments[2]),arguments.length>=4&&(j.colors=arguments[3]),S(U)?j.showHidden=U:U&&e._extend(j,U),H(j.showHidden)&&(j.showHidden=!1),H(j.depth)&&(j.depth=2),H(j.colors)&&(j.colors=!1),H(j.customInspect)&&(j.customInspect=!0),j.colors&&(j.stylize=a),f(j,k,j.depth)}e.inspect=s,s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},s.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function a(k,U){var j=s.styles[U];return j?"\x1B["+s.colors[j][0]+"m"+k+"\x1B["+s.colors[j][1]+"m":k}function c(k,U){return k}function u(k){var U={};return k.forEach(function(j,te){U[j]=!0}),U}function f(k,U,j){if(k.customInspect&&U&&re(U.inspect)&&U.inspect!==e.inspect&&!(U.constructor&&U.constructor.prototype===U)){var te=U.inspect(j,k);return I(te)||(te=f(k,te,j)),te}var B=h(k,U);if(B)return B;var O=Object.keys(U),$=u(O);if(k.showHidden&&(O=Object.getOwnPropertyNames(U)),J(U)&&(O.indexOf("message")>=0||O.indexOf("description")>=0))return y(U);if(O.length===0){if(re(U)){var V=U.name?": "+U.name:"";return k.stylize("[Function"+V+"]","special")}if(M(U))return k.stylize(RegExp.prototype.toString.call(U),"regexp");if(Y(U))return k.stylize(Date.prototype.toString.call(U),"date");if(J(U))return y(U)}var W="",v=!1,E=["{","}"];if(A(U)&&(v=!0,E=["[","]"]),re(U)){var D=U.name?": "+U.name:"";W=" [Function"+D+"]"}if(M(U)&&(W=" "+RegExp.prototype.toString.call(U)),Y(U)&&(W=" "+Date.prototype.toUTCString.call(U)),J(U)&&(W=" "+y(U)),O.length===0&&(!v||U.length==0))return E[0]+W+E[1];if(j<0)return M(U)?k.stylize(RegExp.prototype.toString.call(U),"regexp"):k.stylize("[Object]","special");k.seen.push(U);var K;return v?K=p(k,U,j,$,O):K=O.map(function(me){return m(k,U,j,$,me,v)}),k.seen.pop(),g(K,W,E)}function h(k,U){if(H(U))return k.stylize("undefined","undefined");if(I(U)){var j="'"+JSON.stringify(U).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return k.stylize(j,"string")}if(_(U))return k.stylize(""+U,"number");if(S(U))return k.stylize(""+U,"boolean");if(P(U))return k.stylize("null","null")}function y(k){return"["+Error.prototype.toString.call(k)+"]"}function p(k,U,j,te,B){for(var O=[],$=0,V=U.length;$<V;++$)de(U,String($))?O.push(m(k,U,j,te,String($),!0)):O.push("");return B.forEach(function(W){W.match(/^\d+$/)||O.push(m(k,U,j,te,W,!0))}),O}function m(k,U,j,te,B,O){var $,V,W;if(W=Object.getOwnPropertyDescriptor(U,B)||{value:U[B]},W.get?W.set?V=k.stylize("[Getter/Setter]","special"):V=k.stylize("[Getter]","special"):W.set&&(V=k.stylize("[Setter]","special")),de(te,B)||($="["+B+"]"),V||(k.seen.indexOf(W.value)<0?(P(j)?V=f(k,W.value,null):V=f(k,W.value,j-1),V.indexOf(`
73
- `)>-1&&(O?V=V.split(`
74
- `).map(function(v){return" "+v}).join(`
75
- `).slice(2):V=`
76
- `+V.split(`
77
- `).map(function(v){return" "+v}).join(`
78
- `))):V=k.stylize("[Circular]","special")),H($)){if(O&&B.match(/^\d+$/))return V;$=JSON.stringify(""+B),$.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?($=$.slice(1,-1),$=k.stylize($,"name")):($=$.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),$=k.stylize($,"string"))}return $+": "+V}function g(k,U,j){var te=k.reduce(function(B,O){return O.indexOf(`
79
- `)>=0,B+O.replace(/\u001b\[\d\d?m/g,"").length+1},0);return te>60?j[0]+(U===""?"":U+`
80
- `)+" "+k.join(`,
81
- `)+" "+j[1]:j[0]+U+" "+k.join(", ")+" "+j[1]}e.types=v6();function A(k){return Array.isArray(k)}e.isArray=A;function S(k){return typeof k=="boolean"}e.isBoolean=S;function P(k){return k===null}e.isNull=P;function w(k){return k==null}e.isNullOrUndefined=w;function _(k){return typeof k=="number"}e.isNumber=_;function I(k){return typeof k=="string"}e.isString=I;function T(k){return typeof k=="symbol"}e.isSymbol=T;function H(k){return k===void 0}e.isUndefined=H;function M(k){return C(k)&&Q(k)==="[object RegExp]"}e.isRegExp=M,e.types.isRegExp=M;function C(k){return typeof k=="object"&&k!==null}e.isObject=C;function Y(k){return C(k)&&Q(k)==="[object Date]"}e.isDate=Y,e.types.isDate=Y;function J(k){return C(k)&&(Q(k)==="[object Error]"||k instanceof Error)}e.isError=J,e.types.isNativeError=J;function re(k){return typeof k=="function"}e.isFunction=re;function ee(k){return k===null||typeof k=="boolean"||typeof k=="number"||typeof k=="string"||typeof k=="symbol"||typeof k>"u"}e.isPrimitive=ee,e.isBuffer=_6();function Q(k){return Object.prototype.toString.call(k)}function ae(k){return k<10?"0"+k.toString(10):k.toString(10)}var _e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function pe(){var k=new Date,U=[ae(k.getHours()),ae(k.getMinutes()),ae(k.getSeconds())].join(":");return[k.getDate(),_e[k.getMonth()],U].join(" ")}e.log=function(){console.log("%s - %s",pe(),e.format.apply(e,arguments))},e.inherits=Ke,e._extend=function(k,U){if(!U||!C(U))return k;for(var j=Object.keys(U),te=j.length;te--;)k[j[te]]=U[j[te]];return k};function de(k,U){return Object.prototype.hasOwnProperty.call(k,U)}var F=typeof Symbol<"u"?Symbol("util.promisify.custom"):void 0;e.promisify=function(U){if(typeof U!="function")throw new TypeError('The "original" argument must be of type Function');if(F&&U[F]){var j=U[F];if(typeof j!="function")throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(j,F,{value:j,enumerable:!1,writable:!1,configurable:!0}),j}function j(){for(var te,B,O=new Promise(function(W,v){te=W,B=v}),$=[],V=0;V<arguments.length;V++)$.push(arguments[V]);$.push(function(W,v){W?B(W):te(v)});try{U.apply(this,$)}catch(W){B(W)}return O}return Object.setPrototypeOf(j,Object.getPrototypeOf(U)),F&&Object.defineProperty(j,F,{value:j,enumerable:!1,writable:!1,configurable:!0}),Object.defineProperties(j,t(U))},e.promisify.custom=F;function X(k,U){if(!k){var j=new Error("Promise was rejected with a falsy value");j.reason=k,k=j}return U(k)}function ne(k){if(typeof k!="function")throw new TypeError('The "original" argument must be of type Function');function U(){for(var j=[],te=0;te<arguments.length;te++)j.push(arguments[te]);var B=j.pop();if(typeof B!="function")throw new TypeError("The last argument must be of type Function");var O=this,$=function(){return B.apply(O,arguments)};k.apply(this,j).then(function(V){process.nextTick($.bind(null,null,V))},function(V){process.nextTick(X.bind(null,V,$))})}return Object.setPrototypeOf(U,Object.getPrototypeOf(k)),Object.defineProperties(U,t(k)),U}e.callbackify=ne}(ma)),ma}Object.defineProperty(Un,"__esModule",{value:!0});Un.encode=Un.decode=void 0;const sy=Rr;function E6(e){return(sy.isBrowser?new TextDecoder("utf-8"):new(oy()).TextDecoder("utf-8")).decode(e)}Un.decode=E6;function x6(e){return(sy.isBrowser?new TextEncoder:new(oy()).TextEncoder("utf-8")).encode(e)}Un.encode=x6;var Ln={},A6=M0,S6="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",P6=A6(S6),T6=We&&We.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Ln,"__esModule",{value:!0});Ln.decode=Ln.encode=void 0;const ay=T6(P6);function I6(e){return ay.default.encode(e)}Ln.encode=I6;function B6(e){return ay.default.decode(e)}Ln.decode=B6;var Hn={};Object.defineProperty(Hn,"__esModule",{value:!0});Hn.decode=Hn.encode=void 0;const k6=Ut;function O6(e){return e.toString("base64")}Hn.encode=O6;function R6(e){return k6.Buffer.from(e,"base64")}Hn.decode=R6;var C6=We&&We.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),F6=We&&We.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),Rs=We&&We.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&C6(t,e,r);return F6(t,e),t};Object.defineProperty(ar,"__esModule",{value:!0});ar.base64=Jc=ar.bs58=ar.utf8=zo=ar.hex=void 0;var zo=ar.hex=Rs(Nn);ar.utf8=Rs(Un);var Jc=ar.bs58=Rs(Ln);ar.base64=Rs(Hn);class Vo{constructor(t,r,n,i,o){try{this.swapId=[...zo.decode(t)],this.secretHash=[...zo.decode(n)]}catch(s){throw new Error("Error decoding swapId or secretHash",{cause:s})}if(this.secretHash.length!=32||this.swapId.length!=32)throw new Error("swapId or secretHash must be exactly 32 bits in size");try{this.redeemer=new jr.web3.PublicKey(r)}catch(s){throw new Error("Error decoding redeemer. Ensure it is a valid base58 encoded",{cause:s})}try{this.amount=new jr.BN(i.toString(10),10),this.expiresIn=new jr.BN(o)}catch(s){throw new Error("Error decoding amount. Invalid value for amount",{cause:s})}if(!(Number.isInteger(o)&&o>0))throw new Error("expiresIn must be a positive integer.")}static from(t){let r;if(t.source_swap.chain.includes("solana"))r=t.source_swap;else if(t.destination_swap.chain.includes("solana"))r=t.destination_swap;else throw new Error("Expected source_swap or destination_swap to be one of 'solana', 'solana_localnet', 'solana_devnet'");const{swap_id:n,redeemer:i,secret_hash:o,timelock:s}=r,a=BigInt(r.amount);return new Vo(n,i,o,a,s)}}function N6(e){let t;try{t=[...zo.decode(e)]}catch(r){throw new Error("Error decoding secret. Ensure it is a hex string",{cause:r})}if(t.length!=32)throw new Error("Invalid Secret size. Expected 32 bytes, got "+t.length);return t}class U6{constructor(t,r,n){if(this.provider=t,this.endpoint=r,!t)throw new Error("Provider is required");if(!r)throw new Error("Endpoint URL is required");if(!n)throw new Error("Relayer address is required");this.provider=t,this.program=new jr.Program(Lx,t);try{this.relayer=new jr.web3.PublicKey(n)}catch(i){throw new Error("Error decoding relayer publickey. Ensure it is a base58 encoded string",{cause:i})}}get htlcActorAddress(){if(!this.program.programId)throw new Error("No program found");return this.provider.publicKey.toBase58()}async sendViaRelayer(t,r=!1,n){try{if(t.recentBlockhash=(await this.provider.connection.getLatestBlockhash()).blockhash,t.feePayer=this.relayer,console.log("Transaction to be sent:: ",t),r){const i=await this.provider.wallet.signTransaction(t),o=Jc.encode(i.serialize({requireAllSignatures:!1})),s={orderId:n,serializedTx:o};console.log("Relay Requets:: ",s);const a=await N.Fetcher.post(this.endpoint,{body:JSON.stringify(s),headers:{"Content-Type":"application/json"}});return a.error?N.Err(`Error from Relayer: ${a.error}`):a.result?N.Ok(a.result):N.Err("No result returned from relayer")}else{const i=Jc.encode(t.serialize({requireAllSignatures:!1})),o={orderId:n,serializedTx:i},s=await N.Fetcher.post(this.endpoint,{body:JSON.stringify(o),headers:{"Content-Type":"application/json"}});return s.error?N.Err(`Error from Relayer: ${s.error}`):s.result?N.Ok(s.result):N.Err("No result returned from relayer")}}catch(i){return console.error("Error in sendViaRelayer:",i),N.Err(`Failed to send transaction: ${i instanceof Error?i.message:String(i)}`)}}async initiate(t){const{redeemer:r,secretHash:n,amount:i,expiresIn:o}=Vo.from(t),s=[Buffer.from("swap_account"),Buffer.from(n)];this.swapAccount=jr.web3.PublicKey.findProgramAddressSync(s,this.program.programId)[0];const a=await this.program.methods.initiate(i,o,r,n).accounts({initiator:this.provider.publicKey}).transaction();return await this.sendViaRelayer(a,!0,t.create_order.create_id)}async redeem(t,r){const{secretHash:n,redeemer:i}=Vo.from(t),o=[Buffer.from("swap_account"),Buffer.from(n)];this.swapAccount=jr.web3.PublicKey.findProgramAddressSync(o,this.program.programId)[0];const s=await this.program.methods.redeem(N6(r)).accounts({swapAccount:this.swapAccount,redeemer:i}).transaction();return this.sendViaRelayer(s,!1,t.create_order.create_id)}async refund(t){return console.log("Refund erroneously called for :: ",t.source_swap.swap_id),N.Err("DO NOT CALL THIS FUNCTION. Refund is automatically handled by the relayer.")}}class Ku extends Z.EventBroker{constructor(t){super(),this.environment=Z.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new wv;const{api:r,environment:n}=If(t.environment);if(this.environment=n,this._api=r,typeof t.digestKey=="string"){const o=Z.DigestKey.from(t.digestKey);if(!o.ok)throw new Error(o.error);this._digestKey=o.val}else this._digestKey=t.digestKey;this._quote=t.quote??new n0(this._api.quote),this._auth=t.auth??Z.Siwe.fromDigestKey(new Z.Url(this._api.auth),this._digestKey),this._orderbook=t.orderbook??new we.Orderbook(new Z.Url(this._api.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._solanaHTLC=t.htlc.solana,this._secretManager=t.secretManager??qi.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new gv,this._blockNumberFetcher=t.blockNumberFetcher??new r0(this._api.info,this.environment);const i=new Gr.BitcoinProvider(vw(this.environment));this._btcWallet=Gr.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,i)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const o=Z.DigestKey.from(t.digestKey);if(!o.ok)throw new Error(o.error);r=o.val}else r=t.digestKey;const{api:n}=If(t.environment);if(!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new V0(n.evmRelay,t.wallets.evm,Z.Siwe.fromDigestKey(new Z.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new Y0(n.starknetRelay,t.wallets.starknet,t.environment===Z.Environment.MAINNET?Z.Network.MAINNET:Z.Network.TESTNET):void 0,solana:t.wallets.solana?new U6(t.wallets.solana,new Z.Url(n.solanaRelay),t.environment===Z.Environment.MAINNET?Pf.mainnet:Pf.testnet):void 0};return new Ku({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get solanaHTLC(){return this._solanaHTLC}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 N.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:o}=r.val,s=Date.now().toString(),a=await this._secretManager.generateSecret(s);if(a.error)return N.Err(a.error);const{strategyId:c,btcAddress:u}=t.additionalData,f={strategy_id:c,...u&&{bitcoin_optional_recipient:u}},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:s,timelock:o,secret_hash:N.trim0x(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:f,affiliate_fees:this.withDefaultAffiliateFees(t.affiliateFee)},y=await this._quote.getAttestedQuote(h);if(y.error)return N.Err(y.error);const p=await this._orderbook.createOrder(y.val,this._auth);if(p.error)return N.Err(p.error);const m=await this.pollOrder(p.val);if(m.error)return N.Err(m.error);if(m.val&&we.getBlockchainType(m.val.source_swap.chain)===we.BlockchainType.Solana){const g=await this._secretManager.generateSecret(m.val.create_order.nonce);if(g.error)return N.Err(g.error);const A=await this.solInit(m.val);if(A&&A.error)return N.Err(A.error)}return N.Ok(m.val)}withDefaultAffiliateFees(t){return(t??[]).map(r=>({fee:r.fee,address:r.address,chain:r.chain??Tf.chain,asset:r.asset??Tf.asset}))}async validateAndFillParams(t){if(!t.additionalData.strategyId)return N.Err("StrategyId is required");if(!t.fromAsset||!t.toAsset)return N.Err("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return N.Err("Source and destination assets cannot be the same");if(we.isMainnet(t.fromAsset.chain)&&!we.isMainnet(t.toAsset.chain)||!we.isMainnet(t.fromAsset.chain)&&we.isMainnet(t.toAsset.chain))return N.Err("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return N.Err(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return N.Err(n.error);if(r<n)return N.Err("Send amount should be greater than receive amount");const i=we.getTimeLock(t.fromAsset.chain);if(!i)return N.Err("Unsupported chain for timelock");if((we.isBitcoin(t.fromAsset.chain)||we.isBitcoin(t.toAsset.chain))&&!t.additionalData.btcAddress)return N.Err("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const o=await this.getAddresses(t.fromAsset.chain);if(o.error)return N.Err(o.error);const s=await this.getAddresses(t.toAsset.chain);return s.error?N.Err(s.error):N.Ok({sendAddress:o.val,receiveAddress:s.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(we.getBlockchainType(t)){case we.BlockchainType.EVM:return this._evmHTLC?N.Ok(this._evmHTLC.htlcActorAddress):N.Err("Please provide evmHTLC when initializing garden");case we.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!gw(i)?N.Err("Invalid btc public key"):N.Ok(Pr(i))}case we.BlockchainType.Solana:return this._solanaHTLC?N.Ok(this._solanaHTLC.htlcActorAddress):N.Err("Please provide solanaHTLC when initializing garden");case we.BlockchainType.Starknet:return this._starknetHTLC?N.Ok(this._starknetHTLC.htlcActorAddress):N.Err("Please provide starknetHTLC when initializing garden");default:return N.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return N.Err("Invalid amount ",t);const r=new ly(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?N.Err("Invalid amount ",t):N.Ok(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await Z.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return N.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return N.Ok(r.val);r=await this._orderbook.getOrder(t,!0)}return N.Err(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{const n=await this.filterExpiredAndAssignStatus(r.data);if(this.emit("onPendingOrdersChanged",n.val),r.data.length!==0)for(let i=0;i<n.val.length;i++){const o=n.val[i],s=Iu(o.status);if(we.isBitcoin(o.source_swap.chain)&&o.status===ke.InitiateDetected){const a=this._btcWallet;if(!a){this.emit("error",o,"BTC wallet not found");continue}await this.postRefundSACP(o,a)}switch(s){case Re.Redeem:{const a=await this._secretManager.generateSecret(o.create_order.nonce);if(a.error){this.emit("error",o,a.error);return}switch(we.getBlockchainType(o.destination_swap.chain)){case we.BlockchainType.EVM:{await this.evmRedeem(o,a.val.secret);break}case we.BlockchainType.Bitcoin:{const c=this.btcWallet;if(!c){this.emit("error",o,"BTC wallet not found");return}await this.btcRedeem(c,o,a.val.secret);break}case we.BlockchainType.Starknet:{await this.starknetRedeem(o,a.val.secret);break}case we.BlockchainType.Solana:await this.solRedeem(o,a.val.secret);break;default:this.emit("error",o,"Unsupported chain: "+o.destination_swap.chain)}break}case Re.Refund:{switch(we.getBlockchainType(o.source_swap.chain)){case we.BlockchainType.Solana:{this.emit("error",o,"Solana refund is automatically done by relay service");break}case we.BlockchainType.EVM:{this.emit("error",o,"EVM refund is automatically done by relay service");break}case we.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",o,"BTC wallet not found");return}await this.btcRefund(a,o);break}case we.BlockchainType.Starknet:{this.emit("error",o,"Starknet refund is automatically done by relay service");break}default:this.emit("error",o,"Unsupported chain: "+o.source_swap.chain)}break}}}},"pending",{per_page:500})}async solInit(t){if(!this._solanaHTLC)return this.emit("error",t,"Solana htlc is not iniitalized"),N.Err("Solana htlc not initialized");this.emit("log",this._solanaHTLC.htlcActorAddress,"Initiating solana order");const r=await this._solanaHTLC.initiate(t);return r.error?(this.emit("error",t,r.error),N.Err(r.error)):(this.emit("log",t.create_order.create_id,"Solana Order Initiated successfully"),N.Ok(r))}async solRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing sol redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._solanaHTLC){this.emit("error",t,"Solana HTLC is required");return}const i=await this._solanaHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val))}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._evmHTLC){this.emit("error",t,"EVMHTLC is required");return}const i=await this._evmHTLC.redeem(t,r);if(!i.ok){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Re.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._starknetHTLC){this.emit("error",t,"StarknetHTLC is required");return}const i=await this._starknetHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Re.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Re.Redeem,i.val),this.emit("success",t,Re.Redeem,i.val))}async btcRedeem(t,r,n){var a,c;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),o=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!o){this.emit("error",r,"Failed to get initiate_tx_hash");return}let s=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==o)s=!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"),s=!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 u=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let f=!1;for(const h of u.vin)if(h.txid===o){f=!0;break}if(f){this.emit("log",r.create_order.create_id,"already a valid redeem");let h=0;try{const[y]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);y!==0&&(h=y)}catch{h=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:o,redeemedAt:h,redeemTxHash:r.destination_swap.redeem_tx_hash});return}s=!0}catch(u){if(u.message.includes("Transaction not found"))s=!0;else{this.emit("error",r,"Failed to get redeem tx: "+u);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const f=await(await li.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Pr(r.destination_swap.initiator),Pr(r.destination_swap.redeemer),r.destination_swap.timelock,s?[o]:[])).getRedeemHex(N.trim0x(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient),h=await this.broadcastRedeemTx(f,r.create_order.create_id);if(h.error||!h.val){this.emit("error",r,h.error||"Failed to broadcast redeem tx");return}s?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,h.val)):this.emit("success",r,Re.Redeem,h.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:o,redeemedAt:Date.now(),redeemTxHash:h.val})}catch(u){this.emit("error",r,"Failed btc redeem: "+u)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Re.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const o=await(await li.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Pr(r.source_swap.initiator),Pr(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,Re.Refund,o),this.emit("success",r,Re.Refund,o)}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 li.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,Pr(t.source_swap.initiator),Pr(t.source_swap.redeemer),t.source_swap.timelock),o=t.create_order.additional_data.bitcoin_optional_recipient;if(o)try{const s=await i.generateInstantRefundSACP(o);if(!this._api)return;const a=new Z.Url("https://testnet.api.hashira.io/").endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await N.Fetcher.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:s})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(s){this.emit("error",t,"Failed to generate and post SACP: "+s);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return N.Ok([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return N.Err(r.error);const n=[];for(let o=0;o<t.length;o++){const s=t[o];if(Np(s))continue;const a=s.source_swap.chain,c=s.destination_swap.chain,u=a.includes("mainnet")?"mainnet":"testnet";if(!r.val||!r.val[u]){this.emit("error",s,`Block numbers not available for environment: ${u}`);continue}const f=r.val[u];f.solana&&(f.solana_testnet=f.solana,f.solana_localnet=f.solana),f.arbitrum_sepolia&&(f.arbitrum_localnet=f.arbitrum_sepolia),f.ethereum&&(f.ethereum_localnet=f.ethereum),f.bitcoin&&(f.bitcoin_regtest=f.bitcoin,f.bitcoin_testnet=f.bitcoin);const h=f[a],y=f[c];if(!h||!y){this.emit("error",s,`Error while fetching CurrentBlockNumbers for chains: ${a}, ${c}`);continue}const p=Tu(s,h,y);n.push({...s,status:p})}return N.Ok(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return N.Err("API not found");const n=new Z.Url("https://testnet.api.hashira.io/relayer").endpoint("/bitcoin/redeem"),i=await this._auth.getAuthHeaders(),s=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 s.status==="Ok"&&s.result?N.Ok(s.result):N.Err(s.error)}catch(n){return N.Err("Failed to broadcast redeem tx: "+n)}}}class L6{constructor(t,r,n){this.callData=new De.CallData(W0),this.account=t,this.starknetProvider=new De.RpcProvider({nodeUrl:r||(n?Hi[n].nodeUrl:Hi.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 De.Contract(K0,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=De.num.toHex(n),o=De.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await Tx(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.starknetProvider);if(a.error)return N.Err(a.error)}catch(a){return N.Err(`Allowance check failed: ${a}`)}const s=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),o.low,o.high,...Z.hexToU32Array(t.create_order.secret_hash)]});if(!s.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return N.Ok(s.transaction_hash)}catch(r){return N.Err(`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,o=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:De.CallData.compile({swap_id:i,secret:Z.hexToU32Array(r)})});return o.transaction_hash?N.Ok(o.transaction_hash):N.Err("Failed to redeem HTLC transaction")}catch{return N.Err("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?N.Ok(i.transaction_hash):N.Err("Failed to refund HTLC transaction")}catch{return N.Err("HTLC Refund Error")}}}exports.API=To;exports.AbiErrorInputsNotFoundError=ob;exports.AbiErrorNotFoundError=sb;exports.AbiFunctionNotFoundError=di;exports.AbiFunctionOutputsNotFoundError=Wd;exports.AbiFunctionSignatureNotFoundError=cb;exports.BaseError=z;exports.BlockNumberFetcher=r0;exports.EvmRelay=V0;exports.Garden=Ku;exports.Hash=tu;exports.HttpRequestError=vn;exports.InvalidArrayError=Kd;exports.OrderActions=Re;exports.OrderStatus=ke;exports.ParseOrderStatus=Tu;exports.ParseSwapStatus=Hc;exports.Quote=n0;exports.STARKNET_CONFIG=Hi;exports.SecretManager=qi;exports.StarknetHTLC=L6;exports.StarknetRelay=Y0;exports.SwapStatus=Ce;exports.abytes=zi;exports.aexists=hi;exports.ahash=Ab;exports.batchGatewayAbi=Rg;exports.call=Eu;exports.concat=Jr;exports.concatBytes=Fb;exports.concatHex=Jt;exports.constructOrderPair=Lc;exports.decodeAbiParameters=Wi;exports.decodeErrorResult=ph;exports.encodeAbiParameters=Zo;exports.evmToViemChainMap=G0;exports.filterDeadlineExpiredOrders=Aw;exports.formatAbiItem=Yt;exports.getAbiItem=jn;exports.getUrl=es;exports.hyperliquid=q0;exports.hyperliquidTestnet=j0;exports.isAddressEqual=wu;exports.isExpired=$i;exports.isHex=fr;exports.parseAction=xw;exports.parseActionFromStatus=Iu;exports.randomBytes=Nb;exports.sha256=Ph;exports.slice=Pn;exports.solidityError=dh;exports.stringify=wt;exports.switchOrAddNetwork=z0;exports.toBytes=Yo;exports.toFunctionSelector=Qo;exports.toXOnly=Pr;exports.validateBTCAddress=ww;