/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@meshsdk/core-cst@1.9.0-beta.102/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__commonJS=(e,t)=>function(){return t||(0,e[__getOwnPropNames(e)[0]])((t={exports:{}}).exports,t),t.exports},__copyProps=(e,t,r,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let i of __getOwnPropNames(t))__hasOwnProp.call(e,i)||i===r||__defProp(e,i,{get:()=>t[i],enumerable:!(o=__getOwnPropDesc(t,i))||o.enumerable});return e},__toESM=(e,t,r)=>(r=null!=e?__create(__getProtoOf(e)):{},__copyProps(!t&&e&&e.__esModule?r:__defProp(r,"default",{value:e,enumerable:!0}),e)),require_bignumber=__commonJS({"../../node_modules/bignumber.js/bignumber.js"(e,t){"use strict";!function(e){var r,o=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,i=Math.ceil,a=Math.floor,n="[BigNumber Error] ",s=n+"Number primitive has more than 15 significant digits: ",d=1e14,u=14,c=9007199254740991,l=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],p=1e7,h=1e9;function A(e){var t=0|e;return e>0||e===t?t:t-1}function f(e){for(var t,r,o=1,i=e.length,a=e[0]+"";o<i;){for(t=e[o++]+"",r=u-t.length;r--;t="0"+t);a+=t}for(i=a.length;48===a.charCodeAt(--i););return a.slice(0,i+1||1)}function g(e,t){var r,o,i=e.c,a=t.c,n=e.s,s=t.s,d=e.e,u=t.e;if(!n||!s)return null;if(r=i&&!i[0],o=a&&!a[0],r||o)return r?o?0:-s:n;if(n!=s)return n;if(r=n<0,o=d==u,!i||!a)return o?0:!i^r?1:-1;if(!o)return d>u^r?1:-1;for(s=(d=i.length)<(u=a.length)?d:u,n=0;n<s;n++)if(i[n]!=a[n])return i[n]>a[n]^r?1:-1;return d==u?0:d>u^r?1:-1}function I(e,t,r,o){if(e<t||e>r||e!==a(e))throw Error(n+(o||"Argument")+("number"==typeof e?e<t||e>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function C(e){var t=e.c.length-1;return A(e.e/u)==t&&e.c[t]%2!=0}function m(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function y(e,t,r){var o,i;if(t<0){for(i=r+".";++t;i+=r);e=i+e}else if(++t>(o=e.length)){for(i=r,t-=o;--t;i+=r);e+=i}else t<o&&(e=e.slice(0,t)+"."+e.slice(t));return e}r=function e(t){var r,S,w,B,E,b=O.prototype={constructor:O,toString:null,valueOf:null},P=new O(1),D=20,x=4,v=-7,H=21,Q=-1e7,T=1e7,K=!1,V=1,R=0,k={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},U="0123456789abcdefghijklmnopqrstuvwxyz",N=!0;function O(e,t){var r,i,n,d,l,p,h,A,f=this;if(!(f instanceof O))return new O(e,t);if(null==t){if(e&&!0===e._isBigNumber)return f.s=e.s,void(!e.c||e.e>T?f.c=f.e=null:e.e<Q?f.c=[f.e=0]:(f.e=e.e,f.c=e.c.slice()));if((p="number"==typeof e)&&0*e==0){if(f.s=1/e<0?(e=-e,-1):1,e===~~e){for(d=0,l=e;l>=10;l/=10,d++);return void(d>T?f.c=f.e=null:(f.e=d,f.c=[e]))}A=String(e)}else{if(!o.test(A=String(e)))return w(f,A,p);f.s=45==A.charCodeAt(0)?(A=A.slice(1),-1):1}(d=A.indexOf("."))>-1&&(A=A.replace(".","")),(l=A.search(/e/i))>0?(d<0&&(d=l),d+=+A.slice(l+1),A=A.substring(0,l)):d<0&&(d=A.length)}else{if(I(t,2,U.length,"Base"),10==t&&N)return _(f=new O(e),D+f.e+1,x);if(A=String(e),p="number"==typeof e){if(0*e!=0)return w(f,A,p,t);if(f.s=1/e<0?(A=A.slice(1),-1):1,O.DEBUG&&A.replace(/^0\.0*|\./,"").length>15)throw Error(s+e)}else f.s=45===A.charCodeAt(0)?(A=A.slice(1),-1):1;for(r=U.slice(0,t),d=l=0,h=A.length;l<h;l++)if(r.indexOf(i=A.charAt(l))<0){if("."==i){if(l>d){d=h;continue}}else if(!n&&(A==A.toUpperCase()&&(A=A.toLowerCase())||A==A.toLowerCase()&&(A=A.toUpperCase()))){n=!0,l=-1,d=0;continue}return w(f,String(e),p,t)}p=!1,(d=(A=S(A,t,10,f.s)).indexOf("."))>-1?A=A.replace(".",""):d=A.length}for(l=0;48===A.charCodeAt(l);l++);for(h=A.length;48===A.charCodeAt(--h););if(A=A.slice(l,++h)){if(h-=l,p&&O.DEBUG&&h>15&&(e>c||e!==a(e)))throw Error(s+f.s*e);if((d=d-l-1)>T)f.c=f.e=null;else if(d<Q)f.c=[f.e=0];else{if(f.e=d,f.c=[],l=(d+1)%u,d<0&&(l+=u),l<h){for(l&&f.c.push(+A.slice(0,l)),h-=u;l<h;)f.c.push(+A.slice(l,l+=u));l=u-(A=A.slice(l)).length}else l-=h;for(;l--;A+="0");f.c.push(+A)}}else f.c=[f.e=0]}function z(e,t,r,o){var i,a,n,s,d;if(null==r?r=x:I(r,0,8),!e.c)return e.toString();if(i=e.c[0],n=e.e,null==t)d=f(e.c),d=1==o||2==o&&(n<=v||n>=H)?m(d,n):y(d,n,"0");else if(a=(e=_(new O(e),t,r)).e,s=(d=f(e.c)).length,1==o||2==o&&(t<=a||a<=v)){for(;s<t;d+="0",s++);d=m(d,a)}else if(t-=n+(2===o&&a>n),d=y(d,a,"0"),a+1>s){if(--t>0)for(d+=".";t--;d+="0");}else if((t+=a-s)>0)for(a+1==s&&(d+=".");t--;d+="0");return e.s<0&&i?"-"+d:d}function F(e,t){for(var r,o,i=1,a=new O(e[0]);i<e.length;i++)(!(o=new O(e[i])).s||(r=g(a,o))===t||0===r&&a.s===t)&&(a=o);return a}function M(e,t,r){for(var o=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,o++);return(r=o+r*u-1)>T?e.c=e.e=null:r<Q?e.c=[e.e=0]:(e.e=r,e.c=t),e}function _(e,t,r,o){var n,s,c,p,h,A,f,g=e.c,I=l;if(g){e:{for(n=1,p=g[0];p>=10;p/=10,n++);if((s=t-n)<0)s+=u,c=t,h=g[A=0],f=a(h/I[n-c-1]%10);else if((A=i((s+1)/u))>=g.length){if(!o)break e;for(;g.length<=A;g.push(0));h=f=0,n=1,c=(s%=u)-u+1}else{for(h=p=g[A],n=1;p>=10;p/=10,n++);f=(c=(s%=u)-u+n)<0?0:a(h/I[n-c-1]%10)}if(o=o||t<0||null!=g[A+1]||(c<0?h:h%I[n-c-1]),o=r<4?(f||o)&&(0==r||r==(e.s<0?3:2)):f>5||5==f&&(4==r||o||6==r&&(s>0?c>0?h/I[n-c]:0:g[A-1])%10&1||r==(e.s<0?8:7)),t<1||!g[0])return g.length=0,o?(t-=e.e+1,g[0]=I[(u-t%u)%u],e.e=-t||0):g[0]=e.e=0,e;if(0==s?(g.length=A,p=1,A--):(g.length=A+1,p=I[u-s],g[A]=c>0?a(h/I[n-c]%I[c])*p:0),o)for(;;){if(0==A){for(s=1,c=g[0];c>=10;c/=10,s++);for(c=g[0]+=p,p=1;c>=10;c/=10,p++);s!=p&&(e.e++,g[0]==d&&(g[0]=1));break}if(g[A]+=p,g[A]!=d)break;g[A--]=0,p=1}for(s=g.length;0===g[--s];g.pop());}e.e>T?e.c=e.e=null:e.e<Q&&(e.c=[e.e=0])}return e}function L(e){var t,r=e.e;return null===r?e.toString():(t=f(e.c),t=r<=v||r>=H?m(t,r):y(t,r,"0"),e.s<0?"-"+t:t)}return O.clone=e,O.ROUND_UP=0,O.ROUND_DOWN=1,O.ROUND_CEIL=2,O.ROUND_FLOOR=3,O.ROUND_HALF_UP=4,O.ROUND_HALF_DOWN=5,O.ROUND_HALF_EVEN=6,O.ROUND_HALF_CEIL=7,O.ROUND_HALF_FLOOR=8,O.EUCLID=9,O.config=O.set=function(e){var t,r;if(null!=e){if("object"!=typeof e)throw Error(n+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(I(r=e[t],0,h,t),D=r),e.hasOwnProperty(t="ROUNDING_MODE")&&(I(r=e[t],0,8,t),x=r),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((r=e[t])&&r.pop?(I(r[0],-h,0,t),I(r[1],0,h,t),v=r[0],H=r[1]):(I(r,-h,h,t),v=-(H=r<0?-r:r))),e.hasOwnProperty(t="RANGE"))if((r=e[t])&&r.pop)I(r[0],-h,-1,t),I(r[1],1,h,t),Q=r[0],T=r[1];else{if(I(r,-h,h,t),!r)throw Error(n+t+" cannot be zero: "+r);Q=-(T=r<0?-r:r)}if(e.hasOwnProperty(t="CRYPTO")){if((r=e[t])!==!!r)throw Error(n+t+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw K=!r,Error(n+"crypto unavailable");K=r}else K=r}if(e.hasOwnProperty(t="MODULO_MODE")&&(I(r=e[t],0,9,t),V=r),e.hasOwnProperty(t="POW_PRECISION")&&(I(r=e[t],0,h,t),R=r),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(r=e[t]))throw Error(n+t+" not an object: "+r);k=r}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(r=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(r))throw Error(n+t+" invalid: "+r);N="0123456789"==r.slice(0,10),U=r}}return{DECIMAL_PLACES:D,ROUNDING_MODE:x,EXPONENTIAL_AT:[v,H],RANGE:[Q,T],CRYPTO:K,MODULO_MODE:V,POW_PRECISION:R,FORMAT:k,ALPHABET:U}},O.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!O.DEBUG)return!0;var t,r,o=e.c,i=e.e,s=e.s;e:if("[object Array]"=={}.toString.call(o)){if((1===s||-1===s)&&i>=-h&&i<=h&&i===a(i)){if(0===o[0]){if(0===i&&1===o.length)return!0;break e}if((t=(i+1)%u)<1&&(t+=u),String(o[0]).length==t){for(t=0;t<o.length;t++)if((r=o[t])<0||r>=d||r!==a(r))break e;if(0!==r)return!0}}}else if(null===o&&null===i&&(null===s||1===s||-1===s))return!0;throw Error(n+"Invalid BigNumber: "+e)},O.maximum=O.max=function(){return F(arguments,-1)},O.minimum=O.min=function(){return F(arguments,1)},O.random=(B=9007199254740992,E=Math.random()*B&2097151?function(){return a(Math.random()*B)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,r,o,s,d,c=0,p=[],A=new O(P);if(null==e?e=D:I(e,0,h),s=i(e/u),K)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(s*=2));c<s;)(d=131072*t[c]+(t[c+1]>>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),t[c]=r[0],t[c+1]=r[1]):(p.push(d%1e14),c+=2);c=s/2}else{if(!crypto.randomBytes)throw K=!1,Error(n+"crypto unavailable");for(t=crypto.randomBytes(s*=7);c<s;)(d=281474976710656*(31&t[c])+1099511627776*t[c+1]+4294967296*t[c+2]+16777216*t[c+3]+(t[c+4]<<16)+(t[c+5]<<8)+t[c+6])>=9e15?crypto.randomBytes(7).copy(t,c):(p.push(d%1e14),c+=7);c=s/7}if(!K)for(;c<s;)(d=E())<9e15&&(p[c++]=d%1e14);for(s=p[--c],e%=u,s&&e&&(d=l[u-e],p[c]=a(s/d)*d);0===p[c];p.pop(),c--);if(c<0)p=[o=0];else{for(o=-1;0===p[0];p.splice(0,1),o-=u);for(c=1,d=p[0];d>=10;d/=10,c++);c<u&&(o-=u-c)}return A.e=o,A.c=p,A}),O.sum=function(){for(var e=1,t=arguments,r=new O(t[0]);e<t.length;)r=r.plus(t[e++]);return r},S=function(){var e="0123456789";function t(e,t,r,o){for(var i,a,n=[0],s=0,d=e.length;s<d;){for(a=n.length;a--;n[a]*=t);for(n[0]+=o.indexOf(e.charAt(s++)),i=0;i<n.length;i++)n[i]>r-1&&(null==n[i+1]&&(n[i+1]=0),n[i+1]+=n[i]/r|0,n[i]%=r)}return n.reverse()}return function(o,i,a,n,s){var d,u,c,l,p,h,A,g,I=o.indexOf("."),C=D,m=x;for(I>=0&&(l=R,R=0,o=o.replace(".",""),h=(g=new O(i)).pow(o.length-I),R=l,g.c=t(y(f(h.c),h.e,"0"),10,a,e),g.e=g.c.length),c=l=(A=t(o,i,a,s?(d=U,e):(d=e,U))).length;0==A[--l];A.pop());if(!A[0])return d.charAt(0);if(I<0?--c:(h.c=A,h.e=c,h.s=n,A=(h=r(h,g,C,m,a)).c,p=h.r,c=h.e),I=A[u=c+C+1],l=a/2,p=p||u<0||null!=A[u+1],p=m<4?(null!=I||p)&&(0==m||m==(h.s<0?3:2)):I>l||I==l&&(4==m||p||6==m&&1&A[u-1]||m==(h.s<0?8:7)),u<1||!A[0])o=p?y(d.charAt(1),-C,d.charAt(0)):d.charAt(0);else{if(A.length=u,p)for(--a;++A[--u]>a;)A[u]=0,u||(++c,A=[1].concat(A));for(l=A.length;!A[--l];);for(I=0,o="";I<=l;o+=d.charAt(A[I++]));o=y(o,c,d.charAt(0))}return o}}(),r=function(){function e(e,t,r){var o,i,a,n,s=0,d=e.length,u=t%p,c=t/p|0;for(e=e.slice();d--;)s=((i=u*(a=e[d]%p)+(o=c*a+(n=e[d]/p|0)*u)%p*p+s)/r|0)+(o/p|0)+c*n,e[d]=i%r;return s&&(e=[s].concat(e)),e}function t(e,t,r,o){var i,a;if(r!=o)a=r>o?1:-1;else for(i=a=0;i<r;i++)if(e[i]!=t[i]){a=e[i]>t[i]?1:-1;break}return a}function r(e,t,r,o){for(var i=0;r--;)e[r]-=i,i=e[r]<t[r]?1:0,e[r]=i*o+e[r]-t[r];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(o,i,n,s,c){var l,p,h,f,g,I,C,m,y,S,w,B,E,b,P,D,x,v=o.s==i.s?1:-1,H=o.c,Q=i.c;if(!(H&&H[0]&&Q&&Q[0]))return new O(o.s&&i.s&&(H?!Q||H[0]!=Q[0]:Q)?H&&0==H[0]||!Q?0*v:v/0:NaN);for(y=(m=new O(v)).c=[],v=n+(p=o.e-i.e)+1,c||(c=d,p=A(o.e/u)-A(i.e/u),v=v/u|0),h=0;Q[h]==(H[h]||0);h++);if(Q[h]>(H[h]||0)&&p--,v<0)y.push(1),f=!0;else{for(b=H.length,D=Q.length,h=0,v+=2,(g=a(c/(Q[0]+1)))>1&&(Q=e(Q,g,c),H=e(H,g,c),D=Q.length,b=H.length),E=D,w=(S=H.slice(0,D)).length;w<D;S[w++]=0);x=Q.slice(),x=[0].concat(x),P=Q[0],Q[1]>=c/2&&P++;do{if(g=0,(l=t(Q,S,D,w))<0){if(B=S[0],D!=w&&(B=B*c+(S[1]||0)),(g=a(B/P))>1)for(g>=c&&(g=c-1),C=(I=e(Q,g,c)).length,w=S.length;1==t(I,S,C,w);)g--,r(I,D<C?x:Q,C,c),C=I.length,l=1;else 0==g&&(l=g=1),C=(I=Q.slice()).length;if(C<w&&(I=[0].concat(I)),r(S,I,w,c),w=S.length,-1==l)for(;t(Q,S,D,w)<1;)g++,r(S,D<w?x:Q,w,c),w=S.length}else 0===l&&(g++,S=[0]);y[h++]=g,S[0]?S[w++]=H[E]||0:(S=[H[E]],w=1)}while((E++<b||null!=S[0])&&v--);f=null!=S[0],y[0]||y.splice(0,1)}if(c==d){for(h=1,v=y[0];v>=10;v/=10,h++);_(m,n+(m.e=h+p*u-1)+1,s,f)}else m.e=p,m.r=+f;return m}}(),w=function(){var e=/^(-?)0([xbo])(?=\w[\w.]*$)/i,t=/^([^.]+)\.$/,r=/^\.([^.]+)$/,o=/^-?(Infinity|NaN)$/,i=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(a,s,d,u){var c,l=d?s:s.replace(i,"");if(o.test(l))a.s=isNaN(l)?null:l<0?-1:1;else{if(!d&&(l=l.replace(e,(function(e,t,r){return c="x"==(r=r.toLowerCase())?16:"b"==r?2:8,u&&u!=c?e:t})),u&&(c=u,l=l.replace(t,"$1").replace(r,"0.$1")),s!=l))return new O(l,c);if(O.DEBUG)throw Error(n+"Not a"+(u?" base "+u:"")+" number: "+s);a.s=null}a.c=a.e=null}}(),b.absoluteValue=b.abs=function(){var e=new O(this);return e.s<0&&(e.s=1),e},b.comparedTo=function(e,t){return g(this,new O(e,t))},b.decimalPlaces=b.dp=function(e,t){var r,o,i,a=this;if(null!=e)return I(e,0,h),null==t?t=x:I(t,0,8),_(new O(a),e+a.e+1,t);if(!(r=a.c))return null;if(o=((i=r.length-1)-A(this.e/u))*u,i=r[i])for(;i%10==0;i/=10,o--);return o<0&&(o=0),o},b.dividedBy=b.div=function(e,t){return r(this,new O(e,t),D,x)},b.dividedToIntegerBy=b.idiv=function(e,t){return r(this,new O(e,t),0,1)},b.exponentiatedBy=b.pow=function(e,t){var r,o,s,d,c,l,p,h,A=this;if((e=new O(e)).c&&!e.isInteger())throw Error(n+"Exponent not an integer: "+L(e));if(null!=t&&(t=new O(t)),c=e.e>14,!A.c||!A.c[0]||1==A.c[0]&&!A.e&&1==A.c.length||!e.c||!e.c[0])return h=new O(Math.pow(+L(A),c?e.s*(2-C(e)):+L(e))),t?h.mod(t):h;if(l=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new O(NaN);(o=!l&&A.isInteger()&&t.isInteger())&&(A=A.mod(t))}else{if(e.e>9&&(A.e>0||A.e<-1||(0==A.e?A.c[0]>1||c&&A.c[1]>=24e7:A.c[0]<8e13||c&&A.c[0]<=9999975e7)))return d=A.s<0&&C(e)?-0:0,A.e>-1&&(d=1/d),new O(l?1/d:d);R&&(d=i(R/u+2))}for(c?(r=new O(.5),l&&(e.s=1),p=C(e)):p=(s=Math.abs(+L(e)))%2,h=new O(P);;){if(p){if(!(h=h.times(A)).c)break;d?h.c.length>d&&(h.c.length=d):o&&(h=h.mod(t))}if(s){if(0===(s=a(s/2)))break;p=s%2}else if(_(e=e.times(r),e.e+1,1),e.e>14)p=C(e);else{if(0===(s=+L(e)))break;p=s%2}A=A.times(A),d?A.c&&A.c.length>d&&(A.c.length=d):o&&(A=A.mod(t))}return o?h:(l&&(h=P.div(h)),t?h.mod(t):d?_(h,R,x,undefined):h)},b.integerValue=function(e){var t=new O(this);return null==e?e=x:I(e,0,8),_(t,t.e+1,e)},b.isEqualTo=b.eq=function(e,t){return 0===g(this,new O(e,t))},b.isFinite=function(){return!!this.c},b.isGreaterThan=b.gt=function(e,t){return g(this,new O(e,t))>0},b.isGreaterThanOrEqualTo=b.gte=function(e,t){return 1===(t=g(this,new O(e,t)))||0===t},b.isInteger=function(){return!!this.c&&A(this.e/u)>this.c.length-2},b.isLessThan=b.lt=function(e,t){return g(this,new O(e,t))<0},b.isLessThanOrEqualTo=b.lte=function(e,t){return-1===(t=g(this,new O(e,t)))||0===t},b.isNaN=function(){return!this.s},b.isNegative=function(){return this.s<0},b.isPositive=function(){return this.s>0},b.isZero=function(){return!!this.c&&0==this.c[0]},b.minus=function(e,t){var r,o,i,a,n=this,s=n.s;if(t=(e=new O(e,t)).s,!s||!t)return new O(NaN);if(s!=t)return e.s=-t,n.plus(e);var c=n.e/u,l=e.e/u,p=n.c,h=e.c;if(!c||!l){if(!p||!h)return p?(e.s=-t,e):new O(h?n:NaN);if(!p[0]||!h[0])return h[0]?(e.s=-t,e):new O(p[0]?n:3==x?-0:0)}if(c=A(c),l=A(l),p=p.slice(),s=c-l){for((a=s<0)?(s=-s,i=p):(l=c,i=h),i.reverse(),t=s;t--;i.push(0));i.reverse()}else for(o=(a=(s=p.length)<(t=h.length))?s:t,s=t=0;t<o;t++)if(p[t]!=h[t]){a=p[t]<h[t];break}if(a&&(i=p,p=h,h=i,e.s=-e.s),(t=(o=h.length)-(r=p.length))>0)for(;t--;p[r++]=0);for(t=d-1;o>s;){if(p[--o]<h[o]){for(r=o;r&&!p[--r];p[r]=t);--p[r],p[o]+=d}p[o]-=h[o]}for(;0==p[0];p.splice(0,1),--l);return p[0]?M(e,p,l):(e.s=3==x?-1:1,e.c=[e.e=0],e)},b.modulo=b.mod=function(e,t){var o,i,a=this;return e=new O(e,t),!a.c||!e.s||e.c&&!e.c[0]?new O(NaN):!e.c||a.c&&!a.c[0]?new O(a):(9==V?(i=e.s,e.s=1,o=r(a,e,0,3),e.s=i,o.s*=i):o=r(a,e,0,V),(e=a.minus(o.times(e))).c[0]||1!=V||(e.s=a.s),e)},b.multipliedBy=b.times=function(e,t){var r,o,i,a,n,s,c,l,h,f,g,I,C,m,y,S=this,w=S.c,B=(e=new O(e,t)).c;if(!(w&&B&&w[0]&&B[0]))return!S.s||!e.s||w&&!w[0]&&!B||B&&!B[0]&&!w?e.c=e.e=e.s=null:(e.s*=S.s,w&&B?(e.c=[0],e.e=0):e.c=e.e=null),e;for(o=A(S.e/u)+A(e.e/u),e.s*=S.s,(c=w.length)<(f=B.length)&&(C=w,w=B,B=C,i=c,c=f,f=i),i=c+f,C=[];i--;C.push(0));for(m=d,y=p,i=f;--i>=0;){for(r=0,g=B[i]%y,I=B[i]/y|0,a=i+(n=c);a>i;)r=((l=g*(l=w[--n]%y)+(s=I*l+(h=w[n]/y|0)*g)%y*y+C[a]+r)/m|0)+(s/y|0)+I*h,C[a--]=l%m;C[a]=r}return r?++o:C.splice(0,1),M(e,C,o)},b.negated=function(){var e=new O(this);return e.s=-e.s||null,e},b.plus=function(e,t){var r,o=this,i=o.s;if(t=(e=new O(e,t)).s,!i||!t)return new O(NaN);if(i!=t)return e.s=-t,o.minus(e);var a=o.e/u,n=e.e/u,s=o.c,c=e.c;if(!a||!n){if(!s||!c)return new O(i/0);if(!s[0]||!c[0])return c[0]?e:new O(s[0]?o:0*i)}if(a=A(a),n=A(n),s=s.slice(),i=a-n){for(i>0?(n=a,r=c):(i=-i,r=s),r.reverse();i--;r.push(0));r.reverse()}for((i=s.length)-(t=c.length)<0&&(r=c,c=s,s=r,t=i),i=0;t;)i=(s[--t]=s[t]+c[t]+i)/d|0,s[t]=d===s[t]?0:s[t]%d;return i&&(s=[i].concat(s),++n),M(e,s,n)},b.precision=b.sd=function(e,t){var r,o,i,a=this;if(null!=e&&e!==!!e)return I(e,1,h),null==t?t=x:I(t,0,8),_(new O(a),e,t);if(!(r=a.c))return null;if(o=(i=r.length-1)*u+1,i=r[i]){for(;i%10==0;i/=10,o--);for(i=r[0];i>=10;i/=10,o++);}return e&&a.e+1>o&&(o=a.e+1),o},b.shiftedBy=function(e){return I(e,-9007199254740991,c),this.times("1e"+e)},b.squareRoot=b.sqrt=function(){var e,t,o,i,a,n=this,s=n.c,d=n.s,u=n.e,c=D+4,l=new O("0.5");if(1!==d||!s||!s[0])return new O(!d||d<0&&(!s||s[0])?NaN:s?n:1/0);if(0==(d=Math.sqrt(+L(n)))||d==1/0?(((t=f(s)).length+u)%2==0&&(t+="0"),d=Math.sqrt(+t),u=A((u+1)/2)-(u<0||u%2),o=new O(t=d==1/0?"5e"+u:(t=d.toExponential()).slice(0,t.indexOf("e")+1)+u)):o=new O(d+""),o.c[0])for((d=(u=o.e)+c)<3&&(d=0);;)if(a=o,o=l.times(a.plus(r(n,a,c,1))),f(a.c).slice(0,d)===(t=f(o.c)).slice(0,d)){if(o.e<u&&--d,"9999"!=(t=t.slice(d-3,d+1))&&(i||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(_(o,o.e+D+2,1),e=!o.times(o).eq(n));break}if(!i&&(_(a,a.e+D+2,0),a.times(a).eq(n))){o=a;break}c+=4,d+=4,i=1}return _(o,o.e+D+1,x,e)},b.toExponential=function(e,t){return null!=e&&(I(e,0,h),e++),z(this,e,t,1)},b.toFixed=function(e,t){return null!=e&&(I(e,0,h),e=e+this.e+1),z(this,e,t)},b.toFormat=function(e,t,r){var o,i=this;if(null==r)null!=e&&t&&"object"==typeof t?(r=t,t=null):e&&"object"==typeof e?(r=e,e=t=null):r=k;else if("object"!=typeof r)throw Error(n+"Argument not an object: "+r);if(o=i.toFixed(e,t),i.c){var a,s=o.split("."),d=+r.groupSize,u=+r.secondaryGroupSize,c=r.groupSeparator||"",l=s[0],p=s[1],h=i.s<0,A=h?l.slice(1):l,f=A.length;if(u&&(a=d,d=u,u=a,f-=a),d>0&&f>0){for(a=f%d||d,l=A.substr(0,a);a<f;a+=d)l+=c+A.substr(a,d);u>0&&(l+=c+A.slice(a)),h&&(l="-"+l)}o=p?l+(r.decimalSeparator||"")+((u=+r.fractionGroupSize)?p.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+(r.fractionGroupSeparator||"")):p):l}return(r.prefix||"")+o+(r.suffix||"")},b.toFraction=function(e){var t,o,i,a,s,d,c,p,h,A,g,I,C=this,m=C.c;if(null!=e&&(!(c=new O(e)).isInteger()&&(c.c||1!==c.s)||c.lt(P)))throw Error(n+"Argument "+(c.isInteger()?"out of range: ":"not an integer: ")+L(c));if(!m)return new O(C);for(t=new O(P),h=o=new O(P),i=p=new O(P),I=f(m),s=t.e=I.length-C.e-1,t.c[0]=l[(d=s%u)<0?u+d:d],e=!e||c.comparedTo(t)>0?s>0?t:h:c,d=T,T=1/0,c=new O(I),p.c[0]=0;A=r(c,t,0,1),1!=(a=o.plus(A.times(i))).comparedTo(e);)o=i,i=a,h=p.plus(A.times(a=h)),p=a,t=c.minus(A.times(a=t)),c=a;return a=r(e.minus(o),i,0,1),p=p.plus(a.times(h)),o=o.plus(a.times(i)),p.s=h.s=C.s,g=r(h,i,s*=2,x).minus(C).abs().comparedTo(r(p,o,s,x).minus(C).abs())<1?[h,i]:[p,o],T=d,g},b.toNumber=function(){return+L(this)},b.toPrecision=function(e,t){return null!=e&&I(e,1,h),z(this,e,t,2)},b.toString=function(e){var t,r=this,o=r.s,i=r.e;return null===i?o?(t="Infinity",o<0&&(t="-"+t)):t="NaN":(null==e?t=i<=v||i>=H?m(f(r.c),i):y(f(r.c),i,"0"):10===e&&N?t=y(f((r=_(new O(r),D+i+1,x)).c),r.e,"0"):(I(e,2,U.length,"Base"),t=S(y(f(r.c),i,"0"),10,e,o,!0)),o<0&&r.c[0]&&(t="-"+t)),t},b.valueOf=b.toJSON=function(){return L(this)},b._isBigNumber=!0,null!=t&&O.set(t),O}(),r.default=r.BigNumber=r,"function"==typeof define&&define.amd?define((function(){return r})):void 0!==t&&t.exports?t.exports=r:(e||(e="undefined"!=typeof self&&self?self:window),e.BigNumber=r)}(e)}}),require_stringify=__commonJS({"../../node_modules/json-bigint/lib/stringify.js"(e,t){"use strict";var r=require_bignumber(),o=t.exports;!function(){var e,t,i,a=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,n={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function s(e){return a.lastIndex=0,a.test(e)?'"'+e.replace(a,(function(e){var t=n[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}))+'"':'"'+e+'"'}function d(o,a){var n,u,c,l,p,h=e,A=a[o],f=null!=A&&(A instanceof r||r.isBigNumber(A));switch(A&&"object"==typeof A&&"function"==typeof A.toJSON&&(A=A.toJSON(o)),"function"==typeof i&&(A=i.call(a,o,A)),typeof A){case"string":return f?A:s(A);case"number":return isFinite(A)?String(A):"null";case"boolean":case"null":case"bigint":return String(A);case"object":if(!A)return"null";if(e+=t,p=[],"[object Array]"===Object.prototype.toString.apply(A)){for(l=A.length,n=0;n<l;n+=1)p[n]=d(n,A)||"null";return c=0===p.length?"[]":e?"[\n"+e+p.join(",\n"+e)+"\n"+h+"]":"["+p.join(",")+"]",e=h,c}if(i&&"object"==typeof i)for(l=i.length,n=0;n<l;n+=1)"string"==typeof i[n]&&(c=d(u=i[n],A))&&p.push(s(u)+(e?": ":":")+c);else Object.keys(A).forEach((function(t){var r=d(t,A);r&&p.push(s(t)+(e?": ":":")+r)}));return c=0===p.length?"{}":e?"{\n"+e+p.join(",\n"+e)+"\n"+h+"}":"{"+p.join(",")+"}",e=h,c}}"function"!=typeof o.stringify&&(o.stringify=function(r,o,a){var n;if(e="",t="","number"==typeof a)for(n=0;n<a;n+=1)t+=" ";else"string"==typeof a&&(t=a);if(i=o,o&&"function"!=typeof o&&("object"!=typeof o||"number"!=typeof o.length))throw new Error("JSON.stringify");return d("",{"":r})})}()}}),require_parse=__commonJS({"../../node_modules/json-bigint/lib/parse.js"(e,t){"use strict";var r=null,o=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,i=/(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/;t.exports=function(e){var t={strict:!1,storeAsString:!1,alwaysParseAsBig:!1,useNativeBigInt:!1,protoAction:"error",constructorAction:"error"};if(null!=e){if(!0===e.strict&&(t.strict=!0),!0===e.storeAsString&&(t.storeAsString=!0),t.alwaysParseAsBig=!0===e.alwaysParseAsBig&&e.alwaysParseAsBig,t.useNativeBigInt=!0===e.useNativeBigInt&&e.useNativeBigInt,void 0!==e.constructorAction){if("error"!==e.constructorAction&&"ignore"!==e.constructorAction&&"preserve"!==e.constructorAction)throw new Error(`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${e.constructorAction}`);t.constructorAction=e.constructorAction}if(void 0!==e.protoAction){if("error"!==e.protoAction&&"ignore"!==e.protoAction&&"preserve"!==e.protoAction)throw new Error(`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${e.protoAction}`);t.protoAction=e.protoAction}}var a,n,s,d,u={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},c=function(e){throw{name:"SyntaxError",message:e,at:a,text:s}},l=function(e){return e&&e!==n&&c("Expected '"+e+"' instead of '"+n+"'"),n=s.charAt(a),a+=1,n},p=function(){var e,o="";for("-"===n&&(o="-",l("-"));n>="0"&&n<="9";)o+=n,l();if("."===n)for(o+=".";l()&&n>="0"&&n<="9";)o+=n;if("e"===n||"E"===n)for(o+=n,l(),"-"!==n&&"+"!==n||(o+=n,l());n>="0"&&n<="9";)o+=n,l();if(e=+o,isFinite(e))return null==r&&(r=require_bignumber()),o.length>15?t.storeAsString?o:t.useNativeBigInt?BigInt(o):new r(o):t.alwaysParseAsBig?t.useNativeBigInt?BigInt(e):new r(e):e;c("Bad number")},h=function(){var e,t,r,o="";if('"'===n)for(var i=a;l();){if('"'===n)return a-1>i&&(o+=s.substring(i,a-1)),l(),o;if("\\"===n){if(a-1>i&&(o+=s.substring(i,a-1)),l(),"u"===n){for(r=0,t=0;t<4&&(e=parseInt(l(),16),isFinite(e));t+=1)r=16*r+e;o+=String.fromCharCode(r)}else{if("string"!=typeof u[n])break;o+=u[n]}i=a}}c("Bad string")},A=function(){for(;n&&n<=" ";)l()};return d=function(){switch(A(),n){case"{":return function(){var e,r=Object.create(null);if("{"===n){if(l("{"),A(),"}"===n)return l("}"),r;for(;n;){if(e=h(),A(),l(":"),!0===t.strict&&Object.hasOwnProperty.call(r,e)&&c('Duplicate key "'+e+'"'),!0===o.test(e)?"error"===t.protoAction?c("Object contains forbidden prototype property"):"ignore"===t.protoAction?d():r[e]=d():!0===i.test(e)?"error"===t.constructorAction?c("Object contains forbidden constructor property"):"ignore"===t.constructorAction?d():r[e]=d():r[e]=d(),A(),"}"===n)return l("}"),r;l(","),A()}}c("Bad object")}();case"[":return function(){var e=[];if("["===n){if(l("["),A(),"]"===n)return l("]"),e;for(;n;){if(e.push(d()),A(),"]"===n)return l("]"),e;l(","),A()}}c("Bad array")}();case'"':return h();case"-":return p();default:return n>="0"&&n<="9"?p():function(){switch(n){case"t":return l("t"),l("r"),l("u"),l("e"),!0;case"f":return l("f"),l("a"),l("l"),l("s"),l("e"),!1;case"n":return l("n"),l("u"),l("l"),l("l"),null}c("Unexpected '"+n+"'")}()}},function(e,t){var r;return s=e+"",a=0,n=" ",r=d(),A(),n&&c("Syntax error"),"function"==typeof t?function e(r,o){var i,a=r[o];return a&&"object"==typeof a&&Object.keys(a).forEach((function(t){void 0!==(i=e(a,t))?a[t]=i:delete a[t]})),t.call(r,o,a)}({"":r},""):r}}}}),require_json_bigint=__commonJS({"../../node_modules/json-bigint/index.js"(e,t){"use strict";var r=require_stringify().stringify,o=require_parse();t.exports=function(e){return{parse:o(e),stringify:r}},t.exports.parse=o(),t.exports.stringify=r}}),require_nanoassert=__commonJS({"../../node_modules/nanoassert/index.js"(e,t){"use strict";t.exports=function e(t,o){if(!t){var i=new r(o);throw Error.captureStackTrace&&Error.captureStackTrace(i,e),i}};var r=class extends Error{};r.prototype.name="AssertionError"}}),require_b4a=__commonJS({"../../node_modules/b4a/index.js"(e,t){"use strict";function r(e){return Buffer.isBuffer(e)?e:Buffer.from(e.buffer,e.byteOffset,e.byteLength)}t.exports={isBuffer:function(e){return Buffer.isBuffer(e)||e instanceof Uint8Array},isEncoding:function(e){return Buffer.isEncoding(e)},alloc:function(e,t,r){return Buffer.alloc(e,t,r)},allocUnsafe:function(e){return Buffer.allocUnsafe(e)},allocUnsafeSlow:function(e){return Buffer.allocUnsafeSlow(e)},byteLength:function(e,t){return Buffer.byteLength(e,t)},compare:function(e,t){return Buffer.compare(e,t)},concat:function(e,t){return Buffer.concat(e,t)},copy:function(e,t,o,i,a){return r(e).copy(t,o,i,a)},equals:function(e,t){return r(e).equals(t)},fill:function(e,t,o,i,a){return r(e).fill(t,o,i,a)},from:function(e,t,r){return Buffer.from(e,t,r)},includes:function(e,t,o,i){return r(e).includes(t,o,i)},indexOf:function(e,t,o,i){return r(e).indexOf(t,o,i)},lastIndexOf:function(e,t,o,i){return r(e).lastIndexOf(t,o,i)},swap16:function(e){return r(e).swap16()},swap32:function(e){return r(e).swap32()},swap64:function(e){return r(e).swap64()},toBuffer:r,toString:function(e,t,o,i){return r(e).toString(t,o,i)},write:function(e,t,o,i,a){return r(e).write(t,o,i,a)},readDoubleBE:function(e,t){return r(e).readDoubleBE(t)},readDoubleLE:function(e,t){return r(e).readDoubleLE(t)},readFloatBE:function(e,t){return r(e).readFloatBE(t)},readFloatLE:function(e,t){return r(e).readFloatLE(t)},readInt32BE:function(e,t){return r(e).readInt32BE(t)},readInt32LE:function(e,t){return r(e).readInt32LE(t)},readUInt32BE:function(e,t){return r(e).readUInt32BE(t)},readUInt32LE:function(e,t){return r(e).readUInt32LE(t)},writeDoubleBE:function(e,t,o){return r(e).writeDoubleBE(t,o)},writeDoubleLE:function(e,t,o){return r(e).writeDoubleLE(t,o)},writeFloatBE:function(e,t,o){return r(e).writeFloatBE(t,o)},writeFloatLE:function(e,t,o){return r(e).writeFloatLE(t,o)},writeInt32BE:function(e,t,o){return r(e).writeInt32BE(t,o)},writeInt32LE:function(e,t,o){return r(e).writeInt32LE(t,o)},writeUInt32BE:function(e,t,o){return r(e).writeUInt32BE(t,o)},writeUInt32LE:function(e,t,o){return r(e).writeUInt32LE(t,o)}}}}),require_blake2b=__commonJS({"../../node_modules/blake2b-wasm/blake2b.js"(e,t){"use strict";var r,o,i=(()=>{for(var e=new Uint8Array(128),t=0;t<64;t++)e[t<26?t+65:t<52?t+71:t<62?t-4:4*t-205]=t;return t=>{for(var r=t.length,o=new Uint8Array(3*(r-("="==t[r-1])-("="==t[r-2]))/4|0),i=0,a=0;i<r;){var n=e[t.charCodeAt(i++)],s=e[t.charCodeAt(i++)],d=e[t.charCodeAt(i++)],u=e[t.charCodeAt(i++)];o[a++]=n<<2|s>>4,o[a++]=s<<4|d>>2,o[a++]=d<<6|u}return o}})(),a=(r={"wasm-binary:./blake2b.wat"(e,t){t.exports=i("AGFz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AmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=")}},function(){return o||(0,r[Object.keys(r)[0]])((o={exports:{}}).exports,o),o.exports})(),n=WebAssembly.compile(a);t.exports=async e=>(await WebAssembly.instantiate(await n,e)).exports}}),require_blake2b_wasm=__commonJS({"../../node_modules/blake2b-wasm/index.js"(e,t){"use strict";var r=require_nanoassert(),o=require_b4a(),i=null,a="undefined"!=typeof WebAssembly&&require_blake2b()().then((e=>{i=e})),n=64,s=[];t.exports=A;var d=t.exports.BYTES_MIN=16,u=t.exports.BYTES_MAX=64,c=(t.exports.BYTES=32,t.exports.KEYBYTES_MIN=16),l=t.exports.KEYBYTES_MAX=64,p=(t.exports.KEYBYTES=32,t.exports.SALTBYTES=16),h=t.exports.PERSONALBYTES=16;function A(e,t,o,a,f){if(!(this instanceof A))return new A(e,t,o,a,f);if(!i)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");e||(e=32),!0!==f&&(r(e>=d,"digestLength must be at least "+d+", was given "+e),r(e<=u,"digestLength must be at most "+u+", was given "+e),null!=t&&(r(t instanceof Uint8Array,"key must be Uint8Array or Buffer"),r(t.length>=c,"key must be at least "+c+", was given "+t.length),r(t.length<=l,"key must be at least "+l+", was given "+t.length)),null!=o&&(r(o instanceof Uint8Array,"salt must be Uint8Array or Buffer"),r(o.length===p,"salt must be exactly "+p+", was given "+o.length)),null!=a&&(r(a instanceof Uint8Array,"personal must be Uint8Array or Buffer"),r(a.length===h,"personal must be exactly "+h+", was given "+a.length))),s.length||(s.push(n),n+=216),this.digestLength=e,this.finalized=!1,this.pointer=s.pop(),this._memory=new Uint8Array(i.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=t?t.length:0,this._memory[2]=1,this._memory[3]=1,o&&this._memory.set(o,32),a&&this._memory.set(a,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),i.blake2b_init(this.pointer,this.digestLength),t&&(this.update(t),this._memory.fill(0,n,n+t.length),this._memory[this.pointer+200]=128)}function f(){}A.prototype._realloc=function(e){i.memory.grow(Math.max(0,Math.ceil(Math.abs(e-this._memory.length)/65536))),this._memory=new Uint8Array(i.memory.buffer)},A.prototype.update=function(e){return r(!1===this.finalized,"Hash instance finalized"),r(e instanceof Uint8Array,"input must be Uint8Array or Buffer"),n+e.length>this._memory.length&&this._realloc(n+e.length),this._memory.set(e,n),i.blake2b_update(this.pointer,n,n+e.length),this},A.prototype.digest=function(e){if(r(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,s.push(this.pointer),i.blake2b_final(this.pointer),!e||"binary"===e)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof e)return o.toString(this._memory,e,this.pointer+128,this.pointer+128+this.digestLength);r(e instanceof Uint8Array&&e.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var t=0;t<this.digestLength;t++)e[t]=this._memory[this.pointer+128+t];return e},A.prototype.final=A.prototype.digest,A.WASM=i,A.SUPPORTED="undefined"!=typeof WebAssembly,A.ready=function(e){return e||(e=f),a?a.then((()=>e()),e):e(new Error("WebAssembly not supported"))},A.prototype.ready=A.ready,A.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},A.prototype.setPartialHash=function(e){this._memory.set(e,this.pointer)}}}),require_blake2b2=__commonJS({"../../node_modules/blake2b/index.js"(e,t){"use strict";var r=require_nanoassert(),o=require_blake2b_wasm();function i(e,t,r){var o=e[t]+e[r],i=e[t+1]+e[r+1];o>=4294967296&&i++,e[t]=o,e[t+1]=i}function a(e,t,r,o){var i=e[t]+r;r<0&&(i+=4294967296);var a=e[t+1]+o;i>=4294967296&&a++,e[t]=i,e[t+1]=a}function n(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function s(e,t,r,o,n,s){var d=l[n],u=l[n+1],p=l[s],h=l[s+1];i(c,e,t),a(c,e,d,u);var A=c[o]^c[e],f=c[o+1]^c[e+1];c[o]=f,c[o+1]=A,i(c,r,o),A=c[t]^c[r],f=c[t+1]^c[r+1],c[t]=A>>>24^f<<8,c[t+1]=f>>>24^A<<8,i(c,e,t),a(c,e,p,h),A=c[o]^c[e],f=c[o+1]^c[e+1],c[o]=A>>>16^f<<16,c[o+1]=f>>>16^A<<16,i(c,r,o),A=c[t]^c[r],f=c[t+1]^c[r+1],c[t]=f>>>31^A<<1,c[t+1]=A>>>31^f<<1}var d=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),u=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map((function(e){return 2*e}))),c=new Uint32Array(32),l=new Uint32Array(32);function p(e,t){var r=0;for(r=0;r<16;r++)c[r]=e.h[r],c[r+16]=d[r];for(c[24]=c[24]^e.t,c[25]=c[25]^e.t/4294967296,t&&(c[28]=~c[28],c[29]=~c[29]),r=0;r<32;r++)l[r]=n(e.b,4*r);for(r=0;r<12;r++)s(0,8,16,24,u[16*r+0],u[16*r+1]),s(2,10,18,26,u[16*r+2],u[16*r+3]),s(4,12,20,28,u[16*r+4],u[16*r+5]),s(6,14,22,30,u[16*r+6],u[16*r+7]),s(0,10,20,30,u[16*r+8],u[16*r+9]),s(2,12,22,24,u[16*r+10],u[16*r+11]),s(4,14,16,26,u[16*r+12],u[16*r+13]),s(6,8,18,28,u[16*r+14],u[16*r+15]);for(r=0;r<16;r++)e.h[r]=e.h[r]^c[r]^c[r+16]}var h=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function A(e,t,r,o){h.fill(0),this.b=new Uint8Array(128),this.h=new Uint32Array(16),this.t=0,this.c=0,this.outlen=e,h[0]=e,t&&(h[1]=t.length),h[2]=1,h[3]=1,r&&h.set(r,32),o&&h.set(o,48);for(var i=0;i<16;i++)this.h[i]=d[i]^n(h,4*i);t&&(f(this,t),this.c=128)}function f(e,t){for(var r=0;r<t.length;r++)128===e.c&&(e.t+=e.c,p(e,!1),e.c=0),e.b[e.c++]=t[r]}function g(e){return e<16?"0"+e.toString(16):e.toString(16)}A.prototype.update=function(e){return r(e instanceof Uint8Array,"input must be Uint8Array or Buffer"),f(this,e),this},A.prototype.digest=function(e){var t=e&&"binary"!==e&&"hex"!==e?e:new Uint8Array(this.outlen);return r(t instanceof Uint8Array,'out must be "binary", "hex", Uint8Array, or Buffer'),r(t.length>=this.outlen,"out must have at least outlen bytes of space"),function(e,t){e.t+=e.c;for(;e.c<128;)e.b[e.c++]=0;p(e,!0);for(var r=0;r<e.outlen;r++)t[r]=e.h[r>>2]>>8*(3&r)}(this,t),"hex"===e?function(e){for(var t="",r=0;r<e.length;r++)t+=g(e[r]);return t}(t):t},A.prototype.final=A.prototype.digest,A.ready=function(e){o.ready((function(){e()}))};var I=A;t.exports=function(e,t,o,i,a){return!0!==a&&(r(e>=C,"outlen must be at least "+C+", was given "+e),r(e<=m,"outlen must be at most "+m+", was given "+e),null!=t&&(r(t instanceof Uint8Array,"key must be Uint8Array or Buffer"),r(t.length>=y,"key must be at least "+y+", was given "+t.length),r(t.length<=S,"key must be at most "+S+", was given "+t.length)),null!=o&&(r(o instanceof Uint8Array,"salt must be Uint8Array or Buffer"),r(o.length===w,"salt must be exactly "+w+", was given "+o.length)),null!=i&&(r(i instanceof Uint8Array,"personal must be Uint8Array or Buffer"),r(i.length===B,"personal must be exactly "+B+", was given "+i.length))),new I(e,t,o,i)},t.exports.ready=function(e){o.ready((function(){e()}))},t.exports.WASM_SUPPORTED=o.SUPPORTED,t.exports.WASM_LOADED=!1;var C=t.exports.BYTES_MIN=16,m=t.exports.BYTES_MAX=64,y=(t.exports.BYTES=32,t.exports.KEYBYTES_MIN=16),S=t.exports.KEYBYTES_MAX=64,w=(t.exports.KEYBYTES=32,t.exports.SALTBYTES=16),B=t.exports.PERSONALBYTES=16;o.ready((function(e){e||(t.exports.WASM_LOADED=!0,t.exports=o)}))}});import{Cardano as Cardano7,Serialization as Serialization9}from"@cardano-sdk/core";import{Cardano,Serialization}from"@cardano-sdk/core";import*as Crypto from"@cardano-sdk/crypto";import{HexBlob as CardanoHexBlob,typedHex}from"@cardano-sdk/util";var Slot=Cardano.Slot,Value=Serialization.Value,Transaction=Serialization.Transaction,TransactionId=e=>Cardano.TransactionId(e),TransactionBody=Serialization.TransactionBody,TransactionWitnessSet=Serialization.TransactionWitnessSet,AuxilliaryData=Serialization.AuxiliaryData,TransactionMetadatum=Serialization.TransactionMetadatum,MetadatumMap=Serialization.MetadatumMap,MetadatumList=Serialization.MetadatumList,TransactionUnspentOutput=Serialization.TransactionUnspentOutput,TransactionInput=Serialization.TransactionInput,TransactionOutput=Serialization.TransactionOutput,PlutusData=Serialization.PlutusData,PlutusList=Serialization.PlutusList,PlutusMap=Serialization.PlutusMap,Redeemers=Serialization.Redeemers,Redeemer=Serialization.Redeemer,RedeemerPurpose=Cardano.RedeemerPurpose,RedeemerTag=Serialization.RedeemerTag,Script=Serialization.Script,PolicyId=Cardano.PolicyId,AssetName=Cardano.AssetName,AssetId=Cardano.AssetId,ScriptHash=Crypto.Hash28ByteBase16,Address=Cardano.Address,RewardAddress=Cardano.RewardAddress,AddressType=Cardano.AddressType,BaseAddress=Cardano.BaseAddress,EnterpriseAddress=Cardano.EnterpriseAddress,PaymentAddress=Cardano.PaymentAddress,AssetFingerprint=Cardano.AssetFingerprint,Credential=Serialization.Credential,Ed25519PublicKeyHex2=Crypto.Ed25519PublicKeyHex,Ed25519PrivateNormalKeyHex=e=>typedHex(e,64),Ed25519PrivateExtendedKeyHex=e=>typedHex(e,128),Ed25519KeyHash2=Crypto.Ed25519KeyHash,Ed25519KeyHashHex2=Crypto.Ed25519KeyHashHex,Hash28ByteBase162=Crypto.Hash28ByteBase16,Hash32ByteBase162=e=>Crypto.Hash32ByteBase16(e),CredentialType=Cardano.CredentialType,Certificate=Serialization.Certificate,PoolId=Cardano.PoolId,StakeRegistration=Serialization.StakeRegistration,StakeDelegation=Serialization.StakeDelegation,CertificateType=Cardano.CertificateType,VkeyWitness=Serialization.VkeyWitness,Ed25519SignatureHex2=Crypto.Ed25519SignatureHex,Ed25519PublicKey2=Crypto.Ed25519PublicKey,Ed25519Signature2=Crypto.Ed25519Signature,Bip32PrivateKey2=Crypto.Bip32PrivateKey,Bip32PrivateKeyHex2=Crypto.Bip32PrivateKeyHex,Bip32PublicKey2=Crypto.Bip32PublicKey,Bip32PublicKeyHex2=Crypto.Bip32PublicKeyHex,PlutusLanguageVersion=Cardano.PlutusLanguageVersion,NativeScript=Serialization.NativeScript,PlutusV1Script=Serialization.PlutusV1Script,PlutusV2Script=Serialization.PlutusV2Script,PlutusV3Script=Serialization.PlutusV3Script,PlutusDataKind=Serialization.PlutusDataKind,PointerAddress=Cardano.PointerAddress,CertIndex=Cardano.CertIndex,TxIndex=Cardano.TxIndex,Costmdls=Serialization.Costmdls,CostModel=Serialization.CostModel,CborWriter=Serialization.CborWriter,ConstrPlutusData=Serialization.ConstrPlutusData,RewardAccount=Cardano.RewardAccount,Hash=Serialization.Hash,DatumHash=e=>Crypto.Hash32ByteBase16(e),Datum=Serialization.Datum,ExUnits=Serialization.ExUnits,NetworkId=Cardano.NetworkId,DatumKind=Serialization.DatumKind,CborSet=Serialization.CborSet,RequireAllOf=Cardano.NativeScriptKind.RequireAllOf,RequireAnyOf=Cardano.NativeScriptKind.RequireAnyOf,RequireNOf=Cardano.NativeScriptKind.RequireNOf,RequireSignature=Cardano.NativeScriptKind.RequireSignature,RequireTimeAfter=Cardano.NativeScriptKind.RequireTimeAfter,RequireTimeBefore=Cardano.NativeScriptKind.RequireTimeBefore,VrfVkBech32=Cardano.VrfVkBech32,ScriptPubkey=Serialization.ScriptPubkey,DRepID=Cardano.DRepID,DRep=Serialization.DRep,StakeCredentialStatus=Cardano.StakeCredentialStatus,HexBlob=CardanoHexBlob,TxCBOR=Serialization.TxCBOR,Ed25519PrivateKey2=Crypto.Ed25519PrivateKey,computeAuxiliaryDataHash=Cardano.computeAuxiliaryDataHash,blake2b2=Crypto.blake2b,BootstrapWitness=Serialization.BootstrapWitness;import{blake2b as blake2b4,ready}from"@cardano-sdk/crypto";import{isHexString,stringToHex}from"@meshsdk/common";var import_json_bigint=__toESM(require_json_bigint(),1);import{Buffer as Buffer2}from"buffer";import{Cbor,CborArray,CborBytes,CborMap,CborNegInt,CborSimple,CborText,CborUInt,isRawCborArray,isRawCborMap}from"@harmoniclabs/cbor";import{blake2b as blake2b3}from"blakejs";var CoseSign1=class e{protectedMap;unProtectedMap;payload;signature;constructor(e){this.protectedMap=e.protectedMap,this.unProtectedMap=e.unProtectedMap,this.payload=e.payload,this.unProtectedMap.map.find((e=>import_json_bigint.default.stringify(e.k.toRawObj())===import_json_bigint.default.stringify({text:"hashed"})))||this.unProtectedMap.map.push({k:new CborText("hashed"),v:new CborSimple(!1)}),this.signature=e.signature}static fromCbor(t){const r=Cbor.parse(t);if(!isRawCborArray(r.toRawObj()))throw Error("Invalid CBOR");if(4!==r.array.length)throw Error("Invalid COSE_SIGN1");let o;const i=r.array[0];try{if(o=Cbor.parse(i.bytes),!isRawCborMap(o.toRawObj()))throw Error()}catch(e){throw Error("Invalid protected")}let a=r.array[1];if(!isRawCborMap(a.toRawObj()))throw Error("Invalid unprotected");const n=r.array[2],s=r.array[3];return new e({protectedMap:o,unProtectedMap:a,payload:n,signature:s})}createSigStructure(e=Buffer2.alloc(0)){let t=new CborBytes(Buffer2.alloc(0));if(0!==this.protectedMap.map.length&&(t=new CborBytes(Cbor.encode(this.protectedMap).toBuffer())),!this.payload)throw Error("Invalid payload");const r=new CborArray([new CborText("Signature1"),t,new CborBytes(e),this.payload]);return Buffer2.from(Cbor.encode(r).toBuffer())}buildMessage(e){this.signature=new CborBytes(e);let t=new CborBytes(Buffer2.alloc(0));if(0!==this.protectedMap.map.length&&(t=new CborBytes(Cbor.encode(this.protectedMap).toBuffer())),!this.payload)throw Error("Invalid payload");const r=new CborArray([t,this.unProtectedMap,this.payload,this.signature]);return Buffer2.from(Cbor.encode(r).toBuffer())}verifySignature({externalAad:e=Buffer2.alloc(0),publicKeyBuffer:t}={}){if(t||(t=this.getPublicKey()),!t)throw Error("Public key not found");if(!this.signature)throw Error("Signature not found");return new Ed25519PublicKey2(t).verify(new Ed25519Signature2(this.signature.bytes),HexBlob(Buffer2.from(this.createSigStructure(e)).toString("hex")))}hashPayload(){if(!this.unProtectedMap)throw Error("Invalid unprotected map");if(!this.payload)throw Error("Invalid payload");const e=this.unProtectedMap.map.findIndex((e=>import_json_bigint.default.stringify(e.k)===import_json_bigint.default.stringify(new CborText("hashed")))),t=this.unProtectedMap.map[e];if(t&&import_json_bigint.default.stringify(t.v)===import_json_bigint.default.stringify(new CborSimple(!0)))throw Error("Payload already hashed");if(t&&import_json_bigint.default.stringify(t.v)===import_json_bigint.default.stringify(new CborSimple(!0))!=0)throw Error("Invalid unprotected map");this.unProtectedMap.map.splice(e,1);const r=blake2b3(this.payload.bytes,void 0,24);this.payload=new CborBytes(r)}getAddress(){const e=this.protectedMap.map.find((e=>import_json_bigint.default.stringify(e.k.toRawObj())===import_json_bigint.default.stringify({text:"address"})));if(!e)throw Error("Address not found");return Buffer2.from(e.v.bytes)}getPublicKey(){const e=this.protectedMap.map.find((e=>import_json_bigint.default.stringify(e.k.toRawObj())===import_json_bigint.default.stringify({uint:BigInt(4)})));if(!e)throw Error("Public key not found");return Buffer2.from(e.v.bytes)}getSignature(){return this.signature?Buffer2.from(this.signature.bytes):this.signature}getPayload(){return this.payload?Buffer2.from(this.payload.bytes):this.payload}},getPublicKeyFromCoseKey=e=>{const t=Cbor.parse(e).toRawObj().map.find((e=>import_json_bigint.default.stringify(e.k)===import_json_bigint.default.stringify({neg:BigInt(-2)})));if(t)return Buffer2.from(t.v.bytes);throw Error("Public key not found")},getCoseKeyFromPublicKey=e=>{const t=[];return t.push({k:new CborUInt(1),v:new CborUInt(1)}),t.push({k:new CborUInt(3),v:new CborNegInt(-8)}),t.push({k:new CborNegInt(-1),v:new CborUInt(6)}),t.push({k:new CborNegInt(-2),v:new CborBytes(Buffer2.from(e,"hex"))}),Buffer2.from(Cbor.encode(new CborMap(t)).toBuffer())},checkSignature=async(e,{key:t,signature:r},o)=>{await ready();const i=CoseSign1.fromCbor(r),a=getPublicKeyFromCoseKey(t);if(o){let e=NetworkId.Mainnet;const t=BaseAddress.fromAddress(Address.fromBech32(o)),r=Ed25519PublicKey2.fromBytes(a),i={hash:Hash28ByteBase162(r.hash().hex()),type:0};if(o.startsWith("addr")){o.startsWith("addr_test1")&&(e=NetworkId.Testnet);const r=t?.getStakeCredential();if(r){if(o!==BaseAddress.fromCredentials(e,i,r).toAddress().toBech32()){const t=RewardAddress.fromCredentials(e,r).toAddress().toBech32();if(RewardAddress.fromCredentials(e,i).toAddress().toBech32()!==t)return!1}}else{if(EnterpriseAddress.fromCredentials(e,i).toAddress().toBech32()!==o)return!1}}else{if(!o.startsWith("stake"))return!1;o.startsWith("stake_test1")&&(e=NetworkId.Testnet);if(RewardAddress.fromCredentials(e,i).toAddress().toBech32()!==o)return!1}}if(null===i.getPayload())return!1;const n=isHexString(e)?e:stringToHex(e),s=i.getPayload(),d=0==Buffer.from(n,"hex").compare(s),u=blake2b4.hash(n,28)==s.toString("hex");return!(!d&&!u)&&i.verifySignature({publicKeyBuffer:a})};import crypto2 from"crypto";var pool,poolOffset,POOL_SIZE_MULTIPLIER=128,fillPool=e=>{!pool||pool.length<e?(pool=Buffer.allocUnsafe(e*POOL_SIZE_MULTIPLIER),crypto2.randomFillSync(pool),poolOffset=0):poolOffset+e>pool.length&&(crypto2.randomFillSync(pool),poolOffset=0),poolOffset+=e},random=e=>(fillPool(e|=0),pool.subarray(poolOffset-e,poolOffset)),customRandom=(e,t,r)=>{let o=(2<<31-Math.clz32(e.length-1|1))-1,i=Math.ceil(1.6*o*t/e.length);return(a=t)=>{let n="";for(;;){let t=r(i),s=i;for(;s--;)if(n+=e[t[s]&o]||"",n.length===a)return n}}},customAlphabet=(e,t=21)=>customRandom(e,t,random);import{stringToHex as stringToHex2}from"@meshsdk/common";var generateNonce=(e="",t=32)=>{if(t<=0||t>2048)throw new Error("Length must be bewteen 1 and 2048");const r=customAlphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")(t);return stringToHex2(`${e}${r}`)};import{CborBytes as CborBytes2,CborMap as CborMap2,CborNegInt as CborNegInt2,CborText as CborText2,CborUInt as CborUInt2}from"@harmoniclabs/cbor";import{isHexString as isHexString2,stringToHex as stringToHex3}from"@meshsdk/common";var signData=(e,t)=>{const r=isHexString2(e)?e:stringToHex3(e),o=Buffer.from(r,"hex"),i=Buffer.from(t.key.toPublic().bytes()),a=[];a.push({k:new CborUInt2(1),v:new CborNegInt2(-8)}),a.push({k:new CborUInt2(4),v:new CborBytes2(i)}),a.push({k:new CborText2("address"),v:new CborBytes2(Buffer.from(t.address.toBytes(),"hex"))});const n=new CoseSign1({protectedMap:new CborMap2(a),unProtectedMap:new CborMap2([]),payload:new CborBytes2(o)}),s=t.key.sign(HexBlob(Buffer.from(n.createSigStructure()).toString("hex"))),d=n.buildMessage(Buffer.from(s.bytes())).toString("hex");return{key:getCoseKeyFromPublicKey(i.toString("hex")).toString("hex"),signature:d}};import{Cardano as Cardano3}from"@cardano-sdk/core";import base323 from"base32-encoding";import{bech32 as bech323}from"bech32";import{fromUTF8,mnemonicToEntropy,toBytes as toBytes4}from"@meshsdk/common";var import_blake2b=__toESM(require_blake2b2(),1);import{pbkdf2Sync}from"crypto";import{HexBlob as HexBlob2}from"@cardano-sdk/util";import hash from"hash.js";import{HARDENED_KEY_START}from"@meshsdk/common";var buildBaseAddress=(e,t,r,o=CredentialType.KeyHash,i=CredentialType.KeyHash)=>BaseAddress.fromCredentials(e,{hash:t,type:o},{hash:r,type:i}),buildEnterpriseAddress=(e,t,r=CredentialType.KeyHash)=>EnterpriseAddress.fromCredentials(e,{hash:t,type:r}),clampScalar=e=>(void 0!==e[0]&&(e[0]&=248),void 0!==e[31]&&(e[31]&=31,e[31]|=64),e),buildBip32PrivateKey=(e,t="")=>{const r=Buffer.from(e,"hex"),o=pbkdf2Sync(t,r,4096,96,"sha512");return Bip32PrivateKey2.fromBytes(clampScalar(o))},buildRewardAddress=(e,t,r=CredentialType.KeyHash)=>{const o={type:r,hash:t};return RewardAddress.fromCredentials(e,o)},buildKeys=(e,t,r=0)=>{if("string"==typeof e){const o=Bip32PrivateKey2.fromHex(Bip32PrivateKeyHex2(e)).derive([HARDENED_KEY_START+1852,HARDENED_KEY_START+1815,HARDENED_KEY_START+t]);return{paymentKey:o.derive([0,r]).toRawKey(),stakeKey:o.derive([2,0]).toRawKey(),dRepKey:o.derive([3,r]).toRawKey()}}return{paymentKey:Ed25519PrivateKey2.fromNormalHex(Ed25519PrivateNormalKeyHex(e[0])),stakeKey:Ed25519PrivateKey2.fromNormalHex(Ed25519PrivateNormalKeyHex(e[1]))}},buildEd25519PrivateKeyFromSecretKey=e=>Ed25519PrivateKey2.fromExtendedBytes(new Uint8Array(clampScalar(Buffer.from(hash.sha512().update(Buffer.from(e,"hex")).digest())))),buildScriptPubkey=e=>{const t=new ScriptPubkey(Ed25519KeyHashHex2(e.hex()));return NativeScript.newScriptPubkey(t)},buildDRepID=(e,t=NetworkId.Testnet,r=AddressType.EnterpriseKey)=>{const o=Buffer.from(e,"hex"),i=(0,import_blake2b.default)(28).update(o).digest("hex"),a=EnterpriseAddress.packParts({networkId:t,paymentPart:{hash:Hash28ByteBase162(i),type:CredentialType.KeyHash},type:r});return HexBlob2.toTypedBech32("drep",HexBlob2.fromBytes(a))};import{Serialization as Serialization3}from"@cardano-sdk/core";import{Ed25519KeyHash as Ed25519KeyHash4}from"@cardano-sdk/crypto";import{HexBlob as HexBlob5}from"@cardano-sdk/util";import base32 from"base32-encoding";import{bech32}from"bech32";import{toBytes as toBytes3}from"@meshsdk/common";import{HexBlob as HexBlob3}from"@cardano-sdk/util";import{toBytes}from"@meshsdk/common";var toPlutusData=e=>{const t=e=>{const t=new PlutusList;return e.forEach((e=>{t.add(toPlutusData(e))})),t};switch(typeof e){case"string":return PlutusData.newBytes(toBytes(e));case"number":case"bigint":return PlutusData.newInteger(BigInt(e));case"object":if(e instanceof Array){const r=t(e);return PlutusData.newList(r)}if(e instanceof Map){const t=new PlutusMap;return e.forEach(((e,r)=>{t.insert(toPlutusData(r),toPlutusData(e))})),PlutusData.newMap(t)}return PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(e.alternative),t(e.fields)))}},isConstrPlutusDataJson=e=>"object"==typeof e&&"constructor"in e&&("number"==typeof e.constructor||"bigint"==typeof e.constructor||"string"==typeof e.constructor)&&"fields"in e&&Array.isArray(e.fields);function isMapPlutusDataJson(e){return"object"==typeof e&&Array.isArray(e)}function isKeyValuePlutusDataJson(e){return"object"==typeof e&&"k"in e&&"object"==typeof e.k&&"v"in e&&"object"==typeof e.v}var fromJsonToPlutusData=e=>{if(isConstrPlutusDataJson(e)){const t=new PlutusList;e.fields.map((e=>{t.add(fromJsonToPlutusData(e))}));const r=new ConstrPlutusData(BigInt(e.constructor),t);return PlutusData.newConstrPlutusData(r)}if("int"in e&&1===Object.keys(e).length){if("bigint"==typeof e.int||"number"==typeof e.int||"string"==typeof e.int)return PlutusData.newInteger(BigInt(e.int));throw new Error("Malformed int field in Plutus data, expected one of bigint, number or string")}if("bytes"in e&&1===Object.keys(e).length){if("string"==typeof e.bytes)return PlutusData.newBytes(Buffer.from(e.bytes,"hex"));throw new Error("Malformed bytes field in Plutus data, expected string")}if("list"in e&&1===Object.keys(e).length){if(Array.isArray(e.list)){const t=new PlutusList;return e.list.map((e=>{t.add(fromJsonToPlutusData(e))})),PlutusData.newList(t)}throw new Error("Malformed list field in Plutus data, expected list")}if("map"in e&&1===Object.keys(e).length){if(isMapPlutusDataJson(e.map)){const t=new PlutusMap;return e.map.forEach((e=>{if(!isKeyValuePlutusDataJson(e))throw new Error("Malformed key value pair in Plutus data map");t.insert(fromJsonToPlutusData(e.k),fromJsonToPlutusData(e.v))})),PlutusData.newMap(t)}throw console.log(e),new Error("Malformed map field in Plutus data")}throw new Error("Malformed Plutus data json")},fromBuilderToPlutusData=e=>{if("Mesh"===e.type)return toPlutusData(e.content);if("CBOR"===e.type)return PlutusData.fromCbor(HexBlob3(e.content));if("JSON"===e.type){let t;return t="string"==typeof e.content?JSON.parse(e.content):e.content,fromJsonToPlutusData(t)}throw new Error("Malformed builder data, expected types of, Mesh, CBOR or JSON")},fromPlutusDataToJson=e=>{if(e.getKind()===PlutusDataKind.ConstrPlutusData){const t=e.asConstrPlutusData();if(void 0!==t){const e=t.getData(),r=[];for(let t=0;t<e.getLength();t++){const o=e.get(t);r.push(fromPlutusDataToJson(o))}return{constructor:t.getAlternative(),fields:r}}throw new Error("Invalid constructor data found")}if(e.getKind()===PlutusDataKind.Map){const t=e.asMap(),r=[];if(void 0!==t){const e=t.getKeys();for(let o=0;o<e.getLength();o++){const i=e.get(o),a=t.get(i);a&&r.push({k:fromPlutusDataToJson(i),v:fromPlutusDataToJson(a)})}return{map:r}}throw new Error("Invalid map data found")}if(e.getKind()===PlutusDataKind.List){const t=e.asList();if(void 0!==t){const e=[];for(let r=0;r<t.getLength();r++){const o=t.get(r);e.push(fromPlutusDataToJson(o))}return{list:e}}throw new Error("Invalid list data found")}if(e.getKind()===PlutusDataKind.Integer){const t=e.asInteger();if(void 0!==t)return{int:t};throw new Error("Invalid integer data found")}if(e.getKind()===PlutusDataKind.Bytes){const t=e.asBoundedBytes();if(void 0!==t)return{bytes:Buffer.from(t).toString("hex")};throw new Error("Invalid bytes data found")}throw new Error("Invalid Plutus data found")},datumCborToJson=e=>{const t=PlutusData.fromCbor(HexBlob3(e));return fromPlutusDataToJson(t)},parseDatumCbor=e=>datumCborToJson(e),parseInlineDatum=e=>{const t=e.inline_datum||"";return datumCborToJson(t)},deserializeDataHash=e=>DatumHash(e),deserializePlutusData=e=>PlutusData.fromCbor(HexBlob3(e));import{Serialization as Serialization2}from"@cardano-sdk/core";import{HexBlob as HexBlob4}from"@cardano-sdk/util";import{toBytes as toBytes2}from"@meshsdk/common";var deserializeEd25519KeyHash=e=>Ed25519KeyHash2.fromBytes(toBytes2(e)),deserializePlutusScript=(e,t)=>{switch(t){case"V1":return PlutusV1Script.fromCbor(HexBlob4(e));case"V2":return PlutusV2Script.fromCbor(HexBlob4(e));case"V3":return PlutusV3Script.fromCbor(HexBlob4(e));default:throw new Error("Invalid Plutus script version")}},deserializeNativeScript=e=>NativeScript.fromCbor(HexBlob4(e)),deserializeScriptHash=e=>ScriptHash(e),deserializeScriptRef=e=>Script.fromCbor(HexBlob4(e)),deserializeTxUnspentOutput=e=>TransactionUnspentOutput.fromCbor(HexBlob4(e)),deserializeValue=e=>Value.fromCbor(HexBlob4(e)),deserializeTx=e=>Transaction.fromCbor(Serialization2.TxCBOR(e)),deserializeTxHash=e=>TransactionId(e),toAddress=e=>Address.fromBech32(e),toCardanoAddress=e=>{try{return Address.fromBech32(e)}catch{try{return Address.fromBase58(e)}catch{throw new Error(`Invalid address format, ${e}`)}}},toBaseAddress=e=>BaseAddress.fromAddress(toAddress(e)),toEnterpriseAddress=e=>EnterpriseAddress.fromAddress(toAddress(e)),toRewardAddress=e=>RewardAddress.fromAddress(toAddress(e)),fromTxUnspentOutput=e=>{let t=e.output().datum()?e.output().datum()?.asDataHash()?.toString():void 0;const r=e.output().scriptRef()?e.output().scriptRef()?.toCbor().toString():void 0,o=e.output().datum()?.asInlineData()?e.output().datum()?.asInlineData()?.toCbor().toString():void 0;return o&&!t&&(t=resolveDataHash(o,"CBOR")),{input:{outputIndex:Number(e.input().index()),txHash:e.input().transactionId()},output:{address:e.output().address().toBech32(),amount:fromValue(e.output().amount()),dataHash:t,plutusData:o,scriptRef:r}}},toTxUnspentOutput=e=>{const t=new TransactionInput(deserializeTxHash(e.input.txHash),BigInt(e.input.outputIndex)),r=new TransactionOutput(toAddress(e.output.address),toValue(e.output.amount));if(void 0!==e.output.dataHash&&r.setDatum(Datum.fromCore(deserializeDataHash(e.output.dataHash))),void 0!==e.output.plutusData){const t=deserializePlutusData(e.output.plutusData),o=new Serialization3.Datum(void 0,t);r.setDatum(o)}return void 0!==e.output.scriptRef&&r.setScriptRef(deserializeScriptRef(e.output.scriptRef)),new TransactionUnspentOutput(t,r)},addressToBech32=e=>e.toBech32(),fromValue=e=>{const t=[{unit:"lovelace",quantity:e.coin().toString()}],r=e.multiasset();if(void 0!==r){const e=Array.from(r.keys());for(let o=0;o<e.length;o+=1){const i=e[o];if(void 0!==i){const e=r.get(i);void 0!==e&&t.push({unit:i,quantity:e.toString()})}}}return t},toScriptRef=e=>{if("code"in e){const t=deserializePlutusScript(e.code,e.version);if(t instanceof PlutusV1Script)return Script.newPlutusV1Script(t);if(t instanceof PlutusV2Script)return Script.newPlutusV2Script(t);if(t instanceof PlutusV3Script)return Script.newPlutusV3Script(t)}return Script.newNativeScript(toNativeScript(e))},fromScriptRef=e=>{const t=Script.fromCbor(HexBlob5(e)),r=t.asPlutusV3()?.toCbor().toString();if(r)return{code:r,version:"V3"};const o=t.asPlutusV2()?.toCbor().toString();if(o)return{code:o,version:"V2"};const i=t.asPlutusV1()?.toCbor().toString();if(i)return{code:i,version:"V1"};const a=t.asNative();if(!a)throw new Error("Invalid script");return fromNativeScript(a)},fromNativeScript=e=>{const t=e=>{const t=new Array;for(let r=0;r<e.length;r+=1){const o=e[r];o&&t.push(fromNativeScript(o))}return t};switch(e.kind()){case RequireAllOf:return{type:"all",scripts:t(e.asScriptAll().nativeScripts())};case RequireAnyOf:return{type:"any",scripts:t(e.asScriptAny().nativeScripts())};case RequireNOf:{const r=e.asScriptNOfK();return{type:"atLeast",required:r.required(),scripts:t(r.nativeScripts())}}case RequireTimeAfter:return{type:"after",slot:e.asTimelockStart().slot().toString()};case RequireTimeBefore:return{type:"before",slot:e.asTimelockExpiry().slot().toString()};case RequireSignature:return{type:"sig",keyHash:e.asScriptPubkey().keyHash().toString()};default:throw new Error(`Script Kind: ${e.kind()}, is not supported`)}},toNativeScript=e=>{const t=e=>{const t=[];return e.forEach((e=>{t.push(toNativeScript(e))})),t};switch(e.type){case"all":return NativeScript.newScriptAll(new Serialization3.ScriptAll(t(e.scripts)));case"any":return NativeScript.newScriptAny(new Serialization3.ScriptAny(t(e.scripts)));case"atLeast":return NativeScript.newScriptNOfK(new Serialization3.ScriptNOfK(t(e.scripts),e.required));case"after":return NativeScript.newTimelockStart(new Serialization3.TimelockStart(Slot(parseInt(e.slot))));case"before":return NativeScript.newTimelockExpiry(new Serialization3.TimelockExpiry(Slot(parseInt(e.slot))));case"sig":return NativeScript.newScriptPubkey(new Serialization3.ScriptPubkey(Ed25519KeyHash4.fromBytes(toBytes3(e.keyHash)).hex()))}},toValue=e=>{const t=new Map;e.filter((e=>"lovelace"!==e.unit&&""!==e.unit)).forEach((e=>{t.set(AssetId(e.unit),BigInt(e.quantity))}));const r=e.find((e=>"lovelace"===e.unit||""===e.unit)),o=new Value(BigInt(r?r.quantity:0));return(e.length>1||!r)&&o.setMultiasset(t),o},toDRep=e=>{if(58===e.length){const{prefix:t,words:r}=bech32.decode(e);if("drep"!==t)throw new Error("Invalid DRepId prefix");const o=base32.decode(new Uint8Array(r));if(34===o[0])return Serialization3.DRep.newKeyHash(Ed25519KeyHashHex2(o.subarray(1).toString("hex")));if(35===o[0])return Serialization3.DRep.newScriptHash(Hash28ByteBase162(o.subarray(1).toString("hex")));throw new Error("Malformed CIP129 DRepId")}{const{prefix:t,words:r}=bech32.decode(e);switch(t){case"drep":return Serialization3.DRep.newKeyHash(Ed25519KeyHashHex2(base32.decode(new Uint8Array(r)).toString("hex")));case"drep_script":return Serialization3.DRep.newScriptHash(Hash28ByteBase162(base32.decode(new Uint8Array(r)).toString("hex")));default:throw new Error("Malformed DRepId prefix")}}},getDRepIds=e=>{let t={cip105:"",cip129:""};if(58===e.length){t.cip129=e;const{prefix:r,words:o}=bech32.decode(e);if("drep"!==r)throw new Error("Malformed CIP129 DRepId");const i=base32.decode(new Uint8Array(o));if(34===i[0])t.cip105=bech32.encode("drep",base32.encode(i.subarray(1)));else{if(35!==i[0])throw new Error("Malformed CIP129 DRepId");t.cip105=bech32.encode("drep_script",base32.encode(i.subarray(1)))}}else{t.cip105=e;try{const{prefix:r,words:o}=bech32.decode(e);let i=base32.decode(new Uint8Array(o));if("drep"===r){if(!i)throw new Error("Malformed key hash in DRepId");let e=new Uint8Array(i.length+1);e.set([34]),e.set(i,1);let r=base32.encode(e);t.cip129=bech32.encode("drep",r)}else{if("drep_script"!==r)throw new Error("Can only calculate DRepIds for script/key DReps");{if(!i)throw new Error("Malformed script hash in DRepId");let e=new Uint8Array(i.length+1);e.set([35]),e.set(i,1);let r=base32.encode(e);t.cip129=bech32.encode("drep",r)}}}catch(e){throw console.error(e),new Error("Malformed DRepId")}}return t},toPlutusLanguageVersion=e=>{switch(e){case"V1":return PlutusLanguageVersion.V1;case"V2":return PlutusLanguageVersion.V2;case"V3":return PlutusLanguageVersion.V3}};function mergeValue(e,t){const r=e.multiasset()??new Map;return t.multiasset()?.forEach(((e,t)=>{const o=(r.get(t)??0n)+e;0n==o?r.delete(t):r.set(t,o)})),new Value(BigInt(e.coin())+BigInt(t.coin()),r.size>0?r:void 0)}function negateValue(e){const t=e.multiasset()?.entries(),r=new Map;if(t)for(const e of t)r.set(e[0],-e[1]);return new Value(-e.coin(),r)}function subValue(e,t){return mergeValue(e,negateValue(t))}function negatives(e){const t=e.multiasset()?.entries(),r=e.coin()<0n?e.coin():0n,o=new Map;if(t)for(const e of t)e[1]<0n&&o.set(e[0],e[1]);return new Value(r,o)}function assetTypes(e){let t=0n==e.coin()?0:1;const r=e.multiasset();return r&&r.forEach((()=>{t+=1})),t}function empty(e){return 0==assetTypes(e)}import{HexBlob as HexBlob6}from"@cardano-sdk/util";import{pubKeyAddress,scriptAddress}from"@meshsdk/common";var serializeAddress=(e,t=0)=>{const{pubKeyHash:r,scriptHash:o,stakeCredentialHash:i,stakeScriptCredentialHash:a}=e,n=!r,s=!i,d=n?o:r,u=s?a:i;if(!d)throw new Error("Error: serializeAddress: Address must contain a payment part");const c=n?scriptAddress(d,u,s):pubKeyAddress(d,u,s);return serializeAddressObj(c,t)},addrBech32ToPlutusData=e=>{const t=Address.fromBech32(e).getProps(),r=new PlutusList;if(!t.paymentPart)throw new Error("Error: addrBech32ToPlutusDataHex: Address must contain a payment part");r.add(PlutusData.newBytes(Buffer.from(t.paymentPart.hash,"hex")));const o=PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(t.paymentPart.type),r)),i=new PlutusList;let a;if(t.delegationPart){i.add(PlutusData.newBytes(Buffer.from(t.delegationPart.hash,"hex")));const e=PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(0),i)),r=new PlutusList;r.add(e),a=PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(0),r))}else if(t.pointer){const e=new PlutusList;e.add(PlutusData.newInteger(BigInt(t.pointer.slot))),e.add(PlutusData.newInteger(BigInt(t.pointer.txIndex))),e.add(PlutusData.newInteger(BigInt(t.pointer.certIndex)));const r=PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(1),e)),o=new PlutusList;o.add(r),a=PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(0),o))}else a=PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(1),new PlutusList));const n=new PlutusList;return n.add(o),n.add(a),PlutusData.newConstrPlutusData(new ConstrPlutusData(BigInt(0),n))},addrBech32ToPlutusDataHex=e=>addrBech32ToPlutusData(e).toCbor(),addrBech32ToPlutusDataObj=e=>fromPlutusDataToJson(addrBech32ToPlutusData(e)),plutusDataToAddrBech32=(e,t=0)=>{const r=e.asConstrPlutusData();if(!r||r.getAlternative()!==BigInt(0))throw new Error("Error: serializeAddressObj: Address must contain a constructor 0");const o=r.getData();if(2!==o.getLength())throw new Error("Error: serializeAddressObj: Address must contain 2 parts");const i=o.get(0).asConstrPlutusData();if(!i)throw new Error("Error: serializeAddressObj: Payment part must be a constructor");const a=i.getData();if(1!==a.getLength())throw new Error("Error: serializeAddressObj: Payment part must contain 1 element");const n=a.get(0).asBoundedBytes();if(!n)throw new Error("Error: serializeAddressObj: Payment inner part must be bytes");if(i.getAlternative()!==BigInt(0)&&i.getAlternative()!==BigInt(1))throw new Error("Error: serializeAddressObj: Payment part must be alternative 0 or 1");const s={hash:Hash28ByteBase162(Buffer.from(n).toString("hex")),type:Number(i.getAlternative())},d=o.get(1).asConstrPlutusData();if(!d)throw new Error("Error: serializeAddressObj: Delegation part must be a constructor");if(d.getAlternative()===BigInt(1))return EnterpriseAddress.fromCredentials(t,s).toAddress().toBech32().toString();if(d.getAlternative()===BigInt(0)){const e=d.getData();if(1!==e.getLength())throw new Error("Error: serializeAddressObj: Delegation part must contain 1 element");const r=e.get(0).asConstrPlutusData();if(!r)throw new Error("Error: serializeAddressObj: Delegation inner part must be a constructor");if(r.getAlternative()===BigInt(0)){const e=r.getData();if(1!==e.getLength())throw new Error("Error: serializeAddressObj: Delegation inner part must contain 1 element");const o=e.get(0).asConstrPlutusData();if(!o)throw new Error("Error: serializeAddressObj: Delegation inner part must be a constructor");const i=o.getData();if(1!==i.getLength())throw new Error("Error: serializeAddressObj: Delegation bytes part must contain 1 element");const a=i.get(0).asBoundedBytes();if(!a)throw new Error("Error: serializeAddressObj: Delegation bytes part must be of type bytes");const n={hash:Hash28ByteBase162(Buffer.from(a).toString("hex")),type:Number(o.getAlternative())};return BaseAddress.fromCredentials(t,s,n).toAddress().toBech32().toString()}if(r.getAlternative()===BigInt(1)){const e=r.getData();if(3!==e.getLength())throw new Error("Error: serializeAddressObj: Delegation inner part must contain 3 elements");const o=e.get(0).asInteger();if(!o)throw new Error("Error: serializeAddressObj: Delegation inner part slot must be integer");const i=e.get(1).asInteger();if(!i)throw new Error("Error: serializeAddressObj: Delegation inner part txIndex must be integer");const a=e.get(2).asInteger();if(!a)throw new Error("Error: serializeAddressObj: Delegation inner part certIndex must be integer");const n={slot:o,txIndex:TxIndex(Number(i)),certIndex:CertIndex(Number(a))};return PointerAddress.fromCredentials(t,s,n).toAddress().toBech32().toString()}throw new Error("Error: serializeAddressObj: Delegation inner part must be alternative 0 or 1")}throw new Error("Error: serializeAddressObj: Delegation part must be alternative 0 or 1")},serializeAddressObj=(e,t=0)=>{const r=fromJsonToPlutusData(e);return plutusDataToAddrBech32(r,t)},serializePlutusAddressToBech32=(e,t=0)=>{const r=PlutusData.fromCbor(HexBlob6(e));return plutusDataToAddrBech32(r,t).toString()},deserializeBech32Address=e=>{const t=Address.fromBech32(e).getProps();return{pubKeyHash:t.paymentPart?.type===CredentialType.KeyHash?t.paymentPart?.hash:"",scriptHash:t.paymentPart?.type===CredentialType.ScriptHash?t.paymentPart?.hash:"",stakeCredentialHash:t.delegationPart?.type===CredentialType.KeyHash?t.delegationPart?.hash:"",stakeScriptCredentialHash:t.delegationPart?.type===CredentialType.ScriptHash?t.delegationPart?.hash:""}},deserializeAddress=e=>{const t=Address.fromString(e);if(null===t)throw new Error("Invalid address");return t},scriptHashToBech32=(e,t,r=0,o=!1)=>t?BaseAddress.fromCredentials(r,{hash:Hash28ByteBase162(e),type:CredentialType.ScriptHash},{hash:Hash28ByteBase162(t),type:o?CredentialType.ScriptHash:CredentialType.KeyHash}).toAddress().toBech32().toString():EnterpriseAddress.fromCredentials(r,{hash:Hash28ByteBase162(e),type:CredentialType.ScriptHash}).toAddress().toBech32().toString(),v2ScriptToBech32=(e,t,r=0,o=!1)=>scriptHashToBech32(Script.fromCbor(HexBlob6(e)).hash().toString(),t,r,o),scriptHashToRewardAddress=(e,t=0)=>RewardAddress.fromCredentials(t,{hash:Hash28ByteBase162(e),type:CredentialType.ScriptHash}).toAddress().toBech32().toString(),keyHashToRewardAddress=(e,t=0)=>RewardAddress.fromCredentials(t,{hash:Hash28ByteBase162(e),type:CredentialType.KeyHash}).toAddress().toBech32().toString();import base322 from"base32-encoding";import{bech32 as bech322}from"bech32";var bytesToHex=e=>Buffer.from(e).toString("hex"),hexToBytes=e=>Buffer.from(e,"hex"),utf8ToBytes=e=>Buffer.from(e,"utf8"),utf8ToHex=e=>Buffer.from(e,"utf8").toString("hex"),hexToBech32=(e,t)=>{const r=Buffer.from(t,"hex"),o=base322.encode(r);return bech322.encode(e,o)},addVKeyWitnessSetToTransaction=(e,t)=>{const r=Transaction.fromCbor(TxCBOR(e)),o=r.witnessSet(),i=TransactionWitnessSet.fromCbor(HexBlob(t)),a=o.vkeys(),n=i.vkeys(),s=[...a?.values()??[],...n?.values()??[]];return o.setVkeys(CborSet.fromCore(s.map((e=>e.toCore())),VkeyWitness.fromCore)),r.setWitnessSet(o),r.toCbor()},calculateFees=(e,t,r,o,i,a,n)=>{let s=t+a.toCbor().length/2*e;s+=calculateRefScriptFees(n,r);let d=BigInt(0),u=o,c=1;for(;u%1;)u*=10,c*=10;let l=i,p=1;for(;l%1;)l*=10,p*=10;if(a.witnessSet().redeemers())for(const e of a.witnessSet().redeemers().values())d+=e.exUnits().mem()*BigInt(u.toString())/BigInt(c.toString()),d+=e.exUnits().steps()*BigInt(l.toString())/BigInt(p.toString()),u%c!=0&&(d+=BigInt(1)),l%p!=0&&(d+=BigInt(1));return BigInt(s)+d},calculateRefScriptFees=(e,t,r=1.2)=>{let o=0;const i=25600;let a=e,n=1;for(;a>=i;)o+=i*n*t,a-=i,n*=r;return a>0&&(o+=a*n*t),o=Math.ceil(o),o};import{Cardano as Cardano2,Serialization as Serialization4}from"@cardano-sdk/core";var toCardanoAnchor=e=>({url:e.anchorUrl,dataHash:Hash32ByteBase162(e.anchorDataHash)}),toCardanoGovernanceActionId=e=>e?{id:Cardano2.TransactionId(e.transactionId),actionIndex:e.govActionIndex}:null,toCardanoCredential=e=>"KeyHash"===e.type?{type:CredentialType.KeyHash,hash:Hash28ByteBase162(e.keyHash)}:{type:CredentialType.ScriptHash,hash:Hash28ByteBase162(e.scriptHash)},toCardanoFraction=e=>({numerator:Number(e.numerator),denominator:Number(e.denominator)}),fractionToString=e=>""+Number(e.numerator)/Number(e.denominator),toCardanoCostModels=e=>{const t=new Map;for(const[r,o]of Object.entries(e))t.set(toPlutusLanguageVersion(r),o);return t},toCardanoProtocolParamUpdate=e=>{const t={};if(void 0!==e.minFeeA&&(t.minFeeCoefficient=Number(e.minFeeA)),void 0!==e.minFeeB&&(t.minFeeConstant=Number(e.minFeeB)),void 0!==e.maxBlockBodySize&&(t.maxBlockBodySize=Number(e.maxBlockBodySize)),void 0!==e.maxTxSize&&(t.maxTxSize=Number(e.maxTxSize)),void 0!==e.maxBlockHeaderSize&&(t.maxBlockHeaderSize=Number(e.maxBlockHeaderSize)),void 0!==e.keyDeposit&&(t.stakeKeyDeposit=Number(e.keyDeposit)),void 0!==e.poolDeposit&&(t.poolDeposit=Number(e.poolDeposit)),void 0!==e.maxEpoch&&(t.poolRetirementEpochBound=Number(e.maxEpoch)),void 0!==e.nOpt&&(t.desiredNumberOfPools=Number(e.nOpt)),void 0!==e.poolPledgeInfluence&&(t.poolInfluence=fractionToString(e.poolPledgeInfluence)),void 0!==e.expansionRate&&(t.monetaryExpansion=fractionToString(e.expansionRate)),void 0!==e.treasuryGrowthRate&&(t.treasuryExpansion=fractionToString(e.treasuryGrowthRate)),void 0!==e.minPoolCost&&(t.minPoolCost=Number(e.minPoolCost)),void 0!==e.adaPerUtxoByte&&(t.coinsPerUtxoByte=Number(e.adaPerUtxoByte)),void 0!==e.costModels&&(t.costModels=toCardanoCostModels(e.costModels)),void 0!==e.executionCosts){const r=e.executionCosts.memPrice?Number(e.executionCosts.memPrice.numerator)/Number(e.executionCosts.memPrice.denominator):void 0,o=e.executionCosts.stepPrice?Number(e.executionCosts.stepPrice.numerator)/Number(e.executionCosts.stepPrice.denominator):void 0;void 0===r&&void 0===o||(t.prices={memory:r,steps:o})}if(void 0!==e.maxTxExUnits&&(t.maxExecutionUnitsPerTransaction={memory:Number(e.maxTxExUnits.mem),steps:Number(e.maxTxExUnits.steps)}),void 0!==e.maxBlockExUnits&&(t.maxExecutionUnitsPerBlock={memory:Number(e.maxBlockExUnits.mem),steps:Number(e.maxBlockExUnits.steps)}),void 0!==e.maxValueSize&&(t.maxValueSize=Number(e.maxValueSize)),void 0!==e.collateralPercentage&&(t.collateralPercentage=Number(e.collateralPercentage)),void 0!==e.maxCollateralInputs&&(t.maxCollateralInputs=Number(e.maxCollateralInputs)),void 0!==e.poolVotingThresholds){const r={};void 0!==e.poolVotingThresholds.motionNoConfidence&&(r.motionNoConfidence=toCardanoFraction(e.poolVotingThresholds.motionNoConfidence)),void 0!==e.poolVotingThresholds.committeeNormal&&(r.committeeNormal=toCardanoFraction(e.poolVotingThresholds.committeeNormal)),void 0!==e.poolVotingThresholds.committeeNoConfidence&&(r.committeeNoConfidence=toCardanoFraction(e.poolVotingThresholds.committeeNoConfidence)),void 0!==e.poolVotingThresholds.hardForkInitiation&&(r.hardForkInitiation=toCardanoFraction(e.poolVotingThresholds.hardForkInitiation)),void 0!==e.poolVotingThresholds.ppSecurityGroup&&(r.securityRelevantParamVotingThreshold=toCardanoFraction(e.poolVotingThresholds.ppSecurityGroup)),Object.keys(r).length>0&&(t.poolVotingThresholds=r)}if(void 0!==e.drepVotingThresholds){const r={};void 0!==e.drepVotingThresholds.motionNoConfidence&&(r.motionNoConfidence=toCardanoFraction(e.drepVotingThresholds.motionNoConfidence)),void 0!==e.drepVotingThresholds.committeeNormal&&(r.committeeNormal=toCardanoFraction(e.drepVotingThresholds.committeeNormal)),void 0!==e.drepVotingThresholds.committeeNoConfidence&&(r.committeeNoConfidence=toCardanoFraction(e.drepVotingThresholds.committeeNoConfidence)),void 0!==e.drepVotingThresholds.updateConstitution&&(r.updateConstitution=toCardanoFraction(e.drepVotingThresholds.updateConstitution)),void 0!==e.drepVotingThresholds.hardForkInitiation&&(r.hardForkInitiation=toCardanoFraction(e.drepVotingThresholds.hardForkInitiation)),void 0!==e.drepVotingThresholds.ppNetworkGroup&&(r.ppNetworkGroup=toCardanoFraction(e.drepVotingThresholds.ppNetworkGroup)),void 0!==e.drepVotingThresholds.ppEconomicGroup&&(r.ppEconomicGroup=toCardanoFraction(e.drepVotingThresholds.ppEconomicGroup)),void 0!==e.drepVotingThresholds.ppTechnicalGroup&&(r.ppTechnicalGroup=toCardanoFraction(e.drepVotingThresholds.ppTechnicalGroup)),void 0!==e.drepVotingThresholds.ppGovGroup&&(r.ppGovernanceGroup=toCardanoFraction(e.drepVotingThresholds.ppGovGroup)),void 0!==e.drepVotingThresholds.treasuryWithdrawal&&(r.treasuryWithdrawal=toCardanoFraction(e.drepVotingThresholds.treasuryWithdrawal)),Object.keys(r).length>0&&(t.dRepVotingThresholds=r)}return void 0!==e.minCommitteeSize&&(t.minCommitteeSize=Number(e.minCommitteeSize)),void 0!==e.committeeTermLimit&&(t.committeeTermLimit=Cardano2.EpochNo(e.committeeTermLimit)),void 0!==e.govActionValidityPeriod&&(t.governanceActionValidityPeriod=Cardano2.EpochNo(e.govActionValidityPeriod)),void 0!==e.govActionDeposit&&(t.governanceActionDeposit=Number(e.govActionDeposit)),void 0!==e.drepDeposit&&(t.dRepDeposit=Number(e.drepDeposit)),void 0!==e.drepInactivityPeriod&&(t.dRepInactivityPeriod=Cardano2.EpochNo(e.drepInactivityPeriod)),void 0!==e.refScriptCostPerByte&&(t.minFeeRefScriptCostPerByte=fractionToString(e.refScriptCostPerByte)),t},toCardanoCommittee=e=>{const t=[];for(const r of e.members)t.push({coldCredential:toCardanoCredential(r.stakeCredential),epoch:Cardano2.EpochNo(r.termLimit)});return{members:t,quorumThreshold:toCardanoFraction(e.quorumThreshold)}},toCardanoConstitution=e=>{let t=null;return e.scriptHash&&(t=Hash28ByteBase162(e.scriptHash.bytes)),{anchor:toCardanoAnchor(e.anchor),scriptHash:t}},toCardanoWithdrawals=e=>{const t=new Set;for(const[r,o]of Object.entries(e)){const e=toAddress(r);if(!e)throw new Error(`Invalid reward address: ${r}`);const i=e.getType();if(i!==AddressType.RewardKey&&i!==AddressType.RewardScript)throw new Error(`Address is not a reward address: ${r}`);const a=BigInt(o);t.add({rewardAccount:RewardAccount(e.toBech32()),coin:a})}return t},toCardanoProposalProcedure=(e,t,r,o)=>{const i=toAddress(r);if(!i)throw new Error(`Invalid reward account: ${r}`);const a=i.getType();if(a!==AddressType.RewardKey&&a!==AddressType.RewardScript)throw new Error(`Address is not a reward address: ${r}`);const n=RewardAccount(i.toBech32()),s=toCardanoAnchor(t);let d;switch(e.kind){case"ParameterChangeAction":{const t=e.action;d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.parameter_change_action,governanceActionId:toCardanoGovernanceActionId(t.govActionId),protocolParamUpdate:toCardanoProtocolParamUpdate(t.protocolParamUpdates),policyHash:t.policyHash?Hash28ByteBase162(t.policyHash.bytes):null}};break}case"HardForkInitiationAction":{const t=e.action;d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.hard_fork_initiation_action,governanceActionId:toCardanoGovernanceActionId(t.govActionId),protocolVersion:{major:t.protocolVersion.major,minor:t.protocolVersion.minor}}};break}case"TreasuryWithdrawalsAction":{const t=e.action;d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.treasury_withdrawals_action,withdrawals:toCardanoWithdrawals(t.withdrawals),policyHash:t.policyHash?Hash28ByteBase162(t.policyHash.bytes):null}};break}case"NoConfidenceAction":{const t=e.action;d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.no_confidence,governanceActionId:toCardanoGovernanceActionId(t.govActionId)}};break}case"UpdateCommitteeAction":{const t=e.action,r=new Set;for(const e of t.membersToRemove)r.add(toCardanoCredential(e));const i=toCardanoCommittee(t.committee);d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.update_committee,governanceActionId:toCardanoGovernanceActionId(t.govActionId),membersToBeRemoved:r,membersToBeAdded:new Set(i.members),newQuorumThreshold:i.quorumThreshold}};break}case"NewConstitutionAction":{const t=e.action;d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.new_constitution,governanceActionId:toCardanoGovernanceActionId(t.govActionId),constitution:toCardanoConstitution(t.constitution)}};break}case"InfoAction":d={anchor:s,deposit:o,rewardAccount:n,governanceAction:{__typename:Cardano2.GovernanceActionType.info_action}};break}return Serialization4.ProposalProcedure.fromCore(d)},resolveDataHash=(e,t="Mesh")=>fromBuilderToPlutusData({content:e,type:t}).hash().toString(),resolveNativeScriptAddress=(e,t=0)=>{const r=toNativeScript(e);return EnterpriseAddress.fromCredentials(t,{hash:r.hash(),type:Cardano3.CredentialType.ScriptHash}).toAddress().toBech32().toString()},resolveNativeScriptHash=e=>toNativeScript(e).hash().toString(),resolvePaymentKeyHash=e=>{try{const t=[toBaseAddress(e)?.getPaymentCredential().hash,toEnterpriseAddress(e)?.getPaymentCredential().hash].find((e=>void 0!==e));if(void 0!==t)return t.toString();throw new Error(`Couldn't resolve payment key hash from address: ${e}`)}catch(e){throw new Error(`An error occurred during resolvePaymentKeyHash: ${e}.`)}},resolvePlutusScriptAddress=(e,t=0)=>{const r=deserializePlutusScript(e.code,e.version);return EnterpriseAddress.fromCredentials(t,{hash:r.hash(),type:Cardano3.CredentialType.ScriptHash}).toAddress().toBech32().toString()},resolvePlutusScriptHash=e=>{try{const t=toEnterpriseAddress(e),r=t?.getPaymentCredential().hash;if(void 0!==r)return r.toString();throw new Error(`Couldn't resolve script hash from address: ${e}`)}catch(e){throw new Error(`An error occurred during resolveScriptHash: ${e}.`)}},resolvePoolId=e=>PoolId.fromKeyHash(Ed25519KeyHashHex2(e)).toString(),resolvePrivateKey=e=>{const t=((e,t="")=>Bip32PrivateKey2.fromBip39Entropy(Buffer.from(toBytes4(e)),fromUTF8(t)))(mnemonicToEntropy(e.join(" "))),r=base323.encode(t.bytes());return bech323.encode("xprv",r,1023)},resolveScriptRef=e=>toScriptRef(e).toCbor().toString(),resolveRewardAddress=e=>{try{const t=toAddress(e),r=toBaseAddress(e),o=r?.getStakeCredential().hash;if(void 0!==o)return buildRewardAddress(t.getNetworkId(),o).toAddress().toBech32().toString();throw new Error(`Couldn't resolve reward address from address: ${e}`)}catch(e){throw new Error(`An error occurred during resolveRewardAddress: ${e}.`)}},resolveStakeKeyHash=e=>{try{const t=[toBaseAddress(e)?.getStakeCredential().hash,toRewardAddress(e)?.getPaymentCredential().hash].find((e=>void 0!==e));if(void 0!==t)return t.toString();throw new Error(`Couldn't resolve stake key hash from address: ${e}`)}catch(e){throw new Error(`An error occurred during resolveStakeKeyHash: ${e}.`)}},resolveTxHash=e=>deserializeTx(e).body().hash().toString(),resolveScriptHashDRepId=e=>DRepID.cip129FromCredential({type:Cardano3.CredentialType.ScriptHash,hash:Hash28ByteBase162(e)}).toString(),resolveEd25519KeyHash=e=>{try{const t=[toBaseAddress(e)?.getPaymentCredential().hash,toEnterpriseAddress(e)?.getPaymentCredential().hash].find((e=>void 0!==e));if(void 0!==t)return t.toString();throw new Error(`Couldn't resolve key hash from address: ${e}`)}catch(e){throw new Error(`An error occurred during resolveEd25519KeyHash: ${e}.`)}};import{Buffer as Buffer3}from"buffer";import{Serialization as Serialization8,setInConwayEra}from"@cardano-sdk/core";import{HexBlob as HexBlob8}from"@cardano-sdk/util";import{Cbor as Cbor2,CborArray as CborArray2,CborBytes as CborBytes3,CborString,CborTag,CborUInt as CborUInt3}from"@harmoniclabs/cbor";import base324 from"base32-encoding";import{bech32 as bech324}from"bech32";import{DEFAULT_PROTOCOL_PARAMETERS,DEFAULT_V1_COST_MODEL_LIST,DEFAULT_V2_COST_MODEL_LIST,DEFAULT_V3_COST_MODEL_LIST,fromUTF8 as fromUTF82,mnemonicToEntropy as mnemonicToEntropy2,toBytes as toBytes5}from"@meshsdk/common";import{Cardano as Cardano4,Serialization as Serialization5}from"@cardano-sdk/core";var toCardanoCert=e=>{switch(e.type){case"RegisterPool":{let t=[];for(const r of e.poolParams.relays)switch(r.type){case"SingleHostAddr":t.push(Serialization5.Relay.newSingleHostAddr(new Serialization5.SingleHostAddr(r.port,r.IPV4,r.IPV6)));break;case"SingleHostName":t.push(Serialization5.Relay.newSingleHostName(new Serialization5.SingleHostName(r.domainName,r.port)));break;case"MultiHostName":t.push(Serialization5.Relay.newMultiHostName(new Serialization5.MultiHostName(r.domainName)))}let r=Serialization5.CborSet.fromCore([],Serialization5.Hash.fromCore),o=[...r.values()];for(const t of e.poolParams.owners)o.push(Serialization5.Hash.fromCore(Ed25519KeyHashHex2(t)));r.setValues(o);const i=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.poolParams.rewardAddress));if(void 0===i)throw new Error("Error parsing reward address, it is expected to be in bech32 format");const a=e.poolParams.metadata?new Serialization5.PoolMetadata(e.poolParams.metadata.URL,Crypto2.Hash32ByteBase16(e.poolParams.metadata.hash)):void 0;return Certificate.newPoolRegistration(new Serialization5.PoolRegistration(new Serialization5.PoolParams(Ed25519KeyHashHex2(e.poolParams.operator),Cardano4.VrfVkHex(e.poolParams.vrfKeyHash),BigInt(e.poolParams.pledge),BigInt(e.poolParams.cost),new Serialization5.UnitInterval(BigInt(e.poolParams.margin[0]),BigInt(e.poolParams.margin[1])),i,r,t,a)))}case"RegisterStake":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");return Certificate.newStakeRegistration(new Serialization5.StakeRegistration(t.getPaymentCredential()))}case"DelegateStake":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");return Certificate.newStakeDelegation(new Serialization5.StakeDelegation(t.getPaymentCredential(),e.poolId.startsWith("pool1")?Cardano4.PoolId.toKeyHash(Cardano4.PoolId(e.poolId)):Ed25519KeyHashHex2(e.poolId)))}case"DeregisterStake":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");return Certificate.newStakeDeregistration(new Serialization5.StakeDeregistration(t.getPaymentCredential()))}case"RetirePool":return Certificate.newPoolRetirement(new Serialization5.PoolRetirement(e.poolId.startsWith("pool1")?Cardano4.PoolId.toKeyHash(Cardano4.PoolId(e.poolId)):Ed25519KeyHashHex2(e.poolId),Cardano4.EpochNo(e.epoch)));case"VoteDelegation":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");if(void 0!==e.drep.dRepId)return Certificate.newVoteDelegationCert(new Serialization5.VoteDelegation(t.getPaymentCredential(),toDRep(e.drep.dRepId)));if(void 0!==e.drep.alwaysAbstain)return Certificate.newVoteDelegationCert(new Serialization5.VoteDelegation(t.getPaymentCredential(),Serialization5.DRep.newAlwaysAbstain()));if(void 0!==e.drep.alwaysNoConfidence)return Certificate.newVoteDelegationCert(new Serialization5.VoteDelegation(t.getPaymentCredential(),Serialization5.DRep.newAlwaysNoConfidence()));throw new Error("Malformed DRep type")}case"StakeAndVoteDelegation":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");if(void 0!==e.drep.dRepId)return Certificate.newStakeVoteDelegationCert(new Serialization5.StakeVoteDelegation(t.getPaymentCredential(),toDRep(e.drep.dRepId),Ed25519KeyHashHex2(e.poolKeyHash)));if(void 0!==e.drep.alwaysAbstain)return Certificate.newStakeVoteDelegationCert(new Serialization5.StakeVoteDelegation(t.getPaymentCredential(),Serialization5.DRep.newAlwaysAbstain(),Ed25519KeyHashHex2(e.poolKeyHash)));if(void 0!==e.drep.alwaysNoConfidence)return Certificate.newStakeVoteDelegationCert(new Serialization5.StakeVoteDelegation(t.getPaymentCredential(),Serialization5.DRep.newAlwaysNoConfidence(),Ed25519KeyHashHex2(e.poolKeyHash)));throw new Error("Malformed DRep type")}case"StakeRegistrationAndDelegation":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");return Certificate.newStakeRegistrationDelegationCert(new Serialization5.StakeRegistrationDelegation(t.getPaymentCredential(),BigInt(e.coin),Ed25519KeyHashHex2(e.poolKeyHash)))}case"VoteRegistrationAndDelegation":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");if(void 0!==e.drep.dRepId)return Certificate.newVoteRegistrationDelegationCert(new Serialization5.VoteRegistrationDelegation(t.getPaymentCredential(),BigInt(e.coin),toDRep(e.drep.dRepId)));if(void 0!==e.drep.alwaysAbstain)return Certificate.newVoteRegistrationDelegationCert(new Serialization5.VoteRegistrationDelegation(t.getPaymentCredential(),BigInt(e.coin),Serialization5.DRep.newAlwaysAbstain()));if(void 0!==e.drep.alwaysNoConfidence)return Certificate.newVoteRegistrationDelegationCert(new Serialization5.VoteRegistrationDelegation(t.getPaymentCredential(),BigInt(e.coin),Serialization5.DRep.newAlwaysNoConfidence()));throw new Error("Malformed DRep type")}case"StakeVoteRegistrationAndDelegation":{const t=Cardano4.RewardAddress.fromAddress(Cardano4.Address.fromBech32(e.stakeKeyAddress));if(void 0===t)throw new Error("Error parsing reward address, it is expected to be in bech32 format");if(void 0!==e.drep.dRepId)return Certificate.newStakeVoteDelegationCert(new Serialization5.StakeVoteDelegation(t.getPaymentCredential(),toDRep(e.drep.dRepId),Ed25519KeyHashHex2(e.poolKeyHash)));if(void 0!==e.drep.alwaysAbstain)return Certificate.newStakeVoteDelegationCert(new Serialization5.StakeVoteDelegation(t.getPaymentCredential(),Serialization5.DRep.newAlwaysAbstain(),Ed25519KeyHashHex2(e.poolKeyHash)));if(void 0!==e.drep.alwaysNoConfidence)return Certificate.newStakeVoteDelegationCert(new Serialization5.StakeVoteDelegation(t.getPaymentCredential(),Serialization5.DRep.newAlwaysNoConfidence(),Ed25519KeyHashHex2(e.poolKeyHash)));throw new Error("Malformed DRep type")}case"CommitteeHotAuth":{const t=Cardano4.Address.fromBech32(e.committeeHotKeyAddress).getProps().paymentPart,r=Cardano4.Address.fromBech32(e.committeeColdKeyAddress).getProps().paymentPart;if(!t||!r)throw new Error("Malformed hot/cold credential");return Certificate.newAuthCommitteeHotCert(new Serialization5.AuthCommitteeHot(r,t))}case"CommitteeColdResign":{const t=Cardano4.Address.fromBech32(e.committeeColdKeyAddress).getProps().paymentPart;if(!t)throw new Error("Malformed hot/cold credential");let r;return e.anchor&&(r=new Serialization5.Anchor(e.anchor.anchorUrl,Hash32ByteBase162(e.anchor.anchorDataHash))),Certificate.newResignCommitteeColdCert(new Serialization5.ResignCommitteeCold(t,r))}case"DRepRegistration":{let t;e.anchor&&(t=new Serialization5.Anchor(e.anchor.anchorUrl,Hash32ByteBase162(e.anchor.anchorDataHash)));const r=toDRep(e.drepId).toCore();if(Cardano4.isDRepCredential(r))return Certificate.newRegisterDelegateRepresentativeCert(new Serialization5.RegisterDelegateRepresentative(r,BigInt(e.coin),t));throw new Error("DRepId must be a Credential")}case"DRepDeregistration":{const t=toDRep(e.drepId).toCore();if(Cardano4.isDRepCredential(t))return Certificate.newUnregisterDelegateRepresentativeCert(new Serialization5.UnregisterDelegateRepresentative(t,BigInt(e.coin)));throw new Error("DRepId must be a Credential")}case"DRepUpdate":{let t;e.anchor&&(t=new Serialization5.Anchor(e.anchor.anchorUrl,Hash32ByteBase162(e.anchor.anchorDataHash)));const r=toDRep(e.drepId).toCore();if(Cardano4.isDRepCredential(r))return Certificate.newUpdateDelegateRepresentativeCert(new Serialization5.UpdateDelegateRepresentative(r,t));throw new Error("DRepId must be a Credential")}}},toCardanoMetadataMap=e=>{let t=new Map;return e.forEach(((e,r)=>{t.set(r,toCardanoMetadatum(e))})),t},toCardanoMetadatum=e=>{if("number"==typeof e)return TransactionMetadatum.newInteger(BigInt(e));if("string"==typeof e)return TransactionMetadatum.newText(e);if("bigint"==typeof e)return TransactionMetadatum.newInteger(e);if(e instanceof Uint8Array)return TransactionMetadatum.newBytes(e);if(e instanceof Map){const t=new MetadatumMap;return e.forEach(((e,r)=>{t.insert(toCardanoMetadatum(r),toCardanoMetadatum(e))})),TransactionMetadatum.newMap(t)}if(Array.isArray(e)){const t=new MetadatumList;return e.forEach((e=>{t.add(toCardanoMetadatum(e))})),TransactionMetadatum.newList(t)}throw new Error("metadatumToObj: Unsupported Metadatum type")},import_blake2b2=__toESM(require_blake2b2(),1);import{Serialization as Serialization6}from"@cardano-sdk/core";import{Hash32ByteBase16 as Hash32ByteBase163}from"@cardano-sdk/crypto";import{HexBlob as HexBlob7}from"@cardano-sdk/util";var CBOR_EMPTY_MAP=new Uint8Array([160]),hashScriptData=(e,t,r)=>{const o=new Serialization6.CborWriter;if(r&&r.size()>0&&(!t||0===t.size()))o.writeEncodedValue(CBOR_EMPTY_MAP),o.writeEncodedValue(Buffer.from(r.toCbor(),"hex")),o.writeEncodedValue(CBOR_EMPTY_MAP);else{if(!t||0===t.size())return;o.writeEncodedValue(Buffer.from(t.toCbor(),"hex")),r&&r.size()>0&&o.writeEncodedValue(Buffer.from(r.toCbor(),"hex")),o.writeEncodedValue(Buffer.from(e.languageViewsEncoding(),"hex"))}const i=(0,import_blake2b2.default)(32).update(Buffer.from(o.encode())).digest("hex");return Hash32ByteBase163.fromHexBlob(HexBlob7(i))};import{Cardano as Cardano6,Serialization as Serialization7}from"@cardano-sdk/core";var toCardanoVoter=e=>{switch(e.type){case"ConstitutionalCommittee":switch(e.hotCred.type){case"KeyHash":return Serialization7.Voter.newConstitutionalCommitteeHotKey({type:0,hash:Hash28ByteBase162(e.hotCred.keyHash)});case"ScriptHash":return Serialization7.Voter.newConstitutionalCommitteeHotKey({type:1,hash:Hash28ByteBase162(e.hotCred.scriptHash)})}case"DRep":{const t=toDRep(e.drepId);if(void 0!==t.toKeyHash())return Serialization7.Voter.newDrep({type:0,hash:Hash28ByteBase162(t.toKeyHash())});if(void 0!==t.toScriptHash())return Serialization7.Voter.newDrep({type:1,hash:Hash28ByteBase162(t.toScriptHash())});throw new Error("Invalid DRep provided")}case"StakingPool":return Serialization7.Voter.newStakingPool(Ed25519KeyHashHex2(e.keyHash))}},toCardanoVotingProcedure=e=>new Serialization7.VotingProcedure(toCardanoVoteKind(e.voteKind),e.anchor?toCardanoAnchor2(e.anchor):void 0),toCardanoAnchor2=e=>new Serialization7.Anchor(e.anchorUrl,Hash32ByteBase162(e.anchorDataHash)),toCardanoVoteKind=e=>{switch(e){case"Yes":return 1;case"No":return 0;case"Abstain":return 2}},toCardanoGovernanceActionId2=e=>new Serialization7.GovernanceActionId(Cardano6.TransactionId(e.txHash),BigInt(e.txIndex)),VKEY_PUBKEY_SIZE_BYTES=32,VKEY_SIGNATURE_SIZE_BYTES=64,CHAIN_CODE_SIZE_BYTES=32,CardanoSDKSerializer=class{protocolParams;constructor(e){setInConwayEra(!0),this.protocolParams=e||DEFAULT_PROTOCOL_PARAMETERS}serializeRewardAddress(e,t,r){return RewardAddress.fromCredentials(r??0,{type:t?CredentialType.ScriptHash:CredentialType.KeyHash,hash:Hash28ByteBase162(e)}).toAddress().toBech32()}serializePoolId(e){return PoolId.fromKeyHash(Ed25519KeyHashHex2(e)).toString()}serializeAddress(e,t){let r,o;e.pubKeyHash&&""!==e.pubKeyHash?r={type:CredentialType.KeyHash,hash:Hash28ByteBase162(e.pubKeyHash)}:e.scriptHash&&""!==e.scriptHash&&(r={type:CredentialType.ScriptHash,hash:Hash28ByteBase162(e.scriptHash)}),e.stakeCredentialHash&&""!==e.stakeCredentialHash?o={type:CredentialType.KeyHash,hash:Hash28ByteBase162(e.stakeCredentialHash)}:e.stakeScriptCredentialHash&&(o={type:CredentialType.ScriptHash,hash:Hash28ByteBase162(e.stakeScriptCredentialHash)});let i=AddressType.BasePaymentKeyStakeKey;return r&&o?r.type===CredentialType.KeyHash&&o.type===CredentialType.KeyHash?i=AddressType.BasePaymentKeyStakeKey:r.type===CredentialType.KeyHash&&o.type===CredentialType.ScriptHash?i=AddressType.BasePaymentKeyStakeScript:r.type===CredentialType.ScriptHash&&o.type===CredentialType.KeyHash?i=AddressType.BasePaymentScriptStakeKey:r.type===CredentialType.ScriptHash&&o.type===CredentialType.ScriptHash&&(i=AddressType.BasePaymentScriptStakeScript):r?r.type===CredentialType.KeyHash?i=AddressType.EnterpriseKey:r.type===CredentialType.ScriptHash&&(i=AddressType.EnterpriseScript):o&&(o.type===CredentialType.KeyHash?i=AddressType.RewardKey:o.type===CredentialType.ScriptHash&&(i=AddressType.RewardScript)),new Address({type:i,networkId:t??0,paymentPart:r,delegationPart:o}).toBech32()}serializeData(e){return fromBuilderToPlutusData(e).toCbor().toString()}deserializer={key:{deserializeAddress:function(e){const t=Address.fromBech32(e).getProps();return{pubKeyHash:t.paymentPart?.type===CredentialType.KeyHash?t.paymentPart?.hash??"":"",scriptHash:t.paymentPart?.type===CredentialType.ScriptHash?t.paymentPart?.hash??"":"",stakeCredentialHash:t.delegationPart?.type===CredentialType.KeyHash?t.paymentPart?.hash??"":"",stakeScriptCredentialHash:t.delegationPart?.type===CredentialType.ScriptHash?t.paymentPart?.hash??"":""}}},script:{deserializeNativeScript:function(e){const t=toNativeScript(e);return{scriptHash:t.hash().toString(),scriptCbor:t.toCbor().toString()}},deserializePlutusScript:function(e){let t;switch(e.version){case"V1":t=new PlutusV1Script(HexBlob8(e.code));break;case"V2":t=new PlutusV2Script(HexBlob8(e.code));break;case"V3":t=new PlutusV3Script(HexBlob8(e.code))}return{scriptHash:t.hash().toString(),scriptCbor:t.toCbor().toString()}}},cert:{deserializePoolId:function(e){const t=PoolId(e);return PoolId.toKeyHash(t).toString()}}};resolver={keys:{resolveStakeKeyHash:function(e){const t=toAddress(e);return t.asReward()?.getPaymentCredential().type===CredentialType.KeyHash?t.asReward().getPaymentCredential().hash:""},resolvePrivateKey:function(e){const t=((e,t="")=>Bip32PrivateKey2.fromBip39Entropy(Buffer3.from(toBytes5(e)),fromUTF82(t)))(mnemonicToEntropy2(e.join(" "))),r=base324.encode(t.bytes());return bech324.encode("xprv",r,1023)},resolveRewardAddress:function(e){const t=toAddress(e),r=t.getProps();return r.delegationPart?RewardAddress.fromCredentials(t.getNetworkId(),r.delegationPart).toAddress().toBech32()??"":""},resolveEd25519KeyHash:function(e){const t=toAddress(e).getProps();return t.paymentPart?t.paymentPart.hash.toString():""}},tx:{resolveTxHash:function(e){return Transaction.fromCbor(Serialization8.TxCBOR(e)).getId()}},data:{resolveDataHash:function(e,t="Mesh"){return resolveDataHash(e,t)}},script:{resolveScriptRef:function(e){if("code"in e){let t;switch(e.version){case"V1":t=1;break;case"V2":t=2;break;case"V3":t=3}let r=new CborTag(24,Cbor2.parse(CborString.fromCborObj(new CborBytes3(Cbor2.encode(new CborArray2([new CborUInt3(t),new CborString(e.code).toCborObj()])).toBuffer()))));return Cbor2.encode(r).toString()}{const t=toNativeScript(e);let r=new CborTag(24,Cbor2.parse(CborString.fromCborObj(new CborBytes3(Cbor2.encode(new CborArray2([new CborUInt3(0),new CborString(t.toCbor()).toCborObj()])).toBuffer()))));return Cbor2.encode(r).toString()}}}};serializeTxBody=(e,t)=>new CardanoSDKSerializerCore(t??this.protocolParams).coreSerializeTx(e);serializeTxBodyWithMockSignatures(e,t){return new CardanoSDKSerializerCore(t).coreSerializeTxWithMockSignatures(e)}addSigningKeys=(e,t)=>{let r=Transaction.fromCbor(Serialization8.TxCBOR(e)),o=r.witnessSet(),i=o.vkeys(),a=i?[...i.values()]:[];for(let e=0;e<t.length;e++){let o=t[e];if(o){68===o.length&&"5820"===o.substring(0,4)&&(o=o.substring(4));const e=buildEd25519PrivateKeyFromSecretKey(o),t=e.sign(HexBlob8(r.getId()));a.push(new VkeyWitness(Ed25519PublicKeyHex2(e.toPublic().hex()),Ed25519SignatureHex2(t.hex())))}}return o.setVkeys(Serialization8.CborSet.fromCore(a.map((e=>e.toCore())),VkeyWitness.fromCore)),r.setWitnessSet(o),r.toCbor()};serializeValue(e){return toValue(e).toCbor()}serializeOutput(e){let t=new TransactionOutput(toCardanoAddress(e.address),toValue(e.amount));if("Hash"===e.datum?.type?t.setDatum(Datum.newDataHash(fromBuilderToPlutusData(e.datum.data).hash())):"Inline"===e.datum?.type?t.setDatum(Datum.newInlineData(fromBuilderToPlutusData(e.datum.data))):"Embedded"===e.datum?.type&&t.setDatum(Datum.newDataHash(fromBuilderToPlutusData(e.datum.data).hash())),e.referenceScript)switch(e.referenceScript.version){case"V1":t.setScriptRef(Script.newPlutusV1Script(PlutusV1Script.fromCbor(HexBlob8(e.referenceScript.code))));break;case"V2":t.setScriptRef(Script.newPlutusV2Script(PlutusV2Script.fromCbor(HexBlob8(e.referenceScript.code))));break;case"V3":t.setScriptRef(Script.newPlutusV3Script(PlutusV3Script.fromCbor(HexBlob8(e.referenceScript.code))));break;default:t.setScriptRef(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(e.referenceScript.code))))}return t.toCbor()}parser={getRequiredInputs:function(e){throw new Error("Function not implemented.")},parse:function(e,t){throw new Error("Method not implemented.")},toTester:function(){throw new Error("Method not implemented.")},getBuilderBody:function(){throw new Error("Method not implemented.")},getBuilderBodyWithoutChange:function(){throw new Error("Method not implemented.")}}},CardanoSDKSerializerCore=class{txBody;txWitnessSet;txAuxilliaryData;utxoContext=new Map;mintRedeemers=new Map;scriptsProvided=new Set;datumsProvided=new Set;usedLanguages={0:!1,1:!1,2:!1};protocolParams;refScriptSize;constructor(e){this.protocolParams=e||DEFAULT_PROTOCOL_PARAMETERS,this.txBody=new TransactionBody(Serialization8.CborSet.fromCore([],TransactionInput.fromCore),[],BigInt(0),void 0),this.refScriptSize=0,this.txWitnessSet=new TransactionWitnessSet,this.txAuxilliaryData=new AuxilliaryData}coreSerializeTxBody=e=>{const{inputs:t,outputs:r,collaterals:o,requiredSignatures:i,referenceInputs:a,mints:n,metadata:s,scriptMetadata:d,validityRange:u,certificates:c,withdrawals:l,votes:p,proposals:h,totalCollateral:A,collateralReturnAddress:f,changeAddress:g}=e,I=this.removeBodyInputRefInputOverlap(t,a);try{this.addAllInputs(t)}catch(e){throwErrorWithOrigin("Error serializing inputs",e)}try{this.setFee(e.fee??"0")}catch(e){throwErrorWithOrigin("Error serializing fee",e)}try{this.sanitizeOutputs(r)}catch(e){throwErrorWithOrigin("Error calculating min utxo values for outputs",e)}try{this.addAllOutputs(r)}catch(e){throwErrorWithOrigin("Error serializing outputs",e)}try{this.addAllMints(n)}catch(e){throwErrorWithOrigin("Error serializing mints",e)}try{this.addAllCerts(c)}catch(e){throwErrorWithOrigin("Error serializing certificates",e)}try{this.addAllWithdrawals(l)}catch(e){throwErrorWithOrigin("Error serializing withdrawals",e)}try{this.addAllVotes(p)}catch(e){throwErrorWithOrigin("Error serializing votes",e)}try{this.addAllProposals(h)}catch(e){throwErrorWithOrigin("Error serializing proposals",e)}try{this.addAllCollateralInputs(o)}catch(e){throwErrorWithOrigin("Error serializing collateral inputs",e)}if(A)try{this.txBody.setTotalCollateral(BigInt(A)),this.addCollateralReturn(A,o,f??g)}catch(e){throwErrorWithOrigin("Error serializing total collateral and collateral return",e)}try{this.addAllReferenceInputs(I)}catch(e){throwErrorWithOrigin("Error serializing reference inputs",e)}this.removeInputRefInputOverlap();try{this.setValidityInterval(u)}catch(e){throwErrorWithOrigin("Error serializing validity interval",e)}try{this.addAllRequiredSignatures(i)}catch(e){throwErrorWithOrigin("Error serializing required signatures",e)}if(s.size>0)try{this.addMetadata(s)}catch(e){throwErrorWithOrigin("Error serializing metadata",e)}try{this.addScriptMetadata(d)}catch(e){throwErrorWithOrigin("Error serializing script metadata",e)}return this.txBody};coreSerializeTx(e){const t=this.coreSerializeTxBody(e);return void 0!==e.fee&&this.txBody.setFee(BigInt(e.fee)),this.buildWitnessSet(),new Transaction(t,this.txWitnessSet,this.txAuxilliaryData).toCbor()}coreSerializeTxWithMockSignatures(e){const t=this.coreSerializeTxBody(e),r=this.createMockedWitnessSet(e.expectedNumberKeyWitnesses,e.expectedByronAddressWitnesses);return new Transaction(t,r,this.txAuxilliaryData).toCbor()}sanitizeOutputs=e=>{for(let t=0;t<e.length;t++){let r=e[t],o=!1;for(let e=0;e<r.amount.length;e++){let t=r.amount[e];if((""==t?.unit||"lovelace"==t?.unit)&&(o=!0,"0"==t?.quantity||""==t?.quantity)){t.unit="lovelace",t.quantity="10000000";let e=(160+this.toCardanoOutput(r).toCbor().length/2+1)*this.protocolParams.coinsPerUtxoSize;t.quantity=e.toString()}}if(!o){let e={unit:"lovelace",quantity:"10000000"};r.amount.push(e);let t=(160+this.toCardanoOutput(r).toCbor().length/2+1)*this.protocolParams.coinsPerUtxoSize;if(e.quantity=t.toString(),!o){let e={unit:"lovelace",quantity:"10000000"};r.amount.push(e);let t=(160+this.toCardanoOutput(r).toCbor().length/2+1)*this.protocolParams.coinsPerUtxoSize;e.quantity=t.toString()}}}};addAllInputs=e=>{for(let t=0;t<e.length;t+=1){const r=e[t];if(r)switch(r.type){case"PubKey":this.addTxIn(r);break;case"Script":this.addScriptTxIn(r,t);break;case"SimpleScript":this.addSimpleScriptTxIn(r)}}};addTxIn=e=>{let t=new TransactionInput(TransactionId(e.txIn.txHash),BigInt(e.txIn.txIndex));const r=this.txBody.inputs(),o=[...r.values()];if(o.find((e=>{e.index()==t.index()&&(e.transactionId,t.transactionId)})))throw new Error("Duplicate input added to tx body");o.push(t),r.setValues(o);const i=new TransactionOutput(toCardanoAddress(e.txIn.address),toValue(e.txIn.amount));this.utxoContext.set(t,i),this.txBody.setInputs(r),e.txIn.scriptSize&&(this.refScriptSize+=e.txIn.scriptSize)};addScriptTxIn=(e,t)=>{if(this.addTxIn({type:"PubKey",txIn:e.txIn}),!e.scriptTxIn.scriptSource)throw new Error("A script input had no script source");if(!e.scriptTxIn.datumSource)throw new Error("A script input had no datum source");if(!e.scriptTxIn.redeemer)throw new Error("A script input had no redeemer");"Provided"===e.scriptTxIn.scriptSource.type?this.addProvidedPlutusScript(e.scriptTxIn.scriptSource.script):"Inline"===e.scriptTxIn.scriptSource.type&&this.addScriptRef(e.scriptTxIn.scriptSource),"Provided"===e.scriptTxIn.datumSource.type?this.datumsProvided.add(fromBuilderToPlutusData(e.scriptTxIn.datumSource.data)):"Inline"===e.scriptTxIn.datumSource.type&&this.addReferenceInput({txHash:e.txIn.txHash,txIndex:e.txIn.txIndex});let r=e.scriptTxIn.redeemer.exUnits,o=this.txWitnessSet.redeemers()??Redeemers.fromCore([]),i=[...o.values()];i.push(new Redeemer(RedeemerTag.Spend,BigInt(t),fromBuilderToPlutusData(e.scriptTxIn.redeemer.data),new ExUnits(BigInt(r.mem),BigInt(r.steps)))),o.setValues(i),this.txWitnessSet.setRedeemers(o)};addSimpleScriptTxIn=e=>{if(this.addTxIn({type:"PubKey",txIn:e.txIn}),!e.simpleScriptTxIn.scriptSource)throw new Error("A native script input had no script source");"Provided"===e.simpleScriptTxIn.scriptSource.type?this.scriptsProvided.add(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(e.simpleScriptTxIn.scriptSource.scriptCode))).toCbor()):"Inline"===e.simpleScriptTxIn.scriptSource.type&&this.addSimpleScriptRef(e.simpleScriptTxIn.scriptSource)};addAllOutputs=e=>{for(let t=0;t<e.length;t++)this.addOutput(e[t])};addOutput=e=>{const t=this.txBody.outputs();t.push(this.toCardanoOutput(e)),this.txBody.setOutputs(t)};toCardanoOutput=e=>{let t=new TransactionOutput(toCardanoAddress(e.address),toValue(e.amount));if("Hash"===e.datum?.type)t.setDatum(Datum.newDataHash(DatumHash(fromBuilderToPlutusData(e.datum.data).hash())));else if("Inline"===e.datum?.type)t.setDatum(Datum.newInlineData(fromBuilderToPlutusData(e.datum.data)));else if("Embedded"===e.datum?.type){t.setDatum(Datum.newDataHash(DatumHash(fromBuilderToPlutusData(e.datum.data).hash())));const r=this.txWitnessSet.plutusData()??Serialization8.CborSet.fromCore([],Serialization8.PlutusData.fromCore),o=[...r.values()];o.push(fromBuilderToPlutusData(e.datum.data)),r.setValues(o),this.txWitnessSet.setPlutusData(r)}if(e.referenceScript)switch(e.referenceScript.version){case"V1":t.setScriptRef(Script.newPlutusV1Script(PlutusV1Script.fromCbor(HexBlob8(e.referenceScript.code))));break;case"V2":t.setScriptRef(Script.newPlutusV2Script(PlutusV2Script.fromCbor(HexBlob8(e.referenceScript.code))));break;case"V3":t.setScriptRef(Script.newPlutusV3Script(PlutusV3Script.fromCbor(HexBlob8(e.referenceScript.code))))}return t};addAllReferenceInputs=e=>{for(let t=0;t<e.length;t++)this.addReferenceInput(e[t])};addReferenceInput=e=>{let t=this.txBody.referenceInputs()??Serialization8.CborSet.fromCore([],TransactionInput.fromCore),r=[...t.values()];r.some((t=>t.transactionId().toString()===e.txHash&&t.index().toString()===e.txIndex.toString()))||(r.push(new TransactionInput(TransactionId(e.txHash),BigInt(e.txIndex))),t.setValues(r),e.scriptSize&&(this.refScriptSize+=e.scriptSize),this.txBody.setReferenceInputs(t))};addAllMints=e=>{for(let t=0;t<e.length;t++)this.addMint(e[t]);let t=this.txWitnessSet.redeemers()??Redeemers.fromCore([]),r=[...t.values()],o=0;this.mintRedeemers.forEach((e=>{const i=new Redeemer(e.tag(),BigInt(o),e.data(),e.exUnits());r.push(i),t.setValues(r),o++})),this.txWitnessSet.setRedeemers(t)};addMint=e=>{const t=this.txBody.mint()??new Map;for(const r of e.mintValue){const o=`${e.policyId}${r.assetName}`;for(const e of t.keys())if(e.toString()==o)throw new Error("The same asset is already in the mint field");t.set(AssetId.fromParts(PolicyId(e.policyId),AssetName(r.assetName)),BigInt(r.amount))}if(this.txBody.setMint(t),"Native"===e.type){if(!e.scriptSource)throw new Error("Script source not provided for native script mint");const t=e.scriptSource;if(!t)throw new Error("A script source for a native script was not a native script somehow");"Provided"===t.type?this.scriptsProvided.add(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(t.scriptCode))).toCbor()):"Inline"===t.type&&this.addSimpleScriptRef(t)}else if("Plutus"===e.type){if(!e.scriptSource)throw new Error("Script source not provided for plutus script mint");const t=e.scriptSource;if(!t)throw new Error("A script source for a plutus mint was not plutus script somehow");if(!e.redeemer)throw new Error("A redeemer was not provided for a plutus mint");const r=new Redeemer(RedeemerTag.Mint,BigInt(0),fromBuilderToPlutusData(e.redeemer.data),new ExUnits(BigInt(e.redeemer.exUnits.mem),BigInt(e.redeemer.exUnits.steps)));if(this.mintRedeemers.has(e.policyId)){if(this.mintRedeemers.get(e.policyId)?.toCbor()!==r.toCbor())throw new Error("The same minting policy must have the same redeemer")}else this.mintRedeemers.set(e.policyId,r);"Provided"===t.type?this.addProvidedPlutusScript(t.script):"Inline"===t.type&&this.addScriptRef(t)}};addAllCerts=e=>{for(let t=0;t<e.length;t++)this.addCert(e[t],t)};addCert=(e,t)=>{const r=this.txBody.certs()??Serialization8.CborSet.fromCore([],Serialization8.Certificate.fromCore);let o=[...r.values()];if(o.push(toCardanoCert(e.certType)),r.setValues(o),this.txBody.setCerts(r),"SimpleScriptCertificate"===e.type){if(!e.simpleScriptSource)throw new Error("Script source not provided for native script cert");const t=e.simpleScriptSource;if(!t)throw new Error("A script source for a native script was not a native script somehow");"Provided"===t.type?this.scriptsProvided.add(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(t.scriptCode))).toCbor()):"Inline"===t.type&&this.addSimpleScriptRef(t)}else if("ScriptCertificate"===e.type){if(!e.scriptSource)throw new Error("Script source not provided for plutus script certificate");const r=e.scriptSource;if(!r)throw new Error("A script source for a plutus certificate was not plutus script somehow");if(!e.redeemer)throw new Error("A redeemer was not provided for a plutus certificate");let o=this.txWitnessSet.redeemers()??Redeemers.fromCore([]),i=[...o.values()];i.push(new Redeemer(RedeemerTag.Cert,BigInt(t),fromBuilderToPlutusData(e.redeemer.data),new ExUnits(BigInt(e.redeemer.exUnits.mem),BigInt(e.redeemer.exUnits.steps)))),o.setValues(i),this.txWitnessSet.setRedeemers(o),"Provided"===r.type?this.addProvidedPlutusScript(r.script):"Inline"===r.type&&this.addScriptRef(r)}};addAllWithdrawals=e=>{for(let t=0;t<e.length;t++)this.addWithdrawal(e[t],t)};addWithdrawal=(e,t)=>{const r=this.txBody.withdrawals()??new Map,o=toCardanoAddress(e.address),i=o.asReward();if(!i)throw new Error("Failed to parse reward address for withdrawal");if(r.set(RewardAccount.fromCredential(i.getPaymentCredential(),o.getNetworkId()),BigInt(e.coin)),this.txBody.setWithdrawals(r),"SimpleScriptWithdrawal"===e.type){if(!e.scriptSource)throw new Error("Script source not provided for native script cert");const t=e.scriptSource;if(!t)throw new Error("A script source for a native script was not a native script somehow");"Provided"===t.type?this.scriptsProvided.add(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(t.scriptCode))).toCbor()):"Inline"===t.type&&this.addSimpleScriptRef(t)}else if("ScriptWithdrawal"===e.type){if(!e.scriptSource)throw new Error("Script source not provided for plutus script certificate");const r=e.scriptSource;if(!r)throw new Error("A script source for a plutus certificate was not plutus script somehow");if(!e.redeemer)throw new Error("A redeemer was not provided for a plutus certificate");let o=this.txWitnessSet.redeemers()??Redeemers.fromCore([]),i=[...o.values()];i.push(new Redeemer(RedeemerTag.Reward,BigInt(t),fromBuilderToPlutusData(e.redeemer.data),new ExUnits(BigInt(e.redeemer.exUnits.mem),BigInt(e.redeemer.exUnits.steps)))),o.setValues(i),this.txWitnessSet.setRedeemers(o),"Provided"===r.type?this.addProvidedPlutusScript(r.script):"Inline"===r.type&&this.addScriptRef(r)}};addAllCollateralInputs=e=>{for(let t=0;t<e.length;t++)this.addCollateralInput(e[t])};addCollateralInput=e=>{let t=new TransactionInput(TransactionId(e.txIn.txHash),BigInt(e.txIn.txIndex));const r=this.txBody.collateral()??Serialization8.CborSet.fromCore([],TransactionInput.fromCore),o=[...r.values()];if(o.find((e=>{e.index()==t.index()&&(e.transactionId,t.transactionId)})))throw new Error("Duplicate input added to tx body");o.push(t),r.setValues(o);const i=new TransactionOutput(toCardanoAddress(e.txIn.address),toValue(e.txIn.amount));this.utxoContext.set(t,i),this.txBody.setCollateral(r)};addCollateralReturn=(e,t,r)=>{let o=Value.fromCore({coins:-BigInt(e)});for(const e of t)o=mergeValue(o,toValue(e.txIn.amount));const i=new TransactionOutput(toCardanoAddress(r),o);this.txBody.setCollateralReturn(i)};setValidityInterval=e=>{e.invalidBefore&&this.txBody.setValidityStartInterval(Slot(e.invalidBefore)),e.invalidHereafter&&this.txBody.setTtl(Slot(e.invalidHereafter))};setFee=e=>{this.txBody.setFee(BigInt(e))};addAllRequiredSignatures=e=>{const t=this.txBody.requiredSigners()??Serialization8.CborSet.fromCore([],Serialization8.Hash.fromCore);let r=[...t.values()];for(const t of e)r.push(Serialization8.Hash.fromCore(Ed25519KeyHashHex2(t)));t.setValues(r),this.txBody.setRequiredSigners(t)};addMetadata=e=>{this.txAuxilliaryData.setMetadata(new Serialization8.GeneralTransactionMetadata(toCardanoMetadataMap(e)))};addScriptMetadata=e=>{let t=[],r=[],o=[],i=[];for(let a of e)switch(a.scriptType){case"Native":t.push(NativeScript.fromCbor(HexBlob8(a.scriptCbor)));break;case"PlutusV1":r.push(PlutusV1Script.fromCbor(HexBlob8(a.scriptCbor)));break;case"PlutusV2":o.push(PlutusV2Script.fromCbor(HexBlob8(a.scriptCbor)));break;case"PlutusV3":i.push(PlutusV3Script.fromCbor(HexBlob8(a.scriptCbor)))}this.txAuxilliaryData.setNativeScripts(t),this.txAuxilliaryData.setPlutusV1Scripts(r),this.txAuxilliaryData.setPlutusV2Scripts(o),this.txAuxilliaryData.setPlutusV3Scripts(i)};createMockedWitnessSet=(e,t)=>{this.buildWitnessSet();const r=TransactionWitnessSet.fromCbor(this.txWitnessSet.toCbor()),o=this.mockBootstrapWitnesses(t),i=this.mockVkeyWitnesses(e),a=CborSet.fromCore([],BootstrapWitness.fromCore);a.setValues(o),r.setBootstraps(a);const n=CborSet.fromCore([],VkeyWitness.fromCore);return n.setValues(i),r.setVkeys(n),r};buildWitnessSet=()=>{let e=this.txWitnessSet.nativeScripts()??Serialization8.CborSet.fromCore([],NativeScript.fromCore),t=this.txWitnessSet.plutusV1Scripts()??Serialization8.CborSet.fromCore([],PlutusV1Script.fromCore),r=this.txWitnessSet.plutusV2Scripts()??Serialization8.CborSet.fromCore([],PlutusV2Script.fromCore),o=this.txWitnessSet.plutusV3Scripts()??Serialization8.CborSet.fromCore([],PlutusV3Script.fromCore);this.scriptsProvided.forEach((i=>{const a=Script.fromCbor(HexBlob8(i));if(void 0!==a.asNative()){let t=[...e.values()];t.push(a.asNative()),e.setValues(t)}else if(void 0!==a.asPlutusV1()){let e=[...t.values()];e.push(a.asPlutusV1()),t.setValues(e)}else if(void 0!==a.asPlutusV2()){let e=[...r.values()];e.push(a.asPlutusV2()),r.setValues(e)}else if(void 0!==a.asPlutusV3()){let e=[...o.values()];e.push(a.asPlutusV3()),o.setValues(e)}this.txWitnessSet.setNativeScripts(e),this.txWitnessSet.setPlutusV1Scripts(t),this.txWitnessSet.setPlutusV2Scripts(r),this.txWitnessSet.setPlutusV3Scripts(o)}));let i=this.txWitnessSet.plutusData()??Serialization8.CborSet.fromCore([],PlutusData.fromCore),a=[...i.values()];this.datumsProvided.forEach((e=>{a.push(e)})),i.setValues(a),this.txWitnessSet.setPlutusData(i);let n=Serialization8.CostModel.newPlutusV1(DEFAULT_V1_COST_MODEL_LIST),s=Serialization8.CostModel.newPlutusV2(DEFAULT_V2_COST_MODEL_LIST),d=Serialization8.CostModel.newPlutusV3(DEFAULT_V3_COST_MODEL_LIST),u=new Serialization8.Costmdls;this.usedLanguages[PlutusLanguageVersion.V1]&&u.insert(n),this.usedLanguages[PlutusLanguageVersion.V2]&&u.insert(s),this.usedLanguages[PlutusLanguageVersion.V3]&&u.insert(d);const c=this.txWitnessSet.redeemers()??Redeemers.fromCore([]);let l=hashScriptData(u,c,i.size()>0?i:void 0);l&&this.txBody.setScriptDataHash(l);let p=computeAuxiliaryDataHash(this.txAuxilliaryData.toCore());p&&this.txBody.setAuxiliaryDataHash(p)};removeInputRefInputOverlap=()=>{let e=[];const t=this.txBody.inputs()?.values();if(this.txBody.referenceInputs()){this.txBody.referenceInputs().values().forEach((r=>{let o=!1;for(let e=0;e<t.length;e++)r.toCbor()===t[e].toCbor()&&(o=!0);o||e.push(r)})),this.txBody.setReferenceInputs(Serialization8.CborSet.fromCore(e.map((e=>e.toCore())),TransactionInput.fromCore))}};removeBodyInputRefInputOverlap=(e,t)=>{let r=[];for(let o=0;o<t.length;o++){let i=t[o];e.some((e=>e.txIn.txHash===i.txHash&&e.txIn.txIndex===i.txIndex))||r.push(i)}return r};addScriptRef=e=>{if("Inline"===e.type){if(!e.scriptSize)throw new Error("A reference script was used without providing its size, this must be provided as fee calculations are based on it");switch(this.addReferenceInput({txHash:e.txHash,txIndex:e.txIndex,scriptSize:Number(e.scriptSize)}),e.version){case"V1":this.usedLanguages[PlutusLanguageVersion.V1]=!0;break;case"V2":this.usedLanguages[PlutusLanguageVersion.V2]=!0;break;case"V3":this.usedLanguages[PlutusLanguageVersion.V3]=!0}}};addSimpleScriptRef=e=>{if("Inline"===e.type){if(!e.scriptSize)throw new Error("A reference script was used without providing its size, this must be provided as fee calculations are based on it");this.addReferenceInput({txHash:e.txHash,txIndex:e.txIndex,scriptSize:Number(e.scriptSize)})}};addProvidedPlutusScript=e=>{switch(e.version){case"V1":this.scriptsProvided.add(Script.newPlutusV1Script(PlutusV1Script.fromCbor(HexBlob8(e.code))).toCbor()),this.usedLanguages[PlutusLanguageVersion.V1]=!0;break;case"V2":this.scriptsProvided.add(Script.newPlutusV2Script(PlutusV2Script.fromCbor(HexBlob8(e.code))).toCbor()),this.usedLanguages[PlutusLanguageVersion.V2]=!0;break;case"V3":this.scriptsProvided.add(Script.newPlutusV3Script(PlutusV3Script.fromCbor(HexBlob8(e.code))).toCbor()),this.usedLanguages[PlutusLanguageVersion.V3]=!0}};addAllVotes=e=>{for(let t=0;t<e.length;t++){const r=e[t];switch(r.type){case"BasicVote":this.addBasicVote(r);break;case"ScriptVote":this.addScriptVote(r,t);break;case"SimpleScriptVote":this.addSimpleScriptVote(r)}}};addBasicVote=e=>{const t=this.txBody.votingProcedures()??Serialization8.VotingProcedures.fromCore([]);t.insert(toCardanoVoter(e.vote.voter),toCardanoGovernanceActionId2(e.vote.govActionId),toCardanoVotingProcedure(e.vote.votingProcedure)),this.txBody.setVotingProcedures(t)};addScriptVote=(e,t)=>{if(!e.scriptSource)throw new Error("Script source not provided for plutus script vote");const r=e.scriptSource;if(!r)throw new Error("A script source for a plutus certificate was not plutus script somehow");if(!e.redeemer)throw new Error("A redeemer was not provided for a plutus vote");let o=this.txWitnessSet.redeemers()??Redeemers.fromCore([]),i=[...o.values()];i.push(new Redeemer(RedeemerTag.Voting,BigInt(t),fromBuilderToPlutusData(e.redeemer.data),new ExUnits(BigInt(e.redeemer.exUnits.mem),BigInt(e.redeemer.exUnits.steps)))),o.setValues(i),this.txWitnessSet.setRedeemers(o),"Provided"===r.type?this.addProvidedPlutusScript(r.script):"Inline"===r.type&&this.addScriptRef(r),this.addBasicVote({type:"BasicVote",vote:e.vote})};addSimpleScriptVote=e=>{if(!e.simpleScriptSource)throw new Error("Script source not provided for native script vote");const t=e.simpleScriptSource;if(!t)throw new Error("A script source for a native script was not a native script somehow");"Provided"===t.type?this.scriptsProvided.add(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(t.scriptCode))).toCbor()):"Inline"===t.type&&this.addSimpleScriptRef(t),this.addBasicVote({type:"BasicVote",vote:e.vote})};addAllProposals=e=>{for(let t=0;t<e.length;t++){const r=e[t];if(r)switch(r.type){case"BasicProposal":this.addBasicProposal(r);break;case"ScriptProposal":this.addScriptProposal(r,t);break;case"SimpleScriptProposal":this.addSimpleScriptProposal(r)}}};addBasicProposal=e=>{const t=this.txBody.proposalProcedures(),r=t?[...t.values()]:[],o=toCardanoProposalProcedure(e.proposalType.governanceAction,e.proposalType.anchor,e.proposalType.rewardAccount,BigInt(e.proposalType.deposit));r.push(o),this.txBody.setProposalProcedures(CborSet.fromCore(r.map((e=>e.toCore())),Serialization8.ProposalProcedure.fromCore))};addScriptProposal=(e,t)=>{if("ScriptProposal"!==e.type)throw new Error("Expected ScriptProposal");if(!e.scriptSource)throw new Error("Script source not provided for plutus script proposal");const r=e.scriptSource;if(!r)throw new Error("A script source for a plutus proposal was not plutus script somehow");if(!e.redeemer)throw new Error("A redeemer was not provided for a plutus proposal");let o=this.txWitnessSet.redeemers()??Redeemers.fromCore([]),i=[...o.values()];i.push(new Redeemer(RedeemerTag.Proposing,BigInt(t),fromBuilderToPlutusData(e.redeemer.data),new ExUnits(BigInt(e.redeemer.exUnits.mem),BigInt(e.redeemer.exUnits.steps)))),o.setValues(i),this.txWitnessSet.setRedeemers(o),"Provided"===r.type?this.addProvidedPlutusScript(r.script):"Inline"===r.type&&this.addScriptRef(r),this.addBasicProposal(e)};addSimpleScriptProposal=e=>{if("SimpleScriptProposal"!==e.type)throw new Error("Expected SimpleScriptProposal");if(!e.simpleScriptSource)throw new Error("Script source not provided for native script proposal");const t=e.simpleScriptSource;if(!t)throw new Error("A script source for a native script was not a native script somehow");"Provided"===t.type?this.scriptsProvided.add(Script.newNativeScript(NativeScript.fromCbor(HexBlob8(t.scriptCode))).toCbor()):"Inline"===t.type&&this.addSimpleScriptRef(t),this.addBasicProposal(e)};mockVkeyWitnesses=e=>{let t=[];for(let r=0;r<e;r++){const e=this.numberToIntegerHex(r),o=this.mockPubkey(e),i=this.mockSignature(e);t.push(new VkeyWitness(Ed25519PublicKeyHex2(o),Ed25519SignatureHex2(i)))}return t};mockPubkey(e){return"0".repeat(2*VKEY_PUBKEY_SIZE_BYTES-e.length).concat(e)}mockSignature(e){return"0".repeat(2*VKEY_SIGNATURE_SIZE_BYTES-e.length).concat(e)}mockChainCode=e=>"0".repeat(2*CHAIN_CODE_SIZE_BYTES-e.length).concat(e);numberToIntegerHex=e=>BigInt(e).toString(16);mockBootstrapWitnesses=e=>{let t=[];for(let r=0;r<e.length;r++){const o=Address.fromBytes(e[r]).asByron();if(!o)throw new Error(`Failed to parse byron address: ${e[r]}`);const i=this.numberToIntegerHex(r),a=this.mockPubkey(i),n=this.mockSignature(i),s=this.mockChainCode(i),d=o.getAttributes();t.push(new BootstrapWitness(Ed25519PublicKeyHex2(a),Ed25519SignatureHex2(n),HexBlob8(s),this.serializeByronAttributes(d)))}return t};serializeByronAttributes=e=>{const t=new CborWriter;let r=0;if(e.magic&&r++,e.derivationPath&&r++,t.writeStartMap(r),e.derivationPath){t.writeInt(1);const r=(new CborWriter).writeByteString(Buffer3.from(e.derivationPath,"hex")).encode();t.writeByteString(r)}if(e.magic){t.writeInt(2);const r=(new CborWriter).writeInt(e.magic).encode();t.writeByteString(r)}return t.encodeAsHex()}},throwErrorWithOrigin=(e,t)=>{throw t instanceof Error?new Error(`${e}: ${t.message}`):"string"==typeof t?new Error(`${e}: ${t}`):"object"==typeof t?new Error(`${e}: ${JSON.stringify(t)}`):new Error(`${e}: ${String(t)}`)};import{Cbor as Cbor3,CborBytes as CborBytes4}from"@harmoniclabs/cbor";import{dataFromCbor}from"@harmoniclabs/plutus-data";import{Application,encodeUPLC,parseUPLC,UPLCConst,UPLCProgram}from"@harmoniclabs/uplc";var supportedPlutusCoreVersions=[{version:[1,0,0],language:"Plutus V1"},{version:[1,1,0],language:"Plutus V3"}],applyArgsToPlutusScript=(e,t,r)=>{const o=getPurePlutusBytes(t),i=parseUPLC(o,"flat"),a=e.map((e=>dataFromCbor(e)));let n=i.body;for(const e of a){const t=UPLCConst.data(e);n=new Application(n,t)}const s=new UPLCProgram(i.version,n),d=encodeUPLC(s).toBuffer().buffer;return applyEncoding(d,r)},normalizePlutusScript=(e,t)=>{const r=Buffer.from(e,"hex"),o=getPurePlutusBytes(r),i=applyEncoding(o,t);return Buffer.from(i).toString("hex")},hasSupportedPlutusVersion=e=>{if(e.length<3)return!1;const t=[e[0],e[1],e[2]];return supportedPlutusCoreVersions.some((e=>e.version[0]===t[0]&&e.version[1]===t[1]&&e.version[2]===t[2]))},getPurePlutusBytes=e=>{let t=e,r=0;try{for(;t.length>=3&&r!=t.length;){if(r=t.length,hasSupportedPlutusVersion(t))return t;const e=Cbor3.parse(t);if(!(e instanceof CborBytes4))break;t=e.bytes}}catch(e){console.error("Error parsing Plutus script:",e)}if(hasSupportedPlutusVersion(t))return t;throw new Error("Unsupported Plutus version or invalid Plutus script bytes")},applyCborEncoding=e=>Cbor3.encode(new CborBytes4(e)).toBuffer(),applyEncoding=(e,t)=>{switch(t){case"SingleCBOR":default:return applyCborEncoding(e);case"DoubleCBOR":return applyCborEncoding(applyCborEncoding(e));case"PurePlutusScriptBytes":return e}},applyParamsToScript=(e,t,r="Mesh")=>{let o=[];switch(r){case"JSON":t.forEach((e=>{o.push(fromBuilderToPlutusData({type:"JSON",content:e}))}));break;case"CBOR":t.forEach((e=>{o.push(fromBuilderToPlutusData({type:"CBOR",content:e}))}));break;case"Mesh":t.forEach((e=>{o.push(fromBuilderToPlutusData({type:"Mesh",content:e}))}))}const i=o.map((e=>Buffer.from(e.toCbor(),"hex")));return Buffer.from(applyArgsToPlutusScript(i,Buffer.from(e,"hex"),"DoubleCBOR")).toString("hex")};import*as CardanoSDKUtil from"@cardano-sdk/util";import*as Crypto2 from"@cardano-sdk/crypto";import*as CardanoSDK from"@cardano-sdk/core";export{Address,AddressType,AssetFingerprint,AssetId,AssetName,AuxilliaryData,BaseAddress,Bip32PrivateKey2 as Bip32PrivateKey,Bip32PrivateKeyHex2 as Bip32PrivateKeyHex,Bip32PublicKey2 as Bip32PublicKey,Bip32PublicKeyHex2 as Bip32PublicKeyHex,BootstrapWitness,Cardano7 as Cardano,CardanoSDK,CardanoSDKSerializer,CardanoSDKUtil,CborSet,CborWriter,CertIndex,Certificate,CertificateType,ConstrPlutusData,CoseSign1,CostModel,Costmdls,Credential,CredentialType,Crypto2 as Crypto,DRep,DRepID,Datum,DatumHash,DatumKind,Ed25519KeyHash2 as Ed25519KeyHash,Ed25519KeyHashHex2 as Ed25519KeyHashHex,Ed25519PrivateExtendedKeyHex,Ed25519PrivateKey2 as Ed25519PrivateKey,Ed25519PrivateNormalKeyHex,Ed25519PublicKey2 as Ed25519PublicKey,Ed25519PublicKeyHex2 as Ed25519PublicKeyHex,Ed25519Signature2 as Ed25519Signature,Ed25519SignatureHex2 as Ed25519SignatureHex,EnterpriseAddress,ExUnits,Hash,Hash28ByteBase162 as Hash28ByteBase16,Hash32ByteBase162 as Hash32ByteBase16,HexBlob,MetadatumList,MetadatumMap,NativeScript,NetworkId,PaymentAddress,PlutusData,PlutusDataKind,PlutusLanguageVersion,PlutusList,PlutusMap,PlutusV1Script,PlutusV2Script,PlutusV3Script,PointerAddress,PolicyId,PoolId,Redeemer,RedeemerPurpose,RedeemerTag,Redeemers,RequireAllOf,RequireAnyOf,RequireNOf,RequireSignature,RequireTimeAfter,RequireTimeBefore,RewardAccount,RewardAddress,Script,ScriptHash,ScriptPubkey,Serialization9 as Serialization,Slot,StakeCredentialStatus,StakeDelegation,StakeRegistration,Transaction,TransactionBody,TransactionId,TransactionInput,TransactionMetadatum,TransactionOutput,TransactionUnspentOutput,TransactionWitnessSet,TxCBOR,TxIndex,Value,VkeyWitness,VrfVkBech32,addVKeyWitnessSetToTransaction,addrBech32ToPlutusDataHex,addrBech32ToPlutusDataObj,addressToBech32,applyEncoding,applyParamsToScript,assetTypes,blake2b2 as blake2b,buildBaseAddress,buildBip32PrivateKey,buildDRepID,buildEd25519PrivateKeyFromSecretKey,buildEnterpriseAddress,buildKeys,buildRewardAddress,buildScriptPubkey,bytesToHex,calculateFees,checkSignature,clampScalar,computeAuxiliaryDataHash,deserializeAddress,deserializeBech32Address,deserializeDataHash,deserializeEd25519KeyHash,deserializeNativeScript,deserializePlutusData,deserializePlutusScript,deserializeScriptHash,deserializeScriptRef,deserializeTx,deserializeTxHash,deserializeTxUnspentOutput,deserializeValue,empty,fromBuilderToPlutusData,fromJsonToPlutusData,fromNativeScript,fromPlutusDataToJson,fromScriptRef,fromTxUnspentOutput,fromValue,generateNonce,getCoseKeyFromPublicKey,getDRepIds,getPublicKeyFromCoseKey,hexToBech32,hexToBytes,keyHashToRewardAddress,mergeValue,negateValue,negatives,normalizePlutusScript,parseDatumCbor,parseInlineDatum,resolveDataHash,resolveEd25519KeyHash,resolveNativeScriptAddress,resolveNativeScriptHash,resolvePaymentKeyHash,resolvePlutusScriptAddress,resolvePlutusScriptHash,resolvePoolId,resolvePrivateKey,resolveRewardAddress,resolveScriptHashDRepId,resolveScriptRef,resolveStakeKeyHash,resolveTxHash,scriptHashToBech32,scriptHashToRewardAddress,serializeAddress,serializeAddressObj,serializePlutusAddressToBech32,signData,subValue,toAddress,toBaseAddress,toCardanoAddress,toCardanoAnchor,toCardanoGovernanceActionId,toCardanoProposalProcedure,toDRep,toEnterpriseAddress,toNativeScript,toPlutusData,toPlutusLanguageVersion,toRewardAddress,toScriptRef,toTxUnspentOutput,toValue,utf8ToBytes,utf8ToHex,v2ScriptToBech32};
//# sourceMappingURL=/sm/f58fa42acdac7098817f45c5de38a309b4b0f43cc86d165149e59c17fab09144.map