@smartledger/bsv 7.9.0 → 7.10.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +38 -38
  3. package/bsv-covenant.min.js +1 -1
  4. package/bsv-ecies.min.js +1 -1
  5. package/bsv-gdaf.min.js +54 -54
  6. package/bsv-ltp.min.js +58 -85
  7. package/bsv-message.min.js +2 -2
  8. package/bsv-mnemonic.min.js +12 -14
  9. package/bsv-script-helper.min.js +1 -1
  10. package/bsv-shamir.min.js +14 -16
  11. package/bsv-smartcontract.min.js +23 -25
  12. package/bsv.bundle.js +54 -54
  13. package/bsv.min.js +54 -54
  14. package/build/esbuild.js +84 -4
  15. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  16. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  17. package/docs/getting-started/INSTALLATION.md +23 -23
  18. package/docs/getting-started/QUICK_START.md +7 -7
  19. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  20. package/index.js +9 -1
  21. package/lib/covenant/helpers.js +146 -0
  22. package/lib/covenant/index.js +21 -0
  23. package/lib/covenant/pushtx.js +243 -0
  24. package/lib/covenant-interface.js +408 -397
  25. package/lib/custom-script-helper.js +44 -38
  26. package/lib/ecies/bitcore-ecies.js +3 -4
  27. package/lib/ecies/electrum-ecies.js +4 -6
  28. package/lib/ecies/errors.js +1 -1
  29. package/lib/gdaf/attestation-signer.js +7 -7
  30. package/lib/gdaf/attestation-verifier.js +5 -6
  31. package/lib/gdaf/did-resolver.js +10 -9
  32. package/lib/gdaf/smartledger-anchor.js +13 -12
  33. package/lib/gdaf/zk-prover.js +8 -8
  34. package/lib/ltp/anchor.js +2 -3
  35. package/lib/ltp/claim.js +2 -3
  36. package/lib/ltp/index.js +2 -3
  37. package/lib/ltp/obligation.js +9 -9
  38. package/lib/ltp/proof.js +7 -7
  39. package/lib/ltp/registry.js +4 -5
  40. package/lib/ltp/right.js +11 -11
  41. package/lib/message/index.js +5 -4
  42. package/lib/message/message.js +11 -11
  43. package/lib/mnemonic/errors.js +1 -1
  44. package/lib/mnemonic/index.js +5 -4
  45. package/lib/mnemonic/mnemonic.js +22 -10
  46. package/lib/ordinals/bsv20.js +4 -4
  47. package/lib/ordinals/inscription.js +8 -12
  48. package/lib/ordinals/ordlock.js +26 -21
  49. package/lib/smart_contract/authorizers.js +8 -6
  50. package/lib/smart_contract/builder.js +32 -26
  51. package/lib/smart_contract/covenant.js +32 -25
  52. package/lib/smart_contract/covenant_helpers.js +8 -139
  53. package/lib/smart_contract/debugger.js +9 -6
  54. package/lib/smart_contract/dsl.js +5 -6
  55. package/lib/smart_contract/index.js +11 -8
  56. package/lib/smart_contract/locks.js +3 -4
  57. package/lib/smart_contract/opcode_list.js +2 -3
  58. package/lib/smart_contract/pels.js +4 -5
  59. package/lib/smart_contract/preimage.js +11 -7
  60. package/lib/smart_contract/pushtx.js +8 -263
  61. package/lib/smart_contract/script_interpreter.js +112 -105
  62. package/lib/smart_contract/script_tester.js +24 -18
  63. package/lib/smart_contract/script_utils.js +15 -14
  64. package/lib/smart_contract/sighash.js +23 -15
  65. package/lib/smart_contract/stack_examiner.js +70 -63
  66. package/lib/smart_contract/token.js +6 -6
  67. package/lib/smart_contract/utxo_generator.js +21 -15
  68. package/lib/smartutxo.js +27 -21
  69. package/lib/spv/headerchain.js +3 -3
  70. package/lib/spv/merkleproof.js +3 -3
  71. package/package.json +4 -2
  72. package/version.js +1 -1
