@stacks/stacking 7.3.1 → 7.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksStacking=e():t.StacksStacking=e()}(this,()=>(()=>{var t,e,n={74:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomBytes=e.wrapConstructorWithOpts=e.wrapConstructor=e.checkOpts=e.Hash=e.concatBytes=e.toBytes=e.utf8ToBytes=e.asyncLoop=e.nextTick=e.hexToBytes=e.bytesToHex=e.isLE=e.rotr=e.createView=e.u32=e.u8=void 0;const r=n(452);if(e.u8=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength),e.u32=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),e.createView=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),e.rotr=(t,e)=>t<<32-e|t>>>e,e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],!e.isLE)throw new Error("Non little-endian hardware is not supported");const i=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function o(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}function s(t){if("string"==typeof t&&(t=o(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}e.bytesToHex=function(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=i[t[n]];return e},e.hexToBytes=function(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e},e.nextTick=async()=>{},e.asyncLoop=async function(t,n,r){let i=Date.now();for(let o=0;o<t;o++){r(o);const t=Date.now()-i;t>=0&&t<n||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=o,e.toBytes=s,e.concatBytes=function(...t){if(!t.every(t=>t instanceof Uint8Array))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce((t,e)=>t+e.length,0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n},e.Hash=class{clone(){return this._cloneInto()}},e.checkOpts=function(t,e){if(void 0!==e&&("object"!=typeof e||(n=e,"[object Object]"!==Object.prototype.toString.call(n)||n.constructor!==Object)))throw new TypeError("Options should be object or undefined");var n;return Object.assign(t,e)},e.wrapConstructor=function(t){const e=e=>t().update(s(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e},e.wrapConstructorWithOpts=function(t){const e=(e,n)=>t(n).update(s(e)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e},e.randomBytes=function(t=32){if(r.crypto.web)return r.crypto.web.getRandomValues(new Uint8Array(t));if(r.crypto.node)return new Uint8Array(r.crypto.node.randomBytes(t).buffer);throw new Error("The environment doesn't have randomBytes function")}},216:(t,e,n)=>{const r=n(403);t.exports=r("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},258:(t,e,n)=>{"use strict";e.ns=e.bJ=void 0;n(669),n(639);const r=n(877);Object.defineProperty(e,"bJ",{enumerable:!0,get:function(){return r.c32address}}),Object.defineProperty(e,"ns",{enumerable:!0,get:function(){return r.c32addressDecode}})},290:(t,e,n)=>{t=n.nmd(t);var r="__lodash_hash_undefined__",i=9007199254740991,o="[object Arguments]",s="[object Boolean]",a="[object Date]",c="[object Function]",u="[object GeneratorFunction]",h="[object Map]",d="[object Number]",f="[object Object]",l="[object Promise]",p="[object RegExp]",g="[object Set]",y="[object String]",w="[object Symbol]",b="[object WeakMap]",m="[object ArrayBuffer]",A="[object DataView]",E="[object Float32Array]",S="[object Float64Array]",v="[object Int8Array]",x="[object Int16Array]",C="[object Int32Array]",I="[object Uint8Array]",_="[object Uint8ClampedArray]",T="[object Uint16Array]",P="[object Uint32Array]",k=/\w*$/,R=/^\[object .+?Constructor\]$/,O=/^(?:0|[1-9]\d*)$/,N={};N[o]=N["[object Array]"]=N[m]=N[A]=N[s]=N[a]=N[E]=N[S]=N[v]=N[x]=N[C]=N[h]=N[d]=N[f]=N[p]=N[g]=N[y]=N[w]=N[I]=N[_]=N[T]=N[P]=!0,N["[object Error]"]=N[c]=N[b]=!1;var B="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,U="object"==typeof self&&self&&self.Object===Object&&self,H=B||U||Function("return this")(),$=e&&!e.nodeType&&e,D=$&&t&&!t.nodeType&&t,L=D&&D.exports===$;function K(t,e){return t.set(e[0],e[1]),t}function M(t,e){return t.add(e),t}function j(t,e,n,r){var i=-1,o=t?t.length:0;for(r&&o&&(n=t[++i]);++i<o;)n=e(n,t[i],i,t);return n}function G(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function F(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function W(t,e){return function(n){return t(e(n))}}function V(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var q,z=Array.prototype,X=Function.prototype,J=Object.prototype,Z=H["__core-js_shared__"],Y=(q=/[^.]+$/.exec(Z&&Z.keys&&Z.keys.IE_PROTO||""))?"Symbol(src)_1."+q:"",Q=X.toString,tt=J.hasOwnProperty,et=J.toString,nt=RegExp("^"+Q.call(tt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=L?H.Buffer:void 0,it=H.Symbol,ot=H.Uint8Array,st=W(Object.getPrototypeOf,Object),at=Object.create,ct=J.propertyIsEnumerable,ut=z.splice,ht=Object.getOwnPropertySymbols,dt=rt?rt.isBuffer:void 0,ft=W(Object.keys,Object),lt=Ht(H,"DataView"),pt=Ht(H,"Map"),gt=Ht(H,"Promise"),yt=Ht(H,"Set"),wt=Ht(H,"WeakMap"),bt=Ht(Object,"create"),mt=Mt(lt),At=Mt(pt),Et=Mt(gt),St=Mt(yt),vt=Mt(wt),xt=it?it.prototype:void 0,Ct=xt?xt.valueOf:void 0;function It(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function _t(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Tt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Pt(t){this.__data__=new _t(t)}function kt(t,e,n){var r=t[e];tt.call(t,e)&&jt(r,n)&&(void 0!==n||e in t)||(t[e]=n)}function Rt(t,e){for(var n=t.length;n--;)if(jt(t[n][0],e))return n;return-1}function Ot(t,e,n,r,i,l,b){var R;if(r&&(R=l?r(t,i,l,b):r(t)),void 0!==R)return R;if(!qt(t))return t;var O=Gt(t);if(O){if(R=function(t){var e=t.length,n=t.constructor(e);return e&&"string"==typeof t[0]&&tt.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),!e)return function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}(t,R)}else{var B=Dt(t),U=B==c||B==u;if(Wt(t))return function(t,e){if(e)return t.slice();var n=new t.constructor(t.length);return t.copy(n),n}(t,e);if(B==f||B==o||U&&!l){if(G(t))return l?t:{};if(R=function(t){return"function"!=typeof t.constructor||Kt(t)?{}:qt(e=st(t))?at(e):{};var e}(U?{}:t),!e)return function(t,e){return Bt(t,$t(t),e)}(t,function(t,e){return t&&Bt(e,zt(e),t)}(R,t))}else{if(!N[B])return l?t:{};R=function(t,e,n,r){var i,o=t.constructor;switch(e){case m:return Nt(t);case s:case a:return new o(+t);case A:return function(t,e){var n=e?Nt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,r);case E:case S:case v:case x:case C:case I:case _:case T:case P:return function(t,e){var n=e?Nt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}(t,r);case h:return function(t,e,n){return j(e?n(F(t),!0):F(t),K,new t.constructor)}(t,r,n);case d:case y:return new o(t);case p:return function(t){var e=new t.constructor(t.source,k.exec(t));return e.lastIndex=t.lastIndex,e}(t);case g:return function(t,e,n){return j(e?n(V(t),!0):V(t),M,new t.constructor)}(t,r,n);case w:return i=t,Ct?Object(Ct.call(i)):{}}}(t,B,Ot,e)}}b||(b=new Pt);var H=b.get(t);if(H)return H;if(b.set(t,R),!O)var $=n?function(t){return function(t,e,n){var r=e(t);return Gt(t)?r:function(t,e){for(var n=-1,r=e.length,i=t.length;++n<r;)t[i+n]=e[n];return t}(r,n(t))}(t,zt,$t)}(t):zt(t);return function(t,e){for(var n=-1,r=t?t.length:0;++n<r&&!1!==e(t[n],n););}($||t,function(i,o){$&&(i=t[o=i]),kt(R,o,Ot(i,e,n,r,o,t,b))}),R}function Nt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function Bt(t,e,n,r){n||(n={});for(var i=-1,o=e.length;++i<o;){var s=e[i],a=r?r(n[s],t[s],s,n,t):void 0;kt(n,s,void 0===a?t[s]:a)}return n}function Ut(t,e){var n,r,i=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function Ht(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return function(t){return!(!qt(t)||(e=t,Y&&Y in e))&&(Vt(t)||G(t)?nt:R).test(Mt(t));var e}(n)?n:void 0}It.prototype.clear=function(){this.__data__=bt?bt(null):{}},It.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},It.prototype.get=function(t){var e=this.__data__;if(bt){var n=e[t];return n===r?void 0:n}return tt.call(e,t)?e[t]:void 0},It.prototype.has=function(t){var e=this.__data__;return bt?void 0!==e[t]:tt.call(e,t)},It.prototype.set=function(t,e){return this.__data__[t]=bt&&void 0===e?r:e,this},_t.prototype.clear=function(){this.__data__=[]},_t.prototype.delete=function(t){var e=this.__data__,n=Rt(e,t);return!(n<0||(n==e.length-1?e.pop():ut.call(e,n,1),0))},_t.prototype.get=function(t){var e=this.__data__,n=Rt(e,t);return n<0?void 0:e[n][1]},_t.prototype.has=function(t){return Rt(this.__data__,t)>-1},_t.prototype.set=function(t,e){var n=this.__data__,r=Rt(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},Tt.prototype.clear=function(){this.__data__={hash:new It,map:new(pt||_t),string:new It}},Tt.prototype.delete=function(t){return Ut(this,t).delete(t)},Tt.prototype.get=function(t){return Ut(this,t).get(t)},Tt.prototype.has=function(t){return Ut(this,t).has(t)},Tt.prototype.set=function(t,e){return Ut(this,t).set(t,e),this},Pt.prototype.clear=function(){this.__data__=new _t},Pt.prototype.delete=function(t){return this.__data__.delete(t)},Pt.prototype.get=function(t){return this.__data__.get(t)},Pt.prototype.has=function(t){return this.__data__.has(t)},Pt.prototype.set=function(t,e){var n=this.__data__;if(n instanceof _t){var r=n.__data__;if(!pt||r.length<199)return r.push([t,e]),this;n=this.__data__=new Tt(r)}return n.set(t,e),this};var $t=ht?W(ht,Object):function(){return[]},Dt=function(t){return et.call(t)};function Lt(t,e){return!!(e=null==e?i:e)&&("number"==typeof t||O.test(t))&&t>-1&&t%1==0&&t<e}function Kt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||J)}function Mt(t){if(null!=t){try{return Q.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function jt(t,e){return t===e||t!=t&&e!=e}(lt&&Dt(new lt(new ArrayBuffer(1)))!=A||pt&&Dt(new pt)!=h||gt&&Dt(gt.resolve())!=l||yt&&Dt(new yt)!=g||wt&&Dt(new wt)!=b)&&(Dt=function(t){var e=et.call(t),n=e==f?t.constructor:void 0,r=n?Mt(n):void 0;if(r)switch(r){case mt:return A;case At:return h;case Et:return l;case St:return g;case vt:return b}return e});var Gt=Array.isArray;function Ft(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=i}(t.length)&&!Vt(t)}var Wt=dt||function(){return!1};function Vt(t){var e=qt(t)?et.call(t):"";return e==c||e==u}function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function zt(t){return Ft(t)?function(t,e){var n=Gt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&Ft(t)}(t)&&tt.call(t,"callee")&&(!ct.call(t,"callee")||et.call(t)==o)}(t)?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],r=n.length,i=!!r;for(var s in t)!e&&!tt.call(t,s)||i&&("length"==s||Lt(s,r))||n.push(s);return n}(t):function(t){if(!Kt(t))return ft(t);var e=[];for(var n in Object(t))tt.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}t.exports=function(t){return Ot(t,!0,!0)}},403:t=>{"use strict";t.exports=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var i=t.charAt(r),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=r}var s=t.length,a=t.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function h(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var n=0,r=0,i=0;t[n]===a;)r++,n++;for(var o=(t.length-n)*c+1>>>0,u=new Uint8Array(o);t[n];){var h=t.charCodeAt(n);if(h>255)return;var d=e[h];if(255===d)return;for(var f=0,l=o-1;(0!==d||f<i)&&-1!==l;l--,f++)d+=s*u[l]>>>0,u[l]=d%256>>>0,d=d/256>>>0;if(0!==d)throw new Error("Non-zero carry");i=f,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var g=new Uint8Array(r+(o-p)),y=r;p!==o;)g[y++]=u[p++];return g}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var n=0,r=0,i=0,o=e.length;i!==o&&0===e[i];)i++,n++;for(var c=(o-i)*u+1>>>0,h=new Uint8Array(c);i!==o;){for(var d=e[i],f=0,l=c-1;(0!==d||f<r)&&-1!==l;l--,f++)d+=256*h[l]>>>0,h[l]=d%s>>>0,d=d/s>>>0;if(0!==d)throw new Error("Non-zero carry");r=f,i++}for(var p=c-r;p!==c&&0===h[p];)p++;for(var g=a.repeat(n);p<c;++p)g+=t.charAt(h[p]);return g},decodeUnsafe:h,decode:function(t){var e=h(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}},414:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.decode=e.encode=void 0;const r=n(688),i=n(74),o=n(403),s="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";e.encode=function(t,e="00"){const n="string"==typeof t?(0,i.hexToBytes)(t):t,a="string"==typeof e?(0,i.hexToBytes)(e):t;if(!(n instanceof Uint8Array&&a instanceof Uint8Array))throw new TypeError("Argument must be of type Uint8Array or string");const c=(0,r.sha256)((0,r.sha256)(new Uint8Array([...a,...n])));return o(s).encode([...a,...n,...c.slice(0,4)])},e.decode=function(t){const e=o(s).decode(t),n=e.slice(0,1),i=e.slice(1,-4),a=(0,r.sha256)((0,r.sha256)(new Uint8Array([...n,...i])));return e.slice(-4).forEach((t,e)=>{if(t!==a[e])throw new Error("Invalid checksum")}),{prefix:n,data:i}}},452:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.crypto=void 0,e.crypto={node:void 0,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0}},460:(t,e)=>{"use strict";function n(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function r(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)}function i(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function o(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");n(t.outputLen),n(t.blockLen)}function s(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function a(t,e){i(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}Object.defineProperty(e,"__esModule",{value:!0}),e.output=e.exists=e.hash=e.bytes=e.bool=e.number=void 0,e.number=n,e.bool=r,e.bytes=i,e.hash=o,e.exists=s,e.output=a;const c={number:n,bool:r,bytes:i,hash:o,exists:s,output:a};e.default=c},546:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SHA2=void 0;const r=n(460),i=n(74);class o extends i.Hash{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,i.createView)(this.buffer)}update(t){r.default.exists(this);const{view:e,buffer:n,blockLen:o}=this,s=(t=(0,i.toBytes)(t)).length;for(let r=0;r<s;){const a=Math.min(o-this.pos,s-r);if(a===o){const e=(0,i.createView)(t);for(;o<=s-r;r+=o)this.process(e,r);continue}n.set(t.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){r.default.exists(this),r.default.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:o,isLE:s}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(n,0),a=0);for(let t=a;t<o;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,o-8,BigInt(8*this.length),s),this.process(n,0);const c=(0,i.createView)(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const h=u/4,d=this.get();if(h>d.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<h;t++)c.setUint32(4*t,d[t],s)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return t.length=r,t.pos=s,t.finished=i,t.destroyed=o,r%e&&t.buffer.set(n),t}}e.SHA2=o},639:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32checkDecode=e.c32checkEncode=void 0;const r=n(688),i=n(74),o=n(669);function s(t){const e=(0,r.sha256)((0,r.sha256)((0,i.hexToBytes)(t)));return(0,i.bytesToHex)(e.slice(0,4))}e.c32checkEncode=function(t,e){if(t<0||t>=32)throw new Error("Invalid version (must be between 0 and 31)");if(!e.match(/^[0-9a-fA-F]*$/))throw new Error("Invalid data (not a hex string)");(e=e.toLowerCase()).length%2!=0&&(e=`0${e}`);let n=t.toString(16);1===n.length&&(n=`0${n}`);const r=s(`${n}${e}`),i=(0,o.c32encode)(`${e}${r}`);return`${o.c32[t]}${i}`},e.c32checkDecode=function(t){t=(0,o.c32normalize)(t);const e=(0,o.c32decode)(t.slice(1)),n=t[0],r=o.c32.indexOf(n),i=e.slice(-8);let a=r.toString(16);if(1===a.length&&(a=`0${a}`),s(`${a}${e.substring(0,e.length-8)}`)!==i)throw new Error("Invalid c32check string: checksum mismatch");return[r,e.substring(0,e.length-8)]}},669:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32decode=e.c32normalize=e.c32encode=e.c32=void 0;const r=n(74);e.c32="0123456789ABCDEFGHJKMNPQRSTVWXYZ";const i="0123456789abcdef";function o(t){return t.toUpperCase().replace(/O/g,"0").replace(/L|I/g,"1")}e.c32encode=function(t,n){if(!t.match(/^[0-9a-fA-F]*$/))throw new Error("Not a hex-encoded string");t.length%2!=0&&(t=`0${t}`);let o=[],s=0;for(let n=(t=t.toLowerCase()).length-1;n>=0;n--)if(s<4){const r=i.indexOf(t[n])>>s;let a=0;0!==n&&(a=i.indexOf(t[n-1]));const c=1+s,u=a%(1<<c)<<5-c,h=e.c32[r+u];s=c,o.unshift(h)}else s=0;let a=0;for(let t=0;t<o.length&&"0"===o[t];t++)a++;o=o.slice(a);const c=(new TextDecoder).decode((0,r.hexToBytes)(t)).match(/^\u0000*/),u=c?c[0].length:0;for(let t=0;t<u;t++)o.unshift(e.c32[0]);if(n){const t=n-o.length;for(let n=0;n<t;n++)o.unshift(e.c32[0])}return o.join("")},e.c32normalize=o,e.c32decode=function(t,n){if(!(t=o(t)).match(`^[${e.c32}]*$`))throw new Error("Not a c32-encoded string");const r=t.match(`^${e.c32[0]}*`),s=r?r[0].length:0;let a=[],c=0,u=0;for(let n=t.length-1;n>=0;n--){4===u&&(a.unshift(i[c]),u=0,c=0);const r=(e.c32.indexOf(t[n])<<u)+c,o=i[r%16];if(u+=1,c=r>>4,c>1<<u)throw new Error("Panic error in decoding.");a.unshift(o)}a.unshift(i[c]),a.length%2==1&&a.unshift("0");let h=0;for(let t=0;t<a.length&&"0"===a[t];t++)h++;a=a.slice(h-h%2);let d=a.join("");for(let t=0;t<s;t++)d=`00${d}`;if(n){const t=2*n-d.length;for(let e=0;e<t;e+=2)d=`00${d}`}return d}},688:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha224=e.sha256=void 0;const r=n(546),i=n(74),o=(t,e,n)=>t&e^~t&n,s=(t,e,n)=>t&e^t&n^e&n,a=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),c=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),u=new Uint32Array(64);class h extends r.SHA2{constructor(){super(64,32,8,!1),this.A=0|c[0],this.B=0|c[1],this.C=0|c[2],this.D=0|c[3],this.E=0|c[4],this.F=0|c[5],this.G=0|c[6],this.H=0|c[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[t,e,n,r,i,o,s,a]}set(t,e,n,r,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)u[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=u[t-15],n=u[t-2],r=(0,i.rotr)(e,7)^(0,i.rotr)(e,18)^e>>>3,o=(0,i.rotr)(n,17)^(0,i.rotr)(n,19)^n>>>10;u[t]=o+u[t-7]+r+u[t-16]|0}let{A:n,B:r,C:c,D:h,E:d,F:f,G:l,H:p}=this;for(let t=0;t<64;t++){const e=p+((0,i.rotr)(d,6)^(0,i.rotr)(d,11)^(0,i.rotr)(d,25))+o(d,f,l)+a[t]+u[t]|0,g=((0,i.rotr)(n,2)^(0,i.rotr)(n,13)^(0,i.rotr)(n,22))+s(n,r,c)|0;p=l,l=f,f=d,d=h+e|0,h=c,c=r,r=n,n=e+g|0}n=n+this.A|0,r=r+this.B|0,c=c+this.C|0,h=h+this.D|0,d=d+this.E|0,f=f+this.F|0,l=l+this.G|0,p=p+this.H|0,this.set(n,r,c,h,d,f,l,p)}roundClean(){u.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class d extends h{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}e.sha256=(0,i.wrapConstructor)(()=>new h),e.sha224=(0,i.wrapConstructor)(()=>new d)},877:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32ToB58=e.b58ToC32=e.c32addressDecode=e.c32address=e.versions=void 0;const r=n(639),i=n(414),o=n(74);e.versions={mainnet:{p2pkh:22,p2sh:20},testnet:{p2pkh:26,p2sh:21}};const s={};s[0]=e.versions.mainnet.p2pkh,s[5]=e.versions.mainnet.p2sh,s[111]=e.versions.testnet.p2pkh,s[196]=e.versions.testnet.p2sh;const a={};function c(t,e){if(!e.match(/^[0-9a-fA-F]{40}$/))throw new Error("Invalid argument: not a hash160 hex string");return`S${(0,r.c32checkEncode)(t,e)}`}function u(t){if(t.length<=5)throw new Error("Invalid c32 address: invalid length");if("S"!=t[0])throw new Error('Invalid c32 address: must start with "S"');return(0,r.c32checkDecode)(t.slice(1))}a[e.versions.mainnet.p2pkh]=0,a[e.versions.mainnet.p2sh]=5,a[e.versions.testnet.p2pkh]=111,a[e.versions.testnet.p2sh]=196,e.c32address=c,e.c32addressDecode=u,e.b58ToC32=function(t,e=-1){const n=i.decode(t),r=(0,o.bytesToHex)(n.data),a=parseInt((0,o.bytesToHex)(n.prefix),16);let u;return e<0?(u=a,void 0!==s[a]&&(u=s[a])):u=e,c(u,r)},e.c32ToB58=function(t,e=-1){const n=u(t),r=n[0],o=n[1];let s;e<0?(s=r,void 0!==a[r]&&(s=a[r])):s=e;let c=s.toString(16);return 1===c.length&&(c=`0${c}`),i.encode(o,c)}},976:()=>{},991:(t,e)=>{"use strict";for(var n=[],r=[],i=("undefined"!=typeof Uint8Array&&Uint8Array,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),o=0;o<64;++o)n[o]=i[o],r[i.charCodeAt(o)]=o;r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63}},r={};function i(t){var e=r[t];if(void 0!==e)return e.exports;var o=r[t]={id:t,loaded:!1,exports:{}};return n[t](o,o.exports,i),o.loaded=!0,o.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},e=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__proto__,i.t=function(n,r){if(1&r&&(n=this(n)),8&r)return n;if("object"==typeof n&&n){if(4&r&&n.__esModule)return n;if(16&r&&"function"==typeof n.then)return n}var o=Object.create(null);i.r(o);var s={};t=t||[null,e({}),e([]),e(e)];for(var a=2&r&&n;("object"==typeof a||"function"==typeof a)&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach(t=>s[t]=()=>n[t]);return s.default=()=>n,i.d(o,s),o},i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.nmd=t=>(t.paths=[],t.children||(t.children=[]),t);var o={};return(()=>{"use strict";function t(t,n){return c(e(t),n)}function e(t){if("bigint"==typeof t)return t;if("string"==typeof t)return BigInt(t);if("number"==typeof t){if(!Number.isInteger(t))throw new RangeError("Invalid value. Values of type 'number' must be an integer.");if(t>Number.MAX_SAFE_INTEGER)throw new RangeError(`Invalid value. Values of type 'number' must be less than or equal to ${Number.MAX_SAFE_INTEGER}. For larger values, try using a BigInt instead.`);return BigInt(t)}if(E(t,Uint8Array))return BigInt(`0x${d(t)}`);throw new TypeError("intToBigInt: Invalid value type. Must be a number, bigint, BigInt-compatible string, or Uint8Array.")}function n(t){return/^0x/i.test(t)?t.slice(2):t}function r(t){if("string"!=typeof t)throw new TypeError("hexToBigInt: expected string, got "+typeof t);return BigInt(`0x${t}`)}function s(t,n=8){return("bigint"==typeof t?t:e(t)).toString(16).padStart(2*n,"0")}function a(t){return parseInt(t,16)}function c(t,e=16){return f(s(t,e))}function u(t){return e=BigInt(`0x${d(t)}`),n=BigInt(8*t.byteLength),function(t,e){return t&BigInt(1)<<e}(e,n-BigInt(1))?e-(BigInt(1)<<n):e;var e,n}i.r(o),i.d(o,{InvalidAddressError:()=>Ro,Pox4SignatureTopic:()=>Wo,StackingClient:()=>ns,btcAddressVersionToLegacyHashMode:()=>Oo,decodeBtcAddress:()=>No,decodeBtcAddressBytes:()=>Bo,ensureLegacyBtcAddressForPox1:()=>Go,ensurePox2Activated:()=>jo,ensureSignerArgsReadiness:()=>Fo,extractPoxAddressFromClarityValue:()=>Uo,getErrorString:()=>Ho,pox4SignatureMessage:()=>zo,poxAddressToBtcAddress:()=>Lo,poxAddressToTuple:()=>$o,signPox4SignatureHash:()=>Vo,unwrap:()=>Ko,unwrapMap:()=>Mo,verifyPox4SignatureHash:()=>qo});const h=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function d(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(const n of t)e+=h[n];return e}function f(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);t=(t=n(t)).length%2?`0${t}`:t;const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e}function l(t){return(new TextEncoder).encode(t)}function p(t){return(new TextDecoder).decode(t)}function g(t){const e=[];for(let n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return new Uint8Array(e)}function y(t){return String.fromCharCode.apply(null,t)}function w(t){return!Number.isInteger(t)||t<0||t>255}function b(t){if(t.some(w))throw new Error("Some values are invalid bytes.");return new Uint8Array(t)}function m(...t){if(!t.every(t=>t instanceof Uint8Array))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce((t,e)=>t+e.length,0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}function A(t){return m(...t.map(t=>"number"==typeof t?b([t]):t instanceof Array?b(t):t))}function E(t,e){return t instanceof e||t?.constructor?.name?.toLowerCase()===e.name}const S={referrerPolicy:"origin",headers:{"x-hiro-product":"stacksjs"}};async function v(t,e){const n={};return Object.assign(n,S,e),await fetch(t,n)}function x(...t){const{fetchLib:e,middlewares:n}=function(t){let e=v,n=[];return t.length>0&&"function"==typeof t[0]&&(e=t.shift()),t.length>0&&(n=t),{fetchLib:e,middlewares:n}}(t);return async(t,r)=>{let i={url:t,init:r??{}};for(const t of n)"function"==typeof t.pre&&(i=await Promise.resolve(t.pre({fetch:e,...i}))??i);let o=await e(i.url,i.init);for(const t of n)if("function"==typeof t.post){const n=await Promise.resolve(t.post({fetch:e,url:i.url,init:i.init,response:o?.clone()??o}));o=n??o}return o}}var C,I,_,T,P;!function(t){t[t.Mainnet=1]="Mainnet",t[t.Testnet=2147483648]="Testnet"}(C||(C={})),function(t){t[t.Mainnet=385875968]="Mainnet",t[t.Testnet=4278190080]="Testnet"}(I||(I={})),C.Mainnet,(P=_||(_={}))[P.Mainnet=0]="Mainnet",P[P.Testnet=128]="Testnet",function(t){t[t.MainnetSingleSig=22]="MainnetSingleSig",t[t.MainnetMultiSig=20]="MainnetMultiSig",t[t.TestnetSingleSig=26]="TestnetSingleSig",t[t.TestnetMultiSig=21]="TestnetMultiSig"}(T||(T={})),_.Mainnet;const k={chainId:C.Mainnet,transactionVersion:_.Mainnet,peerNetworkId:I.Mainnet,magicBytes:"X2",bootAddress:"SP000000000000000000002Q6VF78",addressVersion:{singleSig:T.MainnetSingleSig,multiSig:T.MainnetMultiSig},client:{baseUrl:"https://api.mainnet.hiro.so"}},R={chainId:C.Testnet,transactionVersion:_.Testnet,peerNetworkId:I.Testnet,magicBytes:"T2",bootAddress:"ST000000000000000000002AMW42H",addressVersion:{singleSig:T.TestnetSingleSig,multiSig:T.TestnetMultiSig},client:{baseUrl:"https://api.testnet.hiro.so"}},O={...R,addressVersion:{...R.addressVersion},magicBytes:"id",client:{baseUrl:"http://localhost:3999"}},N={...O,addressVersion:{...O.addressVersion},client:{...O.client}},B=["mainnet","testnet","devnet","mocknet"];function U(t){return"string"==typeof t?function(t){switch(t){case"mainnet":return k;case"testnet":return R;case"devnet":return O;case"mocknet":return N;default:throw new Error(`Unknown network name: ${t}`)}}(t):t}function H(t){return t.client.fetch?t.client:{...t.client,fetch:x()}}class $ extends Error{constructor(t){super(t),this.message=t,this.name=this.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class D extends ${constructor(t){super(t)}}class L extends ${constructor(t){super(t)}}class K extends ${constructor(t){super(t)}}class M extends ${constructor(t){super(t)}}class j extends ${constructor(t){super(t)}}function G(t,e){return t[e]}function F(t,e,n=0){return t[n]=e,t}function W(t,e,n=0){return t[n+3]=e,e>>>=8,t[n+2]=e,e>>>=8,t[n+1]=e,e>>>=8,t[n]=e,t}function V(t,e,n=0){return t[n+0]=255&e,e>>>=8,t[n+1]=255&e,e>>>=8,t[n+2]=255&e,e>>>=8,t[n+3]=255&e,t}const q=new Map;function z(t,e){const n=q.get(t);if(void 0!==n)return n(e);const r=function(t){const e=Object.values(t).filter(t=>"number"==typeof t),n=new Set(e);return t=>n.has(t)}(t);return q.set(t,r),z(t,e)}class X{constructor(t){this.consumed=0,this.source="string"==typeof t?f(t):t}readBytes(t){const e=this.source.subarray(this.consumed,this.consumed+t);return this.consumed+=t,e}readUInt32BE(){return(t=this.readBytes(4))[0]*2**24+65536*t[1]+256*t[2]+t[3];var t}readUInt8(){return G(this.readBytes(1),0)}readUInt16BE(){return((t=this.readBytes(2))[0+0]<<8|t[1])>>>0;var t}readBigUIntLE(t){const e=d(this.readBytes(t).slice().reverse());return BigInt(`0x${e}`)}readBigUIntBE(t){const e=d(this.readBytes(t));return BigInt(`0x${e}`)}get readOffset(){return this.consumed}set readOffset(t){this.consumed=t}get internalBytes(){return this.source}readUInt8Enum(t,e){const n=this.readUInt8();if(z(t,n))return n;throw e(n)}}const J=128,Z=128,Y=16;var Q,tt,et,nt,rt,it;(it=Q||(Q={}))[it.TokenTransfer=0]="TokenTransfer",it[it.SmartContract=1]="SmartContract",it[it.VersionedSmartContract=6]="VersionedSmartContract",it[it.ContractCall=2]="ContractCall",it[it.PoisonMicroblock=3]="PoisonMicroblock",it[it.Coinbase=4]="Coinbase",it[it.CoinbaseToAltRecipient=5]="CoinbaseToAltRecipient",it[it.TenureChange=7]="TenureChange",it[it.NakamotoCoinbase=8]="NakamotoCoinbase",(rt=tt||(tt={}))[rt.Clarity1=1]="Clarity1",rt[rt.Clarity2=2]="Clarity2",rt[rt.Clarity3=3]="Clarity3",rt[rt.Clarity4=4]="Clarity4",(nt=et||(et={}))[nt.OnChainOnly=1]="OnChainOnly",nt[nt.OffChainOnly=2]="OffChainOnly",nt[nt.Any=3]="Any";var ot,st,at,ct,ut,ht,dt,ft,lt,pt,gt,yt,wt,bt,mt,At,Et,St,vt,xt;function Ct(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function It(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}et.OnChainOnly,et.OffChainOnly,et.Any,et.OnChainOnly,et.OnChainOnly,et.OffChainOnly,et.OffChainOnly,et.Any,et.Any,(xt=ot||(ot={}))[xt.Allow=1]="Allow",xt[xt.Deny=2]="Deny",(vt=st||(st={}))[vt.STX=0]="STX",vt[vt.Fungible=1]="Fungible",vt[vt.NonFungible=2]="NonFungible",(St=at||(at={}))[St.Standard=4]="Standard",St[St.Sponsored=5]="Sponsored",(Et=ct||(ct={}))[Et.P2PKH=0]="P2PKH",Et[Et.P2SH=1]="P2SH",Et[Et.P2WPKH=2]="P2WPKH",Et[Et.P2WSH=3]="P2WSH",Et[Et.P2SHNonSequential=5]="P2SHNonSequential",Et[Et.P2WSHNonSequential=7]="P2WSHNonSequential",(At=ut||(ut={}))[At.Compressed=0]="Compressed",At[At.Uncompressed=1]="Uncompressed",function(t){t[t.Equal=1]="Equal",t[t.Greater=2]="Greater",t[t.GreaterEqual=3]="GreaterEqual",t[t.Less=4]="Less",t[t.LessEqual=5]="LessEqual"}(ht||(ht={})),function(t){t[t.Sends=16]="Sends",t[t.DoesNotSend=17]="DoesNotSend"}(dt||(dt={})),(mt=ft||(ft={}))[mt.Origin=1]="Origin",mt[mt.Standard=2]="Standard",mt[mt.Contract=3]="Contract",function(t){t[t.STX=0]="STX",t[t.Fungible=1]="Fungible",t[t.NonFungible=2]="NonFungible"}(lt||(lt={})),(bt=pt||(pt={}))[bt.BlockFound=0]="BlockFound",bt[bt.Extended=1]="Extended",bt[bt.ExtendedRuntime=2]="ExtendedRuntime",bt[bt.ExtendedReadCount=3]="ExtendedReadCount",bt[bt.ExtendedReadLength=4]="ExtendedReadLength",bt[bt.ExtendedWriteCount=5]="ExtendedWriteCount",bt[bt.ExtendedWriteLength=6]="ExtendedWriteLength",(wt=gt||(gt={}))[wt.PublicKeyCompressed=0]="PublicKeyCompressed",wt[wt.PublicKeyUncompressed=1]="PublicKeyUncompressed",wt[wt.SignatureCompressed=2]="SignatureCompressed",wt[wt.SignatureUncompressed=3]="SignatureUncompressed",function(t){t.Serialization="Serialization",t.Deserialization="Deserialization",t.SignatureValidation="SignatureValidation",t.FeeTooLow="FeeTooLow",t.BadNonce="BadNonce",t.NotEnoughFunds="NotEnoughFunds",t.NoSuchContract="NoSuchContract",t.NoSuchPublicFunction="NoSuchPublicFunction",t.BadFunctionArgument="BadFunctionArgument",t.ContractAlreadyExists="ContractAlreadyExists",t.PoisonMicroblocksDoNotConflict="PoisonMicroblocksDoNotConflict",t.PoisonMicroblockHasUnknownPubKeyHash="PoisonMicroblockHasUnknownPubKeyHash",t.PoisonMicroblockIsInvalid="PoisonMicroblockIsInvalid",t.BadAddressVersionByte="BadAddressVersionByte",t.NoCoinbaseViaMempool="NoCoinbaseViaMempool",t.ServerFailureNoSuchChainTip="ServerFailureNoSuchChainTip",t.ServerFailureDatabase="ServerFailureDatabase",t.ServerFailureOther="ServerFailureOther"}(yt||(yt={}));const _t={number:Ct,bool:function(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)},bytes:It,hash:function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Ct(t.outputLen),Ct(t.blockLen)},exists:function(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")},output:function(t,e){It(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}},Tt=("object"==typeof self&&"crypto"in self&&self.crypto,t=>new DataView(t.buffer,t.byteOffset,t.byteLength)),Pt=(t,e)=>t<<32-e|t>>>e;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function kt(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));class Rt{clone(){return this._cloneInto()}}function Ot(t){const e=e=>t().update(kt(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}class Nt extends Rt{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Tt(this.buffer)}update(t){_t.exists(this);const{view:e,buffer:n,blockLen:r}=this,i=(t=kt(t)).length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const e=Tt(t);for(;r<=i-o;o+=r)this.process(e,o);continue}n.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_t.exists(this),_t.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:i}=this;let{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(n,0),o=0);for(let t=o;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=Tt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)s.setUint32(4*t,u[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return t.length=r,t.pos=s,t.finished=i,t.destroyed=o,r%e&&t.buffer.set(n),t}}const Bt=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ut=Uint8Array.from({length:16},(t,e)=>e),Ht=Ut.map(t=>(9*t+5)%16);let $t=[Ut],Dt=[Ht];for(let t=0;t<4;t++)for(let e of[$t,Dt])e.push(e[t].map(t=>Bt[t]));const Lt=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>new Uint8Array(t)),Kt=$t.map((t,e)=>t.map(t=>Lt[e][t])),Mt=Dt.map((t,e)=>t.map(t=>Lt[e][t])),jt=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Gt=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),Ft=(t,e)=>t<<e|t>>>32-e;function Wt(t,e,n,r){return 0===t?e^n^r:1===t?e&n|~e&r:2===t?(e|~n)^r:3===t?e&r|n&~r:e^(n|~r)}const Vt=new Uint32Array(16);class qt extends Nt{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:e,h2:n,h3:r,h4:i}=this;return[t,e,n,r,i]}set(t,e,n,r,i){this.h0=0|t,this.h1=0|e,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(t,e){for(let n=0;n<16;n++,e+=4)Vt[n]=t.getUint32(e,!0);let n=0|this.h0,r=n,i=0|this.h1,o=i,s=0|this.h2,a=s,c=0|this.h3,u=c,h=0|this.h4,d=h;for(let t=0;t<5;t++){const e=4-t,f=jt[t],l=Gt[t],p=$t[t],g=Dt[t],y=Kt[t],w=Mt[t];for(let e=0;e<16;e++){const r=Ft(n+Wt(t,i,s,c)+Vt[p[e]]+f,y[e])+h|0;n=h,h=c,c=0|Ft(s,10),s=i,i=r}for(let t=0;t<16;t++){const n=Ft(r+Wt(e,o,a,u)+Vt[g[t]]+l,w[t])+d|0;r=d,d=u,u=0|Ft(a,10),a=o,o=n}}this.set(this.h1+s+u|0,this.h2+c+d|0,this.h3+h+r|0,this.h4+n+o|0,this.h0+i+a|0)}roundClean(){Vt.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const zt=Ot(()=>new qt),Xt=(t,e,n)=>t&e^~t&n,Jt=(t,e,n)=>t&e^t&n^e&n,Zt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Yt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qt=new Uint32Array(64);class te extends Nt{constructor(){super(64,32,8,!1),this.A=0|Yt[0],this.B=0|Yt[1],this.C=0|Yt[2],this.D=0|Yt[3],this.E=0|Yt[4],this.F=0|Yt[5],this.G=0|Yt[6],this.H=0|Yt[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[t,e,n,r,i,o,s,a]}set(t,e,n,r,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)Qt[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=Qt[t-15],n=Qt[t-2],r=Pt(e,7)^Pt(e,18)^e>>>3,i=Pt(n,17)^Pt(n,19)^n>>>10;Qt[t]=i+Qt[t-7]+r+Qt[t-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:a,G:c,H:u}=this;for(let t=0;t<64;t++){const e=u+(Pt(s,6)^Pt(s,11)^Pt(s,25))+Xt(s,a,c)+Zt[t]+Qt[t]|0,h=(Pt(n,2)^Pt(n,13)^Pt(n,22))+Jt(n,r,i)|0;u=c,c=a,a=s,s=o+e|0,o=i,i=r,r=n,n=e+h|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,i,o,s,a,c,u)}roundClean(){Qt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class ee extends te{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const ne=Ot(()=>new te),re=(Ot(()=>new ee),BigInt(2**32-1)),ie=BigInt(32);function oe(t,e=!1){return e?{h:Number(t&re),l:Number(t>>ie&re)}:{h:0|Number(t>>ie&re),l:0|Number(t&re)}}const se=function(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:o,l:s}=oe(t[i],e);[n[i],r[i]]=[o,s]}return[n,r]},ae=(t,e,n)=>t>>>n,ce=(t,e,n)=>t<<32-n|e>>>n,ue=(t,e,n)=>t>>>n|e<<32-n,he=(t,e,n)=>t<<32-n|e>>>n,de=(t,e,n)=>t<<64-n|e>>>n-32,fe=(t,e,n)=>t>>>n-32|e<<64-n,le=function(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:0|i}},pe=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),ge=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,ye=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),we=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,be=(t,e,n,r,i,o)=>e+n+r+i+o+(t/2**32|0)|0,me=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),[Ae,Ee]=se(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Se=new Uint32Array(80),ve=new Uint32Array(80);class xe extends Nt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:e,Bh:n,Bl:r,Ch:i,Cl:o,Dh:s,Dl:a,Eh:c,El:u,Fh:h,Fl:d,Gh:f,Gl:l,Hh:p,Hl:g}=this;return[t,e,n,r,i,o,s,a,c,u,h,d,f,l,p,g]}set(t,e,n,r,i,o,s,a,c,u,h,d,f,l,p,g){this.Ah=0|t,this.Al=0|e,this.Bh=0|n,this.Bl=0|r,this.Ch=0|i,this.Cl=0|o,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|h,this.Fl=0|d,this.Gh=0|f,this.Gl=0|l,this.Hh=0|p,this.Hl=0|g}process(t,e){for(let n=0;n<16;n++,e+=4)Se[n]=t.getUint32(e),ve[n]=t.getUint32(e+=4);for(let t=16;t<80;t++){const e=0|Se[t-15],n=0|ve[t-15],r=ue(e,n,1)^ue(e,n,8)^ae(e,n,7),i=he(e,n,1)^he(e,n,8)^ce(e,n,7),o=0|Se[t-2],s=0|ve[t-2],a=ue(o,s,19)^de(o,s,61)^ae(o,s,6),c=he(o,s,19)^fe(o,s,61)^ce(o,s,6),u=ye(i,c,ve[t-7],ve[t-16]),h=we(u,r,a,Se[t-7],Se[t-16]);Se[t]=0|h,ve[t]=0|u}let{Ah:n,Al:r,Bh:i,Bl:o,Ch:s,Cl:a,Dh:c,Dl:u,Eh:h,El:d,Fh:f,Fl:l,Gh:p,Gl:g,Hh:y,Hl:w}=this;for(let t=0;t<80;t++){const e=ue(h,d,14)^ue(h,d,18)^de(h,d,41),b=he(h,d,14)^he(h,d,18)^fe(h,d,41),m=h&f^~h&p,A=me(w,b,d&l^~d&g,Ee[t],ve[t]),E=be(A,y,e,m,Ae[t],Se[t]),S=0|A,v=ue(n,r,28)^de(n,r,34)^de(n,r,39),x=he(n,r,28)^fe(n,r,34)^fe(n,r,39),C=n&i^n&s^i&s,I=r&o^r&a^o&a;y=0|p,w=0|g,p=0|f,g=0|l,f=0|h,l=0|d,({h,l:d}=le(0|c,0|u,0|E,0|S)),c=0|s,u=0|a,s=0|i,a=0|o,i=0|n,o=0|r;const _=pe(S,x,I);n=ge(_,E,v,C),r=0|_}({h:n,l:r}=le(0|this.Ah,0|this.Al,0|n,0|r)),({h:i,l:o}=le(0|this.Bh,0|this.Bl,0|i,0|o)),({h:s,l:a}=le(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=le(0|this.Dh,0|this.Dl,0|c,0|u)),({h,l:d}=le(0|this.Eh,0|this.El,0|h,0|d)),({h:f,l}=le(0|this.Fh,0|this.Fl,0|f,0|l)),({h:p,l:g}=le(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:w}=le(0|this.Hh,0|this.Hl,0|y,0|w)),this.set(n,r,i,o,s,a,c,u,h,d,f,l,p,g,y,w)}roundClean(){Se.fill(0),ve.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Ce extends xe{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}class Ie extends xe{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class _e extends xe{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}Ot(()=>new xe),Ot(()=>new Ce);const Te=Ot(()=>new Ie);Ot(()=>new _e);var Pe=i(976),ke=i.t(Pe,2);const Re=BigInt(0),Oe=BigInt(1),Ne=BigInt(2),Be=BigInt(3),Ue=BigInt(8),He=Object.freeze({a:Re,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:Oe,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),$e=(t,e)=>(t+e/Ne)/e,De={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const{n:e}=He,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Oe*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),a=$e(o*t,e),c=$e(-r*t,e);let u=pn(t-a*n-c*i,e),h=pn(-a*r-c*o,e);const d=u>s,f=h>s;if(d&&(u=e-u),f&&(h=e-h),u>s||h>s)throw new Error("splitScalarEndo: Endomorphism failed, k="+t);return{k1neg:d,k1:u,k2neg:f,k2:h}}},Le=32,Ke=32,Me=32,je=Le+1,Ge=2*Le+1;function Fe(t){const{a:e,b:n}=He,r=pn(t*t),i=pn(r*t);return pn(i+e*t+n)}const We=He.a===Re;class Ve extends Error{constructor(t){super(t)}}function qe(t){if(!(t instanceof ze))throw new TypeError("JacobianPoint expected")}class ze{constructor(t,e,n){this.x=t,this.y=e,this.z=n}static fromAffine(t){if(!(t instanceof Ze))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(Ze.ZERO)?ze.ZERO:new ze(t.x,t.y,Oe)}static toAffineBatch(t){const e=function(t,e=He.P){const n=new Array(t.length),r=yn(t.reduce((t,r,i)=>r===Re?t:(n[i]=t,pn(t*r,e)),Oe),e);return t.reduceRight((t,r,i)=>r===Re?t:(n[i]=pn(t*n[i],e),pn(t*r,e)),r),n}(t.map(t=>t.z));return t.map((t,n)=>t.toAffine(e[n]))}static normalizeZ(t){return ze.toAffineBatch(t).map(ze.fromAffine)}equals(t){qe(t);const{x:e,y:n,z:r}=this,{x:i,y:o,z:s}=t,a=pn(r*r),c=pn(s*s),u=pn(e*c),h=pn(i*a),d=pn(pn(n*s)*c),f=pn(pn(o*r)*a);return u===h&&d===f}negate(){return new ze(this.x,pn(-this.y),this.z)}double(){const{x:t,y:e,z:n}=this,r=pn(t*t),i=pn(e*e),o=pn(i*i),s=t+i,a=pn(Ne*(pn(s*s)-r-o)),c=pn(Be*r),u=pn(c*c),h=pn(u-Ne*a),d=pn(c*(a-h)-Ue*o),f=pn(Ne*e*n);return new ze(h,d,f)}add(t){qe(t);const{x:e,y:n,z:r}=this,{x:i,y:o,z:s}=t;if(i===Re||o===Re)return this;if(e===Re||n===Re)return t;const a=pn(r*r),c=pn(s*s),u=pn(e*c),h=pn(i*a),d=pn(pn(n*s)*c),f=pn(pn(o*r)*a),l=pn(h-u),p=pn(f-d);if(l===Re)return p===Re?this.double():ze.ZERO;const g=pn(l*l),y=pn(l*g),w=pn(u*g),b=pn(p*p-y-Ne*w),m=pn(p*(w-b)-d*y),A=pn(r*s*l);return new ze(b,m,A)}subtract(t){return this.add(t.negate())}multiplyUnsafe(t){const e=ze.ZERO;if("bigint"==typeof t&&t===Re)return e;let n=ln(t);if(n===Oe)return this;if(!We){let t=e,r=this;for(;n>Re;)n&Oe&&(t=t.add(r)),r=r.double(),n>>=Oe;return t}let{k1neg:r,k1:i,k2neg:o,k2:s}=De.splitScalar(n),a=e,c=e,u=this;for(;i>Re||s>Re;)i&Oe&&(a=a.add(u)),s&Oe&&(c=c.add(u)),u=u.double(),i>>=Oe,s>>=Oe;return r&&(a=a.negate()),o&&(c=c.negate()),c=new ze(pn(c.x*De.beta),c.y,c.z),a.add(c)}precomputeWindow(t){const e=We?128/t+1:256/t+1,n=[];let r=this,i=r;for(let o=0;o<e;o++){i=r,n.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(r),n.push(i);r=i.double()}return n}wNAF(t,e){!e&&this.equals(ze.BASE)&&(e=Ze.BASE);const n=e&&e._WINDOW_SIZE||1;if(256%n)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let r=e&&Je.get(e);r||(r=this.precomputeWindow(n),e&&1!==n&&(r=ze.normalizeZ(r),Je.set(e,r)));let i=ze.ZERO,o=ze.BASE;const s=1+(We?128/n:256/n),a=2**(n-1),c=BigInt(2**n-1),u=2**n,h=BigInt(n);for(let e=0;e<s;e++){const n=e*a;let s=Number(t&c);t>>=h,s>a&&(s-=u,t+=Oe);const d=n,f=n+Math.abs(s)-1,l=e%2!=0,p=s<0;0===s?o=o.add(Xe(l,r[d])):i=i.add(Xe(p,r[f]))}return{p:i,f:o}}multiply(t,e){let n,r,i=ln(t);if(We){const{k1neg:t,k1:o,k2neg:s,k2:a}=De.splitScalar(i);let{p:c,f:u}=this.wNAF(o,e),{p:h,f:d}=this.wNAF(a,e);c=Xe(t,c),h=Xe(s,h),h=new ze(pn(h.x*De.beta),h.y,h.z),n=c.add(h),r=u.add(d)}else{const{p:t,f:o}=this.wNAF(i,e);n=t,r=o}return ze.normalizeZ([n,r])[0]}toAffine(t){const{x:e,y:n,z:r}=this,i=this.equals(ze.ZERO);null==t&&(t=i?Ue:yn(r));const o=t,s=pn(o*o),a=pn(s*o),c=pn(e*s),u=pn(n*a),h=pn(r*o);if(i)return Ze.ZERO;if(h!==Oe)throw new Error("invZ was invalid");return new Ze(c,u)}}function Xe(t,e){const n=e.negate();return t?n:e}ze.BASE=new ze(He.Gx,He.Gy,Oe),ze.ZERO=new ze(Re,Oe,Re);const Je=new WeakMap;class Ze{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,Je.delete(this)}hasEvenY(){return this.y%Ne===Re}static fromCompressedHex(t){const e=32===t.length,n=dn(e?t:t.subarray(1));if(!Sn(n))throw new Error("Point is not on curve");let r=function(t){const{P:e}=He,n=BigInt(6),r=BigInt(11),i=BigInt(22),o=BigInt(23),s=BigInt(44),a=BigInt(88),c=t*t*t%e,u=c*c*t%e,h=gn(u,Be)*u%e,d=gn(h,Be)*u%e,f=gn(d,Ne)*c%e,l=gn(f,r)*f%e,p=gn(l,i)*l%e,g=gn(p,s)*p%e,y=gn(g,a)*g%e,w=gn(y,s)*p%e,b=gn(w,Be)*u%e,m=gn(b,o)*l%e,A=gn(m,n)*c%e,E=gn(A,Ne);if(E*E%e!==t)throw new Error("Cannot find square root");return E}(Fe(n));const i=(r&Oe)===Oe;e?i&&(r=pn(-r)):!(1&~t[0])!==i&&(r=pn(-r));const o=new Ze(n,r);return o.assertValidity(),o}static fromUncompressedHex(t){const e=dn(t.subarray(1,Le+1)),n=dn(t.subarray(Le+1,2*Le+1)),r=new Ze(e,n);return r.assertValidity(),r}static fromHex(t){const e=fn(t),n=e.length,r=e[0];if(n===Le)return this.fromCompressedHex(e);if(n===je&&(2===r||3===r))return this.fromCompressedHex(e);if(n===Ge&&4===r)return this.fromUncompressedHex(e);throw new Error(`Point.fromHex: received invalid point. Expected 32-${je} compressed bytes or ${Ge} uncompressed bytes, not ${n}`)}static fromPrivateKey(t){return Ze.BASE.multiply(xn(t))}static fromSignature(t,e,n){const{r,s:i}=Cn(e);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const o=wn(fn(t)),{n:s}=He,a=2===n||3===n?r+s:r,c=yn(a,s),u=pn(-o*c,s),h=pn(i*c,s),d=1&n?"03":"02",f=Ze.fromHex(d+sn(a)),l=Ze.BASE.multiplyAndAddUnsafe(f,u,h);if(!l)throw new Error("Cannot recover signature: point at infinify");return l.assertValidity(),l}toRawBytes(t=!1){return hn(this.toHex(t))}toHex(t=!1){const e=sn(this.x);return t?`${this.hasEvenY()?"02":"03"}${e}`:`04${e}${sn(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const t="Point is not on elliptic curve",{x:e,y:n}=this;if(!Sn(e)||!Sn(n))throw new Error(t);const r=pn(n*n);if(pn(r-Fe(e))!==Re)throw new Error(t)}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new Ze(this.x,pn(-this.y))}double(){return ze.fromAffine(this).double().toAffine()}add(t){return ze.fromAffine(this).add(ze.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return ze.fromAffine(this).multiply(t,this).toAffine()}multiplyAndAddUnsafe(t,e,n){const r=ze.fromAffine(this),i=e===Re||e===Oe||this!==Ze.BASE?r.multiplyUnsafe(e):r.multiply(e),o=ze.fromAffine(t).multiplyUnsafe(n),s=i.add(o);return s.equals(ze.ZERO)?void 0:s.toAffine()}}function Ye(t){return Number.parseInt(t[0],16)>=8?"00"+t:t}function Qe(t){if(t.length<2||2!==t[0])throw new Error(`Invalid signature integer tag: ${rn(t)}`);const e=t[1],n=t.subarray(2,e+2);if(!e||n.length!==e)throw new Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:dn(n),left:t.subarray(e+2)}}Ze.BASE=new Ze(He.Gx,He.Gy),Ze.ZERO=new Ze(Re,Re);class tn{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromCompact(t){const e=t instanceof Uint8Array,n="Signature.fromCompact";if("string"!=typeof t&&!e)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=e?rn(t):t;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new tn(un(r.slice(0,64)),un(r.slice(64,128)))}static fromDER(t){const e=t instanceof Uint8Array;if("string"!=typeof t&&!e)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:n,s:r}=function(t){if(t.length<2||48!=t[0])throw new Error(`Invalid signature tag: ${rn(t)}`);if(t[1]!==t.length-2)throw new Error("Invalid signature: incorrect length");const{data:e,left:n}=Qe(t.subarray(2)),{data:r,left:i}=Qe(n);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${rn(i)}`);return{r:e,s:r}}(e?t:hn(t));return new tn(n,r)}static fromHex(t){return this.fromDER(t)}assertValidity(){const{r:t,s:e}=this;if(!En(t))throw new Error("Invalid Signature: r must be 0 < r < n");if(!En(e))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const t=He.n>>Oe;return this.s>t}normalizeS(){return this.hasHighS()?new tn(this.r,pn(-this.s,He.n)):this}toDERRawBytes(){return hn(this.toDERHex())}toDERHex(){const t=Ye(cn(this.s)),e=Ye(cn(this.r)),n=t.length/2,r=e.length/2,i=cn(n),o=cn(r);return`30${cn(r+n+4)}02${o}${e}02${i}${t}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return hn(this.toCompactHex())}toCompactHex(){return sn(this.r)+sn(this.s)}}function en(...t){if(!t.every(t=>t instanceof Uint8Array))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce((t,e)=>t+e.length,0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}const nn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function rn(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");let e="";for(let n=0;n<t.length;n++)e+=nn[t[n]];return e}const on=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function sn(t){if("bigint"!=typeof t)throw new Error("Expected bigint");if(!(Re<=t&&t<on))throw new Error("Expected number 0 <= n < 2^256");return t.toString(16).padStart(64,"0")}function an(t){const e=hn(sn(t));if(32!==e.length)throw new Error("Error: expected 32 bytes");return e}function cn(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function un(t){if("string"!=typeof t)throw new TypeError("hexToNumber: expected string, got "+typeof t);return BigInt(`0x${t}`)}function hn(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex"+t.length);const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e}function dn(t){return un(rn(t))}function fn(t){return t instanceof Uint8Array?Uint8Array.from(t):hn(t)}function ln(t){if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)return BigInt(t);if("bigint"==typeof t&&En(t))return t;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function pn(t,e=He.P){const n=t%e;return n>=Re?n:e+n}function gn(t,e){const{P:n}=He;let r=t;for(;e-- >Re;)r*=r,r%=n;return r}function yn(t,e=He.P){if(t===Re||e<=Re)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=pn(t,e),r=e,i=Re,o=Oe,s=Oe,a=Re;for(;n!==Re;){const t=r/n,e=r%n,c=i-s*t,u=o-a*t;r=n,n=e,i=s,o=a,s=c,a=u}if(r!==Oe)throw new Error("invert: does not exist");return pn(i,e)}function wn(t,e=!1){const n=function(t){const e=8*t.length-8*Ke,n=dn(t);return e>0?n>>BigInt(e):n}(t);if(e)return n;const{n:r}=He;return n>=r?n-r:n}let bn,mn;class An{constructor(t,e){if(this.hashLen=t,this.qByteLen=e,"number"!=typeof t||t<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");this.v=new Uint8Array(t).fill(1),this.k=new Uint8Array(t).fill(0),this.counter=0}hmac(...t){return Nn.hmacSha256(this.k,...t)}hmacSync(...t){return mn(this.k,...t)}checkSync(){if("function"!=typeof mn)throw new Ve("hmacSha256Sync needs to be set")}incr(){if(this.counter>=1e3)throw new Error("Tried 1,000 k values for sign(), all were invalid");this.counter+=1}async reseed(t=new Uint8Array){this.k=await this.hmac(this.v,Uint8Array.from([0]),t),this.v=await this.hmac(this.v),0!==t.length&&(this.k=await this.hmac(this.v,Uint8Array.from([1]),t),this.v=await this.hmac(this.v))}reseedSync(t=new Uint8Array){this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),t),this.v=this.hmacSync(this.v),0!==t.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),t),this.v=this.hmacSync(this.v))}async generate(){this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=await this.hmac(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return en(...e)}generateSync(){this.checkSync(),this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=this.hmacSync(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return en(...e)}}function En(t){return Re<t&&t<He.n}function Sn(t){return Re<t&&t<He.P}function vn(t,e,n,r=!0){const{n:i}=He,o=wn(t,!0);if(!En(o))return;const s=yn(o,i),a=Ze.BASE.multiply(o),c=pn(a.x,i);if(c===Re)return;const u=pn(s*pn(e+n*c,i),i);if(u===Re)return;let h=new tn(c,u),d=(a.x===h.r?0:2)|Number(a.y&Oe);return r&&h.hasHighS()&&(h=h.normalizeS(),d^=1),{sig:h,recovery:d}}function xn(t){let e;if("bigint"==typeof t)e=t;else if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)e=BigInt(t);else if("string"==typeof t){if(t.length!==2*Ke)throw new Error("Expected 32 bytes of private key");e=un(t)}else{if(!(t instanceof Uint8Array))throw new TypeError("Expected valid private key");if(t.length!==Ke)throw new Error("Expected 32 bytes of private key");e=dn(t)}if(!En(e))throw new Error("Expected private key: 0 < key < n");return e}function Cn(t){if(t instanceof tn)return t.assertValidity(),t;try{return tn.fromDER(t)}catch(e){return tn.fromCompact(t)}}function In(t){return dn(t.length>Le?t.slice(0,Le):t)}function _n(t){const e=In(t),n=pn(e,He.n);return Tn(n<Re?e:n)}function Tn(t){return an(t)}const Pn={strict:!0};function kn(t,e,n,r=Pn){let i;try{i=Cn(t),e=fn(e)}catch(t){return!1}const{r:o,s}=i;if(r.strict&&i.hasHighS())return!1;const a=wn(e);let c;try{c=function(t){return t instanceof Ze?(t.assertValidity(),t):Ze.fromHex(t)}(n)}catch(t){return!1}const{n:u}=He,h=yn(s,u),d=pn(a*h,u),f=pn(o*h,u),l=Ze.BASE.multiplyAndAddUnsafe(c,d,f);return!!l&&pn(l.x,u)===o}Ze.BASE._setWindowSize(8);const Rn={node:ke,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},On={},Nn={bytesToHex:rn,hexToBytes:hn,concatBytes:en,mod:pn,invert:yn,isValidPrivateKey(t){try{return xn(t),!0}catch(t){return!1}},_bigintTo32Bytes:an,_normalizePrivateKey:xn,hashToPrivateKey:t=>{t=fn(t);const e=Ke+8;if(t.length<e||t.length>1024)throw new Error("Expected valid bytes of private key as per FIPS 186");return an(pn(dn(t),He.n-Oe)+Oe)},randomBytes:(t=32)=>{if(Rn.web)return Rn.web.getRandomValues(new Uint8Array(t));if(Rn.node){const{randomBytes:e}=Rn.node;return Uint8Array.from(e(t))}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>Nn.hashToPrivateKey(Nn.randomBytes(Ke+8)),precompute(t=8,e=Ze.BASE){const n=e===Ze.BASE?e:new Ze(e.x,e.y);return n._setWindowSize(t),n.multiply(Be),n},sha256:async(...t)=>{if(Rn.web){const e=await Rn.web.subtle.digest("SHA-256",en(...t));return new Uint8Array(e)}if(Rn.node){const{createHash:e}=Rn.node,n=e("sha256");return t.forEach(t=>n.update(t)),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(t,...e)=>{if(Rn.web){const n=await Rn.web.subtle.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),r=en(...e),i=await Rn.web.subtle.sign("HMAC",n,r);return new Uint8Array(i)}if(Rn.node){const{createHmac:n}=Rn.node,r=n("sha256",t);return e.forEach(t=>r.update(t)),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(t,...e)=>{let n=On[t];if(void 0===n){const e=await Nn.sha256(Uint8Array.from(t,t=>t.charCodeAt(0)));n=en(e,e),On[t]=n}return Nn.sha256(n,...e)},taggedHashSync:(t,...e)=>{if("function"!=typeof bn)throw new Ve("sha256Sync is undefined, you need to set it");let n=On[t];if(void 0===n){const e=bn(Uint8Array.from(t,t=>t.charCodeAt(0)));n=en(e,e),On[t]=n}return bn(n,...e)},_JacobianPoint:ze};Object.defineProperties(Nn,{sha256Sync:{configurable:!1,get:()=>bn,set(t){bn||(bn=t)}},hmacSha256Sync:{configurable:!1,get:()=>mn,set(t){mn||(mn=t)}}});var Bn,Un,Hn,$n=i(258),Dn=i(290),Ln=i.n(Dn);function Kn(t){return Un[t]}(Hn=Bn||(Bn={})).Int="int",Hn.UInt="uint",Hn.Buffer="buffer",Hn.BoolTrue="true",Hn.BoolFalse="false",Hn.PrincipalStandard="address",Hn.PrincipalContract="contract",Hn.ResponseOk="ok",Hn.ResponseErr="err",Hn.OptionalNone="none",Hn.OptionalSome="some",Hn.List="list",Hn.Tuple="tuple",Hn.StringASCII="ascii",Hn.StringUTF8="utf8",function(t){t[t.int=0]="int",t[t.uint=1]="uint",t[t.buffer=2]="buffer",t[t.true=3]="true",t[t.false=4]="false",t[t.address=5]="address",t[t.contract=6]="contract",t[t.ok=7]="ok",t[t.err=8]="err",t[t.none=9]="none",t[t.some=10]="some",t[t.list=11]="list",t[t.tuple=12]="tuple",t[t.ascii=13]="ascii",t[t.utf8=14]="utf8"}(Un||(Un={}));const Mn=BigInt("0xffffffffffffffffffffffffffffffff"),jn=BigInt(0),Gn=BigInt("0x7fffffffffffffffffffffffffffffff"),Fn=BigInt("-170141183460469231731687303715884105728"),Wn=t=>{const n=e(t);if(n<jn)throw new RangeError("Cannot construct unsigned clarity integer from negative value");if(n>Mn)throw new RangeError(`Cannot construct unsigned clarity integer greater than ${Mn}`);return{type:Bn.UInt,value:n}},Vn=t=>{if(t.byteLength>1048576)throw new Error("Cannot construct clarity buffer that is greater than 1MB");return{type:Bn.Buffer,value:d(t)}};var qn,zn;function Xn(t,e){return{type:qn.LengthPrefixedList,lengthPrefixBytes:e||4,values:t}}function Jn(t){if(65!=f(t).byteLength)throw Error("Invalid signature");return{type:qn.MessageSignature,data:t}}function Zn(t,e,n){const r=e||1,i=n||J;if(Cr(t,i))throw new Error(`String length exceeds maximum bytes ${i}`);return{type:qn.LengthPrefixedString,content:t,lengthPrefixBytes:r,maxLengthBytes:i}}function Yn(t){const e=(0,$n.ns)(t);return{type:qn.Address,version:e[0],hash160:e[1]}}function Qn(t,e){return{pubKeyEncoding:t,type:qn.TransactionAuthField,contents:e}}(zn=qn||(qn={}))[zn.Address=0]="Address",zn[zn.Principal=1]="Principal",zn[zn.LengthPrefixedString=2]="LengthPrefixedString",zn[zn.MemoString=3]="MemoString",zn[zn.Asset=4]="Asset",zn[zn.PostCondition=5]="PostCondition",zn[zn.PublicKey=6]="PublicKey",zn[zn.LengthPrefixedList=7]="LengthPrefixedList",zn[zn.Payload=8]="Payload",zn[zn.MessageSignature=9]="MessageSignature",zn[zn.StructuredDataSignature=10]="StructuredDataSignature",zn[zn.TransactionAuthField=11]="TransactionAuthField";class tr extends Rt{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,_t.hash(t);const n=kt(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<i.length;t++)i[t]^=54;this.iHash.update(i),this.oHash=t.create();for(let t=0;t<i.length;t++)i[t]^=106;this.oHash.update(i),i.fill(0)}update(t){return _t.exists(this),this.iHash.update(t),this}digestInto(t){_t.exists(this),_t.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return t.finished=r,t.destroyed=i,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const er=(t,e,n)=>new tr(t,e).update(n).digest();er.create=(t,e)=>new tr(t,e);const nr=32;function rr(t){if(t.length<2*nr*2+1)throw new Error("Invalid signature");const e=t.slice(0,2),n=t.slice(2,2+2*nr),r=t.slice(2+2*nr);return{recoveryId:a(e),r:n,s:r}}function ir(t){return t.slice(-2)+t.slice(0,-2)}function or(t){const e="string"==typeof t?f(t):t;if(32!=e.length&&33!=e.length)throw new Error(`Improperly formatted private-key. Private-key byte length should be 32 or 33. Length provided: ${e.length}`);if(33==e.length&&1!==e[32])throw new Error("Improperly formatted private-key. 33 bytes indicate compressed key, but the last byte must be == 01");return e}function sr(t){return t="string"==typeof t?f(t):t,{type:qn.PublicKey,data:t}}function ar(t){return"string"==typeof t?t:d(t)}Nn.hmacSha256Sync=(t,...e)=>{const n=er.create(ne,t);return e.forEach(t=>n.update(t)),n.digest()};const cr=ar;function ur(t){return 33===("string"==typeof t?t.length/2:t.byteLength)}function hr(t){return!cr(t).startsWith("04")}function dr(t){const e=ur(t=or(t));return d(function(t,e=!1){return Ze.fromPrivateKey(t).toRawBytes(e)}(t.slice(0,32),e))}function fr(t,e){t=or(t);const[n,r]=function(t,e,n={}){const{seed:r,m:i,d:o}=function(t,e,n){if(null==t)throw new Error(`sign: expected valid message hash, not "${t}"`);const r=fn(t),i=xn(e),o=[Tn(i),_n(r)];if(null!=n){!0===n&&(n=Nn.randomBytes(Le));const t=fn(n);if(t.length!==Le)throw new Error(`sign: Expected ${Le} bytes of extra data`);o.push(t)}return{seed:en(...o),m:In(r),d:i}}(t,e,n.extraEntropy),s=new An(Me,Ke);let a;for(s.reseedSync(r);!(a=vn(s.generateSync(),i,o,n.canonical));)s.reseedSync();return function(t,e){const{sig:n,recovery:r}=t,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},e),s=i?n.toDERRawBytes():n.toCompactRawBytes();return o?[s,r]:s}(a,n)}(e,t.slice(0,32),{canonical:!0,recovered:!0});if(null==r)throw new Error("No signature recoveryId received");return s(r,1)+tn.fromHex(n).toCompactHex()}function lr(t,e,n,r){if(0===r.length)throw Error("Invalid number of public keys");if(!(e!==ct.P2PKH&&e!==ct.P2WPKH||1===r.length&&1===n))throw Error("Invalid number of public keys or signatures");if((e===ct.P2WPKH||e===ct.P2WSH||e===ct.P2WSHNonSequential)&&!r.map(t=>t.data).every(hr))throw Error("Public keys must be compressed for segwit");switch(e){case ct.P2PKH:return pr(t,kr(r[0].data));case ct.P2WPKH:return pr(t,Rr(r[0].data));case ct.P2SH:case ct.P2SHNonSequential:return pr(t,Or(n,r.map(Zr)));case ct.P2WSH:case ct.P2WSHNonSequential:return pr(t,Nr(n,r.map(Zr)))}}function pr(t,e){return{type:qn.Address,version:t,hash160:e}}function gr(t){return(0,$n.bJ)(t.version,t.hash160)}function yr(t){const[e,n,r]=t.split(/\.|::/);var i,o,s;return i=e,o=n,s=r,{type:qn.Asset,address:Yn(i),contractName:Zn(o),assetName:Zn(s)}}function wr(t){if(t.includes(".")){const[e,n]=t.split(".");return function(t,e){const n=Yn(t),r=Zn(e);return{type:qn.Principal,prefix:ft.Contract,address:n,contractName:r}}(e,n)}return function(t){const e=Yn(t);return{type:qn.Principal,prefix:ft.Standard,address:e}}(t)}function br(t){if(t.includes(".")){const[e,n]=t.split(".");return function(t,e){return mr(Yn(t),Zn(e))}(e,n)}return function(t){const e=Yn(t);return{type:Bn.PrincipalStandard,value:gr(e)}}(t)}function mr(t,e){if(l(e.content).byteLength>=128)throw new Error("Contract name must be less than 128 bytes");return{type:Bn.PrincipalContract,value:`${gr(t)}.${e.content}`}}function Ar(){return{type:Bn.OptionalNone}}function Er(t){return{type:Bn.OptionalSome,value:t}}function Sr(t){for(const e in t)if(!Br(e))throw new Error(`"${e}" is not a valid Clarity name`);return{type:Bn.Tuple,value:t}}const vr=t=>({type:Bn.StringASCII,value:t});function xr(t){let n;if("string"==typeof t){const e="0x"===t.slice(0,2).toLowerCase();n=new X(f(e?t.slice(2):t))}else n=t instanceof Uint8Array?new X(t):t;switch(n.readUInt8Enum(Un,t=>{throw new L(`Cannot recognize Clarity Type: ${t}`)})){case Un.int:return(t=>{"string"==typeof t&&t.toLowerCase().startsWith("0x")&&(t=u(f(t))),E(t,Uint8Array)&&(t=u(t));const n=e(t);if(n>Gn)throw new RangeError(`Cannot construct clarity integer from value greater than ${Gn}`);if(n<Fn)throw new RangeError(`Cannot construct clarity integer form value less than ${Fn}`);return{type:Bn.Int,value:n}})(u(n.readBytes(16)));case Un.uint:return Wn(n.readBytes(16));case Un.buffer:const t=n.readUInt32BE();return Vn(n.readBytes(t));case Un.true:return{type:Bn.BoolTrue};case Un.false:return{type:Bn.BoolFalse};case Un.address:return s=Mr(n),{type:Bn.PrincipalStandard,value:gr(s)};case Un.contract:return mr(Mr(n),Fr(n));case Un.ok:return o=xr(n),{type:Bn.ResponseOk,value:o};case Un.err:return function(t){return{type:Bn.ResponseErr,value:t}}(xr(n));case Un.none:return Ar();case Un.some:return Er(xr(n));case Un.list:const a=n.readUInt32BE(),c=[];for(let t=0;t<a;t++)c.push(xr(n));return i=c,{type:Bn.List,value:i};case Un.tuple:const h=n.readUInt32BE(),d={};for(let t=0;t<h;t++){const t=Fr(n).content;if(void 0===t)throw new L('"content" is undefined');d[t]=xr(n)}return Sr(d);case Un.ascii:const l=n.readUInt32BE(),g=y(n.readBytes(l));return vr(g);case Un.utf8:const w=n.readUInt32BE(),b=p(n.readBytes(w));return r=b,{type:Bn.StringUTF8,value:r};default:throw new L("Unable to deserialize Clarity Value from Uint8Array. Could not find valid Clarity Type.")}var r,i,o,s}const Cr=(t,e)=>!!t&&l(t).length>e;function Ir(t){return Ln()(t)}function _r(t,e){const n=Ir(t);return delete n[e],n}const Tr=t=>zt(ne(t)),Pr=t=>d(Te(t)),kr=t=>d(Tr(t)),Rr=t=>{const e=Tr(t),n=m(new Uint8Array([0]),new Uint8Array([e.length]),e);return d(Tr(n))},Or=(t,e)=>{if(t>15||e.length>15)throw Error("P2SH multisig address can only contain up to 15 public keys");const n=[];n.push(80+t),e.forEach(t=>{n.push(t.length),n.push(t)}),n.push(80+e.length),n.push(174);const r=A(n);return d(Tr(r))},Nr=(t,e)=>{if(t>15||e.length>15)throw Error("P2WSH multisig address can only contain up to 15 public keys");const n=[];n.push(80+t),e.forEach(t=>{n.push(t.length),n.push(t)}),n.push(80+e.length),n.push(174);const r=A(n),i=ne(r),o=[];o.push(0),o.push(i.length),o.push(i);const s=A(o);return d(Tr(s))};function Br(t){return/^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/.test(t)&&t.length<128}const Ur=t=>{if(t.okay)return xr(t.result);throw new Error(t.cause)};function Hr(t,e){return A([Kn(t),e])}function $r(t,e){const n=[],r="ascii"==e?g(t.value):l(t.value),i=new Uint8Array(4);return W(i,r.length,0),n.push(i),n.push(r),Hr(t.type,A(n))}function Dr(t){switch(t.type){case Bn.BoolTrue:case Bn.BoolFalse:return function(t){return new Uint8Array([Kn(t.type)])}(t);case Bn.OptionalNone:case Bn.OptionalSome:return(e=t).type===Bn.OptionalNone?new Uint8Array([Kn(e.type)]):Hr(e.type,Dr(e.value));case Bn.Buffer:return function(t){const e=new Uint8Array(4);return W(e,Math.ceil(t.value.length/2),0),Hr(t.type,m(e,f(t.value)))}(t);case Bn.UInt:return function(t){const e=c(BigInt(t.value),Y);return Hr(t.type,e)}(t);case Bn.Int:return function(t){const e=c(function(t,e){if(t<-(BigInt(1)<<e-BigInt(1))||(BigInt(1)<<e-BigInt(1))-BigInt(1)<t)throw`Unable to represent integer in width: ${e}`;return t>=BigInt(0)?BigInt(t):t+(BigInt(1)<<e)}(BigInt(t.value),BigInt(Z)),Y);return Hr(t.type,e)}(t);case Bn.PrincipalStandard:return function(t){return Hr(t.type,Kr(Yn(t.value)))}(t);case Bn.PrincipalContract:return function(t){const[e,n]=function(t){const[e,n]=t.split(".");if(!e||!n)throw new Error(`Invalid contract identifier: ${t}`);return[e,n]}(t.value);return Hr(t.type,m(Kr(Yn(e)),Gr(Zn(n))))}(t);case Bn.ResponseOk:case Bn.ResponseErr:return function(t){return Hr(t.type,Dr(t.value))}(t);case Bn.List:return function(t){const e=[],n=new Uint8Array(4);W(n,t.value.length,0),e.push(n);for(const n of t.value){const t=Dr(n);e.push(t)}return Hr(t.type,A(e))}(t);case Bn.Tuple:return function(t){const e=[],n=new Uint8Array(4);W(n,Object.keys(t.value).length,0),e.push(n);const r=Object.keys(t.value).sort((t,e)=>t.localeCompare(e));for(const n of r){const r=Zn(n);e.push(Gr(r));const i=Dr(t.value[n]);e.push(i)}return Hr(t.type,A(e))}(t);case Bn.StringASCII:return function(t){return $r(t,"ascii")}(t);case Bn.StringUTF8:return function(t){return $r(t,"utf8")}(t);default:throw new D("Unable to serialize. Invalid Clarity Value.")}var e}function Lr(e){switch(e.type){case qn.Address:return Kr(e);case qn.Principal:return jr(e);case qn.LengthPrefixedString:return Gr(e);case qn.MemoString:return function(t){const e=[],n=l(t.content),r=(i=d(n),o=68,i.padEnd(o,"0"));var i,o;return e.push(f(r)),A(e)}(e);case qn.Asset:return Wr(e);case qn.PostCondition:return function(e){const n=[];if(n.push(e.conditionType),n.push(jr(e.principal)),e.conditionType!==st.Fungible&&e.conditionType!==st.NonFungible||n.push(Wr(e.asset)),e.conditionType===st.NonFungible&&n.push(Dr(e.assetName)),n.push(e.conditionCode),e.conditionType===st.STX||e.conditionType===st.Fungible){if(e.amount>BigInt("0xffffffffffffffff"))throw new D("The post-condition amount may not be larger than 8 bytes");n.push(t(e.amount,8))}return A(n)}(e);case qn.PublicKey:return Zr(e);case qn.LengthPrefixedList:return qr(e);case qn.Payload:return Xr(e);case qn.TransactionAuthField:return function(t){const e=[];switch(t.contents.type){case qn.PublicKey:e.push(t.pubKeyEncoding===ut.Compressed?gt.PublicKeyCompressed:gt.PublicKeyUncompressed),e.push(f((n=t.contents.data,Ze.fromHex(cr(n)).toHex(!0))));break;case qn.MessageSignature:e.push(t.pubKeyEncoding===ut.Compressed?gt.SignatureCompressed:gt.SignatureUncompressed),e.push(Jr(t.contents))}var n;return A(e)}(e);case qn.MessageSignature:return Jr(e)}}function Kr(t){const e=[];return e.push(f(s(t.version,1))),e.push(f(t.hash160)),A(e)}function Mr(t){const e=E(t,X)?t:new X(t),n=a(d(e.readBytes(1))),r=d(e.readBytes(20));return{type:qn.Address,version:n,hash160:r}}function jr(t){const e=[];return e.push(t.prefix),t.prefix!==ft.Standard&&t.prefix!==ft.Contract||e.push(Kr(t.address)),t.prefix===ft.Contract&&e.push(Gr(t.contractName)),A(e)}function Gr(t){const e=[],n=l(t.content),r=n.byteLength;return e.push(f(s(r,t.lengthPrefixBytes))),e.push(n),A(e)}function Fr(t,e,n){e=e||1;const r=E(t,X)?t:new X(t),i=a(d(r.readBytes(e)));return Zn(p(r.readBytes(i)),e,n??128)}function Wr(t){const e=[];return e.push(Kr(t.address)),e.push(Gr(t.contractName)),e.push(Gr(t.assetName)),A(e)}function Vr(t){const e=E(t,X)?t:new X(t);return{type:qn.Asset,address:Mr(e),contractName:Fr(e),assetName:Fr(e)}}function qr(t){const e=t.values,n=[];n.push(f(s(e.length,t.lengthPrefixBytes)));for(const t of e)n.push(Lr(t));return A(n)}function zr(t){const e=E(t,X)?t:new X(t),n=e.readUInt8Enum(st,t=>{throw new L(`Could not read ${t} as PostConditionType`)}),r=function(t){const e=E(t,X)?t:new X(t),n=e.readUInt8Enum(ft,t=>{throw new L(`Unexpected Principal payload type: ${t}`)});if(n===ft.Origin)return{type:qn.Principal,prefix:n};const r=Mr(e);if(n===ft.Standard)return{type:qn.Principal,prefix:n,address:r};const i=Fr(e);return{type:qn.Principal,prefix:n,address:r,contractName:i}}(e);let i,o,s;switch(n){case st.STX:return i=e.readUInt8Enum(ht,t=>{throw new L(`Could not read ${t} as FungibleConditionCode`)}),s=BigInt(`0x${d(e.readBytes(8))}`),{type:qn.PostCondition,conditionType:st.STX,principal:r,conditionCode:i,amount:s};case st.Fungible:return o=Vr(e),i=e.readUInt8Enum(ht,t=>{throw new L(`Could not read ${t} as FungibleConditionCode`)}),s=BigInt(`0x${d(e.readBytes(8))}`),{type:qn.PostCondition,conditionType:st.Fungible,principal:r,conditionCode:i,amount:s,asset:o};case st.NonFungible:o=Vr(e);const t=xr(e);return i=e.readUInt8Enum(dt,t=>{throw new L(`Could not read ${t} as FungibleConditionCode`)}),{type:qn.PostCondition,conditionType:st.NonFungible,principal:r,conditionCode:i,asset:o,assetName:t}}}function Xr(e){const n=[];switch(n.push(e.payloadType),e.payloadType){case Q.TokenTransfer:n.push(Dr(e.recipient)),n.push(t(e.amount,8)),n.push(Lr(e.memo));break;case Q.ContractCall:n.push(Lr(e.contractAddress)),n.push(Lr(e.contractName)),n.push(Lr(e.functionName));const r=new Uint8Array(4);W(r,e.functionArgs.length,0),n.push(r),e.functionArgs.forEach(t=>{n.push(Dr(t))});break;case Q.SmartContract:n.push(Lr(e.contractName)),n.push(Lr(e.codeBody));break;case Q.VersionedSmartContract:n.push(e.clarityVersion),n.push(Lr(e.contractName)),n.push(Lr(e.codeBody));break;case Q.PoisonMicroblock:break;case Q.Coinbase:n.push(e.coinbaseBytes);break;case Q.CoinbaseToAltRecipient:n.push(e.coinbaseBytes),n.push(Dr(e.recipient));break;case Q.NakamotoCoinbase:n.push(e.coinbaseBytes),n.push(Dr(e.recipient?Er(e.recipient):Ar())),n.push(e.vrfProof);break;case Q.TenureChange:n.push(f(e.tenureHash)),n.push(f(e.previousTenureHash)),n.push(f(e.burnViewHash)),n.push(f(e.previousTenureEnd)),n.push(W(new Uint8Array(4),e.previousTenureBlocks)),n.push(F(new Uint8Array(1),e.cause)),n.push(f(e.publicKeyHash))}return A(n)}function Jr(t){return f(t.data)}function Zr(t){return t.data.slice()}function Yr(){return{type:qn.MessageSignature,data:d(new Uint8Array(65))}}function Qr(t,n,r,i){const o=lr(0,t,1,[sr(n)]).hash160,s=hr(n)?ut.Compressed:ut.Uncompressed;return{hashMode:t,signer:o,nonce:e(r),fee:e(i),keyEncoding:s,signature:Yr()}}function ti(t){return"signature"in t}function ei(t){return t===ct.P2SH||t===ct.P2WSH}function ni(t){return t===ct.P2SHNonSequential||t===ct.P2WSHNonSequential}function ri(t){const e=Ir(t);return e.nonce=0,e.fee=0,ti(e)?e.signature=Yr():e.fields=[],{...e,nonce:BigInt(0),fee:BigInt(0)}}function ii(e){return ti(e)?function(e){return A([e.hashMode,f(e.signer),t(e.nonce,8),t(e.fee,8),e.keyEncoding,Jr(e.signature)])}(e):function(e){const n=[e.hashMode,f(e.signer),t(e.nonce,8),t(e.fee,8)],r=Xn(e.fields);n.push(qr(r));const i=new Uint8Array(2);return function(t,e,n=0){t[n+0]=e>>>8,t[n+1]=e>>>0}(i,e.signaturesRequired,0),n.push(i),A(n)}(e)}function oi(e,n,r,i){const o=e+d(new Uint8Array([n]))+d(t(r,8))+d(t(i,8));if(49!==f(o).byteLength)throw Error("Invalid signature hash length");return Pr(f(o))}function si(t,e,n){var r;const i=f(t+((r=(hr(e.data)?ut.Compressed:ut.Uncompressed).toString(16)).length%2?`0${r}`:r)+n);if(i.byteLength>98)throw Error("Invalid signature hash length");return Pr(i)}function ai(t,e,n,i,o,s){const a=oi(t,e,n,i),c=sr(function(t,e,n=ut.Compressed){const i=rr(e),o=new tn(r(i.r),r(i.s)),s=Ze.fromSignature(t,o,i.recoveryId),a=n===ut.Compressed;return s.toHex(a)}(a,s,o));return{pubKey:c,nextSigHash:si(a,c,s)}}function ci(t){return{authType:at.Standard,spendingCondition:t}}function ui(t,e){return{authType:at.Sponsored,spendingCondition:t,sponsorSpendingCondition:e||Qr(ct.P2PKH,"0".repeat(66),0,0)}}function hi(t){if(t.spendingCondition)switch(t.authType){case at.Standard:return ci(ri(t.spendingCondition));case at.Sponsored:return ui(ri(t.spendingCondition),function(){const t=Qr(ct.P2PKH,"",0,0);return t.signer=(qn.Address,T.MainnetSingleSig,"0".repeat(40)),t.keyEncoding=ut.Compressed,t.signature=Yr(),t}());default:throw new M("Unexpected authorization type for signing")}throw new Error("Authorization missing SpendingCondition")}class di{constructor({auth:t,payload:n,postConditions:r=Xn([]),postConditionMode:i=ot.Deny,transactionVersion:o,chainId:s,network:a="mainnet"}){a=U(a),this.transactionVersion=o??a.transactionVersion,this.chainId=s??a.chainId,this.auth=t,this.payload="amount"in n?{...n,amount:e(n.amount)}:n,this.postConditionMode=i,this.postConditions=r,this.anchorMode=et.Any}signBegin(){const t=Ir(this);return t.auth=hi(t.auth),t.txid()}verifyBegin(){const t=Ir(this);return t.auth=hi(t.auth),t.txid()}verifyOrigin(){return function(t,e){switch(t.authType){case at.Standard:case at.Sponsored:return function(t,e,n){return ti(t)?function(t,e,n){const{pubKey:r,nextSigHash:i}=ai(e,n,t.fee,t.nonce,t.keyEncoding,t.signature.data),o=lr(0,t.hashMode,1,[r]).hash160;if(o!==t.signer)throw new j(`Signer hash does not equal hash of public key(s): ${o} != ${t.signer}`);return i}(t,e,n):function(t,e,n){const r=[];let i=e,o=!1,s=0;for(const e of t.fields)switch(e.contents.type){case qn.PublicKey:hr(e.contents.data)||(o=!0),r.push(e.contents);break;case qn.MessageSignature:e.pubKeyEncoding===ut.Uncompressed&&(o=!0);const{pubKey:a,nextSigHash:c}=ai(i,n,t.fee,t.nonce,e.pubKeyEncoding,e.contents.data);if(ei(t.hashMode)&&(i=c),r.push(a),s+=1,65536===s)throw new j("Too many signatures")}if(ei(t.hashMode)&&s!==t.signaturesRequired||ni(t.hashMode)&&s<t.signaturesRequired)throw new j("Incorrect number of signatures");if(o&&(t.hashMode===ct.P2WSH||t.hashMode===ct.P2WSHNonSequential))throw new j("Uncompressed keys are not allowed in this hash mode");const a=lr(0,t.hashMode,t.signaturesRequired,r).hash160;if(a!==t.signer)throw new j(`Signer hash does not equal hash of public key(s): ${a} != ${t.signer}`);return i}(t,e,n)}(t.spendingCondition,e,at.Standard);default:throw new M("Invalid origin auth type")}}(this.auth,this.verifyBegin())}signNextOrigin(t,e){if(void 0===this.auth.spendingCondition)throw new Error('"auth.spendingCondition" is undefined');if(void 0===this.auth.authType)throw new Error('"auth.authType" is undefined');return this.signAndAppend(this.auth.spendingCondition,t,at.Standard,e)}signNextSponsor(t,e){if(this.auth.authType===at.Sponsored)return this.signAndAppend(this.auth.sponsorSpendingCondition,t,at.Sponsored,e);throw new Error('"auth.sponsorSpendingCondition" is undefined')}appendPubkey(t){const e="object"==typeof t&&"type"in t?t:sr(t),n=this.auth.spendingCondition;if(!n||ti(n))throw new Error("Can't append public key to a singlesig condition");{const t=hr(e.data);n.fields.push(Qn(t?ut.Compressed:ut.Uncompressed,e))}}signAndAppend(t,e,n,r){const{nextSig:i,nextSigHash:o}=function(t,e,n,r,i){const o=oi(t,e,n,r),s=fr(i,o);return{nextSig:s,nextSigHash:si(o,sr(dr(i)),s)}}(e,n,t.fee,t.nonce,r);if(ti(t))t.signature=Jn(i);else{const e=ur(r);t.fields.push(Qn(e?ut.Compressed:ut.Uncompressed,Jn(i)))}return o}txid(){const t=this.serializeBytes();return Pr(t)}setSponsor(t){if(this.auth.authType!=at.Sponsored)throw new M("Cannot sponsor sign a non-sponsored transaction");this.auth=function(t,n){return{...t,sponsorSpendingCondition:{...n,nonce:e(n.nonce),fee:e(n.fee)}}}(this.auth,t)}setFee(t){this.auth=function(t,n){switch(t.authType){case at.Standard:const r={...t.spendingCondition,fee:e(n)};return{...t,spendingCondition:r};case at.Sponsored:const i={...t.sponsorSpendingCondition,fee:e(n)};return{...t,sponsorSpendingCondition:i}}}(this.auth,t)}setNonce(t){this.auth=function(t,n){const r={...t.spendingCondition,nonce:e(n)};return{...t,spendingCondition:r}}(this.auth,t)}setSponsorNonce(t){if(this.auth.authType!=at.Sponsored)throw new M("Cannot sponsor sign a non-sponsored transaction");this.auth=function(t,n){const r={...t.sponsorSpendingCondition,nonce:e(n)};return{...t,sponsorSpendingCondition:r}}(this.auth,t)}serialize(){return d(this.serializeBytes())}serializeBytes(){if(void 0===this.transactionVersion)throw new D('"transactionVersion" is undefined');if(void 0===this.chainId)throw new D('"chainId" is undefined');if(void 0===this.auth)throw new D('"auth" is undefined');if(void 0===this.payload)throw new D('"payload" is undefined');const t=[];t.push(this.transactionVersion);const e=new Uint8Array(4);return W(e,this.chainId,0),t.push(e),t.push(function(t){const e=[];switch(e.push(t.authType),t.authType){case at.Standard:e.push(ii(t.spendingCondition));break;case at.Sponsored:e.push(ii(t.spendingCondition)),e.push(ii(t.sponsorSpendingCondition))}return A(e)}(this.auth)),t.push(this.anchorMode),t.push(this.postConditionMode),t.push(qr(this.postConditions)),t.push(Xr(this.payload)),A(t)}}function fi(t){return(e=t.transactionVersion,t=>t[e])({[_.Mainnet]:k,[_.Testnet]:R});var e}async function li({transaction:t,attachment:e,network:r,client:i}){const o=t.serialize(),s=e?"string"==typeof e?e:d(e):void 0,a=e?{tx:o,attachment:s}:{tx:o},c={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)},u=r??fi(t),h=Object.assign({},H(U(u)),i),f=`${h.baseUrl}/v2/transactions`,l=await h.fetch(f,c);if(!l.ok)try{return await l.json()}catch(t){throw Error("Failed to broadcast transaction (unable to parse node response).",{cause:t})}const p=await l.text(),g=p.replace(/["]+/g,"");if(64!==(y=n(y=g)).length||!/^[0-9a-fA-F]+$/.test(y))throw new Error(p);var y;return{txid:g}}async function pi({contractName:t,contractAddress:e,functionName:n,functionArgs:r,senderAddress:i,network:o="mainnet",client:s}){const a={sender:i,arguments:r.map(t=>`0x${d(Dr(t))}`)},c={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)},u=encodeURIComponent(n),h=Object.assign({},H(U(o)),s),f=`${h.baseUrl}/v2/contracts/call-read/${e}/${t}/${u}`,l=await h.fetch(f,c);if(!l.ok){const t=await l.text().catch(()=>"");throw new Error(`Error calling read-only function. Response ${l.status}: ${l.statusText}. Attempted to fetch ${f} and failed with the message: "${t}"`)}return await l.json().then(Ur)}function gi(t,e="hex"){switch(t.type){case Bn.BoolTrue:return"true";case Bn.BoolFalse:return"false";case Bn.Int:return t.value.toString();case Bn.UInt:return`u${t.value.toString()}`;case Bn.Buffer:if("tryAscii"===e){const e=y(f(t.value));if(/[ -~]/.test(e))return JSON.stringify(e)}return`0x${t.value}`;case Bn.OptionalNone:return"none";case Bn.OptionalSome:return`(some ${gi(t.value,e)})`;case Bn.ResponseErr:return`(err ${gi(t.value,e)})`;case Bn.ResponseOk:return`(ok ${gi(t.value,e)})`;case Bn.PrincipalStandard:case Bn.PrincipalContract:return t.value;case Bn.List:return`(list ${t.value.map(t=>gi(t,e)).join(" ")})`;case Bn.Tuple:return`(tuple ${Object.keys(t.value).map(n=>`(${n} ${gi(t.value[n],e)})`).join(" ")})`;case Bn.StringASCII:return`"${t.value}"`;case Bn.StringUTF8:return`u"${t.value}"`}}function yi(t){switch(t.type){case Bn.BoolTrue:case Bn.BoolFalse:return"bool";case Bn.Int:return"int";case Bn.UInt:return"uint";case Bn.Buffer:return`(buff ${Math.ceil(t.value.length/2)})`;case Bn.OptionalNone:return"(optional none)";case Bn.OptionalSome:return`(optional ${yi(t.value)})`;case Bn.ResponseErr:return`(response UnknownType ${yi(t.value)})`;case Bn.ResponseOk:return`(response ${yi(t.value)} UnknownType)`;case Bn.PrincipalStandard:case Bn.PrincipalContract:return"principal";case Bn.List:return`(list ${t.value.length} ${t.value.length?yi(t.value[0]):"UnknownType"})`;case Bn.Tuple:return`(tuple ${Object.keys(t.value).map(e=>`(${e} ${yi(t.value[e])})`).join(" ")})`;case Bn.StringASCII:return`(string-ascii ${g(t.value).length})`;case Bn.StringUTF8:return`(string-utf8 ${l(t.value).length})`}}var wi;!function(t){t[t.ClarityAbiTypeUInt128=1]="ClarityAbiTypeUInt128",t[t.ClarityAbiTypeInt128=2]="ClarityAbiTypeInt128",t[t.ClarityAbiTypeBool=3]="ClarityAbiTypeBool",t[t.ClarityAbiTypePrincipal=4]="ClarityAbiTypePrincipal",t[t.ClarityAbiTypeNone=5]="ClarityAbiTypeNone",t[t.ClarityAbiTypeBuffer=6]="ClarityAbiTypeBuffer",t[t.ClarityAbiTypeResponse=7]="ClarityAbiTypeResponse",t[t.ClarityAbiTypeOptional=8]="ClarityAbiTypeOptional",t[t.ClarityAbiTypeTuple=9]="ClarityAbiTypeTuple",t[t.ClarityAbiTypeList=10]="ClarityAbiTypeList",t[t.ClarityAbiTypeStringAscii=11]="ClarityAbiTypeStringAscii",t[t.ClarityAbiTypeStringUtf8=12]="ClarityAbiTypeStringUtf8",t[t.ClarityAbiTypeTraitReference=13]="ClarityAbiTypeTraitReference"}(wi||(wi={}));const bi=t=>"string"==typeof t,mi=t=>void 0!==t.buffer,Ai=t=>void 0!==t["string-ascii"],Ei=t=>void 0!==t["string-utf8"],Si=t=>void 0!==t.response,vi=t=>void 0!==t.optional,xi=t=>void 0!==t.tuple,Ci=t=>void 0!==t.list;function Ii(t){if(bi(t))return"int128"===t?"int":"uint128"===t?"uint":t;if(mi(t))return`(buff ${t.buffer.length})`;if(Ai(t))return`(string-ascii ${t["string-ascii"].length})`;if(Ei(t))return`(string-utf8 ${t["string-utf8"].length})`;if(Si(t))return`(response ${Ii(t.response.ok)} ${Ii(t.response.error)})`;if(vi(t))return`(optional ${Ii(t.optional)})`;if(xi(t))return`(tuple ${t.tuple.map(t=>`(${t.name} ${Ii(t.type)})`).join(" ")})`;if(Ci(t))return`(list ${t.list.length} ${Ii(t.list.type)})`;throw new Error(`Type string unsupported for Clarity type: ${JSON.stringify(t)}`)}function _i(t,e){const n=function(t){if(bi(t)){if("uint128"===t)return{id:wi.ClarityAbiTypeUInt128,type:t};if("int128"===t)return{id:wi.ClarityAbiTypeInt128,type:t};if("bool"===t)return{id:wi.ClarityAbiTypeBool,type:t};if("principal"===t)return{id:wi.ClarityAbiTypePrincipal,type:t};if("trait_reference"===t)return{id:wi.ClarityAbiTypeTraitReference,type:t};if("none"===t)return{id:wi.ClarityAbiTypeNone,type:t};throw new Error(`Unexpected Clarity ABI type primitive: ${JSON.stringify(t)}`)}if(mi(t))return{id:wi.ClarityAbiTypeBuffer,type:t};if(Si(t))return{id:wi.ClarityAbiTypeResponse,type:t};if(vi(t))return{id:wi.ClarityAbiTypeOptional,type:t};if(xi(t))return{id:wi.ClarityAbiTypeTuple,type:t};if(Ci(t))return{id:wi.ClarityAbiTypeList,type:t};if(Ai(t))return{id:wi.ClarityAbiTypeStringAscii,type:t};if(Ei(t))return{id:wi.ClarityAbiTypeStringUtf8,type:t};throw new Error(`Unexpected Clarity ABI type: ${JSON.stringify(t)}`)}(e);switch(t.type){case Bn.BoolTrue:case Bn.BoolFalse:return n.id===wi.ClarityAbiTypeBool;case Bn.Int:return n.id===wi.ClarityAbiTypeInt128;case Bn.UInt:return n.id===wi.ClarityAbiTypeUInt128;case Bn.Buffer:return n.id===wi.ClarityAbiTypeBuffer&&n.type.buffer.length>=Math.ceil(t.value.length/2);case Bn.StringASCII:return n.id===wi.ClarityAbiTypeStringAscii&&n.type["string-ascii"].length>=t.value.length;case Bn.StringUTF8:return n.id===wi.ClarityAbiTypeStringUtf8&&n.type["string-utf8"].length>=t.value.length;case Bn.OptionalNone:return n.id===wi.ClarityAbiTypeNone||n.id===wi.ClarityAbiTypeOptional;case Bn.OptionalSome:return n.id===wi.ClarityAbiTypeOptional&&_i(t.value,n.type.optional);case Bn.ResponseErr:return n.id===wi.ClarityAbiTypeResponse&&_i(t.value,n.type.response.error);case Bn.ResponseOk:return n.id===wi.ClarityAbiTypeResponse&&_i(t.value,n.type.response.ok);case Bn.PrincipalContract:return n.id===wi.ClarityAbiTypePrincipal||n.id===wi.ClarityAbiTypeTraitReference;case Bn.PrincipalStandard:return n.id===wi.ClarityAbiTypePrincipal;case Bn.List:return n.id==wi.ClarityAbiTypeList&&n.type.list.length>=t.value.length&&t.value.every(t=>_i(t,n.type.list.type));case Bn.Tuple:if(n.id==wi.ClarityAbiTypeTuple){const e=Ir(t.value);for(let t=0;t<n.type.tuple.length;t++){const r=n.type.tuple[t],i=r.name,o=e[i];if(!o)return!1;if(!_i(o,r.type))return!1;delete e[i]}return!0}return!1;default:return!1}}var Ti;function Pi(t){return Ti[t]}!function(t){t[t.eq=1]="eq",t[t.gt=2]="gt",t[t.lt=4]="lt",t[t.gte=3]="gte",t[t.lte=5]="lte",t[t.sent=16]="sent",t[t["not-sent"]=17]="not-sent"}(Ti||(Ti={}));class ki{constructor(t){this.transaction=t,this.sigHash=t.signBegin(),this.originDone=!1,this.checkOversign=!0,this.checkOverlap=!0;const e=t.auth.spendingCondition;if(e&&!ti(e)){if(e.fields.filter(t=>t.contents.type===qn.MessageSignature).length>=e.signaturesRequired)throw new Error("SpendingCondition has more signatures than are expected");e.fields.forEach(n=>{if(n.contents.type!==qn.MessageSignature)return;const r=n.contents,i=ai(this.sigHash,t.auth.authType,e.fee,e.nonce,ut.Compressed,r.data);ni(e.hashMode)||(this.sigHash=i.nextSigHash)})}}static createSponsorSigner(t,e){if(t.auth.authType!=at.Sponsored)throw new M("Cannot add sponsor to non-sponsored transaction");const n=Ir(t);n.setSponsor(e);const r=n.verifyOrigin(),i=new this(n);return i.originDone=!0,i.sigHash=r,i.checkOversign=!0,i.checkOverlap=!0,i}signOrigin(t){if(this.checkOverlap&&this.originDone)throw new M("Cannot sign origin after sponsor key");if(void 0===this.transaction.auth)throw new M('"transaction.auth" is undefined');if(void 0===this.transaction.auth.spendingCondition)throw new M('"transaction.auth.spendingCondition" is undefined');const e=this.transaction.auth.spendingCondition;if((e.hashMode===ct.P2SH||e.hashMode===ct.P2WSH)&&this.checkOversign&&e.fields.filter(t=>t.contents.type===qn.MessageSignature).length>=e.signaturesRequired)throw new Error("Origin would have too many signatures");const n=this.transaction.signNextOrigin(this.sigHash,t);(ti(this.transaction.auth.spendingCondition)||ei(this.transaction.auth.spendingCondition.hashMode))&&(this.sigHash=n)}appendOrigin(t){const e="object"==typeof t&&"type"in t?t:sr(t);if(this.checkOverlap&&this.originDone)throw Error("Cannot append public key to origin after sponsor key");if(void 0===this.transaction.auth)throw new Error('"transaction.auth" is undefined');if(void 0===this.transaction.auth.spendingCondition)throw new Error('"transaction.auth.spendingCondition" is undefined');this.transaction.appendPubkey(e)}signSponsor(t){if(void 0===this.transaction.auth)throw new M('"transaction.auth" is undefined');if(this.transaction.auth.authType!==at.Sponsored)throw new M('"transaction.auth.authType" is not AuthType.Sponsored');const e=this.transaction.signNextSponsor(this.sigHash,t);this.sigHash=e,this.originDone=!0}getTxInComplete(){return Ir(this.transaction)}resume(t){this.transaction=Ir(t),this.sigHash=t.signBegin()}}async function Ri(t){const n={fee:BigInt(0),nonce:BigInt(0),network:k,postConditionMode:ot.Deny,sponsored:!1},r=Object.assign(n,t);r.network=U(r.network),r.client=Object.assign({},H(r.network),r.client),r.postConditionMode=function(t){if("number"==typeof t)return t;if("allow"===t)return ot.Allow;if("deny"===t)return ot.Deny;throw new Error(`Invalid post condition mode: ${t}`)}(r.postConditionMode);const i=(o=r.contractAddress,s=r.contractName,a=r.functionName,c=r.functionArgs,"string"==typeof s&&(s=Zn(s)),"string"==typeof a&&(a=Zn(a)),{type:qn.Payload,payloadType:Q.ContractCall,contractAddress:"string"==typeof o?Yn(o):o,contractName:s,functionName:a,functionArgs:c});var o,s,a,c;if(r?.validateWithAbi){let t;if("boolean"==typeof r.validateWithAbi){if(!r?.network)throw new Error("Network option must be provided in order to validate with ABI");t=await async function({contractAddress:t,contractName:e,network:n="mainnet",client:r}){const i=Object.assign({},H(U(n)),r),o=`${i.baseUrl}/v2/contracts/interface/${t}/${e}`,s=await i.fetch(o);if(!s.ok){const n=await s.text().catch(()=>"");throw new Error(`Error fetching contract ABI for contract "${e}" at address ${t}. Response ${s.status}: ${s.statusText}. Attempted to fetch ${o} and failed with the message: "${n}"`)}return JSON.parse(await s.text())}({...r})}else t=r.validateWithAbi;!function(t,e){const n=e.functions.filter(e=>e.name===t.functionName.content);if(1===n.length){const e=n[0].args;if(t.functionArgs.length!==e.length)throw new Error(`Clarity function expects ${e.length} argument(s) but received ${t.functionArgs.length}`);for(let n=0;n<t.functionArgs.length;n++){const r=t.functionArgs[n],i=e[n];if(!_i(r,i.type)){const e=n+1;throw new Error(`Clarity function \`${t.functionName.content}\` expects argument ${e} to be of type ${Ii(i.type)}, not ${yi(r)}`)}}return!0}throw 0===n.length?new Error(`ABI doesn't contain a function with the name ${t.functionName.content}`):new Error(`Malformed ABI. Contains multiple functions with the name ${t.functionName.content}`)}(i,t)}let u=null;if("publicKey"in r)u=Qr(ct.P2PKH,r.publicKey,r.nonce,r.fee);else{const t=r.useNonSequentialMultiSig?ct.P2SHNonSequential:ct.P2SH,n=r.address?Ni(r.publicKeys.map(cr),r.numSignatures,t,Yn(r.address).hash160):r.publicKeys.map(cr);u=function(t,n,r,i,o){return{hashMode:t,signer:lr(0,t,n,r.map(sr)).hash160,nonce:e(i),fee:e(o),fields:[],signaturesRequired:n}}(t,r.numSignatures,n,r.nonce,r.fee)}const h=r.sponsored?ui(u):ci(u),f=Xn((r.postConditions??[]).map(t=>"string"==typeof t?zr(t):"string"==typeof t.type?function(t){switch(t.type){case"stx-postcondition":return{type:qn.PostCondition,conditionType:st.STX,principal:"origin"===t.address?{type:qn.Principal,prefix:ft.Origin}:wr(t.address),conditionCode:Pi(t.condition),amount:BigInt(t.amount)};case"ft-postcondition":return{type:qn.PostCondition,conditionType:st.Fungible,principal:"origin"===t.address?{type:qn.Principal,prefix:ft.Origin}:wr(t.address),conditionCode:Pi(t.condition),amount:BigInt(t.amount),asset:yr(t.asset)};case"nft-postcondition":return{type:qn.PostCondition,conditionType:st.NonFungible,principal:"origin"===t.address?{type:qn.Principal,prefix:ft.Origin}:wr(t.address),conditionCode:Pi(t.condition),asset:yr(t.asset),assetName:t.assetId};default:throw new Error("Invalid post condition type")}}(t):t)),l=new di({transactionVersion:r.network.transactionVersion,chainId:r.network.chainId,auth:h,payload:i,postConditions:f,postConditionMode:r.postConditionMode});if(void 0===t.fee||null===t.fee){const t=await async function({transaction:t,network:e,client:n}){const r=e??fi(t),i=Object.assign({},H(U(r)),n);try{const e=function(t){const e=t.auth.spendingCondition.hashMode;if([ct.P2SH,ct.P2WSH].includes(e)){const e=t.auth.spendingCondition,n=e.fields.filter(t=>t.contents.type===qn.MessageSignature).length,r=66*(e.signaturesRequired-n);return t.serializeBytes().byteLength+r}return t.serializeBytes().byteLength}(t);return(await async function({payload:t,estimatedLength:e,network:n="mainnet",client:r}){const i={transaction_payload:t,estimated_len:e},o={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)},s=Object.assign({},H(U(n)),r),a=`${s.baseUrl}/v2/fees/transaction`,c=await s.fetch(a,o);if(!c.ok){const t=await c.text().catch(()=>"");if(t.includes("NoEstimateAvailable")){let e={};try{e=JSON.parse(t)}catch(t){}throw new K(e?.reason_data?.message??"")}throw new Error(`Error estimating transaction fee. Response ${c.status}: ${c.statusText}. Attempted to fetch ${a} and failed with the message: "${t}"`)}return(await c.json()).estimations}({payload:d(Xr(t.payload)),estimatedLength:e,network:r,client:i}))[1].fee}catch(e){if(!(e instanceof K))throw e;return await async function({transaction:t,network:e,client:n}){const r="number"==typeof t?"mainnet":e??fi(t),i=Object.assign({},H(U(r)),n),o=`${i.baseUrl}/v2/fees/transfer`,s=await i.fetch(o,{headers:{Accept:"application/text"}});if(!s.ok){const t=await s.text().catch(()=>"");throw new Error(`Error estimating transfer fee. Response ${s.status}: ${s.statusText}. Attempted to fetch ${o} and failed with the message: "${t}"`)}const a=await s.text(),c="number"==typeof t?BigInt(t):BigInt(Math.ceil(t.serializeBytes().byteLength));return BigInt(a)*c}({transaction:t,network:r})}}({transaction:l,...r});l.setFee(t)}if(void 0===t.nonce||null===t.nonce){const t=r.network.addressVersion.singleSig,e=(0,$n.bJ)(t,l.auth.spendingCondition.signer),n=await async function(t){try{return await async function({address:t,network:e="mainnet",client:n}){const r=Object.assign({},H(U(e)),n),i=`${r.baseUrl}/extended/v1/address/${t}/nonces`,o=await r.fetch(i),s=await o.json();return BigInt(s.possible_next_nonce)}(t)}catch(t){}const e=U(t.network??"mainnet"),n=Object.assign({},H(e),t.client),r=`${n.baseUrl}/v2/accounts/${t.address}?proof=0`,i=await n.fetch(r);if(!i.ok){const t=await i.text().catch(()=>"");throw new Error(`Error fetching nonce. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${t}"`)}const o=await i.json();return BigInt(o.nonce)}({address:e,...r});l.setNonce(n)}return l}async function Oi(t){if("senderKey"in t){const e=dr(t.senderKey),n=_r(t,"senderKey"),r=await Ri({publicKey:e,...n}),i=t.senderKey;return new ki(r).signOrigin(i),r}{const e=_r(t,"signerKeys"),n=await Ri(e);return function(t,e,n,r){if(ti(t.auth.spendingCondition))throw new Error("Transaction is not a multi-sig transaction");const i=new ki(t),o=r?Ni(e,t.auth.spendingCondition.signaturesRequired,t.auth.spendingCondition.hashMode,Yn(r).hash160):e;for(const t of o){const e=n.find(e=>dr(e)===t);e?i.signOrigin(e):i.appendOrigin(t)}}(n,t.publicKeys.map(cr).slice(),t.signerKeys.map(ar),t.address),n}}function Ni(t,e,n,r){if(lr(0,n,e,t.map(sr)).hash160===r)return t;const i=t.slice().sort();if(lr(0,n,e,i.map(sr)).hash160===r)return i;throw new Error("Failed to find matching multi-sig address given public-keys.")}var Bi=(t=>(t[t.P2PKH=0]="P2PKH",t[t.P2SH=1]="P2SH",t[t.P2SHP2WPKH=2]="P2SHP2WPKH",t[t.P2SHP2WSH=3]="P2SHP2WSH",t[t.P2WPKH=4]="P2WPKH",t[t.P2WSH=5]="P2WSH",t[t.P2TR=6]="P2TR",t))(Bi||{});const Ui={mainnet:{P2PKH:0,P2SH:5},testnet:{P2PKH:111,P2SH:196},devnet:{P2PKH:111,P2SH:196},mocknet:{P2PKH:111,P2SH:196}},Hi=/^(1|3|m|n|2)/,$i=/^(bc1q|tb1q|bcrt1q)/i,Di=/^(bc1p|tb1p|bcrt1p)/i,Li={mainnet:"bc",testnet:"tb",devnet:"bcrt",mocknet:"bcrt"},Ki=/^(bc|tb)/i,Mi=0,ji=1;var Gi=(t=>(t.Period1="Period1",t.Period2a="Period2a",t.Period2b="Period2b",t.Period3="Period3",t))(Gi||{}),Fi=(t=>(t[t.ERR_STACKING_UNREACHABLE=255]="ERR_STACKING_UNREACHABLE",t[t.ERR_STACKING_CORRUPTED_STATE=254]="ERR_STACKING_CORRUPTED_STATE",t[t.ERR_STACKING_INSUFFICIENT_FUNDS=1]="ERR_STACKING_INSUFFICIENT_FUNDS",t[t.ERR_STACKING_INVALID_LOCK_PERIOD=2]="ERR_STACKING_INVALID_LOCK_PERIOD",t[t.ERR_STACKING_ALREADY_STACKED=3]="ERR_STACKING_ALREADY_STACKED",t[t.ERR_STACKING_NO_SUCH_PRINCIPAL=4]="ERR_STACKING_NO_SUCH_PRINCIPAL",t[t.ERR_STACKING_EXPIRED=5]="ERR_STACKING_EXPIRED",t[t.ERR_STACKING_STX_LOCKED=6]="ERR_STACKING_STX_LOCKED",t[t.ERR_STACKING_PERMISSION_DENIED=9]="ERR_STACKING_PERMISSION_DENIED",t[t.ERR_STACKING_THRESHOLD_NOT_MET=11]="ERR_STACKING_THRESHOLD_NOT_MET",t[t.ERR_STACKING_POX_ADDRESS_IN_USE=12]="ERR_STACKING_POX_ADDRESS_IN_USE",t[t.ERR_STACKING_INVALID_POX_ADDRESS=13]="ERR_STACKING_INVALID_POX_ADDRESS",t[t.ERR_STACKING_ALREADY_REJECTED=17]="ERR_STACKING_ALREADY_REJECTED",t[t.ERR_STACKING_INVALID_AMOUNT=18]="ERR_STACKING_INVALID_AMOUNT",t[t.ERR_NOT_ALLOWED=19]="ERR_NOT_ALLOWED",t[t.ERR_STACKING_ALREADY_DELEGATED=20]="ERR_STACKING_ALREADY_DELEGATED",t[t.ERR_DELEGATION_EXPIRES_DURING_LOCK=21]="ERR_DELEGATION_EXPIRES_DURING_LOCK",t[t.ERR_DELEGATION_TOO_MUCH_LOCKED=22]="ERR_DELEGATION_TOO_MUCH_LOCKED",t[t.ERR_DELEGATION_POX_ADDR_REQUIRED=23]="ERR_DELEGATION_POX_ADDR_REQUIRED",t[t.ERR_INVALID_START_BURN_HEIGHT=24]="ERR_INVALID_START_BURN_HEIGHT",t[t.ERR_NOT_CURRENT_STACKER=25]="ERR_NOT_CURRENT_STACKER",t[t.ERR_STACK_EXTEND_NOT_LOCKED=26]="ERR_STACK_EXTEND_NOT_LOCKED",t[t.ERR_STACK_INCREASE_NOT_LOCKED=27]="ERR_STACK_INCREASE_NOT_LOCKED",t[t.ERR_DELEGATION_NO_REWARD_SLOT=28]="ERR_DELEGATION_NO_REWARD_SLOT",t[t.ERR_DELEGATION_WRONG_REWARD_SLOT=29]="ERR_DELEGATION_WRONG_REWARD_SLOT",t[t.ERR_STACKING_IS_DELEGATED=30]="ERR_STACKING_IS_DELEGATED",t[t.ERR_STACKING_NOT_DELEGATED=31]="ERR_STACKING_NOT_DELEGATED",t))(Fi||{});function Wi(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function Vi(...t){const e=(t,e)=>n=>t(e(n));return{encode:Array.from(t).reverse().reduce((t,n)=>t?e(t,n.encode):n.encode,void 0),decode:t.reduce((t,n)=>t?e(t,n.decode):n.decode,void 0)}}function qi(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("alphabet.encode input should be an array of numbers");return e.map(e=>{if(Wi(e),e<0||e>=t.length)throw new Error(`Digit index outside alphabet: ${e} (alphabet: ${t.length})`);return t[e]})},decode:e=>{if(!Array.isArray(e)||e.length&&"string"!=typeof e[0])throw new Error("alphabet.decode input should be array of strings");return e.map(e=>{if("string"!=typeof e)throw new Error(`alphabet.decode: not string element=${e}`);const n=t.indexOf(e);if(-1===n)throw new Error(`Unknown letter: "${e}". Allowed: ${t}`);return n})}}}function zi(t=""){if("string"!=typeof t)throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&"string"!=typeof e[0])throw new Error("join.encode input should be array of strings");for(let t of e)if("string"!=typeof t)throw new Error(`join.encode: non-string input=${t}`);return e.join(t)},decode:e=>{if("string"!=typeof e)throw new Error("join.decode input should be string");return e.split(t)}}}function Xi(t,e="="){if(Wi(t),"string"!=typeof e)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let t of n)if("string"!=typeof t)throw new Error(`padding.encode: non-string input=${t}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let t of n)if("string"!=typeof t)throw new Error(`padding.decode: non-string input=${t}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function Ji(t){if("function"!=typeof t)throw new Error("normalize fn should be function");return{encode:t=>t,decode:e=>t(e)}}function Zi(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const i=[],o=Array.from(t);for(o.forEach(t=>{if(Wi(t),t<0||t>=e)throw new Error(`Wrong integer: ${t}`)});;){let t=0,s=!0;for(let i=r;i<o.length;i++){const a=o[i],c=e*t+a;if(!Number.isSafeInteger(c)||e*t/e!==t||c-a!==e*t)throw new Error("convertRadix: carry overflow");if(t=c%n,o[i]=Math.floor(c/n),!Number.isSafeInteger(o[i])||o[i]*n+t!==c)throw new Error("convertRadix: carry overflow");s&&(o[i]?s=!1:r=i)}if(i.push(t),s)break}for(let e=0;e<t.length-1&&0===t[e];e++)i.push(0);return i.reverse()}const Yi=(t,e)=>e?Yi(e,t%e):t,Qi=(t,e)=>t+(e-Yi(t,e));function to(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Qi(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Qi(e,n)}`);let i=0,o=0;const s=2**n-1,a=[];for(const r of t){if(Wi(r),r>=2**e)throw new Error(`convertRadix2: invalid data word=${r} from=${e}`);if(i=i<<e|r,o+e>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${e}`);for(o+=e;o>=n;o-=n)a.push((i>>o-n&s)>>>0);i&=2**o-1}if(i=i<<n-o&s,!r&&o>=e)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&a.push(i>>>0),a}function eo(t,e=!1){if(Wi(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Qi(8,t)>32||Qi(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return to(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(to(n,t,8,e))}}}function no(t){if("function"!=typeof t)throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch(t){}}}Vi(eo(4),qi("0123456789ABCDEF"),zi("")),Vi(eo(5),qi("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Xi(5),zi("")),Vi(eo(5),qi("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Xi(5),zi("")),Vi(eo(5),qi("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),zi(""),Ji(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),Vi(eo(6),qi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Xi(6),zi("")),Vi(eo(6),qi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Xi(6),zi(""));const ro=t=>{return Vi((Wi(e=58),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Zi(Array.from(t),256,e)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(Zi(t,e,256))}}),qi(t),zi(""));var e},io=(ro("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),ro("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),ro("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),Vi(qi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),zi(""))),oo=[996825010,642813549,513874426,1027748829,705979059];function so(t){const e=t>>25;let n=(33554431&t)<<5;for(let t=0;t<oo.length;t++)1==(e>>t&1)&&(n^=oo[t]);return n}function ao(t,e,n=1){const r=t.length;let i=1;for(let e=0;e<r;e++){const n=t.charCodeAt(e);if(n<33||n>126)throw new Error(`Invalid prefix (${t})`);i=so(i)^n>>5}i=so(i);for(let e=0;e<r;e++)i=so(i)^31&t.charCodeAt(e);for(let t of e)i=so(i)^t;for(let t=0;t<6;t++)i=so(i);return i^=n,io.encode(to([i%2**30],30,5,!1))}function co(t){const e="bech32"===t?1:734539939,n=eo(5),r=n.decode,i=n.encode,o=no(r);function s(t,n=90){if("string"!=typeof t)throw new Error("bech32.decode input should be string, not "+typeof t);if(t.length<8||!1!==n&&t.length>n)throw new TypeError(`Wrong string length: ${t.length} (${t}). Expected (8..${n})`);const r=t.toLowerCase();if(t!==r&&t!==t.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=(t=r).lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const o=t.slice(0,i),s=t.slice(i+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=io.decode(s).slice(0,-6),c=ao(o,a,e);if(!s.endsWith(c))throw new Error(`Invalid checksum in ${t}: expected "${c}"`);return{prefix:o,words:a}}return{encode:function(t,n,r=90){if("string"!=typeof t)throw new Error("bech32.encode prefix should be string, not "+typeof t);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const i=t.length+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);return`${t=t.toLowerCase()}1${io.encode(n)}${ao(t,n,e)}`},decode:s,decodeToBytes:function(t){const{prefix:e,words:n}=s(t,!1);return{prefix:e,words:n,bytes:r(n)}},decodeUnsafe:no(s),fromWords:r,fromWordsUnsafe:o,toWords:i}}const uo=co("bech32"),ho=co("bech32m");Vi(eo(4),qi("0123456789abcdef"),zi(""),Ji(t=>{if("string"!=typeof t||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var fo=i(216),lo=i.n(fo);Nn.hmacSha256Sync=(t,...e)=>{const n=er.create(ne,t);return e.forEach(t=>n.update(t)),n.digest()},i(991);const po=9007199254740991;function go(t){if(t<0||t>po||t%1!=0)throw new RangeError("value out of range")}const yo="Stacks Signed Message:\n";function wo(t,e=yo){const n="string"==typeof t?l(t):t,r=function(t,e,n=0){return go(t),e||(e=new Uint8Array(function(t){return go(t),t<253?1:t<=65535?3:t<=4294967295?5:9}(t))),t<253?F(e,t,n):t<=65535?(F(e,253,n),function(t,e,n=0){t[n+0]=255&e,e>>>=8,t[n+1]=255&e}(e,t,n+1)):t<=4294967295?(F(e,254,n),V(e,t,n+1)):(F(e,255,n),V(e,t>>>0,n+1),V(e,t/4294967296|0,n+5)),e}(n.length);return m(l(e),r,n)}var bo;Nn.hmacSha256Sync=(t,...e)=>{const n=er.create(ne,t);return e.forEach(t=>n.update(t)),n.digest()},function(t){t.InvalidFormat="InvalidFormat",t.IsNotPoint="IsNotPoint"}(bo||(bo={}));const mo=new Uint8Array([83,73,80,48,49,56]);function Ao(t){return ne(Dr(t))}function Eo({message:t,domain:e}){const n=Ao(t);if((r=e).type!==Bn.Tuple||!["name","version","chain-id"].every(t=>t in r.value)||!["name","version"].every(t=>r.value[t].type===Bn.StringASCII)||r.value["chain-id"].type!==Bn.UInt)throw new Error("domain parameter must be a valid domain of type TupleCV with keys 'name', 'version', 'chain-id' with respective types StringASCII, StringASCII, UInt");var r;const i=Ao(e);return m(mo,i,n)}var So=Object.defineProperty,vo=Object.defineProperties,xo=Object.getOwnPropertyDescriptors,Co=Object.getOwnPropertySymbols,Io=Object.prototype.hasOwnProperty,_o=Object.prototype.propertyIsEnumerable,To=(t,e,n)=>e in t?So(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Po=(t,e)=>{for(var n in e||(e={}))Io.call(e,n)&&To(t,n,e[n]);if(Co)for(var n of Co(e))_o.call(e,n)&&To(t,n,e[n]);return t},ko=(t,e)=>vo(t,xo(e));class Ro extends Error{constructor(t,e){const n=`'${t}' is not a valid P2PKH/P2SH/P2WPKH/P2WSH/P2TR address`;super(n),this.message=n,this.name=this.constructor.name,this.innerError=e,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}function Oo(t){switch(t){case Ui.mainnet.P2PKH:case Ui.testnet.P2PKH:return Bi.P2PKH;case Ui.mainnet.P2SH:case Ui.testnet.P2SH:return Bi.P2SH;default:throw new Error("Invalid pox address version")}}function No(t){const{version:e,data:n}=Bo(t);return{version:e,data:d(n)}}function Bo(t){try{if(Hi.test(t)){const e=function(t){const e=lo().decode(t),n=e.slice(0,-4),r=e.slice(-4),i=ne(ne(n));if(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3])throw new Error("Invalid checksum");if(21!==n.length)throw new TypeError("Invalid address length");return{version:G(n,0),hash:n.slice(1)}}(t);return{version:Oo(e.version),data:e.hash}}if(Ki.test(t)){const e=function(t){if($i.test(t))return function(t){const{words:e}=uo.decode(t),n=e[0];if(n>0)throw new Error("Addresses with a witness version >= 1 should be encoded in bech32m");return{witnessVersion:n,data:uo.fromWords(e.slice(1))}}(t);if(Di.test(t))return function(t){const{words:e}=ho.decode(t),n=e[0];if(0==n)throw new Error("Addresses with witness version 1 should be encoded in bech32");return{witnessVersion:n,data:ho.fromWords(e.slice(1))}}(t);throw new Error(`Native segwit address ${t} does not match valid prefix ${$i} or ${Di}`)}(t);return{version:function(t,e){if(t===Mi&&20===e)return Bi.P2WPKH;if(t===Mi&&32===e)return Bi.P2WSH;if(t===ji&&32===e)return Bi.P2TR;throw new Error("Invalid native segwit witness version and byte length. Currently, only P2WPKH, P2WSH, and P2TR are supported.")}(e.witnessVersion,e.data.length),data:e.data}}throw new Error("Unknown BTC address prefix.")}catch(e){throw new Ro(t,e)}}function Uo(t){const e=t;if(e.type!==Bn.Tuple||!e.value)throw new Error("Invalid argument, expected ClarityValue to be a TupleCV");if(!("version"in e.value)||!("hashbytes"in e.value))throw new Error("Invalid argument, expected Clarity tuple value to contain `version` and `hashbytes` keys");const n=e.value.version,r=e.value.hashbytes;if(n.type!==Bn.Buffer||r.type!==Bn.Buffer)throw new Error("Invalid argument, expected Clarity tuple value to contain `version` and `hashbytes` buffers");return{version:f(n.value)[0],hashBytes:f(r.value)}}function Ho(t){switch(t){case Fi.ERR_STACKING_UNREACHABLE:return"Stacking unreachable";case Fi.ERR_STACKING_CORRUPTED_STATE:return"Stacking state is corrupted";case Fi.ERR_STACKING_INSUFFICIENT_FUNDS:return"Insufficient funds";case Fi.ERR_STACKING_INVALID_LOCK_PERIOD:return"Invalid lock period";case Fi.ERR_STACKING_ALREADY_STACKED:return"Account already stacked. Concurrent stacking not allowed.";case Fi.ERR_STACKING_NO_SUCH_PRINCIPAL:return"Principal does not exist";case Fi.ERR_STACKING_EXPIRED:return"Stacking expired";case Fi.ERR_STACKING_STX_LOCKED:return"STX balance is locked";case Fi.ERR_STACKING_PERMISSION_DENIED:return"Permission denied";case Fi.ERR_STACKING_THRESHOLD_NOT_MET:return"Stacking threshold not met";case Fi.ERR_STACKING_POX_ADDRESS_IN_USE:return"PoX address already in use";case Fi.ERR_STACKING_INVALID_POX_ADDRESS:return"Invalid PoX address";case Fi.ERR_STACKING_ALREADY_REJECTED:return"Stacking already rejected";case Fi.ERR_STACKING_INVALID_AMOUNT:return"Invalid amount";case Fi.ERR_NOT_ALLOWED:return"Stacking not allowed";case Fi.ERR_STACKING_ALREADY_DELEGATED:return"Already delegated";case Fi.ERR_DELEGATION_EXPIRES_DURING_LOCK:return"Delegation expires during lock period";case Fi.ERR_DELEGATION_TOO_MUCH_LOCKED:return"Delegation too much locked";case Fi.ERR_DELEGATION_POX_ADDR_REQUIRED:return"PoX address required for delegation";case Fi.ERR_INVALID_START_BURN_HEIGHT:return"Invalid start burn height";case Fi.ERR_NOT_CURRENT_STACKER:return"ERR_NOT_CURRENT_STACKER";case Fi.ERR_STACK_EXTEND_NOT_LOCKED:case Fi.ERR_STACK_INCREASE_NOT_LOCKED:return"Stacker must be currently locked";case Fi.ERR_DELEGATION_NO_REWARD_SLOT:return"Invalid reward-cycle and reward-cycle-index";case Fi.ERR_DELEGATION_WRONG_REWARD_SLOT:return"PoX address must match the one on record";case Fi.ERR_STACKING_IS_DELEGATED:return"Stacker must be directly stacking and not delegating";case Fi.ERR_STACKING_NOT_DELEGATED:return"Stacker must be delegating and not be directly stacking"}}function $o(t){const{version:e,data:n}=Bo(t);return Sr({version:Vn(c(BigInt(e),1)),hashbytes:Vn(n)})}function Do(t,e,n){if(!B.includes(n))throw new Error("Invalid network.");switch("string"==typeof e&&(e=f(e)),t){case Bi.P2PKH:case Bi.P2SH:case Bi.P2SHP2WPKH:case Bi.P2SHP2WSH:{const r=function(t,e){switch(t){case Bi.P2PKH:return Ui[e].P2PKH;case Bi.P2SH:case Bi.P2SHP2WPKH:case Bi.P2SHP2WSH:return Ui[e].P2SH;default:throw new Error("Invalid pox address version")}}(t,n);return function(t,e){return function(t){const e=ne(ne(t));return lo().encode(m(t,e).slice(0,t.length+4))}(m(new Uint8Array([t]),e.slice(0,20)))}(r,e)}case Bi.P2WPKH:case Bi.P2WSH:{const t=uo.toWords(e);return uo.encode(Li[n],[Mi,...t])}case Bi.P2TR:{const t=ho.toWords(e);return ho.encode(Li[n],[ji,...t])}}throw new Error(`Unexpected address version: ${t}`)}function Lo(...t){return"number"==typeof t[0]?Do(t[0],t[1],t[2]):function(t,e){const n=Uo(t);return Do(n.version,n.hashBytes,e)}(t[0],t[1])}function Ko(t){if(t.type===Bn.OptionalSome)return t.value;if(t.type!==Bn.OptionalNone)throw new Error("Object is not an 'Optional'")}function Mo(t,e){if(t.type===Bn.OptionalSome)return e(t.value);if(t.type!==Bn.OptionalNone)throw new Error("Object is not an 'Optional'")}function jo(t){if(t.period===Gi.Period1)throw new Error(`PoX-2 has not activated yet (currently in period ${t.period} of PoX-2 operation)`)}function Go({contract:t,poxAddress:e}){if(e&&t.endsWith(".pox")&&!Hi.test(e))throw new Error("PoX-1 requires P2PKH/P2SH/P2SH-P2WPKH/P2SH-P2WSH bitcoin addresses")}function Fo({contract:t,signerKey:e,signerSignature:n,maxAmount:r,authId:i}){const o=void 0!==r,s=void 0!==i;if(/\.pox(-[2-3])?$/.test(t)){if(e||n||o||s)throw new Error("PoX-1, PoX-2 and PoX-3 do not accept a `signerKey`, `signerSignature`, `maxAmount` or `authId`")}else if(!e||!o||void 0===i)throw new Error("PoX-4 requires a `signerKey` (buff 33), `maxAmount` (uint), and `authId` (uint)")}var Wo=(t=>(t.StackStx="stack-stx",t.AggregateCommit="agg-commit",t.AggregateIncrease="agg-increase",t.StackExtend="stack-extend",t.StackIncrease="stack-increase",t))(Wo||{});function Vo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:i,privateKey:o,maxAmount:s,authId:a}){return function({message:t,domain:e,privateKey:n}){return function({messageHash:t,privateKey:e}){return(n=fr(e,t)).slice(2)+n.slice(0,2);var n}({messageHash:d(ne(Eo({message:t,domain:e}))),privateKey:n})}(ko(Po({},zo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:i,maxAmount:s,authId:a})),{privateKey:o}))}function qo({topic:t,poxAddress:e,rewardCycle:n,period:i,network:o,publicKey:s,signature:a,maxAmount:c,authId:u}){return function({signature:t,message:e,publicKey:n}){return function({signature:t,message:e,publicKey:n}){const{r:i,s:o}=rr(t),s=new tn(r(i),r(o)),a=kn(s,"string"==typeof e?function(t,e=yo){return ne(wo(t,e))}(e):e,n,{strict:!1});return a||"string"!=typeof e?a:kn(s,ne(wo(e,"Stacks Message Signing:\n")),n,{strict:!1})}({signature:ir(t),message:e,publicKey:n})}({message:ne(Eo(zo({topic:t,poxAddress:e,rewardCycle:n,period:i,network:o,maxAmount:c,authId:u}))),publicKey:s,signature:a})}function zo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:i,maxAmount:o,authId:s}){const a=U(i);return{message:Sr({"pox-addr":$o(e),"reward-cycle":Wn(n),topic:vr(t),period:Wn(r),"max-amount":Wn(o),"auth-id":Wn(s)}),domain:Sr({name:vr("pox-4-signer"),version:vr("1.0.0"),"chain-id":Wn(a.chainId)})}}var Xo=Object.defineProperty,Jo=Object.getOwnPropertySymbols,Zo=Object.prototype.hasOwnProperty,Yo=Object.prototype.propertyIsEnumerable,Qo=(t,e,n)=>e in t?Xo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ts=(t,e)=>{for(var n in e||(e={}))Zo.call(e,n)&&Qo(t,n,e[n]);if(Jo)for(var n of Jo(e))Yo.call(e,n)&&Qo(t,n,e[n]);return t},es=(t,e)=>{var n={};for(var r in t)Zo.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&Jo)for(var r of Jo(t))e.indexOf(r)<0&&Yo.call(t,r)&&(n[r]=t[r]);return n};class ns{constructor(t){var e;this.address=t.address,this.network=U(null!=(e=t.network)?e:"mainnet"),this.client=Object.assign({},H(this.network),t.client)}get baseUrl(){return this.client.baseUrl}get fetch(){return this.client.fetch}getCoreInfo(){return this.client.fetch(`${this.client.baseUrl}/v2/info`).then(t=>t.json())}getPoxInfo(){return this.client.fetch(`${this.client.baseUrl}/v2/pox`).then(t=>t.json())}async getTargetBlockTime(){const t=await this.client.fetch(`${this.client.baseUrl}/extended/v1/info/network_block_times`).then(t=>t.json());return this.network.chainId===C.Mainnet?t.mainnet.target_block_time:t.testnet.target_block_time}async getAccountStatus(){return this.client.fetch(`${this.client.baseUrl}/v2/accounts/${this.address}?proof=0`).then(t=>t.json()).then(t=>(t.balance=BigInt(t.balance),t.locked=BigInt(t.locked),t))}async getAccountBalance(){return this.getAccountStatus().then(t=>t.balance)}async getAccountExtendedBalances(){return this.client.fetch(`${this.client.baseUrl}/extended/v1/address/${this.address}/balances`).then(t=>t.json()).then(t=>(t.stx.balance=BigInt(t.stx.balance),t.stx.total_sent=BigInt(t.stx.total_sent),t.stx.total_received=BigInt(t.stx.total_received),t.stx.locked=BigInt(t.stx.locked),t))}async getAccountBalanceLocked(){return this.getAccountStatus().then(t=>t.locked)}async getCycleDuration(){const t=this.getPoxInfo(),e=await this.getTargetBlockTime();return Promise.all([t,e]).then(([t,e])=>t.reward_cycle_length*e)}async getRewardsTotalForBtcAddress(){return this.client.fetch(`${this.client.baseUrl}/extended/v1/burnchain/rewards/${this.address}/total`).then(t=>t.json()).then(t=>(t.reward_amount=BigInt(t.reward_amount),t))}async getRewardsForBtcAddress(t){let e=`${this.client.baseUrl}/extended/v1/burnchain/rewards/${this.address}`;return t&&(e+=`?limit=${t.limit}&offset=${t.offset}`),this.client.fetch(e).then(t=>t.json())}async getRewardHoldersForBtcAddress(t){let e=`${this.client.baseUrl}/extended/v1/burnchain/reward_slot_holders/${this.address}`;return t&&(e+=`?limit=${t.limit}&offset=${t.offset}`),this.client.fetch(e).then(t=>t.json())}async getRewardSet(t){const[e,n]=this.parseContractId(null==t?void 0:t.contractId);return Mo(await pi({client:this.client,senderAddress:this.address,contractAddress:e,contractName:n,functionArgs:[Wn(t.rewardCyleId),Wn(t.rewardSetIndex)],functionName:"get-reward-set-pox-address"}),t=>({pox_address:{version:f(t.value["pox-addr"].value.version.value),hashbytes:f(t.value["pox-addr"].value.hashbytes.value)},total_ustx:BigInt(t.value["total-ustx"].value)}))}async getSecondsUntilNextCycle(){const t=this.getPoxInfo(),e=this.getTargetBlockTime(),n=this.getCoreInfo();return Promise.all([t,e,n]).then(([t,e,n])=>(t.reward_cycle_length-(n.burn_block_height-t.first_burnchain_block_height)%t.reward_cycle_length)*e)}async getSecondsUntilStackingDeadline(){const t=this.getPoxInfo(),e=this.getTargetBlockTime();return Promise.all([t,e]).then(([t,e])=>t.next_cycle.blocks_until_prepare_phase*e)}async getPoxOperationInfo(t){const e=[...(t=null!=t?t:await this.getPoxInfo()).contract_versions].sort((t,e)=>t.activation_burnchain_block_height-e.activation_burnchain_block_height),[n,r,i,o]=e,s=e.filter(e=>(null==t?void 0:t.current_burnchain_block_height)>=e.activation_burnchain_block_height),a=s[s.length-1];return{period:Gi.Period3,pox1:n,pox2:r,pox3:i,pox4:o,current:a}}async hasMinimumStx(){return await this.getAccountBalance()>=BigInt((await this.getPoxInfo()).min_amount_ustx)}async canStack({poxAddress:t,cycles:e}){const n=this.getAccountBalance(),r=this.getPoxInfo();return Promise.all([n,r]).then(([n,r])=>{const i=$o(t),[o,s]=this.parseContractId(r.contract_id);return pi({client:this.client,contractName:s,contractAddress:o,functionName:"can-stack-stx",senderAddress:this.address,functionArgs:[i,Wn(n.toString()),Wn(r.reward_cycle_id),Wn(e.toString())]})}).then(t=>t.type===Bn.ResponseOk?{eligible:!0}:{eligible:!1,reason:Fi[+gi(t.value)]})}async stack(t){var e=t,{amountMicroStx:n,poxAddress:r,cycles:i,burnBlockHeight:o,signerKey:s,signerSignature:a,maxAmount:c,authId:u}=e,h=es(e,["amountMicroStx","poxAddress","cycles","burnBlockHeight","signerKey","signerSignature","maxAmount","authId"]);const d=await this.getPoxInfo(),f=await this.getPoxOperationInfo(d),l=await this.getStackingContract(f);Go({contract:l,poxAddress:r}),Fo({contract:l,signerKey:s,signerSignature:a,maxAmount:c,authId:u});const p=this.getStackOptions({contract:l,amountMicroStx:n,cycles:i,poxAddress:r,burnBlockHeight:o,signerKey:s,signerSignature:a,maxAmount:c,authId:u});return li({transaction:await Oi(ts(ts({},p),rs(h))),client:this.client})}async stackExtend(t){var e=t,{extendCycles:n,poxAddress:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}=e,c=es(e,["extendCycles","poxAddress","signerKey","signerSignature","maxAmount","authId"]);const u=await this.getPoxInfo();jo(await this.getPoxOperationInfo(u)),Fo({contract:u.contract_id,signerKey:i,signerSignature:o,maxAmount:s,authId:a});const h=this.getStackExtendOptions({contract:u.contract_id,extendCycles:n,poxAddress:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a});return li({transaction:await Oi(ts(ts({},h),rs(c))),client:this.client})}async stackIncrease(t){var e=t,{increaseBy:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}=e,a=es(e,["increaseBy","signerKey","signerSignature","maxAmount","authId"]);const c=await this.getPoxInfo();jo(await this.getPoxOperationInfo(c)),Fo({contract:c.contract_id,signerKey:r,signerSignature:i,maxAmount:o,authId:s});const u=this.getStackIncreaseOptions({contract:c.contract_id,increaseBy:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s});return li({transaction:await Oi(ts(ts({},u),rs(a))),client:this.client})}async delegateStx(t){var e=t,{amountMicroStx:n,delegateTo:r,untilBurnBlockHeight:i,poxAddress:o}=e,s=es(e,["amountMicroStx","delegateTo","untilBurnBlockHeight","poxAddress"]);const a=await this.getPoxInfo(),c=await this.getPoxOperationInfo(a),u=await this.getStackingContract(c);Go({contract:u,poxAddress:o});const h=this.getDelegateOptions({contract:u,amountMicroStx:n,delegateTo:r,untilBurnBlockHeight:i,poxAddress:o});return li({transaction:await Oi(ts(ts({},h),rs(s))),client:this.client})}async delegateStackStx(t){var e=t,{stacker:n,amountMicroStx:r,poxAddress:i,burnBlockHeight:o,cycles:s}=e,a=es(e,["stacker","amountMicroStx","poxAddress","burnBlockHeight","cycles"]);const c=await this.getPoxInfo(),u=await this.getPoxOperationInfo(c),h=await this.getStackingContract(u);Go({contract:h,poxAddress:i});const d=this.getDelegateStackOptions({contract:h,stacker:n,amountMicroStx:r,poxAddress:i,burnBlockHeight:o,cycles:s});return li({transaction:await Oi(ts(ts({},d),rs(a))),client:this.client})}async delegateStackExtend(t){var e=t,{stacker:n,poxAddress:r,extendCount:i}=e,o=es(e,["stacker","poxAddress","extendCount"]);const s=(await this.getPoxInfo()).contract_id,a=this.getDelegateStackExtendOptions({contract:s,stacker:n,poxAddress:r,extendCount:i});return li({transaction:await Oi(ts(ts({},a),rs(o))),client:this.client})}async delegateStackIncrease(t){var e=t,{stacker:n,poxAddress:r,increaseBy:i}=e,o=es(e,["stacker","poxAddress","increaseBy"]);const s=await this.getPoxInfo();jo(await this.getPoxOperationInfo(s));const a=this.getDelegateStackIncreaseOptions({contract:s.contract_id,stacker:n,poxAddress:r,increaseBy:i});return li({transaction:await Oi(ts(ts({},a),rs(o))),client:this.client})}async stackAggregationCommit(t){var e=t,{poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}=e,c=es(e,["poxAddress","rewardCycle","signerKey","signerSignature","maxAmount","authId"]);const u=await this.getStackingContract();Go({contract:u,poxAddress:n}),Fo({contract:u,signerKey:i,signerSignature:o,maxAmount:s,authId:a});const h=this.getStackAggregationCommitOptions({contract:u,poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a});return li({transaction:await Oi(ts(ts({},h),rs(c))),client:this.client})}async stackAggregationCommitIndexed(t){var e=t,{poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}=e,c=es(e,["poxAddress","rewardCycle","signerKey","signerSignature","maxAmount","authId"]);const u=await this.getStackingContract();Go({contract:u,poxAddress:n}),Fo({contract:u,signerKey:i,signerSignature:o,maxAmount:s,authId:a});const h=this.getStackAggregationCommitOptionsIndexed({contract:u,poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a});return li({transaction:await Oi(ts(ts({},h),rs(c))),client:this.client})}async stackAggregationIncrease(t){var e=t,{poxAddress:n,rewardCycle:r,rewardIndex:i,signerKey:o,signerSignature:s,maxAmount:a,authId:c}=e,u=es(e,["poxAddress","rewardCycle","rewardIndex","signerKey","signerSignature","maxAmount","authId"]);const h=await this.getStackingContract();Go({contract:h,poxAddress:n}),Fo({contract:h,signerKey:o,signerSignature:s,maxAmount:a,authId:c});const d=this.getStackAggregationIncreaseOptions({contract:h,poxAddress:n,rewardCycle:r,rewardCycleIndex:i,signerKey:o,signerSignature:s,maxAmount:a,authId:c});return li({transaction:await Oi(ts(ts({},d),rs(u))),client:this.client})}async revokeDelegateStx(t){"string"==typeof t&&(t={privateKey:t});const e=(await this.getPoxInfo()).contract_id,n=this.getRevokeDelegateStxOptions(e);return li({transaction:await Oi(ts(ts({},n),rs(t))),client:this.client})}getStackOptions({amountMicroStx:t,poxAddress:e,cycles:n,contract:r,burnBlockHeight:i,signerKey:o,signerSignature:s,maxAmount:a,authId:c}){const u=$o(e),[h,d]=this.parseContractId(r),l=[Wn(t),u,Wn(i),Wn(n)];return o&&a&&void 0!==c&&(l.push(s?Er(Vn(f(s))):Ar()),l.push(Vn(f(o))),l.push(Wn(a)),l.push(Wn(c))),{client:this.client,contractAddress:h,contractName:d,functionName:"stack-stx",functionArgs:l,validateWithAbi:!0,network:this.network}}getStackExtendOptions({extendCycles:t,poxAddress:e,contract:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}){const a=$o(e),[c,u]=this.parseContractId(n),h=[Wn(t),a];return r&&o&&void 0!==s&&(h.push(i?Er(Vn(f(i))):Ar()),h.push(Vn(f(r))),h.push(Wn(o)),h.push(Wn(s))),{client:this.client,contractAddress:c,contractName:u,functionName:"stack-extend",functionArgs:h,validateWithAbi:!0,network:this.network}}getStackIncreaseOptions({increaseBy:t,contract:e,signerKey:n,signerSignature:r,maxAmount:i,authId:o}){const[s,a]=this.parseContractId(e),c=[Wn(t)];return n&&i&&void 0!==o&&(c.push(r?Er(Vn(f(r))):Ar()),c.push(Vn(f(n))),c.push(Wn(i)),c.push(Wn(o))),{client:this.client,contractAddress:s,contractName:a,functionName:"stack-increase",functionArgs:c,validateWithAbi:!0,network:this.network}}getDelegateOptions({contract:t,amountMicroStx:e,delegateTo:n,untilBurnBlockHeight:r,poxAddress:i}){const o=i?Er($o(i)):Ar(),[s,a]=this.parseContractId(t);return{client:this.client,contractAddress:s,contractName:a,functionName:"delegate-stx",functionArgs:[Wn(e),br(n),r?Er(Wn(r)):Ar(),o],validateWithAbi:!0,network:this.network}}getDelegateStackOptions({contract:t,stacker:e,amountMicroStx:n,poxAddress:r,burnBlockHeight:i,cycles:o}){const s=$o(r),[a,c]=this.parseContractId(t);return{client:this.client,contractAddress:a,contractName:c,functionName:"delegate-stack-stx",functionArgs:[br(e),Wn(n),s,Wn(i),Wn(o)],validateWithAbi:!0,network:this.network}}getDelegateStackExtendOptions({contract:t,stacker:e,poxAddress:n,extendCount:r}){const i=$o(n),[o,s]=this.parseContractId(t);return{client:this.client,contractAddress:o,contractName:s,functionName:"delegate-stack-extend",functionArgs:[br(e),i,Wn(r)],validateWithAbi:!0,network:this.network}}getDelegateStackIncreaseOptions({contract:t,stacker:e,poxAddress:n,increaseBy:r}){const i=$o(n),[o,s]=this.parseContractId(t);return{client:this.client,contractAddress:o,contractName:s,functionName:"delegate-stack-increase",functionArgs:[br(e),i,Wn(r)],validateWithAbi:!0,network:this.network}}getStackAggregationCommitOptions({contract:t,poxAddress:e,rewardCycle:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}){const a=$o(e),[c,u]=this.parseContractId(t),h=[a,Wn(n)];return r&&o&&void 0!==s&&(h.push(i?Er(Vn(f(i))):Ar()),h.push(Vn(f(r))),h.push(Wn(o)),h.push(Wn(s))),{client:this.client,contractAddress:c,contractName:u,functionName:"stack-aggregation-commit",functionArgs:h,validateWithAbi:!0,network:this.network}}getStackAggregationIncreaseOptions({contract:t,poxAddress:e,rewardCycle:n,rewardCycleIndex:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}){const c=$o(e),[u,h]=this.parseContractId(t),d=[c,Wn(n),Wn(r)];return i&&s&&void 0!==a&&(d.push(o?Er(Vn(f(o))):Ar()),d.push(Vn(f(i))),d.push(Wn(s)),d.push(Wn(a))),{client:this.client,contractAddress:u,contractName:h,functionName:"stack-aggregation-increase",functionArgs:d,validateWithAbi:!0,network:this.network}}getStackAggregationCommitOptionsIndexed({contract:t,poxAddress:e,rewardCycle:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}){const a=$o(e),[c,u]=this.parseContractId(t),h=[a,Wn(n)];return r&&o&&void 0!==s&&(h.push(i?Er(Vn(f(i))):Ar()),h.push(Vn(f(r))),h.push(Wn(o)),h.push(Wn(s))),{client:this.client,contractAddress:c,contractName:u,functionName:"stack-aggregation-commit-indexed",functionArgs:h,validateWithAbi:!0,network:this.network}}getRevokeDelegateStxOptions(t){const[e,n]=this.parseContractId(t);return{client:this.client,contractAddress:e,contractName:n,functionName:"revoke-delegate-stx",functionArgs:[],validateWithAbi:!0,network:this.network}}async getStatus(){const t=await this.getPoxInfo(),[e,n]=this.parseContractId(t.contract_id),r=await this.getAccountStatus();return pi({contractAddress:e,contractName:n,functionName:"get-stacker-info",senderAddress:this.address,functionArgs:[br(this.address)],client:this.client}).then(t=>{if(t.type===Bn.OptionalSome){const e=t.value,n=e.value["pox-addr"],i=e.value["first-reward-cycle"],o=e.value["lock-period"],s=n.value.version,a=n.value.hashbytes;return{stacked:!0,details:{first_reward_cycle:Number(i.value),lock_period:Number(o.value),unlock_height:r.unlock_height,pox_address:{version:f(s.value),hashbytes:f(a.value)}}}}if(t.type===Bn.OptionalNone)return{stacked:!1};throw new Error("Error fetching stacker info")})}async getDelegationStatus(){const t=await this.getPoxInfo(),[e,n]=this.parseContractId(t.contract_id);return pi({contractAddress:e,contractName:n,functionName:"get-delegation-info",functionArgs:[br(this.address)],senderAddress:this.address,client:this.client}).then(t=>{if(t.type===Bn.OptionalSome){const e=t.value,n=e.value["amount-ustx"],r=e.value["delegated-to"],i=Mo(e.value["pox-addr"],t=>({version:f(t.value.version.value)[0],hashbytes:f(t.value.hashbytes.value)})),o=Ko(e.value["until-burn-ht"]);return{delegated:!0,details:{amount_micro_stx:BigInt(n.value),delegated_to:r.value,pox_address:i,until_burn_ht:o?Number(o.value):void 0}}}if(t.type===Bn.OptionalNone)return{delegated:!1};throw new Error("Error fetching delegation info")})}async verifySignerKeySignature({topic:t,poxAddress:e,rewardCycle:n,period:r,signerSignature:i,signerKey:o,amount:s,maxAmount:a,authId:c}){const u=await this.getPoxInfo(),[h,d]=this.parseContractId(u.contract_id);return pi({contractAddress:h,contractName:d,functionName:"verify-signer-key-sig",functionArgs:[$o(e),Wn(n),vr(t),Wn(r),i?Er(Vn(f(i))):Ar(),Vn(f(o)),Wn(s),Wn(a),Wn(c)],senderAddress:this.address,client:this.client}).then(t=>t.type===Bn.ResponseOk)}async getStackingContract(t){switch((t=null!=t?t:await this.getPoxOperationInfo()).period){case Gi.Period1:return t.pox1.contract_id;case Gi.Period2a:case Gi.Period2b:return t.pox2.contract_id;case Gi.Period3:default:return t.current.contract_id}}modifyLockTxFee({tx:t,amountMicroStx:n}){const r=function(t){switch(t.authType){case at.Standard:return t.spendingCondition.fee;case at.Sponsored:return t.sponsorSpendingCondition.fee}}(t.auth);return t.payload.functionArgs[0]=Wn(e(n)-r),t}parseContractId(t){const e=t.split(".");if(2===e.length&&(t=>{try{return(0,$n.ns)(t),!0}catch(t){return!1}})(e[0])&&e[1].startsWith("pox"))return e;throw new Error("Stacking contract ID is malformed")}signPoxSignature({topic:t,poxAddress:e,rewardCycle:n,period:r,signerPrivateKey:i,authId:o,maxAmount:s}){return Vo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:this.network,privateKey:i,maxAmount:s,authId:o})}}function rs(t){return t.senderKey=t.privateKey,delete t.privateKey,t}})(),o})());
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksStacking=e():t.StacksStacking=e()}(this,()=>(()=>{var t,e,n={74:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomBytes=e.wrapConstructorWithOpts=e.wrapConstructor=e.checkOpts=e.Hash=e.concatBytes=e.toBytes=e.utf8ToBytes=e.asyncLoop=e.nextTick=e.hexToBytes=e.bytesToHex=e.isLE=e.rotr=e.createView=e.u32=e.u8=void 0;const r=n(452);if(e.u8=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength),e.u32=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),e.createView=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),e.rotr=(t,e)=>t<<32-e|t>>>e,e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],!e.isLE)throw new Error("Non little-endian hardware is not supported");const i=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function o(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}function s(t){if("string"==typeof t&&(t=o(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}e.bytesToHex=function(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=i[t[n]];return e},e.hexToBytes=function(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e},e.nextTick=async()=>{},e.asyncLoop=async function(t,n,r){let i=Date.now();for(let o=0;o<t;o++){r(o);const t=Date.now()-i;t>=0&&t<n||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=o,e.toBytes=s,e.concatBytes=function(...t){if(!t.every(t=>t instanceof Uint8Array))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce((t,e)=>t+e.length,0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n},e.Hash=class{clone(){return this._cloneInto()}},e.checkOpts=function(t,e){if(void 0!==e&&("object"!=typeof e||(n=e,"[object Object]"!==Object.prototype.toString.call(n)||n.constructor!==Object)))throw new TypeError("Options should be object or undefined");var n;return Object.assign(t,e)},e.wrapConstructor=function(t){const e=e=>t().update(s(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e},e.wrapConstructorWithOpts=function(t){const e=(e,n)=>t(n).update(s(e)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e},e.randomBytes=function(t=32){if(r.crypto.web)return r.crypto.web.getRandomValues(new Uint8Array(t));if(r.crypto.node)return new Uint8Array(r.crypto.node.randomBytes(t).buffer);throw new Error("The environment doesn't have randomBytes function")}},216:(t,e,n)=>{const r=n(403);t.exports=r("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},258:(t,e,n)=>{"use strict";e.ns=e.bJ=void 0;n(669),n(639);const r=n(877);Object.defineProperty(e,"bJ",{enumerable:!0,get:function(){return r.c32address}}),Object.defineProperty(e,"ns",{enumerable:!0,get:function(){return r.c32addressDecode}})},290:(t,e,n)=>{t=n.nmd(t);var r="__lodash_hash_undefined__",i=9007199254740991,o="[object Arguments]",s="[object Boolean]",a="[object Date]",c="[object Function]",u="[object GeneratorFunction]",h="[object Map]",d="[object Number]",f="[object Object]",l="[object Promise]",p="[object RegExp]",g="[object Set]",y="[object String]",w="[object Symbol]",b="[object WeakMap]",m="[object ArrayBuffer]",A="[object DataView]",E="[object Float32Array]",S="[object Float64Array]",v="[object Int8Array]",x="[object Int16Array]",C="[object Int32Array]",I="[object Uint8Array]",_="[object Uint8ClampedArray]",T="[object Uint16Array]",P="[object Uint32Array]",k=/\w*$/,R=/^\[object .+?Constructor\]$/,O=/^(?:0|[1-9]\d*)$/,N={};N[o]=N["[object Array]"]=N[m]=N[A]=N[s]=N[a]=N[E]=N[S]=N[v]=N[x]=N[C]=N[h]=N[d]=N[f]=N[p]=N[g]=N[y]=N[w]=N[I]=N[_]=N[T]=N[P]=!0,N["[object Error]"]=N[c]=N[b]=!1;var B="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,U="object"==typeof self&&self&&self.Object===Object&&self,H=B||U||Function("return this")(),$=e&&!e.nodeType&&e,D=$&&t&&!t.nodeType&&t,L=D&&D.exports===$;function K(t,e){return t.set(e[0],e[1]),t}function M(t,e){return t.add(e),t}function j(t,e,n,r){var i=-1,o=t?t.length:0;for(r&&o&&(n=t[++i]);++i<o;)n=e(n,t[i],i,t);return n}function G(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function F(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function W(t,e){return function(n){return t(e(n))}}function V(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var q,z=Array.prototype,X=Function.prototype,J=Object.prototype,Z=H["__core-js_shared__"],Y=(q=/[^.]+$/.exec(Z&&Z.keys&&Z.keys.IE_PROTO||""))?"Symbol(src)_1."+q:"",Q=X.toString,tt=J.hasOwnProperty,et=J.toString,nt=RegExp("^"+Q.call(tt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=L?H.Buffer:void 0,it=H.Symbol,ot=H.Uint8Array,st=W(Object.getPrototypeOf,Object),at=Object.create,ct=J.propertyIsEnumerable,ut=z.splice,ht=Object.getOwnPropertySymbols,dt=rt?rt.isBuffer:void 0,ft=W(Object.keys,Object),lt=Ht(H,"DataView"),pt=Ht(H,"Map"),gt=Ht(H,"Promise"),yt=Ht(H,"Set"),wt=Ht(H,"WeakMap"),bt=Ht(Object,"create"),mt=Mt(lt),At=Mt(pt),Et=Mt(gt),St=Mt(yt),vt=Mt(wt),xt=it?it.prototype:void 0,Ct=xt?xt.valueOf:void 0;function It(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function _t(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Tt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Pt(t){this.__data__=new _t(t)}function kt(t,e,n){var r=t[e];tt.call(t,e)&&jt(r,n)&&(void 0!==n||e in t)||(t[e]=n)}function Rt(t,e){for(var n=t.length;n--;)if(jt(t[n][0],e))return n;return-1}function Ot(t,e,n,r,i,l,b){var R;if(r&&(R=l?r(t,i,l,b):r(t)),void 0!==R)return R;if(!qt(t))return t;var O=Gt(t);if(O){if(R=function(t){var e=t.length,n=t.constructor(e);return e&&"string"==typeof t[0]&&tt.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),!e)return function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}(t,R)}else{var B=Dt(t),U=B==c||B==u;if(Wt(t))return function(t,e){if(e)return t.slice();var n=new t.constructor(t.length);return t.copy(n),n}(t,e);if(B==f||B==o||U&&!l){if(G(t))return l?t:{};if(R=function(t){return"function"!=typeof t.constructor||Kt(t)?{}:qt(e=st(t))?at(e):{};var e}(U?{}:t),!e)return function(t,e){return Bt(t,$t(t),e)}(t,function(t,e){return t&&Bt(e,zt(e),t)}(R,t))}else{if(!N[B])return l?t:{};R=function(t,e,n,r){var i,o=t.constructor;switch(e){case m:return Nt(t);case s:case a:return new o(+t);case A:return function(t,e){var n=e?Nt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,r);case E:case S:case v:case x:case C:case I:case _:case T:case P:return function(t,e){var n=e?Nt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}(t,r);case h:return function(t,e,n){return j(e?n(F(t),!0):F(t),K,new t.constructor)}(t,r,n);case d:case y:return new o(t);case p:return function(t){var e=new t.constructor(t.source,k.exec(t));return e.lastIndex=t.lastIndex,e}(t);case g:return function(t,e,n){return j(e?n(V(t),!0):V(t),M,new t.constructor)}(t,r,n);case w:return i=t,Ct?Object(Ct.call(i)):{}}}(t,B,Ot,e)}}b||(b=new Pt);var H=b.get(t);if(H)return H;if(b.set(t,R),!O)var $=n?function(t){return function(t,e,n){var r=e(t);return Gt(t)?r:function(t,e){for(var n=-1,r=e.length,i=t.length;++n<r;)t[i+n]=e[n];return t}(r,n(t))}(t,zt,$t)}(t):zt(t);return function(t,e){for(var n=-1,r=t?t.length:0;++n<r&&!1!==e(t[n],n););}($||t,function(i,o){$&&(i=t[o=i]),kt(R,o,Ot(i,e,n,r,o,t,b))}),R}function Nt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function Bt(t,e,n,r){n||(n={});for(var i=-1,o=e.length;++i<o;){var s=e[i],a=r?r(n[s],t[s],s,n,t):void 0;kt(n,s,void 0===a?t[s]:a)}return n}function Ut(t,e){var n,r,i=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function Ht(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return function(t){return!(!qt(t)||(e=t,Y&&Y in e))&&(Vt(t)||G(t)?nt:R).test(Mt(t));var e}(n)?n:void 0}It.prototype.clear=function(){this.__data__=bt?bt(null):{}},It.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},It.prototype.get=function(t){var e=this.__data__;if(bt){var n=e[t];return n===r?void 0:n}return tt.call(e,t)?e[t]:void 0},It.prototype.has=function(t){var e=this.__data__;return bt?void 0!==e[t]:tt.call(e,t)},It.prototype.set=function(t,e){return this.__data__[t]=bt&&void 0===e?r:e,this},_t.prototype.clear=function(){this.__data__=[]},_t.prototype.delete=function(t){var e=this.__data__,n=Rt(e,t);return!(n<0||(n==e.length-1?e.pop():ut.call(e,n,1),0))},_t.prototype.get=function(t){var e=this.__data__,n=Rt(e,t);return n<0?void 0:e[n][1]},_t.prototype.has=function(t){return Rt(this.__data__,t)>-1},_t.prototype.set=function(t,e){var n=this.__data__,r=Rt(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},Tt.prototype.clear=function(){this.__data__={hash:new It,map:new(pt||_t),string:new It}},Tt.prototype.delete=function(t){return Ut(this,t).delete(t)},Tt.prototype.get=function(t){return Ut(this,t).get(t)},Tt.prototype.has=function(t){return Ut(this,t).has(t)},Tt.prototype.set=function(t,e){return Ut(this,t).set(t,e),this},Pt.prototype.clear=function(){this.__data__=new _t},Pt.prototype.delete=function(t){return this.__data__.delete(t)},Pt.prototype.get=function(t){return this.__data__.get(t)},Pt.prototype.has=function(t){return this.__data__.has(t)},Pt.prototype.set=function(t,e){var n=this.__data__;if(n instanceof _t){var r=n.__data__;if(!pt||r.length<199)return r.push([t,e]),this;n=this.__data__=new Tt(r)}return n.set(t,e),this};var $t=ht?W(ht,Object):function(){return[]},Dt=function(t){return et.call(t)};function Lt(t,e){return!!(e=null==e?i:e)&&("number"==typeof t||O.test(t))&&t>-1&&t%1==0&&t<e}function Kt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||J)}function Mt(t){if(null!=t){try{return Q.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function jt(t,e){return t===e||t!=t&&e!=e}(lt&&Dt(new lt(new ArrayBuffer(1)))!=A||pt&&Dt(new pt)!=h||gt&&Dt(gt.resolve())!=l||yt&&Dt(new yt)!=g||wt&&Dt(new wt)!=b)&&(Dt=function(t){var e=et.call(t),n=e==f?t.constructor:void 0,r=n?Mt(n):void 0;if(r)switch(r){case mt:return A;case At:return h;case Et:return l;case St:return g;case vt:return b}return e});var Gt=Array.isArray;function Ft(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=i}(t.length)&&!Vt(t)}var Wt=dt||function(){return!1};function Vt(t){var e=qt(t)?et.call(t):"";return e==c||e==u}function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function zt(t){return Ft(t)?function(t,e){var n=Gt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&Ft(t)}(t)&&tt.call(t,"callee")&&(!ct.call(t,"callee")||et.call(t)==o)}(t)?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],r=n.length,i=!!r;for(var s in t)!e&&!tt.call(t,s)||i&&("length"==s||Lt(s,r))||n.push(s);return n}(t):function(t){if(!Kt(t))return ft(t);var e=[];for(var n in Object(t))tt.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}t.exports=function(t){return Ot(t,!0,!0)}},403:t=>{"use strict";t.exports=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var i=t.charAt(r),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=r}var s=t.length,a=t.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function h(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var n=0,r=0,i=0;t[n]===a;)r++,n++;for(var o=(t.length-n)*c+1>>>0,u=new Uint8Array(o);t[n];){var h=t.charCodeAt(n);if(h>255)return;var d=e[h];if(255===d)return;for(var f=0,l=o-1;(0!==d||f<i)&&-1!==l;l--,f++)d+=s*u[l]>>>0,u[l]=d%256>>>0,d=d/256>>>0;if(0!==d)throw new Error("Non-zero carry");i=f,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var g=new Uint8Array(r+(o-p)),y=r;p!==o;)g[y++]=u[p++];return g}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var n=0,r=0,i=0,o=e.length;i!==o&&0===e[i];)i++,n++;for(var c=(o-i)*u+1>>>0,h=new Uint8Array(c);i!==o;){for(var d=e[i],f=0,l=c-1;(0!==d||f<r)&&-1!==l;l--,f++)d+=256*h[l]>>>0,h[l]=d%s>>>0,d=d/s>>>0;if(0!==d)throw new Error("Non-zero carry");r=f,i++}for(var p=c-r;p!==c&&0===h[p];)p++;for(var g=a.repeat(n);p<c;++p)g+=t.charAt(h[p]);return g},decodeUnsafe:h,decode:function(t){var e=h(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}},414:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.decode=e.encode=void 0;const r=n(688),i=n(74),o=n(403),s="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";e.encode=function(t,e="00"){const n="string"==typeof t?(0,i.hexToBytes)(t):t,a="string"==typeof e?(0,i.hexToBytes)(e):t;if(!(n instanceof Uint8Array&&a instanceof Uint8Array))throw new TypeError("Argument must be of type Uint8Array or string");const c=(0,r.sha256)((0,r.sha256)(new Uint8Array([...a,...n])));return o(s).encode([...a,...n,...c.slice(0,4)])},e.decode=function(t){const e=o(s).decode(t),n=e.slice(0,1),i=e.slice(1,-4),a=(0,r.sha256)((0,r.sha256)(new Uint8Array([...n,...i])));return e.slice(-4).forEach((t,e)=>{if(t!==a[e])throw new Error("Invalid checksum")}),{prefix:n,data:i}}},452:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.crypto=void 0,e.crypto={node:void 0,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0}},460:(t,e)=>{"use strict";function n(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function r(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)}function i(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function o(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");n(t.outputLen),n(t.blockLen)}function s(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function a(t,e){i(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}Object.defineProperty(e,"__esModule",{value:!0}),e.output=e.exists=e.hash=e.bytes=e.bool=e.number=void 0,e.number=n,e.bool=r,e.bytes=i,e.hash=o,e.exists=s,e.output=a;const c={number:n,bool:r,bytes:i,hash:o,exists:s,output:a};e.default=c},546:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SHA2=void 0;const r=n(460),i=n(74);class o extends i.Hash{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,i.createView)(this.buffer)}update(t){r.default.exists(this);const{view:e,buffer:n,blockLen:o}=this,s=(t=(0,i.toBytes)(t)).length;for(let r=0;r<s;){const a=Math.min(o-this.pos,s-r);if(a===o){const e=(0,i.createView)(t);for(;o<=s-r;r+=o)this.process(e,r);continue}n.set(t.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){r.default.exists(this),r.default.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:o,isLE:s}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(n,0),a=0);for(let t=a;t<o;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,o-8,BigInt(8*this.length),s),this.process(n,0);const c=(0,i.createView)(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const h=u/4,d=this.get();if(h>d.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<h;t++)c.setUint32(4*t,d[t],s)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return t.length=r,t.pos=s,t.finished=i,t.destroyed=o,r%e&&t.buffer.set(n),t}}e.SHA2=o},639:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32checkDecode=e.c32checkEncode=void 0;const r=n(688),i=n(74),o=n(669);function s(t){const e=(0,r.sha256)((0,r.sha256)((0,i.hexToBytes)(t)));return(0,i.bytesToHex)(e.slice(0,4))}e.c32checkEncode=function(t,e){if(t<0||t>=32)throw new Error("Invalid version (must be between 0 and 31)");if(!e.match(/^[0-9a-fA-F]*$/))throw new Error("Invalid data (not a hex string)");(e=e.toLowerCase()).length%2!=0&&(e=`0${e}`);let n=t.toString(16);1===n.length&&(n=`0${n}`);const r=s(`${n}${e}`),i=(0,o.c32encode)(`${e}${r}`);return`${o.c32[t]}${i}`},e.c32checkDecode=function(t){t=(0,o.c32normalize)(t);const e=(0,o.c32decode)(t.slice(1)),n=t[0],r=o.c32.indexOf(n),i=e.slice(-8);let a=r.toString(16);if(1===a.length&&(a=`0${a}`),s(`${a}${e.substring(0,e.length-8)}`)!==i)throw new Error("Invalid c32check string: checksum mismatch");return[r,e.substring(0,e.length-8)]}},669:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32decode=e.c32normalize=e.c32encode=e.c32=void 0;const r=n(74);e.c32="0123456789ABCDEFGHJKMNPQRSTVWXYZ";const i="0123456789abcdef";function o(t){return t.toUpperCase().replace(/O/g,"0").replace(/L|I/g,"1")}e.c32encode=function(t,n){if(!t.match(/^[0-9a-fA-F]*$/))throw new Error("Not a hex-encoded string");t.length%2!=0&&(t=`0${t}`);let o=[],s=0;for(let n=(t=t.toLowerCase()).length-1;n>=0;n--)if(s<4){const r=i.indexOf(t[n])>>s;let a=0;0!==n&&(a=i.indexOf(t[n-1]));const c=1+s,u=a%(1<<c)<<5-c,h=e.c32[r+u];s=c,o.unshift(h)}else s=0;let a=0;for(let t=0;t<o.length&&"0"===o[t];t++)a++;o=o.slice(a);const c=(new TextDecoder).decode((0,r.hexToBytes)(t)).match(/^\u0000*/),u=c?c[0].length:0;for(let t=0;t<u;t++)o.unshift(e.c32[0]);if(n){const t=n-o.length;for(let n=0;n<t;n++)o.unshift(e.c32[0])}return o.join("")},e.c32normalize=o,e.c32decode=function(t,n){if(!(t=o(t)).match(`^[${e.c32}]*$`))throw new Error("Not a c32-encoded string");const r=t.match(`^${e.c32[0]}*`),s=r?r[0].length:0;let a=[],c=0,u=0;for(let n=t.length-1;n>=0;n--){4===u&&(a.unshift(i[c]),u=0,c=0);const r=(e.c32.indexOf(t[n])<<u)+c,o=i[r%16];if(u+=1,c=r>>4,c>1<<u)throw new Error("Panic error in decoding.");a.unshift(o)}a.unshift(i[c]),a.length%2==1&&a.unshift("0");let h=0;for(let t=0;t<a.length&&"0"===a[t];t++)h++;a=a.slice(h-h%2);let d=a.join("");for(let t=0;t<s;t++)d=`00${d}`;if(n){const t=2*n-d.length;for(let e=0;e<t;e+=2)d=`00${d}`}return d}},688:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha224=e.sha256=void 0;const r=n(546),i=n(74),o=(t,e,n)=>t&e^~t&n,s=(t,e,n)=>t&e^t&n^e&n,a=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),c=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),u=new Uint32Array(64);class h extends r.SHA2{constructor(){super(64,32,8,!1),this.A=0|c[0],this.B=0|c[1],this.C=0|c[2],this.D=0|c[3],this.E=0|c[4],this.F=0|c[5],this.G=0|c[6],this.H=0|c[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[t,e,n,r,i,o,s,a]}set(t,e,n,r,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)u[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=u[t-15],n=u[t-2],r=(0,i.rotr)(e,7)^(0,i.rotr)(e,18)^e>>>3,o=(0,i.rotr)(n,17)^(0,i.rotr)(n,19)^n>>>10;u[t]=o+u[t-7]+r+u[t-16]|0}let{A:n,B:r,C:c,D:h,E:d,F:f,G:l,H:p}=this;for(let t=0;t<64;t++){const e=p+((0,i.rotr)(d,6)^(0,i.rotr)(d,11)^(0,i.rotr)(d,25))+o(d,f,l)+a[t]+u[t]|0,g=((0,i.rotr)(n,2)^(0,i.rotr)(n,13)^(0,i.rotr)(n,22))+s(n,r,c)|0;p=l,l=f,f=d,d=h+e|0,h=c,c=r,r=n,n=e+g|0}n=n+this.A|0,r=r+this.B|0,c=c+this.C|0,h=h+this.D|0,d=d+this.E|0,f=f+this.F|0,l=l+this.G|0,p=p+this.H|0,this.set(n,r,c,h,d,f,l,p)}roundClean(){u.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class d extends h{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}e.sha256=(0,i.wrapConstructor)(()=>new h),e.sha224=(0,i.wrapConstructor)(()=>new d)},877:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32ToB58=e.b58ToC32=e.c32addressDecode=e.c32address=e.versions=void 0;const r=n(639),i=n(414),o=n(74);e.versions={mainnet:{p2pkh:22,p2sh:20},testnet:{p2pkh:26,p2sh:21}};const s={};s[0]=e.versions.mainnet.p2pkh,s[5]=e.versions.mainnet.p2sh,s[111]=e.versions.testnet.p2pkh,s[196]=e.versions.testnet.p2sh;const a={};function c(t,e){if(!e.match(/^[0-9a-fA-F]{40}$/))throw new Error("Invalid argument: not a hash160 hex string");return`S${(0,r.c32checkEncode)(t,e)}`}function u(t){if(t.length<=5)throw new Error("Invalid c32 address: invalid length");if("S"!=t[0])throw new Error('Invalid c32 address: must start with "S"');return(0,r.c32checkDecode)(t.slice(1))}a[e.versions.mainnet.p2pkh]=0,a[e.versions.mainnet.p2sh]=5,a[e.versions.testnet.p2pkh]=111,a[e.versions.testnet.p2sh]=196,e.c32address=c,e.c32addressDecode=u,e.b58ToC32=function(t,e=-1){const n=i.decode(t),r=(0,o.bytesToHex)(n.data),a=parseInt((0,o.bytesToHex)(n.prefix),16);let u;return e<0?(u=a,void 0!==s[a]&&(u=s[a])):u=e,c(u,r)},e.c32ToB58=function(t,e=-1){const n=u(t),r=n[0],o=n[1];let s;e<0?(s=r,void 0!==a[r]&&(s=a[r])):s=e;let c=s.toString(16);return 1===c.length&&(c=`0${c}`),i.encode(o,c)}},976:()=>{},991:(t,e)=>{"use strict";for(var n=[],r=[],i=("undefined"!=typeof Uint8Array&&Uint8Array,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),o=0;o<64;++o)n[o]=i[o],r[i.charCodeAt(o)]=o;r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63}},r={};function i(t){var e=r[t];if(void 0!==e)return e.exports;var o=r[t]={id:t,loaded:!1,exports:{}};return n[t](o,o.exports,i),o.loaded=!0,o.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},e=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__proto__,i.t=function(n,r){if(1&r&&(n=this(n)),8&r)return n;if("object"==typeof n&&n){if(4&r&&n.__esModule)return n;if(16&r&&"function"==typeof n.then)return n}var o=Object.create(null);i.r(o);var s={};t=t||[null,e({}),e([]),e(e)];for(var a=2&r&&n;("object"==typeof a||"function"==typeof a)&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach(t=>s[t]=()=>n[t]);return s.default=()=>n,i.d(o,s),o},i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.nmd=t=>(t.paths=[],t.children||(t.children=[]),t);var o={};return(()=>{"use strict";function t(t,n){return c(e(t),n)}function e(t){if("bigint"==typeof t)return t;if("string"==typeof t)return BigInt(t);if("number"==typeof t){if(!Number.isInteger(t))throw new RangeError("Invalid value. Values of type 'number' must be an integer.");if(t>Number.MAX_SAFE_INTEGER)throw new RangeError(`Invalid value. Values of type 'number' must be less than or equal to ${Number.MAX_SAFE_INTEGER}. For larger values, try using a BigInt instead.`);return BigInt(t)}if(E(t,Uint8Array))return BigInt(`0x${d(t)}`);throw new TypeError("intToBigInt: Invalid value type. Must be a number, bigint, BigInt-compatible string, or Uint8Array.")}function n(t){return/^0x/i.test(t)?t.slice(2):t}function r(t){if("string"!=typeof t)throw new TypeError("hexToBigInt: expected string, got "+typeof t);return BigInt(`0x${t}`)}function s(t,n=8){return("bigint"==typeof t?t:e(t)).toString(16).padStart(2*n,"0")}function a(t){return parseInt(t,16)}function c(t,e=16){return f(s(t,e))}function u(t){return e=BigInt(`0x${d(t)}`),n=BigInt(8*t.byteLength),function(t,e){return t&BigInt(1)<<e}(e,n-BigInt(1))?e-(BigInt(1)<<n):e;var e,n}i.r(o),i.d(o,{InvalidAddressError:()=>No,Pox4SignatureTopic:()=>qo,StackingClient:()=>is,btcAddressVersionToLegacyHashMode:()=>Bo,decodeBtcAddress:()=>Uo,decodeBtcAddressBytes:()=>Ho,ensureLegacyBtcAddressForPox1:()=>Wo,ensurePox2Activated:()=>Fo,ensureSignerArgsReadiness:()=>Vo,extractPoxAddressFromClarityValue:()=>$o,getErrorString:()=>Do,pox4SignatureMessage:()=>Jo,poxAddressToBtcAddress:()=>Mo,poxAddressToTuple:()=>Lo,signPox4SignatureHash:()=>zo,unwrap:()=>jo,unwrapMap:()=>Go,verifyPox4SignatureHash:()=>Xo});const h=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function d(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(const n of t)e+=h[n];return e}function f(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);t=(t=n(t)).length%2?`0${t}`:t;const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e}function l(t){return(new TextEncoder).encode(t)}function p(t){return(new TextDecoder).decode(t)}function g(t){const e=[];for(let n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return new Uint8Array(e)}function y(t){return String.fromCharCode.apply(null,t)}function w(t){return!Number.isInteger(t)||t<0||t>255}function b(t){if(t.some(w))throw new Error("Some values are invalid bytes.");return new Uint8Array(t)}function m(...t){if(!t.every(t=>t instanceof Uint8Array))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce((t,e)=>t+e.length,0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}function A(t){return m(...t.map(t=>"number"==typeof t?b([t]):t instanceof Array?b(t):t))}function E(t,e){return t instanceof e||t?.constructor?.name?.toLowerCase()===e.name}const S={referrerPolicy:"origin",headers:{"x-hiro-product":"stacksjs"}};async function v(t,e){const n={};return Object.assign(n,S,e),await fetch(t,n)}function x(...t){const{fetchLib:e,middlewares:n}=function(t){let e=v,n=[];return t.length>0&&"function"==typeof t[0]&&(e=t.shift()),t.length>0&&(n=t),{fetchLib:e,middlewares:n}}(t);return async(t,r)=>{let i={url:t,init:r??{}};for(const t of n)"function"==typeof t.pre&&(i=await Promise.resolve(t.pre({fetch:e,...i}))??i);let o=await e(i.url,i.init);for(const t of n)if("function"==typeof t.post){const n=await Promise.resolve(t.post({fetch:e,url:i.url,init:i.init,response:o?.clone()??o}));o=n??o}return o}}var C,I,_,T,P;!function(t){t[t.Mainnet=1]="Mainnet",t[t.Testnet=2147483648]="Testnet"}(C||(C={})),function(t){t[t.Mainnet=385875968]="Mainnet",t[t.Testnet=4278190080]="Testnet"}(I||(I={})),C.Mainnet,(P=_||(_={}))[P.Mainnet=0]="Mainnet",P[P.Testnet=128]="Testnet",function(t){t[t.MainnetSingleSig=22]="MainnetSingleSig",t[t.MainnetMultiSig=20]="MainnetMultiSig",t[t.TestnetSingleSig=26]="TestnetSingleSig",t[t.TestnetMultiSig=21]="TestnetMultiSig"}(T||(T={})),_.Mainnet;const k={chainId:C.Mainnet,transactionVersion:_.Mainnet,peerNetworkId:I.Mainnet,magicBytes:"X2",bootAddress:"SP000000000000000000002Q6VF78",addressVersion:{singleSig:T.MainnetSingleSig,multiSig:T.MainnetMultiSig},client:{baseUrl:"https://api.mainnet.hiro.so"}},R={chainId:C.Testnet,transactionVersion:_.Testnet,peerNetworkId:I.Testnet,magicBytes:"T2",bootAddress:"ST000000000000000000002AMW42H",addressVersion:{singleSig:T.TestnetSingleSig,multiSig:T.TestnetMultiSig},client:{baseUrl:"https://api.testnet.hiro.so"}},O={...R,addressVersion:{...R.addressVersion},magicBytes:"id",client:{baseUrl:"http://localhost:3999"}},N={...O,addressVersion:{...O.addressVersion},client:{...O.client}},B=["mainnet","testnet","devnet","mocknet"];function U(t){return"string"==typeof t?function(t){switch(t){case"mainnet":return k;case"testnet":return R;case"devnet":return O;case"mocknet":return N;default:throw new Error(`Unknown network name: ${t}`)}}(t):t}function H(t){return t.client.fetch?t.client:{...t.client,fetch:x()}}class $ extends Error{constructor(t){super(t),this.message=t,this.name=this.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class D extends ${constructor(t){super(t)}}class L extends ${constructor(t){super(t)}}class K extends ${constructor(t){super(t)}}class M extends ${constructor(t){super(t)}}class j extends ${constructor(t){super(t)}}function G(t,e){return t[e]}function F(t,e,n=0){return t[n]=e,t}function W(t,e,n=0){return t[n+3]=e,e>>>=8,t[n+2]=e,e>>>=8,t[n+1]=e,e>>>=8,t[n]=e,t}function V(t,e,n=0){return t[n+0]=255&e,e>>>=8,t[n+1]=255&e,e>>>=8,t[n+2]=255&e,e>>>=8,t[n+3]=255&e,t}const q=new Map;function z(t,e){const n=q.get(t);if(void 0!==n)return n(e);const r=function(t){const e=Object.values(t).filter(t=>"number"==typeof t),n=new Set(e);return t=>n.has(t)}(t);return q.set(t,r),z(t,e)}class X{constructor(t){this.consumed=0,this.source="string"==typeof t?f(t):t}readBytes(t){const e=this.source.subarray(this.consumed,this.consumed+t);return this.consumed+=t,e}readUInt32BE(){return(t=this.readBytes(4))[0]*2**24+65536*t[1]+256*t[2]+t[3];var t}readUInt8(){return G(this.readBytes(1),0)}readUInt16BE(){return((t=this.readBytes(2))[0+0]<<8|t[1])>>>0;var t}readBigUIntLE(t){const e=d(this.readBytes(t).slice().reverse());return BigInt(`0x${e}`)}readBigUIntBE(t){const e=d(this.readBytes(t));return BigInt(`0x${e}`)}get readOffset(){return this.consumed}set readOffset(t){this.consumed=t}get internalBytes(){return this.source}readUInt8Enum(t,e){const n=this.readUInt8();if(z(t,n))return n;throw e(n)}}const J=128,Z=128,Y=16;var Q,tt,et,nt,rt,it;(it=Q||(Q={}))[it.TokenTransfer=0]="TokenTransfer",it[it.SmartContract=1]="SmartContract",it[it.VersionedSmartContract=6]="VersionedSmartContract",it[it.ContractCall=2]="ContractCall",it[it.PoisonMicroblock=3]="PoisonMicroblock",it[it.Coinbase=4]="Coinbase",it[it.CoinbaseToAltRecipient=5]="CoinbaseToAltRecipient",it[it.TenureChange=7]="TenureChange",it[it.NakamotoCoinbase=8]="NakamotoCoinbase",(rt=tt||(tt={}))[rt.Clarity1=1]="Clarity1",rt[rt.Clarity2=2]="Clarity2",rt[rt.Clarity3=3]="Clarity3",rt[rt.Clarity4=4]="Clarity4",rt[rt.Clarity5=5]="Clarity5",(nt=et||(et={}))[nt.OnChainOnly=1]="OnChainOnly",nt[nt.OffChainOnly=2]="OffChainOnly",nt[nt.Any=3]="Any";var ot,st,at,ct,ut,ht,dt,ft,lt,pt,gt,yt,wt,bt,mt,At,Et,St,vt,xt;function Ct(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function It(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}et.OnChainOnly,et.OffChainOnly,et.Any,et.OnChainOnly,et.OnChainOnly,et.OffChainOnly,et.OffChainOnly,et.Any,et.Any,(xt=ot||(ot={}))[xt.Allow=1]="Allow",xt[xt.Deny=2]="Deny",xt[xt.Originator=3]="Originator",(vt=st||(st={}))[vt.STX=0]="STX",vt[vt.Fungible=1]="Fungible",vt[vt.NonFungible=2]="NonFungible",(St=at||(at={}))[St.Standard=4]="Standard",St[St.Sponsored=5]="Sponsored",(Et=ct||(ct={}))[Et.P2PKH=0]="P2PKH",Et[Et.P2SH=1]="P2SH",Et[Et.P2WPKH=2]="P2WPKH",Et[Et.P2WSH=3]="P2WSH",Et[Et.P2SHNonSequential=5]="P2SHNonSequential",Et[Et.P2WSHNonSequential=7]="P2WSHNonSequential",(At=ut||(ut={}))[At.Compressed=0]="Compressed",At[At.Uncompressed=1]="Uncompressed",function(t){t[t.Equal=1]="Equal",t[t.Greater=2]="Greater",t[t.GreaterEqual=3]="GreaterEqual",t[t.Less=4]="Less",t[t.LessEqual=5]="LessEqual"}(ht||(ht={})),function(t){t[t.Sends=16]="Sends",t[t.DoesNotSend=17]="DoesNotSend",t[t.MaybeSent=18]="MaybeSent"}(dt||(dt={})),(mt=ft||(ft={}))[mt.Origin=1]="Origin",mt[mt.Standard=2]="Standard",mt[mt.Contract=3]="Contract",function(t){t[t.STX=0]="STX",t[t.Fungible=1]="Fungible",t[t.NonFungible=2]="NonFungible"}(lt||(lt={})),(bt=pt||(pt={}))[bt.BlockFound=0]="BlockFound",bt[bt.Extended=1]="Extended",bt[bt.ExtendedRuntime=2]="ExtendedRuntime",bt[bt.ExtendedReadCount=3]="ExtendedReadCount",bt[bt.ExtendedReadLength=4]="ExtendedReadLength",bt[bt.ExtendedWriteCount=5]="ExtendedWriteCount",bt[bt.ExtendedWriteLength=6]="ExtendedWriteLength",(wt=gt||(gt={}))[wt.PublicKeyCompressed=0]="PublicKeyCompressed",wt[wt.PublicKeyUncompressed=1]="PublicKeyUncompressed",wt[wt.SignatureCompressed=2]="SignatureCompressed",wt[wt.SignatureUncompressed=3]="SignatureUncompressed",function(t){t.Serialization="Serialization",t.Deserialization="Deserialization",t.SignatureValidation="SignatureValidation",t.FeeTooLow="FeeTooLow",t.BadNonce="BadNonce",t.NotEnoughFunds="NotEnoughFunds",t.NoSuchContract="NoSuchContract",t.NoSuchPublicFunction="NoSuchPublicFunction",t.BadFunctionArgument="BadFunctionArgument",t.ContractAlreadyExists="ContractAlreadyExists",t.PoisonMicroblocksDoNotConflict="PoisonMicroblocksDoNotConflict",t.PoisonMicroblockHasUnknownPubKeyHash="PoisonMicroblockHasUnknownPubKeyHash",t.PoisonMicroblockIsInvalid="PoisonMicroblockIsInvalid",t.BadAddressVersionByte="BadAddressVersionByte",t.NoCoinbaseViaMempool="NoCoinbaseViaMempool",t.ServerFailureNoSuchChainTip="ServerFailureNoSuchChainTip",t.ServerFailureDatabase="ServerFailureDatabase",t.ServerFailureOther="ServerFailureOther"}(yt||(yt={}));const _t={number:Ct,bool:function(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)},bytes:It,hash:function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Ct(t.outputLen),Ct(t.blockLen)},exists:function(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")},output:function(t,e){It(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}},Tt=("object"==typeof self&&"crypto"in self&&self.crypto,t=>new DataView(t.buffer,t.byteOffset,t.byteLength)),Pt=(t,e)=>t<<32-e|t>>>e;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function kt(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));class Rt{clone(){return this._cloneInto()}}function Ot(t){const e=e=>t().update(kt(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}class Nt extends Rt{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Tt(this.buffer)}update(t){_t.exists(this);const{view:e,buffer:n,blockLen:r}=this,i=(t=kt(t)).length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const e=Tt(t);for(;r<=i-o;o+=r)this.process(e,o);continue}n.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_t.exists(this),_t.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:i}=this;let{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(n,0),o=0);for(let t=o;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=Tt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)s.setUint32(4*t,u[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return t.length=r,t.pos=s,t.finished=i,t.destroyed=o,r%e&&t.buffer.set(n),t}}const Bt=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ut=Uint8Array.from({length:16},(t,e)=>e),Ht=Ut.map(t=>(9*t+5)%16);let $t=[Ut],Dt=[Ht];for(let t=0;t<4;t++)for(let e of[$t,Dt])e.push(e[t].map(t=>Bt[t]));const Lt=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>new Uint8Array(t)),Kt=$t.map((t,e)=>t.map(t=>Lt[e][t])),Mt=Dt.map((t,e)=>t.map(t=>Lt[e][t])),jt=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Gt=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),Ft=(t,e)=>t<<e|t>>>32-e;function Wt(t,e,n,r){return 0===t?e^n^r:1===t?e&n|~e&r:2===t?(e|~n)^r:3===t?e&r|n&~r:e^(n|~r)}const Vt=new Uint32Array(16);class qt extends Nt{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:e,h2:n,h3:r,h4:i}=this;return[t,e,n,r,i]}set(t,e,n,r,i){this.h0=0|t,this.h1=0|e,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(t,e){for(let n=0;n<16;n++,e+=4)Vt[n]=t.getUint32(e,!0);let n=0|this.h0,r=n,i=0|this.h1,o=i,s=0|this.h2,a=s,c=0|this.h3,u=c,h=0|this.h4,d=h;for(let t=0;t<5;t++){const e=4-t,f=jt[t],l=Gt[t],p=$t[t],g=Dt[t],y=Kt[t],w=Mt[t];for(let e=0;e<16;e++){const r=Ft(n+Wt(t,i,s,c)+Vt[p[e]]+f,y[e])+h|0;n=h,h=c,c=0|Ft(s,10),s=i,i=r}for(let t=0;t<16;t++){const n=Ft(r+Wt(e,o,a,u)+Vt[g[t]]+l,w[t])+d|0;r=d,d=u,u=0|Ft(a,10),a=o,o=n}}this.set(this.h1+s+u|0,this.h2+c+d|0,this.h3+h+r|0,this.h4+n+o|0,this.h0+i+a|0)}roundClean(){Vt.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const zt=Ot(()=>new qt),Xt=(t,e,n)=>t&e^~t&n,Jt=(t,e,n)=>t&e^t&n^e&n,Zt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Yt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qt=new Uint32Array(64);class te extends Nt{constructor(){super(64,32,8,!1),this.A=0|Yt[0],this.B=0|Yt[1],this.C=0|Yt[2],this.D=0|Yt[3],this.E=0|Yt[4],this.F=0|Yt[5],this.G=0|Yt[6],this.H=0|Yt[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[t,e,n,r,i,o,s,a]}set(t,e,n,r,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)Qt[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=Qt[t-15],n=Qt[t-2],r=Pt(e,7)^Pt(e,18)^e>>>3,i=Pt(n,17)^Pt(n,19)^n>>>10;Qt[t]=i+Qt[t-7]+r+Qt[t-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:a,G:c,H:u}=this;for(let t=0;t<64;t++){const e=u+(Pt(s,6)^Pt(s,11)^Pt(s,25))+Xt(s,a,c)+Zt[t]+Qt[t]|0,h=(Pt(n,2)^Pt(n,13)^Pt(n,22))+Jt(n,r,i)|0;u=c,c=a,a=s,s=o+e|0,o=i,i=r,r=n,n=e+h|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,i,o,s,a,c,u)}roundClean(){Qt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class ee extends te{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const ne=Ot(()=>new te),re=(Ot(()=>new ee),BigInt(2**32-1)),ie=BigInt(32);function oe(t,e=!1){return e?{h:Number(t&re),l:Number(t>>ie&re)}:{h:0|Number(t>>ie&re),l:0|Number(t&re)}}const se=function(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:o,l:s}=oe(t[i],e);[n[i],r[i]]=[o,s]}return[n,r]},ae=(t,e,n)=>t>>>n,ce=(t,e,n)=>t<<32-n|e>>>n,ue=(t,e,n)=>t>>>n|e<<32-n,he=(t,e,n)=>t<<32-n|e>>>n,de=(t,e,n)=>t<<64-n|e>>>n-32,fe=(t,e,n)=>t>>>n-32|e<<64-n,le=function(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:0|i}},pe=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),ge=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,ye=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),we=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,be=(t,e,n,r,i,o)=>e+n+r+i+o+(t/2**32|0)|0,me=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),[Ae,Ee]=se(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Se=new Uint32Array(80),ve=new Uint32Array(80);class xe extends Nt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:e,Bh:n,Bl:r,Ch:i,Cl:o,Dh:s,Dl:a,Eh:c,El:u,Fh:h,Fl:d,Gh:f,Gl:l,Hh:p,Hl:g}=this;return[t,e,n,r,i,o,s,a,c,u,h,d,f,l,p,g]}set(t,e,n,r,i,o,s,a,c,u,h,d,f,l,p,g){this.Ah=0|t,this.Al=0|e,this.Bh=0|n,this.Bl=0|r,this.Ch=0|i,this.Cl=0|o,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|h,this.Fl=0|d,this.Gh=0|f,this.Gl=0|l,this.Hh=0|p,this.Hl=0|g}process(t,e){for(let n=0;n<16;n++,e+=4)Se[n]=t.getUint32(e),ve[n]=t.getUint32(e+=4);for(let t=16;t<80;t++){const e=0|Se[t-15],n=0|ve[t-15],r=ue(e,n,1)^ue(e,n,8)^ae(e,n,7),i=he(e,n,1)^he(e,n,8)^ce(e,n,7),o=0|Se[t-2],s=0|ve[t-2],a=ue(o,s,19)^de(o,s,61)^ae(o,s,6),c=he(o,s,19)^fe(o,s,61)^ce(o,s,6),u=ye(i,c,ve[t-7],ve[t-16]),h=we(u,r,a,Se[t-7],Se[t-16]);Se[t]=0|h,ve[t]=0|u}let{Ah:n,Al:r,Bh:i,Bl:o,Ch:s,Cl:a,Dh:c,Dl:u,Eh:h,El:d,Fh:f,Fl:l,Gh:p,Gl:g,Hh:y,Hl:w}=this;for(let t=0;t<80;t++){const e=ue(h,d,14)^ue(h,d,18)^de(h,d,41),b=he(h,d,14)^he(h,d,18)^fe(h,d,41),m=h&f^~h&p,A=me(w,b,d&l^~d&g,Ee[t],ve[t]),E=be(A,y,e,m,Ae[t],Se[t]),S=0|A,v=ue(n,r,28)^de(n,r,34)^de(n,r,39),x=he(n,r,28)^fe(n,r,34)^fe(n,r,39),C=n&i^n&s^i&s,I=r&o^r&a^o&a;y=0|p,w=0|g,p=0|f,g=0|l,f=0|h,l=0|d,({h,l:d}=le(0|c,0|u,0|E,0|S)),c=0|s,u=0|a,s=0|i,a=0|o,i=0|n,o=0|r;const _=pe(S,x,I);n=ge(_,E,v,C),r=0|_}({h:n,l:r}=le(0|this.Ah,0|this.Al,0|n,0|r)),({h:i,l:o}=le(0|this.Bh,0|this.Bl,0|i,0|o)),({h:s,l:a}=le(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=le(0|this.Dh,0|this.Dl,0|c,0|u)),({h,l:d}=le(0|this.Eh,0|this.El,0|h,0|d)),({h:f,l}=le(0|this.Fh,0|this.Fl,0|f,0|l)),({h:p,l:g}=le(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:w}=le(0|this.Hh,0|this.Hl,0|y,0|w)),this.set(n,r,i,o,s,a,c,u,h,d,f,l,p,g,y,w)}roundClean(){Se.fill(0),ve.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Ce extends xe{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}class Ie extends xe{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class _e extends xe{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}Ot(()=>new xe),Ot(()=>new Ce);const Te=Ot(()=>new Ie);Ot(()=>new _e);var Pe=i(976),ke=i.t(Pe,2);const Re=BigInt(0),Oe=BigInt(1),Ne=BigInt(2),Be=BigInt(3),Ue=BigInt(8),He=Object.freeze({a:Re,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:Oe,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),$e=(t,e)=>(t+e/Ne)/e,De={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const{n:e}=He,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Oe*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),a=$e(o*t,e),c=$e(-r*t,e);let u=pn(t-a*n-c*i,e),h=pn(-a*r-c*o,e);const d=u>s,f=h>s;if(d&&(u=e-u),f&&(h=e-h),u>s||h>s)throw new Error("splitScalarEndo: Endomorphism failed, k="+t);return{k1neg:d,k1:u,k2neg:f,k2:h}}},Le=32,Ke=32,Me=32,je=Le+1,Ge=2*Le+1;function Fe(t){const{a:e,b:n}=He,r=pn(t*t),i=pn(r*t);return pn(i+e*t+n)}const We=He.a===Re;class Ve extends Error{constructor(t){super(t)}}function qe(t){if(!(t instanceof ze))throw new TypeError("JacobianPoint expected")}class ze{constructor(t,e,n){this.x=t,this.y=e,this.z=n}static fromAffine(t){if(!(t instanceof Ze))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(Ze.ZERO)?ze.ZERO:new ze(t.x,t.y,Oe)}static toAffineBatch(t){const e=function(t,e=He.P){const n=new Array(t.length),r=yn(t.reduce((t,r,i)=>r===Re?t:(n[i]=t,pn(t*r,e)),Oe),e);return t.reduceRight((t,r,i)=>r===Re?t:(n[i]=pn(t*n[i],e),pn(t*r,e)),r),n}(t.map(t=>t.z));return t.map((t,n)=>t.toAffine(e[n]))}static normalizeZ(t){return ze.toAffineBatch(t).map(ze.fromAffine)}equals(t){qe(t);const{x:e,y:n,z:r}=this,{x:i,y:o,z:s}=t,a=pn(r*r),c=pn(s*s),u=pn(e*c),h=pn(i*a),d=pn(pn(n*s)*c),f=pn(pn(o*r)*a);return u===h&&d===f}negate(){return new ze(this.x,pn(-this.y),this.z)}double(){const{x:t,y:e,z:n}=this,r=pn(t*t),i=pn(e*e),o=pn(i*i),s=t+i,a=pn(Ne*(pn(s*s)-r-o)),c=pn(Be*r),u=pn(c*c),h=pn(u-Ne*a),d=pn(c*(a-h)-Ue*o),f=pn(Ne*e*n);return new ze(h,d,f)}add(t){qe(t);const{x:e,y:n,z:r}=this,{x:i,y:o,z:s}=t;if(i===Re||o===Re)return this;if(e===Re||n===Re)return t;const a=pn(r*r),c=pn(s*s),u=pn(e*c),h=pn(i*a),d=pn(pn(n*s)*c),f=pn(pn(o*r)*a),l=pn(h-u),p=pn(f-d);if(l===Re)return p===Re?this.double():ze.ZERO;const g=pn(l*l),y=pn(l*g),w=pn(u*g),b=pn(p*p-y-Ne*w),m=pn(p*(w-b)-d*y),A=pn(r*s*l);return new ze(b,m,A)}subtract(t){return this.add(t.negate())}multiplyUnsafe(t){const e=ze.ZERO;if("bigint"==typeof t&&t===Re)return e;let n=ln(t);if(n===Oe)return this;if(!We){let t=e,r=this;for(;n>Re;)n&Oe&&(t=t.add(r)),r=r.double(),n>>=Oe;return t}let{k1neg:r,k1:i,k2neg:o,k2:s}=De.splitScalar(n),a=e,c=e,u=this;for(;i>Re||s>Re;)i&Oe&&(a=a.add(u)),s&Oe&&(c=c.add(u)),u=u.double(),i>>=Oe,s>>=Oe;return r&&(a=a.negate()),o&&(c=c.negate()),c=new ze(pn(c.x*De.beta),c.y,c.z),a.add(c)}precomputeWindow(t){const e=We?128/t+1:256/t+1,n=[];let r=this,i=r;for(let o=0;o<e;o++){i=r,n.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(r),n.push(i);r=i.double()}return n}wNAF(t,e){!e&&this.equals(ze.BASE)&&(e=Ze.BASE);const n=e&&e._WINDOW_SIZE||1;if(256%n)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let r=e&&Je.get(e);r||(r=this.precomputeWindow(n),e&&1!==n&&(r=ze.normalizeZ(r),Je.set(e,r)));let i=ze.ZERO,o=ze.BASE;const s=1+(We?128/n:256/n),a=2**(n-1),c=BigInt(2**n-1),u=2**n,h=BigInt(n);for(let e=0;e<s;e++){const n=e*a;let s=Number(t&c);t>>=h,s>a&&(s-=u,t+=Oe);const d=n,f=n+Math.abs(s)-1,l=e%2!=0,p=s<0;0===s?o=o.add(Xe(l,r[d])):i=i.add(Xe(p,r[f]))}return{p:i,f:o}}multiply(t,e){let n,r,i=ln(t);if(We){const{k1neg:t,k1:o,k2neg:s,k2:a}=De.splitScalar(i);let{p:c,f:u}=this.wNAF(o,e),{p:h,f:d}=this.wNAF(a,e);c=Xe(t,c),h=Xe(s,h),h=new ze(pn(h.x*De.beta),h.y,h.z),n=c.add(h),r=u.add(d)}else{const{p:t,f:o}=this.wNAF(i,e);n=t,r=o}return ze.normalizeZ([n,r])[0]}toAffine(t){const{x:e,y:n,z:r}=this,i=this.equals(ze.ZERO);null==t&&(t=i?Ue:yn(r));const o=t,s=pn(o*o),a=pn(s*o),c=pn(e*s),u=pn(n*a),h=pn(r*o);if(i)return Ze.ZERO;if(h!==Oe)throw new Error("invZ was invalid");return new Ze(c,u)}}function Xe(t,e){const n=e.negate();return t?n:e}ze.BASE=new ze(He.Gx,He.Gy,Oe),ze.ZERO=new ze(Re,Oe,Re);const Je=new WeakMap;class Ze{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,Je.delete(this)}hasEvenY(){return this.y%Ne===Re}static fromCompressedHex(t){const e=32===t.length,n=dn(e?t:t.subarray(1));if(!Sn(n))throw new Error("Point is not on curve");let r=function(t){const{P:e}=He,n=BigInt(6),r=BigInt(11),i=BigInt(22),o=BigInt(23),s=BigInt(44),a=BigInt(88),c=t*t*t%e,u=c*c*t%e,h=gn(u,Be)*u%e,d=gn(h,Be)*u%e,f=gn(d,Ne)*c%e,l=gn(f,r)*f%e,p=gn(l,i)*l%e,g=gn(p,s)*p%e,y=gn(g,a)*g%e,w=gn(y,s)*p%e,b=gn(w,Be)*u%e,m=gn(b,o)*l%e,A=gn(m,n)*c%e,E=gn(A,Ne);if(E*E%e!==t)throw new Error("Cannot find square root");return E}(Fe(n));const i=(r&Oe)===Oe;e?i&&(r=pn(-r)):!(1&~t[0])!==i&&(r=pn(-r));const o=new Ze(n,r);return o.assertValidity(),o}static fromUncompressedHex(t){const e=dn(t.subarray(1,Le+1)),n=dn(t.subarray(Le+1,2*Le+1)),r=new Ze(e,n);return r.assertValidity(),r}static fromHex(t){const e=fn(t),n=e.length,r=e[0];if(n===Le)return this.fromCompressedHex(e);if(n===je&&(2===r||3===r))return this.fromCompressedHex(e);if(n===Ge&&4===r)return this.fromUncompressedHex(e);throw new Error(`Point.fromHex: received invalid point. Expected 32-${je} compressed bytes or ${Ge} uncompressed bytes, not ${n}`)}static fromPrivateKey(t){return Ze.BASE.multiply(xn(t))}static fromSignature(t,e,n){const{r,s:i}=Cn(e);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const o=wn(fn(t)),{n:s}=He,a=2===n||3===n?r+s:r,c=yn(a,s),u=pn(-o*c,s),h=pn(i*c,s),d=1&n?"03":"02",f=Ze.fromHex(d+sn(a)),l=Ze.BASE.multiplyAndAddUnsafe(f,u,h);if(!l)throw new Error("Cannot recover signature: point at infinify");return l.assertValidity(),l}toRawBytes(t=!1){return hn(this.toHex(t))}toHex(t=!1){const e=sn(this.x);return t?`${this.hasEvenY()?"02":"03"}${e}`:`04${e}${sn(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const t="Point is not on elliptic curve",{x:e,y:n}=this;if(!Sn(e)||!Sn(n))throw new Error(t);const r=pn(n*n);if(pn(r-Fe(e))!==Re)throw new Error(t)}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new Ze(this.x,pn(-this.y))}double(){return ze.fromAffine(this).double().toAffine()}add(t){return ze.fromAffine(this).add(ze.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return ze.fromAffine(this).multiply(t,this).toAffine()}multiplyAndAddUnsafe(t,e,n){const r=ze.fromAffine(this),i=e===Re||e===Oe||this!==Ze.BASE?r.multiplyUnsafe(e):r.multiply(e),o=ze.fromAffine(t).multiplyUnsafe(n),s=i.add(o);return s.equals(ze.ZERO)?void 0:s.toAffine()}}function Ye(t){return Number.parseInt(t[0],16)>=8?"00"+t:t}function Qe(t){if(t.length<2||2!==t[0])throw new Error(`Invalid signature integer tag: ${rn(t)}`);const e=t[1],n=t.subarray(2,e+2);if(!e||n.length!==e)throw new Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:dn(n),left:t.subarray(e+2)}}Ze.BASE=new Ze(He.Gx,He.Gy),Ze.ZERO=new Ze(Re,Re);class tn{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromCompact(t){const e=t instanceof Uint8Array,n="Signature.fromCompact";if("string"!=typeof t&&!e)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=e?rn(t):t;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new tn(un(r.slice(0,64)),un(r.slice(64,128)))}static fromDER(t){const e=t instanceof Uint8Array;if("string"!=typeof t&&!e)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:n,s:r}=function(t){if(t.length<2||48!=t[0])throw new Error(`Invalid signature tag: ${rn(t)}`);if(t[1]!==t.length-2)throw new Error("Invalid signature: incorrect length");const{data:e,left:n}=Qe(t.subarray(2)),{data:r,left:i}=Qe(n);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${rn(i)}`);return{r:e,s:r}}(e?t:hn(t));return new tn(n,r)}static fromHex(t){return this.fromDER(t)}assertValidity(){const{r:t,s:e}=this;if(!En(t))throw new Error("Invalid Signature: r must be 0 < r < n");if(!En(e))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const t=He.n>>Oe;return this.s>t}normalizeS(){return this.hasHighS()?new tn(this.r,pn(-this.s,He.n)):this}toDERRawBytes(){return hn(this.toDERHex())}toDERHex(){const t=Ye(cn(this.s)),e=Ye(cn(this.r)),n=t.length/2,r=e.length/2,i=cn(n),o=cn(r);return`30${cn(r+n+4)}02${o}${e}02${i}${t}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return hn(this.toCompactHex())}toCompactHex(){return sn(this.r)+sn(this.s)}}function en(...t){if(!t.every(t=>t instanceof Uint8Array))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce((t,e)=>t+e.length,0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}const nn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function rn(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");let e="";for(let n=0;n<t.length;n++)e+=nn[t[n]];return e}const on=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function sn(t){if("bigint"!=typeof t)throw new Error("Expected bigint");if(!(Re<=t&&t<on))throw new Error("Expected number 0 <= n < 2^256");return t.toString(16).padStart(64,"0")}function an(t){const e=hn(sn(t));if(32!==e.length)throw new Error("Error: expected 32 bytes");return e}function cn(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function un(t){if("string"!=typeof t)throw new TypeError("hexToNumber: expected string, got "+typeof t);return BigInt(`0x${t}`)}function hn(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex"+t.length);const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e}function dn(t){return un(rn(t))}function fn(t){return t instanceof Uint8Array?Uint8Array.from(t):hn(t)}function ln(t){if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)return BigInt(t);if("bigint"==typeof t&&En(t))return t;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function pn(t,e=He.P){const n=t%e;return n>=Re?n:e+n}function gn(t,e){const{P:n}=He;let r=t;for(;e-- >Re;)r*=r,r%=n;return r}function yn(t,e=He.P){if(t===Re||e<=Re)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=pn(t,e),r=e,i=Re,o=Oe,s=Oe,a=Re;for(;n!==Re;){const t=r/n,e=r%n,c=i-s*t,u=o-a*t;r=n,n=e,i=s,o=a,s=c,a=u}if(r!==Oe)throw new Error("invert: does not exist");return pn(i,e)}function wn(t,e=!1){const n=function(t){const e=8*t.length-8*Ke,n=dn(t);return e>0?n>>BigInt(e):n}(t);if(e)return n;const{n:r}=He;return n>=r?n-r:n}let bn,mn;class An{constructor(t,e){if(this.hashLen=t,this.qByteLen=e,"number"!=typeof t||t<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");this.v=new Uint8Array(t).fill(1),this.k=new Uint8Array(t).fill(0),this.counter=0}hmac(...t){return Nn.hmacSha256(this.k,...t)}hmacSync(...t){return mn(this.k,...t)}checkSync(){if("function"!=typeof mn)throw new Ve("hmacSha256Sync needs to be set")}incr(){if(this.counter>=1e3)throw new Error("Tried 1,000 k values for sign(), all were invalid");this.counter+=1}async reseed(t=new Uint8Array){this.k=await this.hmac(this.v,Uint8Array.from([0]),t),this.v=await this.hmac(this.v),0!==t.length&&(this.k=await this.hmac(this.v,Uint8Array.from([1]),t),this.v=await this.hmac(this.v))}reseedSync(t=new Uint8Array){this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),t),this.v=this.hmacSync(this.v),0!==t.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),t),this.v=this.hmacSync(this.v))}async generate(){this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=await this.hmac(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return en(...e)}generateSync(){this.checkSync(),this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=this.hmacSync(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return en(...e)}}function En(t){return Re<t&&t<He.n}function Sn(t){return Re<t&&t<He.P}function vn(t,e,n,r=!0){const{n:i}=He,o=wn(t,!0);if(!En(o))return;const s=yn(o,i),a=Ze.BASE.multiply(o),c=pn(a.x,i);if(c===Re)return;const u=pn(s*pn(e+n*c,i),i);if(u===Re)return;let h=new tn(c,u),d=(a.x===h.r?0:2)|Number(a.y&Oe);return r&&h.hasHighS()&&(h=h.normalizeS(),d^=1),{sig:h,recovery:d}}function xn(t){let e;if("bigint"==typeof t)e=t;else if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)e=BigInt(t);else if("string"==typeof t){if(t.length!==2*Ke)throw new Error("Expected 32 bytes of private key");e=un(t)}else{if(!(t instanceof Uint8Array))throw new TypeError("Expected valid private key");if(t.length!==Ke)throw new Error("Expected 32 bytes of private key");e=dn(t)}if(!En(e))throw new Error("Expected private key: 0 < key < n");return e}function Cn(t){if(t instanceof tn)return t.assertValidity(),t;try{return tn.fromDER(t)}catch(e){return tn.fromCompact(t)}}function In(t){return dn(t.length>Le?t.slice(0,Le):t)}function _n(t){const e=In(t),n=pn(e,He.n);return Tn(n<Re?e:n)}function Tn(t){return an(t)}const Pn={strict:!0};function kn(t,e,n,r=Pn){let i;try{i=Cn(t),e=fn(e)}catch(t){return!1}const{r:o,s}=i;if(r.strict&&i.hasHighS())return!1;const a=wn(e);let c;try{c=function(t){return t instanceof Ze?(t.assertValidity(),t):Ze.fromHex(t)}(n)}catch(t){return!1}const{n:u}=He,h=yn(s,u),d=pn(a*h,u),f=pn(o*h,u),l=Ze.BASE.multiplyAndAddUnsafe(c,d,f);return!!l&&pn(l.x,u)===o}Ze.BASE._setWindowSize(8);const Rn={node:ke,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},On={},Nn={bytesToHex:rn,hexToBytes:hn,concatBytes:en,mod:pn,invert:yn,isValidPrivateKey(t){try{return xn(t),!0}catch(t){return!1}},_bigintTo32Bytes:an,_normalizePrivateKey:xn,hashToPrivateKey:t=>{t=fn(t);const e=Ke+8;if(t.length<e||t.length>1024)throw new Error("Expected valid bytes of private key as per FIPS 186");return an(pn(dn(t),He.n-Oe)+Oe)},randomBytes:(t=32)=>{if(Rn.web)return Rn.web.getRandomValues(new Uint8Array(t));if(Rn.node){const{randomBytes:e}=Rn.node;return Uint8Array.from(e(t))}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>Nn.hashToPrivateKey(Nn.randomBytes(Ke+8)),precompute(t=8,e=Ze.BASE){const n=e===Ze.BASE?e:new Ze(e.x,e.y);return n._setWindowSize(t),n.multiply(Be),n},sha256:async(...t)=>{if(Rn.web){const e=await Rn.web.subtle.digest("SHA-256",en(...t));return new Uint8Array(e)}if(Rn.node){const{createHash:e}=Rn.node,n=e("sha256");return t.forEach(t=>n.update(t)),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(t,...e)=>{if(Rn.web){const n=await Rn.web.subtle.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),r=en(...e),i=await Rn.web.subtle.sign("HMAC",n,r);return new Uint8Array(i)}if(Rn.node){const{createHmac:n}=Rn.node,r=n("sha256",t);return e.forEach(t=>r.update(t)),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(t,...e)=>{let n=On[t];if(void 0===n){const e=await Nn.sha256(Uint8Array.from(t,t=>t.charCodeAt(0)));n=en(e,e),On[t]=n}return Nn.sha256(n,...e)},taggedHashSync:(t,...e)=>{if("function"!=typeof bn)throw new Ve("sha256Sync is undefined, you need to set it");let n=On[t];if(void 0===n){const e=bn(Uint8Array.from(t,t=>t.charCodeAt(0)));n=en(e,e),On[t]=n}return bn(n,...e)},_JacobianPoint:ze};Object.defineProperties(Nn,{sha256Sync:{configurable:!1,get:()=>bn,set(t){bn||(bn=t)}},hmacSha256Sync:{configurable:!1,get:()=>mn,set(t){mn||(mn=t)}}});var Bn,Un,Hn,$n=i(258),Dn=i(290),Ln=i.n(Dn);function Kn(t){return Un[t]}(Hn=Bn||(Bn={})).Int="int",Hn.UInt="uint",Hn.Buffer="buffer",Hn.BoolTrue="true",Hn.BoolFalse="false",Hn.PrincipalStandard="address",Hn.PrincipalContract="contract",Hn.ResponseOk="ok",Hn.ResponseErr="err",Hn.OptionalNone="none",Hn.OptionalSome="some",Hn.List="list",Hn.Tuple="tuple",Hn.StringASCII="ascii",Hn.StringUTF8="utf8",function(t){t[t.int=0]="int",t[t.uint=1]="uint",t[t.buffer=2]="buffer",t[t.true=3]="true",t[t.false=4]="false",t[t.address=5]="address",t[t.contract=6]="contract",t[t.ok=7]="ok",t[t.err=8]="err",t[t.none=9]="none",t[t.some=10]="some",t[t.list=11]="list",t[t.tuple=12]="tuple",t[t.ascii=13]="ascii",t[t.utf8=14]="utf8"}(Un||(Un={}));const Mn=BigInt("0xffffffffffffffffffffffffffffffff"),jn=BigInt(0),Gn=BigInt("0x7fffffffffffffffffffffffffffffff"),Fn=BigInt("-170141183460469231731687303715884105728"),Wn=t=>{const n=e(t);if(n<jn)throw new RangeError("Cannot construct unsigned clarity integer from negative value");if(n>Mn)throw new RangeError(`Cannot construct unsigned clarity integer greater than ${Mn}`);return{type:Bn.UInt,value:n}},Vn=t=>{if(t.byteLength>1048576)throw new Error("Cannot construct clarity buffer that is greater than 1MB");return{type:Bn.Buffer,value:d(t)}};var qn,zn;function Xn(t,e){return{type:qn.LengthPrefixedList,lengthPrefixBytes:e||4,values:t}}function Jn(t){if(65!=f(t).byteLength)throw Error("Invalid signature");return{type:qn.MessageSignature,data:t}}function Zn(t,e,n){const r=e||1,i=n||J;if(Cr(t,i))throw new Error(`String length exceeds maximum bytes ${i}`);return{type:qn.LengthPrefixedString,content:t,lengthPrefixBytes:r,maxLengthBytes:i}}function Yn(t){const e=(0,$n.ns)(t);return{type:qn.Address,version:e[0],hash160:e[1]}}function Qn(t,e){return{pubKeyEncoding:t,type:qn.TransactionAuthField,contents:e}}(zn=qn||(qn={}))[zn.Address=0]="Address",zn[zn.Principal=1]="Principal",zn[zn.LengthPrefixedString=2]="LengthPrefixedString",zn[zn.MemoString=3]="MemoString",zn[zn.Asset=4]="Asset",zn[zn.PostCondition=5]="PostCondition",zn[zn.PublicKey=6]="PublicKey",zn[zn.LengthPrefixedList=7]="LengthPrefixedList",zn[zn.Payload=8]="Payload",zn[zn.MessageSignature=9]="MessageSignature",zn[zn.StructuredDataSignature=10]="StructuredDataSignature",zn[zn.TransactionAuthField=11]="TransactionAuthField";class tr extends Rt{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,_t.hash(t);const n=kt(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<i.length;t++)i[t]^=54;this.iHash.update(i),this.oHash=t.create();for(let t=0;t<i.length;t++)i[t]^=106;this.oHash.update(i),i.fill(0)}update(t){return _t.exists(this),this.iHash.update(t),this}digestInto(t){_t.exists(this),_t.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return t.finished=r,t.destroyed=i,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const er=(t,e,n)=>new tr(t,e).update(n).digest();er.create=(t,e)=>new tr(t,e);const nr=32;function rr(t){if(t.length<2*nr*2+1)throw new Error("Invalid signature");const e=t.slice(0,2),n=t.slice(2,2+2*nr),r=t.slice(2+2*nr);return{recoveryId:a(e),r:n,s:r}}function ir(t){return t.slice(-2)+t.slice(0,-2)}function or(t){const e="string"==typeof t?f(t):t;if(32!=e.length&&33!=e.length)throw new Error(`Improperly formatted private-key. Private-key byte length should be 32 or 33. Length provided: ${e.length}`);if(33==e.length&&1!==e[32])throw new Error("Improperly formatted private-key. 33 bytes indicate compressed key, but the last byte must be == 01");return e}function sr(t){return t="string"==typeof t?f(t):t,{type:qn.PublicKey,data:t}}function ar(t){return"string"==typeof t?t:d(t)}Nn.hmacSha256Sync=(t,...e)=>{const n=er.create(ne,t);return e.forEach(t=>n.update(t)),n.digest()};const cr=ar;function ur(t){return 33===("string"==typeof t?t.length/2:t.byteLength)}function hr(t){return!cr(t).startsWith("04")}function dr(t){const e=ur(t=or(t));return d(function(t,e=!1){return Ze.fromPrivateKey(t).toRawBytes(e)}(t.slice(0,32),e))}function fr(t,e){t=or(t);const[n,r]=function(t,e,n={}){const{seed:r,m:i,d:o}=function(t,e,n){if(null==t)throw new Error(`sign: expected valid message hash, not "${t}"`);const r=fn(t),i=xn(e),o=[Tn(i),_n(r)];if(null!=n){!0===n&&(n=Nn.randomBytes(Le));const t=fn(n);if(t.length!==Le)throw new Error(`sign: Expected ${Le} bytes of extra data`);o.push(t)}return{seed:en(...o),m:In(r),d:i}}(t,e,n.extraEntropy),s=new An(Me,Ke);let a;for(s.reseedSync(r);!(a=vn(s.generateSync(),i,o,n.canonical));)s.reseedSync();return function(t,e){const{sig:n,recovery:r}=t,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},e),s=i?n.toDERRawBytes():n.toCompactRawBytes();return o?[s,r]:s}(a,n)}(e,t.slice(0,32),{canonical:!0,recovered:!0});if(null==r)throw new Error("No signature recoveryId received");return s(r,1)+tn.fromHex(n).toCompactHex()}function lr(t,e,n,r){if(0===r.length)throw Error("Invalid number of public keys");if(!(e!==ct.P2PKH&&e!==ct.P2WPKH||1===r.length&&1===n))throw Error("Invalid number of public keys or signatures");if((e===ct.P2WPKH||e===ct.P2WSH||e===ct.P2WSHNonSequential)&&!r.map(t=>t.data).every(hr))throw Error("Public keys must be compressed for segwit");switch(e){case ct.P2PKH:return pr(t,kr(r[0].data));case ct.P2WPKH:return pr(t,Rr(r[0].data));case ct.P2SH:case ct.P2SHNonSequential:return pr(t,Or(n,r.map(Zr)));case ct.P2WSH:case ct.P2WSHNonSequential:return pr(t,Nr(n,r.map(Zr)))}}function pr(t,e){return{type:qn.Address,version:t,hash160:e}}function gr(t){return(0,$n.bJ)(t.version,t.hash160)}function yr(t){const[e,n,r]=t.split(/\.|::/);var i,o,s;return i=e,o=n,s=r,{type:qn.Asset,address:Yn(i),contractName:Zn(o),assetName:Zn(s)}}function wr(t){if(t.includes(".")){const[e,n]=t.split(".");return function(t,e){const n=Yn(t),r=Zn(e);return{type:qn.Principal,prefix:ft.Contract,address:n,contractName:r}}(e,n)}return function(t){const e=Yn(t);return{type:qn.Principal,prefix:ft.Standard,address:e}}(t)}function br(t){if(t.includes(".")){const[e,n]=t.split(".");return function(t,e){return mr(Yn(t),Zn(e))}(e,n)}return function(t){const e=Yn(t);return{type:Bn.PrincipalStandard,value:gr(e)}}(t)}function mr(t,e){if(l(e.content).byteLength>=128)throw new Error("Contract name must be less than 128 bytes");return{type:Bn.PrincipalContract,value:`${gr(t)}.${e.content}`}}function Ar(){return{type:Bn.OptionalNone}}function Er(t){return{type:Bn.OptionalSome,value:t}}function Sr(t){for(const e in t)if(!Br(e))throw new Error(`"${e}" is not a valid Clarity name`);return{type:Bn.Tuple,value:t}}const vr=t=>({type:Bn.StringASCII,value:t});function xr(t){let n;if("string"==typeof t){const e="0x"===t.slice(0,2).toLowerCase();n=new X(f(e?t.slice(2):t))}else n=t instanceof Uint8Array?new X(t):t;switch(n.readUInt8Enum(Un,t=>{throw new L(`Cannot recognize Clarity Type: ${t}`)})){case Un.int:return(t=>{"string"==typeof t&&t.toLowerCase().startsWith("0x")&&(t=u(f(t))),E(t,Uint8Array)&&(t=u(t));const n=e(t);if(n>Gn)throw new RangeError(`Cannot construct clarity integer from value greater than ${Gn}`);if(n<Fn)throw new RangeError(`Cannot construct clarity integer form value less than ${Fn}`);return{type:Bn.Int,value:n}})(u(n.readBytes(16)));case Un.uint:return Wn(n.readBytes(16));case Un.buffer:const t=n.readUInt32BE();return Vn(n.readBytes(t));case Un.true:return{type:Bn.BoolTrue};case Un.false:return{type:Bn.BoolFalse};case Un.address:return s=Mr(n),{type:Bn.PrincipalStandard,value:gr(s)};case Un.contract:return mr(Mr(n),Fr(n));case Un.ok:return o=xr(n),{type:Bn.ResponseOk,value:o};case Un.err:return function(t){return{type:Bn.ResponseErr,value:t}}(xr(n));case Un.none:return Ar();case Un.some:return Er(xr(n));case Un.list:const a=n.readUInt32BE(),c=[];for(let t=0;t<a;t++)c.push(xr(n));return i=c,{type:Bn.List,value:i};case Un.tuple:const h=n.readUInt32BE(),d={};for(let t=0;t<h;t++){const t=Fr(n).content;if(void 0===t)throw new L('"content" is undefined');d[t]=xr(n)}return Sr(d);case Un.ascii:const l=n.readUInt32BE(),g=y(n.readBytes(l));return vr(g);case Un.utf8:const w=n.readUInt32BE(),b=p(n.readBytes(w));return r=b,{type:Bn.StringUTF8,value:r};default:throw new L("Unable to deserialize Clarity Value from Uint8Array. Could not find valid Clarity Type.")}var r,i,o,s}const Cr=(t,e)=>!!t&&l(t).length>e;function Ir(t){return Ln()(t)}function _r(t,e){const n=Ir(t);return delete n[e],n}const Tr=t=>zt(ne(t)),Pr=t=>d(Te(t)),kr=t=>d(Tr(t)),Rr=t=>{const e=Tr(t),n=m(new Uint8Array([0]),new Uint8Array([e.length]),e);return d(Tr(n))},Or=(t,e)=>{if(t>15||e.length>15)throw Error("P2SH multisig address can only contain up to 15 public keys");const n=[];n.push(80+t),e.forEach(t=>{n.push(t.length),n.push(t)}),n.push(80+e.length),n.push(174);const r=A(n);return d(Tr(r))},Nr=(t,e)=>{if(t>15||e.length>15)throw Error("P2WSH multisig address can only contain up to 15 public keys");const n=[];n.push(80+t),e.forEach(t=>{n.push(t.length),n.push(t)}),n.push(80+e.length),n.push(174);const r=A(n),i=ne(r),o=[];o.push(0),o.push(i.length),o.push(i);const s=A(o);return d(Tr(s))};function Br(t){return/^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/.test(t)&&t.length<128}const Ur=t=>{if(t.okay)return xr(t.result);throw new Error(t.cause)};function Hr(t,e){return A([Kn(t),e])}function $r(t,e){const n=[],r="ascii"==e?g(t.value):l(t.value),i=new Uint8Array(4);return W(i,r.length,0),n.push(i),n.push(r),Hr(t.type,A(n))}function Dr(t){switch(t.type){case Bn.BoolTrue:case Bn.BoolFalse:return function(t){return new Uint8Array([Kn(t.type)])}(t);case Bn.OptionalNone:case Bn.OptionalSome:return(e=t).type===Bn.OptionalNone?new Uint8Array([Kn(e.type)]):Hr(e.type,Dr(e.value));case Bn.Buffer:return function(t){const e=new Uint8Array(4);return W(e,Math.ceil(t.value.length/2),0),Hr(t.type,m(e,f(t.value)))}(t);case Bn.UInt:return function(t){const e=c(BigInt(t.value),Y);return Hr(t.type,e)}(t);case Bn.Int:return function(t){const e=c(function(t,e){if(t<-(BigInt(1)<<e-BigInt(1))||(BigInt(1)<<e-BigInt(1))-BigInt(1)<t)throw`Unable to represent integer in width: ${e}`;return t>=BigInt(0)?BigInt(t):t+(BigInt(1)<<e)}(BigInt(t.value),BigInt(Z)),Y);return Hr(t.type,e)}(t);case Bn.PrincipalStandard:return function(t){return Hr(t.type,Kr(Yn(t.value)))}(t);case Bn.PrincipalContract:return function(t){const[e,n]=function(t){const[e,n]=t.split(".");if(!e||!n)throw new Error(`Invalid contract identifier: ${t}`);return[e,n]}(t.value);return Hr(t.type,m(Kr(Yn(e)),Gr(Zn(n))))}(t);case Bn.ResponseOk:case Bn.ResponseErr:return function(t){return Hr(t.type,Dr(t.value))}(t);case Bn.List:return function(t){const e=[],n=new Uint8Array(4);W(n,t.value.length,0),e.push(n);for(const n of t.value){const t=Dr(n);e.push(t)}return Hr(t.type,A(e))}(t);case Bn.Tuple:return function(t){const e=[],n=new Uint8Array(4);W(n,Object.keys(t.value).length,0),e.push(n);const r=Object.keys(t.value).sort((t,e)=>t.localeCompare(e));for(const n of r){const r=Zn(n);e.push(Gr(r));const i=Dr(t.value[n]);e.push(i)}return Hr(t.type,A(e))}(t);case Bn.StringASCII:return function(t){return $r(t,"ascii")}(t);case Bn.StringUTF8:return function(t){return $r(t,"utf8")}(t);default:throw new D("Unable to serialize. Invalid Clarity Value.")}var e}function Lr(e){switch(e.type){case qn.Address:return Kr(e);case qn.Principal:return jr(e);case qn.LengthPrefixedString:return Gr(e);case qn.MemoString:return function(t){const e=[],n=l(t.content),r=(i=d(n),o=68,i.padEnd(o,"0"));var i,o;return e.push(f(r)),A(e)}(e);case qn.Asset:return Wr(e);case qn.PostCondition:return function(e){const n=[];if(n.push(e.conditionType),n.push(jr(e.principal)),e.conditionType!==st.Fungible&&e.conditionType!==st.NonFungible||n.push(Wr(e.asset)),e.conditionType===st.NonFungible&&n.push(Dr(e.assetName)),n.push(e.conditionCode),e.conditionType===st.STX||e.conditionType===st.Fungible){if(e.amount>BigInt("0xffffffffffffffff"))throw new D("The post-condition amount may not be larger than 8 bytes");n.push(t(e.amount,8))}return A(n)}(e);case qn.PublicKey:return Zr(e);case qn.LengthPrefixedList:return qr(e);case qn.Payload:return Xr(e);case qn.TransactionAuthField:return function(t){const e=[];switch(t.contents.type){case qn.PublicKey:e.push(t.pubKeyEncoding===ut.Compressed?gt.PublicKeyCompressed:gt.PublicKeyUncompressed),e.push(f((n=t.contents.data,Ze.fromHex(cr(n)).toHex(!0))));break;case qn.MessageSignature:e.push(t.pubKeyEncoding===ut.Compressed?gt.SignatureCompressed:gt.SignatureUncompressed),e.push(Jr(t.contents))}var n;return A(e)}(e);case qn.MessageSignature:return Jr(e)}}function Kr(t){const e=[];return e.push(f(s(t.version,1))),e.push(f(t.hash160)),A(e)}function Mr(t){const e=E(t,X)?t:new X(t),n=a(d(e.readBytes(1))),r=d(e.readBytes(20));return{type:qn.Address,version:n,hash160:r}}function jr(t){const e=[];return e.push(t.prefix),t.prefix!==ft.Standard&&t.prefix!==ft.Contract||e.push(Kr(t.address)),t.prefix===ft.Contract&&e.push(Gr(t.contractName)),A(e)}function Gr(t){const e=[],n=l(t.content),r=n.byteLength;return e.push(f(s(r,t.lengthPrefixBytes))),e.push(n),A(e)}function Fr(t,e,n){e=e||1;const r=E(t,X)?t:new X(t),i=a(d(r.readBytes(e)));return Zn(p(r.readBytes(i)),e,n??128)}function Wr(t){const e=[];return e.push(Kr(t.address)),e.push(Gr(t.contractName)),e.push(Gr(t.assetName)),A(e)}function Vr(t){const e=E(t,X)?t:new X(t);return{type:qn.Asset,address:Mr(e),contractName:Fr(e),assetName:Fr(e)}}function qr(t){const e=t.values,n=[];n.push(f(s(e.length,t.lengthPrefixBytes)));for(const t of e)n.push(Lr(t));return A(n)}function zr(t){const e=E(t,X)?t:new X(t),n=e.readUInt8Enum(st,t=>{throw new L(`Could not read ${t} as PostConditionType`)}),r=function(t){const e=E(t,X)?t:new X(t),n=e.readUInt8Enum(ft,t=>{throw new L(`Unexpected Principal payload type: ${t}`)});if(n===ft.Origin)return{type:qn.Principal,prefix:n};const r=Mr(e);if(n===ft.Standard)return{type:qn.Principal,prefix:n,address:r};const i=Fr(e);return{type:qn.Principal,prefix:n,address:r,contractName:i}}(e);let i,o,s;switch(n){case st.STX:return i=e.readUInt8Enum(ht,t=>{throw new L(`Could not read ${t} as FungibleConditionCode`)}),s=BigInt(`0x${d(e.readBytes(8))}`),{type:qn.PostCondition,conditionType:st.STX,principal:r,conditionCode:i,amount:s};case st.Fungible:return o=Vr(e),i=e.readUInt8Enum(ht,t=>{throw new L(`Could not read ${t} as FungibleConditionCode`)}),s=BigInt(`0x${d(e.readBytes(8))}`),{type:qn.PostCondition,conditionType:st.Fungible,principal:r,conditionCode:i,amount:s,asset:o};case st.NonFungible:o=Vr(e);const t=xr(e);return i=e.readUInt8Enum(dt,t=>{throw new L(`Could not read ${t} as FungibleConditionCode`)}),{type:qn.PostCondition,conditionType:st.NonFungible,principal:r,conditionCode:i,asset:o,assetName:t}}}function Xr(e){const n=[];switch(n.push(e.payloadType),e.payloadType){case Q.TokenTransfer:n.push(Dr(e.recipient)),n.push(t(e.amount,8)),n.push(Lr(e.memo));break;case Q.ContractCall:n.push(Lr(e.contractAddress)),n.push(Lr(e.contractName)),n.push(Lr(e.functionName));const r=new Uint8Array(4);W(r,e.functionArgs.length,0),n.push(r),e.functionArgs.forEach(t=>{n.push(Dr(t))});break;case Q.SmartContract:n.push(Lr(e.contractName)),n.push(Lr(e.codeBody));break;case Q.VersionedSmartContract:n.push(e.clarityVersion),n.push(Lr(e.contractName)),n.push(Lr(e.codeBody));break;case Q.PoisonMicroblock:break;case Q.Coinbase:n.push(e.coinbaseBytes);break;case Q.CoinbaseToAltRecipient:n.push(e.coinbaseBytes),n.push(Dr(e.recipient));break;case Q.NakamotoCoinbase:n.push(e.coinbaseBytes),n.push(Dr(e.recipient?Er(e.recipient):Ar())),n.push(e.vrfProof);break;case Q.TenureChange:n.push(f(e.tenureHash)),n.push(f(e.previousTenureHash)),n.push(f(e.burnViewHash)),n.push(f(e.previousTenureEnd)),n.push(W(new Uint8Array(4),e.previousTenureBlocks)),n.push(F(new Uint8Array(1),e.cause)),n.push(f(e.publicKeyHash))}return A(n)}function Jr(t){return f(t.data)}function Zr(t){return t.data.slice()}function Yr(){return{type:qn.MessageSignature,data:d(new Uint8Array(65))}}function Qr(t,n,r,i){const o=lr(0,t,1,[sr(n)]).hash160,s=hr(n)?ut.Compressed:ut.Uncompressed;return{hashMode:t,signer:o,nonce:e(r),fee:e(i),keyEncoding:s,signature:Yr()}}function ti(t){return"signature"in t}function ei(t){return t===ct.P2SH||t===ct.P2WSH}function ni(t){return t===ct.P2SHNonSequential||t===ct.P2WSHNonSequential}function ri(t){const e=Ir(t);return e.nonce=0,e.fee=0,ti(e)?e.signature=Yr():e.fields=[],{...e,nonce:BigInt(0),fee:BigInt(0)}}function ii(e){return ti(e)?function(e){return A([e.hashMode,f(e.signer),t(e.nonce,8),t(e.fee,8),e.keyEncoding,Jr(e.signature)])}(e):function(e){const n=[e.hashMode,f(e.signer),t(e.nonce,8),t(e.fee,8)],r=Xn(e.fields);n.push(qr(r));const i=new Uint8Array(2);return function(t,e,n=0){t[n+0]=e>>>8,t[n+1]=e>>>0}(i,e.signaturesRequired,0),n.push(i),A(n)}(e)}function oi(e,n,r,i){const o=e+d(new Uint8Array([n]))+d(t(r,8))+d(t(i,8));if(49!==f(o).byteLength)throw Error("Invalid signature hash length");return Pr(f(o))}function si(t,e,n){var r;const i=f(t+((r=(hr(e.data)?ut.Compressed:ut.Uncompressed).toString(16)).length%2?`0${r}`:r)+n);if(i.byteLength>98)throw Error("Invalid signature hash length");return Pr(i)}function ai(t,e,n,i,o,s){const a=oi(t,e,n,i),c=sr(function(t,e,n=ut.Compressed){const i=rr(e),o=new tn(r(i.r),r(i.s)),s=Ze.fromSignature(t,o,i.recoveryId),a=n===ut.Compressed;return s.toHex(a)}(a,s,o));return{pubKey:c,nextSigHash:si(a,c,s)}}function ci(t){return{authType:at.Standard,spendingCondition:t}}function ui(t,e){return{authType:at.Sponsored,spendingCondition:t,sponsorSpendingCondition:e||Qr(ct.P2PKH,"0".repeat(66),0,0)}}function hi(t){if(t.spendingCondition)switch(t.authType){case at.Standard:return ci(ri(t.spendingCondition));case at.Sponsored:return ui(ri(t.spendingCondition),function(){const t=Qr(ct.P2PKH,"",0,0);return t.signer=(qn.Address,T.MainnetSingleSig,"0".repeat(40)),t.keyEncoding=ut.Compressed,t.signature=Yr(),t}());default:throw new M("Unexpected authorization type for signing")}throw new Error("Authorization missing SpendingCondition")}class di{constructor({auth:t,payload:n,postConditions:r=Xn([]),postConditionMode:i=ot.Deny,transactionVersion:o,chainId:s,network:a="mainnet"}){a=U(a),this.transactionVersion=o??a.transactionVersion,this.chainId=s??a.chainId,this.auth=t,this.payload="amount"in n?{...n,amount:e(n.amount)}:n,this.postConditionMode=i,this.postConditions=r,this.anchorMode=et.Any}signBegin(){const t=Ir(this);return t.auth=hi(t.auth),t.txid()}verifyBegin(){const t=Ir(this);return t.auth=hi(t.auth),t.txid()}verifyOrigin(){return function(t,e){switch(t.authType){case at.Standard:case at.Sponsored:return function(t,e,n){return ti(t)?function(t,e,n){const{pubKey:r,nextSigHash:i}=ai(e,n,t.fee,t.nonce,t.keyEncoding,t.signature.data),o=lr(0,t.hashMode,1,[r]).hash160;if(o!==t.signer)throw new j(`Signer hash does not equal hash of public key(s): ${o} != ${t.signer}`);return i}(t,e,n):function(t,e,n){const r=[];let i=e,o=!1,s=0;for(const e of t.fields)switch(e.contents.type){case qn.PublicKey:hr(e.contents.data)||(o=!0),r.push(e.contents);break;case qn.MessageSignature:e.pubKeyEncoding===ut.Uncompressed&&(o=!0);const{pubKey:a,nextSigHash:c}=ai(i,n,t.fee,t.nonce,e.pubKeyEncoding,e.contents.data);if(ei(t.hashMode)&&(i=c),r.push(a),s+=1,65536===s)throw new j("Too many signatures")}if(ei(t.hashMode)&&s!==t.signaturesRequired||ni(t.hashMode)&&s<t.signaturesRequired)throw new j("Incorrect number of signatures");if(o&&(t.hashMode===ct.P2WSH||t.hashMode===ct.P2WSHNonSequential))throw new j("Uncompressed keys are not allowed in this hash mode");const a=lr(0,t.hashMode,t.signaturesRequired,r).hash160;if(a!==t.signer)throw new j(`Signer hash does not equal hash of public key(s): ${a} != ${t.signer}`);return i}(t,e,n)}(t.spendingCondition,e,at.Standard);default:throw new M("Invalid origin auth type")}}(this.auth,this.verifyBegin())}signNextOrigin(t,e){if(void 0===this.auth.spendingCondition)throw new Error('"auth.spendingCondition" is undefined');if(void 0===this.auth.authType)throw new Error('"auth.authType" is undefined');return this.signAndAppend(this.auth.spendingCondition,t,at.Standard,e)}signNextSponsor(t,e){if(this.auth.authType===at.Sponsored)return this.signAndAppend(this.auth.sponsorSpendingCondition,t,at.Sponsored,e);throw new Error('"auth.sponsorSpendingCondition" is undefined')}appendPubkey(t){const e="object"==typeof t&&"type"in t?t:sr(t),n=this.auth.spendingCondition;if(!n||ti(n))throw new Error("Can't append public key to a singlesig condition");{const t=hr(e.data);n.fields.push(Qn(t?ut.Compressed:ut.Uncompressed,e))}}signAndAppend(t,e,n,r){const{nextSig:i,nextSigHash:o}=function(t,e,n,r,i){const o=oi(t,e,n,r),s=fr(i,o);return{nextSig:s,nextSigHash:si(o,sr(dr(i)),s)}}(e,n,t.fee,t.nonce,r);if(ti(t))t.signature=Jn(i);else{const e=ur(r);t.fields.push(Qn(e?ut.Compressed:ut.Uncompressed,Jn(i)))}return o}txid(){const t=this.serializeBytes();return Pr(t)}setSponsor(t){if(this.auth.authType!=at.Sponsored)throw new M("Cannot sponsor sign a non-sponsored transaction");this.auth=function(t,n){return{...t,sponsorSpendingCondition:{...n,nonce:e(n.nonce),fee:e(n.fee)}}}(this.auth,t)}setFee(t){this.auth=function(t,n){switch(t.authType){case at.Standard:const r={...t.spendingCondition,fee:e(n)};return{...t,spendingCondition:r};case at.Sponsored:const i={...t.sponsorSpendingCondition,fee:e(n)};return{...t,sponsorSpendingCondition:i}}}(this.auth,t)}setNonce(t){this.auth=function(t,n){const r={...t.spendingCondition,nonce:e(n)};return{...t,spendingCondition:r}}(this.auth,t)}setSponsorNonce(t){if(this.auth.authType!=at.Sponsored)throw new M("Cannot sponsor sign a non-sponsored transaction");this.auth=function(t,n){const r={...t.sponsorSpendingCondition,nonce:e(n)};return{...t,sponsorSpendingCondition:r}}(this.auth,t)}serialize(){return d(this.serializeBytes())}serializeBytes(){if(void 0===this.transactionVersion)throw new D('"transactionVersion" is undefined');if(void 0===this.chainId)throw new D('"chainId" is undefined');if(void 0===this.auth)throw new D('"auth" is undefined');if(void 0===this.payload)throw new D('"payload" is undefined');const t=[];t.push(this.transactionVersion);const e=new Uint8Array(4);return W(e,this.chainId,0),t.push(e),t.push(function(t){const e=[];switch(e.push(t.authType),t.authType){case at.Standard:e.push(ii(t.spendingCondition));break;case at.Sponsored:e.push(ii(t.spendingCondition)),e.push(ii(t.sponsorSpendingCondition))}return A(e)}(this.auth)),t.push(this.anchorMode),t.push(this.postConditionMode),t.push(qr(this.postConditions)),t.push(Xr(this.payload)),A(t)}}function fi(t){return(e=t.transactionVersion,t=>t[e])({[_.Mainnet]:k,[_.Testnet]:R});var e}async function li({transaction:t,attachment:e,network:r,client:i}){const o=t.serialize(),s=e?"string"==typeof e?e:d(e):void 0,a=e?{tx:o,attachment:s}:{tx:o},c={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)},u=r??fi(t),h=Object.assign({},H(U(u)),i),f=`${h.baseUrl}/v2/transactions`,l=await h.fetch(f,c);if(!l.ok)try{return await l.json()}catch(t){throw Error("Failed to broadcast transaction (unable to parse node response).",{cause:t})}const p=await l.text(),g=p.replace(/["]+/g,"");if(64!==(y=n(y=g)).length||!/^[0-9a-fA-F]+$/.test(y))throw new Error(p);var y;return{txid:g}}async function pi({contractName:t,contractAddress:e,functionName:n,functionArgs:r,senderAddress:i,network:o="mainnet",client:s}){const a={sender:i,arguments:r.map(t=>`0x${d(Dr(t))}`)},c={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)},u=encodeURIComponent(n),h=Object.assign({},H(U(o)),s),f=`${h.baseUrl}/v2/contracts/call-read/${e}/${t}/${u}`,l=await h.fetch(f,c);if(!l.ok){const t=await l.text().catch(()=>"");throw new Error(`Error calling read-only function. Response ${l.status}: ${l.statusText}. Attempted to fetch ${f} and failed with the message: "${t}"`)}return await l.json().then(Ur)}function gi(t,e="hex"){switch(t.type){case Bn.BoolTrue:return"true";case Bn.BoolFalse:return"false";case Bn.Int:return t.value.toString();case Bn.UInt:return`u${t.value.toString()}`;case Bn.Buffer:if("tryAscii"===e){const e=y(f(t.value));if(/[ -~]/.test(e))return JSON.stringify(e)}return`0x${t.value}`;case Bn.OptionalNone:return"none";case Bn.OptionalSome:return`(some ${gi(t.value,e)})`;case Bn.ResponseErr:return`(err ${gi(t.value,e)})`;case Bn.ResponseOk:return`(ok ${gi(t.value,e)})`;case Bn.PrincipalStandard:case Bn.PrincipalContract:return t.value;case Bn.List:return`(list ${t.value.map(t=>gi(t,e)).join(" ")})`;case Bn.Tuple:return`(tuple ${Object.keys(t.value).map(n=>`(${n} ${gi(t.value[n],e)})`).join(" ")})`;case Bn.StringASCII:return`"${t.value}"`;case Bn.StringUTF8:return`u"${t.value}"`}}function yi(t){switch(t.type){case Bn.BoolTrue:case Bn.BoolFalse:return"bool";case Bn.Int:return"int";case Bn.UInt:return"uint";case Bn.Buffer:return`(buff ${Math.ceil(t.value.length/2)})`;case Bn.OptionalNone:return"(optional none)";case Bn.OptionalSome:return`(optional ${yi(t.value)})`;case Bn.ResponseErr:return`(response UnknownType ${yi(t.value)})`;case Bn.ResponseOk:return`(response ${yi(t.value)} UnknownType)`;case Bn.PrincipalStandard:case Bn.PrincipalContract:return"principal";case Bn.List:return`(list ${t.value.length} ${t.value.length?yi(t.value[0]):"UnknownType"})`;case Bn.Tuple:return`(tuple ${Object.keys(t.value).map(e=>`(${e} ${yi(t.value[e])})`).join(" ")})`;case Bn.StringASCII:return`(string-ascii ${g(t.value).length})`;case Bn.StringUTF8:return`(string-utf8 ${l(t.value).length})`}}var wi;!function(t){t[t.ClarityAbiTypeUInt128=1]="ClarityAbiTypeUInt128",t[t.ClarityAbiTypeInt128=2]="ClarityAbiTypeInt128",t[t.ClarityAbiTypeBool=3]="ClarityAbiTypeBool",t[t.ClarityAbiTypePrincipal=4]="ClarityAbiTypePrincipal",t[t.ClarityAbiTypeNone=5]="ClarityAbiTypeNone",t[t.ClarityAbiTypeBuffer=6]="ClarityAbiTypeBuffer",t[t.ClarityAbiTypeResponse=7]="ClarityAbiTypeResponse",t[t.ClarityAbiTypeOptional=8]="ClarityAbiTypeOptional",t[t.ClarityAbiTypeTuple=9]="ClarityAbiTypeTuple",t[t.ClarityAbiTypeList=10]="ClarityAbiTypeList",t[t.ClarityAbiTypeStringAscii=11]="ClarityAbiTypeStringAscii",t[t.ClarityAbiTypeStringUtf8=12]="ClarityAbiTypeStringUtf8",t[t.ClarityAbiTypeTraitReference=13]="ClarityAbiTypeTraitReference"}(wi||(wi={}));const bi=t=>"string"==typeof t,mi=t=>void 0!==t.buffer,Ai=t=>void 0!==t["string-ascii"],Ei=t=>void 0!==t["string-utf8"],Si=t=>void 0!==t.response,vi=t=>void 0!==t.optional,xi=t=>void 0!==t.tuple,Ci=t=>void 0!==t.list;function Ii(t){if(bi(t))return"int128"===t?"int":"uint128"===t?"uint":t;if(mi(t))return`(buff ${t.buffer.length})`;if(Ai(t))return`(string-ascii ${t["string-ascii"].length})`;if(Ei(t))return`(string-utf8 ${t["string-utf8"].length})`;if(Si(t))return`(response ${Ii(t.response.ok)} ${Ii(t.response.error)})`;if(vi(t))return`(optional ${Ii(t.optional)})`;if(xi(t))return`(tuple ${t.tuple.map(t=>`(${t.name} ${Ii(t.type)})`).join(" ")})`;if(Ci(t))return`(list ${t.list.length} ${Ii(t.list.type)})`;throw new Error(`Type string unsupported for Clarity type: ${JSON.stringify(t)}`)}function _i(t,e){const n=function(t){if(bi(t)){if("uint128"===t)return{id:wi.ClarityAbiTypeUInt128,type:t};if("int128"===t)return{id:wi.ClarityAbiTypeInt128,type:t};if("bool"===t)return{id:wi.ClarityAbiTypeBool,type:t};if("principal"===t)return{id:wi.ClarityAbiTypePrincipal,type:t};if("trait_reference"===t)return{id:wi.ClarityAbiTypeTraitReference,type:t};if("none"===t)return{id:wi.ClarityAbiTypeNone,type:t};throw new Error(`Unexpected Clarity ABI type primitive: ${JSON.stringify(t)}`)}if(mi(t))return{id:wi.ClarityAbiTypeBuffer,type:t};if(Si(t))return{id:wi.ClarityAbiTypeResponse,type:t};if(vi(t))return{id:wi.ClarityAbiTypeOptional,type:t};if(xi(t))return{id:wi.ClarityAbiTypeTuple,type:t};if(Ci(t))return{id:wi.ClarityAbiTypeList,type:t};if(Ai(t))return{id:wi.ClarityAbiTypeStringAscii,type:t};if(Ei(t))return{id:wi.ClarityAbiTypeStringUtf8,type:t};throw new Error(`Unexpected Clarity ABI type: ${JSON.stringify(t)}`)}(e);switch(t.type){case Bn.BoolTrue:case Bn.BoolFalse:return n.id===wi.ClarityAbiTypeBool;case Bn.Int:return n.id===wi.ClarityAbiTypeInt128;case Bn.UInt:return n.id===wi.ClarityAbiTypeUInt128;case Bn.Buffer:return n.id===wi.ClarityAbiTypeBuffer&&n.type.buffer.length>=Math.ceil(t.value.length/2);case Bn.StringASCII:return n.id===wi.ClarityAbiTypeStringAscii&&n.type["string-ascii"].length>=t.value.length;case Bn.StringUTF8:return n.id===wi.ClarityAbiTypeStringUtf8&&n.type["string-utf8"].length>=t.value.length;case Bn.OptionalNone:return n.id===wi.ClarityAbiTypeNone||n.id===wi.ClarityAbiTypeOptional;case Bn.OptionalSome:return n.id===wi.ClarityAbiTypeOptional&&_i(t.value,n.type.optional);case Bn.ResponseErr:return n.id===wi.ClarityAbiTypeResponse&&_i(t.value,n.type.response.error);case Bn.ResponseOk:return n.id===wi.ClarityAbiTypeResponse&&_i(t.value,n.type.response.ok);case Bn.PrincipalContract:return n.id===wi.ClarityAbiTypePrincipal||n.id===wi.ClarityAbiTypeTraitReference;case Bn.PrincipalStandard:return n.id===wi.ClarityAbiTypePrincipal;case Bn.List:return n.id==wi.ClarityAbiTypeList&&n.type.list.length>=t.value.length&&t.value.every(t=>_i(t,n.type.list.type));case Bn.Tuple:if(n.id==wi.ClarityAbiTypeTuple){const e=Ir(t.value);for(let t=0;t<n.type.tuple.length;t++){const r=n.type.tuple[t],i=r.name,o=e[i];if(!o)return!1;if(!_i(o,r.type))return!1;delete e[i]}return!0}return!1;default:return!1}}const Ti=BigInt("18446744073709551615");function Pi(t){const n=e(t);if(n<0n||n>Ti)throw new RangeError(`Post-condition amount must be between 0 and ${Ti} (u64 max), received: ${n}`);return n}var ki;function Ri(t){return ki[t]}!function(t){t[t.eq=1]="eq",t[t.gt=2]="gt",t[t.lt=4]="lt",t[t.gte=3]="gte",t[t.lte=5]="lte",t[t.sent=16]="sent",t[t["not-sent"]=17]="not-sent",t[t["maybe-sent"]=18]="maybe-sent"}(ki||(ki={}));class Oi{constructor(t){this.transaction=t,this.sigHash=t.signBegin(),this.originDone=!1,this.checkOversign=!0,this.checkOverlap=!0;const e=t.auth.spendingCondition;if(e&&!ti(e)){if(e.fields.filter(t=>t.contents.type===qn.MessageSignature).length>=e.signaturesRequired)throw new Error("SpendingCondition has more signatures than are expected");e.fields.forEach(n=>{if(n.contents.type!==qn.MessageSignature)return;const r=n.contents,i=ai(this.sigHash,t.auth.authType,e.fee,e.nonce,ut.Compressed,r.data);ni(e.hashMode)||(this.sigHash=i.nextSigHash)})}}static createSponsorSigner(t,e){if(t.auth.authType!=at.Sponsored)throw new M("Cannot add sponsor to non-sponsored transaction");const n=Ir(t);n.setSponsor(e);const r=n.verifyOrigin(),i=new this(n);return i.originDone=!0,i.sigHash=r,i.checkOversign=!0,i.checkOverlap=!0,i}signOrigin(t){if(this.checkOverlap&&this.originDone)throw new M("Cannot sign origin after sponsor key");if(void 0===this.transaction.auth)throw new M('"transaction.auth" is undefined');if(void 0===this.transaction.auth.spendingCondition)throw new M('"transaction.auth.spendingCondition" is undefined');const e=this.transaction.auth.spendingCondition;if((e.hashMode===ct.P2SH||e.hashMode===ct.P2WSH)&&this.checkOversign&&e.fields.filter(t=>t.contents.type===qn.MessageSignature).length>=e.signaturesRequired)throw new Error("Origin would have too many signatures");const n=this.transaction.signNextOrigin(this.sigHash,t);(ti(this.transaction.auth.spendingCondition)||ei(this.transaction.auth.spendingCondition.hashMode))&&(this.sigHash=n)}appendOrigin(t){const e="object"==typeof t&&"type"in t?t:sr(t);if(this.checkOverlap&&this.originDone)throw Error("Cannot append public key to origin after sponsor key");if(void 0===this.transaction.auth)throw new Error('"transaction.auth" is undefined');if(void 0===this.transaction.auth.spendingCondition)throw new Error('"transaction.auth.spendingCondition" is undefined');this.transaction.appendPubkey(e)}signSponsor(t){if(void 0===this.transaction.auth)throw new M('"transaction.auth" is undefined');if(this.transaction.auth.authType!==at.Sponsored)throw new M('"transaction.auth.authType" is not AuthType.Sponsored');const e=this.transaction.signNextSponsor(this.sigHash,t);this.sigHash=e,this.originDone=!0}getTxInComplete(){return Ir(this.transaction)}resume(t){this.transaction=Ir(t),this.sigHash=t.signBegin()}}async function Ni(t){const n={fee:BigInt(0),nonce:BigInt(0),network:k,postConditionMode:ot.Deny,sponsored:!1},r=Object.assign(n,t);r.network=U(r.network),r.client=Object.assign({},H(r.network),r.client),r.postConditionMode=function(t){if("number"==typeof t)return t;if("allow"===t)return ot.Allow;if("deny"===t)return ot.Deny;if("originator"===t)return ot.Originator;throw new Error(`Invalid post condition mode: ${t}`)}(r.postConditionMode);const i=(o=r.contractAddress,s=r.contractName,a=r.functionName,c=r.functionArgs,"string"==typeof s&&(s=Zn(s)),"string"==typeof a&&(a=Zn(a)),{type:qn.Payload,payloadType:Q.ContractCall,contractAddress:"string"==typeof o?Yn(o):o,contractName:s,functionName:a,functionArgs:c});var o,s,a,c;if(r?.validateWithAbi){let t;if("boolean"==typeof r.validateWithAbi){if(!r?.network)throw new Error("Network option must be provided in order to validate with ABI");t=await async function({contractAddress:t,contractName:e,network:n="mainnet",client:r}){const i=Object.assign({},H(U(n)),r),o=`${i.baseUrl}/v2/contracts/interface/${t}/${e}`,s=await i.fetch(o);if(!s.ok){const n=await s.text().catch(()=>"");throw new Error(`Error fetching contract ABI for contract "${e}" at address ${t}. Response ${s.status}: ${s.statusText}. Attempted to fetch ${o} and failed with the message: "${n}"`)}return JSON.parse(await s.text())}({...r})}else t=r.validateWithAbi;!function(t,e){const n=e.functions.filter(e=>e.name===t.functionName.content);if(1===n.length){const e=n[0].args;if(t.functionArgs.length!==e.length)throw new Error(`Clarity function expects ${e.length} argument(s) but received ${t.functionArgs.length}`);for(let n=0;n<t.functionArgs.length;n++){const r=t.functionArgs[n],i=e[n];if(!_i(r,i.type)){const e=n+1;throw new Error(`Clarity function \`${t.functionName.content}\` expects argument ${e} to be of type ${Ii(i.type)}, not ${yi(r)}`)}}return!0}throw 0===n.length?new Error(`ABI doesn't contain a function with the name ${t.functionName.content}`):new Error(`Malformed ABI. Contains multiple functions with the name ${t.functionName.content}`)}(i,t)}let u=null;if("publicKey"in r)u=Qr(ct.P2PKH,r.publicKey,r.nonce,r.fee);else{const t=r.useNonSequentialMultiSig?ct.P2SHNonSequential:ct.P2SH,n=r.address?Ui(r.publicKeys.map(cr),r.numSignatures,t,Yn(r.address).hash160):r.publicKeys.map(cr);u=function(t,n,r,i,o){return{hashMode:t,signer:lr(0,t,n,r.map(sr)).hash160,nonce:e(i),fee:e(o),fields:[],signaturesRequired:n}}(t,r.numSignatures,n,r.nonce,r.fee)}const h=r.sponsored?ui(u):ci(u),f=Xn((r.postConditions??[]).map(t=>"string"==typeof t?zr(t):"string"==typeof t.type?function(t){switch(t.type){case"stx-postcondition":return{type:qn.PostCondition,conditionType:st.STX,principal:"origin"===t.address?{type:qn.Principal,prefix:ft.Origin}:wr(t.address),conditionCode:Ri(t.condition),amount:Pi(t.amount)};case"ft-postcondition":return{type:qn.PostCondition,conditionType:st.Fungible,principal:"origin"===t.address?{type:qn.Principal,prefix:ft.Origin}:wr(t.address),conditionCode:Ri(t.condition),amount:Pi(t.amount),asset:yr(t.asset)};case"nft-postcondition":return{type:qn.PostCondition,conditionType:st.NonFungible,principal:"origin"===t.address?{type:qn.Principal,prefix:ft.Origin}:wr(t.address),conditionCode:Ri(t.condition),asset:yr(t.asset),assetName:t.assetId};default:throw new Error("Invalid post condition type")}}(t):t)),l=new di({transactionVersion:r.network.transactionVersion,chainId:r.network.chainId,auth:h,payload:i,postConditions:f,postConditionMode:r.postConditionMode});if(void 0===t.fee||null===t.fee){const t=await async function({transaction:t,network:e,client:n}){const r=e??fi(t),i=Object.assign({},H(U(r)),n);try{const e=function(t){const e=t.auth.spendingCondition.hashMode;if([ct.P2SH,ct.P2WSH].includes(e)){const e=t.auth.spendingCondition,n=e.fields.filter(t=>t.contents.type===qn.MessageSignature).length,r=66*(e.signaturesRequired-n);return t.serializeBytes().byteLength+r}return t.serializeBytes().byteLength}(t);return(await async function({payload:t,estimatedLength:e,network:n="mainnet",client:r}){const i={transaction_payload:t,estimated_len:e},o={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)},s=Object.assign({},H(U(n)),r),a=`${s.baseUrl}/v2/fees/transaction`,c=await s.fetch(a,o);if(!c.ok){const t=await c.text().catch(()=>"");if(t.includes("NoEstimateAvailable")){let e={};try{e=JSON.parse(t)}catch(t){}throw new K(e?.reason_data?.message??"")}throw new Error(`Error estimating transaction fee. Response ${c.status}: ${c.statusText}. Attempted to fetch ${a} and failed with the message: "${t}"`)}return(await c.json()).estimations}({payload:d(Xr(t.payload)),estimatedLength:e,network:r,client:i}))[1].fee}catch(e){if(!(e instanceof K))throw e;return await async function({transaction:t,network:e,client:n}){const r="number"==typeof t?"mainnet":e??fi(t),i=Object.assign({},H(U(r)),n),o=`${i.baseUrl}/v2/fees/transfer`,s=await i.fetch(o,{headers:{Accept:"application/text"}});if(!s.ok){const t=await s.text().catch(()=>"");throw new Error(`Error estimating transfer fee. Response ${s.status}: ${s.statusText}. Attempted to fetch ${o} and failed with the message: "${t}"`)}const a=await s.text(),c="number"==typeof t?BigInt(t):BigInt(Math.ceil(t.serializeBytes().byteLength));return BigInt(a)*c}({transaction:t,network:r})}}({transaction:l,...r});l.setFee(t)}if(void 0===t.nonce||null===t.nonce){const t=r.network.addressVersion.singleSig,e=(0,$n.bJ)(t,l.auth.spendingCondition.signer),n=await async function(t){try{return await async function({address:t,network:e="mainnet",client:n}){const r=Object.assign({},H(U(e)),n),i=`${r.baseUrl}/extended/v1/address/${t}/nonces`,o=await r.fetch(i),s=await o.json();return BigInt(s.possible_next_nonce)}(t)}catch(t){}const e=U(t.network??"mainnet"),n=Object.assign({},H(e),t.client),r=`${n.baseUrl}/v2/accounts/${t.address}?proof=0`,i=await n.fetch(r);if(!i.ok){const t=await i.text().catch(()=>"");throw new Error(`Error fetching nonce. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${t}"`)}const o=await i.json();return BigInt(o.nonce)}({address:e,...r});l.setNonce(n)}return l}async function Bi(t){if("senderKey"in t){const e=dr(t.senderKey),n=_r(t,"senderKey"),r=await Ni({publicKey:e,...n}),i=t.senderKey;return new Oi(r).signOrigin(i),r}{const e=_r(t,"signerKeys"),n=await Ni(e);return function(t,e,n,r){if(ti(t.auth.spendingCondition))throw new Error("Transaction is not a multi-sig transaction");const i=new Oi(t),o=r?Ui(e,t.auth.spendingCondition.signaturesRequired,t.auth.spendingCondition.hashMode,Yn(r).hash160):e;for(const t of o){const e=n.find(e=>dr(e)===t);e?i.signOrigin(e):i.appendOrigin(t)}}(n,t.publicKeys.map(cr).slice(),t.signerKeys.map(ar),t.address),n}}function Ui(t,e,n,r){if(lr(0,n,e,t.map(sr)).hash160===r)return t;const i=t.slice().sort();if(lr(0,n,e,i.map(sr)).hash160===r)return i;throw new Error("Failed to find matching multi-sig address given public-keys.")}var Hi=(t=>(t[t.P2PKH=0]="P2PKH",t[t.P2SH=1]="P2SH",t[t.P2SHP2WPKH=2]="P2SHP2WPKH",t[t.P2SHP2WSH=3]="P2SHP2WSH",t[t.P2WPKH=4]="P2WPKH",t[t.P2WSH=5]="P2WSH",t[t.P2TR=6]="P2TR",t))(Hi||{});const $i={mainnet:{P2PKH:0,P2SH:5},testnet:{P2PKH:111,P2SH:196},devnet:{P2PKH:111,P2SH:196},mocknet:{P2PKH:111,P2SH:196}},Di=/^(1|3|m|n|2)/,Li=/^(bc1q|tb1q|bcrt1q)/i,Ki=/^(bc1p|tb1p|bcrt1p)/i,Mi={mainnet:"bc",testnet:"tb",devnet:"bcrt",mocknet:"bcrt"},ji=/^(bc|tb)/i,Gi=0,Fi=1;var Wi=(t=>(t.Period1="Period1",t.Period2a="Period2a",t.Period2b="Period2b",t.Period3="Period3",t))(Wi||{}),Vi=(t=>(t[t.ERR_STACKING_UNREACHABLE=255]="ERR_STACKING_UNREACHABLE",t[t.ERR_STACKING_CORRUPTED_STATE=254]="ERR_STACKING_CORRUPTED_STATE",t[t.ERR_STACKING_INSUFFICIENT_FUNDS=1]="ERR_STACKING_INSUFFICIENT_FUNDS",t[t.ERR_STACKING_INVALID_LOCK_PERIOD=2]="ERR_STACKING_INVALID_LOCK_PERIOD",t[t.ERR_STACKING_ALREADY_STACKED=3]="ERR_STACKING_ALREADY_STACKED",t[t.ERR_STACKING_NO_SUCH_PRINCIPAL=4]="ERR_STACKING_NO_SUCH_PRINCIPAL",t[t.ERR_STACKING_EXPIRED=5]="ERR_STACKING_EXPIRED",t[t.ERR_STACKING_STX_LOCKED=6]="ERR_STACKING_STX_LOCKED",t[t.ERR_STACKING_PERMISSION_DENIED=9]="ERR_STACKING_PERMISSION_DENIED",t[t.ERR_STACKING_THRESHOLD_NOT_MET=11]="ERR_STACKING_THRESHOLD_NOT_MET",t[t.ERR_STACKING_POX_ADDRESS_IN_USE=12]="ERR_STACKING_POX_ADDRESS_IN_USE",t[t.ERR_STACKING_INVALID_POX_ADDRESS=13]="ERR_STACKING_INVALID_POX_ADDRESS",t[t.ERR_STACKING_ALREADY_REJECTED=17]="ERR_STACKING_ALREADY_REJECTED",t[t.ERR_STACKING_INVALID_AMOUNT=18]="ERR_STACKING_INVALID_AMOUNT",t[t.ERR_NOT_ALLOWED=19]="ERR_NOT_ALLOWED",t[t.ERR_STACKING_ALREADY_DELEGATED=20]="ERR_STACKING_ALREADY_DELEGATED",t[t.ERR_DELEGATION_EXPIRES_DURING_LOCK=21]="ERR_DELEGATION_EXPIRES_DURING_LOCK",t[t.ERR_DELEGATION_TOO_MUCH_LOCKED=22]="ERR_DELEGATION_TOO_MUCH_LOCKED",t[t.ERR_DELEGATION_POX_ADDR_REQUIRED=23]="ERR_DELEGATION_POX_ADDR_REQUIRED",t[t.ERR_INVALID_START_BURN_HEIGHT=24]="ERR_INVALID_START_BURN_HEIGHT",t[t.ERR_NOT_CURRENT_STACKER=25]="ERR_NOT_CURRENT_STACKER",t[t.ERR_STACK_EXTEND_NOT_LOCKED=26]="ERR_STACK_EXTEND_NOT_LOCKED",t[t.ERR_STACK_INCREASE_NOT_LOCKED=27]="ERR_STACK_INCREASE_NOT_LOCKED",t[t.ERR_DELEGATION_NO_REWARD_SLOT=28]="ERR_DELEGATION_NO_REWARD_SLOT",t[t.ERR_DELEGATION_WRONG_REWARD_SLOT=29]="ERR_DELEGATION_WRONG_REWARD_SLOT",t[t.ERR_STACKING_IS_DELEGATED=30]="ERR_STACKING_IS_DELEGATED",t[t.ERR_STACKING_NOT_DELEGATED=31]="ERR_STACKING_NOT_DELEGATED",t))(Vi||{});function qi(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function zi(...t){const e=(t,e)=>n=>t(e(n));return{encode:Array.from(t).reverse().reduce((t,n)=>t?e(t,n.encode):n.encode,void 0),decode:t.reduce((t,n)=>t?e(t,n.decode):n.decode,void 0)}}function Xi(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("alphabet.encode input should be an array of numbers");return e.map(e=>{if(qi(e),e<0||e>=t.length)throw new Error(`Digit index outside alphabet: ${e} (alphabet: ${t.length})`);return t[e]})},decode:e=>{if(!Array.isArray(e)||e.length&&"string"!=typeof e[0])throw new Error("alphabet.decode input should be array of strings");return e.map(e=>{if("string"!=typeof e)throw new Error(`alphabet.decode: not string element=${e}`);const n=t.indexOf(e);if(-1===n)throw new Error(`Unknown letter: "${e}". Allowed: ${t}`);return n})}}}function Ji(t=""){if("string"!=typeof t)throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&"string"!=typeof e[0])throw new Error("join.encode input should be array of strings");for(let t of e)if("string"!=typeof t)throw new Error(`join.encode: non-string input=${t}`);return e.join(t)},decode:e=>{if("string"!=typeof e)throw new Error("join.decode input should be string");return e.split(t)}}}function Zi(t,e="="){if(qi(t),"string"!=typeof e)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let t of n)if("string"!=typeof t)throw new Error(`padding.encode: non-string input=${t}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let t of n)if("string"!=typeof t)throw new Error(`padding.decode: non-string input=${t}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function Yi(t){if("function"!=typeof t)throw new Error("normalize fn should be function");return{encode:t=>t,decode:e=>t(e)}}function Qi(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const i=[],o=Array.from(t);for(o.forEach(t=>{if(qi(t),t<0||t>=e)throw new Error(`Wrong integer: ${t}`)});;){let t=0,s=!0;for(let i=r;i<o.length;i++){const a=o[i],c=e*t+a;if(!Number.isSafeInteger(c)||e*t/e!==t||c-a!==e*t)throw new Error("convertRadix: carry overflow");if(t=c%n,o[i]=Math.floor(c/n),!Number.isSafeInteger(o[i])||o[i]*n+t!==c)throw new Error("convertRadix: carry overflow");s&&(o[i]?s=!1:r=i)}if(i.push(t),s)break}for(let e=0;e<t.length-1&&0===t[e];e++)i.push(0);return i.reverse()}const to=(t,e)=>e?to(e,t%e):t,eo=(t,e)=>t+(e-to(t,e));function no(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(eo(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${eo(e,n)}`);let i=0,o=0;const s=2**n-1,a=[];for(const r of t){if(qi(r),r>=2**e)throw new Error(`convertRadix2: invalid data word=${r} from=${e}`);if(i=i<<e|r,o+e>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${e}`);for(o+=e;o>=n;o-=n)a.push((i>>o-n&s)>>>0);i&=2**o-1}if(i=i<<n-o&s,!r&&o>=e)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&a.push(i>>>0),a}function ro(t,e=!1){if(qi(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(eo(8,t)>32||eo(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return no(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(no(n,t,8,e))}}}function io(t){if("function"!=typeof t)throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch(t){}}}zi(ro(4),Xi("0123456789ABCDEF"),Ji("")),zi(ro(5),Xi("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Zi(5),Ji("")),zi(ro(5),Xi("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Zi(5),Ji("")),zi(ro(5),Xi("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Ji(""),Yi(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),zi(ro(6),Xi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Zi(6),Ji("")),zi(ro(6),Xi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Zi(6),Ji(""));const oo=t=>{return zi((qi(e=58),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Qi(Array.from(t),256,e)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(Qi(t,e,256))}}),Xi(t),Ji(""));var e},so=(oo("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),oo("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),oo("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),zi(Xi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Ji(""))),ao=[996825010,642813549,513874426,1027748829,705979059];function co(t){const e=t>>25;let n=(33554431&t)<<5;for(let t=0;t<ao.length;t++)1==(e>>t&1)&&(n^=ao[t]);return n}function uo(t,e,n=1){const r=t.length;let i=1;for(let e=0;e<r;e++){const n=t.charCodeAt(e);if(n<33||n>126)throw new Error(`Invalid prefix (${t})`);i=co(i)^n>>5}i=co(i);for(let e=0;e<r;e++)i=co(i)^31&t.charCodeAt(e);for(let t of e)i=co(i)^t;for(let t=0;t<6;t++)i=co(i);return i^=n,so.encode(no([i%2**30],30,5,!1))}function ho(t){const e="bech32"===t?1:734539939,n=ro(5),r=n.decode,i=n.encode,o=io(r);function s(t,n=90){if("string"!=typeof t)throw new Error("bech32.decode input should be string, not "+typeof t);if(t.length<8||!1!==n&&t.length>n)throw new TypeError(`Wrong string length: ${t.length} (${t}). Expected (8..${n})`);const r=t.toLowerCase();if(t!==r&&t!==t.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=(t=r).lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const o=t.slice(0,i),s=t.slice(i+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=so.decode(s).slice(0,-6),c=uo(o,a,e);if(!s.endsWith(c))throw new Error(`Invalid checksum in ${t}: expected "${c}"`);return{prefix:o,words:a}}return{encode:function(t,n,r=90){if("string"!=typeof t)throw new Error("bech32.encode prefix should be string, not "+typeof t);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const i=t.length+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);return`${t=t.toLowerCase()}1${so.encode(n)}${uo(t,n,e)}`},decode:s,decodeToBytes:function(t){const{prefix:e,words:n}=s(t,!1);return{prefix:e,words:n,bytes:r(n)}},decodeUnsafe:io(s),fromWords:r,fromWordsUnsafe:o,toWords:i}}const fo=ho("bech32"),lo=ho("bech32m");zi(ro(4),Xi("0123456789abcdef"),Ji(""),Yi(t=>{if("string"!=typeof t||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var po=i(216),go=i.n(po);Nn.hmacSha256Sync=(t,...e)=>{const n=er.create(ne,t);return e.forEach(t=>n.update(t)),n.digest()},i(991);const yo=9007199254740991;function wo(t){if(t<0||t>yo||t%1!=0)throw new RangeError("value out of range")}const bo="Stacks Signed Message:\n";function mo(t,e=bo){const n="string"==typeof t?l(t):t,r=function(t,e,n=0){return wo(t),e||(e=new Uint8Array(function(t){return wo(t),t<253?1:t<=65535?3:t<=4294967295?5:9}(t))),t<253?F(e,t,n):t<=65535?(F(e,253,n),function(t,e,n=0){t[n+0]=255&e,e>>>=8,t[n+1]=255&e}(e,t,n+1)):t<=4294967295?(F(e,254,n),V(e,t,n+1)):(F(e,255,n),V(e,t>>>0,n+1),V(e,t/4294967296|0,n+5)),e}(n.length);return m(l(e),r,n)}var Ao;Nn.hmacSha256Sync=(t,...e)=>{const n=er.create(ne,t);return e.forEach(t=>n.update(t)),n.digest()},function(t){t.InvalidFormat="InvalidFormat",t.IsNotPoint="IsNotPoint"}(Ao||(Ao={}));const Eo=new Uint8Array([83,73,80,48,49,56]);function So(t){return ne(Dr(t))}function vo({message:t,domain:e}){const n=So(t);if((r=e).type!==Bn.Tuple||!["name","version","chain-id"].every(t=>t in r.value)||!["name","version"].every(t=>r.value[t].type===Bn.StringASCII)||r.value["chain-id"].type!==Bn.UInt)throw new Error("domain parameter must be a valid domain of type TupleCV with keys 'name', 'version', 'chain-id' with respective types StringASCII, StringASCII, UInt");var r;const i=So(e);return m(Eo,i,n)}var xo=Object.defineProperty,Co=Object.defineProperties,Io=Object.getOwnPropertyDescriptors,_o=Object.getOwnPropertySymbols,To=Object.prototype.hasOwnProperty,Po=Object.prototype.propertyIsEnumerable,ko=(t,e,n)=>e in t?xo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ro=(t,e)=>{for(var n in e||(e={}))To.call(e,n)&&ko(t,n,e[n]);if(_o)for(var n of _o(e))Po.call(e,n)&&ko(t,n,e[n]);return t},Oo=(t,e)=>Co(t,Io(e));class No extends Error{constructor(t,e){const n=`'${t}' is not a valid P2PKH/P2SH/P2WPKH/P2WSH/P2TR address`;super(n),this.message=n,this.name=this.constructor.name,this.innerError=e,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}function Bo(t){switch(t){case $i.mainnet.P2PKH:case $i.testnet.P2PKH:return Hi.P2PKH;case $i.mainnet.P2SH:case $i.testnet.P2SH:return Hi.P2SH;default:throw new Error("Invalid pox address version")}}function Uo(t){const{version:e,data:n}=Ho(t);return{version:e,data:d(n)}}function Ho(t){try{if(Di.test(t)){const e=function(t){const e=go().decode(t),n=e.slice(0,-4),r=e.slice(-4),i=ne(ne(n));if(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3])throw new Error("Invalid checksum");if(21!==n.length)throw new TypeError("Invalid address length");return{version:G(n,0),hash:n.slice(1)}}(t);return{version:Bo(e.version),data:e.hash}}if(ji.test(t)){const e=function(t){if(Li.test(t))return function(t){const{words:e}=fo.decode(t),n=e[0];if(n>0)throw new Error("Addresses with a witness version >= 1 should be encoded in bech32m");return{witnessVersion:n,data:fo.fromWords(e.slice(1))}}(t);if(Ki.test(t))return function(t){const{words:e}=lo.decode(t),n=e[0];if(0==n)throw new Error("Addresses with witness version 1 should be encoded in bech32");return{witnessVersion:n,data:lo.fromWords(e.slice(1))}}(t);throw new Error(`Native segwit address ${t} does not match valid prefix ${Li} or ${Ki}`)}(t);return{version:function(t,e){if(t===Gi&&20===e)return Hi.P2WPKH;if(t===Gi&&32===e)return Hi.P2WSH;if(t===Fi&&32===e)return Hi.P2TR;throw new Error("Invalid native segwit witness version and byte length. Currently, only P2WPKH, P2WSH, and P2TR are supported.")}(e.witnessVersion,e.data.length),data:e.data}}throw new Error("Unknown BTC address prefix.")}catch(e){throw new No(t,e)}}function $o(t){const e=t;if(e.type!==Bn.Tuple||!e.value)throw new Error("Invalid argument, expected ClarityValue to be a TupleCV");if(!("version"in e.value)||!("hashbytes"in e.value))throw new Error("Invalid argument, expected Clarity tuple value to contain `version` and `hashbytes` keys");const n=e.value.version,r=e.value.hashbytes;if(n.type!==Bn.Buffer||r.type!==Bn.Buffer)throw new Error("Invalid argument, expected Clarity tuple value to contain `version` and `hashbytes` buffers");return{version:f(n.value)[0],hashBytes:f(r.value)}}function Do(t){switch(t){case Vi.ERR_STACKING_UNREACHABLE:return"Stacking unreachable";case Vi.ERR_STACKING_CORRUPTED_STATE:return"Stacking state is corrupted";case Vi.ERR_STACKING_INSUFFICIENT_FUNDS:return"Insufficient funds";case Vi.ERR_STACKING_INVALID_LOCK_PERIOD:return"Invalid lock period";case Vi.ERR_STACKING_ALREADY_STACKED:return"Account already stacked. Concurrent stacking not allowed.";case Vi.ERR_STACKING_NO_SUCH_PRINCIPAL:return"Principal does not exist";case Vi.ERR_STACKING_EXPIRED:return"Stacking expired";case Vi.ERR_STACKING_STX_LOCKED:return"STX balance is locked";case Vi.ERR_STACKING_PERMISSION_DENIED:return"Permission denied";case Vi.ERR_STACKING_THRESHOLD_NOT_MET:return"Stacking threshold not met";case Vi.ERR_STACKING_POX_ADDRESS_IN_USE:return"PoX address already in use";case Vi.ERR_STACKING_INVALID_POX_ADDRESS:return"Invalid PoX address";case Vi.ERR_STACKING_ALREADY_REJECTED:return"Stacking already rejected";case Vi.ERR_STACKING_INVALID_AMOUNT:return"Invalid amount";case Vi.ERR_NOT_ALLOWED:return"Stacking not allowed";case Vi.ERR_STACKING_ALREADY_DELEGATED:return"Already delegated";case Vi.ERR_DELEGATION_EXPIRES_DURING_LOCK:return"Delegation expires during lock period";case Vi.ERR_DELEGATION_TOO_MUCH_LOCKED:return"Delegation too much locked";case Vi.ERR_DELEGATION_POX_ADDR_REQUIRED:return"PoX address required for delegation";case Vi.ERR_INVALID_START_BURN_HEIGHT:return"Invalid start burn height";case Vi.ERR_NOT_CURRENT_STACKER:return"ERR_NOT_CURRENT_STACKER";case Vi.ERR_STACK_EXTEND_NOT_LOCKED:case Vi.ERR_STACK_INCREASE_NOT_LOCKED:return"Stacker must be currently locked";case Vi.ERR_DELEGATION_NO_REWARD_SLOT:return"Invalid reward-cycle and reward-cycle-index";case Vi.ERR_DELEGATION_WRONG_REWARD_SLOT:return"PoX address must match the one on record";case Vi.ERR_STACKING_IS_DELEGATED:return"Stacker must be directly stacking and not delegating";case Vi.ERR_STACKING_NOT_DELEGATED:return"Stacker must be delegating and not be directly stacking"}}function Lo(t){const{version:e,data:n}=Ho(t);return Sr({version:Vn(c(BigInt(e),1)),hashbytes:Vn(n)})}function Ko(t,e,n){if(!B.includes(n))throw new Error("Invalid network.");switch("string"==typeof e&&(e=f(e)),t){case Hi.P2PKH:case Hi.P2SH:case Hi.P2SHP2WPKH:case Hi.P2SHP2WSH:{const r=function(t,e){switch(t){case Hi.P2PKH:return $i[e].P2PKH;case Hi.P2SH:case Hi.P2SHP2WPKH:case Hi.P2SHP2WSH:return $i[e].P2SH;default:throw new Error("Invalid pox address version")}}(t,n);return function(t,e){return function(t){const e=ne(ne(t));return go().encode(m(t,e).slice(0,t.length+4))}(m(new Uint8Array([t]),e.slice(0,20)))}(r,e)}case Hi.P2WPKH:case Hi.P2WSH:{const t=fo.toWords(e);return fo.encode(Mi[n],[Gi,...t])}case Hi.P2TR:{const t=lo.toWords(e);return lo.encode(Mi[n],[Fi,...t])}}throw new Error(`Unexpected address version: ${t}`)}function Mo(...t){return"number"==typeof t[0]?Ko(t[0],t[1],t[2]):function(t,e){const n=$o(t);return Ko(n.version,n.hashBytes,e)}(t[0],t[1])}function jo(t){if(t.type===Bn.OptionalSome)return t.value;if(t.type!==Bn.OptionalNone)throw new Error("Object is not an 'Optional'")}function Go(t,e){if(t.type===Bn.OptionalSome)return e(t.value);if(t.type!==Bn.OptionalNone)throw new Error("Object is not an 'Optional'")}function Fo(t){if(t.period===Wi.Period1)throw new Error(`PoX-2 has not activated yet (currently in period ${t.period} of PoX-2 operation)`)}function Wo({contract:t,poxAddress:e}){if(e&&t.endsWith(".pox")&&!Di.test(e))throw new Error("PoX-1 requires P2PKH/P2SH/P2SH-P2WPKH/P2SH-P2WSH bitcoin addresses")}function Vo({contract:t,signerKey:e,signerSignature:n,maxAmount:r,authId:i}){const o=void 0!==r,s=void 0!==i;if(/\.pox(-[2-3])?$/.test(t)){if(e||n||o||s)throw new Error("PoX-1, PoX-2 and PoX-3 do not accept a `signerKey`, `signerSignature`, `maxAmount` or `authId`")}else if(!e||!o||void 0===i)throw new Error("PoX-4 requires a `signerKey` (buff 33), `maxAmount` (uint), and `authId` (uint)")}var qo=(t=>(t.StackStx="stack-stx",t.AggregateCommit="agg-commit",t.AggregateIncrease="agg-increase",t.StackExtend="stack-extend",t.StackIncrease="stack-increase",t))(qo||{});function zo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:i,privateKey:o,maxAmount:s,authId:a}){return function({message:t,domain:e,privateKey:n}){return function({messageHash:t,privateKey:e}){return(n=fr(e,t)).slice(2)+n.slice(0,2);var n}({messageHash:d(ne(vo({message:t,domain:e}))),privateKey:n})}(Oo(Ro({},Jo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:i,maxAmount:s,authId:a})),{privateKey:o}))}function Xo({topic:t,poxAddress:e,rewardCycle:n,period:i,network:o,publicKey:s,signature:a,maxAmount:c,authId:u}){return function({signature:t,message:e,publicKey:n}){return function({signature:t,message:e,publicKey:n}){const{r:i,s:o}=rr(t),s=new tn(r(i),r(o)),a=kn(s,"string"==typeof e?function(t,e=bo){return ne(mo(t,e))}(e):e,n,{strict:!1});return a||"string"!=typeof e?a:kn(s,ne(mo(e,"Stacks Message Signing:\n")),n,{strict:!1})}({signature:ir(t),message:e,publicKey:n})}({message:ne(vo(Jo({topic:t,poxAddress:e,rewardCycle:n,period:i,network:o,maxAmount:c,authId:u}))),publicKey:s,signature:a})}function Jo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:i,maxAmount:o,authId:s}){const a=U(i);return{message:Sr({"pox-addr":Lo(e),"reward-cycle":Wn(n),topic:vr(t),period:Wn(r),"max-amount":Wn(o),"auth-id":Wn(s)}),domain:Sr({name:vr("pox-4-signer"),version:vr("1.0.0"),"chain-id":Wn(a.chainId)})}}var Zo=Object.defineProperty,Yo=Object.getOwnPropertySymbols,Qo=Object.prototype.hasOwnProperty,ts=Object.prototype.propertyIsEnumerable,es=(t,e,n)=>e in t?Zo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ns=(t,e)=>{for(var n in e||(e={}))Qo.call(e,n)&&es(t,n,e[n]);if(Yo)for(var n of Yo(e))ts.call(e,n)&&es(t,n,e[n]);return t},rs=(t,e)=>{var n={};for(var r in t)Qo.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&Yo)for(var r of Yo(t))e.indexOf(r)<0&&ts.call(t,r)&&(n[r]=t[r]);return n};class is{constructor(t){var e;this.address=t.address,this.network=U(null!=(e=t.network)?e:"mainnet"),this.client=Object.assign({},H(this.network),t.client)}get baseUrl(){return this.client.baseUrl}get fetch(){return this.client.fetch}getCoreInfo(){return this.client.fetch(`${this.client.baseUrl}/v2/info`).then(t=>t.json())}getPoxInfo(){return this.client.fetch(`${this.client.baseUrl}/v2/pox`).then(t=>t.json())}async getTargetBlockTime(){const t=await this.client.fetch(`${this.client.baseUrl}/extended/v1/info/network_block_times`).then(t=>t.json());return this.network.chainId===C.Mainnet?t.mainnet.target_block_time:t.testnet.target_block_time}async getAccountStatus(){return this.client.fetch(`${this.client.baseUrl}/v2/accounts/${this.address}?proof=0`).then(t=>t.json()).then(t=>(t.balance=BigInt(t.balance),t.locked=BigInt(t.locked),t))}async getAccountBalance(){return this.getAccountStatus().then(t=>t.balance)}async getAccountExtendedBalances(){return this.client.fetch(`${this.client.baseUrl}/extended/v1/address/${this.address}/balances`).then(t=>t.json()).then(t=>(t.stx.balance=BigInt(t.stx.balance),t.stx.total_sent=BigInt(t.stx.total_sent),t.stx.total_received=BigInt(t.stx.total_received),t.stx.locked=BigInt(t.stx.locked),t))}async getAccountBalanceLocked(){return this.getAccountStatus().then(t=>t.locked)}async getCycleDuration(){const t=this.getPoxInfo(),e=await this.getTargetBlockTime();return Promise.all([t,e]).then(([t,e])=>t.reward_cycle_length*e)}async getRewardsTotalForBtcAddress(){return this.client.fetch(`${this.client.baseUrl}/extended/v1/burnchain/rewards/${this.address}/total`).then(t=>t.json()).then(t=>(t.reward_amount=BigInt(t.reward_amount),t))}async getRewardsForBtcAddress(t){let e=`${this.client.baseUrl}/extended/v1/burnchain/rewards/${this.address}`;return t&&(e+=`?limit=${t.limit}&offset=${t.offset}`),this.client.fetch(e).then(t=>t.json())}async getRewardHoldersForBtcAddress(t){let e=`${this.client.baseUrl}/extended/v1/burnchain/reward_slot_holders/${this.address}`;return t&&(e+=`?limit=${t.limit}&offset=${t.offset}`),this.client.fetch(e).then(t=>t.json())}async getRewardSet(t){const[e,n]=this.parseContractId(null==t?void 0:t.contractId);return Go(await pi({client:this.client,senderAddress:this.address,contractAddress:e,contractName:n,functionArgs:[Wn(t.rewardCyleId),Wn(t.rewardSetIndex)],functionName:"get-reward-set-pox-address"}),t=>({pox_address:{version:f(t.value["pox-addr"].value.version.value),hashbytes:f(t.value["pox-addr"].value.hashbytes.value)},total_ustx:BigInt(t.value["total-ustx"].value)}))}async getSecondsUntilNextCycle(){const t=this.getPoxInfo(),e=this.getTargetBlockTime(),n=this.getCoreInfo();return Promise.all([t,e,n]).then(([t,e,n])=>(t.reward_cycle_length-(n.burn_block_height-t.first_burnchain_block_height)%t.reward_cycle_length)*e)}async getSecondsUntilStackingDeadline(){const t=this.getPoxInfo(),e=this.getTargetBlockTime();return Promise.all([t,e]).then(([t,e])=>t.next_cycle.blocks_until_prepare_phase*e)}async getPoxOperationInfo(t){const e=[...(t=null!=t?t:await this.getPoxInfo()).contract_versions].sort((t,e)=>t.activation_burnchain_block_height-e.activation_burnchain_block_height),[n,r,i,o]=e,s=e.filter(e=>(null==t?void 0:t.current_burnchain_block_height)>=e.activation_burnchain_block_height),a=s[s.length-1];return{period:Wi.Period3,pox1:n,pox2:r,pox3:i,pox4:o,current:a}}async hasMinimumStx(){return await this.getAccountBalance()>=BigInt((await this.getPoxInfo()).min_amount_ustx)}async canStack({poxAddress:t,cycles:e}){const n=this.getAccountBalance(),r=this.getPoxInfo();return Promise.all([n,r]).then(([n,r])=>{const i=Lo(t),[o,s]=this.parseContractId(r.contract_id);return pi({client:this.client,contractName:s,contractAddress:o,functionName:"can-stack-stx",senderAddress:this.address,functionArgs:[i,Wn(n.toString()),Wn(r.reward_cycle_id),Wn(e.toString())]})}).then(t=>t.type===Bn.ResponseOk?{eligible:!0}:{eligible:!1,reason:Vi[+gi(t.value)]})}async stack(t){var e=t,{amountMicroStx:n,poxAddress:r,cycles:i,burnBlockHeight:o,signerKey:s,signerSignature:a,maxAmount:c,authId:u}=e,h=rs(e,["amountMicroStx","poxAddress","cycles","burnBlockHeight","signerKey","signerSignature","maxAmount","authId"]);const d=await this.getPoxInfo(),f=await this.getPoxOperationInfo(d),l=await this.getStackingContract(f);Wo({contract:l,poxAddress:r}),Vo({contract:l,signerKey:s,signerSignature:a,maxAmount:c,authId:u});const p=this.getStackOptions({contract:l,amountMicroStx:n,cycles:i,poxAddress:r,burnBlockHeight:o,signerKey:s,signerSignature:a,maxAmount:c,authId:u});return li({transaction:await Bi(ns(ns({},p),os(h))),client:this.client})}async stackExtend(t){var e=t,{extendCycles:n,poxAddress:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}=e,c=rs(e,["extendCycles","poxAddress","signerKey","signerSignature","maxAmount","authId"]);const u=await this.getPoxInfo();Fo(await this.getPoxOperationInfo(u)),Vo({contract:u.contract_id,signerKey:i,signerSignature:o,maxAmount:s,authId:a});const h=this.getStackExtendOptions({contract:u.contract_id,extendCycles:n,poxAddress:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a});return li({transaction:await Bi(ns(ns({},h),os(c))),client:this.client})}async stackIncrease(t){var e=t,{increaseBy:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}=e,a=rs(e,["increaseBy","signerKey","signerSignature","maxAmount","authId"]);const c=await this.getPoxInfo();Fo(await this.getPoxOperationInfo(c)),Vo({contract:c.contract_id,signerKey:r,signerSignature:i,maxAmount:o,authId:s});const u=this.getStackIncreaseOptions({contract:c.contract_id,increaseBy:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s});return li({transaction:await Bi(ns(ns({},u),os(a))),client:this.client})}async delegateStx(t){var e=t,{amountMicroStx:n,delegateTo:r,untilBurnBlockHeight:i,poxAddress:o}=e,s=rs(e,["amountMicroStx","delegateTo","untilBurnBlockHeight","poxAddress"]);const a=await this.getPoxInfo(),c=await this.getPoxOperationInfo(a),u=await this.getStackingContract(c);Wo({contract:u,poxAddress:o});const h=this.getDelegateOptions({contract:u,amountMicroStx:n,delegateTo:r,untilBurnBlockHeight:i,poxAddress:o});return li({transaction:await Bi(ns(ns({},h),os(s))),client:this.client})}async delegateStackStx(t){var e=t,{stacker:n,amountMicroStx:r,poxAddress:i,burnBlockHeight:o,cycles:s}=e,a=rs(e,["stacker","amountMicroStx","poxAddress","burnBlockHeight","cycles"]);const c=await this.getPoxInfo(),u=await this.getPoxOperationInfo(c),h=await this.getStackingContract(u);Wo({contract:h,poxAddress:i});const d=this.getDelegateStackOptions({contract:h,stacker:n,amountMicroStx:r,poxAddress:i,burnBlockHeight:o,cycles:s});return li({transaction:await Bi(ns(ns({},d),os(a))),client:this.client})}async delegateStackExtend(t){var e=t,{stacker:n,poxAddress:r,extendCount:i}=e,o=rs(e,["stacker","poxAddress","extendCount"]);const s=(await this.getPoxInfo()).contract_id,a=this.getDelegateStackExtendOptions({contract:s,stacker:n,poxAddress:r,extendCount:i});return li({transaction:await Bi(ns(ns({},a),os(o))),client:this.client})}async delegateStackIncrease(t){var e=t,{stacker:n,poxAddress:r,increaseBy:i}=e,o=rs(e,["stacker","poxAddress","increaseBy"]);const s=await this.getPoxInfo();Fo(await this.getPoxOperationInfo(s));const a=this.getDelegateStackIncreaseOptions({contract:s.contract_id,stacker:n,poxAddress:r,increaseBy:i});return li({transaction:await Bi(ns(ns({},a),os(o))),client:this.client})}async stackAggregationCommit(t){var e=t,{poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}=e,c=rs(e,["poxAddress","rewardCycle","signerKey","signerSignature","maxAmount","authId"]);const u=await this.getStackingContract();Wo({contract:u,poxAddress:n}),Vo({contract:u,signerKey:i,signerSignature:o,maxAmount:s,authId:a});const h=this.getStackAggregationCommitOptions({contract:u,poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a});return li({transaction:await Bi(ns(ns({},h),os(c))),client:this.client})}async stackAggregationCommitIndexed(t){var e=t,{poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}=e,c=rs(e,["poxAddress","rewardCycle","signerKey","signerSignature","maxAmount","authId"]);const u=await this.getStackingContract();Wo({contract:u,poxAddress:n}),Vo({contract:u,signerKey:i,signerSignature:o,maxAmount:s,authId:a});const h=this.getStackAggregationCommitOptionsIndexed({contract:u,poxAddress:n,rewardCycle:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a});return li({transaction:await Bi(ns(ns({},h),os(c))),client:this.client})}async stackAggregationIncrease(t){var e=t,{poxAddress:n,rewardCycle:r,rewardIndex:i,signerKey:o,signerSignature:s,maxAmount:a,authId:c}=e,u=rs(e,["poxAddress","rewardCycle","rewardIndex","signerKey","signerSignature","maxAmount","authId"]);const h=await this.getStackingContract();Wo({contract:h,poxAddress:n}),Vo({contract:h,signerKey:o,signerSignature:s,maxAmount:a,authId:c});const d=this.getStackAggregationIncreaseOptions({contract:h,poxAddress:n,rewardCycle:r,rewardCycleIndex:i,signerKey:o,signerSignature:s,maxAmount:a,authId:c});return li({transaction:await Bi(ns(ns({},d),os(u))),client:this.client})}async revokeDelegateStx(t){"string"==typeof t&&(t={privateKey:t});const e=(await this.getPoxInfo()).contract_id,n=this.getRevokeDelegateStxOptions(e);return li({transaction:await Bi(ns(ns({},n),os(t))),client:this.client})}getStackOptions({amountMicroStx:t,poxAddress:e,cycles:n,contract:r,burnBlockHeight:i,signerKey:o,signerSignature:s,maxAmount:a,authId:c}){const u=Lo(e),[h,d]=this.parseContractId(r),l=[Wn(t),u,Wn(i),Wn(n)];return o&&a&&void 0!==c&&(l.push(s?Er(Vn(f(s))):Ar()),l.push(Vn(f(o))),l.push(Wn(a)),l.push(Wn(c))),{client:this.client,contractAddress:h,contractName:d,functionName:"stack-stx",functionArgs:l,validateWithAbi:!0,network:this.network}}getStackExtendOptions({extendCycles:t,poxAddress:e,contract:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}){const a=Lo(e),[c,u]=this.parseContractId(n),h=[Wn(t),a];return r&&o&&void 0!==s&&(h.push(i?Er(Vn(f(i))):Ar()),h.push(Vn(f(r))),h.push(Wn(o)),h.push(Wn(s))),{client:this.client,contractAddress:c,contractName:u,functionName:"stack-extend",functionArgs:h,validateWithAbi:!0,network:this.network}}getStackIncreaseOptions({increaseBy:t,contract:e,signerKey:n,signerSignature:r,maxAmount:i,authId:o}){const[s,a]=this.parseContractId(e),c=[Wn(t)];return n&&i&&void 0!==o&&(c.push(r?Er(Vn(f(r))):Ar()),c.push(Vn(f(n))),c.push(Wn(i)),c.push(Wn(o))),{client:this.client,contractAddress:s,contractName:a,functionName:"stack-increase",functionArgs:c,validateWithAbi:!0,network:this.network}}getDelegateOptions({contract:t,amountMicroStx:e,delegateTo:n,untilBurnBlockHeight:r,poxAddress:i}){const o=i?Er(Lo(i)):Ar(),[s,a]=this.parseContractId(t);return{client:this.client,contractAddress:s,contractName:a,functionName:"delegate-stx",functionArgs:[Wn(e),br(n),r?Er(Wn(r)):Ar(),o],validateWithAbi:!0,network:this.network}}getDelegateStackOptions({contract:t,stacker:e,amountMicroStx:n,poxAddress:r,burnBlockHeight:i,cycles:o}){const s=Lo(r),[a,c]=this.parseContractId(t);return{client:this.client,contractAddress:a,contractName:c,functionName:"delegate-stack-stx",functionArgs:[br(e),Wn(n),s,Wn(i),Wn(o)],validateWithAbi:!0,network:this.network}}getDelegateStackExtendOptions({contract:t,stacker:e,poxAddress:n,extendCount:r}){const i=Lo(n),[o,s]=this.parseContractId(t);return{client:this.client,contractAddress:o,contractName:s,functionName:"delegate-stack-extend",functionArgs:[br(e),i,Wn(r)],validateWithAbi:!0,network:this.network}}getDelegateStackIncreaseOptions({contract:t,stacker:e,poxAddress:n,increaseBy:r}){const i=Lo(n),[o,s]=this.parseContractId(t);return{client:this.client,contractAddress:o,contractName:s,functionName:"delegate-stack-increase",functionArgs:[br(e),i,Wn(r)],validateWithAbi:!0,network:this.network}}getStackAggregationCommitOptions({contract:t,poxAddress:e,rewardCycle:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}){const a=Lo(e),[c,u]=this.parseContractId(t),h=[a,Wn(n)];return r&&o&&void 0!==s&&(h.push(i?Er(Vn(f(i))):Ar()),h.push(Vn(f(r))),h.push(Wn(o)),h.push(Wn(s))),{client:this.client,contractAddress:c,contractName:u,functionName:"stack-aggregation-commit",functionArgs:h,validateWithAbi:!0,network:this.network}}getStackAggregationIncreaseOptions({contract:t,poxAddress:e,rewardCycle:n,rewardCycleIndex:r,signerKey:i,signerSignature:o,maxAmount:s,authId:a}){const c=Lo(e),[u,h]=this.parseContractId(t),d=[c,Wn(n),Wn(r)];return i&&s&&void 0!==a&&(d.push(o?Er(Vn(f(o))):Ar()),d.push(Vn(f(i))),d.push(Wn(s)),d.push(Wn(a))),{client:this.client,contractAddress:u,contractName:h,functionName:"stack-aggregation-increase",functionArgs:d,validateWithAbi:!0,network:this.network}}getStackAggregationCommitOptionsIndexed({contract:t,poxAddress:e,rewardCycle:n,signerKey:r,signerSignature:i,maxAmount:o,authId:s}){const a=Lo(e),[c,u]=this.parseContractId(t),h=[a,Wn(n)];return r&&o&&void 0!==s&&(h.push(i?Er(Vn(f(i))):Ar()),h.push(Vn(f(r))),h.push(Wn(o)),h.push(Wn(s))),{client:this.client,contractAddress:c,contractName:u,functionName:"stack-aggregation-commit-indexed",functionArgs:h,validateWithAbi:!0,network:this.network}}getRevokeDelegateStxOptions(t){const[e,n]=this.parseContractId(t);return{client:this.client,contractAddress:e,contractName:n,functionName:"revoke-delegate-stx",functionArgs:[],validateWithAbi:!0,network:this.network}}async getStatus(){const t=await this.getPoxInfo(),[e,n]=this.parseContractId(t.contract_id),r=await this.getAccountStatus();return pi({contractAddress:e,contractName:n,functionName:"get-stacker-info",senderAddress:this.address,functionArgs:[br(this.address)],client:this.client}).then(t=>{if(t.type===Bn.OptionalSome){const e=t.value,n=e.value["pox-addr"],i=e.value["first-reward-cycle"],o=e.value["lock-period"],s=n.value.version,a=n.value.hashbytes;return{stacked:!0,details:{first_reward_cycle:Number(i.value),lock_period:Number(o.value),unlock_height:r.unlock_height,pox_address:{version:f(s.value),hashbytes:f(a.value)}}}}if(t.type===Bn.OptionalNone)return{stacked:!1};throw new Error("Error fetching stacker info")})}async getDelegationStatus(){const t=await this.getPoxInfo(),[e,n]=this.parseContractId(t.contract_id);return pi({contractAddress:e,contractName:n,functionName:"get-delegation-info",functionArgs:[br(this.address)],senderAddress:this.address,client:this.client}).then(t=>{if(t.type===Bn.OptionalSome){const e=t.value,n=e.value["amount-ustx"],r=e.value["delegated-to"],i=Go(e.value["pox-addr"],t=>({version:f(t.value.version.value)[0],hashbytes:f(t.value.hashbytes.value)})),o=jo(e.value["until-burn-ht"]);return{delegated:!0,details:{amount_micro_stx:BigInt(n.value),delegated_to:r.value,pox_address:i,until_burn_ht:o?Number(o.value):void 0}}}if(t.type===Bn.OptionalNone)return{delegated:!1};throw new Error("Error fetching delegation info")})}async verifySignerKeySignature({topic:t,poxAddress:e,rewardCycle:n,period:r,signerSignature:i,signerKey:o,amount:s,maxAmount:a,authId:c}){const u=await this.getPoxInfo(),[h,d]=this.parseContractId(u.contract_id);return pi({contractAddress:h,contractName:d,functionName:"verify-signer-key-sig",functionArgs:[Lo(e),Wn(n),vr(t),Wn(r),i?Er(Vn(f(i))):Ar(),Vn(f(o)),Wn(s),Wn(a),Wn(c)],senderAddress:this.address,client:this.client}).then(t=>t.type===Bn.ResponseOk)}async getStackingContract(t){switch((t=null!=t?t:await this.getPoxOperationInfo()).period){case Wi.Period1:return t.pox1.contract_id;case Wi.Period2a:case Wi.Period2b:return t.pox2.contract_id;case Wi.Period3:default:return t.current.contract_id}}modifyLockTxFee({tx:t,amountMicroStx:n}){const r=function(t){switch(t.authType){case at.Standard:return t.spendingCondition.fee;case at.Sponsored:return t.sponsorSpendingCondition.fee}}(t.auth);return t.payload.functionArgs[0]=Wn(e(n)-r),t}parseContractId(t){const e=t.split(".");if(2===e.length&&(t=>{try{return(0,$n.ns)(t),!0}catch(t){return!1}})(e[0])&&e[1].startsWith("pox"))return e;throw new Error("Stacking contract ID is malformed")}signPoxSignature({topic:t,poxAddress:e,rewardCycle:n,period:r,signerPrivateKey:i,authId:o,maxAmount:s}){return zo({topic:t,poxAddress:e,rewardCycle:n,period:r,network:this.network,privateKey:i,maxAmount:s,authId:o})}}function os(t){return t.senderKey=t.privateKey,delete t.privateKey,t}})(),o})());
3
3
  //# sourceMappingURL=index.js.map