@smartledger/bsv 9.16.1 → 9.19.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/bsv-ecies.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var bsvEcies=(()=>{var Cc=Object.create;var bn=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var jc=Object.getOwnPropertyNames;var Nc=Object.getPrototypeOf,Dc=Object.prototype.hasOwnProperty;var Pc=(n,t,e)=>t in n?bn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var At=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(r){throw e=[r],r}};var kt=(n,t)=>()=>{try{return t||n((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},zn=(n,t)=>{for(var e in t)bn(n,e,{get:t[e],enumerable:!0})},Qo=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jc(t))!Dc.call(n,o)&&o!==e&&bn(n,o,{get:()=>t[o],enumerable:!(r=kc(t,o))||r.enumerable});return n};var Jo=(n,t,e)=>(e=n!=null?Cc(Nc(n)):{},Qo(t||!n||!n.__esModule?bn(e,"default",{value:n,enumerable:!0}):e,n)),ge=n=>Qo(bn({},"__esModule",{value:!0}),n);var S=(n,t,e)=>Pc(n,typeof t!="symbol"?t+"":t,e);var oi=kt((fa,ri)=>{L();var wt=ri.exports={},Zt,Yt;function jr(){throw new Error("setTimeout has not been defined")}function Nr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Zt=setTimeout:Zt=jr}catch{Zt=jr}try{typeof clearTimeout=="function"?Yt=clearTimeout:Yt=Nr}catch{Yt=Nr}})();function ti(n){if(Zt===setTimeout)return setTimeout(n,0);if((Zt===jr||!Zt)&&setTimeout)return Zt=setTimeout,setTimeout(n,0);try{return Zt(n,0)}catch{try{return Zt.call(null,n,0)}catch{return Zt.call(this,n,0)}}}function Hc(n){if(Yt===clearTimeout)return clearTimeout(n);if((Yt===Nr||!Yt)&&clearTimeout)return Yt=clearTimeout,clearTimeout(n);try{return Yt(n)}catch{try{return Yt.call(null,n)}catch{return Yt.call(this,n)}}}var ce=[],Ve=!1,Fe,Zn=-1;function qc(){!Ve||!Fe||(Ve=!1,Fe.length?ce=Fe.concat(ce):Zn=-1,ce.length&&ei())}function ei(){if(!Ve){var n=ti(qc);Ve=!0;for(var t=ce.length;t;){for(Fe=ce,ce=[];++Zn<t;)Fe&&Fe[Zn].run();Zn=-1,t=ce.length}Fe=null,Ve=!1,Hc(n)}}wt.nextTick=function(n){var t=new Array(arguments.length-1);if(arguments.length>1)for(var e=1;e<arguments.length;e++)t[e-1]=arguments[e];ce.push(new ni(n,t)),ce.length===1&&!Ve&&ti(ei)};function ni(n,t){this.fun=n,this.array=t}ni.prototype.run=function(){this.fun.apply(null,this.array)};wt.title="browser";wt.browser=!0;wt.env={};wt.argv=[];wt.version="";wt.versions={};function fe(){}wt.on=fe;wt.addListener=fe;wt.once=fe;wt.off=fe;wt.removeListener=fe;wt.removeAllListeners=fe;wt.emit=fe;wt.prependListener=fe;wt.prependOnceListener=fe;wt.listeners=function(n){return[]};wt.binding=function(n){throw new Error("process.binding is not supported")};wt.cwd=function(){return"/"};wt.chdir=function(n){throw new Error("process.chdir is not supported")};wt.umask=function(){return 0}});var ci=kt(Yn=>{"use strict";L();Yn.byteLength=Kc;Yn.toByteArray=zc;Yn.fromByteArray=Vc;var Vt=[],Pt=[],Mc=typeof Uint8Array<"u"?Uint8Array:Array,Dr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Le=0,ii=Dr.length;Le<ii;++Le)Vt[Le]=Dr[Le],Pt[Dr.charCodeAt(Le)]=Le;var Le,ii;Pt[45]=62;Pt[95]=63;function si(n){var t=n.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=n.indexOf("=");e===-1&&(e=t);var r=e===t?0:4-e%4;return[e,r]}function Kc(n){var t=si(n),e=t[0],r=t[1];return(e+r)*3/4-r}function $c(n,t,e){return(t+e)*3/4-e}function zc(n){var t,e=si(n),r=e[0],o=e[1],i=new Mc($c(n,r,o)),s=0,f=o>0?r-4:r,c;for(c=0;c<f;c+=4)t=Pt[n.charCodeAt(c)]<<18|Pt[n.charCodeAt(c+1)]<<12|Pt[n.charCodeAt(c+2)]<<6|Pt[n.charCodeAt(c+3)],i[s++]=t>>16&255,i[s++]=t>>8&255,i[s++]=t&255;return o===2&&(t=Pt[n.charCodeAt(c)]<<2|Pt[n.charCodeAt(c+1)]>>4,i[s++]=t&255),o===1&&(t=Pt[n.charCodeAt(c)]<<10|Pt[n.charCodeAt(c+1)]<<4|Pt[n.charCodeAt(c+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function Zc(n){return Vt[n>>18&63]+Vt[n>>12&63]+Vt[n>>6&63]+Vt[n&63]}function Yc(n,t,e){for(var r,o=[],i=t;i<e;i+=3)r=(n[i]<<16&16711680)+(n[i+1]<<8&65280)+(n[i+2]&255),o.push(Zc(r));return o.join("")}function Vc(n){for(var t,e=n.length,r=e%3,o=[],i=16383,s=0,f=e-r;s<f;s+=i)o.push(Yc(n,s,s+i>f?f:s+i));return r===1?(t=n[e-1],o.push(Vt[t>>2]+Vt[t<<4&63]+"==")):r===2&&(t=(n[e-2]<<8)+n[e-1],o.push(Vt[t>>10]+Vt[t>>4&63]+Vt[t<<2&63]+"=")),o.join("")}});var fi=kt(Pr=>{L();Pr.read=function(n,t,e,r,o){var i,s,f=o*8-r-1,c=(1<<f)-1,u=c>>1,h=-7,a=e?o-1:0,l=e?-1:1,d=n[t+a];for(a+=l,i=d&(1<<-h)-1,d>>=-h,h+=f;h>0;i=i*256+n[t+a],a+=l,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=r;h>0;s=s*256+n[t+a],a+=l,h-=8);if(i===0)i=1-u;else{if(i===c)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,r),i=i-u}return(d?-1:1)*s*Math.pow(2,i-r)};Pr.write=function(n,t,e,r,o,i){var s,f,c,u=i*8-o-1,h=(1<<u)-1,a=h>>1,l=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:i-1,g=r?1:-1,y=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(f=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+a>=1?t+=l/c:t+=l*Math.pow(2,1-a),t*c>=2&&(s++,c/=2),s+a>=h?(f=0,s=h):s+a>=1?(f=(t*c-1)*Math.pow(2,o),s=s+a):(f=t*Math.pow(2,a-1)*Math.pow(2,o),s=0));o>=8;n[e+d]=f&255,d+=g,f/=256,o-=8);for(s=s<<o|f,u+=o;u>0;n[e+d]=s&255,d+=g,s/=256,u-=8);n[e+d-g]|=y*128}});var vi=kt(Qe=>{"use strict";L();var Hr=ci(),Ge=fi(),ui=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Qe.Buffer=E;Qe.SlowBuffer=tf;Qe.INSPECT_MAX_BYTES=50;var Vn=2147483647;Qe.kMaxLength=Vn;E.TYPED_ARRAY_SUPPORT=Wc();!E.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Wc(){try{let n=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(n,t),n.foo()===42}catch{return!1}}Object.defineProperty(E.prototype,"parent",{enumerable:!0,get:function(){if(E.isBuffer(this))return this.buffer}});Object.defineProperty(E.prototype,"offset",{enumerable:!0,get:function(){if(E.isBuffer(this))return this.byteOffset}});function ue(n){if(n>Vn)throw new RangeError('The value "'+n+'" is invalid for option "size"');let t=new Uint8Array(n);return Object.setPrototypeOf(t,E.prototype),t}function E(n,t,e){if(typeof n=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return $r(n)}return di(n,t,e)}E.poolSize=8192;function di(n,t,e){if(typeof n=="string")return Xc(n,t);if(ArrayBuffer.isView(n))return Qc(n);if(n==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);if(Wt(n,ArrayBuffer)||n&&Wt(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Wt(n,SharedArrayBuffer)||n&&Wt(n.buffer,SharedArrayBuffer)))return Mr(n,t,e);if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=n.valueOf&&n.valueOf();if(r!=null&&r!==n)return E.from(r,t,e);let o=Jc(n);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return E.from(n[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n)}E.from=function(n,t,e){return di(n,t,e)};Object.setPrototypeOf(E.prototype,Uint8Array.prototype);Object.setPrototypeOf(E,Uint8Array);function pi(n){if(typeof n!="number")throw new TypeError('"size" argument must be of type number');if(n<0)throw new RangeError('The value "'+n+'" is invalid for option "size"')}function Gc(n,t,e){return pi(n),n<=0?ue(n):t!==void 0?typeof e=="string"?ue(n).fill(t,e):ue(n).fill(t):ue(n)}E.alloc=function(n,t,e){return Gc(n,t,e)};function $r(n){return pi(n),ue(n<0?0:zr(n)|0)}E.allocUnsafe=function(n){return $r(n)};E.allocUnsafeSlow=function(n){return $r(n)};function Xc(n,t){if((typeof t!="string"||t==="")&&(t="utf8"),!E.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let e=gi(n,t)|0,r=ue(e),o=r.write(n,t);return o!==e&&(r=r.slice(0,o)),r}function qr(n){let t=n.length<0?0:zr(n.length)|0,e=ue(t);for(let r=0;r<t;r+=1)e[r]=n[r]&255;return e}function Qc(n){if(Wt(n,Uint8Array)){let t=new Uint8Array(n);return Mr(t.buffer,t.byteOffset,t.byteLength)}return qr(n)}function Mr(n,t,e){if(t<0||n.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(n.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');let r;return t===void 0&&e===void 0?r=new Uint8Array(n):e===void 0?r=new Uint8Array(n,t):r=new Uint8Array(n,t,e),Object.setPrototypeOf(r,E.prototype),r}function Jc(n){if(E.isBuffer(n)){let t=zr(n.length)|0,e=ue(t);return e.length===0||n.copy(e,0,0,t),e}if(n.length!==void 0)return typeof n.length!="number"||Yr(n.length)?ue(0):qr(n);if(n.type==="Buffer"&&Array.isArray(n.data))return qr(n.data)}function zr(n){if(n>=Vn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Vn.toString(16)+" bytes");return n|0}function tf(n){return+n!=n&&(n=0),E.alloc(+n)}E.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==E.prototype};E.compare=function(t,e){if(Wt(t,Uint8Array)&&(t=E.from(t,t.offset,t.byteLength)),Wt(e,Uint8Array)&&(e=E.from(e,e.offset,e.byteLength)),!E.isBuffer(t)||!E.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,o=e.length;for(let i=0,s=Math.min(r,o);i<s;++i)if(t[i]!==e[i]){r=t[i],o=e[i];break}return r<o?-1:o<r?1:0};E.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};E.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return E.alloc(0);let r;if(e===void 0)for(e=0,r=0;r<t.length;++r)e+=t[r].length;let o=E.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){let s=t[r];if(Wt(s,Uint8Array))i+s.length>o.length?(E.isBuffer(s)||(s=E.from(s)),s.copy(o,i)):Uint8Array.prototype.set.call(o,s,i);else if(E.isBuffer(s))s.copy(o,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return o};function gi(n,t){if(E.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||Wt(n,ArrayBuffer))return n.byteLength;if(typeof n!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof n);let e=n.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&e===0)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return Kr(n).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return Ai(n).length;default:if(o)return r?-1:Kr(n).length;t=(""+t).toLowerCase(),o=!0}}E.byteLength=gi;function ef(n,t,e){let r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(n||(n="utf8");;)switch(n){case"hex":return hf(this,t,e);case"utf8":case"utf-8":return mi(this,t,e);case"ascii":return af(this,t,e);case"latin1":case"binary":return lf(this,t,e);case"base64":return ff(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return df(this,t,e);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),r=!0}}E.prototype._isBuffer=!0;function Ce(n,t,e){let r=n[t];n[t]=n[e],n[e]=r}E.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)Ce(this,e,e+1);return this};E.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)Ce(this,e,e+3),Ce(this,e+1,e+2);return this};E.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)Ce(this,e,e+7),Ce(this,e+1,e+6),Ce(this,e+2,e+5),Ce(this,e+3,e+4);return this};E.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?mi(this,0,t):ef.apply(this,arguments)};E.prototype.toLocaleString=E.prototype.toString;E.prototype.equals=function(t){if(!E.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:E.compare(this,t)===0};E.prototype.inspect=function(){let t="",e=Qe.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"};ui&&(E.prototype[ui]=E.prototype.inspect);E.prototype.compare=function(t,e,r,o,i){if(Wt(t,Uint8Array)&&(t=E.from(t,t.offset,t.byteLength)),!E.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),r===void 0&&(r=t?t.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),e<0||r>t.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&e>=r)return 0;if(o>=i)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,o>>>=0,i>>>=0,this===t)return 0;let s=i-o,f=r-e,c=Math.min(s,f),u=this.slice(o,i),h=t.slice(e,r);for(let a=0;a<c;++a)if(u[a]!==h[a]){s=u[a],f=h[a];break}return s<f?-1:f<s?1:0};function yi(n,t,e,r,o){if(n.length===0)return-1;if(typeof e=="string"?(r=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,Yr(e)&&(e=o?0:n.length-1),e<0&&(e=n.length+e),e>=n.length){if(o)return-1;e=n.length-1}else if(e<0)if(o)e=0;else return-1;if(typeof t=="string"&&(t=E.from(t,r)),E.isBuffer(t))return t.length===0?-1:ai(n,t,e,r,o);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(n,t,e):Uint8Array.prototype.lastIndexOf.call(n,t,e):ai(n,[t],e,r,o);throw new TypeError("val must be string, number or Buffer")}function ai(n,t,e,r,o){let i=1,s=n.length,f=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(n.length<2||t.length<2)return-1;i=2,s/=2,f/=2,e/=2}function c(h,a){return i===1?h[a]:h.readUInt16BE(a*i)}let u;if(o){let h=-1;for(u=e;u<s;u++)if(c(n,u)===c(t,h===-1?0:u-h)){if(h===-1&&(h=u),u-h+1===f)return h*i}else h!==-1&&(u-=u-h),h=-1}else for(e+f>s&&(e=s-f),u=e;u>=0;u--){let h=!0;for(let a=0;a<f;a++)if(c(n,u+a)!==c(t,a)){h=!1;break}if(h)return u}return-1}E.prototype.includes=function(t,e,r){return this.indexOf(t,e,r)!==-1};E.prototype.indexOf=function(t,e,r){return yi(this,t,e,r,!0)};E.prototype.lastIndexOf=function(t,e,r){return yi(this,t,e,r,!1)};function nf(n,t,e,r){e=Number(e)||0;let o=n.length-e;r?(r=Number(r),r>o&&(r=o)):r=o;let i=t.length;r>i/2&&(r=i/2);let s;for(s=0;s<r;++s){let f=parseInt(t.substr(s*2,2),16);if(Yr(f))return s;n[e+s]=f}return s}function rf(n,t,e,r){return Wn(Kr(t,n.length-e),n,e,r)}function of(n,t,e,r){return Wn(mf(t),n,e,r)}function sf(n,t,e,r){return Wn(Ai(t),n,e,r)}function cf(n,t,e,r){return Wn(wf(t,n.length-e),n,e,r)}E.prototype.write=function(t,e,r,o){if(e===void 0)o="utf8",r=this.length,e=0;else if(r===void 0&&typeof e=="string")o=e,r=this.length,e=0;else if(isFinite(e))e=e>>>0,isFinite(r)?(r=r>>>0,o===void 0&&(o="utf8")):(o=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let i=this.length-e;if((r===void 0||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");let s=!1;for(;;)switch(o){case"hex":return nf(this,t,e,r);case"utf8":case"utf-8":return rf(this,t,e,r);case"ascii":case"latin1":case"binary":return of(this,t,e,r);case"base64":return sf(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return cf(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),s=!0}};E.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ff(n,t,e){return t===0&&e===n.length?Hr.fromByteArray(n):Hr.fromByteArray(n.slice(t,e))}function mi(n,t,e){e=Math.min(n.length,e);let r=[],o=t;for(;o<e;){let i=n[o],s=null,f=i>239?4:i>223?3:i>191?2:1;if(o+f<=e){let c,u,h,a;switch(f){case 1:i<128&&(s=i);break;case 2:c=n[o+1],(c&192)===128&&(a=(i&31)<<6|c&63,a>127&&(s=a));break;case 3:c=n[o+1],u=n[o+2],(c&192)===128&&(u&192)===128&&(a=(i&15)<<12|(c&63)<<6|u&63,a>2047&&(a<55296||a>57343)&&(s=a));break;case 4:c=n[o+1],u=n[o+2],h=n[o+3],(c&192)===128&&(u&192)===128&&(h&192)===128&&(a=(i&15)<<18|(c&63)<<12|(u&63)<<6|h&63,a>65535&&a<1114112&&(s=a))}}s===null?(s=65533,f=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),o+=f}return uf(r)}var li=4096;function uf(n){let t=n.length;if(t<=li)return String.fromCharCode.apply(String,n);let e="",r=0;for(;r<t;)e+=String.fromCharCode.apply(String,n.slice(r,r+=li));return e}function af(n,t,e){let r="";e=Math.min(n.length,e);for(let o=t;o<e;++o)r+=String.fromCharCode(n[o]&127);return r}function lf(n,t,e){let r="";e=Math.min(n.length,e);for(let o=t;o<e;++o)r+=String.fromCharCode(n[o]);return r}function hf(n,t,e){let r=n.length;(!t||t<0)&&(t=0),(!e||e<0||e>r)&&(e=r);let o="";for(let i=t;i<e;++i)o+=xf[n[i]];return o}function df(n,t,e){let r=n.slice(t,e),o="";for(let i=0;i<r.length-1;i+=2)o+=String.fromCharCode(r[i]+r[i+1]*256);return o}E.prototype.slice=function(t,e){let r=this.length;t=~~t,e=e===void 0?r:~~e,t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),e<t&&(e=t);let o=this.subarray(t,e);return Object.setPrototypeOf(o,E.prototype),o};function vt(n,t,e){if(n%1!==0||n<0)throw new RangeError("offset is not uint");if(n+t>e)throw new RangeError("Trying to access beyond buffer length")}E.prototype.readUintLE=E.prototype.readUIntLE=function(t,e,r){t=t>>>0,e=e>>>0,r||vt(t,e,this.length);let o=this[t],i=1,s=0;for(;++s<e&&(i*=256);)o+=this[t+s]*i;return o};E.prototype.readUintBE=E.prototype.readUIntBE=function(t,e,r){t=t>>>0,e=e>>>0,r||vt(t,e,this.length);let o=this[t+--e],i=1;for(;e>0&&(i*=256);)o+=this[t+--e]*i;return o};E.prototype.readUint8=E.prototype.readUInt8=function(t,e){return t=t>>>0,e||vt(t,1,this.length),this[t]};E.prototype.readUint16LE=E.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||vt(t,2,this.length),this[t]|this[t+1]<<8};E.prototype.readUint16BE=E.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||vt(t,2,this.length),this[t]<<8|this[t+1]};E.prototype.readUint32LE=E.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||vt(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};E.prototype.readUint32BE=E.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||vt(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};E.prototype.readBigUInt64LE=ye(function(t){t=t>>>0,Xe(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&En(t,this.length-8);let o=e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,i=this[++t]+this[++t]*2**8+this[++t]*2**16+r*2**24;return BigInt(o)+(BigInt(i)<<BigInt(32))});E.prototype.readBigUInt64BE=ye(function(t){t=t>>>0,Xe(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&En(t,this.length-8);let o=e*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],i=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+r;return(BigInt(o)<<BigInt(32))+BigInt(i)});E.prototype.readIntLE=function(t,e,r){t=t>>>0,e=e>>>0,r||vt(t,e,this.length);let o=this[t],i=1,s=0;for(;++s<e&&(i*=256);)o+=this[t+s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o};E.prototype.readIntBE=function(t,e,r){t=t>>>0,e=e>>>0,r||vt(t,e,this.length);let o=e,i=1,s=this[t+--o];for(;o>0&&(i*=256);)s+=this[t+--o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*e)),s};E.prototype.readInt8=function(t,e){return t=t>>>0,e||vt(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};E.prototype.readInt16LE=function(t,e){t=t>>>0,e||vt(t,2,this.length);let r=this[t]|this[t+1]<<8;return r&32768?r|4294901760:r};E.prototype.readInt16BE=function(t,e){t=t>>>0,e||vt(t,2,this.length);let r=this[t+1]|this[t]<<8;return r&32768?r|4294901760:r};E.prototype.readInt32LE=function(t,e){return t=t>>>0,e||vt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};E.prototype.readInt32BE=function(t,e){return t=t>>>0,e||vt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};E.prototype.readBigInt64LE=ye(function(t){t=t>>>0,Xe(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&En(t,this.length-8);let o=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(r<<24);return(BigInt(o)<<BigInt(32))+BigInt(e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});E.prototype.readBigInt64BE=ye(function(t){t=t>>>0,Xe(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&En(t,this.length-8);let o=(e<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(o)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+r)});E.prototype.readFloatLE=function(t,e){return t=t>>>0,e||vt(t,4,this.length),Ge.read(this,t,!0,23,4)};E.prototype.readFloatBE=function(t,e){return t=t>>>0,e||vt(t,4,this.length),Ge.read(this,t,!1,23,4)};E.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||vt(t,8,this.length),Ge.read(this,t,!0,52,8)};E.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||vt(t,8,this.length),Ge.read(this,t,!1,52,8)};function jt(n,t,e,r,o,i){if(!E.isBuffer(n))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(e+r>n.length)throw new RangeError("Index out of range")}E.prototype.writeUintLE=E.prototype.writeUIntLE=function(t,e,r,o){if(t=+t,e=e>>>0,r=r>>>0,!o){let f=Math.pow(2,8*r)-1;jt(this,t,e,r,f,0)}let i=1,s=0;for(this[e]=t&255;++s<r&&(i*=256);)this[e+s]=t/i&255;return e+r};E.prototype.writeUintBE=E.prototype.writeUIntBE=function(t,e,r,o){if(t=+t,e=e>>>0,r=r>>>0,!o){let f=Math.pow(2,8*r)-1;jt(this,t,e,r,f,0)}let i=r-1,s=1;for(this[e+i]=t&255;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+r};E.prototype.writeUint8=E.prototype.writeUInt8=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,1,255,0),this[e]=t&255,e+1};E.prototype.writeUint16LE=E.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2};E.prototype.writeUint16BE=E.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2};E.prototype.writeUint32LE=E.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4};E.prototype.writeUint32BE=E.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function wi(n,t,e,r,o){Si(t,r,o,n,e,7);let i=Number(t&BigInt(4294967295));n[e++]=i,i=i>>8,n[e++]=i,i=i>>8,n[e++]=i,i=i>>8,n[e++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return n[e++]=s,s=s>>8,n[e++]=s,s=s>>8,n[e++]=s,s=s>>8,n[e++]=s,e}function xi(n,t,e,r,o){Si(t,r,o,n,e,7);let i=Number(t&BigInt(4294967295));n[e+7]=i,i=i>>8,n[e+6]=i,i=i>>8,n[e+5]=i,i=i>>8,n[e+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return n[e+3]=s,s=s>>8,n[e+2]=s,s=s>>8,n[e+1]=s,s=s>>8,n[e]=s,e+8}E.prototype.writeBigUInt64LE=ye(function(t,e=0){return wi(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});E.prototype.writeBigUInt64BE=ye(function(t,e=0){return xi(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});E.prototype.writeIntLE=function(t,e,r,o){if(t=+t,e=e>>>0,!o){let c=Math.pow(2,8*r-1);jt(this,t,e,r,c-1,-c)}let i=0,s=1,f=0;for(this[e]=t&255;++i<r&&(s*=256);)t<0&&f===0&&this[e+i-1]!==0&&(f=1),this[e+i]=(t/s>>0)-f&255;return e+r};E.prototype.writeIntBE=function(t,e,r,o){if(t=+t,e=e>>>0,!o){let c=Math.pow(2,8*r-1);jt(this,t,e,r,c-1,-c)}let i=r-1,s=1,f=0;for(this[e+i]=t&255;--i>=0&&(s*=256);)t<0&&f===0&&this[e+i+1]!==0&&(f=1),this[e+i]=(t/s>>0)-f&255;return e+r};E.prototype.writeInt8=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1};E.prototype.writeInt16LE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2};E.prototype.writeInt16BE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2};E.prototype.writeInt32LE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4};E.prototype.writeInt32BE=function(t,e,r){return t=+t,e=e>>>0,r||jt(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};E.prototype.writeBigInt64LE=ye(function(t,e=0){return wi(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});E.prototype.writeBigInt64BE=ye(function(t,e=0){return xi(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function bi(n,t,e,r,o,i){if(e+r>n.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Ei(n,t,e,r,o){return t=+t,e=e>>>0,o||bi(n,t,e,4,34028234663852886e22,-34028234663852886e22),Ge.write(n,t,e,r,23,4),e+4}E.prototype.writeFloatLE=function(t,e,r){return Ei(this,t,e,!0,r)};E.prototype.writeFloatBE=function(t,e,r){return Ei(this,t,e,!1,r)};function Bi(n,t,e,r,o){return t=+t,e=e>>>0,o||bi(n,t,e,8,17976931348623157e292,-17976931348623157e292),Ge.write(n,t,e,r,52,8),e+8}E.prototype.writeDoubleLE=function(t,e,r){return Bi(this,t,e,!0,r)};E.prototype.writeDoubleBE=function(t,e,r){return Bi(this,t,e,!1,r)};E.prototype.copy=function(t,e,r,o){if(!E.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),!o&&o!==0&&(o=this.length),e>=t.length&&(e=t.length),e||(e=0),o>0&&o<r&&(o=r),o===r||t.length===0||this.length===0)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-e<o-r&&(o=t.length-e+r);let i=o-r;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,r,o):Uint8Array.prototype.set.call(t,this.subarray(r,o),e),i};E.prototype.fill=function(t,e,r,o){if(typeof t=="string"){if(typeof e=="string"?(o=e,e=0,r=this.length):typeof r=="string"&&(o=r,r=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!E.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(t.length===1){let s=t.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;e=e>>>0,r=r===void 0?this.length:r>>>0,t||(t=0);let i;if(typeof t=="number")for(i=e;i<r;++i)this[i]=t;else{let s=E.isBuffer(t)?t:E.from(t,o),f=s.length;if(f===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=s[i%f]}return this};var We={};function Zr(n,t,e){We[n]=class extends e{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${n}]`,this.stack,delete this.name}get code(){return n}set code(o){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:o,writable:!0})}toString(){return`${this.name} [${n}]: ${this.message}`}}}Zr("ERR_BUFFER_OUT_OF_BOUNDS",function(n){return n?`${n} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Zr("ERR_INVALID_ARG_TYPE",function(n,t){return`The "${n}" argument must be of type number. Received type ${typeof t}`},TypeError);Zr("ERR_OUT_OF_RANGE",function(n,t,e){let r=`The value of "${n}" is out of range.`,o=e;return Number.isInteger(e)&&Math.abs(e)>2**32?o=hi(String(e)):typeof e=="bigint"&&(o=String(e),(e>BigInt(2)**BigInt(32)||e<-(BigInt(2)**BigInt(32)))&&(o=hi(o)),o+="n"),r+=` It must be ${t}. Received ${o}`,r},RangeError);function hi(n){let t="",e=n.length,r=n[0]==="-"?1:0;for(;e>=r+4;e-=3)t=`_${n.slice(e-3,e)}${t}`;return`${n.slice(0,e)}${t}`}function pf(n,t,e){Xe(t,"offset"),(n[t]===void 0||n[t+e]===void 0)&&En(t,n.length-(e+1))}function Si(n,t,e,r,o,i){if(n>e||n<t){let s=typeof t=="bigint"?"n":"",f;throw i>3?t===0||t===BigInt(0)?f=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:f=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:f=`>= ${t}${s} and <= ${e}${s}`,new We.ERR_OUT_OF_RANGE("value",f,n)}pf(r,o,i)}function Xe(n,t){if(typeof n!="number")throw new We.ERR_INVALID_ARG_TYPE(t,"number",n)}function En(n,t,e){throw Math.floor(n)!==n?(Xe(n,e),new We.ERR_OUT_OF_RANGE(e||"offset","an integer",n)):t<0?new We.ERR_BUFFER_OUT_OF_BOUNDS:new We.ERR_OUT_OF_RANGE(e||"offset",`>= ${e?1:0} and <= ${t}`,n)}var gf=/[^+/0-9A-Za-z-_]/g;function yf(n){if(n=n.split("=")[0],n=n.trim().replace(gf,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function Kr(n,t){t=t||1/0;let e,r=n.length,o=null,i=[];for(let s=0;s<r;++s){if(e=n.charCodeAt(s),e>55295&&e<57344){if(!o){if(e>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+1===r){(t-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(t-=3)>-1&&i.push(239,191,189),o=e;continue}e=(o-55296<<10|e-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((t-=1)<0)break;i.push(e)}else if(e<2048){if((t-=2)<0)break;i.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;i.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return i}function mf(n){let t=[];for(let e=0;e<n.length;++e)t.push(n.charCodeAt(e)&255);return t}function wf(n,t){let e,r,o,i=[];for(let s=0;s<n.length&&!((t-=2)<0);++s)e=n.charCodeAt(s),r=e>>8,o=e%256,i.push(o),i.push(r);return i}function Ai(n){return Hr.toByteArray(yf(n))}function Wn(n,t,e,r){let o;for(o=0;o<r&&!(o+e>=t.length||o>=n.length);++o)t[o+e]=n[o];return o}function Wt(n,t){return n instanceof t||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===t.name}function Yr(n){return n!==n}var xf=(function(){let n="0123456789abcdef",t=new Array(256);for(let e=0;e<16;++e){let r=e*16;for(let o=0;o<16;++o)t[r+o]=n[e]+n[o]}return t})();function ye(n){return typeof BigInt>"u"?bf:n}function bf(){throw new Error("BigInt not supported")}});var ft,M,L=At(()=>{ft=Jo(oi()),M=Jo(vi())});var Vr=kt((wa,Ti)=>{L();Ti.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PublicKey});var Ri=kt((ba,Ii)=>{L();Ii.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PrivateKey});var Wr=kt((Ba,Oi)=>{L();Oi.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.util.preconditions});function Ef(n,t=!1){return t?{h:Number(n&Gn),l:Number(n>>Ui&Gn)}:{h:Number(n>>Ui&Gn)|0,l:Number(n&Gn)|0}}function _i(n,t=!1){let e=n.length,r=new Uint32Array(e),o=new Uint32Array(e);for(let i=0;i<e;i++){let{h:s,l:f}=Ef(n[i],t);[r[i],o[i]]=[s,f]}return[r,o]}function Fi(n,t,e,r){let o=Bf(e),i=Sf(e);n.setUint32(t,r?i:o,r),n.setUint32(t+4,r?o:i,r)}function Gt(n,t,e,r){let o=(t>>>0)+(r>>>0);return{h:n+e+(o/2**32|0)|0,l:o|0}}var Gn,Ui,Bf,Sf,Gr,Xr,ke,je,Bn,Sn,Li,Ci,ki,ji,Ni,Di,Qr=At(()=>{L();Gn=BigInt(4294967295),Ui=BigInt(32);Bf=n=>n/2**32|0,Sf=n=>n>>>0;Gr=(n,t,e)=>n>>>e,Xr=(n,t,e)=>n<<32-e|t>>>e,ke=(n,t,e)=>n>>>e|t<<32-e,je=(n,t,e)=>n<<32-e|t>>>e,Bn=(n,t,e)=>n<<64-e|t>>>e-32,Sn=(n,t,e)=>n>>>e-32|t<<64-e;Li=(n,t,e)=>(n>>>0)+(t>>>0)+(e>>>0),Ci=(n,t,e,r)=>t+e+r+(n/2**32|0)|0,ki=(n,t,e,r)=>(n>>>0)+(t>>>0)+(e>>>0)+(r>>>0),ji=(n,t,e,r,o)=>t+e+r+o+(n/2**32|0)|0,Ni=(n,t,e,r,o)=>(n>>>0)+(t>>>0)+(e>>>0)+(r>>>0)+(o>>>0),Di=(n,t,e,r,o,i)=>t+e+r+o+i+(n/2**32|0)|0});function Xn(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}function ae(n,t=""){if(typeof n!="number")throw new TypeError(Jr(t)+"expected number, got "+typeof n);if(!Number.isSafeInteger(n)||n<0)throw new RangeError(Jr(t)+"expected integer >= 0, got "+n);return n}function Xt(n,t,e=""){if(Xn(n)&&(t===void 0||n.length===t))return n;t!==void 0&&ae(t,"length");let r=Xn(n),o=t!==void 0?` of length ${t}`:"",i=r?`length=${n.length}`:`type=${typeof n}`,s=Jr(e)+"expected Uint8Array"+o+", got "+i;throw r?new RangeError(s):new TypeError(s)}function Qn(n){if(typeof n!="function"||typeof n.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ae(n.outputLen),ae(n.blockLen),n.outputLen<1||n.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function Je(n,t=!0){if(n.destroyed)throw new Error("hash was destroyed");if(t&&n.finished)throw new Error("digest() was already called")}function Jn(n,t){Xt(n,void 0,"output");let e=t.outputLen;if(!(n.length>=e))throw new RangeError('"output" expected length >= '+e)}function Ne(...n){for(let t=0;t<n.length;t++)n[t].fill(0)}function tr(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function Mt(n,t){return n<<32-t|n>>>t}function er(n){if(Xt(n),qi)return n.toHex();let t="";for(let e=0;e<n.length;e++)t+=vf[n[e]];return t}function Hi(n){return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void 0}function to(n){if(typeof n!="string")throw new TypeError("hex string expected, got "+typeof n);if(qi)try{return Uint8Array.fromHex(n)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=n.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let r=new Uint8Array(e);for(let o=0,i=0;o<e;o++,i+=2){let s=Hi(n.charCodeAt(i)),f=Hi(n.charCodeAt(i+1));if(s===void 0||f===void 0){let c=n[i]+n[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}r[o]=s*16+f}return r}function le(n){if(typeof n!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(n))}function Mi(...n){let t=0;for(let r=0;r<n.length;r++){let o=n[r];Xt(o),t+=o.length}let e=new Uint8Array(t);for(let r=0,o=0;r<n.length;r++){let i=n[r];e.set(i,o),o+=i.length}return e}function Tf(n,t,e="opts"){return Pi(n,"defaults"),t!==void 0&&Pi(t,e),Object.assign(n,t)}function De(n,t={}){if(typeof n!="function")throw new TypeError('"hashCons" expected function, got type='+typeof n);t=Tf({},t,"info");let e=(o,i)=>n(i).update(o).digest(),r=n(void 0);return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.canXOF=r.canXOF,e.create=o=>n(o),Object.assign(e,t),Object.freeze(e)}function An(n=32){ae(n,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(n>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${n}`);return t.getRandomValues(new Uint8Array(n))}var Jr,Pi,qi,vf,Pe,me=At(()=>{L();Jr=n=>n?`"${n}" `:"";Pi=(n,t)=>{if(n===null||typeof n!="object"||Array.isArray(n))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof n)};qi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",vf=Array.from({length:256},(n,t)=>t.toString(16).padStart(2,"0"));Pe=n=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,n])})});function Ki(n,t,e){return n&t^~n&e}function $i(n,t,e){return n&t^n&e^t&e}var vn,zi,Zi,Yi,Vi,Wi=At(()=>{L();Qr();me();vn=class{constructor(t,e,r,o){S(this,"blockLen");S(this,"outputLen");S(this,"canXOF",!1);S(this,"padOffset");S(this,"isLE");S(this,"buffer");S(this,"view");S(this,"finished",!1);S(this,"length",0);S(this,"pos",0);S(this,"destroyed",!1);this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(t),this.view=tr(this.buffer)}update(t){Je(this),Xt(t);let{view:e,buffer:r,blockLen:o}=this,i=t.length,s=!1;for(let f=0;f<i;){let c=Math.min(o-this.pos,i-f);if(c===o){let u=tr(t);for(;o<=i-f;f+=o)this.process(u,f);s=!0;continue}r.set(f===0&&c===i?t:t.subarray(f,f+c),this.pos),this.pos+=c,f+=c,this.pos===o&&(this.process(e,0),this.pos=0,s=!0)}return this.length+=t.length,s&&this.roundClean(),this}digestInto(t){Je(this),Jn(t,this),this.finished=!0;let{buffer:e,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,e.fill(0,s),this.padOffset>o-s&&(this.process(r,0),e.fill(0)),Fi(r,o-8,this.length*8,i),this.process(r,0),this.roundClean();let f=t===e?r:tr(t),c=this.outputLen,u=c/4,h=this.get();if(c%4||u>h.length)throw new Error("invalid outputLen");for(let a=0;a<u;a++)f.setUint32(4*a,h[a],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}_cloneIntoMeta(t){let{buffer:e,length:r,finished:o,destroyed:i,pos:s}=this;return t.destroyed=i,t.finished=o,t.length=r,t.pos=s,s&&t.buffer.set(e),t}clone(){return this._cloneInto()}},zi=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Zi=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Yi=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Vi=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});var eo={};zn(eo,{_SHA224:()=>or,_SHA256:()=>rr,_SHA384:()=>sr,_SHA512:()=>ir,_SHA512_224:()=>cr,_SHA512_256:()=>fr,sha224:()=>Ff,sha256:()=>Ee,sha384:()=>Cf,sha512:()=>Lf,sha512_224:()=>jf,sha512_256:()=>kf});var If,we,nr,rr,or,Gi,Rf,Of,xe,be,tn,ir,sr,Uf,_f,cr,fr,Ee,Ff,Lf,Cf,kf,jf,ur=At(()=>{L();Wi();Qr();me();If=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),we=new Uint32Array(64),nr=class extends vn{constructor(e,r){super(64,e,8,!1);S(this,"A",0);S(this,"B",0);S(this,"C",0);S(this,"D",0);S(this,"E",0);S(this,"F",0);S(this,"G",0);S(this,"H",0);this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:o,D:i,E:s,F:f,G:c,H:u}=this;return[e,r,o,i,s,f,c,u]}set(e,r,o,i,s,f,c,u){this.A=e|0,this.B=r|0,this.C=o|0,this.D=i|0,this.E=s|0,this.F=f|0,this.G=c|0,this.H=u|0}_cloneInto(e){return(e||(e=new this.constructor)).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)we[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let d=we[l-15],g=we[l-2],y=Mt(d,7)^Mt(d,18)^d>>>3,m=Mt(g,17)^Mt(g,19)^g>>>10;we[l]=m+we[l-7]+y+we[l-16]|0}let{A:o,B:i,C:s,D:f,E:c,F:u,G:h,H:a}=this;for(let l=0;l<64;l++){let d=Mt(c,6)^Mt(c,11)^Mt(c,25),g=a+d+Ki(c,u,h)+If[l]+we[l]|0,m=(Mt(o,2)^Mt(o,13)^Mt(o,22))+$i(o,i,s)|0;a=h,h=u,u=c,c=f+g|0,f=s,s=i,i=o,o=g+m|0}o=o+this.A|0,i=i+this.B|0,s=s+this.C|0,f=f+this.D|0,c=c+this.E|0,u=u+this.F|0,h=h+this.G|0,a=a+this.H|0,this.set(o,i,s,f,c,u,h,a)}roundClean(){Ne(we)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ne(this.buffer)}},rr=class extends nr{constructor(){super(32,zi)}},or=class extends nr{constructor(){super(28,Zi)}},Gi=_i(["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(n=>BigInt(n))),Rf=Gi[0],Of=Gi[1],xe=new Uint32Array(80),be=new Uint32Array(80),tn=class extends vn{constructor(e,r){super(128,e,16,!1);S(this,"Ah",0);S(this,"Al",0);S(this,"Bh",0);S(this,"Bl",0);S(this,"Ch",0);S(this,"Cl",0);S(this,"Dh",0);S(this,"Dl",0);S(this,"Eh",0);S(this,"El",0);S(this,"Fh",0);S(this,"Fl",0);S(this,"Gh",0);S(this,"Gl",0);S(this,"Hh",0);S(this,"Hl",0);this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:o,Bl:i,Ch:s,Cl:f,Dh:c,Dl:u,Eh:h,El:a,Fh:l,Fl:d,Gh:g,Gl:y,Hh:m,Hl:x}=this;return[e,r,o,i,s,f,c,u,h,a,l,d,g,y,m,x]}set(e,r,o,i,s,f,c,u,h,a,l,d,g,y,m,x){this.Ah=e|0,this.Al=r|0,this.Bh=o|0,this.Bl=i|0,this.Ch=s|0,this.Cl=f|0,this.Dh=c|0,this.Dl=u|0,this.Eh=h|0,this.El=a|0,this.Fh=l|0,this.Fl=d|0,this.Gh=g|0,this.Gl=y|0,this.Hh=m|0,this.Hl=x|0}_cloneInto(e){return(e||(e=new this.constructor)).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)xe[b]=e.getUint32(r),be[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let R=xe[b-15]|0,V=be[b-15]|0,W=ke(R,V,1)^ke(R,V,8)^Gr(R,V,7),at=je(R,V,1)^je(R,V,8)^Xr(R,V,7),G=xe[b-2]|0,K=be[b-2]|0,St=ke(G,K,19)^Bn(G,K,61)^Gr(G,K,6),gt=je(G,K,19)^Sn(G,K,61)^Xr(G,K,6),_t=ki(at,gt,be[b-7],be[b-16]),Ft=ji(_t,W,St,xe[b-7],xe[b-16]);xe[b]=Ft|0,be[b]=_t|0}let{Ah:o,Al:i,Bh:s,Bl:f,Ch:c,Cl:u,Dh:h,Dl:a,Eh:l,El:d,Fh:g,Fl:y,Gh:m,Gl:x,Hh:v,Hl:_}=this;for(let b=0;b<80;b++){let R=ke(l,d,14)^ke(l,d,18)^Bn(l,d,41),V=je(l,d,14)^je(l,d,18)^Sn(l,d,41),W=l&g^~l&m,at=d&y^~d&x,G=Ni(_,V,at,Of[b],be[b]),K=Di(G,v,R,W,Rf[b],xe[b]),St=G|0,gt=ke(o,i,28)^Bn(o,i,34)^Bn(o,i,39),_t=je(o,i,28)^Sn(o,i,34)^Sn(o,i,39),Ft=o&s^o&c^s&c,ct=i&f^i&u^f&u;v=m|0,_=x|0,m=g|0,x=y|0,g=l|0,y=d|0,{h:l,l:d}=Gt(h|0,a|0,K|0,St|0),h=c|0,a=u|0,c=s|0,u=f|0,s=o|0,f=i|0;let st=Li(St,_t,ct);o=Ci(st,K,gt,Ft),i=st|0}({h:o,l:i}=Gt(this.Ah|0,this.Al|0,o|0,i|0)),{h:s,l:f}=Gt(this.Bh|0,this.Bl|0,s|0,f|0),{h:c,l:u}=Gt(this.Ch|0,this.Cl|0,c|0,u|0),{h,l:a}=Gt(this.Dh|0,this.Dl|0,h|0,a|0),{h:l,l:d}=Gt(this.Eh|0,this.El|0,l|0,d|0),{h:g,l:y}=Gt(this.Fh|0,this.Fl|0,g|0,y|0),{h:m,l:x}=Gt(this.Gh|0,this.Gl|0,m|0,x|0),{h:v,l:_}=Gt(this.Hh|0,this.Hl|0,v|0,_|0),this.set(o,i,s,f,c,u,h,a,l,d,g,y,m,x,v,_)}roundClean(){Ne(xe,be)}destroy(){this.destroyed=!0,Ne(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ir=class extends tn{constructor(){super(64,Vi)}},sr=class extends tn{constructor(){super(48,Yi)}},Uf=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),_f=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]),cr=class extends tn{constructor(){super(28,Uf)}},fr=class extends tn{constructor(){super(32,_f)}},Ee=De(()=>new rr,Pe(1)),Ff=De(()=>new or,Pe(4)),Lf=De(()=>new ir,Pe(3)),Cf=De(()=>new sr,Pe(2)),kf=De(()=>new fr,Pe(6)),jf=De(()=>new cr,Pe(5))});function xt(n,t,e=()=>{}){if(!Array.isArray(n))throw new TypeError(`"${t}" expected array, got type=${typeof n}`);for(let r=0;r<n.length;r++)e(n[r],`${t}[${r}]`);return n}function Tn(n,t=""){if(typeof n!="string"){let e=t&&`"${t}" `;throw new TypeError(e+"expected string, got type="+typeof n)}return n}function Be(n,t="object"){if(n===null||typeof n!="object"||Array.isArray(n))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof n}`);return n}function He(n,t){if(typeof n!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof n}`);return n}function Jt(n,t=""){if(typeof n!="boolean")throw new TypeError(Nf(t)+"expected boolean, got type="+typeof n);return n}function lr(n){if(typeof n=="bigint"){if(!Se(n))throw new RangeError("positive bigint expected, got "+n)}else no(n);return n}function bt(n,t=""){if(typeof n!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof n)}if(!Number.isSafeInteger(n)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+n)}}function In(n){let t=lr(n).toString(16);return t.length&1?"0"+t:t}function Qi(n){if(typeof n!="string")throw new TypeError("hex string expected, got "+typeof n);return n===""?ar:BigInt("0x"+n)}function Et(n){return Qi(er(n))}function nn(n){return Qi(er(dr(Xt(n)).reverse()))}function hr(n,t){if(ae(t),t===0)throw new Error("zero output length is invalid");n=lr(n);let e=t*2,r=n.toString(16);if(r.length>e)throw new RangeError("number is too large");return to(r.padStart(e,"0"))}function ro(n,t){return hr(n,t).reverse()}function dr(n){return Uint8Array.from(Z(n))}function rn(n){if(typeof n!="string")throw new TypeError("ascii string expected, got "+typeof n);return Uint8Array.from(n,(t,e)=>{let r=t.charCodeAt(0);if(t.length!==1||r>127)throw new RangeError(`string contains non-ASCII character "${n[e]}" with code ${r} at position ${e}`);return r})}function Se(n){return typeof n=="bigint"&&ar<=n}function oo(n,t,e){return Se(n)&&Se(t)&&Se(e)&&t<=n&&n<e}function io(n,t,e,r){if(!oo(t,e,r))throw new RangeError("expected valid "+n+": "+e+" <= n < "+r+", got "+t)}function on(n){if(n<ar)throw new Error("expected non-negative bigint, got "+n);return n===ar?0:n.toString(2).length}function Ji(n,t,e){if(ae(n,"hashLen"),ae(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let r=m=>new Uint8Array(m),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),f=1e3,c=r(n),u=r(n),h=0,a=()=>{c.fill(1),u.fill(0),h=0},l=(...m)=>e(u,ut(c,...m)),d=(m=o)=>{u=l(i,m),c=l(),m.length!==0&&(u=l(s,m),c=l())},g=()=>{if(h++>=f)throw new Error("drbg: tried max amount of iterations");let m=0,x=[];for(;m<t;){c=l();let v=c.slice();x.push(v),m+=c.length}return ut(...x)};return(m,x)=>{a(),d(m);let v;for(;(v=x(g()))===void 0;)d();return a(),v}}function ht(n,t={},e={},r="object"){Be(n,r),Be(t,"fields"),Be(e,"optFields");function o(s,f,c){let u=r==="object"?`param "${String(s)}"`:`"${r}.${String(s)}"`,h=n[s];if(!Object.hasOwn(n,s)&&(c?h!==void 0:f!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&h===void 0)return;let a=typeof h;if(a!==f||h===null)throw new TypeError(`${u} is invalid: expected ${f}, got ${a}`)}let i=(s,f)=>Object.entries(s).forEach(([c,u])=>o(c,u,f));i(t,!1),i(e,!0)}var Z,no,he,ut,en,Qt,Lt,ar,Xi,Nf,Rn,Ae=At(()=>{L();me();Z=(n,t,e)=>Xt(n,t,e),no=ae;he=er,ut=(...n)=>Mi(...n),en=n=>to(n),Qt=Xn,Lt=n=>An(n),ar=BigInt(0),Xi=BigInt(1),Nf=n=>n?`"${n}" `:"";Rn=n=>(bt(n,"n"),(Xi<<BigInt(n))-Xi)});function Ct(n,t){if(t<=Bt)throw new Error("mod: expected positive modulus, got "+t);let e=n%t;return e>=Bt?e:t+e}function ss(n,t,e){if(e<=lt)throw new Error("pow: expected modulus > 1, got "+e);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<Bt)throw new Error("invalid exponent, negatives unsupported");if(t===Bt)return lt;if(t===lt)return n;let r=n%e;if(r<Bt&&(r+=e),t<qf){let f=lt;for(;t>Bt;)t&lt&&(f=f*r%e),r=r*r%e,t>>=lt;return f}let o=[];for(;t>Bt;)o.push(Number(t&Hf)),t>>=co;let i=new Array(16);i[0]=lt,i[1]=r;for(let f=2;f<16;f++)i[f]=i[f-1]*r%e;let s=i[o[o.length-1]];for(let f=o.length-2;f>=0;f--){s=s*s%e,s=s*s%e,s=s*s%e,s=s*s%e;let c=o[f];c!==0&&(s=s*i[c]%e)}return s}function Nt(n,t,e){if(e<=lt)throw new Error("pow2: expected modulus > 1, got "+e);if(t<Bt)throw new Error("pow2: expected non-negative exponent, got "+t);let r=n;for(;t-- >Bt;)r*=r,r%=e;return r}function ts(n,t){if(n===Bt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected modulus > 1, got "+t);let e=Ct(n,t),r=t,o=Bt,i=lt;for(;e!==Bt;){let f=r/e,c=r-e*f,u=o-i*f;r=e,e=c,o=i,i=u}if(r!==lt)throw new Error("invert: does not exist");return Ct(o,t)}function cs(n,t){if(t<=lt)throw new Error("invertCt: expected prime modulus > 1, got "+t);let e=Ct(n,t);if(e===Bt)throw new Error("invertCt: expected non-zero number");let r=ss(e,t-ve,t);if(Ct(e*r,t)!==lt)throw new Error("invertCt: does not exist");return r}function fo(n,t,e){let r=n;if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function uo(n,t){if((n&lt)===Bt)throw new Error(t+": expected odd modulus, got "+n)}function fs(n,t){let e=n,r=(e.ORDER+lt)/co,o=e.pow(t,r);return fo(e,o,t),o}function Mf(n,t){let e=n,r=(e.ORDER-rs)/os,o=e.mul(t,ve),i=e.pow(o,r),s=e.mul(t,i),f=e.mul(e.mul(s,ve),i),c=e.mul(s,e.sub(f,e.ONE));return fo(e,c,t),c}function Kf(n){let t=cn(n),e=us(n),r=e(t,t.neg(t.ONE)),o=e(t,r),i=e(t,t.neg(r)),s=(n+Df)/is;return((f,c)=>{let u=f,h=u.pow(c,s),a=u.mul(h,r),l=u.mul(h,o),d=u.mul(h,i),g=u.eql(u.sqr(a),c),y=u.eql(u.sqr(l),c);h=u.cmov(h,a,g),a=u.cmov(d,l,y);let m=u.eql(u.sqr(a),c),x=u.cmov(h,a,m);return fo(u,x,c),x})}function us(n){if(n<ns)throw new Error("sqrt is not defined for small field");uo(n,"tonelliShanks");let t=n-lt,e=0;for(;t%ve===Bt;)t/=ve,e++;let r=ve,o=cn(n);for(;so(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return fs;let i=o.pow(r,t),s=(t+lt)/ve;return function(c,u){let h=c;if(h.is0(u))return u;if(so(h,u)!==1)throw new Error("Cannot find square root");let a=e,l=h.mul(h.ONE,i),d=h.pow(u,t),g=h.pow(u,s);for(;!h.eql(d,h.ONE);){if(h.is0(d))throw new Error("Cannot find square root: probably non-prime P");let y=1,m=h.sqr(d);for(;!h.eql(m,h.ONE);)if(y++,m=h.sqr(m),y===a)throw new Error("Cannot find square root");let x=lt<<BigInt(a-y-1),v=h.pow(l,x);a=y,l=h.sqr(v),d=h.mul(d,l),g=h.mul(g,v)}return g}}function $f(n){return uo(n,"Fp.sqrt"),n%co===ns?fs:n%os===rs?Mf:n%is===Pf?Kf(n):us(n)}function Ht(n){if(Be(n,"field"),typeof n.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof n.ORDER);bt(n.BYTES,"BYTES"),bt(n.BITS,"BITS");for(let t of zf)He(n[t],"field."+t);if(n.BYTES<1||n.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(n.ORDER<=lt)throw new Error("invalid field: expected ORDER > 1, got "+n.ORDER);return n}function sn(n,t,e=!1){Ht(n),xt(t,"nums"),Jt(e,"passZero");let r=n,o=new Array(t.length).fill(e?r.ZERO:void 0),i=t.reduce((f,c,u)=>r.is0(c)?f:(o[u]=f,r.mul(f,c)),r.ONE),s=r.inv(i);return t.reduceRight((f,c,u)=>r.is0(c)?f:(o[u]=r.mul(f,o[u]),r.mul(f,c)),s),o}function so(n,t){Ht(n);let e=n;uo(e.ORDER,"FpLegendre");let r=(e.ORDER-lt)/ve,o=e.pow(t,r),i=e.eql(o,e.ONE),s=e.eql(o,e.ZERO),f=e.eql(o,e.neg(e.ONE));if(!i&&!s&&!f)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function ao(n,t){return so(n,t)!==-1}function Zf(n,t){if(t!==void 0&&no(t),n<=Bt)throw new Error("invalid n length: expected positive n, got "+n);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=on(n);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${e})`);let r=t!==void 0?t:e,o=Math.ceil(r/8);return{nBitLength:r,nByteLength:o}}function cn(n,t={}){return Object.freeze(pr.prototype),new pr(n,t)}function as(n){if(typeof n!="bigint")throw new Error("field order must be bigint");if(n<=lt)throw new Error("field order must be greater than 1");let t=on(n-lt);return Math.ceil(t/8)}function fn(n){let t=as(n);return t+Math.ceil(t/2)}function qe(n,t,e=!1){Z(n);let r=n.length,o=as(t),i=Math.max(fn(t),16);if(r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);let s=e?nn(n):Et(n),f=Ct(s,t-lt)+lt;return e?ro(f,o):hr(f,o)}var Bt,lt,ve,ns,co,rs,Df,os,Pf,Hf,is,qf,zf,es,pr,Me=At(()=>{L();Ae();Bt=BigInt(0),lt=BigInt(1),ve=BigInt(2),ns=BigInt(3),co=BigInt(4),rs=BigInt(5),Df=BigInt(7),os=BigInt(8),Pf=BigInt(9),Hf=BigInt(15),is=BigInt(16),qf=BigInt("0x10000000000000000");zf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];es=new WeakMap,pr=class{constructor(t,e={}){S(this,"ORDER");S(this,"BITS");S(this,"BYTES");S(this,"isLE");S(this,"ZERO",Bt);S(this,"ONE",lt);S(this,"_lengths");S(this,"_mod");if(t<=lt)throw new Error("invalid field: expected ORDER > 1, got "+t);let r;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(r=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:i}=Zf(t,r);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(t){return Ct(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return Bt<=t&&t<this.ORDER}is0(t){return t===Bt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&lt)===lt}neg(t){return Ct(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Ct(t*t,this.ORDER)}add(t,e){return Ct(t+e,this.ORDER)}sub(t,e){return Ct(t-e,this.ORDER)}mul(t,e){return Ct(t*e,this.ORDER)}pow(t,e){return ss(t,e,this.ORDER)}div(t,e){return Ct(t*ts(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return ts(t,this.ORDER)}sqrt(t){let e=es.get(this);return e||es.set(this,e=$f(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ro(t,this.BYTES):hr(t,this.BYTES)}fromBytes(t,e=!1){Z(t);let{_lengths:r,BYTES:o,isLE:i,ORDER:s,_mod:f}=this;if(r){if(t.length<1||!r.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?nn(t):Et(t);if(f&&(c=Ct(c,s)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return sn(this,t,!0)}cmov(t,e,r){return Jt(r,"condition"),r?e:t}}});function Te(n){let t=n;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof n);He(t.fromAffine,"Point.fromAffine"),He(t.fromBytes,"Point.fromBytes"),He(t.fromHex,"Point.fromHex"),Be(t.BASE,"Point.BASE"),Be(t.ZERO,"Point.ZERO"),Ht(t.Fp),Ht(t.Fn)}function ps(n,t){Te(n),gs(t,n);let e=sn(n.Fp,t.map(r=>r.Z));return t.map((r,o)=>n.fromAffine(r.toAffine(e[o])))}function Wf(n,t,e=1){if(!Number.isSafeInteger(n)||n<e||n>t)throw new Error("invalid window size, expected ["+e+".."+t+"], got W="+n)}function Gf(n,t){let e=n*(4*t+128);if(e>hs)throw new Error("invalid window size: table would need ~"+Math.ceil(e/2**20)+" MiB, max "+hs/2**20+" MiB")}function go(n,t){if(n!==void 0){He(n,"randomBytes");try{let e=n(t);if(!Qt(e)||e.length!==t)return}catch{return}return n}}function gs(n,t){xt(n,"points"),n.forEach((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)})}function Xf(n,t,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((r,o)=>{if(!(e===void 0?t.isValid(r):Se(r)&&r<e))throw new Error("invalid scalar at index "+o)})}function ho(n){return ys.get(n)||1}function Qf(n,t){let e=n.double(),r=[n];for(let o=1;o<t;o++)r.push(r[o-1].add(e));return r}function Jf(n,t){let e=2**t,r=e/2,o=BigInt(e-1),i=[];for(;n>po;){let s=0;n&On&&(s=Number(n&o),s>=r&&(s-=e),n-=BigInt(s)),i.push(s),n>>=On}return i}function tu(n,t,e){let r=2**t,o=r/2,i=BigInt(r-1),s=BigInt(t),f=[];for(let c=0;c<e;c++){let u=Number(n&i);n>>=s,u>o&&(u-=r,n+=On),f.push(u)}if(n!==po)throw new Error("invalid wnaf");return f}function eu(n,t,e){let r=0;for(let i of e)r=Math.max(r,i.length);let o=n;for(let i=r-1;i>=0;i--){i!==r-1&&(o=o.double());for(let s=0;s<e.length;s++){let f=e[s][i];if(f){let c=t[s][Math.abs(f)-1>>1];o=o.add(f<0?c.negate():c)}}}return o}function un(n,t,e,r=!1){if(Te(n),gs(t,n),Jt(r,"allowOversized"),Xf(e,n.Fn,r?n.Fn.ORDER**Yf:void 0),t.length!==e.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(s=>Qf(s,4)),i=e.map(s=>Jf(s,4));return eu(n.ZERO,o,i)}function ds(n,t,e){if(t){if(t.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ht(t),t}else return cn(n,{isLE:e})}function ms(n,t,e={},r){if(n!=="weierstrass"&&n!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(r===void 0&&(r=n==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${n} CURVE object`);ht(e);for(let c of["p","n","h"]){let u=t[c];if(!(Se(u)&&u!==po))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ds(t.p,e.Fp,r),i=ds(t.n,e.Fn,r),f=["Gx","Gy","a",n==="weierstrass"?"b":"d"];for(let c of f)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function yr(n,t){return function(r){let o=n(r);return{secretKey:o,publicKey:t(o)}}}var po,On,Yf,lo,ls,Vf,hs,ys,gr,mr=At(()=>{L();Ae();Me();po=BigInt(0),On=BigInt(1),Yf=BigInt(4),lo=16,ls=128,Vf=5,hs=2**31;ys=new WeakMap;gr=class{constructor(t,e){S(this,"Point");S(this,"BASE");S(this,"ZERO");S(this,"randomBytes");S(this,"wnafPrecomputes",new WeakMap);S(this,"baseCanBeBlinded");S(this,"bits");Te(t),this.randomBytes=go(e,lo),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,e,r){let o=Math.ceil(r/e)+1,i=2**(e-1),s=[],f=t;for(let c=0;c<o;c++){let u=f;for(let h=0;h<i;h++)s.push(u),u=u.add(f);f=s[s.length-1].double()}return{W:e,bits:r,windows:o,comp:s}}wnafCachedCT(t,e){let{W:r,windows:o,comp:i}=t,s=2**(r-1),f=tu(e,r,o),c=this.ZERO,u=this.BASE;for(let h=0;h<o;h++){let a=f[h],l=h*s,d=Math.abs(a)-1,g=i[l];for(let m=1;m<s;m++)g=m===d?i[l+m]:g;let y=g.negate();a===0?u=u.add(i[l]):c=c.add(a<0?y:g)}return{p:c,f:u}}getWnafPrecomputes(t,e,r,o){let i=this.wnafPrecomputes.get(e),s=i?.find(f=>f.W===t&&f.bits===r);return s||(s=this.buildWnafTable(e,t,r),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(e,i)),i.push(s)),s}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,e){if(this.assertPoint(t),!oo(e,On,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,e,r,o){let i=ho(t);return i===1?this.fixedWindowCT(t,e,r):this.wnafCachedCT(this.getWnafPrecomputes(i,t,r,o),e)}mulCT(t,e,r){return this.validateMulInput(t,e),this.runCT(t,e,this.bits,r)}mulCTBlinded(t,e,r){if(this.validateMulInput(t,e),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+ls,i=this.randomBytes(lo);if(!Qt(i)||i.length!==lo)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=e+Et(i)*this.Point.Fn.ORDER;return this.runCT(t,s,o,r)}fixedWindowCT(t,e,r){let o=Vf,i=1<<o,s=Rn(o),f=new Array(i);f[0]=this.ZERO;for(let h=1;h<i;h++)f[h]=f[h-1].add(t);let c=Math.ceil(r/o),u=this.ZERO;for(let h=c-1;h>=0;h--){if(h!==c-1)for(let d=0;d<o;d++)u=u.double();let a=Number(e>>BigInt(h*o)&s),l=f[0];for(let d=1;d<i;d++)l=d===a?f[d]:l;u=u.add(l)}return{p:u,f:u}}shouldBlind(t,e){return this.randomBytes===void 0?!1:e===On?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,e,r,o){return this.shouldBlind(t,r)?this.mulCTBlinded(t,e,o):this.mulCT(t,e,o)}mulUnsafe(t,e,r){if(this.assertPoint(t),!Se(e))throw new Error("invalid scalar");let o=ho(t);if(o===1||e>=this.Point.Fn.ORDER)return un(this.Point,[t],[e],!0);let i=this.getWnafPrecomputes(o,t,this.bits,r);return this.wnafCachedCT(i,e).p}setWindowSize(t,e){this.assertPoint(t),Wf(e,this.bits);let r=Math.ceil((this.bits+ls)/e)+1;Gf(r*2**(e-1),this.Point.Fp.BYTES),ys.set(t,e),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return ho(t)!==1}}});function yo(n,t="n"){if(typeof n!="number")throw new TypeError(`wrong u32 integer "${t}": expected number, got type=${typeof n}`);if(!Number.isSafeInteger(n)||n<0||n>4294967295)throw new RangeError(`wrong u32 integer "${t}": expected 0..4294967295, got ${n}`);return n}function ws(n){return yo(n,"x"),(n&n-1)===0&&n!==0}function nu(n){if(yo(n),n<=1)return 1;if(n>2147483648)throw new Error("nextPowerOfTwo overflow: result does not fit u32");return 1<<wr(n-1)+1>>>0}function wr(n){return yo(n),31-Math.clz32(n)}function xs(n,t,e,r,o){Ht(n);let i=n,s=e||((a,l)=>new Array(a).fill(l??i.ZERO)),f=a=>{if(Array.isArray(a))return!0;if(!ArrayBuffer.isView(a))return!1;let l=a;return typeof l.length=="number"&&typeof l.slice=="function"&&typeof l[Symbol.iterator]=="function"},c=(a,l)=>{if(!f(l))throw new TypeError(`"${a}" expected polynomial, got type=${typeof l}`)},u=(a,l)=>{c("a",a);let d=a.length;if(l!==void 0&&(c("b",l),l.length!==d))throw new Error(`poly: mismatched lengths ${d} vs ${l.length}`);if(o!==void 0&&d!==o)throw new Error(`poly: expected fixed length ${o}, got ${d}`);return d};function h(a,l,d=!1,g){if(!ws(l))throw new Error("poly.lagrange: expected power of two length, got "+l);let y=g||(d?t.brp(wr(l)):t.roots(wr(l)));for(let m=0;m<l;m++)if(i.eql(a,y[m]))return m;return-1}return{roots:t,create:s,length:o,extend:(a,l)=>{u(a);let d=s(l,i.ZERO);for(let g=0;g<Math.min(a.length,l);g++)d[g]=a[g];return d},degree:a=>{u(a);for(let l=a.length-1;l>=0;l--)if(!i.is0(a[l]))return l;return-1},add:(a,l)=>{let d=u(a,l),g=s(d);for(let y=0;y<d;y++)g[y]=i.add(a[y],l[y]);return g},sub:(a,l)=>{let d=u(a,l),g=s(d);for(let y=0;y<d;y++)g[y]=i.sub(a[y],l[y]);return g},dot:(a,l)=>{let d=u(a,l),g=s(d);for(let y=0;y<d;y++)g[y]=i.mul(a[y],l[y]);return g},mul:(a,l)=>{if(f(l)){let d=u(a,l);if(r){let g=r.direct(a,!1,!0),y=r.direct(l,!1,!0);for(let m=0;m<g.length;m++)g[m]=i.mul(g[m],y[m]);return r.inverse(g,!0,!1)}else{let g=s(d);for(let y=0;y<d;y++)for(let m=0;m<d;m++){let x=(y+m)%d;g[x]=i.add(g[x],i.mul(a[y],l[m]))}return g}}else{let d=s(u(a));for(let g=0;g<d.length;g++)d[g]=i.mul(a[g],l);return d}},convolve(a,l){c("a",a),c("b",l);let d=nu(a.length+l.length-1);return this.mul(this.extend(a,d),this.extend(l,d))},shift(a,l){c("p",a);let d=s(a.length);if(o!==void 0&&a.length!==o)throw new Error(`poly: expected fixed length ${o}, got ${a.length}`);if(!a.length)return d;d[0]=a[0];for(let g=1,y=i.ONE;g<a.length;g++)y=i.mul(y,l),d[g]=i.mul(a[g],y);return d},clone:a=>{u(a);let l=s(a.length);for(let d=0;d<a.length;d++)l[d]=a[d];return l},eval:(a,l)=>{u(a,l);let d=i.ZERO;for(let g=0;g<a.length;g++)d=i.add(d,i.mul(a[g],l[g]));return d},monomial:{basis:(a,l)=>{let d=s(l),g=i.ONE;for(let y=0;y<l;y++)d[y]=g,g=i.mul(g,a);return d},eval:(a,l)=>{u(a);let d=i.ZERO;for(let g=a.length-1;g>=0;g--)d=i.add(i.mul(d,l),a[g]);return d}},lagrange:{basis:(a,l,d=!1,g)=>{if(!ws(l))throw new Error("poly.lagrange: expected power of two length, got "+l);let y=wr(l),m=g||(d?t.brp(y):t.roots(y)),x=s(l),v=h(a,l,d,g);if(v!==-1)return x[v]=i.ONE,x;let _=i.pow(a,BigInt(l)),b=i.mul(i.sub(_,i.ONE),i.inv(BigInt(l))),R=s(l);for(let W=0;W<l;W++)R[W]=i.sub(a,m[W]);let V=i.invertBatch(R);for(let W=0;W<l;W++)x[W]=i.mul(b,i.mul(m[W],V[W]));return x},eval(a,l,d=!1){u(a);let g=h(l,a.length,d);if(g!==-1)return a[g];let y=this.basis(l,a.length,d),m=i.ZERO;for(let x=0;x<a.length;x++)i.is0(a[x])||(m=i.add(m,i.mul(a[x],y[x])));return m}},vanishing(a){if(c("roots",a),o!==void 0&&a.length!==o)throw new Error(`poly: expected fixed length ${o}, got ${a.length}`);let l=s(a.length+1,i.ZERO);l[0]=i.ONE;for(let d of a){let g=i.neg(d);for(let y=l.length-1;y>0;y--)l[y]=i.add(i.mul(l[y],g),l[y-1]);l[0]=i.mul(l[0],g)}return l}}}var bs=At(()=>{L();Me()});function Ke(n,t){if(bt(n),bt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(n<0||n>2**(8*t)-1)throw new Error("invalid I2OSP input: "+n);let e=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)e[r]=n&255,n>>>=8;return new Uint8Array(e)}function ou(n,t){let e=new Uint8Array(n.length);for(let r=0;r<n.length;r++)e[r]=n[r]^t[r];return e}function As(n){if(!Qt(n)&&typeof n!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof n=="string"?rn(n):n;if(t.length===0)throw new Error("DST must be non-empty");return t}function iu(n,t,e,r){if(Z(n),bt(e),typeof r!="function")throw new Error("expand_message_xmd: expected hash function");bt(r.outputLen,"hash.outputLen"),bt(r.blockLen,"hash.blockLen"),t=As(t),t.length>255&&(t=r(ut(rn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:i}=r,s=Math.ceil(e/o);if(e>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let f=ut(t,Ke(t.length,1)),c=new Uint8Array(i),u=Ke(e,2),h=new Array(s),a=r(ut(c,n,u,Ke(0,1),f));h[0]=r(ut(a,Ke(1,1),f));for(let d=1;d<s;d++){let g=[ou(a,h[d-1]),Ke(d+1,1),f];h[d]=r(ut(...g))}return ut(...h).slice(0,e)}function su(n,t,e,r,o){if(Z(n),bt(e),bt(r,"k"),r<0)throw new Error("expand_message_xof: invalid k");if(typeof o!="function")throw new Error("expand_message_xof: expected XOF function");if(typeof o.create!="function")throw new Error("expand_message_xof: expected XOF create");if(t=As(t),e<0||e>65535)throw new Error("expand_message_xof: invalid lenInBytes");if(t.length>255){let i=Math.ceil(2*r/8);t=o.create({dkLen:i}).update(rn("H2C-OVERSIZE-DST-")).update(t).digest()}if(t.length>255)throw new Error("expand_message_xof: invalid DST");return o.create({dkLen:e}).update(n).update(Ke(e,2)).update(t).update(Ke(t.length,1)).digest()}function mo(n,t,e){ht(e,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:r,k:o,m:i,hash:s,expand:f,DST:c}=e;if(bt(s.outputLen,"valid hash"),Z(n),bt(t),bt(i,"m"),bt(o,"k"),r<=BigInt(1))throw new Error("hash_to_field: expected valid field characteristic");if(t<1)throw new Error("hash_to_field: expected count >= 1");if(i<1)throw new Error("hash_to_field: expected m >= 1");if(o<0)throw new Error("hash_to_field: invalid k");let u=r.toString(2).length,h=Math.ceil((u+o)/8),a=t*i*h,l;if(f==="xmd")l=iu(n,c,a,s);else if(f==="xof")l=su(n,c,a,o,s);else if(f==="_internal_pass")l=n;else throw new Error('expand must be "xmd" or "xof"');let d=new Array(t);for(let g=0;g<t;g++){let y=new Array(i);for(let m=0;m<i;m++){let x=h*(m+g*i),v=l.subarray(x,x+h);y[m]=Ct(ru(v),r)}d[g]=y}return d}function vs(n,t){Ht(n),xt(t,"map");let e=t.map((r,o)=>{if(xt(r,"map["+o+"]"),r.length<1)throw new Error("isogenyMap: expected non-empty coefficients");return Array.from(r).reverse()});return(r,o)=>{let[i,s,f,c]=e.map(l=>l.reduce((d,g)=>n.add(n.mul(d,r),g))),u=n.is0(s)||n.is0(c),[h,a]=sn(n,[s,c],!0);return r=n.mul(i,h),o=n.mul(o,n.mul(f,a)),u?{x:n.ZERO,y:n.ZERO}:{x:r,y:o}}}function Ts(n,t,e){if(typeof t!="function")throw new Error("mapToCurve() must be defined");ht(e);let r=c=>Object.freeze({...c,DST:Qt(c.DST)?dr(c.DST):c.DST,...c.encodeDST===void 0?{}:{encodeDST:Qt(c.encodeDST)?dr(c.encodeDST):c.encodeDST}}),o=r(e),i=c=>c&&c.DST!==void 0?{DST:c.DST}:void 0;function s(c){return n.fromAffine(t(c))}function f(c){let u=c.clearCofactor();return u.equals(n.ZERO)?n.ZERO:(u.assertValidity(),u)}return Object.freeze({get defaults(){return r(o)},Point:n,hashToCurve(c,u){let h=Object.assign({},o,i(u)),a=mo(c,2,h),l=s(a[0]),d=s(a[1]);return f(l.add(d))},encodeToCurve(c,u){let h=o.encodeDST===void 0?{}:{DST:o.encodeDST},a=Object.assign({},o,h,i(u)),l=mo(c,1,a),d=s(l[0]);return f(d)},mapToCurve(c){if(o.m===1){if(typeof c!="bigint")throw new Error("expected bigint (m=1)");return f(s([c]))}if(!Array.isArray(c))throw new Error("expected array of bigints");if(c.length!==o.m)throw new Error(`expected array of ${o.m} bigints`);for(let u of c)if(typeof u!="bigint")throw new Error("expected array of bigints");return f(s(c))},hashToScalar(c,u){let h=n.Fn.ORDER,a=Object.assign({},o,{DST:cu},i(u),{p:h,m:1});return mo(c,1,a)[0][0]}})}function fu(n,t){let e=Ht(n),r=e.ORDER,o=Es;for(let y=r-te;y%Ie===Es;y/=Ie)o+=te;let i=o,s=Ie<<i-te-te,f=s*Ie,c=(r-te)/f,u=(c-te)/Ie,h=f-te,a=s,l=e.pow(t,c),d=e.pow(t,(c+te)/Ie),g=(y,m)=>{let x=l,v=e.pow(m,h),_=e.sqr(v);_=e.mul(_,m);let b=e.mul(y,_);b=e.pow(b,u),b=e.mul(b,v),v=e.mul(b,m),_=e.mul(b,y);let R=e.mul(_,v);b=e.pow(R,a);let V=e.eql(b,e.ONE);v=e.mul(_,d),b=e.mul(R,x),_=e.cmov(v,_,V),R=e.cmov(b,R,V);for(let W=i;W>te;W--){let at=W-Ie;at=Ie<<at-te;let G=e.pow(R,at),K=e.eql(G,e.ONE);v=e.mul(_,x),x=e.mul(x,x),G=e.mul(R,x),_=e.cmov(v,_,K),R=e.cmov(G,R,K)}return{isValid:!e.is0(m)&&(V||e.is0(y)),value:_}};if(e.ORDER%Ss===Bs){let y=(e.ORDER-Bs)/Ss,m=e.sqrt(e.neg(t));g=(x,v)=>{let _=e.sqr(v),b=e.mul(x,v);_=e.mul(_,b);let R=e.pow(_,y);R=e.mul(R,b);let V=e.mul(R,m),W=e.mul(e.sqr(R),v),at=e.eql(W,x),G=e.cmov(V,R,at);return{isValid:!e.is0(v)&&at,value:G}}}return g}function Is(n,t){let e=Ht(n);ht(t,{},{},"opts");let{A:r,B:o,Z:i}=t;if(!e.isValidNot0(r)||!e.isValidNot0(o)||!e.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");if(e.eql(i,e.neg(e.ONE))||ao(e,i))throw new Error("mapToCurveSimpleSWU: invalid opts");let s=e.mul(o,e.inv(e.mul(i,r))),f=e.add(e.add(e.mul(e.sqr(s),s),e.mul(r,s)),o);if(!ao(e,f))throw new Error("mapToCurveSimpleSWU: invalid opts");let c=fu(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return u=>{let h,a,l,d,g,y,m,x;h=e.sqr(u),h=e.mul(h,i),a=e.sqr(h),a=e.add(a,h),l=e.add(a,e.ONE),l=e.mul(l,o),d=e.cmov(i,e.neg(a),!e.eql(a,e.ZERO)),d=e.mul(d,r),a=e.sqr(l),y=e.sqr(d),g=e.mul(y,r),a=e.add(a,g),a=e.mul(a,l),y=e.mul(y,d),g=e.mul(y,o),a=e.add(a,g),m=e.mul(h,l);let{isValid:v,value:_}=c(a,y);x=e.mul(h,u),x=e.mul(x,_),m=e.cmov(m,l,v),x=e.cmov(x,_,v);let b=e.isOdd(u)===e.isOdd(x);x=e.cmov(e.neg(x),x,b);let R=sn(e,[d],!0)[0];return m=e.mul(m,R),{x:m,y:x}}}var Es,te,Ie,Bs,Ss,ru,cu,Rs=At(()=>{L();Ae();Me();Es=BigInt(0),te=BigInt(1),Ie=BigInt(2),Bs=BigInt(3),Ss=BigInt(4),ru=Et;cu="HashToScalar-"});function wo(n){ht(n,{name:"string",hash:"function"},{hashToScalar:"function",validatePoint:"function",parsePublicKey:"function",adjustScalar:"function",adjustPoint:"function",challenge:"function",adjustNonces:"function",adjustSecret:"function",adjustPublic:"function",adjustGroupCommitmentShare:"function",adjustDKG:"function"}),Te(n.Point);let{Point:t}=n,e=n.Fn===void 0?t.Fn:n.Fn,r=n.hash,o=n.hashToScalar===void 0?(p,w={DST:new Uint8Array})=>{let B=r(ut(w.DST,p));return e.create(e.isLE?nn(B):Et(B))}:n.hashToScalar,i=le(n.H1!==void 0?n.H1:n.name+"rho"),s=le(n.H2!==void 0?n.H2:n.name+"chal"),f=le(n.H3!==void 0?n.H3:n.name+"nonce"),c=le(n.H4!==void 0?n.H4:n.name+"msg"),u=le(n.H5!==void 0?n.H5:n.name+"com"),h=le(n.HDKG!==void 0?n.HDKG:n.name+"dkg"),a=le(n.HID!==void 0?n.HID:n.name+"id"),l=p=>o(p,{DST:i}),d=p=>o(p,{DST:s}),g=p=>o(p,{DST:f}),y=p=>r(ut(c,p)),m=p=>r(ut(u,p)),x=p=>o(p,{DST:h}),v=p=>o(p,{DST:a}),_=(p=Lt)=>{if(typeof p!="function")throw new TypeError('"rng" expected function, got type='+typeof p);let w=qe(p(fn(e.ORDER)),e.ORDER,e.isLE);return e.isLE?nn(w):Et(w)},b=p=>p.toBytes(),R=p=>{let w=t.fromBytes(p);return n.validatePoint&&n.validatePoint(w),w},V=(p,w)=>({identifier:p,hiding:b(t.BASE.multiply(e.fromBytes(w.hiding))),binding:b(t.BASE.multiply(e.fromBytes(w.binding)))}),W=n.adjustPoint===void 0?p=>p:n.adjustPoint,at=p=>{if(!e.isValid(p)||e.is0(p))throw new Error("Invalid identifier "+p);return p},G=p=>he(e.toBytes(at(p))),K=(p,w="identifier")=>{Tn(p,w);let B=at(e.fromBytes(en(p)));if(G(B)!==p)throw new Error("expected canonical identifier hex");return B},St={encode:(p,w)=>{let B=ut(b(p),e.toBytes(w));return n.adjustTx&&(B=n.adjustTx.encode(B)),B},decode:p=>{n.adjustTx&&(p=n.adjustTx.decode(p));let w=p.subarray(0,-e.BYTES),B=R(w);if(b(B).length!==w.length)throw new Error("invalid signature encoding");let A=e.fromBytes(p.subarray(-e.BYTES));return{R:B,z:A}}},gt=(p=Lt)=>{let w=_(p);n.adjustScalar&&(w=n.adjustScalar(w));let B=t.BASE.multiply(w);return{scalar:w,point:B}},_t="roots are unavailable in FROST polynomial mode",Ft={info:{G:e.ZERO,oddFactor:e.ZERO,powerOfTwo:0},roots(){throw new Error(_t)},brp(){throw new Error(_t)},inverse(){throw new Error(_t)},omega(){throw new Error(_t)},clear(){}},ct=xs(e,Ft),st=(p,w)=>un(t,p,w),I=(p,w)=>{if(!w.length)throw new Error("empty coefficients");return ct.monomial.eval(w,p)},C=(p,w)=>{let B="invalid parameters";if(!p.some(D=>e.eql(D,w)))throw new Error(B);let A=new Set(p);if(A.size!==p.length)throw new Error(B);if(!A.has(w))throw new Error(B);let F=e.ONE,k=e.ONE;for(let D of p)e.eql(D,w)||(F=e.mul(F,D),k=e.mul(k,e.sub(D,w)));return e.div(F,k)},N=(p,w)=>{let B=ct.monomial.basis(p,w.length);return st(w,B)},U=(p,w,B,A=Lt)=>{if(ee(p),w!==void 0&&Z(w,e.BYTES,"secret"),B!==void 0&&xt(B,"coeffs"),typeof A!="function")throw new TypeError('"rng" expected function, got type='+typeof A);let F=w===void 0?_(A):e.fromBytes(w);if(!B){B=[];for(let H=0;H<p.min-1;H++)B.push(_(A))}if(B.length!==p.min-1)throw new Error("wrong coefficients length");let k=[F,...B],D=k.map(H=>t.BASE.multiply(H));return{coefficients:k,commitment:D,secret:F}},T={challenge:(p,w,B)=>x(ut(e.toBytes(p),b(w),b(B))),compute(p,w,B,A=Lt){if(w.length<1)throw new Error("coefficients should have at least one element");let{point:F,scalar:k}=gt(A),D=B[0],H=this.challenge(p,D,F),rt=e.add(k,e.mul(w[0],H));return St.encode(F,rt)},validate(p,w,B){if(w.length<1)throw new Error("commitment should have at least one element");let{R:A,z:F}=St.decode(B),k=R(w[0]),D=this.challenge(p,k,A);if(!A.equals(t.BASE.multiplyUnsafe(F).subtract(k.multiplyUnsafe(D))))throw new Error("invalid proof of knowledge")}},O={challenge:(p,w,B)=>n.challenge?n.challenge(p,w,B):d(ut(b(p),b(w),B)),sign(p,w,B=Lt){let{point:A,scalar:F}=gt(B),k=t.BASE.multiply(w),D=this.challenge(A,k,p),H=e.add(F,e.mul(D,w));return[A,H]},verify(p,w,B,A){n.adjustPoint&&(A=n.adjustPoint(A)),n.adjustPoint&&(w=n.adjustPoint(w));let F=this.challenge(w,A,p),k=t.BASE.multiplyUnsafe(B),D=A.multiplyUnsafe(F),H=k.subtract(D).subtract(w);return H.clearCofactor&&(H=H.clearCofactor()),t.ZERO.equals(H)}},j=(p,w,B)=>{if(!t.BASE.multiply(B).equals(N(p,w)))throw new Error("invalid secret share")},P={fromNumber(p){if(!Number.isSafeInteger(p))throw new Error("expected safe interger");return G(BigInt(p))},derive(p){return Tn(p,"s"),G(v(le(p)))}},$=(p,w=Lt)=>g(ut(w(32),e.toBytes(p))),z=(p,w,B)=>{let A=w.map(q=>[q.identifier,K(q.identifier),R(q.hiding),R(q.binding)]);A.sort((q,yt)=>q[1]<yt[1]?-1:q[1]>yt[1]?1:0);let F=[];for(let[q,yt,Rt,qt]of A)F.push(e.toBytes(yt),b(Rt),b(qt));let k=m(ut(...F)),D=ut(b(p),y(B),k),H={};for(let[q,yt]of A)H[q]=l(ut(D,e.toBytes(yt)));let rt=t.ZERO,tt=[],et=[];for(let[q,yt,Rt,qt]of A){if(t.ZERO.equals(Rt)||t.ZERO.equals(qt))throw new Error("infinity commitment");rt=rt.add(Rt),tt.push(qt),et.push(H[q])}let It=rt.add(st(tt,et));return{identifiers:A.map(q=>q[1]),groupCommitment:It,bindingFactors:H}},ot=(p,w,B,A)=>{let F=W(R(p)),k=K(A),{identifiers:D,groupCommitment:H,bindingFactors:rt}=z(F,w,B),tt=rt[A],et=C(D,k),It=O.challenge(H,F,B);return{lambda:et,challenge:It,bindingFactor:tt,groupCommitment:H}};Object.freeze(P);let pt={Identifier:P,DKG:Object.freeze({round1:(p,w,B,A=Lt)=>{let F=K(p,"id");ee(w);let{coefficients:k,commitment:D}=U(w,B,void 0,A),H=T.compute(F,k,D,A),rt=D.map(b),tt={identifier:G(F),commitment:rt,proofOfKnowledge:H},et={identifier:F,coefficients:k,commitment:D.map(b),signers:{min:w.min,max:w.max},step:1};return{public:tt,secret:et}},round2:(p,w)=>{if(ht(p,{identifier:"bigint",commitment:"object",signers:"object"},{coefficients:"object",round2Cache:"object",step:"number"},"secret"),ee(p.signers,"secret.signers"),xt(w,"others"),w.length!==p.signers.max-1)throw new Error("wrong number of round1 packages");if(!p.coefficients||p.step===3)throw new Error("round3 package used in round2");if(p.round2Cache!==void 0)return p.round2Cache;let B={};for(let A of w){if(A.commitment.length!==p.signers.min)throw new Error("wrong number of commitments");let F=K(A.identifier);if(F===p.identifier)throw new Error("duplicate id="+G(F));T.validate(F,A.commitment,A.proofOfKnowledge);for(let D of A.commitment)R(D);if(B[A.identifier])throw new Error("Duplicate id="+F);let k=e.toBytes(I(F,p.coefficients));B[A.identifier]={identifier:G(p.identifier),signingShare:k}}return p.round2Cache=B,p.step=2,B},round3:(p,w,B)=>{if(ht(p,{identifier:"bigint",commitment:"object",signers:"object"},{coefficients:"object",round2Cache:"object",step:"number"},"secret"),ee(p.signers,"secret.signers"),xt(w,"round1"),xt(B,"round2"),w.length!==p.signers.max-1)throw new Error("wrong length of round1 packages");if(!p.coefficients||p.step!==2)throw new Error("round2 package used in round3");if(B.length!==w.length)throw new Error("wrong length of round2 packages");let A={};for(let q of w){if(!q.identifier||!q.commitment)throw new Error("wrong round1 share");A[q.identifier]={...q}}for(let q of B){if(!q.identifier||!q.signingShare)throw new Error("wrong round2 share");if(!A[q.identifier])throw new Error("round1 share for "+q.identifier+" is missing");A[q.identifier].signingShare=q.signingShare}if(Object.keys(A).length!==w.length)throw new Error("mismatch identifiers between rounds");let F=e.ZERO;if(p.commitment.length!==p.signers.min)throw new Error("wrong commitments length");let k=p.commitment.map(R),D=I(p.identifier,p.coefficients);j(p.identifier,k,D);let H=k.map(b),rt={[G(p.identifier)]:H};for(let q in A){let yt=A[q];if(!yt.signingShare||!yt.commitment)throw new Error("mismatch identifiers");let Rt=K(q),qt=e.fromBytes(yt.signingShare),kr=yt.commitment.map(R);j(p.identifier,kr,qt),F=e.add(F,qt);let xn=G(Rt);if(rt[xn])throw new Error("duplicated id="+xn);rt[xn]=yt.commitment}F=e.add(F,D);let tt=new Array(p.signers.min).fill(t.ZERO);for(let q in rt){let yt=rt[q];if(yt.length!==p.signers.min)throw new Error("wrong commitments length");for(let Rt=0;Rt<yt.length;Rt++)tt[Rt]=tt[Rt].add(R(yt[Rt]))}let et=tt.map(b),It={};for(let q in rt)It[q]=b(N(K(q),tt));let zt={public:{signers:{min:p.signers.min,max:p.signers.max},commitments:et,verifyingShares:Object.fromEntries(Object.entries(It).map(([q,yt])=>[q,yt.slice()]))},secret:{identifier:G(p.identifier),signingShare:e.toBytes(F)}};n.adjustDKG&&(zt=n.adjustDKG(zt));for(let q=0;q<p.coefficients.length;q++)p.coefficients[q]-=p.coefficients[q];return delete p.coefficients,delete p.round2Cache,p.step=3,zt},clean(p){if(ht(p,{identifier:"bigint",commitment:"object",signers:"object"},{coefficients:"object",round2Cache:"object",step:"number"},"secret"),p.identifier-=p.identifier,p.coefficients)for(let w=0;w<p.coefficients.length;w++)p.coefficients[w]-=p.coefficients[w];delete p.round2Cache,p.step=3}}),trustedDealer(p,w,B,A=Lt){if(ee(p),w===void 0){w=[];for(let tt=1;tt<=p.max;tt++)w.push(P.fromNumber(tt))}else if(xt(w,"identifiers"),w.length!==p.max)throw new Error("identifiers should be array of "+p.max);let F={};for(let tt of w){let et=K(tt);if(tt in F)throw new Error("duplicated id="+tt);F[tt]=et}let k=U(p,B,void 0,A),D=k.commitment.map(b),H={},rt={};for(let tt of w){let et=I(F[tt],k.coefficients);rt[tt]=b(t.BASE.multiply(et)),H[tt]={identifier:tt,signingShare:e.toBytes(et)}}return{public:{signers:{min:p.min,max:p.max},commitments:D,verifyingShares:rt},secretShares:H}},validateSecret(p,w){ht(p,{identifier:"string",signingShare:"object"},{},"secret"),Z(p.signingShare,e.BYTES,"secret.signingShare"),ht(w,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),ee(w.signers,"pub.signers"),xt(w.commitments,"pub.commitments");let B=K(p.identifier),A=w.commitments.map(R),F=e.fromBytes(p.signingShare);j(B,A,F)},commit(p,w=Lt){if(ht(p,{identifier:"string",signingShare:"object"},{},"secret"),Z(p.signingShare,e.BYTES,"secret.signingShare"),typeof w!="function")throw new TypeError('"rng" expected function, got type='+typeof w);let B=e.fromBytes(p.signingShare),A=$(B,w),F=$(B,w),k={hiding:e.toBytes(A),binding:e.toBytes(F)};return{nonces:k,commitments:V(p.identifier,k)}},signShare(p,w,B,A,F){ht(p,{identifier:"string",signingShare:"object"},{},"secret"),Z(p.signingShare,e.BYTES,"secret.signingShare"),ht(w,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),ee(w.signers,"pub.signers"),xt(w.commitments,"pub.commitments"),ht(B,{hiding:"object",binding:"object"},{},"nonces"),Z(B.hiding,e.BYTES,"nonces.hiding"),Z(B.binding,e.BYTES,"nonces.binding"),xt(A,"commitmentList"),Z(F,void 0,"msg"),Os(w.signers,A.length);let k=e.fromBytes(B.hiding),D=e.fromBytes(B.binding);if(e.is0(k)||e.is0(D))throw new Error("signing nonces already used");let H={identifier:p.identifier,hiding:b(t.BASE.multiply(k)),binding:b(t.BASE.multiply(D))},rt=A.find(Lc=>Lc.identifier===p.identifier);if(!rt)throw new Error("missing signer commitment");if(he(rt.hiding)!==he(H.hiding)||he(rt.binding)!==he(H.binding))throw new Error("incorrect signer commitment");n.adjustSecret&&(p=n.adjustSecret(p,w)),n.adjustPublic&&(w=n.adjustPublic(w));let tt=e.fromBytes(p.signingShare),{lambda:et,challenge:It,bindingFactor:zt,groupCommitment:q}=ot(w.commitments[0],A,F,p.identifier),yt=n.adjustNonces?n.adjustNonces(q,B):B,Rt=n.adjustNonces?e.fromBytes(yt.hiding):k,qt=n.adjustNonces?e.fromBytes(yt.binding):D,kr=e.mul(e.mul(et,tt),It),xn=e.mul(qt,zt),Fc=e.toBytes(e.add(e.add(Rt,xn),kr));return B.hiding.fill(0),B.binding.fill(0),Fc},verifyShare(p,w,B,A,F){ht(p,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),ee(p.signers,"pub.signers"),xt(p.commitments,"pub.commitments"),xt(w,"commitmentList"),Z(B,void 0,"msg"),K(A),Z(F,e.BYTES,"sigShare"),n.adjustPublic&&(p=n.adjustPublic(p));let k=w.find(qt=>qt.identifier===A);if(!k)throw new Error("cannot find identifier commitment");let D=R(p.verifyingShares[A]),H=R(k.hiding),rt=R(k.binding),{lambda:tt,challenge:et,bindingFactor:It,groupCommitment:zt}=ot(p.commitments[0],w,B,A),q=H.add(rt.multiplyUnsafe(It));n.adjustGroupCommitmentShare&&(q=n.adjustGroupCommitmentShare(zt,q));let yt=t.BASE.multiplyUnsafe(e.fromBytes(F)),Rt=q.add(D.multiplyUnsafe(e.mul(et,tt)));return yt.equals(Rt)},aggregate(p,w,B,A){ht(p,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),ee(p.signers,"pub.signers"),xt(p.commitments,"pub.commitments"),xt(w,"commitmentList"),Z(B,void 0,"msg"),ht(A,{},{},"sigShares");let F=p;n.adjustPublic&&(p=n.adjustPublic(p));try{Os(p.signers,w.length)}catch{throw new $e("aggregation failed",[])}let k=w.map(et=>et.identifier),D=new Set;for(let et of k){if(D.has(et))throw new $e("aggregation failed",[]);D.add(et)}if(k.length!==Object.keys(A).length)throw new $e("aggregation failed",[]);for(let et of k)if(!(et in A)||!(et in p.verifyingShares))throw new $e("aggregation failed",[]);let H=R(p.commitments[0]),{groupCommitment:rt}=z(H,w,B),tt=e.ZERO;for(let et of k)tt=e.add(tt,e.fromBytes(A[et]));if(!O.verify(B,rt,tt,H)){let et=[];for(let It of k)this.verifyShare(F,w,B,It,A[It])||et.push(It);throw new $e("aggregation failed",et)}return St.encode(rt,tt)},sign(p,w){let B=e.fromBytes(w);n.adjustScalar&&(B=n.adjustScalar(B));let[A,F]=O.sign(p,B);return St.encode(A,F)},verify(p,w,B){let A=n.parsePublicKey?n.parsePublicKey(B):R(B),{R:F,z:k}=St.decode(p);return O.verify(w,F,k,A)},combineSecret(p,w){if(xt(p,"shares"),ee(w),p.length<w.min||p.length>w.max)throw new Error("wrong secret shares array");let B=[],A={};for(let D of p){let H=K(D.identifier),rt=G(H);if(A[rt])throw new Error("duplicated id="+rt);A[rt]=!0,B.push([H,e.fromBytes(D.signingShare)])}let F=B.map(([D])=>D),k=e.ZERO;for(let[D,H]of B)k=e.add(k,e.mul(H,C(F,D)));return e.toBytes(k)},utils:Object.freeze({Fn:e,randomScalar:(p=Lt)=>e.toBytes(gt(p).scalar),generateSecretPolynomial:(p,w,B,A)=>{let F=U(p,w,B,A);return{...F,commitment:F.commitment.map(b)}}})};return Object.freeze(pt)}var ee,Os,$e,Us=At(()=>{L();me();Ae();mr();bs();Me();ee=(n,t="signers")=>{if(ht(n,{min:"number",max:"number"},{},t),bt(n.min,t+".min"),bt(n.max,t+".max"),n.min<2||n.max<2||n.min>n.max)throw new Error("Wrong signers info: min="+n.min+" max="+n.max)},Os=(n,t)=>{if(t<n.min||t>n.max)throw new Error("Wrong number of commitments="+t)},$e=class extends Error{constructor(e,r){super(e);S(this,"cheaters");this.cheaters=r}}});var bo={};zn(bo,{_HMAC:()=>Un,hmac:()=>xo});var Un,xo,xr=At(()=>{L();me();Un=class{constructor(t,e){S(this,"oHash");S(this,"iHash");S(this,"blockLen");S(this,"outputLen");S(this,"canXOF",!1);S(this,"finished",!1);S(this,"destroyed",!1);if(Qn(t),Xt(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,o=new Uint8Array(r);o.set(e.length>r?t.create().update(e).digest():e);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),Ne(o)}update(t){return Je(this),this.iHash.update(t),this}digestInto(t){Je(this),Jn(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:r,finished:o,destroyed:i,blockLen:s,outputLen:f,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=f,t.canXOF=c,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xo=(()=>{let n=((t,e,r)=>new Un(t,e).update(r).digest());return n.create=(t,e)=>new Un(t,e),n})()});var uu,Eo,de,Bo,_s=At(()=>{L();Ae();uu=BigInt(0),Eo=class extends Error{constructor(t=""){super(t)}},de={Err:Eo,_tlv:{encode:(n,t)=>{let{Err:e}=de;if(bt(n,"tag"),n<0||n>255)throw new e("tlv.encode: wrong tag");if(Tn(t,"data"),t.length&1)throw new e("tlv.encode: unpadded data");let r=t.length/2,o=In(r);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let i=r>127?In(o.length/2|128):"";return In(n)+i+o+t},decode(n,t){let{Err:e}=de;t=Z(t,void 0,"DER data");let r=0;if(n<0||n>255)throw new e("tlv.decode: wrong tag");if(t.length<2||t[r++]!==n)throw new e("tlv.decode: wrong tlv");let o=t[r++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(r,r+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let h of u)s=s<<8|h;if(r+=c,s<128)throw new e("tlv.decode(long): not minimal encoding")}let f=t.subarray(r,r+s);if(f.length!==s)throw new e("tlv.decode: wrong value length");return{v:f,l:t.subarray(r+s)}}},_int:{encode(n){let{Err:t}=de;if(lr(n),n<uu)throw new t("integer: negative integers are not allowed");let e=In(n);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(n){let{Err:t}=de;if(n.length<1)throw new t("invalid signature integer: empty");if(n[0]&128)throw new t("invalid signature integer: negative");if(n.length>1&&n[0]===0&&!(n[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Et(n)}},toSig(n){let{Err:t,_int:e,_tlv:r}=de,o=Z(n,void 0,"signature"),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:f,l:c}=r.decode(2,i),{v:u,l:h}=r.decode(2,c);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(f),s:e.decode(u)}},hexFromSig(n){let{_tlv:t,_int:e}=de;ht(n,{r:"bigint",s:"bigint"},{},"sig");let r=t.encode(2,e.encode(n.r)),o=t.encode(2,e.encode(n.s)),i=r+o;return t.encode(48,i)}},Bo=(Object.freeze(de._tlv),Object.freeze(de._int),Object.freeze(de))});function au(n,t,e){io("scalar",n,pe,e);let[[r,o],[i,s]]=t,f=Fs(s*n,e),c=Fs(-o*n,e),u=n-f*r-c*i,h=-f*o-c*s,a=u<pe,l=h<pe;a&&(u=-u),l&&(h=-h);let d=Rn(Math.ceil(on(e)/2))+ze;if(u<pe||u>=d||h<pe||h>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:a,k1:u,k2neg:l,k2:h}}function vo(n){if(!["compact","recovered","der"].includes(n))throw new Error('Signature format must be "compact", "recovered", or "der"');return n}function So(n,t){ht(n);let e={};for(let r of Object.keys(t))e[r]=n[r]===void 0?t[r]:n[r];return Jt(e.lowS,"lowS"),Jt(e.prehash,"prehash"),e.format!==void 0&&vo(e.format),e}function Cs(n,t={}){let e=ms("weierstrass",n,t),r=e.Fp,o=e.Fn,i=e.CURVE,{h:s,n:f}=i;ht(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=t,h=t.randomBytes===void 0?Lt:t.randomBytes;if(c&&(!r.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let a=js(r,o);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(st,I,C){if(u&&I.is0())return Uint8Array.of(0);let{x:N,y:U}=I.toAffine(),T=r.toBytes(N);if(Jt(C,"isCompressed"),C){l();let O=!r.isOdd(U);return ut(ks(O),T)}else return ut(Uint8Array.of(4),T,r.toBytes(U))}function g(st){Z(st,void 0,"Point");let{publicKey:I,publicKeyUncompressed:C}=a,N=st.length,U=st[0],T=st.subarray(1);if(u&&N===1&&U===0)return{x:r.ZERO,y:r.ZERO};if(N===I&&(U===2||U===3)){let O=r.fromBytes(T);if(!r.isValid(O))throw new Error("bad point: is not on curve, wrong x");let j=_(O),P;try{P=r.sqrt(j)}catch(ot){let pt=ot instanceof Error?": "+ot.message:"";throw new Error("bad point: is not on curve, sqrt error"+pt)}l();let $=r.isOdd(P);return(U&1)===1!==$&&(P=r.neg(P)),{x:O,y:P}}else if(N===C&&U===4){let O=r.BYTES,j=r.fromBytes(T.subarray(0,O)),P=r.fromBytes(T.subarray(O,O*2));if(!b(j,P))throw new Error("bad point: is not on curve");return{x:j,y:P}}else throw new Error(`bad point: got length ${N}, expected compressed=${I} or uncompressed=${C}`)}let y=t.toBytes===void 0?d:t.toBytes,m=t.fromBytes===void 0?g:t.fromBytes,x=r.mul(i.b,Ao),v=r.is0(i.a)?st=>r.ZERO:st=>r.mul(i.a,st);function _(st){let I=r.sqr(st),C=r.mul(I,st);return r.add(r.add(C,r.mul(st,i.a)),i.b)}function b(st,I){let C=r.sqr(I),N=_(st);return r.eql(C,N)}if(!b(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let R=r.mul(r.pow(i.a,Ao),lu),V=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(R,V)))throw new Error("bad curve params: a or b");function W(st,I,C=!1){if(!r.isValid(I)||C&&r.is0(I))throw new Error(`bad point coordinate ${st}`);return I}function at(st){if(!(st instanceof gt))throw new Error("Weierstrass Point expected")}function G(st){if(!c||!c.basises)throw new Error("no endo");return au(st,c.basises,o.ORDER)}function K(st,I,C,N){if(!o.isValid(N))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:U,k1:T,k2neg:O,k2:j}=G(N),P=new gt(r.mul(C.X,c.beta),C.Y,C.Z);st.push(U?C.negate():C,O?P.negate():P),I.push(T,j)}else st.push(C),I.push(N)}let St=new WeakSet,ct=class ct{constructor(I,C,N){S(this,"X");S(this,"Y");S(this,"Z");this.X=W("x",I),this.Y=W("y",C,!0),this.Z=W("z",N),Object.freeze(this)}static CURVE(){return i}static fromAffine(I){let{x:C,y:N}=I||{};if(!I||!r.isValid(C)||!r.isValid(N))throw new Error("invalid affine point");if(I instanceof ct)throw new Error("projective point not allowed");return r.is0(C)&&r.is0(N)?ct.ZERO:new ct(C,N,r.ONE)}static fromBytes(I){let C=ct.fromAffine(m(Z(I,void 0,"point")));return C.assertValidity(),C}static fromHex(I){return ct.fromBytes(en(I))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(I=6,C=!0){return Ft.setWindowSize(this,I),C||this.multiply(Ao),this}assertValidity(){let I=this;if(I.is0()){if(t.allowInfinityPoint&&r.is0(I.X)&&r.eql(I.Y,r.ONE)&&r.is0(I.Z))return;throw new Error("bad point: ZERO")}if(St.has(I))return;let{x:C,y:N}=I.toAffine();if(!r.isValid(C)||!r.isValid(N))throw new Error("bad point: x or y not field elements");if(!b(C,N))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");St.add(I)}hasEvenY(){let{y:I}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(I)}equals(I){at(I);let{X:C,Y:N,Z:U}=this,{X:T,Y:O,Z:j}=I,P=r.eql(r.mul(C,j),r.mul(T,U)),$=r.eql(r.mul(N,j),r.mul(O,U));return P&&$}negate(){return new ct(this.X,r.neg(this.Y),this.Z)}double(){let{X:I,Y:C,Z:N}=this,U=r.ZERO,T=r.ZERO,O=r.ZERO,j=r.mul(I,I),P=r.mul(C,C),$=r.mul(N,N),z=r.mul(I,C);return z=r.add(z,z),O=r.mul(I,N),O=r.add(O,O),U=v(O),T=r.mul(x,$),T=r.add(U,T),U=r.sub(P,T),T=r.add(P,T),T=r.mul(U,T),U=r.mul(z,U),O=r.mul(x,O),$=v($),z=r.sub(j,$),z=v(z),z=r.add(z,O),O=r.add(j,j),j=r.add(O,j),j=r.add(j,$),j=r.mul(j,z),T=r.add(T,j),$=r.mul(C,N),$=r.add($,$),j=r.mul($,z),U=r.sub(U,j),O=r.mul($,P),O=r.add(O,O),O=r.add(O,O),new ct(U,T,O)}add(I){at(I);let{X:C,Y:N,Z:U}=this,{X:T,Y:O,Z:j}=I,P=r.ZERO,$=r.ZERO,z=r.ZERO,ot=r.mul(C,T),pt=r.mul(N,O),p=r.mul(U,j),w=r.add(C,N),B=r.add(T,O);w=r.mul(w,B),B=r.add(ot,pt),w=r.sub(w,B),B=r.add(C,U);let A=r.add(T,j);return B=r.mul(B,A),A=r.add(ot,p),B=r.sub(B,A),A=r.add(N,U),P=r.add(O,j),A=r.mul(A,P),P=r.add(pt,p),A=r.sub(A,P),z=v(B),P=r.mul(x,p),z=r.add(P,z),P=r.sub(pt,z),z=r.add(pt,z),$=r.mul(P,z),pt=r.add(ot,ot),pt=r.add(pt,ot),p=v(p),B=r.mul(x,B),pt=r.add(pt,p),p=r.sub(ot,p),p=v(p),B=r.add(B,p),ot=r.mul(pt,B),$=r.add($,ot),ot=r.mul(A,B),P=r.mul(w,P),P=r.sub(P,ot),ot=r.mul(w,pt),z=r.mul(A,z),z=r.add(z,ot),new ct(P,$,z)}subtract(I){return at(I),this.add(I.negate())}is0(){return this.equals(ct.ZERO)}multiply(I){if(!o.isValidNot0(I))throw new RangeError("invalid scalar: out of range");let{p:C,f:N}=Ft.mulSecret(this,I,s,_t);return _t([C,N])[0]}multiplyUnsafe(I){let C=this,N=I;if(!o.isValid(N))throw new RangeError("invalid scalar: out of range");if(N===pe||C.is0())return ct.ZERO;if(N===ze)return C;if(Ft.hasWindowSize(this))return Ft.mulUnsafe(C,N,_t);let U=[],T=[];return K(U,T,C,N),un(ct,U,T)}mulAddUnsafe(I,C,N){at(C);let U=[],T=[];return K(U,T,this,I),K(U,T,C,N),un(ct,U,T)}toAffine(I){let C=this,N=I;if(N!=null&&!r.isValid(N))throw new RangeError('"invertedZ" expected valid field element');let{X:U,Y:T,Z:O}=C;if(r.eql(O,r.ONE))return{x:U,y:T};let j=C.is0();N==null&&(N=j?r.ONE:r.inv(O));let P=r.mul(U,N),$=r.mul(T,N),z=r.mul(O,N);if(j)return{x:r.ZERO,y:r.ZERO};if(!r.eql(z,r.ONE))throw new Error("invZ was invalid");return{x:P,y:$}}isTorsionFree(){let{isTorsionFree:I}=t;return s===ze?!0:I?I(ct,this):Ft.mulUnsafe(this,f).is0()}clearCofactor(){let{clearCofactor:I}=t;return s===ze?this:I?I(ct,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===ze?this.is0():this.clearCofactor().is0()}toBytes(I=!0){return Jt(I,"isCompressed"),this.assertValidity(),y(ct,this,I)}toHex(I=!0){return he(this.toBytes(I))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};S(ct,"BASE",new ct(i.Gx,i.Gy,r.ONE)),S(ct,"ZERO",new ct(r.ZERO,r.ONE,r.ZERO)),S(ct,"Fp",r),S(ct,"Fn",o);let gt=ct,_t=st=>ps(gt,st),Ft=new gr(gt,h);return Ft.bits>=6&&gt.BASE.precompute(6),Object.freeze(gt.prototype),Object.freeze(gt),gt}function ks(n){return Uint8Array.of(n?2:3)}function js(n,t){return{secretKey:t.BYTES,publicKey:1+n.BYTES,publicKeyUncompressed:1+2*n.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function hu(n,t={}){Te(n);let{Fn:e}=n,r=t.randomBytes===void 0?Lt:t.randomBytes,o=Object.assign(js(n.Fp,e),{seed:Math.max(fn(e.ORDER),16)});function i(d){try{let g=e.fromBytes(d);return e.isValidNot0(g)}catch{return!1}}function s(d,g){let{publicKey:y,publicKeyUncompressed:m}=o;try{let x=d.length;return g===!0&&x!==y||g===!1&&x!==m?!1:!!n.fromBytes(d)}catch{return!1}}function f(d){return d=d===void 0?r(o.seed):d,qe(Z(d,o.seed,"seed"),e.ORDER)}function c(d,g=!0){return n.BASE.multiply(e.fromBytes(d)).toBytes(g)}function u(d){let{secretKey:g,publicKey:y,publicKeyUncompressed:m}=o,x=e._lengths;if(!Qt(d))return;let v=Z(d,void 0,"key").length,_=v===y||v===m,b=v===g||!!x?.includes(v);if(!(_&&b))return _}function h(d,g,y=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(d);return n.fromBytes(g).multiply(m).toBytes(y)}let a={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:f},l=yr(f,c);return Object.freeze(a),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:l,Point:n,utils:a,lengths:o})}function Ns(n,t,e={}){Te(n);let r=t;Qn(r),ht(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},e),i=o.randomBytes===void 0?Lt:o.randomBytes,s=o.hmac===void 0?(U,T)=>xo(r,U,T):o.hmac,{Fp:f,Fn:c}=n,{ORDER:u,BITS:h}=c,a=fn(u),l=go(i,a),{keygen:d,getPublicKey:g,getSharedSecret:y,utils:m,lengths:x}=hu(n,o),v={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},_=u*Ls+ze<f.ORDER;function b(U){let T=u>>ze;return U>T}function R(U,T){if(!c.isValidNot0(T))throw new Error(`invalid signature ${U}: out of range 1..Point.Fn.ORDER`);return T}function V(){if(!f.isOdd)throw new Error("Field doesn't support isOdd")}function W(U,T,O){return V(),(U===O?0:2)|Number(f.isOdd(T))}function at(){if(_)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function G(U,T){vo(T);let O=x.signature,j=T==="compact"?O:T==="recovered"?O+1:void 0;return Z(U,j)}class K{constructor(T,O,j){S(this,"r");S(this,"s");S(this,"recovery");if(this.r=R("r",T),this.s=R("s",O),j!=null){if(at(),![0,1,2,3].includes(j))throw new Error("invalid recovery id");this.recovery=j}Object.freeze(this)}static fromBytes(T,O=v.format){G(T,O);let j;if(O==="der"){let{r:ot,s:pt}=Bo.toSig(Z(T));return new K(ot,pt)}O==="recovered"&&(j=T[0],O="compact",T=T.subarray(1));let P=x.signature/2,$=T.subarray(0,P),z=T.subarray(P,P*2);return new K(c.fromBytes($),c.fromBytes(z),j)}static fromHex(T,O){return this.fromBytes(en(T),O)}assertRecovery(){let{recovery:T}=this;if(T==null)throw new Error("invalid recovery id: must be present");return T}addRecoveryBit(T){return new K(this.r,this.s,T)}recoverPublicKey(T){let{r:O,s:j}=this,P=this.assertRecovery(),$=P===2||P===3?O+u:O;if(!f.isValid($))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let z=f.toBytes($),ot=n.fromBytes(ut(ks((P&1)===0),z)),pt=c.inv($),p=gt(Z(T,void 0,"msgHash")),w=c.create(-p*pt),B=c.create(j*pt),A=n.BASE.mulAddUnsafe(w,ot,B);if(A.is0())throw new Error("invalid recovery: point at infinify");return A.assertValidity(),A}hasHighS(){return b(this.s)}toBytes(T=v.format){if(vo(T),T==="der")return en(Bo.hexFromSig(this));let{r:O,s:j}=this,P=c.toBytes(O),$=c.toBytes(j);return T==="recovered"?(at(),ut(Uint8Array.of(this.assertRecovery()),P,$)):ut(P,$)}toHex(T){return he(this.toBytes(T))}}Object.freeze(K.prototype),Object.freeze(K);let St=o.bits2int===void 0?function(T){if(T.length>8192)throw new Error("input is too large");let O=Et(T),j=T.length*8-h;return j>0?O>>BigInt(j):O}:o.bits2int,gt=o.bits2int_modN===void 0?function(T){return c.create(St(T))}:o.bits2int_modN,_t=Rn(h);function Ft(U){return io("num < 2^"+h,U,pe,_t),c.toBytes(U)}function ct(U,T){return Z(U,void 0,"message"),T?Z(r(U),void 0,"prehashed message"):U}function st(U,T,O){let{lowS:j,prehash:P,extraEntropy:$}=So(O,v);U=ct(U,P);let z=gt(U),ot=c.fromBytes(T);if(!c.isValidNot0(ot))throw new Error("invalid private key");let pt=[Ft(ot),Ft(z)];if($!=null&&$!==!1){let A=$===!0?i(x.secretKey):$;pt.push(Z(A,void 0,"extraEntropy"))}let p=ut(...pt),w=z;function B(A){let F=St(A);if(!c.isValidNot0(F))return;let k=n.BASE.multiply(F).toAffine(),D=c.create(k.x);if(D===pe)return;let H;if(l!==void 0){let et=Et(qe(l(a),u)),It=c.inv(c.mul(et,F)),zt=c.mul(et,w),q=c.mul(et,ot);H=c.create(It*c.create(zt+q*D))}else{let et=cs(F,u);H=c.create(et*c.create(w+D*ot))}if(H===pe)return;let rt=W(k.x,k.y,D),tt=H;return j&&b(H)&&(tt=c.neg(H),rt^=1),new K(D,tt,_?void 0:rt)}return{seed:p,k2sig:B}}function I(U,T,O={}){let{seed:j,k2sig:P}=st(U,T,O);return Ji(r.outputLen,c.BYTES,s)(j,P).toBytes(O.format)}function C(U,T,O,j={}){let{lowS:P,prehash:$,format:z}=So(j,v);if(O=Z(O,void 0,"publicKey"),T=ct(T,$),!Qt(U)){let ot=U instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+ot)}G(U,z);try{let ot=K.fromBytes(U,z),pt=n.fromBytes(O);if(P&&ot.hasHighS())return!1;let{r:p,s:w}=ot,B=gt(T),A=c.inv(w),F=c.create(B*A),k=c.create(p*A),D=n.BASE.mulAddUnsafe(F,pt,k);if(D.is0())return!1;let H=D.toAffine();return!(c.create(H.x)!==p||z==="recovered"&&ot.recovery!==W(H.x,H.y,p))}catch{return!1}}function N(U,T,O={}){let{prehash:j}=So(O,v);return T=ct(T,j),K.fromBytes(U,"recovered").recoverPublicKey(T).toBytes()}return Object.freeze({keygen:d,getPublicKey:g,getSharedSecret:y,utils:m,lengths:x,Point:n,sign:I,verify:C,recoverPublicKey:N,Signature:K,hash:r})}var Fs,pe,ze,Ls,Ao,lu,Ds=At(()=>{L();xr();me();Ae();mr();_s();Me();Fs=(n,t)=>(n+(n>=0?t:-t)/Ls)/t;pe=BigInt(0),ze=BigInt(1),Ls=BigInt(2),Ao=BigInt(3),lu=BigInt(4)});var Uo={};zn(Uo,{__TEST:()=>mu,schnorr:()=>wu,schnorr_FROST:()=>Su,secp256k1:()=>gu,secp256k1_FROST:()=>Eu,secp256k1_hasher:()=>Ro});function pu(n){let t=br.p,e=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),f=BigInt(44),c=BigInt(88),u=n*n*n%t,h=u*u*n%t,a=Nt(h,e,t)*h%t,l=Nt(a,e,t)*h%t,d=Nt(l,Ps,t)*u%t,g=Nt(d,o,t)*d%t,y=Nt(g,i,t)*g%t,m=Nt(y,f,t)*y%t,x=Nt(m,c,t)*m%t,v=Nt(x,f,t)*y%t,_=Nt(v,e,t)*h%t,b=Nt(_,s,t)*g%t,R=Nt(b,r,t)*u%t,V=Nt(R,Ps,t);if(!Kt.eql(Kt.sqr(V),n))throw new Error("Cannot find square root");return V}function _n(n,...t){let e=Hs[n];if(e===void 0){let r=Ee(rn(n));e=ut(r,r),Hs[n]=e}return Ee(ut(e,...t))}function $s(n){let{Fn:t,BASE:e}=dt,r=t.fromBytes(Z(n,32,"secretKey")),i=e.multiply(r).toAffine();return{scalar:ne(i.y)?r:t.neg(r),bytes:Ks(i)}}function Er(n){let t=Kt;if(!t.isValidNot0(n))throw new Error("invalid x: Fail if x \u2265 p");let e=t.sqr(n),r=t.add(t.mulN(e,n),BigInt(7)),o=t.sqrt(r);ne(o)||(o=t.neg(o));let i=dt.fromAffine({x:n,y:o});return i.assertValidity(),i}function Io(...n){return dt.Fn.create(an(_n("BIP0340/challenge",...n)))}function qs(n){return $s(n).bytes}function yu(n,t,e=An(32)){let{Fn:r,BASE:o}=dt,i=Z(n,void 0,"message"),{bytes:s,scalar:f}=$s(t),c=Z(e,32,"auxRand"),u=r.toBytes(f^an(_n("BIP0340/aux",c))),h=_n("BIP0340/nonce",u,s,i),a=r.create(an(h));if(a===To)throw new Error("sign failed: k is zero");let d=o.multiply(a).toAffine(),g=ne(d.y)?a:r.neg(a),y=Ks(d),m=Io(y,s,i),x=new Uint8Array(64);if(x.set(y,0),x.set(r.toBytes(r.create(g+m*f)),32),!zs(x,i,s))throw new Error("sign: Invalid signature produced");return x}function zs(n,t,e){let{Fp:r,Fn:o,BASE:i}=dt,s=Z(n,64,"signature"),f=Z(t,void 0,"message"),c=Z(e,32,"publicKey");try{let u=Er(an(c)),h=s.subarray(0,32),a=an(h);if(!r.isValidNot0(a))return!1;let l=an(s.subarray(32,64));if(!o.isValidNot0(l))return!1;let d=Io(h,Fn(u),f),g=i.mulAddUnsafe(l,u,o.neg(d)),{x:y,y:m}=g.toAffine();return!(g.is0()||!ne(m)||!r.eql(y,a))}catch{return!1}}function Zs(n,t){if(t===void 0)return To;let e=Fn(n),r=Et(_n("TapTweak",e,t));if(!dt.Fn.isValid(r))throw new Error("invalid TapTweak hash");return r}function Oo(n){let t=dt.fromBytes(n.commitments[0]);return ne(t.y)?n:{signers:{min:n.signers.min,max:n.signers.max},commitments:n.commitments.map(e=>dt.fromBytes(e).negate().toBytes()),verifyingShares:Object.fromEntries(Object.entries(n.verifyingShares).map(([e,r])=>[e,dt.fromBytes(r).negate().toBytes()]))}}function Ys(n,t){let e=dt.fromBytes(t.commitments[0]);if(ne(e.y))return n;let r=dt.Fn;return{...n,signingShare:r.toBytes(r.neg(r.fromBytes(n.signingShare)))}}function Bu(n,t){if(ne(n.y))return t;let e=dt.Fn;return{binding:e.toBytes(e.neg(e.fromBytes(t.binding))),hiding:e.toBytes(e.neg(e.fromBytes(t.hiding)))}}function Vs(n,t,e){let r=dt.Fn,o=Ys(n,t),i=Oo(t),s=Zs(dt.fromBytes(i.commitments[0]),e),f=r.toBytes(r.add(r.fromBytes(o.signingShare),s));return{identifier:o.identifier,signingShare:f}}function Ws(n,t){let e=Oo(n),r=Zs(dt.fromBytes(e.commitments[0]),t);if(r===To)return e;let o=dt.BASE.multiply(r),i=e.commitments.map((f,c)=>(c===0?dt.fromBytes(f).add(o):dt.fromBytes(f)).toBytes()),s={};for(let f in e.verifyingShares)s[f]=dt.fromBytes(e.verifyingShares[f]).add(o).toBytes();return{signers:{min:e.signers.min,max:e.signers.max},commitments:i,verifyingShares:s}}var br,du,To,Ps,Kt,dt,gu,Hs,Fn,Ks,ne,an,mu,wu,xu,Ms,bu,Ro,Eu,Su,_o=At(()=>{L();ur();me();mr();Us();Rs();Me();Ds();Ae();br={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},du={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},To=BigInt(0),Ps=BigInt(2);Kt=cn(br.p,{sqrt:pu}),dt=Cs(br,{Fp:Kt,endo:du}),gu=Ns(dt,Ee),Hs=Object.create(null);Fn=n=>n.toBytes(!0).slice(1),Ks=({x:n})=>Kt.toBytes(n),ne=n=>!Kt.isOdd(n);an=Et;mu=Object.freeze({lift_x:Er,frostTweakPublic:Ws,frostTweakSecret:Vs}),wu=(()=>{let e=r=>(r=r===void 0?An(48):r,qe(Z(r,48,"seed"),br.n));return Object.freeze({keygen:yr(e,qs),getPublicKey:qs,sign:yu,verify:zs,Point:dt,utils:Object.freeze({randomSecretKey:e,taggedHash:_n,lift_x:Er,pointToBytes:Fn}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),xu=vs(Kt,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(n=>n.map(t=>BigInt(t)))),bu=()=>Ms||(Ms=Is(Kt,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:Kt.create(BigInt("-11"))})),Ro=Ts(dt,n=>{let{x:t,y:e}=bu()(Kt.create(n[0]));return xu(t,e)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:Kt.ORDER,m:1,k:128,expand:"xmd",hash:Ee}),Eu=wo({name:"FROST-secp256k1-SHA256-v1",Point:dt,hashToScalar:Ro.hashToScalar,hash:Ee});Su=wo({name:"FROST-secp256k1-SHA256-TR-v1",Point:dt,hashToScalar:Ro.hashToScalar,hash:Ee,parsePublicKey(n){if(n.length===32)return Er(Et(n));if(n.length===33)return dt.fromBytes(n);throw new Error(`expected x-only or compressed public key, got length=${n.length}`)},adjustScalar(n){let t=dt.BASE.multiply(n);return ne(t.y)?n:dt.Fn.neg(n)},adjustPoint:n=>ne(n.y)?n:n.negate(),challenge(n,t,e){return Io(Fn(n),Fn(t),e)},adjustNonces:Bu,adjustGroupCommitmentShare:(n,t)=>ne(n.y)?t:t.negate(),adjustPublic:Oo,adjustSecret:Ys,adjustTx:{encode:n=>n.subarray(1),decode:n=>ut(Uint8Array.of(2),n)},adjustDKG:n=>{let t=new Uint8Array(0);return{public:Ws(n.public,t),secret:Vs(n.secret,n.public,t)}}})});function Fo(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}function Au(n,t=""){if(typeof n!="boolean")throw new TypeError(Br(t)+"expected boolean, got type="+typeof n);return n}function Ln(n,t=""){if(typeof n!="number")throw new TypeError(Br(t)+"expected number, got "+typeof n);if(!Number.isSafeInteger(n)||n<0)throw new RangeError(Br(t)+"expected integer >= 0, got "+n);return n}function Y(n,t,e=""){if(Fo(n)&&(t===void 0||n.length===t))return n;t!==void 0&&Ln(t,"length");let r=Fo(n),o=t!==void 0?` of length ${t}`:"",i=r?`length=${n.length}`:`type=${typeof n}`,s=Br(e)+"expected Uint8Array"+o+", got "+i;throw r?new RangeError(s):new TypeError(s)}function Re(n,t=!0){if(n.destroyed)throw new Error("hash was destroyed");if(t&&n.finished)throw new Error("digest() was already called")}function vu(n,t){Y(n,void 0,"output");let e=t.outputLen;if(!(n.length>=e))throw new RangeError('"output" expected length >= '+e)}function Cn(n,t){if(vu(n,t),!Tt(n))throw new Error("invalid output, must be aligned")}function Sr(n){return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}function Q(n){return new Uint32Array(n.buffer,n.byteOffset,Math.floor(n.byteLength/4))}function nt(...n){for(let t=0;t<n.length;t++)n[t].fill(0)}function ln(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function Ze(n){return n<<24&4278190080|n<<8&16711680|n>>>8&65280|n>>>24&255}function Tu(n){for(let t=0;t<n.length;t++)n[t]=Ze(n[t]);return n}function Lo(n,t){return!n.byteLength||!t.byteLength?!1:n.buffer===t.buffer&&n.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<n.byteOffset+n.byteLength}function Ar(n,t){if(Lo(n,t)&&n.byteOffset<t.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Co(...n){let t=0;for(let r=0;r<n.length;r++){let o=n[r];Y(o),t+=o.length}let e=new Uint8Array(t);for(let r=0,o=0;r<n.length;r++){let i=n[r];e.set(i,o),o+=i.length}return e}function kn(n,t){if(n=Y(n),t=Y(t),n.length!==t.length)return!1;let e=0;for(let r=0;r<n.length;r++)e|=n[r]^t[r];return e===0}function jn(n,t,e){let r=t,o=e||(()=>[]),i=(f,c)=>r(c,...o(f)).update(f).digest(),s=r(new Uint8Array(n),...o(new Uint8Array(0)));return i.outputLen=s.outputLen,i.blockLen=s.blockLen,i.create=(f,...c)=>r(f,...c),i}function hn(n,t,e=!0){if(t===void 0)return new Uint8Array(n);if(Y(t,n,"output"),e&&!Tt(t))throw new Error("invalid output, must be aligned");return t}function Gs(n,t,e){Ln(n),Ln(t),Au(e);let r=new Uint8Array(16),o=ln(r);return o.setBigUint64(0,BigInt(t),e),o.setBigUint64(8,BigInt(n),e),r}function Tt(n){return n.byteOffset%4===0}function mt(n){return Uint8Array.from(Y(n))}var Br,Ot,X,J,re,ko=At(()=>{L();Br=n=>n?`"${n}" `:"";Ot=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;X=Ot?n=>n:n=>Ze(n)>>>0;J=Ot?n=>n:Tu;re=(n,t)=>{function e(r,...o){if(Y(r,void 0,"key"),n.nonceLength!==void 0){let a=o[0];Y(a,n.varSizeNonce?void 0:n.nonceLength,"nonce")}let i=n.tagLength,s=n.nonceLength!==void 0?1:0;if(!n.withAAD){for(let a=s;a<o.length;a++)if(Fo(o[a]))throw new Error("AAD not supported")}n.withAAD&&o[s]!==void 0&&Y(o[s],void 0,"AAD");let f=t(r,...o),c=(a,l)=>{if(l!==void 0){if(a!==2)throw new Error("cipher output not supported");Y(l,void 0,"output")}},u=!1;return{encrypt(a,l){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,Y(a,void 0,"data"),c(f.encrypt.length,l),f.encrypt(a,l)},decrypt(a,l){if(Y(a,void 0,"data"),i&&a.length<i)throw new Error('"ciphertext" expected length >= tagLength='+i);return c(f.decrypt.length,l),f.decrypt(a,l)}}}return Object.assign(e,n),e}});function Ou(n){n.reverse();let t=n[15]&1,e=0;for(let r=0;r<n.length;r++){let o=n[r];n[r]=o>>>1|e,e=(o&1)<<7}return n[0]^=-t&225,n}var oe,No,ie,Iu,Ru,Nn,Oe,Uu,vr,jo,Do,Xs,Qs=At(()=>{L();ko();oe=16,No=new Uint8Array(16),ie=Q(No),Iu=225,Ru=(n,t,e,r)=>{let o=r&1;return{s3:e<<31|r>>>1,s2:t<<31|e>>>1,s1:n<<31|t>>>1,s0:n>>>1^Iu<<24&-(o&1)}},Nn=n=>(n>>>0&255)<<24|(n>>>8&255)<<16|(n>>>16&255)<<8|n>>>24&255|0,Oe=n=>X(Nn(n));Uu=n=>n>64*1024?8:n>1024?4:2,vr=class{constructor(t,e){S(this,"blockLen",oe);S(this,"outputLen",oe);S(this,"s0",0);S(this,"s1",0);S(this,"s2",0);S(this,"s3",0);S(this,"finished",!1);S(this,"destroyed",!1);S(this,"t");S(this,"W");S(this,"windowSize");Y(t,16,"key"),t=mt(t);let r=ln(t),o=r.getUint32(0,!1),i=r.getUint32(4,!1),s=r.getUint32(8,!1),f=r.getUint32(12,!1),c=[];for(let g=0;g<128;g++)c.push({s0:Nn(o),s1:Nn(i),s2:Nn(s),s3:Nn(f)}),{s0:o,s1:i,s2:s,s3:f}=Ru(o,i,s,f);let u=Uu(e||1024);if(![1,2,4,8].includes(u))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=u;let a=128/u,l=this.windowSize=2**u,d=[];for(let g=0;g<a;g++)for(let y=0;y<l;y++){let m=0,x=0,v=0,_=0;for(let b=0;b<u;b++){if(!(y>>>u-b-1&1))continue;let{s0:V,s1:W,s2:at,s3:G}=c[u*g+b];m^=V,x^=W,v^=at,_^=G}d.push({s0:m,s1:x,s2:v,s3:_})}this.t=d}_updateBlock(t,e,r,o){t^=this.s0,e^=this.s1,r^=this.s2,o^=this.s3;let{W:i,t:s,windowSize:f}=this,c=0,u=0,h=0,a=0,l=(1<<i)-1,d=0;for(let g of[t,e,r,o])for(let y=0;y<4;y++){let m=g>>>8*y&255;for(let x=8/i-1;x>=0;x--){let v=m>>>i*x&l,{s0:_,s1:b,s2:R,s3:V}=s[d*f+v];c^=_,u^=b,h^=R,a^=V,d+=1}}this.s0=c,this.s1=u,this.s2=h,this.s3=a}update(t){Re(this),Y(t),t=mt(t);let e=Q(t),r=Math.floor(t.length/oe),o=t.length%oe;for(let i=0;i<r;i++)this._updateBlock(X(e[i*4+0]),X(e[i*4+1]),X(e[i*4+2]),X(e[i*4+3]));return o&&(No.set(t.subarray(r*oe)),this._updateBlock(X(ie[0]),X(ie[1]),X(ie[2]),X(ie[3])),nt(ie)),this}destroy(){this.destroyed=!0;let{t}=this;for(let e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){Re(this),Cn(t,this),this.finished=!0;let{s0:e,s1:r,s2:o,s3:i}=this,s=Q(t);s[0]=e,s[1]=r,s[2]=o,s[3]=i,Ot||J(s.subarray(0,oe/4))}digest(){let t=new Uint8Array(oe);return this.digestInto(t),this.destroy(),t}},jo=class extends vr{constructor(t,e){Y(t);let r=Ou(mt(t));super(r,e),nt(r)}update(t){Re(this),Y(t),t=mt(t);let e=Q(t),r=t.length%oe,o=Math.floor(t.length/oe);for(let i=0;i<o;i++)this._updateBlock(Oe(e[i*4+3]),Oe(e[i*4+2]),Oe(e[i*4+1]),Oe(e[i*4+0]));return r&&(No.set(t.subarray(o*oe)),this._updateBlock(Oe(ie[3]),Oe(ie[2]),Oe(ie[1]),Oe(ie[0])),nt(ie)),this}digestInto(t){Re(this),Cn(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen),{s0:r,s1:o,s2:i,s3:s}=this,f=Q(e);f[0]=r,f[1]=o,f[2]=i,f[3]=s,J(f),e.reverse()}},Do=jn(16,(n,t)=>new vr(n,t),n=>[n.length]),Xs=jn(16,(n,t)=>new jo(n,t),n=>[n.length])});var Yo={};zn(Yo,{__TESTS:()=>Vu,aeskw:()=>qu,aeskwp:()=>Mu,aessiv:()=>Zu,cbc:()=>Nu,cfb:()=>Du,cmac:()=>Pn,ctr:()=>yn,ecb:()=>ju,gcm:()=>Pu,gcmsiv:()=>Hu,rngAesCtrDrbg128:()=>Ku,rngAesCtrDrbg256:()=>$u,siv:()=>zu,unsafe:()=>Yu});function Or(n){if(![16,24,32].includes(n.length))throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length='+n.length)}function zo(n){return n<<1^Fu&-(n>>7)}function dn(n,t){let e=0;for(;t>0;t>>=1)e^=n&-(t&1),n=zo(n);return e}function ec(n,t){if(n.length!==256)throw new Error("wrong sbox length");let e=new Uint32Array(256).map((u,h)=>t(n[h])),r=e.map(Po),o=r.map(Po),i=o.map(Po),s=new Uint32Array(256*256),f=new Uint32Array(256*256),c=new Uint16Array(256*256);for(let u=0;u<256;u++)for(let h=0;h<256;h++){let a=u*256+h;s[a]=e[u]^r[h],f[a]=o[u]^i[h],c[a]=n[u]<<8|n[h]}return{sbox:n,sbox2:c,T0:e,T1:r,T2:o,T3:i,T01:s,T23:f}}function $t(n){Y(n);let t=n.length;Or(n);let{sbox2:e}=Zo,r=[];(!Ot||!Tt(n))&&r.push(n=mt(n));let o=J(Q(n)),i=o.length,s=c=>se(e,c,c,c,c),f=new Uint32Array(t+28);f.set(o);for(let c=i;c<f.length;c++){let u=f[c-1];c%i===0?u=s(Cu(u))^ku[c/i-1]:i>6&&c%i===4&&(u=s(u)),f[c]=f[c-i]^u}return nt(...r),f}function Ur(n){let t=$t(n),e=t.slice(),r=t.length,{sbox2:o}=Zo,{T0:i,T1:s,T2:f,T3:c}=nc;for(let u=0;u<r;u+=4)for(let h=0;h<4;h++)e[u+h]=t[r-u-4+h];nt(t);for(let u=4;u<r-4;u++){let h=e[u],a=se(o,h,h,h,h);e[u]=i[a&255]^s[a>>>8&255]^f[a>>>16&255]^c[a>>>24]}return e}function Ue(n,t,e,r,o,i){return n[e<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function se(n,t,e,r,o){return n[t&255|e&65280]|n[r>>>16&255|o>>>16&65280]<<16}function Ut(n,t,e,r,o){let{sbox2:i,T01:s,T23:f}=Zo,c=0;t^=n[c++],e^=n[c++],r^=n[c++],o^=n[c++];let u=n.length/4-2;for(let g=0;g<u;g++){let y=n[c++]^Ue(s,f,t,e,r,o),m=n[c++]^Ue(s,f,e,r,o,t),x=n[c++]^Ue(s,f,r,o,t,e),v=n[c++]^Ue(s,f,o,t,e,r);t=y,e=m,r=x,o=v}let h=n[c++]^se(i,t,e,r,o),a=n[c++]^se(i,e,r,o,t),l=n[c++]^se(i,r,o,t,e),d=n[c++]^se(i,o,t,e,r);return{s0:h,s1:a,s2:l,s3:d}}function qn(n,t,e,r,o){let{sbox2:i,T01:s,T23:f}=nc,c=0;t^=n[c++],e^=n[c++],r^=n[c++],o^=n[c++];let u=n.length/4-2;for(let g=0;g<u;g++){let y=n[c++]^Ue(s,f,t,o,r,e),m=n[c++]^Ue(s,f,e,t,o,r),x=n[c++]^Ue(s,f,r,e,t,o),v=n[c++]^Ue(s,f,o,r,e,t);t=y,e=m,r=x,o=v}let h=n[c++]^se(i,t,o,r,e),a=n[c++]^se(i,e,t,o,r),l=n[c++]^se(i,r,e,t,o),d=n[c++]^se(i,o,r,e,t);return{s0:h,s1:a,s2:l,s3:d}}function rc(n,t,e,r){Y(t,it,"nonce"),Y(e);let o=e.length;r=hn(o,r),Ar(e,r);let i=t,s=Q(i),f=Q(e),c=Q(r);for(let h=0;h+4<=f.length;h+=4){let{s0:a,s1:l,s2:d,s3:g}=Ut(n,X(s[0]),X(s[1]),X(s[2]),X(s[3]));c[h+0]=f[h+0]^X(a),c[h+1]=f[h+1]^X(l),c[h+2]=f[h+2]^X(d),c[h+3]=f[h+3]^X(g);for(let y=it-1,m=1;y>=0;y--)m=m+i[y]|0,i[y]=m&255,m>>>=8}let u=it*Math.floor(f.length/$o);if(u<o){let{s0:h,s1:a,s2:l,s3:d}=Ut(n,X(s[0]),X(s[1]),X(s[2]),X(s[3])),g=new Uint32Array([h,a,l,d]);J(g);let y=Sr(g);for(let m=u,x=0;m<o;m++,x++)r[m]=e[m]^y[x];nt(g)}return r}function pn(n,t,e,r,o){Y(e,it,"nonce"),Y(r),o=hn(r.length,o);let i=e,s=Q(i),f=ln(i),c=Q(r),u=Q(o),h=t?0:12,a=r.length,l=f.getUint32(h,t);for(let g=0;g+4<=c.length;g+=4){let{s0:y,s1:m,s2:x,s3:v}=Ut(n,X(s[0]),X(s[1]),X(s[2]),X(s[3]));u[g+0]=c[g+0]^X(y),u[g+1]=c[g+1]^X(m),u[g+2]=c[g+2]^X(x),u[g+3]=c[g+3]^X(v),l=l+1>>>0,f.setUint32(h,l,t)}let d=it*Math.floor(c.length/$o);if(d<a){let{s0:g,s1:y,s2:m,s3:x}=Ut(n,X(s[0]),X(s[1]),X(s[2]),X(s[3])),v=new Uint32Array([g,y,m,x]);J(v);let _=Sr(v);for(let b=d,R=0;b<a;b++,R++)o[b]=r[b]^_[R];nt(v)}return o}function oc(n,t){if(Y(n),n.length%it!==0)throw new Error("ciphertext must be multiple of "+it);t!==void 0&&(hn(n.length,t),Ar(n,t))}function ic(n,t,e){Y(n);let r=n.length,o=r%it;if(!t&&o!==0)throw new Error("plaintext must be multiple of "+it);if(t){let i=it-o;i||(i=it),r=r+i}return e!==void 0&&(hn(r,e),Ar(n,e)),r}function sc(n,t,e){e===void 0&&(e=new Uint8Array(t)),(!Ot||!Tt(n))&&(n=mt(n));let r=Q(e);return{b:n,o:r,out:e}}function cc(n,t){if(!t)return n;let e=n.length;if(e===0)throw new Error("pkcs7: empty ciphertext not allowed");let r=n[e-1],o=1;o&=r-1>>>31^1,o&=16-r>>>31^1;for(let i=0;i<16;i++){let s=i-r>>>31,f=(n[e-1-i]^r)===0?1:0;o&=f|s^1}if(!o)throw new Error("aes: bad decrypt");return n.subarray(0,e-r)}function fc(n){let t=new Uint8Array(16),e=Q(t);t.set(n);let r=it-n.length;for(let o=it-r;o<it;o++)t[o]=r;return e}function uc(n,t,e,r,o){let i=o?o.length:0,s=n.create(e,r.length+i);o&&s.update(o);let f=Gs(8*r.length,8*i,t);s.update(r),s.update(f);let c=s.digest();return nt(f),c}function ac(n){return n instanceof Uint32Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint32Array"}function Ir(n,t){if(Y(t,16,"block"),!ac(n))throw new Error("_encryptBlock accepts result of expandKeyLE");let e=Q(t);J(e);let{s0:r,s1:o,s2:i,s3:s}=Ut(n,e[0],e[1],e[2],e[3]);return e[0]=r,e[1]=o,e[2]=i,e[3]=s,J(e),t}function lc(n,t){if(Y(t,16,"block"),!ac(n))throw new Error("_decryptBlock accepts result of expandKeyLE");let e=Q(t);J(e);let{s0:r,s1:o,s2:i,s3:s}=qn(n,e[0],e[1],e[2],e[3]);return e[0]=r,e[1]=o,e[2]=i,e[3]=s,J(e),t}function Hn(n){let t=0;for(let e=it-1;e>=0;e--){let r=(n[e]&128)>>>7;n[e]=n[e]<<1|t,t=r}return n[it-1]^=135&-t,n}function mn(n,t){if(n.length!==t.length)throw new Error("xorBlock: blocks must have same length");for(let e=0;e<n.length;e++)n[e]=n[e]^t[e];return n}function dc(n,t){if(t.length>n.length)throw new Error("xorend: expected len(B) <= len(A)");let e=n.length-t.length;for(let r=0;r<t.length;r++)n[e+r]=n[e+r]^t[r];return n}function Ko(n,t){Or(n);let e=t.length;if(e>127)throw new Error("s2v: expected <= 127 inputs");if(e===0)return Pn(_u,n);let r=Pn(Dn,n);for(let f=0;f<e-1;f++){Hn(r);let c=Pn(t[f],n);mn(r,c),nt(c)}let o=t[e-1];Y(o);let i;if(o.byteLength>=it)i=dc(Uint8Array.from(o),r);else{let f=new Uint8Array(it);f.set(o),f[o.length]=128,i=mn(Hn(r),f),nt(f)}let s=Pn(i,n);return nt(r,i),s}var it,$o,Dn,_u,Fu,Tr,Ho,Lu,Cu,Po,Zo,nc,ku,yn,ju,Nu,Du,Pu,gn,Hu,Rr,Js,qu,tc,Mu,qo,hc,Ku,$u,Mo,Pn,zu,Zu,Yu,Vu,Vo=At(()=>{L();Qs();ko();it=16,$o=4,Dn=new Uint8Array(it),_u=Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]),Fu=283;Tr=(n,t,e=1)=>{if(!Number.isSafeInteger(e)||e<0||e>4294967040)throw new Error("incBytes: wrong carry "+e);Y(n);for(let r=0;r<n.length;r++){let o=t?r:n.length-1-r;e=e+(n[o]&255)|0,n[o]=e&255,e>>>=8}},Ho=(()=>{let n=new Uint8Array(256);for(let e=0,r=1;e<256;e++,r^=zo(r))n[e]=r;let t=new Uint8Array(256);t[0]=99;for(let e=0;e<255;e++){let r=n[255-e];r|=r<<8,t[n[e]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return nt(n),t})(),Lu=Ho.map((n,t)=>Ho.indexOf(t)),Cu=n=>n<<24|n>>>8,Po=n=>n<<8|n>>>24;Zo=ec(Ho,n=>dn(n,3)<<24|n<<16|n<<8|dn(n,2)),nc=ec(Lu,n=>dn(n,11)<<24|dn(n,13)<<16|dn(n,9)<<8|dn(n,14)),ku=(()=>{let n=new Uint8Array(16);for(let t=0,e=1;t<16;t++,e=zo(e))n[t]=e;return n})();yn=re({blockSize:16,nonceLength:16},function(t,e){function r(o,i){if(Y(o),i!==void 0&&(Y(i),!Tt(i)))throw new Error("unaligned destination");let s=$t(t),f=mt(e),c=[s,f];Tt(o)||c.push(o=mt(o));let u=rc(s,f,o,i);return nt(...c),u}return{encrypt:(o,i)=>r(o,i),decrypt:(o,i)=>r(o,i)}});ju=re({blockSize:16},function(t,e={}){let r=!e.disablePadding;return{encrypt(o,i){let s=ic(o,r,i),f=$t(t),{b:c,o:u,out:h}=sc(o,s,i),a=Q(c);J(a);let l=0;for(;l+4<=a.length;){let{s0:d,s1:g,s2:y,s3:m}=Ut(f,a[l+0],a[l+1],a[l+2],a[l+3]);u[l++]=d,u[l++]=g,u[l++]=y,u[l++]=m}if(r){let d=fc(o.subarray(l*4));J(d);let{s0:g,s1:y,s2:m,s3:x}=Ut(f,d[0],d[1],d[2],d[3]);u[l++]=g,u[l++]=y,u[l++]=m,u[l++]=x,nt(d)}return J(u),nt(f),c!==o&&nt(c),h},decrypt(o,i){oc(o,i);let s=Ur(t);i===void 0&&(i=new Uint8Array(o.length));let f=[s];(!Ot||!Tt(o))&&f.push(o=mt(o));let c=Q(o),u=Q(i);J(c);for(let h=0;h+4<=c.length;){let{s0:a,s1:l,s2:d,s3:g}=qn(s,c[h+0],c[h+1],c[h+2],c[h+3]);u[h++]=a,u[h++]=l,u[h++]=d,u[h++]=g}return J(u),nt(...f),cc(i,r)}}}),Nu=re({blockSize:16,nonceLength:16},function(t,e,r={}){let o=!r.disablePadding;return{encrypt(i,s){let f=ic(i,o,s),c=$t(t),{b:u,o:h,out:a}=sc(i,f,s),l=Q(u);J(l);let d=e,g=[c];(!Ot||!Tt(d))&&g.push(d=mt(d));let y=Q(d);J(y);let m=y[0],x=y[1],v=y[2],_=y[3],b=0;for(;b+4<=l.length;)m^=l[b+0],x^=l[b+1],v^=l[b+2],_^=l[b+3],{s0:m,s1:x,s2:v,s3:_}=Ut(c,m,x,v,_),h[b++]=m,h[b++]=x,h[b++]=v,h[b++]=_;if(o){let R=fc(i.subarray(b*4));J(R),m^=R[0],x^=R[1],v^=R[2],_^=R[3],{s0:m,s1:x,s2:v,s3:_}=Ut(c,m,x,v,_),h[b++]=m,h[b++]=x,h[b++]=v,h[b++]=_,nt(R)}return J(h),nt(...g),u!==i&&nt(u),a},decrypt(i,s){oc(i,s);let f=Ur(t);s===void 0&&(s=new Uint8Array(i.length));let c=e,u=[f];(!Ot||!Tt(c))&&u.push(c=mt(c));let h=Q(c);J(h),(!Ot||!Tt(i))&&u.push(i=mt(i));let a=Q(i),l=Q(s);J(a);let d=h[0],g=h[1],y=h[2],m=h[3];for(let x=0;x+4<=a.length;){let v=d,_=g,b=y,R=m;d=a[x+0],g=a[x+1],y=a[x+2],m=a[x+3];let{s0:V,s1:W,s2:at,s3:G}=qn(f,d,g,y,m);l[x++]=V^v,l[x++]=W^_,l[x++]=at^b,l[x++]=G^R}return J(l),nt(...u),cc(s,o)}}}),Du=re({blockSize:16,nonceLength:16},function(t,e){function r(o,i,s){Y(o);let f=o.length;if(s=hn(f,s),Lo(o,s))throw new Error("overlapping src and dst not supported");let c=$t(t),u=e,h=[c];(!Ot||!Tt(u))&&h.push(u=mt(u)),(!Ot||!Tt(o))&&h.push(o=mt(o));let a=Q(o),l=Q(s),d=i?l:a,g=Q(u);J(a),J(g);let y=g[0],m=g[1],x=g[2],v=g[3];for(let b=0;b+4<=a.length;){let{s0:R,s1:V,s2:W,s3:at}=Ut(c,y,m,x,v);l[b+0]=a[b+0]^R,l[b+1]=a[b+1]^V,l[b+2]=a[b+2]^W,l[b+3]=a[b+3]^at,y=d[b++],m=d[b++],x=d[b++],v=d[b++]}let _=it*Math.floor(a.length/$o);if(_<f){Ot||J(a.subarray(_/4)),{s0:y,s1:m,s2:x,s3:v}=Ut(c,y,m,x,v);let b=new Uint32Array([y,m,x,v]);J(b);let R=Sr(b);for(let V=_,W=0;V<f;V++,W++)s[V]=o[V]^R[W];nt(R)}return Ot||J(l.subarray(0,_/4)),nt(...h),s}return{encrypt:(o,i)=>r(o,!0,i),decrypt:(o,i)=>r(o,!1,i)}});Pu=re({blockSize:16,nonceLength:12,tagLength:16,withAAD:!0,varSizeNonce:!0},function(t,e,r){if(e.length<8)throw new Error("aes/gcm: invalid nonce length");let o=16;function i(f,c,u){let h=uc(Do,!1,f,u,r);for(let a=0;a<c.length;a++)h[a]^=c[a];return h}function s(){let f=$t(t),c=Dn.slice(),u=Dn.slice();if(pn(f,!1,u,u,c),e.length===12)u.set(e);else{let a=Dn.slice();ln(a).setBigUint64(8,BigInt(e.length*8),!1);let d=Do.create(c).update(e).update(a);d.digestInto(u),d.destroy()}let h=pn(f,!1,u,Dn);return{xk:f,authKey:c,counter:u,tagMask:h}}return{encrypt(f){let{xk:c,authKey:u,counter:h,tagMask:a}=s(),l=new Uint8Array(f.length+o),d=[c,u,h,a];Tt(f)||d.push(f=mt(f)),pn(c,!1,h,f,l.subarray(0,f.length));let g=i(u,a,l.subarray(0,l.length-o));return d.push(g),l.set(g,f.length),nt(...d),l},decrypt(f){let{xk:c,authKey:u,counter:h,tagMask:a}=s(),l=[c,u,a,h];Tt(f)||l.push(f=mt(f));let d=f.subarray(0,-o),g=f.subarray(-o),y=i(u,a,d);if(l.push(y),!kn(y,g))throw nt(...l),new Error("aes-gcm: invalid tag");let m=pn(c,!1,h,d);return nt(...l),m}}}),gn=(n,t,e)=>r=>{if(!Number.isSafeInteger(r)||t>r||r>e){let o="["+t+".."+e+"]";throw new Error(""+n+": expected value in range "+o+", got "+r)}},Hu=re({blockSize:16,nonceLength:12,tagLength:16,withAAD:!0,varSizeNonce:!0},function(t,e,r){let i=gn("AAD",0,68719476736),s=gn("plaintext",0,2**36),f=gn("nonce",12,12),c=gn("ciphertext",16,2**36+16);Y(t),Or(t),f(e.length),r!==void 0&&i(r.length);function u(){let l=$t(t),d=new Uint8Array(t.length),g=new Uint8Array(16),y=[l,d],m=e;(!Ot||!Tt(m))&&y.push(m=mt(m));let x=Q(m);J(x);let v=0,_=x[0],b=x[1],R=x[2],V=0;for(let at of[g,d].map(Q)){let G=Q(at);for(let K=0;K<G.length;K+=2){let{s0:St,s1:gt}=Ut(l,v,_,b,R);G[K+0]=St,G[K+1]=gt,v=++V}J(G)}let W={authKey:g,encKey:$t(d)};return nt(...y),W}function h(l,d,g){let y=uc(Xs,!0,d,g,r);for(let R=0;R<12;R++)y[R]^=e[R];y[15]&=127;let m=Q(y);J(m);let x=m[0],v=m[1],_=m[2],b=m[3];return{s0:x,s1:v,s2:_,s3:b}=Ut(l,x,v,_,b),m[0]=x,m[1]=v,m[2]=_,m[3]=b,J(m),y}function a(l,d,g){let y=mt(d);y[15]|=128;let m=pn(l,!0,y,g);return nt(y),m}return{encrypt(l){s(l.length);let{encKey:d,authKey:g}=u(),y=h(d,g,l),m=[d,g,y];Tt(l)||m.push(l=mt(l));let x=new Uint8Array(l.length+16);return x.set(y,l.length),x.set(a(d,y,l)),nt(...m),x},decrypt(l){c(l.length);let d=l.subarray(-16),{encKey:g,authKey:y}=u(),m=[g,y];Tt(l)||m.push(l=mt(l));let x=a(g,d,l.subarray(0,-16)),v=h(g,y,x);if(m.push(v),!kn(d,v))throw nt(x,...m),new Error("invalid polyval tag");return nt(...m),x}}});Rr={encrypt(n,t){if(t.length>=2**32)throw new Error("plaintext should be less than 4gb");let e=$t(n);if(t.length===16)Ir(e,t);else{let r=Q(t);J(r);let o=r[0],i=r[1];for(let s=0,f=1;s<6;s++)for(let c=2;c<r.length;c+=2,f++){let{s0:u,s1:h,s2:a,s3:l}=Ut(e,o,i,r[c],r[c+1]);o=u,i=h^Ze(f),r[c]=a,r[c+1]=l}r[0]=o,r[1]=i,J(r)}e.fill(0)},decrypt(n,t){if(t.length-8>=2**32)throw new Error("ciphertext should be less than 4gb");let e=Ur(n),r=t.length/8-1;if(r===1)lc(e,t);else{let o=Q(t);J(o);let i=o[0],s=o[1];for(let f=0,c=r*6;f<6;f++)for(let u=r*2;u>=1;u-=2,c--){s^=Ze(c);let{s0:h,s1:a,s2:l,s3:d}=qn(e,i,s,o[u],o[u+1]);i=h,s=a,o[u]=l,o[u+1]=d}o[0]=i,o[1]=s,J(o)}e.fill(0)}},Js=new Uint8Array(8).fill(166),qu=re({blockSize:8},n=>({encrypt(t){if(!t.length||t.length%8!==0)throw new Error("invalid plaintext length");if(t.length===8)throw new Error("8-byte keys not allowed, use AESKWP");let e=Co(Js,t);return Rr.encrypt(n,e),e},decrypt(t){if(t.length%8!==0||t.length<24)throw new Error("invalid ciphertext length");let e=mt(t);if(Rr.decrypt(n,e),!kn(e.subarray(0,8),Js))throw new Error("integrity check failed");return e.subarray(0,8).fill(0),e.subarray(8)}})),tc=2790873510,Mu=re({blockSize:8},n=>({encrypt(t){if(!t.length)throw new Error("invalid plaintext length");let e=Math.ceil(t.length/8)*8,r=new Uint8Array(8+e);r.set(t,8);let o=Q(r);return o[0]=X(tc),o[1]=X(Ze(t.length)),Rr.encrypt(n,r),r},decrypt(t){if(t.length<16)throw new Error("invalid ciphertext length");let e=mt(t),r=Q(e);Rr.decrypt(n,e);let o=Ze(X(r[1]))>>>0,i=Math.ceil(o/8)*8;if(X(r[0])!==tc||e.length-8!==i)throw new Error("integrity check failed");for(let s=o;s<i;s++)if(e[8+s]!==0)throw new Error("integrity check failed");return e.subarray(0,8).fill(0),e.subarray(8,8+o)}})),qo=class{constructor(t,e,r){S(this,"blockLen");S(this,"key");S(this,"nonce");S(this,"state");S(this,"reseedCnt");this.blockLen=yn.blockSize;let o=t/8,i=16;this.state=new Uint8Array(o+i),this.key=this.state.subarray(0,o),this.nonce=this.state.subarray(o,o+i),this.reseedCnt=1,Tr(this.nonce,!1,1),this.addEntropy(e,r)}update(t){if(yn(this.key,this.nonce).encrypt(new Uint8Array(this.state.length),this.state),t){Y(t);for(let e=0;e<t.length;e++)this.state[e]^=t[e]}Tr(this.nonce,!1,1)}addEntropy(t,e){Y(t,this.state.length,"seed");let r=t.slice();if(e){if(Y(e),e.length>r.length)throw new Error("info length is too big");for(let o=0;o<e.length;o++)r[o]^=e[o]}this.update(r),r.fill(0),this.reseedCnt=1}randomBytes(t,e){if(Ln(t),t>2**16)throw new Error("requested output is too big");if(this.reseedCnt>2**48)throw new Error("entropy exhausted");if(e){if(Y(e),e.length>this.state.length)throw new Error("info length is too big");this.update(e)}let r=new Uint8Array(t);return yn(this.key,this.nonce).encrypt(r,r),Tr(this.nonce,!1,Math.ceil(t/this.blockLen)),this.update(e),this.reseedCnt++,r}clean(){this.state.fill(0),this.reseedCnt=0}},hc=n=>(t,e=void 0)=>new qo(n,t,e),Ku=hc(128),$u=hc(256);Mo=class{constructor(t){S(this,"blockLen",it);S(this,"outputLen",it);S(this,"buffer");S(this,"pos");S(this,"finished");S(this,"destroyed");S(this,"k1");S(this,"k2");S(this,"x");S(this,"x32");S(this,"xk");Y(t),Or(t),this.xk=$t(t),this.buffer=new Uint8Array(it),this.pos=0,this.finished=!1,this.destroyed=!1,this.x=new Uint8Array(it),this.x32=Q(this.x);let e=new Uint8Array(it);Ir(this.xk,e),this.k1=Hn(e),this.k2=Hn(new Uint8Array(this.k1))}process(t,e){let{x:r,x32:o,xk:i}=this;for(let h=0;h<it;h++)r[h]^=t[e+h];J(o);let{s0:s,s1:f,s2:c,s3:u}=Ut(i,o[0],o[1],o[2],o[3]);o[0]=s,o[1]=f,o[2]=c,o[3]=u,J(o)}update(t){Re(this),Y(t);let e=0;if(this.pos){let r=Math.min(it-this.pos,t.length);this.buffer.set(t.subarray(0,r),this.pos),this.pos+=r,e=r,this.pos===it&&e<t.length&&(this.process(this.buffer,0),this.pos=0)}for(;e+it<t.length;)this.process(t,e),e+=it;return e<t.length&&(this.buffer.set(t.subarray(e),0),this.pos=t.length-e),this}digestInto(t){Re(this),Cn(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen),r=new Uint8Array(it);this.pos===it?(r.set(this.buffer),mn(r,this.k1)):(r.set(this.buffer.subarray(0,this.pos)),r[this.pos]=128,mn(r,this.k2)),e.set(this.x),mn(e,r),Ir(this.xk,e),nt(r)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}destroy(){let{buffer:t,destroyed:e,x:r,xk:o,k1:i,k2:s}=this;e||(this.destroyed=!0,nt(t,r,o,i,s))}},Pn=jn(16,n=>new Mo(n));zu=()=>{throw new Error('"siv" from v1 is now "gcmsiv"')},Zu=re({blockSize:16,tagLength:16,withAAD:!0},function(t,...e){let r=gn("plaintext",0,5444517870735016e24),o=gn("ciphertext",16,2**132+16);if(e.length>126)throw new Error('"AAD" expected <= 126 items');if(e.forEach(f=>Y(f)),Y(t),![32,48,64].includes(t.length))throw new Error('"aes key" expected Uint8Array of length 32/48/64, got length='+t.length);let i=t.subarray(0,t.length/2),s=t.subarray(t.length/2);return{encrypt(f){r(f.length);let c=Ko(i,[...e,f]),u=Uint8Array.from(c);u[8]&=127,u[12]&=127;let h=yn(s,u).encrypt(f);return Co(c,h)},decrypt(f){o(f.length);let c=f.subarray(0,it),u=f.subarray(it),h=Uint8Array.from(c);h[8]&=127,h[12]&=127;let a=yn(s,h).decrypt(u),l=Ko(i,[...e,a]);if(kn(l,c))return a;throw nt(a),new Error("invalid siv tag")}}}),Yu=Object.freeze({expandKeyLE:$t,expandKeyDecLE:Ur,encrypt:Ut,decrypt:qn,encryptBlock:Ir,decryptBlock:lc,ctrCounter:rc,ctr32:pn,dbl:Hn,xorBlock:mn,xorend:dc,s2v:Ko}),Vu=Object.freeze({incBytes:Tr})});var gc=kt((Kl,pc)=>{L();pc.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.crypto.Random});var xc=kt((zl,wc)=>{"use strict";L();var{secp256k1:yc}=(_o(),ge(Uo)),{sha512:Wu,sha256:Gu}=(ur(),ge(eo)),{hmac:Xu}=(xr(),ge(bo)),{cbc:mc}=(Vo(),ge(Yo)),Qu=Vr(),_e=Wr(),Ju=gc();function Mn(n){return M.Buffer.from(n.buffer,n.byteOffset,n.byteLength)}function Wo(n,t){return Mn(Xu(Gu,n,t))}function ta(n,t){if(n.length!==t.length)return!1;for(var e=0,r=0;r<n.length;r++)e|=n[r]^t[r];return e===0}var _r=function(){};_r.encrypt=function(n,t,e){_e.checkArgument(n),_e.checkArgument(t),_e.checkArgument(e),e=e||Ju.getRandomBuffer(128/8);var r=mc(Uint8Array.from(t),Uint8Array.from(e)).encrypt(Uint8Array.from(n));return M.Buffer.concat([M.Buffer.from(e),Mn(r)])};_r.decrypt=function(n,t){_e.checkArgument(n),_e.checkArgument(t);var e=n.slice(0,128/8),r=n.slice(128/8),o=mc(Uint8Array.from(t),Uint8Array.from(e)).decrypt(Uint8Array.from(r));return Mn(o)};var wn=function n(t){if(!(this instanceof n))return new n(t);this.opts=t||{}};wn.prototype.privateKey=function(n){return _e.checkArgument(n,"no private key provided"),this._privateKey=n||null,this};wn.prototype.publicKey=function(n){return _e.checkArgument(n,"no public key provided"),this._publicKey=n||null,this};var Fr=function(n,t){var e="_"+n;Object.defineProperty(wn.prototype,n,{configurable:!1,enumerable:!0,get:function(){var r=this[e];return r||(r=this[e]=t.apply(this)),r}})};Fr("Rbuf",function(){var n=this._privateKey.bn.toBuffer({size:32});return Mn(yc.getPublicKey(Uint8Array.from(n),!0))});Fr("kEkM",function(){var n=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),e=yc.getSharedSecret(Uint8Array.from(n),Uint8Array.from(t),!0),r=e.slice(1);return Mn(Wu(r))});Fr("kE",function(){return this.kEkM.slice(0,32)});Fr("kM",function(){return this.kEkM.slice(32,64)});wn.prototype.encrypt=function(n,t){M.Buffer.isBuffer(n)||(n=M.Buffer.from(n)),t===void 0&&(t=Wo(this._privateKey.toBuffer(),n).slice(0,16));var e=_r.encrypt(n,this.kE,t),r=Wo(this.kM,e);return this.opts.shortTag&&(r=r.slice(0,4)),this.opts.noKey?M.Buffer.concat([e,r]):M.Buffer.concat([this.Rbuf,e,r])};wn.prototype.decrypt=function(n){_e.checkArgument(n);var t=0,e=this.opts.shortTag?4:32;if(!this.opts.noKey){var r;switch(n[0]){case 4:r=n.slice(0,65);break;case 3:case 2:r=n.slice(0,33);break;default:throw new Error("Invalid type: "+n[0])}this._publicKey=Qu.fromDER(r),t+=r.length}var o=n.slice(t,n.length-e),i=n.slice(n.length-e,n.length),s=Wo(this.kM,o);if(this.opts.shortTag&&(s=s.slice(0,4)),!ta(i,s))throw new Error("Invalid checksum");return _r.decrypt(o,this.kE)};wc.exports=wn});var Ec=kt((Yl,bc)=>{L();bc.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.errors});var Sc=kt((Wl,Bc)=>{"use strict";L();var ea={name:"ECIES",message:"Internal Error on bsv-ecies Module {0}",errors:[{name:"DecryptionError",message:"Invalid Message: {0}"},{name:"UnsupportAlgorithm",message:"Unsupport Algorithm: {0}"}]};Bc.exports=Ec().extend(ea)});var Rc=kt((Xl,Ic)=>{"use strict";L();var Go=Vr(),Xo=Ri(),Dt=Wr(),na=xc(),Lr=Sc(),{secp256k1:Ac}=(_o(),ge(Uo)),{sha512:ra,sha256:oa}=(ur(),ge(eo)),{hmac:ia}=(xr(),ge(bo)),{cbc:vc}=(Vo(),ge(Yo));function Kn(n){return M.Buffer.from(n.buffer,n.byteOffset,n.byteLength)}function Tc(n,t){return Kn(ia(oa,t,n))}var Cr=function(){};Cr.encrypt=function(n,t,e){return Dt.checkArgument(n),Dt.checkArgument(t),Dt.checkArgument(e),Dt.checkArgument(t.length===16,"keybuf length must be 16"),Dt.checkArgument(e.length===16,"ivbuf length must be 16"),Kn(vc(Uint8Array.from(t),Uint8Array.from(e)).encrypt(Uint8Array.from(n)))};Cr.decrypt=function(n,t,e){return Dt.checkArgument(n),Dt.checkArgument(t),Dt.checkArgument(e),Dt.checkArgument(t.length===16,"keybuf length must be 16"),Dt.checkArgument(e.length===16,"ivbuf length must be 16"),Kn(vc(Uint8Array.from(t),Uint8Array.from(e)).decrypt(Uint8Array.from(n)))};var Ye=function n(t,e="BIE1"){if(e!=="BIE1")throw new Lr.UnsupportAlgorithm(e);if(!(this instanceof n))return new n(t,e);this._privateKey=new Xo,this.opts=t||{},this.opts.ephemeralKey=!0};Ye.prototype.privateKey=function(n){return Dt.checkArgument(Xo.isValid(n),"no private key provided"),this._privateKey=Xo(n.toHex())||null,this.opts.ephemeralKey=!1,this};Ye.prototype.publicKey=function(n){return Dt.checkArgument(Go.isValid(n),"no public key provided"),this._publicKey=Go(n.toString())||null,this._publicKey!=null&&(this.opts.fixedPublicKey=!0),this};var $n=function(n,t){var e="_"+n;Object.defineProperty(Ye.prototype,n,{configurable:!1,enumerable:!0,get:function(){var r=this[e];return r=this[e]=t.apply(this),r}})};$n("Rbuf",function(){var n=this._privateKey.bn.toBuffer({size:32});return Kn(Ac.getPublicKey(Uint8Array.from(n),!0))});$n("ivkEkM",function(){var n=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),e=Ac.getSharedSecret(Uint8Array.from(n),Uint8Array.from(t),!0);return Kn(ra(e))});$n("iv",function(){return this.ivkEkM.slice(0,16)});$n("kE",function(){return this.ivkEkM.slice(16,32)});$n("kM",function(){return this.ivkEkM.slice(32,64)});Ye.prototype.encrypt=function(n){M.Buffer.isBuffer(n)||(n=M.Buffer.from(n));var t=Cr.encrypt(n,this.kE,this.iv),e,r=M.Buffer.from("BIE1");this.opts.noKey&&!this.opts.ephemeralKey?e=M.Buffer.concat([r,t]):e=M.Buffer.concat([r,this.Rbuf,t]);var o=Tc(e,this.kM);return this.opts.shortTag&&(o=o.slice(0,4)),M.Buffer.concat([e,o])};Ye.prototype.decrypt=function(n){Dt.checkArgument(M.Buffer.isBuffer(n),"ciphetext must be a buffer");var t=this.opts.shortTag?4:32,e=4,r=n.slice(0,4);if(!r.equals(M.Buffer.from("BIE1")))throw new Lr.DecryptionError("Invalid Magic");if(!this.opts.noKey){var o=n.slice(4,37);this.opts.fixedPublicKey?console.log('Notice: Overriding PublicKey in message. Consider use "noKey" option if you are not sending message to electrum and do not want to use ephemeral key'):this._publicKey=Go.fromDER(o),e=37}var i=n.slice(e,n.length-t),s=n.slice(n.length-t,n.length),f=Tc(n.slice(0,n.length-t),this.kM);if(this.opts.shortTag&&(f=f.slice(0,4)),s.length!==f.length)throw new Lr.DecryptionError("Invalid checksum");for(var c=0,u=0;u<f.length;u++)c|=s[u]^f[u];if(c!==0)throw new Lr.DecryptionError("Invalid checksum");return Cr.decrypt(i,this.kE,this.iv)};Ye.bitcoreECIES=na;Ic.exports=Ye});var Uc=kt((Jl,Oc)=>{L();Oc.exports=Rc()});var sa=kt((eh,_c)=>{L();_c.exports=Uc()});return sa();})();
1
+ var bsvEcies=(()=>{var Gc=Object.create;var Ln=Object.defineProperty;var Xc=Object.getOwnPropertyDescriptor;var Qc=Object.getOwnPropertyNames;var Jc=Object.getPrototypeOf,tf=Object.prototype.hasOwnProperty;var ef=(e,t,n)=>t in e?Ln(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ot=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(r){throw n=[r],r}};var Ht=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}},fr=(e,t)=>{for(var n in t)Ln(e,n,{get:t[n],enumerable:!0})},gi=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Qc(t))!tf.call(e,o)&&o!==n&&Ln(e,o,{get:()=>t[o],enumerable:!(r=Xc(t,o))||r.enumerable});return e};var yi=(e,t,n)=>(n=e!=null?Gc(Jc(e)):{},gi(t||!e||!e.__esModule?Ln(n,"default",{value:e,enumerable:!0}):n,e)),ve=e=>gi(Ln({},"__esModule",{value:!0}),e);var S=(e,t,n)=>ef(e,typeof t!="symbol"?t+"":t,n);var Ei=Ht((va,bi)=>{C();var Et=bi.exports={},Jt,te;function Jr(){throw new Error("setTimeout has not been defined")}function to(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Jt=setTimeout:Jt=Jr}catch{Jt=Jr}try{typeof clearTimeout=="function"?te=clearTimeout:te=to}catch{te=to}})();function mi(e){if(Jt===setTimeout)return setTimeout(e,0);if((Jt===Jr||!Jt)&&setTimeout)return Jt=setTimeout,setTimeout(e,0);try{return Jt(e,0)}catch{try{return Jt.call(null,e,0)}catch{return Jt.call(this,e,0)}}}function nf(e){if(te===clearTimeout)return clearTimeout(e);if((te===to||!te)&&clearTimeout)return te=clearTimeout,clearTimeout(e);try{return te(e)}catch{try{return te.call(null,e)}catch{return te.call(this,e)}}}var ye=[],fn=!1,$e,ur=-1;function rf(){!fn||!$e||(fn=!1,$e.length?ye=$e.concat(ye):ur=-1,ye.length&&wi())}function wi(){if(!fn){var e=mi(rf);fn=!0;for(var t=ye.length;t;){for($e=ye,ye=[];++ur<t;)$e&&$e[ur].run();ur=-1,t=ye.length}$e=null,fn=!1,nf(e)}}Et.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];ye.push(new xi(e,t)),ye.length===1&&!fn&&mi(wi)};function xi(e,t){this.fun=e,this.array=t}xi.prototype.run=function(){this.fun.apply(null,this.array)};Et.title="browser";Et.browser=!0;Et.env={};Et.argv=[];Et.version="";Et.versions={};function me(){}Et.on=me;Et.addListener=me;Et.once=me;Et.off=me;Et.removeListener=me;Et.removeAllListeners=me;Et.emit=me;Et.prependListener=me;Et.prependOnceListener=me;Et.listeners=function(e){return[]};Et.binding=function(e){throw new Error("process.binding is not supported")};Et.cwd=function(){return"/"};Et.chdir=function(e){throw new Error("process.chdir is not supported")};Et.umask=function(){return 0}});var Ai=Ht(ar=>{"use strict";C();ar.byteLength=sf;ar.toByteArray=ff;ar.fromByteArray=lf;var ee=[],Zt=[],of=typeof Uint8Array<"u"?Uint8Array:Array,eo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ze=0,Bi=eo.length;ze<Bi;++ze)ee[ze]=eo[ze],Zt[eo.charCodeAt(ze)]=ze;var ze,Bi;Zt[45]=62;Zt[95]=63;function Si(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function sf(e){var t=Si(e),n=t[0],r=t[1];return(n+r)*3/4-r}function cf(e,t,n){return(t+n)*3/4-n}function ff(e){var t,n=Si(e),r=n[0],o=n[1],i=new of(cf(e,r,o)),s=0,u=o>0?r-4:r,c;for(c=0;c<u;c+=4)t=Zt[e.charCodeAt(c)]<<18|Zt[e.charCodeAt(c+1)]<<12|Zt[e.charCodeAt(c+2)]<<6|Zt[e.charCodeAt(c+3)],i[s++]=t>>16&255,i[s++]=t>>8&255,i[s++]=t&255;return o===2&&(t=Zt[e.charCodeAt(c)]<<2|Zt[e.charCodeAt(c+1)]>>4,i[s++]=t&255),o===1&&(t=Zt[e.charCodeAt(c)]<<10|Zt[e.charCodeAt(c+1)]<<4|Zt[e.charCodeAt(c+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function uf(e){return ee[e>>18&63]+ee[e>>12&63]+ee[e>>6&63]+ee[e&63]}function af(e,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(e[i+2]&255),o.push(uf(r));return o.join("")}function lf(e){for(var t,n=e.length,r=n%3,o=[],i=16383,s=0,u=n-r;s<u;s+=i)o.push(af(e,s,s+i>u?u:s+i));return r===1?(t=e[n-1],o.push(ee[t>>2]+ee[t<<4&63]+"==")):r===2&&(t=(e[n-2]<<8)+e[n-1],o.push(ee[t>>10]+ee[t>>4&63]+ee[t<<2&63]+"=")),o.join("")}});var vi=Ht(no=>{C();no.read=function(e,t,n,r,o){var i,s,u=o*8-r-1,c=(1<<u)-1,a=c>>1,h=-7,l=n?o-1:0,f=n?-1:1,d=e[t+l];for(l+=f,i=d&(1<<-h)-1,d>>=-h,h+=u;h>0;i=i*256+e[t+l],l+=f,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=r;h>0;s=s*256+e[t+l],l+=f,h-=8);if(i===0)i=1-a;else{if(i===c)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,r),i=i-a}return(d?-1:1)*s*Math.pow(2,i-r)};no.write=function(e,t,n,r,o,i){var s,u,c,a=i*8-o-1,h=(1<<a)-1,l=h>>1,f=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:i-1,g=r?1:-1,y=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+l>=1?t+=f/c:t+=f*Math.pow(2,1-l),t*c>=2&&(s++,c/=2),s+l>=h?(u=0,s=h):s+l>=1?(u=(t*c-1)*Math.pow(2,o),s=s+l):(u=t*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;e[n+d]=u&255,d+=g,u/=256,o-=8);for(s=s<<o|u,a+=o;a>0;e[n+d]=s&255,d+=g,s/=256,a-=8);e[n+d-g]|=y*128}});var Mi=Ht(hn=>{"use strict";C();var ro=Ai(),an=vi(),Ti=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;hn.Buffer=b;hn.SlowBuffer=mf;hn.INSPECT_MAX_BYTES=50;var lr=2147483647;hn.kMaxLength=lr;b.TYPED_ARRAY_SUPPORT=hf();!b.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function hf(){try{let e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(b.prototype,"parent",{enumerable:!0,get:function(){if(b.isBuffer(this))return this.buffer}});Object.defineProperty(b.prototype,"offset",{enumerable:!0,get:function(){if(b.isBuffer(this))return this.byteOffset}});function we(e){if(e>lr)throw new RangeError('The value "'+e+'" is invalid for option "size"');let t=new Uint8Array(e);return Object.setPrototypeOf(t,b.prototype),t}function b(e,t,n){if(typeof e=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return co(e)}return Ui(e,t,n)}b.poolSize=8192;function Ui(e,t,n){if(typeof e=="string")return pf(e,t);if(ArrayBuffer.isView(e))return gf(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(ne(e,ArrayBuffer)||e&&ne(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(ne(e,SharedArrayBuffer)||e&&ne(e.buffer,SharedArrayBuffer)))return io(e,t,n);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=e.valueOf&&e.valueOf();if(r!=null&&r!==e)return b.from(r,t,n);let o=yf(e);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return b.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}b.from=function(e,t,n){return Ui(e,t,n)};Object.setPrototypeOf(b.prototype,Uint8Array.prototype);Object.setPrototypeOf(b,Uint8Array);function _i(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function df(e,t,n){return _i(e),e<=0?we(e):t!==void 0?typeof n=="string"?we(e).fill(t,n):we(e).fill(t):we(e)}b.alloc=function(e,t,n){return df(e,t,n)};function co(e){return _i(e),we(e<0?0:fo(e)|0)}b.allocUnsafe=function(e){return co(e)};b.allocUnsafeSlow=function(e){return co(e)};function pf(e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!b.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let n=Fi(e,t)|0,r=we(n),o=r.write(e,t);return o!==n&&(r=r.slice(0,o)),r}function oo(e){let t=e.length<0?0:fo(e.length)|0,n=we(t);for(let r=0;r<t;r+=1)n[r]=e[r]&255;return n}function gf(e){if(ne(e,Uint8Array)){let t=new Uint8Array(e);return io(t.buffer,t.byteOffset,t.byteLength)}return oo(e)}function io(e,t,n){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return t===void 0&&n===void 0?r=new Uint8Array(e):n===void 0?r=new Uint8Array(e,t):r=new Uint8Array(e,t,n),Object.setPrototypeOf(r,b.prototype),r}function yf(e){if(b.isBuffer(e)){let t=fo(e.length)|0,n=we(t);return n.length===0||e.copy(n,0,0,t),n}if(e.length!==void 0)return typeof e.length!="number"||ao(e.length)?we(0):oo(e);if(e.type==="Buffer"&&Array.isArray(e.data))return oo(e.data)}function fo(e){if(e>=lr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+lr.toString(16)+" bytes");return e|0}function mf(e){return+e!=e&&(e=0),b.alloc(+e)}b.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==b.prototype};b.compare=function(t,n){if(ne(t,Uint8Array)&&(t=b.from(t,t.offset,t.byteLength)),ne(n,Uint8Array)&&(n=b.from(n,n.offset,n.byteLength)),!b.isBuffer(t)||!b.isBuffer(n))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===n)return 0;let r=t.length,o=n.length;for(let i=0,s=Math.min(r,o);i<s;++i)if(t[i]!==n[i]){r=t[i],o=n[i];break}return r<o?-1:o<r?1:0};b.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};b.concat=function(t,n){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return b.alloc(0);let r;if(n===void 0)for(n=0,r=0;r<t.length;++r)n+=t[r].length;let o=b.allocUnsafe(n),i=0;for(r=0;r<t.length;++r){let s=t[r];if(ne(s,Uint8Array))i+s.length>o.length?(b.isBuffer(s)||(s=b.from(s)),s.copy(o,i)):Uint8Array.prototype.set.call(o,s,i);else if(b.isBuffer(s))s.copy(o,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return o};function Fi(e,t){if(b.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||ne(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let n=e.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return so(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return qi(e).length;default:if(o)return r?-1:so(e).length;t=(""+t).toLowerCase(),o=!0}}b.byteLength=Fi;function wf(e,t,n){let r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Rf(this,t,n);case"utf8":case"utf-8":return Ci(this,t,n);case"ascii":return Tf(this,t,n);case"latin1":case"binary":return If(this,t,n);case"base64":return Af(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Of(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}b.prototype._isBuffer=!0;function Ze(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}b.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let n=0;n<t;n+=2)Ze(this,n,n+1);return this};b.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let n=0;n<t;n+=4)Ze(this,n,n+3),Ze(this,n+1,n+2);return this};b.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let n=0;n<t;n+=8)Ze(this,n,n+7),Ze(this,n+1,n+6),Ze(this,n+2,n+5),Ze(this,n+3,n+4);return this};b.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?Ci(this,0,t):wf.apply(this,arguments)};b.prototype.toLocaleString=b.prototype.toString;b.prototype.equals=function(t){if(!b.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:b.compare(this,t)===0};b.prototype.inspect=function(){let t="",n=hn.INSPECT_MAX_BYTES;return t=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(t+=" ... "),"<Buffer "+t+">"};Ti&&(b.prototype[Ti]=b.prototype.inspect);b.prototype.compare=function(t,n,r,o,i){if(ne(t,Uint8Array)&&(t=b.from(t,t.offset,t.byteLength)),!b.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(n===void 0&&(n=0),r===void 0&&(r=t?t.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),n<0||r>t.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&n>=r)return 0;if(o>=i)return-1;if(n>=r)return 1;if(n>>>=0,r>>>=0,o>>>=0,i>>>=0,this===t)return 0;let s=i-o,u=r-n,c=Math.min(s,u),a=this.slice(o,i),h=t.slice(n,r);for(let l=0;l<c;++l)if(a[l]!==h[l]){s=a[l],u=h[l];break}return s<u?-1:u<s?1:0};function Li(e,t,n,r,o){if(e.length===0)return-1;if(typeof n=="string"?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,ao(n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0)if(o)n=0;else return-1;if(typeof t=="string"&&(t=b.from(t,r)),b.isBuffer(t))return t.length===0?-1:Ii(e,t,n,r,o);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):Ii(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function Ii(e,t,n,r,o){let i=1,s=e.length,u=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(e.length<2||t.length<2)return-1;i=2,s/=2,u/=2,n/=2}function c(h,l){return i===1?h[l]:h.readUInt16BE(l*i)}let a;if(o){let h=-1;for(a=n;a<s;a++)if(c(e,a)===c(t,h===-1?0:a-h)){if(h===-1&&(h=a),a-h+1===u)return h*i}else h!==-1&&(a-=a-h),h=-1}else for(n+u>s&&(n=s-u),a=n;a>=0;a--){let h=!0;for(let l=0;l<u;l++)if(c(e,a+l)!==c(t,l)){h=!1;break}if(h)return a}return-1}b.prototype.includes=function(t,n,r){return this.indexOf(t,n,r)!==-1};b.prototype.indexOf=function(t,n,r){return Li(this,t,n,r,!0)};b.prototype.lastIndexOf=function(t,n,r){return Li(this,t,n,r,!1)};function xf(e,t,n,r){n=Number(n)||0;let o=e.length-n;r?(r=Number(r),r>o&&(r=o)):r=o;let i=t.length;r>i/2&&(r=i/2);let s;for(s=0;s<r;++s){let u=parseInt(t.substr(s*2,2),16);if(ao(u))return s;e[n+s]=u}return s}function bf(e,t,n,r){return hr(so(t,e.length-n),e,n,r)}function Ef(e,t,n,r){return hr(Lf(t),e,n,r)}function Bf(e,t,n,r){return hr(qi(t),e,n,r)}function Sf(e,t,n,r){return hr(Cf(t,e.length-n),e,n,r)}b.prototype.write=function(t,n,r,o){if(n===void 0)o="utf8",r=this.length,n=0;else if(r===void 0&&typeof n=="string")o=n,r=this.length,n=0;else if(isFinite(n))n=n>>>0,isFinite(r)?(r=r>>>0,o===void 0&&(o="utf8")):(o=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let i=this.length-n;if((r===void 0||r>i)&&(r=i),t.length>0&&(r<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");let s=!1;for(;;)switch(o){case"hex":return xf(this,t,n,r);case"utf8":case"utf-8":return bf(this,t,n,r);case"ascii":case"latin1":case"binary":return Ef(this,t,n,r);case"base64":return Bf(this,t,n,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Sf(this,t,n,r);default:if(s)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),s=!0}};b.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Af(e,t,n){return t===0&&n===e.length?ro.fromByteArray(e):ro.fromByteArray(e.slice(t,n))}function Ci(e,t,n){n=Math.min(e.length,n);let r=[],o=t;for(;o<n;){let i=e[o],s=null,u=i>239?4:i>223?3:i>191?2:1;if(o+u<=n){let c,a,h,l;switch(u){case 1:i<128&&(s=i);break;case 2:c=e[o+1],(c&192)===128&&(l=(i&31)<<6|c&63,l>127&&(s=l));break;case 3:c=e[o+1],a=e[o+2],(c&192)===128&&(a&192)===128&&(l=(i&15)<<12|(c&63)<<6|a&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:c=e[o+1],a=e[o+2],h=e[o+3],(c&192)===128&&(a&192)===128&&(h&192)===128&&(l=(i&15)<<18|(c&63)<<12|(a&63)<<6|h&63,l>65535&&l<1114112&&(s=l))}}s===null?(s=65533,u=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),o+=u}return vf(r)}var Ri=4096;function vf(e){let t=e.length;if(t<=Ri)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=Ri));return n}function Tf(e,t,n){let r="";n=Math.min(e.length,n);for(let o=t;o<n;++o)r+=String.fromCharCode(e[o]&127);return r}function If(e,t,n){let r="";n=Math.min(e.length,n);for(let o=t;o<n;++o)r+=String.fromCharCode(e[o]);return r}function Rf(e,t,n){let r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let o="";for(let i=t;i<n;++i)o+=kf[e[i]];return o}function Of(e,t,n){let r=e.slice(t,n),o="";for(let i=0;i<r.length-1;i+=2)o+=String.fromCharCode(r[i]+r[i+1]*256);return o}b.prototype.slice=function(t,n){let r=this.length;t=~~t,n=n===void 0?r:~~n,t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),n<0?(n+=r,n<0&&(n=0)):n>r&&(n=r),n<t&&(n=t);let o=this.subarray(t,n);return Object.setPrototypeOf(o,b.prototype),o};function Ut(e,t,n){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}b.prototype.readUintLE=b.prototype.readUIntLE=function(t,n,r){t=t>>>0,n=n>>>0,r||Ut(t,n,this.length);let o=this[t],i=1,s=0;for(;++s<n&&(i*=256);)o+=this[t+s]*i;return o};b.prototype.readUintBE=b.prototype.readUIntBE=function(t,n,r){t=t>>>0,n=n>>>0,r||Ut(t,n,this.length);let o=this[t+--n],i=1;for(;n>0&&(i*=256);)o+=this[t+--n]*i;return o};b.prototype.readUint8=b.prototype.readUInt8=function(t,n){return t=t>>>0,n||Ut(t,1,this.length),this[t]};b.prototype.readUint16LE=b.prototype.readUInt16LE=function(t,n){return t=t>>>0,n||Ut(t,2,this.length),this[t]|this[t+1]<<8};b.prototype.readUint16BE=b.prototype.readUInt16BE=function(t,n){return t=t>>>0,n||Ut(t,2,this.length),this[t]<<8|this[t+1]};b.prototype.readUint32LE=b.prototype.readUInt32LE=function(t,n){return t=t>>>0,n||Ut(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};b.prototype.readUint32BE=b.prototype.readUInt32BE=function(t,n){return t=t>>>0,n||Ut(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};b.prototype.readBigUInt64LE=Te(function(t){t=t>>>0,ln(t,"offset");let n=this[t],r=this[t+7];(n===void 0||r===void 0)&&Cn(t,this.length-8);let o=n+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,i=this[++t]+this[++t]*2**8+this[++t]*2**16+r*2**24;return BigInt(o)+(BigInt(i)<<BigInt(32))});b.prototype.readBigUInt64BE=Te(function(t){t=t>>>0,ln(t,"offset");let n=this[t],r=this[t+7];(n===void 0||r===void 0)&&Cn(t,this.length-8);let o=n*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],i=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+r;return(BigInt(o)<<BigInt(32))+BigInt(i)});b.prototype.readIntLE=function(t,n,r){t=t>>>0,n=n>>>0,r||Ut(t,n,this.length);let o=this[t],i=1,s=0;for(;++s<n&&(i*=256);)o+=this[t+s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*n)),o};b.prototype.readIntBE=function(t,n,r){t=t>>>0,n=n>>>0,r||Ut(t,n,this.length);let o=n,i=1,s=this[t+--o];for(;o>0&&(i*=256);)s+=this[t+--o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*n)),s};b.prototype.readInt8=function(t,n){return t=t>>>0,n||Ut(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};b.prototype.readInt16LE=function(t,n){t=t>>>0,n||Ut(t,2,this.length);let r=this[t]|this[t+1]<<8;return r&32768?r|4294901760:r};b.prototype.readInt16BE=function(t,n){t=t>>>0,n||Ut(t,2,this.length);let r=this[t+1]|this[t]<<8;return r&32768?r|4294901760:r};b.prototype.readInt32LE=function(t,n){return t=t>>>0,n||Ut(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};b.prototype.readInt32BE=function(t,n){return t=t>>>0,n||Ut(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};b.prototype.readBigInt64LE=Te(function(t){t=t>>>0,ln(t,"offset");let n=this[t],r=this[t+7];(n===void 0||r===void 0)&&Cn(t,this.length-8);let o=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(r<<24);return(BigInt(o)<<BigInt(32))+BigInt(n+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});b.prototype.readBigInt64BE=Te(function(t){t=t>>>0,ln(t,"offset");let n=this[t],r=this[t+7];(n===void 0||r===void 0)&&Cn(t,this.length-8);let o=(n<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(o)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+r)});b.prototype.readFloatLE=function(t,n){return t=t>>>0,n||Ut(t,4,this.length),an.read(this,t,!0,23,4)};b.prototype.readFloatBE=function(t,n){return t=t>>>0,n||Ut(t,4,this.length),an.read(this,t,!1,23,4)};b.prototype.readDoubleLE=function(t,n){return t=t>>>0,n||Ut(t,8,this.length),an.read(this,t,!0,52,8)};b.prototype.readDoubleBE=function(t,n){return t=t>>>0,n||Ut(t,8,this.length),an.read(this,t,!1,52,8)};function Pt(e,t,n,r,o,i){if(!b.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}b.prototype.writeUintLE=b.prototype.writeUIntLE=function(t,n,r,o){if(t=+t,n=n>>>0,r=r>>>0,!o){let u=Math.pow(2,8*r)-1;Pt(this,t,n,r,u,0)}let i=1,s=0;for(this[n]=t&255;++s<r&&(i*=256);)this[n+s]=t/i&255;return n+r};b.prototype.writeUintBE=b.prototype.writeUIntBE=function(t,n,r,o){if(t=+t,n=n>>>0,r=r>>>0,!o){let u=Math.pow(2,8*r)-1;Pt(this,t,n,r,u,0)}let i=r-1,s=1;for(this[n+i]=t&255;--i>=0&&(s*=256);)this[n+i]=t/s&255;return n+r};b.prototype.writeUint8=b.prototype.writeUInt8=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,1,255,0),this[n]=t&255,n+1};b.prototype.writeUint16LE=b.prototype.writeUInt16LE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,2,65535,0),this[n]=t&255,this[n+1]=t>>>8,n+2};b.prototype.writeUint16BE=b.prototype.writeUInt16BE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,2,65535,0),this[n]=t>>>8,this[n+1]=t&255,n+2};b.prototype.writeUint32LE=b.prototype.writeUInt32LE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,4,4294967295,0),this[n+3]=t>>>24,this[n+2]=t>>>16,this[n+1]=t>>>8,this[n]=t&255,n+4};b.prototype.writeUint32BE=b.prototype.writeUInt32BE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,4,4294967295,0),this[n]=t>>>24,this[n+1]=t>>>16,this[n+2]=t>>>8,this[n+3]=t&255,n+4};function ki(e,t,n,r,o){Pi(t,r,o,e,n,7);let i=Number(t&BigInt(4294967295));e[n++]=i,i=i>>8,e[n++]=i,i=i>>8,e[n++]=i,i=i>>8,e[n++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=s,s=s>>8,e[n++]=s,s=s>>8,e[n++]=s,s=s>>8,e[n++]=s,n}function Ni(e,t,n,r,o){Pi(t,r,o,e,n,7);let i=Number(t&BigInt(4294967295));e[n+7]=i,i=i>>8,e[n+6]=i,i=i>>8,e[n+5]=i,i=i>>8,e[n+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=s,s=s>>8,e[n+2]=s,s=s>>8,e[n+1]=s,s=s>>8,e[n]=s,n+8}b.prototype.writeBigUInt64LE=Te(function(t,n=0){return ki(this,t,n,BigInt(0),BigInt("0xffffffffffffffff"))});b.prototype.writeBigUInt64BE=Te(function(t,n=0){return Ni(this,t,n,BigInt(0),BigInt("0xffffffffffffffff"))});b.prototype.writeIntLE=function(t,n,r,o){if(t=+t,n=n>>>0,!o){let c=Math.pow(2,8*r-1);Pt(this,t,n,r,c-1,-c)}let i=0,s=1,u=0;for(this[n]=t&255;++i<r&&(s*=256);)t<0&&u===0&&this[n+i-1]!==0&&(u=1),this[n+i]=(t/s>>0)-u&255;return n+r};b.prototype.writeIntBE=function(t,n,r,o){if(t=+t,n=n>>>0,!o){let c=Math.pow(2,8*r-1);Pt(this,t,n,r,c-1,-c)}let i=r-1,s=1,u=0;for(this[n+i]=t&255;--i>=0&&(s*=256);)t<0&&u===0&&this[n+i+1]!==0&&(u=1),this[n+i]=(t/s>>0)-u&255;return n+r};b.prototype.writeInt8=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,1,127,-128),t<0&&(t=255+t+1),this[n]=t&255,n+1};b.prototype.writeInt16LE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,2,32767,-32768),this[n]=t&255,this[n+1]=t>>>8,n+2};b.prototype.writeInt16BE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,2,32767,-32768),this[n]=t>>>8,this[n+1]=t&255,n+2};b.prototype.writeInt32LE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,4,2147483647,-2147483648),this[n]=t&255,this[n+1]=t>>>8,this[n+2]=t>>>16,this[n+3]=t>>>24,n+4};b.prototype.writeInt32BE=function(t,n,r){return t=+t,n=n>>>0,r||Pt(this,t,n,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[n]=t>>>24,this[n+1]=t>>>16,this[n+2]=t>>>8,this[n+3]=t&255,n+4};b.prototype.writeBigInt64LE=Te(function(t,n=0){return ki(this,t,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});b.prototype.writeBigInt64BE=Te(function(t,n=0){return Ni(this,t,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Di(e,t,n,r,o,i){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function ji(e,t,n,r,o){return t=+t,n=n>>>0,o||Di(e,t,n,4,34028234663852886e22,-34028234663852886e22),an.write(e,t,n,r,23,4),n+4}b.prototype.writeFloatLE=function(t,n,r){return ji(this,t,n,!0,r)};b.prototype.writeFloatBE=function(t,n,r){return ji(this,t,n,!1,r)};function Hi(e,t,n,r,o){return t=+t,n=n>>>0,o||Di(e,t,n,8,17976931348623157e292,-17976931348623157e292),an.write(e,t,n,r,52,8),n+8}b.prototype.writeDoubleLE=function(t,n,r){return Hi(this,t,n,!0,r)};b.prototype.writeDoubleBE=function(t,n,r){return Hi(this,t,n,!1,r)};b.prototype.copy=function(t,n,r,o){if(!b.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),!o&&o!==0&&(o=this.length),n>=t.length&&(n=t.length),n||(n=0),o>0&&o<r&&(o=r),o===r||t.length===0||this.length===0)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-n<o-r&&(o=t.length-n+r);let i=o-r;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(n,r,o):Uint8Array.prototype.set.call(t,this.subarray(r,o),n),i};b.prototype.fill=function(t,n,r,o){if(typeof t=="string"){if(typeof n=="string"?(o=n,n=0,r=this.length):typeof r=="string"&&(o=r,r=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!b.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(t.length===1){let s=t.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(n<0||this.length<n||this.length<r)throw new RangeError("Out of range index");if(r<=n)return this;n=n>>>0,r=r===void 0?this.length:r>>>0,t||(t=0);let i;if(typeof t=="number")for(i=n;i<r;++i)this[i]=t;else{let s=b.isBuffer(t)?t:b.from(t,o),u=s.length;if(u===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-n;++i)this[i+n]=s[i%u]}return this};var un={};function uo(e,t,n){un[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(o){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:o,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}uo("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);uo("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError);uo("ERR_OUT_OF_RANGE",function(e,t,n){let r=`The value of "${e}" is out of range.`,o=n;return Number.isInteger(n)&&Math.abs(n)>2**32?o=Oi(String(n)):typeof n=="bigint"&&(o=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(o=Oi(o)),o+="n"),r+=` It must be ${t}. Received ${o}`,r},RangeError);function Oi(e){let t="",n=e.length,r=e[0]==="-"?1:0;for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function Uf(e,t,n){ln(t,"offset"),(e[t]===void 0||e[t+n]===void 0)&&Cn(t,e.length-(n+1))}function Pi(e,t,n,r,o,i){if(e>n||e<t){let s=typeof t=="bigint"?"n":"",u;throw i>3?t===0||t===BigInt(0)?u=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:u=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:u=`>= ${t}${s} and <= ${n}${s}`,new un.ERR_OUT_OF_RANGE("value",u,e)}Uf(r,o,i)}function ln(e,t){if(typeof e!="number")throw new un.ERR_INVALID_ARG_TYPE(t,"number",e)}function Cn(e,t,n){throw Math.floor(e)!==e?(ln(e,n),new un.ERR_OUT_OF_RANGE(n||"offset","an integer",e)):t<0?new un.ERR_BUFFER_OUT_OF_BOUNDS:new un.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${t}`,e)}var _f=/[^+/0-9A-Za-z-_]/g;function Ff(e){if(e=e.split("=")[0],e=e.trim().replace(_f,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function so(e,t){t=t||1/0;let n,r=e.length,o=null,i=[];for(let s=0;s<r;++s){if(n=e.charCodeAt(s),n>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+1===r){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return i}function Lf(e){let t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n)&255);return t}function Cf(e,t){let n,r,o,i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}function qi(e){return ro.toByteArray(Ff(e))}function hr(e,t,n,r){let o;for(o=0;o<r&&!(o+n>=t.length||o>=e.length);++o)t[o+n]=e[o];return o}function ne(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function ao(e){return e!==e}var kf=(function(){let e="0123456789abcdef",t=new Array(256);for(let n=0;n<16;++n){let r=n*16;for(let o=0;o<16;++o)t[r+o]=e[n]+e[o]}return t})();function Te(e){return typeof BigInt>"u"?Nf:e}function Nf(){throw new Error("BigInt not supported")}});var ct,P,C=Ot(()=>{ct=yi(Ei()),P=yi(Mi())});var lo=Ht((ka,Ki)=>{C();Ki.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PublicKey});var zi=Ht((Da,$i)=>{C();$i.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PrivateKey});var ho=Ht((Ha,Zi)=>{C();Zi.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.util.preconditions});function Df(e,t=!1){return t?{h:Number(e&dr),l:Number(e>>Yi&dr)}:{h:Number(e>>Yi&dr)|0,l:Number(e&dr)|0}}function Vi(e,t=!1){let n=e.length,r=new Uint32Array(n),o=new Uint32Array(n);for(let i=0;i<n;i++){let{h:s,l:u}=Df(e[i],t);[r[i],o[i]]=[s,u]}return[r,o]}function Wi(e,t,n,r){let o=jf(n),i=Hf(n);e.setUint32(t,r?i:o,r),e.setUint32(t+4,r?o:i,r)}function re(e,t,n,r){let o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:o|0}}var dr,Yi,jf,Hf,po,go,Ye,Ve,kn,Nn,Gi,Xi,Qi,Ji,ts,es,yo=Ot(()=>{C();dr=BigInt(4294967295),Yi=BigInt(32);jf=e=>e/2**32|0,Hf=e=>e>>>0;po=(e,t,n)=>e>>>n,go=(e,t,n)=>e<<32-n|t>>>n,Ye=(e,t,n)=>e>>>n|t<<32-n,Ve=(e,t,n)=>e<<32-n|t>>>n,kn=(e,t,n)=>e<<64-n|t>>>n-32,Nn=(e,t,n)=>e>>>n-32|t<<64-n;Gi=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Xi=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Qi=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Ji=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,ts=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),es=(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0});function pr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function xe(e,t=""){if(typeof e!="number")throw new TypeError(mo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(mo(t)+"expected integer >= 0, got "+e);return e}function oe(e,t,n=""){if(pr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&xe(t,"length");let r=pr(e),o=t!==void 0?` of length ${t}`:"",i=r?`length=${e.length}`:`type=${typeof e}`,s=mo(n)+"expected Uint8Array"+o+", got "+i;throw r?new RangeError(s):new TypeError(s)}function gr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(xe(e.outputLen),xe(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function dn(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function yr(e,t){oe(e,void 0,"output");let n=t.outputLen;if(!(e.length>=n))throw new RangeError('"output" expected length >= '+n)}function Ie(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function mr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Vt(e,t){return e<<32-t|e>>>t}function wr(e){if(oe(e),os)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Mf[e[n]];return t}function rs(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function wo(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(os)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,n=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let r=new Uint8Array(n);for(let o=0,i=0;o<n;o++,i+=2){let s=rs(e.charCodeAt(i)),u=rs(e.charCodeAt(i+1));if(s===void 0||u===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}r[o]=s*16+u}return r}function be(e){if(typeof e!="string")throw new TypeError("string expected");let t=new TextEncoder().encode(e);try{return new Uint8Array(t)}finally{Ie(t)}}function is(...e){let t=0;for(let r=0;r<e.length;r++){let o=e[r];oe(o),t+=o.length}let n=new Uint8Array(t);for(let r=0,o=0;r<e.length;r++){let i=e[r];n.set(i,o),o+=i.length}return n}function Kf(e,t,n="opts"){return ns(e,"defaults"),t!==void 0&&ns(t,n),Object.assign(Object.create(null),e,t)}function We(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Kf({},t,"info");let n=(o,i)=>e(i).update(o).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=o=>e(o),Object.assign(n,t),Object.freeze(n)}function Dn(e=32){xe(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var mo,qf,ns,os,Mf,Ge,Re=Ot(()=>{C();mo=e=>e?`"${e}" `:"";qf=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},ns=(e,t)=>{qf(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};os=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Mf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));Ge=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])})});function ss(e,t,n){return e&t^~e&n}function cs(e,t,n){return e&t^e&n^t&n}var jn,fs,us,as,ls,hs=Ot(()=>{C();yo();Re();jn=class{constructor(t,n,r,o){S(this,"blockLen");S(this,"outputLen");S(this,"canXOF",!1);S(this,"padOffset");S(this,"isLE");S(this,"buffer");S(this,"view");S(this,"finished",!1);S(this,"length",0);S(this,"pos",0);S(this,"destroyed",!1);this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(t),this.view=mr(this.buffer)}update(t){dn(this),oe(t);let{view:n,buffer:r,blockLen:o}=this,i=t.length,s=!1;for(let u=0;u<i;){let c=Math.min(o-this.pos,i-u);if(c===o){let a=mr(t);for(;o<=i-u;u+=o)this.process(a,u);s=!0;continue}r.set(u===0&&c===i?t:t.subarray(u,u+c),this.pos),this.pos+=c,u+=c,this.pos===o&&(this.process(n,0),this.pos=0,s=!0)}return this.length+=t.length,s&&this.roundClean(),this}digestInto(t){dn(this),yr(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,n.fill(0,s),this.padOffset>o-s&&(this.process(r,0),n.fill(0)),Wi(r,o-8,this.length*8,i),this.process(r,0),this.roundClean();let u=t===n?r:mr(t),c=this.outputLen,a=c/4,h=this.get();if(c%4||a>h.length)throw new Error("invalid outputLen");for(let l=0;l<a;l++)u.setUint32(4*l,h[l],i)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneIntoMeta(t){let{buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return t.destroyed=i,t.finished=o,t.length=r,t.pos=s,s&&t.buffer.set(n),t}clone(){return this._cloneInto()}},fs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),us=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),as=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),ls=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});var xo={};fr(xo,{_SHA224:()=>Er,_SHA256:()=>br,_SHA384:()=>Sr,_SHA512:()=>Br,_SHA512_224:()=>Ar,_SHA512_256:()=>vr,sha224:()=>Wf,sha256:()=>Fe,sha384:()=>Xf,sha512:()=>Gf,sha512_224:()=>Jf,sha512_256:()=>Qf});var $f,Oe,xr,br,Er,ds,zf,Zf,Ue,_e,pn,Br,Sr,Yf,Vf,Ar,vr,Fe,Wf,Gf,Xf,Qf,Jf,Tr=Ot(()=>{C();hs();yo();Re();$f=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Oe=new Uint32Array(64),xr=class extends jn{constructor(n,r){super(64,n,8,!1);S(this,"A",0);S(this,"B",0);S(this,"C",0);S(this,"D",0);S(this,"E",0);S(this,"F",0);S(this,"G",0);S(this,"H",0);this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:n,B:r,C:o,D:i,E:s,F:u,G:c,H:a}=this;return[n,r,o,i,s,u,c,a]}set(n,r,o,i,s,u,c,a){this.A=n|0,this.B=r|0,this.C=o|0,this.D=i|0,this.E=s|0,this.F=u|0,this.G=c|0,this.H=a|0}_cloneInto(n){return(n||(n=new this.constructor)).set(...this.get()),this._cloneIntoMeta(n)}process(n,r){for(let f=0;f<16;f++,r+=4)Oe[f]=n.getUint32(r,!1);for(let f=16;f<64;f++){let d=Oe[f-15],g=Oe[f-2],y=Vt(d,7)^Vt(d,18)^d>>>3,m=Vt(g,17)^Vt(g,19)^g>>>10;Oe[f]=m+Oe[f-7]+y+Oe[f-16]|0}let{A:o,B:i,C:s,D:u,E:c,F:a,G:h,H:l}=this;for(let f=0;f<64;f++){let d=Vt(c,6)^Vt(c,11)^Vt(c,25),g=l+d+ss(c,a,h)+$f[f]+Oe[f]|0,m=(Vt(o,2)^Vt(o,13)^Vt(o,22))+cs(o,i,s)|0;l=h,h=a,a=c,c=u+g|0,u=s,s=i,i=o,o=g+m|0}o=o+this.A|0,i=i+this.B|0,s=s+this.C|0,u=u+this.D|0,c=c+this.E|0,a=a+this.F|0,h=h+this.G|0,l=l+this.H|0,this.set(o,i,s,u,c,a,h,l)}roundClean(){Ie(Oe)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ie(this.buffer)}},br=class extends xr{constructor(){super(32,fs)}},Er=class extends xr{constructor(){super(28,us)}},ds=Vi(["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(e=>BigInt(e))),zf=ds[0],Zf=ds[1],Ue=new Uint32Array(80),_e=new Uint32Array(80),pn=class extends jn{constructor(n,r){super(128,n,16,!1);S(this,"Ah",0);S(this,"Al",0);S(this,"Bh",0);S(this,"Bl",0);S(this,"Ch",0);S(this,"Cl",0);S(this,"Dh",0);S(this,"Dl",0);S(this,"Eh",0);S(this,"El",0);S(this,"Fh",0);S(this,"Fl",0);S(this,"Gh",0);S(this,"Gl",0);S(this,"Hh",0);S(this,"Hl",0);this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:u,Dh:c,Dl:a,Eh:h,El:l,Fh:f,Fl:d,Gh:g,Gl:y,Hh:m,Hl:w}=this;return[n,r,o,i,s,u,c,a,h,l,f,d,g,y,m,w]}set(n,r,o,i,s,u,c,a,h,l,f,d,g,y,m,w){this.Ah=n|0,this.Al=r|0,this.Bh=o|0,this.Bl=i|0,this.Ch=s|0,this.Cl=u|0,this.Dh=c|0,this.Dl=a|0,this.Eh=h|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=g|0,this.Gl=y|0,this.Hh=m|0,this.Hl=w|0}_cloneInto(n){return(n||(n=new this.constructor)).set(...this.get()),this._cloneIntoMeta(n)}process(n,r){for(let B=0;B<16;B++,r+=4)Ue[B]=n.getUint32(r),_e[B]=n.getUint32(r+=4);for(let B=16;B<80;B++){let L=Ue[B-15]|0,K=_e[B-15]|0,$=Ye(L,K,1)^Ye(L,K,8)^po(L,K,7),yt=Ve(L,K,1)^Ve(L,K,8)^go(L,K,7),nt=Ue[B-2]|0,rt=_e[B-2]|0,qt=Ye(nt,rt,19)^kn(nt,rt,61)^po(nt,rt,6),Nt=Ve(nt,rt,19)^Nn(nt,rt,61)^go(nt,rt,6),Mt=Qi(yt,Nt,_e[B-7],_e[B-16]),zt=Ji(Mt,$,qt,Ue[B-7],Ue[B-16]);Ue[B]=zt|0,_e[B]=Mt|0}let{Ah:o,Al:i,Bh:s,Bl:u,Ch:c,Cl:a,Dh:h,Dl:l,Eh:f,El:d,Fh:g,Fl:y,Gh:m,Gl:w,Hh:T,Hl:F}=this;for(let B=0;B<80;B++){let L=Ye(f,d,14)^Ye(f,d,18)^kn(f,d,41),K=Ve(f,d,14)^Ve(f,d,18)^Nn(f,d,41),$=f&g^~f&m,yt=d&y^~d&w,nt=ts(F,K,yt,Zf[B],_e[B]),rt=es(nt,T,L,$,zf[B],Ue[B]),qt=nt|0,Nt=Ye(o,i,28)^kn(o,i,34)^kn(o,i,39),Mt=Ve(o,i,28)^Nn(o,i,34)^Nn(o,i,39),zt=o&s^o&c^s&c,it=i&u^i&a^u&a;T=m|0,F=w|0,m=g|0,w=y|0,g=f|0,y=d|0,{h:f,l:d}=re(h|0,l|0,rt|0,qt|0),h=c|0,l=a|0,c=s|0,a=u|0,s=o|0,u=i|0;let Xt=Gi(qt,Mt,it);o=Xi(Xt,rt,Nt,zt),i=Xt|0}({h:o,l:i}=re(this.Ah|0,this.Al|0,o|0,i|0)),{h:s,l:u}=re(this.Bh|0,this.Bl|0,s|0,u|0),{h:c,l:a}=re(this.Ch|0,this.Cl|0,c|0,a|0),{h,l}=re(this.Dh|0,this.Dl|0,h|0,l|0),{h:f,l:d}=re(this.Eh|0,this.El|0,f|0,d|0),{h:g,l:y}=re(this.Fh|0,this.Fl|0,g|0,y|0),{h:m,l:w}=re(this.Gh|0,this.Gl|0,m|0,w|0),{h:T,l:F}=re(this.Hh|0,this.Hl|0,T|0,F|0),this.set(o,i,s,u,c,a,h,l,f,d,g,y,m,w,T,F)}roundClean(){Ie(Ue,_e)}destroy(){this.destroyed=!0,Ie(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Br=class extends pn{constructor(){super(64,ls)}},Sr=class extends pn{constructor(){super(48,as)}},Yf=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),Vf=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]),Ar=class extends pn{constructor(){super(28,Yf)}},vr=class extends pn{constructor(){super(32,Vf)}},Fe=We(()=>new br,Ge(1)),Wf=We(()=>new Er,Ge(4)),Gf=We(()=>new Br,Ge(3)),Xf=We(()=>new Sr,Ge(2)),Qf=We(()=>new vr,Ge(6)),Jf=We(()=>new Ar,Ge(5))});function Bt(e,t,n=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}function Hn(e,t=""){if(typeof e!="string"){let n=t&&`"${t}" `;throw new TypeError(n+"expected string, got type="+typeof e)}return e}function Le(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function Xe(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}function se(e,t=""){if(typeof e!="boolean")throw new TypeError(tu(t)+"expected boolean, got type="+typeof e);return e}function Rr(e){if(typeof e=="bigint"){if(!Ce(e))throw new RangeError("positive bigint expected, got "+e)}else bo(e);return e}function bt(e,t=""){if(typeof e!="number"){let n=t&&`"${t}" `;throw new TypeError(n+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw new RangeError(n+"expected safe integer, got "+e)}}function Pn(e){let t=Rr(e).toString(16);return t.length&1?"0"+t:t}function gs(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Ir:BigInt("0x"+e)}function It(e){return gs(wr(e))}function yn(e){return gs(wr(Be(oe(e)).reverse()))}function Or(e,t){if(xe(t),t===0)throw new Error("zero output length is invalid");e=Rr(e);let n=t*2,r=e.toString(16);if(r.length>n)throw new RangeError("number is too large");return wo(r.padStart(n,"0"))}function Eo(e,t){return Or(e,t).reverse()}function Bo(e,t){if(e=M(e),t=M(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function Be(e){return Uint8Array.from(M(e))}function mn(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,n)=>{let r=t.charCodeAt(0);if(t.length!==1||r>127)throw new RangeError(`string contains non-ASCII character "${e[n]}" with code ${r} at position ${n}`);return r})}function Ce(e){return typeof e=="bigint"&&Ir<=e}function So(e,t,n){return Ce(e)&&Ce(t)&&Ce(n)&&t<=e&&e<n}function Ao(e,t,n,r){if(!So(t,n,r))throw new RangeError("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function wn(e){if(e<Ir)throw new Error("expected non-negative bigint, got "+e);return e===Ir?0:e.toString(2).length}function ys(e,t,n){if(xe(e,"hashLen"),xe(t,"qByteLen"),typeof n!="function")throw new TypeError("hmacFn must be a function");let r=m=>new Uint8Array(m),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),u=1e3,c=r(e),a=r(e),h=0,l=()=>{c.fill(1),a.fill(0),h=0},f=(...m)=>n(a,ft(c,...m)),d=(m=o)=>{a=f(i,m),c=f(),m.length!==0&&(a=f(s,m),c=f())},g=()=>{if(h++>=u)throw new Error("drbg: tried max amount of iterations");let m=0,w=[];for(;m<t;){c=f();let T=c.slice();w.push(T),m+=c.length}return ft(...w)};return(m,w)=>{l(),d(m);let T;for(;(T=w(g()))===void 0;)d();return l(),T}}function dt(e,t={},n={},r="object"){Le(e,r),Le(t,"fields"),Le(n,"optFields");function o(s,u,c){let a=r==="object"?`param "${String(s)}"`:`"${r}.${String(s)}"`,h=e[s];if(!Object.hasOwn(e,s)&&(c?h!==void 0:u!=="function"))throw new TypeError(`${a} is invalid: expected own property`);if(c&&h===void 0)return;let l=typeof h;if(l!==u||h===null)throw new TypeError(`${a} is invalid: expected ${u}, got ${l}`)}let i=(s,u)=>Object.entries(s).forEach(([c,a])=>o(c,a,u));i(t,!1),i(n,!0)}var M,bo,Ee,ft,gn,ie,Dt,Ir,ps,tu,qn,ke=Ot(()=>{C();Re();M=(e,t,n)=>oe(e,t,n),bo=xe;Ee=wr,ft=(...e)=>is(...e),gn=e=>wo(e),ie=pr,Dt=e=>Dn(e),Ir=BigInt(0),ps=BigInt(1),tu=e=>e?`"${e}" `:"";qn=e=>(bt(e,"n"),(ps<<BigInt(e))-ps)});function jt(e,t){if(t<=Rt)throw new Error("mod: expected positive modulus, got "+t);let n=e%t;return n>=Rt?n:t+n}function Ss(e,t,n){if(n<=pt)throw new Error("pow: expected modulus > 1, got "+n);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<Rt)throw new Error("invalid exponent, negatives unsupported");if(t===Rt)return pt;if(t===pt)return e;let r=e%n;if(r<Rt&&(r+=n),t<ou){let u=pt;for(;t>Rt;)t&pt&&(u=u*r%n),r=r*r%n,t>>=pt;return u}let o=[];for(;t>Rt;)o.push(Number(t&ru)),t>>=To;let i=new Array(16);i[0]=pt,i[1]=r;for(let u=2;u<16;u++)i[u]=i[u-1]*r%n;let s=i[o[o.length-1]];for(let u=o.length-2;u>=0;u--){s=s*s%n,s=s*s%n,s=s*s%n,s=s*s%n;let c=o[u];c!==0&&(s=s*i[c]%n)}return s}function Kt(e,t,n){if(n<=pt)throw new Error("pow2: expected modulus > 1, got "+n);if(t<Rt)throw new Error("pow2: expected non-negative exponent, got "+t);let r=e;for(;t-- >Rt;)r*=r,r%=n;return r}function ms(e,t){if(e===Rt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected modulus > 1, got "+t);let n=jt(e,t),r=t,o=Rt,i=pt;for(;n!==Rt;){let u=r/n,c=r-n*u,a=o-i*u;r=n,n=c,o=i,i=a}if(r!==pt)throw new Error("invert: does not exist");return jt(o,t)}function As(e,t){if(t<=pt)throw new Error("invertCt: expected prime modulus > 1, got "+t);let n=jt(e,t);if(n===Rt)throw new Error("invertCt: expected non-zero number");let r=Ss(n,t-Ne,t);if(jt(n*r,t)!==pt)throw new Error("invertCt: does not exist");return r}function Io(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw new Error("Cannot find square root")}function Ro(e,t){if((e&pt)===Rt)throw new Error(t+": expected odd modulus, got "+e)}function vs(e,t){let n=e,r=(n.ORDER+pt)/To,o=n.pow(t,r);return Io(n,o,t),o}function iu(e,t){let n=e,r=(n.ORDER-bs)/Es,o=n.mul(t,Ne),i=n.pow(o,r),s=n.mul(t,i),u=n.mul(n.mul(s,Ne),i),c=n.mul(s,n.sub(u,n.ONE));return Io(n,c,t),c}function su(e){let t=bn(e),n=Ts(e),r=n(t,t.neg(t.ONE)),o=n(t,r),i=n(t,t.neg(r)),s=(e+eu)/Bs;return((u,c)=>{let a=u,h=a.pow(c,s),l=a.mul(h,r),f=a.mul(h,o),d=a.mul(h,i),g=a.eql(a.sqr(l),c),y=a.eql(a.sqr(f),c);h=a.cmov(h,l,g),l=a.cmov(d,f,y);let m=a.eql(a.sqr(l),c),w=a.cmov(h,l,m);return Io(a,w,c),w})}function Ts(e){if(e<xs)throw new Error("sqrt is not defined for small field");Ro(e,"tonelliShanks");let t=e-pt,n=0;for(;t%Ne===Rt;)t/=Ne,n++;let r=Ne,o=bn(e);for(;vo(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return vs;let i=o.pow(r,t),s=(t+pt)/Ne;return function(c,a){let h=c;if(h.is0(a))return a;if(vo(h,a)!==1)throw new Error("Cannot find square root");let l=n,f=h.mul(h.ONE,i),d=h.pow(a,t),g=h.pow(a,s);for(;!h.eql(d,h.ONE);){if(h.is0(d))throw new Error("Cannot find square root: probably non-prime P");let y=1,m=h.sqr(d);for(;!h.eql(m,h.ONE);)if(y++,m=h.sqr(m),y===l)throw new Error("Cannot find square root");let w=pt<<BigInt(l-y-1),T=h.pow(f,w);l=y,f=h.sqr(T),d=h.mul(d,f),g=h.mul(g,T)}return g}}function cu(e){return Ro(e,"Fp.sqrt"),e%To===xs?vs:e%Es===bs?iu:e%Bs===nu?su(e):Ts(e)}function Yt(e){if(Le(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);bt(e.BYTES,"BYTES"),bt(e.BITS,"BITS");for(let t of fu)Xe(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=pt)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function xn(e,t,n=!1){Yt(e),Bt(t,"nums"),se(n,"passZero");let r=e,o=new Array(t.length).fill(n?r.ZERO:void 0),i=t.reduce((u,c,a)=>r.is0(c)?u:(o[a]=u,r.mul(u,c)),r.ONE),s=r.inv(i);return t.reduceRight((u,c,a)=>r.is0(c)?u:(o[a]=r.mul(u,o[a]),r.mul(u,c)),s),o}function vo(e,t){Yt(e);let n=e;Ro(n.ORDER,"FpLegendre");let r=(n.ORDER-pt)/Ne,o=n.pow(t,r),i=n.eql(o,n.ONE),s=n.eql(o,n.ZERO),u=n.eql(o,n.neg(n.ONE));if(!i&&!s&&!u)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Oo(e,t){return vo(e,t)!==-1}function uu(e,t){if(t!==void 0&&bo(t),e<=Rt)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let n=wn(e);if(t!==void 0&&t<n)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${n})`);let r=t!==void 0?t:n,o=Math.ceil(r/8);return{nBitLength:r,nByteLength:o}}function bn(e,t={}){return Object.freeze(Ur.prototype),new Ur(e,t)}function Is(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=pt)throw new Error("field order must be greater than 1");let t=wn(e-pt);return Math.ceil(t/8)}function En(e){let t=Is(e);return t+Math.ceil(t/2)}function Qe(e,t,n=!1){M(e);let r=e.length,o=Is(t),i=Math.max(En(t),16);if(r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);let s=n?yn(e):It(e),u=jt(s,t-pt)+pt;return n?Eo(u,o):Or(u,o)}var Rt,pt,Ne,xs,To,bs,eu,Es,nu,ru,Bs,ou,fu,ws,Ur,Je=Ot(()=>{C();ke();Rt=BigInt(0),pt=BigInt(1),Ne=BigInt(2),xs=BigInt(3),To=BigInt(4),bs=BigInt(5),eu=BigInt(7),Es=BigInt(8),nu=BigInt(9),ru=BigInt(15),Bs=BigInt(16),ou=BigInt("0x10000000000000000");fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];ws=new WeakMap,Ur=class{constructor(t,n={}){S(this,"ORDER");S(this,"BITS");S(this,"BYTES");S(this,"isLE");S(this,"ZERO",Rt);S(this,"ONE",pt);S(this,"_lengths");S(this,"_mod");if(t<=pt)throw new Error("invalid field: expected ORDER > 1, got "+t);let r;this.isLE=!1,n!=null&&typeof n=="object"&&(typeof n.BITS=="number"&&(r=n.BITS),typeof n.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:n.sqrt,enumerable:!0}),typeof n.isLE=="boolean"&&(this.isLE=n.isLE),n.allowedLengths&&(this._lengths=Object.freeze(n.allowedLengths.slice())),typeof n.modFromBytes=="boolean"&&(this._mod=n.modFromBytes));let{nBitLength:o,nByteLength:i}=uu(t,r);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(t){return jt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return Rt<=t&&t<this.ORDER}is0(t){return t===Rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&pt)===pt}neg(t){return jt(-t,this.ORDER)}eql(t,n){return t===n}sqr(t){return jt(t*t,this.ORDER)}add(t,n){return jt(t+n,this.ORDER)}sub(t,n){return jt(t-n,this.ORDER)}mul(t,n){return jt(t*n,this.ORDER)}pow(t,n){return Ss(t,n,this.ORDER)}div(t,n){return jt(t*ms(n,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,n){return t+n}subN(t,n){return t-n}mulN(t,n){return t*n}inv(t){return ms(t,this.ORDER)}sqrt(t){let n=ws.get(this);return n||ws.set(this,n=cu(this.ORDER)),n(this,t)}toBytes(t){return this.isLE?Eo(t,this.BYTES):Or(t,this.BYTES)}fromBytes(t,n=!1){M(t);let{_lengths:r,BYTES:o,isLE:i,ORDER:s,_mod:u}=this;if(r){if(t.length<1||!r.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+t.length);let a=new Uint8Array(o);a.set(t,i?0:a.length-t.length),t=a}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?yn(t):It(t);if(u&&(c=jt(c,s)),!n&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return xn(this,t,!0)}cmov(t,n,r){return se(r,"condition"),r?n:t}}});function De(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);Xe(t.fromAffine,"Point.fromAffine"),Xe(t.fromBytes,"Point.fromBytes"),Xe(t.fromHex,"Point.fromHex"),Le(t.BASE,"Point.BASE"),Le(t.ZERO,"Point.ZERO"),Yt(t.Fp),Yt(t.Fn)}function _s(e,t){De(e),Fs(t,e);let n=xn(e.Fp,t.map(r=>r.Z));return t.map((r,o)=>e.fromAffine(r.toAffine(n[o])))}function hu(e,t,n=1){if(!Number.isSafeInteger(e)||e<n||e>t)throw new Error("invalid window size, expected ["+n+".."+t+"], got W="+e)}function du(e,t){let n=e*(4*t+128);if(n>Os)throw new Error("invalid window size: table would need ~"+Math.ceil(n/2**20)+" MiB, max "+Os/2**20+" MiB")}function Lo(e,t){if(e!==void 0){Xe(e,"randomBytes");try{let n=e(t);if(!ie(n)||n.length!==t)return}catch{return}return e}}function Fs(e,t){Bt(e,"points"),e.forEach((n,r)=>{if(!(n instanceof t))throw new Error("invalid point at index "+r)})}function pu(e,t,n){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,o)=>{if(!(n===void 0?t.isValid(r):Ce(r)&&r<n))throw new Error("invalid scalar at index "+o)})}function _o(e){return Ls.get(e)||1}function gu(e,t){let n=e.double(),r=[e];for(let o=1;o<t;o++)r.push(r[o-1].add(n));return r}function yu(e,t){let n=2**t,r=n/2,o=BigInt(n-1),i=[];for(;e>Fo;){let s=0;e&Mn&&(s=Number(e&o),s>=r&&(s-=n),e-=BigInt(s)),i.push(s),e>>=Mn}return i}function mu(e,t,n){let r=2**t,o=r/2,i=BigInt(r-1),s=BigInt(t),u=[];for(let c=0;c<n;c++){let a=Number(e&i);e>>=s,a>o&&(a-=r,e+=Mn),u.push(a)}if(e!==Fo)throw new Error("invalid wnaf");return u}function wu(e,t,n){let r=0;for(let i of n)r=Math.max(r,i.length);let o=e;for(let i=r-1;i>=0;i--){i!==r-1&&(o=o.double());for(let s=0;s<n.length;s++){let u=n[s][i];if(u){let c=t[s][Math.abs(u)-1>>1];o=o.add(u<0?c.negate():c)}}}return o}function Bn(e,t,n,r=!1){if(De(e),Fs(t,e),se(r,"allowOversized"),pu(n,e.Fn,r?e.Fn.ORDER**au:void 0),t.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(s=>gu(s,4)),i=n.map(s=>yu(s,4));return wu(e.ZERO,o,i)}function Us(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Yt(t),t}else return bn(e,{isLE:n})}function Cs(e,t,n={},r){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(r===void 0&&(r=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);dt(n);for(let c of["p","n","h"]){let a=t[c];if(!(Ce(a)&&a!==Fo))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Us(t.p,n.Fp,r),i=Us(t.n,n.Fn,r),u=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of u)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function Fr(e,t){return function(r){let o=e(r);return{secretKey:o,publicKey:t(o)}}}var Fo,Mn,au,Uo,Rs,lu,Os,Ls,_r,Lr=Ot(()=>{C();ke();Je();Fo=BigInt(0),Mn=BigInt(1),au=BigInt(4),Uo=16,Rs=128,lu=5,Os=2**31;Ls=new WeakMap;_r=class{constructor(t,n){S(this,"Point");S(this,"BASE");S(this,"ZERO");S(this,"randomBytes");S(this,"wnafPrecomputes",new WeakMap);S(this,"baseCanBeBlinded");S(this,"bits");De(t),this.randomBytes=Lo(n,Uo),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,n,r){let o=Math.ceil(r/n)+1,i=2**(n-1),s=[],u=t;for(let c=0;c<o;c++){let a=u;for(let h=0;h<i;h++)s.push(a),a=a.add(u);u=s[s.length-1].double()}return{W:n,bits:r,windows:o,comp:s}}wnafCachedCT(t,n){let{W:r,windows:o,comp:i}=t,s=2**(r-1),u=mu(n,r,o),c=this.ZERO,a=this.BASE;for(let h=0;h<o;h++){let l=u[h],f=h*s,d=Math.abs(l)-1,g=i[f];for(let m=1;m<s;m++)g=m===d?i[f+m]:g;let y=g.negate();l===0?a=a.add(i[f]):c=c.add(l<0?y:g)}return{p:c,f:a}}getWnafPrecomputes(t,n,r,o){let i=this.wnafPrecomputes.get(n),s=i?.find(u=>u.W===t&&u.bits===r);return s||(s=this.buildWnafTable(n,t,r),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(n,i)),i.push(s)),s}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,n){if(this.assertPoint(t),!So(n,Mn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,n,r,o){let i=_o(t);return i===1?this.fixedWindowCT(t,n,r):this.wnafCachedCT(this.getWnafPrecomputes(i,t,r,o),n)}mulCT(t,n,r){return this.validateMulInput(t,n),this.runCT(t,n,this.bits,r)}mulCTBlinded(t,n,r){if(this.validateMulInput(t,n),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Rs,i=this.randomBytes(Uo);if(!ie(i)||i.length!==Uo)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=n+It(i)*this.Point.Fn.ORDER;return this.runCT(t,s,o,r)}fixedWindowCT(t,n,r){let o=lu,i=1<<o,s=qn(o),u=new Array(i);u[0]=this.ZERO;for(let h=1;h<i;h++)u[h]=u[h-1].add(t);let c=Math.ceil(r/o),a=this.ZERO;for(let h=c-1;h>=0;h--){if(h!==c-1)for(let d=0;d<o;d++)a=a.double();let l=Number(n>>BigInt(h*o)&s),f=u[0];for(let d=1;d<i;d++)f=d===l?u[d]:f;a=a.add(f)}return{p:a,f:a}}shouldBlind(t,n){return this.randomBytes===void 0?!1:n===Mn?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,n,r,o){return this.shouldBlind(t,r)?this.mulCTBlinded(t,n,o):this.mulCT(t,n,o)}mulUnsafe(t,n,r){if(this.assertPoint(t),!Ce(n))throw new Error("invalid scalar");let o=_o(t);if(o===1||n>=this.Point.Fn.ORDER)return Bn(this.Point,[t],[n],!0);let i=this.getWnafPrecomputes(o,t,this.bits,r);return this.wnafCachedCT(i,n).p}setWindowSize(t,n){this.assertPoint(t),hu(n,this.bits);let r=Math.ceil((this.bits+Rs)/n)+1;du(r*2**(n-1),this.Point.Fp.BYTES),Ls.set(t,n),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return _o(t)!==1}}});function Co(e,t="n"){if(typeof e!="number")throw new TypeError(`wrong u32 integer "${t}": expected number, got type=${typeof e}`);if(!Number.isSafeInteger(e)||e<0||e>4294967295)throw new RangeError(`wrong u32 integer "${t}": expected 0..4294967295, got ${e}`);return e}function ks(e){return Co(e,"x"),(e&e-1)===0&&e!==0}function xu(e){if(Co(e),e<=1)return 1;if(e>2147483648)throw new Error("nextPowerOfTwo overflow: result does not fit u32");return 1<<Cr(e-1)+1>>>0}function Cr(e){return Co(e),31-Math.clz32(e)}function Ns(e,t,n,r,o){Yt(e);let i=e,s=n||((l,f)=>new Array(l).fill(f??i.ZERO)),u=l=>{if(Array.isArray(l))return!0;if(!ArrayBuffer.isView(l))return!1;let f=l;return typeof f.length=="number"&&typeof f.slice=="function"&&typeof f[Symbol.iterator]=="function"},c=(l,f)=>{if(!u(f))throw new TypeError(`"${l}" expected polynomial, got type=${typeof f}`)},a=(l,f)=>{c("a",l);let d=l.length;if(f!==void 0&&(c("b",f),f.length!==d))throw new Error(`poly: mismatched lengths ${d} vs ${f.length}`);if(o!==void 0&&d!==o)throw new Error(`poly: expected fixed length ${o}, got ${d}`);return d};function h(l,f,d=!1,g){if(!ks(f))throw new Error("poly.lagrange: expected power of two length, got "+f);let y=g||(d?t.brp(Cr(f)):t.roots(Cr(f)));for(let m=0;m<f;m++)if(i.eql(l,y[m]))return m;return-1}return{roots:t,create:s,length:o,extend:(l,f)=>{a(l);let d=s(f,i.ZERO);for(let g=0;g<Math.min(l.length,f);g++)d[g]=l[g];return d},degree:l=>{a(l);for(let f=l.length-1;f>=0;f--)if(!i.is0(l[f]))return f;return-1},add:(l,f)=>{let d=a(l,f),g=s(d);for(let y=0;y<d;y++)g[y]=i.add(l[y],f[y]);return g},sub:(l,f)=>{let d=a(l,f),g=s(d);for(let y=0;y<d;y++)g[y]=i.sub(l[y],f[y]);return g},dot:(l,f)=>{let d=a(l,f),g=s(d);for(let y=0;y<d;y++)g[y]=i.mul(l[y],f[y]);return g},mul:(l,f)=>{if(u(f)){let d=a(l,f);if(r){let g=r.direct(l,!1,!0),y=r.direct(f,!1,!0);for(let m=0;m<g.length;m++)g[m]=i.mul(g[m],y[m]);return r.inverse(g,!0,!1)}else{let g=s(d);for(let y=0;y<d;y++)for(let m=0;m<d;m++){let w=(y+m)%d;g[w]=i.add(g[w],i.mul(l[y],f[m]))}return g}}else{let d=s(a(l));for(let g=0;g<d.length;g++)d[g]=i.mul(l[g],f);return d}},convolve(l,f){c("a",l),c("b",f);let d=xu(l.length+f.length-1);return this.mul(this.extend(l,d),this.extend(f,d))},shift(l,f){c("p",l);let d=s(l.length);if(o!==void 0&&l.length!==o)throw new Error(`poly: expected fixed length ${o}, got ${l.length}`);if(!l.length)return d;d[0]=l[0];for(let g=1,y=i.ONE;g<l.length;g++)y=i.mul(y,f),d[g]=i.mul(l[g],y);return d},clone:l=>{a(l);let f=s(l.length);for(let d=0;d<l.length;d++)f[d]=l[d];return f},eval:(l,f)=>{a(l,f);let d=i.ZERO;for(let g=0;g<l.length;g++)d=i.add(d,i.mul(l[g],f[g]));return d},monomial:{basis:(l,f)=>{let d=s(f),g=i.ONE;for(let y=0;y<f;y++)d[y]=g,g=i.mul(g,l);return d},eval:(l,f)=>{a(l);let d=i.ZERO;for(let g=l.length-1;g>=0;g--)d=i.add(i.mul(d,f),l[g]);return d}},lagrange:{basis:(l,f,d=!1,g)=>{if(!ks(f))throw new Error("poly.lagrange: expected power of two length, got "+f);let y=Cr(f),m=g||(d?t.brp(y):t.roots(y)),w=s(f),T=h(l,f,d,g);if(T!==-1)return w[T]=i.ONE,w;let F=i.pow(l,BigInt(f)),B=i.mul(i.sub(F,i.ONE),i.inv(BigInt(f))),L=s(f);for(let $=0;$<f;$++)L[$]=i.sub(l,m[$]);let K=i.invertBatch(L);for(let $=0;$<f;$++)w[$]=i.mul(B,i.mul(m[$],K[$]));return w},eval(l,f,d=!1){a(l);let g=h(f,l.length,d);if(g!==-1)return l[g];let y=this.basis(f,l.length,d),m=i.ZERO;for(let w=0;w<l.length;w++)i.is0(l[w])||(m=i.add(m,i.mul(l[w],y[w])));return m}},vanishing(l){if(c("roots",l),o!==void 0&&l.length!==o)throw new Error(`poly: expected fixed length ${o}, got ${l.length}`);let f=s(l.length+1,i.ZERO);f[0]=i.ONE;for(let d of l){let g=i.neg(d);for(let y=f.length-1;y>0;y--)f[y]=i.add(i.mul(f[y],g),f[y-1]);f[0]=i.mul(f[0],g)}return f}}}var Ds=Ot(()=>{C();Je()});function tn(e,t){if(bt(e),bt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function Eu(e,t){let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r];return n}function qs(e){if(!ie(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?mn(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Bu(e,t,n,r){if(M(e),bt(n),typeof r!="function")throw new Error("expand_message_xmd: expected hash function");bt(r.outputLen,"hash.outputLen"),bt(r.blockLen,"hash.blockLen"),t=qs(t),t.length>255&&(t=r(ft(mn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:i}=r,s=Math.ceil(n/o);if(n>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let u=ft(t,tn(t.length,1)),c=new Uint8Array(i),a=tn(n,2),h=new Array(s),l=r(ft(c,e,a,tn(0,1),u));h[0]=r(ft(l,tn(1,1),u));for(let d=1;d<s;d++){let g=[Eu(l,h[d-1]),tn(d+1,1),u];h[d]=r(ft(...g))}return ft(...h).slice(0,n)}function Su(e,t,n,r,o){if(M(e),bt(n),bt(r,"k"),r<0)throw new Error("expand_message_xof: invalid k");if(typeof o!="function")throw new Error("expand_message_xof: expected XOF function");if(typeof o.create!="function")throw new Error("expand_message_xof: expected XOF create");if(t=qs(t),n<0||n>65535)throw new Error("expand_message_xof: invalid lenInBytes");if(t.length>255){let i=Math.ceil(2*r/8);t=o.create({dkLen:i}).update(mn("H2C-OVERSIZE-DST-")).update(t).digest()}if(t.length>255)throw new Error("expand_message_xof: invalid DST");return o.create({dkLen:n}).update(e).update(tn(n,2)).update(t).update(tn(t.length,1)).digest()}function ko(e,t,n){dt(n,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:r,k:o,m:i,hash:s,expand:u,DST:c}=n;if(bt(s.outputLen,"valid hash"),M(e),bt(t),bt(i,"m"),bt(o,"k"),r<=BigInt(1))throw new Error("hash_to_field: expected valid field characteristic");if(t<1)throw new Error("hash_to_field: expected count >= 1");if(i<1)throw new Error("hash_to_field: expected m >= 1");if(o<0)throw new Error("hash_to_field: invalid k");let a=r.toString(2).length,h=Math.ceil((a+o)/8),l=t*i*h,f;if(u==="xmd")f=Bu(e,c,l,s);else if(u==="xof")f=Su(e,c,l,o,s);else if(u==="_internal_pass")f=e;else throw new Error('expand must be "xmd" or "xof"');let d=new Array(t);for(let g=0;g<t;g++){let y=new Array(i);for(let m=0;m<i;m++){let w=h*(m+g*i),T=f.subarray(w,w+h);y[m]=jt(bu(T),r)}d[g]=y}return d}function Ms(e,t){Yt(e),Bt(t,"map");let n=t.map((r,o)=>{if(Bt(r,"map["+o+"]"),r.length<1)throw new Error("isogenyMap: expected non-empty coefficients");return Array.from(r).reverse()});return(r,o)=>{let[i,s,u,c]=n.map(f=>f.reduce((d,g)=>e.add(e.mul(d,r),g))),a=e.is0(s)||e.is0(c),[h,l]=xn(e,[s,c],!0);return r=e.mul(i,h),o=e.mul(o,e.mul(u,l)),a?{x:e.ZERO,y:e.ZERO}:{x:r,y:o}}}function Ks(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");dt(n);let r=c=>Object.freeze({...c,DST:ie(c.DST)?Be(c.DST):c.DST,...c.encodeDST===void 0?{}:{encodeDST:ie(c.encodeDST)?Be(c.encodeDST):c.encodeDST}}),o=r(n),i=c=>c&&c.DST!==void 0?{DST:c.DST}:void 0;function s(c){return e.fromAffine(t(c))}function u(c){let a=c.clearCofactor();return a.equals(e.ZERO)?e.ZERO:(a.assertValidity(),a)}return Object.freeze({get defaults(){return r(o)},Point:e,hashToCurve(c,a){let h=Object.assign({},o,i(a)),l=ko(c,2,h),f=s(l[0]),d=s(l[1]);return u(f.add(d))},encodeToCurve(c,a){let h=o.encodeDST===void 0?{}:{DST:o.encodeDST},l=Object.assign({},o,h,i(a)),f=ko(c,1,l),d=s(f[0]);return u(d)},mapToCurve(c){if(o.m===1){if(typeof c!="bigint")throw new Error("expected bigint (m=1)");return u(s([c]))}if(!Array.isArray(c))throw new Error("expected array of bigints");if(c.length!==o.m)throw new Error(`expected array of ${o.m} bigints`);for(let a of c)if(typeof a!="bigint")throw new Error("expected array of bigints");return u(s(c))},hashToScalar(c,a){let h=e.Fn.ORDER,l=Object.assign({},o,{DST:Au},i(a),{p:h,m:1});return ko(c,1,l)[0][0]}})}function vu(e,t){let n=Yt(e),r=n.ORDER,o=js;for(let y=r-ce;y%je===js;y/=je)o+=ce;let i=o,s=je<<i-ce-ce,u=s*je,c=(r-ce)/u,a=(c-ce)/je,h=u-ce,l=s,f=n.pow(t,c),d=n.pow(t,(c+ce)/je),g=(y,m)=>{let w=f,T=n.pow(m,h),F=n.sqr(T);F=n.mul(F,m);let B=n.mul(y,F);B=n.pow(B,a),B=n.mul(B,T),T=n.mul(B,m),F=n.mul(B,y);let L=n.mul(F,T);B=n.pow(L,l);let K=n.eql(B,n.ONE);T=n.mul(F,d),B=n.mul(L,w),F=n.cmov(T,F,K),L=n.cmov(B,L,K);for(let $=i;$>ce;$--){let yt=$-je;yt=je<<yt-ce;let nt=n.pow(L,yt),rt=n.eql(nt,n.ONE);T=n.mul(F,w),w=n.mul(w,w),nt=n.mul(L,w),F=n.cmov(T,F,rt),L=n.cmov(nt,L,rt)}return{isValid:!n.is0(m)&&(K||n.is0(y)),value:F}};if(n.ORDER%Ps===Hs){let y=(n.ORDER-Hs)/Ps,m=n.sqrt(n.neg(t));g=(w,T)=>{let F=n.sqr(T),B=n.mul(w,T);F=n.mul(F,B);let L=n.pow(F,y);L=n.mul(L,B);let K=n.mul(L,m),$=n.mul(n.sqr(L),T),yt=n.eql($,w),nt=n.cmov(K,L,yt);return{isValid:!n.is0(T)&&yt,value:nt}}}return g}function $s(e,t){let n=Yt(e);dt(t,{},{},"opts");let{A:r,B:o,Z:i}=t;if(!n.isValidNot0(r)||!n.isValidNot0(o)||!n.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");if(n.eql(i,n.neg(n.ONE))||Oo(n,i))throw new Error("mapToCurveSimpleSWU: invalid opts");let s=n.mul(o,n.inv(n.mul(i,r))),u=n.add(n.add(n.mul(n.sqr(s),s),n.mul(r,s)),o);if(!Oo(n,u))throw new Error("mapToCurveSimpleSWU: invalid opts");let c=vu(n,i);if(!n.isOdd)throw new Error("Field does not have .isOdd()");return a=>{let h,l,f,d,g,y,m,w;h=n.sqr(a),h=n.mul(h,i),l=n.sqr(h),l=n.add(l,h),f=n.add(l,n.ONE),f=n.mul(f,o),d=n.cmov(i,n.neg(l),!n.eql(l,n.ZERO)),d=n.mul(d,r),l=n.sqr(f),y=n.sqr(d),g=n.mul(y,r),l=n.add(l,g),l=n.mul(l,f),y=n.mul(y,d),g=n.mul(y,o),l=n.add(l,g),m=n.mul(h,f);let{isValid:T,value:F}=c(l,y);w=n.mul(h,a),w=n.mul(w,F),m=n.cmov(m,f,T),w=n.cmov(w,F,T);let B=n.isOdd(a)===n.isOdd(w);w=n.cmov(n.neg(w),w,B);let L=xn(n,[d],!0)[0];return m=n.mul(m,L),{x:m,y:w}}}var js,ce,je,Hs,Ps,bu,Au,zs=Ot(()=>{C();ke();Je();js=BigInt(0),ce=BigInt(1),je=BigInt(2),Hs=BigInt(3),Ps=BigInt(4),bu=It;Au="HashToScalar-"});function No(e){dt(e,{name:"string",hash:"function"},{hashToScalar:"function",validatePoint:"function",parsePublicKey:"function",adjustScalar:"function",adjustPoint:"function",challenge:"function",adjustNonces:"function",adjustSecret:"function",adjustPublic:"function",adjustGroupCommitmentShare:"function",adjustTx:"object",adjustDKG:"function"}),De(e.Point);let{Point:t,validatePoint:n,parsePublicKey:r,adjustScalar:o,adjustPoint:i,challenge:s,adjustNonces:u,adjustSecret:c,adjustPublic:a,adjustGroupCommitmentShare:h,adjustDKG:l}=e,f=e.Fn===void 0?t.Fn:e.Fn,d=e.adjustTx===void 0?void 0:{encode:e.adjustTx.encode,decode:e.adjustTx.decode};d&&dt(d,{encode:"function",decode:"function"});let g=e.hash,y=e.hashToScalar===void 0?(p,x={DST:new Uint8Array})=>{let A=g(ft(x.DST,p));return f.create(f.isLE?yn(A):It(A))}:e.hashToScalar,m=be(e.H1!==void 0?e.H1:e.name+"rho"),w=be(e.H2!==void 0?e.H2:e.name+"chal"),T=be(e.H3!==void 0?e.H3:e.name+"nonce"),F=be(e.H4!==void 0?e.H4:e.name+"msg"),B=be(e.H5!==void 0?e.H5:e.name+"com"),L=be(e.HDKG!==void 0?e.HDKG:e.name+"dkg"),K=be(e.HID!==void 0?e.HID:e.name+"id"),$=p=>y(p,{DST:m}),yt=p=>y(p,{DST:w}),nt=p=>y(p,{DST:T}),rt=p=>g(ft(F,p)),qt=p=>g(ft(B,p)),Nt=p=>y(p,{DST:L}),Mt=p=>y(p,{DST:K}),zt=(p=Dt)=>{if(typeof p!="function")throw new TypeError('"rng" expected function, got type='+typeof p);let x=Qe(p(En(f.ORDER)),f.ORDER,f.isLE);return f.isLE?yn(x):It(x)},it=p=>p.toBytes(),Xt=p=>{if(p.assertValidity(),p.is0())throw new Error("invalid point: identity");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return n&&n(p),p},lt=p=>Xt(t.fromBytes(p)),Ke=(p,x)=>({identifier:p,hiding:it(t.BASE.multiply(f.fromBytes(x.hiding))),binding:it(t.BASE.multiply(f.fromBytes(x.binding)))}),Qt=i===void 0?p=>p:i,N=p=>{if(!f.isValid(p)||f.is0(p))throw new Error("Invalid identifier "+p);return p},v=p=>Ee(f.toBytes(N(p))),E=(p,x="identifier")=>{Hn(p,x);let A=N(f.fromBytes(gn(p)));if(v(A)!==p)throw new Error("expected canonical identifier hex");return A},I=p=>({identifier:v(E(p.identifier)),commitment:p.commitment.map(x=>Be(x)),proofOfKnowledge:Be(p.proofOfKnowledge)}),U=p=>{let x=p.map(I);return x.sort((A,R)=>{let O=E(A.identifier),_=E(R.identifier);return O<_?-1:O>_?1:0}),x},D=(p,x)=>{if(p.length!==x.length)return!1;for(let A=0;A<p.length;A++){let R=p[A],O=x[A];if(R.identifier!==O.identifier||R.commitment.length!==O.commitment.length)return!1;for(let _=0;_<R.commitment.length;_++)if(!Bo(R.commitment[_],O.commitment[_]))return!1;if(!Bo(R.proofOfKnowledge,O.proofOfKnowledge))return!1}return!0},j={encode:(p,x)=>{let A=ft(it(p),f.toBytes(x));return d&&(A=d.encode(A)),A},decode:p=>{d&&(p=d.decode(p));let x=p.subarray(0,-f.BYTES),A=lt(x);if(it(A).length!==x.length)throw new Error("invalid signature encoding");let R=f.fromBytes(p.subarray(-f.BYTES));return{R:A,z:R}}},k=(p=Dt)=>{let x=zt(p);o&&(x=o(x));let A=t.BASE.multiply(x);return{scalar:x,point:A}},q="roots are unavailable in FROST polynomial mode",z={info:{G:f.ZERO,oddFactor:f.ZERO,powerOfTwo:0},roots(){throw new Error(q)},brp(){throw new Error(q)},inverse(){throw new Error(q)},omega(){throw new Error(q)},clear(){}},ot=Ns(f,z),X=(p,x)=>Bn(t,p,x),ut=(p,x)=>{if(!x.length)throw new Error("empty coefficients");return ot.monomial.eval(x,p)},wt=(p,x)=>{let A="invalid parameters";if(!p.some(H=>f.eql(H,x)))throw new Error(A);let R=new Set(p);if(R.size!==p.length)throw new Error(A);if(!R.has(x))throw new Error(A);let O=f.ONE,_=f.ONE;for(let H of p)f.eql(H,x)||(O=f.mul(O,H),_=f.mul(_,f.sub(H,x)));return f.div(O,_)},St=(p,x)=>{let A=ot.monomial.basis(p,x.length);return X(x,A)},vt=(p,x,A,R=Dt)=>{if(fe(p),x!==void 0&&M(x,f.BYTES,"secret"),A!==void 0&&Bt(A,"coeffs"),typeof R!="function")throw new TypeError('"rng" expected function, got type='+typeof R);let O=x===void 0?zt(R):f.fromBytes(x);if(!A){A=[];for(let Z=0;Z<p.min-1;Z++)A.push(zt(R))}if(A.length!==p.min-1)throw new Error("wrong coefficients length");let _=[O,...A],H=_.map(Z=>t.BASE.multiply(Z));return{coefficients:_,commitment:H,secret:O}},at={challenge:(p,x,A)=>Nt(ft(f.toBytes(p),it(x),it(A))),compute(p,x,A,R=Dt){if(x.length<1)throw new Error("coefficients should have at least one element");let{point:O,scalar:_}=k(R),H=A[0],Z=this.challenge(p,H,O),ht=f.add(_,f.mul(x[0],Z));return j.encode(O,ht)},validate(p,x,A){if(x.length<1)throw new Error("commitment should have at least one element");let{R,z:O}=j.decode(A),_=lt(x[0]),H=this.challenge(p,_,R);if(!R.equals(t.BASE.multiplyUnsafe(O).subtract(_.multiplyUnsafe(H))))throw new Error("invalid proof of knowledge")}},Tt={challenge:(p,x,A)=>s?s(p,x,A):yt(ft(it(p),it(x),A)),sign(p,x,A=Dt){let{point:R,scalar:O}=k(A),_=t.BASE.multiply(x),H=this.challenge(R,_,p),Z=f.add(O,f.mul(H,x));return[R,Z]},verify(p,x,A,R){i&&(R=i(R)),i&&(x=i(x));let O=this.challenge(x,R,p),_=t.BASE.multiplyUnsafe(A),H=R.multiplyUnsafe(O),Z=_.subtract(H).subtract(x);return Z.clearCofactor&&(Z=Z.clearCofactor()),t.ZERO.equals(Z)}},sn=(p,x,A)=>{if(!t.BASE.multiply(A).equals(St(p,x)))throw new Error("invalid secret share")},pe={fromNumber(p){if(!Number.isSafeInteger(p))throw new Error("expected safe interger");return v(BigInt(p))},derive(p){return Hn(p,"s"),v(Mt(be(p)))}},or=(p,x=Dt)=>nt(ft(x(32),f.toBytes(p))),ir=(p,x,A)=>{let R=x.map(xt=>[xt.identifier,E(xt.identifier),lt(xt.hiding),lt(xt.binding)]);R.sort((xt,Lt)=>xt[1]<Lt[1]?-1:xt[1]>Lt[1]?1:0);let O=[];for(let[xt,Lt,J,At]of R)O.push(f.toBytes(Lt),it(J),it(At));let _=qt(ft(...O)),H=ft(it(p),rt(A),_),Z={};for(let[xt,Lt]of R)Z[xt]=$(ft(H,f.toBytes(Lt)));let ht=t.ZERO,st=[],tt=[];for(let[xt,Lt,J,At]of R){if(t.ZERO.equals(J)||t.ZERO.equals(At))throw new Error("infinity commitment");ht=ht.add(J),st.push(At),tt.push(Z[xt])}let Ft=ht.add(X(st,tt));return{identifiers:R.map(xt=>xt[1]),groupCommitment:Ft,bindingFactors:Z}},sr=(p,x,A,R)=>{let O=Qt(lt(p)),_=E(R),{identifiers:H,groupCommitment:Z,bindingFactors:ht}=ir(O,x,A),st=ht[R],tt=wt(H,_),Ft=Tt.challenge(Z,O,A);return{lambda:tt,challenge:Ft,bindingFactor:st,groupCommitment:Z}};Object.freeze(pe);let Wc={Identifier:pe,DKG:Object.freeze({round1:(p,x,A,R=Dt)=>{let O=E(p,"id");fe(x);let{coefficients:_,commitment:H}=vt(x,A,void 0,R),Z=at.compute(O,_,H,R),ht=H.map(it),st={identifier:v(O),commitment:ht,proofOfKnowledge:Z},tt={identifier:O,coefficients:_,commitment:H.map(it),signers:{min:x.min,max:x.max},step:1};return{public:st,secret:tt}},round2:(p,x)=>{if(dt(p,{identifier:"bigint",commitment:"object",signers:"object"},{coefficients:"object",round1Cache:"object",round2Cache:"object",step:"number"},"secret"),fe(p.signers,"secret.signers"),Bt(x,"others"),x.length!==p.signers.max-1)throw new Error("wrong number of round1 packages");if(!p.coefficients||p.step===3)throw new Error("round3 package used in round2");let A=U(x);if(p.round2Cache!==void 0){if(p.round1Cache===void 0||!D(p.round1Cache,A))throw new Error("round1 packages do not match authenticated transcript");return p.round2Cache}let R={};for(let O of A){if(O.commitment.length!==p.signers.min)throw new Error("wrong number of commitments");let _=E(O.identifier);if(_===p.identifier)throw new Error("duplicate id="+v(_));at.validate(_,O.commitment,O.proofOfKnowledge);for(let Z of O.commitment)lt(Z);if(R[O.identifier])throw new Error("Duplicate id="+_);let H=f.toBytes(ut(_,p.coefficients));R[O.identifier]={identifier:v(p.identifier),signingShare:H}}return p.round1Cache=A,p.round2Cache=R,p.step=2,R},round3:(p,x,A)=>{if(dt(p,{identifier:"bigint",commitment:"object",signers:"object"},{coefficients:"object",round1Cache:"object",round2Cache:"object",step:"number"},"secret"),fe(p.signers,"secret.signers"),Bt(x,"round1"),Bt(A,"round2"),x.length!==p.signers.max-1)throw new Error("wrong length of round1 packages");if(!p.coefficients||p.step!==2||!p.round1Cache)throw new Error("round2 package used in round3");let R=U(x),O=p.round1Cache;if(!D(O,R))throw new Error("round1 packages do not match authenticated transcript");if(A.length!==O.length)throw new Error("wrong length of round2 packages");let _={};for(let J of O){if(!J.identifier||!J.commitment)throw new Error("wrong round1 share");_[J.identifier]={...J}}for(let J of A){if(!J.identifier||!J.signingShare)throw new Error("wrong round2 share");if(!_[J.identifier])throw new Error("round1 share for "+J.identifier+" is missing");_[J.identifier].signingShare=J.signingShare}if(Object.keys(_).length!==O.length)throw new Error("mismatch identifiers between rounds");let H=f.ZERO;if(p.commitment.length!==p.signers.min)throw new Error("wrong commitments length");let Z=p.commitment.map(lt),ht=ut(p.identifier,p.coefficients);sn(p.identifier,Z,ht);let st=Z.map(it),tt={[v(p.identifier)]:st};for(let J in _){let At=_[J];if(!At.signingShare||!At.commitment)throw new Error("mismatch identifiers");let ge=E(J),cr=f.fromBytes(At.signingShare),Qr=At.commitment.map(lt);sn(p.identifier,Qr,cr),H=f.add(H,cr);let Fn=v(ge);if(tt[Fn])throw new Error("duplicated id="+Fn);tt[Fn]=At.commitment}H=f.add(H,ht);let Ft=new Array(p.signers.min).fill(t.ZERO);for(let J in tt){let At=tt[J];if(At.length!==p.signers.min)throw new Error("wrong commitments length");for(let ge=0;ge<At.length;ge++)Ft[ge]=Ft[ge].add(lt(At[ge]))}let cn=Ft.map(it),xt={};for(let J in tt)xt[J]=it(St(E(J),Ft));let Lt={public:{signers:{min:p.signers.min,max:p.signers.max},commitments:cn,verifyingShares:Object.fromEntries(Object.entries(xt).map(([J,At])=>[J,At.slice()]))},secret:{identifier:v(p.identifier),signingShare:f.toBytes(H)}};l&&(Lt=l(Lt));for(let J=0;J<p.coefficients.length;J++)p.coefficients[J]-=p.coefficients[J];return delete p.coefficients,delete p.round1Cache,delete p.round2Cache,p.step=3,Lt},clean(p){if(dt(p,{identifier:"bigint",commitment:"object",signers:"object"},{coefficients:"object",round1Cache:"object",round2Cache:"object",step:"number"},"secret"),p.identifier-=p.identifier,p.coefficients)for(let x=0;x<p.coefficients.length;x++)p.coefficients[x]-=p.coefficients[x];delete p.round1Cache,delete p.round2Cache,p.step=3}}),trustedDealer(p,x,A,R=Dt){if(fe(p),x===void 0){x=[];for(let st=1;st<=p.max;st++)x.push(pe.fromNumber(st))}else if(Bt(x,"identifiers"),x.length!==p.max)throw new Error("identifiers should be array of "+p.max);let O={};for(let st of x){let tt=E(st);if(st in O)throw new Error("duplicated id="+st);O[st]=tt}let _=vt(p,A,void 0,R),H=_.commitment.map(it),Z={},ht={};for(let st of x){let tt=ut(O[st],_.coefficients);ht[st]=it(t.BASE.multiply(tt)),Z[st]={identifier:st,signingShare:f.toBytes(tt)}}return{public:{signers:{min:p.min,max:p.max},commitments:H,verifyingShares:ht},secretShares:Z}},validateSecret(p,x){dt(p,{identifier:"string",signingShare:"object"},{},"secret"),M(p.signingShare,f.BYTES,"secret.signingShare"),dt(x,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),fe(x.signers,"pub.signers"),Bt(x.commitments,"pub.commitments");let A=E(p.identifier),R=x.commitments.map(lt),O=f.fromBytes(p.signingShare);sn(A,R,O)},commit(p,x=Dt){if(dt(p,{identifier:"string",signingShare:"object"},{},"secret"),M(p.signingShare,f.BYTES,"secret.signingShare"),typeof x!="function")throw new TypeError('"rng" expected function, got type='+typeof x);let A=f.fromBytes(p.signingShare),R=or(A,x),O=or(A,x),_={hiding:f.toBytes(R),binding:f.toBytes(O)};return{nonces:_,commitments:Ke(p.identifier,_)}},signShare(p,x,A,R,O){dt(p,{identifier:"string",signingShare:"object"},{},"secret"),M(p.signingShare,f.BYTES,"secret.signingShare"),dt(x,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),fe(x.signers,"pub.signers"),Bt(x.commitments,"pub.commitments"),dt(A,{hiding:"object",binding:"object"},{},"nonces"),M(A.hiding,f.BYTES,"nonces.hiding"),M(A.binding,f.BYTES,"nonces.binding"),Bt(R,"commitmentList"),M(O,void 0,"msg"),Zs(x.signers,R.length);let _=f.fromBytes(A.hiding),H=f.fromBytes(A.binding);if(f.is0(_)||f.is0(H))throw new Error("signing nonces already used");let Z={identifier:p.identifier,hiding:it(t.BASE.multiply(_)),binding:it(t.BASE.multiply(H))},ht=R.find(Fn=>Fn.identifier===p.identifier);if(!ht)throw new Error("missing signer commitment");if(Ee(ht.hiding)!==Ee(Z.hiding)||Ee(ht.binding)!==Ee(Z.binding))throw new Error("incorrect signer commitment");c&&(p=c(p,x)),a&&(x=a(x));let st=f.fromBytes(p.signingShare),{lambda:tt,challenge:Ft,bindingFactor:cn,groupCommitment:xt}=sr(x.commitments[0],R,O,p.identifier),Lt=u?u(xt,A):A,J=u?f.fromBytes(Lt.hiding):_,At=u?f.fromBytes(Lt.binding):H,ge=f.mul(f.mul(tt,st),Ft),cr=f.mul(At,cn),Qr=f.toBytes(f.add(f.add(J,cr),ge));return A.hiding.fill(0),A.binding.fill(0),Qr},verifyShare(p,x,A,R,O){dt(p,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),fe(p.signers,"pub.signers"),Bt(p.commitments,"pub.commitments"),Bt(x,"commitmentList"),M(A,void 0,"msg"),E(R),M(O,f.BYTES,"sigShare"),a&&(p=a(p));let _=x.find(At=>At.identifier===R);if(!_)throw new Error("cannot find identifier commitment");let H=lt(p.verifyingShares[R]),Z=lt(_.hiding),ht=lt(_.binding),{lambda:st,challenge:tt,bindingFactor:Ft,groupCommitment:cn}=sr(p.commitments[0],x,A,R),xt=Z.add(ht.multiplyUnsafe(Ft));h&&(xt=h(cn,xt));let Lt=t.BASE.multiplyUnsafe(f.fromBytes(O)),J=xt.add(H.multiplyUnsafe(f.mul(tt,st)));return Lt.equals(J)},aggregate(p,x,A,R){dt(p,{signers:"object",commitments:"object",verifyingShares:"object"},{},"pub"),fe(p.signers,"pub.signers"),Bt(p.commitments,"pub.commitments"),Bt(x,"commitmentList"),M(A,void 0,"msg"),dt(R,{},{},"sigShares");let O=p;a&&(p=a(p));try{Zs(p.signers,x.length)}catch{throw new en("aggregation failed",[])}let _=x.map(tt=>tt.identifier),H=new Set;for(let tt of _){if(H.has(tt))throw new en("aggregation failed",[]);H.add(tt)}if(_.length!==Object.keys(R).length)throw new en("aggregation failed",[]);for(let tt of _)if(!(tt in R)||!(tt in p.verifyingShares))throw new en("aggregation failed",[]);let Z=lt(p.commitments[0]),{groupCommitment:ht}=ir(Z,x,A),st=f.ZERO;for(let tt of _)st=f.add(st,f.fromBytes(R[tt]));if(!Tt.verify(A,ht,st,Z)){let tt=[];for(let Ft of _)this.verifyShare(O,x,A,Ft,R[Ft])||tt.push(Ft);throw new en("aggregation failed",tt)}return j.encode(ht,st)},sign(p,x){let A=f.fromBytes(x);o&&(A=o(A));let[R,O]=Tt.sign(p,A);return j.encode(R,O)},verify(p,x,A){let R=r?Xt(r(A)):lt(A),{R:O,z:_}=j.decode(p);return Tt.verify(x,O,_,R)},combineSecret(p,x){if(Bt(p,"shares"),fe(x),p.length<x.min||p.length>x.max)throw new Error("wrong secret shares array");let A=[],R={};for(let H of p){let Z=E(H.identifier),ht=v(Z);if(R[ht])throw new Error("duplicated id="+ht);R[ht]=!0,A.push([Z,f.fromBytes(H.signingShare)])}let O=A.map(([H])=>H),_=f.ZERO;for(let[H,Z]of A)_=f.add(_,f.mul(Z,wt(O,H)));return f.toBytes(_)},utils:Object.freeze({Fn:f,randomScalar:(p=Dt)=>f.toBytes(k(p).scalar),generateSecretPolynomial:(p,x,A,R)=>{let O=vt(p,x,A,R);return{...O,commitment:O.commitment.map(it)}}})};return Object.freeze(Wc)}var fe,Zs,en,Ys=Ot(()=>{C();Re();ke();Lr();Ds();Je();fe=(e,t="signers")=>{if(dt(e,{min:"number",max:"number"},{},t),bt(e.min,t+".min"),bt(e.max,t+".max"),e.min<2||e.max<2||e.min>e.max)throw new Error("Wrong signers info: min="+e.min+" max="+e.max)},Zs=(e,t)=>{if(t<e.min||t>e.max)throw new Error("Wrong number of commitments="+t)},en=class extends Error{constructor(n,r){super(n);S(this,"cheaters");this.cheaters=r}}});var jo={};fr(jo,{_HMAC:()=>Kn,hmac:()=>Do});var Kn,Do,kr=Ot(()=>{C();Re();Kn=class{constructor(t,n){S(this,"oHash");S(this,"iHash");S(this,"blockLen");S(this,"outputLen");S(this,"canXOF",!1);S(this,"finished",!1);S(this,"destroyed",!1);if(gr(t),oe(n,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),Ie(o)}update(t){return dn(this),this.iHash.update(t),this}digestInto(t){dn(this),yr(t,this),this.finished=!0;let n=t.subarray(0,this.outputLen);this.iHash.digestInto(n),this.oHash.update(n),this.oHash.digestInto(n),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:r,finished:o,destroyed:i,blockLen:s,outputLen:u,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=u,t.canXOF=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Do=(()=>{let e=((t,n,r)=>new Kn(t,n).update(r).digest());return e.create=(t,n)=>new Kn(t,n),e})()});var Tu,Ho,Se,Nr,Vs=Ot(()=>{C();ke();Tu=BigInt(0),Ho=class extends Error{constructor(t=""){super(t)}},Se={Err:Ho,_tlv:{encode:(e,t)=>{let{Err:n}=Se;if(bt(e,"tag"),e<0||e>255)throw new n("tlv.encode: wrong tag");if(Hn(t,"data"),t.length&1)throw new n("tlv.encode: unpadded data");let r=t.length/2,o=Pn(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");let i=r>127?Pn(o.length/2|128):"";return Pn(e)+i+o+t},decode(e,t){let{Err:n}=Se;t=M(t,void 0,"DER data");let r=0;if(e<0||e>255)throw new n("tlv.decode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");let o=t[r++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");let a=t.subarray(r,r+c);if(a.length!==c)throw new n("tlv.decode: length bytes not complete");if(a[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(let h of a)s=s<<8|h;if(r+=c,s<128)throw new n("tlv.decode(long): not minimal encoding")}let u=t.subarray(r,r+s);if(u.length!==s)throw new n("tlv.decode: wrong value length");return{v:u,l:t.subarray(r+s)}}},_int:{encode(e){let{Err:t}=Se;if(Rr(e),e<Tu)throw new t("integer: negative integers are not allowed");let n=Pn(e);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){let{Err:t}=Se;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return It(e)}},toSig(e,t){let{Err:n,_int:r,_tlv:o}=Se;if(t!==void 0&&(bt(t,"maxScalarBytes"),t<1))throw new n("invalid signature: maxScalarBytes must be positive");let i=M(e,void 0,"signature"),{v:s,l:u}=o.decode(48,i);if(u.length)throw new n("invalid signature: left bytes after parsing");let{v:c,l:a}=o.decode(2,s),{v:h,l}=o.decode(2,a);if(l.length)throw new n("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||h.length>t))throw new n("invalid signature: integer too large");return{r:r.decode(c),s:r.decode(h)}},hexFromSig(e){let{_tlv:t,_int:n}=Se;dt(e,{r:"bigint",s:"bigint"},{},"sig");let r=t.encode(2,n.encode(e.r)),o=t.encode(2,n.encode(e.s)),i=r+o;return t.encode(48,i)}},Nr=(Object.freeze(Se._tlv),Object.freeze(Se._int),Object.freeze(Se))});function Iu(e,t,n){Ao("scalar",e,Ae,n);let[[r,o],[i,s]]=t,u=Ws(s*e,n),c=Ws(-o*e,n),a=e-u*r-c*i,h=-u*o-c*s,l=a<Ae,f=h<Ae;l&&(a=-a),f&&(h=-h);let d=qn(Math.ceil(wn(n)/2))+nn;if(a<Ae||a>=d||h<Ae||h>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:a,k2neg:f,k2:h}}function Mo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Po(e,t){dt(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return se(n.lowS,"lowS"),se(n.prehash,"prehash"),n.format!==void 0&&Mo(n.format),n}function Xs(e,t={}){let n=Cs("weierstrass",e,t),r=n.Fp,o=n.Fn,i=n.CURVE,{h:s,n:u}=i;dt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:a,clearCofactor:h,isTorsionFree:l,fromBytes:f,toBytes:d}=t,g=t.randomBytes===void 0?Dt:t.randomBytes;if(c&&(!r.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let y=c?{beta:c.beta,basises:c.basises.map(v=>[...v])}:void 0,m=Js(r,o);function w(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function T(v,E,I){if(E.is0()){if(!a)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:U,y:D}=E.toAffine(),j=r.toBytes(U);if(se(I,"isCompressed"),I){w();let k=!r.isOdd(D);return ft(Qs(k),j)}else return ft(Uint8Array.of(4),j,r.toBytes(D))}function F(v){M(v,void 0,"Point");let{publicKey:E,publicKeyUncompressed:I}=m,U=v.length,D=v[0],j=v.subarray(1);if(a&&U===1&&D===0)return{x:r.ZERO,y:r.ZERO};if(U===E&&(D===2||D===3)){let k=r.fromBytes(j);if(!r.isValid(k))throw new Error("bad point: is not on curve, wrong x");let q=yt(k),z;try{z=r.sqrt(q)}catch(ut){let wt=ut instanceof Error?": "+ut.message:"";throw new Error("bad point: is not on curve, sqrt error"+wt)}w();let ot=r.isOdd(z);return(D&1)===1!==ot&&(z=r.neg(z)),{x:k,y:z}}else if(U===I&&D===4){let k=r.BYTES,q=r.fromBytes(j.subarray(0,k)),z=r.fromBytes(j.subarray(k,k*2));if(!nt(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${U}, expected compressed=${E} or uncompressed=${I}`)}let B=d===void 0?T:d,L=f===void 0?F:f,K=r.mul(i.b,qo),$=r.is0(i.a)?v=>r.ZERO:v=>r.mul(i.a,v);function yt(v){let E=r.sqr(v),I=r.mul(E,v);return r.add(r.add(I,r.mul(v,i.a)),i.b)}function nt(v,E){let I=r.sqr(E),U=yt(v);return r.eql(I,U)}if(!nt(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let rt=r.mul(r.pow(i.a,qo),Ru),qt=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(rt,qt)))throw new Error("bad curve params: a or b");function Nt(v,E,I=!1){if(!r.isValid(E)||I&&r.is0(E))throw new Error(`bad point coordinate ${v}`);return typeof E=="object"&&E!==null?r.create(E):E}function Mt(v){if(!(v instanceof lt))throw new Error("Weierstrass Point expected")}function zt(v){if(!y||!y.basises)throw new Error("no endo");return Iu(v,y.basises,o.ORDER)}function it(v,E,I,U){if(!o.isValid(U))throw new RangeError("invalid scalar: out of range");if(y){let{k1neg:D,k1:j,k2neg:k,k2:q}=zt(U),z=new lt(r.mul(I.X,y.beta),I.Y,I.Z);v.push(D?I.negate():I,k?z.negate():z),E.push(j,q)}else v.push(I),E.push(U)}let Xt=new WeakSet,N=class N{constructor(E,I,U){S(this,"X");S(this,"Y");S(this,"Z");this.X=Nt("x",E),this.Y=Nt("y",I,!0),this.Z=Nt("z",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){let{x:I,y:U}=E||{};if(!E||!r.isValid(I)||!r.isValid(U))throw new Error("invalid affine point");if(E instanceof N)throw new Error("projective point not allowed");return r.is0(I)&&r.is0(U)?N.ZERO:new N(I,U,r.ONE)}static fromBytes(E){let I=N.fromAffine(L(M(E,void 0,"point")));return I.assertValidity(),I}static fromHex(E){return N.fromBytes(gn(E))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=6,I=!0){return Qt.setWindowSize(this,E),I||this.multiply(qo),this}assertValidity(){let E=this;if(E.is0()){if(a&&r.is0(E.X)&&r.eql(E.Y,r.ONE)&&r.is0(E.Z))return;throw new Error("bad point: ZERO")}if(Xt.has(E))return;let{x:I,y:U}=E.toAffine();if(!r.isValid(I)||!r.isValid(U))throw new Error("bad point: x or y not field elements");if(!nt(I,U))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");Xt.add(E)}hasEvenY(){let{y:E}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(E)}equals(E){Mt(E);let{X:I,Y:U,Z:D}=this,{X:j,Y:k,Z:q}=E,z=r.eql(r.mul(I,q),r.mul(j,D)),ot=r.eql(r.mul(U,q),r.mul(k,D));return z&&ot}negate(){return new N(this.X,r.neg(this.Y),this.Z)}double(){let{X:E,Y:I,Z:U}=this,D=r.ZERO,j=r.ZERO,k=r.ZERO,q=r.mul(E,E),z=r.mul(I,I),ot=r.mul(U,U),X=r.mul(E,I);return X=r.add(X,X),k=r.mul(E,U),k=r.add(k,k),D=$(k),j=r.mul(K,ot),j=r.add(D,j),D=r.sub(z,j),j=r.add(z,j),j=r.mul(D,j),D=r.mul(X,D),k=r.mul(K,k),ot=$(ot),X=r.sub(q,ot),X=$(X),X=r.add(X,k),k=r.add(q,q),q=r.add(k,q),q=r.add(q,ot),q=r.mul(q,X),j=r.add(j,q),ot=r.mul(I,U),ot=r.add(ot,ot),q=r.mul(ot,X),D=r.sub(D,q),k=r.mul(ot,z),k=r.add(k,k),k=r.add(k,k),new N(D,j,k)}add(E){Mt(E);let{X:I,Y:U,Z:D}=this,{X:j,Y:k,Z:q}=E,z=r.ZERO,ot=r.ZERO,X=r.ZERO,ut=r.mul(I,j),wt=r.mul(U,k),St=r.mul(D,q),vt=r.add(I,U),at=r.add(j,k);vt=r.mul(vt,at),at=r.add(ut,wt),vt=r.sub(vt,at),at=r.add(I,D);let Tt=r.add(j,q);return at=r.mul(at,Tt),Tt=r.add(ut,St),at=r.sub(at,Tt),Tt=r.add(U,D),z=r.add(k,q),Tt=r.mul(Tt,z),z=r.add(wt,St),Tt=r.sub(Tt,z),X=$(at),z=r.mul(K,St),X=r.add(z,X),z=r.sub(wt,X),X=r.add(wt,X),ot=r.mul(z,X),wt=r.add(ut,ut),wt=r.add(wt,ut),St=$(St),at=r.mul(K,at),wt=r.add(wt,St),St=r.sub(ut,St),St=$(St),at=r.add(at,St),ut=r.mul(wt,at),ot=r.add(ot,ut),ut=r.mul(Tt,at),z=r.mul(vt,z),z=r.sub(z,ut),ut=r.mul(vt,wt),X=r.mul(Tt,X),X=r.add(X,ut),new N(z,ot,X)}subtract(E){return Mt(E),this.add(E.negate())}is0(){return this.equals(N.ZERO)}multiply(E){if(!o.isValidNot0(E))throw new RangeError("invalid scalar: out of range");let{p:I,f:U}=Qt.mulSecret(this,E,s,Ke);return Ke([I,U])[0]}multiplyUnsafe(E){let I=this,U=E;if(!o.isValid(U))throw new RangeError("invalid scalar: out of range");if(U===Ae||I.is0())return N.ZERO;if(U===nn)return I;if(Qt.hasWindowSize(this))return Qt.mulUnsafe(I,U,Ke);let D=[],j=[];return it(D,j,I,U),Bn(N,D,j)}mulAddUnsafe(E,I,U){Mt(I);let D=[],j=[];return it(D,j,this,E),it(D,j,I,U),Bn(N,D,j)}toAffine(E){let I=this,U=E;if(U!=null&&!r.isValid(U))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:j,Z:k}=I;if(r.eql(k,r.ONE))return{x:D,y:j};let q=I.is0();U==null&&(U=q?r.ONE:r.inv(k));let z=r.mul(D,U),ot=r.mul(j,U),X=r.mul(k,U);if(q)return{x:r.ZERO,y:r.ZERO};if(!r.eql(X,r.ONE))throw new Error("invZ was invalid");return{x:z,y:ot}}isTorsionFree(){return s===nn?!0:l?l(N,this):Qt.mulUnsafe(this,u).is0()}clearCofactor(){return s===nn?this:h?h(N,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===nn?this.is0():this.clearCofactor().is0()}toBytes(E=!0){return se(E,"isCompressed"),this.assertValidity(),B(N,this,E)}toHex(E=!0){return Ee(this.toBytes(E))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};S(N,"BASE",new N(i.Gx,i.Gy,r.ONE)),S(N,"ZERO",new N(r.ZERO,r.ONE,r.ZERO)),S(N,"Fp",r),S(N,"Fn",o);let lt=N,Ke=v=>_s(lt,v),Qt=new _r(lt,g);return Qt.bits>=6&&lt.BASE.precompute(6),Object.freeze(lt.prototype),Object.freeze(lt),lt}function Qs(e){return Uint8Array.of(e?2:3)}function Js(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ou(e,t={}){De(e);let{Fn:n}=e,r=t.randomBytes===void 0?Dt:t.randomBytes,o=Object.assign(Js(e.Fp,n),{seed:Math.max(En(n.ORDER),16)});function i(d){try{let g=n.fromBytes(d);return n.isValidNot0(g)}catch{return!1}}function s(d,g){let{publicKey:y,publicKeyUncompressed:m}=o;try{let w=d.length;return g===!0&&w!==y||g===!1&&w!==m?!1:!e.fromBytes(d).is0()}catch{return!1}}function u(d){return d=d===void 0?r(o.seed):d,Qe(M(d,o.seed,"seed"),n.ORDER)}function c(d,g=!0){return e.BASE.multiply(n.fromBytes(d)).toBytes(g)}function a(d){let{secretKey:g,publicKey:y,publicKeyUncompressed:m}=o,w=n._lengths;if(!ie(d))return;let T=M(d,void 0,"key").length,F=T===y||T===m,B=T===g||!!w?.includes(T);if(!(F&&B))return F}function h(d,g,y=!0){if(a(d)===!0)throw new Error("first arg must be private key");if(a(g)===!1)throw new Error("second arg must be public key");let m=n.fromBytes(d),w=e.fromBytes(g);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(m).toBytes(y)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:u},f=Fr(u,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:e,utils:l,lengths:o})}function tc(e,t,n={}){De(e);let r=t;gr(r),dt(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},n),i=o.randomBytes===void 0?Dt:o.randomBytes,s=o.hmac===void 0?(N,v)=>Do(r,N,v):o.hmac,{Fp:u,Fn:c}=e,{ORDER:a,BITS:h}=c,l=En(a),f=Lo(i,l),{keygen:d,getPublicKey:g,getSharedSecret:y,utils:m,lengths:w}=Ou(e,o),T={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},F=a*Gs+nn<u.ORDER;function B(N){let v=a>>nn;return N>v}function L(N,v){if(!c.isValidNot0(v))throw new Error(`invalid signature ${N}: out of range 1..Point.Fn.ORDER`);return v}function K(){if(!u.isOdd)throw new Error("Field doesn't support isOdd")}function $(N,v,E){return K(),(N===E?0:2)|Number(u.isOdd(v))}function yt(){if(F)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function nt(N,v){Mo(v);let E=w.signature,I=v==="compact"?E:v==="recovered"?E+1:void 0;return M(N,I)}class rt{constructor(v,E,I){S(this,"r");S(this,"s");S(this,"recovery");if(this.r=L("r",v),this.s=L("s",E),I!=null){if(yt(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(v,E=T.format){nt(v,E);let I;if(E==="der"){if(v.length>2*c.BYTES+16)throw new Nr.Err("invalid signature: DER signature too long");let{r:k,s:q}=Nr.toSig(M(v),c.BYTES+1);return new rt(k,q)}E==="recovered"&&(I=v[0],E="compact",v=v.subarray(1));let U=w.signature/2,D=v.subarray(0,U),j=v.subarray(U,U*2);return new rt(c.fromBytes(D),c.fromBytes(j),I)}static fromHex(v,E){return this.fromBytes(gn(v),E)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new rt(this.r,this.s,v)}recoverPublicKey(v){let{r:E,s:I}=this,U=this.assertRecovery(),D=U===2||U===3?E+a:E;if(!u.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let j=u.toBytes(D),k=e.fromBytes(ft(Qs((U&1)===0),j)),q=c.inv(D),z=Nt(M(v,void 0,"msgHash")),ot=c.create(-z*q),X=c.create(I*q),ut=e.BASE.mulAddUnsafe(ot,k,X);if(ut.is0())throw new Error("invalid recovery: point at infinify");return ut.assertValidity(),ut}hasHighS(){return B(this.s)}toBytes(v=T.format){if(Mo(v),v==="der")return gn(Nr.hexFromSig(this));let{r:E,s:I}=this,U=c.toBytes(E),D=c.toBytes(I);return v==="recovered"?(yt(),ft(Uint8Array.of(this.assertRecovery()),U,D)):ft(U,D)}toHex(v){return Ee(this.toBytes(v))}}Object.freeze(rt.prototype),Object.freeze(rt);let qt=o.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let E=It(v),I=v.length*8-h;return I>0?E>>BigInt(I):E}:o.bits2int,Nt=o.bits2int_modN===void 0?function(v){return c.create(qt(v))}:o.bits2int_modN,Mt=qn(h);function zt(N){return Ao("num < 2^"+h,N,Ae,Mt),c.toBytes(N)}function it(N,v){return M(N,void 0,"message"),v?M(r(N),void 0,"prehashed message"):N}function Xt(N,v,E){let{lowS:I,prehash:U,extraEntropy:D}=Po(E,T);N=it(N,U);let j=Nt(N),k=c.fromBytes(v);if(!c.isValidNot0(k))throw new Error("invalid private key");let q=[zt(k),zt(j)];if(D!=null&&D!==!1){let ut=D===!0?i(w.secretKey):D;q.push(M(ut,void 0,"extraEntropy"))}let z=ft(...q),ot=j;function X(ut){let wt=qt(ut);if(!c.isValidNot0(wt))return;let St=e.BASE.multiply(wt).toAffine(),vt=c.create(St.x);if(vt===Ae)return;let at;if(f!==void 0){let pe=It(Qe(f(l),a)),or=c.inv(c.mul(pe,wt)),ir=c.mul(pe,ot),sr=c.mul(pe,k);at=c.create(or*c.create(ir+sr*vt))}else{let pe=As(wt,a);at=c.create(pe*c.create(ot+vt*k))}if(at===Ae)return;let Tt=$(St.x,St.y,vt),sn=at;return I&&B(at)&&(sn=c.neg(at),Tt^=1),new rt(vt,sn,F?void 0:Tt)}return{seed:z,k2sig:X}}function lt(N,v,E={}){let{seed:I,k2sig:U}=Xt(N,v,E);return ys(r.outputLen,c.BYTES,s)(I,U).toBytes(E.format)}function Ke(N,v,E,I={}){let{lowS:U,prehash:D,format:j}=Po(I,T);if(E=M(E,void 0,"publicKey"),v=it(v,D),!ie(N)){let k=N instanceof rt?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}nt(N,j);try{let k=rt.fromBytes(N,j),q=e.fromBytes(E);if(q.is0()||U&&k.hasHighS())return!1;let{r:z,s:ot}=k,X=Nt(v),ut=c.inv(ot),wt=c.create(X*ut),St=c.create(z*ut),vt=e.BASE.mulAddUnsafe(wt,q,St);if(vt.is0())return!1;let at=vt.toAffine();return!(c.create(at.x)!==z||j==="recovered"&&k.recovery!==$(at.x,at.y,z))}catch{return!1}}function Qt(N,v,E={}){let{prehash:I}=Po(E,T);return v=it(v,I),rt.fromBytes(N,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:d,getPublicKey:g,getSharedSecret:y,utils:m,lengths:w,Point:e,sign:lt,verify:Ke,recoverPublicKey:Qt,Signature:rt,hash:r})}var Ws,Ae,nn,Gs,qo,Ru,ec=Ot(()=>{C();kr();Re();ke();Lr();Vs();Je();Ws=(e,t)=>(e+(e>=0?t:-t)/Gs)/t;Ae=BigInt(0),nn=BigInt(1),Gs=BigInt(2),qo=BigInt(3),Ru=BigInt(4)});var Yo={};fr(Yo,{__TEST:()=>Cu,schnorr:()=>ku,schnorr_FROST:()=>Pu,secp256k1:()=>Fu,secp256k1_FROST:()=>ju,secp256k1_hasher:()=>zo});function _u(e){let t=Dr.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),u=BigInt(44),c=BigInt(88),a=e*e*e%t,h=a*a*e%t,l=Kt(h,n,t)*h%t,f=Kt(l,n,t)*h%t,d=Kt(f,nc,t)*a%t,g=Kt(d,o,t)*d%t,y=Kt(g,i,t)*g%t,m=Kt(y,u,t)*y%t,w=Kt(m,c,t)*m%t,T=Kt(w,u,t)*y%t,F=Kt(T,n,t)*h%t,B=Kt(F,s,t)*g%t,L=Kt(B,r,t)*a%t,K=Kt(L,nc,t);if(!Wt.eql(Wt.sqr(K),e))throw new Error("Cannot find square root");return K}function $n(e,...t){let n=rc[e];if(n===void 0){let r=Fe(mn(e));n=ft(r,r),rc[e]=n}return Fe(ft(n,...t))}function cc(e){let{Fn:t,BASE:n}=gt,r=t.fromBytes(M(e,32,"secretKey")),i=n.multiply(r).toAffine();return{scalar:ue(i.y)?r:t.neg(r),bytes:sc(i)}}function jr(e){let t=Wt;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x \u2265 p");let n=t.sqr(e),r=t.add(t.mulN(n,e),BigInt(7)),o=t.sqrt(r);ue(o)||(o=t.neg(o));let i=gt.fromAffine({x:e,y:o});return i.assertValidity(),i}function $o(...e){return gt.Fn.create(Sn($n("BIP0340/challenge",...e)))}function oc(e){return cc(e).bytes}function Lu(e,t,n=Dn(32)){let{Fn:r,BASE:o}=gt,i=Be(M(e,void 0,"message")),{bytes:s,scalar:u}=cc(t),c=M(n,32,"auxRand"),a=r.toBytes(u^Sn($n("BIP0340/aux",c))),h=$n("BIP0340/nonce",a,s,i),l=r.create(Sn(h));if(l===Ko)throw new Error("sign failed: k is zero");let d=o.multiply(l).toAffine(),g=ue(d.y)?l:r.neg(l),y=sc(d),m=$o(y,s,i),w=new Uint8Array(64);if(w.set(y,0),w.set(r.toBytes(r.create(g+m*u)),32),!fc(w,i,s))throw new Error("sign: Invalid signature produced");return w}function fc(e,t,n){let{Fp:r,Fn:o,BASE:i}=gt,s=M(e,64,"signature"),u=M(t,void 0,"message"),c=M(n,32,"publicKey");try{let a=jr(Sn(c)),h=s.subarray(0,32),l=Sn(h);if(!r.isValidNot0(l))return!1;let f=Sn(s.subarray(32,64));if(!o.isValidNot0(f))return!1;let d=$o(h,zn(a),u),g=i.mulAddUnsafe(f,a,o.neg(d)),{x:y,y:m}=g.toAffine();return!(g.is0()||!ue(m)||!r.eql(y,l))}catch{return!1}}function uc(e,t){if(t===void 0)return Ko;let n=zn(e),r=It($n("TapTweak",n,t));if(!gt.Fn.isValid(r))throw new Error("invalid TapTweak hash");return r}function Zo(e){let t=gt.fromBytes(e.commitments[0]);return ue(t.y)?e:{signers:{min:e.signers.min,max:e.signers.max},commitments:e.commitments.map(n=>gt.fromBytes(n).negate().toBytes()),verifyingShares:Object.fromEntries(Object.entries(e.verifyingShares).map(([n,r])=>[n,gt.fromBytes(r).negate().toBytes()]))}}function ac(e,t){let n=gt.fromBytes(t.commitments[0]);if(ue(n.y))return e;let r=gt.Fn;return{...e,signingShare:r.toBytes(r.neg(r.fromBytes(e.signingShare)))}}function Hu(e,t){if(ue(e.y))return t;let n=gt.Fn;return{binding:n.toBytes(n.neg(n.fromBytes(t.binding))),hiding:n.toBytes(n.neg(n.fromBytes(t.hiding)))}}function lc(e,t,n){let r=gt.Fn,o=ac(e,t),i=Zo(t),s=uc(gt.fromBytes(i.commitments[0]),n),u=r.toBytes(r.add(r.fromBytes(o.signingShare),s));return{identifier:o.identifier,signingShare:u}}function hc(e,t){let n=Zo(e),r=uc(gt.fromBytes(n.commitments[0]),t);if(r===Ko)return n;let o=gt.BASE.multiply(r),i=n.commitments.map((u,c)=>(c===0?gt.fromBytes(u).add(o):gt.fromBytes(u)).toBytes()),s={};for(let u in n.verifyingShares)s[u]=gt.fromBytes(n.verifyingShares[u]).add(o).toBytes();return{signers:{min:n.signers.min,max:n.signers.max},commitments:i,verifyingShares:s}}var Dr,Uu,Ko,nc,Wt,gt,Fu,rc,zn,sc,ue,Sn,Cu,ku,Nu,ic,Du,zo,ju,Pu,Vo=Ot(()=>{C();Tr();Re();Lr();Ys();zs();Je();ec();ke();Dr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Uu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ko=BigInt(0),nc=BigInt(2);Wt=bn(Dr.p,{sqrt:_u}),gt=Xs(Dr,{Fp:Wt,endo:Uu}),Fu=tc(gt,Fe),rc=Object.create(null);zn=e=>e.toBytes(!0).slice(1),sc=({x:e})=>Wt.toBytes(e),ue=e=>!Wt.isOdd(e);Sn=It;Cu=Object.freeze({lift_x:jr,frostTweakPublic:hc,frostTweakSecret:lc}),ku=(()=>{let n=r=>(r=r===void 0?Dn(48):r,Qe(M(r,48,"seed"),Dr.n));return Object.freeze({keygen:Fr(n,oc),getPublicKey:oc,sign:Lu,verify:fc,Point:gt,utils:Object.freeze({randomSecretKey:n,taggedHash:$n,lift_x:jr,pointToBytes:zn}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),Nu=Ms(Wt,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),Du=()=>ic||(ic=$s(Wt,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:Wt.create(BigInt("-11"))})),zo=Ks(gt,e=>{let{x:t,y:n}=Du()(Wt.create(e[0]));return Nu(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:Wt.ORDER,m:1,k:128,expand:"xmd",hash:Fe}),ju=No({name:"FROST-secp256k1-SHA256-v1",Point:gt,hashToScalar:zo.hashToScalar,hash:Fe});Pu=No({name:"FROST-secp256k1-SHA256-TR-v1",Point:gt,hashToScalar:zo.hashToScalar,hash:Fe,parsePublicKey(e){if(e.length===32)return jr(It(e));if(e.length===33)return gt.fromBytes(e);throw new Error(`expected x-only or compressed public key, got length=${e.length}`)},adjustScalar(e){let t=gt.BASE.multiply(e);return ue(t.y)?e:gt.Fn.neg(e)},adjustPoint:e=>ue(e.y)?e:e.negate(),challenge(e,t,n){return $o(zn(e),zn(t),n)},adjustNonces:Hu,adjustGroupCommitmentShare:(e,t)=>ue(e.y)?t:t.negate(),adjustPublic:Zo,adjustSecret:ac,adjustTx:{encode:e=>e.subarray(1),decode:e=>ft(Uint8Array.of(2),e)},adjustDKG:e=>{let t=new Uint8Array(0);return{public:hc(e.public,t),secret:lc(e.secret,e.public,t)}}})});function Wo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function qu(e,t=""){if(typeof e!="boolean")throw new TypeError(Hr(t)+"expected boolean, got type="+typeof e);return e}function Zn(e,t=""){if(typeof e!="number")throw new TypeError(Hr(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Hr(t)+"expected integer >= 0, got "+e);return e}function Y(e,t,n=""){if(Wo(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Zn(t,"length");let r=Wo(e),o=t!==void 0?` of length ${t}`:"",i=r?`length=${e.length}`:`type=${typeof e}`,s=Hr(n)+"expected Uint8Array"+o+", got "+i;throw r?new RangeError(s):new TypeError(s)}function He(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Mu(e,t){Y(e,void 0,"output");let n=t.outputLen;if(!(e.length>=n))throw new RangeError('"output" expected length >= '+n)}function Yn(e,t){if(Mu(e,t),!_t(e))throw new Error("invalid output, must be aligned")}function Pr(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function W(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Q(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function An(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function rn(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Ku(e){for(let t=0;t<e.length;t++)e[t]=rn(e[t]);return e}function Go(e,t){return!e.byteLength||!t.byteLength?!1:e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function qr(e,t){if(Go(e,t)&&e.byteOffset<t.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Xo(...e){let t=0;for(let r=0;r<e.length;r++){let o=e[r];Y(o),t+=o.length}let n=new Uint8Array(t);for(let r=0,o=0;r<e.length;r++){let i=e[r];n.set(i,o),o+=i.length}return n}function Vn(e,t){if(e=Y(e),t=Y(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function Wn(e,t,n){let r=t,o=n||(()=>[]),i=(u,c)=>r(c,...o(u)).update(u).digest(),s=r(new Uint8Array(e),...o(new Uint8Array(0)));return i.outputLen=s.outputLen,i.blockLen=s.blockLen,i.create=(u,...c)=>r(u,...c),i}function vn(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(Y(t,e,"output"),n&&!_t(t))throw new Error("invalid output, must be aligned");return t}function dc(e,t,n){Zn(e),Zn(t),qu(n);let r=new Uint8Array(16),o=An(r);return o.setBigUint64(0,BigInt(t),n),o.setBigUint64(8,BigInt(e),n),r}function _t(e){return e.byteOffset%4===0}function mt(e){return Uint8Array.from(Y(e))}var Hr,Ct,V,G,ae,Qo=Ot(()=>{C();Hr=e=>e?`"${e}" `:"";Ct=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;V=Ct?e=>e:e=>rn(e)>>>0;G=Ct?e=>e:Ku;ae=(e,t)=>{function n(r,...o){if(Y(r,void 0,"key"),e.nonceLength!==void 0){let l=o[0];Y(l,e.varSizeNonce?void 0:e.nonceLength,"nonce")}let i=e.tagLength,s=e.nonceLength!==void 0?1:0;if(!e.withAAD){for(let l=s;l<o.length;l++)if(Wo(o[l]))throw new Error("AAD not supported")}e.withAAD&&o[s]!==void 0&&Y(o[s],void 0,"AAD");let u=t(r,...o),c=(l,f)=>{if(f!==void 0){if(l!==2)throw new Error("cipher output not supported");Y(f,void 0,"output")}},a=!1;return{encrypt(l,f){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,Y(l,void 0,"data"),c(u.encrypt.length,f),u.encrypt(l,f)},decrypt(l,f){if(Y(l,void 0,"data"),i&&l.length<i)throw new Error('"ciphertext" expected length >= tagLength='+i);return c(u.decrypt.length,f),u.decrypt(l,f)}}}return Object.assign(n,e),n}});function Zu(e){e.reverse();let t=e[15]&1,n=0;for(let r=0;r<e.length;r++){let o=e[r];e[r]=o>>>1|n,n=(o&1)<<7}return e[0]^=-t&225,e}var le,ti,he,$u,zu,Gn,Pe,Yu,Mr,Jo,ei,pc,gc=Ot(()=>{C();Qo();le=16,ti=new Uint8Array(16),he=W(ti),$u=225,zu=(e,t,n,r)=>{let o=r&1;return{s3:n<<31|r>>>1,s2:t<<31|n>>>1,s1:e<<31|t>>>1,s0:e>>>1^$u<<24&-(o&1)}},Gn=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255|0,Pe=e=>V(Gn(e));Yu=e=>e>64*1024?8:e>1024?4:2,Mr=class{constructor(t,n){S(this,"blockLen",le);S(this,"outputLen",le);S(this,"s0",0);S(this,"s1",0);S(this,"s2",0);S(this,"s3",0);S(this,"finished",!1);S(this,"destroyed",!1);S(this,"t");S(this,"W");S(this,"windowSize");Y(t,16,"key"),t=mt(t);let r=An(t),o=r.getUint32(0,!1),i=r.getUint32(4,!1),s=r.getUint32(8,!1),u=r.getUint32(12,!1),c=[];for(let g=0;g<128;g++)c.push({s0:Gn(o),s1:Gn(i),s2:Gn(s),s3:Gn(u)}),{s0:o,s1:i,s2:s,s3:u}=zu(o,i,s,u);let a=Yu(n||1024);if(![1,2,4,8].includes(a))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=a;let l=128/a,f=this.windowSize=2**a,d=[];for(let g=0;g<l;g++)for(let y=0;y<f;y++){let m=0,w=0,T=0,F=0;for(let B=0;B<a;B++){if(!(y>>>a-B-1&1))continue;let{s0:K,s1:$,s2:yt,s3:nt}=c[a*g+B];m^=K,w^=$,T^=yt,F^=nt}d.push({s0:m,s1:w,s2:T,s3:F})}this.t=d}_updateBlock(t,n,r,o){t^=this.s0,n^=this.s1,r^=this.s2,o^=this.s3;let{W:i,t:s,windowSize:u}=this,c=0,a=0,h=0,l=0,f=(1<<i)-1,d=0;for(let g of[t,n,r,o])for(let y=0;y<4;y++){let m=g>>>8*y&255;for(let w=8/i-1;w>=0;w--){let T=m>>>i*w&f,{s0:F,s1:B,s2:L,s3:K}=s[d*u+T];c^=F,a^=B,h^=L,l^=K,d+=1}}this.s0=c,this.s1=a,this.s2=h,this.s3=l}update(t){He(this),Y(t),t=mt(t);let n=W(t),r=Math.floor(t.length/le),o=t.length%le;for(let i=0;i<r;i++)this._updateBlock(V(n[i*4+0]),V(n[i*4+1]),V(n[i*4+2]),V(n[i*4+3]));return o&&(ti.set(t.subarray(r*le)),this._updateBlock(V(he[0]),V(he[1]),V(he[2]),V(he[3])),Q(he)),this}destroy(){this.destroyed=!0;let{t}=this;for(let n of t)n.s0=0,n.s1=0,n.s2=0,n.s3=0}digestInto(t){He(this),Yn(t,this),this.finished=!0;let{s0:n,s1:r,s2:o,s3:i}=this,s=W(t);s[0]=n,s[1]=r,s[2]=o,s[3]=i,Ct||G(s.subarray(0,le/4))}digest(){let t=new Uint8Array(le);return this.digestInto(t),this.destroy(),t}},Jo=class extends Mr{constructor(t,n){Y(t);let r=Zu(mt(t));super(r,n),Q(r)}update(t){He(this),Y(t),t=mt(t);let n=W(t),r=t.length%le,o=Math.floor(t.length/le);for(let i=0;i<o;i++)this._updateBlock(Pe(n[i*4+3]),Pe(n[i*4+2]),Pe(n[i*4+1]),Pe(n[i*4+0]));return r&&(ti.set(t.subarray(o*le)),this._updateBlock(Pe(he[3]),Pe(he[2]),Pe(he[1]),Pe(he[0])),Q(he)),this}digestInto(t){He(this),Yn(t,this),this.finished=!0;let n=t.subarray(0,this.outputLen),{s0:r,s1:o,s2:i,s3:s}=this,u=W(n);u[0]=r,u[1]=o,u[2]=i,u[3]=s,G(u),n.reverse()}},ei=Wn(16,(e,t)=>new Mr(e,t),e=>[e.length]),pc=Wn(16,(e,t)=>new Jo(e,t),e=>[e.length])});var ai={};fr(ai,{__TESTS:()=>la,aeskw:()=>oa,aeskwp:()=>ia,aessiv:()=>ua,cbc:()=>ta,cfb:()=>ea,cmac:()=>Qn,ctr:()=>On,ecb:()=>Ju,gcm:()=>na,gcmsiv:()=>ra,rngAesCtrDrbg128:()=>sa,rngAesCtrDrbg256:()=>ca,siv:()=>fa,unsafe:()=>aa});function Zr(e){if(![16,24,32].includes(e.length))throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length='+e.length)}function fi(e){return e<<1^Wu&-(e>>7)}function Tn(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=fi(e);return n}function wc(e,t){if(e.length!==256)throw new Error("wrong sbox length");let n=new Uint32Array(256).map((a,h)=>t(e[h])),r=n.map(ni),o=r.map(ni),i=o.map(ni),s=new Uint32Array(256*256),u=new Uint32Array(256*256),c=new Uint16Array(256*256);for(let a=0;a<256;a++)for(let h=0;h<256;h++){let l=a*256+h;s[l]=n[a]^r[h],u[l]=o[a]^i[h],c[l]=e[a]<<8|e[h]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:u}}function Gt(e){Y(e);let t=e.length;Zr(e);let{sbox2:n}=ui,r=[];(!Ct||!_t(e))&&r.push(e=mt(e));let o=G(W(e)),i=o.length,s=c=>de(n,c,c,c,c),u=new Uint32Array(t+28);u.set(o);for(let c=i;c<u.length;c++){let a=u[c-1];c%i===0?a=s(Xu(a))^Qu[c/i-1]:i>6&&c%i===4&&(a=s(a)),u[c]=u[c-i]^a}return Q(...r),u}function Yr(e){let t=Gt(e),n=t.slice(),r=t.length,{sbox2:o}=ui,{T0:i,T1:s,T2:u,T3:c}=xc;for(let a=0;a<r;a+=4)for(let h=0;h<4;h++)n[a+h]=t[r-a-4+h];Q(t);for(let a=4;a<r-4;a++){let h=n[a],l=de(o,h,h,h,h);n[a]=i[l&255]^s[l>>>8&255]^u[l>>>16&255]^c[l>>>24]}return n}function qe(e,t,n,r,o,i){return e[n<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function de(e,t,n,r,o){return e[t&255|n&65280]|e[r>>>16&255|o>>>16&65280]<<16}function kt(e,t,n,r,o){let{sbox2:i,T01:s,T23:u}=ui,c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];let a=e.length/4-2;for(let g=0;g<a;g++){let y=e[c++]^qe(s,u,t,n,r,o),m=e[c++]^qe(s,u,n,r,o,t),w=e[c++]^qe(s,u,r,o,t,n),T=e[c++]^qe(s,u,o,t,n,r);t=y,n=m,r=w,o=T}let h=e[c++]^de(i,t,n,r,o),l=e[c++]^de(i,n,r,o,t),f=e[c++]^de(i,r,o,t,n),d=e[c++]^de(i,o,t,n,r);return{s0:h,s1:l,s2:f,s3:d}}function tr(e,t,n,r,o){let{sbox2:i,T01:s,T23:u}=xc,c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];let a=e.length/4-2;for(let g=0;g<a;g++){let y=e[c++]^qe(s,u,t,o,r,n),m=e[c++]^qe(s,u,n,t,o,r),w=e[c++]^qe(s,u,r,n,t,o),T=e[c++]^qe(s,u,o,r,n,t);t=y,n=m,r=w,o=T}let h=e[c++]^de(i,t,o,r,n),l=e[c++]^de(i,n,t,o,r),f=e[c++]^de(i,r,n,t,o),d=e[c++]^de(i,o,r,n,t);return{s0:h,s1:l,s2:f,s3:d}}function bc(e,t,n,r){Y(t,et,"nonce"),Y(n);let o=n.length;r=vn(o,r),qr(n,r);let i=t,s=W(i),u=W(n),c=W(r);for(let h=0;h+4<=u.length;h+=4){let{s0:l,s1:f,s2:d,s3:g}=kt(e,V(s[0]),V(s[1]),V(s[2]),V(s[3]));c[h+0]=u[h+0]^V(l),c[h+1]=u[h+1]^V(f),c[h+2]=u[h+2]^V(d),c[h+3]=u[h+3]^V(g);for(let y=et-1,m=1;y>=0;y--)m=m+i[y]|0,i[y]=m&255,m>>>=8}let a=et*Math.floor(u.length/ci);if(a<o){let{s0:h,s1:l,s2:f,s3:d}=kt(e,V(s[0]),V(s[1]),V(s[2]),V(s[3])),g=new Uint32Array([h,l,f,d]);G(g);let y=Pr(g);for(let m=a,w=0;m<o;m++,w++)r[m]=n[m]^y[w];Q(g)}return r}function In(e,t,n,r,o){Y(n,et,"nonce"),Y(r),o=vn(r.length,o);let i=n,s=W(i),u=An(i),c=W(r),a=W(o),h=t?0:12,l=r.length,f=u.getUint32(h,t);for(let g=0;g+4<=c.length;g+=4){let{s0:y,s1:m,s2:w,s3:T}=kt(e,V(s[0]),V(s[1]),V(s[2]),V(s[3]));a[g+0]=c[g+0]^V(y),a[g+1]=c[g+1]^V(m),a[g+2]=c[g+2]^V(w),a[g+3]=c[g+3]^V(T),f=f+1>>>0,u.setUint32(h,f,t)}let d=et*Math.floor(c.length/ci);if(d<l){let{s0:g,s1:y,s2:m,s3:w}=kt(e,V(s[0]),V(s[1]),V(s[2]),V(s[3])),T=new Uint32Array([g,y,m,w]);G(T);let F=Pr(T);for(let B=d,L=0;B<l;B++,L++)o[B]=r[B]^F[L];Q(T)}return o}function Ec(e,t){if(Y(e),e.length%et!==0)throw new Error("ciphertext must be multiple of "+et);t!==void 0&&(vn(e.length,t),qr(e,t))}function Bc(e,t,n){Y(e);let r=e.length,o=r%et;if(!t&&o!==0)throw new Error("plaintext must be multiple of "+et);if(t){let i=et-o;i||(i=et),r=r+i}return n!==void 0&&(vn(r,n),qr(e,n)),r}function Sc(e,t,n){n===void 0&&(n=new Uint8Array(t)),(!Ct||!_t(e))&&(e=mt(e));let r=W(n);return{b:e,o:r,out:n}}function Ac(e,t){if(!t)return e;let n=e.length;if(n===0)throw new Error("pkcs7: empty ciphertext not allowed");let r=e[n-1],o=1;o&=r-1>>>31^1,o&=16-r>>>31^1;for(let i=0;i<16;i++){let s=i-r>>>31,u=(e[n-1-i]^r)===0?1:0;o&=u|s^1}if(!o)throw new Error("aes: bad decrypt");return e.subarray(0,n-r)}function vc(e){let t=new Uint8Array(16),n=W(t);t.set(e);let r=et-e.length;for(let o=et-r;o<et;o++)t[o]=r;return n}function Tc(e,t,n,r,o){let i=o?o.length:0,s=e.create(n,r.length+i);o&&s.update(o);let u=dc(8*r.length,8*i,t);s.update(r),s.update(u);let c=s.digest();return Q(u),c}function Ic(e){return e instanceof Uint32Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint32Array"}function $r(e,t){if(Y(t,16,"block"),!Ic(e))throw new Error("_encryptBlock accepts result of expandKeyLE");let n=W(t);G(n);let{s0:r,s1:o,s2:i,s3:s}=kt(e,n[0],n[1],n[2],n[3]);return n[0]=r,n[1]=o,n[2]=i,n[3]=s,G(n),t}function Rc(e,t){if(Y(t,16,"block"),!Ic(e))throw new Error("_decryptBlock accepts result of expandKeyLE");let n=W(t);G(n);let{s0:r,s1:o,s2:i,s3:s}=tr(e,n[0],n[1],n[2],n[3]);return n[0]=r,n[1]=o,n[2]=i,n[3]=s,G(n),t}function Jn(e){let t=0;for(let n=et-1;n>=0;n--){let r=(e[n]&128)>>>7;e[n]=e[n]<<1|t,t=r}return e[et-1]^=135&-t,e}function Un(e,t){if(e.length!==t.length)throw new Error("xorBlock: blocks must have same length");for(let n=0;n<e.length;n++)e[n]=e[n]^t[n];return e}function Uc(e,t){if(t.length>e.length)throw new Error("xorend: expected len(B) <= len(A)");let n=e.length-t.length;for(let r=0;r<t.length;r++)e[n+r]=e[n+r]^t[r];return e}function si(e,t){Zr(e);let n=t.length;if(n>127)throw new Error("s2v: expected <= 127 inputs");if(n===0)return Qn(Vu,e);let r=Qn(Xn,e);for(let u=0;u<n-1;u++){Jn(r);let c=Qn(t[u],e);Un(r,c),Q(c)}let o=t[n-1];Y(o);let i;if(o.byteLength>=et)i=Uc(Uint8Array.from(o),r);else{let u=new Uint8Array(et);u.set(o),u[o.length]=128,i=Un(Jn(r),u),Q(u)}let s=Qn(i,e);return Q(r,i),s}var et,ci,Xn,Vu,Wu,Kr,ri,Gu,Xu,ni,ui,xc,Qu,On,Ju,ta,ea,na,Rn,ra,zr,yc,oa,mc,ia,oi,Oc,sa,ca,ii,Qn,fa,ua,aa,la,li=Ot(()=>{C();gc();Qo();et=16,ci=4,Xn=new Uint8Array(et),Vu=Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]),Wu=283;Kr=(e,t,n=1)=>{if(!Number.isSafeInteger(n)||n<0||n>4294967040)throw new Error("incBytes: wrong carry "+n);Y(e);for(let r=0;r<e.length;r++){let o=t?r:e.length-1-r;n=n+(e[o]&255)|0,e[o]=n&255,n>>>=8}},ri=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=fi(r))e[n]=r;let t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return Q(e),t})(),Gu=ri.map((e,t)=>ri.indexOf(t)),Xu=e=>e<<24|e>>>8,ni=e=>e<<8|e>>>24;ui=wc(ri,e=>Tn(e,3)<<24|e<<16|e<<8|Tn(e,2)),xc=wc(Gu,e=>Tn(e,11)<<24|Tn(e,13)<<16|Tn(e,9)<<8|Tn(e,14)),Qu=(()=>{let e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=fi(n))e[t]=n;return e})();On=ae({blockSize:16,nonceLength:16},function(t,n){function r(o,i){if(Y(o),i!==void 0&&(Y(i),!_t(i)))throw new Error("unaligned destination");let s=Gt(t),u=mt(n),c=[s,u];_t(o)||c.push(o=mt(o));let a=bc(s,u,o,i);return Q(...c),a}return{encrypt:(o,i)=>r(o,i),decrypt:(o,i)=>r(o,i)}});Ju=ae({blockSize:16},function(t,n={}){let r=!n.disablePadding;return{encrypt(o,i){let s=Bc(o,r,i),u=Gt(t),{b:c,o:a,out:h}=Sc(o,s,i),l=W(c);G(l);let f=0;for(;f+4<=l.length;){let{s0:d,s1:g,s2:y,s3:m}=kt(u,l[f+0],l[f+1],l[f+2],l[f+3]);a[f++]=d,a[f++]=g,a[f++]=y,a[f++]=m}if(r){let d=vc(o.subarray(f*4));G(d);let{s0:g,s1:y,s2:m,s3:w}=kt(u,d[0],d[1],d[2],d[3]);a[f++]=g,a[f++]=y,a[f++]=m,a[f++]=w,Q(d)}return G(a),Q(u),c!==o&&Q(c),h},decrypt(o,i){Ec(o,i);let s=Yr(t);i===void 0&&(i=new Uint8Array(o.length));let u=[s];(!Ct||!_t(o))&&u.push(o=mt(o));let c=W(o),a=W(i);G(c);for(let h=0;h+4<=c.length;){let{s0:l,s1:f,s2:d,s3:g}=tr(s,c[h+0],c[h+1],c[h+2],c[h+3]);a[h++]=l,a[h++]=f,a[h++]=d,a[h++]=g}return G(a),Q(...u),Ac(i,r)}}}),ta=ae({blockSize:16,nonceLength:16},function(t,n,r={}){let o=!r.disablePadding;return{encrypt(i,s){let u=Bc(i,o,s),c=Gt(t),{b:a,o:h,out:l}=Sc(i,u,s),f=W(a);G(f);let d=n,g=[c];(!Ct||!_t(d))&&g.push(d=mt(d));let y=W(d);G(y);let m=y[0],w=y[1],T=y[2],F=y[3],B=0;for(;B+4<=f.length;)m^=f[B+0],w^=f[B+1],T^=f[B+2],F^=f[B+3],{s0:m,s1:w,s2:T,s3:F}=kt(c,m,w,T,F),h[B++]=m,h[B++]=w,h[B++]=T,h[B++]=F;if(o){let L=vc(i.subarray(B*4));G(L),m^=L[0],w^=L[1],T^=L[2],F^=L[3],{s0:m,s1:w,s2:T,s3:F}=kt(c,m,w,T,F),h[B++]=m,h[B++]=w,h[B++]=T,h[B++]=F,Q(L)}return G(h),Q(...g),a!==i&&Q(a),l},decrypt(i,s){Ec(i,s);let u=Yr(t);s===void 0&&(s=new Uint8Array(i.length));let c=n,a=[u];(!Ct||!_t(c))&&a.push(c=mt(c));let h=W(c);G(h),(!Ct||!_t(i))&&a.push(i=mt(i));let l=W(i),f=W(s);G(l);let d=h[0],g=h[1],y=h[2],m=h[3];for(let w=0;w+4<=l.length;){let T=d,F=g,B=y,L=m;d=l[w+0],g=l[w+1],y=l[w+2],m=l[w+3];let{s0:K,s1:$,s2:yt,s3:nt}=tr(u,d,g,y,m);f[w++]=K^T,f[w++]=$^F,f[w++]=yt^B,f[w++]=nt^L}return G(f),Q(...a),Ac(s,o)}}}),ea=ae({blockSize:16,nonceLength:16},function(t,n){function r(o,i,s){Y(o);let u=o.length;if(s=vn(u,s),Go(o,s))throw new Error("overlapping src and dst not supported");let c=Gt(t),a=n,h=[c];(!Ct||!_t(a))&&h.push(a=mt(a)),(!Ct||!_t(o))&&h.push(o=mt(o));let l=W(o),f=W(s),d=i?f:l,g=W(a);G(l),G(g);let y=g[0],m=g[1],w=g[2],T=g[3];for(let B=0;B+4<=l.length;){let{s0:L,s1:K,s2:$,s3:yt}=kt(c,y,m,w,T);f[B+0]=l[B+0]^L,f[B+1]=l[B+1]^K,f[B+2]=l[B+2]^$,f[B+3]=l[B+3]^yt,y=d[B++],m=d[B++],w=d[B++],T=d[B++]}let F=et*Math.floor(l.length/ci);if(F<u){Ct||G(l.subarray(F/4)),{s0:y,s1:m,s2:w,s3:T}=kt(c,y,m,w,T);let B=new Uint32Array([y,m,w,T]);G(B);let L=Pr(B);for(let K=F,$=0;K<u;K++,$++)s[K]=o[K]^L[$];Q(L)}return Ct||G(f.subarray(0,F/4)),Q(...h),s}return{encrypt:(o,i)=>r(o,!0,i),decrypt:(o,i)=>r(o,!1,i)}});na=ae({blockSize:16,nonceLength:12,tagLength:16,withAAD:!0,varSizeNonce:!0},function(t,n,r){if(n.length<8)throw new Error("aes/gcm: invalid nonce length");let o=16;function i(u,c,a){let h=Tc(ei,!1,u,a,r);for(let l=0;l<c.length;l++)h[l]^=c[l];return h}function s(){let u=Gt(t),c=Xn.slice(),a=Xn.slice();if(In(u,!1,a,a,c),n.length===12)a.set(n);else{let l=Xn.slice();An(l).setBigUint64(8,BigInt(n.length*8),!1);let d=ei.create(c).update(n).update(l);d.digestInto(a),d.destroy()}let h=In(u,!1,a,Xn);return{xk:u,authKey:c,counter:a,tagMask:h}}return{encrypt(u){let{xk:c,authKey:a,counter:h,tagMask:l}=s(),f=new Uint8Array(u.length+o),d=[c,a,h,l];_t(u)||d.push(u=mt(u)),In(c,!1,h,u,f.subarray(0,u.length));let g=i(a,l,f.subarray(0,f.length-o));return d.push(g),f.set(g,u.length),Q(...d),f},decrypt(u){let{xk:c,authKey:a,counter:h,tagMask:l}=s(),f=[c,a,l,h];_t(u)||f.push(u=mt(u));let d=u.subarray(0,-o),g=u.subarray(-o),y=i(a,l,d);if(f.push(y),!Vn(y,g))throw Q(...f),new Error("aes-gcm: invalid tag");let m=In(c,!1,h,d);return Q(...f),m}}}),Rn=(e,t,n)=>r=>{if(!Number.isSafeInteger(r)||t>r||r>n){let o="["+t+".."+n+"]";throw new Error(""+e+": expected value in range "+o+", got "+r)}},ra=ae({blockSize:16,nonceLength:12,tagLength:16,withAAD:!0,varSizeNonce:!0},function(t,n,r){let i=Rn("AAD",0,68719476736),s=Rn("plaintext",0,2**36),u=Rn("nonce",12,12),c=Rn("ciphertext",16,2**36+16);Y(t),Zr(t),u(n.length),r!==void 0&&i(r.length);function a(){let f=Gt(t),d=new Uint8Array(t.length),g=new Uint8Array(16),y=[f,d],m=n;(!Ct||!_t(m))&&y.push(m=mt(m));let w=W(m);G(w);let T=0,F=w[0],B=w[1],L=w[2],K=0;for(let yt of[g,d].map(W)){let nt=W(yt);for(let rt=0;rt<nt.length;rt+=2){let{s0:qt,s1:Nt}=kt(f,T,F,B,L);nt[rt+0]=qt,nt[rt+1]=Nt,T=++K}G(nt)}let $={authKey:g,encKey:Gt(d)};return Q(...y),$}function h(f,d,g){let y=Tc(pc,!0,d,g,r);for(let L=0;L<12;L++)y[L]^=n[L];y[15]&=127;let m=W(y);G(m);let w=m[0],T=m[1],F=m[2],B=m[3];return{s0:w,s1:T,s2:F,s3:B}=kt(f,w,T,F,B),m[0]=w,m[1]=T,m[2]=F,m[3]=B,G(m),y}function l(f,d,g){let y=mt(d);y[15]|=128;let m=In(f,!0,y,g);return Q(y),m}return{encrypt(f){s(f.length);let{encKey:d,authKey:g}=a(),y=h(d,g,f),m=[d,g,y];_t(f)||m.push(f=mt(f));let w=new Uint8Array(f.length+16);return w.set(y,f.length),w.set(l(d,y,f)),Q(...m),w},decrypt(f){c(f.length);let d=f.subarray(-16),{encKey:g,authKey:y}=a(),m=[g,y];_t(f)||m.push(f=mt(f));let w=l(g,d,f.subarray(0,-16)),T=h(g,y,w);if(m.push(T),!Vn(d,T))throw Q(w,...m),new Error("invalid polyval tag");return Q(...m),w}}});zr={encrypt(e,t){if(t.length>=2**32)throw new Error("plaintext should be less than 4gb");let n=Gt(e);if(t.length===16)$r(n,t);else{let r=W(t);G(r);let o=r[0],i=r[1];for(let s=0,u=1;s<6;s++)for(let c=2;c<r.length;c+=2,u++){let{s0:a,s1:h,s2:l,s3:f}=kt(n,o,i,r[c],r[c+1]);o=a,i=h^rn(u),r[c]=l,r[c+1]=f}r[0]=o,r[1]=i,G(r)}n.fill(0)},decrypt(e,t){if(t.length-8>=2**32)throw new Error("ciphertext should be less than 4gb");let n=Yr(e),r=t.length/8-1;if(r===1)Rc(n,t);else{let o=W(t);G(o);let i=o[0],s=o[1];for(let u=0,c=r*6;u<6;u++)for(let a=r*2;a>=1;a-=2,c--){s^=rn(c);let{s0:h,s1:l,s2:f,s3:d}=tr(n,i,s,o[a],o[a+1]);i=h,s=l,o[a]=f,o[a+1]=d}o[0]=i,o[1]=s,G(o)}n.fill(0)}},yc=new Uint8Array(8).fill(166),oa=ae({blockSize:8},e=>({encrypt(t){if(!t.length||t.length%8!==0)throw new Error("invalid plaintext length");if(t.length===8)throw new Error("8-byte keys not allowed, use AESKWP");let n=Xo(yc,t);return zr.encrypt(e,n),n},decrypt(t){if(t.length%8!==0||t.length<24)throw new Error("invalid ciphertext length");let n=mt(t);if(zr.decrypt(e,n),!Vn(n.subarray(0,8),yc))throw new Error("integrity check failed");return n.subarray(0,8).fill(0),n.subarray(8)}})),mc=2790873510,ia=ae({blockSize:8},e=>({encrypt(t){if(!t.length)throw new Error("invalid plaintext length");let n=Math.ceil(t.length/8)*8,r=new Uint8Array(8+n);r.set(t,8);let o=W(r);return o[0]=V(mc),o[1]=V(rn(t.length)),zr.encrypt(e,r),r},decrypt(t){if(t.length<16)throw new Error("invalid ciphertext length");let n=mt(t),r=W(n);zr.decrypt(e,n);let o=rn(V(r[1]))>>>0,i=Math.ceil(o/8)*8;if(V(r[0])!==mc||n.length-8!==i)throw new Error("integrity check failed");for(let s=o;s<i;s++)if(n[8+s]!==0)throw new Error("integrity check failed");return n.subarray(0,8).fill(0),n.subarray(8,8+o)}})),oi=class{constructor(t,n,r){S(this,"blockLen");S(this,"key");S(this,"nonce");S(this,"state");S(this,"reseedCnt");S(this,"destroyed",!1);this.blockLen=On.blockSize;let o=t/8,i=16;this.state=new Uint8Array(o+i),this.key=this.state.subarray(0,o),this.nonce=this.state.subarray(o,o+i),this.reseedCnt=1,Kr(this.nonce,!1,1),this.addEntropy(n,r)}update(t){if(On(this.key,this.nonce).encrypt(new Uint8Array(this.state.length),this.state),t){Y(t);for(let n=0;n<t.length;n++)this.state[n]^=t[n]}Kr(this.nonce,!1,1)}addEntropy(t,n){if(this.destroyed)throw new Error("cannot use destroyed DRBG");Y(t,this.state.length,"seed");let r=t.slice();if(n){if(Y(n),n.length>r.length)throw new Error("info length is too big");for(let o=0;o<n.length;o++)r[o]^=n[o]}this.update(r),r.fill(0),this.reseedCnt=1}randomBytes(t,n){if(this.destroyed)throw new Error("cannot use destroyed DRBG");if(Zn(t),t>2**16)throw new Error("requested output is too big");if(this.reseedCnt>2**48)throw new Error("entropy exhausted");if(n){if(Y(n),n.length>this.state.length)throw new Error("info length is too big");this.update(n)}let r=new Uint8Array(t);return On(this.key,this.nonce).encrypt(r,r),Kr(this.nonce,!1,Math.ceil(t/this.blockLen)),this.update(n),this.reseedCnt++,r}clean(){this.state.fill(0),this.reseedCnt=0,this.destroyed=!0}},Oc=e=>(t,n=void 0)=>new oi(e,t,n),sa=Oc(128),ca=Oc(256);ii=class{constructor(t){S(this,"blockLen",et);S(this,"outputLen",et);S(this,"buffer");S(this,"pos");S(this,"finished");S(this,"destroyed");S(this,"k1");S(this,"k2");S(this,"x");S(this,"x32");S(this,"xk");Y(t),Zr(t),this.xk=Gt(t),this.buffer=new Uint8Array(et),this.pos=0,this.finished=!1,this.destroyed=!1,this.x=new Uint8Array(et),this.x32=W(this.x);let n=new Uint8Array(et);$r(this.xk,n),this.k1=Jn(n),this.k2=Jn(new Uint8Array(this.k1))}process(t,n){let{x:r,x32:o,xk:i}=this;for(let h=0;h<et;h++)r[h]^=t[n+h];G(o);let{s0:s,s1:u,s2:c,s3:a}=kt(i,o[0],o[1],o[2],o[3]);o[0]=s,o[1]=u,o[2]=c,o[3]=a,G(o)}update(t){He(this),Y(t);let n=0;if(this.pos){let r=Math.min(et-this.pos,t.length);this.buffer.set(t.subarray(0,r),this.pos),this.pos+=r,n=r,this.pos===et&&n<t.length&&(this.process(this.buffer,0),this.pos=0)}for(;n+et<t.length;)this.process(t,n),n+=et;return n<t.length&&(this.buffer.set(t.subarray(n),0),this.pos=t.length-n),this}digestInto(t){He(this),Yn(t,this),this.finished=!0;let n=t.subarray(0,this.outputLen),r=new Uint8Array(et);this.pos===et?(r.set(this.buffer),Un(r,this.k1)):(r.set(this.buffer.subarray(0,this.pos)),r[this.pos]=128,Un(r,this.k2)),n.set(this.x),Un(n,r),$r(this.xk,n),Q(r)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}destroy(){let{buffer:t,destroyed:n,x:r,xk:o,k1:i,k2:s}=this;n||(this.destroyed=!0,Q(t,r,o,i,s))}},Qn=Wn(16,e=>new ii(e));fa=()=>{throw new Error('"siv" from v1 is now "gcmsiv"')},ua=ae({blockSize:16,tagLength:16,withAAD:!0},function(t,...n){let r=Rn("plaintext",0,5444517870735016e24),o=Rn("ciphertext",16,2**132+16);if(n.length>126)throw new Error('"AAD" expected <= 126 items');if(n.forEach(u=>Y(u)),Y(t),![32,48,64].includes(t.length))throw new Error('"aes key" expected Uint8Array of length 32/48/64, got length='+t.length);let i=t.subarray(0,t.length/2),s=t.subarray(t.length/2);return{encrypt(u){r(u.length);let c=si(i,[...n,u]),a=Uint8Array.from(c);a[8]&=127,a[12]&=127;let h=On(s,a).encrypt(u);return Xo(c,h)},decrypt(u){o(u.length);let c=u.subarray(0,et),a=u.subarray(et),h=Uint8Array.from(c);h[8]&=127,h[12]&=127;let l=On(s,h).decrypt(a),f=si(i,[...n,l]);if(Vn(f,c))return l;throw Q(l),new Error("invalid siv tag")}}}),aa=Object.freeze({expandKeyLE:Gt,expandKeyDecLE:Yr,encrypt:kt,decrypt:tr,encryptBlock:$r,decryptBlock:Rc,ctrCounter:bc,ctr32:In,dbl:Jn,xorBlock:Un,xorend:Uc,s2v:si}),la=Object.freeze({incBytes:Kr})});var Fc=Ht((sh,_c)=>{C();_c.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.crypto.Random});var Nc=Ht((fh,kc)=>{"use strict";C();var{secp256k1:Lc}=(Vo(),ve(Yo)),{sha512:ha,sha256:da}=(Tr(),ve(xo)),{hmac:pa}=(kr(),ve(jo)),{cbc:Cc}=(li(),ve(ai)),ga=lo(),Me=ho(),ya=Fc();function er(e){return P.Buffer.from(e.buffer,e.byteOffset,e.byteLength)}function hi(e,t){return er(pa(da,e,t))}function ma(e,t){if(e.length!==t.length)return!1;for(var n=0,r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}var Vr=function(){};Vr.encrypt=function(e,t,n){Me.checkArgument(e),Me.checkArgument(t),Me.checkArgument(n),n=n||ya.getRandomBuffer(128/8);var r=Cc(Uint8Array.from(t),Uint8Array.from(n)).encrypt(Uint8Array.from(e));return P.Buffer.concat([P.Buffer.from(n),er(r)])};Vr.decrypt=function(e,t){Me.checkArgument(e),Me.checkArgument(t);var n=e.slice(0,128/8),r=e.slice(128/8),o=Cc(Uint8Array.from(t),Uint8Array.from(n)).decrypt(Uint8Array.from(r));return er(o)};var _n=function e(t){if(!(this instanceof e))return new e(t);this.opts=t||{}};_n.prototype.privateKey=function(e){return Me.checkArgument(e,"no private key provided"),this._privateKey=e||null,this};_n.prototype.publicKey=function(e){return Me.checkArgument(e,"no public key provided"),this._publicKey=e||null,this};var Wr=function(e,t){var n="_"+e;Object.defineProperty(_n.prototype,e,{configurable:!1,enumerable:!0,get:function(){var r=this[n];return r||(r=this[n]=t.apply(this)),r}})};Wr("Rbuf",function(){var e=this._privateKey.bn.toBuffer({size:32});return er(Lc.getPublicKey(Uint8Array.from(e),!0))});Wr("kEkM",function(){var e=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),n=Lc.getSharedSecret(Uint8Array.from(e),Uint8Array.from(t),!0),r=n.slice(1);return er(ha(r))});Wr("kE",function(){return this.kEkM.slice(0,32)});Wr("kM",function(){return this.kEkM.slice(32,64)});_n.prototype.encrypt=function(e,t){P.Buffer.isBuffer(e)||(e=P.Buffer.from(e)),t===void 0&&(t=hi(this._privateKey.toBuffer(),e).slice(0,16));var n=Vr.encrypt(e,this.kE,t),r=hi(this.kM,n);return this.opts.shortTag&&(r=r.slice(0,4)),this.opts.noKey?P.Buffer.concat([n,r]):P.Buffer.concat([this.Rbuf,n,r])};_n.prototype.decrypt=function(e){Me.checkArgument(e);var t=0,n=this.opts.shortTag?4:32;if(!this.opts.noKey){var r;switch(e[0]){case 4:r=e.slice(0,65);break;case 3:case 2:r=e.slice(0,33);break;default:throw new Error("Invalid type: "+e[0])}this._publicKey=ga.fromDER(r),t+=r.length}var o=e.slice(t,e.length-n),i=e.slice(e.length-n,e.length),s=hi(this.kM,o);if(this.opts.shortTag&&(s=s.slice(0,4)),!ma(i,s))throw new Error("Invalid checksum");return Vr.decrypt(o,this.kE)};kc.exports=_n});var jc=Ht((ah,Dc)=>{C();Dc.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.errors});var Pc=Ht((hh,Hc)=>{"use strict";C();var wa={name:"ECIES",message:"Internal Error on bsv-ecies Module {0}",errors:[{name:"DecryptionError",message:"Invalid Message: {0}"},{name:"UnsupportAlgorithm",message:"Unsupport Algorithm: {0}"}]};Hc.exports=jc().extend(wa)});var zc=Ht((ph,$c)=>{"use strict";C();var di=lo(),pi=zi(),$t=ho(),xa=Nc(),Gr=Pc(),{secp256k1:qc}=(Vo(),ve(Yo)),{sha512:ba,sha256:Ea}=(Tr(),ve(xo)),{hmac:Ba}=(kr(),ve(jo)),{cbc:Mc}=(li(),ve(ai));function nr(e){return P.Buffer.from(e.buffer,e.byteOffset,e.byteLength)}function Kc(e,t){return nr(Ba(Ea,t,e))}var Xr=function(){};Xr.encrypt=function(e,t,n){return $t.checkArgument(e),$t.checkArgument(t),$t.checkArgument(n),$t.checkArgument(t.length===16,"keybuf length must be 16"),$t.checkArgument(n.length===16,"ivbuf length must be 16"),nr(Mc(Uint8Array.from(t),Uint8Array.from(n)).encrypt(Uint8Array.from(e)))};Xr.decrypt=function(e,t,n){return $t.checkArgument(e),$t.checkArgument(t),$t.checkArgument(n),$t.checkArgument(t.length===16,"keybuf length must be 16"),$t.checkArgument(n.length===16,"ivbuf length must be 16"),nr(Mc(Uint8Array.from(t),Uint8Array.from(n)).decrypt(Uint8Array.from(e)))};var on=function e(t,n="BIE1"){if(n!=="BIE1")throw new Gr.UnsupportAlgorithm(n);if(!(this instanceof e))return new e(t,n);this._privateKey=new pi,this.opts=t||{},this.opts.ephemeralKey=!0};on.prototype.privateKey=function(e){return $t.checkArgument(pi.isValid(e),"no private key provided"),this._privateKey=pi(e.toHex())||null,this.opts.ephemeralKey=!1,this};on.prototype.publicKey=function(e){return $t.checkArgument(di.isValid(e),"no public key provided"),this._publicKey=di(e.toString())||null,this._publicKey!=null&&(this.opts.fixedPublicKey=!0),this};var rr=function(e,t){var n="_"+e;Object.defineProperty(on.prototype,e,{configurable:!1,enumerable:!0,get:function(){var r=this[n];return r=this[n]=t.apply(this),r}})};rr("Rbuf",function(){var e=this._privateKey.bn.toBuffer({size:32});return nr(qc.getPublicKey(Uint8Array.from(e),!0))});rr("ivkEkM",function(){var e=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),n=qc.getSharedSecret(Uint8Array.from(e),Uint8Array.from(t),!0);return nr(ba(n))});rr("iv",function(){return this.ivkEkM.slice(0,16)});rr("kE",function(){return this.ivkEkM.slice(16,32)});rr("kM",function(){return this.ivkEkM.slice(32,64)});on.prototype.encrypt=function(e){P.Buffer.isBuffer(e)||(e=P.Buffer.from(e));var t=Xr.encrypt(e,this.kE,this.iv),n,r=P.Buffer.from("BIE1");this.opts.noKey&&!this.opts.ephemeralKey?n=P.Buffer.concat([r,t]):n=P.Buffer.concat([r,this.Rbuf,t]);var o=Kc(n,this.kM);return this.opts.shortTag&&(o=o.slice(0,4)),P.Buffer.concat([n,o])};on.prototype.decrypt=function(e){$t.checkArgument(P.Buffer.isBuffer(e),"ciphetext must be a buffer");var t=this.opts.shortTag?4:32,n=4,r=e.slice(0,4);if(!r.equals(P.Buffer.from("BIE1")))throw new Gr.DecryptionError("Invalid Magic");if(!this.opts.noKey){var o=e.slice(4,37);this.opts.fixedPublicKey?console.log('Notice: Overriding PublicKey in message. Consider use "noKey" option if you are not sending message to electrum and do not want to use ephemeral key'):this._publicKey=di.fromDER(o),n=37}var i=e.slice(n,e.length-t),s=e.slice(e.length-t,e.length),u=Kc(e.slice(0,e.length-t),this.kM);if(this.opts.shortTag&&(u=u.slice(0,4)),s.length!==u.length)throw new Gr.DecryptionError("Invalid checksum");for(var c=0,a=0;a<u.length;a++)c|=s[a]^u[a];if(c!==0)throw new Gr.DecryptionError("Invalid checksum");return Xr.decrypt(i,this.kE,this.iv)};on.bitcoreECIES=xa;$c.exports=on});var Yc=Ht((yh,Zc)=>{C();Zc.exports=zc()});var Sa=Ht((wh,Vc)=>{C();Vc.exports=Yc()});return Sa();})();
2
2
  if(typeof module!=="undefined"&&module.exports){module.exports=bsvEcies}else if(typeof define==="function"&&define.amd){define([],function(){return bsvEcies})}