/* esm.sh - borc@2.1.2 */
import*as __0$ from"/node/buffer.mjs";import*as __1$ from"/bignumber.js@^9.0.0?target=es2022";import*as __2$ from"/iso-url@~0.4.7?target=es2022";import*as __3$ from"/ieee754@^1.1.13?target=es2022";var require=n=>{const e=m=>typeof m.default<"u"?m.default:m,c=m=>Object.assign({__esModule:true},m);switch(n){case"node:buffer":return e(__0$);case"bignumber.js":return e(__1$);case"iso-url":return e(__2$);case"ieee754":return e(__3$);default:console.error('module "'+n+'" not found');return null;}};
var ze=Object.create;var St=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Je=Object.getPrototypeOf,Ze=Object.prototype.hasOwnProperty;var b=(u=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(u,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):u)(function(u){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+u+'" is not supported')});var x=(u,t)=>()=>(t||u((t={exports:{}}).exports,t),t.exports);var Qe=(u,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Xe(t))!Ze.call(u,i)&&i!==e&&St(u,i,{get:()=>t[i],enumerable:!(n=We(t,i))||n.enumerable});return u};var Ve=(u,t,e)=>(e=u!=null?ze(Je(u)):{},Qe(t||!u||!u.__esModule?St(e,"default",{value:u,enumerable:!0}):e,u));var Tt=x((Or,Nt)=>{Nt.exports=function(t,e,n){var i=new t.Uint8Array(n),c=e.pushInt,a=e.pushInt32,A=e.pushInt32Neg,B=e.pushInt64,L=e.pushInt64Neg,$=e.pushFloat,xt=e.pushFloatSingle,Lt=e.pushFloatDouble,Gt=e.pushTrue,Dt=e.pushFalse,Yt=e.pushUndefined,Ht=e.pushNull,kt=e.pushInfinity,qt=e.pushInfinityNeg,$t=e.pushNaN,Kt=e.pushNaNNeg,Ct=e.pushArrayStart,Q=e.pushArrayStartFixed,zt=e.pushArrayStartFixed32,Wt=e.pushArrayStartFixed64,Xt=e.pushObjectStart,V=e.pushObjectStartFixed,Jt=e.pushObjectStartFixed32,Zt=e.pushObjectStartFixed64,K=e.pushByteString,Qt=e.pushByteStringStart,C=e.pushUtf8String,Vt=e.pushUtf8StringStart,ot=e.pushSimpleUnassigned,w=e.pushTagStart,jt=e.pushTagStart4,te=e.pushTagStart8,yr=e.pushTagUnassigned,ee=e.pushBreak,re=t.Math.pow,s=0,j=0,tt=0;function se(r){for(r=r|0,s=0,j=r;(s|0)<(j|0)&&(tt=Ce[i[s]&255](i[s]|0)|0,!((tt|0)>0)););return tt|0}function h(r){return r=r|0,((s|0)+(r|0)|0)<(j|0)?0:1}function p(r){return r=r|0,i[r|0]<<8|i[r+1|0]|0}function dt(r){return r=r|0,i[r|0]<<24|i[r+1|0]<<16|i[r+2|0]<<8|i[r+3|0]|0}function S(r){return r=r|0,c(r|0),s=s+1|0,0}function ne(r){return r=r|0,h(1)|0?1:(c(i[s+1|0]|0),s=s+2|0,0)}function ie(r){return r=r|0,h(2)|0?1:(c(p(s+1|0)|0),s=s+3|0,0)}function ue(r){return r=r|0,h(4)|0?1:(a(p(s+1|0)|0,p(s+3|0)|0),s=s+5|0,0)}function he(r){return r=r|0,h(8)|0?1:(B(p(s+1|0)|0,p(s+3|0)|0,p(s+5|0)|0,p(s+7|0)|0),s=s+9|0,0)}function N(r){return r=r|0,c(-1-(r-32|0)|0),s=s+1|0,0}function ae(r){return r=r|0,h(1)|0?1:(c(-1-(i[s+1|0]|0)|0),s=s+2|0,0)}function pe(r){r=r|0;var l=0;return h(2)|0?1:(l=p(s+1|0)|0,c(-1-(l|0)|0),s=s+3|0,0)}function fe(r){return r=r|0,h(4)|0?1:(A(p(s+1|0)|0,p(s+3|0)|0),s=s+5|0,0)}function ce(r){return r=r|0,h(8)|0?1:(L(p(s+1|0)|0,p(s+3|0)|0,p(s+5|0)|0,p(s+7|0)|0),s=s+9|0,0)}function T(r){r=r|0;var l=0,_=0,f=0;return f=r-64|0,h(f|0)|0?1:(l=s+1|0,_=(s+1|0)+(f|0)|0,K(l|0,_|0),s=_|0,0)}function le(r){r=r|0;var l=0,_=0,f=0;return h(1)|0||(f=i[s+1|0]|0,l=s+2|0,_=(s+2|0)+(f|0)|0,h(f+1|0)|0)?1:(K(l|0,_|0),s=_|0,0)}function _e(r){r=r|0;var l=0,_=0,f=0;return h(2)|0||(f=p(s+1|0)|0,l=s+3|0,_=(s+3|0)+(f|0)|0,h(f+2|0)|0)?1:(K(l|0,_|0),s=_|0,0)}function oe(r){r=r|0;var l=0,_=0,f=0;return h(4)|0||(f=dt(s+1|0)|0,l=s+5|0,_=(s+5|0)+(f|0)|0,h(f+4|0)|0)?1:(K(l|0,_|0),s=_|0,0)}function de(r){return r=r|0,1}function Se(r){return r=r|0,Qt(),s=s+1|0,0}function I(r){r=r|0;var l=0,_=0,f=0;return f=r-96|0,h(f|0)|0?1:(l=s+1|0,_=(s+1|0)+(f|0)|0,C(l|0,_|0),s=_|0,0)}function Ne(r){r=r|0;var l=0,_=0,f=0;return h(1)|0||(f=i[s+1|0]|0,l=s+2|0,_=(s+2|0)+(f|0)|0,h(f+1|0)|0)?1:(C(l|0,_|0),s=_|0,0)}function Te(r){r=r|0;var l=0,_=0,f=0;return h(2)|0||(f=p(s+1|0)|0,l=s+3|0,_=(s+3|0)+(f|0)|0,h(f+2|0)|0)?1:(C(l|0,_|0),s=_|0,0)}function Ie(r){r=r|0;var l=0,_=0,f=0;return h(4)|0||(f=dt(s+1|0)|0,l=s+5|0,_=(s+5|0)+(f|0)|0,h(f+4|0)|0)?1:(C(l|0,_|0),s=_|0,0)}function ge(r){return r=r|0,1}function Ee(r){return r=r|0,Vt(),s=s+1|0,0}function g(r){return r=r|0,Q(r-128|0),s=s+1|0,0}function Ae(r){return r=r|0,h(1)|0?1:(Q(i[s+1|0]|0),s=s+2|0,0)}function ye(r){return r=r|0,h(2)|0?1:(Q(p(s+1|0)|0),s=s+3|0,0)}function Fe(r){return r=r|0,h(4)|0?1:(zt(p(s+1|0)|0,p(s+3|0)|0),s=s+5|0,0)}function Ue(r){return r=r|0,h(8)|0?1:(Wt(p(s+1|0)|0,p(s+3|0)|0,p(s+5|0)|0,p(s+7|0)|0),s=s+9|0,0)}function me(r){return r=r|0,Ct(),s=s+1|0,0}function E(r){r=r|0;var l=0;return l=r-160|0,h(l|0)|0?1:(V(l|0),s=s+1|0,0)}function Be(r){return r=r|0,h(1)|0?1:(V(i[s+1|0]|0),s=s+2|0,0)}function Re(r){return r=r|0,h(2)|0?1:(V(p(s+1|0)|0),s=s+3|0,0)}function ve(r){return r=r|0,h(4)|0?1:(Jt(p(s+1|0)|0,p(s+3|0)|0),s=s+5|0,0)}function Me(r){return r=r|0,h(8)|0?1:(Zt(p(s+1|0)|0,p(s+3|0)|0,p(s+5|0)|0,p(s+7|0)|0),s=s+9|0,0)}function we(r){return r=r|0,Xt(),s=s+1|0,0}function G(r){return r=r|0,w(r-192|0|0),s=s+1|0,0}function Fr(r){return r=r|0,w(r|0),s=s+1|0,0}function Ur(r){return r=r|0,w(r|0),s=s+1|0,0}function mr(r){return r=r|0,w(r|0),s=s+1|0,0}function Br(r){return r=r|0,w(r|0),s=s+1|0,0}function m(r){return r=r|0,w(r-192|0|0),s=s+1|0,0}function Rr(r){return r=r|0,w(r|0),s=s+1|0,0}function vr(r){return r=r|0,w(r|0),s=s+1|0,0}function Mr(r){return r=r|0,w(r|0),s=s+1|0,0}function be(r){return r=r|0,h(1)|0?1:(w(i[s+1|0]|0),s=s+2|0,0)}function Oe(r){return r=r|0,h(2)|0?1:(w(p(s+1|0)|0),s=s+3|0,0)}function Pe(r){return r=r|0,h(4)|0?1:(jt(p(s+1|0)|0,p(s+3|0)|0),s=s+5|0,0)}function xe(r){return r=r|0,h(8)|0?1:(te(p(s+1|0)|0,p(s+3|0)|0,p(s+5|0)|0,p(s+7|0)|0),s=s+9|0,0)}function y(r){return r=r|0,ot((r|0)-224|0),s=s+1|0,0}function Le(r){return r=r|0,Dt(),s=s+1|0,0}function Ge(r){return r=r|0,Gt(),s=s+1|0,0}function De(r){return r=r|0,Ht(),s=s+1|0,0}function Ye(r){return r=r|0,Yt(),s=s+1|0,0}function He(r){return r=r|0,h(1)|0?1:(ot(i[s+1|0]|0),s=s+2|0,0)}function ke(r){r=r|0;var l=0,_=0,f=1,z=0,H=0,wr=0;return h(2)|0?1:(l=i[s+1|0]|0,_=i[s+2|0]|0,(l|0)&128&&(f=-1),z=+(((l|0)&124)>>2),H=+(((l|0)&3)<<8|_),+z==0?$(+(+f*5960464477539063e-23*+H)):+z==31?+f==1?+H>0?$t():kt():+H>0?Kt():qt():$(+(+f*re(2,+(+z-25))*+(1024+H))),s=s+3|0,0)}function qe(r){return r=r|0,h(4)|0?1:(xt(i[s+1|0]|0,i[s+2|0]|0,i[s+3|0]|0,i[s+4|0]|0),s=s+5|0,0)}function $e(r){return r=r|0,h(8)|0?1:(Lt(i[s+1|0]|0,i[s+2|0]|0,i[s+3|0]|0,i[s+4|0]|0,i[s+5|0]|0,i[s+6|0]|0,i[s+7|0]|0,i[s+8|0]|0),s=s+9|0,0)}function d(r){return r=r|0,1}function Ke(r){return r=r|0,ee(),s=s+1|0,0}var Ce=[S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,ne,ie,ue,he,d,d,d,d,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,ae,pe,fe,ce,d,d,d,d,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,le,_e,oe,de,d,d,d,Se,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,Ne,Te,Ie,ge,d,d,d,Ee,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,g,Ae,ye,Fe,Ue,d,d,d,me,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,E,Be,Re,ve,Me,d,d,d,we,G,G,G,G,G,G,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,be,Oe,Pe,xe,d,d,d,d,y,y,y,y,y,y,y,y,y,y,y,y,y,y,y,y,y,y,y,y,Le,Ge,De,Ye,He,ke,qe,$e,d,d,d,Ke];return{parse:se}}});var k=x(v=>{"use strict";var et=b("bignumber.js").BigNumber;v.MT={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7};v.TAG={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,REGEXP:35,MIME:36};v.NUMBYTES={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31};v.SIMPLE={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23};v.SYMS={NULL:Symbol("null"),UNDEFINED:Symbol("undef"),PARENT:Symbol("parent"),BREAK:Symbol("break"),STREAM:Symbol("stream")};v.SHIFT32=Math.pow(2,32);v.SHIFT16=Math.pow(2,16);v.MAX_SAFE_HIGH=2097151;v.NEG_ONE=new et(-1);v.TEN=new et(10);v.TWO=new et(2);v.PARENT={ARRAY:0,OBJECT:1,MAP:2,TAG:3,BYTE_STRING:4,UTF8_STRING:5}});var W=x(M=>{"use strict";var{Buffer:je}=b("node:buffer"),gt=b("bignumber.js").BigNumber,Et=k(),It=Et.SHIFT32,tr=Et.SHIFT16,er=2097151;M.parseHalf=function(t){var e,n,i;return i=t[0]&128?-1:1,e=(t[0]&124)>>2,n=(t[0]&3)<<8|t[1],e?e===31?i*(n?NaN:1/0):i*Math.pow(2,e-25)*(1024+n):i*5960464477539063e-23*n};function rr(u){return u<16?"0"+u.toString(16):u.toString(16)}M.arrayBufferToBignumber=function(u){let t=u.byteLength,e="";for(let n=0;n<t;n++)e+=rr(u[n]);return new gt(e,16)};M.buildMap=u=>{let t=new Map,e=Object.keys(u),n=e.length;for(let i=0;i<n;i++)t.set(e[i],u[e[i]]);return t};M.buildInt32=(u,t)=>u*tr+t;M.buildInt64=(u,t,e,n)=>{let i=M.buildInt32(u,t),c=M.buildInt32(e,n);return i>er?new gt(i).times(It).plus(c):i*It+c};M.writeHalf=function(t,e){let n=je.allocUnsafe(4);n.writeFloatBE(e,0);let i=n.readUInt32BE(0);if(i&8191)return!1;var c=i>>16&32768;let a=i>>23&255,A=i&8388607;if(a>=113&&a<=142)c+=(a-112<<10)+(A>>13);else if(a>=103&&a<113){if(A&(1<<126-a)-1)return!1;c+=A+8388608>>126-a}else return!1;return t.writeUInt16BE(c,0),!0};M.keySorter=function(u,t){var e=u[0].byteLength,n=t[0].byteLength;return e>n?1:n>e?-1:u[0].compare(t[0])};M.isNegativeZero=u=>u===0&&1/u<0;M.nextPowerOf2=u=>{let t=0;if(u&&!(u&u-1))return u;for(;u!==0;)u>>=1,t+=1;return 1<<t}});var it=x((Lr,At)=>{"use strict";var nt=k(),sr=nt.MT,X=nt.SIMPLE,rt=nt.SYMS,st=class u{constructor(t){if(typeof t!="number")throw new Error("Invalid Simple type: "+typeof t);if(t<0||t>255||(t|0)!==t)throw new Error("value must be a small positive integer: "+t);this.value=t}toString(){return"simple("+this.value+")"}inspect(){return"simple("+this.value+")"}encodeCBOR(t){return t._pushInt(this.value,sr.SIMPLE_FLOAT)}static isSimple(t){return t instanceof u}static decode(t,e){switch(e==null&&(e=!0),t){case X.FALSE:return!1;case X.TRUE:return!0;case X.NULL:return e?null:rt.NULL;case X.UNDEFINED:return e?void 0:rt.UNDEFINED;case-1:if(!e)throw new Error("Invalid BREAK");return rt.BREAK;default:return new u(t)}}};At.exports=st});var ht=x((Gr,yt)=>{"use strict";var ut=class u{constructor(t,e,n){if(this.tag=t,this.value=e,this.err=n,typeof this.tag!="number")throw new Error("Invalid tag type ("+typeof this.tag+")");if(this.tag<0||(this.tag|0)!==this.tag)throw new Error("Tag must be a positive integer: "+this.tag)}toString(){return`${this.tag}(${JSON.stringify(this.value)})`}encodeCBOR(t){return t._pushTag(this.tag),t.pushAny(this.value)}convert(t){var e,n;if(n=t?.[this.tag],typeof n!="function"&&(n=u["_tag"+this.tag],typeof n!="function"))return this;try{return n.call(u,this.value)}catch(i){return e=i,this.err=e,this}}};yt.exports=ut});var at=x((Dr,Ut)=>{"use strict";var{Buffer:D}=b("node:buffer"),Ft=b("ieee754"),nr=b("bignumber.js").BigNumber,ir=Tt(),R=W(),o=k(),ur=it(),hr=ht(),{URL:ar}=b("iso-url"),q=class u{constructor(t){t=t||{},!t.size||t.size<65536?t.size=65536:t.size=R.nextPowerOf2(t.size),this._heap=new ArrayBuffer(t.size),this._heap8=new Uint8Array(this._heap),this._buffer=D.from(this._heap),this._reset(),this._knownTags=Object.assign({0:e=>new Date(e),1:e=>new Date(e*1e3),2:e=>R.arrayBufferToBignumber(e),3:e=>o.NEG_ONE.minus(R.arrayBufferToBignumber(e)),4:e=>o.TEN.pow(e[0]).times(e[1]),5:e=>o.TWO.pow(e[0]).times(e[1]),32:e=>new ar(e),35:e=>new RegExp(e)},t.tags),this.parser=ir(globalThis,{log:console.log.bind(console),pushInt:this.pushInt.bind(this),pushInt32:this.pushInt32.bind(this),pushInt32Neg:this.pushInt32Neg.bind(this),pushInt64:this.pushInt64.bind(this),pushInt64Neg:this.pushInt64Neg.bind(this),pushFloat:this.pushFloat.bind(this),pushFloatSingle:this.pushFloatSingle.bind(this),pushFloatDouble:this.pushFloatDouble.bind(this),pushTrue:this.pushTrue.bind(this),pushFalse:this.pushFalse.bind(this),pushUndefined:this.pushUndefined.bind(this),pushNull:this.pushNull.bind(this),pushInfinity:this.pushInfinity.bind(this),pushInfinityNeg:this.pushInfinityNeg.bind(this),pushNaN:this.pushNaN.bind(this),pushNaNNeg:this.pushNaNNeg.bind(this),pushArrayStart:this.pushArrayStart.bind(this),pushArrayStartFixed:this.pushArrayStartFixed.bind(this),pushArrayStartFixed32:this.pushArrayStartFixed32.bind(this),pushArrayStartFixed64:this.pushArrayStartFixed64.bind(this),pushObjectStart:this.pushObjectStart.bind(this),pushObjectStartFixed:this.pushObjectStartFixed.bind(this),pushObjectStartFixed32:this.pushObjectStartFixed32.bind(this),pushObjectStartFixed64:this.pushObjectStartFixed64.bind(this),pushByteString:this.pushByteString.bind(this),pushByteStringStart:this.pushByteStringStart.bind(this),pushUtf8String:this.pushUtf8String.bind(this),pushUtf8StringStart:this.pushUtf8StringStart.bind(this),pushSimpleUnassigned:this.pushSimpleUnassigned.bind(this),pushTagUnassigned:this.pushTagUnassigned.bind(this),pushTagStart:this.pushTagStart.bind(this),pushTagStart4:this.pushTagStart4.bind(this),pushTagStart8:this.pushTagStart8.bind(this),pushBreak:this.pushBreak.bind(this)},this._heap)}get _depth(){return this._parents.length}get _currentParent(){return this._parents[this._depth-1]}get _ref(){return this._currentParent.ref}_closeParent(){var t=this._parents.pop();if(t.length>0)throw new Error(`Missing ${t.length} elements`);switch(t.type){case o.PARENT.TAG:this._push(this.createTag(t.ref[0],t.ref[1]));break;case o.PARENT.BYTE_STRING:this._push(this.createByteString(t.ref,t.length));break;case o.PARENT.UTF8_STRING:this._push(this.createUtf8String(t.ref,t.length));break;case o.PARENT.MAP:if(t.values%2>0)throw new Error("Odd number of elements in the map");this._push(this.createMap(t.ref,t.length));break;case o.PARENT.OBJECT:if(t.values%2>0)throw new Error("Odd number of elements in the map");this._push(this.createObject(t.ref,t.length));break;case o.PARENT.ARRAY:this._push(this.createArray(t.ref,t.length));break;default:break}this._currentParent&&this._currentParent.type===o.PARENT.TAG&&this._dec()}_dec(){let t=this._currentParent;t.length<0||(t.length--,t.length===0&&this._closeParent())}_push(t,e){let n=this._currentParent;switch(n.values++,n.type){case o.PARENT.ARRAY:case o.PARENT.BYTE_STRING:case o.PARENT.UTF8_STRING:n.length>-1?this._ref[this._ref.length-n.length]=t:this._ref.push(t),this._dec();break;case o.PARENT.OBJECT:n.tmpKey!=null?(this._ref[n.tmpKey]=t,n.tmpKey=null,this._dec()):(n.tmpKey=t,typeof n.tmpKey!="string"&&(n.type=o.PARENT.MAP,n.ref=R.buildMap(n.ref)));break;case o.PARENT.MAP:n.tmpKey!=null?(this._ref.set(n.tmpKey,t),n.tmpKey=null,this._dec()):n.tmpKey=t;break;case o.PARENT.TAG:this._ref.push(t),e||this._dec();break;default:throw new Error("Unknown parent type")}}_createParent(t,e,n){this._parents[this._depth]={type:e,length:n,ref:t,values:0,tmpKey:null}}_reset(){this._res=[],this._parents=[{type:o.PARENT.ARRAY,length:-1,ref:this._res,values:0,tmpKey:null}]}createTag(t,e){let n=this._knownTags[t];return n?n(e):new hr(t,e)}createMap(t,e){return t}createObject(t,e){return t}createArray(t,e){return t}createByteString(t,e){return D.concat(t)}createByteStringFromHeap(t,e){return t===e?D.alloc(0):D.from(this._heap.slice(t,e))}createInt(t){return t}createInt32(t,e){return R.buildInt32(t,e)}createInt64(t,e,n,i){return R.buildInt64(t,e,n,i)}createFloat(t){return t}createFloatSingle(t,e,n,i){return Ft.read([t,e,n,i],0,!1,23,4)}createFloatDouble(t,e,n,i,c,a,A,B){return Ft.read([t,e,n,i,c,a,A,B],0,!1,52,8)}createInt32Neg(t,e){return-1-R.buildInt32(t,e)}createInt64Neg(t,e,n,i){let c=R.buildInt32(t,e),a=R.buildInt32(n,i);return c>o.MAX_SAFE_HIGH?o.NEG_ONE.minus(new nr(c).times(o.SHIFT32).plus(a)):-1-(c*o.SHIFT32+a)}createTrue(){return!0}createFalse(){return!1}createNull(){return null}createUndefined(){}createInfinity(){return 1/0}createInfinityNeg(){return-1/0}createNaN(){return NaN}createNaNNeg(){return NaN}createUtf8String(t,e){return t.join("")}createUtf8StringFromHeap(t,e){return t===e?"":this._buffer.toString("utf8",t,e)}createSimpleUnassigned(t){return new ur(t)}pushInt(t){this._push(this.createInt(t))}pushInt32(t,e){this._push(this.createInt32(t,e))}pushInt64(t,e,n,i){this._push(this.createInt64(t,e,n,i))}pushFloat(t){this._push(this.createFloat(t))}pushFloatSingle(t,e,n,i){this._push(this.createFloatSingle(t,e,n,i))}pushFloatDouble(t,e,n,i,c,a,A,B){this._push(this.createFloatDouble(t,e,n,i,c,a,A,B))}pushInt32Neg(t,e){this._push(this.createInt32Neg(t,e))}pushInt64Neg(t,e,n,i){this._push(this.createInt64Neg(t,e,n,i))}pushTrue(){this._push(this.createTrue())}pushFalse(){this._push(this.createFalse())}pushNull(){this._push(this.createNull())}pushUndefined(){this._push(this.createUndefined())}pushInfinity(){this._push(this.createInfinity())}pushInfinityNeg(){this._push(this.createInfinityNeg())}pushNaN(){this._push(this.createNaN())}pushNaNNeg(){this._push(this.createNaNNeg())}pushArrayStart(){this._createParent([],o.PARENT.ARRAY,-1)}pushArrayStartFixed(t){this._createArrayStartFixed(t)}pushArrayStartFixed32(t,e){let n=R.buildInt32(t,e);this._createArrayStartFixed(n)}pushArrayStartFixed64(t,e,n,i){let c=R.buildInt64(t,e,n,i);this._createArrayStartFixed(c)}pushObjectStart(){this._createObjectStartFixed(-1)}pushObjectStartFixed(t){this._createObjectStartFixed(t)}pushObjectStartFixed32(t,e){let n=R.buildInt32(t,e);this._createObjectStartFixed(n)}pushObjectStartFixed64(t,e,n,i){let c=R.buildInt64(t,e,n,i);this._createObjectStartFixed(c)}pushByteStringStart(){this._parents[this._depth]={type:o.PARENT.BYTE_STRING,length:-1,ref:[],values:0,tmpKey:null}}pushByteString(t,e){this._push(this.createByteStringFromHeap(t,e))}pushUtf8StringStart(){this._parents[this._depth]={type:o.PARENT.UTF8_STRING,length:-1,ref:[],values:0,tmpKey:null}}pushUtf8String(t,e){this._push(this.createUtf8StringFromHeap(t,e))}pushSimpleUnassigned(t){this._push(this.createSimpleUnassigned(t))}pushTagStart(t){this._parents[this._depth]={type:o.PARENT.TAG,length:1,ref:[t]}}pushTagStart4(t,e){this.pushTagStart(R.buildInt32(t,e))}pushTagStart8(t,e,n,i){this.pushTagStart(R.buildInt64(t,e,n,i))}pushTagUnassigned(t){this._push(this.createTag(t))}pushBreak(){if(this._currentParent.length>-1)throw new Error("Unexpected break");this._closeParent()}_createObjectStartFixed(t){if(t===0){this._push(this.createObject({}));return}this._createParent({},o.PARENT.OBJECT,t)}_createArrayStartFixed(t){if(t===0){this._push(this.createArray([]));return}this._createParent(new Array(t),o.PARENT.ARRAY,t)}_decode(t){if(t.byteLength===0)throw new Error("Input too short");this._reset(),this._heap8.set(t);let e=this.parser.parse(t.byteLength);if(this._depth>1){for(;this._currentParent.length===0;)this._closeParent();if(this._depth>1)throw new Error("Undeterminated nesting")}if(e>0)throw new Error("Failed to parse");if(this._res.length===0)throw new Error("No valid result")}decodeFirst(t){return this._decode(t),this._res[0]}decodeAll(t){return this._decode(t),this._res}static decode(t,e){return typeof t=="string"&&(t=D.from(t,e||"hex")),new u({size:t.length}).decodeFirst(t)}static decodeAll(t,e){return typeof t=="string"&&(t=D.from(t,e||"hex")),new u({size:t.length}).decodeAll(t)}};q.decodeFirst=q.decode;Ut.exports=q});var Rt=x((Yr,Bt)=>{"use strict";var{Buffer:pt}=b("node:buffer"),pr=at(),fr=W(),ft=class u extends pr{createTag(t,e){return`${t}(${e})`}createInt(t){return super.createInt(t).toString()}createInt32(t,e){return super.createInt32(t,e).toString()}createInt64(t,e,n,i){return super.createInt64(t,e,n,i).toString()}createInt32Neg(t,e){return super.createInt32Neg(t,e).toString()}createInt64Neg(t,e,n,i){return super.createInt64Neg(t,e,n,i).toString()}createTrue(){return"true"}createFalse(){return"false"}createFloat(t){let e=super.createFloat(t);return fr.isNegativeZero(t)?"-0_1":`${e}_1`}createFloatSingle(t,e,n,i){return`${super.createFloatSingle(t,e,n,i)}_2`}createFloatDouble(t,e,n,i,c,a,A,B){return`${super.createFloatDouble(t,e,n,i,c,a,A,B)}_3`}createByteString(t,e){let n=t.join(", ");return e===-1?`(_ ${n})`:`h'${n}`}createByteStringFromHeap(t,e){return`h'${pt.from(super.createByteStringFromHeap(t,e)).toString("hex")}'`}createInfinity(){return"Infinity_1"}createInfinityNeg(){return"-Infinity_1"}createNaN(){return"NaN_1"}createNaNNeg(){return"-NaN_1"}createNull(){return"null"}createUndefined(){return"undefined"}createSimpleUnassigned(t){return`simple(${t})`}createArray(t,e){let n=super.createArray(t,e);return e===-1?`[_ ${n.join(", ")}]`:`[${n.join(", ")}]`}createMap(t,e){let n=super.createMap(t),i=Array.from(n.keys()).reduce(mt(n),"");return e===-1?`{_ ${i}}`:`{${i}}`}createObject(t,e){let n=super.createObject(t),i=Object.keys(n).reduce(mt(n),"");return e===-1?`{_ ${i}}`:`{${i}}`}createUtf8String(t,e){let n=t.join(", ");return e===-1?`(_ ${n})`:`"${n}"`}createUtf8StringFromHeap(t,e){return`"${pt.from(super.createUtf8StringFromHeap(t,e)).toString("utf8")}"`}static diagnose(t,e){return typeof t=="string"&&(t=pt.from(t,e||"hex")),new u().decodeFirst(t)}};Bt.exports=ft;function mt(u){return(t,e)=>t?`${t}, ${e}: ${u[e]}`:`${e}: ${u[e]}`}});var Ot=x((Hr,bt)=>{"use strict";var{Buffer:P}=b("node:buffer"),{URL:cr}=b("iso-url"),lt=b("bignumber.js").BigNumber,ct=W(),F=k(),O=F.MT,J=F.NUMBYTES,vt=F.SHIFT32,Mt=F.SYMS,Y=F.TAG,lr=F.MT.SIMPLE_FLOAT<<5|F.NUMBYTES.TWO,_r=F.MT.SIMPLE_FLOAT<<5|F.NUMBYTES.FOUR,or=F.MT.SIMPLE_FLOAT<<5|F.NUMBYTES.EIGHT,dr=F.MT.SIMPLE_FLOAT<<5|F.SIMPLE.TRUE,Sr=F.MT.SIMPLE_FLOAT<<5|F.SIMPLE.FALSE,Nr=F.MT.SIMPLE_FLOAT<<5|F.SIMPLE.UNDEFINED,wt=F.MT.SIMPLE_FLOAT<<5|F.SIMPLE.NULL,Tr=new lt("0x20000000000000"),Ir=P.from("f97e00","hex"),gr=P.from("f9fc00","hex"),Er=P.from("f97c00","hex");function Ar(u){return{}.toString.call(u).slice(8,-1)}var _t=class u{constructor(t){t=t||{},this.streaming=typeof t.stream=="function",this.onData=t.stream,this.semanticTypes=[[cr,this._pushUrl],[lt,this._pushBigNumber]];let e=t.genTypes||[],n=e.length;for(let i=0;i<n;i++)this.addSemanticType(e[i][0],e[i][1]);this._reset()}addSemanticType(t,e){let n=this.semanticTypes.length;for(let i=0;i<n;i++)if(this.semanticTypes[i][0]===t){let a=this.semanticTypes[i][1];return this.semanticTypes[i][1]=e,a}return this.semanticTypes.push([t,e]),null}push(t){return t&&(this.result[this.offset]=t,this.resultMethod[this.offset]=0,this.resultLength[this.offset]=t.length,this.offset++,this.streaming&&this.onData(this.finalize())),!0}pushWrite(t,e,n){return this.result[this.offset]=t,this.resultMethod[this.offset]=e,this.resultLength[this.offset]=n,this.offset++,this.streaming&&this.onData(this.finalize()),!0}_pushUInt8(t){return this.pushWrite(t,1,1)}_pushUInt16BE(t){return this.pushWrite(t,2,2)}_pushUInt32BE(t){return this.pushWrite(t,3,4)}_pushDoubleBE(t){return this.pushWrite(t,4,8)}_pushNaN(){return this.push(Ir)}_pushInfinity(t){let e=t<0?gr:Er;return this.push(e)}_pushFloat(t){let e=P.allocUnsafe(2);if(ct.writeHalf(e,t)&&ct.parseHalf(e)===t)return this._pushUInt8(lr)&&this.push(e);let n=P.allocUnsafe(4);return n.writeFloatBE(t,0),n.readFloatBE(0)===t?this._pushUInt8(_r)&&this.push(n):this._pushUInt8(or)&&this._pushDoubleBE(t)}_pushInt(t,e,n){let i=e<<5;return t<24?this._pushUInt8(i|t):t<=255?this._pushUInt8(i|J.ONE)&&this._pushUInt8(t):t<=65535?this._pushUInt8(i|J.TWO)&&this._pushUInt16BE(t):t<=4294967295?this._pushUInt8(i|J.FOUR)&&this._pushUInt32BE(t):t<=Number.MAX_SAFE_INTEGER?this._pushUInt8(i|J.EIGHT)&&this._pushUInt32BE(Math.floor(t/vt))&&this._pushUInt32BE(t%vt):e===O.NEG_INT?this._pushFloat(n):this._pushFloat(t)}_pushIntNum(t){return t<0?this._pushInt(-t-1,O.NEG_INT,t):this._pushInt(t,O.POS_INT)}_pushNumber(t){switch(!1){case t===t:return this._pushNaN(t);case isFinite(t):return this._pushInfinity(t);case t%1!==0:return this._pushIntNum(t);default:return this._pushFloat(t)}}_pushString(t){let e=P.byteLength(t,"utf8");return this._pushInt(e,O.UTF8_STRING)&&this.pushWrite(t,5,e)}_pushBoolean(t){return this._pushUInt8(t?dr:Sr)}_pushUndefined(t){return this._pushUInt8(Nr)}_pushArray(t,e){let n=e.length;if(!t._pushInt(n,O.ARRAY))return!1;for(let i=0;i<n;i++)if(!t.pushAny(e[i]))return!1;return!0}_pushTag(t){return this._pushInt(t,O.TAG)}_pushDate(t,e){return t._pushTag(Y.DATE_EPOCH)&&t.pushAny(Math.round(e/1e3))}_pushBuffer(t,e){return t._pushInt(e.length,O.BYTE_STRING)&&t.push(e)}_pushNoFilter(t,e){return t._pushBuffer(t,e.slice())}_pushRegexp(t,e){return t._pushTag(Y.REGEXP)&&t.pushAny(e.source)}_pushSet(t,e){if(!t._pushInt(e.size,O.ARRAY))return!1;for(let n of e)if(!t.pushAny(n))return!1;return!0}_pushUrl(t,e){return t._pushTag(Y.URI)&&t.pushAny(e.format())}_pushBigint(t){let e=Y.POS_BIGINT;t.isNegative()&&(t=t.negated().minus(1),e=Y.NEG_BIGINT);let n=t.toString(16);n.length%2&&(n="0"+n);let i=P.from(n,"hex");return this._pushTag(e)&&this._pushBuffer(this,i)}_pushBigNumber(t,e){if(e.isNaN())return t._pushNaN();if(!e.isFinite())return t._pushInfinity(e.isNegative()?-1/0:1/0);if(e.isInteger())return t._pushBigint(e);if(!(t._pushTag(Y.DECIMAL_FRAC)&&t._pushInt(2,O.ARRAY)))return!1;let n=e.decimalPlaces(),i=e.multipliedBy(new lt(10).pow(n));return t._pushIntNum(-n)?i.abs().isLessThan(Tr)?t._pushIntNum(i.toNumber()):t._pushBigint(i):!1}_pushMap(t,e){return t._pushInt(e.size,O.MAP)?this._pushRawMap(e.size,Array.from(e)):!1}_pushObject(t){if(!t)return this._pushUInt8(wt);for(var e=this.semanticTypes.length,n=0;n<e;n++)if(t instanceof this.semanticTypes[n][0])return this.semanticTypes[n][1].call(t,this,t);var i=t.encodeCBOR;if(typeof i=="function")return i.call(t,this);var c=Object.keys(t),a=c.length;return this._pushInt(a,O.MAP)?this._pushRawMap(a,c.map(A=>[A,t[A]])):!1}_pushRawMap(t,e){e=e.map(function(i){return i[0]=u.encode(i[0]),i}).sort(ct.keySorter);for(var n=0;n<t;n++)if(!this.push(e[n][0])||!this.pushAny(e[n][1]))return!1;return!0}write(t){return this.pushAny(t)}pushAny(t){var e=Ar(t);switch(e){case"Number":return this._pushNumber(t);case"String":return this._pushString(t);case"Boolean":return this._pushBoolean(t);case"Object":return this._pushObject(t);case"Array":return this._pushArray(this,t);case"Uint8Array":return this._pushBuffer(this,P.isBuffer(t)?t:P.from(t));case"Null":return this._pushUInt8(wt);case"Undefined":return this._pushUndefined(t);case"Map":return this._pushMap(this,t);case"Set":return this._pushSet(this,t);case"URL":return this._pushUrl(this,t);case"BigNumber":return this._pushBigNumber(this,t);case"Date":return this._pushDate(this,t);case"RegExp":return this._pushRegexp(this,t);case"Symbol":switch(t){case Mt.NULL:return this._pushObject(null);case Mt.UNDEFINED:return this._pushUndefined(void 0);default:throw new Error("Unknown symbol: "+t.toString())}default:throw new Error("Unknown type: "+typeof t+", "+(t?t.toString():""))}}finalize(){if(this.offset===0)return null;for(var t=this.result,e=this.resultLength,n=this.resultMethod,i=this.offset,c=0,a=0;a<i;a++)c+=e[a];var A=P.allocUnsafe(c),B=0,L=0;for(a=0;a<i;a++){switch(L=e[a],n[a]){case 0:t[a].copy(A,B);break;case 1:A.writeUInt8(t[a],B,!0);break;case 2:A.writeUInt16BE(t[a],B,!0);break;case 3:A.writeUInt32BE(t[a],B,!0);break;case 4:A.writeDoubleBE(t[a],B,!0);break;case 5:A.write(t[a],B,L,"utf8");break;default:throw new Error("unkown method")}B+=L}var $=A;return this._reset(),$}_reset(){this.result=[],this.resultMethod=[],this.resultLength=[],this.offset=0}static encode(t){let e=new u;if(!e.pushAny(t))throw new Error("Failed to encode input");return e.finalize()}};bt.exports=_t});var Pt=x(U=>{"use strict";U.Diagnose=Rt();U.Decoder=at();U.Encoder=Ot();U.Simple=it();U.Tagged=ht();U.decodeAll=U.Decoder.decodeAll;U.decodeFirst=U.Decoder.decodeFirst;U.diagnose=U.Diagnose.diagnose;U.encode=U.Encoder.encode;U.decode=U.Decoder.decode;U.leveldb={decode:U.Decoder.decodeAll,encode:U.Encoder.encode,buffer:!0,name:"cbor"}});var Z=Ve(Pt()),{Diagnose:qr,Decoder:$r,Encoder:Kr,Simple:Cr,Tagged:zr,decodeAll:Wr,decodeFirst:Xr,diagnose:Jr,encode:Zr,decode:Qr,leveldb:Vr}=Z,jr=Z.default??Z;export{$r as Decoder,qr as Diagnose,Kr as Encoder,Cr as Simple,zr as Tagged,Qr as decode,Wr as decodeAll,Xr as decodeFirst,jr as default,Jr as diagnose,Zr as encode,Vr as leveldb};
//# sourceMappingURL=borc.mjs.map