package/bsv-ecies.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var bsvEcies=(()=>{var uc=Object.create;var Bn=Object.defineProperty;var ac=Object.getOwnPropertyDescriptor;var lc=Object.getOwnPropertyNames;var hc=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 St=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(r){throw e=[r],r}};var $t=(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 lc(t))!dc.call(n,o)&&o!==e&&Bn(n,o,{get:()=>t[o],enumerable:!(r=ac(t,o))||r.enumerable});return n};var Go=(n,t,e)=>(e=n!=null?uc(hc(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)=>pc(n,typeof t!="symbol"?t+"":t,e);var Jo=$t((Au,Qo)=>{H();var yt=Qo.exports={},Gt,Yt;function Dr(){throw new Error("setTimeout has not been defined")}function jr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Gt=setTimeout:Gt=Dr}catch{Gt=Dr}try{typeof clearTimeout=="function"?Yt=clearTimeout:Yt=jr}catch{Yt=jr}})();function Yo(n){if(Gt===setTimeout)return setTimeout(n,0);if((Gt===Dr||!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 gc(n){if(Yt===clearTimeout)return clearTimeout(n);if((Yt===jr||!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 mc(){!We||!Fe||(We=!1,Fe.length?se=Fe.concat(se):Yn=-1,se.length&&Wo())}function Wo(){if(!We){var n=Yo(mc);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,gc(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=$t(Wn=>{"use strict";H();Wn.byteLength=wc;Wn.toByteArray=bc;Wn.fromByteArray=Sc;var Wt=[],jt=[],yc=typeof Uint8Array<"u"?Uint8Array:Array,Pr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ue=0,ti=Pr.length;Ue<ti;++Ue)Wt[Ue]=Pr[Ue],jt[Pr.charCodeAt(Ue)]=Ue;var Ue,ti;jt[45]=62;jt[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 wc(n){var t=ei(n),e=t[0],r=t[1];return(e+r)*3/4-r}function xc(n,t,e){return(t+e)*3/4-e}function bc(n){var t,e=ei(n),r=e[0],o=e[1],i=new yc(xc(n,r,o)),s=0,c=o>0?r-4:r,f;for(f=0;f<c;f+=4)t=jt[n.charCodeAt(f)]<<18|jt[n.charCodeAt(f+1)]<<12|jt[n.charCodeAt(f+2)]<<6|jt[n.charCodeAt(f+3)],i[s++]=t>>16&255,i[s++]=t>>8&255,i[s++]=t&255;return o===2&&(t=jt[n.charCodeAt(f)]<<2|jt[n.charCodeAt(f+1)]>>4,i[s++]=t&255),o===1&&(t=jt[n.charCodeAt(f)]<<10|jt[n.charCodeAt(f+1)]<<4|jt[n.charCodeAt(f+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function Ec(n){return Wt[n>>18&63]+Wt[n>>12&63]+Wt[n>>6&63]+Wt[n&63]}function Bc(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(Ec(r));return o.join("")}function Sc(n){for(var t,e=n.length,r=e%3,o=[],i=16383,s=0,c=e-r;s<c;s+=i)o.push(Bc(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=$t(qr=>{H();qr.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)};qr.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=$t(tn=>{"use strict";H();var Mr=ni(),Qe=ri(),oi=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;tn.Buffer=b;tn.SlowBuffer=Uc;tn.INSPECT_MAX_BYTES=50;var Xn=2147483647;tn.kMaxLength=Xn;b.TYPED_ARRAY_SUPPORT=Ac();!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 Ac(){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 Ic(n,t);if(ArrayBuffer.isView(n))return Tc(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 zr(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=Fc(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 vc(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 vc(n,t,e)};function Zr(n){return ui(n),fe(n<0?0:$r(n)|0)}b.allocUnsafe=function(n){return Zr(n)};b.allocUnsafeSlow=function(n){return Zr(n)};function Ic(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 Kr(n){let t=n.length<0?0:$r(n.length)|0,e=fe(t);for(let r=0;r<t;r+=1)e[r]=n[r]&255;return e}function Tc(n){if(Xt(n,Uint8Array)){let t=new Uint8Array(n);return zr(t.buffer,t.byteOffset,t.byteLength)}return Kr(n)}function zr(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 Fc(n){if(b.isBuffer(n)){let t=$r(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"||Yr(n.length)?fe(0):Kr(n);if(n.type==="Buffer"&&Array.isArray(n.data))return Kr(n.data)}function $r(n){if(n>=Xn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Xn.toString(16)+" bytes");return n|0}function Uc(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 Vr(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:Vr(n).length;t=(""+t).toLowerCase(),o=!0}}b.byteLength=ai;function Rc(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 Pc(this,t,e);case"utf8":case"utf-8":return hi(this,t,e);case"ascii":return Dc(this,t,e);case"latin1":case"binary":return jc(this,t,e);case"base64":return Nc(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return qc(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):Rc.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,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=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 _c(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(Yr(c))return s;n[e+s]=c}return s}function Oc(n,t,e,r){return Qn(Vr(t,n.length-e),n,e,r)}function Lc(n,t,e,r){return Qn(Vc(t),n,e,r)}function Cc(n,t,e,r){return Qn(xi(t),n,e,r)}function kc(n,t,e,r){return Qn(Zc(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 _c(this,t,e,r);case"utf8":case"utf-8":return Oc(this,t,e,r);case"ascii":case"latin1":case"binary":return Lc(this,t,e,r);case"base64":return Cc(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return kc(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 Nc(n,t,e){return t===0&&e===n.length?Mr.fromByteArray(n):Mr.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 Hc(r)}var si=4096;function Hc(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 Dc(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 jc(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 Pc(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+=$c[n[i]];return o}function qc(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 Ct(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;Ct(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;Ct(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||Ct(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||Ct(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||Ct(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||Ct(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||Ct(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);Ct(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);Ct(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||Ct(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||Ct(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||Ct(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||Ct(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||Ct(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 Gr(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}`}}}Gr("ERR_BUFFER_OUT_OF_BOUNDS",function(n){return n?`${n} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Gr("ERR_INVALID_ARG_TYPE",function(n,t){return`The "${n}" argument must be of type number. Received type ${typeof t}`},TypeError);Gr("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 Mc(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)}Mc(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 Kc=/[^+/0-9A-Za-z-_]/g;function zc(n){if(n=n.split("=")[0],n=n.trim().replace(Kc,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function Vr(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 Vc(n){let t=[];for(let e=0;e<n.length;++e)t.push(n.charCodeAt(e)&255);return t}function Zc(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 Mr.toByteArray(zc(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 Yr(n){return n!==n}var $c=(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"?Gc:n}function Gc(){throw new Error("BigInt not supported")}});var ht,V,H=St(()=>{ht=Go(Jo()),V=Go(bi())});var Jn=$t((Cu,Ei)=>{H();Ei.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});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 tr(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 er(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 nr(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function zt(n,t){return n<<32-t|n>>>t}function rr(n){if(Qt(n),Si)return n.toHex();let t="";for(let e=0;e<n.length;e++)t+=Yc[n[e]];return t}function Bi(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(Si)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=Bi(n.charCodeAt(i)),c=Bi(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 Ai(...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 Si,Yc,ue,Oe,be=St(()=>{H();Si=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yc=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 vi(n,t,e){return n&t^~n&e}function Ii(n,t,e){return n&t^n&e^t&e}var vn,he,de,At,vt,Ti=St(()=>{H();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=nr(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=nr(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),er(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=nr(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 Wc(n,t=!1){return t?{h:Number(n&or),l:Number(n>>Fi&or)}:{h:Number(n>>Fi&or)|0,l:Number(n&or)|0}}function Ui(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}=Wc(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 or,Fi,Qr,Jr,Le,Ce,In,Tn,Ri,_i,Oi,Li,Ci,ki,Ni=St(()=>{H();or=BigInt(4294967295),Fi=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;Ri=(n,t,e)=>(n>>>0)+(t>>>0)+(e>>>0),_i=(n,t,e,r)=>t+e+r+(n/2**32|0)|0,Oi=(n,t,e,r)=>(n>>>0)+(t>>>0)+(e>>>0)+(r>>>0),Li=(n,t,e,r,o)=>t+e+r+o+(n/2**32|0)|0,Ci=(n,t,e,r,o)=>(n>>>0)+(t>>>0)+(e>>>0)+(r>>>0)+(o>>>0),ki=(n,t,e,r,o,i)=>t+e+r+o+i+(n/2**32|0)|0});var to={};Gn(to,{_SHA224:()=>cr,_SHA256:()=>sr,_SHA384:()=>ur,_SHA512:()=>fr,_SHA512_224:()=>ar,_SHA512_256:()=>lr,sha224:()=>ef,sha256:()=>Ae,sha384:()=>rf,sha512:()=>nf,sha512_224:()=>sf,sha512_256:()=>of});var Qc,Ee,ir,sr,cr,Hi,Jc,tf,Be,Se,nn,fr,ur,Ut,Rt,ar,lr,Ae,ef,nf,rf,of,sf,hr=St(()=>{H();Ti();Ni();be();Qc=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),ir=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=zt(h,7)^zt(h,18)^h>>>3,m=zt(d,17)^zt(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=zt(c,6)^zt(c,11)^zt(c,25),d=u+h+vi(c,f,l)+Qc[a]+Ee[a]|0,m=(zt(r,2)^zt(r,13)^zt(r,22))+Ii(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)}},sr=class extends ir{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)}},cr=class extends ir{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)}},Hi=Ui(["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))),Jc=Hi[0],tf=Hi[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,q=Le(S,T,1)^Le(S,T,8)^Qr(S,T,7),ct=Ce(S,T,1)^Ce(S,T,8)^Jr(S,T,7),$=Be[I-2]|0,K=Se[I-2]|0,nt=Le($,K,19)^In($,K,61)^Qr($,K,6),W=Ce($,K,19)^Tn($,K,61)^Jr($,K,6),rt=Oi(ct,W,Se[I-7],Se[I-16]),F=Li(rt,q,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),q=a&d^~a&m,ct=h&p^~h&w,$=Ci(B,T,ct,tf[I],Se[I]),K=ki($,E,S,q,Jc[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,k=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,K|0,nt|0),l=c|0,u=f|0,c=i|0,f=s|0,i=r|0,s=o|0;let U=Ri(nt,rt,k);r=_i(U,K,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)}},fr=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)}},ur=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]),ar=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)}},lr=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 sr,Oe(1)),ef=_e(()=>new cr,Oe(4)),nf=_e(()=>new fr,Oe(3)),rf=_e(()=>new ur,Oe(2)),of=_e(()=>new lr,Oe(6)),sf=_e(()=>new ar,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 gr(n){if(typeof n=="bigint"){if(!dr(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=gr(n).toString(16);return t.length&1?"0"+t:t}function Di(n){if(typeof n!="string")throw new TypeError("hex string expected, got "+typeof n);return n===""?pr:BigInt("0x"+n)}function _t(n){return Di(rr(n))}function on(n){return Di(rr(yr(Qt(n)).reverse()))}function mr(n,t){if(xe(t),t===0)throw new RangeError("zero length");n=gr(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 mr(n,t).reverse()}function yr(n){return Uint8Array.from(ut(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 cf(n,t,e){return dr(n)&&dr(t)&&dr(e)&&t<=n&&n<e}function oo(n,t,e,r){if(!cf(t,e,r))throw new RangeError("expected valid "+n+": "+e+" <= n < "+r+", got "+t)}function He(n){if(n<pr)throw new Error("expected non-negative bigint, got "+n);let t;for(t=0;n>pr;n>>=eo,t+=1);return t}function ji(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 qt(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 ut,no,pe,it,rn,ke,kt,pr,eo,dr,cn,De=St(()=>{H();be();ut=(n,t,e)=>Qt(n,t,e),no=xe,pe=rr,it=(...n)=>Ai(...n),rn=n=>Xr(n),ke=Wr,kt=n=>An(n),pr=BigInt(0),eo=BigInt(1);dr=n=>typeof n=="bigint"&&pr<=n;cn=n=>(eo<<BigInt(n))-eo});function Nt(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 Ht(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 Pi(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=Nt(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 Nt(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 $i(n,t){let e=n,r=(e.ORDER+xt)/Ki,o=e.pow(t,r);return so(e,o,t),o}function af(n,t){let e=n,r=(e.ORDER-zi)/Vi,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 lf(n){let t=fn(n),e=Gi(n),r=e(t,t.neg(t.ONE)),o=e(t,r),i=e(t,t.neg(r)),s=(n+ff)/Zi;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 Gi(n){if(n<Mi)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 $i;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 hf(n){return n%Ki===Mi?$i:n%Vi===zi?af:n%Zi===uf?lf(n):Gi(n)}function Pe(n){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=df.reduce((r,o)=>(r[o]="function",r),t);if(qt(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 pf(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 qe(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 gf(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 wr(n,t)}function Yi(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=Yi(n);return t+Math.ceil(t/2)}function un(n,t,e=!1){ut(n);let r=n.length,o=Yi(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=Nt(s,t-xt)+xt;return e?ro(c,o):mr(c,o)}var It,xt,je,Mi,Ki,zi,ff,Vi,uf,Zi,df,qi,wr,an=St(()=>{H();De();It=BigInt(0),xt=BigInt(1),je=BigInt(2),Mi=BigInt(3),Ki=BigInt(4),zi=BigInt(5),ff=BigInt(7),Vi=BigInt(8),uf=BigInt(9),Zi=BigInt(16);df=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];qi=new WeakMap,wr=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}=gf(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 Nt(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 Nt(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Nt(t*t,this.ORDER)}add(t,e){return Nt(t+e,this.ORDER)}sub(t,e){return Nt(t-e,this.ORDER)}mul(t,e){return Nt(t*e,this.ORDER)}pow(t,e){return pf(this,t,e)}div(t,e){return Nt(t*Pi(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 Pi(t,this.ORDER)}sqrt(t){let e=qi.get(this);return e||qi.set(this,e=hf(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?ro(t,this.BYTES):mr(t,this.BYTES)}fromBytes(t,e=!1){ut(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=Nt(f,s)),!e&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return qe(this,t)}cmov(t,e,r){return Ne(r,"condition"),r?e:t}};Object.freeze(wr.prototype)});function Ji(n){let t=n;if(typeof t!="function")throw new TypeError("Point must be a constructor");qt({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"}),Pe(t.Fp),Pe(t.Fn)}function Rn(n,t){let e=t.negate();return n?e:t}function lo(n,t){let e=qe(n.Fp,t.map(r=>r.Z));return t.map((r,o)=>n.fromAffine(r.toAffine(e[o])))}function ts(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){ts(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 Wi(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 mf(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 yf(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 es.get(n)||1}function Xi(n){if(n!==ln)throw new Error("invalid wNAF")}function ns(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 rs(n,t,e){let r=n.Fn;mf(t,n),yf(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 Qi(n,t,e){if(t){if(t.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Pe(t),t}else return fn(n,{isLE:e})}function os(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=Qi(t.p,e.Fp,r),i=Qi(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 br(n,t){return function(r){let o=n(r);return{secretKey:o,publicKey:t(o)}}}var ln,Me,uo,es,xr,Er=St(()=>{H();De();an();ln=BigInt(0),Me=BigInt(1);uo=new WeakMap,es=new WeakMap;xr=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}=Wi(r,c,s);r=f,u?i=i.add(Rn(h,e[d])):o=o.add(Rn(a,e[l]))}return Xi(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}=Wi(r,s,i);if(r=c,!l){let a=e[f];o=o.add(u?a.negate():a)}}return Xi(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){ts(e,this.bits),es.set(t,e),uo.delete(t)}hasCache(t){return ao(t)!==1}}});function is(n){if(!Number.isSafeInteger(n)||n<0||n>4294967295)throw new Error("wrong u32 integer:"+n);return n}function wf(n){if(is(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 is(n),31-Math.clz32(n)}function ss(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=wf(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 q=0;q<a;q++)S[q]=i.sub(u,m[q]);let T=i.invertBatch(S);for(let q=0;q<a;q++)w[q]=i.mul(I,i.mul(m[q],T[q]));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 cs=St(()=>{H()});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 bf(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 fs(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 Ef(n,t,e,r){ut(n),Pt(e),t=fs(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=[bf(a,u[d-1]),Ke(d+1,1),c];u[d]=r(it(...p))}return it(...u).slice(0,e)}function Bf(n,t,e,r,o){if(ut(n),Pt(e),t=fs(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){qt(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"),ut(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=Ef(n,f,a,s);else if(c==="xof")h=Bf(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]=Nt(xf(B),r)}d[p]=m}return d}function us(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]=qe(n,[s,f],!0);return r=n.mul(i,l),o=n.mul(o,n.mul(c,u)),{x:r,y:o}}}function as(n,t,e){if(typeof t!="function")throw new Error("mapToCurve() must be defined");let r=c=>Object.freeze({...c,DST:ke(c.DST)?yr(c.DST):c.DST,...c.encodeDST===void 0?{}:{encodeDST:ke(c.encodeDST)?yr(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:Sf},f);return po(c,1,u)[0][0]}})}var xf,Sf,ls=St(()=>{H();De();an();xf=_t;Sf="HashToScalar-"});function go(n){qt(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"}),Ji(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=kt)=>{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},q=(g,x)=>({identifier:g,hiding:S(t.BASE.multiply(e.fromBytes(x.hiding))),binding:S(t.BASE.multiply(e.fromBytes(x.binding)))}),ct=n.adjustPoint===void 0?g=>g:n.adjustPoint,$=g=>{if(!e.isValid(g)||e.is0(g))throw new Error("Invalid identifier "+g);return g},K=g=>pe(e.toBytes($(g))),nt=g=>{let x=$(e.fromBytes(rn(g)));if(K(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=kt)=>{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",k={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=ss(e,k),A=(g,x)=>rs(t,g,x),L=(g,x)=>{if(!x.length)throw new Error("empty coefficients");return U.monomial.eval(x,g)},C=(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,N=e.ONE;for(let M of g)e.eql(M,x)||(_=e.mul(_,M),N=e.mul(N,e.sub(M,x)));return e.div(_,N)},D=(g,x)=>{let v=U.monomial.basis(g,x.length);return A(x,v)},O=(g,x,v,R=kt)=>{Br(g);let _=x===void 0?I(R):e.fromBytes(x);if(!v){v=[];for(let z=0;z<g.min-1;z++)v.push(I(R))}if(v.length!==g.min-1)throw new Error("wrong coefficients length");let N=[_,...v],M=N.map(z=>t.BASE.multiply(z));return{coefficients:N,commitment:M,secret:_}},P={challenge:(g,x,v)=>E(it(e.toBytes(g),S(x),S(v))),compute(g,x,v,R=kt){if(x.length<1)throw new Error("coefficients should have at least one element");let{point:_,scalar:N}=rt(R),M=v[0],z=this.challenge(g,M,_),X=e.add(N,e.mul(x[0],z));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),N=T(x[0]),M=this.challenge(g,N,R);if(!R.equals(t.BASE.multiply(_).subtract(N.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=kt){let{point:R,scalar:_}=rt(v),N=t.BASE.multiply(x),M=this.challenge(R,N,g),z=e.add(_,e.mul(M,x));return[R,z]},verify(g,x,v,R){n.adjustPoint&&(R=n.adjustPoint(R)),n.adjustPoint&&(x=n.adjustPoint(x));let _=this.challenge(x,R,g),N=t.BASE.multiply(v),M=R.multiply(_),z=N.subtract(M).subtract(x);return z.clearCofactor&&(z=z.clearCofactor()),t.ZERO.equals(z)}},lt=(g,x,v)=>{if(!t.BASE.multiply(v).equals(D(g,x)))throw new Error("invalid secret share")},ft={fromNumber(g){if(!Number.isSafeInteger(g))throw new Error("expected safe interger");return K(BigInt(g))},derive(g){if(typeof g!="string")throw new Error("wrong identifier string: "+g);return K(B(le(g)))}},J=(g,x=kt)=>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 N=w(it(..._)),M=it(S(g),m(v),N),z={};for(let[gt,Z]of R)z[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,z[gt])}let Tt=A(X,et);return{identifiers:R.map(gt=>gt[1]),groupCommitment:Tt,bindingFactors:z}},dt=(g,x,v,R)=>{let _=ct(T(g)),N=nt(R),{identifiers:M,groupCommitment:z,bindingFactors:X}=wt(_,x,v),et=X[R],Tt=C(M,N),ie=j.challenge(z,_,v);return{lambda:Tt,challenge:ie,bindingFactor:et,groupCommitment:z}};Object.freeze(ft);let Lt={Identifier:ft,DKG:Object.freeze({round1:(g,x,v,R=kt)=>{Br(x);let _=nt(g),{coefficients:N,commitment:M}=O(x,v,void 0,R),z=P.compute(_,N,M,R),X=M.map(S),et={identifier:K(_),commitment:X,proofOfKnowledge:z},Tt={identifier:_,coefficients:N,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="+K(_));P.validate(_,R.commitment,R.proofOfKnowledge);for(let M of R.commitment)T(M);if(v[R.identifier])throw new Error("Duplicate id="+_);let N=e.toBytes(L(_,g.coefficients));v[R.identifier]={identifier:K(g.identifier),signingShare:N}}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 N=g.commitment.map(T),M=L(g.identifier,g.coefficients);lt(g.identifier,N,M);let z=N.map(S),X={[K(g.identifier)]:z};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),Hr=mt.commitment.map(T);lt(g.identifier,Hr,Ye),_=e.add(_,Ye);let En=K(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:K(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=kt){if(Br(g),x===void 0){x=[];for(let et=1;et<=g.max;et++)x.push(ft.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 N=O(g,v,void 0,R),M=N.commitment.map(S),z={},X={};for(let et of x){let Tt=L(_[et],N.coefficients);X[et]=S(t.BASE.multiply(Tt)),z[et]={identifier:et,signingShare:e.toBytes(Tt)}}return{public:{signers:{min:g.min,max:g.max},commitments:M,verifyingShares:X},secretShares:z}},validateSecret(g,x){let v=nt(g.identifier),R=x.commitments.map(T),_=e.fromBytes(g.signingShare);lt(v,R,_)},commit(g,x=kt){let v=e.fromBytes(g.signingShare),R=J(v,x),_=J(v,x),N={hiding:e.toBytes(R),binding:e.toBytes(_)};return{nonces:N,commitments:q(g.identifier,N)}},signShare(g,x,v,R,_){hs(x.signers,R.length);let N=e.fromBytes(v.hiding),M=e.fromBytes(v.binding);if(e.is0(N)||e.is0(M))throw new Error("signing nonces already used");let z={identifier:g.identifier,hiding:S(t.BASE.multiply(N)),binding:S(t.BASE.multiply(M))},X=R.find(fc=>fc.identifier===g.identifier);if(!X)throw new Error("missing signer commitment");if(pe(X.hiding)!==pe(z.hiding)||pe(X.binding)!==pe(z.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):N,Ye=n.adjustNonces?e.fromBytes(mt.binding):M,Hr=e.mul(e.mul(Tt,et),ie),En=e.mul(Ye,gt),cc=e.toBytes(e.add(e.add(Ft,En),Hr));return v.hiding.fill(0),v.binding.fill(0),cc},verifyShare(g,x,v,R,_){n.adjustPublic&&(g=n.adjustPublic(g));let N=x.find(Ye=>Ye.identifier===R);if(!N)throw new Error("cannot find identifier commitment");let M=T(g.verifyingShares[R]),z=T(N.hiding),X=T(N.binding),{lambda:et,challenge:Tt,bindingFactor:ie,groupCommitment:gt}=dt(g.commitments[0],x,v,R),Z=z.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{hs(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 N=T(g.commitments[0]),{groupCommitment:M}=wt(N,x,v),z=e.ZERO;for(let X of _)z=e.add(z,e.fromBytes(R[X]));if(!j.verify(v,M,z,N)){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,z)},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:N}=W.decode(g);return j.verify(x,_,N,R)},combineSecret(g,x){if(Br(x),!Array.isArray(g)||g.length<x.min)throw new Error("wrong secret shares array");let v=[],R={};for(let M of g){let z=nt(M.identifier),X=K(z);if(R[X])throw new Error("duplicated id="+X);R[X]=!0,v.push([z,e.fromBytes(M.signingShare)])}let _=v.map(([M])=>M),N=e.ZERO;for(let[M,z]of v)N=e.add(N,e.mul(z,C(_,M)));return e.toBytes(N)},utils:Object.freeze({Fn:e,randomScalar:(g=kt)=>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 Br,hs,hn,ds=St(()=>{H();be();De();Er();cs();an();Br=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)},hs=(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,Sr=St(()=>{H();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(tr(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),er(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 Af(n,t,e){oo("scalar",n,Mt,e);let[[r,o],[i,s]]=t,c=ps(s*n,e),f=ps(-o*n,e),l=n-c*r-f*i,u=-c*o-f*s,a=l<Mt,h=u<Mt;a&&(l=-l),h&&(u=-u);let d=cn(Math.ceil(He(e)/2))+Et;if(l<Mt||l>=d||u<Mt||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){qt(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 gs(n,t={}){let e=os("weierstrass",n,t),r=e.Fp,o=e.Fn,i=e.CURVE,{h:s,n:c}=i;qt(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=ws(r,o);function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(rt,F,k){if(l&&F.is0())return Uint8Array.of(0);let{x:U,y:A}=F.toAffine(),L=r.toBytes(U);if(Ne(k,"isCompressed"),k){a();let C=!r.isOdd(A);return it(ms(C),L)}else return it(Uint8Array.of(4),L,r.toBytes(A))}function d(rt){ut(rt,void 0,"Point");let{publicKey:F,publicKeyUncompressed:k}=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 C=r.fromBytes(L);if(!r.isValid(C))throw new Error("bad point: is not on curve, wrong x");let D=w(C),O;try{O=r.sqrt(D)}catch(lt){let ft=lt instanceof Error?": "+lt.message:"";throw new Error("bad point: is not on curve, sqrt error"+ft)}a();let P=r.isOdd(O);return(A&1)===1!==P&&(O=r.neg(O)),{x:C,y:O}}else if(U===k&&A===4){let C=r.BYTES,D=r.fromBytes(L.subarray(0,C)),O=r.fromBytes(L.subarray(C,C*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=${k}`)}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),k=r.mul(F,rt);return r.add(r.add(k,r.mul(rt,i.a)),i.b)}function E(rt,F){let k=r.sqr(F),U=w(rt);return r.eql(k,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,k=!1){if(!r.isValid(F)||k&&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 q(rt){if(!f||!f.basises)throw new Error("no endo");return Af(rt,f.basises,o.ORDER)}function ct(rt,F,k,U,A){return k=new $(r.mul(k.X,rt),k.Y,k.Z),F=Rn(U,F),k=Rn(A,k),F.add(k)}let W=class W{constructor(F,k,U){y(this,"X");y(this,"Y");y(this,"Z");this.X=S("x",F),this.Y=S("y",k,!0),this.Z=S("z",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(F){let{x:k,y:U}=F||{};if(!F||!r.isValid(k)||!r.isValid(U))throw new Error("invalid affine point");if(F instanceof W)throw new Error("projective point not allowed");return r.is0(k)&&r.is0(U)?W.ZERO:new W(k,U,r.ONE)}static fromBytes(F){let k=W.fromAffine(m(ut(F,void 0,"point")));return k.assertValidity(),k}static fromHex(F){return W.fromBytes(rn(F))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(F=8,k=!0){return nt.createCache(this,F),k||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:k,y:U}=F.toAffine();if(!r.isValid(k)||!r.isValid(U))throw new Error("bad point: x or y not field elements");if(!E(k,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:k,Y:U,Z:A}=this,{X:L,Y:C,Z:D}=F,O=r.eql(r.mul(k,D),r.mul(L,A)),P=r.eql(r.mul(U,D),r.mul(C,A));return O&&P}negate(){return new W(this.X,r.neg(this.Y),this.Z)}double(){let{a:F,b:k}=i,U=r.mul(k,dn),{X:A,Y:L,Z:C}=this,D=r.ZERO,O=r.ZERO,P=r.ZERO,j=r.mul(A,A),lt=r.mul(L,L),ft=r.mul(C,C),J=r.mul(A,L);return J=r.add(J,J),P=r.mul(A,C),P=r.add(P,P),D=r.mul(F,P),O=r.mul(U,ft),O=r.add(D,O),D=r.sub(lt,O),O=r.add(lt,O),O=r.mul(D,O),D=r.mul(J,D),P=r.mul(U,P),ft=r.mul(F,ft),J=r.sub(j,ft),J=r.mul(F,J),J=r.add(J,P),P=r.add(j,j),j=r.add(P,j),j=r.add(j,ft),j=r.mul(j,J),O=r.add(O,j),ft=r.mul(L,C),ft=r.add(ft,ft),j=r.mul(ft,J),D=r.sub(D,j),P=r.mul(ft,lt),P=r.add(P,P),P=r.add(P,P),new W(D,O,P)}add(F){T(F);let{X:k,Y:U,Z:A}=this,{X:L,Y:C,Z:D}=F,O=r.ZERO,P=r.ZERO,j=r.ZERO,lt=i.a,ft=r.mul(i.b,dn),J=r.mul(k,L),wt=r.mul(U,C),dt=r.mul(A,D),Lt=r.add(k,U),g=r.add(L,C);Lt=r.mul(Lt,g),g=r.add(J,wt),Lt=r.sub(Lt,g),g=r.add(k,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(C,D),x=r.mul(x,O),O=r.add(wt,dt),x=r.sub(x,O),j=r.mul(lt,g),O=r.mul(ft,dt),j=r.add(O,j),O=r.sub(wt,j),j=r.add(wt,j),P=r.mul(O,j),wt=r.add(J,J),wt=r.add(wt,J),dt=r.mul(lt,dt),g=r.mul(ft,g),wt=r.add(wt,dt),dt=r.sub(J,dt),dt=r.mul(lt,dt),g=r.add(g,dt),J=r.mul(wt,g),P=r.add(P,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,P,j)}subtract(F){return T(F),this.add(F.negate())}is0(){return this.equals(W.ZERO)}multiply(F){let{endo:k}=t;if(!o.isValidNot0(F))throw new RangeError("invalid scalar: out of range");let U,A,L=C=>nt.cached(this,C,D=>lo(W,D));if(k){let{k1neg:C,k1:D,k2neg:O,k2:P}=q(F),{p:j,f:lt}=L(D),{p:ft,f:J}=L(P);A=lt.add(J),U=ct(k.beta,j,ft,C,O)}else{let{p:C,f:D}=L(F);U=C,A=D}return lo(W,[U,A])[0]}multiplyUnsafe(F){let{endo:k}=t,U=this,A=F;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===Mt||U.is0())return W.ZERO;if(A===Et)return U;if(nt.hasCache(this))return this.multiply(A);if(k){let{k1neg:L,k1:C,k2neg:D,k2:O}=q(A),{p1:P,p2:j}=ns(W,U,C,O);return ct(k.beta,P,j,L,D)}else return nt.unsafe(U,A)}toAffine(F){let k=this,U=F,{X:A,Y:L,Z:C}=k;if(r.eql(C,r.ONE))return{x:A,y:L};let D=k.is0();U==null&&(U=D?r.ONE:r.inv(C));let O=r.mul(A,U),P=r.mul(L,U),j=r.mul(C,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:P}}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,K=o.BITS,nt=new xr($,t.endo?Math.ceil(K/2):K);return K>=8&&$.BASE.precompute(8),Object.freeze($.prototype),Object.freeze($),$}function ms(n){return Uint8Array.of(n?2:3)}function vf(n,t){let e=Pe(n),r=e.ORDER,o=Mt;for(let m=r-Et;m%te===Mt;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 q=e.eql(S,e.ONE);B=e.mul(I,d),S=e.mul(T,E),I=e.cmov(B,I,q),T=e.cmov(S,T,q);for(let ct=i;ct>Et;ct--){let $=ct-te;$=te<<$-Et;let K=e.pow(T,$),nt=e.eql(K,e.ONE);B=e.mul(I,E),E=e.mul(E,E),K=e.mul(T,E),I=e.cmov(B,I,nt),T=e.cmov(K,T,nt)}return{isValid:!e.is0(w)&&(q||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 q=e.mul(T,w),ct=e.mul(e.sqr(T),B),$=e.eql(ct,E),K=e.cmov(q,T,$);return{isValid:!e.is0(B)&&$,value:K}}}return p}function ys(n,t){let e=Pe(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=vf(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=qe(e,[d],!0)[0];return w=e.mul(w,T),{x:w,y:E}}}function ws(n,t){return{secretKey:t.BYTES,publicKey:1+n.BYTES,publicKeyUncompressed:1+2*n.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function If(n,t={}){let{Fn:e}=n,r=t.randomBytes===void 0?kt:t.randomBytes,o=Object.assign(ws(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(ut(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=ut(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=br(c,f);return Object.freeze(a),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:h,Point:n,utils:a,lengths:o})}function xs(n,t,e={}){let r=t;tr(r),qt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?kt: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}=If(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,C=A==="compact"?L:A==="recovered"?L+1:void 0;return ut(U,C)}class T{constructor(A,L,C){y(this,"r");y(this,"s");y(this,"recovery");if(this.r=B("r",A),this.s=B("s",L),C!=null){if(I(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(A,L=m.format){S(A,L);let C;if(L==="der"){let{r:j,s:lt}=Vt.toSig(ut(A));return new T(j,lt)}L==="recovered"&&(C=A[0],L="compact",A=A.subarray(1));let D=p.signature/2,O=A.subarray(0,D),P=A.subarray(D,D*2);return new T(c.fromBytes(O),c.fromBytes(P),C)}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:C}=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 P=s.toBytes(O),j=n.fromBytes(it(ms((D&1)===0),P)),lt=c.inv(O),ft=ct(ut(A,void 0,"msgHash")),J=c.create(-ft*lt),wt=c.create(C*lt),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(Vt.hexFromSig(this));let{r:L,s:C}=this,D=c.toBytes(L),O=c.toBytes(C);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 q=e.bits2int===void 0?function(A){if(A.length>8192)throw new Error("input is too large");let L=_t(A),C=A.length*8-l;return C>0?L>>BigInt(C):L}:e.bits2int,ct=e.bits2int_modN===void 0?function(A){return c.create(q(A))}:e.bits2int_modN,$=cn(l);function K(U){return oo("num < 2^"+l,U,Mt,$),c.toBytes(U)}function nt(U,A){return ut(U,void 0,"message"),A?ut(r(U),void 0,"prehashed message"):U}function W(U,A,L){let{lowS:C,prehash:D,extraEntropy:O}=wo(L,m);U=nt(U,D);let P=ct(U),j=c.fromBytes(A);if(!c.isValidNot0(j))throw new Error("invalid private key");let lt=[K(j),K(P)];if(O!=null&&O!==!1){let dt=O===!0?o(p.secretKey):O;lt.push(ut(dt,void 0,"extraEntropy"))}let ft=it(...lt),J=P;function wt(dt){let Lt=q(dt);if(!c.isValidNot0(Lt))return;let g=c.inv(Lt),x=n.BASE.multiply(Lt).toAffine(),v=c.create(x.x);if(v===Mt)return;let R=c.create(g*c.create(J+v*j));if(R===Mt)return;let _=(x.x===v?0:2)|Number(x.y&Et),N=R;return C&&E(R)&&(N=c.neg(R),_^=1),new T(v,N,w?void 0:_)}return{seed:ft,k2sig:wt}}function rt(U,A,L={}){let{seed:C,k2sig:D}=W(U,A,L);return ji(r.outputLen,c.BYTES,i)(C,D).toBytes(L.format)}function F(U,A,L,C={}){let{lowS:D,prehash:O,format:P}=wo(C,m);if(L=ut(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,P);try{let j=T.fromBytes(U,P),lt=n.fromBytes(L);if(D&&j.hasHighS())return!1;let{r:ft,s:J}=j,wt=ct(A),dt=c.inv(J),Lt=c.create(wt*dt),g=c.create(ft*dt),x=n.BASE.multiplyUnsafe(Lt).add(lt.multiplyUnsafe(g));return x.is0()?!1:c.create(x.x)===ft}catch{return!1}}function k(U,A,L={}){let{prehash:C}=wo(L,m);return A=nt(A,C),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:k,Signature:T,hash:r})}var ps,bo,Vt,Mt,Et,te,dn,Eo,bs=St(()=>{H();Sr();be();De();Er();an();ps=(n,t)=>(n+(n>=0?t:-t)/te)/t;bo=class extends Error{constructor(t=""){super(t)}},Vt={Err:bo,_tlv:{encode:(n,t)=>{let{Err:e}=Vt;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}=Vt;t=ut(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}=Vt;if(gr(n),n<Mt)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}=Vt;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}=Vt,o=ut(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}=Vt,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(Vt._tlv);Object.freeze(Vt._int);Object.freeze(Vt);Mt=BigInt(0),Et=BigInt(1),te=BigInt(2),dn=BigInt(3),Eo=BigInt(4)});var Io={};Gn(Io,{__TEST:()=>_f,schnorr:()=>Of,schnorr_FROST:()=>jf,secp256k1:()=>Uf,secp256k1_FROST:()=>kf,secp256k1_hasher:()=>Ao});function Ff(n){let t=Ar.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=Ht(u,e,t)*u%t,h=Ht(a,e,t)*u%t,d=Ht(h,Bo,t)*l%t,p=Ht(d,o,t)*d%t,m=Ht(p,i,t)*p%t,w=Ht(m,c,t)*m%t,E=Ht(w,f,t)*w%t,B=Ht(E,c,t)*m%t,I=Ht(B,e,t)*u%t,S=Ht(I,s,t)*p%t,T=Ht(S,r,t)*l%t,q=Ht(T,Bo,t);if(!ge.eql(ge.sqr(q),n))throw new Error("Cannot find square root");return q}function On(n,...t){let e=Es[n];if(e===void 0){let r=Ae(sn(n));e=it(r,r),Es[n]=e}return Ae(it(e,...t))}function vs(n){let{Fn:t,BASE:e}=at,r=t.fromBytes(n),o=e.multiply(r);return{scalar:ee(o.y)?r:t.neg(r),bytes:ze(o)}}function vr(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=at.fromAffine({x:n,y:o});return i.assertValidity(),i}function So(...n){return at.Fn.create(pn(On("BIP0340/challenge",...n)))}function Bs(n){return vs(n).bytes}function Rf(n,t,e=An(32)){let{Fn:r,BASE:o}=at,i=ut(n,void 0,"message"),{bytes:s,scalar:c}=vs(t),f=ut(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),!Is(w,i,s))throw new Error("sign: Invalid signature produced");return w}function Is(n,t,e){let{Fp:r,Fn:o,BASE:i}=at,s=ut(n,64,"signature"),c=ut(t,void 0,"message"),f=ut(e,32,"publicKey");try{let l=vr(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 Ts(n,t){if(t===void 0)return As;let e=ze(n),r=_t(On("TapTweak",e,t));if(!at.Fn.isValid(r))throw new Error("invalid TapTweak hash");return r}function vo(n){let t=at.fromBytes(n.commitments[0]);return ee(t.y)?n:{signers:{min:n.signers.min,max:n.signers.max},commitments:n.commitments.map(e=>at.fromBytes(e).negate().toBytes()),verifyingShares:Object.fromEntries(Object.entries(n.verifyingShares).map(([e,r])=>[e,at.fromBytes(r).negate().toBytes()]))}}function Fs(n,t){let e=at.fromBytes(t.commitments[0]);if(ee(e.y))return n;let r=at.Fn;return{...n,signingShare:r.toBytes(r.neg(r.fromBytes(n.signingShare)))}}function Nf(n,t){if(ee(n.y))return t;let e=at.Fn;return{binding:e.toBytes(e.neg(e.fromBytes(t.binding))),hiding:e.toBytes(e.neg(e.fromBytes(t.hiding)))}}function Hf(n,t,e){let r=at.Fn,o=Fs(n,t),i=vo(t),s=Ts(at.fromBytes(i.commitments[0]),e),c=r.toBytes(r.add(r.fromBytes(o.signingShare),s));return{identifier:o.identifier,signingShare:c}}function Df(n,t){let e=vo(n),r=Ts(at.fromBytes(e.commitments[0]),t),o=at.BASE.multiply(r),i=e.commitments.map((c,f)=>(f===0?at.fromBytes(c).add(o):at.fromBytes(c)).toBytes()),s={};for(let c in e.verifyingShares)s[c]=at.fromBytes(e.verifyingShares[c]).add(o).toBytes();return{signers:{min:e.signers.min,max:e.signers.max},commitments:i,verifyingShares:s}}var Ar,Tf,As,Bo,ge,at,Uf,Es,ze,ee,pn,_f,Of,Lf,Ss,Cf,Ao,kf,jf,To=St(()=>{H();hr();be();Er();ds();ls();an();bs();De();Ar={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Tf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},As=BigInt(0),Bo=BigInt(2);ge=fn(Ar.p,{sqrt:Ff}),at=gs(Ar,{Fp:ge,endo:Tf}),Uf=xs(at,Ae),Es={};ze=n=>n.toBytes(!0).slice(1),ee=n=>n%Bo===As;pn=_t;_f=Object.freeze({lift_x:vr}),Of=(()=>{let e=r=>(r=r===void 0?An(48):r,un(r,Ar.n));return Object.freeze({keygen:br(e,Bs),getPublicKey:Bs,sign:Rf,verify:Is,Point:at,utils:Object.freeze({randomSecretKey:e,taggedHash:On,lift_x:vr,pointToBytes:ze}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),Lf=us(ge,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(n=>n.map(t=>BigInt(t)))),Cf=()=>Ss||(Ss=ys(ge,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:ge.create(BigInt("-11"))})),Ao=as(at,n=>{let{x:t,y:e}=Cf()(ge.create(n[0]));return Lf(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}),kf=go({name:"FROST-secp256k1-SHA256-v1",Point:at,hashToScalar:Ao.hashToScalar,hash:Ae});jf=go({name:"FROST-secp256k1-SHA256-TR-v1",Point:at,hashToScalar:Ao.hashToScalar,hash:Ae,parsePublicKey(n){if(n.length===32)return vr(_t(n));if(n.length===33)return at.fromBytes(n);throw new Error(`expected x-only or compressed public key, got length=${n.length}`)},adjustScalar(n){let t=at.BASE.multiply(n);return ee(t.y)?n:at.Fn.neg(n)},adjustPoint:n=>ee(n.y)?n:n.negate(),challenge(n,t,e){return So(ze(n),ze(t),e)},adjustNonces:Nf,adjustGroupCommitmentShare:(n,t)=>ee(n.y)?t:t.negate(),adjustPublic:vo,adjustSecret:Fs,adjustTx:{encode:n=>n.subarray(1),decode:n=>it(Uint8Array.of(2),n)},adjustDKG:n=>{let t=new Uint8Array(0);return{public:Df(n.public,t),secret:Hf(n.secret,n.public,t)}}})});function Pf(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}function qf(n){if(typeof n!="boolean")throw new TypeError(`boolean expected, not ${n}`)}function Ir(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=Pf(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 Tr(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 Us(n,t,e){Ir(n),Ir(t),qf(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 Kt,Ve,Y,Mf,tt,ne,Ro=St(()=>{H();Kt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,Ve=n=>n<<24&4278190080|n<<8&16711680|n>>>8&65280|n>>>24&255,Y=Kt?n=>n:n=>Ve(n)>>>0,Mf=n=>{for(let t=0;t<n.length;t++)n[t]=Ve(n[t]);return n},tt=Kt?n=>n:Mf;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 Vf(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,Kf,zf,Dn,ve,Zf,Fr,_o,Lo,Rs,_s=St(()=>{H();Ro();me=16,Oo=new Uint8Array(16),re=Q(Oo),Kf=225,zf=(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^Kf<<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));Zf=n=>n>64*1024?8:n>1024?4:2,Fr=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}=zf(o,i,s,c);let l=Zf(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:q,s1:ct,s2:$,s3:K}=f[l*p+S];w^=q,E^=ct,B^=$,I^=K}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:q}=s[d*c+B];f^=I,l^=S,u^=T,a^=q,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 Fr{constructor(t,e){G(t);let r=Vf(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 Fr(n,t),n=>[n.length]),Rs=Hn(16,(n,t)=>new _o(n,t),n=>[n.length])});var Mo={};Gn(Mo,{__TESTS:()=>au,aeskw:()=>ru,aeskwp:()=>ou,aessiv:()=>fu,cbc:()=>Jf,cfb:()=>tu,cmac:()=>Pn,ctr:()=>xn,ecb:()=>Qf,gcm:()=>eu,gcmsiv:()=>nu,rngAesCtrDrbg128:()=>iu,rngAesCtrDrbg256:()=>su,siv:()=>cu,unsafe:()=>uu});function Rr(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 Po(n){return n<<1^Gf&-(n>>7)}function mn(n,t){let e=0;for(;t>0;t>>=1)e^=n&-(t&1),n=Po(n);return e}function Cs(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 Zt(n){G(n);let t=n.length;Rr(n);let{sbox2:e}=qo,r=[];(!Kt||!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(Wf(l))^Xf[f/i-1]:i>6&&f%i===4&&(l=s(l)),c[f]=c[f-i]^l}return st(...r),c}function _r(n){let t=Zt(n),e=t.slice(),r=t.length,{sbox2:o}=qo,{T0:i,T1:s,T2:c,T3:f}=ks;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}=qo,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}=ks,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 Ns(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),qn(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=Tr(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=Tr(B);for(let S=E,T=0;S<a;S++,T++)o[S]=r[S]^I[T];st(B)}return o}function Hs(n){if(G(n),n.length%ot!==0)throw new Error("aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size "+ot)}function Ds(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),(!Kt||!Bt(n))&&(n=pt(n));let i=Q(n);tt(i);let s=Q(e);return{b:i,o:s,out:e}}function js(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 Ps(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 qs(n,t,e,r,o){let i=o?o.length:0,s=n.create(e,r.length+i);o&&s.update(o);let c=Us(8*r.length,8*i,t);s.update(r),s.update(c);let f=s.digest();return st(c),f}function Ms(n){return n instanceof Uint32Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint32Array"}function Mn(n,t){if(G(t,16,"block"),!Ms(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 Ks(n,t){if(G(t,16,"block"),!Ms(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 Vs(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){Rr(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 Pn($f,n);let r=Pn(jn,n);for(let c=0;c<e-1;c++){Kn(r);let f=Pn(t[c],n);$e(r,f),st(f)}let o=t[e-1];G(o);let i;if(o.byteLength>=ot)i=Vs(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=Pn(i,n);return st(r,i),s}var ot,jo,jn,$f,Gf,qn,ko,Yf,Wf,Co,qo,ks,Xf,xn,Qf,Jf,tu,eu,wn,nu,Ur,Os,ru,Ls,ou,No,zs,iu,su,Ho,Pn,cu,fu,uu,au,Ko=St(()=>{H();_s();Ro();ot=16,jo=4,jn=new Uint8Array(ot),$f=Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]),Gf=283;qn=(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^=Po(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})(),Yf=ko.map((n,t)=>ko.indexOf(t)),Wf=n=>n<<24|n>>>8,Co=n=>n<<8|n>>>24;qo=Cs(ko,n=>mn(n,3)<<24|n<<16|n<<8|mn(n,2)),ks=Cs(Yf,n=>mn(n,11)<<24|mn(n,13)<<16|mn(n,9)<<8|mn(n,14)),Xf=(()=>{let n=new Uint8Array(16);for(let t=0,e=1;t<16;t++,e=Po(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=Zt(t),c=pt(e),f=[s,c];Bt(o)||f.push(o=pt(o));let l=Ns(s,c,o,i);return st(...f),l}return{encrypt:(o,i)=>r(o,i),decrypt:(o,i)=>r(o,i)}});Qf=ne({blockSize:16},function(t,e={}){let r=!e.disablePadding;return{encrypt(o,i){let{b:s,o:c,out:f}=Ds(o,r,i),l=Zt(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=Ps(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){Hs(o);let s=_r(t);i=Ze(o.length,i);let c=[s];kn(o,i),(!Kt||!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),js(i,r)}}}),Jf=ne({blockSize:16,nonceLength:16},function(t,e,r={}){let o=!r.disablePadding;return{encrypt(i,s){let c=Zt(t),{b:f,o:l,out:u}=Ds(i,o,s),a=e,h=[c];(!Kt||!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=Ps(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){Hs(i);let c=_r(t),f=e,l=[c];(!Kt||!Bt(f))&&l.push(f=pt(f));let u=Q(f);tt(u),s=Ze(i.length,s),kn(i,s),(!Kt||!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:q,s1:ct,s2:$,s3:K}=zn(c,d,p,m,w);h[E++]=q^B,h[E++]=ct^I,h[E++]=$^S,h[E++]=K^T}return tt(h),st(...l),js(s,o)}}}),tu=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=Zt(t),l=e,u=[f];(!Kt||!Bt(l))&&u.push(l=pt(l)),(!Kt||!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:q,s2:ct,s3:$}=Ot(f,m,w,E,B);h[S+0]=a[S+0]^T,h[S+1]=a[S+1]^q,h[S+2]=a[S+2]^ct,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=Tr(S);for(let q=I,ct=0;q<c;q++,ct++)s[q]=o[q]^T[ct];st(T)}return tt(h),st(...u),s}return{encrypt:(o,i)=>r(o,!0,i),decrypt:(o,i)=>r(o,!1,i)}});eu=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=qs(Lo,!1,c,l,r);for(let a=0;a<f.length;a++)u[a]^=f[a];return u}function s(){let c=Zt(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)}},nu=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),Rr(t),c(e.length),r!==void 0&&i(r.length);function l(){let h=Zt(t),d=new Uint8Array(t.length),p=new Uint8Array(16),m=[h,d],w=e;(!Kt||!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],q=0;for(let $ of[p,d].map(Q)){let K=Q($);for(let nt=0;nt<K.length;nt+=2){let{s0:W,s1:rt}=Ot(h,B,I,S,T);K[nt+0]=W,K[nt+1]=rt,B=++q}tt(K)}let ct={authKey:p,encKey:Zt(d)};return st(...m),ct}function u(h,d,p){let m=qs(Rs,!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}}});Ur={encrypt(n,t){if(t.length>=2**32)throw new Error("plaintext should be less than 4gb");let e=Zt(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=_r(n),r=t.length/8-1;if(r===1)Ks(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)}},Os=new Uint8Array(8).fill(166),ru=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(Os,t);return Ur.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(Ur.decrypt(n,e),!Nn(e.subarray(0,8),Os))throw new Error("integrity check failed");return e.subarray(0,8).fill(0),e.subarray(8)}})),Ls=2790873510,ou=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(Ls),o[1]=Y(Ve(t.length)),Ur.encrypt(n,r),r},decrypt(t){if(t.length<16)throw new Error("invalid ciphertext length");let e=pt(t),r=Q(e);Ur.decrypt(n,e);let o=Ve(Y(r[1]))>>>0,i=Math.ceil(o/8)*8;if(Y(r[0])!==Ls||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,qn(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]}qn(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(Ir(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),qn(this.nonce,!1,Math.ceil(t/this.blockLen)),this.update(e),this.reseedCnt++,r}clean(){this.state.fill(0),this.reseedCnt=0}},zs=n=>(t,e=void 0)=>new No(n,t,e),iu=zs(128),su=zs(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),Rr(t),this.xk=Zt(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))}},Pn=Hn(16,n=>new Ho(n));cu=()=>{throw new Error('"siv" from v1 is now "gcmsiv"')},fu=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")}}}),uu=Object.freeze({expandKeyLE:Zt,expandKeyDecLE:_r,encrypt:Ot,decrypt:zn,encryptBlock:Mn,decryptBlock:Ks,ctrCounter:Ns,ctr32:yn,dbl:Kn,xorBlock:$e,xorend:Vs,s2v:Do}),au=Object.freeze({incBytes:qn})});var Ys=$t((Ya,Gs)=>{"use strict";H();var{secp256k1:Zs}=(To(),ye(Io)),{sha512:lu,sha256:hu}=(hr(),ye(to)),{hmac:du}=(Sr(),ye(yo)),{cbc:$s}=(Ko(),ye(Mo)),Vo=Jn(),pu=Vo.PublicKey,Te=Vo.util.preconditions,gu=Vo.crypto.Random;function Vn(n){return V.Buffer.from(n.buffer,n.byteOffset,n.byteLength)}function zo(n,t){return Vn(du(hu,n,t))}function mu(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 Or=function(){};Or.encrypt=function(n,t,e){Te.checkArgument(n),Te.checkArgument(t),Te.checkArgument(e),e=e||gu.getRandomBuffer(128/8);var r=$s(Uint8Array.from(t),Uint8Array.from(e)).encrypt(Uint8Array.from(n));return V.Buffer.concat([V.Buffer.from(e),Vn(r)])};Or.decrypt=function(n,t){Te.checkArgument(n),Te.checkArgument(t);var e=n.slice(0,128/8),r=n.slice(128/8),o=$s(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 Lr=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}})};Lr("Rbuf",function(){var n=this._privateKey.bn.toBuffer({size:32});return Vn(Zs.getPublicKey(Uint8Array.from(n),!0))});Lr("kEkM",function(){var n=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),e=Zs.getSharedSecret(Uint8Array.from(n),Uint8Array.from(t),!0),r=e.slice(1);return Vn(lu(r))});Lr("kE",function(){return this.kEkM.slice(0,32)});Lr("kM",function(){return this.kEkM.slice(32,64)});bn.prototype.encrypt=function(n,t){V.Buffer.isBuffer(n)||(n=V.Buffer.from(n)),t===void 0&&(t=zo(this._privateKey.toBuffer(),n).slice(0,16));var e=Or.encrypt(n,this.kE,t),r=zo(this.kM,e);return this.opts.shortTag&&(r=r.slice(0,4)),this.opts.noKey?V.Buffer.concat([e,r]):V.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=pu.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)),!mu(i,s))throw new Error("Invalid checksum");return Or.decrypt(o,this.kE)};Gs.exports=bn});var Xs=$t((Xa,Ws)=>{"use strict";H();var yu={name:"ECIES",message:"Internal Error on bsv-ecies Module {0}",errors:[{name:"DecryptionError",message:"Invalid Message: {0}"},{name:"UnsupportAlgorithm",message:"Unsupport Algorithm: {0}"}]};Ws.exports=Jn().errors.extend(yu)});var rc=$t((Ja,nc)=>{"use strict";H();var kr=Jn(),Zo=kr.PublicKey,Qs=kr.PrivateKey,Dt=kr.util.preconditions,wu=Ys(),Cr=Xs(),{secp256k1:Js}=(To(),ye(Io)),{sha512:xu,sha256:bu}=(hr(),ye(to)),{hmac:Eu}=(Sr(),ye(yo)),{cbc:tc}=(Ko(),ye(Mo));function Zn(n){return V.Buffer.from(n.buffer,n.byteOffset,n.byteLength)}function ec(n,t){return Zn(Eu(bu,t,n))}var Nr=function(){};Nr.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"),Zn(tc(Uint8Array.from(t),Uint8Array.from(e)).encrypt(Uint8Array.from(n)))};Nr.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"),Zn(tc(Uint8Array.from(t),Uint8Array.from(e)).decrypt(Uint8Array.from(n)))};var Ge=function n(t,e="BIE1"){if(e!=="BIE1")throw new Cr.UnsupportAlgorithm(e);if(!(this instanceof n))return new n(t,e);this._privateKey=new kr.PrivateKey,this.opts=t||{},this.opts.ephemeralKey=!0};Ge.prototype.privateKey=function(n){return Dt.checkArgument(Qs.isValid(n),"no private key provided"),this._privateKey=Qs(n.toHex())||null,this.opts.ephemeralKey=!1,this};Ge.prototype.publicKey=function(n){return Dt.checkArgument(Zo.isValid(n),"no public key provided"),this._publicKey=Zo(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(Js.getPublicKey(Uint8Array.from(n),!0))});$n("ivkEkM",function(){var n=this._privateKey.bn.toBuffer({size:32}),t=this._publicKey.toDER(),e=Js.getSharedSecret(Uint8Array.from(n),Uint8Array.from(t),!0);return Zn(xu(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){V.Buffer.isBuffer(n)||(n=V.Buffer.from(n));var t=Nr.encrypt(n,this.kE,this.iv),e,r=V.Buffer.from("BIE1");this.opts.noKey&&!this.opts.ephemeralKey?e=V.Buffer.concat([r,t]):e=V.Buffer.concat([r,this.Rbuf,t]);var o=ec(e,this.kM);return this.opts.shortTag&&(o=o.slice(0,4)),V.Buffer.concat([e,o])};Ge.prototype.decrypt=function(n){Dt.checkArgument(V.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(V.Buffer.from("BIE1")))throw new Cr.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=Zo.fromDER(o),e=37}var i=n.slice(e,n.length-t),s=n.slice(n.length-t,n.length),c=ec(n.slice(0,n.length-t),this.kM);if(this.opts.shortTag&&(c=c.slice(0,4)),s.length!==c.length)throw new Cr.DecryptionError("Invalid checksum");for(var f=0,l=0;l<c.length;l++)f|=s[l]^c[l];if(f!==0)throw new Cr.DecryptionError("Invalid checksum");return Nr.decrypt(i,this.kE,this.iv)};Ge.bitcoreECIES=wu;nc.exports=Ge});var ic=$t((el,oc)=>{H();oc.exports=rc()});var Bu=$t((rl,sc)=>{H();sc.exports=ic()});return Bu();})();
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();})();
2
2
  if(typeof module!=="undefined"&&module.exports){module.exports=bsvEcies}else if(typeof define==="function"&&define.amd){define([],function(){return bsvEcies})}