@omnity/ree-client-ts-sdk 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +2 -2
- package/dist/index.es.js +3 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -27,7 +27,7 @@ variant ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.displ
|
|
|
27
27
|
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(i=>r.set(i)),r}static accessor(t){const r=(this[zd]=this[zd]={accessors:{}}).accessors,i=this.prototype;function s(o){const c=to(o);r[c]||(BT(i,o),r[c]=!0)}return z.isArray(t)?t.forEach(s):s(t),this}};yn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);z.reduceDescriptors(yn.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});z.freezeMethods(yn);function zu(e,t){const n=this||pc,r=t||n,i=yn.from(r.headers);let s=r.data;return z.forEach(e,function(c){s=c.call(n,s,i.normalize(),t?t.status:void 0)}),i.normalize(),s}function zm(e){return!!(e&&e.__CANCEL__)}function js(e,t,n){ke.call(this,e??"canceled",ke.ERR_CANCELED,t,n),this.name="CanceledError"}z.inherits(js,ke,{__CANCEL__:!0});function Ym(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new ke("Request failed with status code "+n.status,[ke.ERR_BAD_REQUEST,ke.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function NT(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function kT(e,t){e=e||10;const n=new Array(e),r=new Array(e);let i=0,s=0,o;return t=t!==void 0?t:1e3,function(a){const u=Date.now(),f=r[s];o||(o=u),n[i]=a,r[i]=u;let l=s,d=0;for(;l!==i;)d+=n[l++],l=l%e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const y=f&&u-f;return y?Math.round(d*1e3/y):void 0}}function PT(e,t){let n=0,r=1e3/t,i,s;const o=(u,f=Date.now())=>{n=f,i=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const f=Date.now(),l=f-n;l>=r?o(u,f):(i=u,s||(s=setTimeout(()=>{s=null,o(i)},r-l)))},()=>i&&o(i)]}const _a=(e,t,n=3)=>{let r=0;const i=kT(50,250);return PT(s=>{const o=s.loaded,c=s.lengthComputable?s.total:void 0,a=o-r,u=i(a),f=o<=c;r=o;const l={loaded:o,total:c,progress:c?o/c:void 0,bytes:a,rate:u||void 0,estimated:u&&c&&f?(c-o)/u:void 0,event:s,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(l)},n)},Yd=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Zd=e=>(...t)=>z.asap(()=>e(...t)),RT=Dt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Dt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Dt.origin),Dt.navigator&&/(msie|trident)/i.test(Dt.navigator.userAgent)):()=>!0,UT=Dt.hasStandardBrowserEnv?{write(e,t,n,r,i,s){const o=[e+"="+encodeURIComponent(t)];z.isNumber(n)&&o.push("expires="+new Date(n).toGMTString()),z.isString(r)&&o.push("path="+r),z.isString(i)&&o.push("domain="+i),s===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function CT(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function HT(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Zm(e,t,n){let r=!CT(t);return e&&(r||n==!1)?HT(e,t):t}const Jd=e=>e instanceof yn?{...e}:e;function Gi(e,t){t=t||{};const n={};function r(u,f,l,d){return z.isPlainObject(u)&&z.isPlainObject(f)?z.merge.call({caseless:d},u,f):z.isPlainObject(f)?z.merge({},f):z.isArray(f)?f.slice():f}function i(u,f,l,d){if(z.isUndefined(f)){if(!z.isUndefined(u))return r(void 0,u,l,d)}else return r(u,f,l,d)}function s(u,f){if(!z.isUndefined(f))return r(void 0,f)}function o(u,f){if(z.isUndefined(f)){if(!z.isUndefined(u))return r(void 0,u)}else return r(void 0,f)}function c(u,f,l){if(l in t)return r(u,f);if(l in e)return r(void 0,u)}const a={url:s,method:s,data:s,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:c,headers:(u,f,l)=>i(Jd(u),Jd(f),l,!0)};return z.forEach(Object.keys({...e,...t}),function(f){const l=a[f]||i,d=l(e[f],t[f],f);z.isUndefined(d)&&l!==c||(n[f]=d)}),n}const Jm=e=>{const t=Gi({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:i,xsrfCookieName:s,headers:o,auth:c}=t;t.headers=o=yn.from(o),t.url=Gm(Zm(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&o.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let a;if(z.isFormData(n)){if(Dt.hasStandardBrowserEnv||Dt.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((a=o.getContentType())!==!1){const[u,...f]=a?a.split(";").map(l=>l.trim()).filter(Boolean):[];o.setContentType([u||"multipart/form-data",...f].join("; "))}}if(Dt.hasStandardBrowserEnv&&(r&&z.isFunction(r)&&(r=r(t)),r||r!==!1&&RT(t.url))){const u=i&&s&&UT.read(s);u&&o.set(i,u)}return t},FT=typeof XMLHttpRequest<"u",MT=FT&&function(e){return new Promise(function(n,r){const i=Jm(e);let s=i.data;const o=yn.from(i.headers).normalize();let{responseType:c,onUploadProgress:a,onDownloadProgress:u}=i,f,l,d,y,g;function m(){y&&y(),g&&g(),i.cancelToken&&i.cancelToken.unsubscribe(f),i.signal&&i.signal.removeEventListener("abort",f)}let E=new XMLHttpRequest;E.open(i.method.toUpperCase(),i.url,!0),E.timeout=i.timeout;function _(){if(!E)return;const w=yn.from("getAllResponseHeaders"in E&&E.getAllResponseHeaders()),O={data:!c||c==="text"||c==="json"?E.responseText:E.response,status:E.status,statusText:E.statusText,headers:w,config:e,request:E};Ym(function(R){n(R),m()},function(R){r(R),m()},O),E=null}"onloadend"in E?E.onloadend=_:E.onreadystatechange=function(){!E||E.readyState!==4||E.status===0&&!(E.responseURL&&E.responseURL.indexOf("file:")===0)||setTimeout(_)},E.onabort=function(){E&&(r(new ke("Request aborted",ke.ECONNABORTED,e,E)),E=null)},E.onerror=function(){r(new ke("Network Error",ke.ERR_NETWORK,e,E)),E=null},E.ontimeout=function(){let T=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const O=i.transitional||Wm;i.timeoutErrorMessage&&(T=i.timeoutErrorMessage),r(new ke(T,O.clarifyTimeoutError?ke.ETIMEDOUT:ke.ECONNABORTED,e,E)),E=null},s===void 0&&o.setContentType(null),"setRequestHeader"in E&&z.forEach(o.toJSON(),function(T,O){E.setRequestHeader(O,T)}),z.isUndefined(i.withCredentials)||(E.withCredentials=!!i.withCredentials),c&&c!=="json"&&(E.responseType=i.responseType),u&&([d,g]=_a(u,!0),E.addEventListener("progress",d)),a&&E.upload&&([l,y]=_a(a),E.upload.addEventListener("progress",l),E.upload.addEventListener("loadend",y)),(i.cancelToken||i.signal)&&(f=w=>{E&&(r(!w||w.type?new js(null,e,E):w),E.abort(),E=null)},i.cancelToken&&i.cancelToken.subscribe(f),i.signal&&(i.signal.aborted?f():i.signal.addEventListener("abort",f)));const S=NT(i.url);if(S&&Dt.protocols.indexOf(S)===-1){r(new ke("Unsupported protocol "+S+":",ke.ERR_BAD_REQUEST,e));return}E.send(s||null)})},qT=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,i;const s=function(u){if(!i){i=!0,c();const f=u instanceof Error?u:this.reason;r.abort(f instanceof ke?f:new js(f instanceof Error?f.message:f))}};let o=t&&setTimeout(()=>{o=null,s(new ke(`timeout ${t} of ms exceeded`,ke.ETIMEDOUT))},t);const c=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:a}=r;return a.unsubscribe=()=>z.asap(c),a}},VT=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,i;for(;r<n;)i=r+t,yield e.slice(r,i),r=i},LT=async function*(e,t){for await(const n of $T(e))yield*VT(n,t)},$T=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Qd=(e,t,n,r)=>{const i=LT(e,t);let s=0,o,c=a=>{o||(o=!0,r&&r(a))};return new ReadableStream({async pull(a){try{const{done:u,value:f}=await i.next();if(u){c(),a.close();return}let l=f.byteLength;if(n){let d=s+=l;n(d)}a.enqueue(new Uint8Array(f))}catch(u){throw c(u),u}},cancel(a){return c(a),i.return()}},{highWaterMark:2})},cu=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Qm=cu&&typeof ReadableStream=="function",DT=cu&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),ew=(e,...t)=>{try{return!!e(...t)}catch{return!1}},jT=Qm&&ew(()=>{let e=!1;const t=new Request(Dt.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),e0=64*1024,Qf=Qm&&ew(()=>z.isReadableStream(new Response("").body)),Sa={stream:Qf&&(e=>e.body)};cu&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!Sa[t]&&(Sa[t]=z.isFunction(e[t])?n=>n[t]():(n,r)=>{throw new ke(`Response type '${t}' is not supported`,ke.ERR_NOT_SUPPORT,r)})})})(new Response);const KT=async e=>{if(e==null)return 0;if(z.isBlob(e))return e.size;if(z.isSpecCompliantForm(e))return(await new Request(Dt.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(z.isArrayBufferView(e)||z.isArrayBuffer(e))return e.byteLength;if(z.isURLSearchParams(e)&&(e=e+""),z.isString(e))return(await DT(e)).byteLength},GT=async(e,t)=>{const n=z.toFiniteNumber(e.getContentLength());return n??KT(t)},WT=cu&&(async e=>{let{url:t,method:n,data:r,signal:i,cancelToken:s,timeout:o,onDownloadProgress:c,onUploadProgress:a,responseType:u,headers:f,withCredentials:l="same-origin",fetchOptions:d}=Jm(e);u=u?(u+"").toLowerCase():"text";let y=qT([i,s&&s.toAbortSignal()],o),g;const m=y&&y.unsubscribe&&(()=>{y.unsubscribe()});let E;try{if(a&&jT&&n!=="get"&&n!=="head"&&(E=await GT(f,r))!==0){let O=new Request(t,{method:"POST",body:r,duplex:"half"}),A;if(z.isFormData(r)&&(A=O.headers.get("content-type"))&&f.setContentType(A),O.body){const[R,M]=Yd(E,_a(Zd(a)));r=Qd(O.body,e0,R,M)}}z.isString(l)||(l=l?"include":"omit");const _="credentials"in Request.prototype;g=new Request(t,{...d,signal:y,method:n.toUpperCase(),headers:f.normalize().toJSON(),body:r,duplex:"half",credentials:_?l:void 0});let S=await fetch(g,d);const w=Qf&&(u==="stream"||u==="response");if(Qf&&(c||w&&m)){const O={};["status","statusText","headers"].forEach(v=>{O[v]=S[v]});const A=z.toFiniteNumber(S.headers.get("content-length")),[R,M]=c&&Yd(A,_a(Zd(c),!0))||[];S=new Response(Qd(S.body,e0,R,()=>{M&&M(),m&&m()}),O)}u=u||"text";let T=await Sa[z.findKey(Sa,u)||"text"](S,e);return!w&&m&&m(),await new Promise((O,A)=>{Ym(O,A,{data:T,headers:yn.from(S.headers),status:S.status,statusText:S.statusText,config:e,request:g})})}catch(_){throw m&&m(),_&&_.name==="TypeError"&&/Load failed|fetch/i.test(_.message)?Object.assign(new ke("Network Error",ke.ERR_NETWORK,e,g),{cause:_.cause||_}):ke.from(_,_&&_.code,e,g)}}),el={http:aT,xhr:MT,fetch:WT};z.forEach(el,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const t0=e=>`- ${e}`,XT=e=>z.isFunction(e)||e===null||e===!1,tw={getAdapter:e=>{e=z.isArray(e)?e:[e];const{length:t}=e;let n,r;const i={};for(let s=0;s<t;s++){n=e[s];let o;if(r=n,!XT(n)&&(r=el[(o=String(n)).toLowerCase()],r===void 0))throw new ke(`Unknown adapter '${o}'`);if(r)break;i[o||"#"+s]=r}if(!r){const s=Object.entries(i).map(([c,a])=>`adapter ${c} `+(a===!1?"is not supported by the environment":"is not available in the build"));let o=t?s.length>1?`since :
|
|
28
28
|
`+s.map(t0).join(`
|
|
29
29
|
`):" "+t0(s[0]):"as no adapter specified";throw new ke("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return r},adapters:el};function Yu(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new js(null,e)}function n0(e){return Yu(e),e.headers=yn.from(e.headers),e.data=zu.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),tw.getAdapter(e.adapter||pc.adapter)(e).then(function(r){return Yu(e),r.data=zu.call(e,e.transformResponse,r),r.headers=yn.from(r.headers),r},function(r){return zm(r)||(Yu(e),r&&r.response&&(r.response.data=zu.call(e,e.transformResponse,r.response),r.response.headers=yn.from(r.response.headers))),Promise.reject(r)})}const nw="1.11.0",au={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{au[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const r0={};au.transitional=function(t,n,r){function i(s,o){return"[Axios v"+nw+"] Transitional option '"+s+"'"+o+(r?". "+r:"")}return(s,o,c)=>{if(t===!1)throw new ke(i(o," has been removed"+(n?" in "+n:"")),ke.ERR_DEPRECATED);return n&&!r0[o]&&(r0[o]=!0,console.warn(i(o," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,o,c):!0}};au.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function zT(e,t,n){if(typeof e!="object")throw new ke("options must be an object",ke.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let i=r.length;for(;i-- >0;){const s=r[i],o=t[s];if(o){const c=e[s],a=c===void 0||o(c,s,e);if(a!==!0)throw new ke("option "+s+" must be "+a,ke.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new ke("Unknown option "+s,ke.ERR_BAD_OPTION)}}const ea={assertOptions:zT,validators:au},Yn=ea.validators;let Mi=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Xd,response:new Xd}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const s=i.stack?i.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
30
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Gi(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&ea.assertOptions(r,{silentJSONParsing:Yn.transitional(Yn.boolean),forcedJSONParsing:Yn.transitional(Yn.boolean),clarifyTimeoutError:Yn.transitional(Yn.boolean)},!1),i!=null&&(z.isFunction(i)?n.paramsSerializer={serialize:i}:ea.assertOptions(i,{encode:Yn.function,serialize:Yn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ea.assertOptions(n,{baseUrl:Yn.spelling("baseURL"),withXsrfToken:Yn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&z.merge(s.common,s[n.method]);s&&z.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=yn.concat(o,s);const c=[];let a=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(a=a&&m.synchronous,c.unshift(m.fulfilled,m.rejected))});const u=[];this.interceptors.response.forEach(function(m){u.push(m.fulfilled,m.rejected)});let f,l=0,d;if(!a){const g=[n0.bind(this),void 0];for(g.unshift(...c),g.push(...u),d=g.length,f=Promise.resolve(n);l<d;)f=f.then(g[l++],g[l++]);return f}d=c.length;let y=n;for(l=0;l<d;){const g=c[l++],m=c[l++];try{y=g(y)}catch(E){m.call(this,E);break}}try{f=n0.call(this,y)}catch(g){return Promise.reject(g)}for(l=0,d=u.length;l<d;)f=f.then(u[l++],u[l++]);return f}getUri(t){t=Gi(this.defaults,t);const n=Zm(t.baseURL,t.url,t.allowAbsoluteUrls);return Gm(n,t.params,t.paramsSerializer)}};z.forEach(["delete","get","head","options"],function(t){Mi.prototype[t]=function(n,r){return this.request(Gi(r||{},{method:t,url:n,data:(r||{}).data}))}});z.forEach(["post","put","patch"],function(t){function n(r){return function(s,o,c){return this.request(Gi(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Mi.prototype[t]=n(),Mi.prototype[t+"Form"]=n(!0)});let YT=class rw{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(c=>{r.subscribe(c),s=c}).then(i);return o.cancel=function(){r.unsubscribe(s)},o},t(function(s,o,c){r.reason||(r.reason=new js(s,o,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new rw(function(i){t=i}),cancel:t}}};function ZT(e){return function(n){return e.apply(null,n)}}function JT(e){return z.isObject(e)&&e.isAxiosError===!0}const tl={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(tl).forEach(([e,t])=>{tl[t]=e});function iw(e){const t=new Mi(e),n=Um(Mi.prototype.request,t);return z.extend(n,Mi.prototype,t,{allOwnKeys:!0}),z.extend(n,t,null,{allOwnKeys:!0}),n.create=function(i){return iw(Gi(e,i))},n}const ht=iw(pc);ht.Axios=Mi;ht.CanceledError=js;ht.CancelToken=YT;ht.isCancel=zm;ht.VERSION=nw;ht.toFormData=ou;ht.AxiosError=ke;ht.Cancel=ht.CanceledError;ht.all=function(t){return Promise.all(t)};ht.spread=ZT;ht.isAxiosError=JT;ht.mergeConfig=Gi;ht.AxiosHeaders=yn;ht.formToJSON=e=>Xm(z.isHTMLForm(e)?new FormData(e):e);ht.getAdapter=tw.getAdapter;ht.HttpStatusCode=tl;ht.default=ht;const{Axios:X6,AxiosError:z6,CanceledError:Y6,isCancel:Z6,CancelToken:J6,VERSION:Q6,all:eI,Cancel:tI,isAxiosError:nI,spread:rI,toFormData:iI,AxiosHeaders:sI,HttpStatusCode:oI,formToJSON:cI,getAdapter:aI,mergeConfig:uI}=ht;class QT{axios;constructor(t){this.axios=ht.create({baseURL:t.baseUrl,headers:{Accept:"application/json","Content-Type":"application/json","api-key":`${t.apiKey}`}})}async utxosByAddress(t,n,r=!0){return await this.axios.get(`/addresses/${t}/utxos?filter_dust=true&filter_dust_threshold=
|
|
30
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Gi(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&ea.assertOptions(r,{silentJSONParsing:Yn.transitional(Yn.boolean),forcedJSONParsing:Yn.transitional(Yn.boolean),clarifyTimeoutError:Yn.transitional(Yn.boolean)},!1),i!=null&&(z.isFunction(i)?n.paramsSerializer={serialize:i}:ea.assertOptions(i,{encode:Yn.function,serialize:Yn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ea.assertOptions(n,{baseUrl:Yn.spelling("baseURL"),withXsrfToken:Yn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&z.merge(s.common,s[n.method]);s&&z.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=yn.concat(o,s);const c=[];let a=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(a=a&&m.synchronous,c.unshift(m.fulfilled,m.rejected))});const u=[];this.interceptors.response.forEach(function(m){u.push(m.fulfilled,m.rejected)});let f,l=0,d;if(!a){const g=[n0.bind(this),void 0];for(g.unshift(...c),g.push(...u),d=g.length,f=Promise.resolve(n);l<d;)f=f.then(g[l++],g[l++]);return f}d=c.length;let y=n;for(l=0;l<d;){const g=c[l++],m=c[l++];try{y=g(y)}catch(E){m.call(this,E);break}}try{f=n0.call(this,y)}catch(g){return Promise.reject(g)}for(l=0,d=u.length;l<d;)f=f.then(u[l++],u[l++]);return f}getUri(t){t=Gi(this.defaults,t);const n=Zm(t.baseURL,t.url,t.allowAbsoluteUrls);return Gm(n,t.params,t.paramsSerializer)}};z.forEach(["delete","get","head","options"],function(t){Mi.prototype[t]=function(n,r){return this.request(Gi(r||{},{method:t,url:n,data:(r||{}).data}))}});z.forEach(["post","put","patch"],function(t){function n(r){return function(s,o,c){return this.request(Gi(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Mi.prototype[t]=n(),Mi.prototype[t+"Form"]=n(!0)});let YT=class rw{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(c=>{r.subscribe(c),s=c}).then(i);return o.cancel=function(){r.unsubscribe(s)},o},t(function(s,o,c){r.reason||(r.reason=new js(s,o,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new rw(function(i){t=i}),cancel:t}}};function ZT(e){return function(n){return e.apply(null,n)}}function JT(e){return z.isObject(e)&&e.isAxiosError===!0}const tl={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(tl).forEach(([e,t])=>{tl[t]=e});function iw(e){const t=new Mi(e),n=Um(Mi.prototype.request,t);return z.extend(n,Mi.prototype,t,{allOwnKeys:!0}),z.extend(n,t,null,{allOwnKeys:!0}),n.create=function(i){return iw(Gi(e,i))},n}const ht=iw(pc);ht.Axios=Mi;ht.CanceledError=js;ht.CancelToken=YT;ht.isCancel=zm;ht.VERSION=nw;ht.toFormData=ou;ht.AxiosError=ke;ht.Cancel=ht.CanceledError;ht.all=function(t){return Promise.all(t)};ht.spread=ZT;ht.isAxiosError=JT;ht.mergeConfig=Gi;ht.AxiosHeaders=yn;ht.formToJSON=e=>Xm(z.isHTMLForm(e)?new FormData(e):e);ht.getAdapter=tw.getAdapter;ht.HttpStatusCode=tl;ht.default=ht;const{Axios:X6,AxiosError:z6,CanceledError:Y6,isCancel:Z6,CancelToken:J6,VERSION:Q6,all:eI,Cancel:tI,isAxiosError:nI,spread:rI,toFormData:iI,AxiosHeaders:sI,HttpStatusCode:oI,formToJSON:cI,getAdapter:aI,mergeConfig:uI}=ht;class QT{axios;constructor(t){this.axios=ht.create({baseURL:t.baseUrl,headers:{Accept:"application/json","Content-Type":"application/json","api-key":`${t.apiKey}`}})}async utxosByAddress(t,n,r=!0){return await this.axios.get(`/addresses/${t}/utxos?filter_dust=true&filter_dust_threshold=330&exclude_metaprotocols=${r}&ignore_used_brc20=true&order=asc&count=100${n?`&cursor=${n}`:""}`).then(s=>s.data)}async utxosByAddressMempoolAware(t,n,r=!0){return await this.axios.get(`/mempool/addresses/${t}/utxos?filter_dust=true&exclude_metaprotocols=${r}&filter_dust_threshold=330&order=asc&count=100${n?`&cursor=${n}`:""}`).then(s=>s.data)}async inscriptionIdsByCollectionSymbol(t,n){return await this.axios.get(`/assets/collections/${t}/inscriptions?count=100${n?`&cursor=${n}`:""}`).then(i=>i.data)}async runeUtxosByAddress(t,n,r){return await this.axios.get(`/addresses/${t}/runes/utxos?order_by=height&order=asc&count=100&rune=${n}${r?`&cursor=${r}`:""}`).then(s=>s.data)}async runeInfo(t){return await this.axios.get(`/assets/runes/${t}`).then(r=>r.data)}}var i0;(function(e){e[e.SysFatal=1]="SysFatal",e[e.SysTransient=2]="SysTransient",e[e.DestinationInvalid=3]="DestinationInvalid",e[e.CanisterReject=4]="CanisterReject",e[e.CanisterError=5]="CanisterError"})(i0||(i0={}));var Us;(function(e){e.Replied="replied",e.Rejected="rejected"})(Us||(Us={}));function ex(e){return e!=null&&"reject_code"in e}function tx(e){return e!=null&&"certificate"in e}var Br;(function(e){e.Trust="Trust",e.Protocol="Protocol",e.Reject="Reject",e.Transport="Transport",e.External="External",e.Limit="Limit",e.Input="Input",e.Unknown="Unknown"})(Br||(Br={}));class Ue{constructor(t=!1){this.isCertified=t}toString(){let t=this.toErrorMessage();return this.requestContext&&(t+=`
|
|
31
31
|
Request context:
|
|
32
32
|
Request ID (hex): ${this.requestContext.requestId?rt(this.requestContext.requestId):"undefined"}
|
|
33
33
|
Sender pubkey (hex): ${rt(this.requestContext.senderPubKey)}
|
|
@@ -73,7 +73,7 @@ ic-request`);const nx=new TextEncoder().encode("\vic-response");new TextEncoder(
|
|
|
73
73
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}),ar}var gf={},so={},mf={},ur={},$0;function Kw(){if($0)return ur;$0=1,Object.defineProperty(ur,"__esModule",{value:!0}),ur.encode=ur.decode=ur.check=void 0;function e(r){if(r.length<8||r.length>72||r[0]!==48||r[1]!==r.length-2||r[2]!==2)return!1;const i=r[3];if(i===0||5+i>=r.length||r[4+i]!==2)return!1;const s=r[5+i];return!(s===0||6+i+s!==r.length||r[4]&128||i>1&&r[4]===0&&!(r[5]&128)||r[i+6]&128||s>1&&r[i+6]===0&&!(r[i+7]&128))}ur.check=e;function t(r){if(r.length<8)throw new Error("DER sequence length is too short");if(r.length>72)throw new Error("DER sequence length is too long");if(r[0]!==48)throw new Error("Expected DER sequence");if(r[1]!==r.length-2)throw new Error("DER sequence length is invalid");if(r[2]!==2)throw new Error("Expected DER integer");const i=r[3];if(i===0)throw new Error("R length is zero");if(5+i>=r.length)throw new Error("R length is too long");if(r[4+i]!==2)throw new Error("Expected DER integer (2)");const s=r[5+i];if(s===0)throw new Error("S length is zero");if(6+i+s!==r.length)throw new Error("S length is invalid");if(r[4]&128)throw new Error("R value is negative");if(i>1&&r[4]===0&&!(r[5]&128))throw new Error("R value excessively padded");if(r[i+6]&128)throw new Error("S value is negative");if(s>1&&r[i+6]===0&&!(r[i+7]&128))throw new Error("S value excessively padded");return{r:r.slice(4,4+i),s:r.slice(6+i)}}ur.decode=t;function n(r,i){const s=r.length,o=i.length;if(s===0)throw new Error("R length is zero");if(o===0)throw new Error("S length is zero");if(s>33)throw new Error("R length is too long");if(o>33)throw new Error("S length is too long");if(r[0]&128)throw new Error("R value is negative");if(i[0]&128)throw new Error("S value is negative");if(s>1&&r[0]===0&&!(r[1]&128))throw new Error("R value excessively padded");if(o>1&&i[0]===0&&!(i[1]&128))throw new Error("S value excessively padded");const c=Buffer.allocUnsafe(6+s+o);return c[0]=48,c[1]=c.length-2,c[2]=2,c[3]=r.length,r.copy(c,4),c[4+s]=2,c[5+s]=i.length,i.copy(c,6+s),c}return ur.encode=n,ur}var _i={},D0;function bh(){if(D0)return _i;D0=1,Object.defineProperty(_i,"__esModule",{value:!0}),_i.REVERSE_OPS=_i.OPS=void 0;const e={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};_i.OPS=e;const t={};_i.REVERSE_OPS=t;for(const n of Object.keys(e)){const r=e[n];t[r]=n}return _i}var fr={},j0;function H8(){if(j0)return fr;j0=1,Object.defineProperty(fr,"__esModule",{value:!0}),fr.decode=fr.encode=fr.encodingLength=void 0;const e=bh();function t(i){return i<e.OPS.OP_PUSHDATA1?1:i<=255?2:i<=65535?3:5}fr.encodingLength=t;function n(i,s,o){const c=t(s);return c===1?i.writeUInt8(s,o):c===2?(i.writeUInt8(e.OPS.OP_PUSHDATA1,o),i.writeUInt8(s,o+1)):c===3?(i.writeUInt8(e.OPS.OP_PUSHDATA2,o),i.writeUInt16LE(s,o+1)):(i.writeUInt8(e.OPS.OP_PUSHDATA4,o),i.writeUInt32LE(s,o+1)),c}fr.encode=n;function r(i,s){const o=i.readUInt8(s);let c,a;if(o<e.OPS.OP_PUSHDATA1)c=o,a=1;else if(o===e.OPS.OP_PUSHDATA1){if(s+2>i.length)return null;c=i.readUInt8(s+1),a=2}else if(o===e.OPS.OP_PUSHDATA2){if(s+3>i.length)return null;c=i.readUInt16LE(s+1),a=3}else{if(s+5>i.length)return null;if(o!==e.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");c=i.readUInt32LE(s+1),a=5}return{opcode:o,number:c,size:a}}return fr.decode=r,fr}var Si={},K0;function F8(){if(K0)return Si;K0=1,Object.defineProperty(Si,"__esModule",{value:!0}),Si.encode=Si.decode=void 0;function e(r,i,s){i=i||4,s=s===void 0?!0:s;const o=r.length;if(o===0)return 0;if(o>i)throw new TypeError("Script number overflow");if(s&&(r[o-1]&127)===0&&(o<=1||(r[o-2]&128)===0))throw new Error("Non-minimally encoded script number");if(o===5){const a=r.readUInt32LE(0),u=r.readUInt8(4);return u&128?-((u&-129)*4294967296+a):u*4294967296+a}let c=0;for(let a=0;a<o;++a)c|=r[a]<<8*a;return r[o-1]&128?-(c&~(128<<8*(o-1))):c}Si.decode=e;function t(r){return r>2147483647?5:r>8388607?4:r>32767?3:r>127?2:r>0?1:0}function n(r){let i=Math.abs(r);const s=t(i),o=Buffer.allocUnsafe(s),c=r<0;for(let a=0;a<s;++a)o.writeUInt8(i&255,a),i>>=8;return o[s-1]&128?o.writeUInt8(c?128:0,s-1):c&&(o[s-1]|=128),o}return Si.encode=n,Si}var Ti={},wf={},bf,G0;function Eh(){if(G0)return bf;G0=1;var e={Array:function(n){return n!=null&&n.constructor===Array},Boolean:function(n){return typeof n=="boolean"},Function:function(n){return typeof n=="function"},Nil:function(n){return n==null},Number:function(n){return typeof n=="number"},Object:function(n){return typeof n=="object"},String:function(n){return typeof n=="string"},"":function(){return!0}};e.Null=e.Nil;for(var t in e)e[t].toJSON=(function(n){return n}).bind(null,t);return bf=e,bf}var Ef,W0;function Gw(){if(W0)return Ef;W0=1;var e=Eh();function t(d){return d.name||d.toString().match(/function (.*?)\s*\(/)[1]}function n(d){return e.Nil(d)?"":t(d.constructor)}function r(d){return e.Function(d)?"":e.String(d)?JSON.stringify(d):d&&e.Object(d)?"":d}function i(d,y){Error.captureStackTrace&&Error.captureStackTrace(d,y)}function s(d){return e.Function(d)?d.toJSON?d.toJSON():t(d):e.Array(d)?"Array":d&&e.Object(d)?"Object":d!==void 0?d:""}function o(d,y,g){var m=r(y);return"Expected "+s(d)+", got"+(g!==""?" "+g:"")+(m!==""?" "+m:"")}function c(d,y,g){g=g||n(y),this.message=o(d,y,g),i(this,c),this.__type=d,this.__value=y,this.__valueTypeName=g}c.prototype=Object.create(Error.prototype),c.prototype.constructor=c;function a(d,y,g,m,E){var _='" of type ';return y==="key"&&(_='" with key type '),o('property "'+s(g)+_+s(d),m,E)}function u(d,y,g,m,E){d?(E=E||n(m),this.message=a(d,g,y,m,E)):this.message='Unexpected property "'+y+'"',i(this,c),this.__label=g,this.__property=y,this.__type=d,this.__value=m,this.__valueTypeName=E}u.prototype=Object.create(Error.prototype),u.prototype.constructor=c;function f(d,y){return new c(d,{},y)}function l(d,y,g){return d instanceof u?(y=y+"."+d.__property,d=new u(d.__type,y,d.__label,d.__value,d.__valueTypeName)):d instanceof c&&(d=new u(d.__type,y,g,d.__value,d.__valueTypeName)),i(d),d}return Ef={TfTypeError:c,TfPropertyTypeError:u,tfCustomError:f,tfSubError:l,tfJSON:s,getValueTypeName:n},Ef}var _f,X0;function M8(){if(X0)return _f;X0=1;var e=Eh(),t=Gw();function n(A){return Buffer.isBuffer(A)}function r(A){return typeof A=="string"&&/^([0-9a-f]{2})+$/i.test(A)}function i(A,R){var M=A.toJSON();function v(U){if(!A(U))return!1;if(U.length===R)return!0;throw t.tfCustomError(M+"(Length: "+R+")",M+"(Length: "+U.length+")")}return v.toJSON=function(){return M},v}var s=i.bind(null,e.Array),o=i.bind(null,n),c=i.bind(null,r),a=i.bind(null,e.String);function u(A,R,M){M=M||e.Number;function v(U,V){return M(U,V)&&U>A&&U<R}return v.toJSON=function(){return`${M.toJSON()} between [${A}, ${R}]`},v}var f=Math.pow(2,53)-1;function l(A){return typeof A=="number"&&isFinite(A)}function d(A){return A<<24>>24===A}function y(A){return A<<16>>16===A}function g(A){return(A|0)===A}function m(A){return typeof A=="number"&&A>=-f&&A<=f&&Math.floor(A)===A}function E(A){return(A&255)===A}function _(A){return(A&65535)===A}function S(A){return A>>>0===A}function w(A){return typeof A=="number"&&A>=0&&A<=f&&Math.floor(A)===A}var T={ArrayN:s,Buffer:n,BufferN:o,Finite:l,Hex:r,HexN:c,Int8:d,Int16:y,Int32:g,Int53:m,Range:u,StringN:a,UInt8:E,UInt16:_,UInt32:S,UInt53:w};for(var O in T)T[O].toJSON=(function(A){return A}).bind(null,O);return _f=T,_f}var Sf,z0;function q8(){if(z0)return Sf;z0=1;var e=Gw(),t=Eh(),n=e.tfJSON,r=e.TfTypeError,i=e.TfPropertyTypeError,s=e.tfSubError,o=e.getValueTypeName,c={arrayOf:function(y,g){y=a(y),g=g||{};function m(E,_){return!t.Array(E)||t.Nil(E)||g.minLength!==void 0&&E.length<g.minLength||g.maxLength!==void 0&&E.length>g.maxLength||g.length!==void 0&&E.length!==g.length?!1:E.every(function(S,w){try{return u(y,S,_)}catch(T){throw s(T,w)}})}return m.toJSON=function(){var E="["+n(y)+"]";return g.length!==void 0?E+="{"+g.length+"}":(g.minLength!==void 0||g.maxLength!==void 0)&&(E+="{"+(g.minLength===void 0?0:g.minLength)+","+(g.maxLength===void 0?1/0:g.maxLength)+"}"),E},m},maybe:function d(y){y=a(y);function g(m,E){return t.Nil(m)||y(m,E,d)}return g.toJSON=function(){return"?"+n(y)},g},map:function(y,g){y=a(y),g&&(g=a(g));function m(E,_){if(!t.Object(E)||t.Nil(E))return!1;for(var S in E){try{g&&u(g,S,_)}catch(T){throw s(T,S,"key")}try{var w=E[S];u(y,w,_)}catch(T){throw s(T,S)}}return!0}return g?m.toJSON=function(){return"{"+n(g)+": "+n(y)+"}"}:m.toJSON=function(){return"{"+n(y)+"}"},m},object:function(y){var g={};for(var m in y)g[m]=a(y[m]);function E(_,S){if(!t.Object(_)||t.Nil(_))return!1;var w;try{for(w in g){var T=g[w],O=_[w];u(T,O,S)}}catch(A){throw s(A,w)}if(S){for(w in _)if(!g[w])throw new i(void 0,w)}return!0}return E.toJSON=function(){return n(g)},E},anyOf:function(){var y=[].slice.call(arguments).map(a);function g(m,E){return y.some(function(_){try{return u(_,m,E)}catch{return!1}})}return g.toJSON=function(){return y.map(n).join("|")},g},allOf:function(){var y=[].slice.call(arguments).map(a);function g(m,E){return y.every(function(_){try{return u(_,m,E)}catch{return!1}})}return g.toJSON=function(){return y.map(n).join(" & ")},g},quacksLike:function(y){function g(m){return y===o(m)}return g.toJSON=function(){return y},g},tuple:function(){var y=[].slice.call(arguments).map(a);function g(m,E){return t.Nil(m)||t.Nil(m.length)||E&&m.length!==y.length?!1:y.every(function(_,S){try{return u(_,m[S],E)}catch(w){throw s(w,S)}})}return g.toJSON=function(){return"("+y.map(n).join(", ")+")"},g},value:function(y){function g(m){return m===y}return g.toJSON=function(){return y},g}};c.oneOf=c.anyOf;function a(d){if(t.String(d))return d[0]==="?"?c.maybe(d.slice(1)):t[d]||c.quacksLike(d);if(d&&t.Object(d)){if(t.Array(d)){if(d.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(d[0])}return c.object(d)}else if(t.Function(d))return d;return c.value(d)}function u(d,y,g,m){if(t.Function(d)){if(d(y,g))return!0;throw new r(m||d,y)}return u(a(d),y,g)}for(var f in t)u[f]=t[f];for(f in c)u[f]=c[f];var l=M8();for(f in l)u[f]=l[f];return u.compile=a,u.TfTypeError=r,u.TfPropertyTypeError=i,Sf=u,Sf}var Y0;function Xt(){return Y0||(Y0=1,(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=tc();e.typeforce=q8();const n=t.Buffer.alloc(32,0),r=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(f,l){return f.length!==l.length?!1:f.every((d,y)=>d.equals(l[y]))}e.stacksEqual=i;function s(f){if(!t.Buffer.isBuffer(f)||f.length<33)return!1;const l=f[0],d=f.slice(1,33);if(d.compare(n)===0||d.compare(r)>=0)return!1;if((l===2||l===3)&&f.length===33)return!0;const y=f.slice(33);return y.compare(n)===0||y.compare(r)>=0?!1:l===4&&f.length===65}e.isPoint=s;const o=21*1e14;function c(f){return e.typeforce.UInt53(f)&&f<=o}e.Satoshi=c,e.TAPLEAF_VERSION_MASK=254;function a(f){return!f||!("output"in f)||!t.Buffer.isBuffer(f.output)?!1:f.version!==void 0?(f.version&e.TAPLEAF_VERSION_MASK)===f.version:!0}e.isTapleaf=a;function u(f){return(0,e.Array)(f)?f.length!==2?!1:f.every(l=>u(l)):a(f)}e.isTaptree=u,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(wf)),wf}var Z0;function V8(){if(Z0)return Ti;Z0=1,Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.encode=Ti.decode=void 0;const e=Kw(),t=rn(),n=Xt(),{typeforce:r}=n,i=Buffer.alloc(1,0);function s(u){let f=0;for(;u[f]===0;)++f;return f===u.length?i:(u=u.slice(f),u[0]&128?Buffer.concat([i,u],1+u.length):u)}function o(u){u[0]===0&&(u=u.slice(1));const f=Buffer.alloc(32,0),l=Math.max(0,32-u.length);return u.copy(f,l),f}function c(u){const f=u.readUInt8(u.length-1);if(!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const l=e.decode(u.slice(0,-1)),d=o(l.r),y=o(l.s);return{signature:Buffer.concat([d,y],64),hashType:f}}Ti.decode=c;function a(u,f){if(r({signature:n.BufferN(64),hashType:n.UInt8},{signature:u,hashType:f}),!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const l=Buffer.allocUnsafe(1);l.writeUInt8(f,0);const d=s(u.slice(0,32)),y=s(u.slice(32,64));return Buffer.concat([e.encode(d,y),l])}return Ti.encode=a,Ti}var J0;function rn(){return J0||(J0=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=Kw(),n=bh();Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return n.OPS}});const r=H8(),i=F8(),s=V8(),o=Xt(),{typeforce:c}=o,a=n.OPS.OP_RESERVED;function u(v){return o.Number(v)&&(v===n.OPS.OP_0||v>=n.OPS.OP_1&&v<=n.OPS.OP_16||v===n.OPS.OP_1NEGATE)}function f(v){return o.Buffer(v)||u(v)}function l(v){return o.Array(v)&&v.every(f)}e.isPushOnly=l;function d(v){return v.length-v.filter(f).length}e.countNonPushOnlyOPs=d;function y(v){if(v.length===0)return n.OPS.OP_0;if(v.length===1){if(v[0]>=1&&v[0]<=16)return a+v[0];if(v[0]===129)return n.OPS.OP_1NEGATE}}function g(v){return Buffer.isBuffer(v)}function m(v){return o.Array(v)}function E(v){return Buffer.isBuffer(v)}function _(v){if(g(v))return v;c(o.Array,v);const U=v.reduce((H,$)=>E($)?$.length===1&&y($)!==void 0?H+1:H+r.encodingLength($.length)+$.length:H+1,0),V=Buffer.allocUnsafe(U);let K=0;if(v.forEach(H=>{if(E(H)){const $=y(H);if($!==void 0){V.writeUInt8($,K),K+=1;return}K+=r.encode(V,H.length,K),H.copy(V,K),K+=H.length}else V.writeUInt8(H,K),K+=1}),K!==V.length)throw new Error("Could not decode chunks");return V}e.compile=_;function S(v){if(m(v))return v;c(o.Buffer,v);const U=[];let V=0;for(;V<v.length;){const K=v[V];if(K>n.OPS.OP_0&&K<=n.OPS.OP_PUSHDATA4){const H=r.decode(v,V);if(H===null||(V+=H.size,V+H.number>v.length))return null;const $=v.slice(V,V+H.number);V+=H.number;const P=y($);P!==void 0?U.push(P):U.push($)}else U.push(K),V+=1}return U}e.decompile=S;function w(v){if(g(v)&&(v=S(v)),!v)throw new Error("Could not convert invalid chunks to ASM");return v.map(U=>{if(E(U)){const V=y(U);if(V===void 0)return U.toString("hex");U=V}return n.REVERSE_OPS[U]}).join(" ")}e.toASM=w;function T(v){return c(o.String,v),_(v.split(" ").map(U=>n.OPS[U]!==void 0?n.OPS[U]:(c(o.Hex,U),Buffer.from(U,"hex"))))}e.fromASM=T;function O(v){return v=S(v),c(l,v),v.map(U=>E(U)?U:U===n.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(U-a))}e.toStack=O;function A(v){return o.isPoint(v)}e.isCanonicalPubKey=A;function R(v){const U=v&-129;return U>0&&U<4}e.isDefinedHashType=R;function M(v){return!Buffer.isBuffer(v)||!R(v[v.length-1])?!1:t.check(v.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s})(mf)),mf}var xi={},Q0;function gi(){if(Q0)return xi;Q0=1,Object.defineProperty(xi,"__esModule",{value:!0}),xi.value=xi.prop=void 0;function e(n,r,i){Object.defineProperty(n,r,{configurable:!0,enumerable:!0,get(){const s=i.call(this);return this[r]=s,s},set(s){Object.defineProperty(this,r,{configurable:!0,enumerable:!0,value:s,writable:!0})}})}xi.prop=e;function t(n){let r;return()=>(r!==void 0||(r=n()),r)}return xi.value=t,xi}var ep;function L8(){if(ep)return so;ep=1,Object.defineProperty(so,"__esModule",{value:!0}),so.p2data=void 0;const e=Wn(),t=rn(),n=Xt(),r=gi(),i=t.OPS;function s(o,c){if(!o.data&&!o.output)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),data:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))},o);const u={name:"embed",network:o.network||e.bitcoin};if(r.prop(u,"output",()=>{if(o.data)return t.compile([i.OP_RETURN].concat(o.data))}),r.prop(u,"data",()=>{if(o.output)return t.decompile(o.output).slice(1)}),c.validate&&o.output){const f=t.decompile(o.output);if(f[0]!==i.OP_RETURN)throw new TypeError("Output is invalid");if(!f.slice(1).every(n.typeforce.Buffer))throw new TypeError("Output is invalid");if(o.data&&!(0,n.stacksEqual)(o.data,u.data))throw new TypeError("Data mismatch")}return Object.assign(u,o)}return so.p2data=s,so}var oo={},tp;function $8(){if(tp)return oo;tp=1,Object.defineProperty(oo,"__esModule",{value:!0}),oo.p2ms=void 0;const e=Wn(),t=rn(),n=Xt(),r=gi(),i=t.OPS,s=i.OP_RESERVED;function o(c,a){if(!c.input&&!c.output&&!(c.pubkeys&&c.m!==void 0)&&!c.signatures)throw new TypeError("Not enough data");a=Object.assign({validate:!0},a||{});function u(m){return t.isCanonicalScriptSignature(m)||(a.allowIncomplete&&m===i.OP_0)!==void 0}(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),m:n.typeforce.maybe(n.typeforce.Number),n:n.typeforce.maybe(n.typeforce.Number),output:n.typeforce.maybe(n.typeforce.Buffer),pubkeys:n.typeforce.maybe(n.typeforce.arrayOf(n.isPoint)),signatures:n.typeforce.maybe(n.typeforce.arrayOf(u)),input:n.typeforce.maybe(n.typeforce.Buffer)},c);const l={network:c.network||e.bitcoin};let d=[],y=!1;function g(m){y||(y=!0,d=t.decompile(m),l.m=d[0]-s,l.n=d[d.length-2]-s,l.pubkeys=d.slice(1,-2))}if(r.prop(l,"output",()=>{if(c.m&&l.n&&c.pubkeys)return t.compile([].concat(s+c.m,c.pubkeys,s+l.n,i.OP_CHECKMULTISIG))}),r.prop(l,"m",()=>{if(l.output)return g(l.output),l.m}),r.prop(l,"n",()=>{if(l.pubkeys)return l.pubkeys.length}),r.prop(l,"pubkeys",()=>{if(c.output)return g(c.output),l.pubkeys}),r.prop(l,"signatures",()=>{if(c.input)return t.decompile(c.input).slice(1)}),r.prop(l,"input",()=>{if(c.signatures)return t.compile([i.OP_0].concat(c.signatures))}),r.prop(l,"witness",()=>{if(l.input)return[]}),r.prop(l,"name",()=>{if(!(!l.m||!l.n))return`p2ms(${l.m} of ${l.n})`}),a.validate){if(c.output){if(g(c.output),!n.typeforce.Number(d[0]))throw new TypeError("Output is invalid");if(!n.typeforce.Number(d[d.length-2]))throw new TypeError("Output is invalid");if(d[d.length-1]!==i.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(l.m<=0||l.n>16||l.m>l.n||l.n!==d.length-3)throw new TypeError("Output is invalid");if(!l.pubkeys.every(m=>(0,n.isPoint)(m)))throw new TypeError("Output is invalid");if(c.m!==void 0&&c.m!==l.m)throw new TypeError("m mismatch");if(c.n!==void 0&&c.n!==l.n)throw new TypeError("n mismatch");if(c.pubkeys&&!(0,n.stacksEqual)(c.pubkeys,l.pubkeys))throw new TypeError("Pubkeys mismatch")}if(c.pubkeys){if(c.n!==void 0&&c.n!==c.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(l.n=c.pubkeys.length,l.n<l.m)throw new TypeError("Pubkey count cannot be less than m")}if(c.signatures){if(c.signatures.length<l.m)throw new TypeError("Not enough signatures provided");if(c.signatures.length>l.m)throw new TypeError("Too many signatures provided")}if(c.input){if(c.input[0]!==i.OP_0)throw new TypeError("Input is invalid");if(l.signatures.length===0||!l.signatures.every(u))throw new TypeError("Input has invalid signature(s)");if(c.signatures&&!(0,n.stacksEqual)(c.signatures,l.signatures))throw new TypeError("Signature mismatch");if(c.m!==void 0&&c.m!==c.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(l,c)}return oo.p2ms=o,oo}var co={},np;function D8(){if(np)return co;np=1,Object.defineProperty(co,"__esModule",{value:!0}),co.p2pk=void 0;const e=Wn(),t=rn(),n=Xt(),r=gi(),i=t.OPS;function s(o,c){if(!o.input&&!o.output&&!o.pubkey&&!o.input&&!o.signature)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),pubkey:n.typeforce.maybe(n.isPoint),signature:n.typeforce.maybe(t.isCanonicalScriptSignature),input:n.typeforce.maybe(n.typeforce.Buffer)},o);const a=r.value(()=>t.decompile(o.input)),f={name:"p2pk",network:o.network||e.bitcoin};if(r.prop(f,"output",()=>{if(o.pubkey)return t.compile([o.pubkey,i.OP_CHECKSIG])}),r.prop(f,"pubkey",()=>{if(o.output)return o.output.slice(1,-1)}),r.prop(f,"signature",()=>{if(o.input)return a()[0]}),r.prop(f,"input",()=>{if(o.signature)return t.compile([o.signature])}),r.prop(f,"witness",()=>{if(f.input)return[]}),c.validate){if(o.output){if(o.output[o.output.length-1]!==i.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,n.isPoint)(f.pubkey))throw new TypeError("Output pubkey is invalid");if(o.pubkey&&!o.pubkey.equals(f.pubkey))throw new TypeError("Pubkey mismatch")}if(o.signature&&o.input&&!o.input.equals(f.input))throw new TypeError("Signature mismatch");if(o.input){if(a().length!==1)throw new TypeError("Input is invalid");if(!t.isCanonicalScriptSignature(f.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(f,o)}return co.p2pk=s,co}var ao={},Tf={},Ai={},Zt={},rp;function Ww(){if(rp)return Zt;rp=1,Object.defineProperty(Zt,"__esModule",{value:!0}),Zt.ripemd160=Zt.RIPEMD160=Zt.md5=Zt.MD5=Zt.sha1=Zt.SHA1=void 0;const e=Ry(),t=ui(),n=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),r=new Uint32Array(80);class i extends e.HashMD{constructor(){super(64,20,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0}get(){const{A:v,B:U,C:V,D:K,E:H}=this;return[v,U,V,K,H]}set(v,U,V,K,H){this.A=v|0,this.B=U|0,this.C=V|0,this.D=K|0,this.E=H|0}process(v,U){for(let D=0;D<16;D++,U+=4)r[D]=v.getUint32(U,!1);for(let D=16;D<80;D++)r[D]=(0,t.rotl)(r[D-3]^r[D-8]^r[D-14]^r[D-16],1);let{A:V,B:K,C:H,D:$,E:P}=this;for(let D=0;D<80;D++){let F,x;D<20?(F=(0,e.Chi)(K,H,$),x=1518500249):D<40?(F=K^H^$,x=1859775393):D<60?(F=(0,e.Maj)(K,H,$),x=2400959708):(F=K^H^$,x=3395469782);const B=(0,t.rotl)(V,5)+F+P+x+r[D]|0;P=$,$=H,H=(0,t.rotl)(K,30),K=V,V=B}V=V+this.A|0,K=K+this.B|0,H=H+this.C|0,$=$+this.D|0,P=P+this.E|0,this.set(V,K,H,$,P)}roundClean(){(0,t.clean)(r)}destroy(){this.set(0,0,0,0,0),(0,t.clean)(this.buffer)}}Zt.SHA1=i,Zt.sha1=(0,t.createHasher)(()=>new i);const s=Math.pow(2,32),o=Array.from({length:64},(M,v)=>Math.floor(s*Math.abs(Math.sin(v+1)))),c=n.slice(0,4),a=new Uint32Array(16);class u extends e.HashMD{constructor(){super(64,16,8,!0),this.A=c[0]|0,this.B=c[1]|0,this.C=c[2]|0,this.D=c[3]|0}get(){const{A:v,B:U,C:V,D:K}=this;return[v,U,V,K]}set(v,U,V,K){this.A=v|0,this.B=U|0,this.C=V|0,this.D=K|0}process(v,U){for(let P=0;P<16;P++,U+=4)a[P]=v.getUint32(U,!0);let{A:V,B:K,C:H,D:$}=this;for(let P=0;P<64;P++){let D,F,x;P<16?(D=(0,e.Chi)(K,H,$),F=P,x=[7,12,17,22]):P<32?(D=(0,e.Chi)($,K,H),F=(5*P+1)%16,x=[5,9,14,20]):P<48?(D=K^H^$,F=(3*P+5)%16,x=[4,11,16,23]):(D=H^(K|~$),F=7*P%16,x=[6,10,15,21]),D=D+V+o[P]+a[F],V=$,$=H,H=K,K=K+(0,t.rotl)(D,x[P%4])}V=V+this.A|0,K=K+this.B|0,H=H+this.C|0,$=$+this.D|0,this.set(V,K,H,$)}roundClean(){(0,t.clean)(a)}destroy(){this.set(0,0,0,0),(0,t.clean)(this.buffer)}}Zt.MD5=u,Zt.md5=(0,t.createHasher)(()=>new u);const f=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),l=Uint8Array.from(new Array(16).fill(0).map((M,v)=>v)),d=l.map(M=>(9*M+5)%16),y=(()=>{const U=[[l],[d]];for(let V=0;V<4;V++)for(let K of U)K.push(K[V].map(H=>f[H]));return U})(),g=y[0],m=y[1],E=[[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(M=>Uint8Array.from(M)),_=g.map((M,v)=>M.map(U=>E[v][U])),S=m.map((M,v)=>M.map(U=>E[v][U])),w=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),T=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function O(M,v,U,V){return M===0?v^U^V:M===1?v&U|~v&V:M===2?(v|~U)^V:M===3?v&V|U&~V:v^(U|~V)}const A=new Uint32Array(16);class R extends e.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:v,h1:U,h2:V,h3:K,h4:H}=this;return[v,U,V,K,H]}set(v,U,V,K,H){this.h0=v|0,this.h1=U|0,this.h2=V|0,this.h3=K|0,this.h4=H|0}process(v,U){for(let N=0;N<16;N++,U+=4)A[N]=v.getUint32(U,!0);let V=this.h0|0,K=V,H=this.h1|0,$=H,P=this.h2|0,D=P,F=this.h3|0,x=F,B=this.h4|0,q=B;for(let N=0;N<5;N++){const L=4-N,G=w[N],X=T[N],Y=g[N],ce=m[N],ue=_[N],te=S[N];for(let Z=0;Z<16;Z++){const ae=(0,t.rotl)(V+O(N,H,P,F)+A[Y[Z]]+G,ue[Z])+B|0;V=B,B=F,F=(0,t.rotl)(P,10)|0,P=H,H=ae}for(let Z=0;Z<16;Z++){const ae=(0,t.rotl)(K+O(L,$,D,x)+A[ce[Z]]+X,te[Z])+q|0;K=q,q=x,x=(0,t.rotl)(D,10)|0,D=$,$=ae}}this.set(this.h1+P+x|0,this.h2+F+q|0,this.h3+B+K|0,this.h4+V+$|0,this.h0+H+D|0)}roundClean(){(0,t.clean)(A)}destroy(){this.destroyed=!0,(0,t.clean)(this.buffer),this.set(0,0,0,0,0)}}return Zt.RIPEMD160=R,Zt.ripemd160=(0,t.createHasher)(()=>new R),Zt}var ip;function j8(){if(ip)return Ai;ip=1,Object.defineProperty(Ai,"__esModule",{value:!0}),Ai.ripemd160=Ai.RIPEMD160=void 0;const e=Ww();return Ai.RIPEMD160=e.RIPEMD160,Ai.ripemd160=e.ripemd160,Ai}var vi={},sp;function K8(){if(sp)return vi;sp=1,Object.defineProperty(vi,"__esModule",{value:!0}),vi.sha1=vi.SHA1=void 0;const e=Ww();return vi.SHA1=e.SHA1,vi.sha1=e.sha1,vi}var Un={},op;function Xw(){if(op)return Un;op=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.sha224=Un.SHA224=Un.sha256=Un.SHA256=void 0;const e=Uy();return Un.SHA256=e.SHA256,Un.sha256=e.sha256,Un.SHA224=e.SHA224,Un.sha224=e.sha224,Un}var cp;function Pr(){return cp||(cp=1,(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=j8(),n=K8(),r=Xw();function i(f){return Buffer.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function s(f){return Buffer.from((0,n.sha1)(Uint8Array.from(f)))}e.sha1=s;function o(f){return Buffer.from((0,r.sha256)(Uint8Array.from(f)))}e.sha256=o;function c(f){return Buffer.from((0,t.ripemd160)((0,r.sha256)(Uint8Array.from(f))))}e.hash160=c;function a(f){return Buffer.from((0,r.sha256)((0,r.sha256)(Uint8Array.from(f))))}e.hash256=a,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Buffer.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Buffer.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Buffer.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Buffer.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Buffer.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Buffer.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Buffer.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Buffer.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function u(f,l){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[f],l]))}e.taggedHash=u})(Tf)),Tf}var xf,ap;function G8(){if(ap)return xf;ap=1;function e(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var m=0,E=0,_=0,S=g.length;_!==S&&g[_]===0;)_++,m++;for(var w=(S-_)*f+1>>>0,T=new Uint8Array(w);_!==S;){for(var O=g[_],A=0,R=w-1;(O!==0||A<E)&&R!==-1;R--,A++)O+=256*T[R]>>>0,T[R]=O%c>>>0,O=O/c>>>0;if(O!==0)throw new Error("Non-zero carry");E=A,_++}for(var M=w-E;M!==w&&T[M]===0;)M++;for(var v=a.repeat(m);M<w;++M)v+=t.charAt(T[M]);return v}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;for(var m=0,E=0,_=0;g[m]===a;)E++,m++;for(var S=(g.length-m)*u+1>>>0,w=new Uint8Array(S);g[m];){var T=g.charCodeAt(m);if(T>255)return;var O=n[T];if(O===255)return;for(var A=0,R=S-1;(O!==0||A<_)&&R!==-1;R--,A++)O+=c*w[R]>>>0,w[R]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");_=A,m++}for(var M=S-_;M!==S&&w[M]===0;)M++;for(var v=new Uint8Array(E+(S-M)),U=E;M!==S;)v[U++]=w[M++];return v}function y(g){var m=d(g);if(m)return m;throw new Error("Non-base"+c+" character")}return{encode:l,decodeUnsafe:d,decode:y}}return xf=e,xf}var Af,up;function W8(){return up||(up=1,Af=G8()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")),Af}var vf,fp;function X8(){if(fp)return vf;fp=1;var e=W8();return vf=function(t){function n(o){var c=Uint8Array.from(o),a=t(c),u=c.length+4,f=new Uint8Array(u);return f.set(c,0),f.set(a.subarray(0,4),c.length),e.encode(f,u)}function r(o){var c=o.slice(0,-4),a=o.slice(-4),u=t(c);if(!(a[0]^u[0]|a[1]^u[1]|a[2]^u[2]|a[3]^u[3]))return c}function i(o){var c=e.decodeUnsafe(o);if(c)return r(c)}function s(o){var c=e.decode(o),a=r(c);if(!a)throw new Error("Invalid checksum");return a}return{encode:n,decode:s,decodeUnsafe:i}},vf}var If,lp;function _h(){if(lp)return If;lp=1;var{sha256:e}=Xw(),t=X8();function n(r){return e(e(r))}return If=t(n),If}var hp;function z8(){if(hp)return ao;hp=1,Object.defineProperty(ao,"__esModule",{value:!0}),ao.p2pkh=void 0;const e=Pr(),t=Wn(),n=rn(),r=Xt(),i=gi(),s=_h(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.pubkey&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(25)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),input:r.typeforce.maybe(r.typeforce.Buffer)},a);const f=i.value(()=>{const g=Buffer.from(s.decode(a.address)),m=g.readUInt8(0),E=g.slice(1);return{version:m,hash:E}}),l=i.value(()=>n.decompile(a.input)),d=a.network||t.bitcoin,y={name:"p2pkh",network:d};if(i.prop(y,"address",()=>{if(!y.hash)return;const g=Buffer.allocUnsafe(21);return g.writeUInt8(d.pubKeyHash,0),y.hash.copy(g,1),s.encode(g)}),i.prop(y,"hash",()=>{if(a.output)return a.output.slice(3,23);if(a.address)return f().hash;if(a.pubkey||y.pubkey)return e.hash160(a.pubkey||y.pubkey)}),i.prop(y,"output",()=>{if(y.hash)return n.compile([o.OP_DUP,o.OP_HASH160,y.hash,o.OP_EQUALVERIFY,o.OP_CHECKSIG])}),i.prop(y,"pubkey",()=>{if(a.input)return l()[1]}),i.prop(y,"signature",()=>{if(a.input)return l()[0]}),i.prop(y,"input",()=>{if(a.pubkey&&a.signature)return n.compile([a.signature,a.pubkey])}),i.prop(y,"witness",()=>{if(y.input)return[]}),u.validate){let g=Buffer.from([]);if(a.address){if(f().version!==d.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(f().hash.length!==20)throw new TypeError("Invalid address");g=f().hash}if(a.hash){if(g.length>0&&!g.equals(a.hash))throw new TypeError("Hash mismatch");g=a.hash}if(a.output){if(a.output.length!==25||a.output[0]!==o.OP_DUP||a.output[1]!==o.OP_HASH160||a.output[2]!==20||a.output[23]!==o.OP_EQUALVERIFY||a.output[24]!==o.OP_CHECKSIG)throw new TypeError("Output is invalid");const m=a.output.slice(3,23);if(g.length>0&&!g.equals(m))throw new TypeError("Hash mismatch");g=m}if(a.pubkey){const m=e.hash160(a.pubkey);if(g.length>0&&!g.equals(m))throw new TypeError("Hash mismatch");g=m}if(a.input){const m=l();if(m.length!==2)throw new TypeError("Input is invalid");if(!n.isCanonicalScriptSignature(m[0]))throw new TypeError("Input has invalid signature");if(!(0,r.isPoint)(m[1]))throw new TypeError("Input has invalid pubkey");if(a.signature&&!a.signature.equals(m[0]))throw new TypeError("Signature mismatch");if(a.pubkey&&!a.pubkey.equals(m[1]))throw new TypeError("Pubkey mismatch");const E=e.hash160(m[1]);if(g.length>0&&!g.equals(E))throw new TypeError("Hash mismatch")}}return Object.assign(y,a)}return ao.p2pkh=c,ao}var uo={},dp;function Y8(){if(dp)return uo;dp=1,Object.defineProperty(uo,"__esModule",{value:!0}),uo.p2sh=void 0;const e=Pr(),t=Wn(),n=rn(),r=Xt(),i=gi(),s=_h(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.redeem&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(23)),redeem:r.typeforce.maybe({network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},a);let f=a.network;f||(f=a.redeem&&a.redeem.network||t.bitcoin);const l={network:f},d=i.value(()=>{const m=Buffer.from(s.decode(a.address)),E=m.readUInt8(0),_=m.slice(1);return{version:E,hash:_}}),y=i.value(()=>n.decompile(a.input)),g=i.value(()=>{const m=y(),E=m[m.length-1];return{network:f,output:E===o.OP_FALSE?Buffer.from([]):E,input:n.compile(m.slice(0,-1)),witness:a.witness||[]}});if(i.prop(l,"address",()=>{if(!l.hash)return;const m=Buffer.allocUnsafe(21);return m.writeUInt8(l.network.scriptHash,0),l.hash.copy(m,1),s.encode(m)}),i.prop(l,"hash",()=>{if(a.output)return a.output.slice(2,22);if(a.address)return d().hash;if(l.redeem&&l.redeem.output)return e.hash160(l.redeem.output)}),i.prop(l,"output",()=>{if(l.hash)return n.compile([o.OP_HASH160,l.hash,o.OP_EQUAL])}),i.prop(l,"redeem",()=>{if(a.input)return g()}),i.prop(l,"input",()=>{if(!(!a.redeem||!a.redeem.input||!a.redeem.output))return n.compile([].concat(n.decompile(a.redeem.input),a.redeem.output))}),i.prop(l,"witness",()=>{if(l.redeem&&l.redeem.witness)return l.redeem.witness;if(l.input)return[]}),i.prop(l,"name",()=>{const m=["p2sh"];return l.redeem!==void 0&&l.redeem.name!==void 0&&m.push(l.redeem.name),m.join("-")}),u.validate){let m=Buffer.from([]);if(a.address){if(d().version!==f.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(d().hash.length!==20)throw new TypeError("Invalid address");m=d().hash}if(a.hash){if(m.length>0&&!m.equals(a.hash))throw new TypeError("Hash mismatch");m=a.hash}if(a.output){if(a.output.length!==23||a.output[0]!==o.OP_HASH160||a.output[1]!==20||a.output[22]!==o.OP_EQUAL)throw new TypeError("Output is invalid");const _=a.output.slice(2,22);if(m.length>0&&!m.equals(_))throw new TypeError("Hash mismatch");m=_}const E=_=>{if(_.output){const S=n.decompile(_.output);if(!S||S.length<1)throw new TypeError("Redeem.output too short");if(_.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(n.countNonPushOnlyOPs(S)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const w=e.hash160(_.output);if(m.length>0&&!m.equals(w))throw new TypeError("Hash mismatch");m=w}if(_.input){const S=_.input.length>0,w=_.witness&&_.witness.length>0;if(!S&&!w)throw new TypeError("Empty input");if(S&&w)throw new TypeError("Input and witness provided");if(S){const T=n.decompile(_.input);if(!n.isPushOnly(T))throw new TypeError("Non push-only scriptSig")}}};if(a.input){const _=y();if(!_||_.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(g().output))throw new TypeError("Input is invalid");E(g())}if(a.redeem){if(a.redeem.network&&a.redeem.network!==f)throw new TypeError("Network mismatch");if(a.input){const _=g();if(a.redeem.output&&!a.redeem.output.equals(_.output))throw new TypeError("Redeem.output mismatch");if(a.redeem.input&&!a.redeem.input.equals(_.input))throw new TypeError("Redeem.input mismatch")}E(a.redeem)}if(a.witness&&a.redeem&&a.redeem.witness&&!(0,r.stacksEqual)(a.redeem.witness,a.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(l,a)}return uo.p2sh=c,uo}var fo={},pp;function Z8(){if(pp)return fo;pp=1,Object.defineProperty(fo,"__esModule",{value:!0}),fo.p2wpkh=void 0;const e=Pr(),t=Wn(),n=rn(),r=Xt(),i=gi(),s=ac(),o=n.OPS,c=Buffer.alloc(0);function a(u,f){if(!u.address&&!u.hash&&!u.output&&!u.pubkey&&!u.witness)throw new TypeError("Not enough data");f=Object.assign({validate:!0},f||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(22)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},u);const l=i.value(()=>{const g=s.bech32.decode(u.address),m=g.words.shift(),E=s.bech32.fromWords(g.words);return{version:m,prefix:g.prefix,data:Buffer.from(E)}}),d=u.network||t.bitcoin,y={name:"p2wpkh",network:d};if(i.prop(y,"address",()=>{if(!y.hash)return;const g=s.bech32.toWords(y.hash);return g.unshift(0),s.bech32.encode(d.bech32,g)}),i.prop(y,"hash",()=>{if(u.output)return u.output.slice(2,22);if(u.address)return l().data;if(u.pubkey||y.pubkey)return e.hash160(u.pubkey||y.pubkey)}),i.prop(y,"output",()=>{if(y.hash)return n.compile([o.OP_0,y.hash])}),i.prop(y,"pubkey",()=>{if(u.pubkey)return u.pubkey;if(u.witness)return u.witness[1]}),i.prop(y,"signature",()=>{if(u.witness)return u.witness[0]}),i.prop(y,"input",()=>{if(y.witness)return c}),i.prop(y,"witness",()=>{if(u.pubkey&&u.signature)return[u.signature,u.pubkey]}),f.validate){let g=Buffer.from([]);if(u.address){if(d&&d.bech32!==l().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(l().version!==0)throw new TypeError("Invalid address version");if(l().data.length!==20)throw new TypeError("Invalid address data");g=l().data}if(u.hash){if(g.length>0&&!g.equals(u.hash))throw new TypeError("Hash mismatch");g=u.hash}if(u.output){if(u.output.length!==22||u.output[0]!==o.OP_0||u.output[1]!==20)throw new TypeError("Output is invalid");if(g.length>0&&!g.equals(u.output.slice(2)))throw new TypeError("Hash mismatch");g=u.output.slice(2)}if(u.pubkey){const m=e.hash160(u.pubkey);if(g.length>0&&!g.equals(m))throw new TypeError("Hash mismatch");if(g=m,!(0,r.isPoint)(u.pubkey)||u.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(u.witness){if(u.witness.length!==2)throw new TypeError("Witness is invalid");if(!n.isCanonicalScriptSignature(u.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,r.isPoint)(u.witness[1])||u.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(u.signature&&!u.signature.equals(u.witness[0]))throw new TypeError("Signature mismatch");if(u.pubkey&&!u.pubkey.equals(u.witness[1]))throw new TypeError("Pubkey mismatch");const m=e.hash160(u.witness[1]);if(g.length>0&&!g.equals(m))throw new TypeError("Hash mismatch")}}return Object.assign(y,u)}return fo.p2wpkh=a,fo}var lo={},yp;function J8(){if(yp)return lo;yp=1,Object.defineProperty(lo,"__esModule",{value:!0}),lo.p2wsh=void 0;const e=Pr(),t=Wn(),n=rn(),r=Xt(),i=gi(),s=ac(),o=n.OPS,c=Buffer.alloc(0);function a(f){return!!(Buffer.isBuffer(f)&&f.length===65&&f[0]===4&&(0,r.isPoint)(f))}function u(f,l){if(!f.address&&!f.hash&&!f.output&&!f.redeem&&!f.witness)throw new TypeError("Not enough data");l=Object.assign({validate:!0},l||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),output:r.typeforce.maybe(r.typeforce.BufferN(34)),redeem:r.typeforce.maybe({input:r.typeforce.maybe(r.typeforce.Buffer),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.BufferN(0)),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},f);const d=i.value(()=>{const E=s.bech32.decode(f.address),_=E.words.shift(),S=s.bech32.fromWords(E.words);return{version:_,prefix:E.prefix,data:Buffer.from(S)}}),y=i.value(()=>n.decompile(f.redeem.input));let g=f.network;g||(g=f.redeem&&f.redeem.network||t.bitcoin);const m={network:g};if(i.prop(m,"address",()=>{if(!m.hash)return;const E=s.bech32.toWords(m.hash);return E.unshift(0),s.bech32.encode(g.bech32,E)}),i.prop(m,"hash",()=>{if(f.output)return f.output.slice(2);if(f.address)return d().data;if(m.redeem&&m.redeem.output)return e.sha256(m.redeem.output)}),i.prop(m,"output",()=>{if(m.hash)return n.compile([o.OP_0,m.hash])}),i.prop(m,"redeem",()=>{if(f.witness)return{output:f.witness[f.witness.length-1],input:c,witness:f.witness.slice(0,-1)}}),i.prop(m,"input",()=>{if(m.witness)return c}),i.prop(m,"witness",()=>{if(f.redeem&&f.redeem.input&&f.redeem.input.length>0&&f.redeem.output&&f.redeem.output.length>0){const E=n.toStack(y());return m.redeem=Object.assign({witness:E},f.redeem),m.redeem.input=c,[].concat(E,f.redeem.output)}if(f.redeem&&f.redeem.output&&f.redeem.witness)return[].concat(f.redeem.witness,f.redeem.output)}),i.prop(m,"name",()=>{const E=["p2wsh"];return m.redeem!==void 0&&m.redeem.name!==void 0&&E.push(m.redeem.name),E.join("-")}),l.validate){let E=Buffer.from([]);if(f.address){if(d().prefix!==g.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(d().version!==0)throw new TypeError("Invalid address version");if(d().data.length!==32)throw new TypeError("Invalid address data");E=d().data}if(f.hash){if(E.length>0&&!E.equals(f.hash))throw new TypeError("Hash mismatch");E=f.hash}if(f.output){if(f.output.length!==34||f.output[0]!==o.OP_0||f.output[1]!==32)throw new TypeError("Output is invalid");const _=f.output.slice(2);if(E.length>0&&!E.equals(_))throw new TypeError("Hash mismatch");E=_}if(f.redeem){if(f.redeem.network&&f.redeem.network!==g)throw new TypeError("Network mismatch");if(f.redeem.input&&f.redeem.input.length>0&&f.redeem.witness&&f.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(f.redeem.output){const _=n.decompile(f.redeem.output);if(!_||_.length<1)throw new TypeError("Redeem.output is invalid");if(f.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(n.countNonPushOnlyOPs(_)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const S=e.sha256(f.redeem.output);if(E.length>0&&!E.equals(S))throw new TypeError("Hash mismatch");E=S}if(f.redeem.input&&!n.isPushOnly(y()))throw new TypeError("Non push-only scriptSig");if(f.witness&&f.redeem.witness&&!(0,r.stacksEqual)(f.witness,f.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(f.redeem.input&&y().some(a)||f.redeem.output&&(n.decompile(f.redeem.output)||[]).some(a))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(f.witness&&f.witness.length>0){const _=f.witness[f.witness.length-1];if(f.redeem&&f.redeem.output&&!f.redeem.output.equals(_))throw new TypeError("Witness and redeem.output mismatch");if(f.witness.some(a)||(n.decompile(_)||[]).some(a))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(m,f)}return lo.p2wsh=u,lo}var ho={},Ii={},gp;function Sh(){if(gp)return Ii;gp=1,Object.defineProperty(Ii,"__esModule",{value:!0}),Ii.getEccLib=Ii.initEccLib=void 0;const e={};function t(c,a){c?c!==e.eccLib&&(a?.DANGER_DO_NOT_VERIFY_ECCLIB||i(c),e.eccLib=c):e.eccLib=c}Ii.initEccLib=t;function n(){if(!e.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return e.eccLib}Ii.getEccLib=n;const r=c=>Buffer.from(c,"hex");function i(c){s(typeof c.isXOnlyPoint=="function"),s(c.isXOnlyPoint(r("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),s(c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),s(c.isXOnlyPoint(r("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),s(c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000001"))),s(!c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000000"))),s(!c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),s(typeof c.xOnlyPointAddTweak=="function"),o.forEach(a=>{const u=c.xOnlyPointAddTweak(r(a.pubkey),r(a.tweak));a.result===null?s(u===null):(s(u!==null),s(u.parity===a.parity),s(Buffer.from(u.xOnlyPubkey).equals(r(a.result))))})}function s(c){if(!c)throw new Error("ecc library invalid")}const o=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];return Ii}var Of={},kt={},Fc={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var mp;function Q8(){return mp||(mp=1,(function(e,t){var n=tc(),r=n.Buffer;function i(o,c){for(var a in o)c[a]=o[a]}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(i(n,t),t.Buffer=s);function s(o,c,a){return r(o,c,a)}s.prototype=Object.create(r.prototype),i(r,s),s.from=function(o,c,a){if(typeof o=="number")throw new TypeError("Argument must not be a number");return r(o,c,a)},s.alloc=function(o,c,a){if(typeof o!="number")throw new TypeError("Argument must be a number");var u=r(o);return c!==void 0?typeof a=="string"?u.fill(c,a):u.fill(c):u.fill(0),u},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n.SlowBuffer(o)}})(Fc,Fc.exports)),Fc.exports}var Bf,wp;function eA(){if(wp)return Bf;wp=1;var e=Q8().Buffer,t=9007199254740991;function n(o){if(o<0||o>t||o%1!==0)throw new RangeError("value out of range")}function r(o,c,a){if(n(o),c||(c=e.allocUnsafe(s(o))),!e.isBuffer(c))throw new TypeError("buffer must be a Buffer instance");return a||(a=0),o<253?(c.writeUInt8(o,a),r.bytes=1):o<=65535?(c.writeUInt8(253,a),c.writeUInt16LE(o,a+1),r.bytes=3):o<=4294967295?(c.writeUInt8(254,a),c.writeUInt32LE(o,a+1),r.bytes=5):(c.writeUInt8(255,a),c.writeUInt32LE(o>>>0,a+1),c.writeUInt32LE(o/4294967296|0,a+5),r.bytes=9),c}function i(o,c){if(!e.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");c||(c=0);var a=o.readUInt8(c);if(a<253)return i.bytes=1,a;if(a===253)return i.bytes=3,o.readUInt16LE(c+1);if(a===254)return i.bytes=5,o.readUInt32LE(c+1);i.bytes=9;var u=o.readUInt32LE(c+1),f=o.readUInt32LE(c+5),l=f*4294967296+u;return n(l),l}function s(o){return n(o),o<253?1:o<=65535?3:o<=4294967295?5:9}return Bf={encode:r,decode:i,encodingLength:s},Bf}var bp;function Eu(){if(bp)return kt;bp=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.BufferReader=kt.BufferWriter=kt.cloneBuffer=kt.reverseBuffer=kt.writeUInt64LE=kt.readUInt64LE=kt.varuint=void 0;const e=Xt(),{typeforce:t}=e,n=eA();kt.varuint=n;function r(f,l){if(typeof f!="number")throw new Error("cannot write a non-number as a number");if(f<0)throw new Error("specified a negative value for writing an unsigned value");if(f>l)throw new Error("RangeError: value out of range");if(Math.floor(f)!==f)throw new Error("value has a fractional component")}function i(f,l){const d=f.readUInt32LE(l);let y=f.readUInt32LE(l+4);return y*=4294967296,r(y+d,9007199254740991),y+d}kt.readUInt64LE=i;function s(f,l,d){return r(l,9007199254740991),f.writeInt32LE(l&-1,d),f.writeUInt32LE(Math.floor(l/4294967296),d+4),d+8}kt.writeUInt64LE=s;function o(f){if(f.length<1)return f;let l=f.length-1,d=0;for(let y=0;y<f.length/2;y++)d=f[y],f[y]=f[l],f[l]=d,l--;return f}kt.reverseBuffer=o;function c(f){const l=Buffer.allocUnsafe(f.length);return f.copy(l),l}kt.cloneBuffer=c;class a{static withCapacity(l){return new a(Buffer.alloc(l))}constructor(l,d=0){this.buffer=l,this.offset=d,t(e.tuple(e.Buffer,e.UInt32),[l,d])}writeUInt8(l){this.offset=this.buffer.writeUInt8(l,this.offset)}writeInt32(l){this.offset=this.buffer.writeInt32LE(l,this.offset)}writeUInt32(l){this.offset=this.buffer.writeUInt32LE(l,this.offset)}writeUInt64(l){this.offset=s(this.buffer,l,this.offset)}writeVarInt(l){n.encode(l,this.buffer,this.offset),this.offset+=n.encode.bytes}writeSlice(l){if(this.buffer.length<this.offset+l.length)throw new Error("Cannot write slice out of bounds");this.offset+=l.copy(this.buffer,this.offset)}writeVarSlice(l){this.writeVarInt(l.length),this.writeSlice(l)}writeVector(l){this.writeVarInt(l.length),l.forEach(d=>this.writeVarSlice(d))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}kt.BufferWriter=a;class u{constructor(l,d=0){this.buffer=l,this.offset=d,t(e.tuple(e.Buffer,e.UInt32),[l,d])}readUInt8(){const l=this.buffer.readUInt8(this.offset);return this.offset++,l}readInt32(){const l=this.buffer.readInt32LE(this.offset);return this.offset+=4,l}readUInt32(){const l=this.buffer.readUInt32LE(this.offset);return this.offset+=4,l}readUInt64(){const l=i(this.buffer,this.offset);return this.offset+=8,l}readVarInt(){const l=n.decode(this.buffer,this.offset);return this.offset+=n.decode.bytes,l}readSlice(l){if(this.buffer.length<this.offset+l)throw new Error("Cannot read slice out of bounds");const d=this.buffer.slice(this.offset,this.offset+l);return this.offset+=l,d}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const l=this.readVarInt(),d=[];for(let y=0;y<l;y++)d.push(this.readVarSlice());return d}}return kt.BufferReader=u,kt}var Ep;function Th(){return Ep||(Ep=1,(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=tc(),n=Sh(),r=Pr(),i=Eu(),s=Xt();e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=m=>"left"in m&&"right"in m;function c(m,E){if(m.length<33)throw new TypeError(`The control-block length is too small. Got ${m.length}, expected min 33.`);const _=(m.length-33)/32;let S=E;for(let w=0;w<_;w++){const T=m.slice(33+32*w,65+32*w);S.compare(T)<0?S=y(S,T):S=y(T,S)}return S}e.rootHashFromPath=c;function a(m){if((0,s.isTapleaf)(m))return{hash:f(m)};const E=[a(m[0]),a(m[1])];E.sort((w,T)=>w.hash.compare(T.hash));const[_,S]=E;return{hash:y(_.hash,S.hash),left:_,right:S}}e.toHashTree=a;function u(m,E){if(o(m)){const _=u(m.left,E);if(_!==void 0)return[..._,m.right.hash];const S=u(m.right,E);if(S!==void 0)return[...S,m.left.hash]}else if(m.hash.equals(E))return[]}e.findScriptPath=u;function f(m){const E=m.version||e.LEAF_VERSION_TAPSCRIPT;return r.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([E]),g(m.output)]))}e.tapleafHash=f;function l(m,E){return r.taggedHash("TapTweak",t.Buffer.concat(E?[m,E]:[m]))}e.tapTweakHash=l;function d(m,E){if(!t.Buffer.isBuffer(m)||m.length!==32||E&&E.length!==32)return null;const _=l(m,E),S=(0,n.getEccLib)().xOnlyPointAddTweak(m,_);return!S||S.xOnlyPubkey===null?null:{parity:S.parity,x:t.Buffer.from(S.xOnlyPubkey)}}e.tweakKey=d;function y(m,E){return r.taggedHash("TapBranch",t.Buffer.concat([m,E]))}function g(m){const E=i.varuint.encodingLength(m.length),_=t.Buffer.allocUnsafe(E);return i.varuint.encode(m.length,_),t.Buffer.concat([_,m])}})(Of)),Of}var _p;function tA(){if(_p)return ho;_p=1,Object.defineProperty(ho,"__esModule",{value:!0}),ho.p2tr=void 0;const e=tc(),t=Wn(),n=rn(),r=Xt(),i=Sh(),s=Th(),o=gi(),c=ac(),a=xh(),u=n.OPS,f=1,l=80;function d(y,g){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");g=Object.assign({validate:!0},g||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(34)),internalPubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),pubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),signature:r.typeforce.maybe(r.typeforce.anyOf(r.typeforce.BufferN(64),r.typeforce.BufferN(65))),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer)),scriptTree:r.typeforce.maybe(r.isTaptree),redeem:r.typeforce.maybe({output:r.typeforce.maybe(r.typeforce.Buffer),redeemVersion:r.typeforce.maybe(r.typeforce.Number),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),redeemVersion:r.typeforce.maybe(r.typeforce.Number)},y);const m=o.value(()=>(0,a.fromBech32)(y.address)),E=o.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===l?y.witness.slice(0,-1):y.witness.slice()}),_=o.value(()=>{if(y.scriptTree)return(0,s.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),S=y.network||t.bitcoin,w={name:"p2tr",network:S};if(o.prop(w,"address",()=>{if(!w.pubkey)return;const T=c.bech32m.toWords(w.pubkey);return T.unshift(f),c.bech32m.encode(S.bech32,T)}),o.prop(w,"hash",()=>{const T=_();if(T)return T.hash;const O=E();if(O&&O.length>1){const A=O[O.length-1],R=A[0]&r.TAPLEAF_VERSION_MASK,M=O[O.length-2],v=(0,s.tapleafHash)({output:M,version:R});return(0,s.rootHashFromPath)(A,v)}return null}),o.prop(w,"output",()=>{if(w.pubkey)return n.compile([u.OP_1,w.pubkey])}),o.prop(w,"redeemVersion",()=>y.redeemVersion?y.redeemVersion:y.redeem&&y.redeem.redeemVersion!==void 0&&y.redeem.redeemVersion!==null?y.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(w,"redeem",()=>{const T=E();if(!(!T||T.length<2))return{output:T[T.length-2],witness:T.slice(0,-2),redeemVersion:T[T.length-1][0]&r.TAPLEAF_VERSION_MASK}}),o.prop(w,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return m().data;if(w.internalPubkey){const T=(0,s.tweakKey)(w.internalPubkey,w.hash);if(T)return T.x}}),o.prop(w,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const T=E();if(T&&T.length>1)return T[T.length-1].slice(1,33)}),o.prop(w,"signature",()=>{if(y.signature)return y.signature;const T=E();if(!(!T||T.length!==1))return T[0]}),o.prop(w,"witness",()=>{if(y.witness)return y.witness;const T=_();if(T&&y.redeem&&y.redeem.output&&y.internalPubkey){const O=(0,s.tapleafHash)({output:y.redeem.output,version:w.redeemVersion}),A=(0,s.findScriptPath)(T,O);if(!A)return;const R=(0,s.tweakKey)(y.internalPubkey,T.hash);if(!R)return;const M=e.Buffer.concat([e.Buffer.from([w.redeemVersion|R.parity]),y.internalPubkey].concat(A));return[y.redeem.output,M]}if(y.signature)return[y.signature]}),g.validate){let T=e.Buffer.from([]);if(y.address){if(S&&S.bech32!==m().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(m().version!==f)throw new TypeError("Invalid address version");if(m().data.length!==32)throw new TypeError("Invalid address data");T=m().data}if(y.pubkey){if(T.length>0&&!T.equals(y.pubkey))throw new TypeError("Pubkey mismatch");T=y.pubkey}if(y.output){if(y.output.length!==34||y.output[0]!==u.OP_1||y.output[1]!==32)throw new TypeError("Output is invalid");if(T.length>0&&!T.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");T=y.output.slice(2)}if(y.internalPubkey){const R=(0,s.tweakKey)(y.internalPubkey,w.hash);if(T.length>0&&!T.equals(R.x))throw new TypeError("Pubkey mismatch");T=R.x}if(T&&T.length&&!(0,i.getEccLib)().isXOnlyPoint(T))throw new TypeError("Invalid pubkey for p2tr");const O=_();if(y.hash&&O&&!y.hash.equals(O.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&O){const R=(0,s.tapleafHash)({output:y.redeem.output,version:w.redeemVersion});if(!(0,s.findScriptPath)(O,R))throw new TypeError("Redeem script not in tree")}const A=E();if(y.redeem&&w.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==w.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(y.redeem.output){if(n.decompile(y.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(w.redeem.output&&!y.redeem.output.equals(w.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&w.redeem.witness&&!(0,r.stacksEqual)(y.redeem.witness,w.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(A&&A.length)if(A.length===1){if(y.signature&&!y.signature.equals(A[0]))throw new TypeError("Signature mismatch")}else{const R=A[A.length-1];if(R.length<33)throw new TypeError(`The control-block length is too small. Got ${R.length}, expected min 33.`);if((R.length-33)%32!==0)throw new TypeError(`The control-block length of ${R.length} is incorrect!`);const M=(R.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const v=R.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(v))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid internalPubkey for p2tr witness");const U=R[0]&r.TAPLEAF_VERSION_MASK,V=A[A.length-2],K=(0,s.tapleafHash)({output:V,version:U}),H=(0,s.rootHashFromPath)(R,K),$=(0,s.tweakKey)(v,H);if(!$)throw new TypeError("Invalid outputKey for p2tr witness");if(T.length&&!T.equals($.x))throw new TypeError("Pubkey mismatch for p2tr witness");if($.parity!==(R[0]&1))throw new Error("Incorrect parity")}}return Object.assign(w,y)}return ho.p2tr=d,ho}var Sp;function Ec(){return Sp||(Sp=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=L8();Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const n=$8();Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return n.p2ms}});const r=D8();Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return r.p2pk}});const i=z8();Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=Y8();Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=Z8();Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const c=J8();Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return c.p2wsh}});const a=tA();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return a.p2tr}})})(gf)),gf}var Tp;function xh(){if(Tp)return Yt;Tp=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.toOutputScript=Yt.fromOutputScript=Yt.toBech32=Yt.toBase58Check=Yt.fromBech32=Yt.fromBase58Check=void 0;const e=Wn(),t=Ec(),n=rn(),r=Xt(),i=ac(),s=_h(),o=40,c=2,a=16,u=2,f=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 d(w,T){const O=w.slice(2);if(O.length<c||O.length>o)throw new TypeError("Invalid program length for segwit address");const A=w[0]-f;if(A<u||A>a)throw new TypeError("Invalid version for segwit address");if(w[1]!==O.length)throw new TypeError("Invalid script for segwit address");return console.warn(l),E(O,A,T.bech32)}function y(w){const T=Buffer.from(s.decode(w));if(T.length<21)throw new TypeError(w+" is too short");if(T.length>21)throw new TypeError(w+" is too long");const O=T.readUInt8(0),A=T.slice(1);return{version:O,hash:A}}Yt.fromBase58Check=y;function g(w){let T,O;try{T=i.bech32.decode(w)}catch{}if(T){if(O=T.words[0],O!==0)throw new TypeError(w+" uses wrong encoding")}else if(T=i.bech32m.decode(w),O=T.words[0],O===0)throw new TypeError(w+" uses wrong encoding");const A=i.bech32.fromWords(T.words.slice(1));return{version:O,prefix:T.prefix,data:Buffer.from(A)}}Yt.fromBech32=g;function m(w,T){(0,r.typeforce)((0,r.tuple)(r.Hash160bit,r.UInt8),arguments);const O=Buffer.allocUnsafe(21);return O.writeUInt8(T,0),w.copy(O,1),s.encode(O)}Yt.toBase58Check=m;function E(w,T,O){const A=i.bech32.toWords(w);return A.unshift(T),T===0?i.bech32.encode(O,A):i.bech32m.encode(O,A)}Yt.toBech32=E;function _(w,T){T=T||e.bitcoin;try{return t.p2pkh({output:w,network:T}).address}catch{}try{return t.p2sh({output:w,network:T}).address}catch{}try{return t.p2wpkh({output:w,network:T}).address}catch{}try{return t.p2wsh({output:w,network:T}).address}catch{}try{return t.p2tr({output:w,network:T}).address}catch{}try{return d(w,T)}catch{}throw new Error(n.toASM(w)+" has no matching Address")}Yt.fromOutputScript=_;function S(w,T){T=T||e.bitcoin;let O,A;try{O=y(w)}catch{}if(O){if(O.version===T.pubKeyHash)return t.p2pkh({hash:O.hash}).output;if(O.version===T.scriptHash)return t.p2sh({hash:O.hash}).output}else{try{A=g(w)}catch{}if(A){if(A.prefix!==T.bech32)throw new Error(w+" has an invalid prefix");if(A.version===0){if(A.data.length===20)return t.p2wpkh({hash:A.data}).output;if(A.data.length===32)return t.p2wsh({hash:A.data}).output}else if(A.version===1){if(A.data.length===32)return t.p2tr({pubkey:A.data}).output}else if(A.version>=u&&A.version<=a&&A.data.length>=c&&A.data.length<=o)return console.warn(l),n.compile([A.version+f,A.data])}}throw new Error(w+" has no matching Script")}return Yt.toOutputScript=S,Yt}var po={},yo={},xp;function nA(){if(xp)return yo;xp=1,Object.defineProperty(yo,"__esModule",{value:!0}),yo.fastMerkleRoot=void 0;function e(t,n){if(!Array.isArray(t))throw TypeError("Expected values Array");if(typeof n!="function")throw TypeError("Expected digest Function");let r=t.length;const i=t.concat();for(;r>1;){let s=0;for(let o=0;o<r;o+=2,++s){const c=i[o],a=o+1===r?c:i[o+1],u=Buffer.concat([c,a]);i[s]=n(u)}r=s}return i[0]}return yo.fastMerkleRoot=e,yo}var go={},Ap;function _c(){if(Ap)return go;Ap=1,Object.defineProperty(go,"__esModule",{value:!0}),go.Transaction=void 0;const e=Eu(),t=Pr(),n=rn(),r=rn(),i=Xt(),{typeforce:s}=i;function o(E){const _=E.length;return e.varuint.encodingLength(_)+_}function c(E){const _=E.length;return e.varuint.encodingLength(_)+E.reduce((S,w)=>S+o(w),0)}const a=Buffer.allocUnsafe(0),u=[],f=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),l=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),d=Buffer.from("ffffffffffffffff","hex"),y={script:a,valueBuffer:d};function g(E){return E.value!==void 0}class m{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(_,S){const w=new e.BufferReader(_),T=new m;T.version=w.readInt32();const O=w.readUInt8(),A=w.readUInt8();let R=!1;O===m.ADVANCED_TRANSACTION_MARKER&&A===m.ADVANCED_TRANSACTION_FLAG?R=!0:w.offset-=2;const M=w.readVarInt();for(let U=0;U<M;++U)T.ins.push({hash:w.readSlice(32),index:w.readUInt32(),script:w.readVarSlice(),sequence:w.readUInt32(),witness:u});const v=w.readVarInt();for(let U=0;U<v;++U)T.outs.push({value:w.readUInt64(),script:w.readVarSlice()});if(R){for(let U=0;U<M;++U)T.ins[U].witness=w.readVector();if(!T.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(T.locktime=w.readUInt32(),S)return T;if(w.offset!==_.length)throw new Error("Transaction has unexpected data");return T}static fromHex(_){return m.fromBuffer(Buffer.from(_,"hex"),!1)}static isCoinbaseHash(_){s(i.Hash256bit,_);for(let S=0;S<32;++S)if(_[S]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&m.isCoinbaseHash(this.ins[0].hash)}addInput(_,S,w,T){return s(i.tuple(i.Hash256bit,i.UInt32,i.maybe(i.UInt32),i.maybe(i.Buffer)),arguments),i.Null(w)&&(w=m.DEFAULT_SEQUENCE),this.ins.push({hash:_,index:S,script:T||a,sequence:w,witness:u})-1}addOutput(_,S){return s(i.tuple(i.Buffer,i.Satoshi),arguments),this.outs.push({script:_,value:S})-1}hasWitnesses(){return this.ins.some(_=>_.witness.length!==0)}stripWitnesses(){this.ins.forEach(_=>{_.witness=u})}weight(){const _=this.byteLength(!1),S=this.byteLength(!0);return _*3+S}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(_=!0){const S=_&&this.hasWitnesses();return(S?10:8)+e.varuint.encodingLength(this.ins.length)+e.varuint.encodingLength(this.outs.length)+this.ins.reduce((w,T)=>w+40+o(T.script),0)+this.outs.reduce((w,T)=>w+8+o(T.script),0)+(S?this.ins.reduce((w,T)=>w+c(T.witness),0):0)}clone(){const _=new m;return _.version=this.version,_.locktime=this.locktime,_.ins=this.ins.map(S=>({hash:S.hash,index:S.index,script:S.script,sequence:S.sequence,witness:S.witness})),_.outs=this.outs.map(S=>({script:S.script,value:S.value})),_}hashForSignature(_,S,w){if(s(i.tuple(i.UInt32,i.Buffer,i.Number),arguments),_>=this.ins.length)return l;const T=n.compile(n.decompile(S).filter(R=>R!==r.OPS.OP_CODESEPARATOR)),O=this.clone();if((w&31)===m.SIGHASH_NONE)O.outs=[],O.ins.forEach((R,M)=>{M!==_&&(R.sequence=0)});else if((w&31)===m.SIGHASH_SINGLE){if(_>=this.outs.length)return l;O.outs.length=_+1;for(let R=0;R<_;R++)O.outs[R]=y;O.ins.forEach((R,M)=>{M!==_&&(R.sequence=0)})}w&m.SIGHASH_ANYONECANPAY?(O.ins=[O.ins[_]],O.ins[0].script=T):(O.ins.forEach(R=>{R.script=a}),O.ins[_].script=T);const A=Buffer.allocUnsafe(O.byteLength(!1)+4);return A.writeInt32LE(w,A.length-4),O.__toBuffer(A,0,!1),t.hash256(A)}hashForWitnessV1(_,S,w,T,O,A){if(s(i.tuple(i.UInt32,s.arrayOf(i.Buffer),s.arrayOf(i.Satoshi),i.UInt32),arguments),w.length!==this.ins.length||S.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const R=T===m.SIGHASH_DEFAULT?m.SIGHASH_ALL:T&m.SIGHASH_OUTPUT_MASK,v=(T&m.SIGHASH_INPUT_MASK)===m.SIGHASH_ANYONECANPAY,U=R===m.SIGHASH_NONE,V=R===m.SIGHASH_SINGLE;let K=a,H=a,$=a,P=a,D=a;if(!v){let q=e.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(N=>{q.writeSlice(N.hash),q.writeUInt32(N.index)}),K=t.sha256(q.end()),q=e.BufferWriter.withCapacity(8*this.ins.length),w.forEach(N=>q.writeUInt64(N)),H=t.sha256(q.end()),q=e.BufferWriter.withCapacity(S.map(o).reduce((N,L)=>N+L)),S.forEach(N=>q.writeVarSlice(N)),$=t.sha256(q.end()),q=e.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(N=>q.writeUInt32(N.sequence)),P=t.sha256(q.end())}if(U||V){if(V&&_<this.outs.length){const q=this.outs[_],N=e.BufferWriter.withCapacity(8+o(q.script));N.writeUInt64(q.value),N.writeVarSlice(q.script),D=t.sha256(N.end())}}else{const q=this.outs.map(L=>8+o(L.script)).reduce((L,G)=>L+G),N=e.BufferWriter.withCapacity(q);this.outs.forEach(L=>{N.writeUInt64(L.value),N.writeVarSlice(L.script)}),D=t.sha256(N.end())}const F=(O?2:0)+(A?1:0),x=174-(v?49:0)-(U?32:0)+(A?32:0)+(O?37:0),B=e.BufferWriter.withCapacity(x);if(B.writeUInt8(T),B.writeInt32(this.version),B.writeUInt32(this.locktime),B.writeSlice(K),B.writeSlice(H),B.writeSlice($),B.writeSlice(P),U||V||B.writeSlice(D),B.writeUInt8(F),v){const q=this.ins[_];B.writeSlice(q.hash),B.writeUInt32(q.index),B.writeUInt64(w[_]),B.writeVarSlice(S[_]),B.writeUInt32(q.sequence)}else B.writeUInt32(_);if(A){const q=e.BufferWriter.withCapacity(o(A));q.writeVarSlice(A),B.writeSlice(t.sha256(q.end()))}return V&&B.writeSlice(D),O&&(B.writeSlice(O),B.writeUInt8(0),B.writeUInt32(4294967295)),t.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),B.end()]))}hashForWitnessV0(_,S,w,T){s(i.tuple(i.UInt32,i.Buffer,i.Satoshi,i.UInt32),arguments);let O=Buffer.from([]),A,R=f,M=f,v=f;if(T&m.SIGHASH_ANYONECANPAY||(O=Buffer.allocUnsafe(36*this.ins.length),A=new e.BufferWriter(O,0),this.ins.forEach(V=>{A.writeSlice(V.hash),A.writeUInt32(V.index)}),M=t.hash256(O)),!(T&m.SIGHASH_ANYONECANPAY)&&(T&31)!==m.SIGHASH_SINGLE&&(T&31)!==m.SIGHASH_NONE&&(O=Buffer.allocUnsafe(4*this.ins.length),A=new e.BufferWriter(O,0),this.ins.forEach(V=>{A.writeUInt32(V.sequence)}),v=t.hash256(O)),(T&31)!==m.SIGHASH_SINGLE&&(T&31)!==m.SIGHASH_NONE){const V=this.outs.reduce((K,H)=>K+8+o(H.script),0);O=Buffer.allocUnsafe(V),A=new e.BufferWriter(O,0),this.outs.forEach(K=>{A.writeUInt64(K.value),A.writeVarSlice(K.script)}),R=t.hash256(O)}else if((T&31)===m.SIGHASH_SINGLE&&_<this.outs.length){const V=this.outs[_];O=Buffer.allocUnsafe(8+o(V.script)),A=new e.BufferWriter(O,0),A.writeUInt64(V.value),A.writeVarSlice(V.script),R=t.hash256(O)}O=Buffer.allocUnsafe(156+o(S)),A=new e.BufferWriter(O,0);const U=this.ins[_];return A.writeInt32(this.version),A.writeSlice(M),A.writeSlice(v),A.writeSlice(U.hash),A.writeUInt32(U.index),A.writeVarSlice(S),A.writeUInt64(w),A.writeUInt32(U.sequence),A.writeSlice(R),A.writeUInt32(this.locktime),A.writeUInt32(T),t.hash256(O)}getHash(_){return _&&this.isCoinbase()?Buffer.alloc(32,0):t.hash256(this.__toBuffer(void 0,void 0,_))}getId(){return(0,e.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(_,S){return this.__toBuffer(_,S,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(_,S){s(i.tuple(i.Number,i.Buffer),arguments),this.ins[_].script=S}setWitness(_,S){s(i.tuple(i.Number,[i.Buffer]),arguments),this.ins[_].witness=S}__toBuffer(_,S,w=!1){_||(_=Buffer.allocUnsafe(this.byteLength(w)));const T=new e.BufferWriter(_,S||0);T.writeInt32(this.version);const O=w&&this.hasWitnesses();return O&&(T.writeUInt8(m.ADVANCED_TRANSACTION_MARKER),T.writeUInt8(m.ADVANCED_TRANSACTION_FLAG)),T.writeVarInt(this.ins.length),this.ins.forEach(A=>{T.writeSlice(A.hash),T.writeUInt32(A.index),T.writeVarSlice(A.script),T.writeUInt32(A.sequence)}),T.writeVarInt(this.outs.length),this.outs.forEach(A=>{g(A)?T.writeUInt64(A.value):T.writeSlice(A.valueBuffer),T.writeVarSlice(A.script)}),O&&this.ins.forEach(A=>{T.writeVector(A.witness)}),T.writeUInt32(this.locktime),S!==void 0?_.slice(S,T.offset):_}}return go.Transaction=m,m.DEFAULT_SEQUENCE=4294967295,m.SIGHASH_DEFAULT=0,m.SIGHASH_ALL=1,m.SIGHASH_NONE=2,m.SIGHASH_SINGLE=3,m.SIGHASH_ANYONECANPAY=128,m.SIGHASH_OUTPUT_MASK=3,m.SIGHASH_INPUT_MASK=128,m.ADVANCED_TRANSACTION_MARKER=0,m.ADVANCED_TRANSACTION_FLAG=1,go}var vp;function rA(){if(vp)return po;vp=1,Object.defineProperty(po,"__esModule",{value:!0}),po.Block=void 0;const e=Eu(),t=Pr(),n=nA(),r=_c(),i=Xt(),{typeforce:s}=i,o=new TypeError("Cannot compute merkle root for zero transactions"),c=new TypeError("Cannot compute witness commit for non-segwit block");class a{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(d){if(d.length<80)throw new Error("Buffer too small (< 80 bytes)");const y=new e.BufferReader(d),g=new a;if(g.version=y.readInt32(),g.prevHash=y.readSlice(32),g.merkleRoot=y.readSlice(32),g.timestamp=y.readUInt32(),g.bits=y.readUInt32(),g.nonce=y.readUInt32(),d.length===80)return g;const m=()=>{const S=r.Transaction.fromBuffer(y.buffer.slice(y.offset),!0);return y.offset+=S.byteLength(),S},E=y.readVarInt();g.transactions=[];for(let S=0;S<E;++S){const w=m();g.transactions.push(w)}const _=g.getWitnessCommit();return _&&(g.witnessCommit=_),g}static fromHex(d){return a.fromBuffer(Buffer.from(d,"hex"))}static calculateTarget(d){const y=((d&4278190080)>>24)-3,g=d&8388607,m=Buffer.alloc(32,0);return m.writeUIntBE(g,29-y,3),m}static calculateMerkleRoot(d,y){if(s([{getHash:i.Function}],d),d.length===0)throw o;if(y&&!u(d))throw c;const g=d.map(E=>E.getHash(y)),m=(0,n.fastMerkleRoot)(g,t.hash256);return y?t.hash256(Buffer.concat([m,d[0].ins[0].witness[0]])):m}getWitnessCommit(){if(!u(this.transactions))return null;const d=this.transactions[0].outs.filter(g=>g.script.slice(0,6).equals(Buffer.from("6a24aa21a9ed","hex"))).map(g=>g.script.slice(6,38));if(d.length===0)return null;const y=d[d.length-1];return y instanceof Buffer&&y.length===32?y:null}hasWitnessCommit(){return this.witnessCommit instanceof Buffer&&this.witnessCommit.length===32||this.getWitnessCommit()!==null}hasWitness(){return f(this.transactions)}weight(){const d=this.byteLength(!1,!1),y=this.byteLength(!1,!0);return d*3+y}byteLength(d,y=!0){return d||!this.transactions?80:80+e.varuint.encodingLength(this.transactions.length)+this.transactions.reduce((g,m)=>g+m.byteLength(y),0)}getHash(){return t.hash256(this.toBuffer(!0))}getId(){return(0,e.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const d=new Date(0);return d.setUTCSeconds(this.timestamp),d}toBuffer(d){const y=Buffer.allocUnsafe(this.byteLength(d)),g=new e.BufferWriter(y);return g.writeInt32(this.version),g.writeSlice(this.prevHash),g.writeSlice(this.merkleRoot),g.writeUInt32(this.timestamp),g.writeUInt32(this.bits),g.writeUInt32(this.nonce),d||!this.transactions||(e.varuint.encode(this.transactions.length,y,g.offset),g.offset+=e.varuint.encode.bytes,this.transactions.forEach(m=>{const E=m.byteLength();m.toBuffer(y,g.offset),g.offset+=E})),y}toHex(d){return this.toBuffer(d).toString("hex")}checkTxRoots(){const d=this.hasWitnessCommit();return!d&&this.hasWitness()?!1:this.__checkMerkleRoot()&&(d?this.__checkWitnessCommit():!0)}checkProofOfWork(){const d=(0,e.reverseBuffer)(this.getHash()),y=a.calculateTarget(this.bits);return d.compare(y)<=0}__checkMerkleRoot(){if(!this.transactions)throw o;const d=a.calculateMerkleRoot(this.transactions);return this.merkleRoot.compare(d)===0}__checkWitnessCommit(){if(!this.transactions)throw o;if(!this.hasWitnessCommit())throw c;const d=a.calculateMerkleRoot(this.transactions,!0);return this.witnessCommit.compare(d)===0}}po.Block=a;function u(l){return l instanceof Array&&l[0]&&l[0].ins&&l[0].ins instanceof Array&&l[0].ins[0]&&l[0].ins[0].witness&&l[0].ins[0].witness instanceof Array&&l[0].ins[0].witness.length>0}function f(l){return l instanceof Array&&l.some(d=>typeof d=="object"&&d.ins instanceof Array&&d.ins.some(y=>typeof y=="object"&&y.witness instanceof Array&&y.witness.length>0))}return po}var mo={},Mc={},qc={},Nf={},cs={},as={},kf={},Ip;function Mt(){return Ip||(Ip=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),(function(t){t[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(e.GlobalTypes||(e.GlobalTypes={})),e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(function(t){t[t.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",t[t.WITNESS_UTXO=1]="WITNESS_UTXO",t[t.PARTIAL_SIG=2]="PARTIAL_SIG",t[t.SIGHASH_TYPE=3]="SIGHASH_TYPE",t[t.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=6]="BIP32_DERIVATION",t[t.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",t[t.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",t[t.POR_COMMITMENT=9]="POR_COMMITMENT",t[t.TAP_KEY_SIG=19]="TAP_KEY_SIG",t[t.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",t[t.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",t[t.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",t[t.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(function(t){t[t.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=2]="BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",t[t.TAP_TREE=6]="TAP_TREE",t[t.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]})(kf)),kf}var Vr={},Op;function iA(){if(Op)return Vr;Op=1,Object.defineProperty(Vr,"__esModule",{value:!0});const e=Mt(),t=o=>[...Array(o).keys()];function n(o){if(o.key[0]!==e.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+o.key.toString("hex"));if(o.key.length!==79||![2,3].includes(o.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+o.key.toString("hex"));if(o.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const c=o.key.slice(1),a={masterFingerprint:o.value.slice(0,4),extendedPubkey:c,path:"m"};for(const u of t(o.value.length/4-1)){const f=o.value.readUInt32LE(u*4+4),l=!!(f&2147483648),d=f&2147483647;a.path+="/"+d.toString(10)+(l?"'":"")}return a}Vr.decode=n;function r(o){const c=Buffer.from([e.GlobalTypes.GLOBAL_XPUB]),a=Buffer.concat([c,o.extendedPubkey]),u=o.path.split("/"),f=Buffer.allocUnsafe(u.length*4);o.masterFingerprint.copy(f,0);let l=4;return u.slice(1).forEach(d=>{const y=d.slice(-1)==="'";let g=2147483647&parseInt(y?d.slice(0,-1):d,10);y&&(g+=2147483648),f.writeUInt32LE(g,l),l+=4}),{key:a,value:f}}Vr.encode=r,Vr.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";function i(o){const c=o.extendedPubkey,a=o.masterFingerprint,u=o.path;return Buffer.isBuffer(c)&&c.length===78&&[2,3].indexOf(c[45])>-1&&Buffer.isBuffer(a)&&a.length===4&&typeof u=="string"&&!!u.match(/^m(\/\d+'?)*$/)}Vr.check=i;function s(o,c,a){const u=c.extendedPubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(f=>f.extendedPubkey.equals(c.extendedPubkey)).length===0)}return Vr.canAddToArray=s,Vr}var Vc={},Bp;function sA(){if(Bp)return Vc;Bp=1,Object.defineProperty(Vc,"__esModule",{value:!0});const e=Mt();function t(n){return{key:Buffer.from([e.GlobalTypes.UNSIGNED_TX]),value:n.toBuffer()}}return Vc.encode=t,Vc}var Lr={},Np;function oA(){if(Np)return Lr;Np=1,Object.defineProperty(Lr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+s.key.toString("hex"));return s.value}Lr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTSIG]),value:s}}Lr.encode=n,Lr.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Lr.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptSig===void 0}return Lr.canAdd=i,Lr}var $r={},kp;function cA(){if(kp)return $r;kp=1,Object.defineProperty($r,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+s.key.toString("hex"));return s.value}$r.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTWITNESS]),value:s}}$r.encode=n,$r.expected="Buffer";function r(s){return Buffer.isBuffer(s)}$r.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptWitness===void 0}return $r.canAdd=i,$r}var Dr={},Pp;function aA(){if(Pp)return Dr;Pp=1,Object.defineProperty(Dr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+s.key.toString("hex"));return s.value}Dr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.NON_WITNESS_UTXO]),value:s}}Dr.encode=n,Dr.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Dr.check=r;function i(s,o){return!!s&&!!o&&s.nonWitnessUtxo===void 0}return Dr.canAdd=i,Dr}var jr={},Rp;function uA(){if(Rp)return jr;Rp=1,Object.defineProperty(jr,"__esModule",{value:!0});const e=Mt();function t(o){if(o.key[0]!==e.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+o.key.toString("hex"));if(!(o.key.length===34||o.key.length===66)||![2,3,4].includes(o.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+o.key.toString("hex"));return{pubkey:o.key.slice(1),signature:o.value}}jr.decode=t;function n(o){const c=Buffer.from([e.InputTypes.PARTIAL_SIG]);return{key:Buffer.concat([c,o.pubkey]),value:o.signature}}jr.encode=n,jr.expected="{ pubkey: Buffer; signature: Buffer; }";function r(o){return Buffer.isBuffer(o.pubkey)&&Buffer.isBuffer(o.signature)&&[33,65].includes(o.pubkey.length)&&[2,3,4].includes(o.pubkey[0])&&i(o.signature)}jr.check=r;function i(o){if(!Buffer.isBuffer(o)||o.length<9||o[0]!==48||o.length!==o[1]+3||o[2]!==2)return!1;const c=o[3];if(c>33||c<1||o[3+c+1]!==2)return!1;const a=o[3+c+2];return!(a>33||a<1||o.length!==3+c+2+a+2)}function s(o,c,a){const u=c.pubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(f=>f.pubkey.equals(c.pubkey)).length===0)}return jr.canAddToArray=s,jr}var Kr={},Up;function fA(){if(Up)return Kr;Up=1,Object.defineProperty(Kr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+s.key.toString("hex"));return s.value.toString("utf8")}Kr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.POR_COMMITMENT]),value:Buffer.from(s,"utf8")}}Kr.encode=n,Kr.expected="string";function r(s){return typeof s=="string"}Kr.check=r;function i(s,o){return!!s&&!!o&&s.porCommitment===void 0}return Kr.canAdd=i,Kr}var Gr={},Cp;function lA(){if(Cp)return Gr;Cp=1,Object.defineProperty(Gr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+s.key.toString("hex"));return s.value.readUInt32LE(0)}Gr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.SIGHASH_TYPE]),c=Buffer.allocUnsafe(4);return c.writeUInt32LE(s,0),{key:o,value:c}}Gr.encode=n,Gr.expected="number";function r(s){return typeof s=="number"}Gr.check=r;function i(s,o){return!!s&&!!o&&s.sighashType===void 0}return Gr.canAdd=i,Gr}var Wr={},Hp;function hA(){if(Hp)return Wr;Hp=1,Object.defineProperty(Wr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.TAP_KEY_SIG||s.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return s.value}Wr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_KEY_SIG]),value:s}}Wr.encode=n,Wr.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&(s.length===64||s.length===65)}Wr.check=r;function i(s,o){return!!s&&!!o&&s.tapKeySig===void 0}return Wr.canAdd=i,Wr}var Xr={},Fp;function dA(){if(Fp)return Xr;Fp=1,Object.defineProperty(Xr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+s.key.toString("hex"));if((s.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+s.key.toString("hex"));const o=s.value[s.value.length-1];if((s.key[1]&254)!==o)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+s.key.toString("hex"));const c=s.value.slice(0,-1);return{controlBlock:s.key.slice(1),script:c,leafVersion:o}}Xr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_LEAF_SCRIPT]),c=Buffer.from([s.leafVersion]);return{key:Buffer.concat([o,s.controlBlock]),value:Buffer.concat([s.script,c])}}Xr.encode=n,Xr.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";function r(s){return Buffer.isBuffer(s.controlBlock)&&(s.controlBlock.length-1)%32===0&&(s.controlBlock[0]&254)===s.leafVersion&&Buffer.isBuffer(s.script)}Xr.check=r;function i(s,o,c){const a=o.controlBlock.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.controlBlock.equals(o.controlBlock)).length===0)}return Xr.canAddToArray=i,Xr}var zr={},Mp;function pA(){if(Mp)return zr;Mp=1,Object.defineProperty(zr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.TAP_MERKLE_ROOT||s.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return s.value}zr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_MERKLE_ROOT]),value:s}}zr.encode=n,zr.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&s.length===32}zr.check=r;function i(s,o){return!!s&&!!o&&s.tapMerkleRoot===void 0}return zr.canAdd=i,zr}var Yr={},qp;function yA(){if(qp)return Yr;qp=1,Object.defineProperty(Yr,"__esModule",{value:!0});const e=Mt();function t(s){if(s.key[0]!==e.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+s.key.toString("hex"));if(s.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+s.key.toString("hex"));if(s.value.length!==64&&s.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+s.key.toString("hex"));const o=s.key.slice(1,33),c=s.key.slice(33);return{pubkey:o,leafHash:c,signature:s.value}}Yr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_SCRIPT_SIG]);return{key:Buffer.concat([o,s.pubkey,s.leafHash]),value:s.signature}}Yr.encode=n,Yr.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";function r(s){return Buffer.isBuffer(s.pubkey)&&Buffer.isBuffer(s.leafHash)&&Buffer.isBuffer(s.signature)&&s.pubkey.length===32&&s.leafHash.length===32&&(s.signature.length===64||s.signature.length===65)}Yr.check=r;function i(s,o,c){const a=o.pubkey.toString("hex")+o.leafHash.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.pubkey.equals(o.pubkey)&&u.leafHash.equals(o.leafHash)).length===0)}return Yr.canAddToArray=i,Yr}var Zr={},lr={},us={},Vp;function ts(){if(Vp)return us;Vp=1,Object.defineProperty(us,"__esModule",{value:!0});const e=9007199254740991;function t(s){if(s<0||s>e||s%1!==0)throw new RangeError("value out of range")}function n(s,o,c){if(t(s),o||(o=Buffer.allocUnsafe(i(s))),!Buffer.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");return c||(c=0),s<253?(o.writeUInt8(s,c),Object.assign(n,{bytes:1})):s<=65535?(o.writeUInt8(253,c),o.writeUInt16LE(s,c+1),Object.assign(n,{bytes:3})):s<=4294967295?(o.writeUInt8(254,c),o.writeUInt32LE(s,c+1),Object.assign(n,{bytes:5})):(o.writeUInt8(255,c),o.writeUInt32LE(s>>>0,c+1),o.writeUInt32LE(s/4294967296|0,c+5),Object.assign(n,{bytes:9})),o}us.encode=n;function r(s,o){if(!Buffer.isBuffer(s))throw new TypeError("buffer must be a Buffer instance");o||(o=0);const c=s.readUInt8(o);if(c<253)return Object.assign(r,{bytes:1}),c;if(c===253)return Object.assign(r,{bytes:3}),s.readUInt16LE(o+1);if(c===254)return Object.assign(r,{bytes:5}),s.readUInt32LE(o+1);{Object.assign(r,{bytes:9});const a=s.readUInt32LE(o+1),f=s.readUInt32LE(o+5)*4294967296+a;return t(f),f}}us.decode=r;function i(s){return t(s),s<253?1:s<=65535?3:s<=4294967295?5:9}return us.encodingLength=i,us}var Lp;function Ah(){if(Lp)return lr;Lp=1,Object.defineProperty(lr,"__esModule",{value:!0});const e=ts();lr.range=c=>[...Array(c).keys()];function t(c){if(c.length<1)return c;let a=c.length-1,u=0;for(let f=0;f<c.length/2;f++)u=c[f],c[f]=c[a],c[a]=u,a--;return c}lr.reverseBuffer=t;function n(c){const a=c.map(r);return a.push(Buffer.from([0])),Buffer.concat(a)}lr.keyValsToBuffer=n;function r(c){const a=c.key.length,u=c.value.length,f=e.encodingLength(a),l=e.encodingLength(u),d=Buffer.allocUnsafe(f+a+l+u);return e.encode(a,d,0),c.key.copy(d,f),e.encode(u,d,f+a),c.value.copy(d,f+a+l),d}lr.keyValToBuffer=r;function i(c,a){if(typeof c!="number")throw new Error("cannot write a non-number as a number");if(c<0)throw new Error("specified a negative value for writing an unsigned value");if(c>a)throw new Error("RangeError: value out of range");if(Math.floor(c)!==c)throw new Error("value has a fractional component")}function s(c,a){const u=c.readUInt32LE(a);let f=c.readUInt32LE(a+4);return f*=4294967296,i(f+u,9007199254740991),f+u}lr.readUInt64LE=s;function o(c,a,u){return i(a,9007199254740991),c.writeInt32LE(a&-1,u),c.writeUInt32LE(Math.floor(a/4294967296),u+4),u+8}return lr.writeUInt64LE=o,lr}var $p;function gA(){if($p)return Zr;$p=1,Object.defineProperty(Zr,"__esModule",{value:!0});const e=Mt(),t=Ah(),n=ts();function r(c){if(c.key[0]!==e.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+c.key.toString("hex"));const a=t.readUInt64LE(c.value,0);let u=8;const f=n.decode(c.value,u);u+=n.encodingLength(f);const l=c.value.slice(u);if(l.length!==f)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:l,value:a}}Zr.decode=r;function i(c){const{script:a,value:u}=c,f=n.encodingLength(a.length),l=Buffer.allocUnsafe(8+f+a.length);return t.writeUInt64LE(l,u,0),n.encode(a.length,l,8),a.copy(l,8+f),{key:Buffer.from([e.InputTypes.WITNESS_UTXO]),value:l}}Zr.encode=i,Zr.expected="{ script: Buffer; value: number; }";function s(c){return Buffer.isBuffer(c.script)&&typeof c.value=="number"}Zr.check=s;function o(c,a){return!!c&&!!a&&c.witnessUtxo===void 0}return Zr.canAdd=o,Zr}var Jr={},Dp;function mA(){if(Dp)return Jr;Dp=1,Object.defineProperty(Jr,"__esModule",{value:!0});const e=Mt(),t=ts();function n(o){if(o.key[0]!==e.OutputTypes.TAP_TREE||o.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+o.key.toString("hex"));let c=0;const a=[];for(;c<o.value.length;){const u=o.value[c++],f=o.value[c++],l=t.decode(o.value,c);c+=t.encodingLength(l),a.push({depth:u,leafVersion:f,script:o.value.slice(c,c+l)}),c+=l}return{leaves:a}}Jr.decode=n;function r(o){const c=Buffer.from([e.OutputTypes.TAP_TREE]),a=[].concat(...o.leaves.map(u=>[Buffer.of(u.depth,u.leafVersion),t.encode(u.script.length),u.script]));return{key:c,value:Buffer.concat(a)}}Jr.encode=r,Jr.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";function i(o){return Array.isArray(o.leaves)&&o.leaves.every(c=>c.depth>=0&&c.depth<=128&&(c.leafVersion&254)===c.leafVersion&&Buffer.isBuffer(c.script))}Jr.check=i;function s(o,c){return!!o&&!!c&&o.tapTree===void 0}return Jr.canAdd=s,Jr}var Lc={},jp;function zw(){if(jp)return Lc;jp=1,Object.defineProperty(Lc,"__esModule",{value:!0});const e=r=>[...Array(r).keys()],t=r=>r.length===33&&[2,3].includes(r[0])||r.length===65&&r[0]===4;function n(r,i=t){function s(f){if(f.key[0]!==r)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+f.key.toString("hex"));const l=f.key.slice(1);if(!i(l))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+f.key.toString("hex"));if(f.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const d={masterFingerprint:f.value.slice(0,4),pubkey:l,path:"m"};for(const y of e(f.value.length/4-1)){const g=f.value.readUInt32LE(y*4+4),m=!!(g&2147483648),E=g&2147483647;d.path+="/"+E.toString(10)+(m?"'":"")}return d}function o(f){const l=Buffer.from([r]),d=Buffer.concat([l,f.pubkey]),y=f.path.split("/"),g=Buffer.allocUnsafe(y.length*4);f.masterFingerprint.copy(g,0);let m=4;return y.slice(1).forEach(E=>{const _=E.slice(-1)==="'";let S=2147483647&parseInt(_?E.slice(0,-1):E,10);_&&(S+=2147483648),g.writeUInt32LE(S,m),m+=4}),{key:d,value:g}}const c="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";function a(f){return Buffer.isBuffer(f.pubkey)&&Buffer.isBuffer(f.masterFingerprint)&&typeof f.path=="string"&&i(f.pubkey)&&f.masterFingerprint.length===4}function u(f,l,d){const y=l.pubkey.toString("hex");return d.has(y)?!1:(d.add(y),f.filter(g=>g.pubkey.equals(l.pubkey)).length===0)}return{decode:s,encode:o,check:a,expected:c,canAddToArray:u}}return Lc.makeConverter=n,Lc}var $c={},Kp;function wA(){if(Kp)return $c;Kp=1,Object.defineProperty($c,"__esModule",{value:!0});function e(t){return n;function n(r){let i;if(t.includes(r.key[0])&&(i=r.key.slice(1),!(i.length===33||i.length===65)||![2,3,4].includes(i[0])))throw new Error("Format Error: invalid pubkey in key 0x"+r.key.toString("hex"));return i}}return $c.makeChecker=e,$c}var Dc={},Gp;function bA(){if(Gp)return Dc;Gp=1,Object.defineProperty(Dc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.redeemScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Dc.makeConverter=e,Dc}var jc={},Wp;function EA(){if(Wp)return jc;Wp=1,Object.defineProperty(jc,"__esModule",{value:!0});const e=ts(),t=zw(),n=i=>i.length===32;function r(i){const s=t.makeConverter(i,n);function o(f){const l=e.decode(f.value),d=e.encodingLength(l),y=s.decode({key:f.key,value:f.value.slice(d+l*32)}),g=new Array(l);for(let m=0,E=d;m<l;m++,E+=32)g[m]=f.value.slice(E,E+32);return Object.assign({},y,{leafHashes:g})}function c(f){const l=s.encode(f),d=e.encodingLength(f.leafHashes.length),y=Buffer.allocUnsafe(d);e.encode(f.leafHashes.length,y);const g=Buffer.concat([y,...f.leafHashes,l.value]);return Object.assign({},l,{value:g})}const a="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";function u(f){return Array.isArray(f.leafHashes)&&f.leafHashes.every(l=>Buffer.isBuffer(l)&&l.length===32)&&s.check(f)}return{decode:o,encode:c,check:u,expected:a,canAddToArray:s.canAddToArray}}return jc.makeConverter=r,jc}var Kc={},Xp;function _A(){if(Xp)return Kc;Xp=1,Object.defineProperty(Kc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t||c.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+c.key.toString("hex"));if(c.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)&&c.length===32}function o(c,a){return!!c&&!!a&&c.tapInternalKey===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Kc.makeConverter=e,Kc}var Gc={},zp;function SA(){if(zp)return Gc;zp=1,Object.defineProperty(Gc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.witnessScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Gc.makeConverter=e,Gc}var Yp;function vh(){if(Yp)return as;Yp=1,Object.defineProperty(as,"__esModule",{value:!0});const e=Mt(),t=iA(),n=sA(),r=oA(),i=cA(),s=aA(),o=uA(),c=fA(),a=lA(),u=hA(),f=dA(),l=pA(),d=yA(),y=gA(),g=mA(),m=zw(),E=wA(),_=bA(),S=EA(),w=_A(),T=SA(),O={unsignedTx:n,globalXpub:t,checkPubkey:E.makeChecker([])};as.globals=O;const A={nonWitnessUtxo:s,partialSig:o,sighashType:a,finalScriptSig:r,finalScriptWitness:i,porCommitment:c,witnessUtxo:y,bip32Derivation:m.makeConverter(e.InputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(e.InputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.InputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.InputTypes.PARTIAL_SIG,e.InputTypes.BIP32_DERIVATION]),tapKeySig:u,tapScriptSig:d,tapLeafScript:f,tapBip32Derivation:S.makeConverter(e.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:w.makeConverter(e.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:l};as.inputs=A;const R={bip32Derivation:m.makeConverter(e.OutputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(e.OutputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.OutputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:S.makeConverter(e.OutputTypes.TAP_BIP32_DERIVATION),tapTree:g,tapInternalKey:w.makeConverter(e.OutputTypes.TAP_INTERNAL_KEY)};return as.outputs=R,as}var Zp;function TA(){if(Zp)return cs;Zp=1,Object.defineProperty(cs,"__esModule",{value:!0});const e=vh(),t=Ah(),n=ts(),r=Mt();function i(c,a){let u=0;function f(){const R=n.decode(c,u);u+=n.encodingLength(R);const M=c.slice(u,u+R);return u+=R,M}function l(){const R=c.readUInt32BE(u);return u+=4,R}function d(){const R=c.readUInt8(u);return u+=1,R}function y(){const R=f(),M=f();return{key:R,value:M}}function g(){if(u>=c.length)throw new Error("Format Error: Unexpected End of PSBT");const R=c.readUInt8(u)===0;return R&&u++,R}if(l()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(d()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const m=[],E={};for(;!g();){const R=y(),M=R.key.toString("hex");if(E[M])throw new Error("Format Error: Keys must be unique for global keymap: key "+M);E[M]=1,m.push(R)}const _=m.filter(R=>R.key[0]===r.GlobalTypes.UNSIGNED_TX);if(_.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const S=a(_[0].value),{inputCount:w,outputCount:T}=S.getInputOutputCounts(),O=[],A=[];for(const R of t.range(w)){const M={},v=[];for(;!g();){const U=y(),V=U.key.toString("hex");if(M[V])throw new Error("Format Error: Keys must be unique for each input: input index "+R+" key "+V);M[V]=1,v.push(U)}O.push(v)}for(const R of t.range(T)){const M={},v=[];for(;!g();){const U=y(),V=U.key.toString("hex");if(M[V])throw new Error("Format Error: Keys must be unique for each output: output index "+R+" key "+V);M[V]=1,v.push(U)}A.push(v)}return o(S,{globalMapKeyVals:m,inputKeyVals:O,outputKeyVals:A})}cs.psbtFromBuffer=i;function s(c,a,u){if(!a.equals(Buffer.from([u])))throw new Error(`Format Error: Invalid ${c} key: ${a.toString("hex")}`)}cs.checkKeyBuffer=s;function o(c,{globalMapKeyVals:a,inputKeyVals:u,outputKeyVals:f}){const l={unsignedTx:c};let d=0;for(const _ of a)switch(_.key[0]){case r.GlobalTypes.UNSIGNED_TX:if(s("global",_.key,r.GlobalTypes.UNSIGNED_TX),d>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");d++;break;case r.GlobalTypes.GLOBAL_XPUB:l.globalXpub===void 0&&(l.globalXpub=[]),l.globalXpub.push(e.globals.globalXpub.decode(_));break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(_)}const y=u.length,g=f.length,m=[],E=[];for(const _ of t.range(y)){const S={};for(const w of u[_])switch(e.inputs.checkPubkey(w),w.key[0]){case r.InputTypes.NON_WITNESS_UTXO:if(s("input",w.key,r.InputTypes.NON_WITNESS_UTXO),S.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");S.nonWitnessUtxo=e.inputs.nonWitnessUtxo.decode(w);break;case r.InputTypes.WITNESS_UTXO:if(s("input",w.key,r.InputTypes.WITNESS_UTXO),S.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");S.witnessUtxo=e.inputs.witnessUtxo.decode(w);break;case r.InputTypes.PARTIAL_SIG:S.partialSig===void 0&&(S.partialSig=[]),S.partialSig.push(e.inputs.partialSig.decode(w));break;case r.InputTypes.SIGHASH_TYPE:if(s("input",w.key,r.InputTypes.SIGHASH_TYPE),S.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");S.sighashType=e.inputs.sighashType.decode(w);break;case r.InputTypes.REDEEM_SCRIPT:if(s("input",w.key,r.InputTypes.REDEEM_SCRIPT),S.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");S.redeemScript=e.inputs.redeemScript.decode(w);break;case r.InputTypes.WITNESS_SCRIPT:if(s("input",w.key,r.InputTypes.WITNESS_SCRIPT),S.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");S.witnessScript=e.inputs.witnessScript.decode(w);break;case r.InputTypes.BIP32_DERIVATION:S.bip32Derivation===void 0&&(S.bip32Derivation=[]),S.bip32Derivation.push(e.inputs.bip32Derivation.decode(w));break;case r.InputTypes.FINAL_SCRIPTSIG:s("input",w.key,r.InputTypes.FINAL_SCRIPTSIG),S.finalScriptSig=e.inputs.finalScriptSig.decode(w);break;case r.InputTypes.FINAL_SCRIPTWITNESS:s("input",w.key,r.InputTypes.FINAL_SCRIPTWITNESS),S.finalScriptWitness=e.inputs.finalScriptWitness.decode(w);break;case r.InputTypes.POR_COMMITMENT:s("input",w.key,r.InputTypes.POR_COMMITMENT),S.porCommitment=e.inputs.porCommitment.decode(w);break;case r.InputTypes.TAP_KEY_SIG:s("input",w.key,r.InputTypes.TAP_KEY_SIG),S.tapKeySig=e.inputs.tapKeySig.decode(w);break;case r.InputTypes.TAP_SCRIPT_SIG:S.tapScriptSig===void 0&&(S.tapScriptSig=[]),S.tapScriptSig.push(e.inputs.tapScriptSig.decode(w));break;case r.InputTypes.TAP_LEAF_SCRIPT:S.tapLeafScript===void 0&&(S.tapLeafScript=[]),S.tapLeafScript.push(e.inputs.tapLeafScript.decode(w));break;case r.InputTypes.TAP_BIP32_DERIVATION:S.tapBip32Derivation===void 0&&(S.tapBip32Derivation=[]),S.tapBip32Derivation.push(e.inputs.tapBip32Derivation.decode(w));break;case r.InputTypes.TAP_INTERNAL_KEY:s("input",w.key,r.InputTypes.TAP_INTERNAL_KEY),S.tapInternalKey=e.inputs.tapInternalKey.decode(w);break;case r.InputTypes.TAP_MERKLE_ROOT:s("input",w.key,r.InputTypes.TAP_MERKLE_ROOT),S.tapMerkleRoot=e.inputs.tapMerkleRoot.decode(w);break;default:S.unknownKeyVals||(S.unknownKeyVals=[]),S.unknownKeyVals.push(w)}m.push(S)}for(const _ of t.range(g)){const S={};for(const w of f[_])switch(e.outputs.checkPubkey(w),w.key[0]){case r.OutputTypes.REDEEM_SCRIPT:if(s("output",w.key,r.OutputTypes.REDEEM_SCRIPT),S.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");S.redeemScript=e.outputs.redeemScript.decode(w);break;case r.OutputTypes.WITNESS_SCRIPT:if(s("output",w.key,r.OutputTypes.WITNESS_SCRIPT),S.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");S.witnessScript=e.outputs.witnessScript.decode(w);break;case r.OutputTypes.BIP32_DERIVATION:S.bip32Derivation===void 0&&(S.bip32Derivation=[]),S.bip32Derivation.push(e.outputs.bip32Derivation.decode(w));break;case r.OutputTypes.TAP_INTERNAL_KEY:s("output",w.key,r.OutputTypes.TAP_INTERNAL_KEY),S.tapInternalKey=e.outputs.tapInternalKey.decode(w);break;case r.OutputTypes.TAP_TREE:s("output",w.key,r.OutputTypes.TAP_TREE),S.tapTree=e.outputs.tapTree.decode(w);break;case r.OutputTypes.TAP_BIP32_DERIVATION:S.tapBip32Derivation===void 0&&(S.tapBip32Derivation=[]),S.tapBip32Derivation.push(e.outputs.tapBip32Derivation.decode(w));break;default:S.unknownKeyVals||(S.unknownKeyVals=[]),S.unknownKeyVals.push(w)}E.push(S)}return{globalMap:l,inputs:m,outputs:E}}return cs.psbtFromKeyVals=o,cs}var wo={},Jp;function xA(){if(Jp)return wo;Jp=1,Object.defineProperty(wo,"__esModule",{value:!0});const e=vh(),t=Ah();function n({globalMap:o,inputs:c,outputs:a}){const{globalKeyVals:u,inputKeyVals:f,outputKeyVals:l}=s({globalMap:o,inputs:c,outputs:a}),d=t.keyValsToBuffer(u),y=_=>_.length===0?[Buffer.from([0])]:_.map(t.keyValsToBuffer),g=y(f),m=y(l),E=Buffer.allocUnsafe(5);return E.writeUIntBE(482972169471,0,5),Buffer.concat([E,d].concat(g,m))}wo.psbtToBuffer=n;const r=(o,c)=>o.key.compare(c.key);function i(o,c){const a=new Set,u=Object.entries(o).reduce((l,[d,y])=>{if(d==="unknownKeyVals")return l;const g=c[d];if(g===void 0)return l;const m=(Array.isArray(y)?y:[y]).map(g.encode);return m.map(_=>_.key.toString("hex")).forEach(_=>{if(a.has(_))throw new Error("Serialize Error: Duplicate key: "+_);a.add(_)}),l.concat(m)},[]),f=o.unknownKeyVals?o.unknownKeyVals.filter(l=>!a.has(l.key.toString("hex"))):[];return u.concat(f).sort(r)}function s({globalMap:o,inputs:c,outputs:a}){return{globalKeyVals:i(o,e.globals),inputKeyVals:c.map(u=>i(u,e.inputs)),outputKeyVals:a.map(u=>i(u,e.outputs))}}return wo.psbtToKeyVals=s,wo}var Qp;function Yw(){return Qp||(Qp=1,(function(e){function t(n){for(var r in n)e.hasOwnProperty(r)||(e[r]=n[r])}Object.defineProperty(e,"__esModule",{value:!0}),t(TA()),t(xA())})(Nf)),Nf}var ey;function AA(){if(ey)return qc;ey=1,Object.defineProperty(qc,"__esModule",{value:!0});const e=Yw();function t(s){const o=s[0],c=e.psbtToKeyVals(o),a=s.slice(1);if(a.length===0)throw new Error("Combine: Nothing to combine");const u=r(o);if(u===void 0)throw new Error("Combine: Self missing transaction");const f=i(c.globalKeyVals),l=c.inputKeyVals.map(i),d=c.outputKeyVals.map(i);for(const y of a){const g=r(y);if(g===void 0||!g.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const m=e.psbtToKeyVals(y);i(m.globalKeyVals).forEach(n(f,c.globalKeyVals,m.globalKeyVals)),m.inputKeyVals.map(i).forEach((w,T)=>w.forEach(n(l[T],c.inputKeyVals[T],m.inputKeyVals[T]))),m.outputKeyVals.map(i).forEach((w,T)=>w.forEach(n(d[T],c.outputKeyVals[T],m.outputKeyVals[T])))}return e.psbtFromKeyVals(u,{globalMapKeyVals:c.globalKeyVals,inputKeyVals:c.inputKeyVals,outputKeyVals:c.outputKeyVals})}qc.combine=t;function n(s,o,c){return a=>{if(s.has(a))return;const u=c.filter(f=>f.key.toString("hex")===a)[0];o.push(u),s.add(a)}}function r(s){return s.globalMap.unsignedTx}function i(s){const o=new Set;return s.forEach(c=>{const a=c.key.toString("hex");if(o.has(a))throw new Error("Combine: KeyValue Map keys should be unique");o.add(a)}),o}return qc}var Pf={},ty;function Zw(){return ty||(ty=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=vh();function n(y,g){const m=y[g];if(m===void 0)throw new Error(`No input #${g}`);return m}e.checkForInput=n;function r(y,g){const m=y[g];if(m===void 0)throw new Error(`No output #${g}`);return m}e.checkForOutput=r;function i(y,g,m){if(y.key[0]<m)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(g&&g.filter(E=>E.key.equals(y.key)).length!==0)throw new Error(`Duplicate Key: ${y.key.toString("hex")}`)}e.checkHasKey=i;function s(y){let g=0;return Object.keys(y).forEach(m=>{Number(isNaN(Number(m)))&&g++}),g}e.getEnumLength=s;function o(y,g){let m=!1;if(g.nonWitnessUtxo||g.witnessUtxo){const E=!!g.redeemScript,_=!!g.witnessScript,S=!E||!!g.finalScriptSig,w=!_||!!g.finalScriptWitness,T=!!g.finalScriptSig||!!g.finalScriptWitness;m=S&&w&&T}if(m===!1)throw new Error(`Input #${y} has too much or too little data to clean`)}e.inputCheckUncleanFinalized=o;function c(y,g,m,E){throw new Error(`Data for ${y} key ${g} is incorrect: Expected ${m} and got ${JSON.stringify(E)}`)}function a(y){return(g,m)=>{for(const E of Object.keys(g)){const _=g[E],{canAdd:S,canAddToArray:w,check:T,expected:O}=t[y+"s"][E]||{},A=!!w;if(T)if(A){if(!Array.isArray(_)||m[E]&&!Array.isArray(m[E]))throw new Error(`Key type ${E} must be an array`);_.every(T)||c(y,E,O,_);const R=m[E]||[],M=new Set;if(!_.every(v=>w(R,v,M)))throw new Error("Can not add duplicate data to array");m[E]=R.concat(_)}else{if(T(_)||c(y,E,O,_),!S(m,_))throw new Error(`Can not add duplicate data to ${y}`);m[E]=_}}}}e.updateGlobal=a("global"),e.updateInput=a("input"),e.updateOutput=a("output");function u(y,g){const m=y.length-1,E=n(y,m);e.updateInput(g,E)}e.addInputAttributes=u;function f(y,g){const m=y.length-1,E=r(y,m);e.updateOutput(g,E)}e.addOutputAttributes=f;function l(y,g){if(!Buffer.isBuffer(g)||g.length<4)throw new Error("Set Version: Invalid Transaction");return g.writeUInt32LE(y,0),g}e.defaultVersionSetter=l;function d(y,g){if(!Buffer.isBuffer(g)||g.length<4)throw new Error("Set Locktime: Invalid Transaction");return g.writeUInt32LE(y,g.length-4),g}e.defaultLocktimeSetter=d})(Pf)),Pf}var ny;function vA(){if(ny)return Mc;ny=1,Object.defineProperty(Mc,"__esModule",{value:!0});const e=AA(),t=Yw(),n=Mt(),r=Zw();class i{constructor(o){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:o}}static fromBase64(o,c){const a=Buffer.from(o,"base64");return this.fromBuffer(a,c)}static fromHex(o,c){const a=Buffer.from(o,"hex");return this.fromBuffer(a,c)}static fromBuffer(o,c){const a=t.psbtFromBuffer(o,c),u=new this(a.globalMap.unsignedTx);return Object.assign(u,a),u}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return t.psbtToBuffer(this)}updateGlobal(o){return r.updateGlobal(o,this.globalMap),this}updateInput(o,c){const a=r.checkForInput(this.inputs,o);return r.updateInput(c,a),this}updateOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.updateOutput(c,a),this}addUnknownKeyValToGlobal(o){return r.checkHasKey(o,this.globalMap.unknownKeyVals,r.getEnumLength(n.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(o),this}addUnknownKeyValToInput(o,c){const a=r.checkForInput(this.inputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.InputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addUnknownKeyValToOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.OutputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addInput(o){this.globalMap.unsignedTx.addInput(o),this.inputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.inputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToInput(a,u)),r.addInputAttributes(this.inputs,o),this}addOutput(o){this.globalMap.unsignedTx.addOutput(o),this.outputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.outputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToOutput(a,u)),r.addOutputAttributes(this.outputs,o),this}clearFinalizedInput(o){const c=r.checkForInput(this.inputs,o);r.inputCheckUncleanFinalized(o,c);for(const a of Object.keys(c))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(a)||delete c[a];return this}combine(...o){const c=e.combine([this].concat(o));return Object.assign(this,c),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}return Mc.Psbt=i,Mc}var Qe={},ze={},ry;function dl(){if(ry)return ze;ry=1,Object.defineProperty(ze,"__esModule",{value:!0}),ze.signatureBlocksAction=ze.checkInputForSig=ze.pubkeyInScript=ze.pubkeyPositionInScript=ze.witnessStackToScriptWitness=ze.isP2TR=ze.isP2SHScript=ze.isP2WSHScript=ze.isP2WPKH=ze.isP2PKH=ze.isP2PK=ze.isP2MS=void 0;const e=ts(),t=rn(),n=_c(),r=Pr(),i=Ec();function s(y){return g=>{try{return y({output:g}),!0}catch{return!1}}}ze.isP2MS=s(i.p2ms),ze.isP2PK=s(i.p2pk),ze.isP2PKH=s(i.p2pkh),ze.isP2WPKH=s(i.p2wpkh),ze.isP2WSHScript=s(i.p2wsh),ze.isP2SHScript=s(i.p2sh),ze.isP2TR=s(i.p2tr);function o(y){let g=Buffer.allocUnsafe(0);function m(w){g=Buffer.concat([g,Buffer.from(w)])}function E(w){const T=g.length,O=e.encodingLength(w);g=Buffer.concat([g,Buffer.allocUnsafe(O)]),e.encode(w,g,T)}function _(w){E(w.length),m(w)}function S(w){E(w.length),w.forEach(_)}return S(y),g}ze.witnessStackToScriptWitness=o;function c(y,g){const m=(0,r.hash160)(y),E=y.slice(1,33),_=t.decompile(g);if(_===null)throw new Error("Unknown script error");return _.findIndex(S=>typeof S=="number"?!1:S.equals(y)||S.equals(m)||S.equals(E))}ze.pubkeyPositionInScript=c;function a(y,g){return c(y,g)!==-1}ze.pubkeyInScript=a;function u(y,g){return l(y).some(E=>f(E,t.signature.decode,g))}ze.checkInputForSig=u;function f(y,g,m){const{hashType:E}=g(y),_=[];switch(E&n.Transaction.SIGHASH_ANYONECANPAY&&_.push("addInput"),E&31){case n.Transaction.SIGHASH_ALL:break;case n.Transaction.SIGHASH_SINGLE:case n.Transaction.SIGHASH_NONE:_.push("addOutput"),_.push("setInputSequence");break}return _.indexOf(m)===-1}ze.signatureBlocksAction=f;function l(y){let g=[];if((y.partialSig||[]).length===0){if(!y.finalScriptSig&&!y.finalScriptWitness)return[];g=d(y)}else g=y.partialSig;return g.map(m=>m.signature)}function d(y){const g=y.finalScriptSig?t.decompile(y.finalScriptSig)||[]:[],m=y.finalScriptWitness?t.decompile(y.finalScriptWitness)||[]:[];return g.concat(m).filter(E=>Buffer.isBuffer(E)&&t.isCanonicalScriptSignature(E)).map(E=>({signature:E}))}return ze}var iy;function IA(){if(iy)return Qe;iy=1,Object.defineProperty(Qe,"__esModule",{value:!0}),Qe.checkTaprootInputForSigs=Qe.tapTreeFromList=Qe.tapTreeToList=Qe.tweakInternalPubKey=Qe.checkTaprootOutputFields=Qe.checkTaprootInputFields=Qe.isTaprootOutput=Qe.isTaprootInput=Qe.serializeTaprootSignature=Qe.tapScriptFinalizer=Qe.toXOnly=void 0;const e=Xt(),t=_c(),n=dl(),r=Th(),i=Ec(),s=dl(),o=x=>x.length===32?x:x.slice(1,33);Qe.toXOnly=o;function c(x,B,q){const N=P(B,x,q);try{const G=H(B,N).concat(N.script).concat(N.controlBlock);return{finalScriptWitness:(0,n.witnessStackToScriptWitness)(G)}}catch(L){throw new Error(`Can not finalize taproot input #${x}: ${L}`)}}Qe.tapScriptFinalizer=c;function a(x,B){const q=B?Buffer.from([B]):Buffer.from([]);return Buffer.concat([x,q])}Qe.serializeTaprootSignature=a;function u(x){return x&&!!(x.tapInternalKey||x.tapMerkleRoot||x.tapLeafScript&&x.tapLeafScript.length||x.tapBip32Derivation&&x.tapBip32Derivation.length||x.witnessUtxo&&(0,n.isP2TR)(x.witnessUtxo.script))}Qe.isTaprootInput=u;function f(x,B){return x&&!!(x.tapInternalKey||x.tapTree||x.tapBip32Derivation&&x.tapBip32Derivation.length||B&&(0,n.isP2TR)(B))}Qe.isTaprootOutput=f;function l(x,B,q){v(x,B,q),V(x,B,q)}Qe.checkTaprootInputFields=l;function d(x,B,q){U(x,B,q),y(x,B)}Qe.checkTaprootOutputFields=d;function y(x,B){if(!B.tapTree&&!B.tapInternalKey)return;const q=B.tapInternalKey||x.tapInternalKey,N=B.tapTree||x.tapTree;if(q){const{script:L}=x,G=g(q,N);if(L&&!L.equals(G))throw new Error("Error adding output. Script or address missmatch.")}}function g(x,B){const q=B&&_(B.leaves),{output:N}=(0,i.p2tr)({internalPubkey:x,scriptTree:q});return N}function m(x,B){const q=B.tapInternalKey,N=q&&(0,r.tweakKey)(q,B.tapMerkleRoot);if(!N)throw new Error(`Cannot tweak tap internal key for input #${x}. Public key: ${q&&q.toString("hex")}`);return N.x}Qe.tweakInternalPubKey=m;function E(x){if(!(0,e.isTaptree)(x))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return A(x)}Qe.tapTreeToList=E;function _(x=[]){return x.length===1&&x[0].depth===0?{output:x[0].script,version:x[0].leafVersion}:R(x)}Qe.tapTreeFromList=_;function S(x,B){return T(x).some(N=>(0,s.signatureBlocksAction)(N,w,B))}Qe.checkTaprootInputForSigs=S;function w(x){return{signature:x.slice(0,64),hashType:x.slice(64)[0]||t.Transaction.SIGHASH_DEFAULT}}function T(x){const B=[];if(x.tapKeySig&&B.push(x.tapKeySig),x.tapScriptSig&&B.push(...x.tapScriptSig.map(q=>q.signature)),!B.length){const q=O(x.finalScriptWitness);q&&B.push(q)}return B}function O(x){if(!x)return;const B=x.slice(2);if(B.length===64||B.length===65)return B}function A(x,B=[],q=0){if(q>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return x?(0,e.isTapleaf)(x)?(B.push({depth:q,leafVersion:x.version||r.LEAF_VERSION_TAPSCRIPT,script:x.output}),B):(x[0]&&A(x[0],B,q+1),x[1]&&A(x[1],B,q+1),B):[]}function R(x){let B;for(const q of x)if(B=M(q,B),!B)throw new Error("No room left to insert tapleaf in tree");return B}function M(x,B,q=0){if(q>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(x.depth===q)return B?void 0:{output:x.script,version:x.leafVersion};if((0,e.isTapleaf)(B))return;const N=M(x,B&&B[0],q+1);if(N)return[N,B&&B[1]];const L=M(x,B&&B[1],q+1);if(L)return[B&&B[0],L]}function v(x,B,q){const N=u(x)&&F(B),L=F(x)&&u(B),G=x===B&&u(B)&&F(B);if(N||L||G)throw new Error(`Invalid arguments for Psbt.${q}. Cannot use both taproot and non-taproot fields.`)}function U(x,B,q){const N=f(x)&&F(B),L=F(x)&&f(B),G=x===B&&f(B)&&F(B);if(N||L||G)throw new Error(`Invalid arguments for Psbt.${q}. Cannot use both taproot and non-taproot fields.`)}function V(x,B,q){if(B.tapMerkleRoot){const N=(B.tapLeafScript||[]).every(G=>K(G,B.tapMerkleRoot)),L=(x.tapLeafScript||[]).every(G=>K(G,B.tapMerkleRoot));if(!N||!L)throw new Error(`Invalid arguments for Psbt.${q}. Tapleaf not part of taptree.`)}else if(x.tapMerkleRoot&&!(B.tapLeafScript||[]).every(L=>K(L,x.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${q}. Tapleaf not part of taptree.`)}function K(x,B){if(!B)return!0;const q=(0,r.tapleafHash)({output:x.script,version:x.leafVersion});return(0,r.rootHashFromPath)(x.controlBlock,q).equals(B)}function H(x,B){const q=(0,r.tapleafHash)({output:B.script,version:B.leafVersion});return(x.tapScriptSig||[]).filter(N=>N.leafHash.equals(q)).map(N=>$(B.script,N)).sort((N,L)=>L.positionInScript-N.positionInScript).map(N=>N.signature)}function $(x,B){return Object.assign({positionInScript:(0,n.pubkeyPositionInScript)(B.pubkey,x)},B)}function P(x,B,q){if(!x.tapScriptSig||!x.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${B}. No tapleaf script signature provided.`);const N=(x.tapLeafScript||[]).sort((L,G)=>L.controlBlock.length-G.controlBlock.length).find(L=>D(L,x.tapScriptSig,q));if(!N)throw new Error(`Can not finalize taproot input #${B}. Signature for tapleaf script not found.`);return N}function D(x,B,q){const N=(0,r.tapleafHash)({output:x.script,version:x.leafVersion});return(!q||q.equals(N))&&B.find(G=>G.leafHash.equals(N))!==void 0}function F(x){return x&&!!(x.redeemScript||x.witnessScript||x.bip32Derivation&&x.bip32Derivation.length)}return Qe}var sy;function OA(){if(sy)return mo;sy=1,Object.defineProperty(mo,"__esModule",{value:!0}),mo.Psbt=void 0;const e=vA(),t=ts(),n=Zw(),r=xh(),i=Eu(),s=Wn(),o=Ec(),c=Th(),a=rn(),u=_c(),f=IA(),l=dl(),d={network:s.bitcoin,maximumFeeRate:5e3};class y{static fromBase64(h,b={}){const I=Buffer.from(h,"base64");return this.fromBuffer(I,b)}static fromHex(h,b={}){const I=Buffer.from(h,"hex");return this.fromBuffer(I,b)}static fromBuffer(h,b={}){const I=e.Psbt.fromBuffer(h,g),C=new y(b,I);return V(C.__CACHE.__TX,C.__CACHE),C}constructor(h={},b=new e.Psbt(new m)){this.data=b,this.opts=Object.assign({},d,h),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const I=(C,j,W,ie)=>Object.defineProperty(C,j,{enumerable:W,writable:ie});I(this,"__CACHE",!1,!0),I(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(h){this.setVersion(h)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(h){this.setLocktime(h)}get txInputs(){return this.__CACHE.__TX.ins.map(h=>({hash:(0,i.cloneBuffer)(h.hash),index:h.index,sequence:h.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(h=>{let b;try{b=(0,r.fromOutputScript)(h.script,this.opts.network)}catch{}return{script:(0,i.cloneBuffer)(h.script),value:h.value,address:b}})}combine(...h){return this.data.combine(...h.map(b=>b.data)),this}clone(){const h=y.fromBuffer(this.data.toBuffer());return h.opts=JSON.parse(JSON.stringify(this.opts)),h}setMaximumFeeRate(h){O(h),this.opts.maximumFeeRate=h}setVersion(h){O(h),R(this.data.inputs,"setVersion");const b=this.__CACHE;return b.__TX.version=h,b.__EXTRACTED_TX=void 0,this}setLocktime(h){O(h),R(this.data.inputs,"setLocktime");const b=this.__CACHE;return b.__TX.locktime=h,b.__EXTRACTED_TX=void 0,this}setInputSequence(h,b){O(b),R(this.data.inputs,"setInputSequence");const I=this.__CACHE;if(I.__TX.ins.length<=h)throw new Error("Input index too high");return I.__TX.ins[h].sequence=b,I.__EXTRACTED_TX=void 0,this}addInputs(h){return h.forEach(b=>this.addInput(b)),this}addInput(h){if(arguments.length>1||!h||h.hash===void 0||h.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");(0,f.checkTaprootInputFields)(h,h,"addInput"),R(this.data.inputs,"addInput"),h.witnessScript&&ne(h.witnessScript);const b=this.__CACHE;this.data.addInput(h);const I=b.__TX.ins[b.__TX.ins.length-1];K(b,I);const C=this.data.inputs.length-1,j=this.data.inputs[C];return j.nonWitnessUtxo&&ye(this.__CACHE,j,C),b.__FEE=void 0,b.__FEE_RATE=void 0,b.__EXTRACTED_TX=void 0,this}addOutputs(h){return h.forEach(b=>this.addOutput(b)),this}addOutput(h){if(arguments.length>1||!h||h.value===void 0||h.address===void 0&&h.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");R(this.data.inputs,"addOutput");const{address:b}=h;if(typeof b=="string"){const{network:C}=this.opts,j=(0,r.toOutputScript)(b,C);h=Object.assign({},h,{script:j})}(0,f.checkTaprootOutputFields)(h,h,"addOutput");const I=this.__CACHE;return this.data.addOutput(h),I.__FEE=void 0,I.__FEE_RATE=void 0,I.__EXTRACTED_TX=void 0,this}extractTransaction(h){if(!this.data.inputs.every(w))throw new Error("Not finalized");const b=this.__CACHE;if(h||A(this,b,this.opts),b.__EXTRACTED_TX)return b.__EXTRACTED_TX;const I=b.__TX.clone();return J(this.data.inputs,I,b,!0),I}getFeeRate(){return D("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return D("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,n.checkForInput)(this.data.inputs,0),k(this.data.inputs.length).forEach(h=>this.finalizeInput(h)),this}finalizeInput(h,b){const I=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(I)?this._finalizeTaprootInput(h,I,void 0,b):this._finalizeInput(h,I,b)}finalizeTaprootInput(h,b,I=f.tapScriptFinalizer){const C=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(C))return this._finalizeTaprootInput(h,C,b,I);throw new Error(`Cannot finalize input #${h}. Not Taproot.`)}_finalizeInput(h,b,I=F){const{script:C,isP2SH:j,isP2WSH:W,isSegwit:ie}=ue(h,b,this.__CACHE);if(!C)throw new Error(`No script found for input #${h}`);M(b);const{finalScriptSig:Q,finalScriptWitness:fe}=I(h,b,C,ie,j,W);if(Q&&this.data.updateInput(h,{finalScriptSig:Q}),fe&&this.data.updateInput(h,{finalScriptWitness:fe}),!Q&&!fe)throw new Error(`Unknown error finalizing input #${h}`);return this.data.clearFinalizedInput(h),this}_finalizeTaprootInput(h,b,I,C=f.tapScriptFinalizer){if(!b.witnessUtxo)throw new Error(`Cannot finalize input #${h}. Missing withness utxo.`);if(b.tapKeySig){const j=o.p2tr({output:b.witnessUtxo.script,signature:b.tapKeySig}),W=(0,l.witnessStackToScriptWitness)(j.witness);this.data.updateInput(h,{finalScriptWitness:W})}else{const{finalScriptWitness:j}=C(h,b,I);this.data.updateInput(h,{finalScriptWitness:j})}return this.data.clearFinalizedInput(h),this}getInputType(h){const b=(0,n.checkForInput)(this.data.inputs,h),I=Ae(h,b,this.__CACHE),C=oe(I,h,"input",b.redeemScript||It(b.finalScriptSig),b.witnessScript||Oe(b.finalScriptWitness)),j=C.type==="raw"?"":C.type+"-",W=re(C.meaningfulScript);return j+W}inputHasPubkey(h,b){const I=(0,n.checkForInput)(this.data.inputs,h);return tt(b,I,h,this.__CACHE)}inputHasHDKey(h,b){const I=(0,n.checkForInput)(this.data.inputs,h),C=T(b);return!!I.bip32Derivation&&I.bip32Derivation.some(C)}outputHasPubkey(h,b){const I=(0,n.checkForOutput)(this.data.outputs,h);return ut(b,I,h,this.__CACHE)}outputHasHDKey(h,b){const I=(0,n.checkForOutput)(this.data.outputs,h),C=T(b);return!!I.bip32Derivation&&I.bip32Derivation.some(C)}validateSignaturesOfAllInputs(h){return(0,n.checkForInput)(this.data.inputs,0),k(this.data.inputs.length).map(I=>this.validateSignaturesOfInput(I,h)).reduce((I,C)=>C===!0&&I,!0)}validateSignaturesOfInput(h,b,I){const C=this.data.inputs[h];return(0,f.isTaprootInput)(C)?this.validateSignaturesOfTaprootInput(h,b,I):this._validateSignaturesOfInput(h,b,I)}_validateSignaturesOfInput(h,b,I){const C=this.data.inputs[h],j=(C||{}).partialSig;if(!C||!j||j.length<1)throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");const W=I?j.filter(Ne=>Ne.pubkey.equals(I)):j;if(W.length<1)throw new Error("No signatures for this pubkey");const ie=[];let Q,fe,he;for(const Ne of W){const Pe=a.signature.decode(Ne.signature),{hash:nt,script:je}=he!==Pe.hashType?q(h,Object.assign({},C,{sighashType:Pe.hashType}),this.__CACHE,!0):{hash:Q,script:fe};he=Pe.hashType,Q=nt,fe=je,v(Ne.pubkey,je,"verify"),ie.push(b(Ne.pubkey,nt,Pe.signature))}return ie.every(Ne=>Ne===!0)}validateSignaturesOfTaprootInput(h,b,I){const C=this.data.inputs[h],j=(C||{}).tapKeySig,W=(C||{}).tapScriptSig;if(!C&&!j&&!(W&&!W.length))throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");I=I&&(0,f.toXOnly)(I);const ie=I?X(h,C,this.data.inputs,I,this.__CACHE):N(h,C,this.data.inputs,this.__CACHE);if(!ie.length)throw new Error("No signatures for this pubkey");const Q=ie.find(he=>!he.leafHash);let fe=0;if(j&&Q){if(!b(Q.pubkey,Q.hash,G(j)))return!1;fe++}if(W)for(const he of W){const Ne=ie.find(Pe=>he.pubkey.equals(Pe.pubkey));if(Ne){if(!b(he.pubkey,Ne.hash,G(he.signature)))return!1;fe++}}return fe>0}signAllInputsHD(h,b=[u.Transaction.SIGHASH_ALL]){if(!h||!h.publicKey||!h.fingerprint)throw new Error("Need HDSigner to sign input");const I=[];for(const C of k(this.data.inputs.length))try{this.signInputHD(C,h,b),I.push(!0)}catch{I.push(!1)}if(I.every(C=>C===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(h,b=[u.Transaction.SIGHASH_ALL]){return new Promise((I,C)=>{if(!h||!h.publicKey||!h.fingerprint)return C(new Error("Need HDSigner to sign input"));const j=[],W=[];for(const ie of k(this.data.inputs.length))W.push(this.signInputHDAsync(ie,h,b).then(()=>{j.push(!0)},()=>{j.push(!1)}));return Promise.all(W).then(()=>{if(j.every(ie=>ie===!1))return C(new Error("No inputs were signed"));I()})})}signInputHD(h,b,I=[u.Transaction.SIGHASH_ALL]){if(!b||!b.publicKey||!b.fingerprint)throw new Error("Need HDSigner to sign input");return te(h,this.data.inputs,b).forEach(j=>this.signInput(h,j,I)),this}signInputHDAsync(h,b,I=[u.Transaction.SIGHASH_ALL]){return new Promise((C,j)=>{if(!b||!b.publicKey||!b.fingerprint)return j(new Error("Need HDSigner to sign input"));const ie=te(h,this.data.inputs,b).map(Q=>this.signInputAsync(h,Q,I));return Promise.all(ie).then(()=>{C()}).catch(j)})}signAllInputs(h,b){if(!h||!h.publicKey)throw new Error("Need Signer to sign input");const I=[];for(const C of k(this.data.inputs.length))try{this.signInput(C,h,b),I.push(!0)}catch{I.push(!1)}if(I.every(C=>C===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(h,b){return new Promise((I,C)=>{if(!h||!h.publicKey)return C(new Error("Need Signer to sign input"));const j=[],W=[];for(const[ie]of this.data.inputs.entries())W.push(this.signInputAsync(ie,h,b).then(()=>{j.push(!0)},()=>{j.push(!1)}));return Promise.all(W).then(()=>{if(j.every(ie=>ie===!1))return C(new Error("No inputs were signed"));I()})})}signInput(h,b,I){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const C=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(C)?this._signTaprootInput(h,C,b,void 0,I):this._signInput(h,b,I)}signTaprootInput(h,b,I,C){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const j=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(j))return this._signTaprootInput(h,j,b,I,C);throw new Error(`Input #${h} is not of type Taproot.`)}_signInput(h,b,I=[u.Transaction.SIGHASH_ALL]){const{hash:C,sighashType:j}=B(this.data.inputs,h,b.publicKey,this.__CACHE,I),W=[{pubkey:b.publicKey,signature:a.signature.encode(b.sign(C),j)}];return this.data.updateInput(h,{partialSig:W}),this}_signTaprootInput(h,b,I,C,j=[u.Transaction.SIGHASH_DEFAULT]){const W=this.checkTaprootHashesForSig(h,b,I,C,j),ie=W.filter(fe=>!fe.leafHash).map(fe=>(0,f.serializeTaprootSignature)(I.signSchnorr(fe.hash),b.sighashType))[0],Q=W.filter(fe=>!!fe.leafHash).map(fe=>({pubkey:(0,f.toXOnly)(I.publicKey),signature:(0,f.serializeTaprootSignature)(I.signSchnorr(fe.hash),b.sighashType),leafHash:fe.leafHash}));return ie&&this.data.updateInput(h,{tapKeySig:ie}),Q.length&&this.data.updateInput(h,{tapScriptSig:Q}),this}signInputAsync(h,b,I){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const C=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(C)?this._signTaprootInputAsync(h,C,b,void 0,I):this._signInputAsync(h,b,I)})}signTaprootInputAsync(h,b,I,C){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const j=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(j))return this._signTaprootInputAsync(h,j,b,I,C);throw new Error(`Input #${h} is not of type Taproot.`)})}_signInputAsync(h,b,I=[u.Transaction.SIGHASH_ALL]){const{hash:C,sighashType:j}=B(this.data.inputs,h,b.publicKey,this.__CACHE,I);return Promise.resolve(b.sign(C)).then(W=>{const ie=[{pubkey:b.publicKey,signature:a.signature.encode(W,j)}];this.data.updateInput(h,{partialSig:ie})})}async _signTaprootInputAsync(h,b,I,C,j=[u.Transaction.SIGHASH_DEFAULT]){const W=this.checkTaprootHashesForSig(h,b,I,C,j),ie=[],Q=W.filter(he=>!he.leafHash)[0];if(Q){const he=Promise.resolve(I.signSchnorr(Q.hash)).then(Ne=>({tapKeySig:(0,f.serializeTaprootSignature)(Ne,b.sighashType)}));ie.push(he)}const fe=W.filter(he=>!!he.leafHash);if(fe.length){const he=fe.map(Ne=>Promise.resolve(I.signSchnorr(Ne.hash)).then(Pe=>({tapScriptSig:[{pubkey:(0,f.toXOnly)(I.publicKey),signature:(0,f.serializeTaprootSignature)(Pe,b.sighashType),leafHash:Ne.leafHash}]})));ie.push(...he)}return Promise.all(ie).then(he=>{he.forEach(Ne=>this.data.updateInput(h,Ne))})}checkTaprootHashesForSig(h,b,I,C,j){if(typeof I.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${h}.`);const W=X(h,b,this.data.inputs,I.publicKey,this.__CACHE,C,j);if(!W||!W.length)throw new Error(`Can not sign for input #${h} with the key ${I.publicKey.toString("hex")}`);return W}toBuffer(){return _(this.__CACHE),this.data.toBuffer()}toHex(){return _(this.__CACHE),this.data.toHex()}toBase64(){return _(this.__CACHE),this.data.toBase64()}updateGlobal(h){return this.data.updateGlobal(h),this}updateInput(h,b){return b.witnessScript&&ne(b.witnessScript),(0,f.checkTaprootInputFields)(this.data.inputs[h],b,"updateInput"),this.data.updateInput(h,b),b.nonWitnessUtxo&&ye(this.__CACHE,this.data.inputs[h],h),this}updateOutput(h,b){const I=this.data.outputs[h];return(0,f.checkTaprootOutputFields)(I,b,"updateOutput"),this.data.updateOutput(h,b),this}addUnknownKeyValToGlobal(h){return this.data.addUnknownKeyValToGlobal(h),this}addUnknownKeyValToInput(h,b){return this.data.addUnknownKeyValToInput(h,b),this}addUnknownKeyValToOutput(h,b){return this.data.addUnknownKeyValToOutput(h,b),this}clearFinalizedInput(h){return this.data.clearFinalizedInput(h),this}}mo.Psbt=y;const g=p=>new m(p);class m{constructor(h=Buffer.from([2,0,0,0,0,0,0,0,0,0])){this.tx=u.Transaction.fromBuffer(h),U(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(h){if(h.hash===void 0||h.index===void 0||!Buffer.isBuffer(h.hash)&&typeof h.hash!="string"||typeof h.index!="number")throw new Error("Error adding input.");const b=typeof h.hash=="string"?(0,i.reverseBuffer)(Buffer.from(h.hash,"hex")):h.hash;this.tx.addInput(b,h.index,h.sequence)}addOutput(h){if(h.script===void 0||h.value===void 0||!Buffer.isBuffer(h.script)||typeof h.value!="number")throw new Error("Error adding output.");this.tx.addOutput(h.script,h.value)}toBuffer(){return this.tx.toBuffer()}}function E(p,h,b){switch(b){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return S(1,p.partialSig);case"multisig":const I=o.p2ms({output:h});return S(I.m,p.partialSig,I.pubkeys);default:return!1}}function _(p){if(p.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function S(p,h,b){if(!h)return!1;let I;if(b?I=b.map(C=>{const j=mn(C);return h.find(W=>W.pubkey.equals(j))}).filter(C=>!!C):I=h,I.length>p)throw new Error("Too many signatures");return I.length===p}function w(p){return!!p.finalScriptSig||!!p.finalScriptWitness}function T(p){return h=>!(!h.masterFingerprint.equals(p.fingerprint)||!p.derivePath(h.path).publicKey.equals(h.pubkey))}function O(p){if(typeof p!="number"||p!==Math.floor(p)||p>4294967295||p<0)throw new Error("Invalid 32 bit integer")}function A(p,h,b){const I=h.__FEE_RATE||p.getFeeRate(),C=h.__EXTRACTED_TX.virtualSize(),j=I*C;if(I>=b.maximumFeeRate)throw new Error(`Warning: You are paying around ${(j/1e8).toFixed(8)} in fees, which is ${I} satoshi per byte for a transaction with a VSize of ${C} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function R(p,h){p.forEach(b=>{if((0,f.isTaprootInput)(b)?(0,f.checkTaprootInputForSigs)(b,h):(0,l.checkInputForSig)(b,h))throw new Error("Can not modify transaction, signatures exist.")})}function M(p){if(!p.sighashType||!p.partialSig)return;const{partialSig:h,sighashType:b}=p;h.forEach(I=>{const{hashType:C}=a.signature.decode(I.signature);if(b!==C)throw new Error("Signature sighash does not match input sighash type")})}function v(p,h,b){if(!(0,l.pubkeyInScript)(p,h))throw new Error(`Can not ${b} for this input with the key ${p.toString("hex")}`)}function U(p){if(!p.ins.every(b=>b.script&&b.script.length===0&&b.witness&&b.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function V(p,h){p.ins.forEach(b=>{K(h,b)})}function K(p,h){const b=(0,i.reverseBuffer)(Buffer.from(h.hash)).toString("hex")+":"+h.index;if(p.__TX_IN_CACHE[b])throw new Error("Duplicate input detected.");p.__TX_IN_CACHE[b]=1}function H(p,h){return(b,I,C,j)=>{const W=p({redeem:{output:C}}).output;if(!I.equals(W))throw new Error(`${h} for ${j} #${b} doesn't match the scriptPubKey in the prevout`)}}const $=H(o.p2sh,"Redeem script"),P=H(o.p2wsh,"Witness script");function D(p,h,b,I){if(!b.every(w))throw new Error(`PSBT must be finalized to calculate ${h}`);if(p==="__FEE_RATE"&&I.__FEE_RATE)return I.__FEE_RATE;if(p==="__FEE"&&I.__FEE)return I.__FEE;let C,j=!0;if(I.__EXTRACTED_TX?(C=I.__EXTRACTED_TX,j=!1):C=I.__TX.clone(),J(b,C,I,j),p==="__FEE_RATE")return I.__FEE_RATE;if(p==="__FEE")return I.__FEE}function F(p,h,b,I,C,j){const W=re(b);if(!E(h,b,W))throw new Error(`Can not finalize input #${p}`);return x(b,W,h.partialSig,I,C,j)}function x(p,h,b,I,C,j){let W,ie;const Q=ce(p,h,b),fe=j?o.p2wsh({redeem:Q}):null,he=C?o.p2sh({redeem:fe||Q}):null;return I?(fe?ie=(0,l.witnessStackToScriptWitness)(fe.witness):ie=(0,l.witnessStackToScriptWitness)(Q.witness),he&&(W=he.input)):he?W=he.input:W=Q.input,{finalScriptSig:W,finalScriptWitness:ie}}function B(p,h,b,I,C){const j=(0,n.checkForInput)(p,h),{hash:W,sighashType:ie,script:Q}=q(h,j,I,!1,C);return v(b,Q,"sign"),{hash:W,sighashType:ie}}function q(p,h,b,I,C){const j=b.__TX,W=h.sighashType||u.Transaction.SIGHASH_ALL;Y(W,C);let ie,Q;if(h.nonWitnessUtxo){const Ne=le(b,h,p),Pe=j.ins[p].hash,nt=Ne.getHash();if(!Pe.equals(nt))throw new Error(`Non-witness UTXO hash for input #${p} doesn't match the hash specified in the prevout`);const je=j.ins[p].index;Q=Ne.outs[je]}else if(h.witnessUtxo)Q=h.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:fe,type:he}=oe(Q.script,p,"input",h.redeemScript,h.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(he)>=0)ie=j.hashForWitnessV0(p,fe,Q.value,W);else if((0,l.isP2WPKH)(fe)){const Ne=o.p2pkh({hash:fe.slice(2)}).output;ie=j.hashForWitnessV0(p,Ne,Q.value,W)}else{if(h.nonWitnessUtxo===void 0&&b.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${p} has witnessUtxo but non-segwit script: ${fe.toString("hex")}`);!I&&b.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
74
74
|
*********************
|
|
75
75
|
PROCEED WITH CAUTION!
|
|
76
|
-
*********************`),ie=j.hashForSignature(p,fe,W)}return{script:fe,sighashType:W,hash:ie}}function N(p,h,b,I){const C=[];if(h.tapInternalKey){const W=L(p,h,I);W&&C.push(W)}if(h.tapScriptSig){const W=h.tapScriptSig.map(ie=>ie.pubkey);C.push(...W)}return C.map(W=>X(p,h,b,W,I)).flat()}function L(p,h,b){const{script:I}=qe(p,h,b);return(0,l.isP2TR)(I)?I.subarray(2,34):null}function G(p){return p.length===64?p:p.subarray(0,64)}function X(p,h,b,I,C,j,W){const ie=C.__TX,Q=h.sighashType||u.Transaction.SIGHASH_DEFAULT;Y(Q,W);const fe=b.map((je,Xn)=>qe(Xn,je,C)),he=fe.map(je=>je.script),Ne=fe.map(je=>je.value),Pe=[];if(h.tapInternalKey&&!j){const je=L(p,h,C)||Buffer.from([]);if((0,f.toXOnly)(I).equals(je)){const Xn=ie.hashForWitnessV1(p,he,Ne,Q);Pe.push({pubkey:I,hash:Xn})}}const nt=(h.tapLeafScript||[]).filter(je=>(0,l.pubkeyInScript)(I,je.script)).map(je=>{const Xn=(0,c.tapleafHash)({output:je.script,version:je.leafVersion});return Object.assign({hash:Xn},je)}).filter(je=>!j||j.equals(je.hash)).map(je=>{const Xn=ie.hashForWitnessV1(p,he,Ne,Q,je.hash);return{pubkey:I,hash:Xn,leafHash:je.hash}});return Pe.concat(nt)}function Y(p,h){if(h&&h.indexOf(p)<0){const b=we(p);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${b}`)}}function ce(p,h,b){let I;switch(h){case"multisig":const C=Z(p,b);I=o.p2ms({output:p,signatures:C});break;case"pubkey":I=o.p2pk({output:p,signature:b[0].signature});break;case"pubkeyhash":I=o.p2pkh({output:p,pubkey:b[0].pubkey,signature:b[0].signature});break;case"witnesspubkeyhash":I=o.p2wpkh({output:p,pubkey:b[0].pubkey,signature:b[0].signature});break}return I}function ue(p,h,b){const I=b.__TX,C={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(C.isP2SH=!!h.redeemScript,C.isP2WSH=!!h.witnessScript,h.witnessScript)C.script=h.witnessScript;else if(h.redeemScript)C.script=h.redeemScript;else if(h.nonWitnessUtxo){const j=le(b,h,p),W=I.ins[p].index;C.script=j.outs[W].script}else h.witnessUtxo&&(C.script=h.witnessUtxo.script);return(h.witnessScript||(0,l.isP2WPKH)(C.script))&&(C.isSegwit=!0),C}function te(p,h,b){const I=(0,n.checkForInput)(h,p);if(!I.bip32Derivation||I.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const C=I.bip32Derivation.map(W=>{if(W.masterFingerprint.equals(b.fingerprint))return W}).filter(W=>!!W);if(C.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return C.map(W=>{const ie=b.derivePath(W.path);if(!W.pubkey.equals(ie.publicKey))throw new Error("pubkey did not match bip32Derivation");return ie})}function Z(p,h){return o.p2ms({output:p}).pubkeys.map(I=>(h.filter(C=>C.pubkey.equals(I))[0]||{}).signature).filter(I=>!!I)}function ae(p){let h=0;function b(W){return h+=W,p.slice(h-W,h)}function I(){const W=t.decode(p,h);return h+=t.decode.bytes,W}function C(){return b(I())}function j(){const W=I(),ie=[];for(let Q=0;Q<W;Q++)ie.push(C());return ie}return j()}function we(p){let h=p&u.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(p&31){case u.Transaction.SIGHASH_ALL:h+="SIGHASH_ALL";break;case u.Transaction.SIGHASH_SINGLE:h+="SIGHASH_SINGLE";break;case u.Transaction.SIGHASH_NONE:h+="SIGHASH_NONE";break}return h}function ye(p,h,b){p.__NON_WITNESS_UTXO_BUF_CACHE[b]=h.nonWitnessUtxo;const I=u.Transaction.fromBuffer(h.nonWitnessUtxo);p.__NON_WITNESS_UTXO_TX_CACHE[b]=I;const C=p,j=b;delete h.nonWitnessUtxo,Object.defineProperty(h,"nonWitnessUtxo",{enumerable:!0,get(){const W=C.__NON_WITNESS_UTXO_BUF_CACHE[j],ie=C.__NON_WITNESS_UTXO_TX_CACHE[j];if(W!==void 0)return W;{const Q=ie.toBuffer();return C.__NON_WITNESS_UTXO_BUF_CACHE[j]=Q,Q}},set(W){C.__NON_WITNESS_UTXO_BUF_CACHE[j]=W}})}function J(p,h,b,I){let C=0;p.forEach((Q,fe)=>{if(I&&Q.finalScriptSig&&(h.ins[fe].script=Q.finalScriptSig),I&&Q.finalScriptWitness&&(h.ins[fe].witness=ae(Q.finalScriptWitness)),Q.witnessUtxo)C+=Q.witnessUtxo.value;else if(Q.nonWitnessUtxo){const he=le(b,Q,fe),Ne=h.ins[fe].index,Pe=he.outs[Ne];C+=Pe.value}});const j=h.outs.reduce((Q,fe)=>Q+fe.value,0),W=C-j;if(W<0)throw new Error("Outputs are spending more than Inputs");const ie=h.virtualSize();b.__FEE=W,b.__EXTRACTED_TX=h,b.__FEE_RATE=Math.floor(W/ie)}function le(p,h,b){const I=p.__NON_WITNESS_UTXO_TX_CACHE;return I[b]||ye(p,h,b),I[b]}function Ae(p,h,b){const{script:I}=qe(p,h,b);return I}function qe(p,h,b){if(h.witnessUtxo!==void 0)return{script:h.witnessUtxo.script,value:h.witnessUtxo.value};if(h.nonWitnessUtxo!==void 0){const C=le(b,h,p).outs[b.__TX.ins[p].index];return{script:C.script,value:C.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function tt(p,h,b,I){const C=Ae(b,h,I),{meaningfulScript:j}=oe(C,b,"input",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(p,j)}function ut(p,h,b,I){const C=I.__TX.outs[b].script,{meaningfulScript:j}=oe(C,b,"output",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(p,j)}function It(p){if(!p)return;const h=a.decompile(p);if(!h)return;const b=h[h.length-1];if(!(!Buffer.isBuffer(b)||it(b)||Ce(b)||!a.decompile(b)))return b}function Oe(p){if(!p)return;const h=ae(p),b=h[h.length-1];if(!(it(b)||!a.decompile(b)))return b}function mn(p){if(p.length===65){const h=p[64]&1,b=p.slice(0,33);return b[0]=2|h,b}return p.slice()}function it(p){return p.length===33&&a.isCanonicalPubKey(p)}function Ce(p){return a.isCanonicalScriptSignature(p)}function oe(p,h,b,I,C){const j=(0,l.isP2SHScript)(p),W=j&&I&&(0,l.isP2WSHScript)(I),ie=(0,l.isP2WSHScript)(p);if(j&&I===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((ie||W)&&C===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let Q;return W?(Q=C,$(h,p,I,b),P(h,I,C,b),ne(Q)):ie?(Q=C,P(h,p,C,b),ne(Q)):j?(Q=I,$(h,p,I,b)):Q=p,{meaningfulScript:Q,type:W?"p2sh-p2wsh":j?"p2sh":ie?"p2wsh":"raw"}}function ne(p){if((0,l.isP2WPKH)(p)||(0,l.isP2SHScript)(p))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function re(p){return(0,l.isP2WPKH)(p)?"witnesspubkeyhash":(0,l.isP2PKH)(p)?"pubkeyhash":(0,l.isP2MS)(p)?"multisig":(0,l.isP2PK)(p)?"pubkey":"nonstandard"}function k(p){return[...Array(p).keys()]}return mo}var oy;function BA(){return oy||(oy=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=xh();e.address=t;const n=Pr();e.crypto=n;const r=Wn();e.networks=r;const i=Ec();e.payments=i;const s=rn();e.script=s;var o=rA();Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return o.Block}});var c=OA();Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return c.Psbt}});var a=bh();Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return a.OPS}});var u=_c();Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}});var f=Sh();Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return f.initEccLib}})})(yf)),yf}var Oi={},cy;function NA(){if(cy)return Oi;cy=1,Object.defineProperty(Oi,"__esModule",{value:!0}),Oi.base26Decode=Oi.base26Encode=void 0;function e(n){let r=0n;for(let i=0;i<n.length;i++){const s=BigInt(n.charCodeAt(i)-65),o=BigInt(n.length)-1n-BigInt(i);if(o==0n)r+=s;else{const c=26n**o;r+=c*(s+1n)}}return r}Oi.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let r=[];for(;n>0;){const i=(n-1n)%26n;r.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(i))),n=(n-1n)/26n}return r.reverse().join("")}return Oi.base26Decode=t,Oi}var Bi={},ay;function Jw(){if(ay)return Bi;ay=1,Object.defineProperty(Bi,"__esModule",{value:!0}),Bi.none=Bi.some=void 0;class e{constructor(){}isSome(){return!1}map(s){return new e}value(){return null}}class t{constructor(s){this._value=s}isSome(){return!0}map(s){return new t(s(this.value()))}value(){return this._value}}function n(i){return new t(i)}Bi.some=n;function r(){return new e}return Bi.none=r,Bi}var Ni={},uy;function kA(){if(uy)return Ni;uy=1,Object.defineProperty(Ni,"__esModule",{value:!0}),Ni.decodeLEB128=Ni.encodeLEB128=void 0;function e(n){const r=[];let i=!0;for(;i;){let s=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?i=!1:s|=128,r.push(s)}return r}Ni.encodeLEB128=e;function t(n){let r=BigInt(0);for(let i=0;i<n.length;i++){const s=BigInt(n[i]);if(i>18)throw new Error("Overlong");let o=s&BigInt(127);if(i==18&&(o&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(r|=o<<BigInt(7)*BigInt(i),(s&BigInt(128))==BigInt(0))return{n:r,len:i+1}}throw new Error("Unterminated")}return Ni.decodeLEB128=t,Ni}var Rf={},fy;function PA(){return fy||(fy=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=s=>s.length%2===1?"0"+s:s;e.zero2=t;const n=s=>{let o="";for(let c=0;c<s.length;c++)o+=(0,e.zero2)(s[c].toString(16));return o};e.toHex=n;function r(s,o){const c=[];let a=0;for(;a<s.length;){const u=s.slice(a,a+o);c.push(u),a+=o}return c}e.chunks=r;function i(s){const o=[],c=s.length;if(c<76){const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=255){o.push(Buffer.from("4c","hex"));const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=65535){o.push(Buffer.from("4d","hex"));const a=Buffer.alloc(2);a.writeUInt16LE(c),o.push(a)}else{o.push(Buffer.from("4e","hex"));const a=Buffer.alloc(4);a.writeUInt32LE(c),o.push(a)}return o.push(s),Buffer.concat(o)}e.toPushData=i})(Rf)),Rf}var hr={},ly;function Qw(){if(ly)return hr;ly=1,Object.defineProperty(hr,"__esModule",{value:!0}),hr.removeSpacers=hr.getSpacersVal=hr.applySpacers=void 0;function e(r,i){let s="";for(let o=0;o<r.length;o++)s+=r.charAt(o),i>0&&((i&1)===1&&(s+="•"),i>>=1);return s}hr.applySpacers=e;function t(r){let i=0,s=0;for(let o=0;o<r.length;o++)r.charAt(o)==="•"&&(i+=1<<o-1-s,s++);return i}hr.getSpacersVal=t;function n(r){return r.replace(/[•]+/g,"")}return hr.removeSpacers=n,hr}var hy;function RA(){if(hy)return Xe;hy=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.EtchInscription=Xe.Message=Xe.Runestone=Xe.Etching=Xe.Rune=Xe.Terms=Xe.Range=Xe.Flaw=Xe.Tag=Xe.Flag=Xe.Edict=Xe.RuneId=void 0;const e=BA(),t=NA(),n=Jw(),r=kA(),i=PA(),s=Qw();class o{constructor(w,T){this.block=w,this.idx=T}next(w,T){if(w>BigInt(Number.MAX_SAFE_INTEGER)||T>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let O=BigInt(this.block)+w;if(O>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let A=w===0n?BigInt(this.idx)+T:T;return A>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new o(Number(O),Number(A)))}}Xe.RuneId=o;class c{constructor(w,T,O){this.id=w,this.amount=T,this.output=O}static from_integers(w,T,O,A){return A>4294967295n||A<0n||Number(A)>w.outs.length?(0,n.none)():(0,n.some)(new c(T,O,Number(A)))}}Xe.Edict=c;var a;(function(S){S[S.Etching=0]="Etching",S[S.Terms=1]="Terms",S[S.Turbo=2]="Turbo",S[S.Cenotaph=127]="Cenotaph"})(a||(Xe.Flag=a={}));var u;(function(S){S[S.Body=0]="Body",S[S.Flags=2]="Flags",S[S.Rune=4]="Rune",S[S.Premine=6]="Premine",S[S.Cap=8]="Cap",S[S.Amount=10]="Amount",S[S.HeightStart=12]="HeightStart",S[S.HeightEnd=14]="HeightEnd",S[S.OffsetStart=16]="OffsetStart",S[S.OffsetEnd=18]="OffsetEnd",S[S.Mint=20]="Mint",S[S.Pointer=22]="Pointer",S[S.Cenotaph=126]="Cenotaph",S[S.Divisibility=1]="Divisibility",S[S.Spacers=3]="Spacers",S[S.Symbol=5]="Symbol",S[S.Nop=127]="Nop"})(u||(Xe.Tag=u={}));var f;(function(S){S[S.EdictOutput=0]="EdictOutput",S[S.EdictRuneId=1]="EdictRuneId",S[S.InvalidScript=2]="InvalidScript",S[S.Opcode=3]="Opcode",S[S.SupplyOverflow=4]="SupplyOverflow",S[S.TrailingIntegers=5]="TrailingIntegers",S[S.TruncatedField=6]="TruncatedField",S[S.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",S[S.UnrecognizedFlag=8]="UnrecognizedFlag",S[S.Varint=9]="Varint"})(f||(Xe.Flaw=f={}));class l{constructor(w,T){this.start=w,this.end=T}}Xe.Range=l;class d{constructor(w,T,O,A){this.amount=w,this.cap=T,this.height=O,this.offset=A}}Xe.Terms=d;class y{constructor(w){this.value=w}get name(){return y.toName(this.value)}static toName(w){return(0,t.base26Decode)(w)}static fromName(w){return new y((0,t.base26Encode)((0,s.removeSpacers)(w)))}toString(){return this.name}}Xe.Rune=y;class g{constructor(w,T,O,A,R,M,v){this.divisibility=w,this.premine=T,this.rune=O,this.spacers=A,this.symbol=R,this.terms=M,this.turbo=v}}Xe.Etching=g,g.MAX_DIVISIBILITY=38,g.MAX_SPACERS=134217727;class m{constructor(w=[],T,O,A){this.edicts=w,this.etching=T,this.mint=O,this.pointer=A}static create(w,T="etch"){if(T==="etch"){w=w;const O=y.fromName(w.name),A=new d(w.amount,w.cap,new l(w.startHeight?(0,n.some)(w.startHeight):(0,n.none)(),w.endHeight?(0,n.some)(w.endHeight):(0,n.none)()),new l(w.startOffset?(0,n.some)(w.startOffset):(0,n.none)(),w.endOffset?(0,n.some)(w.endOffset):(0,n.none)())),R=w.divisibility?(0,n.some)(w.divisibility):(0,n.none)(),M=w.premine?(0,n.some)(w.premine):(0,n.none)(),v=w.name.indexOf("•")>-1?(0,n.some)((0,s.getSpacersVal)(w.name)):(0,n.none)(),U=w.symbol?(0,n.some)(w.symbol):(0,n.none)(),V=typeof w.pointer=="number"?(0,n.some)(w.pointer):(0,n.none)(),K=new g(R,M,(0,n.some)(O),v,U,(0,n.some)(A),!0);return new m([],(0,n.some)(K),(0,n.none)(),V)}else if(T==="mint"){w=w;const O=typeof w.pointer=="number"?(0,n.some)(w.pointer):(0,n.none)();return new m([],(0,n.none)(),(0,n.some)(new o(w.block,w.txIdx)),O)}else throw new Error(`not ${T} support now`)}static decipher(w){const T=e.Transaction.fromHex(w),O=m.payload(T);if(O.isSome()){const A=m.integers(O.value()),R=E.from_integers(T,A.value()),M=R.getEtching(),v=R.getMint(),U=R.getPointer();return(0,n.some)(new m(R.edicts,M,v,U))}return(0,n.none)()}encipher(){const T=this.toMessage().toBuffer(),O=Buffer.from("6a5d","hex");let A;if(T.length<76)A=Buffer.alloc(1),A.writeUInt8(T.length);else if(T.length<256)A=Buffer.alloc(2),A.writeUInt8(76),A.writeUInt8(T.length);else if(T.length<65536)A=Buffer.alloc(3),A.writeUInt8(77),A.writeUInt16LE(T.length);else if(T.length<4294967296)A=Buffer.alloc(5),A.writeUInt8(78),A.writeUInt32LE(T.length);else throw new Error("runestone too big!");return Buffer.concat([O,A,T])}static payload(w){for(const T of w.outs){const O=e.script.decompile(T.script);if(O[0]===e.script.OPS.OP_RETURN&&O[1]===m.MAGIC_NUMBER){for(let A=2;A<O.length;A++){const R=O[A];return R instanceof Uint8Array?(0,n.some)(Array.from(R)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(w){let T=[],O=0;for(;O<w.length;){let{n:A,len:R}=(0,r.decodeLEB128)(w.slice(O));T.push(A),O+=R}return(0,n.some)(T)}toMessage(){let w=new Map;const T=this.etching.value();if(T){let R=1;if(T.terms.isSome()){let $=1<<a.Terms;R|=$}if(T.turbo){let $=1<<a.Turbo;R|=$}w.set(u.Flags,[BigInt(R)]);const M=T.rune.value();M!==null&&w.set(u.Rune,[BigInt(M.value)]);const v=T.divisibility.value();v!==null&&w.set(u.Divisibility,[BigInt(v)]);const U=T.spacers.value();U!==null&&w.set(u.Spacers,[BigInt(U)]);const V=T.symbol.value();V!==null&&w.set(u.Symbol,[BigInt(V.charCodeAt(0))]);const K=T.premine.value();K!==null&&w.set(u.Premine,[BigInt(K)]);const H=T.terms.value();if(H!==null){w.set(u.Amount,[BigInt(H.amount)]),w.set(u.Cap,[BigInt(H.cap)]);const $=H.height.start.value();$&&w.set(u.HeightStart,[BigInt($)]);const P=H.height.end.value();P&&w.set(u.HeightEnd,[BigInt(P)]);const D=H.offset.start.value();D&&w.set(u.OffsetStart,[BigInt(D)]);const F=H.offset.end.value();F&&w.set(u.OffsetEnd,[BigInt(F)])}}const O=this.mint.value();O!==null&&w.set(u.Mint,[BigInt(O.block),BigInt(O.idx)]);const A=this.pointer.value();return A!==null&&w.set(u.Pointer,[BigInt(A)]),new E(w,this.edicts,0)}}Xe.Runestone=m,m.MAGIC_NUMBER=93;class E{constructor(w=new Map,T=[],O=0){this.fields=w,this.edicts=T,this.flaws=O}static from_integers(w,T){let O=new Map,A=[],R=0,M=!1;for(let v=0;v<T.length;){let U=T[v];if(Number(U)===u.Body){M=!0,v+=1;continue}if(M){let V=new o(0,0);for(const K of(0,i.chunks)(T.slice(v),4)){if(K.length!=4){R|=f.TrailingIntegers;break}let H=V.next(K[0],K[1]);if(!H.isSome()){R|=f.EdictRuneId;break}const $=c.from_integers(w,H.value(),K[2],K[3]);if(!$.isSome()){R|=f.EdictOutput;break}V=H.value(),A.push($.value())}v+=4}else{let V=T[v+1];const K=O.get(Number(U))||[];K.push(V),O.set(Number(U),K),v+=2}}return new E(O,A,R)}addFieldVal(w,T){const O=this.fields.get(Number(w))||[];O.push(T),this.fields.set(Number(w),O)}addEdict(w){this.edicts.push(w)}toBuffer(){const w=[];for(const[T,O]of this.fields)for(const A of O){const R=Buffer.alloc(1);R.writeUInt8(T),w.push(R),w.push(Buffer.from((0,r.encodeLEB128)(A)))}if(this.edicts.length>0){w.push(Buffer.from("00","hex")),this.edicts.sort((A,R)=>A.id.block==R.id.block?A.id.idx-R.id.idx:A.id.block-R.id.block);let T=0n,O=0n;for(let A=0;A<this.edicts.length;A++){const R=this.edicts[A];if(A==0)T=BigInt(R.id.block),O=BigInt(R.id.idx),w.push(Buffer.from((0,r.encodeLEB128)(T))),w.push(Buffer.from((0,r.encodeLEB128)(O)));else{const M=BigInt(R.id.block),v=BigInt(R.id.idx);if(M==T){const U=v-O;O=v,w.push(Buffer.from((0,r.encodeLEB128)(0n))),w.push(Buffer.from((0,r.encodeLEB128)(U)))}else{const U=M-T;T=M,O=v,w.push(Buffer.from((0,r.encodeLEB128)(U))),w.push(Buffer.from((0,r.encodeLEB128)(v)))}}w.push(Buffer.from((0,r.encodeLEB128)(BigInt(R.amount)))),w.push(Buffer.from((0,r.encodeLEB128)(BigInt(R.output))))}}return Buffer.concat(w)}getFlags(){return Number(this.fields.get(u.Flags))}hasFlags(w){const T=this.getFlags(),O=1<<w;return(T&O)!=0}getMint(){if(!this.fields.has(u.Mint))return(0,n.none)();const[w,T]=this.fields.get(u.Mint);return(0,n.some)(new o(Number(w),Number(T)))}getEtching(){if(!this.hasFlags(a.Etching))return(0,n.none)();const w=this.getDivisibility(),T=this.getPremine(),O=this.getRune(),A=this.getSpacers(),R=this.getSymbol(),M=this.getTerms(),v=this.hasFlags(a.Turbo);return(0,n.some)(new g(w,T,O,A,R,M,v))}getDivisibility(){if(!this.fields.has(u.Divisibility))return(0,n.none)();const[w]=this.fields.get(u.Divisibility);if(w>g.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(w))}getPremine(){if(!this.fields.has(u.Premine))return(0,n.none)();const[w]=this.fields.get(u.Premine);return(0,n.some)(Number(w))}getRune(){if(!this.fields.has(u.Rune))return(0,n.none)();const[w]=this.fields.get(u.Rune);return(0,n.some)(new y(w))}getSpacers(){if(!this.fields.has(u.Spacers))return(0,n.none)();const[w]=this.fields.get(u.Spacers);if(w>g.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(w))}getHeightStart(){if(!this.fields.has(u.HeightStart))return(0,n.none)();const[w]=this.fields.get(u.HeightStart);return(0,n.some)(Number(w))}getHeightEnd(){if(!this.fields.has(u.HeightEnd))return(0,n.none)();const[w]=this.fields.get(u.HeightEnd);return(0,n.some)(Number(w))}getOffsetStart(){if(!this.fields.has(u.OffsetStart))return(0,n.none)();const[w]=this.fields.get(u.OffsetStart);return(0,n.some)(Number(w))}getOffsetEnd(){if(!this.fields.has(u.OffsetEnd))return(0,n.none)();const[w]=this.fields.get(u.OffsetEnd);return(0,n.some)(Number(w))}getCap(){if(!this.fields.has(u.Cap))return(0,n.none)();const[w]=this.fields.get(u.Cap);return(0,n.some)(Number(w))}getAmount(){if(!this.fields.has(u.Amount))return(0,n.none)();const[w]=this.fields.get(u.Amount);return(0,n.some)(Number(w))}getSymbol(){if(!this.fields.has(u.Symbol))return(0,n.none)();const[w]=this.fields.get(u.Symbol);return(0,n.some)(String.fromCharCode(Number(w)))}getTerms(){if(!this.hasFlags(a.Terms))return(0,n.none)();const w=this.getCap();if(!w.isSome())throw new Error("no cap field");const T=this.getAmount();if(!T.isSome())throw new Error("no amount field");const O=this.getHeightStart(),A=this.getHeightEnd(),R=this.getOffsetStart(),M=this.getOffsetEnd(),v=new l(O,A),U=new l(R,M);return(0,n.some)(new d(T.value(),w.value(),v,U))}getPointer(){if(!this.fields.has(u.Pointer))return(0,n.none)();const[w]=this.fields.get(u.Pointer);return(0,n.some)(Number(w))}}Xe.Message=E;class _{constructor(w=new Map,T=Buffer.alloc(0)){this.fields=w,this.data=T}setContent(w,T){this.fields.set(1,Buffer.from(w,"utf8")),this.data=T}setRune(w){let O=(0,t.base26Encode)((0,s.removeSpacers)(w)).toString(16);O.length%2===1&&(O="0"+O),this.setField(_.Tag.RUNE,Buffer.from(O,"hex").reverse())}setField(w,T){this.fields.set(w,T)}static decipher(w,T){const R=e.Transaction.fromHex(w).ins[T].witness[1],M=e.script.decompile(R),v=new Map,U=[];let V=!1;for(let K=5;K<M.length-1;){const H=M[K];if(H===0){V=!0,K++;continue}else if(V)U.push(H),K++;else{const $=H-80,P=M[K+1];if(typeof P=="number"){const D=Buffer.alloc(1);D.writeUInt8(P),v.set($,D)}else v.set($,P);K+=2}}return new _(v,Buffer.concat(U))}encipher(){const w=[];if(this.data&&this.data.length>0){w.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((O,A)=>O[0]-A[0]).forEach(([O,A])=>{const R=Buffer.alloc(1);R.writeUInt8(O),w.push(Buffer.from("01","hex")),w.push(R),A.length!=1||A[0]!=0?w.push((0,i.toPushData)(A)):w.push(A)}),w.push(Buffer.from("00","hex"));const T=(0,i.chunks)(Array.from(this.data),520);for(const O of T)w.push((0,i.toPushData)(Buffer.from(O)))}else{w.push(Buffer.from("0063","hex"));const T=this.fields.get(_.Tag.RUNE);if(!T)throw new Error("No rune found!");w.push((0,i.toPushData)(T))}return w.push(Buffer.from("68","hex")),Buffer.concat(w)}}return Xe.EtchInscription=_,_.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},Xe}var dy;function UA(){return dy||(dy=1,(function(e){var t=Ei&&Ei.__createBinding||(Object.create?(function(s,o,c,a){a===void 0&&(a=c);var u=Object.getOwnPropertyDescriptor(o,c);(!u||("get"in u?!o.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return o[c]}}),Object.defineProperty(s,a,u)}):(function(s,o,c,a){a===void 0&&(a=c),s[a]=o[c]})),n=Ei&&Ei.__exportStar||function(s,o){for(var c in s)c!=="default"&&!Object.prototype.hasOwnProperty.call(o,c)&&t(o,s,c)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(RA(),e);var r=Jw();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return r.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return r.some}});var i=Qw();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return i.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return i.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return i.removeSpacers}})})(Ei)),Ei}var fs=UA();function Eo(e){if(e.length%2!==0)throw new Error("Hex string must have even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}function Ih(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Oh(e){return e===Ns.Mainnet?Pn:Fy}function Bh(e,t=Ns.Testnet){const n=Oh(t);return Ag(e,n)}function si(e){const t=Pn,n=Fy,r=D1;let i,s,o=Jt.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return s=kl(e),s.version===0?s.data.length===20?o=Jt.P2WPKH:o=Jt.P2WSH:o=Jt.P2TR,o}catch{return Jt.UNKNOWN}else try{return i=xg(e),i.version===t.pubKeyHash||i.version===n.pubKeyHash||i.version===r.pubKeyHash?o=Jt.P2PKH:(i.version===t.scriptHash||(i.version,n.scriptHash),o=Jt.P2SH_P2WPKH),o}catch{return Jt.UNKNOWN}}function CA(e,t,n){const r=Bh(e,n),i=t.coins?.[0];return{txid:t.txid,vout:t.vout,satoshis:t.sats.toString(),height:void 0,runes:i?[{id:i.id,amount:i.value.toString()}]:[],address:e,scriptPk:Ih(r)}}async function e1(e,t){try{const n=t===Ns.Mainnet?"https://mpc.omnity.network/utxo-status":"https://mpc.omnity.network/testnet4/utxo-status",r=await ht.post(n,e).then(c=>c.data);if(!r)return null;const i=JSON.stringify(r),o=new TextEncoder().encode(i);return Array.from(o)}catch{return null}}const HA=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:Ih,formatPoolUtxo:CA,getAddressType:si,getScriptByAddress:Bh,getUtxoProof:e1,hexToBytes:Eo,toBitcoinNetwork:Oh},Symbol.toStringTag,{value:"Module"})),FA="kqs64-paaaa-aaaar-qamza-cai",MA="hvyp5-5yaaa-aaaao-qjxha-cai",Qr=BigInt(546),on="0:0",qA="https://runescan-hasura-mainnet.omnity.network/v1/graphql",VA="https://runescan-hasura-testnet.omnity.network/v1/graphql",py={P2PKH:148,P2SH_P2WPKH:91,P2WPKH:68,P2WSH:140,P2SH:108,P2TR:58,UNKNOWN:110},yy={P2PKH:34,P2SH_P2WPKH:32,P2WPKH:31,P2WSH:43,P2SH:32,P2TR:43,UNKNOWN:34},LA=new Set(["P2WPKH","P2WSH","P2SH_P2WPKH","P2TR"]),$A=2;class oi{psbt;client;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);intentions=[];txFee=BigInt(0);additionalDustNeeded=BigInt(0);inputUtxos=[];constructor(t,n){this.config=t,this.psbt=new ma({network:Oh(t.network)}),this.client=n}addInput(t){if(this.inputUtxos.findIndex(i=>i.txid===t.txid&&i.vout===t.vout)>=0)return;const{address:n}=t;if(si(n)===Jt.P2TR){let i=t.pubkey;i||t.address===this.config.address&&this.config.publicKey&&(i=this.config.publicKey);const s=i?i.length===66?i.slice(2):i:void 0;s?this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:Eo(t.scriptPk)},tapInternalKey:Eo(s)}):this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:Eo(t.scriptPk)}})}else this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:Eo(t.scriptPk)}});this.inputAddressTypes.push(si(n)),this.inputUtxos.push(t),(n===this.config.address||n===this.config.paymentAddress)&&t.runes.length!==0&&(this.userInputUtxoDusts+=BigInt(t.satoshis))}addOutput(t,n){this.psbt.addOutput({address:t,value:n}),this.outputAddressTypes.push(si(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:BigInt(0)}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,r){const i=[];if(r==BigInt(0))return i;for(const s of t)if(s.runes.length){const o=s.runes.find(c=>c.id==n);if(o&&BigInt(o.amount)==r){i.push(s);break}}if(i.length==0){let s=BigInt(0);for(const o of t)if(o.runes.forEach(c=>{c.id==n&&(s=s+BigInt(c.amount))}),i.push(o),s>=r)break;if(s<r)throw new Error("INSUFFICIENT_RUNE_UTXOs")}return i}selectBtcUtxos(t,n,r=!1){const i=[];if(n<=BigInt(0))return i;let s=BigInt(0);for(const o of t)if(!(o.runes.length&&!r)&&(s+=BigInt(o.satoshis),i.push(o),s>=n))break;if(s<n)throw new Error(`Insufficient BTC UTXOs: need ${n}, have ${s}`);return i}async addBtcAndFees(t,n){const r=this.config.paymentAddress,i=this.additionalDustNeeded,s=si(r),o=this.userInputUtxoDusts,c=this.config.feeRate;this.outputAddressTypes.push(s);let a=!0,u=BigInt(0),f=BigInt(0),l=[],d=BigInt(0),y=BigInt(0);const g=[...this.inputAddressTypes];do{if(u=f,c!==void 0){const _=oi.estimateTxVirtualSize(this.inputAddressTypes,this.outputAddressTypes);f=BigInt(Math.round(c*_))}else f=(await this.client.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes,pool_address:this.intentions.map(S=>S.poolAddress),output_types:this.outputAddressTypes}).catch(S=>{throw console.error("estimate_min_tx_fee failed:",S),S})).Ok;if(d=n+f+i-o,f>u&&d>0){const _=this.selectBtcUtxos(t,d);if(_.length===0)throw new Error("INSUFFICIENT_BTC_UTXOs");this.inputAddressTypes=g.concat(_.map(()=>s));const S=_.reduce((w,T)=>w+BigInt(T.satoshis),BigInt(0));S-d>0&&S-d>Qr||(this.outputAddressTypes.pop(),a=!1),l=_}}while(f>u&&d>0);this.inputAddressTypes=[...g],a&&this.outputAddressTypes.pop();let m=BigInt(0);l.forEach(_=>{this.addInput(_),m+=BigInt(_.satoshis)});const E=m-d;if(E<0)throw new Error("Insufficient UTXO(s)");E>Qr?this.addOutput(r,E):E>BigInt(0)&&(y=E),this.txFee=y+f}async getInvolvedAddressUtxos(){const t={},n={},r=new Map,i=this.intentions.map(o=>o.poolAddress);r.set(this.config.paymentAddress,{needBtc:!0,runeIds:new Set});const s=o=>{const c=o.trim();return r.has(c)||r.set(c,{needBtc:!1,runeIds:new Set}),r.get(c)};for(const o of this.intentions){for(const u of o.inputCoins){const f=s(u.from);u.coin.id===on?f.needBtc=!0:f.runeIds.add(u.coin.id)}for(const u of o.outputCoins){const f=s(u.to);u.coin.id===on?f.needBtc=!0:f.runeIds.add(u.coin.id)}const c=s(o.poolAddress),a=[...o.inputCoins.map(u=>u.coin.id),...o.outputCoins.map(u=>u.coin.id)];for(const u of a)u===on?c.needBtc=!0:c.runeIds.add(u)}return await Promise.all(Array.from(r.entries()).map(async([o,c])=>{if(c.needBtc)try{t[o]=await this.client.getBtcUtxos(o,!i.includes(o))}catch{t[o]=[]}c.runeIds.size>0&&(n[o]={},await Promise.all(Array.from(c.runeIds).map(async a=>{try{n[o][a]=await this.client.getRuneUtxos(o,a)}catch{n[o][a]=[]}})))})),{btc:t,rune:n}}addInputsAndCalculateOutputs(t){if(!this.intentions.length)throw new Error("No intentions added");const n=this.intentions.map(a=>a.poolAddress),r={},i={};let s=BigInt(0);const o=new Map,c=new Set;this.intentions.forEach(({poolAddress:a,inputCoins:u,outputCoins:f,poolUtxos:l})=>{const d=[...u.filter(({from:g})=>!n.includes(g))],y=[...f];if(d.forEach(({coin:g,from:m})=>{!f.find(E=>E.coin.id===g.id)&&!(n.includes(m)&&m!==a)&&y.push({coin:g,to:a})}),y.forEach(({coin:g})=>{u.find(m=>m.coin.id===g.id)||d.push({coin:g,from:a})}),d.length===0&&y.length===0&&l?.length){const g=o.get(a);o.set(a,g?g.concat(l):[...l]),c.add(a);return}d.forEach(({coin:g,from:m})=>{r[m]??={},r[m][g.id]=(r[m][g.id]??BigInt(0))+BigInt(g.value)}),y.forEach(({coin:g,to:m})=>{i[m]??={},i[m][g.id]=(i[m][g.id]??BigInt(0))+BigInt(g.value)})});for(const[a,u]of o.entries()){if(!u.length)continue;i[a]??={};const f=i[a];u.forEach(l=>{this.addInput(l),f[on]=(f[on]??BigInt(0))+BigInt(l.satoshis),l.runes.forEach(d=>{f[d.id]=(f[d.id]??BigInt(0))+BigInt(d.amount)})})}for(const[a,u]of Object.entries(r))for(const[f,l]of Object.entries(u))if(f===on){if(a===this.config.paymentAddress){s+=l;continue}const d=t.btc[a]||[],y=this.selectBtcUtxos(d,l,n.includes(a)),m=y.reduce((E,_)=>E+BigInt(_.satoshis),BigInt(0))-l;m>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+m),y.forEach(E=>{this.addInput(E),n.includes(a)&&E.runes.forEach(_=>{(r[a]?.[_.id]??BigInt(0))>BigInt(0)||(i[a]??={},i[a][_.id]=(i[a][_.id]??BigInt(0))+BigInt(_.amount))})})}else{const d=t.rune[a]?.[f]||[],y=this.selectRuneUtxos(d,f,l),g=y.reduce((_,S)=>{const w=S.runes.find(T=>T.id===f);return _+BigInt(w?.amount??0)},BigInt(0)),m=y.reduce((_,S)=>_+BigInt(S.satoshis),BigInt(0)),E=g-l;if(n.includes(a)){i[a]??={};const _=i[a],S=(r[a]?.[on]??BigInt(0))>BigInt(0);m>BigInt(0)&&!S&&(_[on]=(_[on]??BigInt(0))+m),E>BigInt(0)&&(_[f]=(_[f]??BigInt(0))+E)}else E>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+E);y.forEach(_=>this.addInput(_))}for(const[a,u]of Object.entries(i))if(!(r[a]||!n.includes(a)||c.has(a)))for(const[f]of Object.entries(u))if(f===on){const l=t.btc[a]||[],d=l.reduce((y,g)=>y+BigInt(g.satoshis),BigInt(0));i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+d,l.forEach(y=>{this.addInput(y),y.runes.forEach(g=>{i[a]??={},i[a][g.id]=(i[a][g.id]??BigInt(0))+BigInt(g.amount)})})}else{const l=t.rune[a]?.[f]||[],d=l.reduce((y,g)=>{const m=g.runes.find(E=>E.id===f);return y+BigInt(m?.amount??0)},BigInt(0));i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+d,l.forEach(y=>this.addInput(y))}return{addressOutputCoinAmounts:i,paymentBtcRequired:s}}addOutputs(t){const n=this.config.mergeSelfRuneBtcOutputs===!0,r=new Set;for(const[,s]of Object.entries(t))for(const o of Object.keys(s))o!==on&&r.add(o);const i=Array.from(r);if(i.length>0){const s=[],o=[];let c=1;i.forEach(u=>{const f=new fs.RuneId(Number(u.split(":")[0]),Number(u.split(":")[1]));for(const[l,d]of Object.entries(t)){const y=d[u]??BigInt(0);y>BigInt(0)&&(s.push(new fs.Edict(f,y,c)),o.push(l),c++)}});const a=new fs.Runestone(s,fs.none(),fs.none(),fs.none());this.addScriptOutput(new Uint8Array(a.encipher())),o.forEach(u=>{const f=t[u]?.[on]??BigInt(0),l=u===this.config.address,d=f>BigInt(0)&&(!l||n),y=d&&f>Qr?f:Qr;this.addOutput(u,y),d?(f<Qr&&(this.additionalDustNeeded+=Qr-f),delete t[u][on]):this.additionalDustNeeded+=Qr})}for(const[s,o]of Object.entries(t)){const c=o[on]??BigInt(0);c>BigInt(0)&&this.addOutput(s,c)}}addIntention(t){this.intentions.push(t)}async build(){const t=await this.getInvolvedAddressUtxos();for(const f of this.intentions){const l=f.poolUtxos;if(!l)continue;t.btc[f.poolAddress]=l,t.rune[f.poolAddress]={};const d=t.rune[f.poolAddress];for(const y of l)for(const g of y.runes)(d[g.id]??=[]).push(y)}const{addressOutputCoinAmounts:n,paymentBtcRequired:r}=this.addInputsAndCalculateOutputs(t);this.addOutputs(n);const i=this.config.paymentAddress,s=t.btc[i]??[];await this.addBtcAndFees(s,r);const c=this.psbt.__CACHE.__TX.clone(),a=[];for(let f=0;f<this.inputUtxos.length;f++){const l=this.inputUtxos[f],d=l.address;if(d!==this.config.paymentAddress||d!==this.config.address)continue;const y=this.psbt.data.inputs[f].redeemScript,g=si(d);if(a.push({index:f,...g===Jt.P2TR?{address:d,disableTweakSigner:!1}:{publicKey:l.pubkey,disableTweakSigner:!0}}),y&&g===Jt.P2SH_P2WPKH){const m=nn([y]);c.setInputScript(f,m)}}const u=c.getId();return{psbt:this.psbt,txid:u,fee:this.txFee,toSignInputs:a}}static estimateTxVirtualSize(t,n){const r=t.length,i=n.length;let s=8+oi.varIntSize(r)+oi.varIntSize(i),o=!1;for(const c of t){const a=oi.parseAddressType(c);if(a.key==="OpReturn")continue;const u=py[a.key]??py.UNKNOWN;s+=u,LA.has(a.key)&&(o=!0)}for(const c of n){const a=oi.parseAddressType(c);if(a.key==="OpReturn"){const f=Math.max(0,a.opReturnLength??0);s+=11+f;continue}const u=yy[a.key]??yy.UNKNOWN;s+=u}return o&&(s+=1),s+$A}static parseAddressType(t){if("OpReturn"in t){const r=t.OpReturn!==void 0?Number(t.OpReturn):0;return{key:"OpReturn",opReturnLength:Number.isFinite(r)?r:0}}const n=["P2PKH","P2SH_P2WPKH","P2WPKH","P2WSH","P2SH","P2TR"];for(const r of n)if(r in t)return{key:r};return{key:"UNKNOWN"}}static varIntSize(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}async send(t){if(!this.intentions.length)throw new Error("No itentions added");const n=this.inputUtxos.filter(i=>i.address===this.config.paymentAddress||i.address===this.config.address),r=await e1(n,this.config.network);if(!r)throw new Error("Failed to get utxo proof");return this.client.orchestrator.invoke({intention_set:{tx_fee_in_sats:this.txFee,initiator_address:this.config.paymentAddress,intentions:this.intentions.map(({action:i,actionParams:s,poolAddress:o,inputCoins:c,outputCoins:a,exchangeId:u,nonce:f})=>({exchange_id:u??this.config.exchangeId,input_coins:c.filter(l=>l.from!==o),output_coins:a,pool_address:o,action:i,action_params:s??"",pool_utxo_spent:[],pool_utxo_received:[],nonce:f}))},initiator_utxo_proof:r,psbt_hex:t,client_info:[this.config.clientInfo??""]}).then(i=>{if(i?.Ok)return i.Ok;{const s=i?.Err??{},o=Object.keys(s)[0],c=s[o];throw new Error(c?o==="ErrorOccurredDuringExecution"?`${o}: ${c.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(i)}`:`Invoke Error: ${JSON.stringify(i)}`)}})}}class Is extends Error{response;request;constructor(t,n){const r=`${Is.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(r),Object.setPrototypeOf(this,Is.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,Is)}static extractMessage(t){return t.errors?.[0]?.message??`GraphQL Error (Code: ${String(t.status)})`}}const gy=e=>e.toUpperCase(),Uf=e=>typeof e=="function"?e():e,t1=(e,t)=>e.map((n,r)=>[n,t[r]]),ls=e=>{let t={};return e instanceof Headers?t=DA(e):Array.isArray(e)?e.forEach(([n,r])=>{n&&r!==void 0&&(t[n]=r)}):e&&(t=e),t},DA=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},jA=e=>{try{const t=e();return KA(t)?t.catch(n=>my(n)):t}catch(t){return my(t)}},my=e=>e instanceof Error?e:new Error(String(e)),KA=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function"&&"catch"in e&&typeof e.catch=="function"&&"finally"in e&&typeof e.finally=="function",Nh=e=>{throw new Error(`Unhandled case: ${String(e)}`)},ra=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),GA=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},WA=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0};function ia(e,t){if(!!!e)throw new Error(t)}function XA(e){return typeof e=="object"&&e!==null}function zA(e,t){if(!!!e)throw new Error("Unexpected invariant triggered.")}const YA=/\r\n|[\n\r]/g;function pl(e,t){let n=0,r=1;for(const i of e.body.matchAll(YA)){if(typeof i.index=="number"||zA(!1),i.index>=t)break;n=i.index+i[0].length,r+=1}return{line:r,column:t+1-n}}function ZA(e){return n1(e.source,pl(e.source,e.start))}function n1(e,t){const n=e.locationOffset.column-1,r="".padStart(n)+e.body,i=t.line-1,s=e.locationOffset.line-1,o=t.line+s,c=t.line===1?n:0,a=t.column+c,u=`${e.name}:${o}:${a}
|
|
76
|
+
*********************`),ie=j.hashForSignature(p,fe,W)}return{script:fe,sighashType:W,hash:ie}}function N(p,h,b,I){const C=[];if(h.tapInternalKey){const W=L(p,h,I);W&&C.push(W)}if(h.tapScriptSig){const W=h.tapScriptSig.map(ie=>ie.pubkey);C.push(...W)}return C.map(W=>X(p,h,b,W,I)).flat()}function L(p,h,b){const{script:I}=qe(p,h,b);return(0,l.isP2TR)(I)?I.subarray(2,34):null}function G(p){return p.length===64?p:p.subarray(0,64)}function X(p,h,b,I,C,j,W){const ie=C.__TX,Q=h.sighashType||u.Transaction.SIGHASH_DEFAULT;Y(Q,W);const fe=b.map((je,Xn)=>qe(Xn,je,C)),he=fe.map(je=>je.script),Ne=fe.map(je=>je.value),Pe=[];if(h.tapInternalKey&&!j){const je=L(p,h,C)||Buffer.from([]);if((0,f.toXOnly)(I).equals(je)){const Xn=ie.hashForWitnessV1(p,he,Ne,Q);Pe.push({pubkey:I,hash:Xn})}}const nt=(h.tapLeafScript||[]).filter(je=>(0,l.pubkeyInScript)(I,je.script)).map(je=>{const Xn=(0,c.tapleafHash)({output:je.script,version:je.leafVersion});return Object.assign({hash:Xn},je)}).filter(je=>!j||j.equals(je.hash)).map(je=>{const Xn=ie.hashForWitnessV1(p,he,Ne,Q,je.hash);return{pubkey:I,hash:Xn,leafHash:je.hash}});return Pe.concat(nt)}function Y(p,h){if(h&&h.indexOf(p)<0){const b=we(p);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${b}`)}}function ce(p,h,b){let I;switch(h){case"multisig":const C=Z(p,b);I=o.p2ms({output:p,signatures:C});break;case"pubkey":I=o.p2pk({output:p,signature:b[0].signature});break;case"pubkeyhash":I=o.p2pkh({output:p,pubkey:b[0].pubkey,signature:b[0].signature});break;case"witnesspubkeyhash":I=o.p2wpkh({output:p,pubkey:b[0].pubkey,signature:b[0].signature});break}return I}function ue(p,h,b){const I=b.__TX,C={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(C.isP2SH=!!h.redeemScript,C.isP2WSH=!!h.witnessScript,h.witnessScript)C.script=h.witnessScript;else if(h.redeemScript)C.script=h.redeemScript;else if(h.nonWitnessUtxo){const j=le(b,h,p),W=I.ins[p].index;C.script=j.outs[W].script}else h.witnessUtxo&&(C.script=h.witnessUtxo.script);return(h.witnessScript||(0,l.isP2WPKH)(C.script))&&(C.isSegwit=!0),C}function te(p,h,b){const I=(0,n.checkForInput)(h,p);if(!I.bip32Derivation||I.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const C=I.bip32Derivation.map(W=>{if(W.masterFingerprint.equals(b.fingerprint))return W}).filter(W=>!!W);if(C.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return C.map(W=>{const ie=b.derivePath(W.path);if(!W.pubkey.equals(ie.publicKey))throw new Error("pubkey did not match bip32Derivation");return ie})}function Z(p,h){return o.p2ms({output:p}).pubkeys.map(I=>(h.filter(C=>C.pubkey.equals(I))[0]||{}).signature).filter(I=>!!I)}function ae(p){let h=0;function b(W){return h+=W,p.slice(h-W,h)}function I(){const W=t.decode(p,h);return h+=t.decode.bytes,W}function C(){return b(I())}function j(){const W=I(),ie=[];for(let Q=0;Q<W;Q++)ie.push(C());return ie}return j()}function we(p){let h=p&u.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(p&31){case u.Transaction.SIGHASH_ALL:h+="SIGHASH_ALL";break;case u.Transaction.SIGHASH_SINGLE:h+="SIGHASH_SINGLE";break;case u.Transaction.SIGHASH_NONE:h+="SIGHASH_NONE";break}return h}function ye(p,h,b){p.__NON_WITNESS_UTXO_BUF_CACHE[b]=h.nonWitnessUtxo;const I=u.Transaction.fromBuffer(h.nonWitnessUtxo);p.__NON_WITNESS_UTXO_TX_CACHE[b]=I;const C=p,j=b;delete h.nonWitnessUtxo,Object.defineProperty(h,"nonWitnessUtxo",{enumerable:!0,get(){const W=C.__NON_WITNESS_UTXO_BUF_CACHE[j],ie=C.__NON_WITNESS_UTXO_TX_CACHE[j];if(W!==void 0)return W;{const Q=ie.toBuffer();return C.__NON_WITNESS_UTXO_BUF_CACHE[j]=Q,Q}},set(W){C.__NON_WITNESS_UTXO_BUF_CACHE[j]=W}})}function J(p,h,b,I){let C=0;p.forEach((Q,fe)=>{if(I&&Q.finalScriptSig&&(h.ins[fe].script=Q.finalScriptSig),I&&Q.finalScriptWitness&&(h.ins[fe].witness=ae(Q.finalScriptWitness)),Q.witnessUtxo)C+=Q.witnessUtxo.value;else if(Q.nonWitnessUtxo){const he=le(b,Q,fe),Ne=h.ins[fe].index,Pe=he.outs[Ne];C+=Pe.value}});const j=h.outs.reduce((Q,fe)=>Q+fe.value,0),W=C-j;if(W<0)throw new Error("Outputs are spending more than Inputs");const ie=h.virtualSize();b.__FEE=W,b.__EXTRACTED_TX=h,b.__FEE_RATE=Math.floor(W/ie)}function le(p,h,b){const I=p.__NON_WITNESS_UTXO_TX_CACHE;return I[b]||ye(p,h,b),I[b]}function Ae(p,h,b){const{script:I}=qe(p,h,b);return I}function qe(p,h,b){if(h.witnessUtxo!==void 0)return{script:h.witnessUtxo.script,value:h.witnessUtxo.value};if(h.nonWitnessUtxo!==void 0){const C=le(b,h,p).outs[b.__TX.ins[p].index];return{script:C.script,value:C.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function tt(p,h,b,I){const C=Ae(b,h,I),{meaningfulScript:j}=oe(C,b,"input",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(p,j)}function ut(p,h,b,I){const C=I.__TX.outs[b].script,{meaningfulScript:j}=oe(C,b,"output",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(p,j)}function It(p){if(!p)return;const h=a.decompile(p);if(!h)return;const b=h[h.length-1];if(!(!Buffer.isBuffer(b)||it(b)||Ce(b)||!a.decompile(b)))return b}function Oe(p){if(!p)return;const h=ae(p),b=h[h.length-1];if(!(it(b)||!a.decompile(b)))return b}function mn(p){if(p.length===65){const h=p[64]&1,b=p.slice(0,33);return b[0]=2|h,b}return p.slice()}function it(p){return p.length===33&&a.isCanonicalPubKey(p)}function Ce(p){return a.isCanonicalScriptSignature(p)}function oe(p,h,b,I,C){const j=(0,l.isP2SHScript)(p),W=j&&I&&(0,l.isP2WSHScript)(I),ie=(0,l.isP2WSHScript)(p);if(j&&I===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((ie||W)&&C===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let Q;return W?(Q=C,$(h,p,I,b),P(h,I,C,b),ne(Q)):ie?(Q=C,P(h,p,C,b),ne(Q)):j?(Q=I,$(h,p,I,b)):Q=p,{meaningfulScript:Q,type:W?"p2sh-p2wsh":j?"p2sh":ie?"p2wsh":"raw"}}function ne(p){if((0,l.isP2WPKH)(p)||(0,l.isP2SHScript)(p))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function re(p){return(0,l.isP2WPKH)(p)?"witnesspubkeyhash":(0,l.isP2PKH)(p)?"pubkeyhash":(0,l.isP2MS)(p)?"multisig":(0,l.isP2PK)(p)?"pubkey":"nonstandard"}function k(p){return[...Array(p).keys()]}return mo}var oy;function BA(){return oy||(oy=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=xh();e.address=t;const n=Pr();e.crypto=n;const r=Wn();e.networks=r;const i=Ec();e.payments=i;const s=rn();e.script=s;var o=rA();Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return o.Block}});var c=OA();Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return c.Psbt}});var a=bh();Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return a.OPS}});var u=_c();Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}});var f=Sh();Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return f.initEccLib}})})(yf)),yf}var Oi={},cy;function NA(){if(cy)return Oi;cy=1,Object.defineProperty(Oi,"__esModule",{value:!0}),Oi.base26Decode=Oi.base26Encode=void 0;function e(n){let r=0n;for(let i=0;i<n.length;i++){const s=BigInt(n.charCodeAt(i)-65),o=BigInt(n.length)-1n-BigInt(i);if(o==0n)r+=s;else{const c=26n**o;r+=c*(s+1n)}}return r}Oi.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let r=[];for(;n>0;){const i=(n-1n)%26n;r.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(i))),n=(n-1n)/26n}return r.reverse().join("")}return Oi.base26Decode=t,Oi}var Bi={},ay;function Jw(){if(ay)return Bi;ay=1,Object.defineProperty(Bi,"__esModule",{value:!0}),Bi.none=Bi.some=void 0;class e{constructor(){}isSome(){return!1}map(s){return new e}value(){return null}}class t{constructor(s){this._value=s}isSome(){return!0}map(s){return new t(s(this.value()))}value(){return this._value}}function n(i){return new t(i)}Bi.some=n;function r(){return new e}return Bi.none=r,Bi}var Ni={},uy;function kA(){if(uy)return Ni;uy=1,Object.defineProperty(Ni,"__esModule",{value:!0}),Ni.decodeLEB128=Ni.encodeLEB128=void 0;function e(n){const r=[];let i=!0;for(;i;){let s=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?i=!1:s|=128,r.push(s)}return r}Ni.encodeLEB128=e;function t(n){let r=BigInt(0);for(let i=0;i<n.length;i++){const s=BigInt(n[i]);if(i>18)throw new Error("Overlong");let o=s&BigInt(127);if(i==18&&(o&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(r|=o<<BigInt(7)*BigInt(i),(s&BigInt(128))==BigInt(0))return{n:r,len:i+1}}throw new Error("Unterminated")}return Ni.decodeLEB128=t,Ni}var Rf={},fy;function PA(){return fy||(fy=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=s=>s.length%2===1?"0"+s:s;e.zero2=t;const n=s=>{let o="";for(let c=0;c<s.length;c++)o+=(0,e.zero2)(s[c].toString(16));return o};e.toHex=n;function r(s,o){const c=[];let a=0;for(;a<s.length;){const u=s.slice(a,a+o);c.push(u),a+=o}return c}e.chunks=r;function i(s){const o=[],c=s.length;if(c<76){const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=255){o.push(Buffer.from("4c","hex"));const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=65535){o.push(Buffer.from("4d","hex"));const a=Buffer.alloc(2);a.writeUInt16LE(c),o.push(a)}else{o.push(Buffer.from("4e","hex"));const a=Buffer.alloc(4);a.writeUInt32LE(c),o.push(a)}return o.push(s),Buffer.concat(o)}e.toPushData=i})(Rf)),Rf}var hr={},ly;function Qw(){if(ly)return hr;ly=1,Object.defineProperty(hr,"__esModule",{value:!0}),hr.removeSpacers=hr.getSpacersVal=hr.applySpacers=void 0;function e(r,i){let s="";for(let o=0;o<r.length;o++)s+=r.charAt(o),i>0&&((i&1)===1&&(s+="•"),i>>=1);return s}hr.applySpacers=e;function t(r){let i=0,s=0;for(let o=0;o<r.length;o++)r.charAt(o)==="•"&&(i+=1<<o-1-s,s++);return i}hr.getSpacersVal=t;function n(r){return r.replace(/[•]+/g,"")}return hr.removeSpacers=n,hr}var hy;function RA(){if(hy)return Xe;hy=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.EtchInscription=Xe.Message=Xe.Runestone=Xe.Etching=Xe.Rune=Xe.Terms=Xe.Range=Xe.Flaw=Xe.Tag=Xe.Flag=Xe.Edict=Xe.RuneId=void 0;const e=BA(),t=NA(),n=Jw(),r=kA(),i=PA(),s=Qw();class o{constructor(w,T){this.block=w,this.idx=T}next(w,T){if(w>BigInt(Number.MAX_SAFE_INTEGER)||T>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let O=BigInt(this.block)+w;if(O>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let A=w===0n?BigInt(this.idx)+T:T;return A>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new o(Number(O),Number(A)))}}Xe.RuneId=o;class c{constructor(w,T,O){this.id=w,this.amount=T,this.output=O}static from_integers(w,T,O,A){return A>4294967295n||A<0n||Number(A)>w.outs.length?(0,n.none)():(0,n.some)(new c(T,O,Number(A)))}}Xe.Edict=c;var a;(function(S){S[S.Etching=0]="Etching",S[S.Terms=1]="Terms",S[S.Turbo=2]="Turbo",S[S.Cenotaph=127]="Cenotaph"})(a||(Xe.Flag=a={}));var u;(function(S){S[S.Body=0]="Body",S[S.Flags=2]="Flags",S[S.Rune=4]="Rune",S[S.Premine=6]="Premine",S[S.Cap=8]="Cap",S[S.Amount=10]="Amount",S[S.HeightStart=12]="HeightStart",S[S.HeightEnd=14]="HeightEnd",S[S.OffsetStart=16]="OffsetStart",S[S.OffsetEnd=18]="OffsetEnd",S[S.Mint=20]="Mint",S[S.Pointer=22]="Pointer",S[S.Cenotaph=126]="Cenotaph",S[S.Divisibility=1]="Divisibility",S[S.Spacers=3]="Spacers",S[S.Symbol=5]="Symbol",S[S.Nop=127]="Nop"})(u||(Xe.Tag=u={}));var f;(function(S){S[S.EdictOutput=0]="EdictOutput",S[S.EdictRuneId=1]="EdictRuneId",S[S.InvalidScript=2]="InvalidScript",S[S.Opcode=3]="Opcode",S[S.SupplyOverflow=4]="SupplyOverflow",S[S.TrailingIntegers=5]="TrailingIntegers",S[S.TruncatedField=6]="TruncatedField",S[S.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",S[S.UnrecognizedFlag=8]="UnrecognizedFlag",S[S.Varint=9]="Varint"})(f||(Xe.Flaw=f={}));class l{constructor(w,T){this.start=w,this.end=T}}Xe.Range=l;class d{constructor(w,T,O,A){this.amount=w,this.cap=T,this.height=O,this.offset=A}}Xe.Terms=d;class y{constructor(w){this.value=w}get name(){return y.toName(this.value)}static toName(w){return(0,t.base26Decode)(w)}static fromName(w){return new y((0,t.base26Encode)((0,s.removeSpacers)(w)))}toString(){return this.name}}Xe.Rune=y;class g{constructor(w,T,O,A,R,M,v){this.divisibility=w,this.premine=T,this.rune=O,this.spacers=A,this.symbol=R,this.terms=M,this.turbo=v}}Xe.Etching=g,g.MAX_DIVISIBILITY=38,g.MAX_SPACERS=134217727;class m{constructor(w=[],T,O,A){this.edicts=w,this.etching=T,this.mint=O,this.pointer=A}static create(w,T="etch"){if(T==="etch"){w=w;const O=y.fromName(w.name),A=new d(w.amount,w.cap,new l(w.startHeight?(0,n.some)(w.startHeight):(0,n.none)(),w.endHeight?(0,n.some)(w.endHeight):(0,n.none)()),new l(w.startOffset?(0,n.some)(w.startOffset):(0,n.none)(),w.endOffset?(0,n.some)(w.endOffset):(0,n.none)())),R=w.divisibility?(0,n.some)(w.divisibility):(0,n.none)(),M=w.premine?(0,n.some)(w.premine):(0,n.none)(),v=w.name.indexOf("•")>-1?(0,n.some)((0,s.getSpacersVal)(w.name)):(0,n.none)(),U=w.symbol?(0,n.some)(w.symbol):(0,n.none)(),V=typeof w.pointer=="number"?(0,n.some)(w.pointer):(0,n.none)(),K=new g(R,M,(0,n.some)(O),v,U,(0,n.some)(A),!0);return new m([],(0,n.some)(K),(0,n.none)(),V)}else if(T==="mint"){w=w;const O=typeof w.pointer=="number"?(0,n.some)(w.pointer):(0,n.none)();return new m([],(0,n.none)(),(0,n.some)(new o(w.block,w.txIdx)),O)}else throw new Error(`not ${T} support now`)}static decipher(w){const T=e.Transaction.fromHex(w),O=m.payload(T);if(O.isSome()){const A=m.integers(O.value()),R=E.from_integers(T,A.value()),M=R.getEtching(),v=R.getMint(),U=R.getPointer();return(0,n.some)(new m(R.edicts,M,v,U))}return(0,n.none)()}encipher(){const T=this.toMessage().toBuffer(),O=Buffer.from("6a5d","hex");let A;if(T.length<76)A=Buffer.alloc(1),A.writeUInt8(T.length);else if(T.length<256)A=Buffer.alloc(2),A.writeUInt8(76),A.writeUInt8(T.length);else if(T.length<65536)A=Buffer.alloc(3),A.writeUInt8(77),A.writeUInt16LE(T.length);else if(T.length<4294967296)A=Buffer.alloc(5),A.writeUInt8(78),A.writeUInt32LE(T.length);else throw new Error("runestone too big!");return Buffer.concat([O,A,T])}static payload(w){for(const T of w.outs){const O=e.script.decompile(T.script);if(O[0]===e.script.OPS.OP_RETURN&&O[1]===m.MAGIC_NUMBER){for(let A=2;A<O.length;A++){const R=O[A];return R instanceof Uint8Array?(0,n.some)(Array.from(R)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(w){let T=[],O=0;for(;O<w.length;){let{n:A,len:R}=(0,r.decodeLEB128)(w.slice(O));T.push(A),O+=R}return(0,n.some)(T)}toMessage(){let w=new Map;const T=this.etching.value();if(T){let R=1;if(T.terms.isSome()){let $=1<<a.Terms;R|=$}if(T.turbo){let $=1<<a.Turbo;R|=$}w.set(u.Flags,[BigInt(R)]);const M=T.rune.value();M!==null&&w.set(u.Rune,[BigInt(M.value)]);const v=T.divisibility.value();v!==null&&w.set(u.Divisibility,[BigInt(v)]);const U=T.spacers.value();U!==null&&w.set(u.Spacers,[BigInt(U)]);const V=T.symbol.value();V!==null&&w.set(u.Symbol,[BigInt(V.charCodeAt(0))]);const K=T.premine.value();K!==null&&w.set(u.Premine,[BigInt(K)]);const H=T.terms.value();if(H!==null){w.set(u.Amount,[BigInt(H.amount)]),w.set(u.Cap,[BigInt(H.cap)]);const $=H.height.start.value();$&&w.set(u.HeightStart,[BigInt($)]);const P=H.height.end.value();P&&w.set(u.HeightEnd,[BigInt(P)]);const D=H.offset.start.value();D&&w.set(u.OffsetStart,[BigInt(D)]);const F=H.offset.end.value();F&&w.set(u.OffsetEnd,[BigInt(F)])}}const O=this.mint.value();O!==null&&w.set(u.Mint,[BigInt(O.block),BigInt(O.idx)]);const A=this.pointer.value();return A!==null&&w.set(u.Pointer,[BigInt(A)]),new E(w,this.edicts,0)}}Xe.Runestone=m,m.MAGIC_NUMBER=93;class E{constructor(w=new Map,T=[],O=0){this.fields=w,this.edicts=T,this.flaws=O}static from_integers(w,T){let O=new Map,A=[],R=0,M=!1;for(let v=0;v<T.length;){let U=T[v];if(Number(U)===u.Body){M=!0,v+=1;continue}if(M){let V=new o(0,0);for(const K of(0,i.chunks)(T.slice(v),4)){if(K.length!=4){R|=f.TrailingIntegers;break}let H=V.next(K[0],K[1]);if(!H.isSome()){R|=f.EdictRuneId;break}const $=c.from_integers(w,H.value(),K[2],K[3]);if(!$.isSome()){R|=f.EdictOutput;break}V=H.value(),A.push($.value())}v+=4}else{let V=T[v+1];const K=O.get(Number(U))||[];K.push(V),O.set(Number(U),K),v+=2}}return new E(O,A,R)}addFieldVal(w,T){const O=this.fields.get(Number(w))||[];O.push(T),this.fields.set(Number(w),O)}addEdict(w){this.edicts.push(w)}toBuffer(){const w=[];for(const[T,O]of this.fields)for(const A of O){const R=Buffer.alloc(1);R.writeUInt8(T),w.push(R),w.push(Buffer.from((0,r.encodeLEB128)(A)))}if(this.edicts.length>0){w.push(Buffer.from("00","hex")),this.edicts.sort((A,R)=>A.id.block==R.id.block?A.id.idx-R.id.idx:A.id.block-R.id.block);let T=0n,O=0n;for(let A=0;A<this.edicts.length;A++){const R=this.edicts[A];if(A==0)T=BigInt(R.id.block),O=BigInt(R.id.idx),w.push(Buffer.from((0,r.encodeLEB128)(T))),w.push(Buffer.from((0,r.encodeLEB128)(O)));else{const M=BigInt(R.id.block),v=BigInt(R.id.idx);if(M==T){const U=v-O;O=v,w.push(Buffer.from((0,r.encodeLEB128)(0n))),w.push(Buffer.from((0,r.encodeLEB128)(U)))}else{const U=M-T;T=M,O=v,w.push(Buffer.from((0,r.encodeLEB128)(U))),w.push(Buffer.from((0,r.encodeLEB128)(v)))}}w.push(Buffer.from((0,r.encodeLEB128)(BigInt(R.amount)))),w.push(Buffer.from((0,r.encodeLEB128)(BigInt(R.output))))}}return Buffer.concat(w)}getFlags(){return Number(this.fields.get(u.Flags))}hasFlags(w){const T=this.getFlags(),O=1<<w;return(T&O)!=0}getMint(){if(!this.fields.has(u.Mint))return(0,n.none)();const[w,T]=this.fields.get(u.Mint);return(0,n.some)(new o(Number(w),Number(T)))}getEtching(){if(!this.hasFlags(a.Etching))return(0,n.none)();const w=this.getDivisibility(),T=this.getPremine(),O=this.getRune(),A=this.getSpacers(),R=this.getSymbol(),M=this.getTerms(),v=this.hasFlags(a.Turbo);return(0,n.some)(new g(w,T,O,A,R,M,v))}getDivisibility(){if(!this.fields.has(u.Divisibility))return(0,n.none)();const[w]=this.fields.get(u.Divisibility);if(w>g.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(w))}getPremine(){if(!this.fields.has(u.Premine))return(0,n.none)();const[w]=this.fields.get(u.Premine);return(0,n.some)(Number(w))}getRune(){if(!this.fields.has(u.Rune))return(0,n.none)();const[w]=this.fields.get(u.Rune);return(0,n.some)(new y(w))}getSpacers(){if(!this.fields.has(u.Spacers))return(0,n.none)();const[w]=this.fields.get(u.Spacers);if(w>g.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(w))}getHeightStart(){if(!this.fields.has(u.HeightStart))return(0,n.none)();const[w]=this.fields.get(u.HeightStart);return(0,n.some)(Number(w))}getHeightEnd(){if(!this.fields.has(u.HeightEnd))return(0,n.none)();const[w]=this.fields.get(u.HeightEnd);return(0,n.some)(Number(w))}getOffsetStart(){if(!this.fields.has(u.OffsetStart))return(0,n.none)();const[w]=this.fields.get(u.OffsetStart);return(0,n.some)(Number(w))}getOffsetEnd(){if(!this.fields.has(u.OffsetEnd))return(0,n.none)();const[w]=this.fields.get(u.OffsetEnd);return(0,n.some)(Number(w))}getCap(){if(!this.fields.has(u.Cap))return(0,n.none)();const[w]=this.fields.get(u.Cap);return(0,n.some)(Number(w))}getAmount(){if(!this.fields.has(u.Amount))return(0,n.none)();const[w]=this.fields.get(u.Amount);return(0,n.some)(Number(w))}getSymbol(){if(!this.fields.has(u.Symbol))return(0,n.none)();const[w]=this.fields.get(u.Symbol);return(0,n.some)(String.fromCharCode(Number(w)))}getTerms(){if(!this.hasFlags(a.Terms))return(0,n.none)();const w=this.getCap();if(!w.isSome())throw new Error("no cap field");const T=this.getAmount();if(!T.isSome())throw new Error("no amount field");const O=this.getHeightStart(),A=this.getHeightEnd(),R=this.getOffsetStart(),M=this.getOffsetEnd(),v=new l(O,A),U=new l(R,M);return(0,n.some)(new d(T.value(),w.value(),v,U))}getPointer(){if(!this.fields.has(u.Pointer))return(0,n.none)();const[w]=this.fields.get(u.Pointer);return(0,n.some)(Number(w))}}Xe.Message=E;class _{constructor(w=new Map,T=Buffer.alloc(0)){this.fields=w,this.data=T}setContent(w,T){this.fields.set(1,Buffer.from(w,"utf8")),this.data=T}setRune(w){let O=(0,t.base26Encode)((0,s.removeSpacers)(w)).toString(16);O.length%2===1&&(O="0"+O),this.setField(_.Tag.RUNE,Buffer.from(O,"hex").reverse())}setField(w,T){this.fields.set(w,T)}static decipher(w,T){const R=e.Transaction.fromHex(w).ins[T].witness[1],M=e.script.decompile(R),v=new Map,U=[];let V=!1;for(let K=5;K<M.length-1;){const H=M[K];if(H===0){V=!0,K++;continue}else if(V)U.push(H),K++;else{const $=H-80,P=M[K+1];if(typeof P=="number"){const D=Buffer.alloc(1);D.writeUInt8(P),v.set($,D)}else v.set($,P);K+=2}}return new _(v,Buffer.concat(U))}encipher(){const w=[];if(this.data&&this.data.length>0){w.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((O,A)=>O[0]-A[0]).forEach(([O,A])=>{const R=Buffer.alloc(1);R.writeUInt8(O),w.push(Buffer.from("01","hex")),w.push(R),A.length!=1||A[0]!=0?w.push((0,i.toPushData)(A)):w.push(A)}),w.push(Buffer.from("00","hex"));const T=(0,i.chunks)(Array.from(this.data),520);for(const O of T)w.push((0,i.toPushData)(Buffer.from(O)))}else{w.push(Buffer.from("0063","hex"));const T=this.fields.get(_.Tag.RUNE);if(!T)throw new Error("No rune found!");w.push((0,i.toPushData)(T))}return w.push(Buffer.from("68","hex")),Buffer.concat(w)}}return Xe.EtchInscription=_,_.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},Xe}var dy;function UA(){return dy||(dy=1,(function(e){var t=Ei&&Ei.__createBinding||(Object.create?(function(s,o,c,a){a===void 0&&(a=c);var u=Object.getOwnPropertyDescriptor(o,c);(!u||("get"in u?!o.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return o[c]}}),Object.defineProperty(s,a,u)}):(function(s,o,c,a){a===void 0&&(a=c),s[a]=o[c]})),n=Ei&&Ei.__exportStar||function(s,o){for(var c in s)c!=="default"&&!Object.prototype.hasOwnProperty.call(o,c)&&t(o,s,c)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(RA(),e);var r=Jw();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return r.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return r.some}});var i=Qw();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return i.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return i.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return i.removeSpacers}})})(Ei)),Ei}var fs=UA();function Eo(e){if(e.length%2!==0)throw new Error("Hex string must have even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}function Ih(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Oh(e){return e===Ns.Mainnet?Pn:Fy}function Bh(e,t=Ns.Testnet){const n=Oh(t);return Ag(e,n)}function si(e){const t=Pn,n=Fy,r=D1;let i,s,o=Jt.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return s=kl(e),s.version===0?s.data.length===20?o=Jt.P2WPKH:o=Jt.P2WSH:o=Jt.P2TR,o}catch{return Jt.UNKNOWN}else try{return i=xg(e),i.version===t.pubKeyHash||i.version===n.pubKeyHash||i.version===r.pubKeyHash?o=Jt.P2PKH:(i.version===t.scriptHash||(i.version,n.scriptHash),o=Jt.P2SH_P2WPKH),o}catch{return Jt.UNKNOWN}}function CA(e,t,n){const r=Bh(e,n),i=t.coins?.[0];return{txid:t.txid,vout:t.vout,satoshis:t.sats.toString(),height:void 0,runes:i?[{id:i.id,amount:i.value.toString()}]:[],address:e,scriptPk:Ih(r)}}async function e1(e,t){try{const n=t===Ns.Mainnet?"https://mpc.omnity.network/utxo-status":"https://mpc.omnity.network/testnet4/utxo-status",r=await ht.post(n,e).then(c=>c.data);if(!r)return null;const i=JSON.stringify(r),o=new TextEncoder().encode(i);return Array.from(o)}catch{return null}}const HA=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:Ih,formatPoolUtxo:CA,getAddressType:si,getScriptByAddress:Bh,getUtxoProof:e1,hexToBytes:Eo,toBitcoinNetwork:Oh},Symbol.toStringTag,{value:"Module"})),FA="kqs64-paaaa-aaaar-qamza-cai",MA="hvyp5-5yaaa-aaaao-qjxha-cai",Qr=BigInt(546),on="0:0",qA="https://gql-runescan-mainnet.omnity.network/v1/graphql",VA="https://gql-runescan-testnet.omnity.network/v1/graphql",py={P2PKH:148,P2SH_P2WPKH:91,P2WPKH:68,P2WSH:140,P2SH:108,P2TR:58,UNKNOWN:110},yy={P2PKH:34,P2SH_P2WPKH:32,P2WPKH:31,P2WSH:43,P2SH:32,P2TR:43,UNKNOWN:34},LA=new Set(["P2WPKH","P2WSH","P2SH_P2WPKH","P2TR"]),$A=2;class oi{psbt;client;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);intentions=[];txFee=BigInt(0);additionalDustNeeded=BigInt(0);inputUtxos=[];constructor(t,n){this.config=t,this.psbt=new ma({network:Oh(t.network)}),this.client=n}addInput(t){if(this.inputUtxos.findIndex(i=>i.txid===t.txid&&i.vout===t.vout)>=0)return;const{address:n}=t;if(si(n)===Jt.P2TR){let i=t.pubkey;i||t.address===this.config.address&&this.config.publicKey&&(i=this.config.publicKey);const s=i?i.length===66?i.slice(2):i:void 0;s?this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:Eo(t.scriptPk)},tapInternalKey:Eo(s)}):this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:Eo(t.scriptPk)}})}else this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:Eo(t.scriptPk)}});this.inputAddressTypes.push(si(n)),this.inputUtxos.push(t),(n===this.config.address||n===this.config.paymentAddress)&&t.runes.length!==0&&(this.userInputUtxoDusts+=BigInt(t.satoshis))}addOutput(t,n){this.psbt.addOutput({address:t,value:n}),this.outputAddressTypes.push(si(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:BigInt(0)}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,r){const i=[];if(r==BigInt(0))return i;for(const s of t)if(s.runes.length){const o=s.runes.find(c=>c.id==n);if(o&&BigInt(o.amount)==r){i.push(s);break}}if(i.length==0){let s=BigInt(0);for(const o of t)if(o.runes.forEach(c=>{c.id==n&&(s=s+BigInt(c.amount))}),i.push(o),s>=r)break;if(s<r)throw new Error("INSUFFICIENT_RUNE_UTXOs")}return i}selectBtcUtxos(t,n,r=!1){const i=[];if(n<=BigInt(0))return i;let s=BigInt(0);for(const o of t)if(!(o.runes.length&&!r)&&(s+=BigInt(o.satoshis),i.push(o),s>=n))break;if(s<n)throw new Error(`Insufficient BTC UTXOs: need ${n}, have ${s}`);return i}async addBtcAndFees(t,n){const r=this.config.paymentAddress,i=this.additionalDustNeeded,s=si(r),o=this.userInputUtxoDusts,c=this.config.feeRate;this.outputAddressTypes.push(s);let a=!0,u=BigInt(0),f=BigInt(0),l=[],d=BigInt(0),y=BigInt(0);const g=[...this.inputAddressTypes];do{if(u=f,c!==void 0){const _=oi.estimateTxVirtualSize(this.inputAddressTypes,this.outputAddressTypes);f=BigInt(Math.round(c*_))}else f=(await this.client.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes,pool_address:this.intentions.map(S=>S.poolAddress),output_types:this.outputAddressTypes}).catch(S=>{throw console.error("estimate_min_tx_fee failed:",S),S})).Ok;if(d=n+f+i-o,f>u&&d>0){const _=this.selectBtcUtxos(t,d);if(_.length===0)throw new Error("INSUFFICIENT_BTC_UTXOs");this.inputAddressTypes=g.concat(_.map(()=>s));const S=_.reduce((w,T)=>w+BigInt(T.satoshis),BigInt(0));S-d>0&&S-d>Qr||(this.outputAddressTypes.pop(),a=!1),l=_}}while(f>u&&d>0);this.inputAddressTypes=[...g],a&&this.outputAddressTypes.pop();let m=BigInt(0);l.forEach(_=>{this.addInput(_),m+=BigInt(_.satoshis)});const E=m-d;if(E<0)throw new Error("Insufficient UTXO(s)");E>Qr?this.addOutput(r,E):E>BigInt(0)&&(y=E),this.txFee=y+f}async getInvolvedAddressUtxos(){const t={},n={},r=new Map,i=this.intentions.map(o=>o.poolAddress);r.set(this.config.paymentAddress,{needBtc:!0,runeIds:new Set});const s=o=>{const c=o.trim();return r.has(c)||r.set(c,{needBtc:!1,runeIds:new Set}),r.get(c)};for(const o of this.intentions){for(const u of o.inputCoins){const f=s(u.from);u.coin.id===on?f.needBtc=!0:f.runeIds.add(u.coin.id)}for(const u of o.outputCoins){const f=s(u.to);u.coin.id===on?f.needBtc=!0:f.runeIds.add(u.coin.id)}const c=s(o.poolAddress),a=[...o.inputCoins.map(u=>u.coin.id),...o.outputCoins.map(u=>u.coin.id)];for(const u of a)u===on?c.needBtc=!0:c.runeIds.add(u)}return await Promise.all(Array.from(r.entries()).map(async([o,c])=>{if(c.needBtc)try{t[o]=await this.client.getBtcUtxos(o,!i.includes(o))}catch{t[o]=[]}c.runeIds.size>0&&(n[o]={},await Promise.all(Array.from(c.runeIds).map(async a=>{try{n[o][a]=await this.client.getRuneUtxos(o,a)}catch{n[o][a]=[]}})))})),{btc:t,rune:n}}addInputsAndCalculateOutputs(t){if(!this.intentions.length)throw new Error("No intentions added");const n=this.intentions.map(a=>a.poolAddress),r={},i={};let s=BigInt(0);const o=new Map,c=new Set;this.intentions.forEach(({poolAddress:a,inputCoins:u,outputCoins:f,poolUtxos:l})=>{const d=[...u.filter(({from:g})=>!n.includes(g))],y=[...f];if(d.forEach(({coin:g,from:m})=>{!f.find(E=>E.coin.id===g.id)&&!(n.includes(m)&&m!==a)&&y.push({coin:g,to:a})}),y.forEach(({coin:g})=>{u.find(m=>m.coin.id===g.id)||d.push({coin:g,from:a})}),d.length===0&&y.length===0&&l?.length){const g=o.get(a);o.set(a,g?g.concat(l):[...l]),c.add(a);return}d.forEach(({coin:g,from:m})=>{r[m]??={},r[m][g.id]=(r[m][g.id]??BigInt(0))+BigInt(g.value)}),y.forEach(({coin:g,to:m})=>{i[m]??={},i[m][g.id]=(i[m][g.id]??BigInt(0))+BigInt(g.value)})});for(const[a,u]of o.entries()){if(!u.length)continue;i[a]??={};const f=i[a];u.forEach(l=>{this.addInput(l),f[on]=(f[on]??BigInt(0))+BigInt(l.satoshis),l.runes.forEach(d=>{f[d.id]=(f[d.id]??BigInt(0))+BigInt(d.amount)})})}for(const[a,u]of Object.entries(r))for(const[f,l]of Object.entries(u))if(f===on){if(a===this.config.paymentAddress){s+=l;continue}const d=t.btc[a]||[],y=this.selectBtcUtxos(d,l,n.includes(a)),m=y.reduce((E,_)=>E+BigInt(_.satoshis),BigInt(0))-l;m>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+m),y.forEach(E=>{this.addInput(E),n.includes(a)&&E.runes.forEach(_=>{(r[a]?.[_.id]??BigInt(0))>BigInt(0)||(i[a]??={},i[a][_.id]=(i[a][_.id]??BigInt(0))+BigInt(_.amount))})})}else{const d=t.rune[a]?.[f]||[],y=this.selectRuneUtxos(d,f,l),g=y.reduce((_,S)=>{const w=S.runes.find(T=>T.id===f);return _+BigInt(w?.amount??0)},BigInt(0)),m=y.reduce((_,S)=>_+BigInt(S.satoshis),BigInt(0)),E=g-l;if(n.includes(a)){i[a]??={};const _=i[a],S=(r[a]?.[on]??BigInt(0))>BigInt(0);m>BigInt(0)&&!S&&(_[on]=(_[on]??BigInt(0))+m),E>BigInt(0)&&(_[f]=(_[f]??BigInt(0))+E)}else E>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+E);y.forEach(_=>this.addInput(_))}for(const[a,u]of Object.entries(i))if(!(r[a]||!n.includes(a)||c.has(a)))for(const[f]of Object.entries(u))if(f===on){const l=t.btc[a]||[],d=l.reduce((y,g)=>y+BigInt(g.satoshis),BigInt(0));i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+d,l.forEach(y=>{this.addInput(y),y.runes.forEach(g=>{i[a]??={},i[a][g.id]=(i[a][g.id]??BigInt(0))+BigInt(g.amount)})})}else{const l=t.rune[a]?.[f]||[],d=l.reduce((y,g)=>{const m=g.runes.find(E=>E.id===f);return y+BigInt(m?.amount??0)},BigInt(0));i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+d,l.forEach(y=>this.addInput(y))}return{addressOutputCoinAmounts:i,paymentBtcRequired:s}}addOutputs(t){const n=this.config.mergeSelfRuneBtcOutputs===!0,r=new Set;for(const[,s]of Object.entries(t))for(const o of Object.keys(s))o!==on&&r.add(o);const i=Array.from(r);if(i.length>0){const s=[],o=[];let c=1;i.forEach(u=>{const f=new fs.RuneId(Number(u.split(":")[0]),Number(u.split(":")[1]));for(const[l,d]of Object.entries(t)){const y=d[u]??BigInt(0);y>BigInt(0)&&(s.push(new fs.Edict(f,y,c)),o.push(l),c++)}});const a=new fs.Runestone(s,fs.none(),fs.none(),fs.none());this.addScriptOutput(new Uint8Array(a.encipher())),o.forEach(u=>{const f=t[u]?.[on]??BigInt(0),l=u===this.config.address,d=f>BigInt(0)&&(!l||n),y=d&&f>Qr?f:Qr;this.addOutput(u,y),d?(f<Qr&&(this.additionalDustNeeded+=Qr-f),delete t[u][on]):this.additionalDustNeeded+=Qr})}for(const[s,o]of Object.entries(t)){const c=o[on]??BigInt(0);c>BigInt(0)&&this.addOutput(s,c)}}addIntention(t){this.intentions.push(t)}async build(){const t=await this.getInvolvedAddressUtxos();for(const f of this.intentions){const l=f.poolUtxos;if(!l)continue;t.btc[f.poolAddress]=l,t.rune[f.poolAddress]={};const d=t.rune[f.poolAddress];for(const y of l)for(const g of y.runes)(d[g.id]??=[]).push(y)}const{addressOutputCoinAmounts:n,paymentBtcRequired:r}=this.addInputsAndCalculateOutputs(t);this.addOutputs(n);const i=this.config.paymentAddress,s=t.btc[i]??[];await this.addBtcAndFees(s,r);const c=this.psbt.__CACHE.__TX.clone(),a=[];for(let f=0;f<this.inputUtxos.length;f++){const l=this.inputUtxos[f],d=l.address;if(d!==this.config.paymentAddress||d!==this.config.address)continue;const y=this.psbt.data.inputs[f].redeemScript,g=si(d);if(a.push({index:f,...g===Jt.P2TR?{address:d,disableTweakSigner:!1}:{publicKey:l.pubkey,disableTweakSigner:!0}}),y&&g===Jt.P2SH_P2WPKH){const m=nn([y]);c.setInputScript(f,m)}}const u=c.getId();return{psbt:this.psbt,txid:u,fee:this.txFee,toSignInputs:a}}static estimateTxVirtualSize(t,n){const r=t.length,i=n.length;let s=8+oi.varIntSize(r)+oi.varIntSize(i),o=!1;for(const c of t){const a=oi.parseAddressType(c);if(a.key==="OpReturn")continue;const u=py[a.key]??py.UNKNOWN;s+=u,LA.has(a.key)&&(o=!0)}for(const c of n){const a=oi.parseAddressType(c);if(a.key==="OpReturn"){const f=Math.max(0,a.opReturnLength??0);s+=11+f;continue}const u=yy[a.key]??yy.UNKNOWN;s+=u}return o&&(s+=1),s+$A}static parseAddressType(t){if("OpReturn"in t){const r=t.OpReturn!==void 0?Number(t.OpReturn):0;return{key:"OpReturn",opReturnLength:Number.isFinite(r)?r:0}}const n=["P2PKH","P2SH_P2WPKH","P2WPKH","P2WSH","P2SH","P2TR"];for(const r of n)if(r in t)return{key:r};return{key:"UNKNOWN"}}static varIntSize(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}async send(t){if(!this.intentions.length)throw new Error("No itentions added");const n=this.inputUtxos.filter(i=>i.address===this.config.paymentAddress||i.address===this.config.address),r=await e1(n,this.config.network);if(!r)throw new Error("Failed to get utxo proof");return this.client.orchestrator.invoke({intention_set:{tx_fee_in_sats:this.txFee,initiator_address:this.config.paymentAddress,intentions:this.intentions.map(({action:i,actionParams:s,poolAddress:o,inputCoins:c,outputCoins:a,exchangeId:u,nonce:f})=>({exchange_id:u??this.config.exchangeId,input_coins:c.filter(l=>l.from!==o),output_coins:a,pool_address:o,action:i,action_params:s??"",pool_utxo_spent:[],pool_utxo_received:[],nonce:f}))},initiator_utxo_proof:r,psbt_hex:t,client_info:[this.config.clientInfo??""]}).then(i=>{if(i?.Ok)return i.Ok;{const s=i?.Err??{},o=Object.keys(s)[0],c=s[o];throw new Error(c?o==="ErrorOccurredDuringExecution"?`${o}: ${c.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(i)}`:`Invoke Error: ${JSON.stringify(i)}`)}})}}class Is extends Error{response;request;constructor(t,n){const r=`${Is.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(r),Object.setPrototypeOf(this,Is.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,Is)}static extractMessage(t){return t.errors?.[0]?.message??`GraphQL Error (Code: ${String(t.status)})`}}const gy=e=>e.toUpperCase(),Uf=e=>typeof e=="function"?e():e,t1=(e,t)=>e.map((n,r)=>[n,t[r]]),ls=e=>{let t={};return e instanceof Headers?t=DA(e):Array.isArray(e)?e.forEach(([n,r])=>{n&&r!==void 0&&(t[n]=r)}):e&&(t=e),t},DA=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},jA=e=>{try{const t=e();return KA(t)?t.catch(n=>my(n)):t}catch(t){return my(t)}},my=e=>e instanceof Error?e:new Error(String(e)),KA=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function"&&"catch"in e&&typeof e.catch=="function"&&"finally"in e&&typeof e.finally=="function",Nh=e=>{throw new Error(`Unhandled case: ${String(e)}`)},ra=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),GA=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},WA=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0};function ia(e,t){if(!!!e)throw new Error(t)}function XA(e){return typeof e=="object"&&e!==null}function zA(e,t){if(!!!e)throw new Error("Unexpected invariant triggered.")}const YA=/\r\n|[\n\r]/g;function pl(e,t){let n=0,r=1;for(const i of e.body.matchAll(YA)){if(typeof i.index=="number"||zA(!1),i.index>=t)break;n=i.index+i[0].length,r+=1}return{line:r,column:t+1-n}}function ZA(e){return n1(e.source,pl(e.source,e.start))}function n1(e,t){const n=e.locationOffset.column-1,r="".padStart(n)+e.body,i=t.line-1,s=e.locationOffset.line-1,o=t.line+s,c=t.line===1?n:0,a=t.column+c,u=`${e.name}:${o}:${a}
|
|
77
77
|
`,f=r.split(/\r\n|[\n\r]/g),l=f[i];if(l.length>120){const d=Math.floor(a/80),y=a%80,g=[];for(let m=0;m<l.length;m+=80)g.push(l.slice(m,m+80));return u+wy([[`${o} |`,g[0]],...g.slice(1,d+1).map(m=>["|",m]),["|","^".padStart(y)],["|",g[d+1]]])}return u+wy([[`${o-1} |`,f[i-1]],[`${o} |`,l],["|","^".padStart(a)],[`${o+1} |`,f[i+1]]])}function wy(e){const t=e.filter(([r,i])=>i!==void 0),n=Math.max(...t.map(([r])=>r.length));return t.map(([r,i])=>r.padStart(n)+(i?" "+i:"")).join(`
|
|
78
78
|
`)}function JA(e){const t=e[0];return t==null||"kind"in t||"length"in t?{nodes:t,source:e[1],positions:e[2],path:e[3],originalError:e[4],extensions:e[5]}:t}class kh extends Error{constructor(t,...n){var r,i,s;const{nodes:o,source:c,positions:a,path:u,originalError:f,extensions:l}=JA(n);super(t),this.name="GraphQLError",this.path=u??void 0,this.originalError=f??void 0,this.nodes=by(Array.isArray(o)?o:o?[o]:void 0);const d=by((r=this.nodes)===null||r===void 0?void 0:r.map(g=>g.loc).filter(g=>g!=null));this.source=c??(d==null||(i=d[0])===null||i===void 0?void 0:i.source),this.positions=a??d?.map(g=>g.start),this.locations=a&&c?a.map(g=>pl(c,g)):d?.map(g=>pl(g.source,g.start));const y=XA(f?.extensions)?f?.extensions:void 0;this.extensions=(s=l??y)!==null&&s!==void 0?s:Object.create(null),Object.defineProperties(this,{message:{writable:!0,enumerable:!0},name:{enumerable:!1},nodes:{enumerable:!1},source:{enumerable:!1},positions:{enumerable:!1},originalError:{enumerable:!1}}),f!=null&&f.stack?Object.defineProperty(this,"stack",{value:f.stack,writable:!0,configurable:!0}):Error.captureStackTrace?Error.captureStackTrace(this,kh):Object.defineProperty(this,"stack",{value:Error().stack,writable:!0,configurable:!0})}get[Symbol.toStringTag](){return"GraphQLError"}toString(){let t=this.message;if(this.nodes)for(const n of this.nodes)n.loc&&(t+=`
|
|
79
79
|
|
package/dist/index.es.js
CHANGED
|
@@ -14787,12 +14787,12 @@ class QT {
|
|
|
14787
14787
|
}
|
|
14788
14788
|
async utxosByAddress(t, n, r = !0) {
|
|
14789
14789
|
return await this.axios.get(
|
|
14790
|
-
`/addresses/${t}/utxos?filter_dust=true&filter_dust_threshold=
|
|
14790
|
+
`/addresses/${t}/utxos?filter_dust=true&filter_dust_threshold=330&exclude_metaprotocols=${r}&ignore_used_brc20=true&order=asc&count=100${n ? `&cursor=${n}` : ""}`
|
|
14791
14791
|
).then((s) => s.data);
|
|
14792
14792
|
}
|
|
14793
14793
|
async utxosByAddressMempoolAware(t, n, r = !0) {
|
|
14794
14794
|
return await this.axios.get(
|
|
14795
|
-
`/mempool/addresses/${t}/utxos?filter_dust=true&exclude_metaprotocols=${r}&filter_dust_threshold=
|
|
14795
|
+
`/mempool/addresses/${t}/utxos?filter_dust=true&exclude_metaprotocols=${r}&filter_dust_threshold=330&order=asc&count=100${n ? `&cursor=${n}` : ""}`
|
|
14796
14796
|
).then((s) => s.data);
|
|
14797
14797
|
}
|
|
14798
14798
|
async inscriptionIdsByCollectionSymbol(t, n) {
|
|
@@ -27773,7 +27773,7 @@ const aI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
27773
27773
|
getUtxoProof: e1,
|
|
27774
27774
|
hexToBytes: bo,
|
|
27775
27775
|
toBitcoinNetwork: Oh
|
|
27776
|
-
}, Symbol.toStringTag, { value: "Module" })), HA = "kqs64-paaaa-aaaar-qamza-cai", FA = "hvyp5-5yaaa-aaaao-qjxha-cai", Qr = BigInt(546), on = "0:0", MA = "https://runescan-
|
|
27776
|
+
}, Symbol.toStringTag, { value: "Module" })), HA = "kqs64-paaaa-aaaar-qamza-cai", FA = "hvyp5-5yaaa-aaaao-qjxha-cai", Qr = BigInt(546), on = "0:0", MA = "https://gql-runescan-mainnet.omnity.network/v1/graphql", qA = "https://gql-runescan-testnet.omnity.network/v1/graphql", py = {
|
|
27777
27777
|
P2PKH: 148,
|
|
27778
27778
|
P2SH_P2WPKH: 91,
|
|
27779
27779
|
P2WPKH: 68,
|