@gardenfi/core 2.1.13 → 2.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ccip-CQkMVqmN.cjs +1 -0
- package/dist/ccip-DgpQO1MZ.js +149 -0
- package/dist/index-BwOLJ71D.cjs +75 -0
- package/dist/index-CAqXP6qV.js +24196 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +20 -20
- package/package.json +2 -2
- package/dist/ccip-BopIsmm6.js +0 -232
- package/dist/ccip-CL6RUZeo.cjs +0 -1
- package/dist/index-CBKJdpVQ.js +0 -19741
- package/dist/index-CCzvHnk1.cjs +0 -71
- package/dist/secp256k1-CHT9yKLe.js +0 -1287
- package/dist/secp256k1-CTwfGMq7.cjs +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";var Ty=Object.defineProperty;var Py=(e,t,r)=>t in e?Ty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Bn=(e,t,r)=>Py(e,typeof t!="symbol"?t+"":t,r);const we=require("@gardenfi/orderbook"),Z=require("@gardenfi/utils"),Kn=require("@catalogfi/wallets"),Rl=require("varuint-bitcoin"),By=require("tiny-secp256k1"),Nl=require("bitcoinjs-lib"),Iy=require("bignumber.js"),qe=require("starknet");function yu(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 If=yu(Rl),an=yu(By),ye=yu(Nl);var $l=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},ga=(e,t,r)=>($l(e,t,"read from private field"),r?r.call(e):t.get(e)),wa=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},va=(e,t,r,n)=>($l(e,t,"write to private field"),t.set(e,r),r);const ky=e=>new Promise(t=>setTimeout(t,e));class Cy{constructor(t,r){this.maxRetries=Math.max(t,0),this.delay=r}async retry(t){let r=0,n;for(;r<this.maxRetries+1;)try{return await t()}catch(i){r++,n=i,await ky(this.delay*r)}throw n}}const Oy=e=>{try{return JSON.parse(e)}catch{return e}};class lr{static async _postWithFallback(t,r){let n="";for(const i of t)try{const s=await fetch(i,{method:"POST",...r});if(s.status>=500){n=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){n=kf(s);continue}throw new Error(n||"All APIs failed")}static async postWithFallback(t,r){return await Ds(r).retry(()=>this._postWithFallback(t,r))}static async _getWithFallback(t,r){let n="";for(const i of t)try{const s=await fetch(i,r);if(s.status>=500){n=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){n=kf(s);continue}throw new Error(n||"All APIs failed")}static async getWithFallback(t,r){return await Ds(r).retry(()=>this._getWithFallback(t,r))}static async _get(t,r){return await this.parse(await fetch(t,r))}static async get(t,r){return await Ds(r).retry(()=>this._get(t,r))}static async _post(t,r){return await this.parse(await fetch(t,{method:"POST",...r}))}static async post(t,r){return await Ds(r).retry(()=>this._post(t,r))}static async parse(t){const r=await t.text();if(t.status>=200&&t.status<300)return Oy(r);throw new Error(r)}}function kf(e){return(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"unknown error"}const Ds=e=>new Cy((e==null?void 0:e.retryCount)??2,(e==null?void 0:e.retryDelay)??1e3),tn=e=>e.startsWith("0x")?e:`0x${e}`,Qr=e=>e.startsWith("0x")?e.slice(2):e;var io,so,oo;let yc=class{constructor(t,r,n=void 0){wa(this,io,void 0),wa(this,so,void 0),wa(this,oo,void 0),va(this,io,t),va(this,oo,n),va(this,so,r)}get ok(){return ga(this,io)}get error(){return ga(this,oo)}get val(){return ga(this,so)}};io=new WeakMap,so=new WeakMap,oo=new WeakMap;const de=e=>new yc(!0,e),K=(e,...t)=>{if(typeof e=="string"&&t&&t.length>0){let r=[e,...t].map(n=>{if(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;if(n!=null&&n.toString)return n.toString()}});return new yc(!1,null,r.filter(n=>n!==void 0).join(" "))}return new yc(!1,null,e)};var Fe=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Fe||{});const Ry="1.0.8";let gt=class mc extends Error{constructor(t,r={}){var o;const n=r.cause instanceof mc?r.cause.details:(o=r.cause)!=null&&o.message?r.cause.message:r.details,i=r.cause instanceof mc&&r.cause.docsPath||r.docsPath,s=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...i?[`Docs: https://abitype.dev${i}`]:[],...n?[`Details: ${n}`]:[],`Version: abitype@${Ry}`].join(`
|
|
2
|
+
`);super(s),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),r.cause&&(this.cause=r.cause),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.shortMessage=t}};function _r(e,t){const r=e.exec(t);return r==null?void 0:r.groups}const Ll=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Fl=/^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)?$/,Ul=/^\(.+?\).*?$/,Cf=/^tuple(?<array>(\[(\d*)\])*)$/;function bc(e){let t=e.type;if(Cf.test(e.type)&&"components"in e){t="(";const r=e.components.length;for(let i=0;i<r;i++){const s=e.components[i];t+=bc(s),i<r-1&&(t+=", ")}const n=_r(Cf,e.type);return t+=`)${(n==null?void 0:n.array)??""}`,bc({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function bi(e){let t="";const r=e.length;for(let n=0;n<r;n++){const i=e[n];t+=bc(i),n!==r-1&&(t+=", ")}return t}function wo(e){var t;return e.type==="function"?`function ${e.name}(${bi(e.inputs)})${e.stateMutability&&e.stateMutability!=="nonpayable"?` ${e.stateMutability}`:""}${(t=e.outputs)!=null&&t.length?` returns (${bi(e.outputs)})`:""}`:e.type==="event"?`event ${e.name}(${bi(e.inputs)})`:e.type==="error"?`error ${e.name}(${bi(e.inputs)})`:e.type==="constructor"?`constructor(${bi(e.inputs)})${e.stateMutability==="payable"?" payable":""}`:e.type==="fallback"?`fallback() external${e.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const Ml=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function Ny(e){return Ml.test(e)}function $y(e){return _r(Ml,e)}const Hl=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function Ly(e){return Hl.test(e)}function Fy(e){return _r(Hl,e)}const Dl=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function Uy(e){return Dl.test(e)}function My(e){return _r(Dl,e)}const jl=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function mu(e){return jl.test(e)}function Hy(e){return _r(jl,e)}const zl=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function Dy(e){return zl.test(e)}function jy(e){return _r(zl,e)}const ql=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function zy(e){return ql.test(e)}function qy(e){return _r(ql,e)}const Gy=/^receive\(\) external payable$/;function Vy(e){return Gy.test(e)}const Wy=new Set(["indexed"]),gc=new Set(["calldata","memory","storage"]);class Ky extends gt{constructor({signature:t}){super("Failed to parse ABI item.",{details:`parseAbiItem(${JSON.stringify(t,null,2)})`,docsPath:"/api/human#parseabiitem-1"}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiItemError"})}}class Yy extends gt{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 Zy extends gt{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 Xy extends gt{constructor({param:t}){super("Invalid ABI parameter.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class Jy extends gt{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 Qy extends gt{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 em extends gt{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 tm extends gt{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 ai extends gt{constructor({signature:t,type:r}){super(`Invalid ${r} signature.`,{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class rm extends gt{constructor({signature:t}){super("Unknown signature.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class nm extends gt{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 im extends gt{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 sm extends gt{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 om(e,t,r){let n="";if(r)for(const i of Object.entries(r)){if(!i)continue;let s="";for(const o of i[1])s+=`[${o.type}${o.name?`:${o.name}`:""}]`;n+=`(${i[0]}{${s}})`}return t?`${t}:${e}${n}`:e}const _a=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 wc(e,t={}){if(Uy(e))return am(e,t);if(Ly(e))return cm(e,t);if(Ny(e))return um(e,t);if(Dy(e))return fm(e,t);if(zy(e))return dm(e);if(Vy(e))return{type:"receive",stateMutability:"payable"};throw new rm({signature:e})}function am(e,t={}){const r=My(e);if(!r)throw new ai({signature:e,type:"function"});const n=Ot(r.parameters),i=[],s=n.length;for(let a=0;a<s;a++)i.push(cn(n[a],{modifiers:gc,structs:t,type:"function"}));const o=[];if(r.returns){const a=Ot(r.returns),c=a.length;for(let u=0;u<c;u++)o.push(cn(a[u],{modifiers:gc,structs:t,type:"function"}))}return{name:r.name,type:"function",stateMutability:r.stateMutability??"nonpayable",inputs:i,outputs:o}}function cm(e,t={}){const r=Fy(e);if(!r)throw new ai({signature:e,type:"event"});const n=Ot(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(cn(n[o],{modifiers:Wy,structs:t,type:"event"}));return{name:r.name,type:"event",inputs:i}}function um(e,t={}){const r=$y(e);if(!r)throw new ai({signature:e,type:"error"});const n=Ot(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(cn(n[o],{structs:t,type:"error"}));return{name:r.name,type:"error",inputs:i}}function fm(e,t={}){const r=jy(e);if(!r)throw new ai({signature:e,type:"constructor"});const n=Ot(r.parameters),i=[],s=n.length;for(let o=0;o<s;o++)i.push(cn(n[o],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:r.stateMutability??"nonpayable",inputs:i}}function dm(e){const t=qy(e);if(!t)throw new ai({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}const lm=/^(?<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$_]*))?$/,hm=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,pm=/^u?int$/;function cn(e,t){var d,y;const r=om(e,t==null?void 0:t.type,t==null?void 0:t.structs);if(_a.has(r))return _a.get(r);const n=Ul.test(e),i=_r(n?hm:lm,e);if(!i)throw new Xy({param:e});if(i.name&&mm(i.name))throw new Jy({param:e,name:i.name});const s=i.name?{name:i.name}:{},o=i.modifier==="indexed"?{indexed:!0}:{},a=(t==null?void 0:t.structs)??{};let c,u={};if(n){c="tuple";const p=Ot(i.type),w=[],b=p.length;for(let m=0;m<b;m++)w.push(cn(p[m],{structs:a}));u={components:w}}else if(i.type in a)c="tuple",u={components:a[i.type]};else if(pm.test(i.type))c=`${i.type}256`;else if(c=i.type,(t==null?void 0:t.type)!=="struct"&&!Gl(c))throw new Zy({type:c});if(i.modifier){if(!((y=(d=t==null?void 0:t.modifiers)==null?void 0:d.has)!=null&&y.call(d,i.modifier)))throw new Qy({param:e,type:t==null?void 0:t.type,modifier:i.modifier});if(gc.has(i.modifier)&&!bm(c,!!i.array))throw new em({param:e,type:t==null?void 0:t.type,modifier:i.modifier})}const f={type:`${c}${i.array??""}`,...s,...o,...u};return _a.set(r,f),f}function Ot(e,t=[],r="",n=0){const i=e.trim().length;for(let s=0;s<i;s++){const o=e[s],a=e.slice(s+1);switch(o){case",":return n===0?Ot(a,[...t,r.trim()]):Ot(a,t,`${r}${o}`,n);case"(":return Ot(a,t,`${r}${o}`,n+1);case")":return Ot(a,t,`${r}${o}`,n-1);default:return Ot(a,t,`${r}${o}`,n)}}if(r==="")return t;if(n!==0)throw new sm({current:r,depth:n});return t.push(r.trim()),t}function Gl(e){return e==="address"||e==="bool"||e==="function"||e==="string"||Ll.test(e)||Fl.test(e)}const ym=/^(?: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 mm(e){return e==="address"||e==="bool"||e==="function"||e==="string"||e==="tuple"||Ll.test(e)||Fl.test(e)||ym.test(e)}function bm(e,t){return t||e==="bytes"||e==="string"||e==="tuple"}function Vl(e){const t={},r=e.length;for(let o=0;o<r;o++){const a=e[o];if(!mu(a))continue;const c=Hy(a);if(!c)throw new ai({signature:a,type:"struct"});const u=c.properties.split(";"),f=[],d=u.length;for(let y=0;y<d;y++){const w=u[y].trim();if(!w)continue;const b=cn(w,{type:"struct"});f.push(b)}if(!f.length)throw new nm({signature:a});t[c.name]=f}const n={},i=Object.entries(t),s=i.length;for(let o=0;o<s;o++){const[a,c]=i[o];n[a]=Wl(c,t)}return n}const gm=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function Wl(e,t,r=new Set){const n=[],i=e.length;for(let s=0;s<i;s++){const o=e[s];if(Ul.test(o.type))n.push(o);else{const c=_r(gm,o.type);if(!(c!=null&&c.type))throw new tm({abiParameter:o});const{array:u,type:f}=c;if(f in t){if(r.has(f))throw new im({type:f});n.push({...o,type:`tuple${u??""}`,components:Wl(t[f]??[],t,new Set([...r,f]))})}else if(Gl(f))n.push(o);else throw new Yy({type:f})}}return n}function Kl(e){const t=Vl(e),r=[],n=e.length;for(let i=0;i<n;i++){const s=e[i];mu(s)||r.push(wc(s,t))}return r}function Of(e){let t;if(typeof e=="string")t=wc(e);else{const r=Vl(e),n=e.length;for(let i=0;i<n;i++){const s=e[i];if(!mu(s)){t=wc(s,r);break}}}if(!t)throw new Ky({signature:e});return t}function ee(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const i=e[r];return typeof i=="function"?i:s=>t(e,s)}function Nt(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new Cm(e.type);return`${e.name}(${Io(e.inputs,{includeName:t})})`}function Io(e,{includeName:t=!1}={}){return e?e.map(r=>wm(r,{includeName:t})).join(t?", ":","):""}function wm(e,{includeName:t}){return e.type.startsWith("tuple")?`(${Io(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}function $t(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Oe(e){return $t(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const Yl="2.28.0";let gi={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Yl}`},H=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,s=(a=gi.getDocsUrl)==null?void 0:a.call(gi,{...r,docsPath:i}),o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...gi.version?[`Version: ${gi.version}`]:[]].join(`
|
|
3
|
+
`);super(o,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=Yl}walk(t){return Zl(this,t)}};function Zl(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?Zl(e.cause,t):t?null:e}class vm extends H{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 Rf extends H{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 Xl extends H{constructor({data:t,params:r,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join(`
|
|
6
|
+
`),{metaMessages:[`Params: (${Io(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 vs extends H{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class _m extends H{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 xm extends H{constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${Oe(r)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class Em extends H{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 Am extends H{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 Nf extends H{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 Jl extends H{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 Sm extends H{constructor({docsPath:t}){super("Cannot extract event signature from empty topics.",{docsPath:t,name:"AbiEventSignatureEmptyTopicsError"})}}class Ql extends H{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 $f extends H{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 Yn extends H{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 eh extends H{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 Tm extends H{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 Pm extends H{constructor(t,r){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${t.type}\` in \`${Nt(t.abiItem)}\`, and`,`\`${r.type}\` in \`${Nt(r.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}let Bm=class extends H{constructor({expectedSize:t,givenSize:r}){super(`Expected bytes${t}, got bytes${r}.`,{name:"BytesSizeMismatchError"})}};class ji extends H{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: (${Io(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 ko extends H{constructor({abiItem:t,param:r}){super([`Expected a topic for indexed event parameter${r.name?` "${r.name}"`:""} on event "${Nt(t,{includeName:!0})}".`].join(`
|
|
18
|
+
`),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t}}class Im extends H{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 km extends H{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"})}}let th=class extends H{constructor(t){super([`Value "${t}" is not a valid array.`].join(`
|
|
21
|
+
`),{name:"InvalidArrayError"})}};class Cm extends H{constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(`
|
|
22
|
+
`),{name:"InvalidDefinitionTypeError"})}}class Om extends H{constructor(t){super(`Filter type "${t}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}let rh=class extends H{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}},nh=class extends H{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 Lf extends H{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 ci(e,{dir:t,size:r=32}={}){return typeof e=="string"?Fr(e,{dir:t,size:r}):Rm(e,{dir:t,size:r})}function Fr(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new nh({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function Rm(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new nh({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const s=t==="right";n[s?i:r-i-1]=e[s?i:e.length-i-1]}return n}let ih=class extends H{constructor({max:t,min:r,signed:n,size:i,value:s}){super(`Number "${s}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}};class Nm extends H{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 $m extends H{constructor(t){super(`Hex value "${t}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let Lm=class extends H{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}};function Rt(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 Ut(e,{size:t}){if(Oe(e)>t)throw new Lm({givenSize:Oe(e),maxSize:t})}function Ze(e,t={}){const{signed:r}=t;t.size&&Ut(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,s=(1n<<BigInt(i)*8n-1n)-1n;return n<=s?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function Fm(e,t={}){let r=e;if(t.size&&(Ut(r,{size:t.size}),r=Rt(r)),Rt(r)==="0x00")return!1;if(Rt(r)==="0x01")return!0;throw new $m(r)}function Lt(e,t={}){return Number(Ze(e,t))}const Um=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ie(e,t={}){return typeof e=="number"||typeof e=="bigint"?te(e,t):typeof e=="string"?Zn(e,t):typeof e=="boolean"?sh(e,t):Me(e,t)}function sh(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Ut(r,{size:t.size}),ci(r,{size:t.size})):r}function Me(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=Um[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Ut(n,{size:t.size}),ci(n,{dir:"right",size:t.size})):n}function te(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const c=typeof e=="bigint"?"n":"";throw new ih({max:s?`${s}${c}`:void 0,min:`${o}${c}`,signed:r,size:n,value:`${e}${c}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?ci(a,{size:n}):a}const Mm=new TextEncoder;function Zn(e,t={}){const r=Mm.encode(e);return Me(r,t)}const Hm=new TextEncoder;function ui(e,t={}){return typeof e=="number"||typeof e=="bigint"?jm(e,t):typeof e=="boolean"?Dm(e,t):$t(e)?Ft(e,t):rn(e,t)}function Dm(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Ut(r,{size:t.size}),ci(r,{size:t.size})):r}const tr={zero:48,nine:57,A:65,F:70,a:97,f:102};function Ff(e){if(e>=tr.zero&&e<=tr.nine)return e-tr.zero;if(e>=tr.A&&e<=tr.F)return e-(tr.A-10);if(e>=tr.a&&e<=tr.f)return e-(tr.a-10)}function Ft(e,t={}){let r=e;t.size&&(Ut(r,{size:t.size}),r=ci(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,s=new Uint8Array(i);for(let o=0,a=0;o<i;o++){const c=Ff(n.charCodeAt(a++)),u=Ff(n.charCodeAt(a++));if(c===void 0||u===void 0)throw new H(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+u}return s}function jm(e,t){const r=te(e,t);return Ft(r)}function rn(e,t={}){const r=Hm.encode(e);return typeof t.size=="number"?(Ut(r,{size:t.size}),ci(r,{dir:"right",size:t.size})):r}function vo(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function zm(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function _s(e,...t){if(!zm(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 qm(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");vo(e.outputLen),vo(e.blockLen)}function Xn(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 oh(e,t){_s(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const js=BigInt(2**32-1),Uf=BigInt(32);function Gm(e,t=!1){return t?{h:Number(e&js),l:Number(e>>Uf&js)}:{h:Number(e>>Uf&js)|0,l:Number(e&js)|0}}function Vm(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:s,l:o}=Gm(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const Wm=(e,t,r)=>e<<r|t>>>32-r,Km=(e,t,r)=>t<<r|e>>>32-r,Ym=(e,t,r)=>t<<r-32|e>>>64-r,Zm=(e,t,r)=>e<<r-32|t>>>64-r,In=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Xm(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function xa(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}const Mf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Jm(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Hf(e){for(let t=0;t<e.length;t++)e[t]=Jm(e[t])}typeof Uint8Array.from([]).toHex=="function"&&Uint8Array.fromHex;function Qm(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function Co(e){return typeof e=="string"&&(e=Qm(e)),_s(e),e}function eb(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];_s(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}let bu=class{clone(){return this._cloneInto()}};function ah(e){const t=n=>e().update(Co(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function tb(e=32){if(In&&typeof In.getRandomValues=="function")return In.getRandomValues(new Uint8Array(e));if(In&&typeof In.randomBytes=="function")return Uint8Array.from(In.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const ch=[],uh=[],fh=[],rb=BigInt(0),wi=BigInt(1),nb=BigInt(2),ib=BigInt(7),sb=BigInt(256),ob=BigInt(113);for(let e=0,t=wi,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],ch.push(2*(5*n+r)),uh.push((e+1)*(e+2)/2%64);let i=rb;for(let s=0;s<7;s++)t=(t<<wi^(t>>ib)*ob)%sb,t&nb&&(i^=wi<<(wi<<BigInt(s))-wi);fh.push(i)}const[ab,cb]=Vm(fh,!0),Df=(e,t,r)=>r>32?Ym(e,t,r):Wm(e,t,r),jf=(e,t,r)=>r>32?Zm(e,t,r):Km(e,t,r);function ub(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)r[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,u=r[c],f=r[c+1],d=Df(u,f,1)^r[a],y=jf(u,f,1)^r[a+1];for(let p=0;p<50;p+=10)e[o+p]^=d,e[o+p+1]^=y}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=uh[o],c=Df(i,s,a),u=jf(i,s,a),f=ch[o];i=e[f],s=e[f+1],e[f]=c,e[f+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=ab[n],e[1]^=cb[n]}r.fill(0)}let fb=class dh extends bu{constructor(t,r,n,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,vo(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Xm(this.state)}keccak(){Mf||Hf(this.state32),ub(this.state32,this.rounds),Mf||Hf(this.state32),this.posOut=0,this.pos=0}update(t){Xn(this);const{blockLen:r,state:n}=this;t=Co(t);const i=t.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=t[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){Xn(this,!1),_s(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=t.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);t.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return vo(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(oh(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return t||(t=new dh(r,n,i,o,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}};const db=(e,t,r)=>ah(()=>new fb(t,e,r)),lb=db(1,136,256/8);function Xe(e,t){const r=t||"hex",n=lb($t(e,{strict:!1})?ui(e):e);return r==="bytes"?n:ie(n)}const hb=e=>Xe(ui(e));function pb(e){return hb(e)}function yb(e){let t=!0,r="",n=0,i="",s=!1;for(let o=0;o<e.length;o++){const a=e[o];if(["(",")",","].includes(a)&&(t=!0),a==="("&&n++,a===")"&&n--,!!t){if(n===0){if(a===" "&&["event","function",""].includes(i))i="";else if(i+=a,a===")"){s=!0;break}continue}if(a===" "){e[o-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!s)throw new H("Unable to normalize signature.");return i}const mb=e=>{const t=typeof e=="string"?e:wo(e);return yb(t)};function lh(e){return pb(mb(e))}const Oo=lh;let dt=class extends H{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"})}},Ro=class 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 Ea=new Ro(8192);function xs(e,t){if(Ea.has(`${e}.${t}`))return Ea.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Xe(rn(r),"bytes"),i=r.split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return Ea.set(`${e}.${t}`,s),s}function hh(e,t){if(!Ve(e,{strict:!1}))throw new dt({address:e});return xs(e,t)}const bb=/^0x[a-fA-F0-9]{40}$/,Aa=new Ro(8192);function Ve(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Aa.has(n))return Aa.get(n);const i=bb.test(e)?e.toLowerCase()===e?!0:r?xs(e)===e:!0:!1;return Aa.set(n,i),i}function Jt(e){return typeof e[0]=="string"?Mt(e):gb(e)}function gb(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 Mt(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function un(e,t,r,{strict:n}={}){return $t(e,{strict:!1})?bh(e,t,r,{strict:n}):mh(e,t,r,{strict:n})}function ph(e,t){if(typeof t=="number"&&t>0&&t>Oe(e)-1)throw new rh({offset:t,position:"start",size:Oe(e)})}function yh(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Oe(e)!==r-t)throw new rh({offset:r,position:"end",size:Oe(e)})}function mh(e,t,r,{strict:n}={}){ph(e,t);const i=e.slice(t,r);return n&&yh(i,t,r),i}function bh(e,t,r,{strict:n}={}){ph(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return n&&yh(i,t,r),i}const wb=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,gh=/^(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 xr(e,t){if(e.length!==t.length)throw new Em({expectedLength:e.length,givenLength:t.length});const r=vb({params:e,values:t}),n=wu(r);return n.length===0?"0x":n}function vb({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(gu({param:e[n],value:t[n]}));return r}function gu({param:e,value:t}){const r=vu(e.type);if(r){const[n,i]=r;return xb(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return Pb(t,{param:e});if(e.type==="address")return _b(t);if(e.type==="bool")return Ab(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=gh.exec(e.type)??[];return Sb(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return Eb(t,{param:e});if(e.type==="string")return Tb(t);throw new Im(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function wu(e){let t=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?t+=32:t+=Oe(a)}const r=[],n=[];let i=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?(r.push(te(t+i,{size:32})),n.push(a),i+=Oe(a)):r.push(a)}return Jt([...r,...n])}function _b(e){if(!Ve(e))throw new dt({address:e});return{dynamic:!1,encoded:Fr(e.toLowerCase())}}function xb(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new th(e);if(!n&&e.length!==t)throw new _m({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const s=[];for(let o=0;o<e.length;o++){const a=gu({param:r,value:e[o]});a.dynamic&&(i=!0),s.push(a)}if(n||i){const o=wu(s);if(n){const a=te(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?Jt([a,o]):a}}if(i)return{dynamic:!0,encoded:o}}return{dynamic:!1,encoded:Jt(s.map(({encoded:o})=>o))}}function Eb(e,{param:t}){const[,r]=t.type.split("bytes"),n=Oe(e);if(!r){let i=e;return n%32!==0&&(i=Fr(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:Jt([Fr(te(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new xm({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:Fr(e,{dir:"right"})}}function Ab(e){if(typeof e!="boolean")throw new H(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:Fr(sh(e))}}function Sb(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 ih({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:te(e,{size:32,signed:t})}}function Tb(e){const t=Zn(e),r=Math.ceil(Oe(t)/32),n=[];for(let i=0;i<r;i++)n.push(Fr(un(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:Jt([Fr(te(Oe(t),{size:32})),...n])}}function Pb(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const s=t.components[i],o=Array.isArray(e)?i:s.name,a=gu({param:s,value:e[o]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?wu(n):Jt(n.map(({encoded:i})=>i))}}function vu(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Es=e=>un(lh(e),0,4);function wn(e){const{abi:t,args:r=[],name:n}=e,i=$t(n,{strict:!1}),s=t.filter(a=>i?a.type==="function"?Es(a)===n:a.type==="event"?Oo(a)===n:!1:"name"in a&&a.name===n);if(s.length===0)return;if(s.length===1)return s[0];let o;for(const a of s){if(!("inputs"in a))continue;if(!r||r.length===0){if(!a.inputs||a.inputs.length===0)return a;continue}if(!a.inputs||a.inputs.length===0||a.inputs.length!==r.length)continue;if(r.every((u,f)=>{const d="inputs"in a&&a.inputs[f];return d?_c(u,d):!1})){if(o&&"inputs"in o&&o.inputs){const u=wh(a.inputs,o.inputs,r);if(u)throw new Pm({abiItem:a,type:u[0]},{abiItem:o,type:u[1]})}o=a}}return o||s[0]}function _c(e,t){const r=typeof e,n=t.type;switch(n){case"address":return Ve(e,{strict:!1});case"bool":return r==="boolean";case"function":return r==="string";case"string":return r==="string";default:return n==="tuple"&&"components"in t?Object.values(t.components).every((i,s)=>_c(Object.values(e)[s],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?r==="number"||r==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?r==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(e)&&e.every(i=>_c(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function wh(e,t,r){for(const n in e){const i=e[n],s=t[n];if(i.type==="tuple"&&s.type==="tuple"&&"components"in i&&"components"in s)return wh(i.components,s.components,r[n]);const o=[i.type,s.type];if(o.includes("address")&&o.includes("bytes20")?!0:o.includes("address")&&o.includes("string")?Ve(r[n],{strict:!1}):o.includes("address")&&o.includes("bytes")?Ve(r[n],{strict:!1}):!1)return o}}const zf="/docs/contract/encodeEventTopics";function As(e){var c;const{abi:t,eventName:r,args:n}=e;let i=t[0];if(r){const u=wn({abi:t,name:r});if(!u)throw new $f(r,{docsPath:zf});i=u}if(i.type!=="event")throw new $f(void 0,{docsPath:zf});const s=Nt(i),o=Oo(s);let a=[];if(n&&"inputs"in i){const u=(c=i.inputs)==null?void 0:c.filter(d=>"indexed"in d&&d.indexed),f=Array.isArray(n)?n:Object.values(n).length>0?(u==null?void 0:u.map(d=>n[d.name]))??[]:[];f.length>0&&(a=(u==null?void 0:u.map((d,y)=>Array.isArray(f[y])?f[y].map((p,w)=>qf({param:d,value:f[y][w]})):typeof f[y]<"u"&&f[y]!==null?qf({param:d,value:f[y]}):null))??[])}return[o,...a]}function qf({param:e,value:t}){if(e.type==="string"||e.type==="bytes")return Xe(ui(t));if(e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/))throw new Om(e.type);return xr([e],[t])}function No(e,{method:t}){var n,i;const r={};return e.transport.type==="fallback"&&((i=(n=e.transport).onResponse)==null||i.call(n,({method:s,response:o,status:a,transport:c})=>{a==="success"&&t===s&&(r[o]=c.request)})),s=>r[s]||e.request}async function _u(e,t){const{address:r,abi:n,args:i,eventName:s,fromBlock:o,strict:a,toBlock:c}=t,u=No(e,{method:"eth_newFilter"}),f=s?As({abi:n,args:i,eventName:s}):void 0,d=await e.request({method:"eth_newFilter",params:[{address:r,fromBlock:typeof o=="bigint"?te(o):o,toBlock:typeof c=="bigint"?te(c):c,topics:f}]});return{abi:n,args:i,eventName:s,id:d,request:u(d),strict:!!a,type:"event"}}function $e(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}const Gf="/docs/contract/encodeFunctionData";function Bb(e){const{abi:t,args:r,functionName:n}=e;let i=t[0];if(n){const s=wn({abi:t,args:r,name:n});if(!s)throw new Yn(n,{docsPath:Gf});i=s}if(i.type!=="function")throw new Yn(void 0,{docsPath:Gf});return{abi:[i],functionName:Es(Nt(i))}}function Pt(e){const{args:t}=e,{abi:r,functionName:n}=(()=>{var a;return e.abi.length===1&&((a=e.functionName)!=null&&a.startsWith("0x"))?e:Bb(e)})(),i=r[0],s=n,o="inputs"in i&&i.inputs?xr(i.inputs,t??[]):void 0;return Mt([s,o??"0x"])}const vh={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."},_h={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},Ib={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class Vf extends H{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class xh extends H{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class kb extends H{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Cb={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 kb({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new xh({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new Vf({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 Vf({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 xu(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(Cb);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function Ob(e,t={}){typeof t.size<"u"&&Ut(e,{size:t.size});const r=Me(e,t);return Ze(r,t)}function Rb(e,t={}){let r=e;if(typeof t.size<"u"&&(Ut(r,{size:t.size}),r=Rt(r)),r.length>1||r[0]>1)throw new Nm(r);return!!r[0]}function hr(e,t={}){typeof t.size<"u"&&Ut(e,{size:t.size});const r=Me(e,t);return Lt(r,t)}function Nb(e,t={}){let r=e;return typeof t.size<"u"&&(Ut(r,{size:t.size}),r=Rt(r,{dir:"right"})),new TextDecoder().decode(r)}function Ss(e,t){const r=typeof t=="string"?Ft(t):t,n=xu(r);if(Oe(r)===0&&e.length>0)throw new vs;if(Oe(t)&&Oe(t)<32)throw new Xl({data:typeof t=="string"?t:Me(t),params:e,size:Oe(t)});let i=0;const s=[];for(let o=0;o<e.length;++o){const a=e[o];n.setPosition(i);const[c,u]=Hn(n,a,{staticPosition:0});i+=u,s.push(c)}return s}function Hn(e,t,{staticPosition:r}){const n=vu(t.type);if(n){const[i,s]=n;return Lb(e,{...t,type:s},{length:i,staticPosition:r})}if(t.type==="tuple")return Hb(e,t,{staticPosition:r});if(t.type==="address")return $b(e);if(t.type==="bool")return Fb(e);if(t.type.startsWith("bytes"))return Ub(e,t,{staticPosition:r});if(t.type.startsWith("uint")||t.type.startsWith("int"))return Mb(e,t);if(t.type==="string")return Db(e,{staticPosition:r});throw new km(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const Wf=32,xc=32;function $b(e){const t=e.readBytes(32);return[xs(Me(mh(t,-20))),32]}function Lb(e,t,{length:r,staticPosition:n}){if(!r){const o=hr(e.readBytes(xc)),a=n+o,c=a+Wf;e.setPosition(a);const u=hr(e.readBytes(Wf)),f=zi(t);let d=0;const y=[];for(let p=0;p<u;++p){e.setPosition(c+(f?p*32:d));const[w,b]=Hn(e,t,{staticPosition:c});d+=b,y.push(w)}return e.setPosition(n+32),[y,32]}if(zi(t)){const o=hr(e.readBytes(xc)),a=n+o,c=[];for(let u=0;u<r;++u){e.setPosition(a+u*32);const[f]=Hn(e,t,{staticPosition:a});c.push(f)}return e.setPosition(n+32),[c,32]}let i=0;const s=[];for(let o=0;o<r;++o){const[a,c]=Hn(e,t,{staticPosition:n+i});i+=c,s.push(a)}return[s,i]}function Fb(e){return[Rb(e.readBytes(32),{size:32}),32]}function Ub(e,t,{staticPosition:r}){const[n,i]=t.type.split("bytes");if(!i){const o=hr(e.readBytes(32));e.setPosition(r+o);const a=hr(e.readBytes(32));if(a===0)return e.setPosition(r+32),["0x",32];const c=e.readBytes(a);return e.setPosition(r+32),[Me(c),32]}return[Me(e.readBytes(Number.parseInt(i),32)),32]}function Mb(e,t){const r=t.type.startsWith("int"),n=Number.parseInt(t.type.split("int")[1]||"256"),i=e.readBytes(32);return[n>48?Ob(i,{signed:r}):hr(i,{signed:r}),32]}function Hb(e,t,{staticPosition:r}){const n=t.components.length===0||t.components.some(({name:o})=>!o),i=n?[]:{};let s=0;if(zi(t)){const o=hr(e.readBytes(xc)),a=r+o;for(let c=0;c<t.components.length;++c){const u=t.components[c];e.setPosition(a+s);const[f,d]=Hn(e,u,{staticPosition:a});s+=d,i[n?c:u==null?void 0:u.name]=f}return e.setPosition(r+32),[i,32]}for(let o=0;o<t.components.length;++o){const a=t.components[o],[c,u]=Hn(e,a,{staticPosition:r});i[n?o:a==null?void 0:a.name]=c,s+=u}return[i,s]}function Db(e,{staticPosition:t}){const r=hr(e.readBytes(32)),n=t+r;e.setPosition(n);const i=hr(e.readBytes(32));if(i===0)return e.setPosition(t+32),["",32];const s=e.readBytes(i,32),o=Nb(Rt(s));return e.setPosition(t+32),[o,32]}function zi(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(zi);const r=vu(e.type);return!!(r&&zi({...e,type:r[1]}))}function Eh(e){const{abi:t,data:r}=e,n=un(r,0,4);if(n==="0x")throw new vs;const s=[...t||[],_h,Ib].find(o=>o.type==="error"&&n===Es(Nt(o)));if(!s)throw new Jl(n,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:s,args:"inputs"in s&&s.inputs&&s.inputs.length>0?Ss(s.inputs,un(r,4)):void 0,errorName:s.name}}const Ue=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);function Ah({abiItem:e,args:t,includeFunctionName:r=!0,includeName:n=!1}){if("name"in e&&"inputs"in e&&e.inputs)return`${r?e.name:""}(${e.inputs.map((i,s)=>`${n&&i.name?`${i.name}: `:""}${typeof t[s]=="object"?Ue(t[s]):t[s]}`).join(", ")})`}const jb={gwei:9,wei:18},zb={ether:-9,wei:9};function Sh(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,s]=[r.slice(0,r.length-t),r.slice(r.length-t)];return s=s.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${s?`.${s}`:""}`}function Eu(e,t="wei"){return Sh(e,jb[t])}function pt(e,t="wei"){return Sh(e,zb[t])}class qb extends H{constructor({address:t}){super(`State for account "${t}" is set multiple times.`,{name:"AccountStateConflictError"})}}class Gb extends H{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function Kf(e){return e.reduce((t,{slot:r,value:n})=>`${t} ${r}: ${n}
|
|
23
|
+
`,"")}function Vb(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+=Kf(n.state)),n.stateDiff&&(i+=` stateDiff:
|
|
29
|
+
`,i+=Kf(n.stateDiff)),i},` State Override:
|
|
30
|
+
`).slice(0,-1)}function Ts(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 Wb extends H{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 Kb extends H{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class Yb extends H{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Ts(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 Zb extends H{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 Xb extends H{constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:f,to:d,value:y}){var w;const p=Ts({chain:i&&`${i==null?void 0:i.name} (id: ${i==null?void 0:i.id})`,from:r==null?void 0:r.address,to:d,value:typeof y<"u"&&`${Eu(y)} ${((w=i==null?void 0:i.nativeCurrency)==null?void 0:w.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${pt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${pt(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${pt(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}}class Th extends H{constructor({blockHash:t,blockNumber:r,blockTag:n,hash:i,index:s}){let o="Transaction";n&&s!==void 0&&(o=`Transaction at block time "${n}" at index "${s}"`),t&&s!==void 0&&(o=`Transaction at block hash "${t}" at index "${s}"`),r&&s!==void 0&&(o=`Transaction at block number "${r}" at index "${s}"`),i&&(o=`Transaction with hash "${i}"`),super(`${o} could not be found.`,{name:"TransactionNotFoundError"})}}class Ph extends H{constructor({hash:t}){super(`Transaction receipt with hash "${t}" could not be found. The Transaction may not be processed on a block yet.`,{name:"TransactionReceiptNotFoundError"})}}class Jb extends H{constructor({hash:t}){super(`Timed out while waiting for transaction with hash "${t}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}}const Qb=e=>e,$o=e=>e;class Bh extends H{constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:f,to:d,value:y,stateOverride:p}){var m;const w=r?$e(r):void 0;let b=Ts({from:w==null?void 0:w.address,to:d,value:typeof y<"u"&&`${Eu(y)} ${((m=i==null?void 0:i.nativeCurrency)==null?void 0:m.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${pt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${pt(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${pt(u)} gwei`,nonce:f});p&&(b+=`
|
|
33
|
+
${Vb(p)}`),super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Raw Call Arguments:",b].filter(Boolean),name:"CallExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class e1 extends H{constructor(t,{abi:r,args:n,contractAddress:i,docsPath:s,functionName:o,sender:a}){const c=wn({abi:r,args:n,name:o}),u=c?Ah({abiItem:c,args:n,includeFunctionName:!1,includeName:!1}):void 0,f=c?Nt(c,{includeName:!0}):void 0,d=Ts({address:i&&Qb(i),function:f,args:u&&u!=="()"&&`${[...Array((o==null?void 0:o.length)??0).keys()].map(()=>" ").join("")}${u}`,sender:a});super(t.shortMessage||`An unknown error occurred while executing the contract function "${o}".`,{cause:t,docsPath:s,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],d&&"Contract Call:",d].filter(Boolean),name:"ContractFunctionExecutionError"}),Object.defineProperty(this,"abi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"args",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"contractAddress",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"formattedArgs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"functionName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sender",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abi=r,this.args=n,this.cause=t,this.contractAddress=i,this.functionName=o,this.sender=a}}class Ec extends H{constructor({abi:t,data:r,functionName:n,message:i}){let s,o,a,c;if(r&&r!=="0x")try{o=Eh({abi:t,data:r});const{abiItem:f,errorName:d,args:y}=o;if(d==="Error")c=y[0];else if(d==="Panic"){const[p]=y;c=vh[p]}else{const p=f?Nt(f,{includeName:!0}):void 0,w=f&&y?Ah({abiItem:f,args:y,includeFunctionName:!1,includeName:!1}):void 0;a=[p?`Error: ${p}`:"",w&&w!=="()"?` ${[...Array((d==null?void 0:d.length)??0).keys()].map(()=>" ").join("")}${w}`:""]}}catch(f){s=f}else i&&(c=i);let u;s instanceof Jl&&(u=s.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:s,metaMessages:a,name:"ContractFunctionRevertedError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"reason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=o,this.raw=r,this.reason=c,this.signature=u}}class t1 extends H{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 r1 extends H{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 Lo extends H{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 Dn extends H{constructor({body:t,cause:r,details:n,headers:i,status:s,url:o}){super("HTTP request failed.",{cause:r,details:n,metaMessages:[s&&`Status: ${s}`,`URL: ${$o(o)}`,t&&`Request body: ${Ue(t)}`].filter(Boolean),name:"HttpRequestError"}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"url",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.body=t,this.headers=i,this.status=s,this.url=o}}class Au extends H{constructor({body:t,error:r,url:n}){super("RPC Request failed.",{cause:r,details:r.message,metaMessages:[`URL: ${$o(n)}`,`Request body: ${Ue(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 Yf extends H{constructor({body:t,url:r}){super("The request took too long to respond.",{details:"The request timed out.",metaMessages:[`URL: ${$o(r)}`,`Request body: ${Ue(t)}`],name:"TimeoutError"})}}const n1=-1;class yt extends H{constructor(t,{code:r,docsPath:n,metaMessages:i,name:s,shortMessage:o}){super(o,{cause:t,docsPath:n,metaMessages:i||(t==null?void 0:t.metaMessages),name:s||"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=s||t.name,this.code=t instanceof Au?t.code:r??n1}}class wt extends yt{constructor(t,r){super(t,r),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=r.data}}class qi extends yt{constructor(t){super(t,{code:qi.code,name:"ParseRpcError",shortMessage:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."})}}Object.defineProperty(qi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32700});class Gi extends yt{constructor(t){super(t,{code:Gi.code,name:"InvalidRequestRpcError",shortMessage:"JSON is not a valid request object."})}}Object.defineProperty(Gi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32600});class Vi extends yt{constructor(t,{method:r}={}){super(t,{code:Vi.code,name:"MethodNotFoundRpcError",shortMessage:`The method${r?` "${r}"`:""} does not exist / is not available.`})}}Object.defineProperty(Vi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32601});class Wi extends yt{constructor(t){super(t,{code:Wi.code,name:"InvalidParamsRpcError",shortMessage:["Invalid parameters were provided to the RPC method.","Double check you have provided the correct parameters."].join(`
|
|
35
|
+
`)})}}Object.defineProperty(Wi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32602});class fn extends yt{constructor(t){super(t,{code:fn.code,name:"InternalRpcError",shortMessage:"An internal error was received."})}}Object.defineProperty(fn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32603});class dn extends yt{constructor(t){super(t,{code:dn.code,name:"InvalidInputRpcError",shortMessage:["Missing or invalid parameters.","Double check you have provided the correct parameters."].join(`
|
|
36
|
+
`)})}}Object.defineProperty(dn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32e3});class Ki extends yt{constructor(t){super(t,{code:Ki.code,name:"ResourceNotFoundRpcError",shortMessage:"Requested resource not found."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceNotFoundRpcError"})}}Object.defineProperty(Ki,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32001});class Yi extends yt{constructor(t){super(t,{code:Yi.code,name:"ResourceUnavailableRpcError",shortMessage:"Requested resource not available."})}}Object.defineProperty(Yi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32002});class Zi extends yt{constructor(t){super(t,{code:Zi.code,name:"TransactionRejectedRpcError",shortMessage:"Transaction creation failed."})}}Object.defineProperty(Zi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32003});class en extends yt{constructor(t,{method:r}={}){super(t,{code:en.code,name:"MethodNotSupportedRpcError",shortMessage:`Method${r?` "${r}"`:""} is not supported.`})}}Object.defineProperty(en,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32004});class Jn extends yt{constructor(t){super(t,{code:Jn.code,name:"LimitExceededRpcError",shortMessage:"Request exceeds defined limit."})}}Object.defineProperty(Jn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32005});class Xi extends yt{constructor(t){super(t,{code:Xi.code,name:"JsonRpcVersionUnsupportedError",shortMessage:"Version of JSON-RPC protocol is not supported."})}}Object.defineProperty(Xi,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32006});class jn extends wt{constructor(t){super(t,{code:jn.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(jn,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class Ji extends wt{constructor(t){super(t,{code:Ji.code,name:"UnauthorizedProviderError",shortMessage:"The requested method and/or account has not been authorized by the user."})}}Object.defineProperty(Ji,"code",{enumerable:!0,configurable:!0,writable:!0,value:4100});class Qi extends wt{constructor(t,{method:r}={}){super(t,{code:Qi.code,name:"UnsupportedProviderMethodError",shortMessage:`The Provider does not support the requested method${r?` " ${r}"`:""}.`})}}Object.defineProperty(Qi,"code",{enumerable:!0,configurable:!0,writable:!0,value:4200});class es extends wt{constructor(t){super(t,{code:es.code,name:"ProviderDisconnectedError",shortMessage:"The Provider is disconnected from all chains."})}}Object.defineProperty(es,"code",{enumerable:!0,configurable:!0,writable:!0,value:4900});class ts extends wt{constructor(t){super(t,{code:ts.code,name:"ChainDisconnectedError",shortMessage:"The Provider is not connected to the requested chain."})}}Object.defineProperty(ts,"code",{enumerable:!0,configurable:!0,writable:!0,value:4901});class rs extends wt{constructor(t){super(t,{code:rs.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(rs,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class ns extends wt{constructor(t){super(t,{code:ns.code,name:"UnsupportedNonOptionalCapabilityError",shortMessage:"This Wallet does not support a capability that was not marked as optional."})}}Object.defineProperty(ns,"code",{enumerable:!0,configurable:!0,writable:!0,value:5700});class is extends wt{constructor(t){super(t,{code:is.code,name:"UnsupportedChainIdError",shortMessage:"This Wallet does not support the requested chain ID."})}}Object.defineProperty(is,"code",{enumerable:!0,configurable:!0,writable:!0,value:5710});class ss extends wt{constructor(t){super(t,{code:ss.code,name:"DuplicateIdError",shortMessage:"There is already a bundle submitted with this ID."})}}Object.defineProperty(ss,"code",{enumerable:!0,configurable:!0,writable:!0,value:5720});class os extends wt{constructor(t){super(t,{code:os.code,name:"UnknownBundleIdError",shortMessage:"This bundle id is unknown / has not been submitted"})}}Object.defineProperty(os,"code",{enumerable:!0,configurable:!0,writable:!0,value:5730});class as extends wt{constructor(t){super(t,{code:as.code,name:"BundleTooLargeError",shortMessage:"The call bundle is too large for the Wallet to process."})}}Object.defineProperty(as,"code",{enumerable:!0,configurable:!0,writable:!0,value:5740});class cs extends wt{constructor(t){super(t,{code:cs.code,name:"AtomicReadyWalletRejectedUpgradeError",shortMessage:"The Wallet can support atomicity after an upgrade, but the user rejected the upgrade."})}}Object.defineProperty(cs,"code",{enumerable:!0,configurable:!0,writable:!0,value:5750});class us extends wt{constructor(t){super(t,{code:us.code,name:"AtomicityNotSupportedError",shortMessage:"The wallet does not support atomic execution but the request requires it."})}}Object.defineProperty(us,"code",{enumerable:!0,configurable:!0,writable:!0,value:5760});class i1 extends yt{constructor(t){super(t,{name:"UnknownRpcError",shortMessage:"An unknown RPC error occurred."})}}const s1=3;function ln(e,{abi:t,address:r,args:n,docsPath:i,functionName:s,sender:o}){const a=e instanceof Lo?e:e instanceof H?e.walk(w=>"data"in w)||e.walk():{},{code:c,data:u,details:f,message:d,shortMessage:y}=a,p=e instanceof vs?new t1({functionName:s}):[s1,fn.code].includes(c)&&(u||f||d||y)?new Ec({abi:t,data:typeof u=="object"?u.data:u,functionName:s,message:a instanceof Au?f:y??d}):e;return new e1(p,{abi:t,args:n,contractAddress:r,docsPath:i,functionName:s,sender:o})}function o1(e){const t=Xe(`0x${e.substring(4)}`).substring(26);return xs(`0x${t}`)}async function a1({hash:e,signature:t}){const r=$t(e)?e:ie(e),{secp256k1:n}=await Promise.resolve().then(()=>Iv);return`0x${(()=>{if(typeof t=="object"&&"r"in t&&"s"in t){const{r:u,s:f,v:d,yParity:y}=t,p=Number(y??d),w=Zf(p);return new n.Signature(Ze(u),Ze(f)).addRecoveryBit(w)}const o=$t(t)?t:ie(t),a=Lt(`0x${o.slice(130)}`),c=Zf(a);return n.Signature.fromCompact(o.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function Zf(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 Ih({hash:e,signature:t}){return o1(await a1({hash:e,signature:t}))}function Hr(e,t="hex"){const r=kh(e),n=xu(new Uint8Array(r.length));return r.encode(n),t==="hex"?Me(n.bytes):n.bytes}function kh(e){return Array.isArray(e)?c1(e.map(t=>kh(t))):u1(e)}function c1(e){const t=e.reduce((i,s)=>i+s.length,0),r=Ch(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:s}of e)s(i)}}}function u1(e){const t=typeof e=="string"?Ft(e):e,r=Ch(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 Ch(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 H("Length is too large.")}function f1(e){const{chainId:t,nonce:r,to:n}=e,i=e.contractAddress??e.address,s=Xe(Mt(["0x05",Hr([t?te(t):"0x",i,r?te(r):"0x"])]));return n==="bytes"?Ft(s):s}async function Oh(e){const{authorization:t,signature:r}=e;return Ih({hash:f1(t),signature:r??t})}class d1 extends H{constructor(t,{account:r,docsPath:n,chain:i,data:s,gas:o,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:f,to:d,value:y}){var w;const p=Ts({from:r==null?void 0:r.address,to:d,value:typeof y<"u"&&`${Eu(y)} ${((w=i==null?void 0:i.nativeCurrency)==null?void 0:w.symbol)||"ETH"}`,data:s,gas:o,gasPrice:typeof a<"u"&&`${pt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${pt(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${pt(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 Un extends H{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(Un,"code",{enumerable:!0,configurable:!0,writable:!0,value:3});Object.defineProperty(Un,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class hn extends H{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${pt(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(hn,"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 Ac extends H{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${pt(r)}`:""} gwei) cannot be lower than the block base fee.`,{cause:t,name:"FeeCapTooLowError"})}}Object.defineProperty(Ac,"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 Sc extends H{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(Sc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class Tc extends H{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(Tc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class Pc extends H{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 Bc extends H{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(Bc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class Ic extends H{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 kc extends H{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(kc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class Cc extends H{constructor({cause:t}){super("The transaction type is not supported for this chain.",{cause:t,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty(Cc,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class fs extends H{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${pt(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${pt(n)} gwei`:""}).`].join(`
|
|
39
|
+
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(fs,"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 Ps extends H{constructor({cause:t}){super(`An error occurred while executing: ${t==null?void 0:t.shortMessage}`,{cause:t,name:"UnknownNodeError"})}}function Fo(e,t){const r=(e.details||"").toLowerCase(),n=e instanceof H?e.walk(i=>(i==null?void 0:i.code)===Un.code):e;return n instanceof H?new Un({cause:e,message:n.details}):Un.nodeMessage.test(r)?new Un({cause:e,message:e.details}):hn.nodeMessage.test(r)?new hn({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):Ac.nodeMessage.test(r)?new Ac({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):Sc.nodeMessage.test(r)?new Sc({cause:e,nonce:t==null?void 0:t.nonce}):Tc.nodeMessage.test(r)?new Tc({cause:e,nonce:t==null?void 0:t.nonce}):Pc.nodeMessage.test(r)?new Pc({cause:e,nonce:t==null?void 0:t.nonce}):Bc.nodeMessage.test(r)?new Bc({cause:e}):Ic.nodeMessage.test(r)?new Ic({cause:e,gas:t==null?void 0:t.gas}):kc.nodeMessage.test(r)?new kc({cause:e,gas:t==null?void 0:t.gas}):Cc.nodeMessage.test(r)?new Cc({cause:e}):fs.nodeMessage.test(r)?new fs({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas,maxPriorityFeePerGas:t==null?void 0:t.maxPriorityFeePerGas}):new Ps({cause:e})}function l1(e,{docsPath:t,...r}){const n=(()=>{const i=Fo(e,r);return i instanceof Ps?e:i})();return new d1(n,{docsPath:t,...r})}function Uo(e,{format:t}){if(!t)return{};const r={};function n(s){const o=Object.keys(s);for(const a of o)a in e&&(r[a]=e[a]),s[a]&&typeof s[a]=="object"&&!Array.isArray(s[a])&&n(s[a])}const i=t(e||{});return n(i),r}function Su(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const s=t(i);if(r)for(const o of r)delete s[o];return{...s,...n(i)}},type:e})}const h1={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function fi(e){const t={};return typeof e.authorizationList<"u"&&(t.authorizationList=p1(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=>Me(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=te(e.gas)),typeof e.gasPrice<"u"&&(t.gasPrice=te(e.gasPrice)),typeof e.maxFeePerBlobGas<"u"&&(t.maxFeePerBlobGas=te(e.maxFeePerBlobGas)),typeof e.maxFeePerGas<"u"&&(t.maxFeePerGas=te(e.maxFeePerGas)),typeof e.maxPriorityFeePerGas<"u"&&(t.maxPriorityFeePerGas=te(e.maxPriorityFeePerGas)),typeof e.nonce<"u"&&(t.nonce=te(e.nonce)),typeof e.to<"u"&&(t.to=e.to),typeof e.type<"u"&&(t.type=h1[e.type]),typeof e.value<"u"&&(t.value=te(e.value)),t}function p1(e){return e.map(t=>({address:t.address,r:t.r?te(BigInt(t.r)):t.r,s:t.s?te(BigInt(t.s)):t.s,chainId:te(t.chainId),nonce:te(t.nonce),...typeof t.yParity<"u"?{yParity:te(t.yParity)}:{},...typeof t.v<"u"&&typeof t.yParity>"u"?{v:te(t.v)}:{}}))}function Xf(e){if(!(!e||e.length===0))return e.reduce((t,{slot:r,value:n})=>{if(r.length!==66)throw new Lf({size:r.length,targetSize:66,type:"hex"});if(n.length!==66)throw new Lf({size:n.length,targetSize:66,type:"hex"});return t[r]=n,t},{})}function y1(e){const{balance:t,nonce:r,state:n,stateDiff:i,code:s}=e,o={};if(s!==void 0&&(o.code=s),t!==void 0&&(o.balance=te(t)),r!==void 0&&(o.nonce=te(r)),n!==void 0&&(o.state=Xf(n)),i!==void 0){if(o.state)throw new Gb;o.stateDiff=Xf(i)}return o}function Tu(e){if(!e)return;const t={};for(const{address:r,...n}of e){if(!Ve(r,{strict:!1}))throw new dt({address:r});if(t[r])throw new qb({address:r});t[r]=y1(n)}return t}const Mo=2n**256n-1n;function vn(e){const{account:t,gasPrice:r,maxFeePerGas:n,maxPriorityFeePerGas:i,to:s}=e,o=t?$e(t):void 0;if(o&&!Ve(o.address))throw new dt({address:o.address});if(s&&!Ve(s))throw new dt({address:s});if(typeof r<"u"&&(typeof n<"u"||typeof i<"u"))throw new Wb;if(n&&n>Mo)throw new hn({maxFeePerGas:n});if(i&&n&&i>n)throw new fs({maxFeePerGas:n,maxPriorityFeePerGas:i})}class m1 extends H{constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class Pu extends H{constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class b1 extends H{constructor({maxPriorityFeePerGas:t}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${pt(t)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class Rh extends H{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 Nh={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Ho(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?Lt(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?Lt(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?Nh[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=w1(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 g1=Su("transaction",Ho);function w1(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 Bu(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:Ho(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 v1=Su("block",Bu);async function Xt(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:i}={}){var f,d,y;const s=n??"latest",o=i??!1,a=r!==void 0?te(r):void 0;let c=null;if(t?c=await e.request({method:"eth_getBlockByHash",params:[t,o]},{dedupe:!0}):c=await e.request({method:"eth_getBlockByNumber",params:[a||s,o]},{dedupe:!!a}),!c)throw new Rh({blockHash:t,blockNumber:r});return(((y=(d=(f=e.chain)==null?void 0:f.formatters)==null?void 0:d.block)==null?void 0:y.format)||Bu)(c)}async function Iu(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function _1(e,t){return $h(e,t)}async function $h(e,t){var s,o;const{block:r,chain:n=e.chain,request:i}=t||{};try{const a=((s=n==null?void 0:n.fees)==null?void 0:s.maxPriorityFeePerGas)??((o=n==null?void 0:n.fees)==null?void 0:o.defaultPriorityFee);if(typeof a=="function"){const u=r||await ee(e,Xt,"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 Ze(c)}catch{const[a,c]=await Promise.all([r?Promise.resolve(r):ee(e,Xt,"getBlock")({}),ee(e,Iu,"getGasPrice")({})]);if(typeof a.baseFeePerGas!="bigint")throw new Pu;const u=c-a.baseFeePerGas;return u<0n?0n:u}}async function x1(e,t){return Oc(e,t)}async function Oc(e,t){var y,p;const{block:r,chain:n=e.chain,request:i,type:s="eip1559"}=t||{},o=await(async()=>{var w,b;return typeof((w=n==null?void 0:n.fees)==null?void 0:w.baseFeeMultiplier)=="function"?n.fees.baseFeeMultiplier({block:r,client:e,request:i}):((b=n==null?void 0:n.fees)==null?void 0:b.baseFeeMultiplier)??1.2})();if(o<1)throw new m1;const c=10**(((y=o.toString().split(".")[1])==null?void 0:y.length)??0),u=w=>w*BigInt(Math.ceil(o*c))/BigInt(c),f=r||await ee(e,Xt,"getBlock")({});if(typeof((p=n==null?void 0:n.fees)==null?void 0:p.estimateFeesPerGas)=="function"){const w=await n.fees.estimateFeesPerGas({block:r,client:e,multiply:u,request:i,type:s});if(w!==null)return w}if(s==="eip1559"){if(typeof f.baseFeePerGas!="bigint")throw new Pu;const w=typeof(i==null?void 0:i.maxPriorityFeePerGas)=="bigint"?i.maxPriorityFeePerGas:await $h(e,{block:f,chain:n,request:i}),b=u(f.baseFeePerGas);return{maxFeePerGas:(i==null?void 0:i.maxFeePerGas)??b+w,maxPriorityFeePerGas:w}}return{gasPrice:(i==null?void 0:i.gasPrice)??u(await ee(e,Iu,"getGasPrice")({}))}}async function ku(e,{address:t,blockTag:r="latest",blockNumber:n}){const i=await e.request({method:"eth_getTransactionCount",params:[t,n?te(n):r]},{dedupe:!!n});return Lt(i)}function Cu(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=>Ft(s)):e.blobs,i=[];for(const s of n)i.push(Uint8Array.from(t.blobToKzgCommitment(s)));return r==="bytes"?i:i.map(s=>Me(s))}function Ou(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=>Ft(o)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(o=>Ft(o)):e.commitments,s=[];for(let o=0;o<n.length;o++){const a=n[o],c=i[o];s.push(Uint8Array.from(t.computeBlobKzgProof(a,c)))}return r==="bytes"?s:s.map(o=>Me(o))}function E1(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+u,a,n)}function A1(e,t,r){return e&t^~e&r}function S1(e,t,r){return e&t^e&r^t&r}let T1=class extends bu{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=xa(this.buffer)}update(t){Xn(this);const{view:r,buffer:n,blockLen:i}=this;t=Co(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=xa(t);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Xn(this),oh(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let d=o;d<i;d++)r[d]=0;E1(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=xa(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 d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}};const P1=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]),Tr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pr=new Uint32Array(64);let B1=class extends T1{constructor(t=32){super(64,t,8,!1),this.A=Tr[0]|0,this.B=Tr[1]|0,this.C=Tr[2]|0,this.D=Tr[3]|0,this.E=Tr[4]|0,this.F=Tr[5]|0,this.G=Tr[6]|0,this.H=Tr[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[t,r,n,i,s,o,a,c]}set(t,r,n,i,s,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)Pr[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){const y=Pr[d-15],p=Pr[d-2],w=Dt(y,7)^Dt(y,18)^y>>>3,b=Dt(p,17)^Dt(p,19)^p>>>10;Pr[d]=b+Pr[d-7]+w+Pr[d-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){const y=Dt(a,6)^Dt(a,11)^Dt(a,25),p=f+y+A1(a,c,u)+P1[d]+Pr[d]|0,b=(Dt(n,2)^Dt(n,13)^Dt(n,22))+S1(n,i,s)|0;f=u,u=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+b|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,s,o,a,c,u,f)}roundClean(){Pr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Lh=ah(()=>new B1);function $i(e,t){const r=t||"hex",n=Lh($t(e,{strict:!1})?ui(e):e);return r==="bytes"?n:ie(n)}function I1(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=$i(t,"bytes");return i.set([r],0),n==="bytes"?i:Me(i)}function Fh(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const s of t)i.push(I1({commitment:s,to:n,version:r}));return i}const Jf=6,Uh=32,Ru=4096,Mh=Uh*Ru,Qf=Mh*Jf-1-1*Ru*Jf,Hh=1;class k1 extends H{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Dh extends H{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class C1 extends H{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class O1 extends H{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Hh}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function R1(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?Ft(e.data):e.data,n=Oe(r);if(!n)throw new Dh;if(n>Qf)throw new k1({maxSize:Qf,size:n});const i=[];let s=!0,o=0;for(;s;){const a=xu(new Uint8Array(Mh));let c=0;for(;c<Ru;){const u=r.slice(o,o+(Uh-1));if(a.pushByte(0),a.pushBytes(u),u.length<31){a.pushByte(128),s=!1;break}c++,o+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>Me(a.bytes))}function jh(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??R1({data:t,to:n}),s=e.commitments??Cu({blobs:i,kzg:r,to:n}),o=e.proofs??Ou({blobs:i,commitments:s,kzg:r,to:n}),a=[];for(let c=0;c<i.length;c++)a.push({blob:i[c],commitment:s[c],proof:o[c]});return a}function zh(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 Yb({transaction:e})}async function di(e){const t=await e.request({method:"eth_chainId"},{dedupe:!0});return Lt(t)}const qh=["blobVersionedHashes","chainId","fees","gas","nonce","type"],ed=new Map;async function Do(e,t){const{account:r=e.account,blobs:n,chain:i,gas:s,kzg:o,nonce:a,nonceManager:c,parameters:u=qh,type:f}=t,d=r&&$e(r),y={...t,...d?{from:d==null?void 0:d.address}:{}};let p;async function w(){return p||(p=await ee(e,Xt,"getBlock")({blockTag:"latest"}),p)}let b;async function m(){return b||(i?i.id:typeof t.chainId<"u"?t.chainId:(b=await ee(e,di,"getChainId")({}),b))}if(u.includes("nonce")&&typeof a>"u"&&d)if(c){const _=await m();y.nonce=await c.consume({address:d.address,chainId:_,client:e})}else y.nonce=await ee(e,ku,"getTransactionCount")({address:d.address,blockTag:"pending"});if((u.includes("blobVersionedHashes")||u.includes("sidecars"))&&n&&o){const _=Cu({blobs:n,kzg:o});if(u.includes("blobVersionedHashes")){const E=Fh({commitments:_,to:"hex"});y.blobVersionedHashes=E}if(u.includes("sidecars")){const E=Ou({blobs:n,commitments:_,kzg:o}),x=jh({blobs:n,commitments:_,proofs:E,to:"hex"});y.sidecars=x}}if(u.includes("chainId")&&(y.chainId=await m()),(u.includes("fees")||u.includes("type"))&&typeof f>"u")try{y.type=zh(y)}catch{let _=ed.get(e.uid);if(typeof _>"u"){const E=await w();_=typeof(E==null?void 0:E.baseFeePerGas)=="bigint",ed.set(e.uid,_)}y.type=_?"eip1559":"legacy"}if(u.includes("fees"))if(y.type!=="legacy"&&y.type!=="eip2930"){if(typeof y.maxFeePerGas>"u"||typeof y.maxPriorityFeePerGas>"u"){const _=await w(),{maxFeePerGas:E,maxPriorityFeePerGas:x}=await Oc(e,{block:_,chain:i,request:y});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas<x)throw new b1({maxPriorityFeePerGas:x});y.maxPriorityFeePerGas=x,y.maxFeePerGas=E}}else{if(typeof t.maxFeePerGas<"u"||typeof t.maxPriorityFeePerGas<"u")throw new Pu;if(typeof t.gasPrice>"u"){const _=await w(),{gasPrice:E}=await Oc(e,{block:_,chain:i,request:y,type:"legacy"});y.gasPrice=E}}return u.includes("gas")&&typeof s>"u"&&(y.gas=await ee(e,Nu,"estimateGas")({...y,account:d&&{address:d.address,type:"json-rpc"}})),vn(y),delete y.parameters,y}async function Gh(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=r?te(r):void 0,s=await e.request({method:"eth_getBalance",params:[t,i||n]});return BigInt(s)}async function Nu(e,t){var i,s,o;const{account:r=e.account}=t,n=r?$e(r):void 0;try{let F=function(V){const{block:X,request:J,rpcStateOverride:W}=V;return e.request({method:"eth_estimateGas",params:W?[J,X??"latest",W]:X?[J,X]:[J]})};const{accessList:a,authorizationList:c,blobs:u,blobVersionedHashes:f,blockNumber:d,blockTag:y,data:p,gas:w,gasPrice:b,maxFeePerBlobGas:m,maxFeePerGas:_,maxPriorityFeePerGas:E,nonce:x,value:v,stateOverride:B,...S}=await Do(e,{...t,parameters:(n==null?void 0:n.type)==="local"?void 0:["blobVersionedHashes"]}),N=(d?te(d):void 0)||y,I=Tu(B),G=await(async()=>{if(S.to)return S.to;if(c&&c.length>0)return await Oh({authorization:c[0]}).catch(()=>{throw new H("`to` is required. Could not infer from `authorizationList`")})})();vn(t);const k=(o=(s=(i=e.chain)==null?void 0:i.formatters)==null?void 0:s.transactionRequest)==null?void 0:o.format,z=(k||fi)({...Uo(S,{format:k}),from:n==null?void 0:n.address,accessList:a,authorizationList:c,blobs:u,blobVersionedHashes:f,data:p,gas:w,gasPrice:b,maxFeePerBlobGas:m,maxFeePerGas:_,maxPriorityFeePerGas:E,nonce:x,to:G,value:v});let D=BigInt(await F({block:N,request:z,rpcStateOverride:I}));if(c){const V=await Gh(e,{address:z.from}),X=await Promise.all(c.map(async J=>{const{address:W}=J,se=await F({block:N,request:{authorizationList:void 0,data:p,from:n==null?void 0:n.address,to:W,value:te(V)},rpcStateOverride:I}).catch(()=>100000n);return 2n*BigInt(se)}));D+=X.reduce((J,W)=>J+W,0n)}return D}catch(a){throw l1(a,{...t,account:n,chain:e.chain})}}async function Vh(e,t){const{abi:r,address:n,args:i,functionName:s,dataSuffix:o,...a}=t,c=Pt({abi:r,args:i,functionName:s});try{return await ee(e,Nu,"estimateGas")({data:`${c}${o?o.replace("0x",""):""}`,to:n,...a})}catch(u){const f=a.account?$e(a.account):void 0;throw ln(u,{abi:r,address:n,args:i,docsPath:"/docs/contract/estimateContractGas",functionName:s,sender:f==null?void 0:f.address})}}function Bs(e,t){if(!Ve(e,{strict:!1}))throw new dt({address:e});if(!Ve(t,{strict:!1}))throw new dt({address:t});return e.toLowerCase()===t.toLowerCase()}const td="/docs/contract/decodeEventLog";function $u(e){const{abi:t,data:r,strict:n,topics:i}=e,s=n??!0,[o,...a]=i;if(!o)throw new Sm({docsPath:td});const c=t.length===1?t[0]:t.find(b=>b.type==="event"&&o===Oo(Nt(b)));if(!(c&&"name"in c)||c.type!=="event")throw new Ql(o,{docsPath:td});const{name:u,inputs:f}=c,d=f==null?void 0:f.some(b=>!("name"in b&&b.name));let y=d?[]:{};const p=f.filter(b=>"indexed"in b&&b.indexed);for(let b=0;b<p.length;b++){const m=p[b],_=a[b];if(!_)throw new ko({abiItem:c,param:m});y[d?b:m.name||b]=N1({param:m,value:_})}const w=f.filter(b=>!("indexed"in b&&b.indexed));if(w.length>0){if(r&&r!=="0x")try{const b=Ss(w,r);if(b)if(d)y=[...y,...b];else for(let m=0;m<w.length;m++)y[w[m].name]=b[m]}catch(b){if(s)throw b instanceof Xl||b instanceof xh?new ji({abiItem:c,data:r,params:w,size:Oe(r)}):b}else if(s)throw new ji({abiItem:c,data:"0x",params:w,size:0})}return{eventName:u,args:Object.values(y).length>0?y:void 0}}function N1({param:e,value:t}){return e.type==="string"||e.type==="bytes"||e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/)?t:(Ss([e],t)||[])[0]}function Lu(e){const{abi:t,args:r,logs:n,strict:i=!0}=e,s=(()=>{if(e.eventName)return Array.isArray(e.eventName)?e.eventName:[e.eventName]})();return n.map(o=>{var a;try{const c=t.find(f=>f.type==="event"&&o.topics[0]===Oo(f));if(!c)return null;const u=$u({...o,abi:[c],strict:i});return s&&!s.includes(u.eventName)||!$1({args:u.args,inputs:c.inputs,matchArgs:r})?null:{...u,...o}}catch(c){let u,f;if(c instanceof Ql)return null;if(c instanceof ji||c instanceof ko){if(i)return null;u=c.abiItem.name,f=(a=c.abiItem.inputs)==null?void 0:a.some(d=>!("name"in d&&d.name))}return{...o,args:f?[]:{},eventName:u}}}).filter(Boolean)}function $1(e){const{args:t,inputs:r,matchArgs:n}=e;if(!n)return!0;if(!t)return!1;function i(s,o,a){try{return s.type==="address"?Bs(o,a):s.type==="string"||s.type==="bytes"?Xe(ui(o))===a:o===a}catch{return!1}}return Array.isArray(t)&&Array.isArray(n)?n.every((s,o)=>{if(s==null)return!0;const a=r[o];return a?(Array.isArray(s)?s:[s]).some(u=>i(a,u,t[o])):!1}):typeof t=="object"&&!Array.isArray(t)&&typeof n=="object"&&!Array.isArray(n)?Object.entries(n).every(([s,o])=>{if(o==null)return!0;const a=r.find(u=>u.name===s);return a?(Array.isArray(o)?o:[o]).some(u=>i(a,u,t[s])):!1}):!1}function mr(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 Fu(e,{address:t,blockHash:r,fromBlock:n,toBlock:i,event:s,events:o,args:a,strict:c}={}){const u=c??!1,f=o??(s?[s]:void 0);let d=[];f&&(d=[f.flatMap(b=>As({abi:[b],eventName:b.name,args:o?void 0:a}))],s&&(d=d[0]));let y;r?y=await e.request({method:"eth_getLogs",params:[{address:t,topics:d,blockHash:r}]}):y=await e.request({method:"eth_getLogs",params:[{address:t,topics:d,fromBlock:typeof n=="bigint"?te(n):n,toBlock:typeof i=="bigint"?te(i):i}]});const p=y.map(w=>mr(w));return f?Lu({abi:f,args:a,logs:p,strict:u}):p}async function Uu(e,t){const{abi:r,address:n,args:i,blockHash:s,eventName:o,fromBlock:a,toBlock:c,strict:u}=t,f=o?wn({abi:r,name:o}):void 0,d=f?void 0:r.filter(y=>y.type==="event");return ee(e,Fu,"getLogs")({address:n,args:i,blockHash:s,event:f,events:d,fromBlock:a,toBlock:c,strict:u})}const Sa="/docs/contract/decodeFunctionResult";function _n(e){const{abi:t,args:r,functionName:n,data:i}=e;let s=t[0];if(n){const a=wn({abi:t,args:r,name:n});if(!a)throw new Yn(n,{docsPath:Sa});s=a}if(s.type!=="function")throw new Yn(void 0,{docsPath:Sa});if(!s.outputs)throw new eh(s.name,{docsPath:Sa});const o=Ss(s.outputs,i);if(o&&o.length>1)return o;if(o&&o.length===1)return o[0]}const Rc=[{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"}],Nc=[{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"}]}],Wh=[{inputs:[],name:"ResolverNotFound",type:"error"},{inputs:[],name:"ResolverWildcardNotSupported",type:"error"},{inputs:[],name:"ResolverNotContract",type:"error"},{inputs:[{name:"returnData",type:"bytes"}],name:"ResolverError",type:"error"},{inputs:[{components:[{name:"status",type:"uint16"},{name:"message",type:"string"}],name:"errors",type:"tuple[]"}],name:"HttpError",type:"error"}],Kh=[...Wh,{name:"resolve",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes"},{name:"data",type:"bytes"}],outputs:[{name:"",type:"bytes"},{name:"address",type:"address"}]},{name:"resolve",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes"},{name:"data",type:"bytes"},{name:"gateways",type:"string[]"}],outputs:[{name:"",type:"bytes"},{name:"address",type:"address"}]}],L1=[...Wh,{name:"reverse",type:"function",stateMutability:"view",inputs:[{type:"bytes",name:"reverseName"}],outputs:[{type:"string",name:"resolvedName"},{type:"address",name:"resolvedAddress"},{type:"address",name:"reverseResolver"},{type:"address",name:"resolver"}]},{name:"reverse",type:"function",stateMutability:"view",inputs:[{type:"bytes",name:"reverseName"},{type:"string[]",name:"gateways"}],outputs:[{type:"string",name:"resolvedName"},{type:"address",name:"resolvedAddress"},{type:"address",name:"reverseResolver"},{type:"address",name:"resolver"}]}],rd=[{name:"text",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"key",type:"string"}],outputs:[{name:"",type:"string"}]}],nd=[{name:"addr",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"}],outputs:[{name:"",type:"address"}]},{name:"addr",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"coinType",type:"uint256"}],outputs:[{name:"",type:"bytes"}]}],id=[{inputs:[{name:"_signer",type:"address"},{name:"_hash",type:"bytes32"},{name:"_signature",type:"bytes"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{name:"_signer",type:"address"},{name:"_hash",type:"bytes32"},{name:"_signature",type:"bytes"}],outputs:[{type:"bool"}],stateMutability:"nonpayable",type:"function",name:"isValidSig"}],F1="0x82ad56cb",Yh="0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe",U1="0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe",M1="0x608060405234801561001057600080fd5b5060405161069438038061069483398101604081905261002f9161051e565b600061003c848484610048565b9050806000526001601ff35b60007f64926492649264926492649264926492649264926492649264926492649264926100748361040c565b036101e7576000606080848060200190518101906100929190610577565b60405192955090935091506000906001600160a01b038516906100b69085906105dd565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b9087906004016105f9565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d19190610633565b6001600160e01b03191614945050505050610405565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e9061022790879087906004016105f9565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102689190610633565b6001600160e01b031916149050610405565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e7610425565b5060208201516040808401518451859392600091859190811061030c5761030c61065d565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b60408051600081526020810180835289905260ff83169181019190915260608101849052608081018390526001600160a01b0389169060019060a0016020604051602081039080840390855afa1580156103ea573d6000803e3d6000fd5b505050602060405103516001600160a01b0316149450505050505b9392505050565b600060208251101561041d57600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b038116811461045857600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561048c578181015183820152602001610474565b50506000910152565b600082601f8301126104a657600080fd5b81516001600160401b038111156104bf576104bf61045b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156104ed576104ed61045b565b60405281815283820160200185101561050557600080fd5b610516826020830160208701610471565b949350505050565b60008060006060848603121561053357600080fd5b835161053e81610443565b6020850151604086015191945092506001600160401b0381111561056157600080fd5b61056d86828701610495565b9150509250925092565b60008060006060848603121561058c57600080fd5b835161059781610443565b60208501519093506001600160401b038111156105b357600080fd5b6105bf86828701610495565b604086015190935090506001600160401b0381111561056157600080fd5b600082516105ef818460208701610471565b9190910192915050565b828152604060208201526000825180604084015261061e816060850160208701610471565b601f01601f1916919091016060019392505050565b60006020828403121561064557600080fd5b81516001600160e01b03198116811461040557600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572";class $c extends H{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 H1 extends H{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 D1 extends H{constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join(`
|
|
40
|
+
`),{name:"ChainNotFoundError"})}}class Zh extends H{constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class jo extends H{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const Ta="/docs/contract/encodeDeployData";function zo(e){const{abi:t,args:r,bytecode:n}=e;if(!r||r.length===0)return n;const i=t.find(o=>"type"in o&&o.type==="constructor");if(!i)throw new vm({docsPath:Ta});if(!("inputs"in i))throw new Rf({docsPath:Ta});if(!i.inputs||i.inputs.length===0)throw new Rf({docsPath:Ta});const s=xr(i.inputs,r);return Mt([n,s])}function li({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 $c({chain:t,contract:{name:r}});if(e&&n.blockCreated&&n.blockCreated>e)throw new $c({blockNumber:e,chain:t,contract:{name:r,blockCreated:n.blockCreated}});return n.address}function Xh(e,{docsPath:t,...r}){const n=(()=>{const i=Fo(e,r);return i instanceof Ps?e:i})();return new Bh(n,{docsPath:t,...r})}function Mu(){let e=()=>{},t=()=>{};return{promise:new Promise((n,i)=>{e=n,t=i}),resolve:e,reject:t}}const Pa=new Map;function Jh({fn:e,id:t,shouldSplitBatch:r,wait:n=0,sort:i}){const s=async()=>{const f=c();o();const d=f.map(({args:y})=>y);d.length!==0&&e(d).then(y=>{i&&Array.isArray(y)&&y.sort(i);for(let p=0;p<f.length;p++){const{resolve:w}=f[p];w==null||w([y[p],y])}}).catch(y=>{for(let p=0;p<f.length;p++){const{reject:w}=f[p];w==null||w(y)}})},o=()=>Pa.delete(t),a=()=>c().map(({args:f})=>f),c=()=>Pa.get(t)||[],u=f=>Pa.set(t,[...c(),f]);return{flush:o,async schedule(f){const{promise:d,resolve:y,reject:p}=Mu();return(r==null?void 0:r([...a(),f]))&&s(),c().length>0?(u({args:f,resolve:y,reject:p}),d):(u({args:f,resolve:y,reject:p}),setTimeout(s,n),d)}}}async function Is(e,t){var k,U,z,F;const{account:r=e.account,batch:n=!!((k=e.batch)!=null&&k.multicall),blockNumber:i,blockTag:s="latest",accessList:o,blobs:a,code:c,data:u,factory:f,factoryData:d,gas:y,gasPrice:p,maxFeePerBlobGas:w,maxFeePerGas:b,maxPriorityFeePerGas:m,nonce:_,to:E,value:x,stateOverride:v,...B}=t,S=r?$e(r):void 0;if(c&&(f||d))throw new H("Cannot provide both `code` & `factory`/`factoryData` as parameters.");if(c&&E)throw new H("Cannot provide both `code` & `to` as parameters.");const C=c&&u,N=f&&d&&E&&u,I=C||N,G=C?q1({code:c,data:u}):N?G1({data:u,factory:f,factoryData:d,to:E}):u;try{vn(t);const V=(i?te(i):void 0)||s,X=Tu(v),J=(F=(z=(U=e.chain)==null?void 0:U.formatters)==null?void 0:z.transactionRequest)==null?void 0:F.format,se=(J||fi)({...Uo(B,{format:J}),from:S==null?void 0:S.address,accessList:o,blobs:a,data:G,gas:y,gasPrice:p,maxFeePerBlobGas:w,maxFeePerGas:b,maxPriorityFeePerGas:m,nonce:_,to:I?void 0:E,value:x});if(n&&j1({request:se})&&!X)try{return await z1(e,{...se,blockNumber:i,blockTag:s})}catch(ae){if(!(ae instanceof Zh)&&!(ae instanceof $c))throw ae}const ne=await e.request({method:"eth_call",params:X?[se,V,X]:[se,V]});return ne==="0x"?{data:void 0}:{data:ne}}catch(D){const V=V1(D),{offchainLookup:X,offchainLookupSignature:J}=await Promise.resolve().then(()=>require("./ccip-CQkMVqmN.cjs"));if(e.ccipRead!==!1&&(V==null?void 0:V.slice(0,10))===J&&E)return{data:await X(e,{data:V,to:E})};throw I&&(V==null?void 0:V.slice(0,10))==="0x101bb98d"?new r1({factory:f}):Xh(D,{...t,account:S,chain:e.chain})}}function j1({request:e}){const{data:t,to:r,...n}=e;return!(!t||t.startsWith(F1)||!r||Object.values(n).filter(i=>typeof i<"u").length>0)}async function z1(e,t){var b;const{batchSize:r=1024,wait:n=0}=typeof((b=e.batch)==null?void 0:b.multicall)=="object"?e.batch.multicall:{},{blockNumber:i,blockTag:s="latest",data:o,multicallAddress:a,to:c}=t;let u=a;if(!u){if(!e.chain)throw new Zh;u=li({blockNumber:i,chain:e.chain,contract:"multicall3"})}const d=(i?te(i):void 0)||s,{schedule:y}=Jh({id:`${e.uid}.${d}`,wait:n,shouldSplitBatch(m){return m.reduce((E,{data:x})=>E+(x.length-2),0)>r*2},fn:async m=>{const _=m.map(v=>({allowFailure:!0,callData:v.data,target:v.to})),E=Pt({abi:Rc,args:[_],functionName:"aggregate3"}),x=await e.request({method:"eth_call",params:[{data:E,to:u},d]});return _n({abi:Rc,args:[_],functionName:"aggregate3",data:x||"0x"})}}),[{returnData:p,success:w}]=await y({data:o,to:c});if(!w)throw new Lo({data:p});return p==="0x"?{data:void 0}:{data:p}}function q1(e){const{code:t,data:r}=e;return zo({abi:Kl(["constructor(bytes, bytes)"]),bytecode:Yh,args:[t,r]})}function G1(e){const{data:t,factory:r,factoryData:n,to:i}=e;return zo({abi:Kl(["constructor(address, bytes, address, bytes)"]),bytecode:U1,args:[i,t,r,n]})}function V1(e){var r;if(!(e instanceof H))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 Qt(e,t){const{abi:r,address:n,args:i,functionName:s,...o}=t,a=Pt({abi:r,args:i,functionName:s});try{const{data:c}=await ee(e,Is,"call")({...o,data:a,to:n});return _n({abi:r,args:i,functionName:s,data:c||"0x"})}catch(c){throw ln(c,{abi:r,address:n,args:i,docsPath:"/docs/contract/readContract",functionName:s})}}async function Qh(e,t){const{abi:r,address:n,args:i,dataSuffix:s,functionName:o,...a}=t,c=a.account?$e(a.account):e.account,u=Pt({abi:r,args:i,functionName:o});try{const{data:f}=await ee(e,Is,"call")({batch:!1,data:`${u}${s?s.replace("0x",""):""}`,to:n,...a,account:c}),d=_n({abi:r,args:i,functionName:o,data:f||"0x"}),y=r.filter(p=>"name"in p&&p.name===t.functionName);return{result:d,request:{abi:y,address:n,args:i,dataSuffix:s,functionName:o,...a,account:c}}}catch(f){throw ln(f,{abi:r,address:n,args:i,docsPath:"/docs/contract/simulateContract",functionName:o,sender:c==null?void 0:c.address})}}const Ba=new Map,sd=new Map;let W1=0;function br(e,t,r){const n=++W1,i=()=>Ba.get(e)||[],s=()=>{const f=i();Ba.set(e,f.filter(d=>d.id!==n))},o=()=>{const f=i();if(!f.some(y=>y.id===n))return;const d=sd.get(e);f.length===1&&d&&d(),s()},a=i();if(Ba.set(e,[...a,{id:n,fns:t}]),a&&a.length>0)return o;const c={};for(const f in t)c[f]=(...d)=>{var p,w;const y=i();if(y.length!==0)for(const b of y)(w=(p=b.fns)[f])==null||w.call(p,...d)};const u=r(c);return typeof u=="function"&&sd.set(e,u),o}async function Lc(e){return new Promise(t=>setTimeout(t,e))}function hi(e,{emitOnBegin:t,initialWaitTime:r,interval:n}){let i=!0;const s=()=>i=!1;return(async()=>{let a;t&&(a=await e({unpoll:s}));const c=await(r==null?void 0:r(a))??n;await Lc(c);const u=async()=>{i&&(await e({unpoll:s}),await Lc(n),u())};u()})(),s}const K1=new Map,Y1=new Map;function Z1(e){const t=(i,s)=>({clear:()=>s.delete(i),get:()=>s.get(i),set:o=>s.set(i,o)}),r=t(e,K1),n=t(e,Y1);return{clear:()=>{r.clear(),n.clear()},promise:r,response:n}}async function X1(e,{cacheKey:t,cacheTime:r=Number.POSITIVE_INFINITY}){const n=Z1(t),i=n.response.get();if(i&&r>0&&new Date().getTime()-i.created.getTime()<r)return i.data;let s=n.promise.get();s||(s=e(),n.promise.set(s));try{const o=await s;return n.response.set({created:new Date,data:o}),o}finally{n.promise.clear()}}const J1=e=>`blockNumber.${e}`;async function ks(e,{cacheTime:t=e.cacheTime}={}){const r=await X1(()=>e.request({method:"eth_blockNumber"}),{cacheKey:J1(e.uid),cacheTime:t});return BigInt(r)}async function qo(e,{filter:t}){const r="strict"in t&&t.strict,n=await t.request({method:"eth_getFilterChanges",params:[t.id]});if(typeof n[0]=="string")return n;const i=n.map(s=>mr(s));return!("abi"in t)||!t.abi?i:Lu({abi:t.abi,logs:i,strict:r})}async function Go(e,{filter:t}){return t.request({method:"eth_uninstallFilter",params:[t.id]})}function e0(e,t){const{abi:r,address:n,args:i,batch:s=!0,eventName:o,fromBlock:a,onError:c,onLogs:u,poll:f,pollingInterval:d=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 m=y??!1,_=Ue(["watchContractEvent",n,i,s,e.uid,o,d,m,a]);return br(_,{onLogs:u,onError:c},E=>{let x;a!==void 0&&(x=a-1n);let v,B=!1;const S=hi(async()=>{var C;if(!B){try{v=await ee(e,_u,"createContractEventFilter")({abi:r,address:n,args:i,eventName:o,strict:m,fromBlock:a})}catch{}B=!0;return}try{let N;if(v)N=await ee(e,qo,"getFilterChanges")({filter:v});else{const I=await ee(e,ks,"getBlockNumber")({});x&&x<I?N=await ee(e,Uu,"getContractEvents")({abi:r,address:n,args:i,eventName:o,fromBlock:x+1n,toBlock:I,strict:m}):N=[],x=I}if(N.length===0)return;if(s)E.onLogs(N);else for(const I of N)E.onLogs([I])}catch(N){v&&N instanceof dn&&(B=!1),(C=E.onError)==null||C.call(E,N)}},{emitOnBegin:!0,interval:d});return async()=>{v&&await ee(e,Go,"uninstallFilter")({filter:v}),S()}})})():(()=>{const m=y??!1,_=Ue(["watchContractEvent",n,i,s,e.uid,o,d,m]);let E=!0,x=()=>E=!1;return br(_,{onLogs:u,onError:c},v=>((async()=>{try{const B=(()=>{if(e.transport.type==="fallback"){const N=e.transport.transports.find(I=>I.config.type==="webSocket");return N?N.value:e.transport}return e.transport})(),S=o?As({abi:r,eventName:o,args:i}):[],{unsubscribe:C}=await B.subscribe({params:["logs",{address:n,topics:S}],onData(N){var G;if(!E)return;const I=N.result;try{const{eventName:k,args:U}=$u({abi:r,data:I.data,topics:I.topics,strict:y}),z=mr(I,{args:U,eventName:k});v.onLogs([z])}catch(k){let U,z;if(k instanceof ji||k instanceof ko){if(y)return;U=k.abiItem.name,z=(G=k.abiItem.inputs)==null?void 0:G.some(D=>!("name"in D&&D.name))}const F=mr(I,{args:z?[]:{},eventName:U});v.onLogs([F])}},onError(N){var I;(I=v.onError)==null||I.call(v,N)}});x=C,E||x()}catch(B){c==null||c(B)}})(),()=>x()))})()}class zr extends H{constructor({docsPath:t}={}){super(["Could not find an Account to execute with this Action.","Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client."].join(`
|
|
41
|
+
`),{docsPath:t,docsSlug:"account",name:"AccountNotFoundError"})}}class ao extends H{constructor({docsPath:t,metaMessages:r,type:n}){super(`Account type "${n}" is not supported.`,{docsPath:t,metaMessages:r,name:"AccountTypeNotSupportedError"})}}function t0({chain:e,currentChainId:t}){if(!e)throw new D1;if(t!==e.id)throw new H1({chain:e,currentChainId:t})}function r0(e,{docsPath:t,...r}){const n=(()=>{const i=Fo(e,r);return i instanceof Ps?e:i})();return new Xb(n,{docsPath:t,...r})}async function Hu(e,{serializedTransaction:t}){return e.request({method:"eth_sendRawTransaction",params:[t]},{retryCount:0})}const Ia=new Ro(128);async function Du(e,t){var _,E,x,v;const{account:r=e.account,chain:n=e.chain,accessList:i,authorizationList:s,blobs:o,data:a,gas:c,gasPrice:u,maxFeePerBlobGas:f,maxFeePerGas:d,maxPriorityFeePerGas:y,nonce:p,value:w,...b}=t;if(typeof r>"u")throw new zr({docsPath:"/docs/actions/wallet/sendTransaction"});const m=r?$e(r):null;try{vn(t);const B=await(async()=>{if(t.to)return t.to;if(t.to!==null&&s&&s.length>0)return await Oh({authorization:s[0]}).catch(()=>{throw new H("`to` is required. Could not infer from `authorizationList`.")})})();if((m==null?void 0:m.type)==="json-rpc"||m===null){let S;n!==null&&(S=await ee(e,di,"getChainId")({}),t0({currentChainId:S,chain:n}));const C=(x=(E=(_=e.chain)==null?void 0:_.formatters)==null?void 0:E.transactionRequest)==null?void 0:x.format,I=(C||fi)({...Uo(b,{format:C}),accessList:i,authorizationList:s,blobs:o,chainId:S,data:a,from:m==null?void 0:m.address,gas:c,gasPrice:u,maxFeePerBlobGas:f,maxFeePerGas:d,maxPriorityFeePerGas:y,nonce:p,to:B,value:w}),G=Ia.get(e.uid),k=G?"wallet_sendTransaction":"eth_sendTransaction";try{return await e.request({method:k,params:[I]},{retryCount:0})}catch(U){if(G===!1)throw U;const z=U;if(z.name==="InvalidInputRpcError"||z.name==="InvalidParamsRpcError"||z.name==="MethodNotFoundRpcError"||z.name==="MethodNotSupportedRpcError")return await e.request({method:"wallet_sendTransaction",params:[I]},{retryCount:0}).then(F=>(Ia.set(e.uid,!0),F)).catch(F=>{const D=F;throw D.name==="MethodNotFoundRpcError"||D.name==="MethodNotSupportedRpcError"?(Ia.set(e.uid,!1),z):D});throw z}}if((m==null?void 0:m.type)==="local"){const S=await ee(e,Do,"prepareTransactionRequest")({account:m,accessList:i,authorizationList:s,blobs:o,chain:n,data:a,gas:c,gasPrice:u,maxFeePerBlobGas:f,maxFeePerGas:d,maxPriorityFeePerGas:y,nonce:p,nonceManager:m.nonceManager,parameters:[...qh,"sidecars"],value:w,...b,to:B}),C=(v=n==null?void 0:n.serializers)==null?void 0:v.transaction,N=await m.signTransaction(S,{serializer:C});return await ee(e,Hu,"sendRawTransaction")({serializedTransaction:N})}throw(m==null?void 0:m.type)==="smart"?new ao({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:"/docs/actions/bundler/sendUserOperation",type:"smart"}):new ao({docsPath:"/docs/actions/wallet/sendTransaction",type:m==null?void 0:m.type})}catch(B){throw B instanceof ao?B:r0(B,{...t,account:m,chain:t.chain||void 0})}}async function n0(e,t){const{abi:r,account:n=e.account,address:i,args:s,dataSuffix:o,functionName:a,...c}=t;if(typeof n>"u")throw new zr({docsPath:"/docs/contract/writeContract"});const u=n?$e(n):null,f=Pt({abi:r,args:s,functionName:a});try{return await ee(e,Du,"sendTransaction")({data:`${f}${o?o.replace("0x",""):""}`,to:i,account:u,...c})}catch(d){throw ln(d,{abi:r,address:i,args:s,docsPath:"/docs/contract/writeContract",functionName:a,sender:u==null?void 0:u.address})}}function ka({abi:e,address:t,client:r}){const n=r,[i,s]=n?"public"in n&&"wallet"in n?[n.public,n.wallet]:"public"in n?[n.public,void 0]:"wallet"in n?[void 0,n.wallet]:[n,n]:[void 0,void 0],o=i!=null,a=s!=null,c={};let u=!1,f=!1,d=!1;for(const y of e)if(y.type==="function"?y.stateMutability==="view"||y.stateMutability==="pure"?u=!0:f=!0:y.type==="event"&&(d=!0),u&&f&&d)break;return o&&(u&&(c.read=new Proxy({},{get(y,p){return(...w)=>{const{args:b,options:m}=zs(w);return ee(i,Qt,"readContract")({abi:e,address:t,functionName:p,args:b,...m})}}})),f&&(c.simulate=new Proxy({},{get(y,p){return(...w)=>{const{args:b,options:m}=zs(w);return ee(i,Qh,"simulateContract")({abi:e,address:t,functionName:p,args:b,...m})}}})),d&&(c.createEventFilter=new Proxy({},{get(y,p){return(...w)=>{const b=e.find(E=>E.type==="event"&&E.name===p),{args:m,options:_}=Ca(w,b);return ee(i,_u,"createContractEventFilter")({abi:e,address:t,eventName:p,args:m,..._})}}}),c.getEvents=new Proxy({},{get(y,p){return(...w)=>{const b=e.find(E=>E.type==="event"&&E.name===p),{args:m,options:_}=Ca(w,b);return ee(i,Uu,"getContractEvents")({abi:e,address:t,eventName:p,args:m,..._})}}}),c.watchEvent=new Proxy({},{get(y,p){return(...w)=>{const b=e.find(E=>E.type==="event"&&E.name===p),{args:m,options:_}=Ca(w,b);return ee(i,e0,"watchContractEvent")({abi:e,address:t,eventName:p,args:m,..._})}}}))),a&&f&&(c.write=new Proxy({},{get(y,p){return(...w)=>{const{args:b,options:m}=zs(w);return ee(s,n0,"writeContract")({abi:e,address:t,functionName:p,args:b,...m})}}})),(o||a)&&f&&(c.estimateGas=new Proxy({},{get(y,p){return(...w)=>{const{args:b,options:m}=zs(w);return ee(i??s,Vh,"estimateContractGas")({abi:e,address:t,functionName:p,args:b,...m,account:m.account??s.account})}}})),c.address=t,c.abi=e,c}function zs(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 Ca(e,t){let r=!1;Array.isArray(e[0])?r=!0:e.length===1?r=t.inputs.some(s=>s.indexed):e.length===2&&(r=!0);const n=r?e[0]:void 0,i=(r?e[1]:e[0])??{};return{args:n,options:i}}const i0={"0x0":"reverted","0x1":"success"};function s0(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=>mr(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Lt(e.transactionIndex):null,status:e.status?i0[e.status]:null,type:e.type?Nh[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const Q1=Su("transactionReceipt",s0);async function o0(e,t){const{atomic:r=!1,chainId:n,receipts:i,version:s="2.0.0",...o}=await e.request({method:"wallet_getCallsStatus",params:[t.id]}),[a,c]=(()=>{const u=o.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{...o,atomic:r,chainId:n?Lt(n):void 0,receipts:(i==null?void 0:i.map(u=>({...u,blockNumber:Ze(u.blockNumber),gasUsed:Ze(u.gasUsed),status:i0[u.status]})))??[],statusCode:c,status:a,version:s}}async function eg(e,t){const{id:r,pollingInterval:n=e.pollingInterval,status:i=({statusCode:y})=>y>=200,timeout:s=6e4}=t,o=Ue(["waitForCallsStatus",e.uid,r]),{promise:a,resolve:c,reject:u}=Mu();let f;const d=br(o,{resolve:c,reject:u},y=>{const p=hi(async()=>{const w=b=>{clearTimeout(f),p(),b(),d()};try{const b=await o0(e,{id:r});if(!i(b))return;w(()=>y.resolve(b))}catch(b){w(()=>y.reject(b))}},{interval:n,emitOnBegin:!0});return p});return f=s?setTimeout(()=>{d(),clearTimeout(f),u(new tg({id:r}))},s):void 0,await a}class tg extends H{constructor({id:t}){super(`Timed out while waiting for call bundle with id "${t}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}const Fc=256;let qs=Fc,Gs;function a0(e=11){if(!Gs||qs+e>Fc*2){Gs="",qs=0;for(let t=0;t<Fc;t++)Gs+=(256+Math.random()*256|0).toString(16).substring(1)}return Gs.substring(qs,qs+++e)}function c0(e){const{batch:t,cacheTime:r=e.pollingInterval??4e3,ccipRead:n,key:i="base",name:s="Base Client",pollingInterval:o=4e3,type:a="base"}=e,c=e.chain,u=e.account?$e(e.account):void 0,{config:f,request:d,value:y}=e.transport({chain:c,pollingInterval:o}),p={...f,...y},w={account:u,batch:t,cacheTime:r,ccipRead:n,chain:c,key:i,name:s,pollingInterval:o,request:d,transport:p,type:a,uid:a0()};function b(m){return _=>{const E=_(m);for(const v in w)delete E[v];const x={...m,...E};return Object.assign(x,{extend:b(x)})}}return Object.assign(w,{extend:b(w)})}const Vs=new Ro(8192);function rg(e,{enabled:t=!0,id:r}){if(!t||!r)return e();if(Vs.get(r))return Vs.get(r);const n=e().finally(()=>Vs.delete(r));return Vs.set(r,n),n}function Uc(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((i,s)=>{const o=async({count:a=0}={})=>{const c=async({error:u})=>{const f=typeof t=="function"?t({count:a,error:u}):t;f&&await Lc(f),o({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});s(u)}};o()})}function ng(e,t={}){return async(r,n={})=>{var d;const{dedupe:i=!1,methods:s,retryDelay:o=150,retryCount:a=3,uid:c}={...t,...n},{method:u}=r;if((d=s==null?void 0:s.exclude)!=null&&d.includes(u))throw new en(new Error("method not supported"),{method:u});if(s!=null&&s.include&&!s.include.includes(u))throw new en(new Error("method not supported"),{method:u});const f=i?Zn(`${c}.${Ue(r)}`):void 0;return rg(()=>Uc(async()=>{try{return await e(r)}catch(y){const p=y;switch(p.code){case qi.code:throw new qi(p);case Gi.code:throw new Gi(p);case Vi.code:throw new Vi(p,{method:r.method});case Wi.code:throw new Wi(p);case fn.code:throw new fn(p);case dn.code:throw new dn(p);case Ki.code:throw new Ki(p);case Yi.code:throw new Yi(p);case Zi.code:throw new Zi(p);case en.code:throw new en(p,{method:r.method});case Jn.code:throw new Jn(p);case Xi.code:throw new Xi(p);case jn.code:throw new jn(p);case Ji.code:throw new Ji(p);case Qi.code:throw new Qi(p);case es.code:throw new es(p);case ts.code:throw new ts(p);case rs.code:throw new rs(p);case ns.code:throw new ns(p);case is.code:throw new is(p);case ss.code:throw new ss(p);case os.code:throw new os(p);case as.code:throw new as(p);case cs.code:throw new cs(p);case us.code:throw new us(p);case 5e3:throw new jn(p);default:throw y instanceof H?y:new i1(p)}}},{delay:({count:y,error:p})=>{var w;if(p&&p instanceof Dn){const b=(w=p==null?void 0:p.headers)==null?void 0:w.get("Retry-After");if(b!=null&&b.match(/\d/))return Number.parseInt(b)*1e3}return~~(1<<y)*o},retryCount:a,shouldRetry:({error:y})=>ig(y)}),{enabled:i,id:f})}}function ig(e){return"code"in e&&typeof e.code=="number"?e.code===-1||e.code===Jn.code||e.code===fn.code:e instanceof Dn&&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 u0({key:e,methods:t,name:r,request:n,retryCount:i=3,retryDelay:s=150,timeout:o,type:a},c){const u=a0();return{config:{key:e,methods:t,name:r,request:n,retryCount:i,retryDelay:s,timeout:o,type:a},request:ng(n,{methods:t,retryCount:i,retryDelay:s,uid:u}),value:c}}function od(e,t={}){const{key:r="custom",methods:n,name:i="Custom Provider",retryDelay:s}=t;return({retryCount:o})=>u0({key:r,methods:n,name:i,request:e.request.bind(e),retryCount:t.retryCount??o,retryDelay:s,type:"custom"})}class sg extends H{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 og(e,{errorInstance:t=new Error("timed out"),timeout:r,signal:n}){return new Promise((i,s)=>{(async()=>{let o;try{const a=new AbortController;r>0&&(o=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"&&s(t),s(a)}finally{clearTimeout(o)}})()})}function ag(){return{current:0,take(){return this.current++},reset(){this.current=0}}}const ad=ag();function cg(e,t={}){return{async request(r){var d;const{body:n,onRequest:i=t.onRequest,onResponse:s=t.onResponse,timeout:o=t.timeout??1e4}=r,a={...t.fetchOptions??{},...r.fetchOptions??{}},{headers:c,method:u,signal:f}=a;try{const y=await og(async({signal:w})=>{const b={...a,body:Array.isArray(n)?Ue(n.map(x=>({jsonrpc:"2.0",id:x.id??ad.take(),...x}))):Ue({jsonrpc:"2.0",id:n.id??ad.take(),...n}),headers:{"Content-Type":"application/json",...c},method:u||"POST",signal:f||(o>0?w:null)},m=new Request(e,b),_=await(i==null?void 0:i(m,b))??{...b,url:e};return await fetch(_.url??e,_)},{errorInstance:new Yf({body:n,url:e}),timeout:o,signal:!0});s&&await s(y);let p;if((d=y.headers.get("Content-Type"))!=null&&d.startsWith("application/json"))p=await y.json();else{p=await y.text();try{p=JSON.parse(p||"{}")}catch(w){if(y.ok)throw w;p={error:p}}}if(!y.ok)throw new Dn({body:n,details:Ue(p.error)||y.statusText,headers:y.headers,status:y.status,url:e});return p}catch(y){throw y instanceof Dn||y instanceof Yf?y:new Dn({body:n,cause:y,url:e})}}}}function f0(e,t={}){const{batch:r,fetchOptions:n,key:i="http",methods:s,name:o="HTTP JSON-RPC",onFetchRequest:a,onFetchResponse:c,retryDelay:u,raw:f}=t;return({chain:d,retryCount:y,timeout:p})=>{const{batchSize:w=1e3,wait:b=0}=typeof r=="object"?r:{},m=t.retryCount??y,_=p??t.timeout??1e4,E=d==null?void 0:d.rpcUrls.default.http[0];if(!E)throw new sg;const x=cg(E,{fetchOptions:n,onRequest:a,onResponse:c,timeout:_});return u0({key:i,methods:s,name:o,async request({method:v,params:B}){const S={method:v,params:B},{schedule:C}=Jh({id:E,wait:b,shouldSplitBatch(k){return k.length>w},fn:k=>x.request({body:k}),sort:(k,U)=>k.id-U.id}),N=async k=>r?C(k):[await x.request({body:k})],[{error:I,result:G}]=await N(S);if(f)return{error:I,result:G};if(I)throw new Au({body:S,error:I,url:E});return G},retryCount:m,retryDelay:u,timeout:_,type:"http"},{fetchOptions:n,url:E})}}function ju(e,t){var n,i,s,o,a,c;if(!(e instanceof H))return!1;const r=e.walk(u=>u instanceof Ec);return r instanceof Ec?!!(((n=r.data)==null?void 0:n.errorName)==="ResolverNotFound"||((i=r.data)==null?void 0:i.errorName)==="ResolverWildcardNotSupported"||((s=r.data)==null?void 0:s.errorName)==="ResolverNotContract"||((o=r.data)==null?void 0:o.errorName)==="ResolverError"||((a=r.data)==null?void 0:a.errorName)==="HttpError"||(c=r.reason)!=null&&c.includes("Wildcard on non-extended resolvers is not supported")||t==="reverse"&&r.reason===vh[50]):!1}function ug(e){const{abi:t,data:r}=e,n=un(r,0,4),i=t.find(s=>s.type==="function"&&n===Es(Nt(s)));if(!i)throw new Tm(n,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:i.name,args:"inputs"in i&&i.inputs&&i.inputs.length>0?Ss(i.inputs,un(r,4)):void 0}}const Oa="/docs/contract/encodeErrorResult";function cd(e){const{abi:t,errorName:r,args:n}=e;let i=t[0];if(r){const c=wn({abi:t,args:n,name:r});if(!c)throw new Nf(r,{docsPath:Oa});i=c}if(i.type!=="error")throw new Nf(void 0,{docsPath:Oa});const s=Nt(i),o=Es(s);let a="0x";if(n&&n.length>0){if(!i.inputs)throw new Am(i.name,{docsPath:Oa});a=xr(i.inputs,n)}return Mt([o,a])}const Ra="/docs/contract/encodeFunctionResult";function fg(e){const{abi:t,functionName:r,result:n}=e;let i=t[0];if(r){const o=wn({abi:t,name:r});if(!o)throw new Yn(r,{docsPath:Ra});i=o}if(i.type!=="function")throw new Yn(void 0,{docsPath:Ra});if(!i.outputs)throw new eh(i.name,{docsPath:Ra});const s=(()=>{if(i.outputs.length===0)return[];if(i.outputs.length===1)return[n];if(Array.isArray(n))return n;throw new th(n)})();return xr(i.outputs,s)}const zu="x-batch-gateway:true";async function dg(e){const{data:t,ccipRequest:r}=e,{args:[n]}=ug({abi:Nc,data:t}),i=[],s=[];return await Promise.all(n.map(async(o,a)=>{try{s[a]=await r(o),i[a]=!1}catch(c){i[a]=!0,s[a]=lg(c)}})),fg({abi:Nc,functionName:"query",result:[i,s]})}function lg(e){return e.name==="HttpRequestError"&&e.status?cd({abi:Nc,errorName:"HttpError",args:[e.status,e.shortMessage]}):cd({abi:[_h],errorName:"Error",args:["shortMessage"in e?e.shortMessage:e.message]})}function d0(e){if(e.length!==66||e.indexOf("[")!==0||e.indexOf("]")!==65)return null;const t=`0x${e.slice(1,65)}`;return $t(t)?t:null}function co(e){let t=new Uint8Array(32).fill(0);if(!e)return Me(t);const r=e.split(".");for(let n=r.length-1;n>=0;n-=1){const i=d0(r[n]),s=i?ui(i):Xe(rn(r[n]),"bytes");t=Xe(Jt([t,s]),"bytes")}return Me(t)}function hg(e){return`[${e.slice(2)}]`}function pg(e){const t=new Uint8Array(32).fill(0);return e?d0(e)||Xe(rn(e)):Me(t)}function Vo(e){const t=e.replace(/^\.|\.$/gm,"");if(t.length===0)return new Uint8Array(1);const r=new Uint8Array(rn(t).byteLength+2);let n=0;const i=t.split(".");for(let s=0;s<i.length;s++){let o=rn(i[s]);o.byteLength>255&&(o=rn(hg(pg(i[s])))),r[n]=o.length,r.set(o,n+1),n+=o.length+1}return r.byteLength!==n+1?r.slice(0,n+1):r}async function yg(e,t){const{blockNumber:r,blockTag:n,coinType:i,name:s,gatewayUrls:o,strict:a}=t,{chain:c}=e,u=(()=>{if(t.universalResolverAddress)return t.universalResolverAddress;if(!c)throw new Error("client chain not configured. universalResolverAddress is required.");return li({blockNumber:r,chain:c,contract:"ensUniversalResolver"})})(),f=c==null?void 0:c.ensTlds;if(f&&!f.some(d=>s.endsWith(d)))return null;try{const d=Pt({abi:nd,functionName:"addr",...i!=null?{args:[co(s),BigInt(i)]}:{args:[co(s)]}}),y={address:u,abi:Kh,functionName:"resolve",args:[ie(Vo(s)),d,o??[zu]],blockNumber:r,blockTag:n},w=await ee(e,Qt,"readContract")(y);if(w[0]==="0x")return null;const b=_n({abi:nd,args:i!=null?[co(s),BigInt(i)]:void 0,functionName:"addr",data:w[0]});return b==="0x"||Rt(b)==="0x00"?null:b}catch(d){if(a)throw d;if(ju(d,"resolve"))return null;throw d}}class mg extends H{constructor({data:t}){super("Unable to extract image from metadata. The metadata may be malformed or invalid.",{metaMessages:["- Metadata must be a JSON object with at least an `image`, `image_url` or `image_data` property.","",`Provided data: ${JSON.stringify(t)}`],name:"EnsAvatarInvalidMetadataError"})}}class vi extends H{constructor({reason:t}){super(`ENS NFT avatar URI is invalid. ${t}`,{name:"EnsAvatarInvalidNftUriError"})}}class qu extends H{constructor({uri:t}){super(`Unable to resolve ENS avatar URI "${t}". The URI may be malformed, invalid, or does not respond with a valid image.`,{name:"EnsAvatarUriResolutionError"})}}class bg extends H{constructor({namespace:t}){super(`ENS NFT avatar namespace "${t}" is not supported. Must be "erc721" or "erc1155".`,{name:"EnsAvatarUnsupportedNamespaceError"})}}const gg=/(?<protocol>https?:\/\/[^\/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/,wg=/^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/,vg=/^data:([a-zA-Z\-/+]*);base64,([^"].*)/,_g=/^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;async function xg(e){try{const t=await fetch(e,{method:"HEAD"});if(t.status===200){const r=t.headers.get("content-type");return r==null?void 0:r.startsWith("image/")}return!1}catch(t){return typeof t=="object"&&typeof t.response<"u"||!globalThis.hasOwnProperty("Image")?!1:new Promise(r=>{const n=new Image;n.onload=()=>{r(!0)},n.onerror=()=>{r(!1)},n.src=e})}}function ud(e,t){return e?e.endsWith("/")?e.slice(0,-1):e:t}function l0({uri:e,gatewayUrls:t}){const r=vg.test(e);if(r)return{uri:e,isOnChain:!0,isEncoded:r};const n=ud(t==null?void 0:t.ipfs,"https://ipfs.io"),i=ud(t==null?void 0:t.arweave,"https://arweave.net"),s=e.match(gg),{protocol:o,subpath:a,target:c,subtarget:u=""}=(s==null?void 0:s.groups)||{},f=o==="ipns:/"||a==="ipns/",d=o==="ipfs:/"||a==="ipfs/"||wg.test(e);if(e.startsWith("http")&&!f&&!d){let p=e;return t!=null&&t.arweave&&(p=e.replace(/https:\/\/arweave.net/g,t==null?void 0:t.arweave)),{uri:p,isOnChain:!1,isEncoded:!1}}if((f||d)&&c)return{uri:`${n}/${f?"ipns":"ipfs"}/${c}${u}`,isOnChain:!1,isEncoded:!1};if(o==="ar:/"&&c)return{uri:`${i}/${c}${u||""}`,isOnChain:!1,isEncoded:!1};let y=e.replace(_g,"");if(y.startsWith("<svg")&&(y=`data:image/svg+xml;base64,${btoa(y)}`),y.startsWith("data:")||y.startsWith("{"))return{uri:y,isOnChain:!0,isEncoded:!1};throw new qu({uri:e})}function h0(e){if(typeof e!="object"||!("image"in e)&&!("image_url"in e)&&!("image_data"in e))throw new mg({data:e});return e.image||e.image_url||e.image_data}async function Eg({gatewayUrls:e,uri:t}){try{const r=await fetch(t).then(i=>i.json());return await Gu({gatewayUrls:e,uri:h0(r)})}catch{throw new qu({uri:t})}}async function Gu({gatewayUrls:e,uri:t}){const{uri:r,isOnChain:n}=l0({uri:t,gatewayUrls:e});if(n||await xg(r))return r;throw new qu({uri:t})}function Ag(e){let t=e;t.startsWith("did:nft:")&&(t=t.replace("did:nft:","").replace(/_/g,"/"));const[r,n,i]=t.split("/"),[s,o]=r.split(":"),[a,c]=n.split(":");if(!s||s.toLowerCase()!=="eip155")throw new vi({reason:"Only EIP-155 supported"});if(!o)throw new vi({reason:"Chain ID not found"});if(!c)throw new vi({reason:"Contract address not found"});if(!i)throw new vi({reason:"Token ID not found"});if(!a)throw new vi({reason:"ERC namespace not found"});return{chainID:Number.parseInt(o),namespace:a.toLowerCase(),contractAddress:c,tokenID:i}}async function Sg(e,{nft:t}){if(t.namespace==="erc721")return Qt(e,{address:t.contractAddress,abi:[{name:"tokenURI",type:"function",stateMutability:"view",inputs:[{name:"tokenId",type:"uint256"}],outputs:[{name:"",type:"string"}]}],functionName:"tokenURI",args:[BigInt(t.tokenID)]});if(t.namespace==="erc1155")return Qt(e,{address:t.contractAddress,abi:[{name:"uri",type:"function",stateMutability:"view",inputs:[{name:"_id",type:"uint256"}],outputs:[{name:"",type:"string"}]}],functionName:"uri",args:[BigInt(t.tokenID)]});throw new bg({namespace:t.namespace})}async function Tg(e,{gatewayUrls:t,record:r}){return/eip155:/i.test(r)?Pg(e,{gatewayUrls:t,record:r}):Gu({uri:r,gatewayUrls:t})}async function Pg(e,{gatewayUrls:t,record:r}){const n=Ag(r),i=await Sg(e,{nft:n}),{uri:s,isOnChain:o,isEncoded:a}=l0({uri:i,gatewayUrls:t});if(o&&(s.includes("data:application/json;base64,")||s.startsWith("{"))){const u=a?atob(s.replace("data:application/json;base64,","")):s,f=JSON.parse(u);return Gu({uri:h0(f),gatewayUrls:t})}let c=n.tokenID;return n.namespace==="erc1155"&&(c=c.replace("0x","").padStart(64,"0")),Eg({gatewayUrls:t,uri:s.replace(/(?:0x)?{id}/,c)})}async function p0(e,t){const{blockNumber:r,blockTag:n,key:i,name:s,gatewayUrls:o,strict:a}=t,{chain:c}=e,u=(()=>{if(t.universalResolverAddress)return t.universalResolverAddress;if(!c)throw new Error("client chain not configured. universalResolverAddress is required.");return li({blockNumber:r,chain:c,contract:"ensUniversalResolver"})})(),f=c==null?void 0:c.ensTlds;if(f&&!f.some(d=>s.endsWith(d)))return null;try{const d={address:u,abi:Kh,functionName:"resolve",args:[ie(Vo(s)),Pt({abi:rd,functionName:"text",args:[co(s),i]}),o??[zu]],blockNumber:r,blockTag:n},p=await ee(e,Qt,"readContract")(d);if(p[0]==="0x")return null;const w=_n({abi:rd,functionName:"text",data:p[0]});return w===""?null:w}catch(d){if(a)throw d;if(ju(d,"resolve"))return null;throw d}}async function Bg(e,{blockNumber:t,blockTag:r,assetGatewayUrls:n,name:i,gatewayUrls:s,strict:o,universalResolverAddress:a}){const c=await ee(e,p0,"getEnsText")({blockNumber:t,blockTag:r,key:"avatar",name:i,universalResolverAddress:a,gatewayUrls:s,strict:o});if(!c)return null;try{return await Tg(e,{record:c,gatewayUrls:n})}catch{return null}}async function Ig(e,{address:t,blockNumber:r,blockTag:n,gatewayUrls:i,strict:s,universalResolverAddress:o}){let a=o;if(!a){if(!e.chain)throw new Error("client chain not configured. universalResolverAddress is required.");a=li({blockNumber:r,chain:e.chain,contract:"ensUniversalResolver"})}const c=`${t.toLowerCase().substring(2)}.addr.reverse`;try{const u={address:a,abi:L1,functionName:"reverse",args:[ie(Vo(c))],blockNumber:r,blockTag:n},f=ee(e,Qt,"readContract"),[d,y]=i?await f({...u,args:[...u.args,i]}):await f(u);return t.toLowerCase()!==y.toLowerCase()?null:d}catch(u){if(s)throw u;if(ju(u,"reverse"))return null;throw u}}async function kg(e,t){const{blockNumber:r,blockTag:n,name:i}=t,{chain:s}=e,o=(()=>{if(t.universalResolverAddress)return t.universalResolverAddress;if(!s)throw new Error("client chain not configured. universalResolverAddress is required.");return li({blockNumber:r,chain:s,contract:"ensUniversalResolver"})})(),a=s==null?void 0:s.ensTlds;if(a&&!a.some(u=>i.endsWith(u)))throw new Error(`${i} is not a valid ENS TLD (${a==null?void 0:a.join(", ")}) for chain "${s.name}" (id: ${s.id}).`);const[c]=await ee(e,Qt,"readContract")({address:o,abi:[{inputs:[{type:"bytes"}],name:"findResolver",outputs:[{type:"address"},{type:"bytes32"}],stateMutability:"view",type:"function"}],functionName:"findResolver",args:[ie(Vo(i))],blockNumber:r,blockTag:n});return c}async function y0(e,t){var m,_,E;const{account:r=e.account,blockNumber:n,blockTag:i="latest",blobs:s,data:o,gas:a,gasPrice:c,maxFeePerBlobGas:u,maxFeePerGas:f,maxPriorityFeePerGas:d,to:y,value:p,...w}=t,b=r?$e(r):void 0;try{vn(t);const v=(n?te(n):void 0)||i,B=(E=(_=(m=e.chain)==null?void 0:m.formatters)==null?void 0:_.transactionRequest)==null?void 0:E.format,C=(B||fi)({...Uo(w,{format:B}),from:b==null?void 0:b.address,blobs:s,data:o,gas:a,gasPrice:c,maxFeePerBlobGas:u,maxFeePerGas:f,maxPriorityFeePerGas:d,to:y,value:p}),N=await e.request({method:"eth_createAccessList",params:[C,v]});return{accessList:N.accessList,gasUsed:BigInt(N.gasUsed)}}catch(x){throw Xh(x,{...t,account:b,chain:e.chain})}}async function Cg(e){const t=No(e,{method:"eth_newBlockFilter"}),r=await e.request({method:"eth_newBlockFilter"});return{id:r,request:t(r),type:"block"}}async function m0(e,{address:t,args:r,event:n,events:i,fromBlock:s,strict:o,toBlock:a}={}){const c=i??(n?[n]:void 0),u=No(e,{method:"eth_newFilter"});let f=[];c&&(f=[c.flatMap(p=>As({abi:[p],eventName:p.name,args:r}))],n&&(f=f[0]));const d=await e.request({method:"eth_newFilter",params:[{address:t,fromBlock:typeof s=="bigint"?te(s):s,toBlock:typeof a=="bigint"?te(a):a,...f.length?{topics:f}:{}}]});return{abi:c,args:r,eventName:n?n.name:void 0,fromBlock:s,id:d,request:u(d),strict:!!o,toBlock:a,type:"event"}}async function b0(e){const t=No(e,{method:"eth_newPendingTransactionFilter"}),r=await e.request({method:"eth_newPendingTransactionFilter"});return{id:r,request:t(r),type:"transaction"}}async function Og(e){const t=await e.request({method:"eth_blobBaseFee"});return BigInt(t)}async function Rg(e,{blockHash:t,blockNumber:r,blockTag:n="latest"}={}){const i=r!==void 0?te(r):void 0;let s;return t?s=await e.request({method:"eth_getBlockTransactionCountByHash",params:[t]},{dedupe:!0}):s=await e.request({method:"eth_getBlockTransactionCountByNumber",params:[i||n]},{dedupe:!!i}),Lt(s)}async function fd(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=r!==void 0?te(r):void 0,s=await e.request({method:"eth_getCode",params:[t,i||n]},{dedupe:!!i});if(s!=="0x")return s}class Ng extends H{constructor({address:t}){super(`No EIP-712 domain found on contract "${t}".`,{metaMessages:["Ensure that:",`- The contract is deployed at the address "${t}".`,"- `eip712Domain()` function exists on the contract.","- `eip712Domain()` function matches signature to ERC-5267 specification."],name:"Eip712DomainNotFoundError"})}}async function $g(e,t){const{address:r,factory:n,factoryData:i}=t;try{const[s,o,a,c,u,f,d]=await ee(e,Qt,"readContract")({abi:Lg,address:r,functionName:"eip712Domain",factory:n,factoryData:i});return{domain:{name:o,version:a,chainId:Number(c),verifyingContract:u,salt:f},extensions:d,fields:s}}catch(s){const o=s;throw o.name==="ContractFunctionExecutionError"&&o.cause.name==="ContractFunctionZeroDataError"?new Ng({address:r}):o}}const Lg=[{inputs:[],name:"eip712Domain",outputs:[{name:"fields",type:"bytes1"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"},{name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"}];function Fg(e){var t;return{baseFeePerGas:e.baseFeePerGas.map(r=>BigInt(r)),gasUsedRatio:e.gasUsedRatio,oldestBlock:BigInt(e.oldestBlock),reward:(t=e.reward)==null?void 0:t.map(r=>r.map(n=>BigInt(n)))}}async function Ug(e,{blockCount:t,blockNumber:r,blockTag:n="latest",rewardPercentiles:i}){const s=r?te(r):void 0,o=await e.request({method:"eth_feeHistory",params:[te(t),s||n,i]},{dedupe:!!s});return Fg(o)}async function Mg(e,{filter:t}){const r=t.strict??!1,i=(await t.request({method:"eth_getFilterLogs",params:[t.id]})).map(s=>mr(s));return t.abi?Lu({abi:t.abi,logs:i,strict:r}):i}function Bt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}class Hg extends H{constructor({domain:t}){super(`Invalid domain "${Ue(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class Dg extends H{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 jg extends H{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function zg(e){const{domain:t={},message:r,primaryType:n}=e,i={EIP712Domain:E0({domain:t}),...e.types};x0({domain:t,message:r,primaryType:n,types:i});const s=["0x1901"];return t&&s.push(qg({domain:t,types:i})),n!=="EIP712Domain"&&s.push(g0({data:r,primaryType:n,types:i})),Xe(Jt(s))}function qg({domain:e,types:t}){return g0({data:e,primaryType:"EIP712Domain",types:t})}function g0({data:e,primaryType:t,types:r}){const n=w0({data:e,primaryType:t,types:r});return Xe(n)}function w0({data:e,primaryType:t,types:r}){const n=[{type:"bytes32"}],i=[Gg({primaryType:t,types:r})];for(const s of r[t]){const[o,a]=_0({types:r,name:s.name,type:s.type,value:e[s.name]});n.push(o),i.push(a)}return xr(n,i)}function Gg({primaryType:e,types:t}){const r=ie(Vg({primaryType:e,types:t}));return Xe(r)}function Vg({primaryType:e,types:t}){let r="";const n=v0({primaryType:e,types:t});n.delete(e);const i=[e,...Array.from(n).sort()];for(const s of i)r+=`${s}(${t[s].map(({name:o,type:a})=>`${a} ${o}`).join(",")})`;return r}function v0({primaryType:e,types:t},r=new Set){const n=e.match(/^\w*/u),i=n==null?void 0:n[0];if(r.has(i)||t[i]===void 0)return r;r.add(i);for(const s of t[i])v0({primaryType:s.type,types:t},r);return r}function _0({types:e,name:t,type:r,value:n}){if(e[r]!==void 0)return[{type:"bytes32"},Xe(w0({data:n,primaryType:r,types:e}))];if(r==="bytes")return n=`0x${(n.length%2?"0":"")+n.slice(2)}`,[{type:"bytes32"},Xe(n)];if(r==="string")return[{type:"bytes32"},Xe(ie(n))];if(r.lastIndexOf("]")===r.length-1){const i=r.slice(0,r.lastIndexOf("[")),s=n.map(o=>_0({name:t,type:i,types:e,value:o}));return[{type:"bytes32"},Xe(xr(s.map(([o])=>o),s.map(([,o])=>o)))]}return[{type:r},n]}function Wg(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(c,u)=>{const f={...u};for(const d of c){const{name:y,type:p}=d;p==="address"&&(f[y]=f[y].toLowerCase())}return f},o=i.EIP712Domain?t?s(i.EIP712Domain,t):{}:{},a=(()=>{if(n!=="EIP712Domain")return s(i[n],r)})();return Ue({domain:o,message:a,primaryType:n,types:i})}function x0(e){const{domain:t,message:r,primaryType:n,types:i}=e,s=(o,a)=>{for(const c of o){const{name:u,type:f}=c,d=a[u],y=f.match(gh);if(y&&(typeof d=="number"||typeof d=="bigint")){const[b,m,_]=y;te(d,{signed:m==="int",size:Number.parseInt(_)/8})}if(f==="address"&&typeof d=="string"&&!Ve(d))throw new dt({address:d});const p=f.match(wb);if(p){const[b,m]=p;if(m&&Oe(d)!==Number.parseInt(m))throw new Bm({expectedSize:Number.parseInt(m),givenSize:Oe(d)})}const w=i[f];w&&(Kg(f),s(w,d))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new Hg({domain:t});s(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])s(i[n],r);else throw new Dg({primaryType:n,types:i})}function E0({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 Kg(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new jg({type:e})}function Yg(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!Ve(i))throw new dt({address:i});if(n<0)throw new jo({chainId:n})}Vu(e)}function Zg(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Dh;for(const r of t){const n=Oe(r),i=Lt(un(r,0,1));if(n!==32)throw new C1({hash:r,size:n});if(i!==Hh)throw new O1({hash:r,version:i})}}Vu(e)}function Vu(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new jo({chainId:t});if(i&&!Ve(i))throw new dt({address:i});if(n&&n>Mo)throw new hn({maxFeePerGas:n});if(r&&n&&r>n)throw new fs({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Xg(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(t<=0)throw new jo({chainId:t});if(s&&!Ve(s))throw new dt({address:s});if(r||i)throw new H("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Mo)throw new hn({maxFeePerGas:n})}function Jg(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:s}=e;if(s&&!Ve(s))throw new dt({address:s});if(typeof t<"u"&&t<=0)throw new jo({chainId:t});if(r||i)throw new H("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Mo)throw new hn({maxFeePerGas:n})}function Wo(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let s=0;s<i.length;s++)if(i[s].length-2!==64)throw new Zb({storageKey:i[s]});if(!Ve(n,{strict:!1}))throw new dt({address:n});t.push([n,i])}return t}function Qg(e,t){const r=zh(e);return r==="eip1559"?rw(e,t):r==="eip2930"?nw(e,t):r==="eip4844"?tw(e,t):r==="eip7702"?ew(e,t):iw(e,t)}function ew(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:s,to:o,value:a,maxFeePerGas:c,maxPriorityFeePerGas:u,accessList:f,data:d}=e;Yg(e);const y=Wo(f),p=sw(r);return Mt(["0x04",Hr([ie(n),s?ie(s):"0x",u?ie(u):"0x",c?ie(c):"0x",i?ie(i):"0x",o??"0x",a?ie(a):"0x",d??"0x",y,p,...Cs(e,t)])])}function tw(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:u,accessList:f,data:d}=e;Zg(e);let y=e.blobVersionedHashes,p=e.sidecars;if(e.blobs&&(typeof y>"u"||typeof p>"u")){const x=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(S=>Me(S)),v=e.kzg,B=Cu({blobs:x,kzg:v});if(typeof y>"u"&&(y=Fh({commitments:B})),typeof p>"u"){const S=Ou({blobs:x,commitments:B,kzg:v});p=jh({blobs:x,commitments:B,proofs:S})}}const w=Wo(f),b=[ie(r),i?ie(i):"0x",u?ie(u):"0x",c?ie(c):"0x",n?ie(n):"0x",s??"0x",o?ie(o):"0x",d??"0x",w,a?ie(a):"0x",y??[],...Cs(e,t)],m=[],_=[],E=[];if(p)for(let x=0;x<p.length;x++){const{blob:v,commitment:B,proof:S}=p[x];m.push(v),_.push(B),E.push(S)}return Mt(["0x03",Hr(p?[b,m,_,E]:b)])}function rw(e,t){const{chainId:r,gas:n,nonce:i,to:s,value:o,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:u,data:f}=e;Vu(e);const d=Wo(u),y=[ie(r),i?ie(i):"0x",c?ie(c):"0x",a?ie(a):"0x",n?ie(n):"0x",s??"0x",o?ie(o):"0x",f??"0x",d,...Cs(e,t)];return Mt(["0x02",Hr(y)])}function nw(e,t){const{chainId:r,gas:n,data:i,nonce:s,to:o,value:a,accessList:c,gasPrice:u}=e;Xg(e);const f=Wo(c),d=[ie(r),s?ie(s):"0x",u?ie(u):"0x",n?ie(n):"0x",o??"0x",a?ie(a):"0x",i??"0x",f,...Cs(e,t)];return Mt(["0x01",Hr(d)])}function iw(e,t){const{chainId:r=0,gas:n,data:i,nonce:s,to:o,value:a,gasPrice:c}=e;Jg(e);let u=[s?ie(s):"0x",c?ie(c):"0x",n?ie(n):"0x",o??"0x",a?ie(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 Kb({v:t.v});return p})(),d=Rt(t.r),y=Rt(t.s);u=[...u,ie(f),d==="0x00"?"0x":d,y==="0x00"?"0x":y]}else r>0&&(u=[...u,ie(r),"0x","0x"]);return Hr(u)}function Cs(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const s=Rt(r.r),o=Rt(r.s);return[typeof i=="number"?i?ie(1):"0x":n===0n?"0x":n===1n?ie(1):n===27n?"0x":ie(1),s==="0x00"?"0x":s,o==="0x00"?"0x":o]}function sw(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{chainId:n,nonce:i,...s}=r,o=r.address;t.push([n?ie(n):"0x",o,i?ie(i):"0x",...Cs({},s)])}return t}const ow=`Ethereum Signed Message:
|
|
42
|
+
`;function aw(e){const t=typeof e=="string"?Zn(e):typeof e.raw=="string"?e.raw:Me(e.raw),r=Zn(`${ow}${Oe(t)}`);return Jt([r,t])}function A0(e,t){return Xe(aw(e),t)}const S0="0x6492649264926492649264926492649264926492649264926492649264926492";function cw(e){return bh(e,-32)===S0}function uw(e){const{address:t,data:r,signature:n,to:i="hex"}=e,s=Mt([xr([{type:"address"},{type:"bytes"},{type:"bytes"}],[t,r,n]),S0]);return i==="hex"?s:Ft(s)}function fw(e){return e.map(t=>({...t,value:BigInt(t.value)}))}function dw(e){return{...e,balance:e.balance?BigInt(e.balance):void 0,nonce:e.nonce?Lt(e.nonce):void 0,storageProof:e.storageProof?fw(e.storageProof):void 0}}async function lw(e,{address:t,blockNumber:r,blockTag:n,storageKeys:i}){const s=n??"latest",o=r!==void 0?te(r):void 0,a=await e.request({method:"eth_getProof",params:[t,i,o||s]});return dw(a)}async function hw(e,{address:t,blockNumber:r,blockTag:n="latest",slot:i}){const s=r!==void 0?te(r):void 0;return await e.request({method:"eth_getStorageAt",params:[t,i,s||n]})}async function Wu(e,{blockHash:t,blockNumber:r,blockTag:n,hash:i,index:s}){var f,d,y;const o=n||"latest",a=r!==void 0?te(r):void 0;let c=null;if(i?c=await e.request({method:"eth_getTransactionByHash",params:[i]},{dedupe:!0}):t?c=await e.request({method:"eth_getTransactionByBlockHashAndIndex",params:[t,te(s)]},{dedupe:!0}):c=await e.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[a||o,te(s)]},{dedupe:!!a}),!c)throw new Th({blockHash:t,blockNumber:r,blockTag:o,hash:i,index:s});return(((y=(d=(f=e.chain)==null?void 0:f.formatters)==null?void 0:d.transaction)==null?void 0:y.format)||Ho)(c)}async function pw(e,{hash:t,transactionReceipt:r}){const[n,i]=await Promise.all([ee(e,ks,"getBlockNumber")({}),t?ee(e,Wu,"getTransaction")({hash:t}):void 0]),s=(r==null?void 0:r.blockNumber)||(i==null?void 0:i.blockNumber);return s?n-s+1n:0n}async function Mc(e,{hash:t}){var i,s,o;const r=await e.request({method:"eth_getTransactionReceipt",params:[t]},{dedupe:!0});if(!r)throw new Ph({hash:t});return(((o=(s=(i=e.chain)==null?void 0:i.formatters)==null?void 0:s.transactionReceipt)==null?void 0:o.format)||s0)(r)}async function yw(e,t){var m;const{allowFailure:r=!0,batchSize:n,blockNumber:i,blockTag:s,multicallAddress:o,stateOverride:a}=t,c=t.contracts,u=n??(typeof((m=e.batch)==null?void 0:m.multicall)=="object"&&e.batch.multicall.batchSize||1024);let f=o;if(!f){if(!e.chain)throw new Error("client chain not configured. multicallAddress is required.");f=li({blockNumber:i,chain:e.chain,contract:"multicall3"})}const d=[[]];let y=0,p=0;for(let _=0;_<c.length;_++){const{abi:E,address:x,args:v,functionName:B}=c[_];try{const S=Pt({abi:E,args:v,functionName:B});p+=(S.length-2)/2,u>0&&p>u&&d[y].length>0&&(y++,p=(S.length-2)/2,d[y]=[]),d[y]=[...d[y],{allowFailure:!0,callData:S,target:x}]}catch(S){const C=ln(S,{abi:E,address:x,args:v,docsPath:"/docs/contract/multicall",functionName:B});if(!r)throw C;d[y]=[...d[y],{allowFailure:!0,callData:"0x",target:x}]}}const w=await Promise.allSettled(d.map(_=>ee(e,Qt,"readContract")({abi:Rc,address:f,args:[_],blockNumber:i,blockTag:s,functionName:"aggregate3",stateOverride:a}))),b=[];for(let _=0;_<w.length;_++){const E=w[_];if(E.status==="rejected"){if(!r)throw E.reason;for(let v=0;v<d[_].length;v++)b.push({status:"failure",error:E.reason,result:void 0});continue}const x=E.value;for(let v=0;v<x.length;v++){const{returnData:B,success:S}=x[v],{callData:C}=d[_][v],{abi:N,address:I,functionName:G,args:k}=c[b.length];try{if(C==="0x")throw new vs;if(!S)throw new Lo({data:B});const U=_n({abi:N,args:k,data:B,functionName:G});b.push(r?{result:U,status:"success"}:U)}catch(U){const z=ln(U,{abi:N,address:I,args:k,docsPath:"/docs/contract/multicall",functionName:G});if(!r)throw z;b.push({error:z,result:void 0,status:"failure"})}}}if(b.length!==c.length)throw new H("multicall results mismatch");return b}const mw="0.1.1";function bw(){return mw}class Be extends Error{constructor(t,r={}){const n=(()=>{var c;if(r.cause instanceof Be){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 Be&&r.cause.docsPath||r.docsPath,o=`https://oxlib.sh${i??""}`,a=[t||"An error occurred.",...r.metaMessages?["",...r.metaMessages]:[],...n||i?["",n?`Details: ${n}`:void 0,i?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
|
|
43
|
+
`);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@${bw()}`}),this.cause=r.cause,this.details=n,this.docs=o,this.docsPath=i,this.shortMessage=t}walk(t){return T0(this,t)}}function T0(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause?T0(e.cause,t):t?null:e}const gw="#__bigint";function ww(e,t,r){return JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString()+gw:i,r)}function vw(e,t){if(ld(e)>t)throw new kw({givenSize:ld(e),maxSize:t})}const rr={zero:48,nine:57,A:65,F:70,a:97,f:102};function dd(e){if(e>=rr.zero&&e<=rr.nine)return e-rr.zero;if(e>=rr.A&&e<=rr.F)return e-(rr.A-10);if(e>=rr.a&&e<=rr.f)return e-(rr.a-10)}function _w(e,t={}){const{dir:r,size:n=32}=t;if(n===0)return e;if(e.length>n)throw new Cw({size:e.length,targetSize:n,type:"Bytes"});const i=new Uint8Array(n);for(let s=0;s<n;s++){const o=r==="right";i[o?s:n-s-1]=e[o?s:e.length-s-1]}return i}function Ku(e,t){if(Tt(e)>t)throw new Lw({givenSize:Tt(e),maxSize:t})}function xw(e,t){if(typeof t=="number"&&t>0&&t>Tt(e)-1)throw new C0({offset:t,position:"start",size:Tt(e)})}function Ew(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Tt(e)!==r-t)throw new C0({offset:r,position:"end",size:Tt(e)})}function P0(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 Fw({size:Math.ceil(i.length/2),targetSize:n,type:"Hex"});return`0x${i[r==="right"?"padEnd":"padStart"](n*2,"0")}`}const Aw=new TextEncoder;function Sw(e){return e instanceof Uint8Array?e:typeof e=="string"?Pw(e):Tw(e)}function Tw(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Pw(e,t={}){const{size:r}=t;let n=e;r&&(Ku(e,r),n=yn(e,r));let i=n.slice(2);i.length%2&&(i=`0${i}`);const s=i.length/2,o=new Uint8Array(s);for(let a=0,c=0;a<s;a++){const u=dd(i.charCodeAt(c++)),f=dd(i.charCodeAt(c++));if(u===void 0||f===void 0)throw new Be(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);o[a]=u*16+f}return o}function Bw(e,t={}){const{size:r}=t,n=Aw.encode(e);return typeof r=="number"?(vw(n,r),Iw(n,r)):n}function Iw(e,t){return _w(e,{dir:"right",size:t})}function ld(e){return e.length}let kw=class extends Be{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${t}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}},Cw=class extends Be{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:"Bytes.SizeExceedsPaddingSizeError"})}};const Ow=new TextEncoder,Rw=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Nw(e,t={}){const{strict:r=!1}=t;if(!e)throw new hd(e);if(typeof e!="string")throw new hd(e);if(r&&!/^0x[0-9a-fA-F]*$/.test(e))throw new pd(e);if(!e.startsWith("0x"))throw new pd(e)}function er(...e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function B0(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Ku(r,t.size),pn(r,t.size)):r}function I0(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=Rw[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Ku(n,t.size),yn(n,t.size)):n}function ft(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const u=typeof e=="bigint"?"n":"";throw new k0({max:s?`${s}${u}`:void 0,min:`${o}${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?pn(c,n):c}function Yu(e,t={}){return I0(Ow.encode(e),t)}function pn(e,t){return P0(e,{dir:"left",size:t})}function yn(e,t){return P0(e,{dir:"right",size:t})}function Zu(e,t,r,n={}){const{strict:i}=n;xw(e,t);const s=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return i&&Ew(s,t,r),s}function Tt(e){return Math.ceil((e.length-2)/2)}function $w(e,t={}){const{strict:r=!1}=t;try{return Nw(e,{strict:r}),!0}catch{return!1}}class k0 extends Be{constructor({max:t,min:r,signed:n,size:i,value:s}){super(`Number \`${s}\` is not in safe${i?` ${i*8}-bit`:""}${n?" signed":" unsigned"} integer range ${t?`(\`${r}\` to \`${t}\`)`:`(above \`${r}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class hd extends Be{constructor(t){super(`Value \`${typeof t=="object"?ww(t):t}\` of type \`${typeof t}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}}class pd extends Be{constructor(t){super(`Value \`${t}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}}class Lw extends Be{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${t}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class C0 extends Be{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset \`${t}\` is out-of-bounds (size: \`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}class Fw extends Be{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 Uw(e){return{address:e.address,amount:ft(e.amount),index:ft(e.index),validatorIndex:ft(e.validatorIndex)}}function Mw(e){return{...typeof e.baseFeePerGas=="bigint"&&{baseFeePerGas:ft(e.baseFeePerGas)},...typeof e.blobBaseFee=="bigint"&&{blobBaseFee:ft(e.blobBaseFee)},...typeof e.feeRecipient=="string"&&{feeRecipient:e.feeRecipient},...typeof e.gasLimit=="bigint"&&{gasLimit:ft(e.gasLimit)},...typeof e.number=="bigint"&&{number:ft(e.number)},...typeof e.prevRandao=="bigint"&&{prevRandao:ft(e.prevRandao)},...typeof e.time=="bigint"&&{time:ft(e.time)},...e.withdrawals&&{withdrawals:e.withdrawals.map(Uw)}}}async function Hc(e,t){const{blockNumber:r,blockTag:n="latest",blocks:i,returnFullTransactions:s,traceTransfers:o,validation:a}=t;try{const c=[];for(const y of i){const p=y.blockOverrides?Mw(y.blockOverrides):void 0,w=y.calls.map(m=>{const _=m,E=_.account?$e(_.account):void 0,x={..._,data:_.abi?Pt(_):_.data,from:_.from??(E==null?void 0:E.address)};return vn(x),fi(x)}),b=y.stateOverrides?Tu(y.stateOverrides):void 0;c.push({blockOverrides:p,calls:w,stateOverrides:b})}const f=(r?te(r):void 0)||n;return(await e.request({method:"eth_simulateV1",params:[{blockStateCalls:c,returnFullTransactions:s,traceTransfers:o,validation:a},f]})).map((y,p)=>({...Bu(y),calls:y.calls.map((w,b)=>{var G,k;const{abi:m,args:_,functionName:E,to:x}=i[p].calls[b],v=((G=w.error)==null?void 0:G.data)??w.returnData,B=BigInt(w.gasUsed),S=(k=w.logs)==null?void 0:k.map(U=>mr(U)),C=w.status==="0x1"?"success":"failure",N=m&&C==="success"&&v!=="0x"?_n({abi:m,data:v,functionName:E}):null,I=(()=>{var z;if(C==="success")return;let U;if(((z=w.error)==null?void 0:z.data)==="0x"?U=new vs:w.error&&(U=new Lo(w.error)),!!U)return ln(U,{abi:m??[],address:x,args:_,functionName:E??"<unknown>"})})();return{data:v,gasUsed:B,logs:S,status:C,...C==="success"?{result:N}:{error:I}}})}))}catch(c){const u=c,f=Fo(u,{});throw f instanceof Ps?u:f}}var Dr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Hw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Dw(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 Qn={},Er={},qr={};Object.defineProperty(qr,"__esModule",{value:!0});qr.anumber=Dc;qr.abytes=O0;qr.ahash=zw;qr.aexists=qw;qr.aoutput=Gw;function Dc(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function jw(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function O0(e,...t){if(!jw(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 zw(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Dc(e.outputLen),Dc(e.blockLen)}function qw(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 Gw(e,t){O0(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var Os={},Ko={};Object.defineProperty(Ko,"__esModule",{value:!0});Ko.crypto=void 0;Ko.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.Hash=e.nextTick=e.byteSwapIfBE=e.isLE=void 0,e.isBytes=n,e.u8=i,e.u32=s,e.createView=o,e.rotr=a,e.rotl=c,e.byteSwap=u,e.byteSwap32=f,e.bytesToHex=y,e.hexToBytes=b,e.asyncLoop=_,e.utf8ToBytes=E,e.toBytes=x,e.concatBytes=v,e.checkOpts=S,e.wrapConstructor=C,e.wrapConstructorWithOpts=N,e.wrapXOFConstructorWithOpts=I,e.randomBytes=G;const t=Ko,r=qr;function n(k){return k instanceof Uint8Array||ArrayBuffer.isView(k)&&k.constructor.name==="Uint8Array"}function i(k){return new Uint8Array(k.buffer,k.byteOffset,k.byteLength)}function s(k){return new Uint32Array(k.buffer,k.byteOffset,Math.floor(k.byteLength/4))}function o(k){return new DataView(k.buffer,k.byteOffset,k.byteLength)}function a(k,U){return k<<32-U|k>>>U}function c(k,U){return k<<U|k>>>32-U>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function u(k){return k<<24&4278190080|k<<8&16711680|k>>>8&65280|k>>>24&255}e.byteSwapIfBE=e.isLE?k=>k:k=>u(k);function f(k){for(let U=0;U<k.length;U++)k[U]=u(k[U])}const d=Array.from({length:256},(k,U)=>U.toString(16).padStart(2,"0"));function y(k){(0,r.abytes)(k);let U="";for(let z=0;z<k.length;z++)U+=d[k[z]];return U}const p={_0:48,_9:57,A:65,F:70,a:97,f:102};function w(k){if(k>=p._0&&k<=p._9)return k-p._0;if(k>=p.A&&k<=p.F)return k-(p.A-10);if(k>=p.a&&k<=p.f)return k-(p.a-10)}function b(k){if(typeof k!="string")throw new Error("hex string expected, got "+typeof k);const U=k.length,z=U/2;if(U%2)throw new Error("hex string expected, got unpadded hex of length "+U);const F=new Uint8Array(z);for(let D=0,V=0;D<z;D++,V+=2){const X=w(k.charCodeAt(V)),J=w(k.charCodeAt(V+1));if(X===void 0||J===void 0){const W=k[V]+k[V+1];throw new Error('hex string expected, got non-hex character "'+W+'" at index '+V)}F[D]=X*16+J}return F}const m=async()=>{};e.nextTick=m;async function _(k,U,z){let F=Date.now();for(let D=0;D<k;D++){z(D);const V=Date.now()-F;V>=0&&V<U||(await(0,e.nextTick)(),F+=V)}}function E(k){if(typeof k!="string")throw new Error("utf8ToBytes expected string, got "+typeof k);return new Uint8Array(new TextEncoder().encode(k))}function x(k){return typeof k=="string"&&(k=E(k)),(0,r.abytes)(k),k}function v(...k){let U=0;for(let F=0;F<k.length;F++){const D=k[F];(0,r.abytes)(D),U+=D.length}const z=new Uint8Array(U);for(let F=0,D=0;F<k.length;F++){const V=k[F];z.set(V,D),D+=V.length}return z}class B{clone(){return this._cloneInto()}}e.Hash=B;function S(k,U){if(U!==void 0&&{}.toString.call(U)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(k,U)}function C(k){const U=F=>k().update(x(F)).digest(),z=k();return U.outputLen=z.outputLen,U.blockLen=z.blockLen,U.create=()=>k(),U}function N(k){const U=(F,D)=>k(D).update(x(F)).digest(),z=k({});return U.outputLen=z.outputLen,U.blockLen=z.blockLen,U.create=F=>k(F),U}function I(k){const U=(F,D)=>k(D).update(x(F)).digest(),z=k({});return U.outputLen=z.outputLen,U.blockLen=z.blockLen,U.create=F=>k(F),U}function G(k=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(k));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(k);throw new Error("crypto.getRandomValues must be defined")}})(Os);Object.defineProperty(Er,"__esModule",{value:!0});Er.HashMD=void 0;Er.setBigUint64=R0;Er.Chi=Vw;Er.Maj=Ww;const Na=qr,_i=Os;function R0(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+u,a,n)}function Vw(e,t,r){return e&t^~e&r}function Ww(e,t,r){return e&t^e&r^t&r}class Kw extends _i.Hash{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,_i.createView)(this.buffer)}update(t){(0,Na.aexists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,_i.toBytes)(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=(0,_i.createView)(t);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Na.aexists)(this),(0,Na.aoutput)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let d=o;d<i;d++)r[d]=0;R0(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,_i.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 d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}}Er.HashMD=Kw;Object.defineProperty(Qn,"__esModule",{value:!0});Qn.ripemd160=Qn.RIPEMD160=void 0;const Yw=Er,Li=Os,Zw=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),N0=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Xw=N0.map(e=>(9*e+5)%16);let Xu=[N0],Ju=[Xw];for(let e=0;e<4;e++)for(let t of[Xu,Ju])t.push(t[e].map(r=>Zw[r]));const $0=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),Jw=Xu.map((e,t)=>e.map(r=>$0[t][r])),Qw=Ju.map((e,t)=>e.map(r=>$0[t][r])),e2=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),t2=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function yd(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 Ws=new Uint32Array(16);let L0=class extends Yw.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=s|0}process(t,r){for(let p=0;p<16;p++,r+=4)Ws[p]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,u=this.h3|0,f=u,d=this.h4|0,y=d;for(let p=0;p<5;p++){const w=4-p,b=e2[p],m=t2[p],_=Xu[p],E=Ju[p],x=Jw[p],v=Qw[p];for(let B=0;B<16;B++){const S=(0,Li.rotl)(n+yd(p,s,a,u)+Ws[_[B]]+b,x[B])+d|0;n=d,d=u,u=(0,Li.rotl)(a,10)|0,a=s,s=S}for(let B=0;B<16;B++){const S=(0,Li.rotl)(i+yd(w,o,c,f)+Ws[E[B]]+m,v[B])+y|0;i=y,y=f,f=(0,Li.rotl)(c,10)|0,c=o,o=S}}this.set(this.h1+a+f|0,this.h2+u+y|0,this.h3+d+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){Ws.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};Qn.RIPEMD160=L0;Qn.ripemd160=(0,Li.wrapConstructor)(()=>new L0);function md(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function r2(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Qu(e,...t){if(!r2(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 bd(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 n2(e,t){Qu(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Ks=BigInt(2**32-1),gd=BigInt(32);function i2(e,t=!1){return t?{h:Number(e&Ks),l:Number(e>>gd&Ks)}:{h:Number(e>>gd&Ks)|0,l:Number(e&Ks)|0}}function s2(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:s,l:o}=i2(e[i],t);[r[i],n[i]]=[s,o]}return[r,n]}const o2=(e,t,r)=>e<<r|t>>>32-r,a2=(e,t,r)=>t<<r|e>>>32-r,c2=(e,t,r)=>t<<r-32|e>>>64-r,u2=(e,t,r)=>e<<r-32|t>>>64-r;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function f2(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}const wd=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function d2(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function vd(e){for(let t=0;t<e.length;t++)e[t]=d2(e[t])}function l2(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function F0(e){return typeof e=="string"&&(e=l2(e)),Qu(e),e}let h2=class{clone(){return this._cloneInto()}};function p2(e){const t=n=>e().update(F0(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}const U0=[],M0=[],H0=[],y2=BigInt(0),xi=BigInt(1),m2=BigInt(2),b2=BigInt(7),g2=BigInt(256),w2=BigInt(113);for(let e=0,t=xi,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],U0.push(2*(5*n+r)),M0.push((e+1)*(e+2)/2%64);let i=y2;for(let s=0;s<7;s++)t=(t<<xi^(t>>b2)*w2)%g2,t&m2&&(i^=xi<<(xi<<BigInt(s))-xi);H0.push(i)}const[v2,_2]=s2(H0,!0),_d=(e,t,r)=>r>32?c2(e,t,r):o2(e,t,r),xd=(e,t,r)=>r>32?u2(e,t,r):a2(e,t,r);function x2(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)r[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,u=r[c],f=r[c+1],d=_d(u,f,1)^r[a],y=xd(u,f,1)^r[a+1];for(let p=0;p<50;p+=10)e[o+p]^=d,e[o+p+1]^=y}let i=e[2],s=e[3];for(let o=0;o<24;o++){const a=M0[o],c=_d(i,s,a),u=xd(i,s,a),f=U0[o];i=e[f],s=e[f+1],e[f]=c,e[f+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=v2[n],e[1]^=_2[n]}r.fill(0)}class ef extends h2{constructor(t,r,n,i=!1,s=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,md(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=f2(this.state)}keccak(){wd||vd(this.state32),x2(this.state32,this.rounds),wd||vd(this.state32),this.posOut=0,this.pos=0}update(t){bd(this);const{blockLen:r,state:n}=this;t=F0(t);const i=t.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=t[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){bd(this,!1),Qu(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=t.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);t.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return md(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(n2(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return t||(t=new ef(r,n,i,o,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}}const E2=(e,t,r)=>p2(()=>new ef(t,e,r)),A2=E2(1,136,256/8);var pr={};Object.defineProperty(pr,"__esModule",{value:!0});pr.sha224=pr.sha256=pr.SHA256=void 0;const $a=Er,At=Os,S2=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]),Br=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ir=new Uint32Array(64);class tf extends $a.HashMD{constructor(){super(64,32,8,!1),this.A=Br[0]|0,this.B=Br[1]|0,this.C=Br[2]|0,this.D=Br[3]|0,this.E=Br[4]|0,this.F=Br[5]|0,this.G=Br[6]|0,this.H=Br[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[t,r,n,i,s,o,a,c]}set(t,r,n,i,s,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)Ir[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){const y=Ir[d-15],p=Ir[d-2],w=(0,At.rotr)(y,7)^(0,At.rotr)(y,18)^y>>>3,b=(0,At.rotr)(p,17)^(0,At.rotr)(p,19)^p>>>10;Ir[d]=b+Ir[d-7]+w+Ir[d-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){const y=(0,At.rotr)(a,6)^(0,At.rotr)(a,11)^(0,At.rotr)(a,25),p=f+y+(0,$a.Chi)(a,c,u)+S2[d]+Ir[d]|0,b=((0,At.rotr)(n,2)^(0,At.rotr)(n,13)^(0,At.rotr)(n,22))+(0,$a.Maj)(n,i,s)|0;f=u,u=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+b|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,s,o,a,c,u,f)}roundClean(){Ir.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}pr.SHA256=tf;class T2 extends tf{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}pr.sha256=(0,At.wrapConstructor)(()=>new tf);pr.sha224=(0,At.wrapConstructor)(()=>new T2);function D0(e,t={}){const{as:r=typeof e=="string"?"Hex":"Bytes"}=t,n=A2(Sw(e));return r==="Bytes"?n:I0(n)}class P2 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 B2={checksum:new P2(8192)},La=B2.checksum,I2=/^0x[a-fA-F0-9]{40}$/;function Yo(e,t={}){const{strict:r=!0}=t;if(!I2.test(e))throw new Ed({address:e,cause:new C2});if(r){if(e.toLowerCase()===e)return;if(k2(e)!==e)throw new Ed({address:e,cause:new O2})}}function k2(e){if(La.has(e))return La.get(e);Yo(e,{strict:!1});const t=e.substring(2).toLowerCase(),r=D0(Bw(t),{as:"Bytes"}),n=t.split("");for(let s=0;s<40;s+=2)r[s>>1]>>4>=8&&n[s]&&(n[s]=n[s].toUpperCase()),(r[s>>1]&15)>=8&&n[s+1]&&(n[s+1]=n[s+1].toUpperCase());const i=`0x${n.join("")}`;return La.set(e,i),i}function jc(e,t={}){const{strict:r=!0}=t??{};try{return Yo(e,{strict:r}),!0}catch{return!1}}class Ed extends Be{constructor({address:t,cause:r}){super(`Address "${t}" is invalid.`,{cause:r}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class C2 extends Be{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class O2 extends Be{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}function zc(e){let t=!0,r="",n=0,i="",s=!1;for(let o=0;o<e.length;o++){const a=e[o];if(["(",")",","].includes(a)&&(t=!0),a==="("&&n++,a===")"&&n--,!!t){if(n===0){if(a===" "&&["event","function","error",""].includes(i))i="";else if(i+=a,a===")"){s=!0;break}continue}if(a===" "){e[o-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!s)throw new Be("Unable to normalize signature.");return i}function qc(e,t){const r=typeof e,n=t.type;switch(n){case"address":return jc(e,{strict:!1});case"bool":return r==="boolean";case"function":return r==="string";case"string":return r==="string";default:return n==="tuple"&&"components"in t?Object.values(t.components).every((i,s)=>qc(Object.values(e)[s],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?r==="number"||r==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?r==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(e)&&e.every(i=>qc(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function j0(e,t,r){for(const n in e){const i=e[n],s=t[n];if(i.type==="tuple"&&s.type==="tuple"&&"components"in i&&"components"in s)return j0(i.components,s.components,r[n]);const o=[i.type,s.type];if(o.includes("address")&&o.includes("bytes20")?!0:o.includes("address")&&o.includes("string")?jc(r[n],{strict:!1}):o.includes("address")&&o.includes("bytes")?jc(r[n],{strict:!1}):!1)return o}}function z0(e,t={}){const{prepare:r=!0}=t,n=Array.isArray(e)||typeof e=="string"?Of(e):e;return{...n,...r?{hash:Mn(n)}:{}}}function R2(e,t,r){const{args:n=[],prepare:i=!0}=r??{},s=$w(t,{strict:!1}),o=e.filter(u=>s?u.type==="function"||u.type==="error"?q0(u)===Zu(t,0,4):u.type==="event"?Mn(u)===t:!1:"name"in u&&u.name===t);if(o.length===0)throw new Gc({name:t});if(o.length===1)return{...o[0],...i?{hash:Mn(o[0])}:{}};let a;for(const u of o){if(!("inputs"in u))continue;if(!n||n.length===0){if(!u.inputs||u.inputs.length===0)return{...u,...i?{hash:Mn(u)}:{}};continue}if(!u.inputs||u.inputs.length===0||u.inputs.length!==n.length)continue;if(n.every((d,y)=>{const p="inputs"in u&&u.inputs[y];return p?qc(d,p):!1})){if(a&&"inputs"in a&&a.inputs){const d=j0(u.inputs,a.inputs,n);if(d)throw new $2({abiItem:u,type:d[0]},{abiItem:a,type:d[1]})}a=u}}const c=(()=>{if(a)return a;const[u,...f]=o;return{...u,overloads:f}})();if(!c)throw new Gc({name:t});return{...c,...i?{hash:Mn(c)}:{}}}function q0(e){return Zu(Mn(e),0,4)}function N2(e){const t=typeof e=="string"?e:wo(e);return zc(t)}function Mn(e){return typeof e!="string"&&"hash"in e&&e.hash?e.hash:D0(Yu(N2(e)))}class $2 extends Be{constructor(t,r){super("Found ambiguous types in overloaded ABI Items.",{metaMessages:[`\`${t.type}\` in \`${zc(wo(t.abiItem))}\`, and`,`\`${r.type}\` in \`${zc(wo(r.abiItem))}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiItem.AmbiguityError"})}}class Gc extends Be{constructor({name:t,data:r,type:n="item"}){const i=t?` with name "${t}"`:r?` with data "${r}"`:"";super(`ABI ${n}${i} not found.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiItem.NotFoundError"})}}const L2=/^(.*)\[([0-9]*)\]$/,F2=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,G0=/^(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 U2({checksumAddress:e,parameters:t,values:r}){const n=[];for(let i=0;i<t.length;i++)n.push(rf({checksumAddress:e,parameter:t[i],value:r[i]}));return n}function rf({checksumAddress:e=!1,parameter:t,value:r}){const n=t,i=V2(n.type);if(i){const[s,o]=i;return H2(r,{checksumAddress:e,length:s,parameter:{...n,type:o}})}if(n.type==="tuple")return G2(r,{checksumAddress:e,parameter:n});if(n.type==="address")return M2(r,{checksum:e});if(n.type==="bool")return j2(r);if(n.type.startsWith("uint")||n.type.startsWith("int")){const s=n.type.startsWith("int"),[,,o="256"]=G0.exec(n.type)??[];return z2(r,{signed:s,size:Number(o)})}if(n.type.startsWith("bytes"))return D2(r,{type:n.type});if(n.type==="string")return q2(r);throw new Y0(n.type)}function nf(e){let t=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?t+=32:t+=Tt(a)}const r=[],n=[];let i=0;for(let s=0;s<e.length;s++){const{dynamic:o,encoded:a}=e[s];o?(r.push(ft(t+i,{size:32})),n.push(a),i+=Tt(a)):r.push(a)}return er(...r,...n)}function M2(e,t){const{checksum:r=!1}=t;return Yo(e,{strict:r}),{dynamic:!1,encoded:pn(e.toLowerCase())}}function H2(e,t){const{checksumAddress:r,length:n,parameter:i}=t,s=n===null;if(!Array.isArray(e))throw new K2(e);if(!s&&e.length!==n)throw new W2({expectedLength:n,givenLength:e.length,type:`${i.type}[${n}]`});let o=!1;const a=[];for(let c=0;c<e.length;c++){const u=rf({checksumAddress:r,parameter:i,value:e[c]});u.dynamic&&(o=!0),a.push(u)}if(s||o){const c=nf(a);if(s){const u=ft(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?er(u,c):u}}if(o)return{dynamic:!0,encoded:c}}return{dynamic:!1,encoded:er(...a.map(({encoded:c})=>c))}}function D2(e,{type:t}){const[,r]=t.split("bytes"),n=Tt(e);if(!r){let i=e;return n%32!==0&&(i=yn(i,Math.ceil((e.length-2)/2/32)*32)),{dynamic:!0,encoded:er(pn(ft(n,{size:32})),i)}}if(n!==Number.parseInt(r))throw new W0({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:yn(e)}}function j2(e){if(typeof e!="boolean")throw new Be(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:pn(B0(e))}}function z2(e,{signed:t,size:r}){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 k0({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:ft(e,{size:32,signed:t})}}function q2(e){const t=Yu(e),r=Math.ceil(Tt(t)/32),n=[];for(let i=0;i<r;i++)n.push(yn(Zu(t,i*32,(i+1)*32)));return{dynamic:!0,encoded:er(yn(ft(Tt(t),{size:32})),...n)}}function G2(e,t){const{checksumAddress:r,parameter:n}=t;let i=!1;const s=[];for(let o=0;o<n.components.length;o++){const a=n.components[o],c=Array.isArray(e)?o:a.name,u=rf({checksumAddress:r,parameter:a,value:e[c]});s.push(u),u.dynamic&&(i=!0)}return{dynamic:i,encoded:i?nf(s):er(...s.map(({encoded:o})=>o))}}function V2(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function V0(e,t,r){const{checksumAddress:n=!1}={};if(e.length!==t.length)throw new K0({expectedLength:e.length,givenLength:t.length});const i=U2({checksumAddress:n,parameters:e,values:t}),s=nf(i);return s.length===0?"0x":s}function Vc(e,t){if(e.length!==t.length)throw new K0({expectedLength:e.length,givenLength:t.length});const r=[];for(let n=0;n<e.length;n++){const i=e[n],s=t[n];r.push(Vc.encode(i,s))}return er(...r)}(function(e){function t(r,n,i=!1){if(r==="address"){const c=n;return Yo(c),pn(c.toLowerCase(),i?32:0)}if(r==="string")return Yu(n);if(r==="bytes")return n;if(r==="bool")return pn(B0(n),i?32:1);const s=r.match(G0);if(s){const[c,u,f="256"]=s,d=Number.parseInt(f)/8;return ft(n,{size:i?32:d,signed:u==="int"})}const o=r.match(F2);if(o){const[c,u]=o;if(Number.parseInt(u)!==(n.length-2)/2)throw new W0({expectedSize:Number.parseInt(u),value:n});return yn(n,i?32:0)}const a=r.match(L2);if(a&&Array.isArray(n)){const[c,u]=a,f=[];for(let d=0;d<n.length;d++)f.push(t(u,n[d],!0));return f.length===0?"0x":er(...f)}throw new Y0(r)}e.encode=t})(Vc||(Vc={}));class W2 extends Be{constructor({expectedLength:t,givenLength:r,type:n}){super(`Array length mismatch for type \`${n}\`. Expected: \`${t}\`. Given: \`${r}\`.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.ArrayLengthMismatchError"})}}class W0 extends Be{constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${Tt(r)}) does not match expected size (bytes${t}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class K0 extends Be{constructor({expectedLength:t,givenLength:r}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${t}`,`Given length (values): ${r}`].join(`
|
|
44
|
+
`)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class K2 extends Be{constructor(t){super(`Value \`${t}\` is not a valid array.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidArrayError"})}}class Y0 extends Be{constructor(t){super(`Type \`${t}\` is not a valid ABI Type.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidTypeError"})}}function Y2(e,t){var i;const{bytecode:r,args:n}=t;return er(r,(i=e.inputs)!=null&&i.length&&(n!=null&&n.length)?V0(e.inputs,n):"0x")}function Z2(e){return z0(e)}function X2(e,...t){const{overloads:r}=e,n=r?J2([e,...r],e.name,{args:t[0]}):e,i=Q2(n),s=t.length>0?V0(n.inputs,t[0]):void 0;return s?er(i,s):i}function kn(e,t={}){return z0(e,t)}function J2(e,t,r){const n=R2(e,t,r);if(n.type!=="function")throw new Gc({name:t,type:"function"});return n}function Q2(e){return q0(e)}const ev="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",jt="0x0000000000000000000000000000000000000000",tv="0x6080604052348015600e575f80fd5b5061016d8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063f8b2cb4f1461002d575b5f80fd5b610047600480360381019061004291906100db565b61005d565b604051610054919061011e565b60405180910390f35b5f8173ffffffffffffffffffffffffffffffffffffffff16319050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100aa82610081565b9050919050565b6100ba816100a0565b81146100c4575f80fd5b50565b5f813590506100d5816100b1565b92915050565b5f602082840312156100f0576100ef61007d565b5b5f6100fd848285016100c7565b91505092915050565b5f819050919050565b61011881610106565b82525050565b5f6020820190506101315f83018461010f565b9291505056fea26469706673582212203b9fe929fe995c7cf9887f0bdba8a36dd78e8b73f149b17d2d9ad7cd09d2dc6264736f6c634300081a0033";async function rv(e,t){const{blockNumber:r,blockTag:n,calls:i,stateOverrides:s,traceAssetChanges:o,traceTransfers:a,validation:c}=t,u=t.account?$e(t.account):void 0;if(o&&!u)throw new H("`account` is required when `traceAssetChanges` is true");const f=u?Y2(Z2("constructor(bytes, bytes)"),{bytecode:Yh,args:[tv,X2(kn("function getBalance(address)"),[u.address])]}):void 0,d=o?await Promise.all(t.calls.map(async W=>{if(!W.data&&!W.abi)return;const{accessList:se}=await y0(e,{account:u.address,...W,data:W.abi?Pt(W):W.data});return se.map(({address:ne,storageKeys:ae})=>ae.length>0?ne:null)})).then(W=>W.flat().filter(Boolean)):[],y=s==null?void 0:s.map(W=>W.address===(u==null?void 0:u.address)?{...W,nonce:0}:W),p=await Hc(e,{blockNumber:r,blockTag:n,blocks:[...o?[{calls:[{data:f}],stateOverrides:s},{calls:d.map((W,se)=>({abi:[kn("function balanceOf(address) returns (uint256)")],functionName:"balanceOf",args:[u.address],to:W,from:jt,nonce:se})),stateOverrides:[{address:jt,nonce:0}]}]:[],{calls:[...i,{}].map((W,se)=>({...W,from:u==null?void 0:u.address,nonce:se})),stateOverrides:y},...o?[{calls:[{data:f}]},{calls:d.map((W,se)=>({abi:[kn("function balanceOf(address) returns (uint256)")],functionName:"balanceOf",args:[u.address],to:W,from:jt,nonce:se})),stateOverrides:[{address:jt,nonce:0}]},{calls:d.map((W,se)=>({to:W,abi:[kn("function decimals() returns (uint256)")],functionName:"decimals",from:jt,nonce:se})),stateOverrides:[{address:jt,nonce:0}]},{calls:d.map((W,se)=>({to:W,abi:[kn("function tokenURI(uint256) returns (string)")],functionName:"tokenURI",args:[0n],from:jt,nonce:se})),stateOverrides:[{address:jt,nonce:0}]},{calls:d.map((W,se)=>({to:W,abi:[kn("function symbol() returns (string)")],functionName:"symbol",from:jt,nonce:se})),stateOverrides:[{address:jt,nonce:0}]}]:[]],traceTransfers:a,validation:c}),w=o?p[2]:p[0],[b,m,,_,E,x,v,B]=o?p:[],{calls:S,...C}=w,N=S.slice(0,-1)??[],I=(b==null?void 0:b.calls)??[],G=(m==null?void 0:m.calls)??[],k=[...I,...G].map(W=>W.status==="success"?Ze(W.data):null),U=(_==null?void 0:_.calls)??[],z=(E==null?void 0:E.calls)??[],F=[...U,...z].map(W=>W.status==="success"?Ze(W.data):null),D=((x==null?void 0:x.calls)??[]).map(W=>W.status==="success"?W.result:null),V=((B==null?void 0:B.calls)??[]).map(W=>W.status==="success"?W.result:null),X=((v==null?void 0:v.calls)??[]).map(W=>W.status==="success"?W.result:null),J=[];for(const[W,se]of F.entries()){const ne=k[W];if(typeof se!="bigint"||typeof ne!="bigint")continue;const ae=D[W-1],be=V[W-1],xe=X[W-1],He=W===0?{address:ev,decimals:18,symbol:"ETH"}:{address:d[W-1],decimals:xe||ae?Number(ae??1):void 0,symbol:be??void 0};J.some(R=>R.token.address===He.address)||J.push({token:He,value:{pre:ne,post:se,diff:se-ne}})}return{assetChanges:J,block:C,results:N}}class Z0 extends bu{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,qm(t);const n=Co(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(n.length>i?t.create().update(n).digest():n);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return Xn(this),this.iHash.update(t),this}digestInto(t){Xn(this),_s(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const X0=(e,t,r)=>new Z0(e,t).update(r).digest();X0.create=(e,t)=>new Z0(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const sf=BigInt(0),Wc=BigInt(1);function ei(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function of(e){if(!ei(e))throw new Error("Uint8Array expected")}function ds(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Ys(e){const t=e.toString(16);return t.length&1?"0"+t:t}function J0(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?sf:BigInt("0x"+e)}const Q0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",nv=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ls(e){if(of(e),Q0)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=nv[e[r]];return t}const nr={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ad(e){if(e>=nr._0&&e<=nr._9)return e-nr._0;if(e>=nr.A&&e<=nr.F)return e-(nr.A-10);if(e>=nr.a&&e<=nr.f)return e-(nr.a-10)}function _o(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Q0)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=Ad(e.charCodeAt(s)),a=Ad(e.charCodeAt(s+1));if(o===void 0||a===void 0){const c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function nn(e){return J0(ls(e))}function ep(e){return of(e),J0(ls(Uint8Array.from(e).reverse()))}function hs(e,t){return _o(e.toString(16).padStart(t*2,"0"))}function tp(e,t){return hs(e,t).reverse()}function Ct(e,t,r){let n;if(typeof t=="string")try{n=_o(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(ei(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const i=n.length;if(typeof r=="number"&&i!==r)throw new Error(e+" of length "+r+" expected, got "+i);return n}function xo(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];of(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const s=e[n];r.set(s,i),i+=s.length}return r}const Fa=e=>typeof e=="bigint"&&sf<=e;function af(e,t,r){return Fa(e)&&Fa(t)&&Fa(r)&&t<=e&&e<r}function zn(e,t,r,n){if(!af(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function iv(e){let t;for(t=0;e>sf;e>>=Wc,t+=1);return t}const Zo=e=>(Wc<<BigInt(e))-Wc,Ua=e=>new Uint8Array(e),Sd=e=>Uint8Array.from(e);function sv(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Ua(e),i=Ua(e),s=0;const o=()=>{n.fill(1),i.fill(0),s=0},a=(...d)=>r(i,n,...d),c=(d=Ua(0))=>{i=a(Sd([0]),d),n=a(),d.length!==0&&(i=a(Sd([1]),d),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let d=0;const y=[];for(;d<t;){n=a();const p=n.slice();y.push(p),d+=n.length}return xo(...y)};return(d,y)=>{o(),c(d);let p;for(;!(p=y(u()));)c();return o(),p}}const ov={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||ei(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Xo(e,t,r={}){const n=(i,s,o)=>{const a=ov[s];if(typeof a!="function")throw new Error("invalid validator function");const c=e[i];if(!(o&&c===void 0)&&!a(c,e))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+c)};for(const[i,s]of Object.entries(t))n(i,s,!1);for(const[i,s]of Object.entries(r))n(i,s,!0);return e}function Td(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(i!==void 0)return i;const s=e(r,...n);return t.set(r,s),s}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ge=BigInt(0),Ne=BigInt(1),Jr=BigInt(2),av=BigInt(3),Kc=BigInt(4),Pd=BigInt(5),Bd=BigInt(8);function ht(e,t){const r=e%t;return r>=Ge?r:t+r}function cv(e,t,r){if(t<Ge)throw new Error("invalid exponent, negatives unsupported");if(r<=Ge)throw new Error("invalid modulus");if(r===Ne)return Ge;let n=Ne;for(;t>Ge;)t&Ne&&(n=n*e%r),e=e*e%r,t>>=Ne;return n}function xt(e,t,r){let n=e;for(;t-- >Ge;)n*=n,n%=r;return n}function Yc(e,t){if(e===Ge)throw new Error("invert: expected non-zero number");if(t<=Ge)throw new Error("invert: expected positive modulus, got "+t);let r=ht(e,t),n=t,i=Ge,s=Ne;for(;r!==Ge;){const a=n/r,c=n%r,u=i-s*a;n=r,r=c,i=s,s=u}if(n!==Ne)throw new Error("invert: does not exist");return ht(i,t)}function uv(e){const t=(e-Ne)/Jr;let r,n,i;for(r=e-Ne,n=0;r%Jr===Ge;r/=Jr,n++);for(i=Jr;i<e&&cv(i,t,e)!==e-Ne;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const o=(e+Ne)/Kc;return function(c,u){const f=c.pow(u,o);if(!c.eql(c.sqr(f),u))throw new Error("Cannot find square root");return f}}const s=(r+Ne)/Jr;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,f=a.pow(a.mul(a.ONE,i),r),d=a.pow(c,s),y=a.pow(c,r);for(;!a.eql(y,a.ONE);){if(a.eql(y,a.ZERO))return a.ZERO;let p=1;for(let b=a.sqr(y);p<u&&!a.eql(b,a.ONE);p++)b=a.sqr(b);const w=a.pow(f,Ne<<BigInt(u-p-1));f=a.sqr(w),d=a.mul(d,w),y=a.mul(y,f),u=p}return d}}function fv(e){if(e%Kc===av){const t=(e+Ne)/Kc;return function(n,i){const s=n.pow(i,t);if(!n.eql(n.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%Bd===Pd){const t=(e-Pd)/Bd;return function(n,i){const s=n.mul(i,Jr),o=n.pow(s,t),a=n.mul(i,o),c=n.mul(n.mul(a,Jr),o),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return uv(e)}const dv=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function lv(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=dv.reduce((n,i)=>(n[i]="function",n),t);return Xo(e,r)}function hv(e,t,r){if(r<Ge)throw new Error("invalid exponent, negatives unsupported");if(r===Ge)return e.ONE;if(r===Ne)return t;let n=e.ONE,i=t;for(;r>Ge;)r&Ne&&(n=e.mul(n,i)),i=e.sqr(i),r>>=Ne;return n}function pv(e,t){const r=new Array(t.length),n=t.reduce((s,o,a)=>e.is0(o)?s:(r[a]=s,e.mul(s,o)),e.ONE),i=e.inv(n);return t.reduceRight((s,o,a)=>e.is0(o)?s:(r[a]=e.mul(s,r[a]),e.mul(s,o)),i),r}function rp(e,t){const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function np(e,t,r=!1,n={}){if(e<=Ge)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:i,nByteLength:s}=rp(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:s,MASK:Zo(i),ZERO:Ge,ONE:Ne,create:c=>ht(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Ge<=c&&c<e},is0:c=>c===Ge,isOdd:c=>(c&Ne)===Ne,neg:c=>ht(-c,e),eql:(c,u)=>c===u,sqr:c=>ht(c*c,e),add:(c,u)=>ht(c+u,e),sub:(c,u)=>ht(c-u,e),mul:(c,u)=>ht(c*u,e),pow:(c,u)=>hv(a,c,u),div:(c,u)=>ht(c*Yc(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Yc(c,e),sqrt:n.sqrt||(c=>(o||(o=fv(e)),o(a,c))),invertBatch:c=>pv(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>r?tp(c,s):hs(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?ep(c):nn(c)}});return Object.freeze(a)}function ip(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function sp(e){const t=ip(e);return t+Math.ceil(t/2)}function yv(e,t,r=!1){const n=e.length,i=ip(t),s=sp(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const o=r?ep(e):nn(e),a=ht(o,t-Ne)+Ne;return r?tp(a,i):hs(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Id=BigInt(0),Zc=BigInt(1);function Ma(e,t){const r=t.negate();return e?r:t}function op(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ha(e,t){op(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1),i=2**e,s=Zo(e),o=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:i,shiftBy:o}}function kd(e,t,r){const{windowSize:n,mask:i,maxNumber:s,shiftBy:o}=r;let a=Number(e&i),c=e>>o;a>n&&(a-=s,c+=Zc);const u=t*n,f=u+Math.abs(a)-1,d=a===0,y=a<0,p=t%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:y,isNegF:p,offsetF:u}}function mv(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function bv(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}const Da=new WeakMap,ap=new WeakMap;function ja(e){return ap.get(e)||1}function gv(e,t){return{constTimeNegate:Ma,hasPrecomputes(r){return ja(r)!==1},unsafeLadder(r,n,i=e.ZERO){let s=r;for(;n>Id;)n&Zc&&(i=i.add(s)),s=s.double(),n>>=Zc;return i},precomputeWindow(r,n){const{windows:i,windowSize:s}=Ha(n,t),o=[];let a=r,c=a;for(let u=0;u<i;u++){c=a,o.push(c);for(let f=1;f<s;f++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,n,i){let s=e.ZERO,o=e.BASE;const a=Ha(r,t);for(let c=0;c<a.windows;c++){const{nextN:u,offset:f,isZero:d,isNeg:y,isNegF:p,offsetF:w}=kd(i,c,a);i=u,d?o=o.add(Ma(p,n[w])):s=s.add(Ma(y,n[f]))}return{p:s,f:o}},wNAFUnsafe(r,n,i,s=e.ZERO){const o=Ha(r,t);for(let a=0;a<o.windows&&i!==Id;a++){const{nextN:c,offset:u,isZero:f,isNeg:d}=kd(i,a,o);if(i=c,!f){const y=n[u];s=s.add(d?y.negate():y)}}return s},getPrecomputes(r,n,i){let s=Da.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Da.set(n,i(s))),s},wNAFCached(r,n,i){const s=ja(r);return this.wNAF(s,this.getPrecomputes(s,r,i),n)},wNAFCachedUnsafe(r,n,i,s){const o=ja(r);return o===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,i),n,s)},setWindowSize(r,n){op(n,t),ap.set(r,n),Da.delete(r)}}}function wv(e,t,r,n){if(mv(r,e),bv(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=e.ZERO,s=iv(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=Zo(o),c=new Array(Number(a)+1).fill(i),u=Math.floor((t.BITS-1)/o)*o;let f=i;for(let d=u;d>=0;d-=o){c.fill(i);for(let p=0;p<n.length;p++){const w=n[p],b=Number(w>>BigInt(d)&a);c[b]=c[b].add(r[p])}let y=i;for(let p=c.length-1,w=i;p>0;p--)w=w.add(c[p]),y=y.add(w);if(f=f.add(y),d!==0)for(let p=0;p<o;p++)f=f.double()}return f}function cp(e){return lv(e.Fp),Xo(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...rp(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Cd(e){e.lowS!==void 0&&ds("lowS",e.lowS),e.prehash!==void 0&&ds("prehash",e.prehash)}function vv(e){const t=cp(e);Xo(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:i}=t;if(r){if(!n.eql(i,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}class _v extends Error{constructor(t=""){super(t)}}const ur={Err:_v,_tlv:{encode:(e,t)=>{const{Err:r}=ur;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");const n=t.length/2,i=Ys(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const s=n>127?Ys(i.length/2|128):"";return Ys(e)+s+i+t},decode(e,t){const{Err:r}=ur;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const i=t[n++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");const u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){const{Err:t}=ur;if(e<fr)throw new t("integer: negative integers are not allowed");let r=Ys(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=ur;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return nn(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=ur,i=Ct("signature",e),{v:s,l:o}=n.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){const{_tlv:t,_int:r}=ur,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s)),s=n+i;return t.encode(48,s)}},fr=BigInt(0),ze=BigInt(1);BigInt(2);const Od=BigInt(3);BigInt(4);function xv(e){const t=vv(e),{Fp:r}=t,n=np(t.n,t.nBitLength),i=t.toBytes||((b,m,_)=>{const E=m.toAffine();return xo(Uint8Array.from([4]),r.toBytes(E.x),r.toBytes(E.y))}),s=t.fromBytes||(b=>{const m=b.subarray(1),_=r.fromBytes(m.subarray(0,r.BYTES)),E=r.fromBytes(m.subarray(r.BYTES,2*r.BYTES));return{x:_,y:E}});function o(b){const{a:m,b:_}=t,E=r.sqr(b),x=r.mul(E,b);return r.add(r.add(x,r.mul(b,m)),_)}if(!r.eql(r.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return af(b,ze,t.n)}function c(b){const{allowedPrivateKeyLengths:m,nByteLength:_,wrapPrivateKey:E,n:x}=t;if(m&&typeof b!="bigint"){if(ei(b)&&(b=ls(b)),typeof b!="string"||!m.includes(b.length))throw new Error("invalid private key");b=b.padStart(_*2,"0")}let v;try{v=typeof b=="bigint"?b:nn(Ct("private key",b,_))}catch{throw new Error("invalid private key, expected hex or "+_+" bytes, got "+typeof b)}return E&&(v=ht(v,x)),zn("private key",v,ze,x),v}function u(b){if(!(b instanceof y))throw new Error("ProjectivePoint expected")}const f=Td((b,m)=>{const{px:_,py:E,pz:x}=b;if(r.eql(x,r.ONE))return{x:_,y:E};const v=b.is0();m==null&&(m=v?r.ONE:r.inv(x));const B=r.mul(_,m),S=r.mul(E,m),C=r.mul(x,m);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(C,r.ONE))throw new Error("invZ was invalid");return{x:B,y:S}}),d=Td(b=>{if(b.is0()){if(t.allowInfinityPoint&&!r.is0(b.py))return;throw new Error("bad point: ZERO")}const{x:m,y:_}=b.toAffine();if(!r.isValid(m)||!r.isValid(_))throw new Error("bad point: x or y not FE");const E=r.sqr(_),x=o(m);if(!r.eql(E,x))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class y{constructor(m,_,E){if(m==null||!r.isValid(m))throw new Error("x required");if(_==null||!r.isValid(_))throw new Error("y required");if(E==null||!r.isValid(E))throw new Error("z required");this.px=m,this.py=_,this.pz=E,Object.freeze(this)}static fromAffine(m){const{x:_,y:E}=m||{};if(!m||!r.isValid(_)||!r.isValid(E))throw new Error("invalid affine point");if(m instanceof y)throw new Error("projective point not allowed");const x=v=>r.eql(v,r.ZERO);return x(_)&&x(E)?y.ZERO:new y(_,E,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){const _=r.invertBatch(m.map(E=>E.pz));return m.map((E,x)=>E.toAffine(_[x])).map(y.fromAffine)}static fromHex(m){const _=y.fromAffine(s(Ct("pointHex",m)));return _.assertValidity(),_}static fromPrivateKey(m){return y.BASE.multiply(c(m))}static msm(m,_){return wv(y,n,m,_)}_setWindowSize(m){w.setWindowSize(this,m)}assertValidity(){d(this)}hasEvenY(){const{y:m}=this.toAffine();if(r.isOdd)return!r.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){u(m);const{px:_,py:E,pz:x}=this,{px:v,py:B,pz:S}=m,C=r.eql(r.mul(_,S),r.mul(v,x)),N=r.eql(r.mul(E,S),r.mul(B,x));return C&&N}negate(){return new y(this.px,r.neg(this.py),this.pz)}double(){const{a:m,b:_}=t,E=r.mul(_,Od),{px:x,py:v,pz:B}=this;let S=r.ZERO,C=r.ZERO,N=r.ZERO,I=r.mul(x,x),G=r.mul(v,v),k=r.mul(B,B),U=r.mul(x,v);return U=r.add(U,U),N=r.mul(x,B),N=r.add(N,N),S=r.mul(m,N),C=r.mul(E,k),C=r.add(S,C),S=r.sub(G,C),C=r.add(G,C),C=r.mul(S,C),S=r.mul(U,S),N=r.mul(E,N),k=r.mul(m,k),U=r.sub(I,k),U=r.mul(m,U),U=r.add(U,N),N=r.add(I,I),I=r.add(N,I),I=r.add(I,k),I=r.mul(I,U),C=r.add(C,I),k=r.mul(v,B),k=r.add(k,k),I=r.mul(k,U),S=r.sub(S,I),N=r.mul(k,G),N=r.add(N,N),N=r.add(N,N),new y(S,C,N)}add(m){u(m);const{px:_,py:E,pz:x}=this,{px:v,py:B,pz:S}=m;let C=r.ZERO,N=r.ZERO,I=r.ZERO;const G=t.a,k=r.mul(t.b,Od);let U=r.mul(_,v),z=r.mul(E,B),F=r.mul(x,S),D=r.add(_,E),V=r.add(v,B);D=r.mul(D,V),V=r.add(U,z),D=r.sub(D,V),V=r.add(_,x);let X=r.add(v,S);return V=r.mul(V,X),X=r.add(U,F),V=r.sub(V,X),X=r.add(E,x),C=r.add(B,S),X=r.mul(X,C),C=r.add(z,F),X=r.sub(X,C),I=r.mul(G,V),C=r.mul(k,F),I=r.add(C,I),C=r.sub(z,I),I=r.add(z,I),N=r.mul(C,I),z=r.add(U,U),z=r.add(z,U),F=r.mul(G,F),V=r.mul(k,V),z=r.add(z,F),F=r.sub(U,F),F=r.mul(G,F),V=r.add(V,F),U=r.mul(z,V),N=r.add(N,U),U=r.mul(X,V),C=r.mul(D,C),C=r.sub(C,U),U=r.mul(D,z),I=r.mul(X,I),I=r.add(I,U),new y(C,N,I)}subtract(m){return this.add(m.negate())}is0(){return this.equals(y.ZERO)}wNAF(m){return w.wNAFCached(this,m,y.normalizeZ)}multiplyUnsafe(m){const{endo:_,n:E}=t;zn("scalar",m,fr,E);const x=y.ZERO;if(m===fr)return x;if(this.is0()||m===ze)return this;if(!_||w.hasPrecomputes(this))return w.wNAFCachedUnsafe(this,m,y.normalizeZ);let{k1neg:v,k1:B,k2neg:S,k2:C}=_.splitScalar(m),N=x,I=x,G=this;for(;B>fr||C>fr;)B&ze&&(N=N.add(G)),C&ze&&(I=I.add(G)),G=G.double(),B>>=ze,C>>=ze;return v&&(N=N.negate()),S&&(I=I.negate()),I=new y(r.mul(I.px,_.beta),I.py,I.pz),N.add(I)}multiply(m){const{endo:_,n:E}=t;zn("scalar",m,ze,E);let x,v;if(_){const{k1neg:B,k1:S,k2neg:C,k2:N}=_.splitScalar(m);let{p:I,f:G}=this.wNAF(S),{p:k,f:U}=this.wNAF(N);I=w.constTimeNegate(B,I),k=w.constTimeNegate(C,k),k=new y(r.mul(k.px,_.beta),k.py,k.pz),x=I.add(k),v=G.add(U)}else{const{p:B,f:S}=this.wNAF(m);x=B,v=S}return y.normalizeZ([x,v])[0]}multiplyAndAddUnsafe(m,_,E){const x=y.BASE,v=(S,C)=>C===fr||C===ze||!S.equals(x)?S.multiplyUnsafe(C):S.multiply(C),B=v(this,_).add(v(m,E));return B.is0()?void 0:B}toAffine(m){return f(this,m)}isTorsionFree(){const{h:m,isTorsionFree:_}=t;if(m===ze)return!0;if(_)return _(y,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:m,clearCofactor:_}=t;return m===ze?this:_?_(y,this):this.multiplyUnsafe(t.h)}toRawBytes(m=!0){return ds("isCompressed",m),this.assertValidity(),i(y,this,m)}toHex(m=!0){return ds("isCompressed",m),ls(this.toRawBytes(m))}}y.BASE=new y(t.Gx,t.Gy,r.ONE),y.ZERO=new y(r.ZERO,r.ONE,r.ZERO);const p=t.nBitLength,w=gv(y,t.endo?Math.ceil(p/2):p);return{CURVE:t,ProjectivePoint:y,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function Ev(e){const t=cp(e);return Xo(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Av(e){const t=Ev(e),{Fp:r,n}=t,i=r.BYTES+1,s=2*r.BYTES+1;function o(F){return ht(F,n)}function a(F){return Yc(F,n)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:d}=xv({...t,toBytes(F,D,V){const X=D.toAffine(),J=r.toBytes(X.x),W=xo;return ds("isCompressed",V),V?W(Uint8Array.from([D.hasEvenY()?2:3]),J):W(Uint8Array.from([4]),J,r.toBytes(X.y))},fromBytes(F){const D=F.length,V=F[0],X=F.subarray(1);if(D===i&&(V===2||V===3)){const J=nn(X);if(!af(J,ze,r.ORDER))throw new Error("Point is not on curve");const W=f(J);let se;try{se=r.sqrt(W)}catch(be){const xe=be instanceof Error?": "+be.message:"";throw new Error("Point is not on curve"+xe)}const ne=(se&ze)===ze;return(V&1)===1!==ne&&(se=r.neg(se)),{x:J,y:se}}else if(D===s&&V===4){const J=r.fromBytes(X.subarray(0,r.BYTES)),W=r.fromBytes(X.subarray(r.BYTES,2*r.BYTES));return{x:J,y:W}}else{const J=i,W=s;throw new Error("invalid Point, expected length of "+J+", or uncompressed "+W+", got "+D)}}}),y=F=>ls(hs(F,t.nByteLength));function p(F){const D=n>>ze;return F>D}function w(F){return p(F)?o(-F):F}const b=(F,D,V)=>nn(F.slice(D,V));class m{constructor(D,V,X){zn("r",D,ze,n),zn("s",V,ze,n),this.r=D,this.s=V,X!=null&&(this.recovery=X),Object.freeze(this)}static fromCompact(D){const V=t.nByteLength;return D=Ct("compactSignature",D,V*2),new m(b(D,0,V),b(D,V,2*V))}static fromDER(D){const{r:V,s:X}=ur.toSig(Ct("DER",D));return new m(V,X)}assertValidity(){}addRecoveryBit(D){return new m(this.r,this.s,D)}recoverPublicKey(D){const{r:V,s:X,recovery:J}=this,W=S(Ct("msgHash",D));if(J==null||![0,1,2,3].includes(J))throw new Error("recovery id invalid");const se=J===2||J===3?V+t.n:V;if(se>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const ne=J&1?"03":"02",ae=c.fromHex(ne+y(se)),be=a(se),xe=o(-W*be),He=o(X*be),R=c.BASE.multiplyAndAddUnsafe(ae,xe,He);if(!R)throw new Error("point at infinify");return R.assertValidity(),R}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return _o(this.toDERHex())}toDERHex(){return ur.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return _o(this.toCompactHex())}toCompactHex(){return y(this.r)+y(this.s)}}const _={isValidPrivateKey(F){try{return u(F),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const F=sp(t.n);return yv(t.randomBytes(F),t.n)},precompute(F=8,D=c.BASE){return D._setWindowSize(F),D.multiply(BigInt(3)),D}};function E(F,D=!0){return c.fromPrivateKey(F).toRawBytes(D)}function x(F){const D=ei(F),V=typeof F=="string",X=(D||V)&&F.length;return D?X===i||X===s:V?X===2*i||X===2*s:F instanceof c}function v(F,D,V=!0){if(x(F))throw new Error("first arg must be private key");if(!x(D))throw new Error("second arg must be public key");return c.fromHex(D).multiply(u(F)).toRawBytes(V)}const B=t.bits2int||function(F){if(F.length>8192)throw new Error("input is too large");const D=nn(F),V=F.length*8-t.nBitLength;return V>0?D>>BigInt(V):D},S=t.bits2int_modN||function(F){return o(B(F))},C=Zo(t.nBitLength);function N(F){return zn("num < 2^"+t.nBitLength,F,fr,C),hs(F,t.nByteLength)}function I(F,D,V=G){if(["recovered","canonical"].some(q=>q in V))throw new Error("sign() legacy options not supported");const{hash:X,randomBytes:J}=t;let{lowS:W,prehash:se,extraEntropy:ne}=V;W==null&&(W=!0),F=Ct("msgHash",F),Cd(V),se&&(F=Ct("prehashed msgHash",X(F)));const ae=S(F),be=u(D),xe=[N(be),N(ae)];if(ne!=null&&ne!==!1){const q=ne===!0?J(r.BYTES):ne;xe.push(Ct("extraEntropy",q))}const He=xo(...xe),R=ae;function $(q){const Q=B(q);if(!d(Q))return;const oe=a(Q),T=c.BASE.multiply(Q).toAffine(),P=o(T.x);if(P===fr)return;const j=o(oe*o(R+P*be));if(j===fr)return;let Y=(T.x===P?0:2)|Number(T.y&ze),he=j;return W&&p(j)&&(he=w(j),Y^=1),new m(P,he,Y)}return{seed:He,k2sig:$}}const G={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};function U(F,D,V=G){const{seed:X,k2sig:J}=I(F,D,V),W=t;return sv(W.hash.outputLen,W.nByteLength,W.hmac)(X,J)}c.BASE._setWindowSize(8);function z(F,D,V,X=k){var Y;const J=F;D=Ct("msgHash",D),V=Ct("publicKey",V);const{lowS:W,prehash:se,format:ne}=X;if(Cd(X),"strict"in X)throw new Error("options.strict was renamed to lowS");if(ne!==void 0&&ne!=="compact"&&ne!=="der")throw new Error("format must be compact or der");const ae=typeof J=="string"||ei(J),be=!ae&&!ne&&typeof J=="object"&&J!==null&&typeof J.r=="bigint"&&typeof J.s=="bigint";if(!ae&&!be)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let xe,He;try{if(be&&(xe=new m(J.r,J.s)),ae){try{ne!=="compact"&&(xe=m.fromDER(J))}catch(he){if(!(he instanceof ur.Err))throw he}!xe&&ne!=="der"&&(xe=m.fromCompact(J))}He=c.fromHex(V)}catch{return!1}if(!xe||W&&xe.hasHighS())return!1;se&&(D=t.hash(D));const{r:R,s:$}=xe,q=S(D),Q=a($),oe=o(q*Q),T=o(R*Q),P=(Y=c.BASE.multiplyAndAddUnsafe(He,oe,T))==null?void 0:Y.toAffine();return P?o(P.x)===R:!1}return{CURVE:t,getPublicKey:E,getSharedSecret:v,sign:U,verify:z,ProjectivePoint:c,Signature:m,utils:_}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Sv(e){return{hash:e,hmac:(t,...r)=>X0(e,t,eb(...r)),randomBytes:tb}}function Tv(e,t){const r=n=>Av({...e,...Sv(n)});return{...r(t),create:r}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const up=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Rd=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Pv=BigInt(1),Xc=BigInt(2),Nd=(e,t)=>(e+t/Xc)/t;function Bv(e){const t=up,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,d=xt(f,r,t)*f%t,y=xt(d,r,t)*f%t,p=xt(y,Xc,t)*u%t,w=xt(p,i,t)*p%t,b=xt(w,s,t)*w%t,m=xt(b,a,t)*b%t,_=xt(m,c,t)*m%t,E=xt(_,a,t)*b%t,x=xt(E,r,t)*f%t,v=xt(x,o,t)*w%t,B=xt(v,n,t)*u%t,S=xt(B,Xc,t);if(!Jc.eql(Jc.sqr(S),e))throw new Error("Cannot find square root");return S}const Jc=np(up,void 0,void 0,{sqrt:Bv}),cf=Tv({a:BigInt(0),b:BigInt(7),Fp:Jc,n:Rd,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=Rd,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Pv*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,o=BigInt("0x100000000000000000000000000000000"),a=Nd(s*e,t),c=Nd(-n*e,t);let u=ht(e-a*r-c*i,t),f=ht(-a*n-c*s,t);const d=u>o,y=f>o;if(d&&(u=t-u),y&&(f=t-f),u>o||f>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:d,k1:u,k2neg:y,k2:f}}}},Lh);BigInt(0);cf.ProjectivePoint;const Iv=Object.freeze(Object.defineProperty({__proto__:null,secp256k1:cf},Symbol.toStringTag,{value:"Module"}));function kv({r:e,s:t,to:r="hex",v:n,yParity:i}){const s=(()=>{if(i===0||i===1)return i;if(n&&(n===27n||n===28n||n>=35n))return n%2n===0n?1:0;throw new Error("Invalid `v` or `yParity` value")})(),o=`0x${new cf.Signature(Ze(e),Ze(t)).toCompactHex()}${s===0?"1b":"1c"}`;return r==="hex"?o:Ft(o)}async function uf(e,t){var d,y,p;const{address:r,factory:n,factoryData:i,hash:s,signature:o,universalSignatureVerifierAddress:a=(p=(y=(d=e.chain)==null?void 0:d.contracts)==null?void 0:y.universalSignatureVerifier)==null?void 0:p.address,...c}=t,u=$t(o)?o:typeof o=="object"&&"r"in o&&"s"in o?kv(o):Me(o),f=await(async()=>!n&&!i||cw(u)?u:uw({address:n,data:i,signature:u}))();try{const w=a?{to:a,data:Pt({abi:id,functionName:"isValidSig",args:[r,s,f]}),...c}:{data:zo({abi:id,args:[r,s,f],bytecode:M1}),...c},{data:b}=await ee(e,Is,"call")(w);return Fm(b??"0x0")}catch(w){try{if(Bs(hh(r),await Ih({hash:s,signature:o})))return!0}catch{}if(w instanceof Bh)return!1;throw w}}async function Cv(e,{address:t,message:r,factory:n,factoryData:i,signature:s,...o}){const a=A0(r);return uf(e,{address:t,factory:n,factoryData:i,hash:a,signature:s,...o})}async function Ov(e,t){const{address:r,factory:n,factoryData:i,signature:s,message:o,primaryType:a,types:c,domain:u,...f}=t,d=zg({message:o,primaryType:a,types:c,domain:u});return uf(e,{address:r,factory:n,factoryData:i,hash:d,signature:s,...f})}function fp(e,{emitOnBegin:t=!1,emitMissed:r=!1,onBlockNumber:n,onError:i,poll:s,pollingInterval:o=e.pollingInterval}){const a=typeof s<"u"?s:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket");let c;return a?(()=>{const d=Ue(["watchBlockNumber",e.uid,t,r,o]);return br(d,{onBlockNumber:n,onError:i},y=>hi(async()=>{var p;try{const w=await ee(e,ks,"getBlockNumber")({cacheTime:0});if(c){if(w===c)return;if(w-c>1&&r)for(let b=c+1n;b<w;b++)y.onBlockNumber(b,c),c=b}(!c||w>c)&&(y.onBlockNumber(w,c),c=w)}catch(w){(p=y.onError)==null||p.call(y,w)}},{emitOnBegin:t,interval:o}))})():(()=>{const d=Ue(["watchBlockNumber",e.uid,t,r]);return br(d,{onBlockNumber:n,onError:i},y=>{let p=!0,w=()=>p=!1;return(async()=>{try{const b=(()=>{if(e.transport.type==="fallback"){const _=e.transport.transports.find(E=>E.config.type==="webSocket");return _?_.value:e.transport}return e.transport})(),{unsubscribe:m}=await b.subscribe({params:["newHeads"],onData(_){var x;if(!p)return;const E=Ze((x=_.result)==null?void 0:x.number);y.onBlockNumber(E,c),c=E},onError(_){var E;(E=y.onError)==null||E.call(y,_)}});w=m,p||w()}catch(b){i==null||i(b)}})(),()=>w()})})()}async function Rv(e,{confirmations:t=1,hash:r,onReplaced:n,pollingInterval:i=e.pollingInterval,retryCount:s=6,retryDelay:o=({count:c})=>~~(1<<c)*200,timeout:a=18e4}){const c=Ue(["waitForTransactionReceipt",e.uid,r]);let u,f,d,y=!1;const{promise:p,resolve:w,reject:b}=Mu(),m=a?setTimeout(()=>b(new Jb({hash:r})),a):void 0,_=br(c,{onReplaced:n,resolve:w,reject:b},E=>{const x=ee(e,fp,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:i,async onBlockNumber(v){const B=C=>{clearTimeout(m),x(),C(),_()};let S=v;if(!y)try{if(d){if(t>1&&(!d.blockNumber||S-d.blockNumber+1n<t))return;B(()=>E.resolve(d));return}if(u||(y=!0,await Uc(async()=>{u=await ee(e,Wu,"getTransaction")({hash:r}),u.blockNumber&&(S=u.blockNumber)},{delay:o,retryCount:s}),y=!1),d=await ee(e,Mc,"getTransactionReceipt")({hash:r}),t>1&&(!d.blockNumber||S-d.blockNumber+1n<t))return;B(()=>E.resolve(d))}catch(C){if(C instanceof Th||C instanceof Ph){if(!u){y=!1;return}try{f=u,y=!0;const N=await Uc(()=>ee(e,Xt,"getBlock")({blockNumber:S,includeTransactions:!0}),{delay:o,retryCount:s,shouldRetry:({error:k})=>k instanceof Rh});y=!1;const I=N.transactions.find(({from:k,nonce:U})=>k===f.from&&U===f.nonce);if(!I||(d=await ee(e,Mc,"getTransactionReceipt")({hash:I.hash}),t>1&&(!d.blockNumber||S-d.blockNumber+1n<t)))return;let G="replaced";I.to===f.to&&I.value===f.value&&I.input===f.input?G="repriced":I.from===I.to&&I.value===0n&&(G="cancelled"),B(()=>{var k;(k=E.onReplaced)==null||k.call(E,{reason:G,replacedTransaction:f,transaction:I,transactionReceipt:d}),E.resolve(d)})}catch(N){B(()=>E.reject(N))}}else B(()=>E.reject(C))}}})});return p}function Nv(e,{blockTag:t="latest",emitMissed:r=!1,emitOnBegin:n=!1,onBlock:i,onError:s,includeTransactions:o,poll:a,pollingInterval:c=e.pollingInterval}){const u=typeof a<"u"?a:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket"),f=o??!1;let d;return u?(()=>{const w=Ue(["watchBlocks",e.uid,t,r,n,f,c]);return br(w,{onBlock:i,onError:s},b=>hi(async()=>{var m;try{const _=await ee(e,Xt,"getBlock")({blockTag:t,includeTransactions:f});if(_.number&&(d!=null&&d.number)){if(_.number===d.number)return;if(_.number-d.number>1&&r)for(let E=(d==null?void 0:d.number)+1n;E<_.number;E++){const x=await ee(e,Xt,"getBlock")({blockNumber:E,includeTransactions:f});b.onBlock(x,d),d=x}}(!(d!=null&&d.number)||t==="pending"&&!(_!=null&&_.number)||_.number&&_.number>d.number)&&(b.onBlock(_,d),d=_)}catch(_){(m=b.onError)==null||m.call(b,_)}},{emitOnBegin:n,interval:c}))})():(()=>{let w=!0,b=!0,m=()=>w=!1;return(async()=>{try{n&&ee(e,Xt,"getBlock")({blockTag:t,includeTransactions:f}).then(x=>{w&&b&&(i(x,void 0),b=!1)});const _=(()=>{if(e.transport.type==="fallback"){const x=e.transport.transports.find(v=>v.config.type==="webSocket");return x?x.value:e.transport}return e.transport})(),{unsubscribe:E}=await _.subscribe({params:["newHeads"],async onData(x){if(!w)return;const v=await ee(e,Xt,"getBlock")({blockNumber:x.blockNumber,includeTransactions:f}).catch(()=>{});w&&(i(v,d),b=!1,d=v)},onError(x){s==null||s(x)}});m=E,w||m()}catch(_){s==null||s(_)}})(),()=>m()})()}function $v(e,{address:t,args:r,batch:n=!0,event:i,events:s,fromBlock:o,onError:a,onLogs:c,poll:u,pollingInterval:f=e.pollingInterval,strict:d}){const y=typeof u<"u"?u:typeof o=="bigint"?!0:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket"),p=d??!1;return y?(()=>{const m=Ue(["watchEvent",t,r,n,e.uid,i,f,o]);return br(m,{onLogs:c,onError:a},_=>{let E;o!==void 0&&(E=o-1n);let x,v=!1;const B=hi(async()=>{var S;if(!v){try{x=await ee(e,m0,"createEventFilter")({address:t,args:r,event:i,events:s,strict:p,fromBlock:o})}catch{}v=!0;return}try{let C;if(x)C=await ee(e,qo,"getFilterChanges")({filter:x});else{const N=await ee(e,ks,"getBlockNumber")({});E&&E!==N?C=await ee(e,Fu,"getLogs")({address:t,args:r,event:i,events:s,fromBlock:E+1n,toBlock:N}):C=[],E=N}if(C.length===0)return;if(n)_.onLogs(C);else for(const N of C)_.onLogs([N])}catch(C){x&&C instanceof dn&&(v=!1),(S=_.onError)==null||S.call(_,C)}},{emitOnBegin:!0,interval:f});return async()=>{x&&await ee(e,Go,"uninstallFilter")({filter:x}),B()}})})():(()=>{let m=!0,_=()=>m=!1;return(async()=>{try{const E=(()=>{if(e.transport.type==="fallback"){const S=e.transport.transports.find(C=>C.config.type==="webSocket");return S?S.value:e.transport}return e.transport})(),x=s??(i?[i]:void 0);let v=[];x&&(v=[x.flatMap(C=>As({abi:[C],eventName:C.name,args:r}))],i&&(v=v[0]));const{unsubscribe:B}=await E.subscribe({params:["logs",{address:t,topics:v}],onData(S){var N;if(!m)return;const C=S.result;try{const{eventName:I,args:G}=$u({abi:x??[],data:C.data,topics:C.topics,strict:p}),k=mr(C,{args:G,eventName:I});c([k])}catch(I){let G,k;if(I instanceof ji||I instanceof ko){if(d)return;G=I.abiItem.name,k=(N=I.abiItem.inputs)==null?void 0:N.some(z=>!("name"in z&&z.name))}const U=mr(C,{args:k?[]:{},eventName:G});c([U])}},onError(S){a==null||a(S)}});_=B,m||_()}catch(E){a==null||a(E)}})(),()=>_()})()}function Lv(e,{batch:t=!0,onError:r,onTransactions:n,poll:i,pollingInterval:s=e.pollingInterval}){return(typeof i<"u"?i:e.transport.type!=="webSocket")?(()=>{const u=Ue(["watchPendingTransactions",e.uid,t,s]);return br(u,{onTransactions:n,onError:r},f=>{let d;const y=hi(async()=>{var p;try{if(!d)try{d=await ee(e,b0,"createPendingTransactionFilter")({});return}catch(b){throw y(),b}const w=await ee(e,qo,"getFilterChanges")({filter:d});if(w.length===0)return;if(t)f.onTransactions(w);else for(const b of w)f.onTransactions([b])}catch(w){(p=f.onError)==null||p.call(f,w)}},{emitOnBegin:!0,interval:s});return async()=>{d&&await ee(e,Go,"uninstallFilter")({filter:d}),y()}})})():(()=>{let u=!0,f=()=>u=!1;return(async()=>{try{const{unsubscribe:d}=await e.transport.subscribe({params:["newPendingTransactions"],onData(y){if(!u)return;const p=y.result;n([p])},onError(y){r==null||r(y)}});f=d,u||f()}catch(d){r==null||r(d)}})(),()=>f()})()}function Fv(e){var d,y,p;const{scheme:t,statement:r,...n}=((d=e.match(Uv))==null?void 0:d.groups)??{},{chainId:i,expirationTime:s,issuedAt:o,notBefore:a,requestId:c,...u}=((y=e.match(Mv))==null?void 0:y.groups)??{},f=(p=e.split("Resources:")[1])==null?void 0:p.split(`
|
|
45
|
+
- `).slice(1);return{...n,...u,...i?{chainId:Number(i)}:{},...s?{expirationTime:new Date(s)}:{},...o?{issuedAt:new Date(o)}:{},...a?{notBefore:new Date(a)}:{},...c?{requestId:c}:{},...f?{resources:f}:{},...t?{scheme:t}:{},...r?{statement:r}:{}}}const Uv=/^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+-.]*):\/\/)?(?<domain>[a-zA-Z0-9+-.]*(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/,Mv=/(?:URI: (?<uri>.+))\n(?:Version: (?<version>.+))\n(?:Chain ID: (?<chainId>\d+))\n(?:Nonce: (?<nonce>[a-zA-Z0-9]+))\n(?:Issued At: (?<issuedAt>.+))(?:\nExpiration Time: (?<expirationTime>.+))?(?:\nNot Before: (?<notBefore>.+))?(?:\nRequest ID: (?<requestId>.+))?/;function Hv(e){const{address:t,domain:r,message:n,nonce:i,scheme:s,time:o=new Date}=e;if(r&&n.domain!==r||i&&n.nonce!==i||s&&n.scheme!==s||n.expirationTime&&o>=n.expirationTime||n.notBefore&&o<n.notBefore)return!1;try{if(!n.address||t&&!Bs(n.address,t))return!1}catch{return!1}return!0}async function Dv(e,t){const{address:r,domain:n,message:i,nonce:s,scheme:o,signature:a,time:c=new Date,...u}=t,f=Fv(i);if(!f.address||!Hv({address:r,domain:n,message:f,nonce:s,scheme:o,time:c}))return!1;const y=A0(i);return uf(e,{address:f.address,hash:y,signature:a,...u})}function jv(e){return{call:t=>Is(e,t),createAccessList:t=>y0(e,t),createBlockFilter:()=>Cg(e),createContractEventFilter:t=>_u(e,t),createEventFilter:t=>m0(e,t),createPendingTransactionFilter:()=>b0(e),estimateContractGas:t=>Vh(e,t),estimateGas:t=>Nu(e,t),getBalance:t=>Gh(e,t),getBlobBaseFee:()=>Og(e),getBlock:t=>Xt(e,t),getBlockNumber:t=>ks(e,t),getBlockTransactionCount:t=>Rg(e,t),getBytecode:t=>fd(e,t),getChainId:()=>di(e),getCode:t=>fd(e,t),getContractEvents:t=>Uu(e,t),getEip712Domain:t=>$g(e,t),getEnsAddress:t=>yg(e,t),getEnsAvatar:t=>Bg(e,t),getEnsName:t=>Ig(e,t),getEnsResolver:t=>kg(e,t),getEnsText:t=>p0(e,t),getFeeHistory:t=>Ug(e,t),estimateFeesPerGas:t=>x1(e,t),getFilterChanges:t=>qo(e,t),getFilterLogs:t=>Mg(e,t),getGasPrice:()=>Iu(e),getLogs:t=>Fu(e,t),getProof:t=>lw(e,t),estimateMaxPriorityFeePerGas:t=>_1(e,t),getStorageAt:t=>hw(e,t),getTransaction:t=>Wu(e,t),getTransactionConfirmations:t=>pw(e,t),getTransactionCount:t=>ku(e,t),getTransactionReceipt:t=>Mc(e,t),multicall:t=>yw(e,t),prepareTransactionRequest:t=>Do(e,t),readContract:t=>Qt(e,t),sendRawTransaction:t=>Hu(e,t),simulate:t=>Hc(e,t),simulateBlocks:t=>Hc(e,t),simulateCalls:t=>rv(e,t),simulateContract:t=>Qh(e,t),verifyMessage:t=>Cv(e,t),verifySiweMessage:t=>Dv(e,t),verifyTypedData:t=>Ov(e,t),uninstallFilter:t=>Go(e,t),waitForTransactionReceipt:t=>Rv(e,t),watchBlocks:t=>Nv(e,t),watchBlockNumber:t=>fp(e,t),watchContractEvent:t=>e0(e,t),watchEvent:t=>$v(e,t),watchPendingTransactions:t=>Lv(e,t)}}function zv(e){const{key:t="public",name:r="Public Client"}=e;return c0({...e,key:t,name:r,type:"publicClient"}).extend(jv)}async function qv(e,{chain:t}){const{id:r,name:n,nativeCurrency:i,rpcUrls:s,blockExplorers:o}=t;await e.request({method:"wallet_addEthereumChain",params:[{chainId:te(r),chainName:n,nativeCurrency:i,rpcUrls:s.default.http,blockExplorerUrls:o?Object.values(o).map(({url:a})=>a):void 0}]},{dedupe:!0,retryCount:0})}function Gv(e,t){const{abi:r,args:n,bytecode:i,...s}=t,o=zo({abi:r,args:n,bytecode:i});return Du(e,{...s,...s.authorizationList?{to:null}:{},data:o})}async function Vv(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=>xs(n))}async function Wv(e,t={}){const{account:r=e.account,chainId:n}=t,i=r?$e(r):void 0,s=await e.request({method:"wallet_getCapabilities",params:[i==null?void 0:i.address]}),o={};for(const[a,c]of Object.entries(s))o[Number(a)]=c;return typeof n=="number"?o[n]:o}async function Kv(e){return await e.request({method:"wallet_getPermissions"},{dedupe:!0})}async function dp(e,t){var c;const{account:r=e.account,chainId:n,nonce:i}=t;if(!r)throw new zr({docsPath:"/docs/eip7702/prepareAuthorization"});const s=$e(r),o=(()=>{if(t.executor)return t.executor==="self"?t.executor:$e(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 ee(e,di,"getChainId")({})),typeof a.nonce>"u"&&(a.nonce=await ee(e,ku,"getTransactionCount")({address:s.address,blockTag:"pending"}),(o==="self"||o!=null&&o.address&&Bs(o.address,s.address))&&(a.nonce+=1)),a}async function Yv(e){return(await e.request({method:"eth_requestAccounts"},{dedupe:!0,retryCount:0})).map(r=>hh(r))}async function Zv(e,t){return e.request({method:"wallet_requestPermissions",params:[t]},{retryCount:0})}async function Xv(e,t){const{account:r=e.account,capabilities:n,chain:i=e.chain,forceAtomic:s=!1,id:o,version:a="2.0.0"}=t;if(typeof r>"u")throw new zr({docsPath:"/experimental/eip5792/sendCalls"});const c=r?$e(r):null,u=t.calls.map(f=>{const d=f;return{data:d.abi?Pt({abi:d.abi,functionName:d.functionName,args:d.args}):d.data,to:d.to,value:d.value?te(d.value):void 0}});try{const f=await e.request({method:"wallet_sendCalls",params:[{atomicRequired:s,calls:u,capabilities:n,chainId:te(i.id),from:c==null?void 0:c.address,id:o,version:a}]},{retryCount:0});return typeof f=="string"?{id:f}:f}catch(f){throw r0(f,{...t,account:c,chain:t.chain})}}async function Jv(e,t){const{id:r}=t;await e.request({method:"wallet_showCallsStatus",params:[r]})}async function Qv(e,t){const{account:r=e.account}=t;if(!r)throw new zr({docsPath:"/docs/eip7702/signAuthorization"});const n=$e(r);if(!n.signAuthorization)throw new ao({docsPath:"/docs/eip7702/signAuthorization",metaMessages:["The `signAuthorization` Action does not support JSON-RPC Accounts."],type:n.type});const i=await dp(e,t);return n.signAuthorization(i)}async function e_(e,{account:t=e.account,message:r}){if(!t)throw new zr({docsPath:"/docs/actions/wallet/signMessage"});const n=$e(t);if(n.signMessage)return n.signMessage({message:r});const i=typeof r=="string"?Zn(r):r.raw instanceof Uint8Array?ie(r.raw):r.raw;return e.request({method:"personal_sign",params:[i,n.address]},{retryCount:0})}async function t_(e,t){var u,f,d,y;const{account:r=e.account,chain:n=e.chain,...i}=t;if(!r)throw new zr({docsPath:"/docs/actions/wallet/signTransaction"});const s=$e(r);vn({account:s,...t});const o=await ee(e,di,"getChainId")({});n!==null&&t0({currentChainId:o,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)||fi;return s.signTransaction?s.signTransaction({...i,chainId:o},{serializer:(y=(d=e.chain)==null?void 0:d.serializers)==null?void 0:y.transaction}):await e.request({method:"eth_signTransaction",params:[{...c(i),chainId:te(o),from:s.address}]},{retryCount:0})}async function r_(e,t){const{account:r=e.account,domain:n,message:i,primaryType:s}=t;if(!r)throw new zr({docsPath:"/docs/actions/wallet/signTypedData"});const o=$e(r),a={EIP712Domain:E0({domain:n}),...t.types};if(x0({domain:n,message:i,primaryType:s,types:a}),o.signTypedData)return o.signTypedData({domain:n,message:i,primaryType:s,types:a});const c=Wg({domain:n,message:i,primaryType:s,types:a});return e.request({method:"eth_signTypedData_v4",params:[o.address,c]},{retryCount:0})}async function n_(e,{id:t}){await e.request({method:"wallet_switchEthereumChain",params:[{chainId:te(t)}]},{retryCount:0})}async function i_(e,t){return await e.request({method:"wallet_watchAsset",params:t},{retryCount:0})}function s_(e){return{addChain:t=>qv(e,t),deployContract:t=>Gv(e,t),getAddresses:()=>Vv(e),getCallsStatus:t=>o0(e,t),getCapabilities:()=>Wv(e),getChainId:()=>di(e),getPermissions:()=>Kv(e),prepareAuthorization:t=>dp(e,t),prepareTransactionRequest:t=>Do(e,t),requestAddresses:()=>Yv(e),requestPermissions:t=>Zv(e,t),sendCalls:t=>Xv(e,t),sendRawTransaction:t=>Hu(e,t),sendTransaction:t=>Du(e,t),showCallsStatus:t=>Jv(e,t),signAuthorization:t=>Qv(e,t),signMessage:t=>e_(e,t),signTransaction:t=>t_(e,t),signTypedData:t=>r_(e,t),switchChain:t=>n_(e,t),waitForCallsStatus:t=>eg(e,t),watchAsset:t=>i_(e,t),writeContract:t=>n0(e,t)}}function za(e){const{key:t="wallet",name:r="Wallet Client",transport:n}=e;return c0({...e,key:t,name:r,transport:n,type:"walletClient"}).extend(s_)}const uo={mainnet:{orderbook:"https://api.garden.finance",auth:"https://api.garden.finance/auth",quote:"https://api.garden.finance/quote",info:"https://api.garden.finance/info",evmRelay:"https://api.garden.finance/relayer",starknetRelay:"https://api.garden.finance/starknet"},testnet:{orderbook:"https://testnet.api.garden.finance",auth:"https://testnet.api.garden.finance/auth",quote:"https://testnet.api.garden.finance/quote",info:"https://testnet.api.garden.finance/info",evmRelay:"https://testnet.api.garden.finance/relayer",starknetRelay:"https://testnet.api.garden.finance/starknet"},localnet:{orderbook:"",auth:"",quote:"",info:"",evmRelay:"",starknetRelay:""}},ps={[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"}},$d={chain:we.SupportedAssets.mainnet.base_cbBTC.chain,asset:we.SupportedAssets.mainnet.base_cbBTC.atomicSwapAddress};function Qc(e){const t=typeof e=="string"?e:e.environment,r=t===Z.Environment.MAINNET?uo.mainnet:Z.Environment.TESTNET?uo.testnet:uo.localnet;return{api:typeof e=="string"?r:{...r,...e},environment:t}}function eu(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function Zr(e,t){if(!e)throw new Error(t)}function o_(e){return Buffer.concat([Uint8Array.from([192]),a_(e)])}function a_(e){const t=If.encodingLength(e.length),r=Buffer.allocUnsafe(t);return If.encode(e.length,r),Buffer.concat([r,e])}function c_(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Nr=e=>e.length===64?e:e.slice(2),u_=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return an.isPoint(t)}catch{return!1}},tu=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function f_(e,t){if(!e)return!1;const r=t===Z.Environment.MAINNET?ye.networks.bitcoin:t===Z.Environment.TESTNET?ye.networks.testnet:ye.networks.regtest;if(!r)return!1;ye.initEccLib(an);try{return ye.address.toOutputScript(e,r),!0}catch{return!1}}const d_=e=>{switch(e){case Z.Environment.MAINNET:return Kn.BitcoinNetwork.Mainnet;case Z.Environment.TESTNET:return Kn.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}},l_=e=>{const t=e.toLowerCase().replace("0x","");return/^[0-9a-f]+$/.test(t)},h_=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")&&l_(r)?BigInt(r).toString():r);return Z.Ok(t)}return Z.Err("Invalid signature format")};var Se=(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))(Se||{}),Pe=(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))(Pe||{});const ff=(e,t,r)=>{const n=ru(e.source_swap,t),i=ru(e.destination_swap,r);if(i===Pe.RedeemDetected)return Se.RedeemDetected;if(i===Pe.Redeemed)return Se.Redeemed;if(n===Pe.Refunded)return Se.Refunded;if(n===Pe.RefundDetected)return Se.RefundDetected;if(i===Pe.Expired)return Se.CounterPartySwapExpired;if(n===Pe.Expired)return Se.Expired;if(i===Pe.Refunded)return Se.CounterPartyRefunded;if(i===Pe.RefundDetected)return Se.CounterPartyRefundDetected;const s=Number(e.create_order.additional_data.deadline);return i===Pe.Initiated?Se.CounterPartyInitiated:i===Pe.InitiateDetected?Se.CounterPartyInitiateDetected:ys(s,12)?Se.DeadLineExceeded:n===Pe.Initiated?Se.Initiated:ys(s,1)?Se.DeadLineExceeded:n===Pe.InitiateDetected?Se.InitiateDetected:n===Pe.Redeemed?Se.CounterPartyRedeemed:n===Pe.RedeemDetected?Se.CounterPartyRedeemDetected:Se.Matched},ru=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?Pe.Redeemed:Pe.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?Pe.Refunded:Pe.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Pe.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?Pe.Initiated:Pe.InitiateDetected:Pe.Idle},p_=(e,t,r)=>{const n=ff(e,t,r);return df(n)},df=e=>{switch(e){case Se.Matched:return Fe.Initiate;case Se.CounterPartyInitiated:case Se.CounterPartyInitiateDetected:case Se.RedeemDetected:return Fe.Redeem;case Se.Expired:return Fe.Refund;default:return Fe.Idle}},ys=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},y_=e=>e.filter(t=>!lp(t)),lp=e=>{const{source_swap:t,create_order:r}=e,{initiate_tx_hash:n,initiate_block_number:i}=t,{deadline:s}=r.additional_data;return n&&Number(i)?!1:n&&!Number(i)?ys(Number(s),12):n?!1:ys(Number(s),1)},m_=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),b_=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),g_=Buffer.concat([m_,b_]),w_=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Ld={failedToCreateInternalPubkey:"failed to create internal pubkey"};function v_(){const e=Nl.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=an.pointMultiply(Buffer.concat([Buffer.from("04","hex"),g_]),e);if(!t)throw new Error(Ld.failedToCreateInternalPubkey);const r=an.pointAdd(w_,t);if(!r)throw new Error(Ld.failedToCreateInternalPubkey);return eu(Buffer.from(r))}var Ie={},it={},Ar={},Jo={};Jo.byteLength=E_;Jo.toByteArray=S_;Jo.fromByteArray=B_;var Zt=[],St=[],__=typeof Uint8Array<"u"?Uint8Array:Array,qa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Cn=0,x_=qa.length;Cn<x_;++Cn)Zt[Cn]=qa[Cn],St[qa.charCodeAt(Cn)]=Cn;St[45]=62;St[95]=63;function hp(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 E_(e){var t=hp(e),r=t[0],n=t[1];return(r+n)*3/4-n}function A_(e,t,r){return(t+r)*3/4-r}function S_(e){var t,r=hp(e),n=r[0],i=r[1],s=new __(A_(e,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=St[e.charCodeAt(c)]<<18|St[e.charCodeAt(c+1)]<<12|St[e.charCodeAt(c+2)]<<6|St[e.charCodeAt(c+3)],s[o++]=t>>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=St[e.charCodeAt(c)]<<2|St[e.charCodeAt(c+1)]>>4,s[o++]=t&255),i===1&&(t=St[e.charCodeAt(c)]<<10|St[e.charCodeAt(c+1)]<<4|St[e.charCodeAt(c+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function T_(e){return Zt[e>>18&63]+Zt[e>>12&63]+Zt[e>>6&63]+Zt[e&63]}function P_(e,t,r){for(var n,i=[],s=t;s<r;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(e[s+2]&255),i.push(T_(n));return i.join("")}function B_(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(P_(e,o,o+s>a?a:o+s));return n===1?(t=e[r-1],i.push(Zt[t>>2]+Zt[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Zt[t>>10]+Zt[t>>4&63]+Zt[t<<2&63]+"=")),i.join("")}var lf={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */lf.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,c=(1<<a)-1,u=c>>1,f=-7,d=r?i-1:0,y=r?-1:1,p=e[t+d];for(d+=y,s=p&(1<<-f)-1,p>>=-f,f+=a;f>0;s=s*256+e[t+d],d+=y,f-=8);for(o=s&(1<<-f)-1,s>>=-f,f+=n;f>0;o=o*256+e[t+d],d+=y,f-=8);if(s===0)s=1-u;else{if(s===c)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-u}return(p?-1:1)*o*Math.pow(2,s-n)};lf.write=function(e,t,r,n,i,s){var o,a,c,u=s*8-i-1,f=(1<<u)-1,d=f>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,w=n?1:-1,b=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=f):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+d>=1?t+=y/c:t+=y*Math.pow(2,1-d),t*c>=2&&(o++,c/=2),o+d>=f?(a=0,o=f):o+d>=1?(a=(t*c-1)*Math.pow(2,i),o=o+d):(a=t*Math.pow(2,d-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=a&255,p+=w,a/=256,i-=8);for(o=o<<i|a,u+=i;u>0;e[r+p]=o&255,p+=w,o/=256,u-=8);e[r+p-w]|=b*128};/*!
|
|
46
|
+
* The buffer module from node.js, for the browser.
|
|
47
|
+
*
|
|
48
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
49
|
+
* @license MIT
|
|
50
|
+
*/(function(e){const t=Jo,r=lf,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=E,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=s(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const g=new Uint8Array(1),l={foo:function(){return 42}};return Object.setPrototypeOf(l,Uint8Array.prototype),Object.setPrototypeOf(g,l),g.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function o(g){if(g>i)throw new RangeError('The value "'+g+'" is invalid for option "size"');const l=new Uint8Array(g);return Object.setPrototypeOf(l,a.prototype),l}function a(g,l,h){if(typeof g=="number"){if(typeof l=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return d(g)}return c(g,l,h)}a.poolSize=8192;function c(g,l,h){if(typeof g=="string")return y(g,l);if(ArrayBuffer.isView(g))return w(g);if(g==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof g);if(mt(g,ArrayBuffer)||g&&mt(g.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(mt(g,SharedArrayBuffer)||g&&mt(g.buffer,SharedArrayBuffer)))return b(g,l,h);if(typeof g=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const A=g.valueOf&&g.valueOf();if(A!=null&&A!==g)return a.from(A,l,h);const O=m(g);if(O)return O;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof g[Symbol.toPrimitive]=="function")return a.from(g[Symbol.toPrimitive]("string"),l,h);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof g)}a.from=function(g,l,h){return c(g,l,h)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function u(g){if(typeof g!="number")throw new TypeError('"size" argument must be of type number');if(g<0)throw new RangeError('The value "'+g+'" is invalid for option "size"')}function f(g,l,h){return u(g),g<=0?o(g):l!==void 0?typeof h=="string"?o(g).fill(l,h):o(g).fill(l):o(g)}a.alloc=function(g,l,h){return f(g,l,h)};function d(g){return u(g),o(g<0?0:_(g)|0)}a.allocUnsafe=function(g){return d(g)},a.allocUnsafeSlow=function(g){return d(g)};function y(g,l){if((typeof l!="string"||l==="")&&(l="utf8"),!a.isEncoding(l))throw new TypeError("Unknown encoding: "+l);const h=x(g,l)|0;let A=o(h);const O=A.write(g,l);return O!==h&&(A=A.slice(0,O)),A}function p(g){const l=g.length<0?0:_(g.length)|0,h=o(l);for(let A=0;A<l;A+=1)h[A]=g[A]&255;return h}function w(g){if(mt(g,Uint8Array)){const l=new Uint8Array(g);return b(l.buffer,l.byteOffset,l.byteLength)}return p(g)}function b(g,l,h){if(l<0||g.byteLength<l)throw new RangeError('"offset" is outside of buffer bounds');if(g.byteLength<l+(h||0))throw new RangeError('"length" is outside of buffer bounds');let A;return l===void 0&&h===void 0?A=new Uint8Array(g):h===void 0?A=new Uint8Array(g,l):A=new Uint8Array(g,l,h),Object.setPrototypeOf(A,a.prototype),A}function m(g){if(a.isBuffer(g)){const l=_(g.length)|0,h=o(l);return h.length===0||g.copy(h,0,0,l),h}if(g.length!==void 0)return typeof g.length!="number"||Kr(g.length)?o(0):p(g);if(g.type==="Buffer"&&Array.isArray(g.data))return p(g.data)}function _(g){if(g>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return g|0}function E(g){return+g!=g&&(g=0),a.alloc(+g)}a.isBuffer=function(l){return l!=null&&l._isBuffer===!0&&l!==a.prototype},a.compare=function(l,h){if(mt(l,Uint8Array)&&(l=a.from(l,l.offset,l.byteLength)),mt(h,Uint8Array)&&(h=a.from(h,h.offset,h.byteLength)),!a.isBuffer(l)||!a.isBuffer(h))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(l===h)return 0;let A=l.length,O=h.length;for(let L=0,M=Math.min(A,O);L<M;++L)if(l[L]!==h[L]){A=l[L],O=h[L];break}return A<O?-1:O<A?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,h){if(!Array.isArray(l))throw new TypeError('"list" argument must be an Array of Buffers');if(l.length===0)return a.alloc(0);let A;if(h===void 0)for(h=0,A=0;A<l.length;++A)h+=l[A].length;const O=a.allocUnsafe(h);let L=0;for(A=0;A<l.length;++A){let M=l[A];if(mt(M,Uint8Array))L+M.length>O.length?(a.isBuffer(M)||(M=a.from(M)),M.copy(O,L)):Uint8Array.prototype.set.call(O,M,L);else if(a.isBuffer(M))M.copy(O,L);else throw new TypeError('"list" argument must be an Array of Buffers');L+=M.length}return O};function x(g,l){if(a.isBuffer(g))return g.length;if(ArrayBuffer.isView(g)||mt(g,ArrayBuffer))return g.byteLength;if(typeof g!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof g);const h=g.length,A=arguments.length>2&&arguments[2]===!0;if(!A&&h===0)return 0;let O=!1;for(;;)switch(l){case"ascii":case"latin1":case"binary":return h;case"utf8":case"utf-8":return pe(g).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return h*2;case"hex":return h>>>1;case"base64":return yi(g).length;default:if(O)return A?-1:pe(g).length;l=(""+l).toLowerCase(),O=!0}}a.byteLength=x;function v(g,l,h){let A=!1;if((l===void 0||l<0)&&(l=0),l>this.length||((h===void 0||h>this.length)&&(h=this.length),h<=0)||(h>>>=0,l>>>=0,h<=l))return"";for(g||(g="utf8");;)switch(g){case"hex":return W(this,l,h);case"utf8":case"utf-8":return F(this,l,h);case"ascii":return X(this,l,h);case"latin1":case"binary":return J(this,l,h);case"base64":return z(this,l,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return se(this,l,h);default:if(A)throw new TypeError("Unknown encoding: "+g);g=(g+"").toLowerCase(),A=!0}}a.prototype._isBuffer=!0;function B(g,l,h){const A=g[l];g[l]=g[h],g[h]=A}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 h=0;h<l;h+=2)B(this,h,h+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 h=0;h<l;h+=4)B(this,h,h+3),B(this,h+1,h+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 h=0;h<l;h+=8)B(this,h,h+7),B(this,h+1,h+6),B(this,h+2,h+5),B(this,h+3,h+4);return this},a.prototype.toString=function(){const l=this.length;return l===0?"":arguments.length===0?F(this,0,l):v.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 h=e.INSPECT_MAX_BYTES;return l=this.toString("hex",0,h).replace(/(.{2})/g,"$1 ").trim(),this.length>h&&(l+=" ... "),"<Buffer "+l+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(l,h,A,O,L){if(mt(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(h===void 0&&(h=0),A===void 0&&(A=l?l.length:0),O===void 0&&(O=0),L===void 0&&(L=this.length),h<0||A>l.length||O<0||L>this.length)throw new RangeError("out of range index");if(O>=L&&h>=A)return 0;if(O>=L)return-1;if(h>=A)return 1;if(h>>>=0,A>>>=0,O>>>=0,L>>>=0,this===l)return 0;let M=L-O,fe=A-h;const ke=Math.min(M,fe),Te=this.slice(O,L),Ce=l.slice(h,A);for(let ge=0;ge<ke;++ge)if(Te[ge]!==Ce[ge]){M=Te[ge],fe=Ce[ge];break}return M<fe?-1:fe<M?1:0};function S(g,l,h,A,O){if(g.length===0)return-1;if(typeof h=="string"?(A=h,h=0):h>2147483647?h=2147483647:h<-2147483648&&(h=-2147483648),h=+h,Kr(h)&&(h=O?0:g.length-1),h<0&&(h=g.length+h),h>=g.length){if(O)return-1;h=g.length-1}else if(h<0)if(O)h=0;else return-1;if(typeof l=="string"&&(l=a.from(l,A)),a.isBuffer(l))return l.length===0?-1:C(g,l,h,A,O);if(typeof l=="number")return l=l&255,typeof Uint8Array.prototype.indexOf=="function"?O?Uint8Array.prototype.indexOf.call(g,l,h):Uint8Array.prototype.lastIndexOf.call(g,l,h):C(g,[l],h,A,O);throw new TypeError("val must be string, number or Buffer")}function C(g,l,h,A,O){let L=1,M=g.length,fe=l.length;if(A!==void 0&&(A=String(A).toLowerCase(),A==="ucs2"||A==="ucs-2"||A==="utf16le"||A==="utf-16le")){if(g.length<2||l.length<2)return-1;L=2,M/=2,fe/=2,h/=2}function ke(Ce,ge){return L===1?Ce[ge]:Ce.readUInt16BE(ge*L)}let Te;if(O){let Ce=-1;for(Te=h;Te<M;Te++)if(ke(g,Te)===ke(l,Ce===-1?0:Te-Ce)){if(Ce===-1&&(Ce=Te),Te-Ce+1===fe)return Ce*L}else Ce!==-1&&(Te-=Te-Ce),Ce=-1}else for(h+fe>M&&(h=M-fe),Te=h;Te>=0;Te--){let Ce=!0;for(let ge=0;ge<fe;ge++)if(ke(g,Te+ge)!==ke(l,ge)){Ce=!1;break}if(Ce)return Te}return-1}a.prototype.includes=function(l,h,A){return this.indexOf(l,h,A)!==-1},a.prototype.indexOf=function(l,h,A){return S(this,l,h,A,!0)},a.prototype.lastIndexOf=function(l,h,A){return S(this,l,h,A,!1)};function N(g,l,h,A){h=Number(h)||0;const O=g.length-h;A?(A=Number(A),A>O&&(A=O)):A=O;const L=l.length;A>L/2&&(A=L/2);let M;for(M=0;M<A;++M){const fe=parseInt(l.substr(M*2,2),16);if(Kr(fe))return M;g[h+M]=fe}return M}function I(g,l,h,A){return Pn(pe(l,g.length-h),g,h,A)}function G(g,l,h,A){return Pn(Sr(l),g,h,A)}function k(g,l,h,A){return Pn(yi(l),g,h,A)}function U(g,l,h,A){return Pn(Tn(l,g.length-h),g,h,A)}a.prototype.write=function(l,h,A,O){if(h===void 0)O="utf8",A=this.length,h=0;else if(A===void 0&&typeof h=="string")O=h,A=this.length,h=0;else if(isFinite(h))h=h>>>0,isFinite(A)?(A=A>>>0,O===void 0&&(O="utf8")):(O=A,A=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const L=this.length-h;if((A===void 0||A>L)&&(A=L),l.length>0&&(A<0||h<0)||h>this.length)throw new RangeError("Attempt to write outside buffer bounds");O||(O="utf8");let M=!1;for(;;)switch(O){case"hex":return N(this,l,h,A);case"utf8":case"utf-8":return I(this,l,h,A);case"ascii":case"latin1":case"binary":return G(this,l,h,A);case"base64":return k(this,l,h,A);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,l,h,A);default:if(M)throw new TypeError("Unknown encoding: "+O);O=(""+O).toLowerCase(),M=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function z(g,l,h){return l===0&&h===g.length?t.fromByteArray(g):t.fromByteArray(g.slice(l,h))}function F(g,l,h){h=Math.min(g.length,h);const A=[];let O=l;for(;O<h;){const L=g[O];let M=null,fe=L>239?4:L>223?3:L>191?2:1;if(O+fe<=h){let ke,Te,Ce,ge;switch(fe){case 1:L<128&&(M=L);break;case 2:ke=g[O+1],(ke&192)===128&&(ge=(L&31)<<6|ke&63,ge>127&&(M=ge));break;case 3:ke=g[O+1],Te=g[O+2],(ke&192)===128&&(Te&192)===128&&(ge=(L&15)<<12|(ke&63)<<6|Te&63,ge>2047&&(ge<55296||ge>57343)&&(M=ge));break;case 4:ke=g[O+1],Te=g[O+2],Ce=g[O+3],(ke&192)===128&&(Te&192)===128&&(Ce&192)===128&&(ge=(L&15)<<18|(ke&63)<<12|(Te&63)<<6|Ce&63,ge>65535&&ge<1114112&&(M=ge))}}M===null?(M=65533,fe=1):M>65535&&(M-=65536,A.push(M>>>10&1023|55296),M=56320|M&1023),A.push(M),O+=fe}return V(A)}const D=4096;function V(g){const l=g.length;if(l<=D)return String.fromCharCode.apply(String,g);let h="",A=0;for(;A<l;)h+=String.fromCharCode.apply(String,g.slice(A,A+=D));return h}function X(g,l,h){let A="";h=Math.min(g.length,h);for(let O=l;O<h;++O)A+=String.fromCharCode(g[O]&127);return A}function J(g,l,h){let A="";h=Math.min(g.length,h);for(let O=l;O<h;++O)A+=String.fromCharCode(g[O]);return A}function W(g,l,h){const A=g.length;(!l||l<0)&&(l=0),(!h||h<0||h>A)&&(h=A);let O="";for(let L=l;L<h;++L)O+=mi[g[L]];return O}function se(g,l,h){const A=g.slice(l,h);let O="";for(let L=0;L<A.length-1;L+=2)O+=String.fromCharCode(A[L]+A[L+1]*256);return O}a.prototype.slice=function(l,h){const A=this.length;l=~~l,h=h===void 0?A:~~h,l<0?(l+=A,l<0&&(l=0)):l>A&&(l=A),h<0?(h+=A,h<0&&(h=0)):h>A&&(h=A),h<l&&(h=l);const O=this.subarray(l,h);return Object.setPrototypeOf(O,a.prototype),O};function ne(g,l,h){if(g%1!==0||g<0)throw new RangeError("offset is not uint");if(g+l>h)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(l,h,A){l=l>>>0,h=h>>>0,A||ne(l,h,this.length);let O=this[l],L=1,M=0;for(;++M<h&&(L*=256);)O+=this[l+M]*L;return O},a.prototype.readUintBE=a.prototype.readUIntBE=function(l,h,A){l=l>>>0,h=h>>>0,A||ne(l,h,this.length);let O=this[l+--h],L=1;for(;h>0&&(L*=256);)O+=this[l+--h]*L;return O},a.prototype.readUint8=a.prototype.readUInt8=function(l,h){return l=l>>>0,h||ne(l,1,this.length),this[l]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(l,h){return l=l>>>0,h||ne(l,2,this.length),this[l]|this[l+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(l,h){return l=l>>>0,h||ne(l,2,this.length),this[l]<<8|this[l+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(l,h){return l=l>>>0,h||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,h){return l=l>>>0,h||ne(l,4,this.length),this[l]*16777216+(this[l+1]<<16|this[l+2]<<8|this[l+3])},a.prototype.readBigUInt64LE=_t(function(l){l=l>>>0,j(l,"offset");const h=this[l],A=this[l+7];(h===void 0||A===void 0)&&Y(l,this.length-8);const O=h+this[++l]*2**8+this[++l]*2**16+this[++l]*2**24,L=this[++l]+this[++l]*2**8+this[++l]*2**16+A*2**24;return BigInt(O)+(BigInt(L)<<BigInt(32))}),a.prototype.readBigUInt64BE=_t(function(l){l=l>>>0,j(l,"offset");const h=this[l],A=this[l+7];(h===void 0||A===void 0)&&Y(l,this.length-8);const O=h*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+A;return(BigInt(O)<<BigInt(32))+BigInt(L)}),a.prototype.readIntLE=function(l,h,A){l=l>>>0,h=h>>>0,A||ne(l,h,this.length);let O=this[l],L=1,M=0;for(;++M<h&&(L*=256);)O+=this[l+M]*L;return L*=128,O>=L&&(O-=Math.pow(2,8*h)),O},a.prototype.readIntBE=function(l,h,A){l=l>>>0,h=h>>>0,A||ne(l,h,this.length);let O=h,L=1,M=this[l+--O];for(;O>0&&(L*=256);)M+=this[l+--O]*L;return L*=128,M>=L&&(M-=Math.pow(2,8*h)),M},a.prototype.readInt8=function(l,h){return l=l>>>0,h||ne(l,1,this.length),this[l]&128?(255-this[l]+1)*-1:this[l]},a.prototype.readInt16LE=function(l,h){l=l>>>0,h||ne(l,2,this.length);const A=this[l]|this[l+1]<<8;return A&32768?A|4294901760:A},a.prototype.readInt16BE=function(l,h){l=l>>>0,h||ne(l,2,this.length);const A=this[l+1]|this[l]<<8;return A&32768?A|4294901760:A},a.prototype.readInt32LE=function(l,h){return l=l>>>0,h||ne(l,4,this.length),this[l]|this[l+1]<<8|this[l+2]<<16|this[l+3]<<24},a.prototype.readInt32BE=function(l,h){return l=l>>>0,h||ne(l,4,this.length),this[l]<<24|this[l+1]<<16|this[l+2]<<8|this[l+3]},a.prototype.readBigInt64LE=_t(function(l){l=l>>>0,j(l,"offset");const h=this[l],A=this[l+7];(h===void 0||A===void 0)&&Y(l,this.length-8);const O=this[l+4]+this[l+5]*2**8+this[l+6]*2**16+(A<<24);return(BigInt(O)<<BigInt(32))+BigInt(h+this[++l]*2**8+this[++l]*2**16+this[++l]*2**24)}),a.prototype.readBigInt64BE=_t(function(l){l=l>>>0,j(l,"offset");const h=this[l],A=this[l+7];(h===void 0||A===void 0)&&Y(l,this.length-8);const O=(h<<24)+this[++l]*2**16+this[++l]*2**8+this[++l];return(BigInt(O)<<BigInt(32))+BigInt(this[++l]*2**24+this[++l]*2**16+this[++l]*2**8+A)}),a.prototype.readFloatLE=function(l,h){return l=l>>>0,h||ne(l,4,this.length),r.read(this,l,!0,23,4)},a.prototype.readFloatBE=function(l,h){return l=l>>>0,h||ne(l,4,this.length),r.read(this,l,!1,23,4)},a.prototype.readDoubleLE=function(l,h){return l=l>>>0,h||ne(l,8,this.length),r.read(this,l,!0,52,8)},a.prototype.readDoubleBE=function(l,h){return l=l>>>0,h||ne(l,8,this.length),r.read(this,l,!1,52,8)};function ae(g,l,h,A,O,L){if(!a.isBuffer(g))throw new TypeError('"buffer" argument must be a Buffer instance');if(l>O||l<L)throw new RangeError('"value" argument is out of bounds');if(h+A>g.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(l,h,A,O){if(l=+l,h=h>>>0,A=A>>>0,!O){const fe=Math.pow(2,8*A)-1;ae(this,l,h,A,fe,0)}let L=1,M=0;for(this[h]=l&255;++M<A&&(L*=256);)this[h+M]=l/L&255;return h+A},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(l,h,A,O){if(l=+l,h=h>>>0,A=A>>>0,!O){const fe=Math.pow(2,8*A)-1;ae(this,l,h,A,fe,0)}let L=A-1,M=1;for(this[h+L]=l&255;--L>=0&&(M*=256);)this[h+L]=l/M&255;return h+A},a.prototype.writeUint8=a.prototype.writeUInt8=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,1,255,0),this[h]=l&255,h+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,2,65535,0),this[h]=l&255,this[h+1]=l>>>8,h+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,2,65535,0),this[h]=l>>>8,this[h+1]=l&255,h+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,4,4294967295,0),this[h+3]=l>>>24,this[h+2]=l>>>16,this[h+1]=l>>>8,this[h]=l&255,h+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,4,4294967295,0),this[h]=l>>>24,this[h+1]=l>>>16,this[h+2]=l>>>8,this[h+3]=l&255,h+4};function be(g,l,h,A,O){P(l,A,O,g,h,7);let L=Number(l&BigInt(4294967295));g[h++]=L,L=L>>8,g[h++]=L,L=L>>8,g[h++]=L,L=L>>8,g[h++]=L;let M=Number(l>>BigInt(32)&BigInt(4294967295));return g[h++]=M,M=M>>8,g[h++]=M,M=M>>8,g[h++]=M,M=M>>8,g[h++]=M,h}function xe(g,l,h,A,O){P(l,A,O,g,h,7);let L=Number(l&BigInt(4294967295));g[h+7]=L,L=L>>8,g[h+6]=L,L=L>>8,g[h+5]=L,L=L>>8,g[h+4]=L;let M=Number(l>>BigInt(32)&BigInt(4294967295));return g[h+3]=M,M=M>>8,g[h+2]=M,M=M>>8,g[h+1]=M,M=M>>8,g[h]=M,h+8}a.prototype.writeBigUInt64LE=_t(function(l,h=0){return be(this,l,h,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=_t(function(l,h=0){return xe(this,l,h,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(l,h,A,O){if(l=+l,h=h>>>0,!O){const ke=Math.pow(2,8*A-1);ae(this,l,h,A,ke-1,-ke)}let L=0,M=1,fe=0;for(this[h]=l&255;++L<A&&(M*=256);)l<0&&fe===0&&this[h+L-1]!==0&&(fe=1),this[h+L]=(l/M>>0)-fe&255;return h+A},a.prototype.writeIntBE=function(l,h,A,O){if(l=+l,h=h>>>0,!O){const ke=Math.pow(2,8*A-1);ae(this,l,h,A,ke-1,-ke)}let L=A-1,M=1,fe=0;for(this[h+L]=l&255;--L>=0&&(M*=256);)l<0&&fe===0&&this[h+L+1]!==0&&(fe=1),this[h+L]=(l/M>>0)-fe&255;return h+A},a.prototype.writeInt8=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,1,127,-128),l<0&&(l=255+l+1),this[h]=l&255,h+1},a.prototype.writeInt16LE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,2,32767,-32768),this[h]=l&255,this[h+1]=l>>>8,h+2},a.prototype.writeInt16BE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,2,32767,-32768),this[h]=l>>>8,this[h+1]=l&255,h+2},a.prototype.writeInt32LE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,4,2147483647,-2147483648),this[h]=l&255,this[h+1]=l>>>8,this[h+2]=l>>>16,this[h+3]=l>>>24,h+4},a.prototype.writeInt32BE=function(l,h,A){return l=+l,h=h>>>0,A||ae(this,l,h,4,2147483647,-2147483648),l<0&&(l=4294967295+l+1),this[h]=l>>>24,this[h+1]=l>>>16,this[h+2]=l>>>8,this[h+3]=l&255,h+4},a.prototype.writeBigInt64LE=_t(function(l,h=0){return be(this,l,h,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=_t(function(l,h=0){return xe(this,l,h,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function He(g,l,h,A,O,L){if(h+A>g.length)throw new RangeError("Index out of range");if(h<0)throw new RangeError("Index out of range")}function R(g,l,h,A,O){return l=+l,h=h>>>0,O||He(g,l,h,4),r.write(g,l,h,A,23,4),h+4}a.prototype.writeFloatLE=function(l,h,A){return R(this,l,h,!0,A)},a.prototype.writeFloatBE=function(l,h,A){return R(this,l,h,!1,A)};function $(g,l,h,A,O){return l=+l,h=h>>>0,O||He(g,l,h,8),r.write(g,l,h,A,52,8),h+8}a.prototype.writeDoubleLE=function(l,h,A){return $(this,l,h,!0,A)},a.prototype.writeDoubleBE=function(l,h,A){return $(this,l,h,!1,A)},a.prototype.copy=function(l,h,A,O){if(!a.isBuffer(l))throw new TypeError("argument should be a Buffer");if(A||(A=0),!O&&O!==0&&(O=this.length),h>=l.length&&(h=l.length),h||(h=0),O>0&&O<A&&(O=A),O===A||l.length===0||this.length===0)return 0;if(h<0)throw new RangeError("targetStart out of bounds");if(A<0||A>=this.length)throw new RangeError("Index out of range");if(O<0)throw new RangeError("sourceEnd out of bounds");O>this.length&&(O=this.length),l.length-h<O-A&&(O=l.length-h+A);const L=O-A;return this===l&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(h,A,O):Uint8Array.prototype.set.call(l,this.subarray(A,O),h),L},a.prototype.fill=function(l,h,A,O){if(typeof l=="string"){if(typeof h=="string"?(O=h,h=0,A=this.length):typeof A=="string"&&(O=A,A=this.length),O!==void 0&&typeof O!="string")throw new TypeError("encoding must be a string");if(typeof O=="string"&&!a.isEncoding(O))throw new TypeError("Unknown encoding: "+O);if(l.length===1){const M=l.charCodeAt(0);(O==="utf8"&&M<128||O==="latin1")&&(l=M)}}else typeof l=="number"?l=l&255:typeof l=="boolean"&&(l=Number(l));if(h<0||this.length<h||this.length<A)throw new RangeError("Out of range index");if(A<=h)return this;h=h>>>0,A=A===void 0?this.length:A>>>0,l||(l=0);let L;if(typeof l=="number")for(L=h;L<A;++L)this[L]=l;else{const M=a.isBuffer(l)?l:a.from(l,O),fe=M.length;if(fe===0)throw new TypeError('The value "'+l+'" is invalid for argument "value"');for(L=0;L<A-h;++L)this[L+h]=M[L%fe]}return this};const q={};function Q(g,l,h){q[g]=class extends h{constructor(){super(),Object.defineProperty(this,"message",{value:l.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${g}]`,this.stack,delete this.name}get code(){return g}set code(O){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:O,writable:!0})}toString(){return`${this.name} [${g}]: ${this.message}`}}}Q("ERR_BUFFER_OUT_OF_BOUNDS",function(g){return g?`${g} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Q("ERR_INVALID_ARG_TYPE",function(g,l){return`The "${g}" argument must be of type number. Received type ${typeof l}`},TypeError),Q("ERR_OUT_OF_RANGE",function(g,l,h){let A=`The value of "${g}" is out of range.`,O=h;return Number.isInteger(h)&&Math.abs(h)>2**32?O=oe(String(h)):typeof h=="bigint"&&(O=String(h),(h>BigInt(2)**BigInt(32)||h<-(BigInt(2)**BigInt(32)))&&(O=oe(O)),O+="n"),A+=` It must be ${l}. Received ${O}`,A},RangeError);function oe(g){let l="",h=g.length;const A=g[0]==="-"?1:0;for(;h>=A+4;h-=3)l=`_${g.slice(h-3,h)}${l}`;return`${g.slice(0,h)}${l}`}function T(g,l,h){j(l,"offset"),(g[l]===void 0||g[l+h]===void 0)&&Y(l,g.length-(h+1))}function P(g,l,h,A,O,L){if(g>h||g<l){const M=typeof l=="bigint"?"n":"";let fe;throw l===0||l===BigInt(0)?fe=`>= 0${M} and < 2${M} ** ${(L+1)*8}${M}`:fe=`>= -(2${M} ** ${(L+1)*8-1}${M}) and < 2 ** ${(L+1)*8-1}${M}`,new q.ERR_OUT_OF_RANGE("value",fe,g)}T(A,O,L)}function j(g,l){if(typeof g!="number")throw new q.ERR_INVALID_ARG_TYPE(l,"number",g)}function Y(g,l,h){throw Math.floor(g)!==g?(j(g,h),new q.ERR_OUT_OF_RANGE("offset","an integer",g)):l<0?new q.ERR_BUFFER_OUT_OF_BOUNDS:new q.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${l}`,g)}const he=/[^+/0-9A-Za-z-_]/g;function ce(g){if(g=g.split("=")[0],g=g.trim().replace(he,""),g.length<2)return"";for(;g.length%4!==0;)g=g+"=";return g}function pe(g,l){l=l||1/0;let h;const A=g.length;let O=null;const L=[];for(let M=0;M<A;++M){if(h=g.charCodeAt(M),h>55295&&h<57344){if(!O){if(h>56319){(l-=3)>-1&&L.push(239,191,189);continue}else if(M+1===A){(l-=3)>-1&&L.push(239,191,189);continue}O=h;continue}if(h<56320){(l-=3)>-1&&L.push(239,191,189),O=h;continue}h=(O-55296<<10|h-56320)+65536}else O&&(l-=3)>-1&&L.push(239,191,189);if(O=null,h<128){if((l-=1)<0)break;L.push(h)}else if(h<2048){if((l-=2)<0)break;L.push(h>>6|192,h&63|128)}else if(h<65536){if((l-=3)<0)break;L.push(h>>12|224,h>>6&63|128,h&63|128)}else if(h<1114112){if((l-=4)<0)break;L.push(h>>18|240,h>>12&63|128,h>>6&63|128,h&63|128)}else throw new Error("Invalid code point")}return L}function Sr(g){const l=[];for(let h=0;h<g.length;++h)l.push(g.charCodeAt(h)&255);return l}function Tn(g,l){let h,A,O;const L=[];for(let M=0;M<g.length&&!((l-=2)<0);++M)h=g.charCodeAt(M),A=h>>8,O=h%256,L.push(O),L.push(A);return L}function yi(g){return t.toByteArray(ce(g))}function Pn(g,l,h,A){let O;for(O=0;O<A&&!(O+h>=l.length||O>=g.length);++O)l[O+h]=g[O];return O}function mt(g,l){return g instanceof l||g!=null&&g.constructor!=null&&g.constructor.name!=null&&g.constructor.name===l.name}function Kr(g){return g!==g}const mi=function(){const g="0123456789abcdef",l=new Array(256);for(let h=0;h<16;++h){const A=h*16;for(let O=0;O<16;++O)l[A+O]=g[h]+g[O]}return l}();function _t(g){return typeof BigInt>"u"?Yr:g}function Yr(){throw new Error("BigInt not supported")}})(Ar);var ms={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}};ms.Null=ms.Nil;for(var Fd in ms)ms[Fd].toJSON=(function(e){return e}).bind(null,Fd);var hf=ms,sn=hf;function pp(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function pf(e){return sn.Nil(e)?"":pp(e.constructor)}function I_(e){return sn.Function(e)?"":sn.String(e)?JSON.stringify(e):e&&sn.Object(e)?"":e}function yf(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Eo(e){return sn.Function(e)?e.toJSON?e.toJSON():pp(e):sn.Array(e)?"Array":e&&sn.Object(e)?"Object":e!==void 0?e:""}function yp(e,t,r){var n=I_(t);return"Expected "+Eo(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function gr(e,t,r){r=r||pf(t),this.message=yp(e,t,r),yf(this,gr),this.__type=e,this.__value=t,this.__valueTypeName=r}gr.prototype=Object.create(Error.prototype);gr.prototype.constructor=gr;function k_(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),yp('property "'+Eo(r)+s+Eo(e),n,i)}function qn(e,t,r,n,i){e?(i=i||pf(n),this.message=k_(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',yf(this,gr),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}qn.prototype=Object.create(Error.prototype);qn.prototype.constructor=gr;function C_(e,t){return new gr(e,{},t)}function O_(e,t,r){return e instanceof qn?(t=t+"."+e.__property,e=new qn(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof gr&&(e=new qn(e.__type,t,r,e.__value,e.__valueTypeName)),yf(e),e}var mp={TfTypeError:gr,TfPropertyTypeError:qn,tfCustomError:C_,tfSubError:O_,tfJSON:Eo,getValueTypeName:pf},Ga,Ud;function R_(){if(Ud)return Ga;Ud=1;var e=hf,t=mp;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function i(S,C){var N=S.toJSON();function I(G){if(!S(G))return!1;if(G.length===C)return!0;throw t.tfCustomError(N+"(Length: "+C+")",N+"(Length: "+G.length+")")}return I.toJSON=function(){return N},I}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function u(S,C,N){N=N||e.Number;function I(G,k){return N(G,k)&&G>S&&G<C}return I.toJSON=function(){return`${N.toJSON()} between [${S}, ${C}]`},I}var f=Math.pow(2,53)-1;function d(S){return typeof S=="number"&&isFinite(S)}function y(S){return S<<24>>24===S}function p(S){return S<<16>>16===S}function w(S){return(S|0)===S}function b(S){return typeof S=="number"&&S>=-f&&S<=f&&Math.floor(S)===S}function m(S){return(S&255)===S}function _(S){return(S&65535)===S}function E(S){return S>>>0===S}function x(S){return typeof S=="number"&&S>=0&&S<=f&&Math.floor(S)===S}var v={ArrayN:s,Buffer:r,BufferN:o,Finite:d,Hex:n,HexN:a,Int8:y,Int16:p,Int32:w,Int53:b,Range:u,StringN:c,UInt8:m,UInt16:_,UInt32:E,UInt53:x};for(var B in v)v[B].toJSON=(function(S){return S}).bind(null,B);return Ga=v,Ga}var Rs=mp,Ke=hf,ir=Rs.tfJSON,bp=Rs.TfTypeError,gp=Rs.TfPropertyTypeError,Ei=Rs.tfSubError,N_=Rs.getValueTypeName,dr={arrayOf:function(t,r){t=Kt(t),r=r||{};function n(i,s){return!Ke.Array(i)||Ke.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(o,a){try{return ut(t,o,s)}catch(c){throw Ei(c,a)}})}return n.toJSON=function(){var i="["+ir(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=Kt(t);function r(n,i){return Ke.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+ir(t)},r},map:function(t,r){t=Kt(t),r&&(r=Kt(r));function n(i,s){if(!Ke.Object(i)||Ke.Nil(i))return!1;for(var o in i){try{r&&ut(r,o,s)}catch(c){throw Ei(c,o,"key")}try{var a=i[o];ut(t,a,s)}catch(c){throw Ei(c,o)}}return!0}return r?n.toJSON=function(){return"{"+ir(r)+": "+ir(t)+"}"}:n.toJSON=function(){return"{"+ir(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Kt(t[n]);function i(s,o){if(!Ke.Object(s)||Ke.Nil(s))return!1;var a;try{for(a in r){var c=r[a],u=s[a];ut(c,u,o)}}catch(f){throw Ei(f,a)}if(o){for(a in s)if(!r[a])throw new gp(void 0,a)}return!0}return i.toJSON=function(){return ir(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Kt);function r(n,i){return t.some(function(s){try{return ut(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(ir).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Kt);function r(n,i){return t.every(function(s){try{return ut(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(ir).join(" & ")},r},quacksLike:function(t){function r(n){return t===N_(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Kt);function r(n,i){return Ke.Nil(n)||Ke.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return ut(s,n[o],i)}catch(a){throw Ei(a,o)}})}return r.toJSON=function(){return"("+t.map(ir).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};dr.oneOf=dr.anyOf;function Kt(e){if(Ke.String(e))return e[0]==="?"?dr.maybe(e.slice(1)):Ke[e]||dr.quacksLike(e);if(e&&Ke.Object(e)){if(Ke.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return dr.arrayOf(e[0])}return dr.object(e)}else if(Ke.Function(e))return e;return dr.value(e)}function ut(e,t,r,n){if(Ke.Function(e)){if(e(t,r))return!0;throw new bp(n||e,t)}return ut(Kt(e),t,r)}for(var Ur in Ke)ut[Ur]=Ke[Ur];for(Ur in dr)ut[Ur]=dr[Ur];var Md=R_();for(Ur in Md)ut[Ur]=Md[Ur];ut.compile=Kt;ut.TfTypeError=bp;ut.TfPropertyTypeError=gp;var wp=ut;(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=Ar;e.typeforce=wp;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(f,d){return f.length!==d.length?!1:f.every((y,p)=>y.equals(d[p]))}e.stacksEqual=i;function s(f){if(!t.Buffer.isBuffer(f)||f.length<33)return!1;const d=f[0],y=f.slice(1,33);if(y.compare(r)===0||y.compare(n)>=0)return!1;if((d===2||d===3)&&f.length===33)return!0;const p=f.slice(33);return p.compare(r)===0||p.compare(n)>=0?!1:d===4&&f.length===65}e.isPoint=s;const o=21*1e14;function a(f){return e.typeforce.UInt53(f)&&f<=o}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(d=>u(d)):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})(it);var Ns={},Ye={};Object.defineProperty(Ye,"__esModule",{value:!0});Ye.BufferReader=Ye.BufferWriter=Ye.cloneBuffer=Ye.reverseBuffer=Ye.writeUInt64LE=Ye.readUInt64LE=Ye.varuint=void 0;const on=it,{typeforce:vp}=on,bs=Rl;Ye.varuint=bs;function _p(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 xp(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,_p(n+r,9007199254740991),n+r}Ye.readUInt64LE=xp;function Ep(e,t,r){return _p(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Ye.writeUInt64LE=Ep;function $_(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}Ye.reverseBuffer=$_;function L_(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Ye.cloneBuffer=L_;class mf{static withCapacity(t){return new mf(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,vp(on.tuple(on.Buffer,on.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=Ep(this.buffer,t,this.offset)}writeVarInt(t){bs.encode(t,this.buffer,this.offset),this.offset+=bs.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}`)}}Ye.BufferWriter=mf;class F_{constructor(t,r=0){this.buffer=t,this.offset=r,vp(on.tuple(on.Buffer,on.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=xp(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=bs.decode(this.buffer,this.offset);return this.offset+=bs.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}}Ye.BufferReader=F_;var Gr={},ti={};Object.defineProperty(ti,"__esModule",{value:!0});ti.sha1=ti.SHA1=void 0;const Va=Er,fo=Os,Ai=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),kr=new Uint32Array(80);class Ap extends Va.HashMD{constructor(){super(64,20,8,!1),this.A=Ai[0]|0,this.B=Ai[1]|0,this.C=Ai[2]|0,this.D=Ai[3]|0,this.E=Ai[4]|0}get(){const{A:t,B:r,C:n,D:i,E:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0}process(t,r){for(let c=0;c<16;c++,r+=4)kr[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)kr[c]=(0,fo.rotl)(kr[c-3]^kr[c-8]^kr[c-14]^kr[c-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let c=0;c<80;c++){let u,f;c<20?(u=(0,Va.Chi)(i,s,o),f=1518500249):c<40?(u=i^s^o,f=1859775393):c<60?(u=(0,Va.Maj)(i,s,o),f=2400959708):(u=i^s^o,f=3395469782);const d=(0,fo.rotl)(n,5)+u+a+f+kr[c]|0;a=o,o=s,s=(0,fo.rotl)(i,30),i=n,n=d}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,this.set(n,i,s,o,a)}roundClean(){kr.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}ti.SHA1=Ap;ti.sha1=(0,fo.wrapConstructor)(()=>new Ap);(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=Qn,r=ti,n=pr;function i(f){return Buffer.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function s(f){return Buffer.from((0,r.sha1)(Uint8Array.from(f)))}e.sha1=s;function o(f){return Buffer.from((0,n.sha256)(Uint8Array.from(f)))}e.sha256=o;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,d){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[f],d]))}e.taggedHash=u})(Gr);var Wa={},yr={};Object.defineProperty(yr,"__esModule",{value:!0});yr.encode=yr.decode=yr.check=void 0;function U_(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))}yr.check=U_;function M_(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)}}yr.decode=M_;function H_(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}yr.encode=H_;var mn={};Object.defineProperty(mn,"__esModule",{value:!0});mn.REVERSE_OPS=mn.OPS=void 0;const nu={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};mn.OPS=nu;const Sp={};mn.REVERSE_OPS=Sp;for(const e of Object.keys(nu)){const t=nu[e];Sp[t]=e}var Mr={};Object.defineProperty(Mr,"__esModule",{value:!0});Mr.decode=Mr.encode=Mr.encodingLength=void 0;const Lr=mn;function Tp(e){return e<Lr.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Mr.encodingLength=Tp;function D_(e,t,r){const n=Tp(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(Lr.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(Lr.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(Lr.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Mr.encode=D_;function j_(e,t){const r=e.readUInt8(t);let n,i;if(r<Lr.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===Lr.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===Lr.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!==Lr.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Mr.decode=j_;var ri={};Object.defineProperty(ri,"__esModule",{value:!0});ri.encode=ri.decode=void 0;function z_(e,t,r){t=t||4,r=r===void 0?!0:r;const n=e.length;if(n===0)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(e[n-1]&127)&&(n<=1||!(e[n-2]&128)))throw new Error("Non-minimally encoded script number");if(n===5){const s=e.readUInt32LE(0),o=e.readUInt8(4);return o&128?-((o&-129)*4294967296+s):o*4294967296+s}let i=0;for(let s=0;s<n;++s)i|=e[s]<<8*s;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}ri.decode=z_;function q_(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function G_(e){let t=Math.abs(e);const r=q_(t),n=Buffer.allocUnsafe(r),i=e<0;for(let s=0;s<r;++s)n.writeUInt8(t&255,s),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}ri.encode=G_;var Xr={},Hd;function V_(){if(Hd)return Xr;Hd=1,Object.defineProperty(Xr,"__esModule",{value:!0}),Xr.encode=Xr.decode=void 0;const e=yr,t=vt(),r=it,{typeforce:n}=r,i=Buffer.alloc(1,0);function s(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 o(u){u[0]===0&&(u=u.slice(1));const f=Buffer.alloc(32,0),d=Math.max(0,32-u.length);return u.copy(f,d),f}function a(u){const f=u.readUInt8(u.length-1);if(!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const d=e.decode(u.slice(0,-1)),y=o(d.r),p=o(d.s);return{signature:Buffer.concat([y,p],64),hashType:f}}Xr.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 d=Buffer.allocUnsafe(1);d.writeUInt8(f,0);const y=s(u.slice(0,32)),p=s(u.slice(32,64));return Buffer.concat([e.encode(y,p),d])}return Xr.encode=c,Xr}var Dd;function vt(){return Dd||(Dd=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=yr,r=mn;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Mr,i=ri,s=V_(),o=it,{typeforce:a}=o,c=r.OPS.OP_RESERVED;function u(I){return o.Number(I)&&(I===r.OPS.OP_0||I>=r.OPS.OP_1&&I<=r.OPS.OP_16||I===r.OPS.OP_1NEGATE)}function f(I){return o.Buffer(I)||u(I)}function d(I){return o.Array(I)&&I.every(f)}e.isPushOnly=d;function y(I){return I.length-I.filter(f).length}e.countNonPushOnlyOPs=y;function p(I){if(I.length===0)return r.OPS.OP_0;if(I.length===1){if(I[0]>=1&&I[0]<=16)return c+I[0];if(I[0]===129)return r.OPS.OP_1NEGATE}}function w(I){return Buffer.isBuffer(I)}function b(I){return o.Array(I)}function m(I){return Buffer.isBuffer(I)}function _(I){if(w(I))return I;a(o.Array,I);const G=I.reduce((z,F)=>m(F)?F.length===1&&p(F)!==void 0?z+1:z+n.encodingLength(F.length)+F.length:z+1,0),k=Buffer.allocUnsafe(G);let U=0;if(I.forEach(z=>{if(m(z)){const F=p(z);if(F!==void 0){k.writeUInt8(F,U),U+=1;return}U+=n.encode(k,z.length,U),z.copy(k,U),U+=z.length}else k.writeUInt8(z,U),U+=1}),U!==k.length)throw new Error("Could not decode chunks");return k}e.compile=_;function E(I){if(b(I))return I;a(o.Buffer,I);const G=[];let k=0;for(;k<I.length;){const U=I[k];if(U>r.OPS.OP_0&&U<=r.OPS.OP_PUSHDATA4){const z=n.decode(I,k);if(z===null||(k+=z.size,k+z.number>I.length))return null;const F=I.slice(k,k+z.number);k+=z.number;const D=p(F);D!==void 0?G.push(D):G.push(F)}else G.push(U),k+=1}return G}e.decompile=E;function x(I){if(w(I)&&(I=E(I)),!I)throw new Error("Could not convert invalid chunks to ASM");return I.map(G=>{if(m(G)){const k=p(G);if(k===void 0)return G.toString("hex");G=k}return r.REVERSE_OPS[G]}).join(" ")}e.toASM=x;function v(I){return a(o.String,I),_(I.split(" ").map(G=>r.OPS[G]!==void 0?r.OPS[G]:(a(o.Hex,G),Buffer.from(G,"hex"))))}e.fromASM=v;function B(I){return I=E(I),a(d,I),I.map(G=>m(G)?G:G===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(G-c))}e.toStack=B;function S(I){return o.isPoint(I)}e.isCanonicalPubKey=S;function C(I){const G=I&-129;return G>0&&G<4}e.isDefinedHashType=C;function N(I){return!Buffer.isBuffer(I)||!C(I[I.length-1])?!1:t.check(I.slice(0,-1))}e.isCanonicalScriptSignature=N,e.number=i,e.signature=s}(Wa)),Wa}Object.defineProperty(Ns,"__esModule",{value:!0});Ns.Transaction=void 0;const Le=Ye,st=Gr,jd=vt(),W_=vt(),le=it,{typeforce:zt}=le;function Vt(e){const t=e.length;return Le.varuint.encodingLength(t)+t}function K_(e){const t=e.length;return Le.varuint.encodingLength(t)+e.reduce((r,n)=>r+Vt(n),0)}const $r=Buffer.allocUnsafe(0),Ka=[],Ya=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),zd=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Y_=Buffer.from("ffffffffffffffff","hex"),Z_={script:$r,valueBuffer:Y_};function X_(e){return e.value!==void 0}class ue{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Le.BufferReader(t),i=new ue;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===ue.ADVANCED_TRANSACTION_MARKER&&o===ue.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:Ka});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 ue.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){zt(le.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&ue.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return zt(le.tuple(le.Hash256bit,le.UInt32,le.maybe(le.UInt32),le.maybe(le.Buffer)),arguments),le.Null(n)&&(n=ue.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||$r,sequence:n,witness:Ka})-1}addOutput(t,r){return zt(le.tuple(le.Buffer,le.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=Ka})}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)+Le.varuint.encodingLength(this.ins.length)+Le.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+Vt(i.script),0)+this.outs.reduce((n,i)=>n+8+Vt(i.script),0)+(r?this.ins.reduce((n,i)=>n+K_(i.witness),0):0)}clone(){const t=new ue;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(zt(le.tuple(le.UInt32,le.Buffer,le.Number),arguments),t>=this.ins.length)return zd;const i=jd.compile(jd.decompile(r).filter(a=>a!==W_.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===ue.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===ue.SIGHASH_SINGLE){if(t>=this.outs.length)return zd;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=Z_;s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&ue.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=$r}),s.ins[t].script=i);const o=Buffer.allocUnsafe(s.byteLength(!1)+4);return o.writeInt32LE(n,o.length-4),s.__toBuffer(o,0,!1),st.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(zt(le.tuple(le.UInt32,zt.arrayOf(le.Buffer),zt.arrayOf(le.Satoshi),le.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===ue.SIGHASH_DEFAULT?ue.SIGHASH_ALL:i&ue.SIGHASH_OUTPUT_MASK,u=(i&ue.SIGHASH_INPUT_MASK)===ue.SIGHASH_ANYONECANPAY,f=a===ue.SIGHASH_NONE,d=a===ue.SIGHASH_SINGLE;let y=$r,p=$r,w=$r,b=$r,m=$r;if(!u){let v=Le.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(B=>{v.writeSlice(B.hash),v.writeUInt32(B.index)}),y=st.sha256(v.end()),v=Le.BufferWriter.withCapacity(8*this.ins.length),n.forEach(B=>v.writeUInt64(B)),p=st.sha256(v.end()),v=Le.BufferWriter.withCapacity(r.map(Vt).reduce((B,S)=>B+S)),r.forEach(B=>v.writeVarSlice(B)),w=st.sha256(v.end()),v=Le.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(B=>v.writeUInt32(B.sequence)),b=st.sha256(v.end())}if(f||d){if(d&&t<this.outs.length){const v=this.outs[t],B=Le.BufferWriter.withCapacity(8+Vt(v.script));B.writeUInt64(v.value),B.writeVarSlice(v.script),m=st.sha256(B.end())}}else{const v=this.outs.map(S=>8+Vt(S.script)).reduce((S,C)=>S+C),B=Le.BufferWriter.withCapacity(v);this.outs.forEach(S=>{B.writeUInt64(S.value),B.writeVarSlice(S.script)}),m=st.sha256(B.end())}const _=(s?2:0)+(o?1:0),E=174-(u?49:0)-(f?32:0)+(o?32:0)+(s?37:0),x=Le.BufferWriter.withCapacity(E);if(x.writeUInt8(i),x.writeInt32(this.version),x.writeUInt32(this.locktime),x.writeSlice(y),x.writeSlice(p),x.writeSlice(w),x.writeSlice(b),f||d||x.writeSlice(m),x.writeUInt8(_),u){const v=this.ins[t];x.writeSlice(v.hash),x.writeUInt32(v.index),x.writeUInt64(n[t]),x.writeVarSlice(r[t]),x.writeUInt32(v.sequence)}else x.writeUInt32(t);if(o){const v=Le.BufferWriter.withCapacity(Vt(o));v.writeVarSlice(o),x.writeSlice(st.sha256(v.end()))}return d&&x.writeSlice(m),s&&(x.writeSlice(s),x.writeUInt8(0),x.writeUInt32(4294967295)),st.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),x.end()]))}hashForWitnessV0(t,r,n,i){zt(le.tuple(le.UInt32,le.Buffer,le.Satoshi,le.UInt32),arguments);let s=Buffer.from([]),o,a=Ya,c=Ya,u=Ya;if(i&ue.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Le.BufferWriter(s,0),this.ins.forEach(d=>{o.writeSlice(d.hash),o.writeUInt32(d.index)}),c=st.hash256(s)),!(i&ue.SIGHASH_ANYONECANPAY)&&(i&31)!==ue.SIGHASH_SINGLE&&(i&31)!==ue.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Le.BufferWriter(s,0),this.ins.forEach(d=>{o.writeUInt32(d.sequence)}),u=st.hash256(s)),(i&31)!==ue.SIGHASH_SINGLE&&(i&31)!==ue.SIGHASH_NONE){const d=this.outs.reduce((y,p)=>y+8+Vt(p.script),0);s=Buffer.allocUnsafe(d),o=new Le.BufferWriter(s,0),this.outs.forEach(y=>{o.writeUInt64(y.value),o.writeVarSlice(y.script)}),a=st.hash256(s)}else if((i&31)===ue.SIGHASH_SINGLE&&t<this.outs.length){const d=this.outs[t];s=Buffer.allocUnsafe(8+Vt(d.script)),o=new Le.BufferWriter(s,0),o.writeUInt64(d.value),o.writeVarSlice(d.script),a=st.hash256(s)}s=Buffer.allocUnsafe(156+Vt(r)),o=new Le.BufferWriter(s,0);const f=this.ins[t];return o.writeInt32(this.version),o.writeSlice(c),o.writeSlice(u),o.writeSlice(f.hash),o.writeUInt32(f.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(f.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),st.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):st.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Le.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){zt(le.tuple(le.Number,le.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){zt(le.tuple(le.Number,[le.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Le.BufferWriter(t,r||0);i.writeInt32(this.version);const s=n&&this.hasWitnesses();return s&&(i.writeUInt8(ue.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(ue.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(o=>{i.writeSlice(o.hash),i.writeUInt32(o.index),i.writeVarSlice(o.script),i.writeUInt32(o.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(o=>{X_(o)?i.writeUInt64(o.value):i.writeSlice(o.valueBuffer),i.writeVarSlice(o.script)}),s&&this.ins.forEach(o=>{i.writeVector(o.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}Ns.Transaction=ue;ue.DEFAULT_SEQUENCE=4294967295;ue.SIGHASH_DEFAULT=0;ue.SIGHASH_ALL=1;ue.SIGHASH_NONE=2;ue.SIGHASH_SINGLE=3;ue.SIGHASH_ANYONECANPAY=128;ue.SIGHASH_OUTPUT_MASK=3;ue.SIGHASH_INPUT_MASK=128;ue.ADVANCED_TRANSACTION_MARKER=0;ue.ADVANCED_TRANSACTION_FLAG=1;var ve={},$s={};Object.defineProperty($s,"__esModule",{value:!0});const J_=9007199254740991;function bf(e){if(e<0||e>J_||e%1!==0)throw new RangeError("value out of range")}function Fi(e,t,r){if(bf(e),t||(t=Buffer.allocUnsafe(Pp(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(Fi,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(Fi,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(Fi,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(Fi,{bytes:9})),t}$s.encode=Fi;function Ui(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(Ui,{bytes:1}),r;if(r===253)return Object.assign(Ui,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(Ui,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(Ui,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return bf(s),s}}$s.decode=Ui;function Pp(e){return bf(e),e<253?1:e<=65535?3:e<=4294967295?5:9}$s.encodingLength=Pp;var Za={},Qo={},nt={};Object.defineProperty(nt,"__esModule",{value:!0});nt.testnet=nt.regtest=nt.bitcoin=void 0;nt.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
51
|
+
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};nt.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
52
|
+
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};nt.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
53
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var bt={};Object.defineProperty(bt,"__esModule",{value:!0});bt.value=bt.prop=void 0;function Q_(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})}})}bt.prop=Q_;function e6(e){let t;return()=>(t!==void 0||(t=e()),t)}bt.value=e6;Object.defineProperty(Qo,"__esModule",{value:!0});Qo.p2data=void 0;const t6=nt,lo=vt(),qt=it,qd=bt,Gd=lo.OPS;function r6(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,qt.typeforce)({network:qt.typeforce.maybe(qt.typeforce.Object),output:qt.typeforce.maybe(qt.typeforce.Buffer),data:qt.typeforce.maybe(qt.typeforce.arrayOf(qt.typeforce.Buffer))},e);const n={name:"embed",network:e.network||t6.bitcoin};if(qd.prop(n,"output",()=>{if(e.data)return lo.compile([Gd.OP_RETURN].concat(e.data))}),qd.prop(n,"data",()=>{if(e.output)return lo.decompile(e.output).slice(1)}),t.validate&&e.output){const i=lo.decompile(e.output);if(i[0]!==Gd.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(qt.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,qt.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}Qo.p2data=r6;var ea={};Object.defineProperty(ea,"__esModule",{value:!0});ea.p2ms=void 0;const n6=nt,Nn=vt(),Re=it,Cr=bt,$n=Nn.OPS,Zs=$n.OP_RESERVED;function i6(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 Nn.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===$n.OP_0)!==void 0}(0,Re.typeforce)({network:Re.typeforce.maybe(Re.typeforce.Object),m:Re.typeforce.maybe(Re.typeforce.Number),n:Re.typeforce.maybe(Re.typeforce.Number),output:Re.typeforce.maybe(Re.typeforce.Buffer),pubkeys:Re.typeforce.maybe(Re.typeforce.arrayOf(Re.isPoint)),signatures:Re.typeforce.maybe(Re.typeforce.arrayOf(r)),input:Re.typeforce.maybe(Re.typeforce.Buffer)},e);const i={network:e.network||n6.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=Nn.decompile(c),i.m=s[0]-Zs,i.n=s[s.length-2]-Zs,i.pubkeys=s.slice(1,-2))}if(Cr.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Nn.compile([].concat(Zs+e.m,e.pubkeys,Zs+i.n,$n.OP_CHECKMULTISIG))}),Cr.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),Cr.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Cr.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),Cr.prop(i,"signatures",()=>{if(e.input)return Nn.decompile(e.input).slice(1)}),Cr.prop(i,"input",()=>{if(e.signatures)return Nn.compile([$n.OP_0].concat(e.signatures))}),Cr.prop(i,"witness",()=>{if(i.input)return[]}),Cr.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!Re.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!Re.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==$n.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==s.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(c=>(0,Re.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,Re.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]!==$n.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,Re.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)}ea.p2ms=i6;var ta={};Object.defineProperty(ta,"__esModule",{value:!0});ta.p2pk=void 0;const s6=nt,Ln=vt(),kt=it,On=bt,Vd=Ln.OPS;function o6(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,kt.typeforce)({network:kt.typeforce.maybe(kt.typeforce.Object),output:kt.typeforce.maybe(kt.typeforce.Buffer),pubkey:kt.typeforce.maybe(kt.isPoint),signature:kt.typeforce.maybe(Ln.isCanonicalScriptSignature),input:kt.typeforce.maybe(kt.typeforce.Buffer)},e);const r=On.value(()=>Ln.decompile(e.input)),i={name:"p2pk",network:e.network||s6.bitcoin};if(On.prop(i,"output",()=>{if(e.pubkey)return Ln.compile([e.pubkey,Vd.OP_CHECKSIG])}),On.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),On.prop(i,"signature",()=>{if(e.input)return r()[0]}),On.prop(i,"input",()=>{if(e.signature)return Ln.compile([e.signature])}),On.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==Vd.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,kt.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(!Ln.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}ta.p2pk=o6;var ra={};function a6(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),u=Math.log(256)/Math.log(o);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 w=0,b=0,m=0,_=p.length;m!==_&&p[m]===0;)m++,w++;for(var E=(_-m)*u+1>>>0,x=new Uint8Array(E);m!==_;){for(var v=p[m],B=0,S=E-1;(v!==0||B<b)&&S!==-1;S--,B++)v+=256*x[S]>>>0,x[S]=v%o>>>0,v=v/o>>>0;if(v!==0)throw new Error("Non-zero carry");b=B,m++}for(var C=E-b;C!==E&&x[C]===0;)C++;for(var N=a.repeat(w);C<E;++C)N+=e.charAt(x[C]);return N}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;for(var w=0,b=0,m=0;p[w]===a;)b++,w++;for(var _=(p.length-w)*c+1>>>0,E=new Uint8Array(_);p[w];){var x=p.charCodeAt(w);if(x>255)return;var v=t[x];if(v===255)return;for(var B=0,S=_-1;(v!==0||B<m)&&S!==-1;S--,B++)v+=o*E[S]>>>0,E[S]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");m=B,w++}for(var C=_-m;C!==_&&E[C]===0;)C++;for(var N=new Uint8Array(b+(_-C)),I=b;C!==_;)N[I++]=E[C++];return N}function y(p){var w=d(p);if(w)return w;throw new Error("Non-base"+o+" character")}return{encode:f,decodeUnsafe:d,decode:y}}var c6=a6;const u6=c6,f6="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var d6=u6(f6),Xa=d6,l6=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,u=new Uint8Array(c);return u.set(o,0),u.set(a.subarray(0,4),o.length),Xa.encode(u,c)}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=Xa.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Xa.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:Wd}=pr,h6=l6;function p6(e){return Wd(Wd(e))}var gf=h6(p6);Object.defineProperty(ra,"__esModule",{value:!0});ra.p2pkh=void 0;const Ja=Gr,y6=nt,Fn=vt(),ot=it,sr=bt,Kd=gf,Or=Fn.OPS;function m6(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,ot.typeforce)({network:ot.typeforce.maybe(ot.typeforce.Object),address:ot.typeforce.maybe(ot.typeforce.String),hash:ot.typeforce.maybe(ot.typeforce.BufferN(20)),output:ot.typeforce.maybe(ot.typeforce.BufferN(25)),pubkey:ot.typeforce.maybe(ot.isPoint),signature:ot.typeforce.maybe(Fn.isCanonicalScriptSignature),input:ot.typeforce.maybe(ot.typeforce.Buffer)},e);const r=sr.value(()=>{const o=Buffer.from(Kd.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=sr.value(()=>Fn.decompile(e.input)),i=e.network||y6.bitcoin,s={name:"p2pkh",network:i};if(sr.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),Kd.encode(o)}),sr.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Ja.hash160(e.pubkey||s.pubkey)}),sr.prop(s,"output",()=>{if(s.hash)return Fn.compile([Or.OP_DUP,Or.OP_HASH160,s.hash,Or.OP_EQUALVERIFY,Or.OP_CHECKSIG])}),sr.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),sr.prop(s,"signature",()=>{if(e.input)return n()[0]}),sr.prop(s,"input",()=>{if(e.pubkey&&e.signature)return Fn.compile([e.signature,e.pubkey])}),sr.prop(s,"witness",()=>{if(s.input)return[]}),t.validate){let o=Buffer.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");o=r().hash}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==Or.OP_DUP||e.output[1]!==Or.OP_HASH160||e.output[2]!==20||e.output[23]!==Or.OP_EQUALVERIFY||e.output[24]!==Or.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.pubkey){const a=Ja.hash160(e.pubkey);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!Fn.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,ot.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=Ja.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}ra.p2pkh=m6;var na={};Object.defineProperty(na,"__esModule",{value:!0});na.p2sh=void 0;const Yd=Gr,b6=nt,Wt=vt(),Ee=it,Gt=bt,Zd=gf,Si=Wt.OPS;function g6(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,Ee.typeforce)({network:Ee.typeforce.maybe(Ee.typeforce.Object),address:Ee.typeforce.maybe(Ee.typeforce.String),hash:Ee.typeforce.maybe(Ee.typeforce.BufferN(20)),output:Ee.typeforce.maybe(Ee.typeforce.BufferN(23)),redeem:Ee.typeforce.maybe({network:Ee.typeforce.maybe(Ee.typeforce.Object),output:Ee.typeforce.maybe(Ee.typeforce.Buffer),input:Ee.typeforce.maybe(Ee.typeforce.Buffer),witness:Ee.typeforce.maybe(Ee.typeforce.arrayOf(Ee.typeforce.Buffer))}),input:Ee.typeforce.maybe(Ee.typeforce.Buffer),witness:Ee.typeforce.maybe(Ee.typeforce.arrayOf(Ee.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||b6.bitcoin);const n={network:r},i=Gt.value(()=>{const a=Buffer.from(Zd.decode(e.address)),c=a.readUInt8(0),u=a.slice(1);return{version:c,hash:u}}),s=Gt.value(()=>Wt.decompile(e.input)),o=Gt.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Si.OP_FALSE?Buffer.from([]):c,input:Wt.compile(a.slice(0,-1)),witness:e.witness||[]}});if(Gt.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),Zd.encode(a)}),Gt.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 Yd.hash160(n.redeem.output)}),Gt.prop(n,"output",()=>{if(n.hash)return Wt.compile([Si.OP_HASH160,n.hash,Si.OP_EQUAL])}),Gt.prop(n,"redeem",()=>{if(e.input)return o()}),Gt.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return Wt.compile([].concat(Wt.decompile(e.redeem.input),e.redeem.output))}),Gt.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),Gt.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]!==Si.OP_HASH160||e.output[1]!==20||e.output[22]!==Si.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=Wt.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(Wt.countNonPushOnlyOPs(f)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const d=Yd.hash160(u.output);if(a.length>0&&!a.equals(d))throw new TypeError("Hash mismatch");a=d}if(u.input){const f=u.input.length>0,d=u.witness&&u.witness.length>0;if(!f&&!d)throw new TypeError("Empty input");if(f&&d)throw new TypeError("Input and witness provided");if(f){const y=Wt.decompile(u.input);if(!Wt.isPushOnly(y))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=s();if(!u||u.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(o().output))throw new TypeError("Input is invalid");c(o())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const u=o();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,Ee.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}na.p2sh=g6;var ia={},wr={};Object.defineProperty(wr,"__esModule",{value:!0});wr.bech32m=wr.bech32=void 0;const Ao="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Bp={};for(let e=0;e<Ao.length;e++){const t=Ao.charAt(e);Bp[t]=e}function Gn(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 Xd(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=Gn(t)^n>>5}t=Gn(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=Gn(t)^n&31}return t}function wf(e,t,r,n){let i=0,s=0;const o=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],s+=t;s>=r;)s-=r,a.push(i>>s&o);if(n)s>0&&a.push(i<<r-s&o);else{if(s>=t)return"Excess padding";if(i<<r-s&o)return"Non-zero padding"}return a}function w6(e){return wf(e,8,5,!0)}function v6(e){const t=wf(e,5,8,!1);if(Array.isArray(t))return t}function _6(e){const t=wf(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Ip(e){let t;e==="bech32"?t=1:t=734539939;function r(o,a,c){if(c=c||90,o.length+7+a.length>c)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let u=Xd(o);if(typeof u=="string")throw new Error(u);let f=o+"1";for(let d=0;d<a.length;++d){const y=a[d];if(y>>5)throw new Error("Non 5-bit word");u=Gn(u)^y,f+=Ao.charAt(y)}for(let d=0;d<6;++d)u=Gn(u);u^=t;for(let d=0;d<6;++d){const y=u>>(5-d)*5&31;f+=Ao.charAt(y)}return f}function n(o,a){if(a=a||90,o.length<8)return o+" too short";if(o.length>a)return"Exceeds length limit";const c=o.toLowerCase(),u=o.toUpperCase();if(o!==c&&o!==u)return"Mixed-case string "+o;o=c;const f=o.lastIndexOf("1");if(f===-1)return"No separator character for "+o;if(f===0)return"Missing prefix for "+o;const d=o.slice(0,f),y=o.slice(f+1);if(y.length<6)return"Data too short";let p=Xd(d);if(typeof p=="string")return p;const w=[];for(let b=0;b<y.length;++b){const m=y.charAt(b),_=Bp[m];if(_===void 0)return"Unknown character "+m;p=Gn(p)^_,!(b+6>=y.length)&&w.push(_)}return p!==t?"Invalid checksum for "+o:{prefix:d,words:w}}function i(o,a){const c=n(o,a);if(typeof c=="object")return c}function s(o,a){const c=n(o,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:s,encode:r,toWords:w6,fromWordsUnsafe:v6,fromWords:_6}}wr.bech32=Ip("bech32");wr.bech32m=Ip("bech32m");Object.defineProperty(ia,"__esModule",{value:!0});ia.p2wpkh=void 0;const Qa=Gr,x6=nt,ho=vt(),De=it,Rr=bt,Xs=wr,Jd=ho.OPS,E6=Buffer.alloc(0);function A6(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,De.typeforce)({address:De.typeforce.maybe(De.typeforce.String),hash:De.typeforce.maybe(De.typeforce.BufferN(20)),input:De.typeforce.maybe(De.typeforce.BufferN(0)),network:De.typeforce.maybe(De.typeforce.Object),output:De.typeforce.maybe(De.typeforce.BufferN(22)),pubkey:De.typeforce.maybe(De.isPoint),signature:De.typeforce.maybe(ho.isCanonicalScriptSignature),witness:De.typeforce.maybe(De.typeforce.arrayOf(De.typeforce.Buffer))},e);const r=Rr.value(()=>{const s=Xs.bech32.decode(e.address),o=s.words.shift(),a=Xs.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||x6.bitcoin,i={name:"p2wpkh",network:n};if(Rr.prop(i,"address",()=>{if(!i.hash)return;const s=Xs.bech32.toWords(i.hash);return s.unshift(0),Xs.bech32.encode(n.bech32,s)}),Rr.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return Qa.hash160(e.pubkey||i.pubkey)}),Rr.prop(i,"output",()=>{if(i.hash)return ho.compile([Jd.OP_0,i.hash])}),Rr.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Rr.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Rr.prop(i,"input",()=>{if(i.witness)return E6}),Rr.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let s=Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==Jd.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(s.length>0&&!s.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");s=e.output.slice(2)}if(e.pubkey){const o=Qa.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,De.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(!ho.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,De.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const o=Qa.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}ia.p2wpkh=A6;var sa={};Object.defineProperty(sa,"__esModule",{value:!0});sa.p2wsh=void 0;const Qd=Gr,S6=nt,cr=vt(),_e=it,or=bt,Js=wr,el=cr.OPS,ec=Buffer.alloc(0);function Qs(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,_e.isPoint)(e))}function T6(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,_e.typeforce)({network:_e.typeforce.maybe(_e.typeforce.Object),address:_e.typeforce.maybe(_e.typeforce.String),hash:_e.typeforce.maybe(_e.typeforce.BufferN(32)),output:_e.typeforce.maybe(_e.typeforce.BufferN(34)),redeem:_e.typeforce.maybe({input:_e.typeforce.maybe(_e.typeforce.Buffer),network:_e.typeforce.maybe(_e.typeforce.Object),output:_e.typeforce.maybe(_e.typeforce.Buffer),witness:_e.typeforce.maybe(_e.typeforce.arrayOf(_e.typeforce.Buffer))}),input:_e.typeforce.maybe(_e.typeforce.BufferN(0)),witness:_e.typeforce.maybe(_e.typeforce.arrayOf(_e.typeforce.Buffer))},e);const r=or.value(()=>{const o=Js.bech32.decode(e.address),a=o.words.shift(),c=Js.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=or.value(()=>cr.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||S6.bitcoin);const s={network:i};if(or.prop(s,"address",()=>{if(!s.hash)return;const o=Js.bech32.toWords(s.hash);return o.unshift(0),Js.bech32.encode(i.bech32,o)}),or.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return Qd.sha256(s.redeem.output)}),or.prop(s,"output",()=>{if(s.hash)return cr.compile([el.OP_0,s.hash])}),or.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:ec,witness:e.witness.slice(0,-1)}}),or.prop(s,"input",()=>{if(s.witness)return ec}),or.prop(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=cr.toStack(n());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=ec,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),or.prop(s,"name",()=>{const o=["p2wsh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&o.push(s.redeem.name),o.join("-")}),t.validate){let o=Buffer.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==el.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const a=cr.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(cr.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=Qd.sha256(e.redeem.output);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch");o=c}if(e.redeem.input&&!cr.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,_e.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Qs)||e.redeem.output&&(cr.decompile(e.redeem.output)||[]).some(Qs))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(Qs)||(cr.decompile(a)||[]).some(Qs))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}sa.p2wsh=T6;var Ti={},bn={};Object.defineProperty(bn,"__esModule",{value:!0});bn.getEccLib=bn.initEccLib=void 0;const Mi={};function P6(e,t){e?e!==Mi.eccLib&&(t!=null&&t.DANGER_DO_NOT_VERIFY_ECCLIB||I6(e),Mi.eccLib=e):Mi.eccLib=e}bn.initEccLib=P6;function B6(){if(!Mi.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Mi.eccLib}bn.getEccLib=B6;const ar=e=>Buffer.from(e,"hex");function I6(e){Et(typeof e.isXOnlyPoint=="function"),Et(e.isXOnlyPoint(ar("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Et(e.isXOnlyPoint(ar("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Et(e.isXOnlyPoint(ar("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Et(e.isXOnlyPoint(ar("0000000000000000000000000000000000000000000000000000000000000001"))),Et(!e.isXOnlyPoint(ar("0000000000000000000000000000000000000000000000000000000000000000"))),Et(!e.isXOnlyPoint(ar("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Et(typeof e.xOnlyPointAddTweak=="function"),k6.forEach(t=>{const r=e.xOnlyPointAddTweak(ar(t.pubkey),ar(t.tweak));t.result===null?Et(r===null):(Et(r!==null),Et(r.parity===t.parity),Et(Buffer.from(r.xOnlyPubkey).equals(ar(t.result))))})}function Et(e){if(!e)throw new Error("ecc library invalid")}const k6=[{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 vf={};(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=Ar,r=bn,n=Gr,i=Ye,s=it;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=b=>"left"in b&&"right"in b;function a(b,m){if(b.length<33)throw new TypeError(`The control-block length is too small. Got ${b.length}, expected min 33.`);const _=(b.length-33)/32;let E=m;for(let x=0;x<_;x++){const v=b.slice(33+32*x,65+32*x);E.compare(v)<0?E=p(E,v):E=p(v,E)}return E}e.rootHashFromPath=a;function c(b){if((0,s.isTapleaf)(b))return{hash:f(b)};const m=[c(b[0]),c(b[1])];m.sort((x,v)=>x.hash.compare(v.hash));const[_,E]=m;return{hash:p(_.hash,E.hash),left:_,right:E}}e.toHashTree=c;function u(b,m){if(o(b)){const _=u(b.left,m);if(_!==void 0)return[..._,b.right.hash];const E=u(b.right,m);if(E!==void 0)return[...E,b.left.hash]}else if(b.hash.equals(m))return[]}e.findScriptPath=u;function f(b){const m=b.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([m]),w(b.output)]))}e.tapleafHash=f;function d(b,m){return n.taggedHash("TapTweak",t.Buffer.concat(m?[b,m]:[b]))}e.tapTweakHash=d;function y(b,m){if(!t.Buffer.isBuffer(b)||b.length!==32||m&&m.length!==32)return null;const _=d(b,m),E=(0,r.getEccLib)().xOnlyPointAddTweak(b,_);return!E||E.xOnlyPubkey===null?null:{parity:E.parity,x:t.Buffer.from(E.xOnlyPubkey)}}e.tweakKey=y;function p(b,m){return n.taggedHash("TapBranch",t.Buffer.concat([b,m]))}function w(b){const m=i.varuint.encodingLength(b.length),_=t.Buffer.allocUnsafe(m);return i.varuint.encode(b.length,_),t.Buffer.concat([_,b])}})(vf);var at={},tl;function C6(){if(tl)return at;tl=1,Object.defineProperty(at,"__esModule",{value:!0}),at.toOutputScript=at.fromOutputScript=at.toBech32=at.toBase58Check=at.fromBech32=at.fromBase58Check=void 0;const e=nt,t=_f(),r=vt(),n=it,i=wr,s=gf,o=40,a=2,c=16,u=2,f=80,d="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(x,v){const B=x.slice(2);if(B.length<a||B.length>o)throw new TypeError("Invalid program length for segwit address");const S=x[0]-f;if(S<u||S>c)throw new TypeError("Invalid version for segwit address");if(x[1]!==B.length)throw new TypeError("Invalid script for segwit address");return console.warn(d),m(B,S,v.bech32)}function p(x){const v=Buffer.from(s.decode(x));if(v.length<21)throw new TypeError(x+" is too short");if(v.length>21)throw new TypeError(x+" is too long");const B=v.readUInt8(0),S=v.slice(1);return{version:B,hash:S}}at.fromBase58Check=p;function w(x){let v,B;try{v=i.bech32.decode(x)}catch{}if(v){if(B=v.words[0],B!==0)throw new TypeError(x+" uses wrong encoding")}else if(v=i.bech32m.decode(x),B=v.words[0],B===0)throw new TypeError(x+" uses wrong encoding");const S=i.bech32.fromWords(v.words.slice(1));return{version:B,prefix:v.prefix,data:Buffer.from(S)}}at.fromBech32=w;function b(x,v){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const B=Buffer.allocUnsafe(21);return B.writeUInt8(v,0),x.copy(B,1),s.encode(B)}at.toBase58Check=b;function m(x,v,B){const S=i.bech32.toWords(x);return S.unshift(v),v===0?i.bech32.encode(B,S):i.bech32m.encode(B,S)}at.toBech32=m;function _(x,v){v=v||e.bitcoin;try{return t.p2pkh({output:x,network:v}).address}catch{}try{return t.p2sh({output:x,network:v}).address}catch{}try{return t.p2wpkh({output:x,network:v}).address}catch{}try{return t.p2wsh({output:x,network:v}).address}catch{}try{return t.p2tr({output:x,network:v}).address}catch{}try{return y(x,v)}catch{}throw new Error(r.toASM(x)+" has no matching Address")}at.fromOutputScript=_;function E(x,v){v=v||e.bitcoin;let B,S;try{B=p(x)}catch{}if(B){if(B.version===v.pubKeyHash)return t.p2pkh({hash:B.hash}).output;if(B.version===v.scriptHash)return t.p2sh({hash:B.hash}).output}else{try{S=w(x)}catch{}if(S){if(S.prefix!==v.bech32)throw new Error(x+" has an invalid prefix");if(S.version===0){if(S.data.length===20)return t.p2wpkh({hash:S.data}).output;if(S.data.length===32)return t.p2wsh({hash:S.data}).output}else if(S.version===1){if(S.data.length===32)return t.p2tr({pubkey:S.data}).output}else if(S.version>=u&&S.version<=c&&S.data.length>=a&&S.data.length<=o)return console.warn(d),r.compile([S.version+f,S.data])}}throw new Error(x+" has no matching Script")}return at.toOutputScript=E,at}var rl;function O6(){if(rl)return Ti;rl=1,Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.p2tr=void 0;const e=Ar,t=nt,r=vt(),n=it,i=bn,s=vf,o=bt,a=wr,c=C6(),u=r.OPS,f=1,d=80;function y(p,w){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");w=Object.assign({validate:!0},w||{}),(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 b=o.value(()=>(0,c.fromBech32)(p.address)),m=o.value(()=>{if(!(!p.witness||!p.witness.length))return p.witness.length>=2&&p.witness[p.witness.length-1][0]===d?p.witness.slice(0,-1):p.witness.slice()}),_=o.value(()=>{if(p.scriptTree)return(0,s.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),E=p.network||t.bitcoin,x={name:"p2tr",network:E};if(o.prop(x,"address",()=>{if(!x.pubkey)return;const v=a.bech32m.toWords(x.pubkey);return v.unshift(f),a.bech32m.encode(E.bech32,v)}),o.prop(x,"hash",()=>{const v=_();if(v)return v.hash;const B=m();if(B&&B.length>1){const S=B[B.length-1],C=S[0]&n.TAPLEAF_VERSION_MASK,N=B[B.length-2],I=(0,s.tapleafHash)({output:N,version:C});return(0,s.rootHashFromPath)(S,I)}return null}),o.prop(x,"output",()=>{if(x.pubkey)return r.compile([u.OP_1,x.pubkey])}),o.prop(x,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(x,"redeem",()=>{const v=m();if(!(!v||v.length<2))return{output:v[v.length-2],witness:v.slice(0,-2),redeemVersion:v[v.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(x,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return b().data;if(x.internalPubkey){const v=(0,s.tweakKey)(x.internalPubkey,x.hash);if(v)return v.x}}),o.prop(x,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const v=m();if(v&&v.length>1)return v[v.length-1].slice(1,33)}),o.prop(x,"signature",()=>{if(p.signature)return p.signature;const v=m();if(!(!v||v.length!==1))return v[0]}),o.prop(x,"witness",()=>{if(p.witness)return p.witness;const v=_();if(v&&p.redeem&&p.redeem.output&&p.internalPubkey){const B=(0,s.tapleafHash)({output:p.redeem.output,version:x.redeemVersion}),S=(0,s.findScriptPath)(v,B);if(!S)return;const C=(0,s.tweakKey)(p.internalPubkey,v.hash);if(!C)return;const N=e.Buffer.concat([e.Buffer.from([x.redeemVersion|C.parity]),p.internalPubkey].concat(S));return[p.redeem.output,N]}if(p.signature)return[p.signature]}),w.validate){let v=e.Buffer.from([]);if(p.address){if(E&&E.bech32!==b().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(b().version!==f)throw new TypeError("Invalid address version");if(b().data.length!==32)throw new TypeError("Invalid address data");v=b().data}if(p.pubkey){if(v.length>0&&!v.equals(p.pubkey))throw new TypeError("Pubkey mismatch");v=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(v.length>0&&!v.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");v=p.output.slice(2)}if(p.internalPubkey){const C=(0,s.tweakKey)(p.internalPubkey,x.hash);if(v.length>0&&!v.equals(C.x))throw new TypeError("Pubkey mismatch");v=C.x}if(v&&v.length&&!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid pubkey for p2tr");const B=_();if(p.hash&&B&&!p.hash.equals(B.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&B){const C=(0,s.tapleafHash)({output:p.redeem.output,version:x.redeemVersion});if(!(0,s.findScriptPath)(B,C))throw new TypeError("Redeem script not in tree")}const S=m();if(p.redeem&&x.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==x.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(x.redeem.output&&!p.redeem.output.equals(x.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&x.redeem.witness&&!(0,n.stacksEqual)(p.redeem.witness,x.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(S&&S.length)if(S.length===1){if(p.signature&&!p.signature.equals(S[0]))throw new TypeError("Signature mismatch")}else{const C=S[S.length-1];if(C.length<33)throw new TypeError(`The control-block length is too small. Got ${C.length}, expected min 33.`);if((C.length-33)%32!==0)throw new TypeError(`The control-block length of ${C.length} is incorrect!`);const N=(C.length-33)/32;if(N>128)throw new TypeError(`The script path is too long. Got ${N}, expected max 128.`);const I=C.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(I))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(I))throw new TypeError("Invalid internalPubkey for p2tr witness");const G=C[0]&n.TAPLEAF_VERSION_MASK,k=S[S.length-2],U=(0,s.tapleafHash)({output:k,version:G}),z=(0,s.rootHashFromPath)(C,U),F=(0,s.tweakKey)(I,z);if(!F)throw new TypeError("Invalid outputKey for p2tr witness");if(v.length&&!v.equals(F.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(F.parity!==(C[0]&1))throw new Error("Incorrect parity")}}return Object.assign(x,p)}return Ti.p2tr=y,Ti}var nl;function _f(){return nl||(nl=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=Qo;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=ea;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=ta;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=ra;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=na;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=ia;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=sa;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=O6();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Za)),Za}Object.defineProperty(ve,"__esModule",{value:!0});ve.signatureBlocksAction=ve.checkInputForSig=ve.pubkeyInScript=ve.pubkeyPositionInScript=ve.witnessStackToScriptWitness=ve.isP2TR=ve.isP2SHScript=ve.isP2WSHScript=ve.isP2WPKH=ve.isP2PKH=ve.isP2PK=ve.isP2MS=void 0;const il=$s,Hi=vt(),eo=Ns,R6=Gr,xn=_f();function En(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}ve.isP2MS=En(xn.p2ms);ve.isP2PK=En(xn.p2pk);ve.isP2PKH=En(xn.p2pkh);ve.isP2WPKH=En(xn.p2wpkh);ve.isP2WSHScript=En(xn.p2wsh);ve.isP2SHScript=En(xn.p2sh);ve.isP2TR=En(xn.p2tr);function N6(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=il.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),il.encode(o,t,a)}function i(o){n(o.length),r(o)}function s(o){n(o.length),o.forEach(i)}return s(e),t}ve.witnessStackToScriptWitness=N6;function kp(e,t){const r=(0,R6.hash160)(e),n=e.slice(1,33),i=Hi.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(s=>typeof s=="number"?!1:s.equals(e)||s.equals(r)||s.equals(n))}ve.pubkeyPositionInScript=kp;function $6(e,t){return kp(e,t)!==-1}ve.pubkeyInScript=$6;function L6(e,t){return F6(e).some(n=>Cp(n,Hi.signature.decode,t))}ve.checkInputForSig=L6;function Cp(e,t,r){const{hashType:n}=t(e),i=[];switch(n&eo.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case eo.Transaction.SIGHASH_ALL:break;case eo.Transaction.SIGHASH_SINGLE:case eo.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}ve.signatureBlocksAction=Cp;function F6(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=U6(e)}else t=e.partialSig;return t.map(r=>r.signature)}function U6(e){const t=e.finalScriptSig?Hi.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?Hi.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&Hi.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(Ie,"__esModule",{value:!0});Ie.checkTaprootInputForSigs=Ie.tapTreeFromList=Ie.tapTreeToList=Ie.tweakInternalPubKey=Ie.checkTaprootOutputFields=Ie.checkTaprootInputFields=Ie.isTaprootOutput=Ie.isTaprootInput=po=Ie.serializeTaprootSignature=Ie.tapScriptFinalizer=Ie.toXOnly=void 0;const xf=it,M6=Ns,oa=ve,jr=vf,H6=_f(),D6=ve,j6=e=>e.length===32?e:e.slice(1,33);Ie.toXOnly=j6;function z6(e,t,r){const n=ax(t,e,r);try{const s=sx(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,oa.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}Ie.tapScriptFinalizer=z6;function q6(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var po=Ie.serializeTaprootSignature=q6;function yo(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,oa.isP2TR)(e.witnessUtxo.script))}Ie.isTaprootInput=yo;function mo(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,oa.isP2TR)(t))}Ie.isTaprootOutput=mo;function G6(e,t,r){rx(e,t,r),ix(e,t,r)}Ie.checkTaprootInputFields=G6;function V6(e,t,r){nx(e,t,r),W6(e,t)}Ie.checkTaprootOutputFields=V6;function W6(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,s=K6(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function K6(e,t){const r=t&&Op(t.leaves),{output:n}=(0,H6.p2tr)({internalPubkey:e,scriptTree:r});return n}function Y6(e,t){const r=t.tapInternalKey,n=r&&(0,jr.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}Ie.tweakInternalPubKey=Y6;function Z6(e){if(!(0,xf.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return iu(e)}Ie.tapTreeToList=Z6;function Op(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:tx(e)}Ie.tapTreeFromList=Op;function X6(e,t){return Q6(e).some(n=>(0,D6.signatureBlocksAction)(n,J6,t))}Ie.checkTaprootInputForSigs=X6;function J6(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||M6.Transaction.SIGHASH_DEFAULT}}function Q6(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=ex(e.finalScriptWitness);r&&t.push(r)}return t}function ex(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function iu(e,t=[],r=0){if(r>jr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,xf.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||jr.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&iu(e[0],t,r+1),e[1]&&iu(e[1],t,r+1),t):[]}function tx(e){let t;for(const r of e)if(t=su(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function su(e,t,r=0){if(r>jr.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,xf.isTapleaf)(t))return;const n=su(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=su(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function rx(e,t,r){const n=yo(e)&&Vn(t),i=Vn(e)&&yo(t),s=e===t&&yo(t)&&Vn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function nx(e,t,r){const n=mo(e)&&Vn(t),i=Vn(e)&&mo(t),s=e===t&&mo(t)&&Vn(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function ix(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>tc(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>tc(s,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>tc(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function tc(e,t){if(!t)return!0;const r=(0,jr.tapleafHash)({output:e.script,version:e.leafVersion});return(0,jr.rootHashFromPath)(e.controlBlock,r).equals(t)}function sx(e,t){const r=(0,jr.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>ox(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function ox(e,t){return Object.assign({positionInScript:(0,oa.pubkeyPositionInScript)(t.pubkey,e)},t)}function ax(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((i,s)=>i.controlBlock.length-s.controlBlock.length).find(i=>cx(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function cx(e,t,r){const n=(0,jr.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function Vn(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const We={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"},to=192;ye.initEccLib(an);class Di{constructor(t,r,n,i,s,o,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=s,this.expiry=o,this.signer=t,this.network=a,this.internalPubkey=v_(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,Zr(n.length===64,We.secretHashLenMismatch),Zr(i.length===64||i.length===66,`initiator ${We.pubkeyLenMismatch}`),Zr(s.length===64||s.length===66,`redeemer ${We.pubkeyLenMismatch}`),Zr(o>0,We.zeroOrNegativeExpiry);const c=await t.getNetwork();return new Di(t,r,n,eu(s).toString("hex"),eu(i).toString("hex"),o,c,a)}address(){const{address:t}=ye.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(We.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new ye.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const u=await s.getTransaction(c);for(let f=0;f<u.vout.length;f++){const d=u.vout[f];d.scriptpubkey_address===i&&o.push({txid:u.txid,vout:f,value:d.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,u)=>c+u.value,0);if(a===0)throw new Error(`${i} ${We.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);return r??(r=await s.suggestFee(i,a,Kn.Urgency.MEDIUM)),n.addOutput(ye.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async _tempBuildRawTx(t,r){const n=new ye.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const u=await s.getTransaction(c);for(let f=0;f<u.vout.length;f++){const d=u.vout[f];d.scriptpubkey_address===i&&o.push({txid:u.txid,vout:f,value:d.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,u)=>c+u.value,0);if(a===0)throw new Error(`${i} ${We.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);if(n.addOutput(ye.address.toOutputScript(t,this.network),a),r){const c=await s.getFeeRates(),u=Math.ceil(c.hourFee*r),f=a-u;n.outs[0].value=f}return{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return ye.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Kn.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateRedeemSACP(t,r,n){const{tx:i,usedUtxos:s}=await this._buildRawTx(r,n),o=this.getOutputScript(),a=ye.Transaction.SIGHASH_SINGLE|ye.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),u=s.map(d=>d.value),f=Rn(o,s.length);for(let d=0;d<i.ins.length;d++){const y=i.hashForWitnessV1(d,f,u,a,c),p=await this.signer.signSchnorr(y);i.setWitness(d,[po(p,a),Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return i.toHex()}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),s=this.getOutputScript(),o=ye.Transaction.SIGHASH_SINGLE|ye.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(f=>f.value),u=Rn(s,i.length);for(let f=0;f<n.ins.length;f++){const d=n.hashForWitnessV1(f,u,c,o,a),y=await this.signer.signSchnorr(d);n.setWitness(f,[po(y,o),po(y,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){Zr(t.length>0,We.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const d of i)if(!t.find(y=>y.utxo===d.txid))throw new Error(We.counterPartySigNotFound(d.txid));const s=this.getOutputScript(),o=ye.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(d=>d.value),u=Rn(s,i.length);for(let d=0;d<n.ins.length;d++){const y=n.hashForWitnessV1(d,u,c,o,a);if(!an.verifySchnorr(y,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[d].sig,"hex")))throw new Error(We.invalidCounterpartySigForUTXO(t[d].utxo));const p=await this.signer.signSchnorr(y),w=Buffer.from(n.ins[d].hash).reverse().toString("hex"),b=t.find(m=>m.utxo===w);if(!b)throw new Error(We.counterPartySigNotFound(w));n.setWitness(d,[Buffer.from(b.sig,"hex"),p,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){Zr(ye.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,We.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(y=>y.value),c=Rn(this.getOutputScript(),s.length),u=ye.Transaction.SIGHASH_DEFAULT;for(let y=0;y<i.ins.length;y++){const p=i.hashForWitnessV1(y,c,a,u,o),w=await this.signer.signSchnorr(p);i.setWitness(y,[w,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,o),w=await this.signer.signSchnorr(p);f.setWitness(y,[w,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(f.toHex())}async getRedeemHex(t,r){Zr(ye.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,We.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(d=>d.value),c=Rn(this.getOutputScript(),s.length),u=ye.Transaction.SIGHASH_DEFAULT;for(let d=0;d<i.ins.length;d++){const y=i.hashForWitnessV1(d,c,a,u,o),p=await this.signer.signSchnorr(y);i.setWitness(d,[p,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:f}=await this._tempBuildRawTx(n,i.virtualSize());for(let d=0;d<f.ins.length;d++){const y=f.hashForWitnessV1(d,c,a,u,o),p=await this.signer.signSchnorr(y);f.setWitness(d,[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),[s,o]=await this.canRefund(i);if(!s)throw new Error(We.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(y=>y.value),u=Rn(this.getOutputScript(),i.length),f=ye.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),w=await this.signer.signSchnorr(p);n.setWitness(y,[w,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let s=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?s=i.status.block_height+this.expiry-n+1:i.status.confirmed||(s=this.expiry+1),s>0)return[!1,s]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(We.invalidLeaf)}const n=ye.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:to}});if(!n.witness)throw new Error(We.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()),ye.crypto.taggedHash("TapLeaf",o_(r))}refundLeaf(){return ye.script.fromASM(`
|
|
54
|
+
${ye.script.number.encode(this.expiry).toString("hex")}
|
|
55
|
+
OP_CHECKSEQUENCEVERIFY
|
|
56
|
+
OP_DROP
|
|
57
|
+
${this.initiatorPubkey}
|
|
58
|
+
OP_CHECKSIG
|
|
59
|
+
`.trim().replace(/\s+/g," "))}redeemLeaf(){return ye.script.fromASM(`
|
|
60
|
+
OP_SHA256
|
|
61
|
+
${this.secretHash}
|
|
62
|
+
OP_EQUALVERIFY
|
|
63
|
+
${this.redeemerPubkey}
|
|
64
|
+
OP_CHECKSIG
|
|
65
|
+
`.trim().replace(/\s+/g," "))}instantRefundLeaf(){return ye.script.fromASM(`
|
|
66
|
+
${this.initiatorPubkey}
|
|
67
|
+
OP_CHECKSIG
|
|
68
|
+
${this.redeemerPubkey}
|
|
69
|
+
OP_CHECKSIGADD
|
|
70
|
+
OP_2
|
|
71
|
+
OP_NUMEQUAL
|
|
72
|
+
`.trim().replace(/\s+/g," "))}leaves(){return[{version:to,output:this.redeemLeaf()},[{version:to,output:this.refundLeaf()},{version:to,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const s=c_(i,n);return[ye.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(We.invalidLeaf)}}}function Rn(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class ux{constructor(){this.cache={}}set(t,r,n,i){const s={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=s}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class fx{constructor(){this.cache={}}set(t,r){this.cache[t]=r}get(t){return this.cache[t]||null}}class Rp{constructor(t,r){this.url=new Z.Url(t).endpoint("blocknumbers").endpoint(r)}async fetchBlockNumbers(){try{const t=await lr.get(this.url);return de(t)}catch(t){return K("Failed to fetch block numbers",t)}}}class Np{constructor(t){this.quoteUrl=new Z.Url(t)}async getQuoteFromAssets(t,r,n,i=!1,s){const o=tu(t.chain,t.atomicSwapAddress,r.chain,r.atomicSwapAddress);return this.getQuote(o,n,i,s)}async getQuote(t,r,n=!1,i){try{const s={order_pair:t,amount:r.toString(),exact_out:n.toString(),...(i==null?void 0:i.affiliateFee)!==void 0&&{affiliate_fee:i.affiliateFee.toString()}},o=this.quoteUrl.endpoint("/").addSearchParams(s),a=await lr.get(o,{retryCount:0,...i==null?void 0:i.request});return a.error?K(a.error):a.result?de(a.result):K("GetQuote: Unexpected error, result is undefined")}catch(s){return K("GetQuote:",String(s))}}async getAttestedQuote(t){try{const r=await lr.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?K(r.error):r.result?de(r.result):K("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),K("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await lr.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return K(t.error);if(!t.result)return K("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=tu(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 de(r)}catch(t){return K("GetStrategies:",String(t))}}}var $p={},ni={},ii={};Object.defineProperty(ii,"__esModule",{value:!0});ii.testnet=ii.bitcoin=void 0;ii.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
73
|
+
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};ii.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
74
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Lp={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=wp,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})(Lp);var ou={exports:{}},au={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Ar,n=r.Buffer;function i(o,a){for(var c in o)a[c]=o[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=s);function s(o,a,c){return n(o,a,c)}s.prototype=Object.create(n.prototype),i(n,s),s.from=function(o,a,c){if(typeof o=="number")throw new TypeError("Argument must not be a number");return n(o,a,c)},s.alloc=function(o,a,c){if(typeof o!="number")throw new TypeError("Argument must be a number");var u=n(o);return a!==void 0?typeof c=="string"?u.fill(a,c):u.fill(a):u.fill(0),u},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(o)}})(au,au.exports);var lt=au.exports,rc=65536,dx=4294967295;function lx(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
75
|
+
Use Chrome, Firefox or Internet Explorer 11`)}var hx=lt.Buffer,So=Dr.crypto||Dr.msCrypto;So&&So.getRandomValues?ou.exports=px:ou.exports=lx;function px(e,t){if(e>dx)throw new RangeError("requested too many random bytes");var r=hx.allocUnsafe(e);if(e>0)if(e>rc)for(var n=0;n<e;n+=rc)So.getRandomValues(r.slice(n,n+rc));else So.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var yx=ou.exports,cu={exports:{}};typeof Object.create=="function"?cu.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:cu.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 Je=cu.exports,uu={exports:{}},Ef={exports:{}},Wn=typeof Reflect=="object"?Reflect:null,sl=Wn&&typeof Wn.apply=="function"?Wn.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},bo;Wn&&typeof Wn.ownKeys=="function"?bo=Wn.ownKeys:Object.getOwnPropertySymbols?bo=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:bo=function(t){return Object.getOwnPropertyNames(t)};function mx(e){console&&console.warn&&console.warn(e)}var Fp=Number.isNaN||function(t){return t!==t};function me(){me.init.call(this)}Ef.exports=me;Ef.exports.once=vx;me.EventEmitter=me;me.prototype._events=void 0;me.prototype._eventsCount=0;me.prototype._maxListeners=void 0;var ol=10;function aa(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(me,"defaultMaxListeners",{enumerable:!0,get:function(){return ol},set:function(e){if(typeof e!="number"||e<0||Fp(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ol=e}});me.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};me.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Fp(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 Up(e){return e._maxListeners===void 0?me.defaultMaxListeners:e._maxListeners}me.prototype.getMaxListeners=function(){return Up(this)};me.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=s[t];if(c===void 0)return!1;if(typeof c=="function")sl(c,this,r);else for(var u=c.length,f=zp(c,u),n=0;n<u;++n)sl(f[n],this,r);return!0};function Mp(e,t,r,n){var i,s,o;if(aa(r),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),o=s[t]),o===void 0)o=s[t]=r,++e._eventsCount;else if(typeof o=="function"?o=s[t]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),i=Up(e),i>0&&o.length>i&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=o.length,mx(a)}return e}me.prototype.addListener=function(t,r){return Mp(this,t,r,!1)};me.prototype.on=me.prototype.addListener;me.prototype.prependListener=function(t,r){return Mp(this,t,r,!0)};function bx(){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 Hp(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=bx.bind(n);return i.listener=r,n.wrapFn=i,i}me.prototype.once=function(t,r){return aa(r),this.on(t,Hp(this,t,r)),this};me.prototype.prependOnceListener=function(t,r){return aa(r),this.prependListener(t,Hp(this,t,r)),this};me.prototype.removeListener=function(t,r){var n,i,s,o,a;if(aa(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(s=-1,o=n.length-1;o>=0;o--)if(n[o]===r||n[o].listener===r){a=n[o].listener,s=o;break}if(s<0)return this;s===0?n.shift():gx(n,s),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};me.prototype.off=me.prototype.removeListener;me.prototype.removeAllListeners=function(t){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var s=Object.keys(n),o;for(i=0;i<s.length;++i)o=s[i],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(t,r[i]);return this};function Dp(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?wx(i):zp(i,i.length)}me.prototype.listeners=function(t){return Dp(this,t,!0)};me.prototype.rawListeners=function(t){return Dp(this,t,!1)};me.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):jp.call(e,t)};me.prototype.listenerCount=jp;function jp(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}me.prototype.eventNames=function(){return this._eventsCount>0?bo(this._events):[]};function zp(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function gx(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function wx(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function vx(e,t){return new Promise(function(r,n){function i(o){e.removeListener(t,s),n(o)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}qp(e,t,s,{once:!0}),t!=="error"&&_x(e,i,{once:!0})})}function _x(e,t,r){typeof e.on=="function"&&qp(e,"error",t,r)}function qp(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function i(s){n.once&&e.removeEventListener(t,i),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var Gp=Ef.exports,Vp=Gp.EventEmitter;const xx={},Ex=Object.freeze(Object.defineProperty({__proto__:null,default:xx},Symbol.toStringTag,{value:"Module"})),Af=Dw(Ex);var nc,al;function Ax(){if(al)return nc;al=1;function e(w,b){var m=Object.keys(w);if(Object.getOwnPropertySymbols){var _=Object.getOwnPropertySymbols(w);b&&(_=_.filter(function(E){return Object.getOwnPropertyDescriptor(w,E).enumerable})),m.push.apply(m,_)}return m}function t(w){for(var b=1;b<arguments.length;b++){var m=arguments[b]!=null?arguments[b]:{};b%2?e(Object(m),!0).forEach(function(_){r(w,_,m[_])}):Object.getOwnPropertyDescriptors?Object.defineProperties(w,Object.getOwnPropertyDescriptors(m)):e(Object(m)).forEach(function(_){Object.defineProperty(w,_,Object.getOwnPropertyDescriptor(m,_))})}return w}function r(w,b,m){return b=o(b),b in w?Object.defineProperty(w,b,{value:m,enumerable:!0,configurable:!0,writable:!0}):w[b]=m,w}function n(w,b){if(!(w instanceof b))throw new TypeError("Cannot call a class as a function")}function i(w,b){for(var m=0;m<b.length;m++){var _=b[m];_.enumerable=_.enumerable||!1,_.configurable=!0,"value"in _&&(_.writable=!0),Object.defineProperty(w,o(_.key),_)}}function s(w,b,m){return b&&i(w.prototype,b),Object.defineProperty(w,"prototype",{writable:!1}),w}function o(w){var b=a(w,"string");return typeof b=="symbol"?b:String(b)}function a(w,b){if(typeof w!="object"||w===null)return w;var m=w[Symbol.toPrimitive];if(m!==void 0){var _=m.call(w,b);if(typeof _!="object")return _;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(w)}var c=Ar,u=c.Buffer,f=Af,d=f.inspect,y=d&&d.custom||"inspect";function p(w,b,m){u.prototype.copy.call(w,b,m)}return nc=function(){function w(){n(this,w),this.head=null,this.tail=null,this.length=0}return s(w,[{key:"push",value:function(m){var _={data:m,next:null};this.length>0?this.tail.next=_:this.head=_,this.tail=_,++this.length}},{key:"unshift",value:function(m){var _={data:m,next:this.head};this.length===0&&(this.tail=_),this.head=_,++this.length}},{key:"shift",value:function(){if(this.length!==0){var m=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,m}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(m){if(this.length===0)return"";for(var _=this.head,E=""+_.data;_=_.next;)E+=m+_.data;return E}},{key:"concat",value:function(m){if(this.length===0)return u.alloc(0);for(var _=u.allocUnsafe(m>>>0),E=this.head,x=0;E;)p(E.data,_,x),x+=E.data.length,E=E.next;return _}},{key:"consume",value:function(m,_){var E;return m<this.head.data.length?(E=this.head.data.slice(0,m),this.head.data=this.head.data.slice(m)):m===this.head.data.length?E=this.shift():E=_?this._getString(m):this._getBuffer(m),E}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(m){var _=this.head,E=1,x=_.data;for(m-=x.length;_=_.next;){var v=_.data,B=m>v.length?v.length:m;if(B===v.length?x+=v:x+=v.slice(0,m),m-=B,m===0){B===v.length?(++E,_.next?this.head=_.next:this.head=this.tail=null):(this.head=_,_.data=v.slice(B));break}++E}return this.length-=E,x}},{key:"_getBuffer",value:function(m){var _=u.allocUnsafe(m),E=this.head,x=1;for(E.data.copy(_),m-=E.data.length;E=E.next;){var v=E.data,B=m>v.length?v.length:m;if(v.copy(_,_.length-m,0,B),m-=B,m===0){B===v.length?(++x,E.next?this.head=E.next:this.head=this.tail=null):(this.head=E,E.data=v.slice(B));break}++x}return this.length-=x,_}},{key:y,value:function(m,_){return d(this,t(t({},_),{},{depth:0,customInspect:!1}))}}]),w}(),nc}function Sx(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(fu,this,e)):process.nextTick(fu,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted?process.nextTick(go,r):(r._writableState.errorEmitted=!0,process.nextTick(cl,r,s)):process.nextTick(cl,r,s):t?(process.nextTick(go,r),t(s)):process.nextTick(go,r)}),this)}function cl(e,t){fu(e,t),go(e)}function go(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Tx(){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 fu(e,t){e.emit("error",t)}function Px(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var Wp={destroy:Sx,undestroy:Tx,errorOrDestroy:Px},An={};function Bx(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Kp={};function It(e,t,r){r||(r=Error);function n(s,o,a){return typeof t=="string"?t:t(s,o,a)}var i=function(s){Bx(o,s);function o(a,c,u){return s.call(this,n(a,c,u))||this}return o}(r);i.prototype.name=r.name,i.prototype.code=e,Kp[e]=i}function ul(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 Ix(e,t,r){return e.substr(0,t.length)===t}function kx(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Cx(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}It("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);It("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&Ix(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(kx(e," argument"))i="The ".concat(e," ").concat(n," ").concat(ul(t,"type"));else{var s=Cx(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(ul(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);It("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");It("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});It("ERR_STREAM_PREMATURE_CLOSE","Premature close");It("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});It("ERR_MULTIPLE_CALLBACK","Callback called multiple times");It("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");It("ERR_STREAM_WRITE_AFTER_END","write after end");It("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);It("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);It("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");An.codes=Kp;var Ox=An.codes.ERR_INVALID_OPT_VALUE;function Rx(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function Nx(e,t,r,n){var i=Rx(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var s=n?r:"highWaterMark";throw new Ox(s,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var Yp={getHighWaterMark:Nx},$x=Lx;function Lx(e,t){if(ic("noDeprecation"))return e;var r=!1;function n(){if(!r){if(ic("throwDeprecation"))throw new Error(t);ic("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function ic(e){try{if(!Dr.localStorage)return!1}catch{return!1}var t=Dr.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var sc,fl;function Zp(){if(fl)return sc;fl=1,sc=N;function e(R){var $=this;this.next=null,this.entry=null,this.finish=function(){He($,R)}}var t;N.WritableState=S;var r={deprecate:$x},n=Vp,i=Ar.Buffer,s=(typeof Dr<"u"?Dr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(R){return i.from(R)}function a(R){return i.isBuffer(R)||R instanceof s}var c=Wp,u=Yp,f=u.getHighWaterMark,d=An.codes,y=d.ERR_INVALID_ARG_TYPE,p=d.ERR_METHOD_NOT_IMPLEMENTED,w=d.ERR_MULTIPLE_CALLBACK,b=d.ERR_STREAM_CANNOT_PIPE,m=d.ERR_STREAM_DESTROYED,_=d.ERR_STREAM_NULL_VALUES,E=d.ERR_STREAM_WRITE_AFTER_END,x=d.ERR_UNKNOWN_ENCODING,v=c.errorOrDestroy;Je(N,n);function B(){}function S(R,$,q){t=t||si(),R=R||{},typeof q!="boolean"&&(q=$ instanceof t),this.objectMode=!!R.objectMode,q&&(this.objectMode=this.objectMode||!!R.writableObjectMode),this.highWaterMark=f(this,R,"writableHighWaterMark",q),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var Q=R.decodeStrings===!1;this.decodeStrings=!Q,this.defaultEncoding=R.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(oe){V($,oe)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=R.emitClose!==!1,this.autoDestroy=!!R.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}S.prototype.getBuffer=function(){for(var $=this.bufferedRequest,q=[];$;)q.push($),$=$.next;return q},function(){try{Object.defineProperty(S.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var C;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(C=Function.prototype[Symbol.hasInstance],Object.defineProperty(N,Symbol.hasInstance,{value:function($){return C.call(this,$)?!0:this!==N?!1:$&&$._writableState instanceof S}})):C=function($){return $ instanceof this};function N(R){t=t||si();var $=this instanceof t;if(!$&&!C.call(N,this))return new N(R);this._writableState=new S(R,this,$),this.writable=!0,R&&(typeof R.write=="function"&&(this._write=R.write),typeof R.writev=="function"&&(this._writev=R.writev),typeof R.destroy=="function"&&(this._destroy=R.destroy),typeof R.final=="function"&&(this._final=R.final)),n.call(this)}N.prototype.pipe=function(){v(this,new b)};function I(R,$){var q=new E;v(R,q),process.nextTick($,q)}function G(R,$,q,Q){var oe;return q===null?oe=new _:typeof q!="string"&&!$.objectMode&&(oe=new y("chunk",["string","Buffer"],q)),oe?(v(R,oe),process.nextTick(Q,oe),!1):!0}N.prototype.write=function(R,$,q){var Q=this._writableState,oe=!1,T=!Q.objectMode&&a(R);return T&&!i.isBuffer(R)&&(R=o(R)),typeof $=="function"&&(q=$,$=null),T?$="buffer":$||($=Q.defaultEncoding),typeof q!="function"&&(q=B),Q.ending?I(this,q):(T||G(this,Q,R,q))&&(Q.pendingcb++,oe=U(this,Q,T,R,$,q)),oe},N.prototype.cork=function(){this._writableState.corked++},N.prototype.uncork=function(){var R=this._writableState;R.corked&&(R.corked--,!R.writing&&!R.corked&&!R.bufferProcessing&&R.bufferedRequest&&W(this,R))},N.prototype.setDefaultEncoding=function($){if(typeof $=="string"&&($=$.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf(($+"").toLowerCase())>-1))throw new x($);return this._writableState.defaultEncoding=$,this},Object.defineProperty(N.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function k(R,$,q){return!R.objectMode&&R.decodeStrings!==!1&&typeof $=="string"&&($=i.from($,q)),$}Object.defineProperty(N.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function U(R,$,q,Q,oe,T){if(!q){var P=k($,Q,oe);Q!==P&&(q=!0,oe="buffer",Q=P)}var j=$.objectMode?1:Q.length;$.length+=j;var Y=$.length<$.highWaterMark;if(Y||($.needDrain=!0),$.writing||$.corked){var he=$.lastBufferedRequest;$.lastBufferedRequest={chunk:Q,encoding:oe,isBuf:q,callback:T,next:null},he?he.next=$.lastBufferedRequest:$.bufferedRequest=$.lastBufferedRequest,$.bufferedRequestCount+=1}else z(R,$,!1,j,Q,oe,T);return Y}function z(R,$,q,Q,oe,T,P){$.writelen=Q,$.writecb=P,$.writing=!0,$.sync=!0,$.destroyed?$.onwrite(new m("write")):q?R._writev(oe,$.onwrite):R._write(oe,T,$.onwrite),$.sync=!1}function F(R,$,q,Q,oe){--$.pendingcb,q?(process.nextTick(oe,Q),process.nextTick(be,R,$),R._writableState.errorEmitted=!0,v(R,Q)):(oe(Q),R._writableState.errorEmitted=!0,v(R,Q),be(R,$))}function D(R){R.writing=!1,R.writecb=null,R.length-=R.writelen,R.writelen=0}function V(R,$){var q=R._writableState,Q=q.sync,oe=q.writecb;if(typeof oe!="function")throw new w;if(D(q),$)F(R,q,Q,$,oe);else{var T=se(q)||R.destroyed;!T&&!q.corked&&!q.bufferProcessing&&q.bufferedRequest&&W(R,q),Q?process.nextTick(X,R,q,T,oe):X(R,q,T,oe)}}function X(R,$,q,Q){q||J(R,$),$.pendingcb--,Q(),be(R,$)}function J(R,$){$.length===0&&$.needDrain&&($.needDrain=!1,R.emit("drain"))}function W(R,$){$.bufferProcessing=!0;var q=$.bufferedRequest;if(R._writev&&q&&q.next){var Q=$.bufferedRequestCount,oe=new Array(Q),T=$.corkedRequestsFree;T.entry=q;for(var P=0,j=!0;q;)oe[P]=q,q.isBuf||(j=!1),q=q.next,P+=1;oe.allBuffers=j,z(R,$,!0,$.length,oe,"",T.finish),$.pendingcb++,$.lastBufferedRequest=null,T.next?($.corkedRequestsFree=T.next,T.next=null):$.corkedRequestsFree=new e($),$.bufferedRequestCount=0}else{for(;q;){var Y=q.chunk,he=q.encoding,ce=q.callback,pe=$.objectMode?1:Y.length;if(z(R,$,!1,pe,Y,he,ce),q=q.next,$.bufferedRequestCount--,$.writing)break}q===null&&($.lastBufferedRequest=null)}$.bufferedRequest=q,$.bufferProcessing=!1}N.prototype._write=function(R,$,q){q(new p("_write()"))},N.prototype._writev=null,N.prototype.end=function(R,$,q){var Q=this._writableState;return typeof R=="function"?(q=R,R=null,$=null):typeof $=="function"&&(q=$,$=null),R!=null&&this.write(R,$),Q.corked&&(Q.corked=1,this.uncork()),Q.ending||xe(this,Q,q),this},Object.defineProperty(N.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function se(R){return R.ending&&R.length===0&&R.bufferedRequest===null&&!R.finished&&!R.writing}function ne(R,$){R._final(function(q){$.pendingcb--,q&&v(R,q),$.prefinished=!0,R.emit("prefinish"),be(R,$)})}function ae(R,$){!$.prefinished&&!$.finalCalled&&(typeof R._final=="function"&&!$.destroyed?($.pendingcb++,$.finalCalled=!0,process.nextTick(ne,R,$)):($.prefinished=!0,R.emit("prefinish")))}function be(R,$){var q=se($);if(q&&(ae(R,$),$.pendingcb===0&&($.finished=!0,R.emit("finish"),$.autoDestroy))){var Q=R._readableState;(!Q||Q.autoDestroy&&Q.endEmitted)&&R.destroy()}return q}function xe(R,$,q){$.ending=!0,be(R,$),q&&($.finished?process.nextTick(q):R.once("finish",q)),$.ended=!0,R.writable=!1}function He(R,$,q){var Q=R.entry;for(R.entry=null;Q;){var oe=Q.callback;$.pendingcb--,oe(q),Q=Q.next}$.corkedRequestsFree.next=R}return Object.defineProperty(N.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function($){this._writableState&&(this._writableState.destroyed=$)}}),N.prototype.destroy=c.destroy,N.prototype._undestroy=c.undestroy,N.prototype._destroy=function(R,$){$(R)},sc}var oc,dl;function si(){if(dl)return oc;dl=1;var e=Object.keys||function(u){var f=[];for(var d in u)f.push(d);return f};oc=o;var t=Jp(),r=Zp();Je(o,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var s=n[i];o.prototype[s]||(o.prototype[s]=r.prototype[s])}function o(u){if(!(this instanceof o))return new o(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(o.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(o.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(o.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function a(){this._writableState.ended||process.nextTick(c,this)}function c(u){u.end()}return Object.defineProperty(o.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(f){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=f,this._writableState.destroyed=f)}}),oc}var To={},Sf=lt.Buffer,ll=Sf.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 Fx(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 Ux(e){var t=Fx(e);if(typeof t!="string"&&(Sf.isEncoding===ll||!ll(e)))throw new Error("Unknown encoding: "+e);return t||e}To.StringDecoder=Ls;function Ls(e){this.encoding=Ux(e);var t;switch(this.encoding){case"utf16le":this.text=qx,this.end=Gx,t=4;break;case"utf8":this.fillLast=Dx,t=4;break;case"base64":this.text=Vx,this.end=Wx,t=3;break;default:this.write=Kx,this.end=Yx;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Sf.allocUnsafe(t)}Ls.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||""};Ls.prototype.end=zx;Ls.prototype.text=jx;Ls.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 ac(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Mx(e,t,r){var n=t.length-1;if(n<r)return 0;var i=ac(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=ac(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=ac(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function Hx(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 Dx(e){var t=this.lastTotal-this.lastNeed,r=Hx(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 jx(e,t){var r=Mx(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 zx(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function qx(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 Gx(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 Vx(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 Wx(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Kx(e){return e.toString(this.encoding)}function Yx(e){return e&&e.length?this.write(e):""}var hl=An.codes.ERR_STREAM_PREMATURE_CLOSE;function Zx(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 Xx(){}function Jx(e){return e.setHeader&&typeof e.abort=="function"}function Xp(e,t,r){if(typeof t=="function")return Xp(e,null,t);t||(t={}),r=Zx(r||Xx);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||a()},o=e._writableState&&e._writableState.finished,a=function(){i=!1,o=!0,n||r.call(e)},c=e._readableState&&e._readableState.endEmitted,u=function(){n=!1,c=!0,i||r.call(e)},f=function(w){r.call(e,w)},d=function(){var w;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(w=new hl),r.call(e,w);if(i&&!o)return(!e._writableState||!e._writableState.ended)&&(w=new hl),r.call(e,w)},y=function(){e.req.on("finish",a)};return Jx(e)?(e.on("complete",a),e.on("abort",d),e.req?y():e.on("request",y)):i&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",u),e.on("finish",a),t.error!==!1&&e.on("error",f),e.on("close",d),function(){e.removeListener("complete",a),e.removeListener("abort",d),e.removeListener("request",y),e.req&&e.req.removeListener("finish",a),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",a),e.removeListener("end",u),e.removeListener("error",f),e.removeListener("close",d)}}var Tf=Xp,cc,pl;function Qx(){if(pl)return cc;pl=1;var e;function t(x,v,B){return v=r(v),v in x?Object.defineProperty(x,v,{value:B,enumerable:!0,configurable:!0,writable:!0}):x[v]=B,x}function r(x){var v=n(x,"string");return typeof v=="symbol"?v:String(v)}function n(x,v){if(typeof x!="object"||x===null)return x;var B=x[Symbol.toPrimitive];if(B!==void 0){var S=B.call(x,v);if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return(v==="string"?String:Number)(x)}var i=Tf,s=Symbol("lastResolve"),o=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),u=Symbol("lastPromise"),f=Symbol("handlePromise"),d=Symbol("stream");function y(x,v){return{value:x,done:v}}function p(x){var v=x[s];if(v!==null){var B=x[d].read();B!==null&&(x[u]=null,x[s]=null,x[o]=null,v(y(B,!1)))}}function w(x){process.nextTick(p,x)}function b(x,v){return function(B,S){x.then(function(){if(v[c]){B(y(void 0,!0));return}v[f](B,S)},S)}}var m=Object.getPrototypeOf(function(){}),_=Object.setPrototypeOf((e={get stream(){return this[d]},next:function(){var v=this,B=this[a];if(B!==null)return Promise.reject(B);if(this[c])return Promise.resolve(y(void 0,!0));if(this[d].destroyed)return new Promise(function(I,G){process.nextTick(function(){v[a]?G(v[a]):I(y(void 0,!0))})});var S=this[u],C;if(S)C=new Promise(b(S,this));else{var N=this[d].read();if(N!==null)return Promise.resolve(y(N,!1));C=new Promise(this[f])}return this[u]=C,C}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var v=this;return new Promise(function(B,S){v[d].destroy(null,function(C){if(C){S(C);return}B(y(void 0,!0))})})}),e),m),E=function(v){var B,S=Object.create(_,(B={},t(B,d,{value:v,writable:!0}),t(B,s,{value:null,writable:!0}),t(B,o,{value:null,writable:!0}),t(B,a,{value:null,writable:!0}),t(B,c,{value:v._readableState.endEmitted,writable:!0}),t(B,f,{value:function(N,I){var G=S[d].read();G?(S[u]=null,S[s]=null,S[o]=null,N(y(G,!1))):(S[s]=N,S[o]=I)},writable:!0}),B));return S[u]=null,i(v,function(C){if(C&&C.code!=="ERR_STREAM_PREMATURE_CLOSE"){var N=S[o];N!==null&&(S[u]=null,S[s]=null,S[o]=null,N(C)),S[a]=C;return}var I=S[s];I!==null&&(S[u]=null,S[s]=null,S[o]=null,I(y(void 0,!0))),S[c]=!0}),v.on("readable",w.bind(null,S)),S};return cc=E,cc}var uc,yl;function eE(){return yl||(yl=1,uc=function(){throw new Error("Readable.from is not available in the browser")}),uc}var fc,ml;function Jp(){if(ml)return fc;ml=1,fc=I;var e;I.ReadableState=N,Gp.EventEmitter;var t=function(P,j){return P.listeners(j).length},r=Vp,n=Ar.Buffer,i=(typeof Dr<"u"?Dr:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(T){return n.from(T)}function o(T){return n.isBuffer(T)||T instanceof i}var a=Af,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var u=Ax(),f=Wp,d=Yp,y=d.getHighWaterMark,p=An.codes,w=p.ERR_INVALID_ARG_TYPE,b=p.ERR_STREAM_PUSH_AFTER_EOF,m=p.ERR_METHOD_NOT_IMPLEMENTED,_=p.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,E,x,v;Je(I,r);var B=f.errorOrDestroy,S=["error","close","destroy","pause","resume"];function C(T,P,j){if(typeof T.prependListener=="function")return T.prependListener(P,j);!T._events||!T._events[P]?T.on(P,j):Array.isArray(T._events[P])?T._events[P].unshift(j):T._events[P]=[j,T._events[P]]}function N(T,P,j){e=e||si(),T=T||{},typeof j!="boolean"&&(j=P instanceof e),this.objectMode=!!T.objectMode,j&&(this.objectMode=this.objectMode||!!T.readableObjectMode),this.highWaterMark=y(this,T,"readableHighWaterMark",j),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=T.emitClose!==!1,this.autoDestroy=!!T.autoDestroy,this.destroyed=!1,this.defaultEncoding=T.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,T.encoding&&(E||(E=To.StringDecoder),this.decoder=new E(T.encoding),this.encoding=T.encoding)}function I(T){if(e=e||si(),!(this instanceof I))return new I(T);var P=this instanceof e;this._readableState=new N(T,this,P),this.readable=!0,T&&(typeof T.read=="function"&&(this._read=T.read),typeof T.destroy=="function"&&(this._destroy=T.destroy)),r.call(this)}Object.defineProperty(I.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(P){this._readableState&&(this._readableState.destroyed=P)}}),I.prototype.destroy=f.destroy,I.prototype._undestroy=f.undestroy,I.prototype._destroy=function(T,P){P(T)},I.prototype.push=function(T,P){var j=this._readableState,Y;return j.objectMode?Y=!0:typeof T=="string"&&(P=P||j.defaultEncoding,P!==j.encoding&&(T=n.from(T,P),P=""),Y=!0),G(this,T,P,!1,Y)},I.prototype.unshift=function(T){return G(this,T,null,!0,!1)};function G(T,P,j,Y,he){c("readableAddChunk",P);var ce=T._readableState;if(P===null)ce.reading=!1,V(T,ce);else{var pe;if(he||(pe=U(ce,P)),pe)B(T,pe);else if(ce.objectMode||P&&P.length>0)if(typeof P!="string"&&!ce.objectMode&&Object.getPrototypeOf(P)!==n.prototype&&(P=s(P)),Y)ce.endEmitted?B(T,new _):k(T,ce,P,!0);else if(ce.ended)B(T,new b);else{if(ce.destroyed)return!1;ce.reading=!1,ce.decoder&&!j?(P=ce.decoder.write(P),ce.objectMode||P.length!==0?k(T,ce,P,!1):W(T,ce)):k(T,ce,P,!1)}else Y||(ce.reading=!1,W(T,ce))}return!ce.ended&&(ce.length<ce.highWaterMark||ce.length===0)}function k(T,P,j,Y){P.flowing&&P.length===0&&!P.sync?(P.awaitDrain=0,T.emit("data",j)):(P.length+=P.objectMode?1:j.length,Y?P.buffer.unshift(j):P.buffer.push(j),P.needReadable&&X(T)),W(T,P)}function U(T,P){var j;return!o(P)&&typeof P!="string"&&P!==void 0&&!T.objectMode&&(j=new w("chunk",["string","Buffer","Uint8Array"],P)),j}I.prototype.isPaused=function(){return this._readableState.flowing===!1},I.prototype.setEncoding=function(T){E||(E=To.StringDecoder);var P=new E(T);this._readableState.decoder=P,this._readableState.encoding=this._readableState.decoder.encoding;for(var j=this._readableState.buffer.head,Y="";j!==null;)Y+=P.write(j.data),j=j.next;return this._readableState.buffer.clear(),Y!==""&&this._readableState.buffer.push(Y),this._readableState.length=Y.length,this};var z=1073741824;function F(T){return T>=z?T=z:(T--,T|=T>>>1,T|=T>>>2,T|=T>>>4,T|=T>>>8,T|=T>>>16,T++),T}function D(T,P){return T<=0||P.length===0&&P.ended?0:P.objectMode?1:T!==T?P.flowing&&P.length?P.buffer.head.data.length:P.length:(T>P.highWaterMark&&(P.highWaterMark=F(T)),T<=P.length?T:P.ended?P.length:(P.needReadable=!0,0))}I.prototype.read=function(T){c("read",T),T=parseInt(T,10);var P=this._readableState,j=T;if(T!==0&&(P.emittedReadable=!1),T===0&&P.needReadable&&((P.highWaterMark!==0?P.length>=P.highWaterMark:P.length>0)||P.ended))return c("read: emitReadable",P.length,P.ended),P.length===0&&P.ended?q(this):X(this),null;if(T=D(T,P),T===0&&P.ended)return P.length===0&&q(this),null;var Y=P.needReadable;c("need readable",Y),(P.length===0||P.length-T<P.highWaterMark)&&(Y=!0,c("length less than watermark",Y)),P.ended||P.reading?(Y=!1,c("reading or ended",Y)):Y&&(c("do read"),P.reading=!0,P.sync=!0,P.length===0&&(P.needReadable=!0),this._read(P.highWaterMark),P.sync=!1,P.reading||(T=D(j,P)));var he;return T>0?he=$(T,P):he=null,he===null?(P.needReadable=P.length<=P.highWaterMark,T=0):(P.length-=T,P.awaitDrain=0),P.length===0&&(P.ended||(P.needReadable=!0),j!==T&&P.ended&&q(this)),he!==null&&this.emit("data",he),he};function V(T,P){if(c("onEofChunk"),!P.ended){if(P.decoder){var j=P.decoder.end();j&&j.length&&(P.buffer.push(j),P.length+=P.objectMode?1:j.length)}P.ended=!0,P.sync?X(T):(P.needReadable=!1,P.emittedReadable||(P.emittedReadable=!0,J(T)))}}function X(T){var P=T._readableState;c("emitReadable",P.needReadable,P.emittedReadable),P.needReadable=!1,P.emittedReadable||(c("emitReadable",P.flowing),P.emittedReadable=!0,process.nextTick(J,T))}function J(T){var P=T._readableState;c("emitReadable_",P.destroyed,P.length,P.ended),!P.destroyed&&(P.length||P.ended)&&(T.emit("readable"),P.emittedReadable=!1),P.needReadable=!P.flowing&&!P.ended&&P.length<=P.highWaterMark,R(T)}function W(T,P){P.readingMore||(P.readingMore=!0,process.nextTick(se,T,P))}function se(T,P){for(;!P.reading&&!P.ended&&(P.length<P.highWaterMark||P.flowing&&P.length===0);){var j=P.length;if(c("maybeReadMore read 0"),T.read(0),j===P.length)break}P.readingMore=!1}I.prototype._read=function(T){B(this,new m("_read()"))},I.prototype.pipe=function(T,P){var j=this,Y=this._readableState;switch(Y.pipesCount){case 0:Y.pipes=T;break;case 1:Y.pipes=[Y.pipes,T];break;default:Y.pipes.push(T);break}Y.pipesCount+=1,c("pipe count=%d opts=%j",Y.pipesCount,P);var he=(!P||P.end!==!1)&&T!==process.stdout&&T!==process.stderr,ce=he?Sr:Yr;Y.endEmitted?process.nextTick(ce):j.once("end",ce),T.on("unpipe",pe);function pe(g,l){c("onunpipe"),g===j&&l&&l.hasUnpiped===!1&&(l.hasUnpiped=!0,Pn())}function Sr(){c("onend"),T.end()}var Tn=ne(j);T.on("drain",Tn);var yi=!1;function Pn(){c("cleanup"),T.removeListener("close",mi),T.removeListener("finish",_t),T.removeListener("drain",Tn),T.removeListener("error",Kr),T.removeListener("unpipe",pe),j.removeListener("end",Sr),j.removeListener("end",Yr),j.removeListener("data",mt),yi=!0,Y.awaitDrain&&(!T._writableState||T._writableState.needDrain)&&Tn()}j.on("data",mt);function mt(g){c("ondata");var l=T.write(g);c("dest.write",l),l===!1&&((Y.pipesCount===1&&Y.pipes===T||Y.pipesCount>1&&oe(Y.pipes,T)!==-1)&&!yi&&(c("false write response, pause",Y.awaitDrain),Y.awaitDrain++),j.pause())}function Kr(g){c("onerror",g),Yr(),T.removeListener("error",Kr),t(T,"error")===0&&B(T,g)}C(T,"error",Kr);function mi(){T.removeListener("finish",_t),Yr()}T.once("close",mi);function _t(){c("onfinish"),T.removeListener("close",mi),Yr()}T.once("finish",_t);function Yr(){c("unpipe"),j.unpipe(T)}return T.emit("pipe",j),Y.flowing||(c("pipe resume"),j.resume()),T};function ne(T){return function(){var j=T._readableState;c("pipeOnDrain",j.awaitDrain),j.awaitDrain&&j.awaitDrain--,j.awaitDrain===0&&t(T,"data")&&(j.flowing=!0,R(T))}}I.prototype.unpipe=function(T){var P=this._readableState,j={hasUnpiped:!1};if(P.pipesCount===0)return this;if(P.pipesCount===1)return T&&T!==P.pipes?this:(T||(T=P.pipes),P.pipes=null,P.pipesCount=0,P.flowing=!1,T&&T.emit("unpipe",this,j),this);if(!T){var Y=P.pipes,he=P.pipesCount;P.pipes=null,P.pipesCount=0,P.flowing=!1;for(var ce=0;ce<he;ce++)Y[ce].emit("unpipe",this,{hasUnpiped:!1});return this}var pe=oe(P.pipes,T);return pe===-1?this:(P.pipes.splice(pe,1),P.pipesCount-=1,P.pipesCount===1&&(P.pipes=P.pipes[0]),T.emit("unpipe",this,j),this)},I.prototype.on=function(T,P){var j=r.prototype.on.call(this,T,P),Y=this._readableState;return T==="data"?(Y.readableListening=this.listenerCount("readable")>0,Y.flowing!==!1&&this.resume()):T==="readable"&&!Y.endEmitted&&!Y.readableListening&&(Y.readableListening=Y.needReadable=!0,Y.flowing=!1,Y.emittedReadable=!1,c("on readable",Y.length,Y.reading),Y.length?X(this):Y.reading||process.nextTick(be,this)),j},I.prototype.addListener=I.prototype.on,I.prototype.removeListener=function(T,P){var j=r.prototype.removeListener.call(this,T,P);return T==="readable"&&process.nextTick(ae,this),j},I.prototype.removeAllListeners=function(T){var P=r.prototype.removeAllListeners.apply(this,arguments);return(T==="readable"||T===void 0)&&process.nextTick(ae,this),P};function ae(T){var P=T._readableState;P.readableListening=T.listenerCount("readable")>0,P.resumeScheduled&&!P.paused?P.flowing=!0:T.listenerCount("data")>0&&T.resume()}function be(T){c("readable nexttick read 0"),T.read(0)}I.prototype.resume=function(){var T=this._readableState;return T.flowing||(c("resume"),T.flowing=!T.readableListening,xe(this,T)),T.paused=!1,this};function xe(T,P){P.resumeScheduled||(P.resumeScheduled=!0,process.nextTick(He,T,P))}function He(T,P){c("resume",P.reading),P.reading||T.read(0),P.resumeScheduled=!1,T.emit("resume"),R(T),P.flowing&&!P.reading&&T.read(0)}I.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 R(T){var P=T._readableState;for(c("flow",P.flowing);P.flowing&&T.read()!==null;);}I.prototype.wrap=function(T){var P=this,j=this._readableState,Y=!1;T.on("end",function(){if(c("wrapped end"),j.decoder&&!j.ended){var pe=j.decoder.end();pe&&pe.length&&P.push(pe)}P.push(null)}),T.on("data",function(pe){if(c("wrapped data"),j.decoder&&(pe=j.decoder.write(pe)),!(j.objectMode&&pe==null)&&!(!j.objectMode&&(!pe||!pe.length))){var Sr=P.push(pe);Sr||(Y=!0,T.pause())}});for(var he in T)this[he]===void 0&&typeof T[he]=="function"&&(this[he]=function(Sr){return function(){return T[Sr].apply(T,arguments)}}(he));for(var ce=0;ce<S.length;ce++)T.on(S[ce],this.emit.bind(this,S[ce]));return this._read=function(pe){c("wrapped _read",pe),Y&&(Y=!1,T.resume())},this},typeof Symbol=="function"&&(I.prototype[Symbol.asyncIterator]=function(){return x===void 0&&(x=Qx()),x(this)}),Object.defineProperty(I.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(I.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(I.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(P){this._readableState&&(this._readableState.flowing=P)}}),I._fromList=$,Object.defineProperty(I.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function $(T,P){if(P.length===0)return null;var j;return P.objectMode?j=P.buffer.shift():!T||T>=P.length?(P.decoder?j=P.buffer.join(""):P.buffer.length===1?j=P.buffer.first():j=P.buffer.concat(P.length),P.buffer.clear()):j=P.buffer.consume(T,P.decoder),j}function q(T){var P=T._readableState;c("endReadable",P.endEmitted),P.endEmitted||(P.ended=!0,process.nextTick(Q,P,T))}function Q(T,P){if(c("endReadableNT",T.endEmitted,T.length),!T.endEmitted&&T.length===0&&(T.endEmitted=!0,P.readable=!1,P.emit("end"),T.autoDestroy)){var j=P._writableState;(!j||j.autoDestroy&&j.finished)&&P.destroy()}}typeof Symbol=="function"&&(I.from=function(T,P){return v===void 0&&(v=eE()),v(I,T,P)});function oe(T,P){for(var j=0,Y=T.length;j<Y;j++)if(T[j]===P)return j;return-1}return fc}var Qp=vr,ca=An.codes,tE=ca.ERR_METHOD_NOT_IMPLEMENTED,rE=ca.ERR_MULTIPLE_CALLBACK,nE=ca.ERR_TRANSFORM_ALREADY_TRANSFORMING,iE=ca.ERR_TRANSFORM_WITH_LENGTH_0,ua=si();Je(vr,ua);function sE(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new rE);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 vr(e){if(!(this instanceof vr))return new vr(e);ua.call(this,e),this._transformState={afterTransform:sE.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",oE)}function oE(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){bl(e,t,r)}):bl(this,null,null)}vr.prototype.push=function(e,t){return this._transformState.needTransform=!1,ua.prototype.push.call(this,e,t)};vr.prototype._transform=function(e,t,r){r(new tE("_transform()"))};vr.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)}};vr.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};vr.prototype._destroy=function(e,t){ua.prototype._destroy.call(this,e,function(r){t(r)})};function bl(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new iE;if(e._transformState.transforming)throw new nE;return e.push(null)}var aE=gs,ey=Qp;Je(gs,ey);function gs(e){if(!(this instanceof gs))return new gs(e);ey.call(this,e)}gs.prototype._transform=function(e,t,r){r(null,e)};var dc;function cE(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var ty=An.codes,uE=ty.ERR_MISSING_ARGS,fE=ty.ERR_STREAM_DESTROYED;function gl(e){if(e)throw e}function dE(e){return e.setHeader&&typeof e.abort=="function"}function lE(e,t,r,n){n=cE(n);var i=!1;e.on("close",function(){i=!0}),dc===void 0&&(dc=Tf),dc(e,{readable:t,writable:r},function(o){if(o)return n(o);i=!0,n()});var s=!1;return function(o){if(!i&&!s){if(s=!0,dE(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(o||new fE("pipe"))}}}function wl(e){e()}function hE(e,t){return e.pipe(t)}function pE(e){return!e.length||typeof e[e.length-1]!="function"?gl:e.pop()}function yE(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=pE(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new uE("streams");var i,s=t.map(function(o,a){var c=a<t.length-1,u=a>0;return lE(o,c,u,function(f){i||(i=f),f&&s.forEach(wl),!c&&(s.forEach(wl),n(i))})});return t.reduce(hE)}var mE=yE;(function(e,t){t=e.exports=Jp(),t.Stream=t,t.Readable=t,t.Writable=Zp(),t.Duplex=si(),t.Transform=Qp,t.PassThrough=aE,t.finished=Tf,t.pipeline=mE})(uu,uu.exports);var ry=uu.exports,Po=lt.Buffer,ny=ry.Transform,bE=Je;function gE(e,t){if(!Po.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Vr(e){ny.call(this),this._block=Po.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}bE(Vr,ny);Vr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Vr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Vr.prototype.update=function(e,t){if(gE(e,"Data"),this._finalized)throw new Error("Digest already called");Po.isBuffer(e)||(e=Po.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};Vr.prototype._update=function(){throw new Error("_update is not implemented")};Vr.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();e!==void 0&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t};Vr.prototype._digest=function(){throw new Error("_digest is not implemented")};var wE=Vr,vE=Je,iy=wE,_E=lt.Buffer,xE=new Array(16);function fa(){iy.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}vE(fa,iy);fa.prototype._update=function(){for(var e=xE,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,s=this._d;r=Qe(r,n,i,s,e[0],3614090360,7),s=Qe(s,r,n,i,e[1],3905402710,12),i=Qe(i,s,r,n,e[2],606105819,17),n=Qe(n,i,s,r,e[3],3250441966,22),r=Qe(r,n,i,s,e[4],4118548399,7),s=Qe(s,r,n,i,e[5],1200080426,12),i=Qe(i,s,r,n,e[6],2821735955,17),n=Qe(n,i,s,r,e[7],4249261313,22),r=Qe(r,n,i,s,e[8],1770035416,7),s=Qe(s,r,n,i,e[9],2336552879,12),i=Qe(i,s,r,n,e[10],4294925233,17),n=Qe(n,i,s,r,e[11],2304563134,22),r=Qe(r,n,i,s,e[12],1804603682,7),s=Qe(s,r,n,i,e[13],4254626195,12),i=Qe(i,s,r,n,e[14],2792965006,17),n=Qe(n,i,s,r,e[15],1236535329,22),r=et(r,n,i,s,e[1],4129170786,5),s=et(s,r,n,i,e[6],3225465664,9),i=et(i,s,r,n,e[11],643717713,14),n=et(n,i,s,r,e[0],3921069994,20),r=et(r,n,i,s,e[5],3593408605,5),s=et(s,r,n,i,e[10],38016083,9),i=et(i,s,r,n,e[15],3634488961,14),n=et(n,i,s,r,e[4],3889429448,20),r=et(r,n,i,s,e[9],568446438,5),s=et(s,r,n,i,e[14],3275163606,9),i=et(i,s,r,n,e[3],4107603335,14),n=et(n,i,s,r,e[8],1163531501,20),r=et(r,n,i,s,e[13],2850285829,5),s=et(s,r,n,i,e[2],4243563512,9),i=et(i,s,r,n,e[7],1735328473,14),n=et(n,i,s,r,e[12],2368359562,20),r=tt(r,n,i,s,e[5],4294588738,4),s=tt(s,r,n,i,e[8],2272392833,11),i=tt(i,s,r,n,e[11],1839030562,16),n=tt(n,i,s,r,e[14],4259657740,23),r=tt(r,n,i,s,e[1],2763975236,4),s=tt(s,r,n,i,e[4],1272893353,11),i=tt(i,s,r,n,e[7],4139469664,16),n=tt(n,i,s,r,e[10],3200236656,23),r=tt(r,n,i,s,e[13],681279174,4),s=tt(s,r,n,i,e[0],3936430074,11),i=tt(i,s,r,n,e[3],3572445317,16),n=tt(n,i,s,r,e[6],76029189,23),r=tt(r,n,i,s,e[9],3654602809,4),s=tt(s,r,n,i,e[12],3873151461,11),i=tt(i,s,r,n,e[15],530742520,16),n=tt(n,i,s,r,e[2],3299628645,23),r=rt(r,n,i,s,e[0],4096336452,6),s=rt(s,r,n,i,e[7],1126891415,10),i=rt(i,s,r,n,e[14],2878612391,15),n=rt(n,i,s,r,e[5],4237533241,21),r=rt(r,n,i,s,e[12],1700485571,6),s=rt(s,r,n,i,e[3],2399980690,10),i=rt(i,s,r,n,e[10],4293915773,15),n=rt(n,i,s,r,e[1],2240044497,21),r=rt(r,n,i,s,e[8],1873313359,6),s=rt(s,r,n,i,e[15],4264355552,10),i=rt(i,s,r,n,e[6],2734768916,15),n=rt(n,i,s,r,e[13],1309151649,21),r=rt(r,n,i,s,e[4],4149444226,6),s=rt(s,r,n,i,e[11],3174756917,10),i=rt(i,s,r,n,e[2],718787259,15),n=rt(n,i,s,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+s|0};fa.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=_E.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 da(e,t){return e<<t|e>>>32-t}function Qe(e,t,r,n,i,s,o){return da(e+(t&r|~t&n)+i+s|0,o)+t|0}function et(e,t,r,n,i,s,o){return da(e+(t&n|r&~n)+i+s|0,o)+t|0}function tt(e,t,r,n,i,s,o){return da(e+(t^r^n)+i+s|0,o)+t|0}function rt(e,t,r,n,i,s,o){return da(e+(r^(t|~n))+i+s|0,o)+t|0}var EE=fa,Bo=lt.Buffer,sy=ry.Transform,AE=Je;function SE(e,t){if(!Bo.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Wr(e){sy.call(this),this._block=Bo.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}AE(Wr,sy);Wr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Wr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Wr.prototype.update=function(e,t){if(SE(e,"Data"),this._finalized)throw new Error("Digest already called");Bo.isBuffer(e)||(e=Bo.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,o=e.length*8;o>0;++s)this._length[s]+=o,o=this._length[s]/4294967296|0,o>0&&(this._length[s]-=4294967296*o);return this};Wr.prototype._update=function(){throw new Error("_update is not implemented")};Wr.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();e!==void 0&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t};Wr.prototype._digest=function(){throw new Error("_digest is not implemented")};var TE=Wr,lc=Ar.Buffer,PE=Je,oy=TE,BE=new Array(16),Pi=[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],Bi=[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],Ii=[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],ki=[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],Ci=[0,1518500249,1859775393,2400959708,2840853838],Oi=[1352829926,1548603684,1836072691,2053994217,0];function la(){oy.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}PE(la,oy);la.prototype._update=function(){for(var e=BE,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._a|0,c=this._b|0,u=this._c|0,f=this._d|0,d=this._e|0,y=0;y<80;y+=1){var p,w;y<16?(p=vl(r,n,i,s,o,e[Pi[y]],Ci[0],Ii[y]),w=Al(a,c,u,f,d,e[Bi[y]],Oi[0],ki[y])):y<32?(p=_l(r,n,i,s,o,e[Pi[y]],Ci[1],Ii[y]),w=El(a,c,u,f,d,e[Bi[y]],Oi[1],ki[y])):y<48?(p=xl(r,n,i,s,o,e[Pi[y]],Ci[2],Ii[y]),w=xl(a,c,u,f,d,e[Bi[y]],Oi[2],ki[y])):y<64?(p=El(r,n,i,s,o,e[Pi[y]],Ci[3],Ii[y]),w=_l(a,c,u,f,d,e[Bi[y]],Oi[3],ki[y])):(p=Al(r,n,i,s,o,e[Pi[y]],Ci[4],Ii[y]),w=vl(a,c,u,f,d,e[Bi[y]],Oi[4],ki[y])),r=o,o=s,s=gn(i,10),i=n,n=p,a=d,d=f,f=gn(u,10),u=c,c=w}var b=this._b+i+f|0;this._b=this._c+s+d|0,this._c=this._d+o+a|0,this._d=this._e+r+c|0,this._e=this._a+n+u|0,this._a=b};la.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=lc.alloc?lc.alloc(20):new lc(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 gn(e,t){return e<<t|e>>>32-t}function vl(e,t,r,n,i,s,o,a){return gn(e+(t^r^n)+s+o|0,a)+i|0}function _l(e,t,r,n,i,s,o,a){return gn(e+(t&r|~t&n)+s+o|0,a)+i|0}function xl(e,t,r,n,i,s,o,a){return gn(e+((t|~r)^n)+s+o|0,a)+i|0}function El(e,t,r,n,i,s,o,a){return gn(e+(t&n|r&~n)+s+o|0,a)+i|0}function Al(e,t,r,n,i,s,o,a){return gn(e+(t^(r|~n))+s+o|0,a)+i|0}var IE=la,ay={exports:{}},cy=lt.Buffer;function ha(e,t){this._block=cy.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}ha.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=cy.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,s=this._len,o=0;o<i;){for(var a=s%n,c=Math.min(i-o,n-a),u=0;u<c;u++)r[a+u]=e[o+u];s+=c,o+=c,s%n===0&&this._update(r)}return this._len+=i,this};ha.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=this._len*8;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(r&4294967295)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var s=this._hash();return e?s.toString(e):s};ha.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var pi=ha,kE=Je,uy=pi,CE=lt.Buffer,OE=[1518500249,1859775393,-1894007588,-899497514],RE=new Array(80);function Fs(){this.init(),this._w=RE,uy.call(this,64,56)}kE(Fs,uy);Fs.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function NE(e){return e<<5|e>>>27}function $E(e){return e<<30|e>>>2}function LE(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Fs.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=t[a-3]^t[a-8]^t[a-14]^t[a-16];for(var c=0;c<80;++c){var u=~~(c/20),f=NE(r)+LE(u,n,i,s)+o+t[c]+OE[u]|0;o=s,s=i,i=$E(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=s+this._d|0,this._e=o+this._e|0};Fs.prototype._hash=function(){var e=CE.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 FE=Fs,UE=Je,fy=pi,ME=lt.Buffer,HE=[1518500249,1859775393,-1894007588,-899497514],DE=new Array(80);function Us(){this.init(),this._w=DE,fy.call(this,64,56)}UE(Us,fy);Us.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function jE(e){return e<<1|e>>>31}function zE(e){return e<<5|e>>>27}function qE(e){return e<<30|e>>>2}function GE(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Us.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=jE(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var u=~~(c/20),f=zE(r)+GE(u,n,i,s)+o+t[c]+HE[u]|0;o=s,s=i,i=qE(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=s+this._d|0,this._e=o+this._e|0};Us.prototype._hash=function(){var e=ME.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 VE=Us,WE=Je,dy=pi,KE=lt.Buffer,YE=[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],ZE=new Array(64);function Ms(){this.init(),this._w=ZE,dy.call(this,64,56)}WE(Ms,dy);Ms.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 XE(e,t,r){return r^e&(t^r)}function JE(e,t,r){return e&t|r&(e|t)}function QE(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function e5(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function t5(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function r5(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}Ms.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,s=this._d|0,o=this._e|0,a=this._f|0,c=this._g|0,u=this._h|0,f=0;f<16;++f)t[f]=e.readInt32BE(f*4);for(;f<64;++f)t[f]=r5(t[f-2])+t[f-7]+t5(t[f-15])+t[f-16]|0;for(var d=0;d<64;++d){var y=u+e5(o)+XE(o,a,c)+YE[d]+t[d]|0,p=QE(r)+JE(r,n,i)|0;u=c,c=a,a=o,o=s+y|0,s=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=s+this._d|0,this._e=o+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=u+this._h|0};Ms.prototype._hash=function(){var e=KE.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 ly=Ms,n5=Je,i5=ly,s5=pi,o5=lt.Buffer,a5=new Array(64);function pa(){this.init(),this._w=a5,s5.call(this,64,56)}n5(pa,i5);pa.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};pa.prototype._hash=function(){var e=o5.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 c5=pa,u5=Je,hy=pi,f5=lt.Buffer,Sl=[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],d5=new Array(160);function Hs(){this.init(),this._w=d5,hy.call(this,128,112)}u5(Hs,hy);Hs.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 Tl(e,t,r){return r^e&(t^r)}function Pl(e,t,r){return e&t|r&(e|t)}function Bl(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function Il(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function l5(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function h5(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function p5(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function y5(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function je(e,t){return e>>>0<t>>>0?1:0}Hs.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,s=this._dh|0,o=this._eh|0,a=this._fh|0,c=this._gh|0,u=this._hh|0,f=this._al|0,d=this._bl|0,y=this._cl|0,p=this._dl|0,w=this._el|0,b=this._fl|0,m=this._gl|0,_=this._hl|0,E=0;E<32;E+=2)t[E]=e.readInt32BE(E*4),t[E+1]=e.readInt32BE(E*4+4);for(;E<160;E+=2){var x=t[E-30],v=t[E-15*2+1],B=l5(x,v),S=h5(v,x);x=t[E-2*2],v=t[E-2*2+1];var C=p5(x,v),N=y5(v,x),I=t[E-7*2],G=t[E-7*2+1],k=t[E-16*2],U=t[E-16*2+1],z=S+G|0,F=B+I+je(z,S)|0;z=z+N|0,F=F+C+je(z,N)|0,z=z+U|0,F=F+k+je(z,U)|0,t[E]=F,t[E+1]=z}for(var D=0;D<160;D+=2){F=t[D],z=t[D+1];var V=Pl(r,n,i),X=Pl(f,d,y),J=Bl(r,f),W=Bl(f,r),se=Il(o,w),ne=Il(w,o),ae=Sl[D],be=Sl[D+1],xe=Tl(o,a,c),He=Tl(w,b,m),R=_+ne|0,$=u+se+je(R,_)|0;R=R+He|0,$=$+xe+je(R,He)|0,R=R+be|0,$=$+ae+je(R,be)|0,R=R+z|0,$=$+F+je(R,z)|0;var q=W+X|0,Q=J+V+je(q,W)|0;u=c,_=m,c=a,m=b,a=o,b=w,w=p+R|0,o=s+$+je(w,p)|0,s=i,p=y,i=n,y=d,n=r,d=f,f=R+q|0,r=$+Q+je(f,R)|0}this._al=this._al+f|0,this._bl=this._bl+d|0,this._cl=this._cl+y|0,this._dl=this._dl+p|0,this._el=this._el+w|0,this._fl=this._fl+b|0,this._gl=this._gl+m|0,this._hl=this._hl+_|0,this._ah=this._ah+r+je(this._al,f)|0,this._bh=this._bh+n+je(this._bl,d)|0,this._ch=this._ch+i+je(this._cl,y)|0,this._dh=this._dh+s+je(this._dl,p)|0,this._eh=this._eh+o+je(this._el,w)|0,this._fh=this._fh+a+je(this._fl,b)|0,this._gh=this._gh+c+je(this._gl,m)|0,this._hh=this._hh+u+je(this._hl,_)|0};Hs.prototype._hash=function(){var e=f5.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 py=Hs,m5=Je,b5=py,g5=pi,w5=lt.Buffer,v5=new Array(160);function ya(){this.init(),this._w=v5,g5.call(this,128,112)}m5(ya,b5);ya.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};ya.prototype._hash=function(){var e=w5.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 _5=ya,Sn=ay.exports=function(t){t=t.toLowerCase();var r=Sn[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};Sn.sha=FE;Sn.sha1=VE;Sn.sha224=c5;Sn.sha256=ly;Sn.sha384=_5;Sn.sha512=py;var x5=ay.exports,Yt=lt.Buffer,yy=Af.Transform,E5=To.StringDecoder,A5=Je;function Ht(e){yy.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}A5(Ht,yy);var S5=typeof Uint8Array<"u",T5=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(Yt.prototype instanceof Uint8Array||Yt.TYPED_ARRAY_SUPPORT);function P5(e,t){if(e instanceof Yt)return e;if(typeof e=="string")return Yt.from(e,t);if(T5&&ArrayBuffer.isView(e)){if(e.byteLength===0)return Yt.alloc(0);var r=Yt.from(e.buffer,e.byteOffset,e.byteLength);if(r.byteLength===e.byteLength)return r}if(S5&&e instanceof Uint8Array||Yt.isBuffer(e)&&e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return Yt.from(e);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}Ht.prototype.update=function(e,t,r){var n=P5(e,t),i=this._update(n);return this.hashMode?this:(r&&(i=this._toString(i,r)),i)};Ht.prototype.setAutoPadding=function(){};Ht.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Ht.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Ht.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Ht.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)}};Ht.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Ht.prototype._finalOrDigest=function(e){var t=this.__final()||Yt.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Ht.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new E5(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 B5=Ht,I5=Je,k5=EE,C5=IE,O5=x5,my=B5;function ma(e){my.call(this,"digest"),this._hash=e}I5(ma,my);ma.prototype._update=function(e){this._hash.update(e)};ma.prototype._final=function(){return this._hash.digest()};var R5=function(t){return t=t.toLowerCase(),t==="md5"?new k5:t==="rmd160"||t==="ripemd160"?new C5:new ma(O5(t))},ro=lt.Buffer;function N5(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),u=Math.log(256)/Math.log(o);function f(p){if((Array.isArray(p)||p instanceof Uint8Array)&&(p=ro.from(p)),!ro.isBuffer(p))throw new TypeError("Expected Buffer");if(p.length===0)return"";for(var w=0,b=0,m=0,_=p.length;m!==_&&p[m]===0;)m++,w++;for(var E=(_-m)*u+1>>>0,x=new Uint8Array(E);m!==_;){for(var v=p[m],B=0,S=E-1;(v!==0||B<b)&&S!==-1;S--,B++)v+=256*x[S]>>>0,x[S]=v%o>>>0,v=v/o>>>0;if(v!==0)throw new Error("Non-zero carry");b=B,m++}for(var C=E-b;C!==E&&x[C]===0;)C++;for(var N=a.repeat(w);C<E;++C)N+=e.charAt(x[C]);return N}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return ro.alloc(0);for(var w=0,b=0,m=0;p[w]===a;)b++,w++;for(var _=(p.length-w)*c+1>>>0,E=new Uint8Array(_);w<p.length;){var x=p.charCodeAt(w);if(x>255)return;var v=t[x];if(v===255)return;for(var B=0,S=_-1;(v!==0||B<m)&&S!==-1;S--,B++)v+=o*E[S]>>>0,E[S]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");m=B,w++}for(var C=_-m;C!==_&&E[C]===0;)C++;var N=ro.allocUnsafe(b+(_-C));N.fill(0,0,b);for(var I=b;C!==_;)N[I++]=E[C++];return N}function y(p){var w=d(p);if(w)return w;throw new Error("Non-base"+o+" character")}return{encode:f,decodeUnsafe:d,decode:y}}var $5=N5,L5=$5,F5="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",U5=L5(F5),hc=U5,M5=lt.Buffer,H5=function(e){function t(s){var o=e(s);return hc.encode(M5.concat([s,o],s.length+4))}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=hc.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=hc.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},kl=R5,D5=H5;function j5(e){var t=kl("sha256").update(e).digest();return kl("sha256").update(t).digest()}var z5=D5(j5),du=z5;function by(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 lu(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 q5(e,t){return by(du.decode(e),t)}function G5(e,t,r){return typeof e=="number"?du.encode(lu(e,t,r)):du.encode(lu(e.version,e.privateKey,e.compressed))}var V5={decode:q5,decodeRaw:by,encode:G5,encodeRaw:lu},ba={};Object.defineProperty(ba,"__esModule",{value:!0});ba.testEcc=void 0;const re=e=>Buffer.from(e,"hex");function W5(e){Ae(e.isPoint(re("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(!e.isPoint(re("030000000000000000000000000000000000000000000000000000000000000005"))),Ae(e.isPrivate(re("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(e.isPrivate(re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),Ae(!e.isPrivate(re("0000000000000000000000000000000000000000000000000000000000000000"))),Ae(!e.isPrivate(re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),Ae(!e.isPrivate(re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),Ae(Buffer.from(e.privateAdd(re("0000000000000000000000000000000000000000000000000000000000000001"),re("0000000000000000000000000000000000000000000000000000000000000000"))).equals(re("0000000000000000000000000000000000000000000000000000000000000001"))),Ae(e.privateAdd(re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),re("0000000000000000000000000000000000000000000000000000000000000003"))===null),Ae(Buffer.from(e.privateAdd(re("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),re("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(re("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),Ae(Buffer.from(e.privateNegate(re("0000000000000000000000000000000000000000000000000000000000000001"))).equals(re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),Ae(Buffer.from(e.privateNegate(re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(re("0000000000000000000000000000000000000000000000000000000000000003"))),Ae(Buffer.from(e.privateNegate(re("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(re("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),Ae(Buffer.from(e.pointCompress(re("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(re("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(Buffer.from(e.pointCompress(re("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(re("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),Ae(Buffer.from(e.pointCompress(re("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(re("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(Buffer.from(e.pointCompress(re("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(re("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),Ae(Buffer.from(e.pointFromScalar(re("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(re("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),Ae(e.xOnlyPointAddTweak(re("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(re("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),re("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));Ae(Buffer.from(t.xOnlyPubkey).equals(re("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(re("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),re("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),Ae(Buffer.from(t.xOnlyPubkey).equals(re("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),Ae(Buffer.from(e.sign(re("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),re("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(re("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),Ae(e.verify(re("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),re("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),re("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&Ae(Buffer.from(e.signSchnorr(re("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),re("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),re("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(re("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&Ae(e.verifySchnorr(re("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),re("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),re("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}ba.testEcc=W5;function Ae(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(ni,"__esModule",{value:!0});ni.ECPairFactory=ni.networks=void 0;const hu=ii;ni.networks=hu;const ct=Lp,K5=yx,Cl=V5,Y5=ba,pc=ct.typeforce.maybe(ct.typeforce.compile({compressed:ct.maybe(ct.Boolean),network:ct.maybe(ct.Network)})),Z5=e=>e.length===32?e:e.slice(1,33);function X5(e){(0,Y5.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(ct.typeforce(ct.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return ct.typeforce(pc,c),new o(a,void 0,c)}function n(a,c){return ct.typeforce(e.isPoint,a),ct.typeforce(pc,c),new o(void 0,a,c)}function i(a,c){const u=Cl.decode(a),f=u.version;if(ct.Array(c)){if(c=c.filter(d=>f===d.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||hu.bitcoin,f!==c.wif)throw new Error("Invalid network version");return r(u.privateKey,{compressed:u.compressed,network:c})}function s(a){ct.typeforce(pc,a),a===void 0&&(a={});const c=a.rng||K5;let u;do u=c(32),ct.typeforce(ct.Buffer256bit,u);while(!e.isPrivate(u));return r(u,a)}class o{constructor(c,u,f){Bn(this,"__D");Bn(this,"__Q");Bn(this,"compressed");Bn(this,"network");Bn(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||hu.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 Cl.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 d=Buffer.alloc(32,0);let y=0;for(;f[0]>127;)y++,d.writeUIntLE(y,0,6),f=e.sign(c,this.__D,d);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=Z5(this.publicKey),f=e.xOnlyPointAddTweak(u,c);if(!f||f.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const d=Buffer.from([f.parity===0?2:3]);return n(Buffer.concat([d,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,d=e.privateAdd(f,c);if(!d)throw new Error("Invalid tweaked private key!");return r(Buffer.from(d),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:s}}ni.ECPairFactory=X5;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=ni;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}})})($p);const J5=Hw($p);class ws extends Z.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new ws(Qr(t))}static fromWalletClient(t){return new ws(void 0,t)}async initialize(){if(this.digestKey)return de("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?K(t.error):(this.emit("initialized",!0),de("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return K("No walletClient found");if(!this.walletClient.account)return K("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=Qr($i(t)),this.emit("initialized",!0),de(this.digestKey)}catch(t){return K("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return K("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return K(t.error)}return this.digestKey?de(this.digestKey):K("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return K(r.error);const n=$i(Z.with0x(r.val)),i=$i(n);return de({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const u=await this.getDigestKey();if(u.error)return K(u.error);this.digestKey=u.val}const r=J5(an),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),s=$i(i),o=Buffer.from(Qr(this.digestKey),"hex");if(o.length!==32)return K("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(o).sign(Buffer.from(Qr(s),"hex"));return de(c.toString("hex"))}}const Ol=[{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"}],Q5={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},e8={block:v1({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Ho(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?Ze(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:g1({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?Ze(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Q1({format(e){return{l1GasPrice:e.l1GasPrice?Ze(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?Ze(e.l1GasUsed):null,l1Fee:e.l1Fee?Ze(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function t8(e,t){return i8(e)?n8(e):Qg(e,t)}const r8={transaction:t8};function n8(e){s8(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:s,mint:o,to:a,value:c}=e,u=[t,n,a??"0x",o?ie(o):"0x",c?ie(c):"0x",i?ie(i):"0x",s?"0x1":"0x",r??"0x"];return Mt(["0x7e",Hr(u)])}function i8(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function s8(e){const{from:t,to:r}=e;if(t&&!Ve(t))throw new dt({address:t});if(r&&!Ve(r))throw new dt({address:r})}const oi={contracts:Q5,formatters:e8,serializers:r8},o8=Bt({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}}}),a8=Bt({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}),Ri=1,c8=Bt({...oi,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:{...oi.contracts,disputeGameFactory:{[Ri]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Ri]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Ri]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Ri]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Ri}),Ni=11155111,u8=Bt({...oi,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:{...oi.contracts,disputeGameFactory:{[Ni]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Ni]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Ni]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Ni]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Ni}),f8=Bt({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}),d8=Bt({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}),l8=Bt({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}),h8=1,p8=Bt({id:21e6,name:"Corn",nativeCurrency:{decimals:18,name:"Bitcorn",symbol:"BTCN"},rpcUrls:{default:{http:["https://21000000.rpc.thirdweb.com"]}},blockExplorers:{default:{name:"Corn Explorer",url:"https://cornscan.io",apiUrl:"https://api.routescan.io/v2/network/mainnet/evm/21000000/etherscan/api"}},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:3228}},sourceId:h8}),y8=Bt({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}}}),m8=Bt({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}),b8=Bt({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}),no=1,g8=Bt({...oi,id:130,name:"Unichain",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.unichain.org/"]}},blockExplorers:{default:{name:"Uniscan",url:"https://uniscan.xyz",apiUrl:"https://api.uniscan.xyz/api"}},contracts:{...oi.contracts,multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:0},disputeGameFactory:{[no]:{address:"0x2F12d621a16e2d3285929C9996f478508951dFe4"}},portal:{[no]:{address:"0x0bd48f6B86a26D3a217d0Fa6FfE2B491B956A7a2"}},l1StandardBridge:{[no]:{address:"0x81014F44b0a345033bB2b3B21C7a1A308B35fEeA"}}},sourceId:no}),w8={...b8,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},gy={id:3637,name:"Botanix",nativeCurrency:{name:"Botanix",symbol:"BOTX",decimals:18},blockExplorers:{default:{name:"Botanix Explorer",url:"https://botanixscan.io/"}},rpcUrls:{default:{http:["https://rpc.botanixlabs.com/"]}}},wy={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"]}}},vy={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"]}}},Pf={ethereum:y8,arbitrum:o8,ethereum_sepolia:w8,arbitrum_sepolia:a8,ethereum_localnet:we.EthereumLocalnet,arbitrum_localnet:we.ArbitrumLocalnet,base_sepolia:u8,base:c8,bera_testnet:d8,citrea_testnet:l8,bera:f8,monad_testnet:m8,hyperliquid_testnet:wy,hyperliquid:vy,unichain:g8,corn:p8,botanix:gy},_y=async(e,t)=>{var i,s,o;const r=Pf[e],n=await t.getChainId();if(r)try{if(r.id===n)return de({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const a=za({account:t.account,chain:r,transport:od(t.transport)});return de({message:"Switched chain",walletClient:a})}catch(a){if(v8(a))if(a.code===4902)try{await t.addChain({chain:r});const c=za({account:t.account,chain:r,transport:od(t.transport)});return de({message:"Added network",walletClient:c})}catch{return K("Failed to add network")}else if((s=(i=a.body)==null?void 0:i.method)!=null&&s.includes("wallet_switchEthereumChain")||(o=a.message)!=null&&o.includes("wallet_switchEthereumChain")){const c=za({account:t.account,chain:r,transport:f0()});return de({message:"Added network",walletClient:c})}else return K("Failed to switch network");else return K("Failed to switch network")}else return K("Chain not supported")},v8=e=>typeof e=="object"&&e!=null&&("code"in e||"message"in e||"body"in e),_8=[{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 xy{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 _y(t.source_swap.chain,this.wallet);if(r.error)return Z.Err(r.error);if(this.wallet=r.val.walletClient,!this.wallet.account)return Z.Err("No account found");const{create_order:n,source_swap:i}=t;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return Z.Err("Invalid order");const s=Z.with0x(n.secret_hash),o=BigInt(n.timelock),a=Z.with0x(i.redeemer),c=BigInt(i.amount),u=await this.getTokenAddress(t.source_swap.asset);return u.ok?we.isEvmNativeToken(t.source_swap.chain,u.val)?this._initiateOnNativeHTLC(s,o,c,a,t.source_swap.asset):this._initiateOnErc20HTLC(s,o,c,a,t.source_swap.asset,u.val,n.create_id):Z.Err(u.error)}async getTokenAddress(t){try{const n=await ka({address:Z.with0x(t),abi:Ol,client:this.wallet}).read.token();return Z.Ok(n)}catch(r){return Z.Err("Failed to get token address",String(r))}}async _initiateOnNativeHTLC(t,r,n,i,s){if(!this.wallet.account)return Z.Err("No account found");try{const a=await ka({address:Z.with0x(s),abi:_8,client:this.wallet}).write.initiate([i,r,n,t],{account:this.wallet.account,chain:this.wallet.chain,value:n});return Z.Ok(a)}catch(o){return Z.Err("Failed to initiate on native HTLC",String(o))}}async _initiateOnErc20HTLC(t,r,n,i,s,o,a){if(!this.wallet.account)return Z.Err("No account found");try{const c=await this.auth.getAuthHeaders();if(c.error)return Z.Err(c.error);const u=ka({address:Z.with0x(s),abi:Ol,client:this.wallet}),f=await Z.checkAllowanceAndApprove(Number(n),o,s,this.wallet);if(f.error)return Z.Err(f.error);const d=await u.read.eip712Domain(),y=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:d[1],version:d[2],chainId:Number(d[3]),verifyingContract:d[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"},w=await lr.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:a,signature:y,perform_on:"Source"}),headers:p});if(w.error)return Z.Err(w.error);const b=await Z.waitForTransactionReceipt(this.wallet,w.result);return b.val&&b.val.status==="success"?Z.Ok(w.result?w.result:"Initiate hash not found"):Z.Err("Init failed: Transaction receipt not successful")}catch(c){return console.log("init error :",c),Z.Err(String(c))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return Z.Err(n.error);const i=await lr.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:Qr(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});if(i.error)return Z.Err(i.error);const s=Pf[t.destination_swap.chain],a=await zv({chain:s,transport:f0()}).waitForTransactionReceipt({hash:i.result,confirmations:1,timeout:3e5});return a&&a.status==="success"?Z.Ok(i.result?i.result:"Redeem hash not found"):Z.Err("Redeem failed: Transaction receipt not successful")}catch(n){return Z.Err(String(n))}}async refund(){return Z.Err("Refund not supported")}}const Ey=[{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"}]}],x8=async(e,t,r,n,i)=>{try{const s=await pu(e.address,t,r,i);if(s.error)return K(s.error);if(s.val>=n)return de("Allowance already approved");const a=qe.cairo.uint256(BigInt(n)),c=await e.execute([{contractAddress:tn(t),entrypoint:"approve",calldata:[tn(r),a.low,a.high]}]);await i.waitForTransaction(c.transaction_hash,{retryInterval:3e3,successStates:[qe.TransactionExecutionStatus.SUCCEEDED]}),await Z.sleep(2e3);for(let u=0;u<20;u++){const f=await pu(e.address,t,r,i);if(f.error)return K(f.error);if(f.val>=n)return de(c.transaction_hash);await Z.sleep(2e3)}return K("Allowance not approved after transaction.")}catch(s){return K(`Failed to check or approve allowance: ${s instanceof Error?s.message:String(s)}`)}},pu=async(e,t,r,n)=>{try{const s=await new qe.Contract(Ey,tn(t),n).call("allowance",[tn(e),tn(r)]);return de(BigInt((s==null?void 0:s.toString())||"0"))}catch(i){return K(`Failed to check allowance: ${i instanceof Error?i.message:String(i)}`)}},E8=async(e,t,r,n,i)=>{const s=await pu(e,t,r,n);return s.error?K(s.error):de(s.val>=i)},Ay=[{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"}]}],A8={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 Sy{constructor(t,r,n,i){this.url=t instanceof Z.Url?t:new Z.Url(t),this.account=r,this.starknetProvider=new qe.RpcProvider({nodeUrl:i||ps[n].nodeUrl}),this.chainId=ps[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 K("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n;if(!s||!i||!r.secret_hash||!r.timelock)return K("Invalid order");try{const o=new qe.Contract(Ay,t.source_swap.asset,this.account),a=await(o==null?void 0:o.token()),c=qe.num.toHex(a),u=await E8(this.account.address,c,n.asset,this.starknetProvider,BigInt(s));return u.error?K(u.error):u.val?this.initiateRelay(t):this.approveAndInitiate(c,t)}catch(o){return K(String(o))}}async approveAndInitiate(t,r){const{create_order:n,source_swap:i}=r,{redeemer:s,amount:o}=i,{secret_hash:a,timelock:c}=n,u=i.asset;try{const f=qe.cairo.uint256(BigInt(o)),d={contractAddress:tn(t),entrypoint:"approve",calldata:[u,f.low,f.high]},y=qe.cairo.uint256(o),p={contractAddress:tn(u),entrypoint:"initiate",calldata:[s,c.toString(),y.low.toString(),y.high.toString(),...Z.hexToU32Array(a)]},w=await this.account.execute([d,p]);return await this.starknetProvider.waitForTransaction(w.transaction_hash,{retryInterval:2e3,successStates:[qe.TransactionExecutionStatus.SUCCEEDED]}),de(w.transaction_hash)}catch(f){return K(`Failed to approve and initiate: ${String(f)}`)}}async initiateRelay(t){const{create_order:r,source_swap:n}=t,{redeemer:i,amount:s}=n,a={domain:{name:"HTLC",version:qe.shortString.encodeShortString("1"),chainId:this.chainId,revision:qe.TypedDataRevision.ACTIVE},primaryType:"Initiate",types:A8,message:{redeemer:i,amount:qe.cairo.uint256(s),timelock:r.timelock,secretHash:Z.hexToU32Array(r.secret_hash)}};try{const c=await this.account.signMessage(a),u=h_(c);if(u.error)return K(u.error);const f=await lr.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?K(f.error):f.result?de(f.result):K("Init: No result found")}catch(c){return K(`Failed to initiate relayer: ${String(c)}`)}}async redeem(t,r){try{const n=await lr.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?K(n.error):n.result?de(n.result):K("Redeem: No result found")}catch(n){return K(String(n))}}async refund(){return K("Refund is taken care of by the relayer")}}class Bf extends Z.EventBroker{constructor(t){super(),this.environment=Z.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new fx;const{api:r,environment:n}=Qc(t.environment);if(this.environment=n,this._api=r,typeof t.digestKey=="string"){const s=Z.DigestKey.from(t.digestKey);if(!s.ok)throw new Error(s.error);this._digestKey=s.val}else this._digestKey=t.digestKey;this._quote=t.quote??new Np(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._secretManager=t.secretManager??ws.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new ux,this._blockNumberFetcher=t.blockNumberFetcher??new Rp(this._api.info,this.environment);const i=new Kn.BitcoinProvider(d_(this.environment));this._btcWallet=Kn.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,i)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const s=Z.DigestKey.from(t.digestKey);if(!s.ok)throw new Error(s.error);r=s.val}else r=t.digestKey;const{api:n}=Qc(t.environment);if(!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new xy(n.evmRelay,t.wallets.evm,Z.Siwe.fromDigestKey(new Z.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new Sy(n.starknetRelay,t.wallets.starknet,t.environment===Z.Environment.MAINNET?Z.Network.MAINNET:Z.Network.TESTNET):void 0};return new Bf({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return K(r.error);const{sendAddress:n,receiveAddress:i,timelock:s}=r.val,o=Date.now().toString(),a=await this._secretManager.generateSecret(o);if(a.error)return K(a.error);const{strategyId:c,btcAddress:u}=t.additionalData,f={strategy_id:c,...u&&{bitcoin_optional_recipient:u}},d={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:o,timelock:s,secret_hash:Qr(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:f,affiliate_fees:this.withDefaultAffiliateFees(t.affiliateFee)},y=await this._quote.getAttestedQuote(d);if(y.error)return K(y.error);const p=await this._orderbook.createOrder(y.val,this.auth);if(p.error)return K(p.error);const w=await this.pollOrder(p.val);return w.error?K(w.error):de(w.val)}withDefaultAffiliateFees(t){return(t??[]).map(r=>({fee:r.fee,address:r.address,chain:r.chain??$d.chain,asset:r.asset??$d.asset}))}async validateAndFillParams(t){if(!t.additionalData.strategyId)return K("StrategyId is required");if(!t.fromAsset||!t.toAsset)return K("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return K("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 K("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return K(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return K(n.error);if(r<n)return K("Send amount should be greater than receive amount");const i=we.getTimeLock(t.fromAsset.chain);if(!i)return K("Unsupported chain for timelock");if((we.isBitcoin(t.fromAsset.chain)||we.isBitcoin(t.toAsset.chain))&&!t.additionalData.btcAddress)return K("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const s=await this.getAddresses(t.fromAsset.chain);if(s.error)return K(s.error);const o=await this.getAddresses(t.toAsset.chain);return o.error?K(o.error):de({sendAddress:s.val,receiveAddress:o.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(we.getBlockchainType(t)){case we.BlockchainType.EVM:return this._evmHTLC?de(this._evmHTLC.htlcActorAddress):K("Please provide evmHTLC when initializing garden");case we.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!u_(i)?K("Invalid btc public key"):de(Nr(i))}case we.BlockchainType.Starknet:return this._starknetHTLC?de(this._starknetHTLC.htlcActorAddress):K("Please provide starknetHTLC when initializing garden");default:return K("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return K("Invalid amount ",t);const r=new Iy(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?K("Invalid amount ",t):de(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 K(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return de(r.val);r=await this._orderbook.getOrder(t,!0)}return K(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error&&(this.emit("onPendingOrdersChanged",n.val),r.data.length!==0))for(let i=0;i<n.val.length;i++){const s=n.val[i],o=df(s.status);if(we.isBitcoin(s.source_swap.chain)&&s.status===Se.InitiateDetected){const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");continue}await this.postRefundSACP(s,a)}switch(o){case Fe.Redeem:{const a=await this._secretManager.generateSecret(s.create_order.nonce);if(a.error){this.emit("error",s,a.error);return}switch(we.getBlockchainType(s.destination_swap.chain)){case we.BlockchainType.EVM:{await this.evmRedeem(s,a.val.secret);break}case we.BlockchainType.Bitcoin:{const c=this.btcWallet;if(!c){this.emit("error",s,"BTC wallet not found");return}await this.btcRedeem(c,s,a.val.secret);break}case we.BlockchainType.Starknet:{await this.starknetRedeem(s,a.val.secret);break}default:this.emit("error",s,"Unsupported chain: "+s.destination_swap.chain)}break}case Fe.Refund:{switch(we.getBlockchainType(s.source_swap.chain)){case we.BlockchainType.EVM:{this.emit("error",s,"EVM refund is automatically done by relay service");break}case we.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",s,"BTC wallet not found");return}await this.btcRefund(a,s);break}case we.BlockchainType.Starknet:{this.emit("error",s,"Starknet refund is automatically done by relay service");break}default:this.emit("error",s,"Unsupported chain: "+s.source_swap.chain)}break}}}},"pending",{per_page:500})}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Fe.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,Fe.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Fe.Redeem,i.val),this.emit("success",t,Fe.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Fe.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,Fe.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Fe.Redeem,i.val),this.emit("success",t,Fe.Redeem,i.val))}async btcRedeem(t,r,n){var a,c;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),s=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!s){this.emit("error",r,"Failed to get initiate_tx_hash");return}let o=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==s)o=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),o=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const u=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let f=!1;for(const d of u.vin)if(d.txid===s){f=!0;break}if(f){this.emit("log",r.create_order.create_id,"already a valid redeem");let d=0;try{const[y]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);y!==0&&(d=y)}catch{d=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:d,redeemTxHash:r.destination_swap.redeem_tx_hash});return}o=!0}catch(u){if(u.message.includes("Transaction not found"))o=!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 Di.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Nr(r.destination_swap.initiator),Nr(r.destination_swap.redeemer),r.destination_swap.timelock,o?[s]:[])).getRedeemHex(Qr(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient),d=await this.broadcastRedeemTx(f,r.create_order.create_id);if(d.error||!d.val){this.emit("error",r,d.error||"Failed to broadcast redeem tx");return}o?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,d.val)):this.emit("success",r,Fe.Redeem,d.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:s,redeemedAt:Date.now(),redeemTxHash:d.val})}catch(u){console.log("error",u),this.emit("error",r,"Failed btc redeem: "+u)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Fe.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const s=await(await Di.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Nr(r.source_swap.initiator),Nr(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,Fe.Refund,s),this.emit("success",r,Fe.Refund,s)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await Di.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,Nr(t.source_swap.initiator),Nr(t.source_swap.redeemer),t.source_swap.timelock),s=t.create_order.additional_data.bitcoin_optional_recipient;if(s)try{const o=await i.generateInstantRefundSACP(s);if(!this._api)return;const a=new Z.Url(this._api.orderbook).endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await lr.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:o})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(o){this.emit("error",t,"Failed to generate and post SACP: "+o);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return de([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return K(r.error);const n=[];for(let s=0;s<t.length;s++){const o=t[s];if(lp(o))continue;const a=o.source_swap.chain,c=o.destination_swap.chain,u=r==null?void 0:r.val[a],f=r==null?void 0:r.val[c];if(!u||!f){this.emit("error",o,"Error while fetching CurrentBlockNumbers");continue}const d=ff(o,u,f);n.push({...o,status:d})}return de(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return K("API not found");const n=new Z.Url(this._api.evmRelay).endpoint("/bitcoin/redeem "),i=await this._auth.getAuthHeaders(),o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return o.status==="Ok"&&o.result?de(o.result):K(o.error)}catch(n){return K("Failed to broadcast redeem tx: "+n)}}}class S8{constructor(t,r,n){this.callData=new qe.CallData(Ey),this.account=t,this.starknetProvider=new qe.RpcProvider({nodeUrl:r||(n?ps[n].nodeUrl:ps.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 qe.Contract(Ay,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=qe.num.toHex(n),s=qe.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await x8(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.starknetProvider);if(a.error)return K(a.error)}catch(a){return K(`Allowance check failed: ${a}`)}const o=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),s.low,s.high,...Z.hexToU32Array(t.create_order.secret_hash)]});if(!o.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return de(o.transaction_hash)}catch(r){return K(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,s=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:qe.CallData.compile({swap_id:i,secret:Z.hexToU32Array(r)})});return s.transaction_hash?de(s.transaction_hash):K("Failed to redeem HTLC transaction")}catch{return K("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?de(i.transaction_hash):K("Failed to refund HTLC transaction")}catch{return K("HTLC Refund Error")}}}exports.API=uo;exports.BaseError=H;exports.BlockNumberFetcher=Rp;exports.EvmRelay=xy;exports.Garden=Bf;exports.HttpRequestError=Dn;exports.OrderActions=Fe;exports.OrderStatus=Se;exports.ParseOrderStatus=ff;exports.ParseSwapStatus=ru;exports.Quote=Np;exports.STARKNET_CONFIG=ps;exports.SecretManager=ws;exports.StarknetHTLC=S8;exports.StarknetRelay=Sy;exports.SwapStatus=Pe;exports.botanixMainnet=gy;exports.call=Is;exports.concat=Jt;exports.constructOrderPair=tu;exports.decodeErrorResult=Eh;exports.encodeAbiParameters=xr;exports.evmToViemChainMap=Pf;exports.filterDeadlineExpiredOrders=y_;exports.getUrl=$o;exports.hyperliquid=vy;exports.hyperliquidTestnet=wy;exports.isAddressEqual=Bs;exports.isExpired=ys;exports.isHex=$t;exports.localBatchGatewayRequest=dg;exports.localBatchGatewayUrl=zu;exports.parseAction=p_;exports.parseActionFromStatus=df;exports.resolveApiConfig=Qc;exports.stringify=Ue;exports.switchOrAddNetwork=_y;exports.toXOnly=Nr;exports.validateBTCAddress=f_;
|