@toruslabs/broadcast-channel
Version:
A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers
1 lines • 238 kB
JavaScript
"use strict";var BroadcastChannel=(()=>{var Ji=Object.defineProperty;var R0=Object.getOwnPropertyDescriptor;var I0=Object.getOwnPropertyNames;var q0=Object.prototype.hasOwnProperty;var ge=(t,e)=>()=>(t&&(e=t(t=0)),e);var S=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Br=(t,e)=>{for(var r in e)Ji(t,r,{get:e[r],enumerable:!0})},L0=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of I0(e))!q0.call(t,o)&&o!==r&&Ji(t,o,{get:()=>e[o],enumerable:!(n=R0(e,o))||n.enumerable});return t};var z=t=>L0(Ji({},"__esModule",{value:!0}),t);var Qi=S((Ku,is)=>{(function(t,e){"use strict";typeof define=="function"&&define.amd?define(e):typeof is=="object"&&is.exports?is.exports=e():t.log=e()})(Ku,function(){"use strict";var t=function(){},e="undefined",r=typeof window!==e&&typeof window.navigator!==e&&/Trident\/|MSIE /.test(window.navigator.userAgent),n=["trace","debug","info","warn","error"],o={},s=null;function i(y,w){var p=y[w];if(typeof p.bind=="function")return p.bind(y);try{return Function.prototype.bind.call(p,y)}catch{return function(){return Function.prototype.apply.apply(p,[y,arguments])}}}function a(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(y){return y==="debug"&&(y="log"),typeof console===e?!1:y==="trace"&&r?a:console[y]!==void 0?i(console,y):console.log!==void 0?i(console,"log"):t}function l(){for(var y=this.getLevel(),w=0;w<n.length;w++){var p=n[w];this[p]=w<y?t:this.methodFactory(p,y,this.name)}if(this.log=this.debug,typeof console===e&&y<this.levels.SILENT)return"No console available for logging"}function u(y){return function(){typeof console!==e&&(l.call(this),this[y].apply(this,arguments))}}function f(y,w,p){return c(y)||u.apply(this,arguments)}function d(y,w){var p=this,v,E,B,O="loglevel";typeof y=="string"?O+=":"+y:typeof y=="symbol"&&(O=void 0);function D(N){var U=(n[N]||"silent").toUpperCase();if(!(typeof window===e||!O)){try{window.localStorage[O]=U;return}catch{}try{window.document.cookie=encodeURIComponent(O)+"="+U+";"}catch{}}}function M(){var N;if(!(typeof window===e||!O)){try{N=window.localStorage[O]}catch{}if(typeof N===e)try{var U=window.document.cookie,x=encodeURIComponent(O),g=U.indexOf(x+"=");g!==-1&&(N=/^([^;]+)/.exec(U.slice(g+x.length+1))[1])}catch{}return p.levels[N]===void 0&&(N=void 0),N}}function H(){if(!(typeof window===e||!O)){try{window.localStorage.removeItem(O)}catch{}try{window.document.cookie=encodeURIComponent(O)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function P(N){var U=N;if(typeof U=="string"&&p.levels[U.toUpperCase()]!==void 0&&(U=p.levels[U.toUpperCase()]),typeof U=="number"&&U>=0&&U<=p.levels.SILENT)return U;throw new TypeError("log.setLevel() called with invalid level: "+N)}p.name=y,p.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},p.methodFactory=w||f,p.getLevel=function(){return B??E??v},p.setLevel=function(N,U){return B=P(N),U!==!1&&D(B),l.call(p)},p.setDefaultLevel=function(N){E=P(N),M()||p.setLevel(N,!1)},p.resetLevel=function(){B=null,H(),l.call(p)},p.enableAll=function(N){p.setLevel(p.levels.TRACE,N)},p.disableAll=function(N){p.setLevel(p.levels.SILENT,N)},p.rebuild=function(){if(s!==p&&(v=P(s.getLevel())),l.call(p),s===p)for(var N in o)o[N].rebuild()},v=P(s?s.getLevel():"WARN");var A=M();A!=null&&(B=P(A)),l.call(p)}s=new d,s.getLogger=function(w){if(typeof w!="symbol"&&typeof w!="string"||w==="")throw new TypeError("You must supply a name when creating a logger.");var p=o[w];return p||(p=o[w]=new d(w,s.methodFactory)),p};var h=typeof window!==e?window.log:void 0;return s.noConflict=function(){return typeof window!==e&&window.log===s&&(window.log=h),s},s.getLoggers=function(){return o},s.default=s,s})});var Xt=S(Zt=>{"use strict";var N0=Qi();function M0(t){return!!(t&&typeof t.then=="function")}Promise.resolve(!1);Promise.resolve(!0);var D0=Promise.resolve();function F0(t,e){return t||(t=0),new Promise(r=>{setTimeout(()=>r(e),t)})}function j0(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function U0(){return Math.random().toString(36).substring(2)}var ea=0;function H0(){let t=Date.now()*1e3;return t<=ea&&(t=ea+1),ea=t,t}var $u=N0.getLogger("broadcast-channel");$u.setLevel("error");Zt.PROMISE_RESOLVED_VOID=D0;Zt.generateRandomId=U0;Zt.isPromise=M0;Zt.log=$u;Zt.microSeconds=H0;Zt.randomInt=j0;Zt.sleep=F0});var Yu=S(zt=>{"use strict";Object.defineProperty(zt,"__esModule",{value:!0});zt.now=zt.removeTooOldValues=zt.ObliviousSet=void 0;var ta=class{ttl;map=new Map;_to=!1;constructor(e){this.ttl=e}has(e){let r=this.map.get(e);return typeof r>"u"?!1:r<as()-this.ttl?(this.map.delete(e),!1):!0}add(e){this.map.delete(e),this.map.set(e,as()),this._to||(this._to=!0,setTimeout(()=>{this._to=!1,Gu(this)},0))}clear(){this.map.clear()}};zt.ObliviousSet=ta;function Gu(t){let e=as()-t.ttl,r=t.map[Symbol.iterator]();for(;;){let n=r.next().value;if(!n)break;let o=n[0];if(n[1]<e)t.map.delete(o);else break}}zt.removeTooOldValues=Gu;function as(){return Date.now()}zt.now=as});var cs=S((Jt,Wu)=>{"use strict";var V0=Jt&&Jt.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),K0=Jt&&Jt.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),$0=Jt&&Jt.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&V0(e,t,r);return K0(e,t),e};Object.defineProperty(Jt,"__esModule",{value:!0});var G0=$0(Yu());Wu.exports=G0});var Zu=S(rt=>{"use strict";var zr={MAINNET:"mainnet",TESTNET:"testnet",CYAN:"cyan",AQUA:"aqua",CELESTE:"celeste"},Jr={SAPPHIRE_DEVNET:"sapphire_devnet",SAPPHIRE_MAINNET:"sapphire_mainnet"},ae={PRODUCTION:"production",DEVELOPMENT:"development",STAGING:"staging",TESTING:"testing"},Y0={[zr.AQUA]:{networkIdentifier:"aqua",networkMigratedTo:Jr.SAPPHIRE_MAINNET},[zr.CELESTE]:{networkIdentifier:"celeste",networkMigratedTo:Jr.SAPPHIRE_MAINNET},[zr.CYAN]:{networkIdentifier:"cyan",networkMigratedTo:Jr.SAPPHIRE_MAINNET},[zr.MAINNET]:{networkIdentifier:"mainnet",networkMigratedTo:Jr.SAPPHIRE_MAINNET},[zr.TESTNET]:{networkIdentifier:"teal",networkMigratedTo:Jr.SAPPHIRE_DEVNET}},W0={[ae.PRODUCTION]:"https://api.web3auth.io/citadel-service",[ae.DEVELOPMENT]:"https://api-develop.web3auth.io/citadel-service",[ae.STAGING]:"https://api.web3auth.io/citadel-service",[ae.TESTING]:"https://api-develop.web3auth.io/citadel-service"},Z0={[ae.PRODUCTION]:"https://api.web3auth.io/metadata-service",[ae.DEVELOPMENT]:"https://api-develop.web3auth.io/metadata-service",[ae.STAGING]:"https://api.web3auth.io/metadata-service",[ae.TESTING]:"https://api-develop.web3auth.io/metadata-service"},X0={[ae.PRODUCTION]:"https://api.web3auth.io/fnd-service",[ae.DEVELOPMENT]:"https://api-develop.web3auth.io/fnd-service",[ae.STAGING]:"https://api.web3auth.io/fnd-service",[ae.TESTING]:"https://api-develop.web3auth.io/fnd-service"},z0={[ae.PRODUCTION]:"https://api.web3auth.io/session-service",[ae.DEVELOPMENT]:"https://api-develop.web3auth.io/session-service",[ae.STAGING]:"https://api.web3auth.io/session-service",[ae.TESTING]:"https://api-develop.web3auth.io/session-service"},J0={[ae.PRODUCTION]:"https://session.web3auth.io",[ae.DEVELOPMENT]:"https://develop-session.web3auth.io",[ae.STAGING]:"https://session.web3auth.io",[ae.TESTING]:"https://develop-session.web3auth.io"},Q0={SECP256K1:"secp256k1",ED25519:"ed25519"},eg={ECDSA_SECP256K1:"ecdsa-secp256k1",ED25519:"ed25519",BIP340:"bip340"};rt.BUILD_ENV=ae;rt.CITADEL_SERVER_MAP=W0;rt.FND_SERVER_MAP=X0;rt.KEY_TYPE=Q0;rt.LEGACY_METADATA_MAP=Z0;rt.LEGACY_NETWORKS_ROUTE_MAP=Y0;rt.SIG_TYPE=eg;rt.STORAGE_SERVER_MAP=z0;rt.STORAGE_SERVER_SOCKET_URL_MAP=J0;rt.TORUS_LEGACY_NETWORK=zr;rt.TORUS_SAPPHIRE_NETWORK=Jr});var zu=S(Xu=>{"use strict";var tg=[{inputs:[{internalType:"string",name:"_verifier",type:"string"},{internalType:"bytes32",name:"hashedVerifierId",type:"bytes32"}],name:"getNodeSet",outputs:[{internalType:"uint256",name:"currentEpoch",type:"uint256"},{internalType:"string[]",name:"torusNodeEndpoints",type:"string[]"},{internalType:"uint256[]",name:"torusNodePubX",type:"uint256[]"},{internalType:"uint256[]",name:"torusNodePubY",type:"uint256[]"},{internalType:"uint256[]",name:"torusIndexes",type:"uint256[]"}],stateMutability:"view",type:"function"}];Xu.abi=tg});var Ju=S(Ke=>{"use strict";var at=Zu(),rg=zu();Ke.BUILD_ENV=at.BUILD_ENV;Ke.CITADEL_SERVER_MAP=at.CITADEL_SERVER_MAP;Ke.FND_SERVER_MAP=at.FND_SERVER_MAP;Ke.KEY_TYPE=at.KEY_TYPE;Ke.LEGACY_METADATA_MAP=at.LEGACY_METADATA_MAP;Ke.LEGACY_NETWORKS_ROUTE_MAP=at.LEGACY_NETWORKS_ROUTE_MAP;Ke.SIG_TYPE=at.SIG_TYPE;Ke.STORAGE_SERVER_MAP=at.STORAGE_SERVER_MAP;Ke.STORAGE_SERVER_SOCKET_URL_MAP=at.STORAGE_SERVER_SOCKET_URL_MAP;Ke.TORUS_LEGACY_NETWORK=at.TORUS_LEGACY_NETWORK;Ke.TORUS_SAPPHIRE_NETWORK=at.TORUS_SAPPHIRE_NETWORK;Ke.abi=rg.abi});var Zn=S(Qu=>{"use strict";var ra=Ju();function ng(t={}){let e=JSON.parse(JSON.stringify(t));return typeof e.webWorkerSupport>"u"&&(e.webWorkerSupport=!0),e.idb||(e.idb={}),e.idb.ttl||(e.idb.ttl=1e3*45),e.idb.fallbackInterval||(e.idb.fallbackInterval=150),t.idb&&typeof t.idb.onclose=="function"&&(e.idb.onclose=t.idb.onclose),e.localstorage||(e.localstorage={}),e.localstorage.removeTimeout||(e.localstorage.removeTimeout=1e3*60),e.server||(e.server={}),e.server.build_env||(e.server.build_env=ra.BUILD_ENV.PRODUCTION),e.server.api_url||(e.server.api_url=`${ra.STORAGE_SERVER_MAP[e.server.build_env]}/v2`),e.server.socket_url||(e.server.socket_url=`${ra.STORAGE_SERVER_SOCKET_URL_MAP[e.server.build_env]}`),e.server.removeTimeout||(e.server.removeTimeout=1e3*60*5),t.methods&&(e.methods=t.methods),e}Qu.fillOptionsWithDefaults=ng});var oa=S(fe=>{"use strict";var wt=Xt(),og=cs(),sg=Zn(),ig=wt.microSeconds,ag="pubkey.broadcast-channel-0-",ct="messages",Qr={durability:"relaxed"},cg="idb";function na(){if(typeof indexedDB<"u")return indexedDB;if(typeof window<"u"){let t=window;if(typeof t.mozIndexedDB<"u")return t.mozIndexedDB;if(typeof t.webkitIndexedDB<"u")return t.webkitIndexedDB;if(typeof t.msIndexedDB<"u")return t.msIndexedDB}return!1}function Xn(t){t.commit&&t.commit()}function ef(t){let e=na();if(!e)return Promise.reject(new Error("IndexedDB not available"));let r=ag+t,n=e.open(r);return n.onupgradeneeded=s=>{s.target.result.createObjectStore(ct,{keyPath:"id",autoIncrement:!0})},new Promise((s,i)=>{n.onerror=a=>i(a),n.onsuccess=()=>{s(n.result)}})}function tf(t,e,r){let n=Date.now(),o={uuid:e,time:n,data:r},s=t.transaction([ct],"readwrite",Qr);return new Promise((i,a)=>{s.oncomplete=()=>i(),s.onerror=l=>a(l),s.objectStore(ct).add(o),Xn(s)})}function ug(t){let e=t.transaction(ct,"readonly",Qr),r=e.objectStore(ct),n=[];return new Promise(o=>{r.openCursor().onsuccess=s=>{let i=s.target.result;i?(n.push(i.value),i.continue()):(Xn(e),o(n))}})}function rf(t,e){let r=t.transaction(ct,"readonly",Qr),n=r.objectStore(ct),o=[],s=IDBKeyRange.bound(e+1,1/0);if(n.getAll){let a=n.getAll(s);return new Promise((c,l)=>{a.onerror=u=>l(u),a.onsuccess=function(u){c(u.target.result)}})}function i(){try{return s=IDBKeyRange.bound(e+1,1/0),n.openCursor(s)}catch{return n.openCursor()}}return new Promise((a,c)=>{let l=i();l.onerror=u=>c(u),l.onsuccess=u=>{let f=u.target.result;f?f.value.id<e+1?f.continue(e+1):(o.push(f.value),f.continue()):(Xn(r),a(o))}})}function nf(t,e){let n=t.transaction([ct],"readwrite",Qr).objectStore(ct);return Promise.all(e.map(o=>{let s=n.delete(o);return new Promise(i=>{s.onsuccess=()=>i()})}))}function of(t,e){let r=Date.now()-e,n=t.transaction(ct,"readonly",Qr),o=n.objectStore(ct),s=[];return new Promise(i=>{o.openCursor().onsuccess=a=>{let c=a.target.result;if(c){let l=c.value;l.time<r?(s.push(l),c.continue()):(Xn(n),i(s))}else i(s)}})}function sf(t,e){return of(t,e).then(r=>nf(t,r.map(n=>n.id)))}function fg(t,e){return e=sg.fillOptionsWithDefaults(e),ef(t).then(r=>{let n={closed:!1,lastCursorId:0,channelName:t,options:e,uuid:wt.generateRandomId(),eMIs:new og.ObliviousSet(e.idb.ttl*2),writeBlockPromise:wt.PROMISE_RESOLVED_VOID,messagesCallback:null,readQueuePromises:[],db:r,time:wt.microSeconds()};return r.onclose=function(){n.closed=!0,e.idb.onclose&&e.idb.onclose()},af(n),n})}function af(t){t.closed||cf(t).then(()=>wt.sleep(t.options.idb.fallbackInterval)).then(()=>af(t)).catch(e=>{throw e})}function lg(t,e){return!(t.uuid===e.uuid||e.eMIs.has(t.id)||t.data.time<e.messagesCallbackTime)}function cf(t){return t.closed||!t.messagesCallback?wt.PROMISE_RESOLVED_VOID:rf(t.db,t.lastCursorId).then(e=>(e.filter(n=>!!n).map(n=>(n.id>t.lastCursorId&&(t.lastCursorId=n.id),n)).filter(n=>lg(n,t)).sort((n,o)=>n.time-o.time).forEach(n=>{t.messagesCallback&&(t.eMIs.add(n.id),t.messagesCallback(n.data))}),wt.PROMISE_RESOLVED_VOID))}function dg(t){t.closed=!0,t.db.close()}function hg(t,e){return t.writeBlockPromise=t.writeBlockPromise.then(()=>tf(t.db,t.uuid,e)).then(()=>(wt.randomInt(0,10)===0&&sf(t.db,t.options.idb.ttl),wt.PROMISE_RESOLVED_VOID)),t.writeBlockPromise}function pg(t,e,r){t.messagesCallbackTime=r,t.messagesCallback=e,cf(t)}function yg(){return!!na()}function gg(t){return t.idb.fallbackInterval*2}fe.TRANSACTION_SETTINGS=Qr;fe.averageResponseTime=gg;fe.canBeUsed=yg;fe.cleanOldMessages=sf;fe.close=dg;fe.commitIndexedDBTransaction=Xn;fe.create=fg;fe.createDatabase=ef;fe.getAllMessages=ug;fe.getIdb=na;fe.getMessagesHigherThan=rf;fe.getOldMessages=of;fe.microSeconds=ig;fe.onMessage=pg;fe.postMessage=hg;fe.removeMessagesById=nf;fe.type=cg;fe.writeMessage=tf});var us=S($e=>{"use strict";var mg=cs(),bg=Zn(),zn=Xt(),wg=zn.microSeconds,vg="pubkey.broadcastChannel-",_g="localstorage";function sa(){let t=null;if(typeof window>"u")return null;try{t=window.localStorage,t=window["ie8-eventlistener/storage"]||window.localStorage}catch{}return t}function ia(t){return vg+t}function xg(t,e){return new Promise((r,n)=>{zn.sleep().then(()=>{var o;let s=ia(t.channelName),i={token:zn.generateRandomId(),time:Date.now(),data:e,uuid:t.uuid},a=JSON.stringify(i);(o=sa())===null||o===void 0||o.setItem(s,a);let c=document.createEvent("StorageEvent");c.initStorageEvent("storage",!0,!0,s,null,a,"",null),window.dispatchEvent(c),r()}).catch(n)})}function uf(t,e){let r=ia(t),n=o=>{o.key===r&&o.newValue&&e(JSON.parse(o.newValue))};return window.addEventListener("storage",n),n}function ff(t){window.removeEventListener("storage",t)}function lf(){let t=sa();if(!t)return!1;try{let e="__broadcastchannel_check";t.setItem(e,"works"),t.removeItem(e)}catch{return!1}return!0}function Eg(t,e){let r=bg.fillOptionsWithDefaults(e);if(!lf())throw new Error("BroadcastChannel: localstorage cannot be used");let n=zn.generateRandomId(),o=new mg.ObliviousSet(r.localstorage.removeTimeout),s={channelName:t,uuid:n,time:zn.microSeconds(),eMIs:o};return s.listener=uf(t,i=>{s.messagesCallback&&i.uuid!==n&&(!i.token||o.has(i.token)||i.data.time&&i.data.time<(s.messagesCallbackTime||0)||(o.add(i.token),s.messagesCallback(i.data)))}),s}function Sg(t){t.listener&&ff(t.listener)}function Bg(t,e,r){t.messagesCallbackTime=r,t.messagesCallback=e}function Cg(){let e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120}$e.addStorageEventListener=uf;$e.averageResponseTime=Cg;$e.canBeUsed=lf;$e.close=Sg;$e.create=Eg;$e.getLocalStorage=sa;$e.microSeconds=wg;$e.onMessage=Bg;$e.postMessage=xg;$e.removeStorageEventListener=ff;$e.storageKey=ia;$e.type=_g});var fs=S(Nt=>{"use strict";var aa=Xt(),Ag=aa.microSeconds,Tg="native";function Og(t){let e={time:aa.microSeconds(),messagesCallback:null,bc:new BroadcastChannel(t),subFns:[]};return e.bc.onmessage=r=>{e.messagesCallback&&e.messagesCallback(r.data)},e}function Pg(t){t.bc.close(),t.subFns=[]}function kg(t,e){try{return t.bc.postMessage(e),aa.PROMISE_RESOLVED_VOID}catch(r){return Promise.reject(r)}}function Rg(t,e){t.messagesCallback=e}function Ig(){if(typeof window>"u")return!1;if(typeof BroadcastChannel=="function"){if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}return!1}function qg(){return 150}Nt.averageResponseTime=qg;Nt.canBeUsed=Ig;Nt.close=Pg;Nt.create=Og;Nt.microSeconds=Ag;Nt.onMessage=Rg;Nt.postMessage=kg;Nt.type=Tg});function vt(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Me(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function j(t,e,r=""){let n=vt(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return t}function ls(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Me(t.outputLen),Me(t.blockLen)}function Dt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ds(t,e){j(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function hf(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function nt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function hs(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ut(t,e){return t<<32-e|t>>>e}function Ng(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Mg(t){for(let e=0;e<t.length;e++)t[e]=Ng(t[e]);return t}function ft(t){if(j(t),pf)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Dg[t[r]];return e}function df(t){if(t>=Mt._0&&t<=Mt._9)return t-Mt._0;if(t>=Mt.A&&t<=Mt.F)return t-(Mt.A-10);if(t>=Mt.a&&t<=Mt.f)return t-(Mt.a-10)}function Ge(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(pf)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=df(t.charCodeAt(s)),a=df(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function G(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];j(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function _t(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function oe(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Lg,ca,pf,Dg,Mt,Ee,xt=ge(()=>{Lg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;ca=Lg?t=>t:Mg,pf=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Dg=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};Ee=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function yf(t,e,r){return t&e^~t&r}function gf(t,e,r){return t&e^t&r^e&r}var Jn,Ft,jt,me,be,mf=ge(()=>{xt();Jn=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=hs(this.buffer)}update(e){Dt(this),j(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=hs(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Dt(this),ds(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,nt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=hs(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Ft=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),jt=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),me=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),be=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});function Fg(t,e=!1){return e?{h:Number(t&ps),l:Number(t>>bf&ps)}:{h:Number(t>>bf&ps)|0,l:Number(t&ps)|0}}function ys(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Fg(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}function Et(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ps,bf,ua,fa,Cr,Ar,Qn,eo,wf,vf,_f,xf,Ef,Sf,Bf,Cf,Af,Tf,la=ge(()=>{ps=BigInt(4294967295),bf=BigInt(32);ua=(t,e,r)=>t>>>r,fa=(t,e,r)=>t<<32-r|e>>>r,Cr=(t,e,r)=>t>>>r|e<<32-r,Ar=(t,e,r)=>t<<32-r|e>>>r,Qn=(t,e,r)=>t<<64-r|e>>>r-32,eo=(t,e,r)=>t>>>r-32|e<<64-r,wf=(t,e,r)=>t<<r|e>>>32-r,vf=(t,e,r)=>e<<r|t>>>32-r,_f=(t,e,r)=>e<<r-32|t>>>64-r,xf=(t,e,r)=>t<<r-32|e>>>64-r;Ef=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Sf=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Bf=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Cf=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Af=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Tf=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0});var Es={};Br(Es,{_SHA224:()=>bs,_SHA256:()=>ms,_SHA384:()=>vs,_SHA512:()=>ws,_SHA512_224:()=>_s,_SHA512_256:()=>xs,sha224:()=>Kg,sha256:()=>tn,sha384:()=>$g,sha512:()=>rr,sha512_224:()=>Yg,sha512_256:()=>Gg});var Ug,Qt,gs,ms,bs,Of,Hg,Vg,er,tr,en,ws,vs,Se,Be,_s,xs,tn,Kg,rr,$g,Gg,Yg,rn=ge(()=>{mf();la();xt();Ug=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]),Qt=new Uint32Array(64),gs=class extends Jn{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let f=0;f<16;f++,r+=4)Qt[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let d=Qt[f-15],h=Qt[f-2],y=ut(d,7)^ut(d,18)^d>>>3,w=ut(h,17)^ut(h,19)^h>>>10;Qt[f]=w+Qt[f-7]+y+Qt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let d=ut(a,6)^ut(a,11)^ut(a,25),h=u+d+yf(a,c,l)+Ug[f]+Qt[f]|0,w=(ut(n,2)^ut(n,13)^ut(n,22))+gf(n,o,s)|0;u=l,l=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){nt(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),nt(this.buffer)}},ms=class extends gs{A=Ft[0]|0;B=Ft[1]|0;C=Ft[2]|0;D=Ft[3]|0;E=Ft[4]|0;F=Ft[5]|0;G=Ft[6]|0;H=Ft[7]|0;constructor(){super(32)}},bs=class extends gs{A=jt[0]|0;B=jt[1]|0;C=jt[2]|0;D=jt[3]|0;E=jt[4]|0;F=jt[5]|0;G=jt[6]|0;H=jt[7]|0;constructor(){super(28)}},Of=ys(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Hg=Of[0],Vg=Of[1],er=new Uint32Array(80),tr=new Uint32Array(80),en=class extends Jn{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:d,Gh:h,Gl:y,Hh:w,Hl:p}=this;return[e,r,n,o,s,i,a,c,l,u,f,d,h,y,w,p]}set(e,r,n,o,s,i,a,c,l,u,f,d,h,y,w,p){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=w|0,this.Hl=p|0}process(e,r){for(let B=0;B<16;B++,r+=4)er[B]=e.getUint32(r),tr[B]=e.getUint32(r+=4);for(let B=16;B<80;B++){let O=er[B-15]|0,D=tr[B-15]|0,M=Cr(O,D,1)^Cr(O,D,8)^ua(O,D,7),H=Ar(O,D,1)^Ar(O,D,8)^fa(O,D,7),P=er[B-2]|0,A=tr[B-2]|0,N=Cr(P,A,19)^Qn(P,A,61)^ua(P,A,6),U=Ar(P,A,19)^eo(P,A,61)^fa(P,A,6),x=Bf(H,U,tr[B-7],tr[B-16]),g=Cf(x,M,N,er[B-7],er[B-16]);er[B]=g|0,tr[B]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:d,Fh:h,Fl:y,Gh:w,Gl:p,Hh:v,Hl:E}=this;for(let B=0;B<80;B++){let O=Cr(f,d,14)^Cr(f,d,18)^Qn(f,d,41),D=Ar(f,d,14)^Ar(f,d,18)^eo(f,d,41),M=f&h^~f&w,H=d&y^~d&p,P=Af(E,D,H,Vg[B],tr[B]),A=Tf(P,v,O,M,Hg[B],er[B]),N=P|0,U=Cr(n,o,28)^Qn(n,o,34)^Qn(n,o,39),x=Ar(n,o,28)^eo(n,o,34)^eo(n,o,39),g=n&s^n&a^s&a,b=o&i^o&c^i&c;v=w|0,E=p|0,w=h|0,p=y|0,h=f|0,y=d|0,{h:f,l:d}=Et(l|0,u|0,A|0,N|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let m=Ef(N,x,b);n=Sf(m,A,U,g),o=m|0}({h:n,l:o}=Et(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Et(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Et(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Et(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:d}=Et(this.Eh|0,this.El|0,f|0,d|0),{h,l:y}=Et(this.Fh|0,this.Fl|0,h|0,y|0),{h:w,l:p}=Et(this.Gh|0,this.Gl|0,w|0,p|0),{h:v,l:E}=Et(this.Hh|0,this.Hl|0,v|0,E|0),this.set(n,o,s,i,a,c,l,u,f,d,h,y,w,p,v,E)}roundClean(){nt(er,tr)}destroy(){nt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ws=class extends en{Ah=be[0]|0;Al=be[1]|0;Bh=be[2]|0;Bl=be[3]|0;Ch=be[4]|0;Cl=be[5]|0;Dh=be[6]|0;Dl=be[7]|0;Eh=be[8]|0;El=be[9]|0;Fh=be[10]|0;Fl=be[11]|0;Gh=be[12]|0;Gl=be[13]|0;Hh=be[14]|0;Hl=be[15]|0;constructor(){super(64)}},vs=class extends en{Ah=me[0]|0;Al=me[1]|0;Bh=me[2]|0;Bl=me[3]|0;Ch=me[4]|0;Cl=me[5]|0;Dh=me[6]|0;Dl=me[7]|0;Eh=me[8]|0;El=me[9]|0;Fh=me[10]|0;Fl=me[11]|0;Gh=me[12]|0;Gl=me[13]|0;Hh=me[14]|0;Hl=me[15]|0;constructor(){super(48)}},Se=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),Be=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]),_s=class extends en{Ah=Se[0]|0;Al=Se[1]|0;Bh=Se[2]|0;Bl=Se[3]|0;Ch=Se[4]|0;Cl=Se[5]|0;Dh=Se[6]|0;Dl=Se[7]|0;Eh=Se[8]|0;El=Se[9]|0;Fh=Se[10]|0;Fl=Se[11]|0;Gh=Se[12]|0;Gl=Se[13]|0;Hh=Se[14]|0;Hl=Se[15]|0;constructor(){super(28)}},xs=class extends en{Ah=Be[0]|0;Al=Be[1]|0;Bh=Be[2]|0;Bl=Be[3]|0;Ch=Be[4]|0;Cl=Be[5]|0;Dh=Be[6]|0;Dl=Be[7]|0;Eh=Be[8]|0;El=Be[9]|0;Fh=Be[10]|0;Fl=Be[11]|0;Gh=Be[12]|0;Gl=Be[13]|0;Hh=Be[14]|0;Hl=Be[15]|0;constructor(){super(32)}},tn=_t(()=>new ms,Ee(1)),Kg=_t(()=>new bs,Ee(4)),rr=_t(()=>new ws,Ee(3)),$g=_t(()=>new vs,Ee(2)),Gg=_t(()=>new xs,Ee(6)),Yg=_t(()=>new _s,Ee(5))});var ir={};Br(ir,{aInRange:()=>Ut,abool:()=>St,abytes:()=>j,anumber:()=>Me,asafenumber:()=>nr,asciiToBytes:()=>we,bitGet:()=>Zg,bitLen:()=>ro,bitMask:()=>Or,bitSet:()=>Xg,bytesToHex:()=>ft,bytesToNumberBE:()=>Ye,bytesToNumberLE:()=>Ce,concatBytes:()=>G,copyBytes:()=>sr,createHmacDrbg:()=>ya,equalBytes:()=>pa,hexToBytes:()=>Ge,hexToNumber:()=>ha,inRange:()=>Pf,isBytes:()=>vt,memoized:()=>Pr,notImplemented:()=>Cs,numberToBytesBE:()=>or,numberToBytesLE:()=>nn,numberToHexUnpadded:()=>Tr,numberToVarBytesBE:()=>Wg,randomBytes:()=>oe,validateObject:()=>Oe});function St(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function da(t){if(typeof t=="bigint"){if(!Ss(t))throw new Error("positive bigint expected, got "+t)}else Me(t);return t}function nr(t,e=""){if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new Error(r+"expected safe integer, got type="+typeof t)}}function Tr(t){let e=da(t).toString(16);return e.length&1?"0"+e:e}function ha(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Bs:BigInt("0x"+t)}function Ye(t){return ha(ft(t))}function Ce(t){return ha(ft(sr(j(t)).reverse()))}function or(t,e){Me(e),t=da(t);let r=Ge(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function nn(t,e){return or(t,e).reverse()}function Wg(t){return Ge(Tr(da(t)))}function pa(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function sr(t){return Uint8Array.from(t)}function we(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}function Pf(t,e,r){return Ss(t)&&Ss(e)&&Ss(r)&&e<=t&&t<r}function Ut(t,e,r,n){if(!Pf(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function ro(t){let e;for(e=0;t>Bs;t>>=to,e+=1);return e}function Zg(t,e){return t>>BigInt(e)&to}function Xg(t,e,r){return t|(r?to:Bs)<<BigInt(e)}function ya(t,e,r){if(Me(t,"hashLen"),Me(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),l=n(t),u=0,f=()=>{c.fill(1),l.fill(0),u=0},d=(...p)=>r(l,G(c,...p)),h=(p=o)=>{l=d(s,p),c=d(),p.length!==0&&(l=d(i,p),c=d())},y=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,v=[];for(;p<e;){c=d();let E=c.slice();v.push(E),p+=c.length}return G(...v)};return(p,v)=>{f(),h(p);let E;for(;!(E=v(y()));)h();return f(),E}}function Oe(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,i,a){let c=t[s];if(a&&c===void 0)return;let l=typeof c;if(l!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${l}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}function Pr(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}var Bs,to,Ss,Or,Cs,ve=ge(()=>{xt();xt();Bs=BigInt(0),to=BigInt(1);Ss=t=>typeof t=="bigint"&&Bs<=t;Or=t=>(to<<BigInt(t))-to;Cs=()=>{throw new Error("not implemented")}});var oo={};Br(oo,{Field:()=>ar,FpDiv:()=>nm,FpInvertBatch:()=>Ct,FpIsSquare:()=>om,FpLegendre:()=>Ts,FpPow:()=>wa,FpSqrt:()=>Mf,FpSqrtEven:()=>va,FpSqrtOdd:()=>sm,getFieldBytesLength:()=>_a,getMinHashLength:()=>on,invert:()=>As,isNegativeLE:()=>Bt,mapHashToField:()=>Rr,mod:()=>J,nLength:()=>Df,pow:()=>Qg,pow2:()=>te,tonelliShanks:()=>ba,validateField:()=>no});function J(t,e){let r=t%e;return r>=Pe?r:e+r}function Qg(t,e,r){return wa(ar(r),t,e)}function te(t,e,r){let n=t;for(;e-- >Pe;)n*=n,n%=r;return n}function As(t,e){if(t===Pe)throw new Error("invert: expected non-zero number");if(e<=Pe)throw new Error("invert: expected positive modulus, got "+e);let r=J(t,e),n=e,o=Pe,s=de,i=de,a=Pe;for(;r!==Pe;){let l=n/r,u=n%r,f=o-i*l,d=s-a*l;n=r,r=u,o=i,s=a,i=f,a=d}if(n!==de)throw new Error("invert: does not exist");return J(o,e)}function ma(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function Nf(t,e){let r=(t.ORDER+de)/Rf,n=t.pow(e,r);return ma(t,n,e),n}function em(t,e){let r=(t.ORDER-If)/qf,n=t.mul(e,kr),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,kr),o),a=t.mul(s,t.sub(i,t.ONE));return ma(t,a,e),a}function tm(t){let e=ar(t),r=ba(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+zg)/Lf;return(a,c)=>{let l=a.pow(c,i),u=a.mul(l,n),f=a.mul(l,o),d=a.mul(l,s),h=a.eql(a.sqr(u),c),y=a.eql(a.sqr(f),c);l=a.cmov(l,u,h),u=a.cmov(d,f,y);let w=a.eql(a.sqr(u),c),p=a.cmov(l,u,w);return ma(a,p,c),p}}function ba(t){if(t<kf)throw new Error("sqrt is not defined for small field");let e=t-de,r=0;for(;e%kr===Pe;)e/=kr,r++;let n=kr,o=ar(t);for(;Ts(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Nf;let s=o.pow(n,e),i=(e+de)/kr;return function(c,l){if(c.is0(l))return l;if(Ts(c,l)!==1)throw new Error("Cannot find square root");let u=r,f=c.mul(c.ONE,s),d=c.pow(l,e),h=c.pow(l,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let y=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(y++,w=c.sqr(w),y===u)throw new Error("Cannot find square root");let p=de<<BigInt(u-y-1),v=c.pow(f,p);u=y,f=c.sqr(v),d=c.mul(d,f),h=c.mul(h,v)}return h}}function Mf(t){return t%Rf===kf?Nf:t%qf===If?em:t%Lf===Jg?tm(t):ba(t)}function no(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=rm.reduce((n,o)=>(n[o]="function",n),e);return Oe(t,r),t}function wa(t,e,r){if(r<Pe)throw new Error("invalid exponent, negatives unsupported");if(r===Pe)return t.ONE;if(r===de)return e;let n=t.ONE,o=e;for(;r>Pe;)r&de&&(n=t.mul(n,o)),o=t.sqr(o),r>>=de;return n}function Ct(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,a,c)=>t.is0(a)?i:(n[c]=i,t.mul(i,a)),t.ONE),s=t.inv(o);return e.reduceRight((i,a,c)=>t.is0(a)?i:(n[c]=t.mul(i,n[c]),t.mul(i,a)),s),n}function nm(t,e,r){return t.mul(e,typeof r=="bigint"?As(r,t.ORDER):t.inv(r))}function Ts(t,e){let r=(t.ORDER-de)/kr,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function om(t,e){return Ts(t,e)===1}function Df(t,e){e!==void 0&&Me(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ar(t,e={}){return new ga(t,e)}function sm(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?r:t.neg(r)}function va(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function _a(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function on(t){let e=_a(t);return e+Math.ceil(e/2)}function Rr(t,e,r=!1){j(t);let n=t.length,o=_a(e),s=on(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ce(t):Ye(t),a=J(i,e-de)+de;return r?nn(a,o):or(a,o)}var Pe,de,kr,kf,Rf,If,zg,qf,Jg,Lf,Bt,rm,ga,ot=ge(()=>{ve();Pe=BigInt(0),de=BigInt(1),kr=BigInt(2),kf=BigInt(3),Rf=BigInt(4),If=BigInt(5),zg=BigInt(7),qf=BigInt(8),Jg=BigInt(9),Lf=BigInt(16);Bt=(t,e)=>(J(t,e)&de)===de,rm=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];ga=class{ORDER;BITS;BYTES;isLE;ZERO=Pe;ONE=de;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=Pe)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Df(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return J(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return Pe<=e&&e<this.ORDER}is0(e){return e===Pe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&de)===de}neg(e){return J(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return J(e*e,this.ORDER)}add(e,r){return J(e+r,this.ORDER)}sub(e,r){return J(e-r,this.ORDER)}mul(e,r){return J(e*r,this.ORDER)}pow(e,r){return wa(this,e,r)}div(e,r){return J(e*As(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return As(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=Mf(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?nn(e,this.BYTES):or(e,this.BYTES)}fromBytes(e,r=!1){j(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let l=new Uint8Array(o);l.set(e,s?0:l.length-e.length),e=l}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Ce(e):Ye(e);if(a&&(c=J(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Ct(this,e)}cmov(e,r,n){return n?r:e}}});function so(t,e){let r=e.negate();return t?r:e}function qr(t,e){let r=Ct(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Hf(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function xa(t,e){Hf(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Or(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ff(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Ir);let l=e*n,u=l+Math.abs(a)-1,f=a===0,d=a<0,h=e%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:d,isNegF:h,offsetF:l}}function im(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function am(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}function Sa(t){return Vf.get(t)||1}function jf(t){if(t!==sn)throw new Error("invalid wNAF")}function Kf(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>sn||n>sn;)r&Ir&&(s=s.add(o)),n&Ir&&(i=i.add(o)),o=o.double(),r>>=Ir,n>>=Ir;return{p1:s,p2:i}}function $f(t,e,r){let n=t.Fn;im(e,t),am(r,n);let o=e.length,s=r.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,a=ro(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Or(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((n.BITS-1)/c)*c,d=i;for(let h=f;h>=0;h-=c){u.fill(i);for(let w=0;w<s;w++){let p=r[w],v=Number(p>>BigInt(h)&l);u[v]=u[v].add(e[w])}let y=i;for(let w=u.length-1,p=i;w>0;w--)p=p.add(u[w]),y=y.add(p);if(d=d.add(y),h!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Uf(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return no(e),e}else return ar(t,{isLE:r})}function Os(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let l=e[c];if(!(typeof l=="bigint"&&l>sn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Uf(e.p,r.Fp,n),s=Uf(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function cr(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var sn,Ir,Ea,Vf,an,cn=ge(()=>{ve();ot();sn=BigInt(0),Ir=BigInt(1);Ea=new WeakMap,Vf=new WeakMap;an=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>sn;)r&Ir&&(n=n.add(o)),o=o.double(),r>>=Ir;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=xa(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let l=1;l<o;l++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=xa(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:l,isZero:u,isNeg:f,isNegF:d,offsetF:h}=Ff(n,a,i);n=c,u?s=s.add(so(d,r[h])):o=o.add(so(f,r[l]))}return jf(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=xa(e,this.bits);for(let i=0;i<s.windows&&n!==sn;i++){let{nextN:a,offset:c,isZero:l,isNeg:u}=Ff(n,i,s);if(n=a,!l){let f=r[c];o=o.add(u?f.negate():f)}}return jf(n),o}getPrecomputes(e,r,n){let o=Ea.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Ea.set(r,o))),o}cached(e,r,n){let o=Sa(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Sa(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){Hf(r,this.bits),Vf.set(e,r),Ea.delete(e)}hasCache(e){return Sa(e)!==1}}});function ur(t,e){if(nr(t),nr(e),t<0||t>=1<<8*e)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function um(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Gf(t){if(!vt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");return typeof t=="string"?we(t):t}function Ps(t,e,r,n){j(t),nr(r),e=Gf(e),e.length>255&&(e=n(G(we("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=G(e,ur(e.length,1)),c=ur(0,s),l=ur(r,2),u=new Array(i),f=n(G(c,t,l,ur(0,1),a));u[0]=n(G(f,ur(1,1),a));for(let h=1;h<=i;h++){let y=[um(f,u[h-1]),ur(h+1,1),a];u[h]=n(G(...y))}return G(...u).slice(0,r)}function fm(t,e,r,n,o){if(j(t),nr(r),e=Gf(e),e.length>255){let s=Math.ceil(2*n/8);e=o.create({dkLen:s}).update(we("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:r}).update(t).update(ur(r,2)).update(e).update(ur(e.length,1)).digest()}function Ba(t,e,r){Oe(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:o,m:s,hash:i,expand:a,DST:c}=r;nr(i.outputLen,"valid hash"),j(t),nr(e);let l=n.toString(2).length,u=Math.ceil((l+o)/8),f=e*s*u,d;if(a==="xmd")d=Ps(t,c,f,i);else if(a==="xof")d=fm(t,c,f,o,i);else if(a==="_internal_pass")d=t;else throw new Error('expand must be "xmd" or "xof"');let h=new Array(e);for(let y=0;y<e;y++){let w=new Array(s);for(let p=0;p<s;p++){let v=u*(p+y*s),E=d.subarray(v,v+u);w[p]=J(cm(E),n)}h[y]=w}return h}function Yf(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,o)=>{let[s,i,a,c]=r.map(f=>f.reduce((d,h)=>t.add(t.mul(d,n),h))),[l,u]=Ct(t,[i,c],!0);return n=t.mul(s,l),o=t.mul(o,t.mul(a,u)),{x:n,y:o}}}function ks(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function n(s){return t.fromAffine(e(s))}function o(s){let i=s.clearCofactor();return i.equals(t.ZERO)?t.ZERO:(i.assertValidity(),i)}return{defaults:Object.freeze(r),Point:t,hashToCurve(s,i){let a=Object.assign({},r,i),c=Ba(s,2,a),l=n(c[0]),u=n(c[1]);return o(l.add(u))},encodeToCurve(s,i){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,i),l=Ba(s,1,c),u=n(l[0]);return o(u)},mapToCurve(s){if(r.m===1){if(typeof s!="bigint")throw new Error("expected bigint (m=1)");return o(n([s]))}if(!Array.isArray(s))throw new Error("expected array of bigints");for(let i of s)if(typeof i!="bigint")throw new Error("expected array of bigints");return o(n(s))},hashToScalar(s,i){let a=t.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:io},i);return Ba(s,1,c)[0][0]}}}var cm,io,Rs=ge(()=>{ve();ot();cm=Ye;io=we("HashToScalar-")});var Is,Ca,Wf=ge(()=>{xt();Is=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,r){if(ls(e),j(r,void 0,"key"),this.iHash=e.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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),nt(o)}update(e){return Dt(this),this.iHash.update(e),this}digestInto(e){Dt(this),j(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ca=(t,e,r)=>new Is(t,e).update(r).digest();Ca.create=(t,e)=>new Is(t,e)});function lm(t,e,r){let[[n,o],[s,i]]=e,a=Zf(i*t,r),c=Zf(-o*t,r),l=t-a*n-c*s,u=-a*o-c*i,f=l<lt,d=u<lt;f&&(l=-l),d&&(u=-u);let h=Or(Math.ceil(ro(r)/2))+Ae;if(l<lt||l>=h||u<lt||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:l,k2neg:d,k2:u}}function Ta(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Aa(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return St(r.lowS,"lowS"),St(r.prehash,"prehash"),r.format!==void 0&&Ta(r.format),r}function Xf(t,e={}){let r=Os("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=Qf(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(x,g,b){let{x:m,y:_}=g.toAffine(),T=n.toBytes(m);if(St(b,"isCompressed"),b){u();let C=!n.isOdd(_);return G(zf(C),T)}else return G(Uint8Array.of(4),T,n.toBytes(_))}function d(x){j(x,void 0,"Point");let{publicKey:g,publicKeyUncompressed:b}=l,m=x.length,_=x[0],T=x.subarray(1);if(m===g&&(_===2||_===3)){let C=n.fromBytes(T);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let k=w(C),R;try{R=n.sqrt(k)}catch(Z){let Y=Z instanceof Error?": "+Z.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}u();let q=n.isOdd(R);return(_&1)===1!==q&&(R=n.neg(R)),{x:C,y:R}}else if(m===b&&_===4){let C=n.BYTES,k=n.fromBytes(T.subarray(0,C)),R=n.fromBytes(T.subarray(C,C*2));if(!p(k,R))throw new Error("bad point: is not on curve");return{x:k,y:R}}else throw new Error(`bad point: got length ${m}, expected compressed=${g} or uncompressed=${b}`)}let h=e.toBytes||f,y=e.fromBytes||d;function w(x){let g=n.sqr(x),b=n.mul(g,x);return n.add(n.add(b,n.mul(x,s.a)),s.b)}function p(x,g){let b=n.sqr(g),m=w(x);return n.eql(b,m)}if(!p(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,un),Pa),E=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,E)))throw new Error("bad curve params: a or b");function B(x,g,b=!1){if(!n.isValid(g)||b&&n.is0(g))throw new Error(`bad point coordinate ${x}`);return g}function O(x){if(!(x instanceof A))throw new Error("Weierstrass Point expected")}function D(x){if(!c||!c.basises)throw new Error("no endo");return lm(x,c.basises,o.ORDER)}let M=Pr((x,g)=>{let{X:b,Y:m,Z:_}=x;if(n.eql(_,n.ONE))return{x:b,y:m};let T=x.is0();g==null&&(g=T?n.ONE:n.inv(_));let C=n.mul(b,g),k=n.mul(m,g),R=n.mul(_,g);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(R,n.ONE))throw new Error("invZ was invalid");return{x:C,y:k}}),H=Pr(x=>{if(x.is0()){if(e.allowInfinityPoint&&!n.is0(x.Y))return;throw ne