@smartledger/bsv 8.2.0 → 8.3.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/CHANGELOG.md +84 -0
- package/README.md +38 -38
- package/bsv-ecies.min.js +1 -1
- package/bsv-gdaf.min.js +62 -62
- package/bsv-ltp.min.js +48 -48
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +62 -62
- package/bsv.min.js +62 -62
- package/docs/AUDIT_SCOPE.md +8 -8
- package/docs/BRC220_ENCODING_AMENDMENT.md +100 -0
- package/docs/BRC220_PLAN.md +224 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/index.js +5 -0
- package/index.mjs +1 -0
- package/lib/gdaf/attestation-signer.js +2 -38
- package/lib/notaryhash/certificate.js +282 -0
- package/lib/notaryhash/encoding.js +150 -0
- package/lib/notaryhash/index.js +334 -0
- package/lib/notaryhash/merkle.js +209 -0
- package/lib/notaryhash/script.js +261 -0
- package/lib/notaryhash/suites.js +156 -0
- package/lib/util/jcs.js +75 -0
- package/package.json +7 -5
- package/test/notaryhash/certificate.js +249 -0
- package/test/notaryhash/encoding.js +186 -0
- package/test/notaryhash/merkle.js +181 -0
- package/test/notaryhash/script.js +270 -0
- package/test/notaryhash/verify.js +339 -0
- package/version.js +1 -1
package/bsv-ecies.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var bsvEcies=(()=>{var gc=Object.create;var Bn=Object.defineProperty;var mc=Object.getOwnPropertyDescriptor;var yc=Object.getOwnPropertyNames;var wc=Object.getPrototypeOf,xc=Object.prototype.hasOwnProperty;var bc=(n,t,e)=>t in n?Bn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var St=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(r){throw e=[r],r}};var Ct=(n,t)=>()=>{try{return t||n((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},Gn=(n,t)=>{for(var e in t)Bn(n,e,{get:t[e],enumerable:!0})},$o=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of yc(t))!xc.call(n,o)&&o!==e&&Bn(n,o,{get:()=>t[o],enumerable:!(r=mc(t,o))||r.enumerable});return n};var Go=(n,t,e)=>(e=n!=null?gc(wc(n)):{},$o(t||!n||!n.__esModule?Bn(e,"default",{value:n,enumerable:!0}):e,n)),ye=n=>$o(Bn({},"__esModule",{value:!0}),n);var y=(n,t,e)=>bc(n,typeof t!="symbol"?t+"":t,e);var Jo=Ct((Ru,Qo)=>{C();var yt=Qo.exports={},Gt,Yt;function Nr(){throw new Error("setTimeout has not been defined")}function Hr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Gt=setTimeout:Gt=Nr}catch{Gt=Nr}try{typeof clearTimeout=="function"?Yt=clearTimeout:Yt=Hr}catch{Yt=Hr}})();function Yo(n){if(Gt===setTimeout)return setTimeout(n,0);if((Gt===Nr||!Gt)&&setTimeout)return Gt=setTimeout,setTimeout(n,0);try{return Gt(n,0)}catch{try{return Gt.call(null,n,0)}catch{return Gt.call(this,n,0)}}}function Ec(n){if(Yt===clearTimeout)return clearTimeout(n);if((Yt===Hr||!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 se=[],We=!1,Fe,Yn=-1;function Bc(){!We||!Fe||(We=!1,Fe.length?se=Fe.concat(se):Yn=-1,se.length&&Wo())}function Wo(){if(!We){var n=Yo(Bc);We=!0;for(var t=se.length;t;){for(Fe=se,se=[];++Yn<t;)Fe&&Fe[Yn].run();Yn=-1,t=se.length}Fe=null,We=!1,Ec(n)}}yt.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];se.push(new Xo(n,t)),se.length===1&&!We&&Yo(Wo)};function Xo(n,t){this.fun=n,this.array=t}Xo.prototype.run=function(){this.fun.apply(null,this.array)};yt.title="browser";yt.browser=!0;yt.env={};yt.argv=[];yt.version="";yt.versions={};function ce(){}yt.on=ce;yt.addListener=ce;yt.once=ce;yt.off=ce;yt.removeListener=ce;yt.removeAllListeners=ce;yt.emit=ce;yt.prependListener=ce;yt.prependOnceListener=ce;yt.listeners=function(n){return[]};yt.binding=function(n){throw new Error("process.binding is not supported")};yt.cwd=function(){return"/"};yt.chdir=function(n){throw new Error("process.chdir is not supported")};yt.umask=function(){return 0}});var ni=Ct(Wn=>{"use strict";C();Wn.byteLength=Ac;Wn.toByteArray=Ic;Wn.fromByteArray=Uc;var Wt=[],qt=[],Sc=typeof Uint8Array<"u"?Uint8Array:Array,Dr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ue=0,ti=Dr.length;Ue<ti;++Ue)Wt[Ue]=Dr[Ue],qt[Dr.charCodeAt(Ue)]=Ue;var Ue,ti;qt[45]=62;qt[95]=63;function ei(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 Ac(n){var t=ei(n),e=t[0],r=t[1];return(e+r)*3/4-r}function vc(n,t,e){return(t+e)*3/4-e}function Ic(n){var t,e=ei(n),r=e[0],o=e[1],i=new Sc(vc(n,r,o)),s=0,c=o>0?r-4:r,f;for(f=0;f<c;f+=4)t=qt[n.charCodeAt(f)]<<18|qt[n.charCodeAt(f+1)]<<12|qt[n.charCodeAt(f+2)]<<6|qt[n.charCodeAt(f+3)],i[s++]=t>>16&255,i[s++]=t>>8&255,i[s++]=t&255;return o===2&&(t=qt[n.charCodeAt(f)]<<2|qt[n.charCodeAt(f+1)]>>4,i[s++]=t&255),o===1&&(t=qt[n.charCodeAt(f)]<<10|qt[n.charCodeAt(f+1)]<<4|qt[n.charCodeAt(f+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function Tc(n){return Wt[n>>18&63]+Wt[n>>12&63]+Wt[n>>6&63]+Wt[n&63]}function Fc(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(Tc(r));return o.join("")}function Uc(n){for(var t,e=n.length,r=e%3,o=[],i=16383,s=0,c=e-r;s<c;s+=i)o.push(Fc(n,s,s+i>c?c:s+i));return r===1?(t=n[e-1],o.push(Wt[t>>2]+Wt[t<<4&63]+"==")):r===2&&(t=(n[e-2]<<8)+n[e-1],o.push(Wt[t>>10]+Wt[t>>4&63]+Wt[t<<2&63]+"=")),o.join("")}});var ri=Ct(jr=>{C();jr.read=function(n,t,e,r,o){var i,s,c=o*8-r-1,f=(1<<c)-1,l=f>>1,u=-7,a=e?o-1:0,h=e?-1:1,d=n[t+a];for(a+=h,i=d&(1<<-u)-1,d>>=-u,u+=c;u>0;i=i*256+n[t+a],a+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=r;u>0;s=s*256+n[t+a],a+=h,u-=8);if(i===0)i=1-l;else{if(i===f)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,r),i=i-l}return(d?-1:1)*s*Math.pow(2,i-r)};jr.write=function(n,t,e,r,o,i){var s,c,f,l=i*8-o-1,u=(1<<l)-1,a=u>>1,h=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:i-1,p=r?1:-1,m=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-s))<1&&(s--,f*=2),s+a>=1?t+=h/f:t+=h*Math.pow(2,1-a),t*f>=2&&(s++,f/=2),s+a>=u?(c=0,s=u):s+a>=1?(c=(t*f-1)*Math.pow(2,o),s=s+a):(c=t*Math.pow(2,a-1)*Math.pow(2,o),s=0));o>=8;n[e+d]=c&255,d+=p,c/=256,o-=8);for(s=s<<o|c,l+=o;l>0;n[e+d]=s&255,d+=p,s/=256,l-=8);n[e+d-p]|=m*128}});var bi=Ct(tn=>{"use strict";C();var qr=ni(),Qe=ri(),oi=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;tn.Buffer=b;tn.SlowBuffer=kc;tn.INSPECT_MAX_BYTES=50;var Xn=2147483647;tn.kMaxLength=Xn;b.TYPED_ARRAY_SUPPORT=Rc();!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 Rc(){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(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 fe(n){if(n>Xn)throw new RangeError('The value "'+n+'" is invalid for option "size"');let t=new Uint8Array(n);return Object.setPrototypeOf(t,b.prototype),t}function b(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 zr(n)}return fi(n,t,e)}b.poolSize=8192;function fi(n,t,e){if(typeof n=="string")return Oc(n,t);if(ArrayBuffer.isView(n))return Lc(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(Xt(n,ArrayBuffer)||n&&Xt(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Xt(n,SharedArrayBuffer)||n&&Xt(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 b.from(r,t,e);let o=Cc(n);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return b.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)}b.from=function(n,t,e){return fi(n,t,e)};Object.setPrototypeOf(b.prototype,Uint8Array.prototype);Object.setPrototypeOf(b,Uint8Array);function ui(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 _c(n,t,e){return ui(n),n<=0?fe(n):t!==void 0?typeof e=="string"?fe(n).fill(t,e):fe(n).fill(t):fe(n)}b.alloc=function(n,t,e){return _c(n,t,e)};function zr(n){return ui(n),fe(n<0?0:Vr(n)|0)}b.allocUnsafe=function(n){return zr(n)};b.allocUnsafeSlow=function(n){return zr(n)};function Oc(n,t){if((typeof t!="string"||t==="")&&(t="utf8"),!b.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let e=ai(n,t)|0,r=fe(e),o=r.write(n,t);return o!==e&&(r=r.slice(0,o)),r}function Pr(n){let t=n.length<0?0:Vr(n.length)|0,e=fe(t);for(let r=0;r<t;r+=1)e[r]=n[r]&255;return e}function Lc(n){if(Xt(n,Uint8Array)){let t=new Uint8Array(n);return Mr(t.buffer,t.byteOffset,t.byteLength)}return Pr(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,b.prototype),r}function Cc(n){if(b.isBuffer(n)){let t=Vr(n.length)|0,e=fe(t);return e.length===0||n.copy(e,0,0,t),e}if(n.length!==void 0)return typeof n.length!="number"||$r(n.length)?fe(0):Pr(n);if(n.type==="Buffer"&&Array.isArray(n.data))return Pr(n.data)}function Vr(n){if(n>=Xn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Xn.toString(16)+" bytes");return n|0}function kc(n){return+n!=n&&(n=0),b.alloc(+n)}b.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==b.prototype};b.compare=function(t,e){if(Xt(t,Uint8Array)&&(t=b.from(t,t.offset,t.byteLength)),Xt(e,Uint8Array)&&(e=b.from(e,e.offset,e.byteLength)),!b.isBuffer(t)||!b.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};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,e){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(e===void 0)for(e=0,r=0;r<t.length;++r)e+=t[r].length;let o=b.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){let s=t[r];if(Xt(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 ai(n,t){if(b.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||Xt(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 xi(n).length;default:if(o)return r?-1:Kr(n).length;t=(""+t).toLowerCase(),o=!0}}b.byteLength=ai;function Nc(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 Zc(this,t,e);case"utf8":case"utf-8":return hi(this,t,e);case"ascii":return zc(this,t,e);case"latin1":case"binary":return Vc(this,t,e);case"base64":return Mc(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $c(this,t,e);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),r=!0}}b.prototype._isBuffer=!0;function Re(n,t,e){let r=n[t];n[t]=n[e],n[e]=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 e=0;e<t;e+=2)Re(this,e,e+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 e=0;e<t;e+=4)Re(this,e,e+3),Re(this,e+1,e+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 e=0;e<t;e+=8)Re(this,e,e+7),Re(this,e+1,e+6),Re(this,e+2,e+5),Re(this,e+3,e+4);return this};b.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?hi(this,0,t):Nc.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="",e=tn.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"};oi&&(b.prototype[oi]=b.prototype.inspect);b.prototype.compare=function(t,e,r,o,i){if(Xt(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(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,c=r-e,f=Math.min(s,c),l=this.slice(o,i),u=t.slice(e,r);for(let a=0;a<f;++a)if(l[a]!==u[a]){s=l[a],c=u[a];break}return s<c?-1:c<s?1:0};function li(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,$r(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=b.from(t,r)),b.isBuffer(t))return t.length===0?-1:ii(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):ii(n,[t],e,r,o);throw new TypeError("val must be string, number or Buffer")}function ii(n,t,e,r,o){let i=1,s=n.length,c=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,c/=2,e/=2}function f(u,a){return i===1?u[a]:u.readUInt16BE(a*i)}let l;if(o){let u=-1;for(l=e;l<s;l++)if(f(n,l)===f(t,u===-1?0:l-u)){if(u===-1&&(u=l),l-u+1===c)return u*i}else u!==-1&&(l-=l-u),u=-1}else for(e+c>s&&(e=s-c),l=e;l>=0;l--){let u=!0;for(let a=0;a<c;a++)if(f(n,l+a)!==f(t,a)){u=!1;break}if(u)return l}return-1}b.prototype.includes=function(t,e,r){return this.indexOf(t,e,r)!==-1};b.prototype.indexOf=function(t,e,r){return li(this,t,e,r,!0)};b.prototype.lastIndexOf=function(t,e,r){return li(this,t,e,r,!1)};function Hc(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 c=parseInt(t.substr(s*2,2),16);if($r(c))return s;n[e+s]=c}return s}function Dc(n,t,e,r){return Qn(Kr(t,n.length-e),n,e,r)}function jc(n,t,e,r){return Qn(Xc(t),n,e,r)}function qc(n,t,e,r){return Qn(xi(t),n,e,r)}function Pc(n,t,e,r){return Qn(Qc(t,n.length-e),n,e,r)}b.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 Hc(this,t,e,r);case"utf8":case"utf-8":return Dc(this,t,e,r);case"ascii":case"latin1":case"binary":return jc(this,t,e,r);case"base64":return qc(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Pc(this,t,e,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 Mc(n,t,e){return t===0&&e===n.length?qr.fromByteArray(n):qr.fromByteArray(n.slice(t,e))}function hi(n,t,e){e=Math.min(n.length,e);let r=[],o=t;for(;o<e;){let i=n[o],s=null,c=i>239?4:i>223?3:i>191?2:1;if(o+c<=e){let f,l,u,a;switch(c){case 1:i<128&&(s=i);break;case 2:f=n[o+1],(f&192)===128&&(a=(i&31)<<6|f&63,a>127&&(s=a));break;case 3:f=n[o+1],l=n[o+2],(f&192)===128&&(l&192)===128&&(a=(i&15)<<12|(f&63)<<6|l&63,a>2047&&(a<55296||a>57343)&&(s=a));break;case 4:f=n[o+1],l=n[o+2],u=n[o+3],(f&192)===128&&(l&192)===128&&(u&192)===128&&(a=(i&15)<<18|(f&63)<<12|(l&63)<<6|u&63,a>65535&&a<1114112&&(s=a))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),o+=c}return Kc(r)}var si=4096;function Kc(n){let t=n.length;if(t<=si)return String.fromCharCode.apply(String,n);let e="",r=0;for(;r<t;)e+=String.fromCharCode.apply(String,n.slice(r,r+=si));return e}function zc(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 Vc(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 Zc(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+=Jc[n[i]];return o}function $c(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}b.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,b.prototype),o};function bt(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")}b.prototype.readUintLE=b.prototype.readUIntLE=function(t,e,r){t=t>>>0,e=e>>>0,r||bt(t,e,this.length);let o=this[t],i=1,s=0;for(;++s<e&&(i*=256);)o+=this[t+s]*i;return o};b.prototype.readUintBE=b.prototype.readUIntBE=function(t,e,r){t=t>>>0,e=e>>>0,r||bt(t,e,this.length);let o=this[t+--e],i=1;for(;e>0&&(i*=256);)o+=this[t+--e]*i;return o};b.prototype.readUint8=b.prototype.readUInt8=function(t,e){return t=t>>>0,e||bt(t,1,this.length),this[t]};b.prototype.readUint16LE=b.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||bt(t,2,this.length),this[t]|this[t+1]<<8};b.prototype.readUint16BE=b.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||bt(t,2,this.length),this[t]<<8|this[t+1]};b.prototype.readUint32LE=b.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||bt(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,e){return t=t>>>0,e||bt(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};b.prototype.readBigUInt64LE=we(function(t){t=t>>>0,Je(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&Sn(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))});b.prototype.readBigUInt64BE=we(function(t){t=t>>>0,Je(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&Sn(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)});b.prototype.readIntLE=function(t,e,r){t=t>>>0,e=e>>>0,r||bt(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};b.prototype.readIntBE=function(t,e,r){t=t>>>0,e=e>>>0,r||bt(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};b.prototype.readInt8=function(t,e){return t=t>>>0,e||bt(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};b.prototype.readInt16LE=function(t,e){t=t>>>0,e||bt(t,2,this.length);let r=this[t]|this[t+1]<<8;return r&32768?r|4294901760:r};b.prototype.readInt16BE=function(t,e){t=t>>>0,e||bt(t,2,this.length);let r=this[t+1]|this[t]<<8;return r&32768?r|4294901760:r};b.prototype.readInt32LE=function(t,e){return t=t>>>0,e||bt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};b.prototype.readInt32BE=function(t,e){return t=t>>>0,e||bt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};b.prototype.readBigInt64LE=we(function(t){t=t>>>0,Je(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&Sn(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)});b.prototype.readBigInt64BE=we(function(t){t=t>>>0,Je(t,"offset");let e=this[t],r=this[t+7];(e===void 0||r===void 0)&&Sn(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)});b.prototype.readFloatLE=function(t,e){return t=t>>>0,e||bt(t,4,this.length),Qe.read(this,t,!0,23,4)};b.prototype.readFloatBE=function(t,e){return t=t>>>0,e||bt(t,4,this.length),Qe.read(this,t,!1,23,4)};b.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||bt(t,8,this.length),Qe.read(this,t,!0,52,8)};b.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||bt(t,8,this.length),Qe.read(this,t,!1,52,8)};function kt(n,t,e,r,o,i){if(!b.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")}b.prototype.writeUintLE=b.prototype.writeUIntLE=function(t,e,r,o){if(t=+t,e=e>>>0,r=r>>>0,!o){let c=Math.pow(2,8*r)-1;kt(this,t,e,r,c,0)}let i=1,s=0;for(this[e]=t&255;++s<r&&(i*=256);)this[e+s]=t/i&255;return e+r};b.prototype.writeUintBE=b.prototype.writeUIntBE=function(t,e,r,o){if(t=+t,e=e>>>0,r=r>>>0,!o){let c=Math.pow(2,8*r)-1;kt(this,t,e,r,c,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};b.prototype.writeUint8=b.prototype.writeUInt8=function(t,e,r){return t=+t,e=e>>>0,r||kt(this,t,e,1,255,0),this[e]=t&255,e+1};b.prototype.writeUint16LE=b.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=e>>>0,r||kt(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2};b.prototype.writeUint16BE=b.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=e>>>0,r||kt(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2};b.prototype.writeUint32LE=b.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=e>>>0,r||kt(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};b.prototype.writeUint32BE=b.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=e>>>0,r||kt(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 di(n,t,e,r,o){wi(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 pi(n,t,e,r,o){wi(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}b.prototype.writeBigUInt64LE=we(function(t,e=0){return di(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});b.prototype.writeBigUInt64BE=we(function(t,e=0){return pi(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});b.prototype.writeIntLE=function(t,e,r,o){if(t=+t,e=e>>>0,!o){let f=Math.pow(2,8*r-1);kt(this,t,e,r,f-1,-f)}let i=0,s=1,c=0;for(this[e]=t&255;++i<r&&(s*=256);)t<0&&c===0&&this[e+i-1]!==0&&(c=1),this[e+i]=(t/s>>0)-c&255;return e+r};b.prototype.writeIntBE=function(t,e,r,o){if(t=+t,e=e>>>0,!o){let f=Math.pow(2,8*r-1);kt(this,t,e,r,f-1,-f)}let i=r-1,s=1,c=0;for(this[e+i]=t&255;--i>=0&&(s*=256);)t<0&&c===0&&this[e+i+1]!==0&&(c=1),this[e+i]=(t/s>>0)-c&255;return e+r};b.prototype.writeInt8=function(t,e,r){return t=+t,e=e>>>0,r||kt(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1};b.prototype.writeInt16LE=function(t,e,r){return t=+t,e=e>>>0,r||kt(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2};b.prototype.writeInt16BE=function(t,e,r){return t=+t,e=e>>>0,r||kt(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2};b.prototype.writeInt32LE=function(t,e,r){return t=+t,e=e>>>0,r||kt(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};b.prototype.writeInt32BE=function(t,e,r){return t=+t,e=e>>>0,r||kt(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};b.prototype.writeBigInt64LE=we(function(t,e=0){return di(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});b.prototype.writeBigInt64BE=we(function(t,e=0){return pi(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function gi(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 mi(n,t,e,r,o){return t=+t,e=e>>>0,o||gi(n,t,e,4,34028234663852886e22,-34028234663852886e22),Qe.write(n,t,e,r,23,4),e+4}b.prototype.writeFloatLE=function(t,e,r){return mi(this,t,e,!0,r)};b.prototype.writeFloatBE=function(t,e,r){return mi(this,t,e,!1,r)};function yi(n,t,e,r,o){return t=+t,e=e>>>0,o||gi(n,t,e,8,17976931348623157e292,-17976931348623157e292),Qe.write(n,t,e,r,52,8),e+8}b.prototype.writeDoubleLE=function(t,e,r){return yi(this,t,e,!0,r)};b.prototype.writeDoubleBE=function(t,e,r){return yi(this,t,e,!1,r)};b.prototype.copy=function(t,e,r,o){if(!b.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};b.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"&&!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(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=b.isBuffer(t)?t:b.from(t,o),c=s.length;if(c===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=s[i%c]}return this};var Xe={};function Zr(n,t,e){Xe[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=ci(String(e)):typeof e=="bigint"&&(o=String(e),(e>BigInt(2)**BigInt(32)||e<-(BigInt(2)**BigInt(32)))&&(o=ci(o)),o+="n"),r+=` It must be ${t}. Received ${o}`,r},RangeError);function ci(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 Gc(n,t,e){Je(t,"offset"),(n[t]===void 0||n[t+e]===void 0)&&Sn(t,n.length-(e+1))}function wi(n,t,e,r,o,i){if(n>e||n<t){let s=typeof t=="bigint"?"n":"",c;throw i>3?t===0||t===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:c=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:c=`>= ${t}${s} and <= ${e}${s}`,new Xe.ERR_OUT_OF_RANGE("value",c,n)}Gc(r,o,i)}function Je(n,t){if(typeof n!="number")throw new Xe.ERR_INVALID_ARG_TYPE(t,"number",n)}function Sn(n,t,e){throw Math.floor(n)!==n?(Je(n,e),new Xe.ERR_OUT_OF_RANGE(e||"offset","an integer",n)):t<0?new Xe.ERR_BUFFER_OUT_OF_BOUNDS:new Xe.ERR_OUT_OF_RANGE(e||"offset",`>= ${e?1:0} and <= ${t}`,n)}var Yc=/[^+/0-9A-Za-z-_]/g;function Wc(n){if(n=n.split("=")[0],n=n.trim().replace(Yc,""),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 Xc(n){let t=[];for(let e=0;e<n.length;++e)t.push(n.charCodeAt(e)&255);return t}function Qc(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 xi(n){return qr.toByteArray(Wc(n))}function Qn(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 Xt(n,t){return n instanceof t||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===t.name}function $r(n){return n!==n}var Jc=(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 we(n){return typeof BigInt>"u"?tf:n}function tf(){throw new Error("BigInt not supported")}});var ct,K,C=St(()=>{ct=Go(Jo()),K=Go(bi())});var Gr=Ct((qu,Ei)=>{C();Ei.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PublicKey});var Si=Ct((Mu,Bi)=>{C();Bi.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PrivateKey});var Yr=Ct((zu,Ai)=>{C();Ai.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.util.preconditions});function Wr(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}function xe(n,t=""){if(typeof n!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof n}`)}if(!Number.isSafeInteger(n)||n<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${n}`)}}function Qt(n,t,e=""){let r=Wr(n),o=n?.length,i=t!==void 0;if(!r||i&&o!==t){let s=e&&`"${e}" `,c=i?` of length ${t}`:"",f=r?`length=${o}`:`type=${typeof n}`,l=s+"expected Uint8Array"+c+", got "+f;throw r?new RangeError(l):new TypeError(l)}return n}function Jn(n){if(typeof n!="function"||typeof n.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(xe(n.outputLen),xe(n.blockLen),n.outputLen<1)throw new Error('"outputLen" must be >= 1');if(n.blockLen<1)throw new Error('"blockLen" must be >= 1')}function en(n,t=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(t&&n.finished)throw new Error("Hash#digest() has already been called")}function tr(n,t){Qt(n,void 0,"digestInto() output");let e=t.outputLen;if(n.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function ae(...n){for(let t=0;t<n.length;t++)n[t].fill(0)}function er(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function Vt(n,t){return n<<32-t|n>>>t}function nr(n){if(Qt(n),Ii)return n.toHex();let t="";for(let e=0;e<n.length;e++)t+=ef[n[e]];return t}function vi(n){if(n>=ue._0&&n<=ue._9)return n-ue._0;if(n>=ue.A&&n<=ue.F)return n-(ue.A-10);if(n>=ue.a&&n<=ue.f)return n-(ue.a-10)}function Xr(n){if(typeof n!="string")throw new TypeError("hex string expected, got "+typeof n);if(Ii)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=vi(n.charCodeAt(i)),c=vi(n.charCodeAt(i+1));if(s===void 0||c===void 0){let f=n[i]+n[i+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+i)}r[o]=s*16+c}return r}function le(n){if(typeof n!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(n))}function Ti(...n){let t=0;for(let r=0;r<n.length;r++){let o=n[r];Qt(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 _e(n,t={}){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){xe(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 Ii,ef,ue,Oe,be=St(()=>{C();Ii=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ef=Array.from({length:256},(n,t)=>t.toString(16).padStart(2,"0"));ue={_0:48,_9:57,A:65,F:70,a:97,f:102};Oe=n=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,n])})});function Fi(n,t,e){return n&t^~n&e}function Ui(n,t,e){return n&t^n&e^t&e}var vn,he,de,At,vt,Ri=St(()=>{C();be();vn=class{constructor(t,e,r,o){y(this,"blockLen");y(this,"outputLen");y(this,"canXOF",!1);y(this,"padOffset");y(this,"isLE");y(this,"buffer");y(this,"view");y(this,"finished",!1);y(this,"length",0);y(this,"pos",0);y(this,"destroyed",!1);this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(t),this.view=er(this.buffer)}update(t){en(this),Qt(t);let{view:e,buffer:r,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let f=er(t);for(;o<=i-s;s+=o)this.process(f,s);continue}r.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){en(this),tr(t,this),this.finished=!0;let{buffer:e,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,ae(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(r,0),s=0);for(let a=s;a<o;a++)e[a]=0;r.setBigUint64(o-8,BigInt(this.length*8),i),this.process(r,0);let c=er(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=f/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let a=0;a<l;a++)c.setUint32(4*a,u[a],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:r,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%e&&t.buffer.set(r),t}clone(){return this._cloneInto()}},he=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),de=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),At=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),vt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});function nf(n,t=!1){return t?{h:Number(n&rr),l:Number(n>>_i&rr)}:{h:Number(n>>_i&rr)|0,l:Number(n&rr)|0}}function Oi(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:c}=nf(n[i],t);[r[i],o[i]]=[s,c]}return[r,o]}function Jt(n,t,e,r){let o=(t>>>0)+(r>>>0);return{h:n+e+(o/2**32|0)|0,l:o|0}}var rr,_i,Qr,Jr,Le,Ce,In,Tn,Li,Ci,ki,Ni,Hi,Di,ji=St(()=>{C();rr=BigInt(4294967295),_i=BigInt(32);Qr=(n,t,e)=>n>>>e,Jr=(n,t,e)=>n<<32-e|t>>>e,Le=(n,t,e)=>n>>>e|t<<32-e,Ce=(n,t,e)=>n<<32-e|t>>>e,In=(n,t,e)=>n<<64-e|t>>>e-32,Tn=(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),Ni=(n,t,e,r,o)=>t+e+r+o+(n/2**32|0)|0,Hi=(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});var to={};Gn(to,{_SHA224:()=>sr,_SHA256:()=>ir,_SHA384:()=>fr,_SHA512:()=>cr,_SHA512_224:()=>ur,_SHA512_256:()=>ar,sha224:()=>ff,sha256:()=>Ae,sha384:()=>af,sha512:()=>uf,sha512_224:()=>hf,sha512_256:()=>lf});var of,Ee,or,ir,sr,qi,sf,cf,Be,Se,nn,cr,fr,Ut,Rt,ur,ar,Ae,ff,uf,af,lf,hf,lr=St(()=>{C();Ri();ji();be();of=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]),Ee=new Uint32Array(64),or=class extends vn{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:r,D:o,E:i,F:s,G:c,H:f}=this;return[t,e,r,o,i,s,c,f]}set(t,e,r,o,i,s,c,f){this.A=t|0,this.B=e|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=f|0}process(t,e){for(let a=0;a<16;a++,e+=4)Ee[a]=t.getUint32(e,!1);for(let a=16;a<64;a++){let h=Ee[a-15],d=Ee[a-2],p=Vt(h,7)^Vt(h,18)^h>>>3,m=Vt(d,17)^Vt(d,19)^d>>>10;Ee[a]=m+Ee[a-7]+p+Ee[a-16]|0}let{A:r,B:o,C:i,D:s,E:c,F:f,G:l,H:u}=this;for(let a=0;a<64;a++){let h=Vt(c,6)^Vt(c,11)^Vt(c,25),d=u+h+Fi(c,f,l)+of[a]+Ee[a]|0,m=(Vt(r,2)^Vt(r,13)^Vt(r,22))+Ui(r,o,i)|0;u=l,l=f,f=c,c=s+d|0,s=i,i=o,o=r,r=d+m|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,f=f+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(r,o,i,s,c,f,l,u)}roundClean(){ae(Ee)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ae(this.buffer)}},ir=class extends or{constructor(){super(32);y(this,"A",he[0]|0);y(this,"B",he[1]|0);y(this,"C",he[2]|0);y(this,"D",he[3]|0);y(this,"E",he[4]|0);y(this,"F",he[5]|0);y(this,"G",he[6]|0);y(this,"H",he[7]|0)}},sr=class extends or{constructor(){super(28);y(this,"A",de[0]|0);y(this,"B",de[1]|0);y(this,"C",de[2]|0);y(this,"D",de[3]|0);y(this,"E",de[4]|0);y(this,"F",de[5]|0);y(this,"G",de[6]|0);y(this,"H",de[7]|0)}},qi=Oi(["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))),sf=qi[0],cf=qi[1],Be=new Uint32Array(80),Se=new Uint32Array(80),nn=class extends vn{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:r,Bl:o,Ch:i,Cl:s,Dh:c,Dl:f,Eh:l,El:u,Fh:a,Fl:h,Gh:d,Gl:p,Hh:m,Hl:w}=this;return[t,e,r,o,i,s,c,f,l,u,a,h,d,p,m,w]}set(t,e,r,o,i,s,c,f,l,u,a,h,d,p,m,w){this.Ah=t|0,this.Al=e|0,this.Bh=r|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=c|0,this.Dl=f|0,this.Eh=l|0,this.El=u|0,this.Fh=a|0,this.Fl=h|0,this.Gh=d|0,this.Gl=p|0,this.Hh=m|0,this.Hl=w|0}process(t,e){for(let I=0;I<16;I++,e+=4)Be[I]=t.getUint32(e),Se[I]=t.getUint32(e+=4);for(let I=16;I<80;I++){let S=Be[I-15]|0,T=Se[I-15]|0,P=Le(S,T,1)^Le(S,T,8)^Qr(S,T,7),ft=Ce(S,T,1)^Ce(S,T,8)^Jr(S,T,7),$=Be[I-2]|0,z=Se[I-2]|0,nt=Le($,z,19)^In($,z,61)^Qr($,z,6),W=Ce($,z,19)^Tn($,z,61)^Jr($,z,6),rt=ki(ft,W,Se[I-7],Se[I-16]),F=Ni(rt,P,nt,Be[I-7],Be[I-16]);Be[I]=F|0,Se[I]=rt|0}let{Ah:r,Al:o,Bh:i,Bl:s,Ch:c,Cl:f,Dh:l,Dl:u,Eh:a,El:h,Fh:d,Fl:p,Gh:m,Gl:w,Hh:E,Hl:B}=this;for(let I=0;I<80;I++){let S=Le(a,h,14)^Le(a,h,18)^In(a,h,41),T=Ce(a,h,14)^Ce(a,h,18)^Tn(a,h,41),P=a&d^~a&m,ft=h&p^~h&w,$=Hi(B,T,ft,cf[I],Se[I]),z=Di($,E,S,P,sf[I],Be[I]),nt=$|0,W=Le(r,o,28)^In(r,o,34)^In(r,o,39),rt=Ce(r,o,28)^Tn(r,o,34)^Tn(r,o,39),F=r&i^r&c^i&c,N=o&s^o&f^s&f;E=m|0,B=w|0,m=d|0,w=p|0,d=a|0,p=h|0,{h:a,l:h}=Jt(l|0,u|0,z|0,nt|0),l=c|0,u=f|0,c=i|0,f=s|0,i=r|0,s=o|0;let U=Li(nt,rt,N);r=Ci(U,z,W,F),o=U|0}({h:r,l:o}=Jt(this.Ah|0,this.Al|0,r|0,o|0)),{h:i,l:s}=Jt(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:f}=Jt(this.Ch|0,this.Cl|0,c|0,f|0),{h:l,l:u}=Jt(this.Dh|0,this.Dl|0,l|0,u|0),{h:a,l:h}=Jt(this.Eh|0,this.El|0,a|0,h|0),{h:d,l:p}=Jt(this.Fh|0,this.Fl|0,d|0,p|0),{h:m,l:w}=Jt(this.Gh|0,this.Gl|0,m|0,w|0),{h:E,l:B}=Jt(this.Hh|0,this.Hl|0,E|0,B|0),this.set(r,o,i,s,c,f,l,u,a,h,d,p,m,w,E,B)}roundClean(){ae(Be,Se)}destroy(){this.destroyed=!0,ae(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},cr=class extends nn{constructor(){super(64);y(this,"Ah",vt[0]|0);y(this,"Al",vt[1]|0);y(this,"Bh",vt[2]|0);y(this,"Bl",vt[3]|0);y(this,"Ch",vt[4]|0);y(this,"Cl",vt[5]|0);y(this,"Dh",vt[6]|0);y(this,"Dl",vt[7]|0);y(this,"Eh",vt[8]|0);y(this,"El",vt[9]|0);y(this,"Fh",vt[10]|0);y(this,"Fl",vt[11]|0);y(this,"Gh",vt[12]|0);y(this,"Gl",vt[13]|0);y(this,"Hh",vt[14]|0);y(this,"Hl",vt[15]|0)}},fr=class extends nn{constructor(){super(48);y(this,"Ah",At[0]|0);y(this,"Al",At[1]|0);y(this,"Bh",At[2]|0);y(this,"Bl",At[3]|0);y(this,"Ch",At[4]|0);y(this,"Cl",At[5]|0);y(this,"Dh",At[6]|0);y(this,"Dl",At[7]|0);y(this,"Eh",At[8]|0);y(this,"El",At[9]|0);y(this,"Fh",At[10]|0);y(this,"Fl",At[11]|0);y(this,"Gh",At[12]|0);y(this,"Gl",At[13]|0);y(this,"Hh",At[14]|0);y(this,"Hl",At[15]|0)}},Ut=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),Rt=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]),ur=class extends nn{constructor(){super(28);y(this,"Ah",Ut[0]|0);y(this,"Al",Ut[1]|0);y(this,"Bh",Ut[2]|0);y(this,"Bl",Ut[3]|0);y(this,"Ch",Ut[4]|0);y(this,"Cl",Ut[5]|0);y(this,"Dh",Ut[6]|0);y(this,"Dl",Ut[7]|0);y(this,"Eh",Ut[8]|0);y(this,"El",Ut[9]|0);y(this,"Fh",Ut[10]|0);y(this,"Fl",Ut[11]|0);y(this,"Gh",Ut[12]|0);y(this,"Gl",Ut[13]|0);y(this,"Hh",Ut[14]|0);y(this,"Hl",Ut[15]|0)}},ar=class extends nn{constructor(){super(32);y(this,"Ah",Rt[0]|0);y(this,"Al",Rt[1]|0);y(this,"Bh",Rt[2]|0);y(this,"Bl",Rt[3]|0);y(this,"Ch",Rt[4]|0);y(this,"Cl",Rt[5]|0);y(this,"Dh",Rt[6]|0);y(this,"Dl",Rt[7]|0);y(this,"Eh",Rt[8]|0);y(this,"El",Rt[9]|0);y(this,"Fh",Rt[10]|0);y(this,"Fl",Rt[11]|0);y(this,"Gh",Rt[12]|0);y(this,"Gl",Rt[13]|0);y(this,"Hh",Rt[14]|0);y(this,"Hl",Rt[15]|0)}},Ae=_e(()=>new ir,Oe(1)),ff=_e(()=>new sr,Oe(4)),uf=_e(()=>new cr,Oe(3)),af=_e(()=>new fr,Oe(2)),lf=_e(()=>new ar,Oe(6)),hf=_e(()=>new ur,Oe(5))});function Ne(n,t=""){if(typeof n!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof n)}return n}function pr(n){if(typeof n=="bigint"){if(!hr(n))throw new RangeError("positive bigint expected, got "+n)}else no(n);return n}function Pt(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 Fn(n){let t=pr(n).toString(16);return t.length&1?"0"+t:t}function Pi(n){if(typeof n!="string")throw new TypeError("hex string expected, got "+typeof n);return n===""?dr:BigInt("0x"+n)}function _t(n){return Pi(nr(n))}function on(n){return Pi(nr(mr(Qt(n)).reverse()))}function gr(n,t){if(xe(t),t===0)throw new RangeError("zero length");n=pr(n);let e=n.toString(16);if(e.length>t*2)throw new RangeError("number too large");return Xr(e.padStart(t*2,"0"))}function ro(n,t){return gr(n,t).reverse()}function mr(n){return Uint8Array.from(at(n))}function sn(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 df(n,t,e){return hr(n)&&hr(t)&&hr(e)&&t<=n&&n<e}function oo(n,t,e,r){if(!df(t,e,r))throw new RangeError("expected valid "+n+": "+e+" <= n < "+r+", got "+t)}function He(n){if(n<dr)throw new Error("expected non-negative bigint, got "+n);let t;for(t=0;n>dr;n>>=eo,t+=1);return t}function Mi(n,t,e){if(xe(n,"hashLen"),xe(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let r=w=>new Uint8Array(w),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,f=r(n),l=r(n),u=0,a=()=>{f.fill(1),l.fill(0),u=0},h=(...w)=>e(l,it(f,...w)),d=(w=o)=>{l=h(i,w),f=h(),w.length!==0&&(l=h(s,w),f=h())},p=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let w=0,E=[];for(;w<t;){f=h();let B=f.slice();E.push(B),w+=f.length}return it(...E)};return(w,E)=>{a(),d(w);let B;for(;(B=E(p()))===void 0;)d();return a(),B}}function Mt(n,t={},e={}){if(Object.prototype.toString.call(n)!=="[object Object]")throw new TypeError("expected valid options object");function r(i,s,c){if(!c&&s!=="function"&&!Object.hasOwn(n,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let f=n[i];if(c&&f===void 0)return;let l=typeof f;if(l!==s||f===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${l}`)}let o=(i,s)=>Object.entries(i).forEach(([c,f])=>r(c,f,s));o(t,!1),o(e,!0)}var at,no,pe,it,rn,ke,Nt,dr,eo,hr,cn,De=St(()=>{C();be();at=(n,t,e)=>Qt(n,t,e),no=xe,pe=nr,it=(...n)=>Ti(...n),rn=n=>Xr(n),ke=Wr,Nt=n=>An(n),dr=BigInt(0),eo=BigInt(1);hr=n=>typeof n=="bigint"&&dr<=n;cn=n=>(eo<<BigInt(n))-eo});function Ht(n,t){if(t<=It)throw new Error("mod: expected positive modulus, got "+t);let e=n%t;return e>=It?e:t+e}function Dt(n,t,e){if(t<It)throw new Error("pow2: expected non-negative exponent, got "+t);let r=n;for(;t-- >It;)r*=r,r%=e;return r}function Ki(n,t){if(n===It)throw new Error("invert: expected non-zero number");if(t<=It)throw new Error("invert: expected positive modulus, got "+t);let e=Ht(n,t),r=t,o=It,i=xt,s=xt,c=It;for(;e!==It;){let l=r/e,u=r-e*l,a=o-s*l,h=i-c*l;r=e,e=u,o=s,i=c,s=a,c=h}if(r!==xt)throw new Error("invert: does not exist");return Ht(o,t)}function so(n,t,e){let r=n;if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Wi(n,t){let e=n,r=(e.ORDER+xt)/Zi,o=e.pow(t,r);return so(e,o,t),o}function mf(n,t){let e=n,r=(e.ORDER-$i)/Gi,o=e.mul(t,je),i=e.pow(o,r),s=e.mul(t,i),c=e.mul(e.mul(s,je),i),f=e.mul(s,e.sub(c,e.ONE));return so(e,f,t),f}function yf(n){let t=fn(n),e=Xi(n),r=e(t,t.neg(t.ONE)),o=e(t,r),i=e(t,t.neg(r)),s=(n+pf)/Yi;return((c,f)=>{let l=c,u=l.pow(f,s),a=l.mul(u,r),h=l.mul(u,o),d=l.mul(u,i),p=l.eql(l.sqr(a),f),m=l.eql(l.sqr(h),f);u=l.cmov(u,a,p),a=l.cmov(d,h,m);let w=l.eql(l.sqr(a),f),E=l.cmov(u,a,w);return so(l,E,f),E})}function Xi(n){if(n<Vi)throw new Error("sqrt is not defined for small field");let t=n-xt,e=0;for(;t%je===It;)t/=je,e++;let r=je,o=fn(n);for(;io(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Wi;let i=o.pow(r,t),s=(t+xt)/je;return function(f,l){let u=f;if(u.is0(l))return l;if(io(u,l)!==1)throw new Error("Cannot find square root");let a=e,h=u.mul(u.ONE,i),d=u.pow(l,t),p=u.pow(l,s);for(;!u.eql(d,u.ONE);){if(u.is0(d))return u.ZERO;let m=1,w=u.sqr(d);for(;!u.eql(w,u.ONE);)if(m++,w=u.sqr(w),m===a)throw new Error("Cannot find square root");let E=xt<<BigInt(a-m-1),B=u.pow(h,E);a=m,h=u.sqr(B),d=u.mul(d,h),p=u.mul(p,B)}return p}}function wf(n){return n%Zi===Vi?Wi:n%Gi===$i?mf:n%Yi===gf?yf(n):Xi(n)}function qe(n){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=xf.reduce((r,o)=>(r[o]="function",r),t);if(Mt(n,e),Pt(n.BYTES,"BYTES"),Pt(n.BITS,"BITS"),n.BYTES<1||n.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(n.ORDER<=xt)throw new Error("invalid field: expected ORDER > 1, got "+n.ORDER);return n}function bf(n,t,e){let r=n;if(e<It)throw new Error("invalid exponent, negatives unsupported");if(e===It)return r.ONE;if(e===xt)return t;let o=r.ONE,i=t;for(;e>It;)e&xt&&(o=r.mul(o,i)),i=r.sqr(i),e>>=xt;return o}function Pe(n,t,e=!1){let r=n,o=new Array(t.length).fill(e?r.ZERO:void 0),i=t.reduce((c,f,l)=>r.is0(f)?c:(o[l]=c,r.mul(c,f)),r.ONE),s=r.inv(i);return t.reduceRight((c,f,l)=>r.is0(f)?c:(o[l]=r.mul(c,o[l]),r.mul(c,f)),s),o}function io(n,t){let e=n,r=(e.ORDER-xt)/je,o=e.pow(t,r),i=e.eql(o,e.ONE),s=e.eql(o,e.ZERO),c=e.eql(o,e.neg(e.ONE));if(!i&&!s&&!c)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function co(n,t){return io(n,t)!==-1}function Ef(n,t){if(t!==void 0&&no(t),n<=It)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=He(n);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let r=t!==void 0?t:e,o=Math.ceil(r/8);return{nBitLength:r,nByteLength:o}}function fn(n,t={}){return new yr(n,t)}function Qi(n){if(typeof n!="bigint")throw new Error("field order must be bigint");if(n<=xt)throw new Error("field order must be greater than 1");let t=He(n-xt);return Math.ceil(t/8)}function Un(n){let t=Qi(n);return t+Math.ceil(t/2)}function un(n,t,e=!1){at(n);let r=n.length,o=Qi(t),i=Math.max(Un(t),16);if(r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);let s=e?on(n):_t(n),c=Ht(s,t-xt)+xt;return e?ro(c,o):gr(c,o)}var It,xt,je,Vi,Zi,$i,pf,Gi,gf,Yi,xf,zi,yr,an=St(()=>{C();De();It=BigInt(0),xt=BigInt(1),je=BigInt(2),Vi=BigInt(3),Zi=BigInt(4),$i=BigInt(5),pf=BigInt(7),Gi=BigInt(8),gf=BigInt(9),Yi=BigInt(16);xf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];zi=new WeakMap,yr=class{constructor(t,e={}){y(this,"ORDER");y(this,"BITS");y(this,"BYTES");y(this,"isLE");y(this,"ZERO",It);y(this,"ONE",xt);y(this,"_lengths");y(this,"_mod");if(t<=xt)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}=Ef(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 Ht(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return It<=t&&t<this.ORDER}is0(t){return t===It}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&xt)===xt}neg(t){return Ht(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Ht(t*t,this.ORDER)}add(t,e){return Ht(t+e,this.ORDER)}sub(t,e){return Ht(t-e,this.ORDER)}mul(t,e){return Ht(t*e,this.ORDER)}pow(t,e){return bf(this,t,e)}div(t,e){return Ht(t*Ki(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 Ki(t,this.ORDER)}sqrt(t){let e=zi.get(this);return e||zi.set(this,e=wf(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ro(t,this.BYTES):gr(t,this.BYTES)}fromBytes(t,e=!1){at(t);let{_lengths:r,BYTES:o,isLE:i,ORDER:s,_mod:c}=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 l=new Uint8Array(o);l.set(t,i?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=i?on(t):_t(t);if(c&&(f=Ht(f,s)),!e&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return Pe(this,t)}cmov(t,e,r){return Ne(r,"condition"),r?e:t}};Object.freeze(yr.prototype)});function ns(n){let t=n;if(typeof t!="function")throw new TypeError("Point must be a constructor");Mt({Fp:t.Fp,Fn:t.Fn,fromAffine:t.fromAffine,fromBytes:t.fromBytes,fromHex:t.fromHex},{Fp:"object",Fn:"object",fromAffine:"function",fromBytes:"function",fromHex:"function"}),qe(t.Fp),qe(t.Fn)}function Rn(n,t){let e=t.negate();return n?e:t}function lo(n,t){let e=Pe(n.Fp,t.map(r=>r.Z));return t.map((r,o)=>n.fromAffine(r.toAffine(e[o])))}function rs(n,t){if(!Number.isSafeInteger(n)||n<=0||n>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+n)}function fo(n,t){rs(n,t);let e=Math.ceil(t/n)+1,r=2**(n-1),o=2**n,i=cn(n),s=BigInt(n);return{windows:e,windowSize:r,mask:i,maxNumber:o,shiftBy:s}}function Ji(n,t,e){let{windowSize:r,mask:o,maxNumber:i,shiftBy:s}=e,c=Number(n&o),f=n>>s;c>r&&(c-=i,f+=Me);let l=t*r,u=l+Math.abs(c)-1,a=c===0,h=c<0,d=t%2!==0;return{nextN:f,offset:u,isZero:a,isNeg:h,isNegF:d,offsetF:l}}function Bf(n,t){if(!Array.isArray(n))throw new Error("array expected");n.forEach((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)})}function Sf(n,t){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((e,r)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+r)})}function ao(n){return os.get(n)||1}function ts(n){if(n!==ln)throw new Error("invalid wNAF")}function is(n,t,e,r){let o=t,i=n.ZERO,s=n.ZERO;for(;e>ln||r>ln;)e&Me&&(i=i.add(o)),r&Me&&(s=s.add(o)),o=o.double(),e>>=Me,r>>=Me;return{p1:i,p2:s}}function ss(n,t,e){let r=n.Fn;Bf(t,n),Sf(e,r);let o=t.length,i=e.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=n.ZERO,c=He(BigInt(o)),f=1;c>12?f=c-3:c>4?f=c-2:c>0&&(f=2);let l=cn(f),u=new Array(Number(l)+1).fill(s),a=Math.floor((r.BITS-1)/f)*f,h=s;for(let d=a;d>=0;d-=f){u.fill(s);for(let m=0;m<i;m++){let w=e[m],E=Number(w>>BigInt(d)&l);u[E]=u[E].add(t[m])}let p=s;for(let m=u.length-1,w=s;m>0;m--)w=w.add(u[m]),p=p.add(w);if(h=h.add(p),d!==0)for(let m=0;m<f;m++)h=h.double()}return h}function es(n,t,e){if(t){if(t.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return qe(t),t}else return fn(n,{isLE:e})}function cs(n,t,e={},r){if(r===void 0&&(r=n==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${n} CURVE object`);for(let f of["p","n","h"]){let l=t[f];if(!(typeof l=="bigint"&&l>ln))throw new Error(`CURVE.${f} must be positive bigint`)}let o=es(t.p,e.Fp,r),i=es(t.n,e.Fn,r),c=["Gx","Gy","a",n==="weierstrass"?"b":"d"];for(let f of c)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function xr(n,t){return function(r){let o=n(r);return{secretKey:o,publicKey:t(o)}}}var ln,Me,uo,os,wr,br=St(()=>{C();De();an();ln=BigInt(0),Me=BigInt(1);uo=new WeakMap,os=new WeakMap;wr=class{constructor(t,e){y(this,"BASE");y(this,"ZERO");y(this,"Fn");y(this,"bits");this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,r=this.ZERO){let o=t;for(;e>ln;)e&Me&&(r=r.add(o)),o=o.double(),e>>=Me;return r}precomputeWindow(t,e){let{windows:r,windowSize:o}=fo(e,this.bits),i=[],s=t,c=s;for(let f=0;f<r;f++){c=s,i.push(c);for(let l=1;l<o;l++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(t,e,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=fo(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:f,offset:l,isZero:u,isNeg:a,isNegF:h,offsetF:d}=Ji(r,c,s);r=f,u?i=i.add(Rn(h,e[d])):o=o.add(Rn(a,e[l]))}return ts(r),{p:o,f:i}}wNAFUnsafe(t,e,r,o=this.ZERO){let i=fo(t,this.bits);for(let s=0;s<i.windows&&r!==ln;s++){let{nextN:c,offset:f,isZero:l,isNeg:u}=Ji(r,s,i);if(r=c,!l){let a=e[f];o=o.add(u?a.negate():a)}}return ts(r),o}getPrecomputes(t,e,r){let o=uo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof r=="function"&&(o=r(o)),uo.set(e,o))),o}cached(t,e,r){let o=ao(t);return this.wNAF(o,this.getPrecomputes(o,t,r),e)}unsafe(t,e,r,o){let i=ao(t);return i===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,r),e,o)}createCache(t,e){rs(e,this.bits),os.set(t,e),uo.delete(t)}hasCache(t){return ao(t)!==1}}});function fs(n){if(!Number.isSafeInteger(n)||n<0||n>4294967295)throw new Error("wrong u32 integer:"+n);return n}function Af(n){if(fs(n),n<=1)return 1;if(n>2147483648)throw new Error("nextPowerOfTwo overflow: result does not fit u32");return 1<<ho(n-1)+1>>>0}function ho(n){return fs(n),31-Math.clz32(n)}function us(n,t,e,r,o){let i=n,s=e||((u,a)=>new Array(u).fill(a??i.ZERO)),c=u=>{if(Array.isArray(u))return!0;if(!ArrayBuffer.isView(u))return!1;let a=u;return typeof a.length=="number"&&typeof a.slice=="function"&&typeof a[Symbol.iterator]=="function"},f=(...u)=>{if(!u.length)return 0;for(let h of u)if(!c(h))throw new Error("poly: not polynomial: "+h);let a=u[0].length;for(let h=1;h<u.length;h++)if(u[h].length!==a)throw new Error(`poly: mismatched lengths ${a} vs ${u[h].length}`);if(o!==void 0&&a!==o)throw new Error(`poly: expected fixed length ${o}, got ${a}`);return a};function l(u,a,h=!1){let d=ho(a),p=h?t.brp(d):t.roots(d);for(let m=0;m<a;m++)if(i.eql(u,p[m]))return m;return-1}return{roots:t,create:s,length:o,extend:(u,a)=>{f(u);let h=s(a,i.ZERO);for(let d=0;d<Math.min(u.length,a);d++)h[d]=u[d];return h},degree:u=>{f(u);for(let a=u.length-1;a>=0;a--)if(!i.is0(u[a]))return a;return-1},add:(u,a)=>{let h=f(u,a),d=s(h);for(let p=0;p<h;p++)d[p]=i.add(u[p],a[p]);return d},sub:(u,a)=>{let h=f(u,a),d=s(h);for(let p=0;p<h;p++)d[p]=i.sub(u[p],a[p]);return d},dot:(u,a)=>{let h=f(u,a),d=s(h);for(let p=0;p<h;p++)d[p]=i.mul(u[p],a[p]);return d},mul:(u,a)=>{if(c(a)){let h=f(u,a);if(r){let d=r.direct(u,!1,!0),p=r.direct(a,!1,!0);for(let m=0;m<d.length;m++)d[m]=i.mul(d[m],p[m]);return r.inverse(d,!0,!1)}else{let d=s(h);for(let p=0;p<h;p++)for(let m=0;m<h;m++){let w=(p+m)%h;d[w]=i.add(d[w],i.mul(u[p],a[m]))}return d}}else{let h=s(f(u));for(let d=0;d<h.length;d++)h[d]=i.mul(u[d],a);return h}},convolve(u,a){let h=Af(u.length+a.length-1);return this.mul(this.extend(u,h),this.extend(a,h))},shift(u,a){let h=s(f(u));h[0]=u[0];for(let d=1,p=i.ONE;d<u.length;d++)p=i.mul(p,a),h[d]=i.mul(u[d],p);return h},clone:u=>{f(u);let a=s(u.length);for(let h=0;h<u.length;h++)a[h]=u[h];return a},eval:(u,a)=>{f(u,a);let h=i.ZERO;for(let d=0;d<u.length;d++)h=i.add(h,i.mul(u[d],a[d]));return h},monomial:{basis:(u,a)=>{let h=s(a),d=i.ONE;for(let p=0;p<a;p++)h[p]=d,d=i.mul(d,u);return h},eval:(u,a)=>{f(u);let h=i.ZERO;for(let d=u.length-1;d>=0;d--)h=i.add(i.mul(h,a),u[d]);return h}},lagrange:{basis:(u,a,h=!1,d)=>{let p=ho(a),m=d||(h?t.brp(p):t.roots(p)),w=s(a),E=l(u,a,h);if(E!==-1)return w[E]=i.ONE,w;let B=i.pow(u,BigInt(a)),I=i.mul(i.sub(B,i.ONE),i.inv(BigInt(a))),S=s(a);for(let P=0;P<a;P++)S[P]=i.sub(u,m[P]);let T=i.invertBatch(S);for(let P=0;P<a;P++)w[P]=i.mul(I,i.mul(m[P],T[P]));return w},eval(u,a,h=!1){f(u);let d=l(a,u.length,h);if(d!==-1)return u[d];let p=this.basis(a,u.length,h),m=i.ZERO;for(let w=0;w<u.length;w++)i.is0(u[w])||(m=i.add(m,i.mul(u[w],p[w])));return m}},vanishing(u){f(u);let a=s(u.length+1,i.ZERO);a[0]=i.ONE;for(let h of u){let d=i.neg(h);for(let p=a.length-1;p>0;p--)a[p]=i.add(i.mul(a[p],d),a[p-1]);a[0]=i.mul(a[0],d)}return a}}}var as=St(()=>{C()});function Ke(n,t){if(Pt(n),Pt(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 If(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 ls(n){if(!ke(n)&&typeof n!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof n=="string"?sn(n):n;if(t.length===0)throw new Error("DST must be non-empty");return t}function Tf(n,t,e,r){at(n),Pt(e),t=ls(t),t.length>255&&(t=r(it(sn("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 c=it(t,Ke(t.length,1)),f=new Uint8Array(i),l=Ke(e,2),u=new Array(s),a=r(it(f,n,l,Ke(0,1),c));u[0]=r(it(a,Ke(1,1),c));for(let d=1;d<s;d++){let p=[If(a,u[d-1]),Ke(d+1,1),c];u[d]=r(it(...p))}return it(...u).slice(0,e)}function Ff(n,t,e,r,o){if(at(n),Pt(e),t=ls(t),t.length>255){let i=Math.ceil(2*r/8);t=o.create({dkLen:i}).update(sn("H2C-OVERSIZE-DST-")).update(t).digest()}if(e>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:e}).update(n).update(Ke(e,2)).update(t).update(Ke(t.length,1)).digest()}function po(n,t,e){Mt(e,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:r,k:o,m:i,hash:s,expand:c,DST:f}=e;if(Pt(s.outputLen,"valid hash"),at(n),Pt(t),t<1)throw new Error("hash_to_field: expected count >= 1");if(i<1)throw new Error("hash_to_field: expected m >= 1");let l=r.toString(2).length,u=Math.ceil((l+o)/8),a=t*i*u,h;if(c==="xmd")h=Tf(n,f,a,s);else if(c==="xof")h=Ff(n,f,a,o,s);else if(c==="_internal_pass")h=n;else throw new Error('expand must be "xmd" or "xof"');let d=new Array(t);for(let p=0;p<t;p++){let m=new Array(i);for(let w=0;w<i;w++){let E=u*(w+p*i),B=h.subarray(E,E+u);m[w]=Ht(vf(B),r)}d[p]=m}return d}function hs(n,t){let e=t.map(r=>Array.from(r).reverse());return(r,o)=>{let[i,s,c,f]=e.map(a=>a.reduce((h,d)=>n.add(n.mul(h,r),d))),[l,u]=Pe(n,[s,f],!0);return r=n.mul(i,l),o=n.mul(o,n.mul(c,u)),{x:r,y:o}}}function ds(n,t,e){if(typeof t!="function")throw new Error("mapToCurve() must be defined");let r=c=>Object.freeze({...c,DST:ke(c.DST)?mr(c.DST):c.DST,...c.encodeDST===void 0?{}:{encodeDST:ke(c.encodeDST)?mr(c.encodeDST):c.encodeDST}}),o=r(e);function i(c){return n.fromAffine(t(c))}function s(c){let f=c.clearCofactor();return f.equals(n.ZERO)?n.ZERO:(f.assertValidity(),f)}return Object.freeze({get defaults(){return r(o)},Point:n,hashToCurve(c,f){let l=Object.assign({},o,f),u=po(c,2,l),a=i(u[0]),h=i(u[1]);return s(a.add(h))},encodeToCurve(c,f){let l=o.encodeDST?{DST:o.encodeDST}:{},u=Object.assign({},o,l,f),a=po(c,1,u),h=i(a[0]);return s(h)},mapToCurve(c){if(o.m===1){if(typeof c!="bigint")throw new Error("expected bigint (m=1)");return s(i([c]))}if(!Array.isArray(c))throw new Error("expected array of bigints");for(let f of c)if(typeof f!="bigint")throw new Error("expected array of bigints");return s(i(c))},hashToScalar(c,f){let l=n.Fn.ORDER,u=Object.assign({},o,{p:l,m:1,DST:Uf},f);return po(c,1,u)[0][0]}})}var vf,Uf,ps=St(()=>{C();De();an();vf=_t;Uf="HashToScalar-"});function go(n){Mt(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"}),ns(n.Point);let{Point:t}=n,e=n.Fn===void 0?t.Fn:n.Fn,r=n.hash,o=n.hashToScalar===void 0?(g,x={DST:new Uint8Array})=>{let v=r(it(x.DST,g));return e.create(e.isLE?on(v):_t(v))}:n.hashToScalar,i=le(n.H1!==void 0?n.H1:n.name+"rho"),s=le(n.H2!==void 0?n.H2:n.name+"chal"),c=le(n.H3!==void 0?n.H3:n.name+"nonce"),f=le(n.H4!==void 0?n.H4:n.name+"msg"),l=le(n.H5!==void 0?n.H5:n.name+"com"),u=le(n.HDKG!==void 0?n.HDKG:n.name+"dkg"),a=le(n.HID!==void 0?n.HID:n.name+"id"),h=g=>o(g,{DST:i}),d=g=>o(g,{DST:s}),p=g=>o(g,{DST:c}),m=g=>r(it(f,g)),w=g=>r(it(l,g)),E=g=>o(g,{DST:u}),B=g=>o(g,{DST:a}),I=(g=Nt)=>{let x=un(g(Un(e.ORDER)),e.ORDER,e.isLE);return e.isLE?on(x):_t(x)},S=g=>g.toBytes(),T=g=>{let x=t.fromBytes(g);return n.validatePoint&&n.validatePoint(x),x},P=(g,x)=>({identifier:g,hiding:S(t.BASE.multiply(e.fromBytes(x.hiding))),binding:S(t.BASE.multiply(e.fromBytes(x.binding)))}),ft=n.adjustPoint===void 0?g=>g:n.adjustPoint,$=g=>{if(!e.isValid(g)||e.is0(g))throw new Error("Invalid identifier "+g);return g},z=g=>pe(e.toBytes($(g))),nt=g=>{let x=$(e.fromBytes(rn(g)));if(z(x)!==g)throw new Error("expected canonical identifier hex");return x},W={encode:(g,x)=>{let v=it(S(g),e.toBytes(x));return n.adjustTx&&(v=n.adjustTx.encode(v)),v},decode:g=>{n.adjustTx&&(g=n.adjustTx.decode(g));let x=T(g.subarray(0,-e.BYTES)),v=e.fromBytes(g.subarray(-e.BYTES));return{R:x,z:v}}},rt=(g=Nt)=>{let x=I(g);n.adjustScalar&&(x=n.adjustScalar(x));let v=t.BASE.multiply(x);return{scalar:x,point:v}},F="roots are unavailable in FROST polynomial mode",N={info:{G:e.ZERO,oddFactor:e.ZERO,powerOfTwo:0},roots(){throw new Error(F)},brp(){throw new Error(F)},inverse(){throw new Error(F)},omega(){throw new Error(F)},clear(){}},U=us(e,N),A=(g,x)=>ss(t,g,x),L=(g,x)=>{if(!x.length)throw new Error("empty coefficients");return U.monomial.eval(x,g)},k=(g,x)=>{let v="invalid parameters";if(!g.some(M=>e.eql(M,x)))throw new Error(v);let R=new Set(g);if(R.size!==g.length)throw new Error(v);if(!R.has(x))throw new Error(v);let _=e.ONE,H=e.ONE;for(let M of g)e.eql(M,x)||(_=e.mul(_,M),H=e.mul(H,e.sub(M,x)));return e.div(_,H)},D=(g,x)=>{let v=U.monomial.basis(g,x.length);return A(x,v)},O=(g,x,v,R=Nt)=>{Er(g);let _=x===void 0?I(R):e.fromBytes(x);if(!v){v=[];for(let V=0;V<g.min-1;V++)v.push(I(R))}if(v.length!==g.min-1)throw new Error("wrong coefficients length");let H=[_,...v],M=H.map(V=>t.BASE.multiply(V));return{coefficients:H,commitment:M,secret:_}},q={challenge:(g,x,v)=>E(it(e.toBytes(g),S(x),S(v))),compute(g,x,v,R=Nt){if(x.length<1)throw new Error("coefficients should have at least one element");let{point:_,scalar:H}=rt(R),M=v[0],V=this.challenge(g,M,_),X=e.add(H,e.mul(x[0],V));return W.encode(_,X)},validate(g,x,v){if(x.length<1)throw new Error("commitment should have at least one element");let{R,z:_}=W.decode(v),H=T(x[0]),M=this.challenge(g,H,R);if(!R.equals(t.BASE.multiply(_).subtract(H.multiply(M))))throw new Error("invalid proof of knowledge")}},j={challenge:(g,x,v)=>n.challenge?n.challenge(g,x,v):d(it(S(g),S(x),v)),sign(g,x,v=Nt){let{point:R,scalar:_}=rt(v),H=t.BASE.multiply(x),M=this.challenge(R,H,g),V=e.add(_,e.mul(M,x));return[R,V]},verify(g,x,v,R){n.adjustPoint&&(R=n.adjustPoint(R)),n.adjustPoint&&(x=n.adjustPoint(x));let _=this.challenge(x,R,g),H=t.BASE.multiply(v),M=R.multiply(_),V=H.subtract(M).subtract(x);return V.clearCofactor&&(V=V.clearCofactor()),t.ZERO.equals(V)}},ht=(g,x,v)=>{if(!t.BASE.multiply(v).equals(D(g,x)))throw new Error("invalid secret share")},ut={fromNumber(g){if(!Number.isSafeInteger(g))throw new Error("expected safe interger");return z(BigInt(g))},derive(g){if(typeof g!="string")throw new Error("wrong identifier string: "+g);return z(B(le(g)))}},J=(g,x=Nt)=>p(it(x(32),e.toBytes(g))),wt=(g,x,v)=>{let R=x.map(gt=>[gt.identifier,nt(gt.identifier),T(gt.hiding),T(gt.binding)]);R.sort((gt,Z)=>gt[1]<Z[1]?-1:gt[1]>Z[1]?1:0);let _=[];for(let[gt,Z,mt,Ft]of R)_.push(e.toBytes(Z),S(mt),S(Ft));let H=w(it(..._)),M=it(S(g),m(v),H),V={};for(let[gt,Z]of R)V[gt]=h(it(M,e.toBytes(Z)));let X=[],et=[];for(let[gt,Z,mt,Ft]of R){if(t.ZERO.equals(mt)||t.ZERO.equals(Ft))throw new Error("infinity commitment");X.push(mt,Ft),et.push(e.ONE,V[gt])}let Tt=A(X,et);return{identifiers:R.map(gt=>gt[1]),groupCommitment:Tt,bindingFactors:V}},dt=(g,x,v,R)=>{let _=ft(T(g)),H=nt(R),{identifiers:M,groupCommitment:V,bindingFactors:X}=wt(_,x,v),et=X[R],Tt=k(M,H),ie=j.challenge(V,_,v);return{lambda:Tt,challenge:ie,bindingFactor:et,groupCommitment:V}};Object.freeze(ut);let Lt={Identifier:ut,DKG:Object.freeze({round1:(g,x,v,R=Nt)=>{Er(x);let _=nt(g),{coefficients:H,commitment:M}=O(x,v,void 0,R),V=q.compute(_,H,M,R),X=M.map(S),et={identifier:z(_),commitment:X,proofOfKnowledge:V},Tt={identifier:_,coefficients:H,commitment:M.map(S),signers:{min:x.min,max:x.max},step:1};return{public:et,secret:Tt}},round2:(g,x)=>{if(x.length!==g.signers.max-1)throw new Error("wrong number of round1 packages");if(!g.coefficients||g.step===3)throw new Error("round3 package used in round2");let v={};for(let R of x){if(R.commitment.length!==g.signers.min)throw new Error("wrong number of commitments");let _=nt(R.identifier);if(_===g.identifier)throw new Error("duplicate id="+z(_));q.validate(_,R.commitment,R.proofOfKnowledge);for(let M of R.commitment)T(M);if(v[R.identifier])throw new Error("Duplicate id="+_);let H=e.toBytes(L(_,g.coefficients));v[R.identifier]={identifier:z(g.identifier),signingShare:H}}return g.step=2,v},round3:(g,x,v)=>{if(x.length!==g.signers.max-1)throw new Error("wrong length of round1 packages");if(!g.coefficients||g.step!==2)throw new Error("round2 package used in round3");if(v.length!==x.length)throw new Error("wrong length of round2 packages");let R={};for(let Z of x){if(!Z.identifier||!Z.commitment)throw new Error("wrong round1 share");R[Z.identifier]={...Z}}for(let Z of v){if(!Z.identifier||!Z.signingShare)throw new Error("wrong round2 share");if(!R[Z.identifier])throw new Error("round1 share for "+Z.identifier+" is missing");R[Z.identifier].signingShare=Z.signingShare}if(Object.keys(R).length!==x.length)throw new Error("mismatch identifiers between rounds");let _=e.ZERO;if(g.commitment.length!==g.signers.min)throw new Error("wrong commitments length");let H=g.commitment.map(T),M=L(g.identifier,g.coefficients);ht(g.identifier,H,M);let V=H.map(S),X={[z(g.identifier)]:V};for(let Z in R){let mt=R[Z];if(!mt.signingShare||!mt.commitment)throw new Error("mismatch identifiers");let Ft=nt(Z),Ye=e.fromBytes(mt.signingShare),kr=mt.commitment.map(T);ht(g.identifier,kr,Ye),_=e.add(_,Ye);let En=z(Ft);if(X[En])throw new Error("duplicated id="+En);X[En]=mt.commitment}_=e.add(_,M);let et=new Array(g.signers.min).fill(t.ZERO);for(let Z in X){let mt=X[Z];if(mt.length!==g.signers.min)throw new Error("wrong commitments length");for(let Ft=0;Ft<mt.length;Ft++)et[Ft]=et[Ft].add(T(mt[Ft]))}let Tt=et.map(S),ie={};for(let Z in X)ie[Z]=S(D(nt(Z),et));let gt={public:{signers:{min:g.signers.min,max:g.signers.max},commitments:Tt,verifyingShares:Object.fromEntries(Object.entries(ie).map(([Z,mt])=>[Z,mt.slice()]))},secret:{identifier:z(g.identifier),signingShare:e.toBytes(_)}};n.adjustDKG&&(gt=n.adjustDKG(gt));for(let Z=0;Z<g.coefficients.length;Z++)g.coefficients[Z]-=g.coefficients[Z];return delete g.coefficients,g.step=3,gt},clean(g){if(g.identifier-=g.identifier,g.coefficients)for(let x=0;x<g.coefficients.length;x++)g.coefficients[x]-=g.coefficients[x];g.step=3}}),trustedDealer(g,x,v,R=Nt){if(Er(g),x===void 0){x=[];for(let et=1;et<=g.max;et++)x.push(ut.fromNumber(et))}else if(!Array.isArray(x)||x.length!==g.max)throw new Error("identifiers should be array of "+g.max);let _={};for(let et of x){let Tt=nt(et);if(et in _)throw new Error("duplicated id="+et);_[et]=Tt}let H=O(g,v,void 0,R),M=H.commitment.map(S),V={},X={};for(let et of x){let Tt=L(_[et],H.coefficients);X[et]=S(t.BASE.multiply(Tt)),V[et]={identifier:et,signingShare:e.toBytes(Tt)}}return{public:{signers:{min:g.min,max:g.max},commitments:M,verifyingShares:X},secretShares:V}},validateSecret(g,x){let v=nt(g.identifier),R=x.commitments.map(T),_=e.fromBytes(g.signingShare);ht(v,R,_)},commit(g,x=Nt){let v=e.fromBytes(g.signingShare),R=J(v,x),_=J(v,x),H={hiding:e.toBytes(R),binding:e.toBytes(_)};return{nonces:H,commitments:P(g.identifier,H)}},signShare(g,x,v,R,_){gs(x.signers,R.length);let H=e.fromBytes(v.hiding),M=e.fromBytes(v.binding);if(e.is0(H)||e.is0(M))throw new Error("signing nonces already used");let V={identifier:g.identifier,hiding:S(t.BASE.multiply(H)),binding:S(t.BASE.multiply(M))},X=R.find(pc=>pc.identifier===g.identifier);if(!X)throw new Error("missing signer commitment");if(pe(X.hiding)!==pe(V.hiding)||pe(X.binding)!==pe(V.binding))throw new Error("incorrect signer commitment");n.adjustSecret&&(g=n.adjustSecret(g,x)),n.adjustPublic&&(x=n.adjustPublic(x));let et=e.fromBytes(g.signingShare),{lambda:Tt,challenge:ie,bindingFactor:gt,groupCommitment:Z}=dt(x.commitments[0],R,_,g.identifier),mt=n.adjustNonces?n.adjustNonces(Z,v):v,Ft=n.adjustNonces?e.fromBytes(mt.hiding):H,Ye=n.adjustNonces?e.fromBytes(mt.binding):M,kr=e.mul(e.mul(Tt,et),ie),En=e.mul(Ye,gt),dc=e.toBytes(e.add(e.add(Ft,En),kr));return v.hiding.fill(0),v.binding.fill(0),dc},verifyShare(g,x,v,R,_){n.adjustPublic&&(g=n.adjustPublic(g));let H=x.find(Ye=>Ye.identifier===R);if(!H)throw new Error("cannot find identifier commitment");let M=T(g.verifyingShares[R]),V=T(H.hiding),X=T(H.binding),{lambda:et,challenge:Tt,bindingFactor:ie,groupCommitment:gt}=dt(g.commitments[0],x,v,R),Z=V.add(X.multiply(ie));n.adjustGroupCommitmentShare&&(Z=n.adjustGroupCommitmentShare(gt,Z));let mt=t.BASE.multiply(e.fromBytes(_)),Ft=Z.add(M.multiply(e.mul(Tt,et)));return mt.equals(Ft)},aggregate(g,x,v,R){n.adjustPublic&&(g=n.adjustPublic(g));try{gs(g.signers,x.length)}catch{throw new hn("aggregation failed",[])}let _=x.map(X=>X.identifier);if(_.length!==Object.keys(R).length)throw new hn("aggregation failed",[]);for(let X of _)if(!(X in R)||!(X in g.verifyingShares))throw new hn("aggregation failed",[]);let H=T(g.commitments[0]),{groupCommitment:M}=wt(H,x,v),V=e.ZERO;for(let X of _)V=e.add(V,e.fromBytes(R[X]));if(!j.verify(v,M,V,H)){let X=[];for(let et of _)this.verifyShare(g,x,v,et,R[et])||X.push(et);throw new hn("aggregation failed",X)}return W.encode(M,V)},sign(g,x){let v=e.fromBytes(x);n.adjustScalar&&(v=n.adjustScalar(v));let[R,_]=j.sign(g,v);return W.encode(R,_)},verify(g,x,v){let R=n.parsePublicKey?n.parsePublicKey(v):T(v),{R:_,z:H}=W.decode(g);return j.verify(x,_,H,R)},combineSecret(g,x){if(Er(x),!Array.isArray(g)||g.length<x.min)throw new Error("wrong secret shares array");let v=[],R={};for(let M of g){let V=nt(M.identifier),X=z(V);if(R[X])throw new Error("duplicated id="+X);R[X]=!0,v.push([V,e.fromBytes(M.signingShare)])}let _=v.map(([M])=>M),H=e.ZERO;for(let[M,V]of v)H=e.add(H,e.mul(V,k(_,M)));return e.toBytes(H)},utils:Object.freeze({Fn:e,randomScalar:(g=Nt)=>e.toBytes(rt(g).scalar),generateSecretPolynomial:(g,x,v,R)=>{let _=O(g,x,v,R);return{..._,commitment:_.commitment.map(S)}}})};return Object.freeze(Lt)}var Er,gs,hn,ms=St(()=>{C();be();De();br();as();an();Er=n=>{if(!Number.isSafeInteger(n.min)||!Number.isSafeInteger(n.max))throw new Error("Wrong signers info: min="+n.min+" max="+n.max);if(n.min<2||n.max<2||n.min>n.max)throw new Error("Wrong signers info: min="+n.min+" max="+n.max)},gs=(n,t)=>{if(t<n.min||t>n.max)throw new Error("Wrong number of commitments="+t)},hn=class extends Error{constructor(e,r){super(e);y(this,"cheaters");this.cheaters=r}}});var yo={};Gn(yo,{_HMAC:()=>_n,hmac:()=>mo});var _n,mo,Br=St(()=>{C();be();_n=class{constructor(t,e){y(this,"oHash");y(this,"iHash");y(this,"blockLen");y(this,"outputLen");y(this,"canXOF",!1);y(this,"finished",!1);y(this,"destroyed",!1);if(Jn(t),Qt(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");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),ae(o)}update(t){return en(this),this.iHash.update(t),this}digestInto(t){en(this),tr(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:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=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()}},mo=(()=>{let n=((t,e,r)=>new _n(t,e).update(r).digest());return n.create=(t,e)=>new _n(t,e),n})()});function Rf(n,t,e){oo("scalar",n,Kt,e);let[[r,o],[i,s]]=t,c=ys(s*n,e),f=ys(-o*n,e),l=n-c*r-f*i,u=-c*o-f*s,a=l<Kt,h=u<Kt;a&&(l=-l),h&&(u=-u);let d=cn(Math.ceil(He(e)/2))+Et;if(l<Kt||l>=d||u<Kt||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:a,k1:l,k2neg:h,k2:u}}function xo(n){if(!["compact","recovered","der"].includes(n))throw new Error('Signature format must be "compact", "recovered", or "der"');return n}function wo(n,t){Mt(n);let e={};for(let r of Object.keys(t))e[r]=n[r]===void 0?t[r]:n[r];return Ne(e.lowS,"lowS"),Ne(e.prehash,"prehash"),e.format!==void 0&&xo(e.format),e}function ws(n,t={}){let e=cs("weierstrass",n,t),r=e.Fp,o=e.Fn,i=e.CURVE,{h:s,n:c}=i;Mt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:l}=t;if(f&&(!r.is0(i.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Es(r,o);function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(rt,F,N){if(l&&F.is0())return Uint8Array.of(0);let{x:U,y:A}=F.toAffine(),L=r.toBytes(U);if(Ne(N,"isCompressed"),N){a();let k=!r.isOdd(A);return it(xs(k),L)}else return it(Uint8Array.of(4),L,r.toBytes(A))}function d(rt){at(rt,void 0,"Point");let{publicKey:F,publicKeyUncompressed:N}=u,U=rt.length,A=rt[0],L=rt.subarray(1);if(l&&U===1&&A===0)return{x:r.ZERO,y:r.ZERO};if(U===F&&(A===2||A===3)){let k=r.fromBytes(L);if(!r.isValid(k))throw new Error("bad point: is not on curve, wrong x");let D=w(k),O;try{O=r.sqrt(D)}catch(ht){let ut=ht instanceof Error?": "+ht.message:"";throw new Error("bad point: is not on curve, sqrt error"+ut)}a();let q=r.isOdd(O);return(A&1)===1!==q&&(O=r.neg(O)),{x:k,y:O}}else if(U===N&&A===4){let k=r.BYTES,D=r.fromBytes(L.subarray(0,k)),O=r.fromBytes(L.subarray(k,k*2));if(!E(D,O))throw new Error("bad point: is not on curve");return{x:D,y:O}}else throw new Error(`bad point: got length ${U}, expected compressed=${F} or uncompressed=${N}`)}let p=t.toBytes===void 0?h:t.toBytes,m=t.fromBytes===void 0?d:t.fromBytes;function w(rt){let F=r.sqr(rt),N=r.mul(F,rt);return r.add(r.add(N,r.mul(rt,i.a)),i.b)}function E(rt,F){let N=r.sqr(F),U=w(rt);return r.eql(N,U)}if(!E(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let B=r.mul(r.pow(i.a,dn),Eo),I=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(B,I)))throw new Error("bad curve params: a or b");function S(rt,F,N=!1){if(!r.isValid(F)||N&&r.is0(F))throw new Error(`bad point coordinate ${rt}`);return F}function T(rt){if(!(rt instanceof $))throw new Error("Weierstrass Point expected")}function P(rt){if(!f||!f.basises)throw new Error("no endo");return Rf(rt,f.basises,o.ORDER)}function ft(rt,F,N,U,A){return N=new $(r.mul(N.X,rt),N.Y,N.Z),F=Rn(U,F),N=Rn(A,N),F.add(N)}let W=class W{constructor(F,N,U){y(this,"X");y(this,"Y");y(this,"Z");this.X=S("x",F),this.Y=S("y",N,!0),this.Z=S("z",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(F){let{x:N,y:U}=F||{};if(!F||!r.isValid(N)||!r.isValid(U))throw new Error("invalid affine point");if(F instanceof W)throw new Error("projective point not allowed");return r.is0(N)&&r.is0(U)?W.ZERO:new W(N,U,r.ONE)}static fromBytes(F){let N=W.fromAffine(m(at(F,void 0,"point")));return N.assertValidity(),N}static fromHex(F){return W.fromBytes(rn(F))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(F=8,N=!0){return nt.createCache(this,F),N||this.multiply(dn),this}assertValidity(){let F=this;if(F.is0()){if(t.allowInfinityPoint&&r.is0(F.X)&&r.eql(F.Y,r.ONE)&&r.is0(F.Z))return;throw new Error("bad point: ZERO")}let{x:N,y:U}=F.toAffine();if(!r.isValid(N)||!r.isValid(U))throw new Error("bad point: x or y not field elements");if(!E(N,U))throw new Error("bad point: equation left != right");if(!F.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:F}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(F)}equals(F){T(F);let{X:N,Y:U,Z:A}=this,{X:L,Y:k,Z:D}=F,O=r.eql(r.mul(N,D),r.mul(L,A)),q=r.eql(r.mul(U,D),r.mul(k,A));return O&&q}negate(){return new W(this.X,r.neg(this.Y),this.Z)}double(){let{a:F,b:N}=i,U=r.mul(N,dn),{X:A,Y:L,Z:k}=this,D=r.ZERO,O=r.ZERO,q=r.ZERO,j=r.mul(A,A),ht=r.mul(L,L),ut=r.mul(k,k),J=r.mul(A,L);return J=r.add(J,J),q=r.mul(A,k),q=r.add(q,q),D=r.mul(F,q),O=r.mul(U,ut),O=r.add(D,O),D=r.sub(ht,O),O=r.add(ht,O),O=r.mul(D,O),D=r.mul(J,D),q=r.mul(U,q),ut=r.mul(F,ut),J=r.sub(j,ut),J=r.mul(F,J),J=r.add(J,q),q=r.add(j,j),j=r.add(q,j),j=r.add(j,ut),j=r.mul(j,J),O=r.add(O,j),ut=r.mul(L,k),ut=r.add(ut,ut),j=r.mul(ut,J),D=r.sub(D,j),q=r.mul(ut,ht),q=r.add(q,q),q=r.add(q,q),new W(D,O,q)}add(F){T(F);let{X:N,Y:U,Z:A}=this,{X:L,Y:k,Z:D}=F,O=r.ZERO,q=r.ZERO,j=r.ZERO,ht=i.a,ut=r.mul(i.b,dn),J=r.mul(N,L),wt=r.mul(U,k),dt=r.mul(A,D),Lt=r.add(N,U),g=r.add(L,k);Lt=r.mul(Lt,g),g=r.add(J,wt),Lt=r.sub(Lt,g),g=r.add(N,A);let x=r.add(L,D);return g=r.mul(g,x),x=r.add(J,dt),g=r.sub(g,x),x=r.add(U,A),O=r.add(k,D),x=r.mul(x,O),O=r.add(wt,dt),x=r.sub(x,O),j=r.mul(ht,g),O=r.mul(ut,dt),j=r.add(O,j),O=r.sub(wt,j),j=r.add(wt,j),q=r.mul(O,j),wt=r.add(J,J),wt=r.add(wt,J),dt=r.mul(ht,dt),g=r.mul(ut,g),wt=r.add(wt,dt),dt=r.sub(J,dt),dt=r.mul(ht,dt),g=r.add(g,dt),J=r.mul(wt,g),q=r.add(q,J),J=r.mul(x,g),O=r.mul(Lt,O),O=r.sub(O,J),J=r.mul(Lt,wt),j=r.mul(x,j),j=r.add(j,J),new W(O,q,j)}subtract(F){return T(F),this.add(F.negate())}is0(){return this.equals(W.ZERO)}multiply(F){let{endo:N}=t;if(!o.isValidNot0(F))throw new RangeError("invalid scalar: out of range");let U,A,L=k=>nt.cached(this,k,D=>lo(W,D));if(N){let{k1neg:k,k1:D,k2neg:O,k2:q}=P(F),{p:j,f:ht}=L(D),{p:ut,f:J}=L(q);A=ht.add(J),U=ft(N.beta,j,ut,k,O)}else{let{p:k,f:D}=L(F);U=k,A=D}return lo(W,[U,A])[0]}multiplyUnsafe(F){let{endo:N}=t,U=this,A=F;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===Kt||U.is0())return W.ZERO;if(A===Et)return U;if(nt.hasCache(this))return this.multiply(A);if(N){let{k1neg:L,k1:k,k2neg:D,k2:O}=P(A),{p1:q,p2:j}=is(W,U,k,O);return ft(N.beta,q,j,L,D)}else return nt.unsafe(U,A)}toAffine(F){let N=this,U=F,{X:A,Y:L,Z:k}=N;if(r.eql(k,r.ONE))return{x:A,y:L};let D=N.is0();U==null&&(U=D?r.ONE:r.inv(k));let O=r.mul(A,U),q=r.mul(L,U),j=r.mul(k,U);if(D)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:O,y:q}}isTorsionFree(){let{isTorsionFree:F}=t;return s===Et?!0:F?F(W,this):nt.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:F}=t;return s===Et?this:F?F(W,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Et?this.is0():this.clearCofactor().is0()}toBytes(F=!0){return Ne(F,"isCompressed"),this.assertValidity(),p(W,this,F)}toHex(F=!0){return pe(this.toBytes(F))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};y(W,"BASE",new W(i.Gx,i.Gy,r.ONE)),y(W,"ZERO",new W(r.ZERO,r.ONE,r.ZERO)),y(W,"Fp",r),y(W,"Fn",o);let $=W,z=o.BITS,nt=new wr($,t.endo?Math.ceil(z/2):z);return z>=8&&$.BASE.precompute(8),Object.freeze($.prototype),Object.freeze($),$}function xs(n){return Uint8Array.of(n?2:3)}function _f(n,t){let e=qe(n),r=e.ORDER,o=Kt;for(let m=r-Et;m%te===Kt;m/=te)o+=Et;let i=o,s=te<<i-Et-Et,c=s*te,f=(r-Et)/c,l=(f-Et)/te,u=c-Et,a=s,h=e.pow(t,f),d=e.pow(t,(f+Et)/te),p=(m,w)=>{let E=h,B=e.pow(w,u),I=e.sqr(B);I=e.mul(I,w);let S=e.mul(m,I);S=e.pow(S,l),S=e.mul(S,B),B=e.mul(S,w),I=e.mul(S,m);let T=e.mul(I,B);S=e.pow(T,a);let P=e.eql(S,e.ONE);B=e.mul(I,d),S=e.mul(T,E),I=e.cmov(B,I,P),T=e.cmov(S,T,P);for(let ft=i;ft>Et;ft--){let $=ft-te;$=te<<$-Et;let z=e.pow(T,$),nt=e.eql(z,e.ONE);B=e.mul(I,E),E=e.mul(E,E),z=e.mul(T,E),I=e.cmov(B,I,nt),T=e.cmov(z,T,nt)}return{isValid:!e.is0(w)&&(P||e.is0(m)),value:I}};if(e.ORDER%Eo===dn){let m=(e.ORDER-dn)/Eo,w=e.sqrt(e.neg(t));p=(E,B)=>{let I=e.sqr(B),S=e.mul(E,B);I=e.mul(I,S);let T=e.pow(I,m);T=e.mul(T,S);let P=e.mul(T,w),ft=e.mul(e.sqr(T),B),$=e.eql(ft,E),z=e.cmov(P,T,$);return{isValid:!e.is0(B)&&$,value:z}}}return p}function bs(n,t){let e=qe(n),{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))||co(e,i))throw new Error("mapToCurveSimpleSWU: invalid opts");let s=e.mul(o,e.inv(e.mul(i,r))),c=e.add(e.add(e.mul(e.sqr(s),s),e.mul(r,s)),o);if(!co(e,c))throw new Error("mapToCurveSimpleSWU: invalid opts");let f=_f(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return l=>{let u,a,h,d,p,m,w,E;u=e.sqr(l),u=e.mul(u,i),a=e.sqr(u),a=e.add(a,u),h=e.add(a,e.ONE),h=e.mul(h,o),d=e.cmov(i,e.neg(a),!e.eql(a,e.ZERO)),d=e.mul(d,r),a=e.sqr(h),m=e.sqr(d),p=e.mul(m,r),a=e.add(a,p),a=e.mul(a,h),m=e.mul(m,d),p=e.mul(m,o),a=e.add(a,p),w=e.mul(u,h);let{isValid:B,value:I}=f(a,m);E=e.mul(u,l),E=e.mul(E,I),w=e.cmov(w,h,B),E=e.cmov(E,I,B);let S=e.isOdd(l)===e.isOdd(E);E=e.cmov(e.neg(E),E,S);let T=Pe(e,[d],!0)[0];return w=e.mul(w,T),{x:w,y:E}}}function Es(n,t){return{secretKey:t.BYTES,publicKey:1+n.BYTES,publicKeyUncompressed:1+2*n.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Of(n,t={}){let{Fn:e}=n,r=t.randomBytes===void 0?Nt:t.randomBytes,o=Object.assign(Es(n.Fp,e),{seed:Math.max(Un(e.ORDER),16)});function i(d){try{let p=e.fromBytes(d);return e.isValidNot0(p)}catch{return!1}}function s(d,p){let{publicKey:m,publicKeyUncompressed:w}=o;try{let E=d.length;return p===!0&&E!==m||p===!1&&E!==w?!1:!!n.fromBytes(d)}catch{return!1}}function c(d){return d=d===void 0?r(o.seed):d,un(at(d,o.seed,"seed"),e.ORDER)}function f(d,p=!0){return n.BASE.multiply(e.fromBytes(d)).toBytes(p)}function l(d){let{secretKey:p,publicKey:m,publicKeyUncompressed:w}=o,E=e._lengths;if(!ke(d))return;let B=at(d,void 0,"key").length,I=B===m||B===w,S=B===p||!!E?.includes(B);if(!(I&&S))return I}function u(d,p,m=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");let w=e.fromBytes(d);return n.fromBytes(p).multiply(w).toBytes(m)}let a={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},h=xr(c,f);return Object.freeze(a),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:h,Point:n,utils:a,lengths:o})}function Bs(n,t,e={}){let r=t;Jn(r),Mt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Nt:e.randomBytes,i=e.hmac===void 0?(U,A)=>mo(r,U,A):e.hmac,{Fp:s,Fn:c}=n,{ORDER:f,BITS:l}=c,{keygen:u,getPublicKey:a,getSharedSecret:h,utils:d,lengths:p}=Of(n,e),m={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},w=f*te+Et<s.ORDER;function E(U){let A=f>>Et;return U>A}function B(U,A){if(!c.isValidNot0(A))throw new Error(`invalid signature ${U}: out of range 1..Point.Fn.ORDER`);return A}function I(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function S(U,A){xo(A);let L=p.signature,k=A==="compact"?L:A==="recovered"?L+1:void 0;return at(U,k)}class T{constructor(A,L,k){y(this,"r");y(this,"s");y(this,"recovery");if(this.r=B("r",A),this.s=B("s",L),k!=null){if(I(),![0,1,2,3].includes(k))throw new Error("invalid recovery id");this.recovery=k}Object.freeze(this)}static fromBytes(A,L=m.format){S(A,L);let k;if(L==="der"){let{r:j,s:ht}=Zt.toSig(at(A));return new T(j,ht)}L==="recovered"&&(k=A[0],L="compact",A=A.subarray(1));let D=p.signature/2,O=A.subarray(0,D),q=A.subarray(D,D*2);return new T(c.fromBytes(O),c.fromBytes(q),k)}static fromHex(A,L){return this.fromBytes(rn(A),L)}assertRecovery(){let{recovery:A}=this;if(A==null)throw new Error("invalid recovery id: must be present");return A}addRecoveryBit(A){return new T(this.r,this.s,A)}recoverPublicKey(A){let{r:L,s:k}=this,D=this.assertRecovery(),O=D===2||D===3?L+f:L;if(!s.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let q=s.toBytes(O),j=n.fromBytes(it(xs((D&1)===0),q)),ht=c.inv(O),ut=ft(at(A,void 0,"msgHash")),J=c.create(-ut*ht),wt=c.create(k*ht),dt=n.BASE.multiplyUnsafe(J).add(j.multiplyUnsafe(wt));if(dt.is0())throw new Error("invalid recovery: point at infinify");return dt.assertValidity(),dt}hasHighS(){return E(this.s)}toBytes(A=m.format){if(xo(A),A==="der")return rn(Zt.hexFromSig(this));let{r:L,s:k}=this,D=c.toBytes(L),O=c.toBytes(k);return A==="recovered"?(I(),it(Uint8Array.of(this.assertRecovery()),D,O)):it(D,O)}toHex(A){return pe(this.toBytes(A))}}Object.freeze(T.prototype),Object.freeze(T);let P=e.bits2int===void 0?function(A){if(A.length>8192)throw new Error("input is too large");let L=_t(A),k=A.length*8-l;return k>0?L>>BigInt(k):L}:e.bits2int,ft=e.bits2int_modN===void 0?function(A){return c.create(P(A))}:e.bits2int_modN,$=cn(l);function z(U){return oo("num < 2^"+l,U,Kt,$),c.toBytes(U)}function nt(U,A){return at(U,void 0,"message"),A?at(r(U),void 0,"prehashed message"):U}function W(U,A,L){let{lowS:k,prehash:D,extraEntropy:O}=wo(L,m);U=nt(U,D);let q=ft(U),j=c.fromBytes(A);if(!c.isValidNot0(j))throw new Error("invalid private key");let ht=[z(j),z(q)];if(O!=null&&O!==!1){let dt=O===!0?o(p.secretKey):O;ht.push(at(dt,void 0,"extraEntropy"))}let ut=it(...ht),J=q;function wt(dt){let Lt=P(dt);if(!c.isValidNot0(Lt))return;let g=c.inv(Lt),x=n.BASE.multiply(Lt).toAffine(),v=c.create(x.x);if(v===Kt)return;let R=c.create(g*c.create(J+v*j));if(R===Kt)return;let _=(x.x===v?0:2)|Number(x.y&Et),H=R;return k&&E(R)&&(H=c.neg(R),_^=1),new T(v,H,w?void 0:_)}return{seed:ut,k2sig:wt}}function rt(U,A,L={}){let{seed:k,k2sig:D}=W(U,A,L);return Mi(r.outputLen,c.BYTES,i)(k,D).toBytes(L.format)}function F(U,A,L,k={}){let{lowS:D,prehash:O,format:q}=wo(k,m);if(L=at(L,void 0,"publicKey"),A=nt(A,O),!ke(U)){let j=U instanceof T?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+j)}S(U,q);try{let j=T.fromBytes(U,q),ht=n.fromBytes(L);if(D&&j.hasHighS())return!1;let{r:ut,s:J}=j,wt=ft(A),dt=c.inv(J),Lt=c.create(wt*dt),g=c.create(ut*dt),x=n.BASE.multiplyUnsafe(Lt).add(ht.multiplyUnsafe(g));return x.is0()?!1:c.create(x.x)===ut}catch{return!1}}function N(U,A,L={}){let{prehash:k}=wo(L,m);return A=nt(A,k),T.fromBytes(U,"recovered").recoverPublicKey(A).toBytes()}return Object.freeze({keygen:u,getPublicKey:a,getSharedSecret:h,utils:d,lengths:p,Point:n,sign:rt,verify:F,recoverPublicKey:N,Signature:T,hash:r})}var ys,bo,Zt,Kt,Et,te,dn,Eo,Ss=St(()=>{C();Br();be();De();br();an();ys=(n,t)=>(n+(n>=0?t:-t)/te)/t;bo=class extends Error{constructor(t=""){super(t)}},Zt={Err:bo,_tlv:{encode:(n,t)=>{let{Err:e}=Zt;if(Pt(n,"tag"),n<0||n>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let r=t.length/2,o=Fn(r);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let i=r>127?Fn(o.length/2|128):"";return Fn(n)+i+o+t},decode(n,t){let{Err:e}=Zt;t=at(t,void 0,"DER data");let r=0;if(n<0||n>255)throw new e("tlv.encode: 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 f=o&127;if(!f)throw new e("tlv.decode(long): indefinite length not supported");if(f>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(r,r+f);if(l.length!==f)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(r+=f,s<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(r,r+s);if(c.length!==s)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(r+s)}}},_int:{encode(n){let{Err:t}=Zt;if(pr(n),n<Kt)throw new t("integer: negative integers are not allowed");let e=Fn(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}=Zt;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 _t(n)}},toSig(n){let{Err:t,_int:e,_tlv:r}=Zt,o=at(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:c,l:f}=r.decode(2,i),{v:l,l:u}=r.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(n){let{_tlv:t,_int:e}=Zt,r=t.encode(2,e.encode(n.r)),o=t.encode(2,e.encode(n.s)),i=r+o;return t.encode(48,i)}};Object.freeze(Zt._tlv);Object.freeze(Zt._int);Object.freeze(Zt);Kt=BigInt(0),Et=BigInt(1),te=BigInt(2),dn=BigInt(3),Eo=BigInt(4)});var Io={};Gn(Io,{__TEST:()=>Hf,schnorr:()=>Df,schnorr_FROST:()=>Vf,secp256k1:()=>kf,secp256k1_FROST:()=>Pf,secp256k1_hasher:()=>Ao});function Cf(n){let t=Sr.p,e=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),f=BigInt(88),l=n*n*n%t,u=l*l*n%t,a=Dt(u,e,t)*u%t,h=Dt(a,e,t)*u%t,d=Dt(h,Bo,t)*l%t,p=Dt(d,o,t)*d%t,m=Dt(p,i,t)*p%t,w=Dt(m,c,t)*m%t,E=Dt(w,f,t)*w%t,B=Dt(E,c,t)*m%t,I=Dt(B,e,t)*u%t,S=Dt(I,s,t)*p%t,T=Dt(S,r,t)*l%t,P=Dt(T,Bo,t);if(!ge.eql(ge.sqr(P),n))throw new Error("Cannot find square root");return P}function On(n,...t){let e=As[n];if(e===void 0){let r=Ae(sn(n));e=it(r,r),As[n]=e}return Ae(it(e,...t))}function Fs(n){let{Fn:t,BASE:e}=lt,r=t.fromBytes(n),o=e.multiply(r);return{scalar:ee(o.y)?r:t.neg(r),bytes:ze(o)}}function Ar(n){let t=ge;if(!t.isValidNot0(n))throw new Error("invalid x: Fail if x \u2265 p");let e=t.create(n*n),r=t.create(e*n+BigInt(7)),o=t.sqrt(r);ee(o)||(o=t.neg(o));let i=lt.fromAffine({x:n,y:o});return i.assertValidity(),i}function So(...n){return lt.Fn.create(pn(On("BIP0340/challenge",...n)))}function vs(n){return Fs(n).bytes}function Nf(n,t,e=An(32)){let{Fn:r,BASE:o}=lt,i=at(n,void 0,"message"),{bytes:s,scalar:c}=Fs(t),f=at(e,32,"auxRand"),l=r.toBytes(c^pn(On("BIP0340/aux",f))),u=On("BIP0340/nonce",l,s,i),a=r.create(pn(u));if(a===0n)throw new Error("sign failed: k is zero");let h=o.multiply(a),d=ee(h.y)?a:r.neg(a),p=ze(h),m=So(p,s,i),w=new Uint8Array(64);if(w.set(p,0),w.set(r.toBytes(r.create(d+m*c)),32),!Us(w,i,s))throw new Error("sign: Invalid signature produced");return w}function Us(n,t,e){let{Fp:r,Fn:o,BASE:i}=lt,s=at(n,64,"signature"),c=at(t,void 0,"message"),f=at(e,32,"publicKey");try{let l=Ar(pn(f)),u=pn(s.subarray(0,32));if(!r.isValidNot0(u))return!1;let a=pn(s.subarray(32,64));if(!o.isValidNot0(a))return!1;let h=So(o.toBytes(u),ze(l),c),d=i.multiplyUnsafe(a).add(l.multiplyUnsafe(o.neg(h))),{x:p,y:m}=d.toAffine();return!(d.is0()||!ee(m)||p!==u)}catch{return!1}}function Rs(n,t){if(t===void 0)return Ts;let e=ze(n),r=_t(On("TapTweak",e,t));if(!lt.Fn.isValid(r))throw new Error("invalid TapTweak hash");return r}function vo(n){let t=lt.fromBytes(n.commitments[0]);return ee(t.y)?n:{signers:{min:n.signers.min,max:n.signers.max},commitments:n.commitments.map(e=>lt.fromBytes(e).negate().toBytes()),verifyingShares:Object.fromEntries(Object.entries(n.verifyingShares).map(([e,r])=>[e,lt.fromBytes(r).negate().toBytes()]))}}function _s(n,t){let e=lt.fromBytes(t.commitments[0]);if(ee(e.y))return n;let r=lt.Fn;return{...n,signingShare:r.toBytes(r.neg(r.fromBytes(n.signingShare)))}}function Mf(n,t){if(ee(n.y))return t;let e=lt.Fn;return{binding:e.toBytes(e.neg(e.fromBytes(t.binding))),hiding:e.toBytes(e.neg(e.fromBytes(t.hiding)))}}function Kf(n,t,e){let r=lt.Fn,o=_s(n,t),i=vo(t),s=Rs(lt.fromBytes(i.commitments[0]),e),c=r.toBytes(r.add(r.fromBytes(o.signingShare),s));return{identifier:o.identifier,signingShare:c}}function zf(n,t){let e=vo(n),r=Rs(lt.fromBytes(e.commitments[0]),t),o=lt.BASE.multiply(r),i=e.commitments.map((c,f)=>(f===0?lt.fromBytes(c).add(o):lt.fromBytes(c)).toBytes()),s={};for(let c in e.verifyingShares)s[c]=lt.fromBytes(e.verifyingShares[c]).add(o).toBytes();return{signers:{min:e.signers.min,max:e.signers.max},commitments:i,verifyingShares:s}}var Sr,Lf,Ts,Bo,ge,lt,kf,As,ze,ee,pn,Hf,Df,jf,Is,qf,Ao,Pf,Vf,To=St(()=>{C();lr();be();br();ms();ps();an();Ss();De();Sr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Lf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ts=BigInt(0),Bo=BigInt(2);ge=fn(Sr.p,{sqrt:Cf}),lt=ws(Sr,{Fp:ge,endo:Lf}),kf=Bs(lt,Ae),As={};ze=n=>n.toBytes(!0).slice(1),ee=n=>n%Bo===Ts;pn=_t;Hf=Object.freeze({lift_x:Ar}),Df=(()=>{let e=r=>(r=r===void 0?An(48):r,un(r,Sr.n));return Object.freeze({keygen:xr(e,vs),getPublicKey:vs,sign:Nf,verify:Us,Point:lt,utils:Object.freeze({randomSecretKey:e,taggedHash:On,lift_x:Ar,pointToBytes:ze}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),jf=hs(ge,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(n=>n.map(t=>BigInt(t)))),qf=()=>Is||(Is=bs(ge,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:ge.create(BigInt("-11"))})),Ao=ds(lt,n=>{let{x:t,y:e}=qf()(ge.create(n[0]));return jf(t,e)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:ge.ORDER,m:1,k:128,expand:"xmd",hash:Ae}),Pf=go({name:"FROST-secp256k1-SHA256-v1",Point:lt,hashToScalar:Ao.hashToScalar,hash:Ae});Vf=go({name:"FROST-secp256k1-SHA256-TR-v1",Point:lt,hashToScalar:Ao.hashToScalar,hash:Ae,parsePublicKey(n){if(n.length===32)return Ar(_t(n));if(n.length===33)return lt.fromBytes(n);throw new Error(`expected x-only or compressed public key, got length=${n.length}`)},adjustScalar(n){let t=lt.BASE.multiply(n);return ee(t.y)?n:lt.Fn.neg(n)},adjustPoint:n=>ee(n.y)?n:n.negate(),challenge(n,t,e){return So(ze(n),ze(t),e)},adjustNonces:Mf,adjustGroupCommitmentShare:(n,t)=>ee(n.y)?t:t.negate(),adjustPublic:vo,adjustSecret:_s,adjustTx:{encode:n=>n.subarray(1),decode:n=>it(Uint8Array.of(2),n)},adjustDKG:n=>{let t=new Uint8Array(0);return{public:zf(n.public,t),secret:Kf(n.secret,n.public,t)}}})});function Zf(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}function $f(n){if(typeof n!="boolean")throw new TypeError(`boolean expected, not ${n}`)}function vr(n){if(typeof n!="number")throw new TypeError("number expected, got "+typeof n);if(!Number.isSafeInteger(n)||n<0)throw new RangeError("positive integer expected, got "+n)}function G(n,t,e=""){let r=Zf(n),o=n?.length,i=t!==void 0;if(!r||i&&o!==t){let s=e&&`"${e}" `,c=i?` of length ${t}`:"",f=r?`length=${o}`:`type=${typeof n}`,l=s+"expected Uint8Array"+c+", got "+f;throw r?new RangeError(l):new TypeError(l)}return n}function Ln(n,t=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(t&&n.finished)throw new Error("Hash#digest() has already been called")}function Cn(n,t,e=!1){G(n,void 0,"output");let r=t.outputLen;if(n.length<r)throw new RangeError("digestInto() expects output buffer of length at least "+r);if(e&&!Bt(n))throw new Error("invalid output, must be aligned")}function Ir(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 st(...n){for(let t=0;t<n.length;t++)n[t].fill(0)}function gn(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function Fo(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 kn(n,t){if(Fo(n,t)&&n.byteOffset<t.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Uo(...n){let t=0;for(let r=0;r<n.length;r++){let o=n[r];G(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 Nn(n,t){if(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 Hn(n,t,e){let r=t,o=e||(()=>[]),i=(c,f)=>r(f,...o(c)).update(c).digest(),s=r(new Uint8Array(n),...o(new Uint8Array(0)));return i.outputLen=s.outputLen,i.blockLen=s.blockLen,i.create=(c,...f)=>r(c,...f),i}function Ze(n,t,e=!0){if(t===void 0)return new Uint8Array(n);if(G(t,void 0,"output"),t.length!==n)throw new Error('"output" expected Uint8Array of length '+n+", got: "+t.length);if(e&&!Bt(t))throw new Error("invalid output, must be aligned");return t}function Os(n,t,e){vr(n),vr(t),$f(e);let r=new Uint8Array(16),o=gn(r);return o.setBigUint64(0,BigInt(t),e),o.setBigUint64(8,BigInt(n),e),r}function Bt(n){return n.byteOffset%4===0}function pt(n){return Uint8Array.from(G(n))}var zt,Ve,Y,Gf,tt,ne,Ro=St(()=>{C();zt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,Ve=n=>n<<24&4278190080|n<<8&16711680|n>>>8&65280|n>>>24&255,Y=zt?n=>n:n=>Ve(n)>>>0,Gf=n=>{for(let t=0;t<n.length;t++)n[t]=Ve(n[t]);return n},tt=zt?n=>n:Gf;ne=(n,t)=>{function e(r,...o){if(G(r,void 0,"key"),n.nonceLength!==void 0){let u=o[0];G(u,n.varSizeNonce?void 0:n.nonceLength,"nonce")}let i=n.tagLength;i&&o[1]!==void 0&&G(o[1],void 0,"AAD");let s=t(r,...o),c=(u,a)=>{if(a!==void 0){if(u!==2)throw new Error("cipher output not supported");G(a,void 0,"output")}},f=!1;return{encrypt(u,a){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,G(u),c(s.encrypt.length,a),s.encrypt(u,a)},decrypt(u,a){if(G(u),i&&u.length<i)throw new Error('"ciphertext" expected length bigger than tagLength='+i);return c(s.decrypt.length,a),s.decrypt(u,a)}}}return Object.assign(e,n),e}});function Xf(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 me,Oo,re,Yf,Wf,Dn,ve,Qf,Tr,_o,Lo,Ls,Cs=St(()=>{C();Ro();me=16,Oo=new Uint8Array(16),re=Q(Oo),Yf=225,Wf=(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^Yf<<24&-(o&1)}},Dn=n=>(n>>>0&255)<<24|(n>>>8&255)<<16|(n>>>16&255)<<8|n>>>24&255|0,ve=n=>Y(Dn(n));Qf=n=>n>64*1024?8:n>1024?4:2,Tr=class{constructor(t,e){y(this,"blockLen",me);y(this,"outputLen",me);y(this,"s0",0);y(this,"s1",0);y(this,"s2",0);y(this,"s3",0);y(this,"finished",!1);y(this,"destroyed",!1);y(this,"t");y(this,"W");y(this,"windowSize");G(t,16,"key"),t=pt(t);let r=gn(t),o=r.getUint32(0,!1),i=r.getUint32(4,!1),s=r.getUint32(8,!1),c=r.getUint32(12,!1),f=[];for(let p=0;p<128;p++)f.push({s0:Dn(o),s1:Dn(i),s2:Dn(s),s3:Dn(c)}),{s0:o,s1:i,s2:s,s3:c}=Wf(o,i,s,c);let l=Qf(e||1024);if(![1,2,4,8].includes(l))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=l;let a=128/l,h=this.windowSize=2**l,d=[];for(let p=0;p<a;p++)for(let m=0;m<h;m++){let w=0,E=0,B=0,I=0;for(let S=0;S<l;S++){if(!(m>>>l-S-1&1))continue;let{s0:P,s1:ft,s2:$,s3:z}=f[l*p+S];w^=P,E^=ft,B^=$,I^=z}d.push({s0:w,s1:E,s2:B,s3:I})}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:c}=this,f=0,l=0,u=0,a=0,h=(1<<i)-1,d=0;for(let p of[t,e,r,o])for(let m=0;m<4;m++){let w=p>>>8*m&255;for(let E=8/i-1;E>=0;E--){let B=w>>>i*E&h,{s0:I,s1:S,s2:T,s3:P}=s[d*c+B];f^=I,l^=S,u^=T,a^=P,d+=1}}this.s0=f,this.s1=l,this.s2=u,this.s3=a}update(t){Ln(this),G(t),t=pt(t);let e=Q(t),r=Math.floor(t.length/me),o=t.length%me;for(let i=0;i<r;i++)this._updateBlock(Y(e[i*4+0]),Y(e[i*4+1]),Y(e[i*4+2]),Y(e[i*4+3]));return o&&(Oo.set(t.subarray(r*me)),this._updateBlock(Y(re[0]),Y(re[1]),Y(re[2]),Y(re[3])),st(re)),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){Ln(this),Cn(t,this,!0),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,tt(s)}digest(){let t=new Uint8Array(me);return this.digestInto(t),this.destroy(),t}},_o=class extends Tr{constructor(t,e){G(t);let r=Xf(pt(t));super(r,e),st(r)}update(t){Ln(this),G(t),t=pt(t);let e=Q(t),r=t.length%me,o=Math.floor(t.length/me);for(let i=0;i<o;i++)this._updateBlock(ve(e[i*4+3]),ve(e[i*4+2]),ve(e[i*4+1]),ve(e[i*4+0]));return r&&(Oo.set(t.subarray(o*me)),this._updateBlock(ve(re[3]),ve(re[2]),ve(re[1]),ve(re[0])),st(re)),this}digestInto(t){Ln(this),Cn(t,this,!0),this.finished=!0;let e=t.subarray(0,this.outputLen),{s0:r,s1:o,s2:i,s3:s}=this,c=Q(e);c[0]=r,c[1]=o,c[2]=i,c[3]=s,tt(c),e.reverse()}},Lo=Hn(16,(n,t)=>new Tr(n,t),n=>[n.length]),Ls=Hn(16,(n,t)=>new _o(n,t),n=>[n.length])});var Mo={};Gn(Mo,{__TESTS:()=>mu,aeskw:()=>uu,aeskwp:()=>au,aessiv:()=>pu,cbc:()=>iu,cfb:()=>su,cmac:()=>qn,ctr:()=>xn,ecb:()=>ou,gcm:()=>cu,gcmsiv:()=>fu,rngAesCtrDrbg128:()=>lu,rngAesCtrDrbg256:()=>hu,siv:()=>du,unsafe:()=>gu});function Ur(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 qo(n){return n<<1^tu&-(n>>7)}function mn(n,t){let e=0;for(;t>0;t>>=1)e^=n&-(t&1),n=qo(n);return e}function Hs(n,t){if(n.length!==256)throw new Error("Wrong sbox length");let e=new Uint32Array(256).map((l,u)=>t(n[u])),r=e.map(Co),o=r.map(Co),i=o.map(Co),s=new Uint32Array(256*256),c=new Uint32Array(256*256),f=new Uint16Array(256*256);for(let l=0;l<256;l++)for(let u=0;u<256;u++){let a=l*256+u;s[a]=e[l]^r[u],c[a]=o[l]^i[u],f[a]=n[l]<<8|n[u]}return{sbox:n,sbox2:f,T0:e,T1:r,T2:o,T3:i,T01:s,T23:c}}function $t(n){G(n);let t=n.length;Ur(n);let{sbox2:e}=Po,r=[];(!zt||!Bt(n))&&r.push(n=pt(n));let o=tt(Q(n)),i=o.length,s=f=>oe(e,f,f,f,f),c=new Uint32Array(t+28);c.set(o);for(let f=i;f<c.length;f++){let l=c[f-1];f%i===0?l=s(nu(l))^ru[f/i-1]:i>6&&f%i===4&&(l=s(l)),c[f]=c[f-i]^l}return st(...r),c}function Rr(n){let t=$t(n),e=t.slice(),r=t.length,{sbox2:o}=Po,{T0:i,T1:s,T2:c,T3:f}=Ds;for(let l=0;l<r;l+=4)for(let u=0;u<4;u++)e[l+u]=t[r-l-4+u];st(t);for(let l=4;l<r-4;l++){let u=e[l],a=oe(o,u,u,u,u);e[l]=i[a&255]^s[a>>>8&255]^c[a>>>16&255]^f[a>>>24]}return e}function Ie(n,t,e,r,o,i){return n[e<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function oe(n,t,e,r,o){return n[t&255|e&65280]|n[r>>>16&255|o>>>16&65280]<<16}function Ot(n,t,e,r,o){let{sbox2:i,T01:s,T23:c}=Po,f=0;t^=n[f++],e^=n[f++],r^=n[f++],o^=n[f++];let l=n.length/4-2;for(let p=0;p<l;p++){let m=n[f++]^Ie(s,c,t,e,r,o),w=n[f++]^Ie(s,c,e,r,o,t),E=n[f++]^Ie(s,c,r,o,t,e),B=n[f++]^Ie(s,c,o,t,e,r);t=m,e=w,r=E,o=B}let u=n[f++]^oe(i,t,e,r,o),a=n[f++]^oe(i,e,r,o,t),h=n[f++]^oe(i,r,o,t,e),d=n[f++]^oe(i,o,t,e,r);return{s0:u,s1:a,s2:h,s3:d}}function zn(n,t,e,r,o){let{sbox2:i,T01:s,T23:c}=Ds,f=0;t^=n[f++],e^=n[f++],r^=n[f++],o^=n[f++];let l=n.length/4-2;for(let p=0;p<l;p++){let m=n[f++]^Ie(s,c,t,o,r,e),w=n[f++]^Ie(s,c,e,t,o,r),E=n[f++]^Ie(s,c,r,e,t,o),B=n[f++]^Ie(s,c,o,r,e,t);t=m,e=w,r=E,o=B}let u=n[f++]^oe(i,t,o,r,e),a=n[f++]^oe(i,e,t,o,r),h=n[f++]^oe(i,r,e,t,o),d=n[f++]^oe(i,o,r,e,t);return{s0:u,s1:a,s2:h,s3:d}}function js(n,t,e,r){G(t,ot,"nonce"),G(e);let o=e.length;r=Ze(o,r),kn(e,r);let i=t,s=Q(i),c=Q(e),f=Q(r),{s0:l,s1:u,s2:a,s3:h}=Ot(n,Y(s[0]),Y(s[1]),Y(s[2]),Y(s[3]));for(let p=0;p+4<=c.length;p+=4)f[p+0]=c[p+0]^Y(l),f[p+1]=c[p+1]^Y(u),f[p+2]=c[p+2]^Y(a),f[p+3]=c[p+3]^Y(h),Pn(i,!1,1),{s0:l,s1:u,s2:a,s3:h}=Ot(n,Y(s[0]),Y(s[1]),Y(s[2]),Y(s[3]));let d=ot*Math.floor(c.length/jo);if(d<o){let p=new Uint32Array([l,u,a,h]);tt(p);let m=Ir(p);for(let w=d,E=0;w<o;w++,E++)r[w]=e[w]^m[E];st(p)}return r}function yn(n,t,e,r,o){G(e,ot,"nonce"),G(r),o=Ze(r.length,o);let i=e,s=Q(i),c=gn(i),f=Q(r),l=Q(o),u=t?0:12,a=r.length,h=c.getUint32(u,t),{s0:d,s1:p,s2:m,s3:w}=Ot(n,Y(s[0]),Y(s[1]),Y(s[2]),Y(s[3]));for(let B=0;B+4<=f.length;B+=4)l[B+0]=f[B+0]^Y(d),l[B+1]=f[B+1]^Y(p),l[B+2]=f[B+2]^Y(m),l[B+3]=f[B+3]^Y(w),h=h+1>>>0,c.setUint32(u,h,t),{s0:d,s1:p,s2:m,s3:w}=Ot(n,Y(s[0]),Y(s[1]),Y(s[2]),Y(s[3]));let E=ot*Math.floor(f.length/jo);if(E<a){let B=new Uint32Array([d,p,m,w]);tt(B);let I=Ir(B);for(let S=E,T=0;S<a;S++,T++)o[S]=r[S]^I[T];st(B)}return o}function qs(n){if(G(n),n.length%ot!==0)throw new Error("aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size "+ot)}function Ps(n,t,e){G(n);let r=n.length,o=r%ot;if(!t&&o!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");if(t){let c=ot-o;c||(c=ot),r=r+c}e=Ze(r,e),kn(n,e),(!zt||!Bt(n))&&(n=pt(n));let i=Q(n);tt(i);let s=Q(e);return{b:i,o:s,out:e}}function Ms(n,t){if(!t)return n;let e=n.length;if(e===0)throw new Error("aes/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,c=(n[e-1-i]^r)===0?1:0;o&=c|s^1}if(!o)throw new Error("aes/pkcs7: wrong padding");return n.subarray(0,e-r)}function Ks(n){let t=new Uint8Array(16),e=Q(t);t.set(n);let r=ot-n.length;for(let o=ot-r;o<ot;o++)t[o]=r;return e}function zs(n,t,e,r,o){let i=o?o.length:0,s=n.create(e,r.length+i);o&&s.update(o);let c=Os(8*r.length,8*i,t);s.update(r),s.update(c);let f=s.digest();return st(c),f}function Vs(n){return n instanceof Uint32Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint32Array"}function Mn(n,t){if(G(t,16,"block"),!Vs(n))throw new Error("_encryptBlock accepts result of expandKeyLE");let e=Q(t);tt(e);let{s0:r,s1:o,s2:i,s3:s}=Ot(n,e[0],e[1],e[2],e[3]);return e[0]=r,e[1]=o,e[2]=i,e[3]=s,tt(e),t}function Zs(n,t){if(G(t,16,"block"),!Vs(n))throw new Error("_decryptBlock accepts result of expandKeyLE");let e=Q(t);tt(e);let{s0:r,s1:o,s2:i,s3:s}=zn(n,e[0],e[1],e[2],e[3]);return e[0]=r,e[1]=o,e[2]=i,e[3]=s,tt(e),t}function Kn(n){let t=0;for(let e=ot-1;e>=0;e--){let r=(n[e]&128)>>>7;n[e]=n[e]<<1|t,t=r}return t&&(n[ot-1]^=135),n}function $e(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 Gs(n,t){if(t.length>n.length)throw new Error("xorend: len(B) must be less than or equal to 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 Do(n,t){Ur(n);let e=t.length;if(e>127)throw new Error("s2v: number of input strings must be less than or equal to 127");if(e===0)return qn(Jf,n);let r=qn(jn,n);for(let c=0;c<e-1;c++){Kn(r);let f=qn(t[c],n);$e(r,f),st(f)}let o=t[e-1];G(o);let i;if(o.byteLength>=ot)i=Gs(Uint8Array.from(o),r);else{let c=new Uint8Array(ot);c.set(o),c[o.length]=128,i=$e(Kn(r),c),st(c)}let s=qn(i,n);return st(r,i),s}var ot,jo,jn,Jf,tu,Pn,ko,eu,nu,Co,Po,Ds,ru,xn,ou,iu,su,cu,wn,fu,Fr,ks,uu,Ns,au,No,$s,lu,hu,Ho,qn,du,pu,gu,mu,Ko=St(()=>{C();Cs();Ro();ot=16,jo=4,jn=new Uint8Array(ot),Jf=Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]),tu=283;Pn=(n,t,e=1)=>{if(!Number.isSafeInteger(e)||e>4294967040)throw new Error("incBytes: wrong carry "+e);G(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}},ko=(()=>{let n=new Uint8Array(256);for(let e=0,r=1;e<256;e++,r^=qo(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 st(n),t})(),eu=ko.map((n,t)=>ko.indexOf(t)),nu=n=>n<<24|n>>>8,Co=n=>n<<8|n>>>24;Po=Hs(ko,n=>mn(n,3)<<24|n<<16|n<<8|mn(n,2)),Ds=Hs(eu,n=>mn(n,11)<<24|mn(n,13)<<16|mn(n,9)<<8|mn(n,14)),ru=(()=>{let n=new Uint8Array(16);for(let t=0,e=1;t<16;t++,e=qo(e))n[t]=e;return n})();xn=ne({blockSize:16,nonceLength:16},function(t,e){function r(o,i){if(G(o),i!==void 0&&(G(i),!Bt(i)))throw new Error("unaligned destination");let s=$t(t),c=pt(e),f=[s,c];Bt(o)||f.push(o=pt(o));let l=js(s,c,o,i);return st(...f),l}return{encrypt:(o,i)=>r(o,i),decrypt:(o,i)=>r(o,i)}});ou=ne({blockSize:16},function(t,e={}){let r=!e.disablePadding;return{encrypt(o,i){let{b:s,o:c,out:f}=Ps(o,r,i),l=$t(t),u=0;for(;u+4<=s.length;){let{s0:a,s1:h,s2:d,s3:p}=Ot(l,s[u+0],s[u+1],s[u+2],s[u+3]);c[u++]=a,c[u++]=h,c[u++]=d,c[u++]=p}if(r){let a=Ks(o.subarray(u*4));tt(a);let{s0:h,s1:d,s2:p,s3:m}=Ot(l,a[0],a[1],a[2],a[3]);c[u++]=h,c[u++]=d,c[u++]=p,c[u++]=m}return tt(c),st(l),f},decrypt(o,i){qs(o);let s=Rr(t);i=Ze(o.length,i);let c=[s];kn(o,i),(!zt||!Bt(o))&&c.push(o=pt(o));let f=Q(o),l=Q(i);tt(f);for(let u=0;u+4<=f.length;){let{s0:a,s1:h,s2:d,s3:p}=zn(s,f[u+0],f[u+1],f[u+2],f[u+3]);l[u++]=a,l[u++]=h,l[u++]=d,l[u++]=p}return tt(l),st(...c),Ms(i,r)}}}),iu=ne({blockSize:16,nonceLength:16},function(t,e,r={}){let o=!r.disablePadding;return{encrypt(i,s){let c=$t(t),{b:f,o:l,out:u}=Ps(i,o,s),a=e,h=[c];(!zt||!Bt(a))&&h.push(a=pt(a));let d=Q(a);tt(d);let p=d[0],m=d[1],w=d[2],E=d[3],B=0;for(;B+4<=f.length;)p^=f[B+0],m^=f[B+1],w^=f[B+2],E^=f[B+3],{s0:p,s1:m,s2:w,s3:E}=Ot(c,p,m,w,E),l[B++]=p,l[B++]=m,l[B++]=w,l[B++]=E;if(o){let I=Ks(i.subarray(B*4));tt(I),p^=I[0],m^=I[1],w^=I[2],E^=I[3],{s0:p,s1:m,s2:w,s3:E}=Ot(c,p,m,w,E),l[B++]=p,l[B++]=m,l[B++]=w,l[B++]=E}return tt(l),st(...h),u},decrypt(i,s){qs(i);let c=Rr(t),f=e,l=[c];(!zt||!Bt(f))&&l.push(f=pt(f));let u=Q(f);tt(u),s=Ze(i.length,s),kn(i,s),(!zt||!Bt(i))&&l.push(i=pt(i));let a=Q(i),h=Q(s);tt(a);let d=u[0],p=u[1],m=u[2],w=u[3];for(let E=0;E+4<=a.length;){let B=d,I=p,S=m,T=w;d=a[E+0],p=a[E+1],m=a[E+2],w=a[E+3];let{s0:P,s1:ft,s2:$,s3:z}=zn(c,d,p,m,w);h[E++]=P^B,h[E++]=ft^I,h[E++]=$^S,h[E++]=z^T}return tt(h),st(...l),Ms(s,o)}}}),su=ne({blockSize:16,nonceLength:16},function(t,e){function r(o,i,s){G(o);let c=o.length;if(s=Ze(c,s),Fo(o,s))throw new Error("overlapping src and dst not supported.");let f=$t(t),l=e,u=[f];(!zt||!Bt(l))&&u.push(l=pt(l)),(!zt||!Bt(o))&&u.push(o=pt(o));let a=Q(o),h=Q(s),d=i?h:a,p=Q(l);tt(a),tt(p);let m=p[0],w=p[1],E=p[2],B=p[3];for(let S=0;S+4<=a.length;){let{s0:T,s1:P,s2:ft,s3:$}=Ot(f,m,w,E,B);h[S+0]=a[S+0]^T,h[S+1]=a[S+1]^P,h[S+2]=a[S+2]^ft,h[S+3]=a[S+3]^$,m=d[S++],w=d[S++],E=d[S++],B=d[S++]}let I=ot*Math.floor(a.length/jo);if(I<c){({s0:m,s1:w,s2:E,s3:B}=Ot(f,m,w,E,B));let S=new Uint32Array([m,w,E,B]);tt(S);let T=Ir(S);for(let P=I,ft=0;P<c;P++,ft++)s[P]=o[P]^T[ft];st(T)}return tt(h),st(...u),s}return{encrypt:(o,i)=>r(o,!0,i),decrypt:(o,i)=>r(o,!1,i)}});cu=ne({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(t,e,r){if(e.length<8)throw new Error("aes/gcm: invalid nonce length");let o=16;function i(c,f,l){let u=zs(Lo,!1,c,l,r);for(let a=0;a<f.length;a++)u[a]^=f[a];return u}function s(){let c=$t(t),f=jn.slice(),l=jn.slice();if(yn(c,!1,l,l,f),e.length===12)l.set(e);else{let a=jn.slice();gn(a).setBigUint64(8,BigInt(e.length*8),!1);let d=Lo.create(f).update(e).update(a);d.digestInto(l),d.destroy()}let u=yn(c,!1,l,jn);return{xk:c,authKey:f,counter:l,tagMask:u}}return{encrypt(c){let{xk:f,authKey:l,counter:u,tagMask:a}=s(),h=new Uint8Array(c.length+o),d=[f,l,u,a];Bt(c)||d.push(c=pt(c)),yn(f,!1,u,c,h.subarray(0,c.length));let p=i(l,a,h.subarray(0,h.length-o));return d.push(p),h.set(p,c.length),st(...d),h},decrypt(c){let{xk:f,authKey:l,counter:u,tagMask:a}=s(),h=[f,l,a,u];Bt(c)||h.push(c=pt(c));let d=c.subarray(0,-o),p=c.subarray(-o),m=i(l,a,d);if(h.push(m),!Nn(m,p))throw st(...h),new Error("aes/gcm: invalid ghash tag");let w=yn(f,!1,u,d);return st(...h),w}}}),wn=(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)}},fu=ne({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(t,e,r){let i=wn("AAD",0,68719476736),s=wn("plaintext",0,2**36),c=wn("nonce",12,12),f=wn("ciphertext",16,2**36+16);G(t),Ur(t),c(e.length),r!==void 0&&i(r.length);function l(){let h=$t(t),d=new Uint8Array(t.length),p=new Uint8Array(16),m=[h,d],w=e;(!zt||!Bt(w))&&m.push(w=pt(w));let E=Q(w);tt(E);let B=0,I=E[0],S=E[1],T=E[2],P=0;for(let $ of[p,d].map(Q)){let z=Q($);for(let nt=0;nt<z.length;nt+=2){let{s0:W,s1:rt}=Ot(h,B,I,S,T);z[nt+0]=W,z[nt+1]=rt,B=++P}tt(z)}let ft={authKey:p,encKey:$t(d)};return st(...m),ft}function u(h,d,p){let m=zs(Ls,!0,d,p,r);for(let T=0;T<12;T++)m[T]^=e[T];m[15]&=127;let w=Q(m);tt(w);let E=w[0],B=w[1],I=w[2],S=w[3];return{s0:E,s1:B,s2:I,s3:S}=Ot(h,E,B,I,S),w[0]=E,w[1]=B,w[2]=I,w[3]=S,tt(w),m}function a(h,d,p){let m=pt(d);m[15]|=128;let w=yn(h,!0,m,p);return st(m),w}return{encrypt(h){s(h.length);let{encKey:d,authKey:p}=l(),m=u(d,p,h),w=[d,p,m];Bt(h)||w.push(h=pt(h));let E=new Uint8Array(h.length+16);return E.set(m,h.length),E.set(a(d,m,h)),st(...w),E},decrypt(h){f(h.length);let d=h.subarray(-16),{encKey:p,authKey:m}=l(),w=[p,m];Bt(h)||w.push(h=pt(h));let E=a(p,d,h.subarray(0,-16)),B=u(p,m,E);if(w.push(B),!Nn(d,B))throw st(...w),new Error("invalid polyval tag");return st(...w),E}}});Fr={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)Mn(e,t);else{let r=Q(t);tt(r);let o=r[0],i=r[1];for(let s=0,c=1;s<6;s++)for(let f=2;f<r.length;f+=2,c++){let{s0:l,s1:u,s2:a,s3:h}=Ot(e,o,i,r[f],r[f+1]);o=l,i=u^Ve(c),r[f]=a,r[f+1]=h}r[0]=o,r[1]=i,tt(r)}e.fill(0)},decrypt(n,t){if(t.length-8>=2**32)throw new Error("ciphertext should be less than 4gb");let e=Rr(n),r=t.length/8-1;if(r===1)Zs(e,t);else{let o=Q(t);tt(o);let i=o[0],s=o[1];for(let c=0,f=r*6;c<6;c++)for(let l=r*2;l>=1;l-=2,f--){s^=Ve(f);let{s0:u,s1:a,s2:h,s3:d}=zn(e,i,s,o[l],o[l+1]);i=u,s=a,o[l]=h,o[l+1]=d}o[0]=i,o[1]=s,tt(o)}e.fill(0)}},ks=new Uint8Array(8).fill(166),uu=ne({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 in AESKW, use AESKWP instead");let e=Uo(ks,t);return Fr.encrypt(n,e),e},decrypt(t){if(t.length%8!==0||t.length<24)throw new Error("invalid ciphertext length");let e=pt(t);if(Fr.decrypt(n,e),!Nn(e.subarray(0,8),ks))throw new Error("integrity check failed");return e.subarray(0,8).fill(0),e.subarray(8)}})),Ns=2790873510,au=ne({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]=Y(Ns),o[1]=Y(Ve(t.length)),Fr.encrypt(n,r),r},decrypt(t){if(t.length<16)throw new Error("invalid ciphertext length");let e=pt(t),r=Q(e);Fr.decrypt(n,e);let o=Ve(Y(r[1]))>>>0,i=Math.ceil(o/8)*8;if(Y(r[0])!==Ns||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)}})),No=class{constructor(t,e,r){y(this,"blockLen");y(this,"key");y(this,"nonce");y(this,"state");y(this,"reseedCnt");this.blockLen=xn.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,Pn(this.nonce,!1,1),this.addEntropy(e,r)}update(t){if(xn(this.key,this.nonce).encrypt(new Uint8Array(this.state.length),this.state),t){G(t);for(let e=0;e<t.length;e++)this.state[e]^=t[e]}Pn(this.nonce,!1,1)}addEntropy(t,e){G(t,this.state.length,"seed");let r=t.slice();if(e){if(G(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(vr(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(G(e),e.length>this.state.length)throw new Error("info length is too big");this.update(e)}let r=new Uint8Array(t);return xn(this.key,this.nonce).encrypt(r,r),Pn(this.nonce,!1,Math.ceil(t/this.blockLen)),this.update(e),this.reseedCnt++,r}clean(){this.state.fill(0),this.reseedCnt=0}},$s=n=>(t,e=void 0)=>new No(n,t,e),lu=$s(128),hu=$s(256);Ho=class{constructor(t){y(this,"blockLen",ot);y(this,"outputLen",ot);y(this,"buffer");y(this,"pos");y(this,"finished");y(this,"destroyed");y(this,"k1");y(this,"k2");y(this,"x");y(this,"xk");G(t),Ur(t),this.xk=$t(t),this.buffer=new Uint8Array(ot),this.pos=0,this.finished=!1,this.destroyed=!1,this.x=new Uint8Array(ot);let e=new Uint8Array(ot);Mn(this.xk,e),this.k1=Kn(e),this.k2=Kn(new Uint8Array(this.k1))}process(t){$e(this.x,t),Mn(this.xk,this.x)}update(t){if(this.destroyed)throw new Error("Hash instance has been destroyed");if(this.finished)throw new Error("Hash#digest() has already been called");G(t);let e=0;if(this.pos){let r=Math.min(ot-this.pos,t.length);this.buffer.set(t.subarray(0,r),this.pos),this.pos+=r,e=r,this.pos===ot&&e<t.length&&(this.process(this.buffer),this.pos=0)}for(;e+ot<t.length;)this.process(t.subarray(e,e+ot)),e+=ot;return e<t.length&&(this.buffer.set(t.subarray(e),0),this.pos=t.length-e),this}digestInto(t){if(this.destroyed)throw new Error("Hash instance has been destroyed");if(this.finished)throw new Error("Hash#digest() has already been called");Cn(t,this,!0),this.finished=!0;let e=t.subarray(0,this.outputLen),r=new Uint8Array(ot);this.pos===ot?(r.set(this.buffer),$e(r,this.k1)):(r.set(this.buffer.subarray(0,this.pos)),r[this.pos]=128,$e(r,this.k2)),e.set(this.x),$e(e,r),Mn(this.xk,e),st(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,st(t,r,o,i,s))}},qn=Hn(16,n=>new Ho(n));du=()=>{throw new Error('"siv" from v1 is now "gcmsiv"')},pu=ne({blockSize:16,tagLength:16},function(t,...e){let r=wn("plaintext",0,5444517870735016e24),o=wn("ciphertext",16,2**132+16);if(e.length>126)throw new Error('"AAD" number of elements must be less than or equal to 126');if(e.forEach(c=>G(c)),G(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(c){r(c.length);let f=Do(i,[...e,c]),l=Uint8Array.from(f);l[8]&=127,l[12]&=127;let u=xn(s,l).encrypt(c);return Uo(f,u)},decrypt(c){o(c.length);let f=c.subarray(0,ot),l=c.subarray(ot),u=Uint8Array.from(f);u[8]&=127,u[12]&=127;let a=xn(s,u).decrypt(l),h=Do(i,[...e,a]);if(Nn(h,f))return a;throw new Error("invalid siv tag")}}}),gu=Object.freeze({expandKeyLE:$t,expandKeyDecLE:Rr,encrypt:Ot,decrypt:zn,encryptBlock:Mn,decryptBlock:Zs,ctrCounter:js,ctr32:yn,dbl:Kn,xorBlock:$e,xorend:Gs,s2v:Do}),mu=Object.freeze({incBytes:Pn})});var Ws=Ct((il,Ys)=>{C();Ys.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.crypto.Random});var tc=Ct((cl,Js)=>{"use strict";C();var{secp256k1:Xs}=(To(),ye(Io)),{sha512:yu,sha256:wu}=(lr(),ye(to)),{hmac:xu}=(Br(),ye(yo)),{cbc:Qs}=(Ko(),ye(Mo)),bu=Gr(),Te=Yr(),Eu=Ws();function Vn(n){return K.Buffer.from(n.buffer,n.byteOffset,n.byteLength)}function zo(n,t){return Vn(xu(wu,n,t))}function Bu(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){Te.checkArgument(n),Te.checkArgument(t),Te.checkArgument(e),e=e||Eu.getRandomBuffer(128/8);var r=Qs(Uint8Array.from(t),Uint8Array.from(e)).encrypt(Uint8Array.from(n));return K.Buffer.concat([K.Buffer.from(e),Vn(r)])};_r.decrypt=function(n,t){Te.checkArgument(n),Te.checkArgument(t);var e=n.slice(0,128/8),r=n.slice(128/8),o=Qs(Uint8Array.from(t),Uint8Array.from(e)).decrypt(Uint8Array.from(r));return Vn(o)};var bn=function n(t){if(!(this instanceof n))return new n(t);this.opts=t||{}};bn.prototype.privateKey=function(n){return Te.checkArgument(n,"no private key provided"),this._privateKey=n||null,this};bn.prototype.publicKey=function(n){return Te.checkArgument(n,"no public key provided"),this._publicKey=n||null,this};var Or=function(n,t){var e="_"+n;Object.defineProperty(bn.prototype,n,{configurable:!1,enumerable:!0,get:function(){var r=this[e];return r||(r=this[e]=t.apply(this)),r}})};Or("Rbuf",function(){var n=this._privateKey.bn.toBuffer({size:32});return Vn(Xs.getPublicKey(Uint8Array.from(n),!0))});Or("kEkM",function(){var n=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),e=Xs.getSharedSecret(Uint8Array.from(n),Uint8Array.from(t),!0),r=e.slice(1);return Vn(yu(r))});Or("kE",function(){return this.kEkM.slice(0,32)});Or("kM",function(){return this.kEkM.slice(32,64)});bn.prototype.encrypt=function(n,t){K.Buffer.isBuffer(n)||(n=K.Buffer.from(n)),t===void 0&&(t=zo(this._privateKey.toBuffer(),n).slice(0,16));var e=_r.encrypt(n,this.kE,t),r=zo(this.kM,e);return this.opts.shortTag&&(r=r.slice(0,4)),this.opts.noKey?K.Buffer.concat([e,r]):K.Buffer.concat([this.Rbuf,e,r])};bn.prototype.decrypt=function(n){Te.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=bu.fromDER(r),t+=r.length}var o=n.slice(t,n.length-e),i=n.slice(n.length-e,n.length),s=zo(this.kM,o);if(this.opts.shortTag&&(s=s.slice(0,4)),!Bu(i,s))throw new Error("Invalid checksum");return _r.decrypt(o,this.kE)};Js.exports=bn});var nc=Ct((ul,ec)=>{C();ec.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.errors});var oc=Ct((ll,rc)=>{"use strict";C();var Su={name:"ECIES",message:"Internal Error on bsv-ecies Module {0}",errors:[{name:"DecryptionError",message:"Invalid Message: {0}"},{name:"UnsupportAlgorithm",message:"Unsupport Algorithm: {0}"}]};rc.exports=nc().extend(Su)});var uc=Ct((dl,fc)=>{"use strict";C();var Vo=Gr(),Zo=Si(),jt=Yr(),Au=tc(),Lr=oc(),{secp256k1:ic}=(To(),ye(Io)),{sha512:vu,sha256:Iu}=(lr(),ye(to)),{hmac:Tu}=(Br(),ye(yo)),{cbc:sc}=(Ko(),ye(Mo));function Zn(n){return K.Buffer.from(n.buffer,n.byteOffset,n.byteLength)}function cc(n,t){return Zn(Tu(Iu,t,n))}var Cr=function(){};Cr.encrypt=function(n,t,e){return jt.checkArgument(n),jt.checkArgument(t),jt.checkArgument(e),jt.checkArgument(t.length===16,"keybuf length must be 16"),jt.checkArgument(e.length===16,"ivbuf length must be 16"),Zn(sc(Uint8Array.from(t),Uint8Array.from(e)).encrypt(Uint8Array.from(n)))};Cr.decrypt=function(n,t,e){return jt.checkArgument(n),jt.checkArgument(t),jt.checkArgument(e),jt.checkArgument(t.length===16,"keybuf length must be 16"),jt.checkArgument(e.length===16,"ivbuf length must be 16"),Zn(sc(Uint8Array.from(t),Uint8Array.from(e)).decrypt(Uint8Array.from(n)))};var Ge=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 Zo,this.opts=t||{},this.opts.ephemeralKey=!0};Ge.prototype.privateKey=function(n){return jt.checkArgument(Zo.isValid(n),"no private key provided"),this._privateKey=Zo(n.toHex())||null,this.opts.ephemeralKey=!1,this};Ge.prototype.publicKey=function(n){return jt.checkArgument(Vo.isValid(n),"no public key provided"),this._publicKey=Vo(n.toString())||null,this._publicKey!=null&&(this.opts.fixedPublicKey=!0),this};var $n=function(n,t){var e="_"+n;Object.defineProperty(Ge.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 Zn(ic.getPublicKey(Uint8Array.from(n),!0))});$n("ivkEkM",function(){var n=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),e=ic.getSharedSecret(Uint8Array.from(n),Uint8Array.from(t),!0);return Zn(vu(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)});Ge.prototype.encrypt=function(n){K.Buffer.isBuffer(n)||(n=K.Buffer.from(n));var t=Cr.encrypt(n,this.kE,this.iv),e,r=K.Buffer.from("BIE1");this.opts.noKey&&!this.opts.ephemeralKey?e=K.Buffer.concat([r,t]):e=K.Buffer.concat([r,this.Rbuf,t]);var o=cc(e,this.kM);return this.opts.shortTag&&(o=o.slice(0,4)),K.Buffer.concat([e,o])};Ge.prototype.decrypt=function(n){jt.checkArgument(K.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(K.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=Vo.fromDER(o),e=37}var i=n.slice(e,n.length-t),s=n.slice(n.length-t,n.length),c=cc(n.slice(0,n.length-t),this.kM);if(this.opts.shortTag&&(c=c.slice(0,4)),s.length!==c.length)throw new Lr.DecryptionError("Invalid checksum");for(var f=0,l=0;l<c.length;l++)f|=s[l]^c[l];if(f!==0)throw new Lr.DecryptionError("Invalid checksum");return Cr.decrypt(i,this.kE,this.iv)};Ge.bitcoreECIES=Au;fc.exports=Ge});var lc=Ct((gl,ac)=>{C();ac.exports=uc()});var Fu=Ct((yl,hc)=>{C();hc.exports=lc()});return Fu();})();
|
|
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<&&(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<)===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}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&>.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();})();
|
|
2
2
|
if(typeof module!=="undefined"&&module.exports){module.exports=bsvEcies}else if(typeof define==="function"&&define.amd){define([],function(){return bsvEcies})}
|