@gardenfi/core 2.2.1 → 2.3.0
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-l_tRzCaI.cjs → ccip-Bf6sMWsl.cjs} +1 -1
- package/dist/{ccip-BkdyF3_3.js → ccip-Nj9FMoDj.js} +1 -1
- package/dist/index-DVTNtaWz.cjs +99 -0
- package/dist/index-rQk9wiZU.js +24327 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +37 -34
- package/dist/src/index.d.ts +5 -1
- package/dist/src/lib/bitcoin/API.d.ts +4 -0
- package/dist/src/lib/bitcoin/ASConfig.d.ts +19 -0
- package/dist/src/lib/bitcoin/errors.d.ts +16 -0
- package/dist/src/lib/bitcoin/htlc.d.ts +2 -1
- package/dist/src/lib/bitcoin/htlcScript.d.ts +7 -0
- package/dist/src/lib/bitcoin/interface.d.ts +6 -0
- package/dist/src/lib/bitcoin/paths.d.ts +7 -0
- package/dist/src/lib/bitcoin/provider/provider.d.ts +118 -0
- package/dist/src/lib/bitcoin/provider/provider.interface.d.ts +99 -0
- package/dist/src/lib/bitcoin/script.d.ts +6 -0
- package/dist/src/lib/bitcoin/sig.d.ts +20 -0
- package/dist/src/lib/bitcoin/utils.d.ts +8 -0
- package/dist/src/lib/bitcoin/wallet/abstractWallet.d.ts +145 -0
- package/dist/src/lib/bitcoin/wallet/baseWallet.d.ts +13 -0
- package/dist/src/lib/bitcoin/wallet/wallet.d.ts +103 -0
- package/dist/src/lib/bitcoin/wallet/wallet.interface.d.ts +79 -0
- package/dist/src/lib/blockNumberFetcher/blockNumber.d.ts +1 -2
- package/dist/src/lib/evm/htlc/evmHTLC.d.ts +1 -1
- package/dist/src/lib/evm/htlc/evmHTLC.types.d.ts +2 -2
- package/dist/src/lib/evm/relay/evmRelay.types.d.ts +1 -2
- package/dist/src/lib/garden/garden.d.ts +2 -3
- package/dist/src/lib/garden/garden.types.d.ts +3 -4
- package/dist/src/lib/htlc.interface.d.ts +7 -0
- package/dist/src/lib/identifier.d.ts +19 -0
- package/dist/src/lib/quote/quote.d.ts +7 -10
- package/dist/src/lib/quote/quote.types.d.ts +19 -10
- package/dist/src/lib/secretManager/secretManager.d.ts +5 -5
- package/dist/src/lib/secretManager/secretManager.types.d.ts +1 -2
- package/dist/src/lib/solana/htlc/ISolanaHTLC.d.ts +1 -1
- package/dist/src/lib/solana/htlc/solanaHTLC.d.ts +1 -1
- package/dist/src/lib/solana/relayer/solanaRelay.d.ts +1 -2
- package/dist/src/lib/starknet/checkAllowanceAndApprove.d.ts +1 -1
- package/dist/src/lib/starknet/htlc/starknetHTLC.d.ts +1 -2
- package/dist/src/lib/starknet/relay/starknetRelay.d.ts +1 -2
- package/dist/src/lib/starknet/starknetHTLC.types.d.ts +1 -1
- package/dist/src/lib/switchOrAddNetwork.d.ts +1 -1
- package/dist/src/lib/utils.d.ts +7 -2
- package/package.json +9 -7
- package/dist/index-eHNvzW2C.js +0 -26591
- package/dist/index-lHPQc7tc.cjs +0 -84
package/dist/index-lHPQc7tc.cjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";var rg=Object.defineProperty;var ng=(e,t,r)=>t in e?rg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Rn=(e,t,r)=>ng(e,typeof t!="symbol"?t+"":t,r);const U=require("@catalogfi/utils"),be=require("@gardenfi/orderbook"),ce=require("@gardenfi/utils"),cn=require("@catalogfi/wallets"),Bp=require("varuint-bitcoin"),ig=require("tiny-secp256k1"),Ip=require("bitcoinjs-lib"),og=require("bignumber.js"),qe=require("starknet"),jt=require("@coral-xyz/anchor");function bf(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 Rl=bf(Bp),hn=bf(ig),ge=bf(Ip);var Te=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Te||{});const sg="1.0.8";let At=class vu extends Error{constructor(t,r={}){var s;const n=r.cause instanceof vu?r.cause.details:(s=r.cause)!=null&&s.message?r.cause.message:r.details,i=r.cause instanceof vu&&r.cause.docsPath||r.docsPath,o=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...i?[`Docs: https://abitype.dev${i}`]:[],...n?[`Details: ${n}`]:[],`Version: abitype@${sg}`].join(`
|
|
2
|
-
`);super(o),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),r.cause&&(this.cause=r.cause),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.shortMessage=t}};function Or(e,t){const r=e.exec(t);return r==null?void 0:r.groups}const kp=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Op=/^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)?$/,Rp=/^\(.+?\).*?$/,Cl=/^tuple(?<array>(\[(\d*)\])*)$/;function _u(e){let t=e.type;if(Cl.test(e.type)&&"components"in e){t="(";const r=e.components.length;for(let i=0;i<r;i++){const o=e.components[i];t+=_u(o),i<r-1&&(t+=", ")}const n=Or(Cl,e.type);return t+=`)${(n==null?void 0:n.array)??""}`,_u({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Pi(e){let t="";const r=e.length;for(let n=0;n<r;n++){const i=e[n];t+=_u(i),n!==r-1&&(t+=", ")}return t}function _s(e){var t;return e.type==="function"?`function ${e.name}(${Pi(e.inputs)})${e.stateMutability&&e.stateMutability!=="nonpayable"?` ${e.stateMutability}`:""}${(t=e.outputs)!=null&&t.length?` returns (${Pi(e.outputs)})`:""}`:e.type==="event"?`event ${e.name}(${Pi(e.inputs)})`:e.type==="error"?`error ${e.name}(${Pi(e.inputs)})`:e.type==="constructor"?`constructor(${Pi(e.inputs)})${e.stateMutability==="payable"?" payable":""}`:e.type==="fallback"?`fallback() external${e.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const Cp=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function ag(e){return Cp.test(e)}function cg(e){return Or(Cp,e)}const Np=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function ug(e){return Np.test(e)}function fg(e){return Or(Np,e)}const $p=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function lg(e){return $p.test(e)}function dg(e){return Or($p,e)}const Fp=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function gf(e){return Fp.test(e)}function hg(e){return Or(Fp,e)}const Up=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function pg(e){return Up.test(e)}function yg(e){return Or(Up,e)}const Lp=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function mg(e){return Lp.test(e)}function bg(e){return Or(Lp,e)}const gg=/^receive\(\) external payable$/;function wg(e){return gg.test(e)}const vg=new Set(["indexed"]),Eu=new Set(["calldata","memory","storage"]);class _g extends At{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 Eg extends At{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 xg extends At{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 Ag extends At{constructor({param:t}){super("Invalid ABI parameter.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class Sg extends At{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 Pg extends At{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 Tg extends At{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 Bg extends At{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 yi extends At{constructor({signature:t,type:r}){super(`Invalid ${r} signature.`,{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class Ig extends At{constructor({signature:t}){super("Unknown signature.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class kg extends At{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 Og extends At{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 Rg extends At{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 Cg(e,t,r){let n="";if(r)for(const i of Object.entries(r)){if(!i)continue;let o="";for(const s of i[1])o+=`[${s.type}${s.name?`:${s.name}`:""}]`;n+=`(${i[0]}{${o}})`}return t?`${t}:${e}${n}`:e}const Ia=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 xu(e,t={}){if(lg(e))return Ng(e,t);if(ug(e))return $g(e,t);if(ag(e))return Fg(e,t);if(pg(e))return Ug(e,t);if(mg(e))return Lg(e);if(wg(e))return{type:"receive",stateMutability:"payable"};throw new Ig({signature:e})}function Ng(e,t={}){const r=dg(e);if(!r)throw new yi({signature:e,type:"function"});const n=Dt(r.parameters),i=[],o=n.length;for(let a=0;a<o;a++)i.push(pn(n[a],{modifiers:Eu,structs:t,type:"function"}));const s=[];if(r.returns){const a=Dt(r.returns),c=a.length;for(let f=0;f<c;f++)s.push(pn(a[f],{modifiers:Eu,structs:t,type:"function"}))}return{name:r.name,type:"function",stateMutability:r.stateMutability??"nonpayable",inputs:i,outputs:s}}function $g(e,t={}){const r=fg(e);if(!r)throw new yi({signature:e,type:"event"});const n=Dt(r.parameters),i=[],o=n.length;for(let s=0;s<o;s++)i.push(pn(n[s],{modifiers:vg,structs:t,type:"event"}));return{name:r.name,type:"event",inputs:i}}function Fg(e,t={}){const r=cg(e);if(!r)throw new yi({signature:e,type:"error"});const n=Dt(r.parameters),i=[],o=n.length;for(let s=0;s<o;s++)i.push(pn(n[s],{structs:t,type:"error"}));return{name:r.name,type:"error",inputs:i}}function Ug(e,t={}){const r=yg(e);if(!r)throw new yi({signature:e,type:"constructor"});const n=Dt(r.parameters),i=[],o=n.length;for(let s=0;s<o;s++)i.push(pn(n[s],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:r.stateMutability??"nonpayable",inputs:i}}function Lg(e){const t=bg(e);if(!t)throw new yi({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}const Mg=/^(?<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$_]*))?$/,Hg=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Dg=/^u?int$/;function pn(e,t){var l,p;const r=Cg(e,t==null?void 0:t.type,t==null?void 0:t.structs);if(Ia.has(r))return Ia.get(r);const n=Rp.test(e),i=Or(n?Hg:Mg,e);if(!i)throw new Ag({param:e});if(i.name&&qg(i.name))throw new Sg({param:e,name:i.name});const o=i.name?{name:i.name}:{},s=i.modifier==="indexed"?{indexed:!0}:{},a=(t==null?void 0:t.structs)??{};let c,f={};if(n){c="tuple";const h=Dt(i.type),m=[],b=h.length;for(let w=0;w<b;w++)m.push(pn(h[w],{structs:a}));f={components:m}}else if(i.type in a)c="tuple",f={components:a[i.type]};else if(Dg.test(i.type))c=`${i.type}256`;else if(c=i.type,(t==null?void 0:t.type)!=="struct"&&!Mp(c))throw new xg({type:c});if(i.modifier){if(!((p=(l=t==null?void 0:t.modifiers)==null?void 0:l.has)!=null&&p.call(l,i.modifier)))throw new Pg({param:e,type:t==null?void 0:t.type,modifier:i.modifier});if(Eu.has(i.modifier)&&!zg(c,!!i.array))throw new Tg({param:e,type:t==null?void 0:t.type,modifier:i.modifier})}const u={type:`${c}${i.array??""}`,...o,...s,...f};return Ia.set(r,u),u}function Dt(e,t=[],r="",n=0){const i=e.trim().length;for(let o=0;o<i;o++){const s=e[o],a=e.slice(o+1);switch(s){case",":return n===0?Dt(a,[...t,r.trim()]):Dt(a,t,`${r}${s}`,n);case"(":return Dt(a,t,`${r}${s}`,n+1);case")":return Dt(a,t,`${r}${s}`,n-1);default:return Dt(a,t,`${r}${s}`,n)}}if(r==="")return t;if(n!==0)throw new Rg({current:r,depth:n});return t.push(r.trim()),t}function Mp(e){return e==="address"||e==="bool"||e==="function"||e==="string"||kp.test(e)||Op.test(e)}const jg=/^(?: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 qg(e){return e==="address"||e==="bool"||e==="function"||e==="string"||e==="tuple"||kp.test(e)||Op.test(e)||jg.test(e)}function zg(e,t){return t||e==="bytes"||e==="string"||e==="tuple"}function Hp(e){const t={},r=e.length;for(let s=0;s<r;s++){const a=e[s];if(!gf(a))continue;const c=hg(a);if(!c)throw new yi({signature:a,type:"struct"});const f=c.properties.split(";"),u=[],l=f.length;for(let p=0;p<l;p++){const m=f[p].trim();if(!m)continue;const b=pn(m,{type:"struct"});u.push(b)}if(!u.length)throw new kg({signature:a});t[c.name]=u}const n={},i=Object.entries(t),o=i.length;for(let s=0;s<o;s++){const[a,c]=i[s];n[a]=Dp(c,t)}return n}const Gg=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function Dp(e,t,r=new Set){const n=[],i=e.length;for(let o=0;o<i;o++){const s=e[o];if(Rp.test(s.type))n.push(s);else{const c=Or(Gg,s.type);if(!(c!=null&&c.type))throw new Bg({abiParameter:s});const{array:f,type:u}=c;if(u in t){if(r.has(u))throw new Og({type:u});n.push({...s,type:`tuple${f??""}`,components:Dp(t[u]??[],t,new Set([...r,u]))})}else if(Mp(u))n.push(s);else throw new Eg({type:u})}}return n}function jp(e){const t=Hp(e),r=[],n=e.length;for(let i=0;i<n;i++){const o=e[i];gf(o)||r.push(xu(o,t))}return r}function Nl(e){let t;if(typeof e=="string")t=xu(e);else{const r=Hp(e),n=e.length;for(let i=0;i<n;i++){const o=e[i];if(!gf(o)){t=xu(o,r);break}}}if(!t)throw new _g({signature:e});return t}function ue(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const i=e[r];return typeof i=="function"?i:o=>t(e,o)}function qt(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new i1(e.type);return`${e.name}(${Cs(e.inputs,{includeName:t})})`}function Cs(e,{includeName:t=!1}={}){return e?e.map(r=>Vg(r,{includeName:t})).join(t?", ":","):""}function Vg(e,{includeName:t}){return e.type.startsWith("tuple")?`(${Cs(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}function zt(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Oe(e){return zt(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const qp="2.31.6";let Ti={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${qp}`},X=class Au extends Error{constructor(t,r={}){var a;const n=(()=>{var c;return r.cause instanceof Au?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof Au&&r.cause.docsPath||r.docsPath,o=(a=Ti.getDocsUrl)==null?void 0:a.call(Ti,{...r,docsPath:i}),s=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...o?[`Docs: ${o}`]:[],...n?[`Details: ${n}`]:[],...Ti.version?[`Version: ${Ti.version}`]:[]].join(`
|
|
3
|
-
`);super(s,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=qp}walk(t){return zp(this,t)}};function zp(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?zp(e.cause,t):t?null:e}class Wg extends X{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 $l extends X{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 Gp extends X{constructor({data:t,params:r,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join(`
|
|
6
|
-
`),{metaMessages:[`Params: (${Cs(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 Po extends X{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class Kg extends X{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 Yg extends X{constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${Oe(r)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class Zg extends X{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 Xg extends X{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 Fl extends X{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 Vp extends X{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 Jg extends X{constructor({docsPath:t}){super("Cannot extract event signature from empty topics.",{docsPath:t,name:"AbiEventSignatureEmptyTopicsError"})}}class Wp extends X{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 Ul extends X{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 Jn extends X{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 Kp extends X{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 Qg extends X{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 e1 extends X{constructor(t,r){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${t.type}\` in \`${qt(t.abiItem)}\`, and`,`\`${r.type}\` in \`${qt(r.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}let t1=class extends X{constructor({expectedSize:t,givenSize:r}){super(`Expected bytes${t}, got bytes${r}.`,{name:"BytesSizeMismatchError"})}};class Zi extends X{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: (${Cs(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 Ns extends X{constructor({abiItem:t,param:r}){super([`Expected a topic for indexed event parameter${r.name?` "${r.name}"`:""} on event "${qt(t,{includeName:!0})}".`].join(`
|
|
18
|
-
`),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t}}class r1 extends X{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 n1 extends X{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 Yp=class extends X{constructor(t){super([`Value "${t}" is not a valid array.`].join(`
|
|
21
|
-
`),{name:"InvalidArrayError"})}};class i1 extends X{constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(`
|
|
22
|
-
`),{name:"InvalidDefinitionTypeError"})}}class o1 extends X{constructor(t){super(`Filter type "${t}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}let Zp=class extends X{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}},Xp=class extends X{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 Ll extends X{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 mi(e,{dir:t,size:r=32}={}){return typeof e=="string"?zr(e,{dir:t,size:r}):s1(e,{dir:t,size:r})}function zr(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Xp({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function s1(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Xp({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const o=t==="right";n[o?i:r-i-1]=e[o?i:e.length-i-1]}return n}let Jp=class extends X{constructor({max:t,min:r,signed:n,size:i,value:o}){super(`Number "${o}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}};class a1 extends X{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 c1 extends X{constructor(t){super(`Hex value "${t}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let u1=class extends X{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}};function Nt(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 Wt(e,{size:t}){if(Oe(e)>t)throw new u1({givenSize:Oe(e),maxSize:t})}function ze(e,t={}){const{signed:r}=t;t.size&&Wt(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,o=(1n<<BigInt(i)*8n-1n)-1n;return n<=o?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function f1(e,t={}){let r=e;if(t.size&&(Wt(r,{size:t.size}),r=Nt(r)),Nt(r)==="0x00")return!1;if(Nt(r)==="0x01")return!0;throw new c1(r)}function $t(e,t={}){return Number(ze(e,t))}const l1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function nt(e,t={}){return typeof e=="number"||typeof e=="bigint"?ne(e,t):typeof e=="string"?Qn(e,t):typeof e=="boolean"?Qp(e,t):Le(e,t)}function Qp(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Wt(r,{size:t.size}),mi(r,{size:t.size})):r}function Le(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=l1[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Wt(n,{size:t.size}),mi(n,{dir:"right",size:t.size})):n}function ne(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let o;n?r?o=(1n<<BigInt(n)*8n-1n)-1n:o=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(o=BigInt(Number.MAX_SAFE_INTEGER));const s=typeof o=="bigint"&&r?-o-1n:0;if(o&&i>o||i<s){const c=typeof e=="bigint"?"n":"";throw new Jp({max:o?`${o}${c}`:void 0,min:`${s}${c}`,signed:r,size:n,value:`${e}${c}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?mi(a,{size:n}):a}const d1=new TextEncoder;function Qn(e,t={}){const r=d1.encode(e);return Le(r,t)}const h1=new TextEncoder;function bi(e,t={}){return typeof e=="number"||typeof e=="bigint"?y1(e,t):typeof e=="boolean"?p1(e,t):zt(e)?Gt(e,t):un(e,t)}function p1(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Wt(r,{size:t.size}),mi(r,{size:t.size})):r}const hr={zero:48,nine:57,A:65,F:70,a:97,f:102};function Ml(e){if(e>=hr.zero&&e<=hr.nine)return e-hr.zero;if(e>=hr.A&&e<=hr.F)return e-(hr.A-10);if(e>=hr.a&&e<=hr.f)return e-(hr.a-10)}function Gt(e,t={}){let r=e;t.size&&(Wt(r,{size:t.size}),r=mi(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,o=new Uint8Array(i);for(let s=0,a=0;s<i;s++){const c=Ml(n.charCodeAt(a++)),f=Ml(n.charCodeAt(a++));if(c===void 0||f===void 0)throw new X(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);o[s]=c*16+f}return o}function y1(e,t){const r=ne(e,t);return Gt(r)}function un(e,t={}){const r=h1.encode(e);return typeof t.size=="number"?(Wt(r,{size:t.size}),mi(r,{dir:"right",size:t.size})):r}const Vo=BigInt(2**32-1),Hl=BigInt(32);function m1(e,t=!1){return t?{h:Number(e&Vo),l:Number(e>>Hl&Vo)}:{h:Number(e>>Hl&Vo)|0,l:Number(e&Vo)|0}}function b1(e,t=!1){const r=e.length;let n=new Uint32Array(r),i=new Uint32Array(r);for(let o=0;o<r;o++){const{h:s,l:a}=m1(e[o],t);[n[o],i[o]]=[s,a]}return[n,i]}const g1=(e,t,r)=>e<<r|t>>>32-r,w1=(e,t,r)=>t<<r|e>>>32-r,v1=(e,t,r)=>t<<r-32|e>>>64-r,_1=(e,t,r)=>e<<r-32|t>>>64-r,Cn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function wf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Xi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Vt(e,...t){if(!wf(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 E1(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Xi(e.outputLen),Xi(e.blockLen)}function ei(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 e0(e,t){Vt(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function x1(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Kr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ka(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Jt(e,t){return e<<32-t|e>>>t}function Wo(e,t){return e<<t|e>>>32-t>>>0}const A1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function S1(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function P1(e){for(let t=0;t<e.length;t++)e[t]=S1(e[t]);return e}const Dl=A1?e=>e:P1,t0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",T1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ji(e){if(Vt(e),t0)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=T1[e[r]];return t}const pr={_0:48,_9:57,A:65,F:70,a:97,f:102};function jl(e){if(e>=pr._0&&e<=pr._9)return e-pr._0;if(e>=pr.A&&e<=pr.F)return e-(pr.A-10);if(e>=pr.a&&e<=pr.f)return e-(pr.a-10)}function vf(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(t0)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,o=0;i<r;i++,o+=2){const s=jl(e.charCodeAt(o)),a=jl(e.charCodeAt(o+1));if(s===void 0||a===void 0){const c=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function B1(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function $s(e){return typeof e=="string"&&(e=B1(e)),Vt(e),e}function nn(...e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];Vt(i),t+=i.length}const r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){const o=e[n];r.set(o,i),i+=o.length}return r}let _f=class{};function Fs(e){const t=n=>e().update($s(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function I1(e=32){if(Cn&&typeof Cn.getRandomValues=="function")return Cn.getRandomValues(new Uint8Array(e));if(Cn&&typeof Cn.randomBytes=="function")return Uint8Array.from(Cn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const k1=BigInt(0),Bi=BigInt(1),O1=BigInt(2),R1=BigInt(7),C1=BigInt(256),N1=BigInt(113),r0=[],n0=[],i0=[];for(let e=0,t=Bi,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],r0.push(2*(5*n+r)),n0.push((e+1)*(e+2)/2%64);let i=k1;for(let o=0;o<7;o++)t=(t<<Bi^(t>>R1)*N1)%C1,t&O1&&(i^=Bi<<(Bi<<BigInt(o))-Bi);i0.push(i)}const o0=b1(i0,!0),$1=o0[0],F1=o0[1],ql=(e,t,r)=>r>32?v1(e,t,r):g1(e,t,r),zl=(e,t,r)=>r>32?_1(e,t,r):w1(e,t,r);function U1(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let s=0;s<10;s++)r[s]=e[s]^e[s+10]^e[s+20]^e[s+30]^e[s+40];for(let s=0;s<10;s+=2){const a=(s+8)%10,c=(s+2)%10,f=r[c],u=r[c+1],l=ql(f,u,1)^r[a],p=zl(f,u,1)^r[a+1];for(let h=0;h<50;h+=10)e[s+h]^=l,e[s+h+1]^=p}let i=e[2],o=e[3];for(let s=0;s<24;s++){const a=n0[s],c=ql(i,o,a),f=zl(i,o,a),u=r0[s];i=e[u],o=e[u+1],e[u]=c,e[u+1]=f}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)r[a]=e[s+a];for(let a=0;a<10;a++)e[s+a]^=~r[(a+2)%10]&r[(a+4)%10]}e[0]^=$1[n],e[1]^=F1[n]}Kr(r)}class Ef extends _f{constructor(t,r,n,i=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=o,Xi(n),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=x1(this.state)}clone(){return this._cloneInto()}keccak(){Dl(this.state32),U1(this.state32,this.rounds),Dl(this.state32),this.posOut=0,this.pos=0}update(t){ei(this),t=$s(t),Vt(t);const{blockLen:r,state:n}=this,i=t.length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);for(let a=0;a<s;a++)n[this.pos++]^=t[o++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){ei(this,!1),Vt(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,o=t.length;i<o;){this.posOut>=n&&this.keccak();const s=Math.min(n-this.posOut,o-i);t.set(r.subarray(this.posOut,this.posOut+s),i),this.posOut+=s,i+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Xi(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(e0(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,Kr(this.state)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:o,enableXOF:s}=this;return t||(t=new Ef(r,n,i,s,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=n,t.outputLen=i,t.enableXOF=s,t.destroyed=this.destroyed,t}}const L1=(e,t,r)=>Fs(()=>new Ef(t,e,r)),s0=L1(1,136,256/8);function Je(e,t){const r=t||"hex",n=s0(zt(e,{strict:!1})?bi(e):e);return r==="bytes"?n:nt(n)}const M1=e=>Je(bi(e));function H1(e){return M1(e)}function D1(e){let t=!0,r="",n=0,i="",o=!1;for(let s=0;s<e.length;s++){const a=e[s];if(["(",")",","].includes(a)&&(t=!0),a==="("&&n++,a===")"&&n--,!!t){if(n===0){if(a===" "&&["event","function",""].includes(i))i="";else if(i+=a,a===")"){o=!0;break}continue}if(a===" "){e[s-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!o)throw new X("Unable to normalize signature.");return i}const j1=e=>{const t=typeof e=="string"?e:_s(e);return D1(t)};function a0(e){return H1(j1(e))}const Us=a0;let yt=class extends X{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"})}},Ls=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 Oa=new Ls(8192);function To(e,t){if(Oa.has(`${e}.${t}`))return Oa.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Je(un(r),"bytes"),i=r.split("");for(let s=0;s<40;s+=2)n[s>>1]>>4>=8&&i[s]&&(i[s]=i[s].toUpperCase()),(n[s>>1]&15)>=8&&i[s+1]&&(i[s+1]=i[s+1].toUpperCase());const o=`0x${i.join("")}`;return Oa.set(`${e}.${t}`,o),o}function c0(e,t){if(!He(e,{strict:!1}))throw new yt({address:e});return To(e,t)}const q1=/^0x[a-fA-F0-9]{40}$/,Ra=new Ls(8192);function He(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Ra.has(n))return Ra.get(n);const i=q1.test(e)?e.toLowerCase()===e?!0:r?To(e)===e:!0:!1;return Ra.set(n,i),i}function Et(e){return typeof e[0]=="string"?Kt(e):z1(e)}function z1(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 Kt(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function yn(e,t,r,{strict:n}={}){return zt(e,{strict:!1})?Es(e,t,r,{strict:n}):l0(e,t,r,{strict:n})}function u0(e,t){if(typeof t=="number"&&t>0&&t>Oe(e)-1)throw new Zp({offset:t,position:"start",size:Oe(e)})}function f0(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Oe(e)!==r-t)throw new Zp({offset:r,position:"end",size:Oe(e)})}function l0(e,t,r,{strict:n}={}){u0(e,t);const i=e.slice(t,r);return n&&f0(i,t,r),i}function Es(e,t,r,{strict:n}={}){u0(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return n&&f0(i,t,r),i}const G1=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,d0=/^(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 Rr(e,t){if(e.length!==t.length)throw new Zg({expectedLength:e.length,givenLength:t.length});const r=V1({params:e,values:t}),n=Af(r);return n.length===0?"0x":n}function V1({params:e,values:t}){const r=[];for(let n=0;n<e.length;n++)r.push(xf({param:e[n],value:t[n]}));return r}function xf({param:e,value:t}){const r=Sf(e.type);if(r){const[n,i]=r;return K1(t,{length:n,param:{...e,type:i}})}if(e.type==="tuple")return Q1(t,{param:e});if(e.type==="address")return W1(t);if(e.type==="bool")return Z1(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,i="256"]=d0.exec(e.type)??[];return X1(t,{signed:n,size:Number(i)})}if(e.type.startsWith("bytes"))return Y1(t,{param:e});if(e.type==="string")return J1(t);throw new r1(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function Af(e){let t=0;for(let o=0;o<e.length;o++){const{dynamic:s,encoded:a}=e[o];s?t+=32:t+=Oe(a)}const r=[],n=[];let i=0;for(let o=0;o<e.length;o++){const{dynamic:s,encoded:a}=e[o];s?(r.push(ne(t+i,{size:32})),n.push(a),i+=Oe(a)):r.push(a)}return Et([...r,...n])}function W1(e){if(!He(e))throw new yt({address:e});return{dynamic:!1,encoded:zr(e.toLowerCase())}}function K1(e,{length:t,param:r}){const n=t===null;if(!Array.isArray(e))throw new Yp(e);if(!n&&e.length!==t)throw new Kg({expectedLength:t,givenLength:e.length,type:`${r.type}[${t}]`});let i=!1;const o=[];for(let s=0;s<e.length;s++){const a=xf({param:r,value:e[s]});a.dynamic&&(i=!0),o.push(a)}if(n||i){const s=Af(o);if(n){const a=ne(o.length,{size:32});return{dynamic:!0,encoded:o.length>0?Et([a,s]):a}}if(i)return{dynamic:!0,encoded:s}}return{dynamic:!1,encoded:Et(o.map(({encoded:s})=>s))}}function Y1(e,{param:t}){const[,r]=t.type.split("bytes"),n=Oe(e);if(!r){let i=e;return n%32!==0&&(i=zr(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:Et([zr(ne(n,{size:32})),i])}}if(n!==Number.parseInt(r))throw new Yg({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:zr(e,{dir:"right"})}}function Z1(e){if(typeof e!="boolean")throw new X(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:zr(Qp(e))}}function X1(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 Jp({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:ne(e,{size:32,signed:t})}}function J1(e){const t=Qn(e),r=Math.ceil(Oe(t)/32),n=[];for(let i=0;i<r;i++)n.push(zr(yn(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:Et([zr(ne(Oe(t),{size:32})),...n])}}function Q1(e,{param:t}){let r=!1;const n=[];for(let i=0;i<t.components.length;i++){const o=t.components[i],s=Array.isArray(e)?i:o.name,a=xf({param:o,value:e[s]});n.push(a),a.dynamic&&(r=!0)}return{dynamic:r,encoded:r?Af(n):Et(n.map(({encoded:i})=>i))}}function Sf(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Bo=e=>yn(a0(e),0,4);function Sn(e){const{abi:t,args:r=[],name:n}=e,i=zt(n,{strict:!1}),o=t.filter(a=>i?a.type==="function"?Bo(a)===n:a.type==="event"?Us(a)===n:!1:"name"in a&&a.name===n);if(o.length===0)return;if(o.length===1)return o[0];let s;for(const a of o){if(!("inputs"in a))continue;if(!r||r.length===0){if(!a.inputs||a.inputs.length===0)return a;continue}if(!a.inputs||a.inputs.length===0||a.inputs.length!==r.length)continue;if(r.every((f,u)=>{const l="inputs"in a&&a.inputs[u];return l?Su(f,l):!1})){if(s&&"inputs"in s&&s.inputs){const f=h0(a.inputs,s.inputs,r);if(f)throw new e1({abiItem:a,type:f[0]},{abiItem:s,type:f[1]})}s=a}}return s||o[0]}function Su(e,t){const r=typeof e,n=t.type;switch(n){case"address":return He(e,{strict:!1});case"bool":return r==="boolean";case"function":return r==="string";case"string":return r==="string";default:return n==="tuple"&&"components"in t?Object.values(t.components).every((i,o)=>Su(Object.values(e)[o],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?r==="number"||r==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?r==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(e)&&e.every(i=>Su(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function h0(e,t,r){for(const n in e){const i=e[n],o=t[n];if(i.type==="tuple"&&o.type==="tuple"&&"components"in i&&"components"in o)return h0(i.components,o.components,r[n]);const s=[i.type,o.type];if(s.includes("address")&&s.includes("bytes20")?!0:s.includes("address")&&s.includes("string")?He(r[n],{strict:!1}):s.includes("address")&&s.includes("bytes")?He(r[n],{strict:!1}):!1)return s}}const Gl="/docs/contract/encodeEventTopics";function Io(e){var c;const{abi:t,eventName:r,args:n}=e;let i=t[0];if(r){const f=Sn({abi:t,name:r});if(!f)throw new Ul(r,{docsPath:Gl});i=f}if(i.type!=="event")throw new Ul(void 0,{docsPath:Gl});const o=qt(i),s=Us(o);let a=[];if(n&&"inputs"in i){const f=(c=i.inputs)==null?void 0:c.filter(l=>"indexed"in l&&l.indexed),u=Array.isArray(n)?n:Object.values(n).length>0?(f==null?void 0:f.map(l=>n[l.name]))??[]:[];u.length>0&&(a=(f==null?void 0:f.map((l,p)=>Array.isArray(u[p])?u[p].map((h,m)=>Vl({param:l,value:u[p][m]})):typeof u[p]<"u"&&u[p]!==null?Vl({param:l,value:u[p]}):null))??[])}return[s,...a]}function Vl({param:e,value:t}){if(e.type==="string"||e.type==="bytes")return Je(bi(t));if(e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/))throw new o1(e.type);return Rr([e],[t])}function Ms(e,{method:t}){var n,i;const r={};return e.transport.type==="fallback"&&((i=(n=e.transport).onResponse)==null||i.call(n,({method:o,response:s,status:a,transport:c})=>{a==="success"&&t===o&&(r[s]=c.request)})),o=>r[o]||e.request}async function Pf(e,t){const{address:r,abi:n,args:i,eventName:o,fromBlock:s,strict:a,toBlock:c}=t,f=Ms(e,{method:"eth_newFilter"}),u=o?Io({abi:n,args:i,eventName:o}):void 0,l=await e.request({method:"eth_newFilter",params:[{address:r,fromBlock:typeof s=="bigint"?ne(s):s,toBlock:typeof c=="bigint"?ne(c):c,topics:u}]});return{abi:n,args:i,eventName:o,id:l,request:f(l),strict:!!a,type:"event"}}function $e(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}const Wl="/docs/contract/encodeFunctionData";function ew(e){const{abi:t,args:r,functionName:n}=e;let i=t[0];if(n){const o=Sn({abi:t,args:r,name:n});if(!o)throw new Jn(n,{docsPath:Wl});i=o}if(i.type!=="function")throw new Jn(void 0,{docsPath:Wl});return{abi:[i],functionName:Bo(qt(i))}}function Ut(e){const{args:t}=e,{abi:r,functionName:n}=(()=>{var a;return e.abi.length===1&&((a=e.functionName)!=null&&a.startsWith("0x"))?e:ew(e)})(),i=r[0],o=n,s="inputs"in i&&i.inputs?Rr(i.inputs,t??[]):void 0;return Kt([o,s??"0x"])}const p0={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."},y0={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},tw={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class Kl extends X{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class m0 extends X{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class rw extends X{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const nw={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 rw({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new m0({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new Kl({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 Kl({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 Tf(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(nw);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function iw(e,t={}){typeof t.size<"u"&&Wt(e,{size:t.size});const r=Le(e,t);return ze(r,t)}function ow(e,t={}){let r=e;if(typeof t.size<"u"&&(Wt(r,{size:t.size}),r=Nt(r)),r.length>1||r[0]>1)throw new a1(r);return!!r[0]}function Ar(e,t={}){typeof t.size<"u"&&Wt(e,{size:t.size});const r=Le(e,t);return $t(r,t)}function sw(e,t={}){let r=e;return typeof t.size<"u"&&(Wt(r,{size:t.size}),r=Nt(r,{dir:"right"})),new TextDecoder().decode(r)}function ko(e,t){const r=typeof t=="string"?Gt(t):t,n=Tf(r);if(Oe(r)===0&&e.length>0)throw new Po;if(Oe(t)&&Oe(t)<32)throw new Gp({data:typeof t=="string"?t:Le(t),params:e,size:Oe(t)});let i=0;const o=[];for(let s=0;s<e.length;++s){const a=e[s];n.setPosition(i);const[c,f]=Gn(n,a,{staticPosition:0});i+=f,o.push(c)}return o}function Gn(e,t,{staticPosition:r}){const n=Sf(t.type);if(n){const[i,o]=n;return cw(e,{...t,type:o},{length:i,staticPosition:r})}if(t.type==="tuple")return dw(e,t,{staticPosition:r});if(t.type==="address")return aw(e);if(t.type==="bool")return uw(e);if(t.type.startsWith("bytes"))return fw(e,t,{staticPosition:r});if(t.type.startsWith("uint")||t.type.startsWith("int"))return lw(e,t);if(t.type==="string")return hw(e,{staticPosition:r});throw new n1(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const Yl=32,Pu=32;function aw(e){const t=e.readBytes(32);return[To(Le(l0(t,-20))),32]}function cw(e,t,{length:r,staticPosition:n}){if(!r){const s=Ar(e.readBytes(Pu)),a=n+s,c=a+Yl;e.setPosition(a);const f=Ar(e.readBytes(Yl)),u=Qi(t);let l=0;const p=[];for(let h=0;h<f;++h){e.setPosition(c+(u?h*32:l));const[m,b]=Gn(e,t,{staticPosition:c});l+=b,p.push(m)}return e.setPosition(n+32),[p,32]}if(Qi(t)){const s=Ar(e.readBytes(Pu)),a=n+s,c=[];for(let f=0;f<r;++f){e.setPosition(a+f*32);const[u]=Gn(e,t,{staticPosition:a});c.push(u)}return e.setPosition(n+32),[c,32]}let i=0;const o=[];for(let s=0;s<r;++s){const[a,c]=Gn(e,t,{staticPosition:n+i});i+=c,o.push(a)}return[o,i]}function uw(e){return[ow(e.readBytes(32),{size:32}),32]}function fw(e,t,{staticPosition:r}){const[n,i]=t.type.split("bytes");if(!i){const s=Ar(e.readBytes(32));e.setPosition(r+s);const a=Ar(e.readBytes(32));if(a===0)return e.setPosition(r+32),["0x",32];const c=e.readBytes(a);return e.setPosition(r+32),[Le(c),32]}return[Le(e.readBytes(Number.parseInt(i),32)),32]}function lw(e,t){const r=t.type.startsWith("int"),n=Number.parseInt(t.type.split("int")[1]||"256"),i=e.readBytes(32);return[n>48?iw(i,{signed:r}):Ar(i,{signed:r}),32]}function dw(e,t,{staticPosition:r}){const n=t.components.length===0||t.components.some(({name:s})=>!s),i=n?[]:{};let o=0;if(Qi(t)){const s=Ar(e.readBytes(Pu)),a=r+s;for(let c=0;c<t.components.length;++c){const f=t.components[c];e.setPosition(a+o);const[u,l]=Gn(e,f,{staticPosition:a});o+=l,i[n?c:f==null?void 0:f.name]=u}return e.setPosition(r+32),[i,32]}for(let s=0;s<t.components.length;++s){const a=t.components[s],[c,f]=Gn(e,a,{staticPosition:r});i[n?s:a==null?void 0:a.name]=c,o+=f}return[i,o]}function hw(e,{staticPosition:t}){const r=Ar(e.readBytes(32)),n=t+r;e.setPosition(n);const i=Ar(e.readBytes(32));if(i===0)return e.setPosition(t+32),["",32];const o=e.readBytes(i,32),s=sw(Nt(o));return e.setPosition(t+32),[s,32]}function Qi(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(Qi);const r=Sf(e.type);return!!(r&&Qi({...e,type:r[1]}))}function b0(e){const{abi:t,data:r}=e,n=yn(r,0,4);if(n==="0x")throw new Po;const o=[...t||[],y0,tw].find(s=>s.type==="error"&&n===Bo(qt(s)));if(!o)throw new Vp(n,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:o,args:"inputs"in o&&o.inputs&&o.inputs.length>0?ko(o.inputs,yn(r,4)):void 0,errorName:o.name}}const Ue=(e,t,r)=>JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString():i,r);function g0({abiItem:e,args:t,includeFunctionName:r=!0,includeName:n=!1}){if("name"in e&&"inputs"in e&&e.inputs)return`${r?e.name:""}(${e.inputs.map((i,o)=>`${n&&i.name?`${i.name}: `:""}${typeof t[o]=="object"?Ue(t[o]):t[o]}`).join(", ")})`}const pw={gwei:9,wei:18},yw={ether:-9,wei:9};function w0(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,o]=[r.slice(0,r.length-t),r.slice(r.length-t)];return o=o.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${o?`.${o}`:""}`}function Bf(e,t="wei"){return w0(e,pw[t])}function wt(e,t="wei"){return w0(e,yw[t])}class mw extends X{constructor({address:t}){super(`State for account "${t}" is set multiple times.`,{name:"AccountStateConflictError"})}}class bw extends X{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function Zl(e){return e.reduce((t,{slot:r,value:n})=>`${t} ${r}: ${n}
|
|
23
|
-
`,"")}function gw(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+=Zl(n.state)),n.stateDiff&&(i+=` stateDiff:
|
|
29
|
-
`,i+=Zl(n.stateDiff)),i},` State Override:
|
|
30
|
-
`).slice(0,-1)}function Oo(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 ww extends X{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 vw extends X{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class _w extends X{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Oo(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 Ew extends X{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 xw extends X{constructor(t,{account:r,docsPath:n,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:u,to:l,value:p}){var m;const h=Oo({chain:i&&`${i==null?void 0:i.name} (id: ${i==null?void 0:i.id})`,from:r==null?void 0:r.address,to:l,value:typeof p<"u"&&`${Bf(p)} ${((m=i==null?void 0:i.nativeCurrency)==null?void 0:m.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${wt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${wt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${wt(f)} gwei`,nonce:u});super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Request Arguments:",h].filter(Boolean),name:"TransactionExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class v0 extends X{constructor({blockHash:t,blockNumber:r,blockTag:n,hash:i,index:o}){let s="Transaction";n&&o!==void 0&&(s=`Transaction at block time "${n}" at index "${o}"`),t&&o!==void 0&&(s=`Transaction at block hash "${t}" at index "${o}"`),r&&o!==void 0&&(s=`Transaction at block number "${r}" at index "${o}"`),i&&(s=`Transaction with hash "${i}"`),super(`${s} could not be found.`,{name:"TransactionNotFoundError"})}}class _0 extends X{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 Aw extends X{constructor({hash:t}){super(`Timed out while waiting for transaction with hash "${t}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}}const Sw=e=>e,Hs=e=>e;class E0 extends X{constructor(t,{account:r,docsPath:n,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:u,to:l,value:p,stateOverride:h}){var w;const m=r?$e(r):void 0;let b=Oo({from:m==null?void 0:m.address,to:l,value:typeof p<"u"&&`${Bf(p)} ${((w=i==null?void 0:i.nativeCurrency)==null?void 0:w.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${wt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${wt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${wt(f)} gwei`,nonce:u});h&&(b+=`
|
|
33
|
-
${gw(h)}`),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 Pw extends X{constructor(t,{abi:r,args:n,contractAddress:i,docsPath:o,functionName:s,sender:a}){const c=Sn({abi:r,args:n,name:s}),f=c?g0({abiItem:c,args:n,includeFunctionName:!1,includeName:!1}):void 0,u=c?qt(c,{includeName:!0}):void 0,l=Oo({address:i&&Sw(i),function:u,args:f&&f!=="()"&&`${[...Array((s==null?void 0:s.length)??0).keys()].map(()=>" ").join("")}${f}`,sender:a});super(t.shortMessage||`An unknown error occurred while executing the contract function "${s}".`,{cause:t,docsPath:o,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],l&&"Contract Call:",l].filter(Boolean),name:"ContractFunctionExecutionError"}),Object.defineProperty(this,"abi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"args",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"contractAddress",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"formattedArgs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"functionName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sender",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abi=r,this.args=n,this.cause=t,this.contractAddress=i,this.functionName=s,this.sender=a}}class Tu extends X{constructor({abi:t,data:r,functionName:n,message:i}){let o,s,a,c;if(r&&r!=="0x")try{s=b0({abi:t,data:r});const{abiItem:u,errorName:l,args:p}=s;if(l==="Error")c=p[0];else if(l==="Panic"){const[h]=p;c=p0[h]}else{const h=u?qt(u,{includeName:!0}):void 0,m=u&&p?g0({abiItem:u,args:p,includeFunctionName:!1,includeName:!1}):void 0;a=[h?`Error: ${h}`:"",m&&m!=="()"?` ${[...Array((l==null?void 0:l.length)??0).keys()].map(()=>" ").join("")}${m}`:""]}}catch(u){o=u}else i&&(c=i);let f;o instanceof Vp&&(f=o.signature,a=[`Unable to decode signature "${f}" as it was not found on the provided ABI.`,"Make sure you are using the correct ABI and that the error exists on it.",`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${f}.`]),super(c&&c!=="execution reverted"||f?[`The contract function "${n}" reverted with the following ${f?"signature":"reason"}:`,c||f].join(`
|
|
34
|
-
`):`The contract function "${n}" reverted.`,{cause:o,metaMessages:a,name:"ContractFunctionRevertedError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"reason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=s,this.raw=r,this.reason=c,this.signature=f}}class Tw extends X{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 Bw extends X{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 Ds extends X{constructor({data:t,message:r}){super(r||"",{name:"RawContractError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t}}class Vn extends X{constructor({body:t,cause:r,details:n,headers:i,status:o,url:s}){super("HTTP request failed.",{cause:r,details:n,metaMessages:[o&&`Status: ${o}`,`URL: ${Hs(s)}`,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=o,this.url=s}}class If extends X{constructor({body:t,error:r,url:n}){super("RPC Request failed.",{cause:r,details:r.message,metaMessages:[`URL: ${Hs(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 Xl extends X{constructor({body:t,url:r}){super("The request took too long to respond.",{details:"The request timed out.",metaMessages:[`URL: ${Hs(r)}`,`Request body: ${Ue(t)}`],name:"TimeoutError"})}}const Iw=-1;class vt extends X{constructor(t,{code:r,docsPath:n,metaMessages:i,name:o,shortMessage:s}){super(s,{cause:t,docsPath:n,metaMessages:i||(t==null?void 0:t.metaMessages),name:o||"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=o||t.name,this.code=t instanceof If?t.code:r??Iw}}class St extends vt{constructor(t,r){super(t,r),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=r.data}}class eo extends vt{constructor(t){super(t,{code:eo.code,name:"ParseRpcError",shortMessage:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."})}}Object.defineProperty(eo,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32700});class to extends vt{constructor(t){super(t,{code:to.code,name:"InvalidRequestRpcError",shortMessage:"JSON is not a valid request object."})}}Object.defineProperty(to,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32600});class ro extends vt{constructor(t,{method:r}={}){super(t,{code:ro.code,name:"MethodNotFoundRpcError",shortMessage:`The method${r?` "${r}"`:""} does not exist / is not available.`})}}Object.defineProperty(ro,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32601});class no extends vt{constructor(t){super(t,{code:no.code,name:"InvalidParamsRpcError",shortMessage:["Invalid parameters were provided to the RPC method.","Double check you have provided the correct parameters."].join(`
|
|
35
|
-
`)})}}Object.defineProperty(no,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32602});class mn extends vt{constructor(t){super(t,{code:mn.code,name:"InternalRpcError",shortMessage:"An internal error was received."})}}Object.defineProperty(mn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32603});class bn extends vt{constructor(t){super(t,{code:bn.code,name:"InvalidInputRpcError",shortMessage:["Missing or invalid parameters.","Double check you have provided the correct parameters."].join(`
|
|
36
|
-
`)})}}Object.defineProperty(bn,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32e3});class io extends vt{constructor(t){super(t,{code:io.code,name:"ResourceNotFoundRpcError",shortMessage:"Requested resource not found."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceNotFoundRpcError"})}}Object.defineProperty(io,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32001});class oo extends vt{constructor(t){super(t,{code:oo.code,name:"ResourceUnavailableRpcError",shortMessage:"Requested resource not available."})}}Object.defineProperty(oo,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32002});class so extends vt{constructor(t){super(t,{code:so.code,name:"TransactionRejectedRpcError",shortMessage:"Transaction creation failed."})}}Object.defineProperty(so,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32003});class on extends vt{constructor(t,{method:r}={}){super(t,{code:on.code,name:"MethodNotSupportedRpcError",shortMessage:`Method${r?` "${r}"`:""} is not supported.`})}}Object.defineProperty(on,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32004});class ti extends vt{constructor(t){super(t,{code:ti.code,name:"LimitExceededRpcError",shortMessage:"Request exceeds defined limit."})}}Object.defineProperty(ti,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32005});class ao extends vt{constructor(t){super(t,{code:ao.code,name:"JsonRpcVersionUnsupportedError",shortMessage:"Version of JSON-RPC protocol is not supported."})}}Object.defineProperty(ao,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32006});class Wn extends St{constructor(t){super(t,{code:Wn.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(Wn,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class co extends St{constructor(t){super(t,{code:co.code,name:"UnauthorizedProviderError",shortMessage:"The requested method and/or account has not been authorized by the user."})}}Object.defineProperty(co,"code",{enumerable:!0,configurable:!0,writable:!0,value:4100});class uo extends St{constructor(t,{method:r}={}){super(t,{code:uo.code,name:"UnsupportedProviderMethodError",shortMessage:`The Provider does not support the requested method${r?` " ${r}"`:""}.`})}}Object.defineProperty(uo,"code",{enumerable:!0,configurable:!0,writable:!0,value:4200});class fo extends St{constructor(t){super(t,{code:fo.code,name:"ProviderDisconnectedError",shortMessage:"The Provider is disconnected from all chains."})}}Object.defineProperty(fo,"code",{enumerable:!0,configurable:!0,writable:!0,value:4900});class lo extends St{constructor(t){super(t,{code:lo.code,name:"ChainDisconnectedError",shortMessage:"The Provider is not connected to the requested chain."})}}Object.defineProperty(lo,"code",{enumerable:!0,configurable:!0,writable:!0,value:4901});class ho extends St{constructor(t){super(t,{code:ho.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(ho,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class ri extends St{constructor(t){super(t,{code:ri.code,name:"UnsupportedNonOptionalCapabilityError",shortMessage:"This Wallet does not support a capability that was not marked as optional."})}}Object.defineProperty(ri,"code",{enumerable:!0,configurable:!0,writable:!0,value:5700});class po extends St{constructor(t){super(t,{code:po.code,name:"UnsupportedChainIdError",shortMessage:"This Wallet does not support the requested chain ID."})}}Object.defineProperty(po,"code",{enumerable:!0,configurable:!0,writable:!0,value:5710});class yo extends St{constructor(t){super(t,{code:yo.code,name:"DuplicateIdError",shortMessage:"There is already a bundle submitted with this ID."})}}Object.defineProperty(yo,"code",{enumerable:!0,configurable:!0,writable:!0,value:5720});class mo extends St{constructor(t){super(t,{code:mo.code,name:"UnknownBundleIdError",shortMessage:"This bundle id is unknown / has not been submitted"})}}Object.defineProperty(mo,"code",{enumerable:!0,configurable:!0,writable:!0,value:5730});class bo extends St{constructor(t){super(t,{code:bo.code,name:"BundleTooLargeError",shortMessage:"The call bundle is too large for the Wallet to process."})}}Object.defineProperty(bo,"code",{enumerable:!0,configurable:!0,writable:!0,value:5740});class go extends St{constructor(t){super(t,{code:go.code,name:"AtomicReadyWalletRejectedUpgradeError",shortMessage:"The Wallet can support atomicity after an upgrade, but the user rejected the upgrade."})}}Object.defineProperty(go,"code",{enumerable:!0,configurable:!0,writable:!0,value:5750});class ni extends St{constructor(t){super(t,{code:ni.code,name:"AtomicityNotSupportedError",shortMessage:"The wallet does not support atomic execution but the request requires it."})}}Object.defineProperty(ni,"code",{enumerable:!0,configurable:!0,writable:!0,value:5760});class kw extends vt{constructor(t){super(t,{name:"UnknownRpcError",shortMessage:"An unknown RPC error occurred."})}}const Ow=3;function gn(e,{abi:t,address:r,args:n,docsPath:i,functionName:o,sender:s}){const a=e instanceof Ds?e:e instanceof X?e.walk(m=>"data"in m)||e.walk():{},{code:c,data:f,details:u,message:l,shortMessage:p}=a,h=e instanceof Po?new Tw({functionName:o}):[Ow,mn.code].includes(c)&&(f||u||l||p)?new Tu({abi:t,data:typeof f=="object"?f.data:f,functionName:o,message:a instanceof If?u:p??l}):e;return new Pw(h,{abi:t,args:n,contractAddress:r,docsPath:i,functionName:o,sender:s})}function Rw(e){const t=Je(`0x${e.substring(4)}`).substring(26);return To(`0x${t}`)}async function Cw({hash:e,signature:t}){const r=zt(e)?e:nt(e),{secp256k1:n}=await Promise.resolve().then(()=>CE);return`0x${(()=>{if(typeof t=="object"&&"r"in t&&"s"in t){const{r:f,s:u,v:l,yParity:p}=t,h=Number(p??l),m=Jl(h);return new n.Signature(ze(f),ze(u)).addRecoveryBit(m)}const s=zt(t)?t:nt(t);if(Oe(s)!==65)throw new Error("invalid signature length");const a=$t(`0x${s.slice(130)}`),c=Jl(a);return n.Signature.fromCompact(s.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function Jl(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 x0({hash:e,signature:t}){return Rw(await Cw({hash:e,signature:t}))}function Yr(e,t="hex"){const r=A0(e),n=Tf(new Uint8Array(r.length));return r.encode(n),t==="hex"?Le(n.bytes):n.bytes}function A0(e){return Array.isArray(e)?Nw(e.map(t=>A0(t))):$w(e)}function Nw(e){const t=e.reduce((i,o)=>i+o.length,0),r=S0(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:o}of e)o(i)}}}function $w(e){const t=typeof e=="string"?Gt(e):e,r=S0(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 S0(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 X("Length is too large.")}function Fw(e){const{chainId:t,nonce:r,to:n}=e,i=e.contractAddress??e.address,o=Je(Kt(["0x05",Yr([t?ne(t):"0x",i,r?ne(r):"0x"])]));return n==="bytes"?Gt(o):o}async function P0(e){const{authorization:t,signature:r}=e;return x0({hash:Fw(t),signature:r??t})}class Uw extends X{constructor(t,{account:r,docsPath:n,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:f,nonce:u,to:l,value:p}){var m;const h=Oo({from:r==null?void 0:r.address,to:l,value:typeof p<"u"&&`${Bf(p)} ${((m=i==null?void 0:i.nativeCurrency)==null?void 0:m.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${wt(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${wt(c)} gwei`,maxPriorityFeePerGas:typeof f<"u"&&`${wt(f)} gwei`,nonce:u});super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Estimate Gas Arguments:",h].filter(Boolean),name:"EstimateGasExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=t}}class qn extends X{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(qn,"code",{enumerable:!0,configurable:!0,writable:!0,value:3});Object.defineProperty(qn,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class wn extends X{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${wt(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(wn,"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 Bu extends X{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${wt(r)}`:""} gwei) cannot be lower than the block base fee.`,{cause:t,name:"FeeCapTooLowError"})}}Object.defineProperty(Bu,"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 Iu extends X{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(Iu,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class ku extends X{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(ku,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class Ou extends X{constructor({cause:t,nonce:r}={}){super(`Nonce provided for the transaction ${r?`(${r}) `:""}exceeds the maximum allowed nonce.`,{cause:t,name:"NonceMaxValueError"})}}Object.defineProperty(Ou,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/});class Ru extends X{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(Ru,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class Cu extends X{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(Cu,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class Nu extends X{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(Nu,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class $u extends X{constructor({cause:t}){super("The transaction type is not supported for this chain.",{cause:t,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty($u,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class wo extends X{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${wt(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${wt(n)} gwei`:""}).`].join(`
|
|
39
|
-
`),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(wo,"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 Ro extends X{constructor({cause:t}){super(`An error occurred while executing: ${t==null?void 0:t.shortMessage}`,{cause:t,name:"UnknownNodeError"})}}function js(e,t){const r=(e.details||"").toLowerCase(),n=e instanceof X?e.walk(i=>(i==null?void 0:i.code)===qn.code):e;return n instanceof X?new qn({cause:e,message:n.details}):qn.nodeMessage.test(r)?new qn({cause:e,message:e.details}):wn.nodeMessage.test(r)?new wn({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):Bu.nodeMessage.test(r)?new Bu({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):Iu.nodeMessage.test(r)?new Iu({cause:e,nonce:t==null?void 0:t.nonce}):ku.nodeMessage.test(r)?new ku({cause:e,nonce:t==null?void 0:t.nonce}):Ou.nodeMessage.test(r)?new Ou({cause:e,nonce:t==null?void 0:t.nonce}):Ru.nodeMessage.test(r)?new Ru({cause:e}):Cu.nodeMessage.test(r)?new Cu({cause:e,gas:t==null?void 0:t.gas}):Nu.nodeMessage.test(r)?new Nu({cause:e,gas:t==null?void 0:t.gas}):$u.nodeMessage.test(r)?new $u({cause:e}):wo.nodeMessage.test(r)?new wo({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas,maxPriorityFeePerGas:t==null?void 0:t.maxPriorityFeePerGas}):new Ro({cause:e})}function Lw(e,{docsPath:t,...r}){const n=(()=>{const i=js(e,r);return i instanceof Ro?e:i})();return new Uw(n,{docsPath:t,...r})}function qs(e,{format:t}){if(!t)return{};const r={};function n(o){const s=Object.keys(o);for(const a of s)a in e&&(r[a]=e[a]),o[a]&&typeof o[a]=="object"&&!Array.isArray(o[a])&&n(o[a])}const i=t(e||{});return n(i),r}function kf(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const o=t(i);if(r)for(const s of r)delete o[s];return{...o,...n(i)}},type:e})}const Mw={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function gi(e){const t={};return typeof e.authorizationList<"u"&&(t.authorizationList=Hw(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=>Le(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=ne(e.gas)),typeof e.gasPrice<"u"&&(t.gasPrice=ne(e.gasPrice)),typeof e.maxFeePerBlobGas<"u"&&(t.maxFeePerBlobGas=ne(e.maxFeePerBlobGas)),typeof e.maxFeePerGas<"u"&&(t.maxFeePerGas=ne(e.maxFeePerGas)),typeof e.maxPriorityFeePerGas<"u"&&(t.maxPriorityFeePerGas=ne(e.maxPriorityFeePerGas)),typeof e.nonce<"u"&&(t.nonce=ne(e.nonce)),typeof e.to<"u"&&(t.to=e.to),typeof e.type<"u"&&(t.type=Mw[e.type]),typeof e.value<"u"&&(t.value=ne(e.value)),t}function Hw(e){return e.map(t=>({address:t.address,r:t.r?ne(BigInt(t.r)):t.r,s:t.s?ne(BigInt(t.s)):t.s,chainId:ne(t.chainId),nonce:ne(t.nonce),...typeof t.yParity<"u"?{yParity:ne(t.yParity)}:{},...typeof t.v<"u"&&typeof t.yParity>"u"?{v:ne(t.v)}:{}}))}function Ql(e){if(!(!e||e.length===0))return e.reduce((t,{slot:r,value:n})=>{if(r.length!==66)throw new Ll({size:r.length,targetSize:66,type:"hex"});if(n.length!==66)throw new Ll({size:n.length,targetSize:66,type:"hex"});return t[r]=n,t},{})}function Dw(e){const{balance:t,nonce:r,state:n,stateDiff:i,code:o}=e,s={};if(o!==void 0&&(s.code=o),t!==void 0&&(s.balance=ne(t)),r!==void 0&&(s.nonce=ne(r)),n!==void 0&&(s.state=Ql(n)),i!==void 0){if(s.state)throw new bw;s.stateDiff=Ql(i)}return s}function Of(e){if(!e)return;const t={};for(const{address:r,...n}of e){if(!He(r,{strict:!1}))throw new yt({address:r});if(t[r])throw new mw({address:r});t[r]=Dw(n)}return t}const zs=2n**256n-1n;function Pn(e){const{account:t,gasPrice:r,maxFeePerGas:n,maxPriorityFeePerGas:i,to:o}=e,s=t?$e(t):void 0;if(s&&!He(s.address))throw new yt({address:s.address});if(o&&!He(o))throw new yt({address:o});if(typeof r<"u"&&(typeof n<"u"||typeof i<"u"))throw new ww;if(n&&n>zs)throw new wn({maxFeePerGas:n});if(i&&n&&i>n)throw new wo({maxFeePerGas:n,maxPriorityFeePerGas:i})}class jw extends X{constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class Rf extends X{constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class qw extends X{constructor({maxPriorityFeePerGas:t}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${wt(t)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class T0 extends X{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 B0={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Gs(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?$t(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?$t(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?B0[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=Gw(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 zw=kf("transaction",Gs);function Gw(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 Cf(e){const t=(e.transactions??[]).map(r=>typeof r=="string"?r:Gs(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 Vw=kf("block",Cf);async function fr(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:i}={}){var u,l,p;const o=n??"latest",s=i??!1,a=r!==void 0?ne(r):void 0;let c=null;if(t?c=await e.request({method:"eth_getBlockByHash",params:[t,s]},{dedupe:!0}):c=await e.request({method:"eth_getBlockByNumber",params:[a||o,s]},{dedupe:!!a}),!c)throw new T0({blockHash:t,blockNumber:r});return(((p=(l=(u=e.chain)==null?void 0:u.formatters)==null?void 0:l.block)==null?void 0:p.format)||Cf)(c)}async function Nf(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function Ww(e,t){return I0(e,t)}async function I0(e,t){var o,s;const{block:r,chain:n=e.chain,request:i}=t||{};try{const a=((o=n==null?void 0:n.fees)==null?void 0:o.maxPriorityFeePerGas)??((s=n==null?void 0:n.fees)==null?void 0:s.defaultPriorityFee);if(typeof a=="function"){const f=r||await ue(e,fr,"getBlock")({}),u=await a({block:f,client:e,request:i});if(u===null)throw new Error;return u}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):ue(e,fr,"getBlock")({}),ue(e,Nf,"getGasPrice")({})]);if(typeof a.baseFeePerGas!="bigint")throw new Rf;const f=c-a.baseFeePerGas;return f<0n?0n:f}}async function Kw(e,t){return Fu(e,t)}async function Fu(e,t){var p,h;const{block:r,chain:n=e.chain,request:i,type:o="eip1559"}=t||{},s=await(async()=>{var m,b;return typeof((m=n==null?void 0:n.fees)==null?void 0:m.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(s<1)throw new jw;const c=10**(((p=s.toString().split(".")[1])==null?void 0:p.length)??0),f=m=>m*BigInt(Math.ceil(s*c))/BigInt(c),u=r||await ue(e,fr,"getBlock")({});if(typeof((h=n==null?void 0:n.fees)==null?void 0:h.estimateFeesPerGas)=="function"){const m=await n.fees.estimateFeesPerGas({block:r,client:e,multiply:f,request:i,type:o});if(m!==null)return m}if(o==="eip1559"){if(typeof u.baseFeePerGas!="bigint")throw new Rf;const m=typeof(i==null?void 0:i.maxPriorityFeePerGas)=="bigint"?i.maxPriorityFeePerGas:await I0(e,{block:u,chain:n,request:i}),b=f(u.baseFeePerGas);return{maxFeePerGas:(i==null?void 0:i.maxFeePerGas)??b+m,maxPriorityFeePerGas:m}}return{gasPrice:(i==null?void 0:i.gasPrice)??f(await ue(e,Nf,"getGasPrice")({}))}}async function $f(e,{address:t,blockTag:r="latest",blockNumber:n}){const i=await e.request({method:"eth_getTransactionCount",params:[t,typeof n=="bigint"?ne(n):r]},{dedupe:!!n});return $t(i)}function Ff(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=>Gt(o)):e.blobs,i=[];for(const o of n)i.push(Uint8Array.from(t.blobToKzgCommitment(o)));return r==="bytes"?i:i.map(o=>Le(o))}function Uf(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=>Gt(s)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(s=>Gt(s)):e.commitments,o=[];for(let s=0;s<n.length;s++){const a=n[s],c=i[s];o.push(Uint8Array.from(t.computeBlobKzgProof(a,c)))}return r==="bytes"?o:o.map(s=>Le(s))}function Yw(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),c=n?4:0,f=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+f,a,n)}function Zw(e,t,r){return e&t^~e&r}function Xw(e,t,r){return e&t^e&r^t&r}let k0=class extends _f{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=ka(this.buffer)}update(t){ei(this),t=$s(t),Vt(t);const{view:r,buffer:n,blockLen:i}=this,o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=ka(t);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ei(this),e0(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:o}=this;let{pos:s}=this;r[s++]=128,Kr(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)r[l]=0;Yw(n,i-8,BigInt(this.length*8),o),this.process(n,0);const a=ka(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],o)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=o,t.length=i,t.pos=a,i%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}};const Cr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Nr=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Jw=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),$r=new Uint32Array(64);let Lf=class extends k0{constructor(t=32){super(64,t,8,!1),this.A=Cr[0]|0,this.B=Cr[1]|0,this.C=Cr[2]|0,this.D=Cr[3]|0,this.E=Cr[4]|0,this.F=Cr[5]|0,this.G=Cr[6]|0,this.H=Cr[7]|0}get(){const{A:t,B:r,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[t,r,n,i,o,s,a,c]}set(t,r,n,i,o,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)$r[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){const p=$r[l-15],h=$r[l-2],m=Jt(p,7)^Jt(p,18)^p>>>3,b=Jt(h,17)^Jt(h,19)^h>>>10;$r[l]=b+$r[l-7]+m+$r[l-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){const p=Jt(a,6)^Jt(a,11)^Jt(a,25),h=u+p+Zw(a,c,f)+Jw[l]+$r[l]|0,b=(Jt(n,2)^Jt(n,13)^Jt(n,22))+Xw(n,i,o)|0;u=f,f=c,c=a,a=s+h|0,s=o,o=i,i=n,n=h+b|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,i,o,s,a,c,f,u)}roundClean(){Kr($r)}destroy(){this.set(0,0,0,0,0,0,0,0),Kr(this.buffer)}},O0=class extends Lf{constructor(){super(28),this.A=Nr[0]|0,this.B=Nr[1]|0,this.C=Nr[2]|0,this.D=Nr[3]|0,this.E=Nr[4]|0,this.F=Nr[5]|0,this.G=Nr[6]|0,this.H=Nr[7]|0}};const R0=Fs(()=>new Lf),Qw=Fs(()=>new O0),e2=Lf,C0=R0,t2=O0,r2=Qw,n2=Object.freeze(Object.defineProperty({__proto__:null,SHA224:t2,SHA256:e2,sha224:r2,sha256:C0},Symbol.toStringTag,{value:"Module"}));function Di(e,t){const r=t||"hex",n=C0(zt(e,{strict:!1})?bi(e):e);return r==="bytes"?n:nt(n)}function i2(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=Di(t,"bytes");return i.set([r],0),n==="bytes"?i:Le(i)}function N0(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const o of t)i.push(i2({commitment:o,to:n,version:r}));return i}const ed=6,$0=32,Mf=4096,F0=$0*Mf,td=F0*ed-1-1*Mf*ed,U0=1;class o2 extends X{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class L0 extends X{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class s2 extends X{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class a2 extends X{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${U0}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function c2(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?Gt(e.data):e.data,n=Oe(r);if(!n)throw new L0;if(n>td)throw new o2({maxSize:td,size:n});const i=[];let o=!0,s=0;for(;o;){const a=Tf(new Uint8Array(F0));let c=0;for(;c<Mf;){const f=r.slice(s,s+($0-1));if(a.pushByte(0),a.pushBytes(f),f.length<31){a.pushByte(128),o=!1;break}c++,s+=31}i.push(a)}return t==="bytes"?i.map(a=>a.bytes):i.map(a=>Le(a.bytes))}function M0(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??c2({data:t,to:n}),o=e.commitments??Ff({blobs:i,kzg:r,to:n}),s=e.proofs??Uf({blobs:i,commitments:o,kzg:r,to:n}),a=[];for(let c=0;c<i.length;c++)a.push({blob:i[c],commitment:o[c],proof:s[c]});return a}function H0(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 _w({transaction:e})}async function wi(e){const t=await e.request({method:"eth_chainId"},{dedupe:!0});return $t(t)}const D0=["blobVersionedHashes","chainId","fees","gas","nonce","type"],rd=new Map;async function Vs(e,t){const{account:r=e.account,blobs:n,chain:i,gas:o,kzg:s,nonce:a,nonceManager:c,parameters:f=D0,type:u}=t,l=r&&$e(r),p={...t,...l?{from:l==null?void 0:l.address}:{}};let h;async function m(){return h||(h=await ue(e,fr,"getBlock")({blockTag:"latest"}),h)}let b;async function w(){return b||(i?i.id:typeof t.chainId<"u"?t.chainId:(b=await ue(e,wi,"getChainId")({}),b))}if(f.includes("nonce")&&typeof a>"u"&&l)if(c){const _=await w();p.nonce=await c.consume({address:l.address,chainId:_,client:e})}else p.nonce=await ue(e,$f,"getTransactionCount")({address:l.address,blockTag:"pending"});if((f.includes("blobVersionedHashes")||f.includes("sidecars"))&&n&&s){const _=Ff({blobs:n,kzg:s});if(f.includes("blobVersionedHashes")){const S=N0({commitments:_,to:"hex"});p.blobVersionedHashes=S}if(f.includes("sidecars")){const S=Uf({blobs:n,commitments:_,kzg:s}),E=M0({blobs:n,commitments:_,proofs:S,to:"hex"});p.sidecars=E}}if(f.includes("chainId")&&(p.chainId=await w()),(f.includes("fees")||f.includes("type"))&&typeof u>"u")try{p.type=H0(p)}catch{let _=rd.get(e.uid);if(typeof _>"u"){const S=await m();_=typeof(S==null?void 0:S.baseFeePerGas)=="bigint",rd.set(e.uid,_)}p.type=_?"eip1559":"legacy"}if(f.includes("fees"))if(p.type!=="legacy"&&p.type!=="eip2930"){if(typeof p.maxFeePerGas>"u"||typeof p.maxPriorityFeePerGas>"u"){const _=await m(),{maxFeePerGas:S,maxPriorityFeePerGas:E}=await Fu(e,{block:_,chain:i,request:p});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas<E)throw new qw({maxPriorityFeePerGas:E});p.maxPriorityFeePerGas=E,p.maxFeePerGas=S}}else{if(typeof t.maxFeePerGas<"u"||typeof t.maxPriorityFeePerGas<"u")throw new Rf;if(typeof t.gasPrice>"u"){const _=await m(),{gasPrice:S}=await Fu(e,{block:_,chain:i,request:p,type:"legacy"});p.gasPrice=S}}return f.includes("gas")&&typeof o>"u"&&(p.gas=await ue(e,Hf,"estimateGas")({...p,account:l&&{address:l.address,type:"json-rpc"}})),Pn(p),delete p.parameters,p}async function j0(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=typeof r=="bigint"?ne(r):void 0,o=await e.request({method:"eth_getBalance",params:[t,i||n]});return BigInt(o)}async function Hf(e,t){var i,o,s;const{account:r=e.account}=t,n=r?$e(r):void 0;try{let K=function(se){const{block:ae,request:V,rpcStateOverride:R}=se;return e.request({method:"eth_estimateGas",params:R?[V,ae??"latest",R]:ae?[V,ae]:[V]})};const{accessList:a,authorizationList:c,blobs:f,blobVersionedHashes:u,blockNumber:l,blockTag:p,data:h,gas:m,gasPrice:b,maxFeePerBlobGas:w,maxFeePerGas:_,maxPriorityFeePerGas:S,nonce:E,value:v,stateOverride:B,...I}=await Vs(e,{...t,parameters:(n==null?void 0:n.type)==="local"?void 0:["blobVersionedHashes"]}),M=(typeof l=="bigint"?ne(l):void 0)||p,A=Of(B),H=await(async()=>{if(I.to)return I.to;if(c&&c.length>0)return await P0({authorization:c[0]}).catch(()=>{throw new X("`to` is required. Could not infer from `authorizationList`")})})();Pn(t);const F=(s=(o=(i=e.chain)==null?void 0:i.formatters)==null?void 0:o.transactionRequest)==null?void 0:s.format,G=(F||gi)({...qs(I,{format:F}),from:n==null?void 0:n.address,accessList:a,authorizationList:c,blobs:f,blobVersionedHashes:u,data:h,gas:m,gasPrice:b,maxFeePerBlobGas:w,maxFeePerGas:_,maxPriorityFeePerGas:S,nonce:E,to:H,value:v});let te=BigInt(await K({block:M,request:G,rpcStateOverride:A}));if(c){const se=await j0(e,{address:G.from}),ae=await Promise.all(c.map(async V=>{const{address:R}=V,Y=await K({block:M,request:{authorizationList:void 0,data:h,from:n==null?void 0:n.address,to:R,value:ne(se)},rpcStateOverride:A}).catch(()=>100000n);return 2n*BigInt(Y)}));te+=ae.reduce((V,R)=>V+R,0n)}return te}catch(a){throw Lw(a,{...t,account:n,chain:e.chain})}}async function q0(e,t){const{abi:r,address:n,args:i,functionName:o,dataSuffix:s,...a}=t,c=Ut({abi:r,args:i,functionName:o});try{return await ue(e,Hf,"estimateGas")({data:`${c}${s?s.replace("0x",""):""}`,to:n,...a})}catch(f){const u=a.account?$e(a.account):void 0;throw gn(f,{abi:r,address:n,args:i,docsPath:"/docs/contract/estimateContractGas",functionName:o,sender:u==null?void 0:u.address})}}function Co(e,t){if(!He(e,{strict:!1}))throw new yt({address:e});if(!He(t,{strict:!1}))throw new yt({address:t});return e.toLowerCase()===t.toLowerCase()}const nd="/docs/contract/decodeEventLog";function Df(e){const{abi:t,data:r,strict:n,topics:i}=e,o=n??!0,[s,...a]=i;if(!s)throw new Jg({docsPath:nd});const c=t.find(b=>b.type==="event"&&s===Us(qt(b)));if(!(c&&"name"in c)||c.type!=="event")throw new Wp(s,{docsPath:nd});const{name:f,inputs:u}=c,l=u==null?void 0:u.some(b=>!("name"in b&&b.name)),p=l?[]:{},h=u.map((b,w)=>[b,w]).filter(([b])=>"indexed"in b&&b.indexed);for(let b=0;b<h.length;b++){const[w,_]=h[b],S=a[b];if(!S)throw new Ns({abiItem:c,param:w});p[l?_:w.name||_]=u2({param:w,value:S})}const m=u.filter(b=>!("indexed"in b&&b.indexed));if(m.length>0){if(r&&r!=="0x")try{const b=ko(m,r);if(b)if(l)for(let w=0;w<u.length;w++)p[w]=p[w]??b.shift();else for(let w=0;w<m.length;w++)p[m[w].name]=b[w]}catch(b){if(o)throw b instanceof Gp||b instanceof m0?new Zi({abiItem:c,data:r,params:m,size:Oe(r)}):b}else if(o)throw new Zi({abiItem:c,data:"0x",params:m,size:0})}return{eventName:f,args:Object.values(p).length>0?p:void 0}}function u2({param:e,value:t}){return e.type==="string"||e.type==="bytes"||e.type==="tuple"||e.type.match(/^(.*)\[(\d+)?\]$/)?t:(ko([e],t)||[])[0]}function jf(e){const{abi:t,args:r,logs:n,strict:i=!0}=e,o=(()=>{if(e.eventName)return Array.isArray(e.eventName)?e.eventName:[e.eventName]})();return n.map(s=>{var a;try{const c=t.find(u=>u.type==="event"&&s.topics[0]===Us(u));if(!c)return null;const f=Df({...s,abi:[c],strict:i});return o&&!o.includes(f.eventName)||!f2({args:f.args,inputs:c.inputs,matchArgs:r})?null:{...f,...s}}catch(c){let f,u;if(c instanceof Wp)return null;if(c instanceof Zi||c instanceof Ns){if(i)return null;f=c.abiItem.name,u=(a=c.abiItem.inputs)==null?void 0:a.some(l=>!("name"in l&&l.name))}return{...s,args:u?[]:{},eventName:f}}}).filter(Boolean)}function f2(e){const{args:t,inputs:r,matchArgs:n}=e;if(!n)return!0;if(!t)return!1;function i(o,s,a){try{return o.type==="address"?Co(s,a):o.type==="string"||o.type==="bytes"?Je(bi(s))===a:s===a}catch{return!1}}return Array.isArray(t)&&Array.isArray(n)?n.every((o,s)=>{if(o==null)return!0;const a=r[s];return a?(Array.isArray(o)?o:[o]).some(f=>i(a,f,t[s])):!1}):typeof t=="object"&&!Array.isArray(t)&&typeof n=="object"&&!Array.isArray(n)?Object.entries(n).every(([o,s])=>{if(s==null)return!0;const a=r.find(f=>f.name===o);return a?(Array.isArray(s)?s:[s]).some(f=>i(a,f,t[o])):!1}):!1}function Pr(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 qf(e,{address:t,blockHash:r,fromBlock:n,toBlock:i,event:o,events:s,args:a,strict:c}={}){const f=c??!1,u=s??(o?[o]:void 0);let l=[];u&&(l=[u.flatMap(b=>Io({abi:[b],eventName:b.name,args:s?void 0:a}))],o&&(l=l[0]));let p;r?p=await e.request({method:"eth_getLogs",params:[{address:t,topics:l,blockHash:r}]}):p=await e.request({method:"eth_getLogs",params:[{address:t,topics:l,fromBlock:typeof n=="bigint"?ne(n):n,toBlock:typeof i=="bigint"?ne(i):i}]});const h=p.map(m=>Pr(m));return u?jf({abi:u,args:a,logs:h,strict:f}):h}async function zf(e,t){const{abi:r,address:n,args:i,blockHash:o,eventName:s,fromBlock:a,toBlock:c,strict:f}=t,u=s?Sn({abi:r,name:s}):void 0,l=u?void 0:r.filter(p=>p.type==="event");return ue(e,qf,"getLogs")({address:n,args:i,blockHash:o,event:u,events:l,fromBlock:a,toBlock:c,strict:f})}const Ca="/docs/contract/decodeFunctionResult";function Tn(e){const{abi:t,args:r,functionName:n,data:i}=e;let o=t[0];if(n){const a=Sn({abi:t,args:r,name:n});if(!a)throw new Jn(n,{docsPath:Ca});o=a}if(o.type!=="function")throw new Jn(void 0,{docsPath:Ca});if(!o.outputs)throw new Kp(o.name,{docsPath:Ca});const s=ko(o.outputs,i);if(s&&s.length>1)return s;if(s&&s.length===1)return s[0]}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Gf=BigInt(0),Uu=BigInt(1);function xs(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Ko(e){const t=e.toString(16);return t.length&1?"0"+t:t}function z0(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Gf:BigInt("0x"+e)}function Ws(e){return z0(Ji(e))}function G0(e){return Vt(e),z0(Ji(Uint8Array.from(e).reverse()))}function Vf(e,t){return vf(e.toString(16).padStart(t*2,"0"))}function V0(e,t){return Vf(e,t).reverse()}function Ot(e,t,r){let n;if(typeof t=="string")try{n=vf(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(wf(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}const Na=e=>typeof e=="bigint"&&Gf<=e;function l2(e,t,r){return Na(e)&&Na(t)&&Na(r)&&t<=e&&e<r}function d2(e,t,r,n){if(!l2(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function h2(e){let t;for(t=0;e>Gf;e>>=Uu,t+=1);return t}const Ks=e=>(Uu<<BigInt(e))-Uu;function p2(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");const n=h=>new Uint8Array(h),i=h=>Uint8Array.of(h);let o=n(e),s=n(e),a=0;const c=()=>{o.fill(1),s.fill(0),a=0},f=(...h)=>r(s,o,...h),u=(h=n(0))=>{s=f(i(0),h),o=f(),h.length!==0&&(s=f(i(1),h),o=f())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const m=[];for(;h<t;){o=f();const b=o.slice();m.push(b),h+=o.length}return nn(...m)};return(h,m)=>{c(),u(h);let b;for(;!(b=m(l()));)u();return c(),b}}function Wf(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,o,s){const a=e[i];if(s&&a===void 0)return;const c=typeof a;if(c!==o||a===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${c}`)}Object.entries(t).forEach(([i,o])=>n(i,o,!1)),Object.entries(r).forEach(([i,o])=>n(i,o,!0))}function id(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(i!==void 0)return i;const o=e(r,...n);return t.set(r,o),o}}const y2="0.1.1";function m2(){return y2}class Ie extends Error{constructor(t,r={}){const n=(()=>{var c;if(r.cause instanceof Ie){if(r.cause.details)return r.cause.details;if(r.cause.shortMessage)return r.cause.shortMessage}return r.cause&&"details"in r.cause&&typeof r.cause.details=="string"?r.cause.details:(c=r.cause)!=null&&c.message?r.cause.message:r.details})(),i=r.cause instanceof Ie&&r.cause.docsPath||r.docsPath,s=`https://oxlib.sh${i??""}`,a=[t||"An error occurred.",...r.metaMessages?["",...r.metaMessages]:[],...n||i?["",n?`Details: ${n}`:void 0,i?`See: ${s}`:void 0]:[]].filter(c=>typeof c=="string").join(`
|
|
40
|
-
`);super(a,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:`ox@${m2()}`}),this.cause=r.cause,this.details=n,this.docs=s,this.docsPath=i,this.shortMessage=t}walk(t){return W0(this,t)}}function W0(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause?W0(e.cause,t):t?null:e}const b2="#__bigint";function g2(e,t,r){return JSON.stringify(e,(n,i)=>typeof i=="bigint"?i.toString()+b2:i,r)}function w2(e,t){if(sd(e)>t)throw new I2({givenSize:sd(e),maxSize:t})}const yr={zero:48,nine:57,A:65,F:70,a:97,f:102};function od(e){if(e>=yr.zero&&e<=yr.nine)return e-yr.zero;if(e>=yr.A&&e<=yr.F)return e-(yr.A-10);if(e>=yr.a&&e<=yr.f)return e-(yr.a-10)}function v2(e,t={}){const{dir:r,size:n=32}=t;if(n===0)return e;if(e.length>n)throw new k2({size:e.length,targetSize:n,type:"Bytes"});const i=new Uint8Array(n);for(let o=0;o<n;o++){const s=r==="right";i[s?o:n-o-1]=e[s?o:e.length-o-1]}return i}function Kf(e,t){if(Ft(e)>t)throw new $2({givenSize:Ft(e),maxSize:t})}function _2(e,t){if(typeof t=="number"&&t>0&&t>Ft(e)-1)throw new J0({offset:t,position:"start",size:Ft(e)})}function E2(e,t,r){if(typeof t=="number"&&typeof r=="number"&&Ft(e)!==r-t)throw new J0({offset:r,position:"end",size:Ft(e)})}function K0(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 F2({size:Math.ceil(i.length/2),targetSize:n,type:"Hex"});return`0x${i[r==="right"?"padEnd":"padStart"](n*2,"0")}`}const x2=new TextEncoder;function A2(e){return e instanceof Uint8Array?e:typeof e=="string"?P2(e):S2(e)}function S2(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function P2(e,t={}){const{size:r}=t;let n=e;r&&(Kf(e,r),n=_n(e,r));let i=n.slice(2);i.length%2&&(i=`0${i}`);const o=i.length/2,s=new Uint8Array(o);for(let a=0,c=0;a<o;a++){const f=od(i.charCodeAt(c++)),u=od(i.charCodeAt(c++));if(f===void 0||u===void 0)throw new Ie(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);s[a]=f*16+u}return s}function T2(e,t={}){const{size:r}=t,n=x2.encode(e);return typeof r=="number"?(w2(n,r),B2(n,r)):n}function B2(e,t){return v2(e,{dir:"right",size:t})}function sd(e){return e.length}let I2=class extends Ie{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"})}},k2=class extends Ie{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 O2=new TextEncoder,R2=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function C2(e,t={}){const{strict:r=!1}=t;if(!e)throw new ad(e);if(typeof e!="string")throw new ad(e);if(r&&!/^0x[0-9a-fA-F]*$/.test(e))throw new cd(e);if(!e.startsWith("0x"))throw new cd(e)}function lr(...e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}function Y0(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Kf(r,t.size),vn(r,t.size)):r}function Z0(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=R2[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Kf(n,t.size),_n(n,t.size)):n}function dt(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let o;n?r?o=(1n<<BigInt(n)*8n-1n)-1n:o=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(o=BigInt(Number.MAX_SAFE_INTEGER));const s=typeof o=="bigint"&&r?-o-1n:0;if(o&&i>o||i<s){const f=typeof e=="bigint"?"n":"";throw new X0({max:o?`${o}${f}`:void 0,min:`${s}${f}`,signed:r,size:n,value:`${e}${f}`})}const c=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?vn(c,n):c}function Yf(e,t={}){return Z0(O2.encode(e),t)}function vn(e,t){return K0(e,{dir:"left",size:t})}function _n(e,t){return K0(e,{dir:"right",size:t})}function Zf(e,t,r,n={}){const{strict:i}=n;_2(e,t);const o=`0x${e.replace("0x","").slice((t??0)*2,(r??e.length)*2)}`;return i&&E2(o,t,r),o}function Ft(e){return Math.ceil((e.length-2)/2)}function N2(e,t={}){const{strict:r=!1}=t;try{return C2(e,{strict:r}),!0}catch{return!1}}class X0 extends Ie{constructor({max:t,min:r,signed:n,size:i,value:o}){super(`Number \`${o}\` is not in safe${i?` ${i*8}-bit`:""}${n?" signed":" unsigned"} integer range ${t?`(\`${r}\` to \`${t}\`)`:`(above \`${r}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class ad extends Ie{constructor(t){super(`Value \`${typeof t=="object"?g2(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 cd extends Ie{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 $2 extends Ie{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 J0 extends Ie{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 F2 extends Ie{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 U2(e){return{address:e.address,amount:dt(e.amount),index:dt(e.index),validatorIndex:dt(e.validatorIndex)}}function Q0(e){return{...typeof e.baseFeePerGas=="bigint"&&{baseFeePerGas:dt(e.baseFeePerGas)},...typeof e.blobBaseFee=="bigint"&&{blobBaseFee:dt(e.blobBaseFee)},...typeof e.feeRecipient=="string"&&{feeRecipient:e.feeRecipient},...typeof e.gasLimit=="bigint"&&{gasLimit:dt(e.gasLimit)},...typeof e.number=="bigint"&&{number:dt(e.number)},...typeof e.prevRandao=="bigint"&&{prevRandao:dt(e.prevRandao)},...typeof e.time=="bigint"&&{time:dt(e.time)},...e.withdrawals&&{withdrawals:e.withdrawals.map(U2)}}}const Lu=[{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"}],Mu=[{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"}]}],ey=[{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"}],ty=[...ey,{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"}]}],L2=[...ey,{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"}]}],ud=[{name:"text",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"key",type:"string"}],outputs:[{name:"",type:"string"}]}],fd=[{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"}]}],ld=[{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"}],M2="0x82ad56cb",ry="0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe",H2="0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe",D2="0x608060405234801561001057600080fd5b5060405161069438038061069483398101604081905261002f9161051e565b600061003c848484610048565b9050806000526001601ff35b60007f64926492649264926492649264926492649264926492649264926492649264926100748361040c565b036101e7576000606080848060200190518101906100929190610577565b60405192955090935091506000906001600160a01b038516906100b69085906105dd565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b9087906004016105f9565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d19190610633565b6001600160e01b03191614945050505050610405565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e9061022790879087906004016105f9565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102689190610633565b6001600160e01b031916149050610405565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e7610425565b5060208201516040808401518451859392600091859190811061030c5761030c61065d565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b60408051600081526020810180835289905260ff83169181019190915260608101849052608081018390526001600160a01b0389169060019060a0016020604051602081039080840390855afa1580156103ea573d6000803e3d6000fd5b505050602060405103516001600160a01b0316149450505050505b9392505050565b600060208251101561041d57600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b038116811461045857600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561048c578181015183820152602001610474565b50506000910152565b600082601f8301126104a657600080fd5b81516001600160401b038111156104bf576104bf61045b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156104ed576104ed61045b565b60405281815283820160200185101561050557600080fd5b610516826020830160208701610471565b949350505050565b60008060006060848603121561053357600080fd5b835161053e81610443565b6020850151604086015191945092506001600160401b0381111561056157600080fd5b61056d86828701610495565b9150509250925092565b60008060006060848603121561058c57600080fd5b835161059781610443565b60208501519093506001600160401b038111156105b357600080fd5b6105bf86828701610495565b604086015190935090506001600160401b0381111561056157600080fd5b600082516105ef818460208701610471565b9190910192915050565b828152604060208201526000825180604084015261061e816060850160208701610471565b601f01601f1916919091016060019392505050565b60006020828403121561064557600080fd5b81516001600160e01b03198116811461040557600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572";class Hu extends X{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 j2 extends X{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 q2 extends X{constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join(`
|
|
41
|
-
`),{name:"ChainNotFoundError"})}}class ny extends X{constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class Ys extends X{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const $a="/docs/contract/encodeDeployData";function Zs(e){const{abi:t,args:r,bytecode:n}=e;if(!r||r.length===0)return n;const i=t.find(s=>"type"in s&&s.type==="constructor");if(!i)throw new Wg({docsPath:$a});if(!("inputs"in i))throw new $l({docsPath:$a});if(!i.inputs||i.inputs.length===0)throw new $l({docsPath:$a});const o=Rr(i.inputs,r);return Kt([n,o])}function vi({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 Hu({chain:t,contract:{name:r}});if(e&&n.blockCreated&&n.blockCreated>e)throw new Hu({blockNumber:e,chain:t,contract:{name:r,blockCreated:n.blockCreated}});return n.address}function iy(e,{docsPath:t,...r}){const n=(()=>{const i=js(e,r);return i instanceof Ro?e:i})();return new E0(n,{docsPath:t,...r})}function Xf(){let e=()=>{},t=()=>{};return{promise:new Promise((n,i)=>{e=n,t=i}),resolve:e,reject:t}}const Fa=new Map;function oy({fn:e,id:t,shouldSplitBatch:r,wait:n=0,sort:i}){const o=async()=>{const u=c();s();const l=u.map(({args:p})=>p);l.length!==0&&e(l).then(p=>{i&&Array.isArray(p)&&p.sort(i);for(let h=0;h<u.length;h++){const{resolve:m}=u[h];m==null||m([p[h],p])}}).catch(p=>{for(let h=0;h<u.length;h++){const{reject:m}=u[h];m==null||m(p)}})},s=()=>Fa.delete(t),a=()=>c().map(({args:u})=>u),c=()=>Fa.get(t)||[],f=u=>Fa.set(t,[...c(),u]);return{flush:s,async schedule(u){const{promise:l,resolve:p,reject:h}=Xf();return(r==null?void 0:r([...a(),u]))&&o(),c().length>0?(f({args:u,resolve:p,reject:h}),l):(f({args:u,resolve:p,reject:h}),setTimeout(o,n),l)}}}async function No(e,t){var G,K,te,se;const{account:r=e.account,authorizationList:n,batch:i=!!((G=e.batch)!=null&&G.multicall),blockNumber:o,blockTag:s="latest",accessList:a,blobs:c,blockOverrides:f,code:u,data:l,factory:p,factoryData:h,gas:m,gasPrice:b,maxFeePerBlobGas:w,maxFeePerGas:_,maxPriorityFeePerGas:S,nonce:E,to:v,value:B,stateOverride:I,...N}=t,M=r?$e(r):void 0;if(u&&(p||h))throw new X("Cannot provide both `code` & `factory`/`factoryData` as parameters.");if(u&&v)throw new X("Cannot provide both `code` & `to` as parameters.");const A=u&&l,H=p&&h&&v&&l,F=A||H,D=A?V2({code:u,data:l}):H?W2({data:l,factory:p,factoryData:h,to:v}):l;try{Pn(t);const V=(typeof o=="bigint"?ne(o):void 0)||s,R=f?Q0(f):void 0,Y=Of(I),Q=(se=(te=(K=e.chain)==null?void 0:K.formatters)==null?void 0:te.transactionRequest)==null?void 0:se.format,L=(Q||gi)({...qs(N,{format:Q}),from:M==null?void 0:M.address,accessList:a,authorizationList:n,blobs:c,data:D,gas:m,gasPrice:b,maxFeePerBlobGas:w,maxFeePerGas:_,maxPriorityFeePerGas:S,nonce:E,to:F?void 0:v,value:B});if(i&&z2({request:L})&&!Y&&!R)try{return await G2(e,{...L,blockNumber:o,blockTag:s})}catch(k){if(!(k instanceof ny)&&!(k instanceof Hu))throw k}const z=(()=>{const k=[L,V];return Y&&R?[...k,Y,R]:Y?[...k,Y]:R?[...k,{},R]:k})(),oe=await e.request({method:"eth_call",params:z});return oe==="0x"?{data:void 0}:{data:oe}}catch(ae){const V=K2(ae),{offchainLookup:R,offchainLookupSignature:Y}=await Promise.resolve().then(()=>require("./ccip-l_tRzCaI.cjs"));if(e.ccipRead!==!1&&(V==null?void 0:V.slice(0,10))===Y&&v)return{data:await R(e,{data:V,to:v})};throw F&&(V==null?void 0:V.slice(0,10))==="0x101bb98d"?new Bw({factory:p}):iy(ae,{...t,account:M,chain:e.chain})}}function z2({request:e}){const{data:t,to:r,...n}=e;return!(!t||t.startsWith(M2)||!r||Object.values(n).filter(i=>typeof i<"u").length>0)}async function G2(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:o="latest",data:s,multicallAddress:a,to:c}=t;let f=a;if(!f){if(!e.chain)throw new ny;f=vi({blockNumber:i,chain:e.chain,contract:"multicall3"})}const l=(typeof i=="bigint"?ne(i):void 0)||o,{schedule:p}=oy({id:`${e.uid}.${l}`,wait:n,shouldSplitBatch(w){return w.reduce((S,{data:E})=>S+(E.length-2),0)>r*2},fn:async w=>{const _=w.map(v=>({allowFailure:!0,callData:v.data,target:v.to})),S=Ut({abi:Lu,args:[_],functionName:"aggregate3"}),E=await e.request({method:"eth_call",params:[{data:S,to:f},l]});return Tn({abi:Lu,args:[_],functionName:"aggregate3",data:E||"0x"})}}),[{returnData:h,success:m}]=await p({data:s,to:c});if(!m)throw new Ds({data:h});return h==="0x"?{data:void 0}:{data:h}}function V2(e){const{code:t,data:r}=e;return Zs({abi:jp(["constructor(bytes, bytes)"]),bytecode:ry,args:[t,r]})}function W2(e){const{data:t,factory:r,factoryData:n,to:i}=e;return Zs({abi:jp(["constructor(address, bytes, address, bytes)"]),bytecode:H2,args:[i,t,r,n]})}function K2(e){var r;if(!(e instanceof X))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 dr(e,t){const{abi:r,address:n,args:i,functionName:o,...s}=t,a=Ut({abi:r,args:i,functionName:o});try{const{data:c}=await ue(e,No,"call")({...s,data:a,to:n});return Tn({abi:r,args:i,functionName:o,data:c||"0x"})}catch(c){throw gn(c,{abi:r,address:n,args:i,docsPath:"/docs/contract/readContract",functionName:o})}}async function sy(e,t){const{abi:r,address:n,args:i,dataSuffix:o,functionName:s,...a}=t,c=a.account?$e(a.account):e.account,f=Ut({abi:r,args:i,functionName:s});try{const{data:u}=await ue(e,No,"call")({batch:!1,data:`${f}${o?o.replace("0x",""):""}`,to:n,...a,account:c}),l=Tn({abi:r,args:i,functionName:s,data:u||"0x"}),p=r.filter(h=>"name"in h&&h.name===t.functionName);return{result:l,request:{abi:p,address:n,args:i,dataSuffix:o,functionName:s,...a,account:c}}}catch(u){throw gn(u,{abi:r,address:n,args:i,docsPath:"/docs/contract/simulateContract",functionName:s,sender:c==null?void 0:c.address})}}const Ua=new Map,dd=new Map;let Y2=0;function Tr(e,t,r){const n=++Y2,i=()=>Ua.get(e)||[],o=()=>{const u=i();Ua.set(e,u.filter(l=>l.id!==n))},s=()=>{const u=i();if(!u.some(p=>p.id===n))return;const l=dd.get(e);if(u.length===1&&l){const p=l();p instanceof Promise&&p.catch(()=>{})}o()},a=i();if(Ua.set(e,[...a,{id:n,fns:t}]),a&&a.length>0)return s;const c={};for(const u in t)c[u]=(...l)=>{var h,m;const p=i();if(p.length!==0)for(const b of p)(m=(h=b.fns)[u])==null||m.call(h,...l)};const f=r(c);return typeof f=="function"&&dd.set(e,f),s}async function Du(e){return new Promise(t=>setTimeout(t,e))}function _i(e,{emitOnBegin:t,initialWaitTime:r,interval:n}){let i=!0;const o=()=>i=!1;return(async()=>{let a;t&&(a=await e({unpoll:o}));const c=await(r==null?void 0:r(a))??n;await Du(c);const f=async()=>{i&&(await e({unpoll:o}),await Du(n),f())};f()})(),o}const Z2=new Map,X2=new Map;function J2(e){const t=(i,o)=>({clear:()=>o.delete(i),get:()=>o.get(i),set:s=>o.set(i,s)}),r=t(e,Z2),n=t(e,X2);return{clear:()=>{r.clear(),n.clear()},promise:r,response:n}}async function Q2(e,{cacheKey:t,cacheTime:r=Number.POSITIVE_INFINITY}){const n=J2(t),i=n.response.get();if(i&&r>0&&new Date().getTime()-i.created.getTime()<r)return i.data;let o=n.promise.get();o||(o=e(),n.promise.set(o));try{const s=await o;return n.response.set({created:new Date,data:s}),s}finally{n.promise.clear()}}const ev=e=>`blockNumber.${e}`;async function $o(e,{cacheTime:t=e.cacheTime}={}){const r=await Q2(()=>e.request({method:"eth_blockNumber"}),{cacheKey:ev(e.uid),cacheTime:t});return BigInt(r)}async function Xs(e,{filter:t}){const r="strict"in t&&t.strict,n=await t.request({method:"eth_getFilterChanges",params:[t.id]});if(typeof n[0]=="string")return n;const i=n.map(o=>Pr(o));return!("abi"in t)||!t.abi?i:jf({abi:t.abi,logs:i,strict:r})}async function Js(e,{filter:t}){return t.request({method:"eth_uninstallFilter",params:[t.id]})}function ay(e,t){const{abi:r,address:n,args:i,batch:o=!0,eventName:s,fromBlock:a,onError:c,onLogs:f,poll:u,pollingInterval:l=e.pollingInterval,strict:p}=t;return(typeof u<"u"?u:typeof a=="bigint"?!0:!(e.transport.type==="webSocket"||e.transport.type==="ipc"||e.transport.type==="fallback"&&(e.transport.transports[0].config.type==="webSocket"||e.transport.transports[0].config.type==="ipc")))?(()=>{const w=p??!1,_=Ue(["watchContractEvent",n,i,o,e.uid,s,l,w,a]);return Tr(_,{onLogs:f,onError:c},S=>{let E;a!==void 0&&(E=a-1n);let v,B=!1;const I=_i(async()=>{var N;if(!B){try{v=await ue(e,Pf,"createContractEventFilter")({abi:r,address:n,args:i,eventName:s,strict:w,fromBlock:a})}catch{}B=!0;return}try{let M;if(v)M=await ue(e,Xs,"getFilterChanges")({filter:v});else{const A=await ue(e,$o,"getBlockNumber")({});E&&E<A?M=await ue(e,zf,"getContractEvents")({abi:r,address:n,args:i,eventName:s,fromBlock:E+1n,toBlock:A,strict:w}):M=[],E=A}if(M.length===0)return;if(o)S.onLogs(M);else for(const A of M)S.onLogs([A])}catch(M){v&&M instanceof bn&&(B=!1),(N=S.onError)==null||N.call(S,M)}},{emitOnBegin:!0,interval:l});return async()=>{v&&await ue(e,Js,"uninstallFilter")({filter:v}),I()}})})():(()=>{const w=p??!1,_=Ue(["watchContractEvent",n,i,o,e.uid,s,l,w]);let S=!0,E=()=>S=!1;return Tr(_,{onLogs:f,onError:c},v=>((async()=>{try{const B=(()=>{if(e.transport.type==="fallback"){const M=e.transport.transports.find(A=>A.config.type==="webSocket"||A.config.type==="ipc");return M?M.value:e.transport}return e.transport})(),I=s?Io({abi:r,eventName:s,args:i}):[],{unsubscribe:N}=await B.subscribe({params:["logs",{address:n,topics:I}],onData(M){var H;if(!S)return;const A=M.result;try{const{eventName:F,args:D}=Df({abi:r,data:A.data,topics:A.topics,strict:p}),G=Pr(A,{args:D,eventName:F});v.onLogs([G])}catch(F){let D,G;if(F instanceof Zi||F instanceof Ns){if(p)return;D=F.abiItem.name,G=(H=F.abiItem.inputs)==null?void 0:H.some(te=>!("name"in te&&te.name))}const K=Pr(A,{args:G?[]:{},eventName:D});v.onLogs([K])}},onError(M){var A;(A=v.onError)==null||A.call(v,M)}});E=N,S||E()}catch(B){c==null||c(B)}})(),()=>E()))})()}class Bn extends X{constructor({docsPath:t}={}){super(["Could not find an Account to execute with this Action.","Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client."].join(`
|
|
42
|
-
`),{docsPath:t,docsSlug:"account",name:"AccountNotFoundError"})}}class ls extends X{constructor({docsPath:t,metaMessages:r,type:n}){super(`Account type "${n}" is not supported.`,{docsPath:t,metaMessages:r,name:"AccountTypeNotSupportedError"})}}function cy({chain:e,currentChainId:t}){if(!e)throw new q2;if(t!==e.id)throw new j2({chain:e,currentChainId:t})}function uy(e,{docsPath:t,...r}){const n=(()=>{const i=js(e,r);return i instanceof Ro?e:i})();return new xw(n,{docsPath:t,...r})}async function Jf(e,{serializedTransaction:t}){return e.request({method:"eth_sendRawTransaction",params:[t]},{retryCount:0})}const La=new Ls(128);async function Qs(e,t){var S,E,v,B;const{account:r=e.account,chain:n=e.chain,accessList:i,authorizationList:o,blobs:s,data:a,gas:c,gasPrice:f,maxFeePerBlobGas:u,maxFeePerGas:l,maxPriorityFeePerGas:p,nonce:h,type:m,value:b,...w}=t;if(typeof r>"u")throw new Bn({docsPath:"/docs/actions/wallet/sendTransaction"});const _=r?$e(r):null;try{Pn(t);const I=await(async()=>{if(t.to)return t.to;if(t.to!==null&&o&&o.length>0)return await P0({authorization:o[0]}).catch(()=>{throw new X("`to` is required. Could not infer from `authorizationList`.")})})();if((_==null?void 0:_.type)==="json-rpc"||_===null){let N;n!==null&&(N=await ue(e,wi,"getChainId")({}),cy({currentChainId:N,chain:n}));const M=(v=(E=(S=e.chain)==null?void 0:S.formatters)==null?void 0:E.transactionRequest)==null?void 0:v.format,H=(M||gi)({...qs(w,{format:M}),accessList:i,authorizationList:o,blobs:s,chainId:N,data:a,from:_==null?void 0:_.address,gas:c,gasPrice:f,maxFeePerBlobGas:u,maxFeePerGas:l,maxPriorityFeePerGas:p,nonce:h,to:I,type:m,value:b}),F=La.get(e.uid),D=F?"wallet_sendTransaction":"eth_sendTransaction";try{return await e.request({method:D,params:[H]},{retryCount:0})}catch(G){if(F===!1)throw G;const K=G;if(K.name==="InvalidInputRpcError"||K.name==="InvalidParamsRpcError"||K.name==="MethodNotFoundRpcError"||K.name==="MethodNotSupportedRpcError")return await e.request({method:"wallet_sendTransaction",params:[H]},{retryCount:0}).then(te=>(La.set(e.uid,!0),te)).catch(te=>{const se=te;throw se.name==="MethodNotFoundRpcError"||se.name==="MethodNotSupportedRpcError"?(La.set(e.uid,!1),K):se});throw K}}if((_==null?void 0:_.type)==="local"){const N=await ue(e,Vs,"prepareTransactionRequest")({account:_,accessList:i,authorizationList:o,blobs:s,chain:n,data:a,gas:c,gasPrice:f,maxFeePerBlobGas:u,maxFeePerGas:l,maxPriorityFeePerGas:p,nonce:h,nonceManager:_.nonceManager,parameters:[...D0,"sidecars"],type:m,value:b,...w,to:I}),M=(B=n==null?void 0:n.serializers)==null?void 0:B.transaction,A=await _.signTransaction(N,{serializer:M});return await ue(e,Jf,"sendRawTransaction")({serializedTransaction:A})}throw(_==null?void 0:_.type)==="smart"?new ls({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:"/docs/actions/bundler/sendUserOperation",type:"smart"}):new ls({docsPath:"/docs/actions/wallet/sendTransaction",type:_==null?void 0:_.type})}catch(I){throw I instanceof ls?I:uy(I,{...t,account:_,chain:t.chain||void 0})}}async function fy(e,t){const{abi:r,account:n=e.account,address:i,args:o,dataSuffix:s,functionName:a,...c}=t;if(typeof n>"u")throw new Bn({docsPath:"/docs/contract/writeContract"});const f=n?$e(n):null,u=Ut({abi:r,args:o,functionName:a});try{return await ue(e,Qs,"sendTransaction")({data:`${u}${s?s.replace("0x",""):""}`,to:i,account:f,...c})}catch(l){throw gn(l,{abi:r,address:i,args:o,docsPath:"/docs/contract/writeContract",functionName:a,sender:f==null?void 0:f.address})}}function Ma({abi:e,address:t,client:r}){const n=r,[i,o]=n?"public"in n&&"wallet"in n?[n.public,n.wallet]:"public"in n?[n.public,void 0]:"wallet"in n?[void 0,n.wallet]:[n,n]:[void 0,void 0],s=i!=null,a=o!=null,c={};let f=!1,u=!1,l=!1;for(const p of e)if(p.type==="function"?p.stateMutability==="view"||p.stateMutability==="pure"?f=!0:u=!0:p.type==="event"&&(l=!0),f&&u&&l)break;return s&&(f&&(c.read=new Proxy({},{get(p,h){return(...m)=>{const{args:b,options:w}=Yo(m);return ue(i,dr,"readContract")({abi:e,address:t,functionName:h,args:b,...w})}}})),u&&(c.simulate=new Proxy({},{get(p,h){return(...m)=>{const{args:b,options:w}=Yo(m);return ue(i,sy,"simulateContract")({abi:e,address:t,functionName:h,args:b,...w})}}})),l&&(c.createEventFilter=new Proxy({},{get(p,h){return(...m)=>{const b=e.find(S=>S.type==="event"&&S.name===h),{args:w,options:_}=Ha(m,b);return ue(i,Pf,"createContractEventFilter")({abi:e,address:t,eventName:h,args:w,..._})}}}),c.getEvents=new Proxy({},{get(p,h){return(...m)=>{const b=e.find(S=>S.type==="event"&&S.name===h),{args:w,options:_}=Ha(m,b);return ue(i,zf,"getContractEvents")({abi:e,address:t,eventName:h,args:w,..._})}}}),c.watchEvent=new Proxy({},{get(p,h){return(...m)=>{const b=e.find(S=>S.type==="event"&&S.name===h),{args:w,options:_}=Ha(m,b);return ue(i,ay,"watchContractEvent")({abi:e,address:t,eventName:h,args:w,..._})}}}))),a&&u&&(c.write=new Proxy({},{get(p,h){return(...m)=>{const{args:b,options:w}=Yo(m);return ue(o,fy,"writeContract")({abi:e,address:t,functionName:h,args:b,...w})}}})),(s||a)&&u&&(c.estimateGas=new Proxy({},{get(p,h){return(...m)=>{const{args:b,options:w}=Yo(m);return ue(i??o,q0,"estimateContractGas")({abi:e,address:t,functionName:h,args:b,...w,account:w.account??o.account})}}})),c.address=t,c.abi=e,c}function Yo(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 Ha(e,t){let r=!1;Array.isArray(e[0])?r=!0:e.length===1?r=t.inputs.some(o=>o.indexed):e.length===2&&(r=!0);const n=r?e[0]:void 0,i=(r?e[1]:e[0])??{};return{args:n,options:i}}const ly={"0x0":"reverted","0x1":"success"};function dy(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=>Pr(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?$t(e.transactionIndex):null,status:e.status?ly[e.status]:null,type:e.type?B0[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const tv=kf("transactionReceipt",dy),hy="0x5792579257925792579257925792579257925792579257925792579257925792",py=ne(0,{size:32});async function rv(e,t){const{account:r=e.account,capabilities:n,chain:i=e.chain,experimental_fallback:o,experimental_fallbackDelay:s=32,forceAtomic:a=!1,id:c,version:f="2.0.0"}=t,u=r?$e(r):null,l=t.calls.map(p=>{const h=p,m=h.abi?Ut({abi:h.abi,functionName:h.functionName,args:h.args}):h.data;return{data:h.dataSuffix&&m?Et([m,h.dataSuffix]):m,to:h.to,value:h.value?ne(h.value):void 0}});try{const p=await e.request({method:"wallet_sendCalls",params:[{atomicRequired:a,calls:l,capabilities:n,chainId:ne(i.id),from:u==null?void 0:u.address,id:c,version:f}]},{retryCount:0});return typeof p=="string"?{id:p}:p}catch(p){const h=p;if(o&&(h.name==="MethodNotFoundRpcError"||h.name==="MethodNotSupportedRpcError"||h.name==="UnknownRpcError"||h.details.toLowerCase().includes("does not exist / is not available")||h.details.toLowerCase().includes("missing or invalid. request()")||h.details.toLowerCase().includes("did not match any variant of untagged enum")||h.details.toLowerCase().includes("account upgraded to unsupported contract")||h.details.toLowerCase().includes("eip-7702 not supported")||h.details.toLowerCase().includes("unsupported wc_ method"))){if(n&&Object.values(n).some(S=>!S.optional)){const S="non-optional `capabilities` are not supported on fallback to `eth_sendTransaction`.";throw new ri(new X(S,{details:S}))}if(a&&l.length>1){const _="`forceAtomic` is not supported on fallback to `eth_sendTransaction`.";throw new ni(new X(_,{details:_}))}const m=[];for(const _ of l){const S=Qs(e,{account:u,chain:i,data:_.data,to:_.to,value:_.value?ze(_.value):void 0});m.push(S),s>0&&await new Promise(E=>setTimeout(E,s))}const b=await Promise.allSettled(m);if(b.every(_=>_.status==="rejected"))throw b[0].reason;const w=b.map(_=>_.status==="fulfilled"?_.value:py);return{id:Et([...w,ne(i.id,{size:32}),hy])}}throw uy(p,{...t,account:u,chain:t.chain})}}async function yy(e,t){async function r(u){if(u.endsWith(hy.slice(2))){const p=Nt(Es(u,-64,-32)),h=Es(u,0,-64).slice(2).match(/.{1,64}/g),m=await Promise.all(h.map(w=>py.slice(2)!==w?e.request({method:"eth_getTransactionReceipt",params:[`0x${w}`]},{dedupe:!0}):void 0)),b=m.some(w=>w===null)?100:m.every(w=>(w==null?void 0:w.status)==="0x1")?200:m.every(w=>(w==null?void 0:w.status)==="0x0")?500:600;return{atomic:!1,chainId:$t(p),receipts:m.filter(Boolean),status:b,version:"2.0.0"}}return e.request({method:"wallet_getCallsStatus",params:[u]})}const{atomic:n=!1,chainId:i,receipts:o,version:s="2.0.0",...a}=await r(t.id),[c,f]=(()=>{const u=a.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{...a,atomic:n,chainId:i?$t(i):void 0,receipts:(o==null?void 0:o.map(u=>({...u,blockNumber:ze(u.blockNumber),gasUsed:ze(u.gasUsed),status:ly[u.status]})))??[],statusCode:f,status:c,version:s}}async function nv(e,t){const{id:r,pollingInterval:n=e.pollingInterval,status:i=({statusCode:p})=>p>=200,timeout:o=6e4}=t,s=Ue(["waitForCallsStatus",e.uid,r]),{promise:a,resolve:c,reject:f}=Xf();let u;const l=Tr(s,{resolve:c,reject:f},p=>{const h=_i(async()=>{const m=b=>{clearTimeout(u),h(),b(),l()};try{const b=await yy(e,{id:r});if(!i(b))return;m(()=>p.resolve(b))}catch(b){m(()=>p.reject(b))}},{interval:n,emitOnBegin:!0});return h});return u=o?setTimeout(()=>{l(),clearTimeout(u),f(new iv({id:r}))},o):void 0,await a}class iv extends X{constructor({id:t}){super(`Timed out while waiting for call bundle with id "${t}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}const ju=256;let Zo=ju,Xo;function my(e=11){if(!Xo||Zo+e>ju*2){Xo="",Zo=0;for(let t=0;t<ju;t++)Xo+=(256+Math.random()*256|0).toString(16).substring(1)}return Xo.substring(Zo,Zo+++e)}function by(e){const{batch:t,chain:r,ccipRead:n,key:i="base",name:o="Base Client",type:s="base"}=e,a=(r==null?void 0:r.blockTime)??12e3,c=Math.min(Math.max(Math.floor(a/2),500),4e3),f=e.pollingInterval??c,u=e.cacheTime??f,l=e.account?$e(e.account):void 0,{config:p,request:h,value:m}=e.transport({chain:r,pollingInterval:f}),b={...p,...m},w={account:l,batch:t,cacheTime:u,ccipRead:n,chain:r,key:i,name:o,pollingInterval:f,request:h,transport:b,type:s,uid:my()};function _(S){return E=>{const v=E(S);for(const I in w)delete v[I];const B={...S,...v};return Object.assign(B,{extend:_(B)})}}return Object.assign(w,{extend:_(w)})}const Jo=new Ls(8192);function ov(e,{enabled:t=!0,id:r}){if(!t||!r)return e();if(Jo.get(r))return Jo.get(r);const n=e().finally(()=>Jo.delete(r));return Jo.set(r,n),n}function qu(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((i,o)=>{const s=async({count:a=0}={})=>{const c=async({error:f})=>{const u=typeof t=="function"?t({count:a,error:f}):t;u&&await Du(u),s({count:a+1})};try{const f=await e();i(f)}catch(f){if(a<r&&await n({count:a,error:f}))return c({error:f});o(f)}};s()})}function sv(e,t={}){return async(r,n={})=>{var l;const{dedupe:i=!1,methods:o,retryDelay:s=150,retryCount:a=3,uid:c}={...t,...n},{method:f}=r;if((l=o==null?void 0:o.exclude)!=null&&l.includes(f))throw new on(new Error("method not supported"),{method:f});if(o!=null&&o.include&&!o.include.includes(f))throw new on(new Error("method not supported"),{method:f});const u=i?Qn(`${c}.${Ue(r)}`):void 0;return ov(()=>qu(async()=>{try{return await e(r)}catch(p){const h=p;switch(h.code){case eo.code:throw new eo(h);case to.code:throw new to(h);case ro.code:throw new ro(h,{method:r.method});case no.code:throw new no(h);case mn.code:throw new mn(h);case bn.code:throw new bn(h);case io.code:throw new io(h);case oo.code:throw new oo(h);case so.code:throw new so(h);case on.code:throw new on(h,{method:r.method});case ti.code:throw new ti(h);case ao.code:throw new ao(h);case Wn.code:throw new Wn(h);case co.code:throw new co(h);case uo.code:throw new uo(h);case fo.code:throw new fo(h);case lo.code:throw new lo(h);case ho.code:throw new ho(h);case ri.code:throw new ri(h);case po.code:throw new po(h);case yo.code:throw new yo(h);case mo.code:throw new mo(h);case bo.code:throw new bo(h);case go.code:throw new go(h);case ni.code:throw new ni(h);case 5e3:throw new Wn(h);default:throw p instanceof X?p:new kw(h)}}},{delay:({count:p,error:h})=>{var m;if(h&&h instanceof Vn){const b=(m=h==null?void 0:h.headers)==null?void 0:m.get("Retry-After");if(b!=null&&b.match(/\d/))return Number.parseInt(b)*1e3}return~~(1<<p)*s},retryCount:a,shouldRetry:({error:p})=>av(p)}),{enabled:i,id:u})}}function av(e){return"code"in e&&typeof e.code=="number"?e.code===-1||e.code===ti.code||e.code===mn.code:e instanceof Vn&&e.status?e.status===403||e.status===408||e.status===413||e.status===429||e.status===500||e.status===502||e.status===503||e.status===504:!0}function gy({key:e,methods:t,name:r,request:n,retryCount:i=3,retryDelay:o=150,timeout:s,type:a},c){const f=my();return{config:{key:e,methods:t,name:r,request:n,retryCount:i,retryDelay:o,timeout:s,type:a},request:sv(n,{methods:t,retryCount:i,retryDelay:o,uid:f}),value:c}}function hd(e,t={}){const{key:r="custom",methods:n,name:i="Custom Provider",retryDelay:o}=t;return({retryCount:s})=>gy({key:r,methods:n,name:i,request:e.request.bind(e),retryCount:t.retryCount??s,retryDelay:o,type:"custom"})}class cv extends X{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 uv(e,{errorInstance:t=new Error("timed out"),timeout:r,signal:n}){return new Promise((i,o)=>{(async()=>{let s;try{const a=new AbortController;r>0&&(s=setTimeout(()=>{n&&a.abort()},r)),i(await e({signal:(a==null?void 0:a.signal)||null}))}catch(a){(a==null?void 0:a.name)==="AbortError"&&o(t),o(a)}finally{clearTimeout(s)}})()})}function fv(){return{current:0,take(){return this.current++},reset(){this.current=0}}}const pd=fv();function lv(e,t={}){return{async request(r){var l;const{body:n,onRequest:i=t.onRequest,onResponse:o=t.onResponse,timeout:s=t.timeout??1e4}=r,a={...t.fetchOptions??{},...r.fetchOptions??{}},{headers:c,method:f,signal:u}=a;try{const p=await uv(async({signal:m})=>{const b={...a,body:Array.isArray(n)?Ue(n.map(E=>({jsonrpc:"2.0",id:E.id??pd.take(),...E}))):Ue({jsonrpc:"2.0",id:n.id??pd.take(),...n}),headers:{"Content-Type":"application/json",...c},method:f||"POST",signal:u||(s>0?m:null)},w=new Request(e,b),_=await(i==null?void 0:i(w,b))??{...b,url:e};return await fetch(_.url??e,_)},{errorInstance:new Xl({body:n,url:e}),timeout:s,signal:!0});o&&await o(p);let h;if((l=p.headers.get("Content-Type"))!=null&&l.startsWith("application/json"))h=await p.json();else{h=await p.text();try{h=JSON.parse(h||"{}")}catch(m){if(p.ok)throw m;h={error:h}}}if(!p.ok)throw new Vn({body:n,details:Ue(h.error)||p.statusText,headers:p.headers,status:p.status,url:e});return h}catch(p){throw p instanceof Vn||p instanceof Xl?p:new Vn({body:n,cause:p,url:e})}}}}function wy(e,t={}){const{batch:r,fetchOptions:n,key:i="http",methods:o,name:s="HTTP JSON-RPC",onFetchRequest:a,onFetchResponse:c,retryDelay:f,raw:u}=t;return({chain:l,retryCount:p,timeout:h})=>{const{batchSize:m=1e3,wait:b=0}=typeof r=="object"?r:{},w=t.retryCount??p,_=h??t.timeout??1e4,S=l==null?void 0:l.rpcUrls.default.http[0];if(!S)throw new cv;const E=lv(S,{fetchOptions:n,onRequest:a,onResponse:c,timeout:_});return gy({key:i,methods:o,name:s,async request({method:v,params:B}){const I={method:v,params:B},{schedule:N}=oy({id:S,wait:b,shouldSplitBatch(F){return F.length>m},fn:F=>E.request({body:F}),sort:(F,D)=>F.id-D.id}),M=async F=>r?N(F):[await E.request({body:F})],[{error:A,result:H}]=await M(I);if(u)return{error:A,result:H};if(A)throw new If({body:I,error:A,url:S});return H},retryCount:w,retryDelay:f,timeout:_,type:"http"},{fetchOptions:n,url:S})}}function Qf(e,t){var n,i,o,s,a,c;if(!(e instanceof X))return!1;const r=e.walk(f=>f instanceof Tu);return r instanceof Tu?!!(((n=r.data)==null?void 0:n.errorName)==="ResolverNotFound"||((i=r.data)==null?void 0:i.errorName)==="ResolverWildcardNotSupported"||((o=r.data)==null?void 0:o.errorName)==="ResolverNotContract"||((s=r.data)==null?void 0:s.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===p0[50]):!1}function dv(e){const{abi:t,data:r}=e,n=yn(r,0,4),i=t.find(o=>o.type==="function"&&n===Bo(qt(o)));if(!i)throw new Qg(n,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:i.name,args:"inputs"in i&&i.inputs&&i.inputs.length>0?ko(i.inputs,yn(r,4)):void 0}}const Da="/docs/contract/encodeErrorResult";function yd(e){const{abi:t,errorName:r,args:n}=e;let i=t[0];if(r){const c=Sn({abi:t,args:n,name:r});if(!c)throw new Fl(r,{docsPath:Da});i=c}if(i.type!=="error")throw new Fl(void 0,{docsPath:Da});const o=qt(i),s=Bo(o);let a="0x";if(n&&n.length>0){if(!i.inputs)throw new Xg(i.name,{docsPath:Da});a=Rr(i.inputs,n)}return Kt([s,a])}const ja="/docs/contract/encodeFunctionResult";function hv(e){const{abi:t,functionName:r,result:n}=e;let i=t[0];if(r){const s=Sn({abi:t,name:r});if(!s)throw new Jn(r,{docsPath:ja});i=s}if(i.type!=="function")throw new Jn(void 0,{docsPath:ja});if(!i.outputs)throw new Kp(i.name,{docsPath:ja});const o=(()=>{if(i.outputs.length===0)return[];if(i.outputs.length===1)return[n];if(Array.isArray(n))return n;throw new Yp(n)})();return Rr(i.outputs,o)}const ea="x-batch-gateway:true";async function vy(e){const{data:t,ccipRequest:r}=e,{args:[n]}=dv({abi:Mu,data:t}),i=[],o=[];return await Promise.all(n.map(async(s,a)=>{try{o[a]=s.urls.includes(ea)?await vy({data:s.data,ccipRequest:r}):await r(s),i[a]=!1}catch(c){i[a]=!0,o[a]=pv(c)}})),hv({abi:Mu,functionName:"query",result:[i,o]})}function pv(e){return e.name==="HttpRequestError"&&e.status?yd({abi:Mu,errorName:"HttpError",args:[e.status,e.shortMessage]}):yd({abi:[y0],errorName:"Error",args:["shortMessage"in e?e.shortMessage:e.message]})}function _y(e){if(e.length!==66||e.indexOf("[")!==0||e.indexOf("]")!==65)return null;const t=`0x${e.slice(1,65)}`;return zt(t)?t:null}function ds(e){let t=new Uint8Array(32).fill(0);if(!e)return Le(t);const r=e.split(".");for(let n=r.length-1;n>=0;n-=1){const i=_y(r[n]),o=i?bi(i):Je(un(r[n]),"bytes");t=Je(Et([t,o]),"bytes")}return Le(t)}function yv(e){return`[${e.slice(2)}]`}function mv(e){const t=new Uint8Array(32).fill(0);return e?_y(e)||Je(un(e)):Le(t)}function ta(e){const t=e.replace(/^\.|\.$/gm,"");if(t.length===0)return new Uint8Array(1);const r=new Uint8Array(un(t).byteLength+2);let n=0;const i=t.split(".");for(let o=0;o<i.length;o++){let s=un(i[o]);s.byteLength>255&&(s=un(yv(mv(i[o])))),r[n]=s.length,r.set(s,n+1),n+=s.length+1}return r.byteLength!==n+1?r.slice(0,n+1):r}async function bv(e,t){const{blockNumber:r,blockTag:n,coinType:i,name:o,gatewayUrls:s,strict:a}=t,{chain:c}=e,f=(()=>{if(t.universalResolverAddress)return t.universalResolverAddress;if(!c)throw new Error("client chain not configured. universalResolverAddress is required.");return vi({blockNumber:r,chain:c,contract:"ensUniversalResolver"})})(),u=c==null?void 0:c.ensTlds;if(u&&!u.some(l=>o.endsWith(l)))return null;try{const l=Ut({abi:fd,functionName:"addr",...i!=null?{args:[ds(o),BigInt(i)]}:{args:[ds(o)]}}),p={address:f,abi:ty,functionName:"resolve",args:[nt(ta(o)),l,s??[ea]],blockNumber:r,blockTag:n},m=await ue(e,dr,"readContract")(p);if(m[0]==="0x")return null;const b=Tn({abi:fd,args:i!=null?[ds(o),BigInt(i)]:void 0,functionName:"addr",data:m[0]});return b==="0x"||Nt(b)==="0x00"?null:b}catch(l){if(a)throw l;if(Qf(l,"resolve"))return null;throw l}}class gv extends X{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 Ii extends X{constructor({reason:t}){super(`ENS NFT avatar URI is invalid. ${t}`,{name:"EnsAvatarInvalidNftUriError"})}}class el extends X{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 wv extends X{constructor({namespace:t}){super(`ENS NFT avatar namespace "${t}" is not supported. Must be "erc721" or "erc1155".`,{name:"EnsAvatarUnsupportedNamespaceError"})}}const vv=/(?<protocol>https?:\/\/[^\/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/,_v=/^(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>\/.*)?$/,Ev=/^data:([a-zA-Z\-/+]*);base64,([^"].*)/,xv=/^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;async function Av(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 md(e,t){return e?e.endsWith("/")?e.slice(0,-1):e:t}function Ey({uri:e,gatewayUrls:t}){const r=Ev.test(e);if(r)return{uri:e,isOnChain:!0,isEncoded:r};const n=md(t==null?void 0:t.ipfs,"https://ipfs.io"),i=md(t==null?void 0:t.arweave,"https://arweave.net"),o=e.match(vv),{protocol:s,subpath:a,target:c,subtarget:f=""}=(o==null?void 0:o.groups)||{},u=s==="ipns:/"||a==="ipns/",l=s==="ipfs:/"||a==="ipfs/"||_v.test(e);if(e.startsWith("http")&&!u&&!l){let h=e;return t!=null&&t.arweave&&(h=e.replace(/https:\/\/arweave.net/g,t==null?void 0:t.arweave)),{uri:h,isOnChain:!1,isEncoded:!1}}if((u||l)&&c)return{uri:`${n}/${u?"ipns":"ipfs"}/${c}${f}`,isOnChain:!1,isEncoded:!1};if(s==="ar:/"&&c)return{uri:`${i}/${c}${f||""}`,isOnChain:!1,isEncoded:!1};let p=e.replace(xv,"");if(p.startsWith("<svg")&&(p=`data:image/svg+xml;base64,${btoa(p)}`),p.startsWith("data:")||p.startsWith("{"))return{uri:p,isOnChain:!0,isEncoded:!1};throw new el({uri:e})}function xy(e){if(typeof e!="object"||!("image"in e)&&!("image_url"in e)&&!("image_data"in e))throw new gv({data:e});return e.image||e.image_url||e.image_data}async function Sv({gatewayUrls:e,uri:t}){try{const r=await fetch(t).then(i=>i.json());return await tl({gatewayUrls:e,uri:xy(r)})}catch{throw new el({uri:t})}}async function tl({gatewayUrls:e,uri:t}){const{uri:r,isOnChain:n}=Ey({uri:t,gatewayUrls:e});if(n||await Av(r))return r;throw new el({uri:t})}function Pv(e){let t=e;t.startsWith("did:nft:")&&(t=t.replace("did:nft:","").replace(/_/g,"/"));const[r,n,i]=t.split("/"),[o,s]=r.split(":"),[a,c]=n.split(":");if(!o||o.toLowerCase()!=="eip155")throw new Ii({reason:"Only EIP-155 supported"});if(!s)throw new Ii({reason:"Chain ID not found"});if(!c)throw new Ii({reason:"Contract address not found"});if(!i)throw new Ii({reason:"Token ID not found"});if(!a)throw new Ii({reason:"ERC namespace not found"});return{chainID:Number.parseInt(s),namespace:a.toLowerCase(),contractAddress:c,tokenID:i}}async function Tv(e,{nft:t}){if(t.namespace==="erc721")return dr(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 dr(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 wv({namespace:t.namespace})}async function Bv(e,{gatewayUrls:t,record:r}){return/eip155:/i.test(r)?Iv(e,{gatewayUrls:t,record:r}):tl({uri:r,gatewayUrls:t})}async function Iv(e,{gatewayUrls:t,record:r}){const n=Pv(r),i=await Tv(e,{nft:n}),{uri:o,isOnChain:s,isEncoded:a}=Ey({uri:i,gatewayUrls:t});if(s&&(o.includes("data:application/json;base64,")||o.startsWith("{"))){const f=a?atob(o.replace("data:application/json;base64,","")):o,u=JSON.parse(f);return tl({uri:xy(u),gatewayUrls:t})}let c=n.tokenID;return n.namespace==="erc1155"&&(c=c.replace("0x","").padStart(64,"0")),Sv({gatewayUrls:t,uri:o.replace(/(?:0x)?{id}/,c)})}async function Ay(e,t){const{blockNumber:r,blockTag:n,key:i,name:o,gatewayUrls:s,strict:a}=t,{chain:c}=e,f=(()=>{if(t.universalResolverAddress)return t.universalResolverAddress;if(!c)throw new Error("client chain not configured. universalResolverAddress is required.");return vi({blockNumber:r,chain:c,contract:"ensUniversalResolver"})})(),u=c==null?void 0:c.ensTlds;if(u&&!u.some(l=>o.endsWith(l)))return null;try{const l={address:f,abi:ty,functionName:"resolve",args:[nt(ta(o)),Ut({abi:ud,functionName:"text",args:[ds(o),i]}),s??[ea]],blockNumber:r,blockTag:n},h=await ue(e,dr,"readContract")(l);if(h[0]==="0x")return null;const m=Tn({abi:ud,functionName:"text",data:h[0]});return m===""?null:m}catch(l){if(a)throw l;if(Qf(l,"resolve"))return null;throw l}}async function kv(e,{blockNumber:t,blockTag:r,assetGatewayUrls:n,name:i,gatewayUrls:o,strict:s,universalResolverAddress:a}){const c=await ue(e,Ay,"getEnsText")({blockNumber:t,blockTag:r,key:"avatar",name:i,universalResolverAddress:a,gatewayUrls:o,strict:s});if(!c)return null;try{return await Bv(e,{record:c,gatewayUrls:n})}catch{return null}}async function Ov(e,{address:t,blockNumber:r,blockTag:n,gatewayUrls:i,strict:o,universalResolverAddress:s}){let a=s;if(!a){if(!e.chain)throw new Error("client chain not configured. universalResolverAddress is required.");a=vi({blockNumber:r,chain:e.chain,contract:"ensUniversalResolver"})}const c=`${t.toLowerCase().substring(2)}.addr.reverse`;try{const f={address:a,abi:L2,functionName:"reverse",args:[nt(ta(c))],blockNumber:r,blockTag:n},u=ue(e,dr,"readContract"),[l,p]=i?await u({...f,args:[...f.args,i]}):await u(f);return t.toLowerCase()!==p.toLowerCase()?null:l}catch(f){if(o)throw f;if(Qf(f,"reverse"))return null;throw f}}async function Rv(e,t){const{blockNumber:r,blockTag:n,name:i}=t,{chain:o}=e,s=(()=>{if(t.universalResolverAddress)return t.universalResolverAddress;if(!o)throw new Error("client chain not configured. universalResolverAddress is required.");return vi({blockNumber:r,chain:o,contract:"ensUniversalResolver"})})(),a=o==null?void 0:o.ensTlds;if(a&&!a.some(f=>i.endsWith(f)))throw new Error(`${i} is not a valid ENS TLD (${a==null?void 0:a.join(", ")}) for chain "${o.name}" (id: ${o.id}).`);const[c]=await ue(e,dr,"readContract")({address:s,abi:[{inputs:[{type:"bytes"}],name:"findResolver",outputs:[{type:"address"},{type:"bytes32"}],stateMutability:"view",type:"function"}],functionName:"findResolver",args:[nt(ta(i))],blockNumber:r,blockTag:n});return c}async function Sy(e,t){var w,_,S;const{account:r=e.account,blockNumber:n,blockTag:i="latest",blobs:o,data:s,gas:a,gasPrice:c,maxFeePerBlobGas:f,maxFeePerGas:u,maxPriorityFeePerGas:l,to:p,value:h,...m}=t,b=r?$e(r):void 0;try{Pn(t);const v=(typeof n=="bigint"?ne(n):void 0)||i,B=(S=(_=(w=e.chain)==null?void 0:w.formatters)==null?void 0:_.transactionRequest)==null?void 0:S.format,N=(B||gi)({...qs(m,{format:B}),from:b==null?void 0:b.address,blobs:o,data:s,gas:a,gasPrice:c,maxFeePerBlobGas:f,maxFeePerGas:u,maxPriorityFeePerGas:l,to:p,value:h}),M=await e.request({method:"eth_createAccessList",params:[N,v]});return{accessList:M.accessList,gasUsed:BigInt(M.gasUsed)}}catch(E){throw iy(E,{...t,account:b,chain:e.chain})}}async function Cv(e){const t=Ms(e,{method:"eth_newBlockFilter"}),r=await e.request({method:"eth_newBlockFilter"});return{id:r,request:t(r),type:"block"}}async function Py(e,{address:t,args:r,event:n,events:i,fromBlock:o,strict:s,toBlock:a}={}){const c=i??(n?[n]:void 0),f=Ms(e,{method:"eth_newFilter"});let u=[];c&&(u=[c.flatMap(h=>Io({abi:[h],eventName:h.name,args:r}))],n&&(u=u[0]));const l=await e.request({method:"eth_newFilter",params:[{address:t,fromBlock:typeof o=="bigint"?ne(o):o,toBlock:typeof a=="bigint"?ne(a):a,...u.length?{topics:u}:{}}]});return{abi:c,args:r,eventName:n?n.name:void 0,fromBlock:o,id:l,request:f(l),strict:!!s,toBlock:a,type:"event"}}async function Ty(e){const t=Ms(e,{method:"eth_newPendingTransactionFilter"}),r=await e.request({method:"eth_newPendingTransactionFilter"});return{id:r,request:t(r),type:"transaction"}}async function Nv(e){const t=await e.request({method:"eth_blobBaseFee"});return BigInt(t)}async function $v(e,{blockHash:t,blockNumber:r,blockTag:n="latest"}={}){const i=r!==void 0?ne(r):void 0;let o;return t?o=await e.request({method:"eth_getBlockTransactionCountByHash",params:[t]},{dedupe:!0}):o=await e.request({method:"eth_getBlockTransactionCountByNumber",params:[i||n]},{dedupe:!!i}),$t(o)}async function bd(e,{address:t,blockNumber:r,blockTag:n="latest"}){const i=r!==void 0?ne(r):void 0,o=await e.request({method:"eth_getCode",params:[t,i||n]},{dedupe:!!i});if(o!=="0x")return o}class Fv extends X{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 Uv(e,t){const{address:r,factory:n,factoryData:i}=t;try{const[o,s,a,c,f,u,l]=await ue(e,dr,"readContract")({abi:Lv,address:r,functionName:"eip712Domain",factory:n,factoryData:i});return{domain:{name:s,version:a,chainId:Number(c),verifyingContract:f,salt:u},extensions:l,fields:o}}catch(o){const s=o;throw s.name==="ContractFunctionExecutionError"&&s.cause.name==="ContractFunctionZeroDataError"?new Fv({address:r}):s}}const Lv=[{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 Mv(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 Hv(e,{blockCount:t,blockNumber:r,blockTag:n="latest",rewardPercentiles:i}){const o=typeof r=="bigint"?ne(r):void 0,s=await e.request({method:"eth_feeHistory",params:[ne(t),o||n,i]},{dedupe:!!o});return Mv(s)}async function Dv(e,{filter:t}){const r=t.strict??!1,i=(await t.request({method:"eth_getFilterLogs",params:[t.id]})).map(o=>Pr(o));return t.abi?jf({abi:t.abi,logs:i,strict:r}):i}function Lt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}class jv extends X{constructor({domain:t}){super(`Invalid domain "${Ue(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class qv extends X{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 zv extends X{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function Gv(e){const{domain:t={},message:r,primaryType:n}=e,i={EIP712Domain:Cy({domain:t}),...e.types};Ry({domain:t,message:r,primaryType:n,types:i});const o=["0x1901"];return t&&o.push(Vv({domain:t,types:i})),n!=="EIP712Domain"&&o.push(By({data:r,primaryType:n,types:i})),Je(Et(o))}function Vv({domain:e,types:t}){return By({data:e,primaryType:"EIP712Domain",types:t})}function By({data:e,primaryType:t,types:r}){const n=Iy({data:e,primaryType:t,types:r});return Je(n)}function Iy({data:e,primaryType:t,types:r}){const n=[{type:"bytes32"}],i=[Wv({primaryType:t,types:r})];for(const o of r[t]){const[s,a]=Oy({types:r,name:o.name,type:o.type,value:e[o.name]});n.push(s),i.push(a)}return Rr(n,i)}function Wv({primaryType:e,types:t}){const r=nt(Kv({primaryType:e,types:t}));return Je(r)}function Kv({primaryType:e,types:t}){let r="";const n=ky({primaryType:e,types:t});n.delete(e);const i=[e,...Array.from(n).sort()];for(const o of i)r+=`${o}(${t[o].map(({name:s,type:a})=>`${a} ${s}`).join(",")})`;return r}function ky({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 o of t[i])ky({primaryType:o.type,types:t},r);return r}function Oy({types:e,name:t,type:r,value:n}){if(e[r]!==void 0)return[{type:"bytes32"},Je(Iy({data:n,primaryType:r,types:e}))];if(r==="bytes")return n=`0x${(n.length%2?"0":"")+n.slice(2)}`,[{type:"bytes32"},Je(n)];if(r==="string")return[{type:"bytes32"},Je(nt(n))];if(r.lastIndexOf("]")===r.length-1){const i=r.slice(0,r.lastIndexOf("[")),o=n.map(s=>Oy({name:t,type:i,types:e,value:s}));return[{type:"bytes32"},Je(Rr(o.map(([s])=>s),o.map(([,s])=>s)))]}return[{type:r},n]}function Yv(e){const{domain:t,message:r,primaryType:n,types:i}=e,o=(c,f)=>{const u={...f};for(const l of c){const{name:p,type:h}=l;h==="address"&&(u[p]=u[p].toLowerCase())}return u},s=i.EIP712Domain?t?o(i.EIP712Domain,t):{}:{},a=(()=>{if(n!=="EIP712Domain")return o(i[n],r)})();return Ue({domain:s,message:a,primaryType:n,types:i})}function Ry(e){const{domain:t,message:r,primaryType:n,types:i}=e,o=(s,a)=>{for(const c of s){const{name:f,type:u}=c,l=a[f],p=u.match(d0);if(p&&(typeof l=="number"||typeof l=="bigint")){const[b,w,_]=p;ne(l,{signed:w==="int",size:Number.parseInt(_)/8})}if(u==="address"&&typeof l=="string"&&!He(l))throw new yt({address:l});const h=u.match(G1);if(h){const[b,w]=h;if(w&&Oe(l)!==Number.parseInt(w))throw new t1({expectedSize:Number.parseInt(w),givenSize:Oe(l)})}const m=i[u];m&&(Zv(u),o(m,l))}};if(i.EIP712Domain&&t){if(typeof t!="object")throw new jv({domain:t});o(i.EIP712Domain,t)}if(n!=="EIP712Domain")if(i[n])o(i[n],r);else throw new qv({primaryType:n,types:i})}function Cy({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 Zv(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new zv({type:e})}function Xv(e){const{authorizationList:t}=e;if(t)for(const r of t){const{chainId:n}=r,i=r.address;if(!He(i))throw new yt({address:i});if(n<0)throw new Ys({chainId:n})}rl(e)}function Jv(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new L0;for(const r of t){const n=Oe(r),i=$t(yn(r,0,1));if(n!==32)throw new s2({hash:r,size:n});if(i!==U0)throw new a2({hash:r,version:i})}}rl(e)}function rl(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Ys({chainId:t});if(i&&!He(i))throw new yt({address:i});if(n&&n>zs)throw new wn({maxFeePerGas:n});if(r&&n&&r>n)throw new wo({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Qv(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:o}=e;if(t<=0)throw new Ys({chainId:t});if(o&&!He(o))throw new yt({address:o});if(r||i)throw new X("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>zs)throw new wn({maxFeePerGas:n})}function e_(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:o}=e;if(o&&!He(o))throw new yt({address:o});if(typeof t<"u"&&t<=0)throw new Ys({chainId:t});if(r||i)throw new X("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>zs)throw new wn({maxFeePerGas:n})}function ra(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let o=0;o<i.length;o++)if(i[o].length-2!==64)throw new Ew({storageKey:i[o]});if(!He(n,{strict:!1}))throw new yt({address:n});t.push([n,i])}return t}function t_(e,t){const r=H0(e);return r==="eip1559"?i_(e,t):r==="eip2930"?o_(e,t):r==="eip4844"?n_(e,t):r==="eip7702"?r_(e,t):s_(e,t)}function r_(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:o,to:s,value:a,maxFeePerGas:c,maxPriorityFeePerGas:f,accessList:u,data:l}=e;Xv(e);const p=ra(u),h=a_(r);return Kt(["0x04",Yr([ne(n),o?ne(o):"0x",f?ne(f):"0x",c?ne(c):"0x",i?ne(i):"0x",s??"0x",a?ne(a):"0x",l??"0x",p,h,...Fo(e,t)])])}function n_(e,t){const{chainId:r,gas:n,nonce:i,to:o,value:s,maxFeePerBlobGas:a,maxFeePerGas:c,maxPriorityFeePerGas:f,accessList:u,data:l}=e;Jv(e);let p=e.blobVersionedHashes,h=e.sidecars;if(e.blobs&&(typeof p>"u"||typeof h>"u")){const E=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(I=>Le(I)),v=e.kzg,B=Ff({blobs:E,kzg:v});if(typeof p>"u"&&(p=N0({commitments:B})),typeof h>"u"){const I=Uf({blobs:E,commitments:B,kzg:v});h=M0({blobs:E,commitments:B,proofs:I})}}const m=ra(u),b=[ne(r),i?ne(i):"0x",f?ne(f):"0x",c?ne(c):"0x",n?ne(n):"0x",o??"0x",s?ne(s):"0x",l??"0x",m,a?ne(a):"0x",p??[],...Fo(e,t)],w=[],_=[],S=[];if(h)for(let E=0;E<h.length;E++){const{blob:v,commitment:B,proof:I}=h[E];w.push(v),_.push(B),S.push(I)}return Kt(["0x03",Yr(h?[b,w,_,S]:b)])}function i_(e,t){const{chainId:r,gas:n,nonce:i,to:o,value:s,maxFeePerGas:a,maxPriorityFeePerGas:c,accessList:f,data:u}=e;rl(e);const l=ra(f),p=[ne(r),i?ne(i):"0x",c?ne(c):"0x",a?ne(a):"0x",n?ne(n):"0x",o??"0x",s?ne(s):"0x",u??"0x",l,...Fo(e,t)];return Kt(["0x02",Yr(p)])}function o_(e,t){const{chainId:r,gas:n,data:i,nonce:o,to:s,value:a,accessList:c,gasPrice:f}=e;Qv(e);const u=ra(c),l=[ne(r),o?ne(o):"0x",f?ne(f):"0x",n?ne(n):"0x",s??"0x",a?ne(a):"0x",i??"0x",u,...Fo(e,t)];return Kt(["0x01",Yr(l)])}function s_(e,t){const{chainId:r=0,gas:n,data:i,nonce:o,to:s,value:a,gasPrice:c}=e;e_(e);let f=[o?ne(o):"0x",c?ne(c):"0x",n?ne(n):"0x",s??"0x",a?ne(a):"0x",i??"0x"];if(t){const u=(()=>{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 h=27n+(t.v===27n?0n:1n);if(t.v!==h)throw new vw({v:t.v});return h})(),l=Nt(t.r),p=Nt(t.s);f=[...f,ne(u),l==="0x00"?"0x":l,p==="0x00"?"0x":p]}else r>0&&(f=[...f,ne(r),"0x","0x"]);return Yr(f)}function Fo(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const o=Nt(r.r),s=Nt(r.s);return[typeof i=="number"?i?ne(1):"0x":n===0n?"0x":n===1n?ne(1):n===27n?"0x":ne(1),o==="0x00"?"0x":o,s==="0x00"?"0x":s]}function a_(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{chainId:n,nonce:i,...o}=r,s=r.address;t.push([n?nt(n):"0x",s,i?nt(i):"0x",...Fo({},o)])}return t}const c_=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ny=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),u_=Ny.map(e=>(9*e+5)%16),$y=(()=>{const r=[[Ny],[u_]];for(let n=0;n<4;n++)for(let i of r)i.push(i[n].map(o=>c_[o]));return r})(),Fy=$y[0],Uy=$y[1],Ly=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),f_=Fy.map((e,t)=>e.map(r=>Ly[t][r])),l_=Uy.map((e,t)=>e.map(r=>Ly[t][r])),d_=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),h_=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function gd(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 Qo=new Uint32Array(16);let My=class extends k0{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(t,r){for(let h=0;h<16;h++,r+=4)Qo[h]=t.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,a=this.h2|0,c=a,f=this.h3|0,u=f,l=this.h4|0,p=l;for(let h=0;h<5;h++){const m=4-h,b=d_[h],w=h_[h],_=Fy[h],S=Uy[h],E=f_[h],v=l_[h];for(let B=0;B<16;B++){const I=Wo(n+gd(h,o,a,f)+Qo[_[B]]+b,E[B])+l|0;n=l,l=f,f=Wo(a,10)|0,a=o,o=I}for(let B=0;B<16;B++){const I=Wo(i+gd(m,s,c,u)+Qo[S[B]]+w,v[B])+p|0;i=p,p=u,u=Wo(c,10)|0,c=s,s=I}}this.set(this.h1+a+u|0,this.h2+f+p|0,this.h3+l+i|0,this.h4+n+s|0,this.h0+o+c|0)}roundClean(){Kr(Qo)}destroy(){this.destroyed=!0,Kr(this.buffer),this.set(0,0,0,0,0)}};const p_=Fs(()=>new My),y_=My,m_=p_,b_=Object.freeze(Object.defineProperty({__proto__:null,RIPEMD160:y_,ripemd160:m_},Symbol.toStringTag,{value:"Module"})),g_=`Ethereum Signed Message:
|
|
43
|
-
`;function w_(e){const t=typeof e=="string"?Qn(e):typeof e.raw=="string"?e.raw:Le(e.raw),r=Qn(`${g_}${Oe(t)}`);return Et([r,t])}function Hy(e,t){return Je(w_(e),t)}const Dy="0x6492649264926492649264926492649264926492649264926492649264926492";function v_(e){return Es(e,-32)===Dy}function __(e){const{address:t,data:r,signature:n,to:i="hex"}=e,o=Kt([Rr([{type:"address"},{type:"bytes"},{type:"bytes"}],[t,r,n]),Dy]);return i==="hex"?o:Gt(o)}function E_(e){return e.map(t=>({...t,value:BigInt(t.value)}))}function x_(e){return{...e,balance:e.balance?BigInt(e.balance):void 0,nonce:e.nonce?$t(e.nonce):void 0,storageProof:e.storageProof?E_(e.storageProof):void 0}}async function A_(e,{address:t,blockNumber:r,blockTag:n,storageKeys:i}){const o=n??"latest",s=r!==void 0?ne(r):void 0,a=await e.request({method:"eth_getProof",params:[t,i,s||o]});return x_(a)}async function S_(e,{address:t,blockNumber:r,blockTag:n="latest",slot:i}){const o=r!==void 0?ne(r):void 0;return await e.request({method:"eth_getStorageAt",params:[t,i,o||n]})}async function nl(e,{blockHash:t,blockNumber:r,blockTag:n,hash:i,index:o}){var u,l,p;const s=n||"latest",a=r!==void 0?ne(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,ne(o)]},{dedupe:!0}):c=await e.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[a||s,ne(o)]},{dedupe:!!a}),!c)throw new v0({blockHash:t,blockNumber:r,blockTag:s,hash:i,index:o});return(((p=(l=(u=e.chain)==null?void 0:u.formatters)==null?void 0:l.transaction)==null?void 0:p.format)||Gs)(c)}async function P_(e,{hash:t,transactionReceipt:r}){const[n,i]=await Promise.all([ue(e,$o,"getBlockNumber")({}),t?ue(e,nl,"getTransaction")({hash:t}):void 0]),o=(r==null?void 0:r.blockNumber)||(i==null?void 0:i.blockNumber);return o?n-o+1n:0n}async function zu(e,{hash:t}){var i,o,s;const r=await e.request({method:"eth_getTransactionReceipt",params:[t]},{dedupe:!0});if(!r)throw new _0({hash:t});return(((s=(o=(i=e.chain)==null?void 0:i.formatters)==null?void 0:o.transactionReceipt)==null?void 0:s.format)||dy)(r)}async function T_(e,t){var _;const{account:r,allowFailure:n=!0,batchSize:i,blockNumber:o,blockTag:s,multicallAddress:a,stateOverride:c}=t,f=t.contracts,u=i??(typeof((_=e.batch)==null?void 0:_.multicall)=="object"&&e.batch.multicall.batchSize||1024);let l=a;if(!l){if(!e.chain)throw new Error("client chain not configured. multicallAddress is required.");l=vi({blockNumber:o,chain:e.chain,contract:"multicall3"})}const p=[[]];let h=0,m=0;for(let S=0;S<f.length;S++){const{abi:E,address:v,args:B,functionName:I}=f[S];try{const N=Ut({abi:E,args:B,functionName:I});m+=(N.length-2)/2,u>0&&m>u&&p[h].length>0&&(h++,m=(N.length-2)/2,p[h]=[]),p[h]=[...p[h],{allowFailure:!0,callData:N,target:v}]}catch(N){const M=gn(N,{abi:E,address:v,args:B,docsPath:"/docs/contract/multicall",functionName:I,sender:r});if(!n)throw M;p[h]=[...p[h],{allowFailure:!0,callData:"0x",target:v}]}}const b=await Promise.allSettled(p.map(S=>ue(e,dr,"readContract")({abi:Lu,account:r,address:l,args:[S],blockNumber:o,blockTag:s,functionName:"aggregate3",stateOverride:c}))),w=[];for(let S=0;S<b.length;S++){const E=b[S];if(E.status==="rejected"){if(!n)throw E.reason;for(let B=0;B<p[S].length;B++)w.push({status:"failure",error:E.reason,result:void 0});continue}const v=E.value;for(let B=0;B<v.length;B++){const{returnData:I,success:N}=v[B],{callData:M}=p[S][B],{abi:A,address:H,functionName:F,args:D}=f[w.length];try{if(M==="0x")throw new Po;if(!N)throw new Ds({data:I});const G=Tn({abi:A,args:D,data:I,functionName:F});w.push(n?{result:G,status:"success"}:G)}catch(G){const K=gn(G,{abi:A,address:H,args:D,docsPath:"/docs/contract/multicall",functionName:F});if(!n)throw K;w.push({error:K,result:void 0,status:"failure"})}}}if(w.length!==f.length)throw new X("multicall results mismatch");return w}async function Gu(e,t){const{blockNumber:r,blockTag:n="latest",blocks:i,returnFullTransactions:o,traceTransfers:s,validation:a}=t;try{const c=[];for(const p of i){const h=p.blockOverrides?Q0(p.blockOverrides):void 0,m=p.calls.map(w=>{const _=w,S=_.account?$e(_.account):void 0,E=_.abi?Ut(_):_.data,v={..._,data:_.dataSuffix?Et([E||"0x",_.dataSuffix]):E,from:_.from??(S==null?void 0:S.address)};return Pn(v),gi(v)}),b=p.stateOverrides?Of(p.stateOverrides):void 0;c.push({blockOverrides:h,calls:m,stateOverrides:b})}const u=(typeof r=="bigint"?ne(r):void 0)||n;return(await e.request({method:"eth_simulateV1",params:[{blockStateCalls:c,returnFullTransactions:o,traceTransfers:s,validation:a},u]})).map((p,h)=>({...Cf(p),calls:p.calls.map((m,b)=>{var H,F;const{abi:w,args:_,functionName:S,to:E}=i[h].calls[b],v=((H=m.error)==null?void 0:H.data)??m.returnData,B=BigInt(m.gasUsed),I=(F=m.logs)==null?void 0:F.map(D=>Pr(D)),N=m.status==="0x1"?"success":"failure",M=w&&N==="success"&&v!=="0x"?Tn({abi:w,data:v,functionName:S}):null,A=(()=>{var G;if(N==="success")return;let D;if(((G=m.error)==null?void 0:G.data)==="0x"?D=new Po:m.error&&(D=new Ds(m.error)),!!D)return gn(D,{abi:w??[],address:E??"0x",args:_,functionName:S??"<unknown>"})})();return{data:v,gasUsed:B,logs:I,status:N,...N==="success"?{result:M}:{error:A}}})}))}catch(c){const f=c,u=js(f,{});throw u instanceof Ro?f:u}}function jy(e,t={}){const{as:r=typeof e=="string"?"Hex":"Bytes"}=t,n=s0(A2(e));return r==="Bytes"?n:Z0(n)}class B_ extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const I_={checksum:new B_(8192)},qa=I_.checksum,k_=/^0x[a-fA-F0-9]{40}$/;function na(e,t={}){const{strict:r=!0}=t;if(!k_.test(e))throw new wd({address:e,cause:new R_});if(r){if(e.toLowerCase()===e)return;if(O_(e)!==e)throw new wd({address:e,cause:new C_})}}function O_(e){if(qa.has(e))return qa.get(e);na(e,{strict:!1});const t=e.substring(2).toLowerCase(),r=jy(T2(t),{as:"Bytes"}),n=t.split("");for(let o=0;o<40;o+=2)r[o>>1]>>4>=8&&n[o]&&(n[o]=n[o].toUpperCase()),(r[o>>1]&15)>=8&&n[o+1]&&(n[o+1]=n[o+1].toUpperCase());const i=`0x${n.join("")}`;return qa.set(e,i),i}function Vu(e,t={}){const{strict:r=!0}=t??{};try{return na(e,{strict:r}),!0}catch{return!1}}class wd extends Ie{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 R_ extends Ie{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 C_ extends Ie{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}function Wu(e){let t=!0,r="",n=0,i="",o=!1;for(let s=0;s<e.length;s++){const a=e[s];if(["(",")",","].includes(a)&&(t=!0),a==="("&&n++,a===")"&&n--,!!t){if(n===0){if(a===" "&&["event","function","error",""].includes(i))i="";else if(i+=a,a===")"){o=!0;break}continue}if(a===" "){e[s-1]!==","&&r!==","&&r!==",("&&(r="",t=!1);continue}i+=a,r+=a}}if(!o)throw new Ie("Unable to normalize signature.");return i}function Ku(e,t){const r=typeof e,n=t.type;switch(n){case"address":return Vu(e,{strict:!1});case"bool":return r==="boolean";case"function":return r==="string";case"string":return r==="string";default:return n==="tuple"&&"components"in t?Object.values(t.components).every((i,o)=>Ku(Object.values(e)[o],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?r==="number"||r==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?r==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(e)&&e.every(i=>Ku(i,{...t,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function qy(e,t,r){for(const n in e){const i=e[n],o=t[n];if(i.type==="tuple"&&o.type==="tuple"&&"components"in i&&"components"in o)return qy(i.components,o.components,r[n]);const s=[i.type,o.type];if(s.includes("address")&&s.includes("bytes20")?!0:s.includes("address")&&s.includes("string")?Vu(r[n],{strict:!1}):s.includes("address")&&s.includes("bytes")?Vu(r[n],{strict:!1}):!1)return s}}function zy(e,t={}){const{prepare:r=!0}=t,n=Array.isArray(e)||typeof e=="string"?Nl(e):e;return{...n,...r?{hash:zn(n)}:{}}}function N_(e,t,r){const{args:n=[],prepare:i=!0}=r??{},o=N2(t,{strict:!1}),s=e.filter(f=>o?f.type==="function"||f.type==="error"?Gy(f)===Zf(t,0,4):f.type==="event"?zn(f)===t:!1:"name"in f&&f.name===t);if(s.length===0)throw new Yu({name:t});if(s.length===1)return{...s[0],...i?{hash:zn(s[0])}:{}};let a;for(const f of s){if(!("inputs"in f))continue;if(!n||n.length===0){if(!f.inputs||f.inputs.length===0)return{...f,...i?{hash:zn(f)}:{}};continue}if(!f.inputs||f.inputs.length===0||f.inputs.length!==n.length)continue;if(n.every((l,p)=>{const h="inputs"in f&&f.inputs[p];return h?Ku(l,h):!1})){if(a&&"inputs"in a&&a.inputs){const l=qy(f.inputs,a.inputs,n);if(l)throw new F_({abiItem:f,type:l[0]},{abiItem:a,type:l[1]})}a=f}}const c=(()=>{if(a)return a;const[f,...u]=s;return{...f,overloads:u}})();if(!c)throw new Yu({name:t});return{...c,...i?{hash:zn(c)}:{}}}function Gy(e){return Zf(zn(e),0,4)}function $_(e){const t=typeof e=="string"?e:_s(e);return Wu(t)}function zn(e){return typeof e!="string"&&"hash"in e&&e.hash?e.hash:jy(Yf($_(e)))}class F_ extends Ie{constructor(t,r){super("Found ambiguous types in overloaded ABI Items.",{metaMessages:[`\`${t.type}\` in \`${Wu(_s(t.abiItem))}\`, and`,`\`${r.type}\` in \`${Wu(_s(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 Yu extends Ie{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 U_=/^(.*)\[([0-9]*)\]$/,L_=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Vy=/^(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 M_({checksumAddress:e,parameters:t,values:r}){const n=[];for(let i=0;i<t.length;i++)n.push(il({checksumAddress:e,parameter:t[i],value:r[i]}));return n}function il({checksumAddress:e=!1,parameter:t,value:r}){const n=t,i=W_(n.type);if(i){const[o,s]=i;return D_(r,{checksumAddress:e,length:o,parameter:{...n,type:s}})}if(n.type==="tuple")return V_(r,{checksumAddress:e,parameter:n});if(n.type==="address")return H_(r,{checksum:e});if(n.type==="bool")return q_(r);if(n.type.startsWith("uint")||n.type.startsWith("int")){const o=n.type.startsWith("int"),[,,s="256"]=Vy.exec(n.type)??[];return z_(r,{signed:o,size:Number(s)})}if(n.type.startsWith("bytes"))return j_(r,{type:n.type});if(n.type==="string")return G_(r);throw new Zy(n.type)}function ol(e){let t=0;for(let o=0;o<e.length;o++){const{dynamic:s,encoded:a}=e[o];s?t+=32:t+=Ft(a)}const r=[],n=[];let i=0;for(let o=0;o<e.length;o++){const{dynamic:s,encoded:a}=e[o];s?(r.push(dt(t+i,{size:32})),n.push(a),i+=Ft(a)):r.push(a)}return lr(...r,...n)}function H_(e,t){const{checksum:r=!1}=t;return na(e,{strict:r}),{dynamic:!1,encoded:vn(e.toLowerCase())}}function D_(e,t){const{checksumAddress:r,length:n,parameter:i}=t,o=n===null;if(!Array.isArray(e))throw new Y_(e);if(!o&&e.length!==n)throw new K_({expectedLength:n,givenLength:e.length,type:`${i.type}[${n}]`});let s=!1;const a=[];for(let c=0;c<e.length;c++){const f=il({checksumAddress:r,parameter:i,value:e[c]});f.dynamic&&(s=!0),a.push(f)}if(o||s){const c=ol(a);if(o){const f=dt(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?lr(f,c):f}}if(s)return{dynamic:!0,encoded:c}}return{dynamic:!1,encoded:lr(...a.map(({encoded:c})=>c))}}function j_(e,{type:t}){const[,r]=t.split("bytes"),n=Ft(e);if(!r){let i=e;return n%32!==0&&(i=_n(i,Math.ceil((e.length-2)/2/32)*32)),{dynamic:!0,encoded:lr(vn(dt(n,{size:32})),i)}}if(n!==Number.parseInt(r))throw new Ky({expectedSize:Number.parseInt(r),value:e});return{dynamic:!1,encoded:_n(e)}}function q_(e){if(typeof e!="boolean")throw new Ie(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:vn(Y0(e))}}function z_(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 X0({max:n.toString(),min:i.toString(),signed:t,size:r/8,value:e.toString()})}return{dynamic:!1,encoded:dt(e,{size:32,signed:t})}}function G_(e){const t=Yf(e),r=Math.ceil(Ft(t)/32),n=[];for(let i=0;i<r;i++)n.push(_n(Zf(t,i*32,(i+1)*32)));return{dynamic:!0,encoded:lr(_n(dt(Ft(t),{size:32})),...n)}}function V_(e,t){const{checksumAddress:r,parameter:n}=t;let i=!1;const o=[];for(let s=0;s<n.components.length;s++){const a=n.components[s],c=Array.isArray(e)?s:a.name,f=il({checksumAddress:r,parameter:a,value:e[c]});o.push(f),f.dynamic&&(i=!0)}return{dynamic:i,encoded:i?ol(o):lr(...o.map(({encoded:s})=>s))}}function W_(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function Wy(e,t,r){const{checksumAddress:n=!1}={};if(e.length!==t.length)throw new Yy({expectedLength:e.length,givenLength:t.length});const i=M_({checksumAddress:n,parameters:e,values:t}),o=ol(i);return o.length===0?"0x":o}function Zu(e,t){if(e.length!==t.length)throw new Yy({expectedLength:e.length,givenLength:t.length});const r=[];for(let n=0;n<e.length;n++){const i=e[n],o=t[n];r.push(Zu.encode(i,o))}return lr(...r)}(function(e){function t(r,n,i=!1){if(r==="address"){const c=n;return na(c),vn(c.toLowerCase(),i?32:0)}if(r==="string")return Yf(n);if(r==="bytes")return n;if(r==="bool")return vn(Y0(n),i?32:1);const o=r.match(Vy);if(o){const[c,f,u="256"]=o,l=Number.parseInt(u)/8;return dt(n,{size:i?32:l,signed:f==="int"})}const s=r.match(L_);if(s){const[c,f]=s;if(Number.parseInt(f)!==(n.length-2)/2)throw new Ky({expectedSize:Number.parseInt(f),value:n});return _n(n,i?32:0)}const a=r.match(U_);if(a&&Array.isArray(n)){const[c,f]=a,u=[];for(let l=0;l<n.length;l++)u.push(t(f,n[l],!0));return u.length===0?"0x":lr(...u)}throw new Zy(r)}e.encode=t})(Zu||(Zu={}));class K_ extends Ie{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 Ky extends Ie{constructor({expectedSize:t,value:r}){super(`Size of bytes "${r}" (bytes${Ft(r)}) does not match expected size (bytes${t}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class Yy extends Ie{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 Y_ extends Ie{constructor(t){super(`Value \`${t}\` is not a valid array.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidArrayError"})}}class Zy extends Ie{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 Z_(e,t){var i;const{bytecode:r,args:n}=t;return lr(r,(i=e.inputs)!=null&&i.length&&(n!=null&&n.length)?Wy(e.inputs,n):"0x")}function X_(e){return zy(e)}function J_(e,...t){const{overloads:r}=e,n=r?Q_([e,...r],e.name,{args:t[0]}):e,i=eE(n),o=t.length>0?Wy(n.inputs,t[0]):void 0;return o?lr(i,o):i}function Nn(e,t={}){return zy(e,t)}function Q_(e,t,r){const n=N_(e,t,r);if(n.type!=="function")throw new Yu({name:t,type:"function"});return n}function eE(e){return Gy(e)}const tE="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",Qt="0x0000000000000000000000000000000000000000",rE="0x6080604052348015600e575f80fd5b5061016d8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063f8b2cb4f1461002d575b5f80fd5b610047600480360381019061004291906100db565b61005d565b604051610054919061011e565b60405180910390f35b5f8173ffffffffffffffffffffffffffffffffffffffff16319050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100aa82610081565b9050919050565b6100ba816100a0565b81146100c4575f80fd5b50565b5f813590506100d5816100b1565b92915050565b5f602082840312156100f0576100ef61007d565b5b5f6100fd848285016100c7565b91505092915050565b5f819050919050565b61011881610106565b82525050565b5f6020820190506101315f83018461010f565b9291505056fea26469706673582212203b9fe929fe995c7cf9887f0bdba8a36dd78e8b73f149b17d2d9ad7cd09d2dc6264736f6c634300081a0033";async function nE(e,t){const{blockNumber:r,blockTag:n,calls:i,stateOverrides:o,traceAssetChanges:s,traceTransfers:a,validation:c}=t,f=t.account?$e(t.account):void 0;if(s&&!f)throw new X("`account` is required when `traceAssetChanges` is true");const u=f?Z_(X_("constructor(bytes, bytes)"),{bytecode:ry,args:[rE,J_(Nn("function getBalance(address)"),[f.address])]}):void 0,l=s?await Promise.all(t.calls.map(async V=>{if(!V.data&&!V.abi)return;const{accessList:R}=await Sy(e,{account:f.address,...V,data:V.abi?Ut(V):V.data});return R.map(({address:Y,storageKeys:Q})=>Q.length>0?Y:null)})).then(V=>V.flat().filter(Boolean)):[],p=await Gu(e,{blockNumber:r,blockTag:n,blocks:[...s?[{calls:[{data:u}],stateOverrides:o},{calls:l.map((V,R)=>({abi:[Nn("function balanceOf(address) returns (uint256)")],functionName:"balanceOf",args:[f.address],to:V,from:Qt,nonce:R})),stateOverrides:[{address:Qt,nonce:0}]}]:[],{calls:[...i,{}].map(V=>({...V,from:f==null?void 0:f.address})),stateOverrides:o},...s?[{calls:[{data:u}]},{calls:l.map((V,R)=>({abi:[Nn("function balanceOf(address) returns (uint256)")],functionName:"balanceOf",args:[f.address],to:V,from:Qt,nonce:R})),stateOverrides:[{address:Qt,nonce:0}]},{calls:l.map((V,R)=>({to:V,abi:[Nn("function decimals() returns (uint256)")],functionName:"decimals",from:Qt,nonce:R})),stateOverrides:[{address:Qt,nonce:0}]},{calls:l.map((V,R)=>({to:V,abi:[Nn("function tokenURI(uint256) returns (string)")],functionName:"tokenURI",args:[0n],from:Qt,nonce:R})),stateOverrides:[{address:Qt,nonce:0}]},{calls:l.map((V,R)=>({to:V,abi:[Nn("function symbol() returns (string)")],functionName:"symbol",from:Qt,nonce:R})),stateOverrides:[{address:Qt,nonce:0}]}]:[]],traceTransfers:a,validation:c}),h=s?p[2]:p[0],[m,b,,w,_,S,E,v]=s?p:[],{calls:B,...I}=h,N=B.slice(0,-1)??[],M=(m==null?void 0:m.calls)??[],A=(b==null?void 0:b.calls)??[],H=[...M,...A].map(V=>V.status==="success"?ze(V.data):null),F=(w==null?void 0:w.calls)??[],D=(_==null?void 0:_.calls)??[],G=[...F,...D].map(V=>V.status==="success"?ze(V.data):null),K=((S==null?void 0:S.calls)??[]).map(V=>V.status==="success"?V.result:null),te=((v==null?void 0:v.calls)??[]).map(V=>V.status==="success"?V.result:null),se=((E==null?void 0:E.calls)??[]).map(V=>V.status==="success"?V.result:null),ae=[];for(const[V,R]of G.entries()){const Y=H[V];if(typeof R!="bigint"||typeof Y!="bigint")continue;const Q=K[V-1],O=te[V-1],L=se[V-1],z=V===0?{address:tE,decimals:18,symbol:"ETH"}:{address:l[V-1],decimals:L||Q?Number(Q??1):void 0,symbol:O??void 0};ae.some(oe=>oe.token.address===z.address)||ae.push({token:z,value:{pre:Y,post:R,diff:R-Y}})}return{assetChanges:ae,block:I,results:N}}class Xy extends _f{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,E1(t);const n=$s(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,o=new Uint8Array(i);o.set(n.length>i?t.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Kr(o)}update(t){return ei(this),this.iHash.update(t),this}digestInto(t){ei(this),Vt(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:o,blockLen:s,outputLen:a}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Jy=(e,t,r)=>new Xy(e,t).update(r).digest();Jy.create=(e,t)=>new Xy(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const gt=BigInt(0),pt=BigInt(1),sn=BigInt(2),iE=BigInt(3),Qy=BigInt(4),em=BigInt(5),tm=BigInt(8);function Ct(e,t){const r=e%t;return r>=gt?r:t+r}function It(e,t,r){let n=e;for(;t-- >gt;)n*=n,n%=r;return n}function vd(e,t){if(e===gt)throw new Error("invert: expected non-zero number");if(t<=gt)throw new Error("invert: expected positive modulus, got "+t);let r=Ct(e,t),n=t,i=gt,o=pt;for(;r!==gt;){const a=n/r,c=n%r,f=i-o*a;n=r,r=c,i=o,o=f}if(n!==pt)throw new Error("invert: does not exist");return Ct(i,t)}function rm(e,t){const r=(e.ORDER+pt)/Qy,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function oE(e,t){const r=(e.ORDER-em)/tm,n=e.mul(t,sn),i=e.pow(n,r),o=e.mul(t,i),s=e.mul(e.mul(o,sn),i),a=e.mul(o,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function sE(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-pt,r=0;for(;t%sn===gt;)t/=sn,r++;let n=sn;const i=ia(e);for(;_d(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return rm;let o=i.pow(n,t);const s=(t+pt)/sn;return function(c,f){if(c.is0(f))return f;if(_d(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,o),p=c.pow(f,t),h=c.pow(f,s);for(;!c.eql(p,c.ONE);){if(c.is0(p))return c.ZERO;let m=1,b=c.sqr(p);for(;!c.eql(b,c.ONE);)if(m++,b=c.sqr(b),m===u)throw new Error("Cannot find square root");const w=pt<<BigInt(u-m-1),_=c.pow(l,w);u=m,l=c.sqr(_),p=c.mul(p,l),h=c.mul(h,_)}return h}}function aE(e){return e%Qy===iE?rm:e%tm===em?oE:sE(e)}const cE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function uE(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=cE.reduce((n,i)=>(n[i]="function",n),t);return Wf(e,r),e}function fE(e,t,r){if(r<gt)throw new Error("invalid exponent, negatives unsupported");if(r===gt)return e.ONE;if(r===pt)return t;let n=e.ONE,i=t;for(;r>gt;)r&pt&&(n=e.mul(n,i)),i=e.sqr(i),r>>=pt;return n}function nm(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),i=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),o=e.inv(i);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),o),n}function _d(e,t){const r=(e.ORDER-pt)/sn,n=e.pow(t,r),i=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function lE(e,t){t!==void 0&&Xi(t);const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ia(e,t,r=!1,n={}){if(e<=gt)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,o;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");const u=t;u.BITS&&(i=u.BITS),u.sqrt&&(o=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE)}else typeof t=="number"&&(i=t),n.sqrt&&(o=n.sqrt);const{nBitLength:s,nByteLength:a}=lE(e,i);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c;const f=Object.freeze({ORDER:e,isLE:r,BITS:s,BYTES:a,MASK:Ks(s),ZERO:gt,ONE:pt,create:u=>Ct(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return gt<=u&&u<e},is0:u=>u===gt,isValidNot0:u=>!f.is0(u)&&f.isValid(u),isOdd:u=>(u&pt)===pt,neg:u=>Ct(-u,e),eql:(u,l)=>u===l,sqr:u=>Ct(u*u,e),add:(u,l)=>Ct(u+l,e),sub:(u,l)=>Ct(u-l,e),mul:(u,l)=>Ct(u*l,e),pow:(u,l)=>fE(f,u,l),div:(u,l)=>Ct(u*vd(l,e),e),sqrN:u=>u*u,addN:(u,l)=>u+l,subN:(u,l)=>u-l,mulN:(u,l)=>u*l,inv:u=>vd(u,e),sqrt:o||(u=>(c||(c=aE(e)),c(f,u))),toBytes:u=>r?V0(u,a):Vf(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return r?G0(u):Ws(u)},invertBatch:u=>nm(f,u),cmov:(u,l,p)=>p?l:u});return Object.freeze(f)}function im(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 om(e){const t=im(e);return t+Math.ceil(t/2)}function dE(e,t,r=!1){const n=e.length,i=im(t),o=om(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);const s=r?G0(e):Ws(e),a=Ct(s,t-pt)+pt;return r?V0(a,i):Vf(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ii=BigInt(0),an=BigInt(1);function zi(e,t){const r=t.negate();return e?r:t}function hE(e,t,r){const n=s=>s.pz,i=nm(e.Fp,r.map(n));return r.map((s,a)=>s.toAffine(i[a])).map(e.fromAffine)}function sm(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function za(e,t){sm(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1),i=2**e,o=Ks(e),s=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:s}}function Ed(e,t,r){const{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r;let a=Number(e&i),c=e>>s;a>n&&(a-=o,c+=an);const f=t*n,u=f+Math.abs(a)-1,l=a===0,p=a<0,h=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:p,isNegF:h,offsetF:f}}function pE(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 yE(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 Ga=new WeakMap,am=new WeakMap;function Va(e){return am.get(e)||1}function xd(e){if(e!==ii)throw new Error("invalid wNAF")}function mE(e,t){return{constTimeNegate:zi,hasPrecomputes(r){return Va(r)!==1},unsafeLadder(r,n,i=e.ZERO){let o=r;for(;n>ii;)n&an&&(i=i.add(o)),o=o.double(),n>>=an;return i},precomputeWindow(r,n){const{windows:i,windowSize:o}=za(n,t),s=[];let a=r,c=a;for(let f=0;f<i;f++){c=a,s.push(c);for(let u=1;u<o;u++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(r,n,i){let o=e.ZERO,s=e.BASE;const a=za(r,t);for(let c=0;c<a.windows;c++){const{nextN:f,offset:u,isZero:l,isNeg:p,isNegF:h,offsetF:m}=Ed(i,c,a);i=f,l?s=s.add(zi(h,n[m])):o=o.add(zi(p,n[u]))}return xd(i),{p:o,f:s}},wNAFUnsafe(r,n,i,o=e.ZERO){const s=za(r,t);for(let a=0;a<s.windows&&i!==ii;a++){const{nextN:c,offset:f,isZero:u,isNeg:l}=Ed(i,a,s);if(i=c,!u){const p=n[f];o=o.add(l?p.negate():p)}}return xd(i),o},getPrecomputes(r,n,i){let o=Ga.get(n);return o||(o=this.precomputeWindow(n,r),r!==1&&(typeof i=="function"&&(o=i(o)),Ga.set(n,o))),o},wNAFCached(r,n,i){const o=Va(r);return this.wNAF(o,this.getPrecomputes(o,r,i),n)},wNAFCachedUnsafe(r,n,i,o){const s=Va(r);return s===1?this.unsafeLadder(r,n,o):this.wNAFUnsafe(s,this.getPrecomputes(s,r,i),n,o)},setWindowSize(r,n){sm(n,t),am.set(r,n),Ga.delete(r)}}}function bE(e,t,r,n){let i=t,o=e.ZERO,s=e.ZERO;for(;r>ii||n>ii;)r&an&&(o=o.add(i)),n&an&&(s=s.add(i)),i=i.double(),r>>=an,n>>=an;return{p1:o,p2:s}}function gE(e,t,r,n){pE(r,e),yE(n,t);const i=r.length,o=n.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,a=h2(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=Ks(c),u=new Array(Number(f)+1).fill(s),l=Math.floor((t.BITS-1)/c)*c;let p=s;for(let h=l;h>=0;h-=c){u.fill(s);for(let b=0;b<o;b++){const w=n[b],_=Number(w>>BigInt(h)&f);u[_]=u[_].add(r[b])}let m=s;for(let b=u.length-1,w=s;b>0;b--)w=w.add(u[b]),m=m.add(w);if(p=p.add(m),h!==0)for(let b=0;b<c;b++)p=p.double()}return p}function Ad(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return uE(t),t}else return ia(e)}function wE(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const c=t[a];if(!(typeof c=="bigint"&&c>ii))throw new Error(`CURVE.${a} must be positive bigint`)}const n=Ad(t.p,r.Fp),i=Ad(t.n,r.Fn),s=["Gx","Gy","a","b"];for(const a of s)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Sd(e){e.lowS!==void 0&&xs("lowS",e.lowS),e.prehash!==void 0&&xs("prehash",e.prehash)}class vE extends Error{constructor(t=""){super(t)}}const _r={Err:vE,_tlv:{encode:(e,t)=>{const{Err:r}=_r;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=Ko(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const o=n>127?Ko(i.length/2|128):"";return Ko(e)+o+i+t},decode(e,t){const{Err:r}=_r;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++],o=!!(i&128);let s=0;if(!o)s=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 f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}const a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){const{Err:t}=_r;if(e<Gi)throw new t("integer: negative integers are not allowed");let r=Ko(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}=_r;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 Ws(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=_r,i=Ot("signature",e),{v:o,l:s}=n.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=n.decode(2,o),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){const{_tlv:t,_int:r}=_r,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s)),o=n+i;return t.encode(48,o)}},Gi=BigInt(0),Vi=BigInt(1),_E=BigInt(2),es=BigInt(3),EE=BigInt(4);function xE(e,t,r){function n(i){const o=e.sqr(i),s=e.mul(o,i);return e.add(e.add(s,e.mul(i,t)),r)}return n}function cm(e,t,r){const{BYTES:n}=e;function i(o){let s;if(typeof o=="bigint")s=o;else{let a=Ot("private key",o);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");const c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{s=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof o}`)}}if(r&&(s=e.create(s)),!e.isValidNot0(s))throw new Error("invalid private key: out of range [1..N-1]");return s}return i}function AE(e,t={}){const{Fp:r,Fn:n}=wE("weierstrass",e,t),{h:i,n:o}=e;Wf(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:s}=t;if(s&&(!r.is0(e.a)||typeof s.beta!="bigint"||typeof s.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(M,A,H){const{x:F,y:D}=A.toAffine(),G=r.toBytes(F);if(xs("isCompressed",H),H){a();const K=!r.isOdd(D);return nn(um(K),G)}else return nn(Uint8Array.of(4),G,r.toBytes(D))}function f(M){Vt(M);const A=r.BYTES,H=A+1,F=2*A+1,D=M.length,G=M[0],K=M.subarray(1);if(D===H&&(G===2||G===3)){const te=r.fromBytes(K);if(!r.isValid(te))throw new Error("bad point: is not on curve, wrong x");const se=p(te);let ae;try{ae=r.sqrt(se)}catch(Y){const Q=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+Q)}a();const V=r.isOdd(ae);return(G&1)===1!==V&&(ae=r.neg(ae)),{x:te,y:ae}}else if(D===F&&G===4){const te=r.fromBytes(K.subarray(A*0,A*1)),se=r.fromBytes(K.subarray(A*1,A*2));if(!h(te,se))throw new Error("bad point: is not on curve");return{x:te,y:se}}else throw new Error(`bad point: got length ${D}, expected compressed=${H} or uncompressed=${F}`)}const u=t.toBytes||c,l=t.fromBytes||f,p=xE(r,e.a,e.b);function h(M,A){const H=r.sqr(A),F=p(M);return r.eql(H,F)}if(!h(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const m=r.mul(r.pow(e.a,es),EE),b=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(m,b)))throw new Error("bad curve params: a or b");function w(M,A,H=!1){if(!r.isValid(A)||H&&r.is0(A))throw new Error(`bad point coordinate ${M}`);return A}function _(M){if(!(M instanceof B))throw new Error("ProjectivePoint expected")}const S=id((M,A)=>{const{px:H,py:F,pz:D}=M;if(r.eql(D,r.ONE))return{x:H,y:F};const G=M.is0();A==null&&(A=G?r.ONE:r.inv(D));const K=r.mul(H,A),te=r.mul(F,A),se=r.mul(D,A);if(G)return{x:r.ZERO,y:r.ZERO};if(!r.eql(se,r.ONE))throw new Error("invZ was invalid");return{x:K,y:te}}),E=id(M=>{if(M.is0()){if(t.allowInfinityPoint&&!r.is0(M.py))return;throw new Error("bad point: ZERO")}const{x:A,y:H}=M.toAffine();if(!r.isValid(A)||!r.isValid(H))throw new Error("bad point: x or y not field elements");if(!h(A,H))throw new Error("bad point: equation left != right");if(!M.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(M,A,H,F,D){return H=new B(r.mul(H.px,M),H.py,H.pz),A=zi(F,A),H=zi(D,H),A.add(H)}class B{constructor(A,H,F){this.px=w("x",A),this.py=w("y",H,!0),this.pz=w("z",F),Object.freeze(this)}static fromAffine(A){const{x:H,y:F}=A||{};if(!A||!r.isValid(H)||!r.isValid(F))throw new Error("invalid affine point");if(A instanceof B)throw new Error("projective point not allowed");return r.is0(H)&&r.is0(F)?B.ZERO:new B(H,F,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(A){return hE(B,"pz",A)}static fromBytes(A){return Vt(A),B.fromHex(A)}static fromHex(A){const H=B.fromAffine(l(Ot("pointHex",A)));return H.assertValidity(),H}static fromPrivateKey(A){const H=cm(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return B.BASE.multiply(H(A))}static msm(A,H){return gE(B,n,A,H)}precompute(A=8,H=!0){return N.setWindowSize(this,A),H||this.multiply(es),this}_setWindowSize(A){this.precompute(A)}assertValidity(){E(this)}hasEvenY(){const{y:A}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(A)}equals(A){_(A);const{px:H,py:F,pz:D}=this,{px:G,py:K,pz:te}=A,se=r.eql(r.mul(H,te),r.mul(G,D)),ae=r.eql(r.mul(F,te),r.mul(K,D));return se&&ae}negate(){return new B(this.px,r.neg(this.py),this.pz)}double(){const{a:A,b:H}=e,F=r.mul(H,es),{px:D,py:G,pz:K}=this;let te=r.ZERO,se=r.ZERO,ae=r.ZERO,V=r.mul(D,D),R=r.mul(G,G),Y=r.mul(K,K),Q=r.mul(D,G);return Q=r.add(Q,Q),ae=r.mul(D,K),ae=r.add(ae,ae),te=r.mul(A,ae),se=r.mul(F,Y),se=r.add(te,se),te=r.sub(R,se),se=r.add(R,se),se=r.mul(te,se),te=r.mul(Q,te),ae=r.mul(F,ae),Y=r.mul(A,Y),Q=r.sub(V,Y),Q=r.mul(A,Q),Q=r.add(Q,ae),ae=r.add(V,V),V=r.add(ae,V),V=r.add(V,Y),V=r.mul(V,Q),se=r.add(se,V),Y=r.mul(G,K),Y=r.add(Y,Y),V=r.mul(Y,Q),te=r.sub(te,V),ae=r.mul(Y,R),ae=r.add(ae,ae),ae=r.add(ae,ae),new B(te,se,ae)}add(A){_(A);const{px:H,py:F,pz:D}=this,{px:G,py:K,pz:te}=A;let se=r.ZERO,ae=r.ZERO,V=r.ZERO;const R=e.a,Y=r.mul(e.b,es);let Q=r.mul(H,G),O=r.mul(F,K),L=r.mul(D,te),z=r.add(H,F),oe=r.add(G,K);z=r.mul(z,oe),oe=r.add(Q,O),z=r.sub(z,oe),oe=r.add(H,D);let k=r.add(G,te);return oe=r.mul(oe,k),k=r.add(Q,L),oe=r.sub(oe,k),k=r.add(F,D),se=r.add(K,te),k=r.mul(k,se),se=r.add(O,L),k=r.sub(k,se),V=r.mul(R,oe),se=r.mul(Y,L),V=r.add(se,V),se=r.sub(O,V),V=r.add(O,V),ae=r.mul(se,V),O=r.add(Q,Q),O=r.add(O,Q),L=r.mul(R,L),oe=r.mul(Y,oe),O=r.add(O,L),L=r.sub(Q,L),L=r.mul(R,L),oe=r.add(oe,L),Q=r.mul(O,oe),ae=r.add(ae,Q),Q=r.mul(k,oe),se=r.mul(z,se),se=r.sub(se,Q),Q=r.mul(z,O),V=r.mul(k,V),V=r.add(V,Q),new B(se,ae,V)}subtract(A){return this.add(A.negate())}is0(){return this.equals(B.ZERO)}multiply(A){const{endo:H}=t;if(!n.isValidNot0(A))throw new Error("invalid scalar: out of range");let F,D;const G=K=>N.wNAFCached(this,K,B.normalizeZ);if(H){const{k1neg:K,k1:te,k2neg:se,k2:ae}=H.splitScalar(A),{p:V,f:R}=G(te),{p:Y,f:Q}=G(ae);D=R.add(Q),F=v(H.beta,V,Y,K,se)}else{const{p:K,f:te}=G(A);F=K,D=te}return B.normalizeZ([F,D])[0]}multiplyUnsafe(A){const{endo:H}=t,F=this;if(!n.isValid(A))throw new Error("invalid scalar: out of range");if(A===Gi||F.is0())return B.ZERO;if(A===Vi)return F;if(N.hasPrecomputes(this))return this.multiply(A);if(H){const{k1neg:D,k1:G,k2neg:K,k2:te}=H.splitScalar(A),{p1:se,p2:ae}=bE(B,F,G,te);return v(H.beta,se,ae,D,K)}else return N.wNAFCachedUnsafe(F,A)}multiplyAndAddUnsafe(A,H,F){const D=this.multiplyUnsafe(H).add(A.multiplyUnsafe(F));return D.is0()?void 0:D}toAffine(A){return S(this,A)}isTorsionFree(){const{isTorsionFree:A}=t;return i===Vi?!0:A?A(B,this):N.wNAFCachedUnsafe(this,o).is0()}clearCofactor(){const{clearCofactor:A}=t;return i===Vi?this:A?A(B,this):this.multiplyUnsafe(i)}toBytes(A=!0){return xs("isCompressed",A),this.assertValidity(),u(B,this,A)}toRawBytes(A=!0){return this.toBytes(A)}toHex(A=!0){return Ji(this.toBytes(A))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}B.BASE=new B(e.Gx,e.Gy,r.ONE),B.ZERO=new B(r.ZERO,r.ONE,r.ZERO),B.Fp=r,B.Fn=n;const I=n.BITS,N=mE(B,t.endo?Math.ceil(I/2):I);return B}function um(e){return Uint8Array.of(e?2:3)}function SE(e,t,r={}){Wf(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const n=t.randomBytes||I1,i=t.hmac||((F,...D)=>Jy(t.hash,F,nn(...D))),{Fp:o,Fn:s}=e,{ORDER:a,BITS:c}=s;function f(F){const D=a>>Vi;return F>D}function u(F){return f(F)?s.neg(F):F}function l(F,D){if(!s.isValidNot0(D))throw new Error(`invalid signature ${F}: out of range 1..CURVE.n`)}class p{constructor(D,G,K){l("r",D),l("s",G),this.r=D,this.s=G,K!=null&&(this.recovery=K),Object.freeze(this)}static fromCompact(D){const G=s.BYTES,K=Ot("compactSignature",D,G*2);return new p(s.fromBytes(K.subarray(0,G)),s.fromBytes(K.subarray(G,G*2)))}static fromDER(D){const{r:G,s:K}=_r.toSig(Ot("DER",D));return new p(G,K)}assertValidity(){}addRecoveryBit(D){return new p(this.r,this.s,D)}recoverPublicKey(D){const G=o.ORDER,{r:K,s:te,recovery:se}=this;if(se==null||![0,1,2,3].includes(se))throw new Error("recovery id invalid");if(a*_E<G&&se>1)throw new Error("recovery id is ambiguous for h>1 curve");const V=se===2||se===3?K+a:K;if(!o.isValid(V))throw new Error("recovery id 2 or 3 invalid");const R=o.toBytes(V),Y=e.fromHex(nn(um((se&1)===0),R)),Q=s.inv(V),O=E(Ot("msgHash",D)),L=s.create(-O*Q),z=s.create(te*Q),oe=e.BASE.multiplyUnsafe(L).add(Y.multiplyUnsafe(z));if(oe.is0())throw new Error("point at infinify");return oe.assertValidity(),oe}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s.neg(this.s),this.recovery):this}toBytes(D){if(D==="compact")return nn(s.toBytes(this.r),s.toBytes(this.s));if(D==="der")return vf(_r.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ji(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ji(this.toBytes("compact"))}}const h=cm(s,r.allowedPrivateKeyLengths,r.wrapPrivateKey),m={isValidPrivateKey(F){try{return h(F),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const F=a;return dE(n(om(F)),F)},precompute(F=8,D=e.BASE){return D.precompute(F,!1)}};function b(F,D=!0){return e.fromPrivateKey(F).toBytes(D)}function w(F){if(typeof F=="bigint")return!1;if(F instanceof e)return!0;const G=Ot("key",F).length,K=o.BYTES,te=K+1,se=2*K+1;if(!(r.allowedPrivateKeyLengths||s.BYTES===te))return G===te||G===se}function _(F,D,G=!0){if(w(F)===!0)throw new Error("first arg must be private key");if(w(D)===!1)throw new Error("second arg must be public key");return e.fromHex(D).multiply(h(F)).toBytes(G)}const S=t.bits2int||function(F){if(F.length>8192)throw new Error("input is too large");const D=Ws(F),G=F.length*8-c;return G>0?D>>BigInt(G):D},E=t.bits2int_modN||function(F){return s.create(S(F))},v=Ks(c);function B(F){return d2("num < 2^"+c,F,Gi,v),s.toBytes(F)}function I(F,D,G=N){if(["recovered","canonical"].some(z=>z in G))throw new Error("sign() legacy options not supported");const{hash:K}=t;let{lowS:te,prehash:se,extraEntropy:ae}=G;te==null&&(te=!0),F=Ot("msgHash",F),Sd(G),se&&(F=Ot("prehashed msgHash",K(F)));const V=E(F),R=h(D),Y=[B(R),B(V)];if(ae!=null&&ae!==!1){const z=ae===!0?n(o.BYTES):ae;Y.push(Ot("extraEntropy",z))}const Q=nn(...Y),O=V;function L(z){const oe=S(z);if(!s.isValidNot0(oe))return;const k=s.inv(oe),C=e.BASE.multiply(oe).toAffine(),q=s.create(C.x);if(q===Gi)return;const ee=s.create(k*s.create(O+q*R));if(ee===Gi)return;let re=(C.x===q?0:2)|Number(C.y&Vi),x=ee;return te&&f(ee)&&(x=u(ee),re^=1),new p(q,x,re)}return{seed:Q,k2sig:L}}const N={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function A(F,D,G=N){const{seed:K,k2sig:te}=I(F,D,G);return p2(t.hash.outputLen,s.BYTES,i)(K,te)}e.BASE.precompute(8);function H(F,D,G,K=M){const te=F;D=Ot("msgHash",D),G=Ot("publicKey",G),Sd(K);const{lowS:se,prehash:ae,format:V}=K;if("strict"in K)throw new Error("options.strict was renamed to lowS");if(V!==void 0&&!["compact","der","js"].includes(V))throw new Error('format must be "compact", "der" or "js"');const R=typeof te=="string"||wf(te),Y=!R&&!V&&typeof te=="object"&&te!==null&&typeof te.r=="bigint"&&typeof te.s=="bigint";if(!R&&!Y)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Q,O;try{if(Y)if(V===void 0||V==="js")Q=new p(te.r,te.s);else throw new Error("invalid format");if(R){try{V!=="compact"&&(Q=p.fromDER(te))}catch(x){if(!(x instanceof _r.Err))throw x}!Q&&V!=="der"&&(Q=p.fromCompact(te))}O=e.fromHex(G)}catch{return!1}if(!Q||se&&Q.hasHighS())return!1;ae&&(D=t.hash(D));const{r:L,s:z}=Q,oe=E(D),k=s.inv(z),C=s.create(oe*k),q=s.create(L*k),ee=e.BASE.multiplyUnsafe(C).add(O.multiplyUnsafe(q));return ee.is0()?!1:s.create(ee.x)===L}return Object.freeze({getPublicKey:b,getSharedSecret:_,sign:A,verify:H,utils:m,Point:e,Signature:p})}function PE(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=ia(t.n,e.nBitLength),i={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:i}}function TE(e){const{CURVE:t,curveOpts:r}=PE(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function BE(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function IE(e){const{CURVE:t,curveOpts:r,ecdsaOpts:n}=TE(e),i=AE(t,r),o=SE(i,n,r);return BE(e,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function kE(e,t){const r=n=>IE({...e,hash:n});return{...r(t),create:r}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const As={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")};BigInt(0);const OE=BigInt(1),Xu=BigInt(2),Pd=(e,t)=>(e+t/Xu)/t;function RE(e){const t=As.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=It(u,r,t)*u%t,p=It(l,r,t)*u%t,h=It(p,Xu,t)*f%t,m=It(h,i,t)*h%t,b=It(m,o,t)*m%t,w=It(b,a,t)*b%t,_=It(w,c,t)*w%t,S=It(_,a,t)*b%t,E=It(S,r,t)*u%t,v=It(E,s,t)*m%t,B=It(v,n,t)*f%t,I=It(B,Xu,t);if(!Ju.eql(Ju.sqr(I),e))throw new Error("Cannot find square root");return I}const Ju=ia(As.p,void 0,void 0,{sqrt:RE}),fm=kE({...As,Fp:Ju,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=As.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-OE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),a=Pd(o*e,t),c=Pd(-n*e,t);let f=Ct(e-a*r-c*i,t),u=Ct(-a*n-c*o,t);const l=f>s,p=u>s;if(l&&(f=t-f),p&&(u=t-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:f,k2neg:p,k2:u}}}},R0),CE=Object.freeze(Object.defineProperty({__proto__:null,secp256k1:fm},Symbol.toStringTag,{value:"Module"}));function NE({r:e,s:t,to:r="hex",v:n,yParity:i}){const o=(()=>{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")})(),s=`0x${new fm.Signature(ze(e),ze(t)).toCompactHex()}${o===0?"1b":"1c"}`;return r==="hex"?s:Gt(s)}async function sl(e,t){var l,p,h;const{address:r,factory:n,factoryData:i,hash:o,signature:s,universalSignatureVerifierAddress:a=(h=(p=(l=e.chain)==null?void 0:l.contracts)==null?void 0:p.universalSignatureVerifier)==null?void 0:h.address,...c}=t,f=zt(s)?s:typeof s=="object"&&"r"in s&&"s"in s?NE(s):Le(s),u=await(async()=>!n&&!i||v_(f)?f:__({address:n,data:i,signature:f}))();try{const m=a?{to:a,data:Ut({abi:ld,functionName:"isValidSig",args:[r,o,u]}),...c}:{data:Zs({abi:ld,args:[r,o,u],bytecode:D2}),...c},{data:b}=await ue(e,No,"call")(m);return f1(b??"0x0")}catch(m){try{if(Co(c0(r),await x0({hash:o,signature:s})))return!0}catch{}if(m instanceof E0)return!1;throw m}}async function $E(e,{address:t,message:r,factory:n,factoryData:i,signature:o,...s}){const a=Hy(r);return sl(e,{address:t,factory:n,factoryData:i,hash:a,signature:o,...s})}async function FE(e,t){const{address:r,factory:n,factoryData:i,signature:o,message:s,primaryType:a,types:c,domain:f,...u}=t,l=Gv({message:s,primaryType:a,types:c,domain:f});return sl(e,{address:r,factory:n,factoryData:i,hash:l,signature:o,...u})}function lm(e,{emitOnBegin:t=!1,emitMissed:r=!1,onBlockNumber:n,onError:i,poll:o,pollingInterval:s=e.pollingInterval}){const a=typeof o<"u"?o:!(e.transport.type==="webSocket"||e.transport.type==="ipc"||e.transport.type==="fallback"&&(e.transport.transports[0].config.type==="webSocket"||e.transport.transports[0].config.type==="ipc"));let c;return a?(()=>{const l=Ue(["watchBlockNumber",e.uid,t,r,s]);return Tr(l,{onBlockNumber:n,onError:i},p=>_i(async()=>{var h;try{const m=await ue(e,$o,"getBlockNumber")({cacheTime:0});if(c){if(m===c)return;if(m-c>1&&r)for(let b=c+1n;b<m;b++)p.onBlockNumber(b,c),c=b}(!c||m>c)&&(p.onBlockNumber(m,c),c=m)}catch(m){(h=p.onError)==null||h.call(p,m)}},{emitOnBegin:t,interval:s}))})():(()=>{const l=Ue(["watchBlockNumber",e.uid,t,r]);return Tr(l,{onBlockNumber:n,onError:i},p=>{let h=!0,m=()=>h=!1;return(async()=>{try{const b=(()=>{if(e.transport.type==="fallback"){const _=e.transport.transports.find(S=>S.config.type==="webSocket"||S.config.type==="ipc");return _?_.value:e.transport}return e.transport})(),{unsubscribe:w}=await b.subscribe({params:["newHeads"],onData(_){var E;if(!h)return;const S=ze((E=_.result)==null?void 0:E.number);p.onBlockNumber(S,c),c=S},onError(_){var S;(S=p.onError)==null||S.call(p,_)}});m=w,h||m()}catch(b){i==null||i(b)}})(),()=>m()})})()}async function UE(e,{confirmations:t=1,hash:r,onReplaced:n,pollingInterval:i=e.pollingInterval,retryCount:o=6,retryDelay:s=({count:c})=>~~(1<<c)*200,timeout:a=18e4}){const c=Ue(["waitForTransactionReceipt",e.uid,r]);let f,u,l,p=!1,h,m;const{promise:b,resolve:w,reject:_}=Xf(),S=a?setTimeout(()=>{m(),h(),_(new Aw({hash:r}))},a):void 0;return h=Tr(c,{onReplaced:n,resolve:w,reject:_},E=>{m=ue(e,lm,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:i,async onBlockNumber(v){const B=N=>{clearTimeout(S),m(),N(),h()};let I=v;if(!p)try{if(l){if(t>1&&(!l.blockNumber||I-l.blockNumber+1n<t))return;B(()=>E.resolve(l));return}if(f||(p=!0,await qu(async()=>{f=await ue(e,nl,"getTransaction")({hash:r}),f.blockNumber&&(I=f.blockNumber)},{delay:s,retryCount:o}),p=!1),l=await ue(e,zu,"getTransactionReceipt")({hash:r}),t>1&&(!l.blockNumber||I-l.blockNumber+1n<t))return;B(()=>E.resolve(l))}catch(N){if(N instanceof v0||N instanceof _0){if(!f){p=!1;return}try{u=f,p=!0;const M=await qu(()=>ue(e,fr,"getBlock")({blockNumber:I,includeTransactions:!0}),{delay:s,retryCount:o,shouldRetry:({error:F})=>F instanceof T0});p=!1;const A=M.transactions.find(({from:F,nonce:D})=>F===u.from&&D===u.nonce);if(!A||(l=await ue(e,zu,"getTransactionReceipt")({hash:A.hash}),t>1&&(!l.blockNumber||I-l.blockNumber+1n<t)))return;let H="replaced";A.to===u.to&&A.value===u.value&&A.input===u.input?H="repriced":A.from===A.to&&A.value===0n&&(H="cancelled"),B(()=>{var F;(F=E.onReplaced)==null||F.call(E,{reason:H,replacedTransaction:u,transaction:A,transactionReceipt:l}),E.resolve(l)})}catch(M){B(()=>E.reject(M))}}else B(()=>E.reject(N))}}})}),b}function LE(e,{blockTag:t="latest",emitMissed:r=!1,emitOnBegin:n=!1,onBlock:i,onError:o,includeTransactions:s,poll:a,pollingInterval:c=e.pollingInterval}){const f=typeof a<"u"?a:!(e.transport.type==="webSocket"||e.transport.type==="ipc"||e.transport.type==="fallback"&&(e.transport.transports[0].config.type==="webSocket"||e.transport.transports[0].config.type==="ipc")),u=s??!1;let l;return f?(()=>{const m=Ue(["watchBlocks",e.uid,t,r,n,u,c]);return Tr(m,{onBlock:i,onError:o},b=>_i(async()=>{var w;try{const _=await ue(e,fr,"getBlock")({blockTag:t,includeTransactions:u});if(_.number!==null&&(l==null?void 0:l.number)!=null){if(_.number===l.number)return;if(_.number-l.number>1&&r)for(let S=(l==null?void 0:l.number)+1n;S<_.number;S++){const E=await ue(e,fr,"getBlock")({blockNumber:S,includeTransactions:u});b.onBlock(E,l),l=E}}((l==null?void 0:l.number)==null||t==="pending"&&(_==null?void 0:_.number)==null||_.number!==null&&_.number>l.number)&&(b.onBlock(_,l),l=_)}catch(_){(w=b.onError)==null||w.call(b,_)}},{emitOnBegin:n,interval:c}))})():(()=>{let m=!0,b=!0,w=()=>m=!1;return(async()=>{try{n&&ue(e,fr,"getBlock")({blockTag:t,includeTransactions:u}).then(E=>{m&&b&&(i(E,void 0),b=!1)}).catch(o);const _=(()=>{if(e.transport.type==="fallback"){const E=e.transport.transports.find(v=>v.config.type==="webSocket"||v.config.type==="ipc");return E?E.value:e.transport}return e.transport})(),{unsubscribe:S}=await _.subscribe({params:["newHeads"],async onData(E){var B;if(!m)return;const v=await ue(e,fr,"getBlock")({blockNumber:(B=E.result)==null?void 0:B.number,includeTransactions:u}).catch(()=>{});m&&(i(v,l),b=!1,l=v)},onError(E){o==null||o(E)}});w=S,m||w()}catch(_){o==null||o(_)}})(),()=>w()})()}function ME(e,{address:t,args:r,batch:n=!0,event:i,events:o,fromBlock:s,onError:a,onLogs:c,poll:f,pollingInterval:u=e.pollingInterval,strict:l}){const p=typeof f<"u"?f:typeof s=="bigint"?!0:!(e.transport.type==="webSocket"||e.transport.type==="ipc"||e.transport.type==="fallback"&&(e.transport.transports[0].config.type==="webSocket"||e.transport.transports[0].config.type==="ipc")),h=l??!1;return p?(()=>{const w=Ue(["watchEvent",t,r,n,e.uid,i,u,s]);return Tr(w,{onLogs:c,onError:a},_=>{let S;s!==void 0&&(S=s-1n);let E,v=!1;const B=_i(async()=>{var I;if(!v){try{E=await ue(e,Py,"createEventFilter")({address:t,args:r,event:i,events:o,strict:h,fromBlock:s})}catch{}v=!0;return}try{let N;if(E)N=await ue(e,Xs,"getFilterChanges")({filter:E});else{const M=await ue(e,$o,"getBlockNumber")({});S&&S!==M?N=await ue(e,qf,"getLogs")({address:t,args:r,event:i,events:o,fromBlock:S+1n,toBlock:M}):N=[],S=M}if(N.length===0)return;if(n)_.onLogs(N);else for(const M of N)_.onLogs([M])}catch(N){E&&N instanceof bn&&(v=!1),(I=_.onError)==null||I.call(_,N)}},{emitOnBegin:!0,interval:u});return async()=>{E&&await ue(e,Js,"uninstallFilter")({filter:E}),B()}})})():(()=>{let w=!0,_=()=>w=!1;return(async()=>{try{const S=(()=>{if(e.transport.type==="fallback"){const I=e.transport.transports.find(N=>N.config.type==="webSocket"||N.config.type==="ipc");return I?I.value:e.transport}return e.transport})(),E=o??(i?[i]:void 0);let v=[];E&&(v=[E.flatMap(N=>Io({abi:[N],eventName:N.name,args:r}))],i&&(v=v[0]));const{unsubscribe:B}=await S.subscribe({params:["logs",{address:t,topics:v}],onData(I){var M;if(!w)return;const N=I.result;try{const{eventName:A,args:H}=Df({abi:E??[],data:N.data,topics:N.topics,strict:h}),F=Pr(N,{args:H,eventName:A});c([F])}catch(A){let H,F;if(A instanceof Zi||A instanceof Ns){if(l)return;H=A.abiItem.name,F=(M=A.abiItem.inputs)==null?void 0:M.some(G=>!("name"in G&&G.name))}const D=Pr(N,{args:F?[]:{},eventName:H});c([D])}},onError(I){a==null||a(I)}});_=B,w||_()}catch(S){a==null||a(S)}})(),()=>_()})()}function HE(e,{batch:t=!0,onError:r,onTransactions:n,poll:i,pollingInterval:o=e.pollingInterval}){return(typeof i<"u"?i:e.transport.type!=="webSocket"&&e.transport.type!=="ipc")?(()=>{const f=Ue(["watchPendingTransactions",e.uid,t,o]);return Tr(f,{onTransactions:n,onError:r},u=>{let l;const p=_i(async()=>{var h;try{if(!l)try{l=await ue(e,Ty,"createPendingTransactionFilter")({});return}catch(b){throw p(),b}const m=await ue(e,Xs,"getFilterChanges")({filter:l});if(m.length===0)return;if(t)u.onTransactions(m);else for(const b of m)u.onTransactions([b])}catch(m){(h=u.onError)==null||h.call(u,m)}},{emitOnBegin:!0,interval:o});return async()=>{l&&await ue(e,Js,"uninstallFilter")({filter:l}),p()}})})():(()=>{let f=!0,u=()=>f=!1;return(async()=>{try{const{unsubscribe:l}=await e.transport.subscribe({params:["newPendingTransactions"],onData(p){if(!f)return;const h=p.result;n([h])},onError(p){r==null||r(p)}});u=l,f||u()}catch(l){r==null||r(l)}})(),()=>u()})()}function DE(e){var l,p,h;const{scheme:t,statement:r,...n}=((l=e.match(jE))==null?void 0:l.groups)??{},{chainId:i,expirationTime:o,issuedAt:s,notBefore:a,requestId:c,...f}=((p=e.match(qE))==null?void 0:p.groups)??{},u=(h=e.split("Resources:")[1])==null?void 0:h.split(`
|
|
45
|
-
- `).slice(1);return{...n,...f,...i?{chainId:Number(i)}:{},...o?{expirationTime:new Date(o)}:{},...s?{issuedAt:new Date(s)}:{},...a?{notBefore:new Date(a)}:{},...c?{requestId:c}:{},...u?{resources:u}:{},...t?{scheme:t}:{},...r?{statement:r}:{}}}const jE=/^(?:(?<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)?/,qE=/(?: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 zE(e){const{address:t,domain:r,message:n,nonce:i,scheme:o,time:s=new Date}=e;if(r&&n.domain!==r||i&&n.nonce!==i||o&&n.scheme!==o||n.expirationTime&&s>=n.expirationTime||n.notBefore&&s<n.notBefore)return!1;try{if(!n.address||!He(n.address,{strict:!1})||t&&!Co(n.address,t))return!1}catch{return!1}return!0}async function GE(e,t){const{address:r,domain:n,message:i,nonce:o,scheme:s,signature:a,time:c=new Date,...f}=t,u=DE(i);if(!u.address||!zE({address:r,domain:n,message:u,nonce:o,scheme:s,time:c}))return!1;const p=Hy(i);return sl(e,{address:u.address,hash:p,signature:a,...f})}function VE(e){return{call:t=>No(e,t),createAccessList:t=>Sy(e,t),createBlockFilter:()=>Cv(e),createContractEventFilter:t=>Pf(e,t),createEventFilter:t=>Py(e,t),createPendingTransactionFilter:()=>Ty(e),estimateContractGas:t=>q0(e,t),estimateGas:t=>Hf(e,t),getBalance:t=>j0(e,t),getBlobBaseFee:()=>Nv(e),getBlock:t=>fr(e,t),getBlockNumber:t=>$o(e,t),getBlockTransactionCount:t=>$v(e,t),getBytecode:t=>bd(e,t),getChainId:()=>wi(e),getCode:t=>bd(e,t),getContractEvents:t=>zf(e,t),getEip712Domain:t=>Uv(e,t),getEnsAddress:t=>bv(e,t),getEnsAvatar:t=>kv(e,t),getEnsName:t=>Ov(e,t),getEnsResolver:t=>Rv(e,t),getEnsText:t=>Ay(e,t),getFeeHistory:t=>Hv(e,t),estimateFeesPerGas:t=>Kw(e,t),getFilterChanges:t=>Xs(e,t),getFilterLogs:t=>Dv(e,t),getGasPrice:()=>Nf(e),getLogs:t=>qf(e,t),getProof:t=>A_(e,t),estimateMaxPriorityFeePerGas:t=>Ww(e,t),getStorageAt:t=>S_(e,t),getTransaction:t=>nl(e,t),getTransactionConfirmations:t=>P_(e,t),getTransactionCount:t=>$f(e,t),getTransactionReceipt:t=>zu(e,t),multicall:t=>T_(e,t),prepareTransactionRequest:t=>Vs(e,t),readContract:t=>dr(e,t),sendRawTransaction:t=>Jf(e,t),simulate:t=>Gu(e,t),simulateBlocks:t=>Gu(e,t),simulateCalls:t=>nE(e,t),simulateContract:t=>sy(e,t),verifyMessage:t=>$E(e,t),verifySiweMessage:t=>GE(e,t),verifyTypedData:t=>FE(e,t),uninstallFilter:t=>Js(e,t),waitForTransactionReceipt:t=>UE(e,t),watchBlocks:t=>LE(e,t),watchBlockNumber:t=>lm(e,t),watchContractEvent:t=>ay(e,t),watchEvent:t=>ME(e,t),watchPendingTransactions:t=>HE(e,t)}}function WE(e){const{key:t="public",name:r="Public Client"}=e;return by({...e,key:t,name:r,type:"publicClient"}).extend(VE)}async function KE(e,{chain:t}){const{id:r,name:n,nativeCurrency:i,rpcUrls:o,blockExplorers:s}=t;await e.request({method:"wallet_addEthereumChain",params:[{chainId:ne(r),chainName:n,nativeCurrency:i,rpcUrls:o.default.http,blockExplorerUrls:s?Object.values(s).map(({url:a})=>a):void 0}]},{dedupe:!0,retryCount:0})}function YE(e,t){const{abi:r,args:n,bytecode:i,...o}=t,s=Zs({abi:r,args:n,bytecode:i});return Qs(e,{...o,...o.authorizationList?{to:null}:{},data:s})}async function ZE(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=>To(n))}async function XE(e,t={}){const{account:r=e.account,chainId:n}=t,i=r?$e(r):void 0,o=n?[i==null?void 0:i.address,[ne(n)]]:[i==null?void 0:i.address],s=await e.request({method:"wallet_getCapabilities",params:o}),a={};for(const[c,f]of Object.entries(s)){a[Number(c)]={};for(let[u,l]of Object.entries(f))u==="addSubAccount"&&(u="unstable_addSubAccount"),a[Number(c)][u]=l}return typeof n=="number"?a[n]:a}async function JE(e){return await e.request({method:"wallet_getPermissions"},{dedupe:!0})}async function dm(e,t){var c;const{account:r=e.account,chainId:n,nonce:i}=t;if(!r)throw new Bn({docsPath:"/docs/eip7702/prepareAuthorization"});const o=$e(r),s=(()=>{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 ue(e,wi,"getChainId")({})),typeof a.nonce>"u"&&(a.nonce=await ue(e,$f,"getTransactionCount")({address:o.address,blockTag:"pending"}),(s==="self"||s!=null&&s.address&&Co(s.address,o.address))&&(a.nonce+=1)),a}async function QE(e){return(await e.request({method:"eth_requestAccounts"},{dedupe:!0,retryCount:0})).map(r=>c0(r))}async function e6(e,t){return e.request({method:"wallet_requestPermissions",params:[t]},{retryCount:0})}async function t6(e,t){const{id:r}=t;await e.request({method:"wallet_showCallsStatus",params:[r]})}async function r6(e,t){const{account:r=e.account}=t;if(!r)throw new Bn({docsPath:"/docs/eip7702/signAuthorization"});const n=$e(r);if(!n.signAuthorization)throw new ls({docsPath:"/docs/eip7702/signAuthorization",metaMessages:["The `signAuthorization` Action does not support JSON-RPC Accounts."],type:n.type});const i=await dm(e,t);return n.signAuthorization(i)}async function n6(e,{account:t=e.account,message:r}){if(!t)throw new Bn({docsPath:"/docs/actions/wallet/signMessage"});const n=$e(t);if(n.signMessage)return n.signMessage({message:r});const i=typeof r=="string"?Qn(r):r.raw instanceof Uint8Array?nt(r.raw):r.raw;return e.request({method:"personal_sign",params:[i,n.address]},{retryCount:0})}async function i6(e,t){var f,u,l,p;const{account:r=e.account,chain:n=e.chain,...i}=t;if(!r)throw new Bn({docsPath:"/docs/actions/wallet/signTransaction"});const o=$e(r);Pn({account:o,...t});const s=await ue(e,wi,"getChainId")({});n!==null&&cy({currentChainId:s,chain:n});const a=(n==null?void 0:n.formatters)||((f=e.chain)==null?void 0:f.formatters),c=((u=a==null?void 0:a.transactionRequest)==null?void 0:u.format)||gi;return o.signTransaction?o.signTransaction({...i,chainId:s},{serializer:(p=(l=e.chain)==null?void 0:l.serializers)==null?void 0:p.transaction}):await e.request({method:"eth_signTransaction",params:[{...c(i),chainId:ne(s),from:o.address}]},{retryCount:0})}async function o6(e,t){const{account:r=e.account,domain:n,message:i,primaryType:o}=t;if(!r)throw new Bn({docsPath:"/docs/actions/wallet/signTypedData"});const s=$e(r),a={EIP712Domain:Cy({domain:n}),...t.types};if(Ry({domain:n,message:i,primaryType:o,types:a}),s.signTypedData)return s.signTypedData({domain:n,message:i,primaryType:o,types:a});const c=Yv({domain:n,message:i,primaryType:o,types:a});return e.request({method:"eth_signTypedData_v4",params:[s.address,c]},{retryCount:0})}async function s6(e,{id:t}){await e.request({method:"wallet_switchEthereumChain",params:[{chainId:ne(t)}]},{retryCount:0})}async function a6(e,t){return await e.request({method:"wallet_watchAsset",params:t},{retryCount:0})}function c6(e){return{addChain:t=>KE(e,t),deployContract:t=>YE(e,t),getAddresses:()=>ZE(e),getCallsStatus:t=>yy(e,t),getCapabilities:t=>XE(e,t),getChainId:()=>wi(e),getPermissions:()=>JE(e),prepareAuthorization:t=>dm(e,t),prepareTransactionRequest:t=>Vs(e,t),requestAddresses:()=>QE(e),requestPermissions:t=>e6(e,t),sendCalls:t=>rv(e,t),sendRawTransaction:t=>Jf(e,t),sendTransaction:t=>Qs(e,t),showCallsStatus:t=>t6(e,t),signAuthorization:t=>r6(e,t),signMessage:t=>n6(e,t),signTransaction:t=>i6(e,t),signTypedData:t=>o6(e,t),switchChain:t=>s6(e,t),waitForCallsStatus:t=>nv(e,t),watchAsset:t=>a6(e,t),writeContract:t=>fy(e,t)}}function Wa(e){const{key:t="wallet",name:r="Wallet Client",transport:n}=e;return by({...e,key:t,name:r,transport:n,type:"walletClient"}).extend(c6)}const hs={mainnet:{orderbook:"https://api.garden.finance",auth:"https://api.garden.finance/auth",quote:"https://api.garden.finance/quote",info:"https://api.garden.finance/info",evmRelay:"https://api.garden.finance/relayer",solanaRelay:"https://solana-relayer.garden.finance/",starknetRelay:"https://api.garden.finance/starknet"},testnet:{orderbook:"https://testnet.api.garden.finance",auth:"https://testnet.api.garden.finance/auth",quote:"https://testnet.api.garden.finance/quote",info:"https://testnet.api.garden.finance/info",evmRelay:"https://testnet.api.garden.finance/relayer",solanaRelay:"https://solana-relay.garden.finance",starknetRelay:"https://testnet.api.garden.finance/starknet"},localnet:{orderbook:"",auth:"",quote:"",info:"",evmRelay:"",starknetRelay:"",solanaRelay:""}},vo={[ce.Network.MAINNET]:{chainId:"0x534e5f4d41494e",nodeUrl:"https://starknet-mainnet.public.blastapi.io/rpc/v0_8"},[ce.Network.TESTNET]:{chainId:"0x534e5f5345504f4c4941",nodeUrl:"https://starknet-sepolia.public.blastapi.io/rpc/v0_8"},[ce.Network.LOCALNET]:{chainId:"",nodeUrl:""}},Qu={[ce.Network.MAINNET]:"9cBuPNiHXiMNg3Fin8xLCGJQBTXjYQTFtyaFQv2uiM1H",[ce.Network.TESTNET]:"ANUVKxeqaec3bf4DVPqLTnG1PT3Fng56wPcE7LXAb46Q",[ce.Network.LOCALNET]:"AKnL4NNf3DGWZJS6cPknBuEGnVsV4A4m5tgebLHaRSZ9"},hm={mainnet:"2bag6xpshpvPe7SJ9nSDLHpxqhEAoHPGpEkjNSv7gxoF",staging:"6eksgdCnSjUaGQWZ6iYvauv1qzvYPF33RTGTM1ZuyENx"},Td={chain:be.SupportedAssets.mainnet.base_cbBTC.chain,asset:be.SupportedAssets.mainnet.base_cbBTC.atomicSwapAddress};function ef(e){const t=typeof e=="string"?e:e.environment,r=t===ce.Environment.MAINNET?hs.mainnet:ce.Environment.TESTNET?hs.testnet:hs.localnet;return{api:typeof e=="string"?r:{...r,...e},environment:t}}function tf(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function tn(e,t){if(!e)throw new Error(t)}function u6(e){return Buffer.concat([Uint8Array.from([192]),f6(e)])}function f6(e){const t=Rl.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Rl.encode(e.length,r),Buffer.concat([r,e])}function l6(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Hr=e=>e.length===64?e:e.slice(2),d6=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return hn.isPoint(t)}catch{return!1}},rf=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function h6(e,t){if(!e)return!1;const r=t===ce.Environment.MAINNET?ge.networks.bitcoin:t===ce.Environment.TESTNET?ge.networks.testnet:ge.networks.regtest;if(!r)return!1;ge.initEccLib(hn);try{return ge.address.toOutputScript(e,r),!0}catch{return!1}}const p6=e=>{switch(e){case ce.Environment.MAINNET:return cn.BitcoinNetwork.Mainnet;case ce.Environment.TESTNET:return cn.BitcoinNetwork.Testnet;case ce.Environment.LOCALNET:return cn.BitcoinNetwork.Regtest;default:throw new Error(`Invalid bitcoin network ${e}`)}},y6=e=>{const t=e.toLowerCase().replace("0x","");return/^[0-9a-f]+$/.test(t)},m6=e=>{if(typeof e=="object"&&"r"in e&&"s"in e)return ce.Ok([e.r.toString(),e.s.toString()]);if(Array.isArray(e)){const t=e.map(r=>typeof r=="string"&&r.startsWith("0x")&&y6(r)?BigInt(r).toString():r);return ce.Ok(t)}return ce.Err("Invalid signature format")},Bd=async(e,t)=>{const r=Date.now(),n=3e4,i=2e3;for(;Date.now()-r<n;){const o=await e.getLatestBlockhash(),s=await e.confirmTransaction({signature:t,blockhash:o.blockhash,lastValidBlockHeight:o.lastValidBlockHeight},"confirmed");if(s.value&&s.value.err==null)return console.log("Tx Confirmed ✅"),!0;console.log("Tx not confirmed yet. Retrying in 2 seconds..."),await new Promise(a=>setTimeout(a,i))}return!1};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||{}),Be=(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))(Be||{});const al=(e,t,r)=>{const n=nf(e.source_swap,t),i=nf(e.destination_swap,r);if(i===Be.RedeemDetected)return Se.RedeemDetected;if(i===Be.Redeemed)return Se.Redeemed;if(n===Be.Refunded)return Se.Refunded;if(n===Be.RefundDetected)return Se.RefundDetected;if(i===Be.Expired)return Se.CounterPartySwapExpired;if(n===Be.Expired)return Se.Expired;if(i===Be.Refunded)return Se.CounterPartyRefunded;if(i===Be.RefundDetected)return Se.CounterPartyRefundDetected;const o=Number(e.create_order.additional_data.deadline);return i===Be.Initiated?Se.CounterPartyInitiated:i===Be.InitiateDetected?Se.CounterPartyInitiateDetected:_o(o,12)?Se.DeadLineExceeded:n===Be.Initiated?Se.Initiated:_o(o,1)?Se.DeadLineExceeded:n===Be.InitiateDetected?Se.InitiateDetected:n===Be.Redeemed?Se.CounterPartyRedeemed:n===Be.RedeemDetected?Se.CounterPartyRedeemDetected:Se.Matched},nf=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?Be.Redeemed:Be.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?Be.Refunded:Be.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Be.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?Be.Initiated:Be.InitiateDetected:Be.Idle},b6=(e,t,r)=>{const n=al(e,t,r);return cl(n)},cl=e=>{switch(e){case Se.Matched:return Te.Initiate;case Se.CounterPartyInitiated:case Se.CounterPartyInitiateDetected:case Se.RedeemDetected:return Te.Redeem;case Se.Expired:return Te.Refund;default:return Te.Idle}},_o=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},g6=e=>e.filter(t=>!pm(t)),pm=e=>{const{source_swap:t,create_order:r}=e,{initiate_tx_hash:n,initiate_block_number:i}=t,{deadline:o}=r.additional_data;return n&&Number(i)?!1:n&&!Number(i)?_o(Number(o),12):n?!1:_o(Number(o),1)},w6=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),v6=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),_6=Buffer.concat([w6,v6]),E6=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Id={failedToCreateInternalPubkey:"failed to create internal pubkey"};function x6(){const e=Ip.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=hn.pointMultiply(Buffer.concat([Buffer.from("04","hex"),_6]),e);if(!t)throw new Error(Id.failedToCreateInternalPubkey);const r=hn.pointAdd(E6,t);if(!r)throw new Error(Id.failedToCreateInternalPubkey);return tf(Buffer.from(r))}var Ge=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function A6(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ul(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 ke={},ot={},Yt={},oa={};oa.byteLength=T6;oa.toByteArray=I6;oa.fromByteArray=R6;var ur=[],Rt=[],S6=typeof Uint8Array<"u"?Uint8Array:Array,Ka="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var $n=0,P6=Ka.length;$n<P6;++$n)ur[$n]=Ka[$n],Rt[Ka.charCodeAt($n)]=$n;Rt[45]=62;Rt[95]=63;function ym(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 T6(e){var t=ym(e),r=t[0],n=t[1];return(r+n)*3/4-n}function B6(e,t,r){return(t+r)*3/4-r}function I6(e){var t,r=ym(e),n=r[0],i=r[1],o=new S6(B6(e,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)t=Rt[e.charCodeAt(c)]<<18|Rt[e.charCodeAt(c+1)]<<12|Rt[e.charCodeAt(c+2)]<<6|Rt[e.charCodeAt(c+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=t&255;return i===2&&(t=Rt[e.charCodeAt(c)]<<2|Rt[e.charCodeAt(c+1)]>>4,o[s++]=t&255),i===1&&(t=Rt[e.charCodeAt(c)]<<10|Rt[e.charCodeAt(c+1)]<<4|Rt[e.charCodeAt(c+2)]>>2,o[s++]=t>>8&255,o[s++]=t&255),o}function k6(e){return ur[e>>18&63]+ur[e>>12&63]+ur[e>>6&63]+ur[e&63]}function O6(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(k6(n));return i.join("")}function R6(e){for(var t,r=e.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(O6(e,s,s+o>a?a:s+o));return n===1?(t=e[r-1],i.push(ur[t>>2]+ur[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(ur[t>>10]+ur[t>>4&63]+ur[t<<2&63]+"=")),i.join("")}var fl={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */fl.read=function(e,t,r,n,i){var o,s,a=i*8-n-1,c=(1<<a)-1,f=c>>1,u=-7,l=r?i-1:0,p=r?-1:1,h=e[t+l];for(l+=p,o=h&(1<<-u)-1,h>>=-u,u+=a;u>0;o=o*256+e[t+l],l+=p,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=n;u>0;s=s*256+e[t+l],l+=p,u-=8);if(o===0)o=1-f;else{if(o===c)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-f}return(h?-1:1)*s*Math.pow(2,o-n)};fl.write=function(e,t,r,n,i,o){var s,a,c,f=o*8-i-1,u=(1<<f)-1,l=u>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:o-1,m=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,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+l>=1?t+=p/c:t+=p*Math.pow(2,1-l),t*c>=2&&(s++,c/=2),s+l>=u?(a=0,s=u):s+l>=1?(a=(t*c-1)*Math.pow(2,i),s=s+l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+h]=a&255,h+=m,a/=256,i-=8);for(s=s<<i|a,f+=i;f>0;e[r+h]=s&255,h+=m,s/=256,f-=8);e[r+h-m]|=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=oa,r=fl,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=S,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=o(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function o(){try{const g=new Uint8Array(1),d={foo:function(){return 42}};return Object.setPrototypeOf(d,Uint8Array.prototype),Object.setPrototypeOf(g,d),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 s(g){if(g>i)throw new RangeError('The value "'+g+'" is invalid for option "size"');const d=new Uint8Array(g);return Object.setPrototypeOf(d,a.prototype),d}function a(g,d,y){if(typeof g=="number"){if(typeof d=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(g)}return c(g,d,y)}a.poolSize=8192;function c(g,d,y){if(typeof g=="string")return p(g,d);if(ArrayBuffer.isView(g))return m(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(De(g,ArrayBuffer)||g&&De(g.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(De(g,SharedArrayBuffer)||g&&De(g.buffer,SharedArrayBuffer)))return b(g,d,y);if(typeof g=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const T=g.valueOf&&g.valueOf();if(T!=null&&T!==g)return a.from(T,d,y);const $=w(g);if($)return $;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof g[Symbol.toPrimitive]=="function")return a.from(g[Symbol.toPrimitive]("string"),d,y);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,d,y){return c(g,d,y)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function f(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 u(g,d,y){return f(g),g<=0?s(g):d!==void 0?typeof y=="string"?s(g).fill(d,y):s(g).fill(d):s(g)}a.alloc=function(g,d,y){return u(g,d,y)};function l(g){return f(g),s(g<0?0:_(g)|0)}a.allocUnsafe=function(g){return l(g)},a.allocUnsafeSlow=function(g){return l(g)};function p(g,d){if((typeof d!="string"||d==="")&&(d="utf8"),!a.isEncoding(d))throw new TypeError("Unknown encoding: "+d);const y=E(g,d)|0;let T=s(y);const $=T.write(g,d);return $!==y&&(T=T.slice(0,$)),T}function h(g){const d=g.length<0?0:_(g.length)|0,y=s(d);for(let T=0;T<d;T+=1)y[T]=g[T]&255;return y}function m(g){if(De(g,Uint8Array)){const d=new Uint8Array(g);return b(d.buffer,d.byteOffset,d.byteLength)}return h(g)}function b(g,d,y){if(d<0||g.byteLength<d)throw new RangeError('"offset" is outside of buffer bounds');if(g.byteLength<d+(y||0))throw new RangeError('"length" is outside of buffer bounds');let T;return d===void 0&&y===void 0?T=new Uint8Array(g):y===void 0?T=new Uint8Array(g,d):T=new Uint8Array(g,d,y),Object.setPrototypeOf(T,a.prototype),T}function w(g){if(a.isBuffer(g)){const d=_(g.length)|0,y=s(d);return y.length===0||g.copy(y,0,0,d),y}if(g.length!==void 0)return typeof g.length!="number"||Tt(g.length)?s(0):h(g);if(g.type==="Buffer"&&Array.isArray(g.data))return h(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 S(g){return+g!=g&&(g=0),a.alloc(+g)}a.isBuffer=function(d){return d!=null&&d._isBuffer===!0&&d!==a.prototype},a.compare=function(d,y){if(De(d,Uint8Array)&&(d=a.from(d,d.offset,d.byteLength)),De(y,Uint8Array)&&(y=a.from(y,y.offset,y.byteLength)),!a.isBuffer(d)||!a.isBuffer(y))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(d===y)return 0;let T=d.length,$=y.length;for(let j=0,J=Math.min(T,$);j<J;++j)if(d[j]!==y[j]){T=d[j],$=y[j];break}return T<$?-1:$<T?1:0},a.isEncoding=function(d){switch(String(d).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(d,y){if(!Array.isArray(d))throw new TypeError('"list" argument must be an Array of Buffers');if(d.length===0)return a.alloc(0);let T;if(y===void 0)for(y=0,T=0;T<d.length;++T)y+=d[T].length;const $=a.allocUnsafe(y);let j=0;for(T=0;T<d.length;++T){let J=d[T];if(De(J,Uint8Array))j+J.length>$.length?(a.isBuffer(J)||(J=a.from(J)),J.copy($,j)):Uint8Array.prototype.set.call($,J,j);else if(a.isBuffer(J))J.copy($,j);else throw new TypeError('"list" argument must be an Array of Buffers');j+=J.length}return $};function E(g,d){if(a.isBuffer(g))return g.length;if(ArrayBuffer.isView(g)||De(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 y=g.length,T=arguments.length>2&&arguments[2]===!0;if(!T&&y===0)return 0;let $=!1;for(;;)switch(d){case"ascii":case"latin1":case"binary":return y;case"utf8":case"utf-8":return he(g).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return y*2;case"hex":return y>>>1;case"base64":return _t(g).length;default:if($)return T?-1:he(g).length;d=(""+d).toLowerCase(),$=!0}}a.byteLength=E;function v(g,d,y){let T=!1;if((d===void 0||d<0)&&(d=0),d>this.length||((y===void 0||y>this.length)&&(y=this.length),y<=0)||(y>>>=0,d>>>=0,y<=d))return"";for(g||(g="utf8");;)switch(g){case"hex":return R(this,d,y);case"utf8":case"utf-8":return K(this,d,y);case"ascii":return ae(this,d,y);case"latin1":case"binary":return V(this,d,y);case"base64":return G(this,d,y);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Y(this,d,y);default:if(T)throw new TypeError("Unknown encoding: "+g);g=(g+"").toLowerCase(),T=!0}}a.prototype._isBuffer=!0;function B(g,d,y){const T=g[d];g[d]=g[y],g[y]=T}a.prototype.swap16=function(){const d=this.length;if(d%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let y=0;y<d;y+=2)B(this,y,y+1);return this},a.prototype.swap32=function(){const d=this.length;if(d%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let y=0;y<d;y+=4)B(this,y,y+3),B(this,y+1,y+2);return this},a.prototype.swap64=function(){const d=this.length;if(d%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let y=0;y<d;y+=8)B(this,y,y+7),B(this,y+1,y+6),B(this,y+2,y+5),B(this,y+3,y+4);return this},a.prototype.toString=function(){const d=this.length;return d===0?"":arguments.length===0?K(this,0,d):v.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(d){if(!a.isBuffer(d))throw new TypeError("Argument must be a Buffer");return this===d?!0:a.compare(this,d)===0},a.prototype.inspect=function(){let d="";const y=e.INSPECT_MAX_BYTES;return d=this.toString("hex",0,y).replace(/(.{2})/g,"$1 ").trim(),this.length>y&&(d+=" ... "),"<Buffer "+d+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(d,y,T,$,j){if(De(d,Uint8Array)&&(d=a.from(d,d.offset,d.byteLength)),!a.isBuffer(d))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof d);if(y===void 0&&(y=0),T===void 0&&(T=d?d.length:0),$===void 0&&($=0),j===void 0&&(j=this.length),y<0||T>d.length||$<0||j>this.length)throw new RangeError("out of range index");if($>=j&&y>=T)return 0;if($>=j)return-1;if(y>=T)return 1;if(y>>>=0,T>>>=0,$>>>=0,j>>>=0,this===d)return 0;let J=j-$,pe=T-y;const Re=Math.min(J,pe),Pe=this.slice($,j),Ce=d.slice(y,T);for(let ve=0;ve<Re;++ve)if(Pe[ve]!==Ce[ve]){J=Pe[ve],pe=Ce[ve];break}return J<pe?-1:pe<J?1:0};function I(g,d,y,T,$){if(g.length===0)return-1;if(typeof y=="string"?(T=y,y=0):y>2147483647?y=2147483647:y<-2147483648&&(y=-2147483648),y=+y,Tt(y)&&(y=$?0:g.length-1),y<0&&(y=g.length+y),y>=g.length){if($)return-1;y=g.length-1}else if(y<0)if($)y=0;else return-1;if(typeof d=="string"&&(d=a.from(d,T)),a.isBuffer(d))return d.length===0?-1:N(g,d,y,T,$);if(typeof d=="number")return d=d&255,typeof Uint8Array.prototype.indexOf=="function"?$?Uint8Array.prototype.indexOf.call(g,d,y):Uint8Array.prototype.lastIndexOf.call(g,d,y):N(g,[d],y,T,$);throw new TypeError("val must be string, number or Buffer")}function N(g,d,y,T,$){let j=1,J=g.length,pe=d.length;if(T!==void 0&&(T=String(T).toLowerCase(),T==="ucs2"||T==="ucs-2"||T==="utf16le"||T==="utf-16le")){if(g.length<2||d.length<2)return-1;j=2,J/=2,pe/=2,y/=2}function Re(Ce,ve){return j===1?Ce[ve]:Ce.readUInt16BE(ve*j)}let Pe;if($){let Ce=-1;for(Pe=y;Pe<J;Pe++)if(Re(g,Pe)===Re(d,Ce===-1?0:Pe-Ce)){if(Ce===-1&&(Ce=Pe),Pe-Ce+1===pe)return Ce*j}else Ce!==-1&&(Pe-=Pe-Ce),Ce=-1}else for(y+pe>J&&(y=J-pe),Pe=y;Pe>=0;Pe--){let Ce=!0;for(let ve=0;ve<pe;ve++)if(Re(g,Pe+ve)!==Re(d,ve)){Ce=!1;break}if(Ce)return Pe}return-1}a.prototype.includes=function(d,y,T){return this.indexOf(d,y,T)!==-1},a.prototype.indexOf=function(d,y,T){return I(this,d,y,T,!0)},a.prototype.lastIndexOf=function(d,y,T){return I(this,d,y,T,!1)};function M(g,d,y,T){y=Number(y)||0;const $=g.length-y;T?(T=Number(T),T>$&&(T=$)):T=$;const j=d.length;T>j/2&&(T=j/2);let J;for(J=0;J<T;++J){const pe=parseInt(d.substr(J*2,2),16);if(Tt(pe))return J;g[y+J]=pe}return J}function A(g,d,y,T){return We(he(d,g.length-y),g,y,T)}function H(g,d,y,T){return We(mt(d),g,y,T)}function F(g,d,y,T){return We(_t(d),g,y,T)}function D(g,d,y,T){return We(Z(d,g.length-y),g,y,T)}a.prototype.write=function(d,y,T,$){if(y===void 0)$="utf8",T=this.length,y=0;else if(T===void 0&&typeof y=="string")$=y,T=this.length,y=0;else if(isFinite(y))y=y>>>0,isFinite(T)?(T=T>>>0,$===void 0&&($="utf8")):($=T,T=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const j=this.length-y;if((T===void 0||T>j)&&(T=j),d.length>0&&(T<0||y<0)||y>this.length)throw new RangeError("Attempt to write outside buffer bounds");$||($="utf8");let J=!1;for(;;)switch($){case"hex":return M(this,d,y,T);case"utf8":case"utf-8":return A(this,d,y,T);case"ascii":case"latin1":case"binary":return H(this,d,y,T);case"base64":return F(this,d,y,T);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,d,y,T);default:if(J)throw new TypeError("Unknown encoding: "+$);$=(""+$).toLowerCase(),J=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function G(g,d,y){return d===0&&y===g.length?t.fromByteArray(g):t.fromByteArray(g.slice(d,y))}function K(g,d,y){y=Math.min(g.length,y);const T=[];let $=d;for(;$<y;){const j=g[$];let J=null,pe=j>239?4:j>223?3:j>191?2:1;if($+pe<=y){let Re,Pe,Ce,ve;switch(pe){case 1:j<128&&(J=j);break;case 2:Re=g[$+1],(Re&192)===128&&(ve=(j&31)<<6|Re&63,ve>127&&(J=ve));break;case 3:Re=g[$+1],Pe=g[$+2],(Re&192)===128&&(Pe&192)===128&&(ve=(j&15)<<12|(Re&63)<<6|Pe&63,ve>2047&&(ve<55296||ve>57343)&&(J=ve));break;case 4:Re=g[$+1],Pe=g[$+2],Ce=g[$+3],(Re&192)===128&&(Pe&192)===128&&(Ce&192)===128&&(ve=(j&15)<<18|(Re&63)<<12|(Pe&63)<<6|Ce&63,ve>65535&&ve<1114112&&(J=ve))}}J===null?(J=65533,pe=1):J>65535&&(J-=65536,T.push(J>>>10&1023|55296),J=56320|J&1023),T.push(J),$+=pe}return se(T)}const te=4096;function se(g){const d=g.length;if(d<=te)return String.fromCharCode.apply(String,g);let y="",T=0;for(;T<d;)y+=String.fromCharCode.apply(String,g.slice(T,T+=te));return y}function ae(g,d,y){let T="";y=Math.min(g.length,y);for(let $=d;$<y;++$)T+=String.fromCharCode(g[$]&127);return T}function V(g,d,y){let T="";y=Math.min(g.length,y);for(let $=d;$<y;++$)T+=String.fromCharCode(g[$]);return T}function R(g,d,y){const T=g.length;(!d||d<0)&&(d=0),(!y||y<0||y>T)&&(y=T);let $="";for(let j=d;j<y;++j)$+=Xt[g[j]];return $}function Y(g,d,y){const T=g.slice(d,y);let $="";for(let j=0;j<T.length-1;j+=2)$+=String.fromCharCode(T[j]+T[j+1]*256);return $}a.prototype.slice=function(d,y){const T=this.length;d=~~d,y=y===void 0?T:~~y,d<0?(d+=T,d<0&&(d=0)):d>T&&(d=T),y<0?(y+=T,y<0&&(y=0)):y>T&&(y=T),y<d&&(y=d);const $=this.subarray(d,y);return Object.setPrototypeOf($,a.prototype),$};function Q(g,d,y){if(g%1!==0||g<0)throw new RangeError("offset is not uint");if(g+d>y)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(d,y,T){d=d>>>0,y=y>>>0,T||Q(d,y,this.length);let $=this[d],j=1,J=0;for(;++J<y&&(j*=256);)$+=this[d+J]*j;return $},a.prototype.readUintBE=a.prototype.readUIntBE=function(d,y,T){d=d>>>0,y=y>>>0,T||Q(d,y,this.length);let $=this[d+--y],j=1;for(;y>0&&(j*=256);)$+=this[d+--y]*j;return $},a.prototype.readUint8=a.prototype.readUInt8=function(d,y){return d=d>>>0,y||Q(d,1,this.length),this[d]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(d,y){return d=d>>>0,y||Q(d,2,this.length),this[d]|this[d+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(d,y){return d=d>>>0,y||Q(d,2,this.length),this[d]<<8|this[d+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(d,y){return d=d>>>0,y||Q(d,4,this.length),(this[d]|this[d+1]<<8|this[d+2]<<16)+this[d+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(d,y){return d=d>>>0,y||Q(d,4,this.length),this[d]*16777216+(this[d+1]<<16|this[d+2]<<8|this[d+3])},a.prototype.readBigUInt64LE=Bt(function(d){d=d>>>0,W(d,"offset");const y=this[d],T=this[d+7];(y===void 0||T===void 0)&&ie(d,this.length-8);const $=y+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24,j=this[++d]+this[++d]*2**8+this[++d]*2**16+T*2**24;return BigInt($)+(BigInt(j)<<BigInt(32))}),a.prototype.readBigUInt64BE=Bt(function(d){d=d>>>0,W(d,"offset");const y=this[d],T=this[d+7];(y===void 0||T===void 0)&&ie(d,this.length-8);const $=y*2**24+this[++d]*2**16+this[++d]*2**8+this[++d],j=this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+T;return(BigInt($)<<BigInt(32))+BigInt(j)}),a.prototype.readIntLE=function(d,y,T){d=d>>>0,y=y>>>0,T||Q(d,y,this.length);let $=this[d],j=1,J=0;for(;++J<y&&(j*=256);)$+=this[d+J]*j;return j*=128,$>=j&&($-=Math.pow(2,8*y)),$},a.prototype.readIntBE=function(d,y,T){d=d>>>0,y=y>>>0,T||Q(d,y,this.length);let $=y,j=1,J=this[d+--$];for(;$>0&&(j*=256);)J+=this[d+--$]*j;return j*=128,J>=j&&(J-=Math.pow(2,8*y)),J},a.prototype.readInt8=function(d,y){return d=d>>>0,y||Q(d,1,this.length),this[d]&128?(255-this[d]+1)*-1:this[d]},a.prototype.readInt16LE=function(d,y){d=d>>>0,y||Q(d,2,this.length);const T=this[d]|this[d+1]<<8;return T&32768?T|4294901760:T},a.prototype.readInt16BE=function(d,y){d=d>>>0,y||Q(d,2,this.length);const T=this[d+1]|this[d]<<8;return T&32768?T|4294901760:T},a.prototype.readInt32LE=function(d,y){return d=d>>>0,y||Q(d,4,this.length),this[d]|this[d+1]<<8|this[d+2]<<16|this[d+3]<<24},a.prototype.readInt32BE=function(d,y){return d=d>>>0,y||Q(d,4,this.length),this[d]<<24|this[d+1]<<16|this[d+2]<<8|this[d+3]},a.prototype.readBigInt64LE=Bt(function(d){d=d>>>0,W(d,"offset");const y=this[d],T=this[d+7];(y===void 0||T===void 0)&&ie(d,this.length-8);const $=this[d+4]+this[d+5]*2**8+this[d+6]*2**16+(T<<24);return(BigInt($)<<BigInt(32))+BigInt(y+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24)}),a.prototype.readBigInt64BE=Bt(function(d){d=d>>>0,W(d,"offset");const y=this[d],T=this[d+7];(y===void 0||T===void 0)&&ie(d,this.length-8);const $=(y<<24)+this[++d]*2**16+this[++d]*2**8+this[++d];return(BigInt($)<<BigInt(32))+BigInt(this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+T)}),a.prototype.readFloatLE=function(d,y){return d=d>>>0,y||Q(d,4,this.length),r.read(this,d,!0,23,4)},a.prototype.readFloatBE=function(d,y){return d=d>>>0,y||Q(d,4,this.length),r.read(this,d,!1,23,4)},a.prototype.readDoubleLE=function(d,y){return d=d>>>0,y||Q(d,8,this.length),r.read(this,d,!0,52,8)},a.prototype.readDoubleBE=function(d,y){return d=d>>>0,y||Q(d,8,this.length),r.read(this,d,!1,52,8)};function O(g,d,y,T,$,j){if(!a.isBuffer(g))throw new TypeError('"buffer" argument must be a Buffer instance');if(d>$||d<j)throw new RangeError('"value" argument is out of bounds');if(y+T>g.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(d,y,T,$){if(d=+d,y=y>>>0,T=T>>>0,!$){const pe=Math.pow(2,8*T)-1;O(this,d,y,T,pe,0)}let j=1,J=0;for(this[y]=d&255;++J<T&&(j*=256);)this[y+J]=d/j&255;return y+T},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(d,y,T,$){if(d=+d,y=y>>>0,T=T>>>0,!$){const pe=Math.pow(2,8*T)-1;O(this,d,y,T,pe,0)}let j=T-1,J=1;for(this[y+j]=d&255;--j>=0&&(J*=256);)this[y+j]=d/J&255;return y+T},a.prototype.writeUint8=a.prototype.writeUInt8=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,1,255,0),this[y]=d&255,y+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,2,65535,0),this[y]=d&255,this[y+1]=d>>>8,y+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,2,65535,0),this[y]=d>>>8,this[y+1]=d&255,y+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,4,4294967295,0),this[y+3]=d>>>24,this[y+2]=d>>>16,this[y+1]=d>>>8,this[y]=d&255,y+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,4,4294967295,0),this[y]=d>>>24,this[y+1]=d>>>16,this[y+2]=d>>>8,this[y+3]=d&255,y+4};function L(g,d,y,T,$){P(d,T,$,g,y,7);let j=Number(d&BigInt(4294967295));g[y++]=j,j=j>>8,g[y++]=j,j=j>>8,g[y++]=j,j=j>>8,g[y++]=j;let J=Number(d>>BigInt(32)&BigInt(4294967295));return g[y++]=J,J=J>>8,g[y++]=J,J=J>>8,g[y++]=J,J=J>>8,g[y++]=J,y}function z(g,d,y,T,$){P(d,T,$,g,y,7);let j=Number(d&BigInt(4294967295));g[y+7]=j,j=j>>8,g[y+6]=j,j=j>>8,g[y+5]=j,j=j>>8,g[y+4]=j;let J=Number(d>>BigInt(32)&BigInt(4294967295));return g[y+3]=J,J=J>>8,g[y+2]=J,J=J>>8,g[y+1]=J,J=J>>8,g[y]=J,y+8}a.prototype.writeBigUInt64LE=Bt(function(d,y=0){return L(this,d,y,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Bt(function(d,y=0){return z(this,d,y,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(d,y,T,$){if(d=+d,y=y>>>0,!$){const Re=Math.pow(2,8*T-1);O(this,d,y,T,Re-1,-Re)}let j=0,J=1,pe=0;for(this[y]=d&255;++j<T&&(J*=256);)d<0&&pe===0&&this[y+j-1]!==0&&(pe=1),this[y+j]=(d/J>>0)-pe&255;return y+T},a.prototype.writeIntBE=function(d,y,T,$){if(d=+d,y=y>>>0,!$){const Re=Math.pow(2,8*T-1);O(this,d,y,T,Re-1,-Re)}let j=T-1,J=1,pe=0;for(this[y+j]=d&255;--j>=0&&(J*=256);)d<0&&pe===0&&this[y+j+1]!==0&&(pe=1),this[y+j]=(d/J>>0)-pe&255;return y+T},a.prototype.writeInt8=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,1,127,-128),d<0&&(d=255+d+1),this[y]=d&255,y+1},a.prototype.writeInt16LE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,2,32767,-32768),this[y]=d&255,this[y+1]=d>>>8,y+2},a.prototype.writeInt16BE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,2,32767,-32768),this[y]=d>>>8,this[y+1]=d&255,y+2},a.prototype.writeInt32LE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,4,2147483647,-2147483648),this[y]=d&255,this[y+1]=d>>>8,this[y+2]=d>>>16,this[y+3]=d>>>24,y+4},a.prototype.writeInt32BE=function(d,y,T){return d=+d,y=y>>>0,T||O(this,d,y,4,2147483647,-2147483648),d<0&&(d=4294967295+d+1),this[y]=d>>>24,this[y+1]=d>>>16,this[y+2]=d>>>8,this[y+3]=d&255,y+4},a.prototype.writeBigInt64LE=Bt(function(d,y=0){return L(this,d,y,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Bt(function(d,y=0){return z(this,d,y,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function oe(g,d,y,T,$,j){if(y+T>g.length)throw new RangeError("Index out of range");if(y<0)throw new RangeError("Index out of range")}function k(g,d,y,T,$){return d=+d,y=y>>>0,$||oe(g,d,y,4),r.write(g,d,y,T,23,4),y+4}a.prototype.writeFloatLE=function(d,y,T){return k(this,d,y,!0,T)},a.prototype.writeFloatBE=function(d,y,T){return k(this,d,y,!1,T)};function C(g,d,y,T,$){return d=+d,y=y>>>0,$||oe(g,d,y,8),r.write(g,d,y,T,52,8),y+8}a.prototype.writeDoubleLE=function(d,y,T){return C(this,d,y,!0,T)},a.prototype.writeDoubleBE=function(d,y,T){return C(this,d,y,!1,T)},a.prototype.copy=function(d,y,T,$){if(!a.isBuffer(d))throw new TypeError("argument should be a Buffer");if(T||(T=0),!$&&$!==0&&($=this.length),y>=d.length&&(y=d.length),y||(y=0),$>0&&$<T&&($=T),$===T||d.length===0||this.length===0)return 0;if(y<0)throw new RangeError("targetStart out of bounds");if(T<0||T>=this.length)throw new RangeError("Index out of range");if($<0)throw new RangeError("sourceEnd out of bounds");$>this.length&&($=this.length),d.length-y<$-T&&($=d.length-y+T);const j=$-T;return this===d&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(y,T,$):Uint8Array.prototype.set.call(d,this.subarray(T,$),y),j},a.prototype.fill=function(d,y,T,$){if(typeof d=="string"){if(typeof y=="string"?($=y,y=0,T=this.length):typeof T=="string"&&($=T,T=this.length),$!==void 0&&typeof $!="string")throw new TypeError("encoding must be a string");if(typeof $=="string"&&!a.isEncoding($))throw new TypeError("Unknown encoding: "+$);if(d.length===1){const J=d.charCodeAt(0);($==="utf8"&&J<128||$==="latin1")&&(d=J)}}else typeof d=="number"?d=d&255:typeof d=="boolean"&&(d=Number(d));if(y<0||this.length<y||this.length<T)throw new RangeError("Out of range index");if(T<=y)return this;y=y>>>0,T=T===void 0?this.length:T>>>0,d||(d=0);let j;if(typeof d=="number")for(j=y;j<T;++j)this[j]=d;else{const J=a.isBuffer(d)?d:a.from(d,$),pe=J.length;if(pe===0)throw new TypeError('The value "'+d+'" is invalid for argument "value"');for(j=0;j<T-y;++j)this[j+y]=J[j%pe]}return this};const q={};function ee(g,d,y){q[g]=class extends y{constructor(){super(),Object.defineProperty(this,"message",{value:d.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${g}]`,this.stack,delete this.name}get code(){return g}set code($){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:$,writable:!0})}toString(){return`${this.name} [${g}]: ${this.message}`}}}ee("ERR_BUFFER_OUT_OF_BOUNDS",function(g){return g?`${g} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ee("ERR_INVALID_ARG_TYPE",function(g,d){return`The "${g}" argument must be of type number. Received type ${typeof d}`},TypeError),ee("ERR_OUT_OF_RANGE",function(g,d,y){let T=`The value of "${g}" is out of range.`,$=y;return Number.isInteger(y)&&Math.abs(y)>2**32?$=re(String(y)):typeof y=="bigint"&&($=String(y),(y>BigInt(2)**BigInt(32)||y<-(BigInt(2)**BigInt(32)))&&($=re($)),$+="n"),T+=` It must be ${d}. Received ${$}`,T},RangeError);function re(g){let d="",y=g.length;const T=g[0]==="-"?1:0;for(;y>=T+4;y-=3)d=`_${g.slice(y-3,y)}${d}`;return`${g.slice(0,y)}${d}`}function x(g,d,y){W(d,"offset"),(g[d]===void 0||g[d+y]===void 0)&&ie(d,g.length-(y+1))}function P(g,d,y,T,$,j){if(g>y||g<d){const J=typeof d=="bigint"?"n":"";let pe;throw d===0||d===BigInt(0)?pe=`>= 0${J} and < 2${J} ** ${(j+1)*8}${J}`:pe=`>= -(2${J} ** ${(j+1)*8-1}${J}) and < 2 ** ${(j+1)*8-1}${J}`,new q.ERR_OUT_OF_RANGE("value",pe,g)}x(T,$,j)}function W(g,d){if(typeof g!="number")throw new q.ERR_INVALID_ARG_TYPE(d,"number",g)}function ie(g,d,y){throw Math.floor(g)!==g?(W(g,y),new q.ERR_OUT_OF_RANGE("offset","an integer",g)):d<0?new q.ERR_BUFFER_OUT_OF_BOUNDS:new q.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${d}`,g)}const ye=/[^+/0-9A-Za-z-_]/g;function fe(g){if(g=g.split("=")[0],g=g.trim().replace(ye,""),g.length<2)return"";for(;g.length%4!==0;)g=g+"=";return g}function he(g,d){d=d||1/0;let y;const T=g.length;let $=null;const j=[];for(let J=0;J<T;++J){if(y=g.charCodeAt(J),y>55295&&y<57344){if(!$){if(y>56319){(d-=3)>-1&&j.push(239,191,189);continue}else if(J+1===T){(d-=3)>-1&&j.push(239,191,189);continue}$=y;continue}if(y<56320){(d-=3)>-1&&j.push(239,191,189),$=y;continue}y=($-55296<<10|y-56320)+65536}else $&&(d-=3)>-1&&j.push(239,191,189);if($=null,y<128){if((d-=1)<0)break;j.push(y)}else if(y<2048){if((d-=2)<0)break;j.push(y>>6|192,y&63|128)}else if(y<65536){if((d-=3)<0)break;j.push(y>>12|224,y>>6&63|128,y&63|128)}else if(y<1114112){if((d-=4)<0)break;j.push(y>>18|240,y>>12&63|128,y>>6&63|128,y&63|128)}else throw new Error("Invalid code point")}return j}function mt(g){const d=[];for(let y=0;y<g.length;++y)d.push(g.charCodeAt(y)&255);return d}function Z(g,d){let y,T,$;const j=[];for(let J=0;J<g.length&&!((d-=2)<0);++J)y=g.charCodeAt(J),T=y>>8,$=y%256,j.push($),j.push(T);return j}function _t(g){return t.toByteArray(fe(g))}function We(g,d,y,T){let $;for($=0;$<T&&!($+y>=d.length||$>=g.length);++$)d[$+y]=g[$];return $}function De(g,d){return g instanceof d||g!=null&&g.constructor!=null&&g.constructor.name!=null&&g.constructor.name===d.name}function Tt(g){return g!==g}const Xt=function(){const g="0123456789abcdef",d=new Array(256);for(let y=0;y<16;++y){const T=y*16;for(let $=0;$<16;++$)d[T+$]=g[y]+g[$]}return d}();function Bt(g){return typeof BigInt>"u"?en:g}function en(){throw new Error("BigInt not supported")}})(Yt);var Eo={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}};Eo.Null=Eo.Nil;for(var kd in Eo)Eo[kd].toJSON=(function(e){return e}).bind(null,kd);var ll=Eo,fn=ll;function mm(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function dl(e){return fn.Nil(e)?"":mm(e.constructor)}function C6(e){return fn.Function(e)?"":fn.String(e)?JSON.stringify(e):e&&fn.Object(e)?"":e}function hl(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Ss(e){return fn.Function(e)?e.toJSON?e.toJSON():mm(e):fn.Array(e)?"Array":e&&fn.Object(e)?"Object":e!==void 0?e:""}function bm(e,t,r){var n=C6(t);return"Expected "+Ss(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Br(e,t,r){r=r||dl(t),this.message=bm(e,t,r),hl(this,Br),this.__type=e,this.__value=t,this.__valueTypeName=r}Br.prototype=Object.create(Error.prototype);Br.prototype.constructor=Br;function N6(e,t,r,n,i){var o='" of type ';return t==="key"&&(o='" with key type '),bm('property "'+Ss(r)+o+Ss(e),n,i)}function Kn(e,t,r,n,i){e?(i=i||dl(n),this.message=N6(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',hl(this,Br),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Kn.prototype=Object.create(Error.prototype);Kn.prototype.constructor=Br;function $6(e,t){return new Br(e,{},t)}function F6(e,t,r){return e instanceof Kn?(t=t+"."+e.__property,e=new Kn(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Br&&(e=new Kn(e.__type,t,r,e.__value,e.__valueTypeName)),hl(e),e}var gm={TfTypeError:Br,TfPropertyTypeError:Kn,tfCustomError:$6,tfSubError:F6,tfJSON:Ss,getValueTypeName:dl},Ya,Od;function U6(){if(Od)return Ya;Od=1;var e=ll,t=gm;function r(I){return Buffer.isBuffer(I)}function n(I){return typeof I=="string"&&/^([0-9a-f]{2})+$/i.test(I)}function i(I,N){var M=I.toJSON();function A(H){if(!I(H))return!1;if(H.length===N)return!0;throw t.tfCustomError(M+"(Length: "+N+")",M+"(Length: "+H.length+")")}return A.toJSON=function(){return M},A}var o=i.bind(null,e.Array),s=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function f(I,N,M){M=M||e.Number;function A(H,F){return M(H,F)&&H>I&&H<N}return A.toJSON=function(){return`${M.toJSON()} between [${I}, ${N}]`},A}var u=Math.pow(2,53)-1;function l(I){return typeof I=="number"&&isFinite(I)}function p(I){return I<<24>>24===I}function h(I){return I<<16>>16===I}function m(I){return(I|0)===I}function b(I){return typeof I=="number"&&I>=-u&&I<=u&&Math.floor(I)===I}function w(I){return(I&255)===I}function _(I){return(I&65535)===I}function S(I){return I>>>0===I}function E(I){return typeof I=="number"&&I>=0&&I<=u&&Math.floor(I)===I}var v={ArrayN:o,Buffer:r,BufferN:s,Finite:l,Hex:n,HexN:a,Int8:p,Int16:h,Int32:m,Int53:b,Range:f,StringN:c,UInt8:w,UInt16:_,UInt32:S,UInt53:E};for(var B in v)v[B].toJSON=(function(I){return I}).bind(null,B);return Ya=v,Ya}var Uo=gm,Ye=ll,mr=Uo.tfJSON,wm=Uo.TfTypeError,vm=Uo.TfPropertyTypeError,ki=Uo.tfSubError,L6=Uo.getValueTypeName,Er={arrayOf:function(t,r){t=sr(t),r=r||{};function n(i,o){return!Ye.Array(i)||Ye.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(s,a){try{return lt(t,s,o)}catch(c){throw ki(c,a)}})}return n.toJSON=function(){var i="["+mr(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=sr(t);function r(n,i){return Ye.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+mr(t)},r},map:function(t,r){t=sr(t),r&&(r=sr(r));function n(i,o){if(!Ye.Object(i)||Ye.Nil(i))return!1;for(var s in i){try{r&<(r,s,o)}catch(c){throw ki(c,s,"key")}try{var a=i[s];lt(t,a,o)}catch(c){throw ki(c,s)}}return!0}return r?n.toJSON=function(){return"{"+mr(r)+": "+mr(t)+"}"}:n.toJSON=function(){return"{"+mr(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=sr(t[n]);function i(o,s){if(!Ye.Object(o)||Ye.Nil(o))return!1;var a;try{for(a in r){var c=r[a],f=o[a];lt(c,f,s)}}catch(u){throw ki(u,a)}if(s){for(a in o)if(!r[a])throw new vm(void 0,a)}return!0}return i.toJSON=function(){return mr(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(sr);function r(n,i){return t.some(function(o){try{return lt(o,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(mr).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(sr);function r(n,i){return t.every(function(o){try{return lt(o,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(mr).join(" & ")},r},quacksLike:function(t){function r(n){return t===L6(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(sr);function r(n,i){return Ye.Nil(n)||Ye.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(o,s){try{return lt(o,n[s],i)}catch(a){throw ki(a,s)}})}return r.toJSON=function(){return"("+t.map(mr).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Er.oneOf=Er.anyOf;function sr(e){if(Ye.String(e))return e[0]==="?"?Er.maybe(e.slice(1)):Ye[e]||Er.quacksLike(e);if(e&&Ye.Object(e)){if(Ye.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Er.arrayOf(e[0])}return Er.object(e)}else if(Ye.Function(e))return e;return Er.value(e)}function lt(e,t,r,n){if(Ye.Function(e)){if(e(t,r))return!0;throw new wm(n||e,t)}return lt(sr(e),t,r)}for(var Gr in Ye)lt[Gr]=Ye[Gr];for(Gr in Er)lt[Gr]=Er[Gr];var Rd=U6();for(Gr in Rd)lt[Gr]=Rd[Gr];lt.compile=sr;lt.TfTypeError=wm;lt.TfPropertyTypeError=vm;var _m=lt;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Yt;e.typeforce=_m;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(u,l){return u.length!==l.length?!1:u.every((p,h)=>p.equals(l[h]))}e.stacksEqual=i;function o(u){if(!t.Buffer.isBuffer(u)||u.length<33)return!1;const l=u[0],p=u.slice(1,33);if(p.compare(r)===0||p.compare(n)>=0)return!1;if((l===2||l===3)&&u.length===33)return!0;const h=u.slice(33);return h.compare(r)===0||h.compare(n)>=0?!1:l===4&&u.length===65}e.isPoint=o;const s=21*1e14;function a(u){return e.typeforce.UInt53(u)&&u<=s}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function c(u){return!u||!("output"in u)||!t.Buffer.isBuffer(u.output)?!1:u.version!==void 0?(u.version&e.TAPLEAF_VERSION_MASK)===u.version:!0}e.isTapleaf=c;function f(u){return(0,e.Array)(u)?u.length!==2?!1:u.every(l=>f(l)):c(u)}e.isTaptree=f,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(ot);var Lo={},Ze={};Object.defineProperty(Ze,"__esModule",{value:!0});Ze.BufferReader=Ze.BufferWriter=Ze.cloneBuffer=Ze.reverseBuffer=Ze.writeUInt64LE=Ze.readUInt64LE=Ze.varuint=void 0;const ln=ot,{typeforce:Em}=ln,xo=Bp;Ze.varuint=xo;function xm(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 Am(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,xm(n+r,9007199254740991),n+r}Ze.readUInt64LE=Am;function Sm(e,t,r){return xm(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Ze.writeUInt64LE=Sm;function M6(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}Ze.reverseBuffer=M6;function H6(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Ze.cloneBuffer=H6;class pl{static withCapacity(t){return new pl(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Em(ln.tuple(ln.Buffer,ln.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=Sm(this.buffer,t,this.offset)}writeVarInt(t){xo.encode(t,this.buffer,this.offset),this.offset+=xo.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}Ze.BufferWriter=pl;class D6{constructor(t,r=0){this.buffer=t,this.offset=r,Em(ln.tuple(ln.Buffer,ln.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=Am(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=xo.decode(this.buffer,this.offset);return this.offset+=xo.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}Ze.BufferReader=D6;var Xr={};const j6=ul(b_);var oi={},bt={},ht={},yl={},sa={};Object.defineProperty(sa,"__esModule",{value:!0});sa.crypto=void 0;sa.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=r,e.anumber=n,e.abytes=i,e.ahash=o,e.aexists=s,e.aoutput=a,e.u8=c,e.u32=f,e.clean=u,e.createView=l,e.rotr=p,e.rotl=h,e.byteSwap=m,e.byteSwap32=b,e.bytesToHex=S,e.hexToBytes=B,e.asyncLoop=N,e.utf8ToBytes=M,e.bytesToUtf8=A,e.toBytes=H,e.kdfInputToBytes=F,e.concatBytes=D,e.checkOpts=G,e.createHasher=te,e.createOptHasher=se,e.createXOFer=ae,e.randomBytes=V;const t=sa;function r(R){return R instanceof Uint8Array||ArrayBuffer.isView(R)&&R.constructor.name==="Uint8Array"}function n(R){if(!Number.isSafeInteger(R)||R<0)throw new Error("positive integer expected, got "+R)}function i(R,...Y){if(!r(R))throw new Error("Uint8Array expected");if(Y.length>0&&!Y.includes(R.length))throw new Error("Uint8Array expected of length "+Y+", got length="+R.length)}function o(R){if(typeof R!="function"||typeof R.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");n(R.outputLen),n(R.blockLen)}function s(R,Y=!0){if(R.destroyed)throw new Error("Hash instance has been destroyed");if(Y&&R.finished)throw new Error("Hash#digest() has already been called")}function a(R,Y){i(R);const Q=Y.outputLen;if(R.length<Q)throw new Error("digestInto() expects output buffer of length at least "+Q)}function c(R){return new Uint8Array(R.buffer,R.byteOffset,R.byteLength)}function f(R){return new Uint32Array(R.buffer,R.byteOffset,Math.floor(R.byteLength/4))}function u(...R){for(let Y=0;Y<R.length;Y++)R[Y].fill(0)}function l(R){return new DataView(R.buffer,R.byteOffset,R.byteLength)}function p(R,Y){return R<<32-Y|R>>>Y}function h(R,Y){return R<<Y|R>>>32-Y>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function m(R){return R<<24&4278190080|R<<8&16711680|R>>>8&65280|R>>>24&255}e.swap8IfBE=e.isLE?R=>R:R=>m(R),e.byteSwapIfBE=e.swap8IfBE;function b(R){for(let Y=0;Y<R.length;Y++)R[Y]=m(R[Y]);return R}e.swap32IfBE=e.isLE?R=>R:b;const w=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_=Array.from({length:256},(R,Y)=>Y.toString(16).padStart(2,"0"));function S(R){if(i(R),w)return R.toHex();let Y="";for(let Q=0;Q<R.length;Q++)Y+=_[R[Q]];return Y}const E={_0:48,_9:57,A:65,F:70,a:97,f:102};function v(R){if(R>=E._0&&R<=E._9)return R-E._0;if(R>=E.A&&R<=E.F)return R-(E.A-10);if(R>=E.a&&R<=E.f)return R-(E.a-10)}function B(R){if(typeof R!="string")throw new Error("hex string expected, got "+typeof R);if(w)return Uint8Array.fromHex(R);const Y=R.length,Q=Y/2;if(Y%2)throw new Error("hex string expected, got unpadded hex of length "+Y);const O=new Uint8Array(Q);for(let L=0,z=0;L<Q;L++,z+=2){const oe=v(R.charCodeAt(z)),k=v(R.charCodeAt(z+1));if(oe===void 0||k===void 0){const C=R[z]+R[z+1];throw new Error('hex string expected, got non-hex character "'+C+'" at index '+z)}O[L]=oe*16+k}return O}const I=async()=>{};e.nextTick=I;async function N(R,Y,Q){let O=Date.now();for(let L=0;L<R;L++){Q(L);const z=Date.now()-O;z>=0&&z<Y||(await(0,e.nextTick)(),O+=z)}}function M(R){if(typeof R!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(R))}function A(R){return new TextDecoder().decode(R)}function H(R){return typeof R=="string"&&(R=M(R)),i(R),R}function F(R){return typeof R=="string"&&(R=M(R)),i(R),R}function D(...R){let Y=0;for(let O=0;O<R.length;O++){const L=R[O];i(L),Y+=L.length}const Q=new Uint8Array(Y);for(let O=0,L=0;O<R.length;O++){const z=R[O];Q.set(z,L),L+=z.length}return Q}function G(R,Y){if(Y!==void 0&&{}.toString.call(Y)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(R,Y)}class K{}e.Hash=K;function te(R){const Y=O=>R().update(H(O)).digest(),Q=R();return Y.outputLen=Q.outputLen,Y.blockLen=Q.blockLen,Y.create=()=>R(),Y}function se(R){const Y=(O,L)=>R(L).update(H(O)).digest(),Q=R({});return Y.outputLen=Q.outputLen,Y.blockLen=Q.blockLen,Y.create=O=>R(O),Y}function ae(R){const Y=(O,L)=>R(L).update(H(O)).digest(),Q=R({});return Y.outputLen=Q.outputLen,Y.blockLen=Q.blockLen,Y.create=O=>R(O),Y}e.wrapConstructor=te,e.wrapConstructorWithOpts=se,e.wrapXOFConstructorWithOpts=ae;function V(R=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(R));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(R));throw new Error("crypto.getRandomValues must be defined")}})(yl);Object.defineProperty(ht,"__esModule",{value:!0});ht.SHA512_IV=ht.SHA384_IV=ht.SHA224_IV=ht.SHA256_IV=ht.HashMD=void 0;ht.setBigUint64=Pm;ht.Chi=q6;ht.Maj=z6;const er=yl;function Pm(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),c=n?4:0,f=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+f,a,n)}function q6(e,t,r){return e&t^~e&r}function z6(e,t,r){return e&t^e&r^t&r}class G6 extends er.Hash{constructor(t,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=(0,er.createView)(this.buffer)}update(t){(0,er.aexists)(this),t=(0,er.toBytes)(t),(0,er.abytes)(t);const{view:r,buffer:n,blockLen:i}=this,o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=(0,er.createView)(t);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,er.aexists)(this),(0,er.aoutput)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:o}=this;let{pos:s}=this;r[s++]=128,(0,er.clean)(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)r[l]=0;Pm(n,i-8,BigInt(this.length*8),o),this.process(n,0);const a=(0,er.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],o)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=o,t.length=i,t.pos=a,i%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}}ht.HashMD=G6;ht.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);ht.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);ht.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);ht.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);Object.defineProperty(bt,"__esModule",{value:!0});bt.ripemd160=bt.RIPEMD160=bt.md5=bt.MD5=bt.sha1=bt.SHA1=void 0;const dn=ht,Xe=yl,Ln=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Fr=new Uint32Array(80);class Tm extends dn.HashMD{constructor(){super(64,20,8,!1),this.A=Ln[0]|0,this.B=Ln[1]|0,this.C=Ln[2]|0,this.D=Ln[3]|0,this.E=Ln[4]|0}get(){const{A:t,B:r,C:n,D:i,E:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0}process(t,r){for(let c=0;c<16;c++,r+=4)Fr[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)Fr[c]=(0,Xe.rotl)(Fr[c-3]^Fr[c-8]^Fr[c-14]^Fr[c-16],1);let{A:n,B:i,C:o,D:s,E:a}=this;for(let c=0;c<80;c++){let f,u;c<20?(f=(0,dn.Chi)(i,o,s),u=1518500249):c<40?(f=i^o^s,u=1859775393):c<60?(f=(0,dn.Maj)(i,o,s),u=2400959708):(f=i^o^s,u=3395469782);const l=(0,Xe.rotl)(n,5)+f+a+u+Fr[c]|0;a=s,s=o,o=(0,Xe.rotl)(i,30),i=n,n=l}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,this.set(n,i,o,s,a)}roundClean(){(0,Xe.clean)(Fr)}destroy(){this.set(0,0,0,0,0),(0,Xe.clean)(this.buffer)}}bt.SHA1=Tm;bt.sha1=(0,Xe.createHasher)(()=>new Tm);const V6=Math.pow(2,32),W6=Array.from({length:64},(e,t)=>Math.floor(V6*Math.abs(Math.sin(t+1)))),ts=Ln.slice(0,4),Za=new Uint32Array(16);let Bm=class extends dn.HashMD{constructor(){super(64,16,8,!0),this.A=ts[0]|0,this.B=ts[1]|0,this.C=ts[2]|0,this.D=ts[3]|0}get(){const{A:t,B:r,C:n,D:i}=this;return[t,r,n,i]}set(t,r,n,i){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0}process(t,r){for(let a=0;a<16;a++,r+=4)Za[a]=t.getUint32(r,!0);let{A:n,B:i,C:o,D:s}=this;for(let a=0;a<64;a++){let c,f,u;a<16?(c=(0,dn.Chi)(i,o,s),f=a,u=[7,12,17,22]):a<32?(c=(0,dn.Chi)(s,i,o),f=(5*a+1)%16,u=[5,9,14,20]):a<48?(c=i^o^s,f=(3*a+5)%16,u=[4,11,16,23]):(c=o^(i|~s),f=7*a%16,u=[6,10,15,21]),c=c+n+W6[a]+Za[f],n=s,s=o,o=i,i=i+(0,Xe.rotl)(c,u[a%4])}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,this.set(n,i,o,s)}roundClean(){(0,Xe.clean)(Za)}destroy(){this.set(0,0,0,0),(0,Xe.clean)(this.buffer)}};bt.MD5=Bm;bt.md5=(0,Xe.createHasher)(()=>new Bm);const K6=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Im=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),Y6=Im.map(e=>(9*e+5)%16),km=(()=>{const r=[[Im],[Y6]];for(let n=0;n<4;n++)for(let i of r)i.push(i[n].map(o=>K6[o]));return r})(),Om=km[0],Rm=km[1],Cm=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Z6=Om.map((e,t)=>e.map(r=>Cm[t][r])),X6=Rm.map((e,t)=>e.map(r=>Cm[t][r])),J6=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Q6=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Cd(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 rs=new Uint32Array(16);let Nm=class extends dn.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(t,r){for(let h=0;h<16;h++,r+=4)rs[h]=t.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,a=this.h2|0,c=a,f=this.h3|0,u=f,l=this.h4|0,p=l;for(let h=0;h<5;h++){const m=4-h,b=J6[h],w=Q6[h],_=Om[h],S=Rm[h],E=Z6[h],v=X6[h];for(let B=0;B<16;B++){const I=(0,Xe.rotl)(n+Cd(h,o,a,f)+rs[_[B]]+b,E[B])+l|0;n=l,l=f,f=(0,Xe.rotl)(a,10)|0,a=o,o=I}for(let B=0;B<16;B++){const I=(0,Xe.rotl)(i+Cd(m,s,c,u)+rs[S[B]]+w,v[B])+p|0;i=p,p=u,u=(0,Xe.rotl)(c,10)|0,c=s,s=I}}this.set(this.h1+a+u|0,this.h2+f+p|0,this.h3+l+i|0,this.h4+n+s|0,this.h0+o+c|0)}roundClean(){(0,Xe.clean)(rs)}destroy(){this.destroyed=!0,(0,Xe.clean)(this.buffer),this.set(0,0,0,0,0)}};bt.RIPEMD160=Nm;bt.ripemd160=(0,Xe.createHasher)(()=>new Nm);Object.defineProperty(oi,"__esModule",{value:!0});oi.sha1=oi.SHA1=void 0;const $m=bt;oi.SHA1=$m.SHA1;oi.sha1=$m.sha1;const Fm=ul(n2);(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=j6,r=oi,n=Fm;function i(u){return Buffer.from((0,t.ripemd160)(Uint8Array.from(u)))}e.ripemd160=i;function o(u){return Buffer.from((0,r.sha1)(Uint8Array.from(u)))}e.sha1=o;function s(u){return Buffer.from((0,n.sha256)(Uint8Array.from(u)))}e.sha256=s;function a(u){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(u))))}e.hash160=a;function c(u){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(u))))}e.hash256=c,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Buffer.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Buffer.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Buffer.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Buffer.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Buffer.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Buffer.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Buffer.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Buffer.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function f(u,l){return s(Buffer.concat([e.TAGGED_HASH_PREFIXES[u],l]))}e.taggedHash=f})(Xr);var Xa={},Sr={};Object.defineProperty(Sr,"__esModule",{value:!0});Sr.encode=Sr.decode=Sr.check=void 0;function ex(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))}Sr.check=ex;function tx(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)}}Sr.decode=tx;function rx(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}Sr.encode=rx;var En={};Object.defineProperty(En,"__esModule",{value:!0});En.REVERSE_OPS=En.OPS=void 0;const of={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};En.OPS=of;const Um={};En.REVERSE_OPS=Um;for(const e of Object.keys(of)){const t=of[e];Um[t]=e}var Vr={};Object.defineProperty(Vr,"__esModule",{value:!0});Vr.decode=Vr.encode=Vr.encodingLength=void 0;const jr=En;function Lm(e){return e<jr.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Vr.encodingLength=Lm;function nx(e,t,r){const n=Lm(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(jr.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(jr.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(jr.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Vr.encode=nx;function ix(e,t){const r=e.readUInt8(t);let n,i;if(r<jr.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===jr.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===jr.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!==jr.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Vr.decode=ix;var si={};Object.defineProperty(si,"__esModule",{value:!0});si.encode=si.decode=void 0;function ox(e,t,r){t=t||4,r=r===void 0?!0:r;const n=e.length;if(n===0)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(e[n-1]&127)&&(n<=1||!(e[n-2]&128)))throw new Error("Non-minimally encoded script number");if(n===5){const o=e.readUInt32LE(0),s=e.readUInt8(4);return s&128?-((s&-129)*4294967296+o):s*4294967296+o}let i=0;for(let o=0;o<n;++o)i|=e[o]<<8*o;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}si.decode=ox;function sx(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function ax(e){let t=Math.abs(e);const r=sx(t),n=Buffer.allocUnsafe(r),i=e<0;for(let o=0;o<r;++o)n.writeUInt8(t&255,o),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}si.encode=ax;var rn={},Nd;function cx(){if(Nd)return rn;Nd=1,Object.defineProperty(rn,"__esModule",{value:!0}),rn.encode=rn.decode=void 0;const e=Sr,t=Pt(),r=ot,{typeforce:n}=r,i=Buffer.alloc(1,0);function o(f){let u=0;for(;f[u]===0;)++u;return u===f.length?i:(f=f.slice(u),f[0]&128?Buffer.concat([i,f],1+f.length):f)}function s(f){f[0]===0&&(f=f.slice(1));const u=Buffer.alloc(32,0),l=Math.max(0,32-f.length);return f.copy(u,l),u}function a(f){const u=f.readUInt8(f.length-1);if(!(0,t.isDefinedHashType)(u))throw new Error("Invalid hashType "+u);const l=e.decode(f.slice(0,-1)),p=s(l.r),h=s(l.s);return{signature:Buffer.concat([p,h],64),hashType:u}}rn.decode=a;function c(f,u){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:f,hashType:u}),!(0,t.isDefinedHashType)(u))throw new Error("Invalid hashType "+u);const l=Buffer.allocUnsafe(1);l.writeUInt8(u,0);const p=o(f.slice(0,32)),h=o(f.slice(32,64));return Buffer.concat([e.encode(p,h),l])}return rn.encode=c,rn}var $d;function Pt(){return $d||($d=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=Sr,r=En;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Vr,i=si,o=cx(),s=ot,{typeforce:a}=s,c=r.OPS.OP_RESERVED;function f(A){return s.Number(A)&&(A===r.OPS.OP_0||A>=r.OPS.OP_1&&A<=r.OPS.OP_16||A===r.OPS.OP_1NEGATE)}function u(A){return s.Buffer(A)||f(A)}function l(A){return s.Array(A)&&A.every(u)}e.isPushOnly=l;function p(A){return A.length-A.filter(u).length}e.countNonPushOnlyOPs=p;function h(A){if(A.length===0)return r.OPS.OP_0;if(A.length===1){if(A[0]>=1&&A[0]<=16)return c+A[0];if(A[0]===129)return r.OPS.OP_1NEGATE}}function m(A){return Buffer.isBuffer(A)}function b(A){return s.Array(A)}function w(A){return Buffer.isBuffer(A)}function _(A){if(m(A))return A;a(s.Array,A);const H=A.reduce((G,K)=>w(K)?K.length===1&&h(K)!==void 0?G+1:G+n.encodingLength(K.length)+K.length:G+1,0),F=Buffer.allocUnsafe(H);let D=0;if(A.forEach(G=>{if(w(G)){const K=h(G);if(K!==void 0){F.writeUInt8(K,D),D+=1;return}D+=n.encode(F,G.length,D),G.copy(F,D),D+=G.length}else F.writeUInt8(G,D),D+=1}),D!==F.length)throw new Error("Could not decode chunks");return F}e.compile=_;function S(A){if(b(A))return A;a(s.Buffer,A);const H=[];let F=0;for(;F<A.length;){const D=A[F];if(D>r.OPS.OP_0&&D<=r.OPS.OP_PUSHDATA4){const G=n.decode(A,F);if(G===null||(F+=G.size,F+G.number>A.length))return null;const K=A.slice(F,F+G.number);F+=G.number;const te=h(K);te!==void 0?H.push(te):H.push(K)}else H.push(D),F+=1}return H}e.decompile=S;function E(A){if(m(A)&&(A=S(A)),!A)throw new Error("Could not convert invalid chunks to ASM");return A.map(H=>{if(w(H)){const F=h(H);if(F===void 0)return H.toString("hex");H=F}return r.REVERSE_OPS[H]}).join(" ")}e.toASM=E;function v(A){return a(s.String,A),_(A.split(" ").map(H=>r.OPS[H]!==void 0?r.OPS[H]:(a(s.Hex,H),Buffer.from(H,"hex"))))}e.fromASM=v;function B(A){return A=S(A),a(l,A),A.map(H=>w(H)?H:H===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(H-c))}e.toStack=B;function I(A){return s.isPoint(A)}e.isCanonicalPubKey=I;function N(A){const H=A&-129;return H>0&&H<4}e.isDefinedHashType=N;function M(A){return!Buffer.isBuffer(A)||!N(A[A.length-1])?!1:t.check(A.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=o}(Xa)),Xa}Object.defineProperty(Lo,"__esModule",{value:!0});Lo.Transaction=void 0;const Fe=Ze,at=Xr,Fd=Pt(),ux=Pt(),me=ot,{typeforce:tr}=me;function ir(e){const t=e.length;return Fe.varuint.encodingLength(t)+t}function fx(e){const t=e.length;return Fe.varuint.encodingLength(t)+e.reduce((r,n)=>r+ir(n),0)}const Dr=Buffer.allocUnsafe(0),Ja=[],Qa=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),Ud=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),lx=Buffer.from("ffffffffffffffff","hex"),dx={script:Dr,valueBuffer:lx};function hx(e){return e.value!==void 0}class de{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Fe.BufferReader(t),i=new de;i.version=n.readInt32();const o=n.readUInt8(),s=n.readUInt8();let a=!1;o===de.ADVANCED_TRANSACTION_MARKER&&s===de.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let u=0;u<c;++u)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:Ja});const f=n.readVarInt();for(let u=0;u<f;++u)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let u=0;u<c;++u)i.ins[u].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 de.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){tr(me.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&de.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return tr(me.tuple(me.Hash256bit,me.UInt32,me.maybe(me.UInt32),me.maybe(me.Buffer)),arguments),me.Null(n)&&(n=de.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||Dr,sequence:n,witness:Ja})-1}addOutput(t,r){return tr(me.tuple(me.Buffer,me.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=Ja})}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)+Fe.varuint.encodingLength(this.ins.length)+Fe.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+ir(i.script),0)+this.outs.reduce((n,i)=>n+8+ir(i.script),0)+(r?this.ins.reduce((n,i)=>n+fx(i.witness),0):0)}clone(){const t=new de;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(tr(me.tuple(me.UInt32,me.Buffer,me.Number),arguments),t>=this.ins.length)return Ud;const i=Fd.compile(Fd.decompile(r).filter(a=>a!==ux.OPS.OP_CODESEPARATOR)),o=this.clone();if((n&31)===de.SIGHASH_NONE)o.outs=[],o.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===de.SIGHASH_SINGLE){if(t>=this.outs.length)return Ud;o.outs.length=t+1;for(let a=0;a<t;a++)o.outs[a]=dx;o.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&de.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[t]],o.ins[0].script=i):(o.ins.forEach(a=>{a.script=Dr}),o.ins[t].script=i);const s=Buffer.allocUnsafe(o.byteLength(!1)+4);return s.writeInt32LE(n,s.length-4),o.__toBuffer(s,0,!1),at.hash256(s)}hashForWitnessV1(t,r,n,i,o,s){if(tr(me.tuple(me.UInt32,tr.arrayOf(me.Buffer),tr.arrayOf(me.Satoshi),me.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===de.SIGHASH_DEFAULT?de.SIGHASH_ALL:i&de.SIGHASH_OUTPUT_MASK,f=(i&de.SIGHASH_INPUT_MASK)===de.SIGHASH_ANYONECANPAY,u=a===de.SIGHASH_NONE,l=a===de.SIGHASH_SINGLE;let p=Dr,h=Dr,m=Dr,b=Dr,w=Dr;if(!f){let v=Fe.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(B=>{v.writeSlice(B.hash),v.writeUInt32(B.index)}),p=at.sha256(v.end()),v=Fe.BufferWriter.withCapacity(8*this.ins.length),n.forEach(B=>v.writeUInt64(B)),h=at.sha256(v.end()),v=Fe.BufferWriter.withCapacity(r.map(ir).reduce((B,I)=>B+I)),r.forEach(B=>v.writeVarSlice(B)),m=at.sha256(v.end()),v=Fe.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(B=>v.writeUInt32(B.sequence)),b=at.sha256(v.end())}if(u||l){if(l&&t<this.outs.length){const v=this.outs[t],B=Fe.BufferWriter.withCapacity(8+ir(v.script));B.writeUInt64(v.value),B.writeVarSlice(v.script),w=at.sha256(B.end())}}else{const v=this.outs.map(I=>8+ir(I.script)).reduce((I,N)=>I+N),B=Fe.BufferWriter.withCapacity(v);this.outs.forEach(I=>{B.writeUInt64(I.value),B.writeVarSlice(I.script)}),w=at.sha256(B.end())}const _=(o?2:0)+(s?1:0),S=174-(f?49:0)-(u?32:0)+(s?32:0)+(o?37:0),E=Fe.BufferWriter.withCapacity(S);if(E.writeUInt8(i),E.writeInt32(this.version),E.writeUInt32(this.locktime),E.writeSlice(p),E.writeSlice(h),E.writeSlice(m),E.writeSlice(b),u||l||E.writeSlice(w),E.writeUInt8(_),f){const v=this.ins[t];E.writeSlice(v.hash),E.writeUInt32(v.index),E.writeUInt64(n[t]),E.writeVarSlice(r[t]),E.writeUInt32(v.sequence)}else E.writeUInt32(t);if(s){const v=Fe.BufferWriter.withCapacity(ir(s));v.writeVarSlice(s),E.writeSlice(at.sha256(v.end()))}return l&&E.writeSlice(w),o&&(E.writeSlice(o),E.writeUInt8(0),E.writeUInt32(4294967295)),at.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),E.end()]))}hashForWitnessV0(t,r,n,i){tr(me.tuple(me.UInt32,me.Buffer,me.Satoshi,me.UInt32),arguments);let o=Buffer.from([]),s,a=Qa,c=Qa,f=Qa;if(i&de.SIGHASH_ANYONECANPAY||(o=Buffer.allocUnsafe(36*this.ins.length),s=new Fe.BufferWriter(o,0),this.ins.forEach(l=>{s.writeSlice(l.hash),s.writeUInt32(l.index)}),c=at.hash256(o)),!(i&de.SIGHASH_ANYONECANPAY)&&(i&31)!==de.SIGHASH_SINGLE&&(i&31)!==de.SIGHASH_NONE&&(o=Buffer.allocUnsafe(4*this.ins.length),s=new Fe.BufferWriter(o,0),this.ins.forEach(l=>{s.writeUInt32(l.sequence)}),f=at.hash256(o)),(i&31)!==de.SIGHASH_SINGLE&&(i&31)!==de.SIGHASH_NONE){const l=this.outs.reduce((p,h)=>p+8+ir(h.script),0);o=Buffer.allocUnsafe(l),s=new Fe.BufferWriter(o,0),this.outs.forEach(p=>{s.writeUInt64(p.value),s.writeVarSlice(p.script)}),a=at.hash256(o)}else if((i&31)===de.SIGHASH_SINGLE&&t<this.outs.length){const l=this.outs[t];o=Buffer.allocUnsafe(8+ir(l.script)),s=new Fe.BufferWriter(o,0),s.writeUInt64(l.value),s.writeVarSlice(l.script),a=at.hash256(o)}o=Buffer.allocUnsafe(156+ir(r)),s=new Fe.BufferWriter(o,0);const u=this.ins[t];return s.writeInt32(this.version),s.writeSlice(c),s.writeSlice(f),s.writeSlice(u.hash),s.writeUInt32(u.index),s.writeVarSlice(r),s.writeUInt64(n),s.writeUInt32(u.sequence),s.writeSlice(a),s.writeUInt32(this.locktime),s.writeUInt32(i),at.hash256(o)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):at.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Fe.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){tr(me.tuple(me.Number,me.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){tr(me.tuple(me.Number,[me.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Fe.BufferWriter(t,r||0);i.writeInt32(this.version);const o=n&&this.hasWitnesses();return o&&(i.writeUInt8(de.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(de.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(s=>{i.writeSlice(s.hash),i.writeUInt32(s.index),i.writeVarSlice(s.script),i.writeUInt32(s.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(s=>{hx(s)?i.writeUInt64(s.value):i.writeSlice(s.valueBuffer),i.writeVarSlice(s.script)}),o&&this.ins.forEach(s=>{i.writeVector(s.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}Lo.Transaction=de;de.DEFAULT_SEQUENCE=4294967295;de.SIGHASH_DEFAULT=0;de.SIGHASH_ALL=1;de.SIGHASH_NONE=2;de.SIGHASH_SINGLE=3;de.SIGHASH_ANYONECANPAY=128;de.SIGHASH_OUTPUT_MASK=3;de.SIGHASH_INPUT_MASK=128;de.ADVANCED_TRANSACTION_MARKER=0;de.ADVANCED_TRANSACTION_FLAG=1;var _e={},Mo={};Object.defineProperty(Mo,"__esModule",{value:!0});const px=9007199254740991;function ml(e){if(e<0||e>px||e%1!==0)throw new RangeError("value out of range")}function ji(e,t,r){if(ml(e),t||(t=Buffer.allocUnsafe(Mm(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(ji,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(ji,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(ji,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(ji,{bytes:9})),t}Mo.encode=ji;function qi(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(qi,{bytes:1}),r;if(r===253)return Object.assign(qi,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(qi,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(qi,{bytes:9});const n=e.readUInt32LE(t+1),o=e.readUInt32LE(t+5)*4294967296+n;return ml(o),o}}Mo.decode=qi;function Mm(e){return ml(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Mo.encodingLength=Mm;var ec={},aa={},it={};Object.defineProperty(it,"__esModule",{value:!0});it.testnet=it.regtest=it.bitcoin=void 0;it.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
51
|
-
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};it.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
52
|
-
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};it.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
53
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var xt={};Object.defineProperty(xt,"__esModule",{value:!0});xt.value=xt.prop=void 0;function yx(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}xt.prop=yx;function mx(e){let t;return()=>(t!==void 0||(t=e()),t)}xt.value=mx;Object.defineProperty(aa,"__esModule",{value:!0});aa.p2data=void 0;const bx=it,ps=Pt(),rr=ot,Ld=xt,Md=ps.OPS;function gx(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,rr.typeforce)({network:rr.typeforce.maybe(rr.typeforce.Object),output:rr.typeforce.maybe(rr.typeforce.Buffer),data:rr.typeforce.maybe(rr.typeforce.arrayOf(rr.typeforce.Buffer))},e);const n={name:"embed",network:e.network||bx.bitcoin};if(Ld.prop(n,"output",()=>{if(e.data)return ps.compile([Md.OP_RETURN].concat(e.data))}),Ld.prop(n,"data",()=>{if(e.output)return ps.decompile(e.output).slice(1)}),t.validate&&e.output){const i=ps.decompile(e.output);if(i[0]!==Md.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(rr.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,rr.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}aa.p2data=gx;var ca={};Object.defineProperty(ca,"__esModule",{value:!0});ca.p2ms=void 0;const wx=it,Mn=Pt(),Ne=ot,Ur=xt,Hn=Mn.OPS,ns=Hn.OP_RESERVED;function vx(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 Mn.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===Hn.OP_0)!==void 0}(0,Ne.typeforce)({network:Ne.typeforce.maybe(Ne.typeforce.Object),m:Ne.typeforce.maybe(Ne.typeforce.Number),n:Ne.typeforce.maybe(Ne.typeforce.Number),output:Ne.typeforce.maybe(Ne.typeforce.Buffer),pubkeys:Ne.typeforce.maybe(Ne.typeforce.arrayOf(Ne.isPoint)),signatures:Ne.typeforce.maybe(Ne.typeforce.arrayOf(r)),input:Ne.typeforce.maybe(Ne.typeforce.Buffer)},e);const i={network:e.network||wx.bitcoin};let o=[],s=!1;function a(c){s||(s=!0,o=Mn.decompile(c),i.m=o[0]-ns,i.n=o[o.length-2]-ns,i.pubkeys=o.slice(1,-2))}if(Ur.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Mn.compile([].concat(ns+e.m,e.pubkeys,ns+i.n,Hn.OP_CHECKMULTISIG))}),Ur.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),Ur.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Ur.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),Ur.prop(i,"signatures",()=>{if(e.input)return Mn.decompile(e.input).slice(1)}),Ur.prop(i,"input",()=>{if(e.signatures)return Mn.compile([Hn.OP_0].concat(e.signatures))}),Ur.prop(i,"witness",()=>{if(i.input)return[]}),Ur.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!Ne.typeforce.Number(o[0]))throw new TypeError("Output is invalid");if(!Ne.typeforce.Number(o[o.length-2]))throw new TypeError("Output is invalid");if(o[o.length-1]!==Hn.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==o.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(c=>(0,Ne.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,Ne.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]!==Hn.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,Ne.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)}ca.p2ms=vx;var ua={};Object.defineProperty(ua,"__esModule",{value:!0});ua.p2pk=void 0;const _x=it,Dn=Pt(),Ht=ot,Fn=xt,Hd=Dn.OPS;function Ex(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,Ht.typeforce)({network:Ht.typeforce.maybe(Ht.typeforce.Object),output:Ht.typeforce.maybe(Ht.typeforce.Buffer),pubkey:Ht.typeforce.maybe(Ht.isPoint),signature:Ht.typeforce.maybe(Dn.isCanonicalScriptSignature),input:Ht.typeforce.maybe(Ht.typeforce.Buffer)},e);const r=Fn.value(()=>Dn.decompile(e.input)),i={name:"p2pk",network:e.network||_x.bitcoin};if(Fn.prop(i,"output",()=>{if(e.pubkey)return Dn.compile([e.pubkey,Hd.OP_CHECKSIG])}),Fn.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),Fn.prop(i,"signature",()=>{if(e.input)return r()[0]}),Fn.prop(i,"input",()=>{if(e.signature)return Dn.compile([e.signature])}),Fn.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==Hd.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,Ht.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(!Dn.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}ua.p2pk=Ex;var fa={};function xx(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,a=e.charAt(0),c=Math.log(s)/Math.log(256),f=Math.log(256)/Math.log(s);function u(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,b=0,w=0,_=h.length;w!==_&&h[w]===0;)w++,m++;for(var S=(_-w)*f+1>>>0,E=new Uint8Array(S);w!==_;){for(var v=h[w],B=0,I=S-1;(v!==0||B<b)&&I!==-1;I--,B++)v+=256*E[I]>>>0,E[I]=v%s>>>0,v=v/s>>>0;if(v!==0)throw new Error("Non-zero carry");b=B,w++}for(var N=S-b;N!==S&&E[N]===0;)N++;for(var M=a.repeat(m);N<S;++N)M+=e.charAt(E[N]);return M}function l(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,b=0,w=0;h[m]===a;)b++,m++;for(var _=(h.length-m)*c+1>>>0,S=new Uint8Array(_);h[m];){var E=h.charCodeAt(m);if(E>255)return;var v=t[E];if(v===255)return;for(var B=0,I=_-1;(v!==0||B<w)&&I!==-1;I--,B++)v+=s*S[I]>>>0,S[I]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");w=B,m++}for(var N=_-w;N!==_&&S[N]===0;)N++;for(var M=new Uint8Array(b+(_-N)),A=b;N!==_;)M[A++]=S[N++];return M}function p(h){var m=l(h);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:u,decodeUnsafe:l,decode:p}}var Ax=xx;const Sx=Ax,Px="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var Tx=Sx(Px),tc=Tx,Bx=function(e){function t(o){var s=Uint8Array.from(o),a=e(s),c=s.length+4,f=new Uint8Array(c);return f.set(s,0),f.set(a.subarray(0,4),s.length),tc.encode(f,c)}function r(o){var s=o.slice(0,-4),a=o.slice(-4),c=e(s);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return s}function n(o){var s=tc.decodeUnsafe(o);if(s)return r(s)}function i(o){var s=tc.decode(o),a=r(s);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:Dd}=Fm,Ix=Bx;function kx(e){return Dd(Dd(e))}var bl=Ix(kx);Object.defineProperty(fa,"__esModule",{value:!0});fa.p2pkh=void 0;const rc=Xr,Ox=it,jn=Pt(),ct=ot,br=xt,jd=bl,Lr=jn.OPS;function Rx(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,ct.typeforce)({network:ct.typeforce.maybe(ct.typeforce.Object),address:ct.typeforce.maybe(ct.typeforce.String),hash:ct.typeforce.maybe(ct.typeforce.BufferN(20)),output:ct.typeforce.maybe(ct.typeforce.BufferN(25)),pubkey:ct.typeforce.maybe(ct.isPoint),signature:ct.typeforce.maybe(jn.isCanonicalScriptSignature),input:ct.typeforce.maybe(ct.typeforce.Buffer)},e);const r=br.value(()=>{const s=Buffer.from(jd.decode(e.address)),a=s.readUInt8(0),c=s.slice(1);return{version:a,hash:c}}),n=br.value(()=>jn.decompile(e.input)),i=e.network||Ox.bitcoin,o={name:"p2pkh",network:i};if(br.prop(o,"address",()=>{if(!o.hash)return;const s=Buffer.allocUnsafe(21);return s.writeUInt8(i.pubKeyHash,0),o.hash.copy(s,1),jd.encode(s)}),br.prop(o,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||o.pubkey)return rc.hash160(e.pubkey||o.pubkey)}),br.prop(o,"output",()=>{if(o.hash)return jn.compile([Lr.OP_DUP,Lr.OP_HASH160,o.hash,Lr.OP_EQUALVERIFY,Lr.OP_CHECKSIG])}),br.prop(o,"pubkey",()=>{if(e.input)return n()[1]}),br.prop(o,"signature",()=>{if(e.input)return n()[0]}),br.prop(o,"input",()=>{if(e.pubkey&&e.signature)return jn.compile([e.signature,e.pubkey])}),br.prop(o,"witness",()=>{if(o.input)return[]}),t.validate){let s=Buffer.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");s=r().hash}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==Lr.OP_DUP||e.output[1]!==Lr.OP_HASH160||e.output[2]!==20||e.output[23]!==Lr.OP_EQUALVERIFY||e.output[24]!==Lr.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.pubkey){const a=rc.hash160(e.pubkey);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!jn.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,ct.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=rc.hash160(a[1]);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}fa.p2pkh=Rx;var la={};Object.defineProperty(la,"__esModule",{value:!0});la.p2sh=void 0;const qd=Xr,Cx=it,or=Pt(),xe=ot,nr=xt,zd=bl,Oi=or.OPS;function Nx(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,xe.typeforce)({network:xe.typeforce.maybe(xe.typeforce.Object),address:xe.typeforce.maybe(xe.typeforce.String),hash:xe.typeforce.maybe(xe.typeforce.BufferN(20)),output:xe.typeforce.maybe(xe.typeforce.BufferN(23)),redeem:xe.typeforce.maybe({network:xe.typeforce.maybe(xe.typeforce.Object),output:xe.typeforce.maybe(xe.typeforce.Buffer),input:xe.typeforce.maybe(xe.typeforce.Buffer),witness:xe.typeforce.maybe(xe.typeforce.arrayOf(xe.typeforce.Buffer))}),input:xe.typeforce.maybe(xe.typeforce.Buffer),witness:xe.typeforce.maybe(xe.typeforce.arrayOf(xe.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Cx.bitcoin);const n={network:r},i=nr.value(()=>{const a=Buffer.from(zd.decode(e.address)),c=a.readUInt8(0),f=a.slice(1);return{version:c,hash:f}}),o=nr.value(()=>or.decompile(e.input)),s=nr.value(()=>{const a=o(),c=a[a.length-1];return{network:r,output:c===Oi.OP_FALSE?Buffer.from([]):c,input:or.compile(a.slice(0,-1)),witness:e.witness||[]}});if(nr.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)}),nr.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 qd.hash160(n.redeem.output)}),nr.prop(n,"output",()=>{if(n.hash)return or.compile([Oi.OP_HASH160,n.hash,Oi.OP_EQUAL])}),nr.prop(n,"redeem",()=>{if(e.input)return s()}),nr.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return or.compile([].concat(or.decompile(e.redeem.input),e.redeem.output))}),nr.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),nr.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]!==Oi.OP_HASH160||e.output[1]!==20||e.output[22]!==Oi.OP_EQUAL)throw new TypeError("Output is invalid");const f=e.output.slice(2,22);if(a.length>0&&!a.equals(f))throw new TypeError("Hash mismatch");a=f}const c=f=>{if(f.output){const u=or.decompile(f.output);if(!u||u.length<1)throw new TypeError("Redeem.output too short");if(f.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(or.countNonPushOnlyOPs(u)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const l=qd.hash160(f.output);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(f.input){const u=f.input.length>0,l=f.witness&&f.witness.length>0;if(!u&&!l)throw new TypeError("Empty input");if(u&&l)throw new TypeError("Input and witness provided");if(u){const p=or.decompile(f.input);if(!or.isPushOnly(p))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const f=o();if(!f||f.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(s().output))throw new TypeError("Input is invalid");c(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const f=s();if(e.redeem.output&&!e.redeem.output.equals(f.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(f.input))throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,xe.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}la.p2sh=Nx;var da={},Ir={};Object.defineProperty(Ir,"__esModule",{value:!0});Ir.bech32m=Ir.bech32=void 0;const Ps="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Hm={};for(let e=0;e<Ps.length;e++){const t=Ps.charAt(e);Hm[t]=e}function Yn(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 Gd(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=Yn(t)^n>>5}t=Yn(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=Yn(t)^n&31}return t}function gl(e,t,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],o+=t;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=t)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function $x(e){return gl(e,8,5,!0)}function Fx(e){const t=gl(e,5,8,!1);if(Array.isArray(t))return t}function Ux(e){const t=gl(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Dm(e){let t;e==="bech32"?t=1:t=734539939;function r(s,a,c){if(c=c||90,s.length+7+a.length>c)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let f=Gd(s);if(typeof f=="string")throw new Error(f);let u=s+"1";for(let l=0;l<a.length;++l){const p=a[l];if(p>>5)throw new Error("Non 5-bit word");f=Yn(f)^p,u+=Ps.charAt(p)}for(let l=0;l<6;++l)f=Yn(f);f^=t;for(let l=0;l<6;++l){const p=f>>(5-l)*5&31;u+=Ps.charAt(p)}return u}function n(s,a){if(a=a||90,s.length<8)return s+" too short";if(s.length>a)return"Exceeds length limit";const c=s.toLowerCase(),f=s.toUpperCase();if(s!==c&&s!==f)return"Mixed-case string "+s;s=c;const u=s.lastIndexOf("1");if(u===-1)return"No separator character for "+s;if(u===0)return"Missing prefix for "+s;const l=s.slice(0,u),p=s.slice(u+1);if(p.length<6)return"Data too short";let h=Gd(l);if(typeof h=="string")return h;const m=[];for(let b=0;b<p.length;++b){const w=p.charAt(b),_=Hm[w];if(_===void 0)return"Unknown character "+w;h=Yn(h)^_,!(b+6>=p.length)&&m.push(_)}return h!==t?"Invalid checksum for "+s:{prefix:l,words:m}}function i(s,a){const c=n(s,a);if(typeof c=="object")return c}function o(s,a){const c=n(s,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:o,encode:r,toWords:$x,fromWordsUnsafe:Fx,fromWords:Ux}}Ir.bech32=Dm("bech32");Ir.bech32m=Dm("bech32m");Object.defineProperty(da,"__esModule",{value:!0});da.p2wpkh=void 0;const nc=Xr,Lx=it,ys=Pt(),Me=ot,Mr=xt,is=Ir,Vd=ys.OPS,Mx=Buffer.alloc(0);function Hx(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,Me.typeforce)({address:Me.typeforce.maybe(Me.typeforce.String),hash:Me.typeforce.maybe(Me.typeforce.BufferN(20)),input:Me.typeforce.maybe(Me.typeforce.BufferN(0)),network:Me.typeforce.maybe(Me.typeforce.Object),output:Me.typeforce.maybe(Me.typeforce.BufferN(22)),pubkey:Me.typeforce.maybe(Me.isPoint),signature:Me.typeforce.maybe(ys.isCanonicalScriptSignature),witness:Me.typeforce.maybe(Me.typeforce.arrayOf(Me.typeforce.Buffer))},e);const r=Mr.value(()=>{const o=is.bech32.decode(e.address),s=o.words.shift(),a=is.bech32.fromWords(o.words);return{version:s,prefix:o.prefix,data:Buffer.from(a)}}),n=e.network||Lx.bitcoin,i={name:"p2wpkh",network:n};if(Mr.prop(i,"address",()=>{if(!i.hash)return;const o=is.bech32.toWords(i.hash);return o.unshift(0),is.bech32.encode(n.bech32,o)}),Mr.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return nc.hash160(e.pubkey||i.pubkey)}),Mr.prop(i,"output",()=>{if(i.hash)return ys.compile([Vd.OP_0,i.hash])}),Mr.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Mr.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Mr.prop(i,"input",()=>{if(i.witness)return Mx}),Mr.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let o=Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==Vd.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(o.length>0&&!o.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");o=e.output.slice(2)}if(e.pubkey){const s=nc.hash160(e.pubkey);if(o.length>0&&!o.equals(s))throw new TypeError("Hash mismatch");if(o=s,!(0,Me.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(!ys.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Me.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const s=nc.hash160(e.witness[1]);if(o.length>0&&!o.equals(s))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}da.p2wpkh=Hx;var ha={};Object.defineProperty(ha,"__esModule",{value:!0});ha.p2wsh=void 0;const Wd=Xr,Dx=it,vr=Pt(),Ee=ot,gr=xt,os=Ir,Kd=vr.OPS,ic=Buffer.alloc(0);function ss(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,Ee.isPoint)(e))}function jx(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,Ee.typeforce)({network:Ee.typeforce.maybe(Ee.typeforce.Object),address:Ee.typeforce.maybe(Ee.typeforce.String),hash:Ee.typeforce.maybe(Ee.typeforce.BufferN(32)),output:Ee.typeforce.maybe(Ee.typeforce.BufferN(34)),redeem:Ee.typeforce.maybe({input:Ee.typeforce.maybe(Ee.typeforce.Buffer),network:Ee.typeforce.maybe(Ee.typeforce.Object),output:Ee.typeforce.maybe(Ee.typeforce.Buffer),witness:Ee.typeforce.maybe(Ee.typeforce.arrayOf(Ee.typeforce.Buffer))}),input:Ee.typeforce.maybe(Ee.typeforce.BufferN(0)),witness:Ee.typeforce.maybe(Ee.typeforce.arrayOf(Ee.typeforce.Buffer))},e);const r=gr.value(()=>{const s=os.bech32.decode(e.address),a=s.words.shift(),c=os.bech32.fromWords(s.words);return{version:a,prefix:s.prefix,data:Buffer.from(c)}}),n=gr.value(()=>vr.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Dx.bitcoin);const o={network:i};if(gr.prop(o,"address",()=>{if(!o.hash)return;const s=os.bech32.toWords(o.hash);return s.unshift(0),os.bech32.encode(i.bech32,s)}),gr.prop(o,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(o.redeem&&o.redeem.output)return Wd.sha256(o.redeem.output)}),gr.prop(o,"output",()=>{if(o.hash)return vr.compile([Kd.OP_0,o.hash])}),gr.prop(o,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:ic,witness:e.witness.slice(0,-1)}}),gr.prop(o,"input",()=>{if(o.witness)return ic}),gr.prop(o,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const s=vr.toStack(n());return o.redeem=Object.assign({witness:s},e.redeem),o.redeem.input=ic,[].concat(s,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),gr.prop(o,"name",()=>{const s=["p2wsh"];return o.redeem!==void 0&&o.redeem.name!==void 0&&s.push(o.redeem.name),s.join("-")}),t.validate){let s=Buffer.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==Kd.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const a=vr.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(vr.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=Wd.sha256(e.redeem.output);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch");s=c}if(e.redeem.input&&!vr.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,Ee.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(ss)||e.redeem.output&&(vr.decompile(e.redeem.output)||[]).some(ss))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(ss)||(vr.decompile(a)||[]).some(ss))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)}ha.p2wsh=jx;var Ri={},xn={};Object.defineProperty(xn,"__esModule",{value:!0});xn.getEccLib=xn.initEccLib=void 0;const Wi={};function qx(e,t){e?e!==Wi.eccLib&&(t!=null&&t.DANGER_DO_NOT_VERIFY_ECCLIB||Gx(e),Wi.eccLib=e):Wi.eccLib=e}xn.initEccLib=qx;function zx(){if(!Wi.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Wi.eccLib}xn.getEccLib=zx;const wr=e=>Buffer.from(e,"hex");function Gx(e){kt(typeof e.isXOnlyPoint=="function"),kt(e.isXOnlyPoint(wr("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),kt(e.isXOnlyPoint(wr("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),kt(e.isXOnlyPoint(wr("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),kt(e.isXOnlyPoint(wr("0000000000000000000000000000000000000000000000000000000000000001"))),kt(!e.isXOnlyPoint(wr("0000000000000000000000000000000000000000000000000000000000000000"))),kt(!e.isXOnlyPoint(wr("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),kt(typeof e.xOnlyPointAddTweak=="function"),Vx.forEach(t=>{const r=e.xOnlyPointAddTweak(wr(t.pubkey),wr(t.tweak));t.result===null?kt(r===null):(kt(r!==null),kt(r.parity===t.parity),kt(Buffer.from(r.xOnlyPubkey).equals(wr(t.result))))})}function kt(e){if(!e)throw new Error("ecc library invalid")}const Vx=[{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 wl={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=Yt,r=xn,n=Xr,i=Ze,o=ot;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const s=b=>"left"in b&&"right"in b;function a(b,w){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 S=w;for(let E=0;E<_;E++){const v=b.slice(33+32*E,65+32*E);S.compare(v)<0?S=h(S,v):S=h(v,S)}return S}e.rootHashFromPath=a;function c(b){if((0,o.isTapleaf)(b))return{hash:u(b)};const w=[c(b[0]),c(b[1])];w.sort((E,v)=>E.hash.compare(v.hash));const[_,S]=w;return{hash:h(_.hash,S.hash),left:_,right:S}}e.toHashTree=c;function f(b,w){if(s(b)){const _=f(b.left,w);if(_!==void 0)return[..._,b.right.hash];const S=f(b.right,w);if(S!==void 0)return[...S,b.left.hash]}else if(b.hash.equals(w))return[]}e.findScriptPath=f;function u(b){const w=b.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([w]),m(b.output)]))}e.tapleafHash=u;function l(b,w){return n.taggedHash("TapTweak",t.Buffer.concat(w?[b,w]:[b]))}e.tapTweakHash=l;function p(b,w){if(!t.Buffer.isBuffer(b)||b.length!==32||w&&w.length!==32)return null;const _=l(b,w),S=(0,r.getEccLib)().xOnlyPointAddTweak(b,_);return!S||S.xOnlyPubkey===null?null:{parity:S.parity,x:t.Buffer.from(S.xOnlyPubkey)}}e.tweakKey=p;function h(b,w){return n.taggedHash("TapBranch",t.Buffer.concat([b,w]))}function m(b){const w=i.varuint.encodingLength(b.length),_=t.Buffer.allocUnsafe(w);return i.varuint.encode(b.length,_),t.Buffer.concat([_,b])}})(wl);var ut={},Yd;function Wx(){if(Yd)return ut;Yd=1,Object.defineProperty(ut,"__esModule",{value:!0}),ut.toOutputScript=ut.fromOutputScript=ut.toBech32=ut.toBase58Check=ut.fromBech32=ut.fromBase58Check=void 0;const e=it,t=vl(),r=Pt(),n=ot,i=Ir,o=bl,s=40,a=2,c=16,f=2,u=80,l="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 p(E,v){const B=E.slice(2);if(B.length<a||B.length>s)throw new TypeError("Invalid program length for segwit address");const I=E[0]-u;if(I<f||I>c)throw new TypeError("Invalid version for segwit address");if(E[1]!==B.length)throw new TypeError("Invalid script for segwit address");return console.warn(l),w(B,I,v.bech32)}function h(E){const v=Buffer.from(o.decode(E));if(v.length<21)throw new TypeError(E+" is too short");if(v.length>21)throw new TypeError(E+" is too long");const B=v.readUInt8(0),I=v.slice(1);return{version:B,hash:I}}ut.fromBase58Check=h;function m(E){let v,B;try{v=i.bech32.decode(E)}catch{}if(v){if(B=v.words[0],B!==0)throw new TypeError(E+" uses wrong encoding")}else if(v=i.bech32m.decode(E),B=v.words[0],B===0)throw new TypeError(E+" uses wrong encoding");const I=i.bech32.fromWords(v.words.slice(1));return{version:B,prefix:v.prefix,data:Buffer.from(I)}}ut.fromBech32=m;function b(E,v){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const B=Buffer.allocUnsafe(21);return B.writeUInt8(v,0),E.copy(B,1),o.encode(B)}ut.toBase58Check=b;function w(E,v,B){const I=i.bech32.toWords(E);return I.unshift(v),v===0?i.bech32.encode(B,I):i.bech32m.encode(B,I)}ut.toBech32=w;function _(E,v){v=v||e.bitcoin;try{return t.p2pkh({output:E,network:v}).address}catch{}try{return t.p2sh({output:E,network:v}).address}catch{}try{return t.p2wpkh({output:E,network:v}).address}catch{}try{return t.p2wsh({output:E,network:v}).address}catch{}try{return t.p2tr({output:E,network:v}).address}catch{}try{return p(E,v)}catch{}throw new Error(r.toASM(E)+" has no matching Address")}ut.fromOutputScript=_;function S(E,v){v=v||e.bitcoin;let B,I;try{B=h(E)}catch{}if(B){if(B.version===v.pubKeyHash)return t.p2pkh({hash:B.hash}).output;if(B.version===v.scriptHash)return t.p2sh({hash:B.hash}).output}else{try{I=m(E)}catch{}if(I){if(I.prefix!==v.bech32)throw new Error(E+" has an invalid prefix");if(I.version===0){if(I.data.length===20)return t.p2wpkh({hash:I.data}).output;if(I.data.length===32)return t.p2wsh({hash:I.data}).output}else if(I.version===1){if(I.data.length===32)return t.p2tr({pubkey:I.data}).output}else if(I.version>=f&&I.version<=c&&I.data.length>=a&&I.data.length<=s)return console.warn(l),r.compile([I.version+u,I.data])}}throw new Error(E+" has no matching Script")}return ut.toOutputScript=S,ut}var Zd;function Kx(){if(Zd)return Ri;Zd=1,Object.defineProperty(Ri,"__esModule",{value:!0}),Ri.p2tr=void 0;const e=Yt,t=it,r=Pt(),n=ot,i=xn,o=wl,s=xt,a=Ir,c=Wx(),f=r.OPS,u=1,l=80;function p(h,m){if(!h.address&&!h.output&&!h.pubkey&&!h.internalPubkey&&!(h.witness&&h.witness.length>1))throw new TypeError("Not enough data");m=Object.assign({validate:!0},m||{}),(0,n.typeforce)({address:n.typeforce.maybe(n.typeforce.String),input:n.typeforce.maybe(n.typeforce.BufferN(0)),network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.BufferN(34)),internalPubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),hash:n.typeforce.maybe(n.typeforce.BufferN(32)),pubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),signature:n.typeforce.maybe(n.typeforce.anyOf(n.typeforce.BufferN(64),n.typeforce.BufferN(65))),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer)),scriptTree:n.typeforce.maybe(n.isTaptree),redeem:n.typeforce.maybe({output:n.typeforce.maybe(n.typeforce.Buffer),redeemVersion:n.typeforce.maybe(n.typeforce.Number),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))}),redeemVersion:n.typeforce.maybe(n.typeforce.Number)},h);const b=s.value(()=>(0,c.fromBech32)(h.address)),w=s.value(()=>{if(!(!h.witness||!h.witness.length))return h.witness.length>=2&&h.witness[h.witness.length-1][0]===l?h.witness.slice(0,-1):h.witness.slice()}),_=s.value(()=>{if(h.scriptTree)return(0,o.toHashTree)(h.scriptTree);if(h.hash)return{hash:h.hash}}),S=h.network||t.bitcoin,E={name:"p2tr",network:S};if(s.prop(E,"address",()=>{if(!E.pubkey)return;const v=a.bech32m.toWords(E.pubkey);return v.unshift(u),a.bech32m.encode(S.bech32,v)}),s.prop(E,"hash",()=>{const v=_();if(v)return v.hash;const B=w();if(B&&B.length>1){const I=B[B.length-1],N=I[0]&n.TAPLEAF_VERSION_MASK,M=B[B.length-2],A=(0,o.tapleafHash)({output:M,version:N});return(0,o.rootHashFromPath)(I,A)}return null}),s.prop(E,"output",()=>{if(E.pubkey)return r.compile([f.OP_1,E.pubkey])}),s.prop(E,"redeemVersion",()=>h.redeemVersion?h.redeemVersion:h.redeem&&h.redeem.redeemVersion!==void 0&&h.redeem.redeemVersion!==null?h.redeem.redeemVersion:o.LEAF_VERSION_TAPSCRIPT),s.prop(E,"redeem",()=>{const v=w();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}}),s.prop(E,"pubkey",()=>{if(h.pubkey)return h.pubkey;if(h.output)return h.output.slice(2);if(h.address)return b().data;if(E.internalPubkey){const v=(0,o.tweakKey)(E.internalPubkey,E.hash);if(v)return v.x}}),s.prop(E,"internalPubkey",()=>{if(h.internalPubkey)return h.internalPubkey;const v=w();if(v&&v.length>1)return v[v.length-1].slice(1,33)}),s.prop(E,"signature",()=>{if(h.signature)return h.signature;const v=w();if(!(!v||v.length!==1))return v[0]}),s.prop(E,"witness",()=>{if(h.witness)return h.witness;const v=_();if(v&&h.redeem&&h.redeem.output&&h.internalPubkey){const B=(0,o.tapleafHash)({output:h.redeem.output,version:E.redeemVersion}),I=(0,o.findScriptPath)(v,B);if(!I)return;const N=(0,o.tweakKey)(h.internalPubkey,v.hash);if(!N)return;const M=e.Buffer.concat([e.Buffer.from([E.redeemVersion|N.parity]),h.internalPubkey].concat(I));return[h.redeem.output,M]}if(h.signature)return[h.signature]}),m.validate){let v=e.Buffer.from([]);if(h.address){if(S&&S.bech32!==b().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(b().version!==u)throw new TypeError("Invalid address version");if(b().data.length!==32)throw new TypeError("Invalid address data");v=b().data}if(h.pubkey){if(v.length>0&&!v.equals(h.pubkey))throw new TypeError("Pubkey mismatch");v=h.pubkey}if(h.output){if(h.output.length!==34||h.output[0]!==f.OP_1||h.output[1]!==32)throw new TypeError("Output is invalid");if(v.length>0&&!v.equals(h.output.slice(2)))throw new TypeError("Pubkey mismatch");v=h.output.slice(2)}if(h.internalPubkey){const N=(0,o.tweakKey)(h.internalPubkey,E.hash);if(v.length>0&&!v.equals(N.x))throw new TypeError("Pubkey mismatch");v=N.x}if(v&&v.length&&!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid pubkey for p2tr");const B=_();if(h.hash&&B&&!h.hash.equals(B.hash))throw new TypeError("Hash mismatch");if(h.redeem&&h.redeem.output&&B){const N=(0,o.tapleafHash)({output:h.redeem.output,version:E.redeemVersion});if(!(0,o.findScriptPath)(B,N))throw new TypeError("Redeem script not in tree")}const I=w();if(h.redeem&&E.redeem){if(h.redeem.redeemVersion&&h.redeem.redeemVersion!==E.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(h.redeem.output){if(r.decompile(h.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(E.redeem.output&&!h.redeem.output.equals(E.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(h.redeem.witness&&E.redeem.witness&&!(0,n.stacksEqual)(h.redeem.witness,E.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(I&&I.length)if(I.length===1){if(h.signature&&!h.signature.equals(I[0]))throw new TypeError("Signature mismatch")}else{const N=I[I.length-1];if(N.length<33)throw new TypeError(`The control-block length is too small. Got ${N.length}, expected min 33.`);if((N.length-33)%32!==0)throw new TypeError(`The control-block length of ${N.length} is incorrect!`);const M=(N.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const A=N.slice(1,33);if(h.internalPubkey&&!h.internalPubkey.equals(A))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(A))throw new TypeError("Invalid internalPubkey for p2tr witness");const H=N[0]&n.TAPLEAF_VERSION_MASK,F=I[I.length-2],D=(0,o.tapleafHash)({output:F,version:H}),G=(0,o.rootHashFromPath)(N,D),K=(0,o.tweakKey)(A,G);if(!K)throw new TypeError("Invalid outputKey for p2tr witness");if(v.length&&!v.equals(K.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(K.parity!==(N[0]&1))throw new Error("Incorrect parity")}}return Object.assign(E,h)}return Ri.p2tr=p,Ri}var Xd;function vl(){return Xd||(Xd=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=aa;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=ca;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=ua;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=fa;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const o=la;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return o.p2sh}});const s=da;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return s.p2wpkh}});const a=ha;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=Kx();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(ec)),ec}Object.defineProperty(_e,"__esModule",{value:!0});_e.signatureBlocksAction=_e.checkInputForSig=_e.pubkeyInScript=_e.pubkeyPositionInScript=_e.witnessStackToScriptWitness=_e.isP2TR=_e.isP2SHScript=_e.isP2WSHScript=_e.isP2WPKH=_e.isP2PKH=_e.isP2PK=_e.isP2MS=void 0;const Jd=Mo,Ki=Pt(),as=Lo,Yx=Xr,In=vl();function kn(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}_e.isP2MS=kn(In.p2ms);_e.isP2PK=kn(In.p2pk);_e.isP2PKH=kn(In.p2pkh);_e.isP2WPKH=kn(In.p2wpkh);_e.isP2WSHScript=kn(In.p2wsh);_e.isP2SHScript=kn(In.p2sh);_e.isP2TR=kn(In.p2tr);function Zx(e){let t=Buffer.allocUnsafe(0);function r(s){t=Buffer.concat([t,Buffer.from(s)])}function n(s){const a=t.length,c=Jd.encodingLength(s);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Jd.encode(s,t,a)}function i(s){n(s.length),r(s)}function o(s){n(s.length),s.forEach(i)}return o(e),t}_e.witnessStackToScriptWitness=Zx;function jm(e,t){const r=(0,Yx.hash160)(e),n=e.slice(1,33),i=Ki.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(o=>typeof o=="number"?!1:o.equals(e)||o.equals(r)||o.equals(n))}_e.pubkeyPositionInScript=jm;function Xx(e,t){return jm(e,t)!==-1}_e.pubkeyInScript=Xx;function Jx(e,t){return Qx(e).some(n=>qm(n,Ki.signature.decode,t))}_e.checkInputForSig=Jx;function qm(e,t,r){const{hashType:n}=t(e),i=[];switch(n&as.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case as.Transaction.SIGHASH_ALL:break;case as.Transaction.SIGHASH_SINGLE:case as.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}_e.signatureBlocksAction=qm;function Qx(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=e5(e)}else t=e.partialSig;return t.map(r=>r.signature)}function e5(e){const t=e.finalScriptSig?Ki.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?Ki.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&Ki.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(ke,"__esModule",{value:!0});ke.checkTaprootInputForSigs=ke.tapTreeFromList=ke.tapTreeToList=ke.tweakInternalPubKey=ke.checkTaprootOutputFields=ke.checkTaprootInputFields=ke.isTaprootOutput=ke.isTaprootInput=ms=ke.serializeTaprootSignature=ke.tapScriptFinalizer=ke.toXOnly=void 0;const _l=ot,t5=Lo,pa=_e,Zr=wl,r5=vl(),n5=_e,i5=e=>e.length===32?e:e.slice(1,33);ke.toXOnly=i5;function o5(e,t,r){const n=x5(t,e,r);try{const o=_5(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,pa.witnessStackToScriptWitness)(o)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}ke.tapScriptFinalizer=o5;function s5(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var ms=ke.serializeTaprootSignature=s5;function bs(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,pa.isP2TR)(e.witnessUtxo.script))}ke.isTaprootInput=bs;function gs(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,pa.isP2TR)(t))}ke.isTaprootOutput=gs;function a5(e,t,r){g5(e,t,r),v5(e,t,r)}ke.checkTaprootInputFields=a5;function c5(e,t,r){w5(e,t,r),u5(e,t)}ke.checkTaprootOutputFields=c5;function u5(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,o=f5(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}function f5(e,t){const r=t&&zm(t.leaves),{output:n}=(0,r5.p2tr)({internalPubkey:e,scriptTree:r});return n}function l5(e,t){const r=t.tapInternalKey,n=r&&(0,Zr.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}ke.tweakInternalPubKey=l5;function d5(e){if(!(0,_l.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return sf(e)}ke.tapTreeToList=d5;function zm(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:b5(e)}ke.tapTreeFromList=zm;function h5(e,t){return y5(e).some(n=>(0,n5.signatureBlocksAction)(n,p5,t))}ke.checkTaprootInputForSigs=h5;function p5(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||t5.Transaction.SIGHASH_DEFAULT}}function y5(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=m5(e.finalScriptWitness);r&&t.push(r)}return t}function m5(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function sf(e,t=[],r=0){if(r>Zr.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,_l.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||Zr.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&sf(e[0],t,r+1),e[1]&&sf(e[1],t,r+1),t):[]}function b5(e){let t;for(const r of e)if(t=af(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function af(e,t,r=0){if(r>Zr.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,_l.isTapleaf)(t))return;const n=af(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=af(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function g5(e,t,r){const n=bs(e)&&Zn(t),i=Zn(e)&&bs(t),o=e===t&&bs(t)&&Zn(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function w5(e,t,r){const n=gs(e)&&Zn(t),i=Zn(e)&&gs(t),o=e===t&&gs(t)&&Zn(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function v5(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(o=>oc(o,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(o=>oc(o,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>oc(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function oc(e,t){if(!t)return!0;const r=(0,Zr.tapleafHash)({output:e.script,version:e.leafVersion});return(0,Zr.rootHashFromPath)(e.controlBlock,r).equals(t)}function _5(e,t){const r=(0,Zr.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>E5(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function E5(e,t){return Object.assign({positionInScript:(0,pa.pubkeyPositionInScript)(t.pubkey,e)},t)}function x5(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((i,o)=>i.controlBlock.length-o.controlBlock.length).find(i=>A5(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function A5(e,t,r){const n=(0,Zr.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(o=>o.leafHash.equals(n))!==void 0}function Zn(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const Ke={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"},cs=192;ge.initEccLib(hn);class Yi{constructor(t,r,n,i,o,s,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=o,this.expiry=s,this.signer=t,this.network=a,this.internalPubkey=x6(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,o,s,a){n=n.startsWith("0x")?n.slice(2):n,tn(n.length===64,Ke.secretHashLenMismatch),tn(i.length===64||i.length===66,`initiator ${Ke.pubkeyLenMismatch}`),tn(o.length===64||o.length===66,`redeemer ${Ke.pubkeyLenMismatch}`),tn(s>0,Ke.zeroOrNegativeExpiry);const c=await t.getNetwork();return new Yi(t,r,n,tf(o).toString("hex"),tf(i).toString("hex"),s,c,a)}address(){const{address:t}=ge.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(Ke.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new ge.Transaction;n.version=2;const i=this.address(),o=await this.signer.getProvider();let s=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const f=await o.getTransaction(c);for(let u=0;u<f.vout.length;u++){const l=f.vout[u];l.scriptpubkey_address===i&&s.push({txid:f.txid,vout:u,value:l.value,status:{confirmed:!1}})}}else s=await o.getUTXOs(i);const a=s.reduce((c,f)=>c+f.value,0);if(a===0)throw new Error(`${i} ${Ke.notFunded}`);for(let c=0;c<s.length;c++)n.addInput(Buffer.from(s[c].txid,"hex").reverse(),s[c].vout);return r??(r=await o.suggestFee(i,a,cn.Urgency.MEDIUM)),n.addOutput(ge.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:s}}async _tempBuildRawTx(t,r){const n=new ge.Transaction;n.version=2;const i=this.address(),o=await this.signer.getProvider();let s=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const f=await o.getTransaction(c);for(let u=0;u<f.vout.length;u++){const l=f.vout[u];l.scriptpubkey_address===i&&s.push({txid:f.txid,vout:u,value:l.value,status:{confirmed:!1}})}}else s=await o.getUTXOs(i);const a=s.reduce((c,f)=>c+f.value,0);if(a===0)throw new Error(`${i} ${Ke.notFunded}`);for(let c=0;c<s.length;c++)n.addInput(Buffer.from(s[c].txid,"hex").reverse(),s[c].vout);if(n.addOutput(ge.address.toOutputScript(t,this.network),a),r){const c=await o.getFeeRates(),f=Math.ceil(c.hourFee*r),u=a-f;n.outs[0].value=u}return{tx:n,usedUtxos:s}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return ge.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,cn.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateRedeemSACP(t,r,n){const{tx:i,usedUtxos:o}=await this._buildRawTx(r,n),s=this.getOutputScript(),a=ge.Transaction.SIGHASH_SINGLE|ge.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),f=o.map(l=>l.value),u=Un(s,o.length);for(let l=0;l<i.ins.length;l++){const p=i.hashForWitnessV1(l,u,f,a,c),h=await this.signer.signSchnorr(p);i.setWitness(l,[ms(h,a),Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return i.toHex()}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),o=this.getOutputScript(),s=ge.Transaction.SIGHASH_SINGLE|ge.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(u=>u.value),f=Un(o,i.length);for(let u=0;u<n.ins.length;u++){const l=n.hashForWitnessV1(u,f,c,s,a),p=await this.signer.signSchnorr(l);n.setWitness(u,[ms(p,s),ms(p,s),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){tn(t.length>0,Ke.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const l of i)if(!t.find(p=>p.utxo===l.txid))throw new Error(Ke.counterPartySigNotFound(l.txid));const o=this.getOutputScript(),s=ge.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(l=>l.value),f=Un(o,i.length);for(let l=0;l<n.ins.length;l++){const p=n.hashForWitnessV1(l,f,c,s,a);if(!hn.verifySchnorr(p,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[l].sig,"hex")))throw new Error(Ke.invalidCounterpartySigForUTXO(t[l].utxo));const h=await this.signer.signSchnorr(p),m=Buffer.from(n.ins[l].hash).reverse().toString("hex"),b=t.find(w=>w.utxo===m);if(!b)throw new Error(Ke.counterPartySigNotFound(m));n.setWitness(l,[Buffer.from(b.sig,"hex"),h,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){tn(ge.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Ke.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:o}=await this._tempBuildRawTx(n),s=this.leafHash(1),a=o.map(p=>p.value),c=Un(this.getOutputScript(),o.length),f=ge.Transaction.SIGHASH_DEFAULT;for(let p=0;p<i.ins.length;p++){const h=i.hashForWitnessV1(p,c,a,f,s),m=await this.signer.signSchnorr(h);i.setWitness(p,[m,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:u}=await this._tempBuildRawTx(n,i.virtualSize());for(let p=0;p<u.ins.length;p++){const h=u.hashForWitnessV1(p,c,a,f,s),m=await this.signer.signSchnorr(h);u.setWitness(p,[m,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(u.toHex())}async getRedeemHex(t,r){tn(ge.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,Ke.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:o}=await this._tempBuildRawTx(n),s=this.leafHash(1),a=o.map(l=>l.value),c=Un(this.getOutputScript(),o.length),f=ge.Transaction.SIGHASH_DEFAULT;for(let l=0;l<i.ins.length;l++){const p=i.hashForWitnessV1(l,c,a,f,s),h=await this.signer.signSchnorr(p);i.setWitness(l,[h,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:u}=await this._tempBuildRawTx(n,i.virtualSize());for(let l=0;l<u.ins.length;l++){const p=u.hashForWitnessV1(l,c,a,f,s),h=await this.signer.signSchnorr(p);u.setWitness(l,[h,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return u.toHex()}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[o,s]=await this.canRefund(i);if(!o)throw new Error(Ke.htlcNotExpired(s));const a=this.leafHash(0),c=i.map(p=>p.value),f=Un(this.getOutputScript(),i.length),u=ge.Transaction.SIGHASH_DEFAULT;for(let p=0;p<n.ins.length;p++){n.ins[p].sequence=this.expiry;const h=n.hashForWitnessV1(p,f,c,u,a),m=await this.signer.signSchnorr(h);n.setWitness(p,[m,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let o=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?o=i.status.block_height+this.expiry-n+1:i.status.confirmed||(o=this.expiry+1),o>0)return[!1,o]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(Ke.invalidLeaf)}const n=ge.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:cs}});if(!n.witness)throw new Error(Ke.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()),ge.crypto.taggedHash("TapLeaf",u6(r))}refundLeaf(){return ge.script.fromASM(`
|
|
54
|
-
${ge.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 ge.script.fromASM(`
|
|
60
|
-
OP_SHA256
|
|
61
|
-
${this.secretHash}
|
|
62
|
-
OP_EQUALVERIFY
|
|
63
|
-
${this.redeemerPubkey}
|
|
64
|
-
OP_CHECKSIG
|
|
65
|
-
`.trim().replace(/\s+/g," "))}instantRefundLeaf(){return ge.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:cs,output:this.redeemLeaf()},[{version:cs,output:this.refundLeaf()},{version:cs,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const o=l6(i,n);return[ge.crypto.taggedHash("TapBranch",Buffer.concat(o))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(Ke.invalidLeaf)}}}function Un(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class S5{constructor(){this.cache={}}set(t,r,n,i){const o={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=o}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class P5{constructor(){this.cache={}}set(t,r){this.cache[t]=r}get(t){return this.cache[t]||null}}class Gm{constructor(t,r){this.url=new ce.Url(t).endpoint("blocknumbers").endpoint(r)}async fetchBlockNumbers(){try{const t=await U.Fetcher.get(this.url);return U.Ok(t)}catch(t){return U.Err("Failed to fetch block numbers",t)}}}class Vm{constructor(t){this.quoteUrl=new ce.Url(t)}async getQuoteFromAssets(t,r,n,i=!1,o){const s=rf(t.chain,t.atomicSwapAddress,r.chain,r.atomicSwapAddress);return this.getQuote(s,n,i,o)}async getQuote(t,r,n=!1,i){try{const o={order_pair:t,amount:r.toString(),exact_out:n.toString(),...(i==null?void 0:i.affiliateFee)!==void 0&&{affiliate_fee:i.affiliateFee.toString()}},s=this.quoteUrl.endpoint("/").addSearchParams(o),a=await U.Fetcher.get(s,{retryCount:0,...i==null?void 0:i.request});return a.error?U.Err(a.error):a.result?U.Ok(a.result):U.Err("GetQuote: Unexpected error, result is undefined")}catch(o){return U.Err("GetQuote:",String(o))}}async getAttestedQuote(t){try{const r=await U.Fetcher.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?U.Err(r.error):r.result?U.Ok(r.result):U.Err("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),U.Err("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await U.Fetcher.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return U.Err(t.error);if(!t.result)return U.Err("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=rf(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 U.Ok(r)}catch(t){return U.Err("GetStrategies:",String(t))}}}var Wm={},ai={},ci={};Object.defineProperty(ci,"__esModule",{value:!0});ci.testnet=ci.bitcoin=void 0;ci.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
73
|
-
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};ci.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
74
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Km={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=_m,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})(Km);var cf={exports:{}},uf={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Yt,n=r.Buffer;function i(s,a){for(var c in s)a[c]=s[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o);function o(s,a,c){return n(s,a,c)}o.prototype=Object.create(n.prototype),i(n,o),o.from=function(s,a,c){if(typeof s=="number")throw new TypeError("Argument must not be a number");return n(s,a,c)},o.alloc=function(s,a,c){if(typeof s!="number")throw new TypeError("Argument must be a number");var f=n(s);return a!==void 0?typeof c=="string"?f.fill(a,c):f.fill(a):f.fill(0),f},o.allocUnsafe=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return n(s)},o.allocUnsafeSlow=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(s)}})(uf,uf.exports);var st=uf.exports,sc=65536,T5=4294967295;function B5(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
75
|
-
Use Chrome, Firefox or Internet Explorer 11`)}var I5=st.Buffer,Ts=Ge.crypto||Ge.msCrypto;Ts&&Ts.getRandomValues?cf.exports=k5:cf.exports=B5;function k5(e,t){if(e>T5)throw new RangeError("requested too many random bytes");var r=I5.allocUnsafe(e);if(e>0)if(e>sc)for(var n=0;n<e;n+=sc)Ts.getRandomValues(r.slice(n,n+sc));else Ts.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var O5=cf.exports,ff={exports:{}};typeof Object.create=="function"?ff.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:ff.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 Ve=ff.exports,lf={exports:{}},El={exports:{}},Xn=typeof Reflect=="object"?Reflect:null,Qd=Xn&&typeof Xn.apply=="function"?Xn.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},ws;Xn&&typeof Xn.ownKeys=="function"?ws=Xn.ownKeys:Object.getOwnPropertySymbols?ws=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ws=function(t){return Object.getOwnPropertyNames(t)};function R5(e){console&&console.warn&&console.warn(e)}var Ym=Number.isNaN||function(t){return t!==t};function we(){we.init.call(this)}El.exports=we;El.exports.once=F5;we.EventEmitter=we;we.prototype._events=void 0;we.prototype._eventsCount=0;we.prototype._maxListeners=void 0;var eh=10;function ya(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(we,"defaultMaxListeners",{enumerable:!0,get:function(){return eh},set:function(e){if(typeof e!="number"||e<0||Ym(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");eh=e}});we.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};we.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Ym(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 Zm(e){return e._maxListeners===void 0?we.defaultMaxListeners:e._maxListeners}we.prototype.getMaxListeners=function(){return Zm(this)};we.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(r.length>0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var c=o[t];if(c===void 0)return!1;if(typeof c=="function")Qd(c,this,r);else for(var f=c.length,u=tb(c,f),n=0;n<f;++n)Qd(u[n],this,r);return!0};function Xm(e,t,r,n){var i,o,s;if(ya(r),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),s=o[t]),s===void 0)s=o[t]=r,++e._eventsCount;else if(typeof s=="function"?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),i=Zm(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,R5(a)}return e}we.prototype.addListener=function(t,r){return Xm(this,t,r,!1)};we.prototype.on=we.prototype.addListener;we.prototype.prependListener=function(t,r){return Xm(this,t,r,!0)};function C5(){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 Jm(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=C5.bind(n);return i.listener=r,n.wrapFn=i,i}we.prototype.once=function(t,r){return ya(r),this.on(t,Jm(this,t,r)),this};we.prototype.prependOnceListener=function(t,r){return ya(r),this.prependListener(t,Jm(this,t,r)),this};we.prototype.removeListener=function(t,r){var n,i,o,s,a;if(ya(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():N5(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};we.prototype.off=we.prototype.removeListener;we.prototype.removeAllListeners=function(t){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(t,r[i]);return this};function Qm(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?$5(i):tb(i,i.length)}we.prototype.listeners=function(t){return Qm(this,t,!0)};we.prototype.rawListeners=function(t){return Qm(this,t,!1)};we.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):eb.call(e,t)};we.prototype.listenerCount=eb;function eb(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}we.prototype.eventNames=function(){return this._eventsCount>0?ws(this._events):[]};function tb(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function N5(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function $5(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function F5(e,t){return new Promise(function(r,n){function i(s){e.removeListener(t,o),n(s)}function o(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}rb(e,t,o,{once:!0}),t!=="error"&&U5(e,i,{once:!0})})}function U5(e,t,r){typeof e.on=="function"&&rb(e,"error",t,r)}function rb(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function i(o){n.once&&e.removeEventListener(t,i),r(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var nb=El.exports,ib=nb.EventEmitter;const L5={},M5=Object.freeze(Object.defineProperty({__proto__:null,default:L5},Symbol.toStringTag,{value:"Module"})),xl=ul(M5);var ac,th;function H5(){if(th)return ac;th=1;function e(m,b){var w=Object.keys(m);if(Object.getOwnPropertySymbols){var _=Object.getOwnPropertySymbols(m);b&&(_=_.filter(function(S){return Object.getOwnPropertyDescriptor(m,S).enumerable})),w.push.apply(w,_)}return w}function t(m){for(var b=1;b<arguments.length;b++){var w=arguments[b]!=null?arguments[b]:{};b%2?e(Object(w),!0).forEach(function(_){r(m,_,w[_])}):Object.getOwnPropertyDescriptors?Object.defineProperties(m,Object.getOwnPropertyDescriptors(w)):e(Object(w)).forEach(function(_){Object.defineProperty(m,_,Object.getOwnPropertyDescriptor(w,_))})}return m}function r(m,b,w){return b=s(b),b in m?Object.defineProperty(m,b,{value:w,enumerable:!0,configurable:!0,writable:!0}):m[b]=w,m}function n(m,b){if(!(m instanceof b))throw new TypeError("Cannot call a class as a function")}function i(m,b){for(var w=0;w<b.length;w++){var _=b[w];_.enumerable=_.enumerable||!1,_.configurable=!0,"value"in _&&(_.writable=!0),Object.defineProperty(m,s(_.key),_)}}function o(m,b,w){return b&&i(m.prototype,b),Object.defineProperty(m,"prototype",{writable:!1}),m}function s(m){var b=a(m,"string");return typeof b=="symbol"?b:String(b)}function a(m,b){if(typeof m!="object"||m===null)return m;var w=m[Symbol.toPrimitive];if(w!==void 0){var _=w.call(m,b);if(typeof _!="object")return _;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(m)}var c=Yt,f=c.Buffer,u=xl,l=u.inspect,p=l&&l.custom||"inspect";function h(m,b,w){f.prototype.copy.call(m,b,w)}return ac=function(){function m(){n(this,m),this.head=null,this.tail=null,this.length=0}return o(m,[{key:"push",value:function(w){var _={data:w,next:null};this.length>0?this.tail.next=_:this.head=_,this.tail=_,++this.length}},{key:"unshift",value:function(w){var _={data:w,next:this.head};this.length===0&&(this.tail=_),this.head=_,++this.length}},{key:"shift",value:function(){if(this.length!==0){var w=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,w}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(w){if(this.length===0)return"";for(var _=this.head,S=""+_.data;_=_.next;)S+=w+_.data;return S}},{key:"concat",value:function(w){if(this.length===0)return f.alloc(0);for(var _=f.allocUnsafe(w>>>0),S=this.head,E=0;S;)h(S.data,_,E),E+=S.data.length,S=S.next;return _}},{key:"consume",value:function(w,_){var S;return w<this.head.data.length?(S=this.head.data.slice(0,w),this.head.data=this.head.data.slice(w)):w===this.head.data.length?S=this.shift():S=_?this._getString(w):this._getBuffer(w),S}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(w){var _=this.head,S=1,E=_.data;for(w-=E.length;_=_.next;){var v=_.data,B=w>v.length?v.length:w;if(B===v.length?E+=v:E+=v.slice(0,w),w-=B,w===0){B===v.length?(++S,_.next?this.head=_.next:this.head=this.tail=null):(this.head=_,_.data=v.slice(B));break}++S}return this.length-=S,E}},{key:"_getBuffer",value:function(w){var _=f.allocUnsafe(w),S=this.head,E=1;for(S.data.copy(_),w-=S.data.length;S=S.next;){var v=S.data,B=w>v.length?v.length:w;if(v.copy(_,_.length-w,0,B),w-=B,w===0){B===v.length?(++E,S.next?this.head=S.next:this.head=this.tail=null):(this.head=S,S.data=v.slice(B));break}++E}return this.length-=E,_}},{key:p,value:function(w,_){return l(this,t(t({},_),{},{depth:0,customInspect:!1}))}}]),m}(),ac}function D5(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(df,this,e)):process.nextTick(df,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(o){!t&&o?r._writableState?r._writableState.errorEmitted?process.nextTick(vs,r):(r._writableState.errorEmitted=!0,process.nextTick(rh,r,o)):process.nextTick(rh,r,o):t?(process.nextTick(vs,r),t(o)):process.nextTick(vs,r)}),this)}function rh(e,t){df(e,t),vs(e)}function vs(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function j5(){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 df(e,t){e.emit("error",t)}function q5(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var ob={destroy:D5,undestroy:j5,errorOrDestroy:q5},On={};function z5(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var sb={};function Mt(e,t,r){r||(r=Error);function n(o,s,a){return typeof t=="string"?t:t(o,s,a)}var i=function(o){z5(s,o);function s(a,c,f){return o.call(this,n(a,c,f))||this}return s}(r);i.prototype.name=r.name,i.prototype.code=e,sb[e]=i}function nh(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 G5(e,t,r){return e.substr(0,t.length)===t}function V5(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function W5(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Mt("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Mt("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&G5(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(V5(e," argument"))i="The ".concat(e," ").concat(n," ").concat(nh(t,"type"));else{var o=W5(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(o," ").concat(n," ").concat(nh(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Mt("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Mt("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Mt("ERR_STREAM_PREMATURE_CLOSE","Premature close");Mt("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Mt("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Mt("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Mt("ERR_STREAM_WRITE_AFTER_END","write after end");Mt("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Mt("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Mt("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");On.codes=sb;var K5=On.codes.ERR_INVALID_OPT_VALUE;function Y5(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function Z5(e,t,r,n){var i=Y5(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var o=n?r:"highWaterMark";throw new K5(o,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var ab={getHighWaterMark:Z5},X5=J5;function J5(e,t){if(cc("noDeprecation"))return e;var r=!1;function n(){if(!r){if(cc("throwDeprecation"))throw new Error(t);cc("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function cc(e){try{if(!Ge.localStorage)return!1}catch{return!1}var t=Ge.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var uc,ih;function cb(){if(ih)return uc;ih=1,uc=M;function e(k){var C=this;this.next=null,this.entry=null,this.finish=function(){oe(C,k)}}var t;M.WritableState=I;var r={deprecate:X5},n=ib,i=Yt.Buffer,o=(typeof Ge<"u"?Ge:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(k){return i.from(k)}function a(k){return i.isBuffer(k)||k instanceof o}var c=ob,f=ab,u=f.getHighWaterMark,l=On.codes,p=l.ERR_INVALID_ARG_TYPE,h=l.ERR_METHOD_NOT_IMPLEMENTED,m=l.ERR_MULTIPLE_CALLBACK,b=l.ERR_STREAM_CANNOT_PIPE,w=l.ERR_STREAM_DESTROYED,_=l.ERR_STREAM_NULL_VALUES,S=l.ERR_STREAM_WRITE_AFTER_END,E=l.ERR_UNKNOWN_ENCODING,v=c.errorOrDestroy;Ve(M,n);function B(){}function I(k,C,q){t=t||ui(),k=k||{},typeof q!="boolean"&&(q=C instanceof t),this.objectMode=!!k.objectMode,q&&(this.objectMode=this.objectMode||!!k.writableObjectMode),this.highWaterMark=u(this,k,"writableHighWaterMark",q),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var ee=k.decodeStrings===!1;this.decodeStrings=!ee,this.defaultEncoding=k.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(re){se(C,re)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=k.emitClose!==!1,this.autoDestroy=!!k.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}I.prototype.getBuffer=function(){for(var C=this.bufferedRequest,q=[];C;)q.push(C),C=C.next;return q},function(){try{Object.defineProperty(I.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var N;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(N=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(C){return N.call(this,C)?!0:this!==M?!1:C&&C._writableState instanceof I}})):N=function(C){return C instanceof this};function M(k){t=t||ui();var C=this instanceof t;if(!C&&!N.call(M,this))return new M(k);this._writableState=new I(k,this,C),this.writable=!0,k&&(typeof k.write=="function"&&(this._write=k.write),typeof k.writev=="function"&&(this._writev=k.writev),typeof k.destroy=="function"&&(this._destroy=k.destroy),typeof k.final=="function"&&(this._final=k.final)),n.call(this)}M.prototype.pipe=function(){v(this,new b)};function A(k,C){var q=new S;v(k,q),process.nextTick(C,q)}function H(k,C,q,ee){var re;return q===null?re=new _:typeof q!="string"&&!C.objectMode&&(re=new p("chunk",["string","Buffer"],q)),re?(v(k,re),process.nextTick(ee,re),!1):!0}M.prototype.write=function(k,C,q){var ee=this._writableState,re=!1,x=!ee.objectMode&&a(k);return x&&!i.isBuffer(k)&&(k=s(k)),typeof C=="function"&&(q=C,C=null),x?C="buffer":C||(C=ee.defaultEncoding),typeof q!="function"&&(q=B),ee.ending?A(this,q):(x||H(this,ee,k,q))&&(ee.pendingcb++,re=D(this,ee,x,k,C,q)),re},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var k=this._writableState;k.corked&&(k.corked--,!k.writing&&!k.corked&&!k.bufferProcessing&&k.bufferedRequest&&R(this,k))},M.prototype.setDefaultEncoding=function(C){if(typeof C=="string"&&(C=C.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((C+"").toLowerCase())>-1))throw new E(C);return this._writableState.defaultEncoding=C,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function F(k,C,q){return!k.objectMode&&k.decodeStrings!==!1&&typeof C=="string"&&(C=i.from(C,q)),C}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function D(k,C,q,ee,re,x){if(!q){var P=F(C,ee,re);ee!==P&&(q=!0,re="buffer",ee=P)}var W=C.objectMode?1:ee.length;C.length+=W;var ie=C.length<C.highWaterMark;if(ie||(C.needDrain=!0),C.writing||C.corked){var ye=C.lastBufferedRequest;C.lastBufferedRequest={chunk:ee,encoding:re,isBuf:q,callback:x,next:null},ye?ye.next=C.lastBufferedRequest:C.bufferedRequest=C.lastBufferedRequest,C.bufferedRequestCount+=1}else G(k,C,!1,W,ee,re,x);return ie}function G(k,C,q,ee,re,x,P){C.writelen=ee,C.writecb=P,C.writing=!0,C.sync=!0,C.destroyed?C.onwrite(new w("write")):q?k._writev(re,C.onwrite):k._write(re,x,C.onwrite),C.sync=!1}function K(k,C,q,ee,re){--C.pendingcb,q?(process.nextTick(re,ee),process.nextTick(L,k,C),k._writableState.errorEmitted=!0,v(k,ee)):(re(ee),k._writableState.errorEmitted=!0,v(k,ee),L(k,C))}function te(k){k.writing=!1,k.writecb=null,k.length-=k.writelen,k.writelen=0}function se(k,C){var q=k._writableState,ee=q.sync,re=q.writecb;if(typeof re!="function")throw new m;if(te(q),C)K(k,q,ee,C,re);else{var x=Y(q)||k.destroyed;!x&&!q.corked&&!q.bufferProcessing&&q.bufferedRequest&&R(k,q),ee?process.nextTick(ae,k,q,x,re):ae(k,q,x,re)}}function ae(k,C,q,ee){q||V(k,C),C.pendingcb--,ee(),L(k,C)}function V(k,C){C.length===0&&C.needDrain&&(C.needDrain=!1,k.emit("drain"))}function R(k,C){C.bufferProcessing=!0;var q=C.bufferedRequest;if(k._writev&&q&&q.next){var ee=C.bufferedRequestCount,re=new Array(ee),x=C.corkedRequestsFree;x.entry=q;for(var P=0,W=!0;q;)re[P]=q,q.isBuf||(W=!1),q=q.next,P+=1;re.allBuffers=W,G(k,C,!0,C.length,re,"",x.finish),C.pendingcb++,C.lastBufferedRequest=null,x.next?(C.corkedRequestsFree=x.next,x.next=null):C.corkedRequestsFree=new e(C),C.bufferedRequestCount=0}else{for(;q;){var ie=q.chunk,ye=q.encoding,fe=q.callback,he=C.objectMode?1:ie.length;if(G(k,C,!1,he,ie,ye,fe),q=q.next,C.bufferedRequestCount--,C.writing)break}q===null&&(C.lastBufferedRequest=null)}C.bufferedRequest=q,C.bufferProcessing=!1}M.prototype._write=function(k,C,q){q(new h("_write()"))},M.prototype._writev=null,M.prototype.end=function(k,C,q){var ee=this._writableState;return typeof k=="function"?(q=k,k=null,C=null):typeof C=="function"&&(q=C,C=null),k!=null&&this.write(k,C),ee.corked&&(ee.corked=1,this.uncork()),ee.ending||z(this,ee,q),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function Y(k){return k.ending&&k.length===0&&k.bufferedRequest===null&&!k.finished&&!k.writing}function Q(k,C){k._final(function(q){C.pendingcb--,q&&v(k,q),C.prefinished=!0,k.emit("prefinish"),L(k,C)})}function O(k,C){!C.prefinished&&!C.finalCalled&&(typeof k._final=="function"&&!C.destroyed?(C.pendingcb++,C.finalCalled=!0,process.nextTick(Q,k,C)):(C.prefinished=!0,k.emit("prefinish")))}function L(k,C){var q=Y(C);if(q&&(O(k,C),C.pendingcb===0&&(C.finished=!0,k.emit("finish"),C.autoDestroy))){var ee=k._readableState;(!ee||ee.autoDestroy&&ee.endEmitted)&&k.destroy()}return q}function z(k,C,q){C.ending=!0,L(k,C),q&&(C.finished?process.nextTick(q):k.once("finish",q)),C.ended=!0,k.writable=!1}function oe(k,C,q){var ee=k.entry;for(k.entry=null;ee;){var re=ee.callback;C.pendingcb--,re(q),ee=ee.next}C.corkedRequestsFree.next=k}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(C){this._writableState&&(this._writableState.destroyed=C)}}),M.prototype.destroy=c.destroy,M.prototype._undestroy=c.undestroy,M.prototype._destroy=function(k,C){C(k)},uc}var fc,oh;function ui(){if(oh)return fc;oh=1;var e=Object.keys||function(f){var u=[];for(var l in f)u.push(l);return u};fc=s;var t=fb(),r=cb();Ve(s,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var o=n[i];s.prototype[o]||(s.prototype[o]=r.prototype[o])}function s(f){if(!(this instanceof s))return new s(f);t.call(this,f),r.call(this,f),this.allowHalfOpen=!0,f&&(f.readable===!1&&(this.readable=!1),f.writable===!1&&(this.writable=!1),f.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",a)))}Object.defineProperty(s.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(s.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(s.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function a(){this._writableState.ended||process.nextTick(c,this)}function c(f){f.end()}return Object.defineProperty(s.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(u){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=u,this._writableState.destroyed=u)}}),fc}var Bs={},Al=st.Buffer,sh=Al.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 Q5(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 e8(e){var t=Q5(e);if(typeof t!="string"&&(Al.isEncoding===sh||!sh(e)))throw new Error("Unknown encoding: "+e);return t||e}Bs.StringDecoder=Ho;function Ho(e){this.encoding=e8(e);var t;switch(this.encoding){case"utf16le":this.text=s8,this.end=a8,t=4;break;case"utf8":this.fillLast=n8,t=4;break;case"base64":this.text=c8,this.end=u8,t=3;break;default:this.write=f8,this.end=l8;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Al.allocUnsafe(t)}Ho.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||""};Ho.prototype.end=o8;Ho.prototype.text=i8;Ho.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 lc(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function t8(e,t,r){var n=t.length-1;if(n<r)return 0;var i=lc(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=lc(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=lc(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function r8(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 n8(e){var t=this.lastTotal-this.lastNeed,r=r8(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 i8(e,t){var r=t8(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 o8(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function s8(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 a8(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 c8(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 u8(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function f8(e){return e.toString(this.encoding)}function l8(e){return e&&e.length?this.write(e):""}var ah=On.codes.ERR_STREAM_PREMATURE_CLOSE;function d8(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 h8(){}function p8(e){return e.setHeader&&typeof e.abort=="function"}function ub(e,t,r){if(typeof t=="function")return ub(e,null,t);t||(t={}),r=d8(r||h8);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,o=function(){e.writable||a()},s=e._writableState&&e._writableState.finished,a=function(){i=!1,s=!0,n||r.call(e)},c=e._readableState&&e._readableState.endEmitted,f=function(){n=!1,c=!0,i||r.call(e)},u=function(m){r.call(e,m)},l=function(){var m;if(n&&!c)return(!e._readableState||!e._readableState.ended)&&(m=new ah),r.call(e,m);if(i&&!s)return(!e._writableState||!e._writableState.ended)&&(m=new ah),r.call(e,m)},p=function(){e.req.on("finish",a)};return p8(e)?(e.on("complete",a),e.on("abort",l),e.req?p():e.on("request",p)):i&&!e._writableState&&(e.on("end",o),e.on("close",o)),e.on("end",f),e.on("finish",a),t.error!==!1&&e.on("error",u),e.on("close",l),function(){e.removeListener("complete",a),e.removeListener("abort",l),e.removeListener("request",p),e.req&&e.req.removeListener("finish",a),e.removeListener("end",o),e.removeListener("close",o),e.removeListener("finish",a),e.removeListener("end",f),e.removeListener("error",u),e.removeListener("close",l)}}var Sl=ub,dc,ch;function y8(){if(ch)return dc;ch=1;var e;function t(E,v,B){return v=r(v),v in E?Object.defineProperty(E,v,{value:B,enumerable:!0,configurable:!0,writable:!0}):E[v]=B,E}function r(E){var v=n(E,"string");return typeof v=="symbol"?v:String(v)}function n(E,v){if(typeof E!="object"||E===null)return E;var B=E[Symbol.toPrimitive];if(B!==void 0){var I=B.call(E,v);if(typeof I!="object")return I;throw new TypeError("@@toPrimitive must return a primitive value.")}return(v==="string"?String:Number)(E)}var i=Sl,o=Symbol("lastResolve"),s=Symbol("lastReject"),a=Symbol("error"),c=Symbol("ended"),f=Symbol("lastPromise"),u=Symbol("handlePromise"),l=Symbol("stream");function p(E,v){return{value:E,done:v}}function h(E){var v=E[o];if(v!==null){var B=E[l].read();B!==null&&(E[f]=null,E[o]=null,E[s]=null,v(p(B,!1)))}}function m(E){process.nextTick(h,E)}function b(E,v){return function(B,I){E.then(function(){if(v[c]){B(p(void 0,!0));return}v[u](B,I)},I)}}var w=Object.getPrototypeOf(function(){}),_=Object.setPrototypeOf((e={get stream(){return this[l]},next:function(){var v=this,B=this[a];if(B!==null)return Promise.reject(B);if(this[c])return Promise.resolve(p(void 0,!0));if(this[l].destroyed)return new Promise(function(A,H){process.nextTick(function(){v[a]?H(v[a]):A(p(void 0,!0))})});var I=this[f],N;if(I)N=new Promise(b(I,this));else{var M=this[l].read();if(M!==null)return Promise.resolve(p(M,!1));N=new Promise(this[u])}return this[f]=N,N}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var v=this;return new Promise(function(B,I){v[l].destroy(null,function(N){if(N){I(N);return}B(p(void 0,!0))})})}),e),w),S=function(v){var B,I=Object.create(_,(B={},t(B,l,{value:v,writable:!0}),t(B,o,{value:null,writable:!0}),t(B,s,{value:null,writable:!0}),t(B,a,{value:null,writable:!0}),t(B,c,{value:v._readableState.endEmitted,writable:!0}),t(B,u,{value:function(M,A){var H=I[l].read();H?(I[f]=null,I[o]=null,I[s]=null,M(p(H,!1))):(I[o]=M,I[s]=A)},writable:!0}),B));return I[f]=null,i(v,function(N){if(N&&N.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=I[s];M!==null&&(I[f]=null,I[o]=null,I[s]=null,M(N)),I[a]=N;return}var A=I[o];A!==null&&(I[f]=null,I[o]=null,I[s]=null,A(p(void 0,!0))),I[c]=!0}),v.on("readable",m.bind(null,I)),I};return dc=S,dc}var hc,uh;function m8(){return uh||(uh=1,hc=function(){throw new Error("Readable.from is not available in the browser")}),hc}var pc,fh;function fb(){if(fh)return pc;fh=1,pc=A;var e;A.ReadableState=M,nb.EventEmitter;var t=function(P,W){return P.listeners(W).length},r=ib,n=Yt.Buffer,i=(typeof Ge<"u"?Ge:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(x){return n.from(x)}function s(x){return n.isBuffer(x)||x instanceof i}var a=xl,c;a&&a.debuglog?c=a.debuglog("stream"):c=function(){};var f=H5(),u=ob,l=ab,p=l.getHighWaterMark,h=On.codes,m=h.ERR_INVALID_ARG_TYPE,b=h.ERR_STREAM_PUSH_AFTER_EOF,w=h.ERR_METHOD_NOT_IMPLEMENTED,_=h.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,S,E,v;Ve(A,r);var B=u.errorOrDestroy,I=["error","close","destroy","pause","resume"];function N(x,P,W){if(typeof x.prependListener=="function")return x.prependListener(P,W);!x._events||!x._events[P]?x.on(P,W):Array.isArray(x._events[P])?x._events[P].unshift(W):x._events[P]=[W,x._events[P]]}function M(x,P,W){e=e||ui(),x=x||{},typeof W!="boolean"&&(W=P instanceof e),this.objectMode=!!x.objectMode,W&&(this.objectMode=this.objectMode||!!x.readableObjectMode),this.highWaterMark=p(this,x,"readableHighWaterMark",W),this.buffer=new f,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=x.emitClose!==!1,this.autoDestroy=!!x.autoDestroy,this.destroyed=!1,this.defaultEncoding=x.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,x.encoding&&(S||(S=Bs.StringDecoder),this.decoder=new S(x.encoding),this.encoding=x.encoding)}function A(x){if(e=e||ui(),!(this instanceof A))return new A(x);var P=this instanceof e;this._readableState=new M(x,this,P),this.readable=!0,x&&(typeof x.read=="function"&&(this._read=x.read),typeof x.destroy=="function"&&(this._destroy=x.destroy)),r.call(this)}Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(P){this._readableState&&(this._readableState.destroyed=P)}}),A.prototype.destroy=u.destroy,A.prototype._undestroy=u.undestroy,A.prototype._destroy=function(x,P){P(x)},A.prototype.push=function(x,P){var W=this._readableState,ie;return W.objectMode?ie=!0:typeof x=="string"&&(P=P||W.defaultEncoding,P!==W.encoding&&(x=n.from(x,P),P=""),ie=!0),H(this,x,P,!1,ie)},A.prototype.unshift=function(x){return H(this,x,null,!0,!1)};function H(x,P,W,ie,ye){c("readableAddChunk",P);var fe=x._readableState;if(P===null)fe.reading=!1,se(x,fe);else{var he;if(ye||(he=D(fe,P)),he)B(x,he);else if(fe.objectMode||P&&P.length>0)if(typeof P!="string"&&!fe.objectMode&&Object.getPrototypeOf(P)!==n.prototype&&(P=o(P)),ie)fe.endEmitted?B(x,new _):F(x,fe,P,!0);else if(fe.ended)B(x,new b);else{if(fe.destroyed)return!1;fe.reading=!1,fe.decoder&&!W?(P=fe.decoder.write(P),fe.objectMode||P.length!==0?F(x,fe,P,!1):R(x,fe)):F(x,fe,P,!1)}else ie||(fe.reading=!1,R(x,fe))}return!fe.ended&&(fe.length<fe.highWaterMark||fe.length===0)}function F(x,P,W,ie){P.flowing&&P.length===0&&!P.sync?(P.awaitDrain=0,x.emit("data",W)):(P.length+=P.objectMode?1:W.length,ie?P.buffer.unshift(W):P.buffer.push(W),P.needReadable&&ae(x)),R(x,P)}function D(x,P){var W;return!s(P)&&typeof P!="string"&&P!==void 0&&!x.objectMode&&(W=new m("chunk",["string","Buffer","Uint8Array"],P)),W}A.prototype.isPaused=function(){return this._readableState.flowing===!1},A.prototype.setEncoding=function(x){S||(S=Bs.StringDecoder);var P=new S(x);this._readableState.decoder=P,this._readableState.encoding=this._readableState.decoder.encoding;for(var W=this._readableState.buffer.head,ie="";W!==null;)ie+=P.write(W.data),W=W.next;return this._readableState.buffer.clear(),ie!==""&&this._readableState.buffer.push(ie),this._readableState.length=ie.length,this};var G=1073741824;function K(x){return x>=G?x=G:(x--,x|=x>>>1,x|=x>>>2,x|=x>>>4,x|=x>>>8,x|=x>>>16,x++),x}function te(x,P){return x<=0||P.length===0&&P.ended?0:P.objectMode?1:x!==x?P.flowing&&P.length?P.buffer.head.data.length:P.length:(x>P.highWaterMark&&(P.highWaterMark=K(x)),x<=P.length?x:P.ended?P.length:(P.needReadable=!0,0))}A.prototype.read=function(x){c("read",x),x=parseInt(x,10);var P=this._readableState,W=x;if(x!==0&&(P.emittedReadable=!1),x===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):ae(this),null;if(x=te(x,P),x===0&&P.ended)return P.length===0&&q(this),null;var ie=P.needReadable;c("need readable",ie),(P.length===0||P.length-x<P.highWaterMark)&&(ie=!0,c("length less than watermark",ie)),P.ended||P.reading?(ie=!1,c("reading or ended",ie)):ie&&(c("do read"),P.reading=!0,P.sync=!0,P.length===0&&(P.needReadable=!0),this._read(P.highWaterMark),P.sync=!1,P.reading||(x=te(W,P)));var ye;return x>0?ye=C(x,P):ye=null,ye===null?(P.needReadable=P.length<=P.highWaterMark,x=0):(P.length-=x,P.awaitDrain=0),P.length===0&&(P.ended||(P.needReadable=!0),W!==x&&P.ended&&q(this)),ye!==null&&this.emit("data",ye),ye};function se(x,P){if(c("onEofChunk"),!P.ended){if(P.decoder){var W=P.decoder.end();W&&W.length&&(P.buffer.push(W),P.length+=P.objectMode?1:W.length)}P.ended=!0,P.sync?ae(x):(P.needReadable=!1,P.emittedReadable||(P.emittedReadable=!0,V(x)))}}function ae(x){var P=x._readableState;c("emitReadable",P.needReadable,P.emittedReadable),P.needReadable=!1,P.emittedReadable||(c("emitReadable",P.flowing),P.emittedReadable=!0,process.nextTick(V,x))}function V(x){var P=x._readableState;c("emitReadable_",P.destroyed,P.length,P.ended),!P.destroyed&&(P.length||P.ended)&&(x.emit("readable"),P.emittedReadable=!1),P.needReadable=!P.flowing&&!P.ended&&P.length<=P.highWaterMark,k(x)}function R(x,P){P.readingMore||(P.readingMore=!0,process.nextTick(Y,x,P))}function Y(x,P){for(;!P.reading&&!P.ended&&(P.length<P.highWaterMark||P.flowing&&P.length===0);){var W=P.length;if(c("maybeReadMore read 0"),x.read(0),W===P.length)break}P.readingMore=!1}A.prototype._read=function(x){B(this,new w("_read()"))},A.prototype.pipe=function(x,P){var W=this,ie=this._readableState;switch(ie.pipesCount){case 0:ie.pipes=x;break;case 1:ie.pipes=[ie.pipes,x];break;default:ie.pipes.push(x);break}ie.pipesCount+=1,c("pipe count=%d opts=%j",ie.pipesCount,P);var ye=(!P||P.end!==!1)&&x!==process.stdout&&x!==process.stderr,fe=ye?mt:en;ie.endEmitted?process.nextTick(fe):W.once("end",fe),x.on("unpipe",he);function he(g,d){c("onunpipe"),g===W&&d&&d.hasUnpiped===!1&&(d.hasUnpiped=!0,We())}function mt(){c("onend"),x.end()}var Z=Q(W);x.on("drain",Z);var _t=!1;function We(){c("cleanup"),x.removeListener("close",Xt),x.removeListener("finish",Bt),x.removeListener("drain",Z),x.removeListener("error",Tt),x.removeListener("unpipe",he),W.removeListener("end",mt),W.removeListener("end",en),W.removeListener("data",De),_t=!0,ie.awaitDrain&&(!x._writableState||x._writableState.needDrain)&&Z()}W.on("data",De);function De(g){c("ondata");var d=x.write(g);c("dest.write",d),d===!1&&((ie.pipesCount===1&&ie.pipes===x||ie.pipesCount>1&&re(ie.pipes,x)!==-1)&&!_t&&(c("false write response, pause",ie.awaitDrain),ie.awaitDrain++),W.pause())}function Tt(g){c("onerror",g),en(),x.removeListener("error",Tt),t(x,"error")===0&&B(x,g)}N(x,"error",Tt);function Xt(){x.removeListener("finish",Bt),en()}x.once("close",Xt);function Bt(){c("onfinish"),x.removeListener("close",Xt),en()}x.once("finish",Bt);function en(){c("unpipe"),W.unpipe(x)}return x.emit("pipe",W),ie.flowing||(c("pipe resume"),W.resume()),x};function Q(x){return function(){var W=x._readableState;c("pipeOnDrain",W.awaitDrain),W.awaitDrain&&W.awaitDrain--,W.awaitDrain===0&&t(x,"data")&&(W.flowing=!0,k(x))}}A.prototype.unpipe=function(x){var P=this._readableState,W={hasUnpiped:!1};if(P.pipesCount===0)return this;if(P.pipesCount===1)return x&&x!==P.pipes?this:(x||(x=P.pipes),P.pipes=null,P.pipesCount=0,P.flowing=!1,x&&x.emit("unpipe",this,W),this);if(!x){var ie=P.pipes,ye=P.pipesCount;P.pipes=null,P.pipesCount=0,P.flowing=!1;for(var fe=0;fe<ye;fe++)ie[fe].emit("unpipe",this,{hasUnpiped:!1});return this}var he=re(P.pipes,x);return he===-1?this:(P.pipes.splice(he,1),P.pipesCount-=1,P.pipesCount===1&&(P.pipes=P.pipes[0]),x.emit("unpipe",this,W),this)},A.prototype.on=function(x,P){var W=r.prototype.on.call(this,x,P),ie=this._readableState;return x==="data"?(ie.readableListening=this.listenerCount("readable")>0,ie.flowing!==!1&&this.resume()):x==="readable"&&!ie.endEmitted&&!ie.readableListening&&(ie.readableListening=ie.needReadable=!0,ie.flowing=!1,ie.emittedReadable=!1,c("on readable",ie.length,ie.reading),ie.length?ae(this):ie.reading||process.nextTick(L,this)),W},A.prototype.addListener=A.prototype.on,A.prototype.removeListener=function(x,P){var W=r.prototype.removeListener.call(this,x,P);return x==="readable"&&process.nextTick(O,this),W},A.prototype.removeAllListeners=function(x){var P=r.prototype.removeAllListeners.apply(this,arguments);return(x==="readable"||x===void 0)&&process.nextTick(O,this),P};function O(x){var P=x._readableState;P.readableListening=x.listenerCount("readable")>0,P.resumeScheduled&&!P.paused?P.flowing=!0:x.listenerCount("data")>0&&x.resume()}function L(x){c("readable nexttick read 0"),x.read(0)}A.prototype.resume=function(){var x=this._readableState;return x.flowing||(c("resume"),x.flowing=!x.readableListening,z(this,x)),x.paused=!1,this};function z(x,P){P.resumeScheduled||(P.resumeScheduled=!0,process.nextTick(oe,x,P))}function oe(x,P){c("resume",P.reading),P.reading||x.read(0),P.resumeScheduled=!1,x.emit("resume"),k(x),P.flowing&&!P.reading&&x.read(0)}A.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 k(x){var P=x._readableState;for(c("flow",P.flowing);P.flowing&&x.read()!==null;);}A.prototype.wrap=function(x){var P=this,W=this._readableState,ie=!1;x.on("end",function(){if(c("wrapped end"),W.decoder&&!W.ended){var he=W.decoder.end();he&&he.length&&P.push(he)}P.push(null)}),x.on("data",function(he){if(c("wrapped data"),W.decoder&&(he=W.decoder.write(he)),!(W.objectMode&&he==null)&&!(!W.objectMode&&(!he||!he.length))){var mt=P.push(he);mt||(ie=!0,x.pause())}});for(var ye in x)this[ye]===void 0&&typeof x[ye]=="function"&&(this[ye]=function(mt){return function(){return x[mt].apply(x,arguments)}}(ye));for(var fe=0;fe<I.length;fe++)x.on(I[fe],this.emit.bind(this,I[fe]));return this._read=function(he){c("wrapped _read",he),ie&&(ie=!1,x.resume())},this},typeof Symbol=="function"&&(A.prototype[Symbol.asyncIterator]=function(){return E===void 0&&(E=y8()),E(this)}),Object.defineProperty(A.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(A.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(A.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(P){this._readableState&&(this._readableState.flowing=P)}}),A._fromList=C,Object.defineProperty(A.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function C(x,P){if(P.length===0)return null;var W;return P.objectMode?W=P.buffer.shift():!x||x>=P.length?(P.decoder?W=P.buffer.join(""):P.buffer.length===1?W=P.buffer.first():W=P.buffer.concat(P.length),P.buffer.clear()):W=P.buffer.consume(x,P.decoder),W}function q(x){var P=x._readableState;c("endReadable",P.endEmitted),P.endEmitted||(P.ended=!0,process.nextTick(ee,P,x))}function ee(x,P){if(c("endReadableNT",x.endEmitted,x.length),!x.endEmitted&&x.length===0&&(x.endEmitted=!0,P.readable=!1,P.emit("end"),x.autoDestroy)){var W=P._writableState;(!W||W.autoDestroy&&W.finished)&&P.destroy()}}typeof Symbol=="function"&&(A.from=function(x,P){return v===void 0&&(v=m8()),v(A,x,P)});function re(x,P){for(var W=0,ie=x.length;W<ie;W++)if(x[W]===P)return W;return-1}return pc}var lb=kr,ma=On.codes,b8=ma.ERR_METHOD_NOT_IMPLEMENTED,g8=ma.ERR_MULTIPLE_CALLBACK,w8=ma.ERR_TRANSFORM_ALREADY_TRANSFORMING,v8=ma.ERR_TRANSFORM_WITH_LENGTH_0,ba=ui();Ve(kr,ba);function _8(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new g8);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 kr(e){if(!(this instanceof kr))return new kr(e);ba.call(this,e),this._transformState={afterTransform:_8.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",E8)}function E8(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){lh(e,t,r)}):lh(this,null,null)}kr.prototype.push=function(e,t){return this._transformState.needTransform=!1,ba.prototype.push.call(this,e,t)};kr.prototype._transform=function(e,t,r){r(new b8("_transform()"))};kr.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)}};kr.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};kr.prototype._destroy=function(e,t){ba.prototype._destroy.call(this,e,function(r){t(r)})};function lh(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new v8;if(e._transformState.transforming)throw new w8;return e.push(null)}var x8=Ao,db=lb;Ve(Ao,db);function Ao(e){if(!(this instanceof Ao))return new Ao(e);db.call(this,e)}Ao.prototype._transform=function(e,t,r){r(null,e)};var yc;function A8(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var hb=On.codes,S8=hb.ERR_MISSING_ARGS,P8=hb.ERR_STREAM_DESTROYED;function dh(e){if(e)throw e}function T8(e){return e.setHeader&&typeof e.abort=="function"}function B8(e,t,r,n){n=A8(n);var i=!1;e.on("close",function(){i=!0}),yc===void 0&&(yc=Sl),yc(e,{readable:t,writable:r},function(s){if(s)return n(s);i=!0,n()});var o=!1;return function(s){if(!i&&!o){if(o=!0,T8(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(s||new P8("pipe"))}}}function hh(e){e()}function I8(e,t){return e.pipe(t)}function k8(e){return!e.length||typeof e[e.length-1]!="function"?dh:e.pop()}function O8(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=k8(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new S8("streams");var i,o=t.map(function(s,a){var c=a<t.length-1,f=a>0;return B8(s,c,f,function(u){i||(i=u),u&&o.forEach(hh),!c&&(o.forEach(hh),n(i))})});return t.reduce(I8)}var R8=O8;(function(e,t){t=e.exports=fb(),t.Stream=t,t.Readable=t,t.Writable=cb(),t.Duplex=ui(),t.Transform=lb,t.PassThrough=x8,t.finished=Sl,t.pipeline=R8})(lf,lf.exports);var pb=lf.exports,Is=st.Buffer,yb=pb.Transform,C8=Ve;function N8(e,t){if(!Is.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Jr(e){yb.call(this),this._block=Is.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}C8(Jr,yb);Jr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Jr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Jr.prototype.update=function(e,t){if(N8(e,"Data"),this._finalized)throw new Error("Digest already called");Is.isBuffer(e)||(e=Is.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var o=0,s=e.length*8;s>0;++o)this._length[o]+=s,s=this._length[o]/4294967296|0,s>0&&(this._length[o]-=4294967296*s);return this};Jr.prototype._update=function(){throw new Error("_update is not implemented")};Jr.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};Jr.prototype._digest=function(){throw new Error("_digest is not implemented")};var $8=Jr,F8=Ve,mb=$8,U8=st.Buffer,L8=new Array(16);function ga(){mb.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}F8(ga,mb);ga.prototype._update=function(){for(var e=L8,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,o=this._d;r=Qe(r,n,i,o,e[0],3614090360,7),o=Qe(o,r,n,i,e[1],3905402710,12),i=Qe(i,o,r,n,e[2],606105819,17),n=Qe(n,i,o,r,e[3],3250441966,22),r=Qe(r,n,i,o,e[4],4118548399,7),o=Qe(o,r,n,i,e[5],1200080426,12),i=Qe(i,o,r,n,e[6],2821735955,17),n=Qe(n,i,o,r,e[7],4249261313,22),r=Qe(r,n,i,o,e[8],1770035416,7),o=Qe(o,r,n,i,e[9],2336552879,12),i=Qe(i,o,r,n,e[10],4294925233,17),n=Qe(n,i,o,r,e[11],2304563134,22),r=Qe(r,n,i,o,e[12],1804603682,7),o=Qe(o,r,n,i,e[13],4254626195,12),i=Qe(i,o,r,n,e[14],2792965006,17),n=Qe(n,i,o,r,e[15],1236535329,22),r=et(r,n,i,o,e[1],4129170786,5),o=et(o,r,n,i,e[6],3225465664,9),i=et(i,o,r,n,e[11],643717713,14),n=et(n,i,o,r,e[0],3921069994,20),r=et(r,n,i,o,e[5],3593408605,5),o=et(o,r,n,i,e[10],38016083,9),i=et(i,o,r,n,e[15],3634488961,14),n=et(n,i,o,r,e[4],3889429448,20),r=et(r,n,i,o,e[9],568446438,5),o=et(o,r,n,i,e[14],3275163606,9),i=et(i,o,r,n,e[3],4107603335,14),n=et(n,i,o,r,e[8],1163531501,20),r=et(r,n,i,o,e[13],2850285829,5),o=et(o,r,n,i,e[2],4243563512,9),i=et(i,o,r,n,e[7],1735328473,14),n=et(n,i,o,r,e[12],2368359562,20),r=tt(r,n,i,o,e[5],4294588738,4),o=tt(o,r,n,i,e[8],2272392833,11),i=tt(i,o,r,n,e[11],1839030562,16),n=tt(n,i,o,r,e[14],4259657740,23),r=tt(r,n,i,o,e[1],2763975236,4),o=tt(o,r,n,i,e[4],1272893353,11),i=tt(i,o,r,n,e[7],4139469664,16),n=tt(n,i,o,r,e[10],3200236656,23),r=tt(r,n,i,o,e[13],681279174,4),o=tt(o,r,n,i,e[0],3936430074,11),i=tt(i,o,r,n,e[3],3572445317,16),n=tt(n,i,o,r,e[6],76029189,23),r=tt(r,n,i,o,e[9],3654602809,4),o=tt(o,r,n,i,e[12],3873151461,11),i=tt(i,o,r,n,e[15],530742520,16),n=tt(n,i,o,r,e[2],3299628645,23),r=rt(r,n,i,o,e[0],4096336452,6),o=rt(o,r,n,i,e[7],1126891415,10),i=rt(i,o,r,n,e[14],2878612391,15),n=rt(n,i,o,r,e[5],4237533241,21),r=rt(r,n,i,o,e[12],1700485571,6),o=rt(o,r,n,i,e[3],2399980690,10),i=rt(i,o,r,n,e[10],4293915773,15),n=rt(n,i,o,r,e[1],2240044497,21),r=rt(r,n,i,o,e[8],1873313359,6),o=rt(o,r,n,i,e[15],4264355552,10),i=rt(i,o,r,n,e[6],2734768916,15),n=rt(n,i,o,r,e[13],1309151649,21),r=rt(r,n,i,o,e[4],4149444226,6),o=rt(o,r,n,i,e[11],3174756917,10),i=rt(i,o,r,n,e[2],718787259,15),n=rt(n,i,o,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+o|0};ga.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=U8.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 wa(e,t){return e<<t|e>>>32-t}function Qe(e,t,r,n,i,o,s){return wa(e+(t&r|~t&n)+i+o|0,s)+t|0}function et(e,t,r,n,i,o,s){return wa(e+(t&n|r&~n)+i+o|0,s)+t|0}function tt(e,t,r,n,i,o,s){return wa(e+(t^r^n)+i+o|0,s)+t|0}function rt(e,t,r,n,i,o,s){return wa(e+(r^(t|~n))+i+o|0,s)+t|0}var M8=ga,ks=st.Buffer,bb=pb.Transform,H8=Ve;function D8(e,t){if(!ks.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Qr(e){bb.call(this),this._block=ks.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}H8(Qr,bb);Qr.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Qr.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Qr.prototype.update=function(e,t){if(D8(e,"Data"),this._finalized)throw new Error("Digest already called");ks.isBuffer(e)||(e=ks.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var o=0,s=e.length*8;s>0;++o)this._length[o]+=s,s=this._length[o]/4294967296|0,s>0&&(this._length[o]-=4294967296*s);return this};Qr.prototype._update=function(){throw new Error("_update is not implemented")};Qr.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};Qr.prototype._digest=function(){throw new Error("_digest is not implemented")};var j8=Qr,mc=Yt.Buffer,q8=Ve,gb=j8,z8=new Array(16),Ci=[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],Ni=[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],$i=[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],Fi=[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],Ui=[0,1518500249,1859775393,2400959708,2840853838],Li=[1352829926,1548603684,1836072691,2053994217,0];function va(){gb.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}q8(va,gb);va.prototype._update=function(){for(var e=z8,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=this._e|0,a=this._a|0,c=this._b|0,f=this._c|0,u=this._d|0,l=this._e|0,p=0;p<80;p+=1){var h,m;p<16?(h=ph(r,n,i,o,s,e[Ci[p]],Ui[0],$i[p]),m=gh(a,c,f,u,l,e[Ni[p]],Li[0],Fi[p])):p<32?(h=yh(r,n,i,o,s,e[Ci[p]],Ui[1],$i[p]),m=bh(a,c,f,u,l,e[Ni[p]],Li[1],Fi[p])):p<48?(h=mh(r,n,i,o,s,e[Ci[p]],Ui[2],$i[p]),m=mh(a,c,f,u,l,e[Ni[p]],Li[2],Fi[p])):p<64?(h=bh(r,n,i,o,s,e[Ci[p]],Ui[3],$i[p]),m=yh(a,c,f,u,l,e[Ni[p]],Li[3],Fi[p])):(h=gh(r,n,i,o,s,e[Ci[p]],Ui[4],$i[p]),m=ph(a,c,f,u,l,e[Ni[p]],Li[4],Fi[p])),r=s,s=o,o=An(i,10),i=n,n=h,a=l,l=u,u=An(f,10),f=c,c=m}var b=this._b+i+u|0;this._b=this._c+o+l|0,this._c=this._d+s+a|0,this._d=this._e+r+c|0,this._e=this._a+n+f|0,this._a=b};va.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=mc.alloc?mc.alloc(20):new mc(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 An(e,t){return e<<t|e>>>32-t}function ph(e,t,r,n,i,o,s,a){return An(e+(t^r^n)+o+s|0,a)+i|0}function yh(e,t,r,n,i,o,s,a){return An(e+(t&r|~t&n)+o+s|0,a)+i|0}function mh(e,t,r,n,i,o,s,a){return An(e+((t|~r)^n)+o+s|0,a)+i|0}function bh(e,t,r,n,i,o,s,a){return An(e+(t&n|r&~n)+o+s|0,a)+i|0}function gh(e,t,r,n,i,o,s,a){return An(e+(t^(r|~n))+o+s|0,a)+i|0}var G8=va,wb={exports:{}},V8={}.toString,W8=Array.isArray||function(e){return V8.call(e)=="[object Array]"},bc,wh;function Ei(){return wh||(wh=1,bc=TypeError),bc}var gc,vh;function vb(){return vh||(vh=1,gc=Object),gc}var wc,_h;function K8(){return _h||(_h=1,wc=Error),wc}var vc,Eh;function Y8(){return Eh||(Eh=1,vc=EvalError),vc}var _c,xh;function Z8(){return xh||(xh=1,_c=RangeError),_c}var Ec,Ah;function X8(){return Ah||(Ah=1,Ec=ReferenceError),Ec}var xc,Sh;function _b(){return Sh||(Sh=1,xc=SyntaxError),xc}var Ac,Ph;function J8(){return Ph||(Ph=1,Ac=URIError),Ac}var Sc,Th;function Q8(){return Th||(Th=1,Sc=Math.abs),Sc}var Pc,Bh;function eA(){return Bh||(Bh=1,Pc=Math.floor),Pc}var Tc,Ih;function tA(){return Ih||(Ih=1,Tc=Math.max),Tc}var Bc,kh;function rA(){return kh||(kh=1,Bc=Math.min),Bc}var Ic,Oh;function nA(){return Oh||(Oh=1,Ic=Math.pow),Ic}var kc,Rh;function iA(){return Rh||(Rh=1,kc=Math.round),kc}var Oc,Ch;function oA(){return Ch||(Ch=1,Oc=Number.isNaN||function(t){return t!==t}),Oc}var Rc,Nh;function sA(){if(Nh)return Rc;Nh=1;var e=oA();return Rc=function(r){return e(r)||r===0?r:r<0?-1:1},Rc}var Cc,$h;function aA(){return $h||($h=1,Cc=Object.getOwnPropertyDescriptor),Cc}var Nc,Fh;function xi(){if(Fh)return Nc;Fh=1;var e=aA();if(e)try{e([],"length")}catch{e=null}return Nc=e,Nc}var $c,Uh;function _a(){if(Uh)return $c;Uh=1;var e=Object.defineProperty||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return $c=e,$c}var Fc,Lh;function Eb(){return Lh||(Lh=1,Fc=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},r=Symbol("test"),n=Object(r);if(typeof r=="string"||Object.prototype.toString.call(r)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var i=42;t[r]=i;for(var o in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var s=Object.getOwnPropertySymbols(t);if(s.length!==1||s[0]!==r||!Object.prototype.propertyIsEnumerable.call(t,r))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var a=Object.getOwnPropertyDescriptor(t,r);if(a.value!==i||a.enumerable!==!0)return!1}return!0}),Fc}var Uc,Mh;function cA(){if(Mh)return Uc;Mh=1;var e=typeof Symbol<"u"&&Symbol,t=Eb();return Uc=function(){return typeof e!="function"||typeof Symbol!="function"||typeof e("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},Uc}var Lc,Hh;function xb(){return Hh||(Hh=1,Lc=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),Lc}var Mc,Dh;function Ab(){if(Dh)return Mc;Dh=1;var e=vb();return Mc=e.getPrototypeOf||null,Mc}var Hc,jh;function uA(){if(jh)return Hc;jh=1;var e="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,r=Math.max,n="[object Function]",i=function(c,f){for(var u=[],l=0;l<c.length;l+=1)u[l]=c[l];for(var p=0;p<f.length;p+=1)u[p+c.length]=f[p];return u},o=function(c,f){for(var u=[],l=f,p=0;l<c.length;l+=1,p+=1)u[p]=c[l];return u},s=function(a,c){for(var f="",u=0;u<a.length;u+=1)f+=a[u],u+1<a.length&&(f+=c);return f};return Hc=function(c){var f=this;if(typeof f!="function"||t.apply(f)!==n)throw new TypeError(e+f);for(var u=o(arguments,1),l,p=function(){if(this instanceof l){var _=f.apply(this,i(u,arguments));return Object(_)===_?_:this}return f.apply(c,i(u,arguments))},h=r(0,f.length-u.length),m=[],b=0;b<h;b++)m[b]="$"+b;if(l=Function("binder","return function ("+s(m,",")+"){ return binder.apply(this,arguments); }")(p),f.prototype){var w=function(){};w.prototype=f.prototype,l.prototype=new w,w.prototype=null}return l},Hc}var Dc,qh;function Do(){if(qh)return Dc;qh=1;var e=uA();return Dc=Function.prototype.bind||e,Dc}var jc,zh;function Pl(){return zh||(zh=1,jc=Function.prototype.call),jc}var qc,Gh;function Tl(){return Gh||(Gh=1,qc=Function.prototype.apply),qc}var zc,Vh;function fA(){return Vh||(Vh=1,zc=typeof Reflect<"u"&&Reflect&&Reflect.apply),zc}var Gc,Wh;function Sb(){if(Wh)return Gc;Wh=1;var e=Do(),t=Tl(),r=Pl(),n=fA();return Gc=n||e.call(r,t),Gc}var Vc,Kh;function Bl(){if(Kh)return Vc;Kh=1;var e=Do(),t=Ei(),r=Pl(),n=Sb();return Vc=function(o){if(o.length<1||typeof o[0]!="function")throw new t("a function is required");return n(e,r,o)},Vc}var Wc,Yh;function lA(){if(Yh)return Wc;Yh=1;var e=Bl(),t=xi(),r;try{r=[].__proto__===Array.prototype}catch(s){if(!s||typeof s!="object"||!("code"in s)||s.code!=="ERR_PROTO_ACCESS")throw s}var n=!!r&&t&&t(Object.prototype,"__proto__"),i=Object,o=i.getPrototypeOf;return Wc=n&&typeof n.get=="function"?e([n.get]):typeof o=="function"?function(a){return o(a==null?a:i(a))}:!1,Wc}var Kc,Zh;function Il(){if(Zh)return Kc;Zh=1;var e=xb(),t=Ab(),r=lA();return Kc=e?function(i){return e(i)}:t?function(i){if(!i||typeof i!="object"&&typeof i!="function")throw new TypeError("getProto: not an object");return t(i)}:r?function(i){return r(i)}:null,Kc}var Yc,Xh;function Pb(){if(Xh)return Yc;Xh=1;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=Do();return Yc=r.call(e,t),Yc}var Zc,Jh;function Tb(){if(Jh)return Zc;Jh=1;var e,t=vb(),r=K8(),n=Y8(),i=Z8(),o=X8(),s=_b(),a=Ei(),c=J8(),f=Q8(),u=eA(),l=tA(),p=rA(),h=nA(),m=iA(),b=sA(),w=Function,_=function(ee){try{return w('"use strict"; return ('+ee+").constructor;")()}catch{}},S=xi(),E=_a(),v=function(){throw new a},B=S?function(){try{return arguments.callee,v}catch{try{return S(arguments,"callee").get}catch{return v}}}():v,I=cA()(),N=Il(),M=Ab(),A=xb(),H=Tl(),F=Pl(),D={},G=typeof Uint8Array>"u"||!N?e:N(Uint8Array),K={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":I&&N?N([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":D,"%AsyncGenerator%":D,"%AsyncGeneratorFunction%":D,"%AsyncIteratorPrototype%":D,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":r,"%eval%":eval,"%EvalError%":n,"%Float16Array%":typeof Float16Array>"u"?e:Float16Array,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":w,"%GeneratorFunction%":D,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":I&&N?N(N([][Symbol.iterator]())):e,"%JSON%":typeof JSON=="object"?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!I||!N?e:N(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":t,"%Object.getOwnPropertyDescriptor%":S,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":i,"%ReferenceError%":o,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!I||!N?e:N(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":I&&N?N(""[Symbol.iterator]()):e,"%Symbol%":I?Symbol:e,"%SyntaxError%":s,"%ThrowTypeError%":B,"%TypedArray%":G,"%TypeError%":a,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":c,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet,"%Function.prototype.call%":F,"%Function.prototype.apply%":H,"%Object.defineProperty%":E,"%Object.getPrototypeOf%":M,"%Math.abs%":f,"%Math.floor%":u,"%Math.max%":l,"%Math.min%":p,"%Math.pow%":h,"%Math.round%":m,"%Math.sign%":b,"%Reflect.getPrototypeOf%":A};if(N)try{null.error}catch(ee){var te=N(N(ee));K["%Error.prototype%"]=te}var se=function ee(re){var x;if(re==="%AsyncFunction%")x=_("async function () {}");else if(re==="%GeneratorFunction%")x=_("function* () {}");else if(re==="%AsyncGeneratorFunction%")x=_("async function* () {}");else if(re==="%AsyncGenerator%"){var P=ee("%AsyncGeneratorFunction%");P&&(x=P.prototype)}else if(re==="%AsyncIteratorPrototype%"){var W=ee("%AsyncGenerator%");W&&N&&(x=N(W.prototype))}return K[re]=x,x},ae={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},V=Do(),R=Pb(),Y=V.call(F,Array.prototype.concat),Q=V.call(H,Array.prototype.splice),O=V.call(F,String.prototype.replace),L=V.call(F,String.prototype.slice),z=V.call(F,RegExp.prototype.exec),oe=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,k=/\\(\\)?/g,C=function(re){var x=L(re,0,1),P=L(re,-1);if(x==="%"&&P!=="%")throw new s("invalid intrinsic syntax, expected closing `%`");if(P==="%"&&x!=="%")throw new s("invalid intrinsic syntax, expected opening `%`");var W=[];return O(re,oe,function(ie,ye,fe,he){W[W.length]=fe?O(he,k,"$1"):ye||ie}),W},q=function(re,x){var P=re,W;if(R(ae,P)&&(W=ae[P],P="%"+W[0]+"%"),R(K,P)){var ie=K[P];if(ie===D&&(ie=se(P)),typeof ie>"u"&&!x)throw new a("intrinsic "+re+" exists, but is not available. Please file an issue!");return{alias:W,name:P,value:ie}}throw new s("intrinsic "+re+" does not exist!")};return Zc=function(re,x){if(typeof re!="string"||re.length===0)throw new a("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof x!="boolean")throw new a('"allowMissing" argument must be a boolean');if(z(/^%?[^%]*%?$/,re)===null)throw new s("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var P=C(re),W=P.length>0?P[0]:"",ie=q("%"+W+"%",x),ye=ie.name,fe=ie.value,he=!1,mt=ie.alias;mt&&(W=mt[0],Q(P,Y([0,1],mt)));for(var Z=1,_t=!0;Z<P.length;Z+=1){var We=P[Z],De=L(We,0,1),Tt=L(We,-1);if((De==='"'||De==="'"||De==="`"||Tt==='"'||Tt==="'"||Tt==="`")&&De!==Tt)throw new s("property names with quotes must have matching quotes");if((We==="constructor"||!_t)&&(he=!0),W+="."+We,ye="%"+W+"%",R(K,ye))fe=K[ye];else if(fe!=null){if(!(We in fe)){if(!x)throw new a("base intrinsic for "+re+" exists, but the property is not available.");return}if(S&&Z+1>=P.length){var Xt=S(fe,We);_t=!!Xt,_t&&"get"in Xt&&!("originalValue"in Xt.get)?fe=Xt.get:fe=fe[We]}else _t=R(fe,We),fe=fe[We];_t&&!he&&(K[ye]=fe)}}return fe},Zc}var Xc,Qh;function Ai(){if(Qh)return Xc;Qh=1;var e=Tb(),t=Bl(),r=t([e("%String.prototype.indexOf%")]);return Xc=function(i,o){var s=e(i,!!o);return typeof s=="function"&&r(i,".prototype.")>-1?t([s]):s},Xc}var Jc,ep;function dA(){if(ep)return Jc;ep=1;var e=Function.prototype.toString,t=typeof Reflect=="object"&&Reflect!==null&&Reflect.apply,r,n;if(typeof t=="function"&&typeof Object.defineProperty=="function")try{r=Object.defineProperty({},"length",{get:function(){throw n}}),n={},t(function(){throw 42},null,r)}catch(S){S!==n&&(t=null)}else t=null;var i=/^\s*class\b/,o=function(E){try{var v=e.call(E);return i.test(v)}catch{return!1}},s=function(E){try{return o(E)?!1:(e.call(E),!0)}catch{return!1}},a=Object.prototype.toString,c="[object Object]",f="[object Function]",u="[object GeneratorFunction]",l="[object HTMLAllCollection]",p="[object HTML document.all class]",h="[object HTMLCollection]",m=typeof Symbol=="function"&&!!Symbol.toStringTag,b=!(0 in[,]),w=function(){return!1};if(typeof document=="object"){var _=document.all;a.call(_)===a.call(document.all)&&(w=function(E){if((b||!E)&&(typeof E>"u"||typeof E=="object"))try{var v=a.call(E);return(v===l||v===p||v===h||v===c)&&E("")==null}catch{}return!1})}return Jc=t?function(E){if(w(E))return!0;if(!E||typeof E!="function"&&typeof E!="object")return!1;try{t(E,null,r)}catch(v){if(v!==n)return!1}return!o(E)&&s(E)}:function(E){if(w(E))return!0;if(!E||typeof E!="function"&&typeof E!="object")return!1;if(m)return s(E);if(o(E))return!1;var v=a.call(E);return v!==f&&v!==u&&!/^\[object HTML/.test(v)?!1:s(E)},Jc}var Qc,tp;function hA(){if(tp)return Qc;tp=1;var e=dA(),t=Object.prototype.toString,r=Object.prototype.hasOwnProperty,n=function(c,f,u){for(var l=0,p=c.length;l<p;l++)r.call(c,l)&&(u==null?f(c[l],l,c):f.call(u,c[l],l,c))},i=function(c,f,u){for(var l=0,p=c.length;l<p;l++)u==null?f(c.charAt(l),l,c):f.call(u,c.charAt(l),l,c)},o=function(c,f,u){for(var l in c)r.call(c,l)&&(u==null?f(c[l],l,c):f.call(u,c[l],l,c))};function s(a){return t.call(a)==="[object Array]"}return Qc=function(c,f,u){if(!e(f))throw new TypeError("iterator must be a function");var l;arguments.length>=3&&(l=u),s(c)?n(c,f,l):typeof c=="string"?i(c,f,l):o(c,f,l)},Qc}var eu,rp;function pA(){return rp||(rp=1,eu=["Float16Array","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array"]),eu}var tu,np;function yA(){if(np)return tu;np=1;var e=pA(),t=typeof globalThis>"u"?Ge:globalThis;return tu=function(){for(var n=[],i=0;i<e.length;i++)typeof t[e[i]]=="function"&&(n[n.length]=e[i]);return n},tu}var ru={exports:{}},nu,ip;function mA(){if(ip)return nu;ip=1;var e=_a(),t=_b(),r=Ei(),n=xi();return nu=function(o,s,a){if(!o||typeof o!="object"&&typeof o!="function")throw new r("`obj` must be an object or a function`");if(typeof s!="string"&&typeof s!="symbol")throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new r("`loose`, if provided, must be a boolean");var c=arguments.length>3?arguments[3]:null,f=arguments.length>4?arguments[4]:null,u=arguments.length>5?arguments[5]:null,l=arguments.length>6?arguments[6]:!1,p=!!n&&n(o,s);if(e)e(o,s,{configurable:u===null&&p?p.configurable:!u,enumerable:c===null&&p?p.enumerable:!c,value:a,writable:f===null&&p?p.writable:!f});else if(l||!c&&!f&&!u)o[s]=a;else throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},nu}var iu,op;function bA(){if(op)return iu;op=1;var e=_a(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return e([],"length",{value:1}).length!==1}catch{return!0}},iu=t,iu}var ou,sp;function gA(){if(sp)return ou;sp=1;var e=Tb(),t=mA(),r=bA()(),n=xi(),i=Ei(),o=e("%Math.floor%");return ou=function(a,c){if(typeof a!="function")throw new i("`fn` is not a function");if(typeof c!="number"||c<0||c>4294967295||o(c)!==c)throw new i("`length` must be a positive 32-bit integer");var f=arguments.length>2&&!!arguments[2],u=!0,l=!0;if("length"in a&&n){var p=n(a,"length");p&&!p.configurable&&(u=!1),p&&!p.writable&&(l=!1)}return(u||l||!f)&&(r?t(a,"length",c,!0,!0):t(a,"length",c)),a},ou}var su,ap;function wA(){if(ap)return su;ap=1;var e=Do(),t=Tl(),r=Sb();return su=function(){return r(e,t,arguments)},su}var cp;function vA(){return cp||(cp=1,function(e){var t=gA(),r=_a(),n=Bl(),i=wA();e.exports=function(s){var a=n(arguments),c=s.length-(arguments.length-1);return t(a,1+(c>0?c:0),!0)},r?r(e.exports,"apply",{value:i}):e.exports.apply=i}(ru)),ru.exports}var au,up;function Ea(){if(up)return au;up=1;var e=Eb();return au=function(){return e()&&!!Symbol.toStringTag},au}var cu,fp;function Bb(){if(fp)return cu;fp=1;var e=hA(),t=yA(),r=vA(),n=Ai(),i=xi(),o=Il(),s=n("Object.prototype.toString"),a=Ea()(),c=typeof globalThis>"u"?Ge:globalThis,f=t(),u=n("String.prototype.slice"),l=n("Array.prototype.indexOf",!0)||function(w,_){for(var S=0;S<w.length;S+=1)if(w[S]===_)return S;return-1},p={__proto__:null};a&&i&&o?e(f,function(b){var w=new c[b];if(Symbol.toStringTag in w&&o){var _=o(w),S=i(_,Symbol.toStringTag);if(!S&&_){var E=o(_);S=i(E,Symbol.toStringTag)}p["$"+b]=r(S.get)}}):e(f,function(b){var w=new c[b],_=w.slice||w.set;_&&(p["$"+b]=r(_))});var h=function(w){var _=!1;return e(p,function(S,E){if(!_)try{"$"+S(w)===E&&(_=u(E,1))}catch{}}),_},m=function(w){var _=!1;return e(p,function(S,E){if(!_)try{S(w),_=u(E,1)}catch{}}),_};return cu=function(w){if(!w||typeof w!="object")return!1;if(!a){var _=u(s(w),8,-1);return l(f,_)>-1?_:_!=="Object"?!1:m(w)}return i?h(w):null},cu}var uu,lp;function Ib(){if(lp)return uu;lp=1;var e=Bb();return uu=function(r){return!!e(r)},uu}var _A=Ei(),EA=Ai(),xA=EA("TypedArray.prototype.buffer",!0),AA=Ib(),SA=xA||function(t){if(!AA(t))throw new _A("Not a Typed Array");return t.buffer},ar=st.Buffer,PA=W8,TA=SA,BA=ArrayBuffer.isView||function(t){try{return TA(t),!0}catch{return!1}},IA=typeof Uint8Array<"u",kb=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",kA=kb&&(ar.prototype instanceof Uint8Array||ar.TYPED_ARRAY_SUPPORT),OA=function(t,r){if(t instanceof ar)return t;if(typeof t=="string")return ar.from(t,r);if(kb&&BA(t)){if(t.byteLength===0)return ar.alloc(0);if(kA){var n=ar.from(t.buffer,t.byteOffset,t.byteLength);if(n.byteLength===t.byteLength)return n}var i=t instanceof Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),o=ar.from(i);if(o.length===t.byteLength)return o}if(IA&&t instanceof Uint8Array)return ar.from(t);var s=PA(t);if(s)for(var a=0;a<t.length;a+=1){var c=t[a];if(typeof c!="number"||c<0||c>255||~~c!==c)throw new RangeError("Array items must be numbers in the range 0-255.")}if(s||ar.isBuffer(t)&&t.constructor&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t))return ar.from(t);throw new TypeError('The "data" argument must be a string, an Array, a Buffer, a Uint8Array, or a DataView.')},RA=st.Buffer,CA=OA;function xa(e,t){this._block=RA.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}xa.prototype.update=function(e,t){e=CA(e,t||"utf8");for(var r=this._block,n=this._blockSize,i=e.length,o=this._len,s=0;s<i;){for(var a=o%n,c=Math.min(i-s,n-a),f=0;f<c;f++)r[a+f]=e[s+f];o+=c,s+=c,o%n===0&&this._update(r)}return this._len+=i,this};xa.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=this._len*8;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(r&4294967295)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o};xa.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Si=xa,NA=Ve,Ob=Si,$A=st.Buffer,FA=[1518500249,1859775393,-1894007588,-899497514],UA=new Array(80);function jo(){this.init(),this._w=UA,Ob.call(this,64,56)}NA(jo,Ob);jo.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function LA(e){return e<<5|e>>>27}function MA(e){return e<<30|e>>>2}function HA(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}jo.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=t[a-3]^t[a-8]^t[a-14]^t[a-16];for(var c=0;c<80;++c){var f=~~(c/20),u=LA(r)+HA(f,n,i,o)+s+t[c]+FA[f]|0;s=o,o=i,i=MA(n),n=r,r=u}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=s+this._e|0};jo.prototype._hash=function(){var e=$A.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 DA=jo,jA=Ve,Rb=Si,qA=st.Buffer,zA=[1518500249,1859775393,-1894007588,-899497514],GA=new Array(80);function qo(){this.init(),this._w=GA,Rb.call(this,64,56)}jA(qo,Rb);qo.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function VA(e){return e<<1|e>>>31}function WA(e){return e<<5|e>>>27}function KA(e){return e<<30|e>>>2}function YA(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}qo.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=this._e|0,a=0;a<16;++a)t[a]=e.readInt32BE(a*4);for(;a<80;++a)t[a]=VA(t[a-3]^t[a-8]^t[a-14]^t[a-16]);for(var c=0;c<80;++c){var f=~~(c/20),u=WA(r)+YA(f,n,i,o)+s+t[c]+zA[f]|0;s=o,o=i,i=KA(n),n=r,r=u}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=s+this._e|0};qo.prototype._hash=function(){var e=qA.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 ZA=qo,XA=Ve,Cb=Si,JA=st.Buffer,QA=[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],e3=new Array(64);function zo(){this.init(),this._w=e3,Cb.call(this,64,56)}XA(zo,Cb);zo.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 t3(e,t,r){return r^e&(t^r)}function r3(e,t,r){return e&t|r&(e|t)}function n3(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function i3(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function o3(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function s3(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}zo.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,s=this._e|0,a=this._f|0,c=this._g|0,f=this._h|0,u=0;u<16;++u)t[u]=e.readInt32BE(u*4);for(;u<64;++u)t[u]=s3(t[u-2])+t[u-7]+o3(t[u-15])+t[u-16]|0;for(var l=0;l<64;++l){var p=f+i3(s)+t3(s,a,c)+QA[l]+t[l]|0,h=n3(r)+r3(r,n,i)|0;f=c,c=a,a=s,s=o+p|0,o=i,i=n,n=r,r=p+h|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=s+this._e|0,this._f=a+this._f|0,this._g=c+this._g|0,this._h=f+this._h|0};zo.prototype._hash=function(){var e=JA.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 Nb=zo,a3=Ve,c3=Nb,u3=Si,f3=st.Buffer,l3=new Array(64);function Aa(){this.init(),this._w=l3,u3.call(this,64,56)}a3(Aa,c3);Aa.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};Aa.prototype._hash=function(){var e=f3.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 d3=Aa,h3=Ve,$b=Si,p3=st.Buffer,dp=[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],y3=new Array(160);function Go(){this.init(),this._w=y3,$b.call(this,128,112)}h3(Go,$b);Go.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 hp(e,t,r){return r^e&(t^r)}function pp(e,t,r){return e&t|r&(e|t)}function yp(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function mp(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function m3(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function b3(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function g3(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function w3(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}Go.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,o=this._dh|0,s=this._eh|0,a=this._fh|0,c=this._gh|0,f=this._hh|0,u=this._al|0,l=this._bl|0,p=this._cl|0,h=this._dl|0,m=this._el|0,b=this._fl|0,w=this._gl|0,_=this._hl|0,S=0;S<32;S+=2)t[S]=e.readInt32BE(S*4),t[S+1]=e.readInt32BE(S*4+4);for(;S<160;S+=2){var E=t[S-30],v=t[S-15*2+1],B=m3(E,v),I=b3(v,E);E=t[S-2*2],v=t[S-2*2+1];var N=g3(E,v),M=w3(v,E),A=t[S-7*2],H=t[S-7*2+1],F=t[S-16*2],D=t[S-16*2+1],G=I+H|0,K=B+A+je(G,I)|0;G=G+M|0,K=K+N+je(G,M)|0,G=G+D|0,K=K+F+je(G,D)|0,t[S]=K,t[S+1]=G}for(var te=0;te<160;te+=2){K=t[te],G=t[te+1];var se=pp(r,n,i),ae=pp(u,l,p),V=yp(r,u),R=yp(u,r),Y=mp(s,m),Q=mp(m,s),O=dp[te],L=dp[te+1],z=hp(s,a,c),oe=hp(m,b,w),k=_+Q|0,C=f+Y+je(k,_)|0;k=k+oe|0,C=C+z+je(k,oe)|0,k=k+L|0,C=C+O+je(k,L)|0,k=k+G|0,C=C+K+je(k,G)|0;var q=R+ae|0,ee=V+se+je(q,R)|0;f=c,_=w,c=a,w=b,a=s,b=m,m=h+k|0,s=o+C+je(m,h)|0,o=i,h=p,i=n,p=l,n=r,l=u,u=k+q|0,r=C+ee+je(u,k)|0}this._al=this._al+u|0,this._bl=this._bl+l|0,this._cl=this._cl+p|0,this._dl=this._dl+h|0,this._el=this._el+m|0,this._fl=this._fl+b|0,this._gl=this._gl+w|0,this._hl=this._hl+_|0,this._ah=this._ah+r+je(this._al,u)|0,this._bh=this._bh+n+je(this._bl,l)|0,this._ch=this._ch+i+je(this._cl,p)|0,this._dh=this._dh+o+je(this._dl,h)|0,this._eh=this._eh+s+je(this._el,m)|0,this._fh=this._fh+a+je(this._fl,b)|0,this._gh=this._gh+c+je(this._gl,w)|0,this._hh=this._hh+f+je(this._hl,_)|0};Go.prototype._hash=function(){var e=p3.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 Fb=Go,v3=Ve,_3=Fb,E3=Si,x3=st.Buffer,A3=new Array(160);function Sa(){this.init(),this._w=A3,E3.call(this,128,112)}v3(Sa,_3);Sa.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};Sa.prototype._hash=function(){var e=x3.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 S3=Sa;(function(e){e.exports=function(r){var n=r.toLowerCase(),i=e.exports[n];if(!i)throw new Error(n+" is not supported (we accept pull requests)");return new i},e.exports.sha=DA,e.exports.sha1=ZA,e.exports.sha224=d3,e.exports.sha256=Nb,e.exports.sha384=S3,e.exports.sha512=Fb})(wb);var P3=wb.exports,cr=st.Buffer,Ub=xl.Transform,T3=Bs.StringDecoder,B3=Ve;function Zt(e){Ub.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}B3(Zt,Ub);var I3=typeof Uint8Array<"u",k3=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(cr.prototype instanceof Uint8Array||cr.TYPED_ARRAY_SUPPORT);function O3(e,t){if(e instanceof cr)return e;if(typeof e=="string")return cr.from(e,t);if(k3&&ArrayBuffer.isView(e)){if(e.byteLength===0)return cr.alloc(0);var r=cr.from(e.buffer,e.byteOffset,e.byteLength);if(r.byteLength===e.byteLength)return r}if(I3&&e instanceof Uint8Array||cr.isBuffer(e)&&e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return cr.from(e);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}Zt.prototype.update=function(e,t,r){var n=O3(e,t),i=this._update(n);return this.hashMode?this:(r&&(i=this._toString(i,r)),i)};Zt.prototype.setAutoPadding=function(){};Zt.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Zt.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Zt.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Zt.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)}};Zt.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Zt.prototype._finalOrDigest=function(e){var t=this.__final()||cr.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Zt.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new T3(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 R3=Zt,C3=Ve,N3=M8,$3=G8,F3=P3,Lb=R3;function Pa(e){Lb.call(this,"digest"),this._hash=e}C3(Pa,Lb);Pa.prototype._update=function(e){this._hash.update(e)};Pa.prototype._final=function(){return this._hash.digest()};var U3=function(t){return t=t.toLowerCase(),t==="md5"?new N3:t==="rmd160"||t==="ripemd160"?new $3:new Pa(F3(t))},us=st.Buffer;function L3(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,a=e.charAt(0),c=Math.log(s)/Math.log(256),f=Math.log(256)/Math.log(s);function u(h){if((Array.isArray(h)||h instanceof Uint8Array)&&(h=us.from(h)),!us.isBuffer(h))throw new TypeError("Expected Buffer");if(h.length===0)return"";for(var m=0,b=0,w=0,_=h.length;w!==_&&h[w]===0;)w++,m++;for(var S=(_-w)*f+1>>>0,E=new Uint8Array(S);w!==_;){for(var v=h[w],B=0,I=S-1;(v!==0||B<b)&&I!==-1;I--,B++)v+=256*E[I]>>>0,E[I]=v%s>>>0,v=v/s>>>0;if(v!==0)throw new Error("Non-zero carry");b=B,w++}for(var N=S-b;N!==S&&E[N]===0;)N++;for(var M=a.repeat(m);N<S;++N)M+=e.charAt(E[N]);return M}function l(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return us.alloc(0);for(var m=0,b=0,w=0;h[m]===a;)b++,m++;for(var _=(h.length-m)*c+1>>>0,S=new Uint8Array(_);m<h.length;){var E=h.charCodeAt(m);if(E>255)return;var v=t[E];if(v===255)return;for(var B=0,I=_-1;(v!==0||B<w)&&I!==-1;I--,B++)v+=s*S[I]>>>0,S[I]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");w=B,m++}for(var N=_-w;N!==_&&S[N]===0;)N++;var M=us.allocUnsafe(b+(_-N));M.fill(0,0,b);for(var A=b;N!==_;)M[A++]=S[N++];return M}function p(h){var m=l(h);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:u,decodeUnsafe:l,decode:p}}var Mb=L3,M3=Mb,H3="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",D3=M3(H3),fu=D3,j3=st.Buffer,q3=function(e){function t(o){var s=e(o);return fu.encode(j3.concat([o,s],o.length+4))}function r(o){var s=o.slice(0,-4),a=o.slice(-4),c=e(s);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return s}function n(o){var s=fu.decodeUnsafe(o);if(s)return r(s)}function i(o){var s=fu.decode(o),a=r(s);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},bp=U3,z3=q3;function G3(e){var t=bp("sha256").update(e).digest();return bp("sha256").update(t).digest()}var V3=z3(G3),hf=V3;function Hb(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 pf(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 W3(e,t){return Hb(hf.decode(e),t)}function K3(e,t,r){return typeof e=="number"?hf.encode(pf(e,t,r)):hf.encode(pf(e.version,e.privateKey,e.compressed))}var Y3={decode:W3,decodeRaw:Hb,encode:K3,encodeRaw:pf},Ta={};Object.defineProperty(Ta,"__esModule",{value:!0});Ta.testEcc=void 0;const le=e=>Buffer.from(e,"hex");function Z3(e){Ae(e.isPoint(le("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(!e.isPoint(le("030000000000000000000000000000000000000000000000000000000000000005"))),Ae(e.isPrivate(le("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(e.isPrivate(le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),Ae(!e.isPrivate(le("0000000000000000000000000000000000000000000000000000000000000000"))),Ae(!e.isPrivate(le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),Ae(!e.isPrivate(le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),Ae(Buffer.from(e.privateAdd(le("0000000000000000000000000000000000000000000000000000000000000001"),le("0000000000000000000000000000000000000000000000000000000000000000"))).equals(le("0000000000000000000000000000000000000000000000000000000000000001"))),Ae(e.privateAdd(le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),le("0000000000000000000000000000000000000000000000000000000000000003"))===null),Ae(Buffer.from(e.privateAdd(le("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),le("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(le("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),Ae(Buffer.from(e.privateNegate(le("0000000000000000000000000000000000000000000000000000000000000001"))).equals(le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),Ae(Buffer.from(e.privateNegate(le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(le("0000000000000000000000000000000000000000000000000000000000000003"))),Ae(Buffer.from(e.privateNegate(le("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(le("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),Ae(Buffer.from(e.pointCompress(le("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(le("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(Buffer.from(e.pointCompress(le("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(le("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),Ae(Buffer.from(e.pointCompress(le("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(le("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(Buffer.from(e.pointCompress(le("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(le("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),Ae(Buffer.from(e.pointFromScalar(le("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(le("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),Ae(e.xOnlyPointAddTweak(le("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(le("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),le("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));Ae(Buffer.from(t.xOnlyPubkey).equals(le("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(le("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),le("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),Ae(Buffer.from(t.xOnlyPubkey).equals(le("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),Ae(Buffer.from(e.sign(le("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),le("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(le("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),Ae(e.verify(le("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),le("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),le("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&Ae(Buffer.from(e.signSchnorr(le("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),le("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),le("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(le("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&Ae(e.verifySchnorr(le("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),le("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),le("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}Ta.testEcc=Z3;function Ae(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(ai,"__esModule",{value:!0});ai.ECPairFactory=ai.networks=void 0;const yf=ci;ai.networks=yf;const ft=Km,X3=O5,gp=Y3,J3=Ta,lu=ft.typeforce.maybe(ft.typeforce.compile({compressed:ft.maybe(ft.Boolean),network:ft.maybe(ft.Network)})),Q3=e=>e.length===32?e:e.slice(1,33);function eS(e){(0,J3.testEcc)(e);function t(a){return e.isPoint(a)}function r(a,c){if(ft.typeforce(ft.Buffer256bit,a),!e.isPrivate(a))throw new TypeError("Private key not in range [1, n)");return ft.typeforce(lu,c),new s(a,void 0,c)}function n(a,c){return ft.typeforce(e.isPoint,a),ft.typeforce(lu,c),new s(void 0,a,c)}function i(a,c){const f=gp.decode(a),u=f.version;if(ft.Array(c)){if(c=c.filter(l=>u===l.wif).pop(),!c)throw new Error("Unknown network version")}else if(c=c||yf.bitcoin,u!==c.wif)throw new Error("Invalid network version");return r(f.privateKey,{compressed:f.compressed,network:c})}function o(a){ft.typeforce(lu,a),a===void 0&&(a={});const c=a.rng||X3;let f;do f=c(32),ft.typeforce(ft.Buffer256bit,f);while(!e.isPrivate(f));return r(f,a)}class s{constructor(c,f,u){Rn(this,"__D");Rn(this,"__Q");Rn(this,"compressed");Rn(this,"network");Rn(this,"lowR");this.__D=c,this.__Q=f,this.lowR=!1,u===void 0&&(u={}),this.compressed=u.compressed===void 0?!0:u.compressed,this.network=u.network||yf.bitcoin,f!==void 0&&(this.__Q=Buffer.from(e.pointCompress(f,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const c=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(c)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return gp.encode(this.network.wif,this.__D,this.compressed)}tweak(c){return this.privateKey?this.tweakFromPrivateKey(c):this.tweakFromPublicKey(c)}sign(c,f){if(!this.__D)throw new Error("Missing private key");if(f===void 0&&(f=this.lowR),f===!1)return Buffer.from(e.sign(c,this.__D));{let u=e.sign(c,this.__D);const l=Buffer.alloc(32,0);let p=0;for(;u[0]>127;)p++,l.writeUIntLE(p,0,6),u=e.sign(c,this.__D,l);return Buffer.from(u)}}signSchnorr(c){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(c,this.privateKey))}verify(c,f){return e.verify(c,this.publicKey,f)}verifySchnorr(c,f){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(c,this.publicKey.subarray(1,33),f)}tweakFromPublicKey(c){const f=Q3(this.publicKey),u=e.xOnlyPointAddTweak(f,c);if(!u||u.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const l=Buffer.from([u.parity===0?2:3]);return n(Buffer.concat([l,u.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(c){const u=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,l=e.privateAdd(u,c);if(!l)throw new Error("Invalid tweaked private key!");return r(Buffer.from(l),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:o}}ai.ECPairFactory=eS;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=ai;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}})})(Wm);const tS=A6(Wm);class So extends ce.EventBroker{get isInitialized(){return!!this.digestKey}constructor(t,r){super(),this.digestKey=t,this.walletClient=r}static fromDigestKey(t){return new So(U.trim0x(t))}static fromWalletClient(t){return new So(void 0,t)}async initialize(){if(this.digestKey)return U.Ok("Already initialized");const t=await this.deriveDigestKeyFromWalletClient();return t.error?U.Err(t.error):(this.emit("initialized",!0),U.Ok("Initialized"))}async deriveDigestKeyFromWalletClient(){if(!this.walletClient)return U.Err("No walletClient found");if(!this.walletClient.account)return U.Err("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return this.digestKey=U.trim0x(Di(t)),this.emit("initialized",!0),U.Ok(this.digestKey)}catch(t){return U.Err("Failed to initialize: "+t)}}async getDigestKey(){if(!this.digestKey&&!this.walletClient)return U.Err("No private key or wallet client found");if(!this.digestKey&&this.walletClient){const t=await this.deriveDigestKeyFromWalletClient();if(t.error)return U.Err(t.error)}return this.digestKey?U.Ok(this.digestKey):U.Err("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return U.Err(r.error);const n=Di(ce.with0x(r.val)),i=Di(n);return U.Ok({secret:n,secretHash:i})}async signMessage(t){if(!this.digestKey){const f=await this.getDigestKey();if(f.error)return U.Err(f.error);this.digestKey=f.val}const r=tS(hn),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),o=Di(i),s=Buffer.from(U.trim0x(this.digestKey),"hex");if(s.length!==32)return U.Err("Invalid private key length. Expected 32 bytes.");const c=r.fromPrivateKey(s).sign(Buffer.from(U.trim0x(o),"hex"));return U.Ok(c.toString("hex"))}}const wp=[{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"}],rS={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},nS={block:Vw({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Gs(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:zw({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:tv({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 iS(e,t){return aS(e)?sS(e):t_(e,t)}const oS={transaction:iS};function sS(e){cS(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:o,mint:s,to:a,value:c}=e,f=[t,n,a??"0x",s?nt(s):"0x",c?nt(c):"0x",i?nt(i):"0x",o?"0x1":"0x",r??"0x"];return Kt(["0x7e",Yr(f)])}function aS(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function cS(e){const{from:t,to:r}=e;if(t&&!He(t))throw new yt({address:t});if(r&&!He(r))throw new yt({address:r})}const fi={blockTime:2e3,contracts:rS,formatters:nS,serializers:oS},uS=Lt({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}}}),fS=Lt({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}),Mi=1,lS=Lt({...fi,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:{...fi.contracts,disputeGameFactory:{[Mi]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Mi]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Mi]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Mi]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Mi}),Hi=11155111,dS=Lt({...fi,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:{...fi.contracts,disputeGameFactory:{[Hi]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Hi]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Hi]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Hi]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Hi}),hS=Lt({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}),pS=Lt({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}),yS=Lt({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}),mS=1,bS=Lt({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:mS}),gS=Lt({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}}}),wS=Lt({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}),vS=Lt({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}),fs=1,_S=Lt({...fi,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:{...fi.contracts,multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:0},disputeGameFactory:{[fs]:{address:"0x2F12d621a16e2d3285929C9996f478508951dFe4"}},portal:{[fs]:{address:"0x0bd48f6B86a26D3a217d0Fa6FfE2B491B956A7a2"}},l1StandardBridge:{[fs]:{address:"0x81014F44b0a345033bB2b3B21C7a1A308B35fEeA"}}},sourceId:fs}),ES={...vS,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Db={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/"]}}},jb={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"]}}},qb={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"]}}},kl={ethereum:gS,arbitrum:uS,ethereum_sepolia:ES,arbitrum_sepolia:fS,ethereum_localnet:be.EthereumLocalnet,arbitrum_localnet:be.ArbitrumLocalnet,base_sepolia:dS,base:lS,bera_testnet:pS,citrea_testnet:yS,bera:hS,monad_testnet:wS,hyperliquid_testnet:jb,hyperliquid:qb,unichain:_S,corn:bS,botanix:Db},zb=async(e,t)=>{var i,o,s;const r=kl[e],n=await t.getChainId();if(r)try{if(r.id===n)return U.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const a=Wa({account:t.account,chain:r,transport:hd(t.transport)});return U.Ok({message:"Switched chain",walletClient:a})}catch(a){if(xS(a))if(a.code===4902)try{await t.addChain({chain:r});const c=Wa({account:t.account,chain:r,transport:hd(t.transport)});return U.Ok({message:"Added network",walletClient:c})}catch{return U.Err("Failed to add network")}else if((o=(i=a.body)==null?void 0:i.method)!=null&&o.includes("wallet_switchEthereumChain")||(s=a.message)!=null&&s.includes("wallet_switchEthereumChain")){const c=Wa({account:t.account,chain:r,transport:wy()});return U.Ok({message:"Added network",walletClient:c})}else return U.Err("Failed to switch network");else return U.Err("Failed to switch network")}else return U.Err("Chain not supported")},xS=e=>typeof e=="object"&&e!=null&&("code"in e||"message"in e||"body"in e),AS=[{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 Gb{constructor(t,r,n){this.url=new ce.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 ce.Err("No account found");if(this.wallet.account.address.toLowerCase()!==t.source_swap.initiator.toLowerCase())return ce.Err("Account address and order initiator mismatch");if(!be.isEVM(t.source_swap.chain))return ce.Err("Source chain is not an EVM chain");const r=await zb(t.source_swap.chain,this.wallet);if(r.error)return ce.Err(r.error);if(this.wallet=r.val.walletClient,!this.wallet.account)return ce.Err("No account found");const{create_order:n,source_swap:i}=t;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return ce.Err("Invalid order");const o=ce.with0x(n.secret_hash),s=BigInt(n.timelock),a=ce.with0x(i.redeemer),c=BigInt(i.amount),f=await this.getTokenAddress(t.source_swap.asset);return f.ok?be.isEvmNativeToken(t.source_swap.chain,f.val)?this._initiateOnNativeHTLC(o,s,c,a,t.source_swap.asset):this._initiateOnErc20HTLC(o,s,c,a,t.source_swap.asset,f.val,n.create_id):ce.Err(f.error)}async getTokenAddress(t){try{const n=await Ma({address:ce.with0x(t),abi:wp,client:this.wallet}).read.token();return ce.Ok(n)}catch(r){return ce.Err("Failed to get token address",String(r))}}async _initiateOnNativeHTLC(t,r,n,i,o){if(!this.wallet.account)return ce.Err("No account found");try{const a=await Ma({address:ce.with0x(o),abi:AS,client:this.wallet}).write.initiate([i,r,n,t],{account:this.wallet.account,chain:this.wallet.chain,value:n});return ce.Ok(a)}catch(s){return ce.Err("Failed to initiate on native HTLC",String(s))}}async _initiateOnErc20HTLC(t,r,n,i,o,s,a){if(!this.wallet.account)return ce.Err("No account found");try{const c=await this.auth.getAuthHeaders();if(c.error)return ce.Err(c.error);const f=Ma({address:ce.with0x(o),abi:wp,client:this.wallet}),u=await ce.checkAllowanceAndApprove(Number(n),s,o,this.wallet);if(u.error)return ce.Err(u.error);const l=await f.read.eip712Domain(),p=await this.wallet.signTypedData({account:this.wallet.account,domain:{name:l[1],version:l[2],chainId:Number(l[3]),verifyingContract:l[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}}),h={...c.val,"Content-Type":"application/json"},m=await U.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:a,signature:p,perform_on:"Source"}),headers:h});if(m.error)return ce.Err(m.error);const b=await ce.waitForTransactionReceipt(this.wallet,m.result);return b.val&&b.val.status==="success"?ce.Ok(m.result?m.result:"Initiate hash not found"):ce.Err("Init failed: Transaction receipt not successful")}catch(c){return console.log("init error :",c),ce.Err(String(c))}}async redeem(t,r){try{const n=await this.auth.getAuthHeaders();if(n.error)return ce.Err(n.error);const i=await U.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:U.trim0x(r),perform_on:"Destination"}),headers:{...n.val,"Content-Type":"application/json"}});if(i.error)return ce.Err(i.error);const o=kl[t.destination_swap.chain],a=await WE({chain:o,transport:wy()}).waitForTransactionReceipt({hash:i.result,confirmations:1,timeout:3e5});return a&&a.status==="success"?ce.Ok(i.result?i.result:"Redeem hash not found"):ce.Err("Redeem failed: Transaction receipt not successful")}catch(n){return ce.Err(String(n))}}async refund(){return ce.Err("Refund not supported")}}const Vb=[{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"}]}],Wb=async(e,t,r,n,i)=>{try{const o=await Os(e.address,t,r,i);if(o.error)return U.Err(o.error);if(o.val>=n)return U.Ok("Allowance already approved");const a=qe.cairo.uint256(BigInt(n)),c=await e.execute([{contractAddress:U.with0x(t),entrypoint:"approve",calldata:[U.with0x(r),a.low,a.high]}]);await i.waitForTransaction(c.transaction_hash,{retryInterval:3e3,successStates:[qe.TransactionExecutionStatus.SUCCEEDED]}),await ce.sleep(2e3);for(let f=0;f<20;f++){const u=await Os(e.address,t,r,i);if(u.error)return U.Err(u.error);if(u.val>=n)return U.Ok(c.transaction_hash);await ce.sleep(2e3)}return U.Err("Allowance not approved after transaction.")}catch(o){return U.Err(`Failed to check or approve allowance: ${o instanceof Error?o.message:String(o)}`)}},Os=async(e,t,r,n)=>{try{const o=await new qe.Contract(Vb,U.with0x(t),n).call("allowance",[U.with0x(e),U.with0x(r)]);return U.Ok(BigInt((o==null?void 0:o.toString())||"0"))}catch(i){return U.Err(`Failed to check allowance: ${i instanceof Error?i.message:String(i)}`)}},Kb=async(e,t,r,n,i)=>{const o=await Os(e,t,r,n);return o.error?U.Err(o.error):U.Ok(o.val>=i)},Yb=[{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"}]}],SS={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 Zb{constructor(t,r,n,i){this.url=t instanceof ce.Url?t:new ce.Url(t),this.account=r,this.starknetProvider=new qe.RpcProvider({nodeUrl:i||vo[n].nodeUrl}),this.chainId=vo[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 U.Err("No account address");const{create_order:r,source_swap:n}=t,{redeemer:i,amount:o}=n;if(!o||!i||!r.secret_hash||!r.timelock)return U.Err("Invalid order");try{const s=new qe.Contract(Yb,t.source_swap.asset,this.account),a=await(s==null?void 0:s.token()),c=qe.num.toHex(a),f=await Kb(this.account.address,c,n.asset,this.starknetProvider,BigInt(o));return f.error?U.Err(f.error):f.val?this.initiateRelay(t):this.approveAndInitiate(c,t)}catch(s){return U.Err(String(s))}}async approveAndInitiate(t,r){const{create_order:n,source_swap:i}=r,{redeemer:o,amount:s}=i,{secret_hash:a,timelock:c}=n,f=i.asset;try{const u=qe.cairo.uint256(BigInt(s)),l={contractAddress:U.with0x(t),entrypoint:"approve",calldata:[f,u.low,u.high]},p=qe.cairo.uint256(s),h={contractAddress:U.with0x(f),entrypoint:"initiate",calldata:[o,c.toString(),p.low.toString(),p.high.toString(),...ce.hexToU32Array(a)]},m=await this.account.execute([l,h]);return await this.starknetProvider.waitForTransaction(m.transaction_hash,{retryInterval:2e3,successStates:[qe.TransactionExecutionStatus.SUCCEEDED]}),U.Ok(m.transaction_hash)}catch(u){return U.Err(`Failed to approve and initiate: ${String(u)}`)}}async initiateRelay(t){const{create_order:r,source_swap:n}=t,{redeemer:i,amount:o}=n,a={domain:{name:"HTLC",version:qe.shortString.encodeShortString("1"),chainId:this.chainId,revision:qe.TypedDataRevision.ACTIVE},primaryType:"Initiate",types:SS,message:{redeemer:i,amount:qe.cairo.uint256(o),timelock:r.timelock,secretHash:ce.hexToU32Array(r.secret_hash)}};try{const c=await this.account.signMessage(a),f=m6(c);if(f.error)return U.Err(f.error);const u=await U.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:f.val,perform_on:"Source"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return u.error?U.Err(u.error):u.result?U.Ok(u.result):U.Err("Init: No result found")}catch(c){return U.Err(`Failed to initiate relayer: ${String(c)}`)}}async redeem(t,r){try{const n=await U.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t.create_order.create_id,secret:r,perform_on:"Destination"}),headers:{"Content-Type":"application/json"},retryCount:10,retryDelay:2e3});return n.error?U.Err(n.error):n.result?U.Ok(n.result):U.Err("Redeem: No result found")}catch(n){return U.Err(String(n))}}async refund(){return U.Err("Refund is taken care of by the relayer")}}const PS="2bag6xpshpvPe7SJ9nSDLHpxqhEAoHPGpEkjNSv7gxoF",TS={name:"solana_native_swaps",version:"0.3.0",spec:"0.1.0",description:"Created with Anchor"},BS=[{name:"initiate",discriminator:[5,63,123,113,153,75,148,14],accounts:[{name:"swap_account",writable:!0,pda:{seeds:[{kind:"const",value:[115,119,97,112,95,97,99,99,111,117,110,116]},{kind:"account",path:"initiator"},{kind:"arg",path:"secret_hash"}]}},{name:"initiator",docs:["Initiator must sign this transaction"],writable:!0,signer:!0},{name:"system_program",address:"11111111111111111111111111111111"}],args:[{name:"amount_lamports",type:"u64"},{name:"expires_in_slots",type:"u64"},{name:"redeemer",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]},{name:"instant_refund",discriminator:[211,202,103,41,183,147,59,251],accounts:[{name:"swap_account",writable:!0},{name:"initiator",writable:!0},{name:"redeemer",docs:["Redeemer must sign this transaction"],signer:!0}],args:[]},{name:"redeem",discriminator:[184,12,86,149,70,196,97,225],accounts:[{name:"swap_account",writable:!0},{name:"initiator",docs:["This is included here for the PDA rent refund using the `close` attribute above"],writable:!0},{name:"redeemer",writable:!0}],args:[{name:"secret",type:{array:["u8",32]}}]},{name:"refund",discriminator:[2,96,183,251,63,208,46,46],accounts:[{name:"swap_account",writable:!0},{name:"initiator",writable:!0}],args:[]}],IS=[{name:"SwapAccount",discriminator:[53,126,9,14,14,197,105,182]}],kS=[{name:"Initiated",discriminator:[6,108,212,91,67,60,207,221]},{name:"InstantRefunded",discriminator:[220,50,18,207,183,232,218,25]},{name:"Redeemed",discriminator:[14,29,183,71,31,165,107,38]},{name:"Refunded",discriminator:[35,103,149,246,196,123,221,99]}],OS=[{code:6e3,name:"InvalidInitiator",msg:"The provided initiator is not the original initiator of this swap account"},{code:6001,name:"InvalidRedeemer",msg:"The provided redeemer is not the original redeemer of this swap amount"},{code:6002,name:"InvalidSecret",msg:"The provided secret does not correspond to the secret hash in the swap account"},{code:6003,name:"RefundBeforeExpiry",msg:"Attempt to perform a refund before expiry time"}],RS=[{name:"Initiated",type:{kind:"struct",fields:[{name:"amount_lamports",type:"u64"},{name:"expires_in_slots",type:"u64"},{name:"initiator",type:"pubkey"},{name:"redeemer",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]}},{name:"InstantRefunded",type:{kind:"struct",fields:[{name:"initiator",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]}},{name:"Redeemed",type:{kind:"struct",fields:[{name:"initiator",type:"pubkey"},{name:"secret",type:{array:["u8",32]}}]}},{name:"Refunded",type:{kind:"struct",fields:[{name:"initiator",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]}},{name:"SwapAccount",type:{kind:"struct",fields:[{name:"amount_lamports",type:"u64"},{name:"expiry_slot",type:"u64"},{name:"initiator",type:"pubkey"},{name:"redeemer",type:"pubkey"},{name:"secret_hash",type:{array:["u8",32]}}]}}],mf={address:PS,metadata:TS,instructions:BS,accounts:IS,events:kS,errors:OS,types:RS};var xr={},li={};Object.defineProperty(li,"__esModule",{value:!0});li.decode=li.encode=void 0;const vp=Yt;function CS(e){return e.reduce((t,r)=>t+r.toString(16).padStart(2,"0"),"0x")}li.encode=CS;function NS(e){e.indexOf("0x")===0&&(e=e.substr(2)),e.length%2===1&&(e="0"+e);let t=e.match(/.{2}/g);return t===null?vp.Buffer.from([]):vp.Buffer.from(t.map(r=>parseInt(r,16)))}li.decode=NS;var di={},Wr={},du;Object.defineProperty(Wr,"__esModule",{value:!0});Wr.isVersionedTransaction=Wr.chunks=Wr.isBrowser=void 0;Wr.isBrowser=process.env.ANCHOR_BROWSER||typeof window<"u"&&!(!((du=window.process)===null||du===void 0)&&du.hasOwnProperty("type"));function $S(e,t){return Array.apply(0,new Array(Math.ceil(e.length/t))).map((r,n)=>e.slice(n*t,(n+1)*t))}Wr.chunks=$S;const FS=e=>"version"in e;Wr.isVersionedTransaction=FS;var hu={},pu={},yu,_p;function US(){if(_p)return yu;_p=1;var e=Ea()(),t=Ai(),r=t("Object.prototype.toString"),n=function(a){return e&&a&&typeof a=="object"&&Symbol.toStringTag in a?!1:r(a)==="[object Arguments]"},i=function(a){return n(a)?!0:a!==null&&typeof a=="object"&&"length"in a&&typeof a.length=="number"&&a.length>=0&&r(a)!=="[object Array]"&&"callee"in a&&r(a.callee)==="[object Function]"},o=function(){return n(arguments)}();return n.isLegacyArguments=i,yu=o?n:i,yu}var mu,Ep;function LS(){if(Ep)return mu;Ep=1;var e=Ai(),t=Ea()(),r=Pb(),n=xi(),i;if(t){var o=e("RegExp.prototype.exec"),s={},a=function(){throw s},c={toString:a,valueOf:a};typeof Symbol.toPrimitive=="symbol"&&(c[Symbol.toPrimitive]=a),i=function(p){if(!p||typeof p!="object")return!1;var h=n(p,"lastIndex"),m=h&&r(h,"value");if(!m)return!1;try{o(p,c)}catch(b){return b===s}}}else{var f=e("Object.prototype.toString"),u="[object RegExp]";i=function(p){return!p||typeof p!="object"&&typeof p!="function"?!1:f(p)===u}}return mu=i,mu}var bu,xp;function MS(){if(xp)return bu;xp=1;var e=Ai(),t=LS(),r=e("RegExp.prototype.exec"),n=Ei();return bu=function(o){if(!t(o))throw new n("`regex` must be a RegExp");return function(a){return r(o,a)!==null}},bu}var gu,Ap;function HS(){if(Ap)return gu;Ap=1;var e=Ai(),t=MS(),r=t(/^\s*(?:function)?\*/),n=Ea()(),i=Il(),o=e("Object.prototype.toString"),s=e("Function.prototype.toString"),a=function(){if(!n)return!1;try{return Function("return function*() {}")()}catch{}},c;return gu=function(u){if(typeof u!="function")return!1;if(r(s(u)))return!0;if(!n){var l=o(u);return l==="[object GeneratorFunction]"}if(!i)return!1;if(typeof c>"u"){var p=a();c=p?i(p):!1}return i(u)===c},gu}var Sp;function DS(){return Sp||(Sp=1,function(e){var t=US(),r=HS(),n=Bb(),i=Ib();function o(Z){return Z.call.bind(Z)}var s=typeof BigInt<"u",a=typeof Symbol<"u",c=o(Object.prototype.toString),f=o(Number.prototype.valueOf),u=o(String.prototype.valueOf),l=o(Boolean.prototype.valueOf);if(s)var p=o(BigInt.prototype.valueOf);if(a)var h=o(Symbol.prototype.valueOf);function m(Z,_t){if(typeof Z!="object")return!1;try{return _t(Z),!0}catch{return!1}}e.isArgumentsObject=t,e.isGeneratorFunction=r,e.isTypedArray=i;function b(Z){return typeof Promise<"u"&&Z instanceof Promise||Z!==null&&typeof Z=="object"&&typeof Z.then=="function"&&typeof Z.catch=="function"}e.isPromise=b;function w(Z){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?ArrayBuffer.isView(Z):i(Z)||L(Z)}e.isArrayBufferView=w;function _(Z){return n(Z)==="Uint8Array"}e.isUint8Array=_;function S(Z){return n(Z)==="Uint8ClampedArray"}e.isUint8ClampedArray=S;function E(Z){return n(Z)==="Uint16Array"}e.isUint16Array=E;function v(Z){return n(Z)==="Uint32Array"}e.isUint32Array=v;function B(Z){return n(Z)==="Int8Array"}e.isInt8Array=B;function I(Z){return n(Z)==="Int16Array"}e.isInt16Array=I;function N(Z){return n(Z)==="Int32Array"}e.isInt32Array=N;function M(Z){return n(Z)==="Float32Array"}e.isFloat32Array=M;function A(Z){return n(Z)==="Float64Array"}e.isFloat64Array=A;function H(Z){return n(Z)==="BigInt64Array"}e.isBigInt64Array=H;function F(Z){return n(Z)==="BigUint64Array"}e.isBigUint64Array=F;function D(Z){return c(Z)==="[object Map]"}D.working=typeof Map<"u"&&D(new Map);function G(Z){return typeof Map>"u"?!1:D.working?D(Z):Z instanceof Map}e.isMap=G;function K(Z){return c(Z)==="[object Set]"}K.working=typeof Set<"u"&&K(new Set);function te(Z){return typeof Set>"u"?!1:K.working?K(Z):Z instanceof Set}e.isSet=te;function se(Z){return c(Z)==="[object WeakMap]"}se.working=typeof WeakMap<"u"&&se(new WeakMap);function ae(Z){return typeof WeakMap>"u"?!1:se.working?se(Z):Z instanceof WeakMap}e.isWeakMap=ae;function V(Z){return c(Z)==="[object WeakSet]"}V.working=typeof WeakSet<"u"&&V(new WeakSet);function R(Z){return V(Z)}e.isWeakSet=R;function Y(Z){return c(Z)==="[object ArrayBuffer]"}Y.working=typeof ArrayBuffer<"u"&&Y(new ArrayBuffer);function Q(Z){return typeof ArrayBuffer>"u"?!1:Y.working?Y(Z):Z instanceof ArrayBuffer}e.isArrayBuffer=Q;function O(Z){return c(Z)==="[object DataView]"}O.working=typeof ArrayBuffer<"u"&&typeof DataView<"u"&&O(new DataView(new ArrayBuffer(1),0,1));function L(Z){return typeof DataView>"u"?!1:O.working?O(Z):Z instanceof DataView}e.isDataView=L;var z=typeof SharedArrayBuffer<"u"?SharedArrayBuffer:void 0;function oe(Z){return c(Z)==="[object SharedArrayBuffer]"}function k(Z){return typeof z>"u"?!1:(typeof oe.working>"u"&&(oe.working=oe(new z)),oe.working?oe(Z):Z instanceof z)}e.isSharedArrayBuffer=k;function C(Z){return c(Z)==="[object AsyncFunction]"}e.isAsyncFunction=C;function q(Z){return c(Z)==="[object Map Iterator]"}e.isMapIterator=q;function ee(Z){return c(Z)==="[object Set Iterator]"}e.isSetIterator=ee;function re(Z){return c(Z)==="[object Generator]"}e.isGeneratorObject=re;function x(Z){return c(Z)==="[object WebAssembly.Module]"}e.isWebAssemblyCompiledModule=x;function P(Z){return m(Z,f)}e.isNumberObject=P;function W(Z){return m(Z,u)}e.isStringObject=W;function ie(Z){return m(Z,l)}e.isBooleanObject=ie;function ye(Z){return s&&m(Z,p)}e.isBigIntObject=ye;function fe(Z){return a&&m(Z,h)}e.isSymbolObject=fe;function he(Z){return P(Z)||W(Z)||ie(Z)||ye(Z)||fe(Z)}e.isBoxedPrimitive=he;function mt(Z){return typeof Uint8Array<"u"&&(Q(Z)||k(Z))}e.isAnyArrayBuffer=mt,["isProxy","isExternal","isModuleNamespaceObject"].forEach(function(Z){Object.defineProperty(e,Z,{enumerable:!1,value:function(){throw new Error(Z+" is not supported in userland")}})})}(pu)),pu}var wu,Pp;function jS(){return Pp||(Pp=1,wu=function(t){return t&&typeof t=="object"&&typeof t.copy=="function"&&typeof t.fill=="function"&&typeof t.readUInt8=="function"}),wu}var Tp;function Xb(){return Tp||(Tp=1,function(e){var t=Object.getOwnPropertyDescriptors||function(L){for(var z=Object.keys(L),oe={},k=0;k<z.length;k++)oe[z[k]]=Object.getOwnPropertyDescriptor(L,z[k]);return oe},r=/%[sdj%]/g;e.format=function(O){if(!B(O)){for(var L=[],z=0;z<arguments.length;z++)L.push(s(arguments[z]));return L.join(" ")}for(var z=1,oe=arguments,k=oe.length,C=String(O).replace(r,function(ee){if(ee==="%%")return"%";if(z>=k)return ee;switch(ee){case"%s":return String(oe[z++]);case"%d":return Number(oe[z++]);case"%j":try{return JSON.stringify(oe[z++])}catch{return"[Circular]"}default:return ee}}),q=oe[z];z<k;q=oe[++z])S(q)||!A(q)?C+=" "+q:C+=" "+s(q);return C},e.deprecate=function(O,L){if(typeof process<"u"&&process.noDeprecation===!0)return O;if(typeof process>"u")return function(){return e.deprecate(O,L).apply(this,arguments)};var z=!1;function oe(){if(!z){if(process.throwDeprecation)throw new Error(L);process.traceDeprecation?console.trace(L):console.error(L),z=!0}return O.apply(this,arguments)}return oe};var n={},i=/^$/;if(process.env.NODE_DEBUG){var o=process.env.NODE_DEBUG;o=o.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".*").replace(/,/g,"$|^").toUpperCase(),i=new RegExp("^"+o+"$","i")}e.debuglog=function(O){if(O=O.toUpperCase(),!n[O])if(i.test(O)){var L=process.pid;n[O]=function(){var z=e.format.apply(e,arguments);console.error("%s %d: %s",O,L,z)}}else n[O]=function(){};return n[O]};function s(O,L){var z={seen:[],stylize:c};return arguments.length>=3&&(z.depth=arguments[2]),arguments.length>=4&&(z.colors=arguments[3]),_(L)?z.showHidden=L:L&&e._extend(z,L),N(z.showHidden)&&(z.showHidden=!1),N(z.depth)&&(z.depth=2),N(z.colors)&&(z.colors=!1),N(z.customInspect)&&(z.customInspect=!0),z.colors&&(z.stylize=a),u(z,O,z.depth)}e.inspect=s,s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},s.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function a(O,L){var z=s.styles[L];return z?"\x1B["+s.colors[z][0]+"m"+O+"\x1B["+s.colors[z][1]+"m":O}function c(O,L){return O}function f(O){var L={};return O.forEach(function(z,oe){L[z]=!0}),L}function u(O,L,z){if(O.customInspect&&L&&D(L.inspect)&&L.inspect!==e.inspect&&!(L.constructor&&L.constructor.prototype===L)){var oe=L.inspect(z,O);return B(oe)||(oe=u(O,oe,z)),oe}var k=l(O,L);if(k)return k;var C=Object.keys(L),q=f(C);if(O.showHidden&&(C=Object.getOwnPropertyNames(L)),F(L)&&(C.indexOf("message")>=0||C.indexOf("description")>=0))return p(L);if(C.length===0){if(D(L)){var ee=L.name?": "+L.name:"";return O.stylize("[Function"+ee+"]","special")}if(M(L))return O.stylize(RegExp.prototype.toString.call(L),"regexp");if(H(L))return O.stylize(Date.prototype.toString.call(L),"date");if(F(L))return p(L)}var re="",x=!1,P=["{","}"];if(w(L)&&(x=!0,P=["[","]"]),D(L)){var W=L.name?": "+L.name:"";re=" [Function"+W+"]"}if(M(L)&&(re=" "+RegExp.prototype.toString.call(L)),H(L)&&(re=" "+Date.prototype.toUTCString.call(L)),F(L)&&(re=" "+p(L)),C.length===0&&(!x||L.length==0))return P[0]+re+P[1];if(z<0)return M(L)?O.stylize(RegExp.prototype.toString.call(L),"regexp"):O.stylize("[Object]","special");O.seen.push(L);var ie;return x?ie=h(O,L,z,q,C):ie=C.map(function(ye){return m(O,L,z,q,ye,x)}),O.seen.pop(),b(ie,re,P)}function l(O,L){if(N(L))return O.stylize("undefined","undefined");if(B(L)){var z="'"+JSON.stringify(L).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return O.stylize(z,"string")}if(v(L))return O.stylize(""+L,"number");if(_(L))return O.stylize(""+L,"boolean");if(S(L))return O.stylize("null","null")}function p(O){return"["+Error.prototype.toString.call(O)+"]"}function h(O,L,z,oe,k){for(var C=[],q=0,ee=L.length;q<ee;++q)V(L,String(q))?C.push(m(O,L,z,oe,String(q),!0)):C.push("");return k.forEach(function(re){re.match(/^\d+$/)||C.push(m(O,L,z,oe,re,!0))}),C}function m(O,L,z,oe,k,C){var q,ee,re;if(re=Object.getOwnPropertyDescriptor(L,k)||{value:L[k]},re.get?re.set?ee=O.stylize("[Getter/Setter]","special"):ee=O.stylize("[Getter]","special"):re.set&&(ee=O.stylize("[Setter]","special")),V(oe,k)||(q="["+k+"]"),ee||(O.seen.indexOf(re.value)<0?(S(z)?ee=u(O,re.value,null):ee=u(O,re.value,z-1),ee.indexOf(`
|
|
76
|
-
`)>-1&&(C?ee=ee.split(`
|
|
77
|
-
`).map(function(x){return" "+x}).join(`
|
|
78
|
-
`).slice(2):ee=`
|
|
79
|
-
`+ee.split(`
|
|
80
|
-
`).map(function(x){return" "+x}).join(`
|
|
81
|
-
`))):ee=O.stylize("[Circular]","special")),N(q)){if(C&&k.match(/^\d+$/))return ee;q=JSON.stringify(""+k),q.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(q=q.slice(1,-1),q=O.stylize(q,"name")):(q=q.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),q=O.stylize(q,"string"))}return q+": "+ee}function b(O,L,z){var oe=O.reduce(function(k,C){return C.indexOf(`
|
|
82
|
-
`)>=0,k+C.replace(/\u001b\[\d\d?m/g,"").length+1},0);return oe>60?z[0]+(L===""?"":L+`
|
|
83
|
-
`)+" "+O.join(`,
|
|
84
|
-
`)+" "+z[1]:z[0]+L+" "+O.join(", ")+" "+z[1]}e.types=DS();function w(O){return Array.isArray(O)}e.isArray=w;function _(O){return typeof O=="boolean"}e.isBoolean=_;function S(O){return O===null}e.isNull=S;function E(O){return O==null}e.isNullOrUndefined=E;function v(O){return typeof O=="number"}e.isNumber=v;function B(O){return typeof O=="string"}e.isString=B;function I(O){return typeof O=="symbol"}e.isSymbol=I;function N(O){return O===void 0}e.isUndefined=N;function M(O){return A(O)&&K(O)==="[object RegExp]"}e.isRegExp=M,e.types.isRegExp=M;function A(O){return typeof O=="object"&&O!==null}e.isObject=A;function H(O){return A(O)&&K(O)==="[object Date]"}e.isDate=H,e.types.isDate=H;function F(O){return A(O)&&(K(O)==="[object Error]"||O instanceof Error)}e.isError=F,e.types.isNativeError=F;function D(O){return typeof O=="function"}e.isFunction=D;function G(O){return O===null||typeof O=="boolean"||typeof O=="number"||typeof O=="string"||typeof O=="symbol"||typeof O>"u"}e.isPrimitive=G,e.isBuffer=jS();function K(O){return Object.prototype.toString.call(O)}function te(O){return O<10?"0"+O.toString(10):O.toString(10)}var se=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function ae(){var O=new Date,L=[te(O.getHours()),te(O.getMinutes()),te(O.getSeconds())].join(":");return[O.getDate(),se[O.getMonth()],L].join(" ")}e.log=function(){console.log("%s - %s",ae(),e.format.apply(e,arguments))},e.inherits=Ve,e._extend=function(O,L){if(!L||!A(L))return O;for(var z=Object.keys(L),oe=z.length;oe--;)O[z[oe]]=L[z[oe]];return O};function V(O,L){return Object.prototype.hasOwnProperty.call(O,L)}var R=typeof Symbol<"u"?Symbol("util.promisify.custom"):void 0;e.promisify=function(L){if(typeof L!="function")throw new TypeError('The "original" argument must be of type Function');if(R&&L[R]){var z=L[R];if(typeof z!="function")throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(z,R,{value:z,enumerable:!1,writable:!1,configurable:!0}),z}function z(){for(var oe,k,C=new Promise(function(re,x){oe=re,k=x}),q=[],ee=0;ee<arguments.length;ee++)q.push(arguments[ee]);q.push(function(re,x){re?k(re):oe(x)});try{L.apply(this,q)}catch(re){k(re)}return C}return Object.setPrototypeOf(z,Object.getPrototypeOf(L)),R&&Object.defineProperty(z,R,{value:z,enumerable:!1,writable:!1,configurable:!0}),Object.defineProperties(z,t(L))},e.promisify.custom=R;function Y(O,L){if(!O){var z=new Error("Promise was rejected with a falsy value");z.reason=O,O=z}return L(O)}function Q(O){if(typeof O!="function")throw new TypeError('The "original" argument must be of type Function');function L(){for(var z=[],oe=0;oe<arguments.length;oe++)z.push(arguments[oe]);var k=z.pop();if(typeof k!="function")throw new TypeError("The last argument must be of type Function");var C=this,q=function(){return k.apply(C,arguments)};O.apply(this,z).then(function(ee){process.nextTick(q.bind(null,null,ee))},function(ee){process.nextTick(Y.bind(null,ee,q))})}return Object.setPrototypeOf(L,Object.getPrototypeOf(O)),Object.defineProperties(L,t(O)),L}e.callbackify=Q}(hu)),hu}Object.defineProperty(di,"__esModule",{value:!0});di.encode=di.decode=void 0;const Jb=Wr;function qS(e){return(Jb.isBrowser?new TextDecoder("utf-8"):new(Xb()).TextDecoder("utf-8")).decode(e)}di.decode=qS;function zS(e){return(Jb.isBrowser?new TextEncoder:new(Xb()).TextEncoder("utf-8")).encode(e)}di.encode=zS;var hi={},GS=Mb,VS="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",WS=GS(VS),KS=Ge&&Ge.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(hi,"__esModule",{value:!0});hi.decode=hi.encode=void 0;const Qb=KS(WS);function YS(e){return Qb.default.encode(e)}hi.encode=YS;function ZS(e){return Qb.default.decode(e)}hi.decode=ZS;var pi={};Object.defineProperty(pi,"__esModule",{value:!0});pi.decode=pi.encode=void 0;const XS=Yt;function JS(e){return e.toString("base64")}pi.encode=JS;function QS(e){return XS.Buffer.from(e,"base64")}pi.decode=QS;var e4=Ge&&Ge.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),t4=Ge&&Ge.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),Ba=Ge&&Ge.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&e4(t,e,r);return t4(t,e),t};Object.defineProperty(xr,"__esModule",{value:!0});xr.base64=xr.bs58=xr.utf8=Rs=xr.hex=void 0;var Rs=xr.hex=Ba(li);xr.utf8=Ba(di);xr.bs58=Ba(hi);xr.base64=Ba(pi);class qr{constructor(t,r,n,i,o){try{this.swapId=[...Rs.decode(t)],this.secretHash=[...Rs.decode(n)]}catch(s){throw new Error("Error decoding swapId or secretHash",{cause:s})}if(this.secretHash.length!=32||this.swapId.length!=32)throw new Error("swapId or secretHash must be exactly 32 bits in size");try{this.redeemer=new jt.web3.PublicKey(r)}catch(s){throw new Error("Error decoding redeemer. Ensure it is a valid base58 encoded",{cause:s})}try{this.amount=new jt.BN(i.toString(10),10),this.expiresIn=new jt.BN(o)}catch(s){throw new Error("Error decoding amount. Invalid value for amount",{cause:s})}if(!(Number.isInteger(o)&&o>0))throw new Error("expiresIn must be a positive integer.")}static from(t){let r;if(t.source_swap.chain.includes("solana"))r=t.source_swap;else if(t.destination_swap.chain.includes("solana"))r=t.destination_swap;else throw new Error("Expected source_swap or destination_swap to be one of 'solana', 'solana_localnet', 'solana_devnet'");const{swap_id:n,redeemer:i,secret_hash:o,timelock:s}=r,a=BigInt(r.amount);return new qr(n,i,o,a,s)}}function eg(e){let t;try{t=[...Rs.decode(e)]}catch(r){throw new Error("Error decoding secret. Ensure it is a hex string",{cause:r})}if(t.length!=32)throw new Error("Invalid Secret size. Expected 32 bytes, got "+t.length);return t}class tg{constructor(t,r,n,i){if(this.provider=t,this.url=r,!t)throw new Error("Provider is required");if(!r)throw new Error("Endpoint URL is required");if(!n)throw new Error("Relayer address is required");if(!i)throw new Error("Program address is required");try{this.relayer=new jt.web3.PublicKey(n)}catch(s){throw new Error("Error decoding relayer public key. Ensure it is base58 encoded.",{cause:s})}const o={...mf,metadata:{...mf.metadata??{}},address:i};try{this.program=new jt.Program(o,this.provider)}catch(s){throw new Error("Error creating Program instance. Ensure the IDL and provider are correct.",{cause:s})}}get htlcActorAddress(){if(!this.program.programId)throw new Error("No program found");return this.provider.publicKey.toBase58()}async sendViaRelayer(t,r){try{t.recentBlockhash=(await this.provider.connection.getLatestBlockhash()).blockhash,t.feePayer=this.relayer;const i=(await this.provider.wallet.signTransaction(t)).serialize({requireAllSignatures:!1}).toString("base64"),o={order_id:r,serialized_tx:i,perform_on:"source"},s=await U.Fetcher.post(this.url.endpoint("/spl-initiate"),{body:JSON.stringify(o),headers:{"Content-Type":"application/json"}});return s.error?U.Err(`Error from Relayer: ${s.error}`):s.result?U.Ok(s.result):U.Err("No result returned from relayer")}catch(n){return U.Err(`Failed to send transaction: ${n instanceof Error?n.message:String(n)}`)}}async initiateViaHTLC(t,r){if(!r)return U.Err("Order is required");try{const n=await this.provider.sendAndConfirm(t);return n?await Bd(this.provider.connection,n)?U.Ok(n):U.Err("HTLC: Failed to Initiate swap, confirmation timed out"):U.Err("Failed to initiate HTLC transaction")}catch(n){return U.Err(`Error initiating swap: ${n instanceof Error?n.message:String(n)}`)}}async initiate(t){const{redeemer:r,secretHash:n,amount:i,expiresIn:o}=qr.from(t),s=[Buffer.from("swap_account"),this.provider.publicKey.toBuffer(),Buffer.from(n)];this.swapAccount=jt.web3.PublicKey.findProgramAddressSync(s,this.program.programId)[0];try{const a=await this.program.methods.initiate(i,o,r,n).accounts({initiator:this.provider.publicKey}).transaction();return be.isSolanaNativeToken(t.source_swap.chain,t.source_swap.asset)?this.initiateViaHTLC(a,t):this.sendViaRelayer(a,t.create_order.create_id)}catch(a){return U.Err("Error initiating swap: ",a)}}async redeem(t,r){const{secretHash:n}=qr.from(t),i=[Buffer.from("swap_account"),this.provider.publicKey.toBuffer(),Buffer.from(n)];this.swapAccount=jt.web3.PublicKey.findProgramAddressSync(i,this.program.programId)[0];try{const o=eg(r),s={order_id:t.create_order.create_id,secret:Buffer.from(o).toString("hex"),perform_on:"destination"},a=await U.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify(s),headers:{"Content-Type":"application/json"}});if(a.error)return U.Err(`Redeem: Error from relayer: ${a.error}`);if(!a.result)return U.Err("Redeem: No transaction hash returned from relayer");const c=a.result;return await Bd(this.provider.connection,c)?U.Ok(c):U.Err("Redeem: Timed out waiting for confirmation")}catch(o){return console.error("Redeem: Caught exception:",o),U.Err(`Error redeeming: ${o instanceof Error?o.message:String(o)}`)}}async refund(){return U.Err("Refund is automatically handled by the relayer.")}}class Ol extends ce.EventBroker{constructor(t){super(),this.environment=ce.Environment.TESTNET,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.bitcoinRedeemCache=new P5;const{api:r,environment:n}=ef(t.environment);if(this.environment=n,this._api=r,typeof t.digestKey=="string"){const o=ce.DigestKey.from(t.digestKey);if(!o.ok)throw new Error(o.error);this._digestKey=o.val}else this._digestKey=t.digestKey;this._quote=t.quote??new Vm(this._api.quote),this._auth=t.auth??ce.Siwe.fromDigestKey(new ce.Url(this._api.auth),this._digestKey),this._orderbook=t.orderbook??new be.Orderbook(new ce.Url(this._api.orderbook)),this._evmHTLC=t.htlc.evm,this._starknetHTLC=t.htlc.starknet,this._solanaHTLC=t.htlc.solana,this._secretManager=t.secretManager??So.fromDigestKey(this._digestKey.digestKey),this.orderExecutorCache=new S5,this._blockNumberFetcher=t.blockNumberFetcher??new Gm(this._api.info,this.environment);const i=new cn.BitcoinProvider(p6(this.environment));this._btcWallet=cn.BitcoinWallet.fromPrivateKey(this._digestKey.digestKey,i)}static fromWallets(t){let r;if(typeof t.digestKey=="string"){const o=ce.DigestKey.from(t.digestKey);if(!o.ok)throw new Error(o.error);r=o.val}else r=t.digestKey;const{api:n}=ef(t.environment);if(!n)throw new Error("API not found, invalid environment "+t.environment);const i={evm:t.wallets.evm?new Gb(n.evmRelay,t.wallets.evm,ce.Siwe.fromDigestKey(new ce.Url(n.auth),r)):void 0,starknet:t.wallets.starknet?new Zb(n.starknetRelay,t.wallets.starknet,t.environment===ce.Environment.MAINNET?ce.Network.MAINNET:ce.Network.TESTNET):void 0,solana:t.wallets.solana?new tg(t.wallets.solana,new ce.Url(n.solanaRelay),t.environment===ce.Environment.MAINNET?Qu.mainnet:Qu.testnet,t.solanaProgramAddress?t.solanaProgramAddress:hm.mainnet):void 0};return new Ol({htlc:i,...t})}get evmHTLC(){return this._evmHTLC}get starknetHTLC(){return this._starknetHTLC}get solanaHTLC(){return this._solanaHTLC}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderbook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}get auth(){return this._auth}get digestKey(){return this._digestKey}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return U.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:o}=r.val,s=Date.now().toString(),a=await this._secretManager.generateSecret(s);if(a.error)return U.Err(a.error);const{strategyId:c,btcAddress:f}=t.additionalData,u={strategy_id:c,...f&&{bitcoin_optional_recipient:f}},l={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:s,timelock:o,secret_hash:U.trim0x(a.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:u,affiliate_fees:this.withDefaultAffiliateFees(t.affiliateFee)},p=await this._quote.getAttestedQuote(l);if(p.error)return U.Err(p.error);const h=await this._orderbook.createOrder(p.val,this._auth);if(h.error)return U.Err(h.error);const m=await this.pollOrder(h.val);return m.error?U.Err(m.error):U.Ok(m.val)}withDefaultAffiliateFees(t){return(t??[]).map(r=>({fee:r.fee,address:r.address,chain:r.chain??Td.chain,asset:r.asset??Td.asset}))}async validateAndFillParams(t){if(!t.additionalData.strategyId)return U.Err("StrategyId is required");if(!t.fromAsset||!t.toAsset)return U.Err("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return U.Err("Source and destination assets cannot be the same");if(be.isMainnet(t.fromAsset.chain)&&!be.isMainnet(t.toAsset.chain)||!be.isMainnet(t.fromAsset.chain)&&be.isMainnet(t.toAsset.chain))return U.Err("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return U.Err(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return U.Err(n.error);if(r<n)return U.Err("Send amount should be greater than receive amount");const i=be.getTimeLock(t.fromAsset.chain);if(!i)return U.Err("Unsupported chain for timelock");if((be.isBitcoin(t.fromAsset.chain)||be.isBitcoin(t.toAsset.chain))&&!t.additionalData.btcAddress)return U.Err("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const o=await this.getAddresses(t.fromAsset.chain);if(o.error)return U.Err(o.error);const s=await this.getAddresses(t.toAsset.chain);return s.error?U.Err(s.error):U.Ok({sendAddress:o.val,receiveAddress:s.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(be.getBlockchainType(t)){case be.BlockchainType.EVM:return this._evmHTLC?U.Ok(this._evmHTLC.htlcActorAddress):U.Err("Please provide evmHTLC when initializing garden");case be.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!d6(i)?U.Err("Invalid btc public key"):U.Ok(Hr(i))}case be.BlockchainType.Solana:return this._solanaHTLC?U.Ok(this._solanaHTLC.htlcActorAddress):U.Err("Please provide solanaHTLC when initializing garden");case be.BlockchainType.Starknet:return this._starknetHTLC?U.Ok(this._starknetHTLC.htlcActorAddress):U.Err("Please provide starknetHTLC when initializing garden");default:return U.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return U.Err("Invalid amount ",t);const r=new og(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?U.Err("Invalid amount ",t):U.Ok(r)}async pollOrder(t){let r=await this._orderbook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ce.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return U.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return U.Ok(r.val);r=await this._orderbook.getOrder(t,!0)}return U.Err(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this._orderbook.subscribeOrders(this._digestKey.userId,!0,t,async r=>{const n=await this.filterExpiredAndAssignStatus(r.data);if(this.emit("onPendingOrdersChanged",n.val),r.data.length!==0)for(let i=0;i<n.val.length;i++){const o=n.val[i],s=cl(o.status);if(be.isBitcoin(o.source_swap.chain)&&o.status===Se.InitiateDetected){const a=this._btcWallet;if(!a){this.emit("error",o,"BTC wallet not found");continue}await this.postRefundSACP(o,a)}switch(s){case Te.Redeem:{const a=await this._secretManager.generateSecret(o.create_order.nonce);if(a.error){this.emit("error",o,a.error);return}switch(be.getBlockchainType(o.destination_swap.chain)){case be.BlockchainType.EVM:{await this.evmRedeem(o,a.val.secret);break}case be.BlockchainType.Bitcoin:{const c=this.btcWallet;if(!c){this.emit("error",o,"BTC wallet not found");return}await this.btcRedeem(c,o,a.val.secret);break}case be.BlockchainType.Starknet:{await this.starknetRedeem(o,a.val.secret);break}case be.BlockchainType.Solana:await this.solRedeem(o,a.val.secret);break;default:this.emit("error",o,"Unsupported chain: "+o.destination_swap.chain)}break}case Te.Refund:{switch(be.getBlockchainType(o.source_swap.chain)){case be.BlockchainType.Solana:{this.emit("error",o,"Solana refund is automatically done by relay service");break}case be.BlockchainType.EVM:{this.emit("error",o,"EVM refund is automatically done by relay service");break}case be.BlockchainType.Bitcoin:{const a=this.btcWallet;if(!a){this.emit("error",o,"BTC wallet not found");return}await this.btcRefund(a,o);break}case be.BlockchainType.Starknet:{this.emit("error",o,"Starknet refund is automatically done by relay service");break}default:this.emit("error",o,"Unsupported chain: "+o.source_swap.chain)}break}}}},"pending",{per_page:500})}async solRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing sol redeem"),this.orderExecutorCache.get(t,Te.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}if(!this._solanaHTLC){this.emit("error",t,"Solana HTLC is required");return}const i=await this._solanaHTLC.redeem(t,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,Te.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Te.Redeem,i.val),this.emit("success",t,Te.Redeem,i.val))}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,Te.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}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,Te.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,Te.Redeem,i.val),this.emit("success",t,Te.Redeem,i.val)}async starknetRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing starknet redeem"),this.orderExecutorCache.get(t,Te.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,Te.Redeem,t.destination_swap.redeem_tx_hash);return}i.val&&(this.orderExecutorCache.set(t,Te.Redeem,i.val),this.emit("success",t,Te.Redeem,i.val))}async btcRedeem(t,r,n){var a,c;const i=this.bitcoinRedeemCache.get(r.create_order.create_id),o=(a=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:a.split(":").at(0);if(!o){this.emit("error",r,"Failed to get initiate_tx_hash");return}let s=!1;if(i)if(i.redeemedFromUTXO&&i.redeemedFromUTXO!==o)s=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else if(i.redeemedAt&&Date.now()-i.redeemedAt>1e3*60*15)this.emit("log",r.create_order.create_id,"redeem not confirmed in last 15 minutes"),s=!0;else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const f=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let u=!1;for(const l of f.vin)if(l.txid===o){u=!0;break}if(u){this.emit("log",r.create_order.create_id,"already a valid redeem");let l=0;try{const[p]=await(await t.getProvider()).getTransactionTimes([r.destination_swap.redeem_tx_hash]);p!==0&&(l=p)}catch{l=Date.now()}this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:o,redeemedAt:l,redeemTxHash:r.destination_swap.redeem_tx_hash});return}s=!0}catch(f){if(f.message.includes("Transaction not found"))s=!0;else{this.emit("error",r,"Failed to get redeem tx: "+f);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const u=await(await Yi.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Hr(r.destination_swap.initiator),Hr(r.destination_swap.redeemer),r.destination_swap.timelock,s?[o]:[])).getRedeemHex(U.trim0x(n),(c=r.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient),l=await this.broadcastRedeemTx(u,r.create_order.create_id);if(l.error||!l.val){this.emit("error",r,l.error||"Failed to broadcast redeem tx");return}s?(this.emit("log",r.create_order.create_id,"rbf: btc redeem success"),this.emit("rbf",r,l.val)):this.emit("success",r,Te.Redeem,l.val),this.bitcoinRedeemCache.set(r.create_order.create_id,{redeemedFromUTXO:o,redeemedAt:Date.now(),redeemTxHash:l.val})}catch(f){this.emit("error",r,"Failed btc redeem: "+f)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,Te.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const o=await(await Yi.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Hr(r.source_swap.initiator),Hr(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,Te.Refund,o),this.emit("success",r,Te.Refund,o)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await Yi.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,Hr(t.source_swap.initiator),Hr(t.source_swap.redeemer),t.source_swap.timelock),o=t.create_order.additional_data.bitcoin_optional_recipient;if(o)try{const s=await i.generateInstantRefundSACP(o);if(!this._api)return;const a=new ce.Url(this._api.orderbook).endpoint("orders/bitcoin/"+t.create_order.create_id+"/instant-refund");(await U.Fetcher.post(a,{headers:{"Content-Type":"application/json"},body:JSON.stringify({instant_refund_tx_bytes:s})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(s){this.emit("error",t,"Failed to generate and post SACP: "+s);return}}async filterExpiredAndAssignStatus(t){var i;if(t.length===0)return U.Ok([]);const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return U.Err(r.error);const n=[];for(let o=0;o<t.length;o++){const s=t[o];if(pm(s))continue;const a=s.source_swap.chain,c=s.destination_swap.chain,f=r==null?void 0:r.val[a],u=r==null?void 0:r.val[c];if(!f||!u){this.emit("error",s,"Error while fetching CurrentBlockNumbers");continue}const l=al(s,f,u);n.push({...s,status:l})}return U.Ok(n)}async broadcastRedeemTx(t,r){try{if(!this._api)return U.Err("API not found");const n=new ce.Url(this._api.evmRelay).endpoint("/bitcoin/redeem "),i=await this._auth.getAuthHeaders(),s=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...i.val},body:JSON.stringify({redeem_tx_bytes:t,order_id:r})})).json();return s.status==="Ok"&&s.result?U.Ok(s.result):U.Err(s.error)}catch(n){return U.Err("Failed to broadcast redeem tx: "+n)}}}class r4{constructor(t,r,n){this.callData=new qe.CallData(Vb),this.account=t,this.starknetProvider=new qe.RpcProvider({nodeUrl:r||(n?vo[n].nodeUrl:vo.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(Yb,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),o=qe.cairo.uint256(BigInt(t.source_swap.amount));try{const a=await Wb(this.account,i,t.source_swap.asset,BigInt(t.source_swap.amount),this.starknetProvider);if(a.error)return U.Err(a.error)}catch(a){return U.Err(`Allowance check failed: ${a}`)}const s=await this.account.execute({contractAddress:t.source_swap.asset,entrypoint:"initiate",calldata:[t.source_swap.redeemer,BigInt(t.source_swap.timelock),o.low,o.high,...ce.hexToU32Array(t.create_order.secret_hash)]});if(!s.transaction_hash)throw new Error("Failed to initiate HTLC transaction");return U.Ok(s.transaction_hash)}catch(r){return U.Err(`HTLC Initiation Error: ${r}`)}}async redeem(t,r){try{const n=await this.getHTLCContract(t,!0),i=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,o=await this.account.execute({contractAddress:n.address,entrypoint:"redeem",calldata:qe.CallData.compile({swap_id:i,secret:ce.hexToU32Array(r)})});return o.transaction_hash?U.Ok(o.transaction_hash):U.Err("Failed to redeem HTLC transaction")}catch{return U.Err("HTLC Redeem Error")}}async refund(t){try{const r=t.create_order.source_chain.includes("starknet")?t.source_swap.swap_id:t.destination_swap.swap_id,n=await this.getHTLCContract(t),i=await this.account.execute({contractAddress:n.address,entrypoint:"refund",calldata:{orderId:r}});return i.transaction_hash?U.Ok(i.transaction_hash):U.Err("Failed to refund HTLC transaction")}catch{return U.Err("HTLC Refund Error")}}}class n4{constructor(t){if(this.provider=t,!t)throw new Error("Provider is required");this.provider=t,this.program=new jt.Program(mf,t)}get htlcActorAddress(){if(!this.program.programId)throw new Error("No program found");return this.provider.publicKey.toBase58()}async initiate(t){if(!t)return U.Err("Order is required");try{const{redeemer:r,secretHash:n,amount:i,expiresIn:o}=qr.from(t),s=[Buffer.from("swap_account"),this.provider.publicKey.toBuffer(),Buffer.from(n)];this.swapAccount=jt.web3.PublicKey.findProgramAddressSync(s,this.program.programId)[0];const a=await this.program.methods.initiate(i,o,r,n).accounts({initiator:this.provider.publicKey}).transaction(),c=await this.provider.sendAndConfirm(a);return c?U.Ok(c):U.Err("Failed to initiate HTLC transaction")}catch(r){return U.Err(`Error initiating swap: ${r instanceof Error?r.message:String(r)}`)}}async redeem(t,r){if(!t)return U.Err("Order is required");if(!r)return U.Err("Secret is required");const{secretHash:n}=qr.from(t),i=[Buffer.from("swap_account"),this.provider.publicKey.toBuffer(),Buffer.from(n)];this.swapAccount=jt.web3.PublicKey.findProgramAddressSync(i,this.program.programId)[0];try{const{redeemer:o}=qr.from(t);if(!this.swapAccount)return U.Err("Swap account not initialized. Call initiate() first or provide swap ID.");const s=await this.program.methods.redeem(eg(r)).accounts({swapAccount:this.swapAccount,initiator:this.provider.publicKey,redeemer:o}).transaction(),a=await this.provider.sendAndConfirm(s);return a?U.Ok(a):U.Err("Failed to redeem HTLC transaction")}catch(o){return U.Err(`Error redeeming swap: ${o instanceof Error?o.message:String(o)}`)}}async refund(t){if(!t)return U.Err("Order is required");const{secretHash:r}=qr.from(t),n=[Buffer.from("swap_account"),Buffer.from(r)];this.swapAccount=jt.web3.PublicKey.findProgramAddressSync(n,this.program.programId)[0];try{if(console.log("Initiating refund for ::",t.source_swap.swap_id),!this.swapAccount)return U.Err("Swap account not initialized. Call initiate() first or provide swap ID.");const i=await this.program.methods.refund().accounts({swapAccount:this.swapAccount,initiator:this.provider.publicKey}).transaction(),o=await this.provider.sendAndConfirm(i);return o?U.Ok(o):U.Err("Failed to refund HTLC transaction")}catch(i){return U.Err(`Error refunding swap: ${i instanceof Error?i.message:String(i)}`)}}}exports.API=hs;exports.BaseError=X;exports.BlockNumberFetcher=Gm;exports.EvmRelay=Gb;exports.Garden=Ol;exports.HttpRequestError=Vn;exports.OrderActions=Te;exports.OrderStatus=Se;exports.ParseOrderStatus=al;exports.ParseSwapStatus=nf;exports.Quote=Vm;exports.STARKNET_CONFIG=vo;exports.SecretManager=So;exports.SolanaHTLC=n4;exports.SolanaRelay=tg;exports.SolanaRelayerAddress=Qu;exports.StarknetHTLC=r4;exports.StarknetRelay=Zb;exports.SwapStatus=Be;exports.botanixMainnet=Db;exports.call=No;exports.checkAllowance=Os;exports.checkAllowanceAndApprove=Wb;exports.concat=Et;exports.constructOrderPair=rf;exports.decodeErrorResult=b0;exports.encodeAbiParameters=Rr;exports.evmToViemChainMap=kl;exports.filterDeadlineExpiredOrders=g6;exports.getUrl=Hs;exports.hyperliquid=qb;exports.hyperliquidTestnet=jb;exports.isAddressEqual=Co;exports.isAllowanceSufficient=Kb;exports.isExpired=_o;exports.isHex=zt;exports.localBatchGatewayRequest=vy;exports.localBatchGatewayUrl=ea;exports.parseAction=b6;exports.parseActionFromStatus=cl;exports.resolveApiConfig=ef;exports.solanaProgramAddress=hm;exports.stringify=Ue;exports.switchOrAddNetwork=zb;exports.toXOnly=Hr;exports.validateBTCAddress=h6;
|