nervur 0.22.0 → 0.22.1

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.
@@ -1,2 +1,2 @@
1
1
  // The kit as one module's text, for an edge's shell.
2
- export default "var Ya=Object.defineProperty;var Va=(r,t)=>{for(var e in t)Ya(r,e,{get:t[e],enumerable:!0})};var Mi=\"org.nervur.kits\",Ja=()=>{let r=globalThis;return r[Symbol.for(Mi)]??=new Map},mn,_o=r=>{let t=Ja();mn??=`kit${String(t.size)}`,t.set(mn,r)},Qa=/\\bimport\\s*(\\{[^}]*\\}|\\*\\s*as\\s+[A-Za-z_$][\\w$]*)\\s*from\\s*(['\"])nervur\\2\\s*;?/g,tl=/(^|[\\n;{}])\\s*(import\\s*[\\w{*'\"]|export\\s*(\\*|\\{[^}]*\\})\\s*from\\b)/,jo=r=>{if(mn===void 0)throw new Error(\"no kit is bound to link a module against\");let t=`globalThis[Symbol.for(${JSON.stringify(Mi)})].get(${JSON.stringify(mn)})`,e=r.replace(Qa,(n,o)=>o.startsWith(\"*\")?`const ${o.replace(/^\\*\\s*as\\s+/,\"\")} = ${t};`:`const { ${o.slice(1,-1).split(\",\").map(i=>i.trim()).filter(i=>i!==\"\").map(i=>i.replace(/\\s+as\\s+/,\": \")).join(\", \")} } = ${t};`);if(tl.test(e))throw new Error(\"a module imports nothing but 'nervur'\");return e},He=r=>{let{module:t,version:e,classes:n}=r??{};if(typeof t!=\"string\"||typeof e!=\"string\"||!Array.isArray(n))throw new Error(\"the code exports no module: module, version and classes\");return{module:t,version:e,classes:n}};var qe=class{get drawer(){return t=>this.draw(t)}},ze=class{},ne=class{},oe=class{},Ht=class{},we=class{};var el=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,\"0\")),rl=/^(?:[0-9a-f]{2})*$/,_=r=>{let t=\"\";for(let e of r)t+=el[e];return t},K=(r,t)=>typeof r==\"string\"&&rl.test(r)&&(t===void 0||r.length===t*2),$=r=>{if(!K(r))throw new TypeError(\"not hex\");let t=new Uint8Array(r.length/2);for(let e=0;e<t.length;e+=1)t[e]=parseInt(r.slice(e*2,e*2+2),16);return t},C=(...r)=>{let t=new Uint8Array(r.reduce((n,o)=>n+o.length,0)),e=0;for(let n of r)t.set(n,e),e+=n.length;return t},yr=r=>r.every(t=>t===0),nl=new TextEncoder,I=r=>nl.encode(r);var gt=()=>{let r=globalThis.crypto?.subtle;if(!r)throw new Error(\"this terrain has no crypto.subtle: a ward needs a secure context\");return r},rt=r=>Uint8Array.from(r);var ol=new Uint8Array(0),se=async r=>new Uint8Array(await gt().digest(\"SHA-256\",rt(r))),dt=async(r,t,e)=>{let n=await gt().importKey(\"raw\",rt(r),\"HKDF\",!1,[\"deriveBits\"]),o=await gt().deriveBits({name:\"HKDF\",hash:\"SHA-256\",salt:ol,info:rt(t)},n,e*8);return new Uint8Array(o)};var sl=new TextDecoder(\"utf-8\",{fatal:!0,ignoreBOM:!0}),Io=/-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/y,$o=/\\\\(?:[\"\\\\/bfnrt]|u[0-9a-fA-F]{4})/y,No=/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/,Ui=[\"true\",\"false\",\"null\"],X=(r,t)=>{for(;t<r.length&&` \t\n\\r`.includes(r[t]);)t+=1;return t},mr=(r,t)=>{if(r[t]!=='\"')return-1;for(t+=1;t<r.length;){let e=r.charCodeAt(t);if(e===34)return t+1;if(e<32)return-1;if(e!==92){t+=1;continue}if($o.lastIndex=t,!$o.test(r))return-1;t=$o.lastIndex}return-1},Ci=(r,t)=>{if(r[t]==='\"')return mr(r,t);let e=Ui.find(n=>r.startsWith(n,t));return e?t+e.length:(Io.lastIndex=t,Io.test(r)?Io.lastIndex:-1)},Lo=(r,t)=>{let e=mr(r,t);if(e<0)return-1;let n=X(r,e);return r[n]===\":\"?X(r,n+1):-1},Hi=(r,t)=>{let e=[];for(;;){let n=r[t];if(n===\"{\"||n===\"[\")if(t=X(r,t+1),r[t]===(n===\"{\"?\"}\":\"]\"))t+=1;else{if(e.push(n),n===\"{\"&&(t=Lo(r,t))<0)return-1;continue}else if((t=Ci(r,t))<0)return-1;for(;;){if(e.length===0)return t;t=X(r,t);let o=e.at(-1);if(r[t]===\",\"){if(t=X(r,t+1),o===\"{\"&&(t=Lo(r,t))<0)return-1;break}if(r[t]!==(o===\"{\"?\"}\":\"]\"))return-1;e.pop(),t+=1}}},qi=r=>{if(typeof r==\"string\")return r;try{return sl.decode(r)}catch{return null}},gr=r=>{let t=qi(r);if(t===null)return null;let e=new Map,n=X(t,0);if(t[n]!==\"{\")return null;if(n=X(t,n+1),t[n]===\"}\")return X(t,n+1)===t.length?e:null;for(;;){let o=n,s=Lo(t,n);if(s<0)return null;let i=JSON.parse(t.slice(o,mr(t,o)));if(e.has(i))return null;let c=Hi(t,s);if(c<0)return null;if(e.set(i,t.slice(s,c)),n=X(t,c),t[n]===\"}\")return X(t,n+1)===t.length?e:null;if(t[n]!==\",\")return null;n=X(t,n+1)}},il=r=>{let[,t,e,n=\"\",o=\"0\"]=/^(-?)(0|[1-9]\\d*)(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/.exec(r),s=Number(r);if(!Number.isFinite(s))return!1;let i=(e+n).replace(/^0+/,\"\");if(s===0)return i===\"\"&&t===\"\";let c=i.replace(/0+$/,\"\"),a=BigInt(o)-BigInt(n.length)+BigInt(i.length-c.length);return a<0n?!0:BigInt(c)*10n**a===(s<0?-BigInt(s):BigInt(s))||r===String(s)},cl=r=>{let t=0,e=0;for(let n=0;n<r.length;n+=1){let o=r[n];o==='\"'?n=mr(r,n)-1:o===\"{\"||o===\"[\"?e=Math.max(e,t+=1):(o===\"}\"||o===\"]\")&&(t-=1)}return e},al=r=>{let t=0,e=()=>{t=X(r,t);let o=r[t];if(o===\"{\"||o===\"[\"){let c=o===\"{\",a=c?{}:[];if(t=X(r,t+1),r[t]===(c?\"}\":\"]\"))return t+=1,a;for(;;){if(c){let l=n();if(Object.hasOwn(a,l))throw new Error(\"two keys of one name\");t=X(r,t)+1,Object.defineProperty(a,l,{value:e(),enumerable:!0,writable:!0,configurable:!0})}else a.push(e());if(t=X(r,t),r[t++]!==\",\")return a}}if(o==='\"')return n();let s=Ci(r,t),i=r.slice(t,s);if(t=s,Ui.includes(i))return JSON.parse(i);if(!il(i))throw new Error(\"a number no double holds as written\");return Number(i)},n=()=>{t=X(r,t);let o=mr(r,t),s=JSON.parse(r.slice(t,o));if(No.test(s))throw new Error(\"a lone surrogate\");return t=o,s};return e()},br=(r,t)=>{let e=qi(r);if(e===null)return;let n=X(e,0),o=Hi(e,n);if(!(o<0||X(e,o)!==e.length||cl(e)>t))try{return al(e)}catch{return}},ie=(r,t)=>{let e=(n,o,s)=>{if(n===null||typeof n==\"boolean\")return!0;if(typeof n==\"string\")return!No.test(n);if(typeof n==\"number\")return Number.isFinite(n)&&!Object.is(n,-0);if(typeof n!=\"object\"||o===0||s.has(n))return!1;s.add(n);let i=Array.isArray(n)?Object.keys(n).length===n.length&&n.every(c=>e(c,o-1,s)):[Object.prototype,null].includes(Object.getPrototypeOf(n))&&Object.getOwnPropertySymbols(n).length===0&&Object.entries(Object.getOwnPropertyDescriptors(n)).every(([c,a])=>!No.test(c)&&a.enumerable===!0&&\"value\"in a&&e(a.value,o-1,s));return s.delete(n),i};return e(r,t,new Set)?JSON.stringify(r):void 0},Do=r=>/^[1-9]\\d{0,15}$/.test(r)&&Number(r)<=Number.MAX_SAFE_INTEGER;var Ke=16,zi=(r,t,e)=>({params:{name:\"AES-GCM\",iv:rt(t),additionalData:rt(e),tagLength:Ke*8},key:gt().importKey(\"raw\",rt(r),\"AES-GCM\",!1,[\"encrypt\",\"decrypt\"])}),Dt=async(r,t,e,n)=>{let o=zi(r,t,e);return new Uint8Array(await gt().encrypt(o.params,await o.key,rt(n)))},qt=async(r,t,e,n)=>{if(n.length<Ke)return null;let o=zi(r,t,e);try{return new Uint8Array(await gt().decrypt(o.params,await o.key,rt(n)))}catch{return null}};var gn=BigInt(4294967295),Ki=BigInt(32);function ll(r,t=!1){return t?{h:Number(r&gn),l:Number(r>>Ki&gn)}:{h:Number(r>>Ki&gn)|0,l:Number(r&gn)|0}}function bn(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=ll(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var ul=r=>r/2**32|0,fl=r=>r>>>0;function Wi(r,t,e,n){let o=ul(e),s=fl(e);r.setUint32(t,n?s:o,n),r.setUint32(t+4,n?o:s,n)}var Po=(r,t,e)=>r>>>e,Fo=(r,t,e)=>r<<32-e|t>>>e,ye=(r,t,e)=>r>>>e|t<<32-e,me=(r,t,e)=>r<<32-e|t>>>e,xr=(r,t,e)=>r<<64-e|t>>>e-32,Er=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Gi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Zi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Xi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Yi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Vi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ji=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;function kr(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name===\"Uint8Array\"&&\"BYTES_PER_ELEMENT\"in r&&r.BYTES_PER_ELEMENT===1}var xn=r=>r?`\"${r}\" `:\"\";function at(r,t=\"\"){if(typeof r!=\"number\")throw new TypeError(xn(t)+\"expected number, got \"+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(xn(t)+\"expected integer >= 0, got \"+r);return r}function ec(r,t=\"\"){if(typeof r!=\"boolean\")throw new TypeError(xn(t)+\"expected boolean, got type=\"+typeof r);return r}function z(r,t,e=\"\"){if(kr(r)&&(t===void 0||r.length===t))return r;t!==void 0&&at(t,\"length\");let n=kr(r),o=t!==void 0?` of length ${t}`:\"\",s=n?`length=${r.length}`:`type=${typeof r}`,i=xn(e)+\"expected Uint8Array\"+o+\", got \"+s;throw n?new RangeError(i):new TypeError(i)}var hl=(r,t)=>{if(r===null||typeof r!=\"object\"||Array.isArray(r))throw new TypeError((t===\"object\"?\"\":`\"${t}\" `)+\"expected object, got type=\"+typeof r)},Qi=(r,t)=>{hl(r,t);let e=Object.getPrototypeOf(r);if(e!==Object.prototype&&e!==null)throw new TypeError(`\"${t}\" expected plain object`);if(Object.hasOwn(r,\"__proto__\"))throw new TypeError(`\"${t}.__proto__\" is not allowed`)};function We(r,t=!0){if(r.destroyed)throw new Error(\"hash was destroyed\");if(t&&r.finished)throw new Error(\"digest() was already called\")}function En(r,t){z(r,void 0,\"output\");let e=t.outputLen;if(!(r.length>=e))throw new RangeError('\"output\" expected length >= '+e)}function Or(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Ge(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function kn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var rc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function pl(r){return r<<24&4278190080|r<<8&16711680|r>>>8&65280|r>>>24&255}function wl(r){for(let t=0;t<r.length;t++)r[t]=pl(r[t]);return r}var Ze=rc?r=>r:wl,nc=typeof Uint8Array.from([]).toHex==\"function\"&&typeof Uint8Array.fromHex==\"function\",yl=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,\"0\"));function vr(r){if(z(r),nc)return r.toHex();let t=\"\";for(let e=0;e<r.length;e++)t+=yl[r[e]];return t}function tc(r){return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void 0}function On(r){if(typeof r!=\"string\")throw new TypeError(\"hex string expected, got \"+typeof r);if(nc)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError(\"hex string expected, got unpadded hex of length \"+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=tc(r.charCodeAt(s)),c=tc(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character \"'+a+'\" at index '+s)}n[o]=i*16+c}return n}function vn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];z(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Mo(r,t,e=\"opts\"){return Qi(r,\"defaults\"),t!==void 0&&Qi(t,e),Object.assign(Object.create(null),r,t)}function Ar(r,t={}){if(typeof r!=\"function\")throw new TypeError('\"hashCons\" expected function, got type='+typeof r);t=Mo({},t,\"info\");let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function An(r=32){at(r,\"bytesLength\");let t=typeof globalThis==\"object\"?globalThis.crypto:null;if(typeof t?.getRandomValues!=\"function\")throw new Error(\"crypto.getRandomValues must be defined\");if(r>65536)throw new RangeError(`\"bytesLength\" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var ge=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});var Bn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kn(this.buffer)}update(t){We(this),z(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let l=kn(t);for(;o<=s-c;c+=o)this.process(l,c);i=!0;continue}n.set(c===0&&a===s?t:t.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(e,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){We(this),En(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,e.fill(0,i),this.padOffset>o-i&&(this.process(n,0),e.fill(0)),Wi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=t===e?n:kn(t),a=this.outputLen,l=a/4,u=this.get();if(a%4||l>u.length)throw new Error(\"invalid outputLen\");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:e,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(e),t}clone(){return this._cloneInto()}};var oc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var sc=bn([\"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(r=>BigInt(r))),ml=sc[0],gl=sc[1],ce=new Uint32Array(80),ae=new Uint32Array(80),Uo=class extends Bn{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,e){super(128,t,16,!1),this.Ah=e[0]|0,this.Al=e[1]|0,this.Bh=e[2]|0,this.Bl=e[3]|0,this.Ch=e[4]|0,this.Cl=e[5]|0,this.Dh=e[6]|0,this.Dl=e[7]|0,this.Eh=e[8]|0,this.El=e[9]|0,this.Fh=e[10]|0,this.Fl=e[11]|0,this.Gh=e[12]|0,this.Gl=e[13]|0,this.Hh=e[14]|0,this.Hl=e[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:h,Gh:p,Gl:g,Hh:m,Hl:k}=this;return[t,e,n,o,s,i,c,a,l,u,f,h,p,g,m,k]}set(t,e,n,o,s,i,c,a,l,u,f,h,p,g,m,k){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=g|0,this.Hh=m|0,this.Hl=k|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,e){for(let d=0;d<16;d++,e+=4)ce[d]=t.getUint32(e),ae[d]=t.getUint32(e+=4);for(let d=16;d<80;d++){let w=ce[d-15]|0,y=ae[d-15]|0,v=ye(w,y,1)^ye(w,y,8)^Po(w,y,7),O=me(w,y,1)^me(w,y,8)^Fo(w,y,7),E=ce[d-2]|0,b=ae[d-2]|0,T=ye(E,b,19)^xr(E,b,61)^Po(E,b,6),B=me(E,b,19)^Er(E,b,61)^Fo(E,b,6),j=Xi(O,B,ae[d-7],ae[d-16]),P=Yi(j,v,T,ce[d-7],ce[d-16]);ce[d]=P|0,ae[d]=j|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:h,Fh:p,Fl:g,Gh:m,Gl:k,Hh:S,Hl:x}=this;for(let d=0;d<80;d++){let w=ye(f,h,14)^ye(f,h,18)^xr(f,h,41),y=me(f,h,14)^me(f,h,18)^Er(f,h,41),v=f&p^~f&m,O=h&g^~h&k,E=Vi(x,y,O,gl[d],ae[d]),b=Ji(E,S,w,v,ml[d],ce[d]),T=E|0,B=ye(n,o,28)^xr(n,o,34)^xr(n,o,39),j=me(n,o,28)^Er(n,o,34)^Er(n,o,39),P=n&s^n&c^s&c,A=o&i^o&a^i&a;S=m|0,x=k|0,m=p|0,k=g|0,p=f|0,g=h|0,{h:f,l:h}=Pt(l|0,u|0,b|0,T|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let N=Gi(T,j,A);n=Zi(N,b,B,P),o=N|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Pt(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Pt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=Pt(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:g}=Pt(this.Fh|0,this.Fl|0,p|0,g|0),{h:m,l:k}=Pt(this.Gh|0,this.Gl|0,m|0,k|0),{h:S,l:x}=Pt(this.Hh|0,this.Hl|0,S|0,x|0),this.set(n,o,s,i,c,a,l,u,f,h,p,g,m,k,S,x)}roundClean(){Ge(ce,ae)}destroy(){this.destroyed=!0,Ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Co=class extends Uo{constructor(){super(64,oc)}};var Ho=Ar(()=>new Co,ge(3));function Br(r,t,e=()=>{}){if(!Array.isArray(r))throw new TypeError(`\"${t}\" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)e(r[n],`${t}[${n}]`);return r}var Y=(r,t,e)=>z(r,t,e),qo=at;function le(r,t=\"object\"){if(r===null||typeof r!=\"object\"||Array.isArray(r))throw new TypeError(t===\"object\"?\"expected valid options object\":`\"${t}\" expected object, got type=${typeof r}`);return r}function be(r,t){if(typeof r!=\"function\")throw new TypeError(`\"${t}\" is invalid: expected function, got ${typeof r}`);return r}var cc=vr,zo=(...r)=>vn(...r),ac=r=>On(r),Sr=kr,Tr=r=>An(r),Sn=BigInt(0),ic=BigInt(1),bl=r=>r?`\"${r}\" `:\"\";function zt(r,t=\"\"){if(typeof r!=\"boolean\")throw new TypeError(bl(t)+\"expected boolean, got type=\"+typeof r);return r}function xl(r){if(typeof r==\"bigint\"){if(!ue(r))throw new RangeError(\"positive bigint expected, got \"+r)}else qo(r);return r}function Xe(r,t=\"\"){if(typeof r!=\"number\"){let e=t&&`\"${t}\" `;throw new TypeError(e+\"expected number, got type=\"+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`\"${t}\" `;throw new RangeError(e+\"expected safe integer, got \"+r)}}function lc(r){if(typeof r!=\"string\")throw new TypeError(\"hex string expected, got \"+typeof r);return r===\"\"?Sn:BigInt(\"0x\"+r)}function Tn(r){return lc(vr(r))}function Kt(r){return lc(vr(fe(z(r)).reverse()))}function Ko(r,t){if(at(t),t===0)throw new Error(\"zero output length is invalid\");r=xl(r);let e=t*2,n=r.toString(16);if(n.length>e)throw new RangeError(\"number is too large\");return On(n.padStart(e,\"0\"))}function Rn(r,t){return Ko(r,t).reverse()}function fe(r){return Uint8Array.from(Y(r))}function ue(r){return typeof r==\"bigint\"&&Sn<=r}function Wo(r,t,e){return ue(r)&&ue(t)&&ue(e)&&t<=r&&r<e}function xe(r,t,e,n){if(!Wo(t,e,n))throw new RangeError(\"expected valid \"+r+\": \"+e+\" <= n < \"+n+\", got \"+t)}function Go(r){if(r<Sn)throw new Error(\"expected non-negative bigint, got \"+r);return r===Sn?0:r.toString(2).length}var uc=r=>(Xe(r,\"n\"),(ic<<BigInt(r))-ic);function bt(r,t={},e={},n=\"object\"){le(r,n),le(t,\"fields\"),le(e,\"optFields\");function o(i,c,a){let l=n===\"object\"?`param \"${String(i)}\"`:`\"${n}.${String(i)}\"`,u=r[i];if(!Object.hasOwn(r,i)&&(a?u!==void 0:c!==\"function\"))throw new TypeError(`${l} is invalid: expected own property`);if(a&&u===void 0)return;let f=typeof u;if(f!==c||u===null)throw new TypeError(`${l} is invalid: expected ${c}, got ${f}`)}let s=(i,c)=>Object.entries(i).forEach(([a,l])=>o(a,l,c));s(t,!1),s(e,!0)}var V=BigInt(0),q=BigInt(1),Ee=BigInt(2),hc=BigInt(3),Zo=BigInt(4),pc=BigInt(5),El=BigInt(7),wc=BigInt(8),kl=BigInt(9),Ol=BigInt(15),yc=BigInt(16),vl=BigInt(\"0x10000000000000000\");function H(r,t){if(t<=V)throw new Error(\"mod: expected positive modulus, got \"+t);let e=r%t;return e>=V?e:t+e}function Al(r,t,e){if(e<=q)throw new Error(\"pow: expected modulus > 1, got \"+e);if(typeof t!=\"bigint\")throw new TypeError(\"invalid exponent: expected bigint, got \"+typeof t);if(t<V)throw new Error(\"invalid exponent, negatives unsupported\");if(t===V)return q;if(t===q)return r;let n=r%e;if(n<V&&(n+=e),t<vl){let c=q;for(;t>V;)t&q&&(c=c*n%e),n=n*n%e,t>>=q;return c}let o=[];for(;t>V;)o.push(Number(t&Ol)),t>>=Zo;let s=new Array(16);s[0]=q,s[1]=n;for(let c=2;c<16;c++)s[c]=s[c-1]*n%e;let i=s[o[o.length-1]];for(let c=o.length-2;c>=0;c--){i=i*i%e,i=i*i%e,i=i*i%e,i=i*i%e;let a=o[c];a!==0&&(i=i*s[a]%e)}return i}function xt(r,t,e){if(e<=q)throw new Error(\"pow2: expected modulus > 1, got \"+e);if(t<V)throw new Error(\"pow2: expected non-negative exponent, got \"+t);let n=r;for(;t-- >V;)n*=n,n%=e;return n}function fc(r,t){if(r===V)throw new Error(\"invert: expected non-zero number\");if(t<=q)throw new Error(\"invert: expected modulus > 1, got \"+t);let e=H(r,t),n=t,o=V,s=q;for(;e!==V;){let c=n/e,a=n-e*c,l=o-s*c;n=e,e=a,o=s,s=l}if(n!==q)throw new Error(\"invert: does not exist\");return H(o,t)}function Xo(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error(\"Cannot find square root\")}function Yo(r,t){if((r&q)===V)throw new Error(t+\": expected odd modulus, got \"+r)}function mc(r,t){let e=r,n=(e.ORDER+q)/Zo,o=e.pow(t,n);return Xo(e,o,t),o}function Bl(r,t){let e=r,n=(e.ORDER-pc)/wc,o=e.mul(t,Ee),s=e.pow(o,n),i=e.mul(t,s),c=e.mul(e.mul(i,Ee),s),a=e.mul(i,e.sub(c,e.ONE));return Xo(e,a,t),a}function Sl(r){let t=In(r),e=gc(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+El)/yc;return((c,a)=>{let l=c,u=l.pow(a,i),f=l.mul(u,n),h=l.mul(u,o),p=l.mul(u,s),g=l.eql(l.sqr(f),a),m=l.eql(l.sqr(h),a);u=l.cmov(u,f,g),f=l.cmov(p,h,m);let k=l.eql(l.sqr(f),a),S=l.cmov(u,f,k);return Xo(l,S,a),S})}function gc(r){if(r<hc)throw new Error(\"sqrt is not defined for small field\");Yo(r,\"tonelliShanks\");let t=r-q,e=0;for(;t%Ee===V;)t/=Ee,e++;let n=Ee,o=In(r);for(;Rr(o,n)===1;)if(n++>1e3)throw new Error(\"Cannot find square root: probably non-prime P\");if(e===1)return mc;let s=o.pow(n,t),i=(t+q)/Ee;return function(a,l){let u=a;if(u.is0(l))return l;if(Rr(u,l)!==1)throw new Error(\"Cannot find square root\");let f=e,h=u.mul(u.ONE,s),p=u.pow(l,t),g=u.pow(l,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))throw new Error(\"Cannot find square root: probably non-prime P\");let m=1,k=u.sqr(p);for(;!u.eql(k,u.ONE);)if(m++,k=u.sqr(k),m===f)throw new Error(\"Cannot find square root\");let S=q<<BigInt(f-m-1),x=u.pow(h,S);f=m,h=u.sqr(x),p=u.mul(p,h),g=u.mul(g,x)}return g}}function Tl(r){return Yo(r,\"Fp.sqrt\"),r%Zo===hc?mc:r%wc===pc?Bl:r%yc===kl?Sl(r):gc(r)}var bc=(r,t)=>(H(r,t)&q)===q,Rl=[\"create\",\"isValid\",\"is0\",\"neg\",\"inv\",\"sqrt\",\"sqr\",\"eql\",\"add\",\"sub\",\"mul\",\"pow\",\"div\",\"addN\",\"subN\",\"mulN\",\"sqrN\"];function Ye(r){if(le(r,\"field\"),typeof r.ORDER!=\"bigint\")throw new TypeError('param \"ORDER\" is invalid: expected bigint, got '+typeof r.ORDER);Xe(r.BYTES,\"BYTES\"),Xe(r.BITS,\"BITS\");for(let t of Rl)be(r[t],\"field.\"+t);if(r.BYTES<1||r.BITS<1)throw new Error(\"invalid field: expected BYTES/BITS > 0\");if(r.ORDER<=q)throw new Error(\"invalid field: expected ORDER > 1, got \"+r.ORDER);return r}function jn(r,t,e=!1){Ye(r),Br(t,\"nums\"),zt(e,\"passZero\");let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((c,a,l)=>n.is0(a)?c:(o[l]=c,n.mul(c,a)),n.ONE),i=n.inv(s);return t.reduceRight((c,a,l)=>n.is0(a)?c:(o[l]=n.mul(c,o[l]),n.mul(c,a)),i),o}function Rr(r,t){Ye(r);let e=r;Yo(e.ORDER,\"FpLegendre\");let n=(e.ORDER-q)/Ee,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),c=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!c)throw new Error(\"invalid Legendre symbol result\");return s?1:i?0:-1}function _l(r,t){if(t!==void 0&&qo(t),r<=V)throw new Error(\"invalid n length: expected positive n, got \"+r);if(t!==void 0&&t<1)throw new Error(\"invalid n length: expected positive bit length, got \"+t);let e=Go(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${e})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var dc=new WeakMap,_n=class{ORDER;BITS;BYTES;isLE;ZERO=V;ONE=q;_lengths;_mod;constructor(t,e={}){if(t<=q)throw new Error(\"invalid field: expected ORDER > 1, got \"+t);let n;this.isLE=!1,e!=null&&typeof e==\"object\"&&(typeof e.BITS==\"number\"&&(n=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:s}=_l(t,n);if(s>2048)throw new Error(\"invalid field: expected ORDER of <= 2048 bytes\");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return H(t,this.ORDER)}isValid(t){if(typeof t!=\"bigint\")throw new TypeError(\"invalid field element: expected bigint, got \"+typeof t);return V<=t&&t<this.ORDER}is0(t){return t===V}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&q)===q}neg(t){return H(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return H(t*t,this.ORDER)}add(t,e){return H(t+e,this.ORDER)}sub(t,e){return H(t-e,this.ORDER)}mul(t,e){return H(t*e,this.ORDER)}pow(t,e){return Al(t,e,this.ORDER)}div(t,e){return H(t*fc(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 fc(t,this.ORDER)}sqrt(t){let e=dc.get(this);return e||dc.set(this,e=Tl(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Rn(t,this.BYTES):Ko(t,this.BYTES)}fromBytes(t,e=!1){Y(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error(\"Field.fromBytes: expected \"+n+\" bytes, got \"+t.length);let l=new Uint8Array(o);l.set(t,s?0:l.length-t.length),t=l}if(t.length!==o)throw new Error(\"Field.fromBytes: expected \"+o+\" bytes, got \"+t.length);let a=s?Kt(t):Tn(t);if(c&&(a=H(a,i)),!e&&!this.isValid(a))throw new Error(\"invalid field element: outside of range 0..ORDER\");return a}invertBatch(t){return jn(this,t,!0)}cmov(t,e,n){return zt(n,\"condition\"),n?e:t}};function In(r,t={}){return Object.freeze(_n.prototype),new _n(r,t)}var Qo=BigInt(0),_r=BigInt(1),jl=BigInt(4),Vo=16,xc=128,Il=5,Ec=2**31;function jr(r){let t=r;if(typeof t!=\"function\")throw new TypeError('\"Point\" expected constructor, got type='+typeof r);be(t.fromAffine,\"Point.fromAffine\"),be(t.fromBytes,\"Point.fromBytes\"),be(t.fromHex,\"Point.fromHex\"),le(t.BASE,\"Point.BASE\"),le(t.ZERO,\"Point.ZERO\"),Ye(t.Fp),Ye(t.Fn)}function Oc(r,t){jr(r),vc(t,r);let e=jn(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function $l(r,t,e=1){if(!Number.isSafeInteger(r)||r<e||r>t)throw new Error(\"invalid window size, expected [\"+e+\"..\"+t+\"], got W=\"+r)}function Nl(r,t){let e=r*(4*t+128);if(e>Ec)throw new Error(\"invalid window size: table would need ~\"+Math.ceil(e/2**20)+\" MiB, max \"+Ec/2**20+\" MiB\")}function Ll(r,t){if(r!==void 0){be(r,\"randomBytes\");try{let e=r(t);if(!Sr(e)||e.length!==t)return}catch{return}return r}}function vc(r,t){Br(r,\"points\"),r.forEach((e,n)=>{if(!(e instanceof t))throw new Error(\"invalid point at index \"+n)})}function Dl(r,t,e){if(!Array.isArray(r))throw new Error(\"array of scalars expected\");r.forEach((n,o)=>{if(!(e===void 0?t.isValid(n):ue(n)&&n<e))throw new Error(\"invalid scalar at index \"+o)})}var Ac=new WeakMap;function Jo(r){return Ac.get(r)||1}function Pl(r,t){let e=r.double(),n=[r];for(let o=1;o<t;o++)n.push(n[o-1].add(e));return n}function Fl(r,t){let e=2**t,n=e/2,o=BigInt(e-1),s=[];for(;r>Qo;){let i=0;r&_r&&(i=Number(r&o),i>=n&&(i-=e),r-=BigInt(i)),s.push(i),r>>=_r}return s}function Ml(r,t,e){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),c=[];for(let a=0;a<e;a++){let l=Number(r&s);r>>=i,l>o&&(l-=n,r+=_r),c.push(l)}if(r!==Qo)throw new Error(\"invalid wnaf\");return c}function Ul(r,t,e){let n=0;for(let s of e)n=Math.max(n,s.length);let o=r;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<e.length;i++){let c=e[i][s];if(c){let a=t[i][Math.abs(c)-1>>1];o=o.add(c<0?a.negate():a)}}}return o}var $n=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,e){jr(t),this.randomBytes=Ll(e,Vo),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,e,n){let o=Math.ceil(n/e)+1,s=2**(e-1),i=[],c=t;for(let a=0;a<o;a++){let l=c;for(let u=0;u<s;u++)i.push(l),l=l.add(c);c=i[i.length-1].double()}return{W:e,bits:n,windows:o,comp:i}}wnafCachedCT(t,e){let{W:n,windows:o,comp:s}=t,i=2**(n-1),c=Ml(e,n,o),a=this.ZERO,l=this.BASE;for(let u=0;u<o;u++){let f=c[u],h=u*i,p=Math.abs(f)-1,g=s[h];for(let k=1;k<i;k++)g=k===p?s[h+k]:g;let m=g.negate();f===0?l=l.add(s[h]):a=a.add(f<0?m:g)}return{p:a,f:l}}getWnafPrecomputes(t,e,n,o){let s=this.wnafPrecomputes.get(e),i=s?.find(c=>c.W===t&&c.bits===n);return i||(i=this.buildWnafTable(e,t,n),typeof o==\"function\"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(e,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('\"point\" expected Point instance, got type='+typeof t)}validateMulInput(t,e){if(this.assertPoint(t),!Wo(e,_r,this.Point.Fn.ORDER))throw new Error(\"invalid scalar\")}runCT(t,e,n,o){let s=Jo(t);return s===1?this.fixedWindowCT(t,e,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),e)}mulCT(t,e,n){return this.validateMulInput(t,e),this.runCT(t,e,this.bits,n)}mulCTBlinded(t,e,n){if(this.validateMulInput(t,e),this.randomBytes===void 0)throw new Error(\"randomBytes is required for scalar blinding\");let o=this.Point.Fn.BITS+xc,s=this.randomBytes(Vo);if(!Sr(s)||s.length!==Vo)throw new Error(\"randomBytes returned invalid byte array\");s[0]=s[0]&63|128;let i=e+Tn(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,e,n){let o=Il,s=1<<o,i=uc(o),c=new Array(s);c[0]=this.ZERO;for(let u=1;u<s;u++)c[u]=c[u-1].add(t);let a=Math.ceil(n/o),l=this.ZERO;for(let u=a-1;u>=0;u--){if(u!==a-1)for(let p=0;p<o;p++)l=l.double();let f=Number(e>>BigInt(u*o)&i),h=c[0];for(let p=1;p<s;p++)h=p===f?c[p]:h;l=l.add(h)}return{p:l,f:l}}shouldBlind(t,e){return this.randomBytes===void 0?!1:e===_r?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,e,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,e,o):this.mulCT(t,e,o)}mulUnsafe(t,e,n){if(this.assertPoint(t),!ue(e))throw new Error(\"invalid scalar\");let o=Jo(t);if(o===1||e>=this.Point.Fn.ORDER)return Cl(this.Point,[t],[e],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,e).p}setWindowSize(t,e){this.assertPoint(t),$l(e,this.bits);let n=Math.ceil((this.bits+xc)/e)+1;Nl(n*2**(e-1),this.Point.Fp.BYTES),Ac.set(t,e),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return Jo(t)!==1}};function Cl(r,t,e,n=!1){if(jr(r),vc(t,r),zt(n,\"allowOversized\"),Dl(e,r.Fn,n?r.Fn.ORDER**jl:void 0),t.length!==e.length)throw new Error(\"arrays of points and scalars must have equal length\");let o=t.map(i=>Pl(i,4)),s=e.map(i=>Fl(i,4));return Ul(r.ZERO,o,s)}function kc(r,t,e){if(t){if(t.ORDER!==r)throw new Error(\"Field.ORDER must match order: Fp == p, Fn == n\");return Ye(t),t}else return In(r,{isLE:e})}function Bc(r,t,e={},n){if(r!==\"weierstrass\"&&r!==\"edwards\")throw new Error('expected curve type \"weierstrass\" or \"edwards\"');if(n===void 0&&(n=r===\"edwards\"),!t||typeof t!=\"object\")throw new Error(`expected valid ${r} CURVE object`);bt(e);for(let a of[\"p\",\"n\",\"h\"]){let l=t[a];if(!(ue(l)&&l!==Qo))throw new Error(`CURVE.${a} must be positive bigint`)}let o=kc(t.p,e.Fp,n),s=kc(t.n,e.Fn,n),c=[\"Gx\",\"Gy\",\"a\",r===\"weierstrass\"?\"b\":\"d\"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Nn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Ln=BigInt(0),Dn=BigInt(1),Pn=BigInt(2),Hl=BigInt(4),Sc=BigInt(8);function ql(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),c=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,c)}function Tc(r,t={}){bt(t,{},{},\"extraOpts\");let e=t,n=Bc(\"edwards\",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;if(Rr(o,i.a)!==1)throw new Error(\"edwards: CURVE.a must be a square in Fp for complete addition formulas\");if(Rr(o,i.d)!==-1)throw new Error(\"edwards: CURVE.d must be a non-square in Fp for complete addition formulas\");bt(e,{},{uvRatio:\"function\",randomBytes:\"function\"});let a=e.randomBytes===void 0?Tr:e.randomBytes,l=Pn<<BigInt(o.BYTES*8)-Dn;function u(x){if(!o.isOdd)throw new Error(\"Field does not have .isOdd()\");return o.isOdd(x)}let f=e.uvRatio===void 0?(x,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(x,d))}}catch{return{isValid:!1,value:Ln}}}:e.uvRatio;if(!ql(o,i,i.Gx,i.Gy))throw new Error(\"bad curve params: generator point\");let h=o.eql(i.a,o.neg(o.ONE))?x=>o.neg(x):o.eql(i.a,o.ONE)?x=>x:x=>o.mul(i.a,x);function p(x,d,w=!1){let y=w?Dn:Ln;return xe(\"coordinate \"+x,d,y,l),d}function g(x){if(!(x instanceof m))throw new Error(\"EdwardsPoint expected\")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(d,w,y,v){this.X=p(\"x\",d),this.Y=p(\"y\",w),this.Z=p(\"z\",y,!0),this.T=p(\"t\",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){if(d instanceof m)throw new Error(\"extended point not allowed\");let{x:w,y}=d||{};return p(\"x\",w),p(\"y\",y),new m(w,y,o.ONE,o.mul(w,y))}static fromBytes(d,w=!1){let y=o.BYTES,{a:v,d:O}=i;d=fe(Y(d,y,\"point\")),zt(w,\"zip215\");let E=fe(d),b=d[y-1];E[y-1]=b&-129;let T=Kt(E),B=w?l:o.ORDER;xe(\"point.y\",T,Ln,B);let j=o.sqr(T),P=o.sub(j,o.ONE),A=o.sub(o.mulN(O,j),v),{isValid:N,value:R}=f(P,A);if(!N)throw new Error(\"bad point: invalid y coordinate\");let F=u(R),M=(b&128)!==0;if(!w&&o.is0(R)&&M)throw new Error(\"bad point: x=0 and x_0=1\");return M!==F&&(R=o.neg(R)),m.fromAffine({x:R,y:T})}static fromHex(d,w=!1){return m.fromBytes(ac(d),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,w=!0){return S.setWindowSize(this,d),w||this.multiply(Pn),this}assertValidity(){let d=this,{a:w,d:y}=i;if(d.is0())throw new Error(\"bad point: ZERO\");let{X:v,Y:O,Z:E,T:b}=d,T=o.sqr(v),B=o.sqr(O),j=o.sqr(E),P=o.sqr(j),A=o.mul(T,w),N=o.mul(o.add(A,B),j),R=o.add(P,o.mul(y,o.mul(T,B)));if(!o.eql(N,R))throw new Error(\"bad point: equation left != right (1)\");let F=o.mul(v,O),M=o.mul(E,b);if(!o.eql(F,M))throw new Error(\"bad point: equation left != right (2)\")}equals(d){g(d);let{X:w,Y:y,Z:v}=this,{X:O,Y:E,Z:b}=d,T=o.mul(w,b),B=o.mul(O,v),j=o.mul(y,b),P=o.mul(E,v);return o.eql(T,B)&&o.eql(j,P)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:d,Y:w,Z:y}=this,v=o.sqr(d),O=o.sqr(w),E=o.mul(o.sqr(y),Pn),b=h(v),T=o.addN(d,w),B=o.sub(o.subN(o.sqr(T),v),O),j=o.addN(b,O),P=o.subN(j,E),A=o.subN(b,O),N=o.mul(B,P),R=o.mul(j,A),F=o.mul(B,A),M=o.mul(P,j);return new m(N,R,M,F)}add(d){g(d);let{d:w}=i,{X:y,Y:v,Z:O,T:E}=this,{X:b,Y:T,Z:B,T:j}=d,P=o.mul(y,b),A=o.mul(v,T),N=o.mul(o.mulN(E,w),j),R=o.mul(O,B),F=o.sub(o.subN(o.mulN(o.addN(y,v),o.addN(b,T)),P),A),M=o.subN(R,N),W=o.addN(R,N),Z=o.sub(A,h(P)),et=o.mul(F,M),it=o.mul(W,Z),ct=o.mul(F,Z),Ct=o.mul(M,W);return new m(et,it,Ct,ct)}subtract(d){return g(d),this.add(d.negate())}multiply(d){if(!s.isValidNot0(d))throw new RangeError(\"invalid scalar: expected 1 <= sc < curve.n\");let{p:w,f:y}=S.mulSecret(this,d,c,k);return k([w,y])[0]}multiplyUnsafe(d){if(!s.isValid(d))throw new RangeError(\"invalid scalar: expected 0 <= sc < curve.n\");return d===Ln?m.ZERO:this.is0()||d===Dn?this:S.mulUnsafe(this,d,k)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.mulUnsafe(this,i.n).is0()}toAffine(d){let w=this,y=d;if(y!=null&&typeof y!=\"bigint\")throw new TypeError('\"invertedZ\" expected bigint, got type='+typeof y);let{X:v,Y:O,Z:E}=w,b=w.is0();y==null&&(y=b?o.create(Sc):o.inv(E));let T=o.mul(v,y),B=o.mul(O,y),j=o.mul(E,y);if(b)return{x:o.ZERO,y:o.ONE};if(!o.eql(j,o.ONE))throw new Error(\"invZ was invalid\");return{x:T,y:B}}clearCofactor(){return c===Dn?this:c===Pn?this.double():c===Hl?this.double().double():c===Sc?this.double().double().double():this.multiplyUnsafe(c)}toBytes(){let{x:d,y:w}=this.toAffine(),y=o.toBytes(w);return y[y.length-1]|=u(d)?128:0,y}toHex(){return cc(this.toBytes())}toString(){return`<Point ${this.is0()?\"ZERO\":this.toHex()}>`}}let k=x=>Oc(m,x),S=new $n(m,a);return S.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function Rc(r,t,e={}){if(jr(r),typeof t!=\"function\")throw new Error('\"hash\" function param is required');let n=t,o=e;bt(o,{},{adjustScalarBytes:\"function\",randomBytes:\"function\",domain:\"function\",prehash:\"function\",zip215:\"boolean\",mapToCurve:\"function\",toMontgomery:\"function\",toMontgomerySecret:\"function\"});let{prehash:s}=o,{BASE:i,Fp:c,Fn:a}=r,l=n.outputLen,u=2*c.BYTES;if(l!==void 0&&(Xe(l,\"hash.outputLen\"),l!==u))throw new Error(`hash.outputLen must be ${u}, got ${l}`);let f=o.randomBytes===void 0?Tr:o.randomBytes,h=o.toMontgomery,p=o.toMontgomerySecret,g=o.adjustScalarBytes===void 0?A=>A:o.adjustScalarBytes,m=o.domain===void 0?(A,N,R)=>{if(zt(R,\"phflag\"),N.length||R)throw new Error(\"Contexts/pre-hash are not supported\");return A}:o.domain;function k(A){return a.create(Kt(A))}function S(A){let N=b.secretKey;Y(A,b.secretKey,\"secretKey\");let R=Y(n(A),2*N,\"hashedSecretKey\"),F=g(R.slice(0,N)),M=R.slice(N,2*N),W=k(F);return{head:F,prefix:M,scalar:W}}function x(A){let{head:N,prefix:R,scalar:F}=S(A),M=i.multiply(F),W=M.toBytes();return{head:N,prefix:R,scalar:F,point:M,pointBytes:W}}function d(A){return x(A).pointBytes}function w(A=Uint8Array.of(),...N){let R=zo(...N);return k(n(m(R,Y(A,void 0,\"context\"),!!s)))}function y(A,N,R={}){bt(R,{},{},\"options\"),A=fe(Y(A,void 0,\"message\")),s&&(A=s(A));let{prefix:F,scalar:M,pointBytes:W}=x(N),Z=w(R.context,F,A),et=i.multiply(Z).toBytes(),it=w(R.context,et,W,A),ct=a.create(Z+it*M);if(!a.isValid(ct))throw new Error(\"sign failed: invalid s\");let Ct=zo(et,a.toBytes(ct));return Y(Ct,b.signature,\"result\")}let v={zip215:o.zip215};function O(A,N,R,F=v){bt(F);let{context:M}=F,W=F.zip215===void 0?!!v.zip215:F.zip215,Z=b.signature;A=Y(A,Z,\"signature\"),N=Y(N,void 0,\"message\"),R=Y(R,b.publicKey,\"publicKey\"),W!==void 0&&zt(W,\"zip215\"),s&&(N=s(N));let et=Z/2,it=A.subarray(0,et),ct=Kt(A.subarray(et,Z)),Ct,pr,wn;try{Ct=r.fromBytes(R,W),pr=r.fromBytes(it,W),wn=i.multiplyUnsafe(ct)}catch{return!1}if(!W&&Ct.isSmallOrder())return!1;let wr=w(M,it,R,N);return pr.add(Ct.multiplyUnsafe(wr)).subtract(wn).clearCofactor().is0()}let E=c.BYTES,b={secretKey:E,publicKey:E,signature:2*E,seed:E};function T(A){return A=A===void 0?f(b.seed):A,Y(A,b.seed,\"seed\")}function B(A){return Sr(A)&&A.length===b.secretKey}function j(A,N){try{return!!r.fromBytes(A,N===void 0?v.zip215:N)}catch{return!1}}let P={getExtendedPublicKey:x,randomSecretKey:T,isValidSecretKey:B,isValidPublicKey:j,toMontgomery(A){if(h===void 0)throw new Error(\"Montgomery conversion is not supported for this curve\");return h(r.fromBytes(A))},toMontgomerySecret(A){if(p===void 0)throw new Error(\"Montgomery conversion is not supported for this curve\");return p(A)}};return Object.freeze(b),Object.freeze(P),Object.freeze({keygen:Nn(T,d),getPublicKey:d,sign:y,verify:O,utils:P,Point:r,lengths:b})}function Ir(r,t=\"n\"){if(typeof r!=\"number\")throw new TypeError(`wrong u32 integer \"${t}\": expected number, got type=${typeof r}`);if(!Number.isSafeInteger(r)||r<0||r>4294967295)throw new RangeError(`wrong u32 integer \"${t}\": expected 0..4294967295, got ${r}`);return r}function jc(r){return Ir(r,\"x\"),(r&r-1)===0&&r!==0}function ts(r,t){if(Ir(r),typeof t!=\"number\")throw new TypeError('\"bits\" expected number, got type='+typeof t);if(!Number.isSafeInteger(t)||t<0||t>32)throw new Error(`expected integer 0 <= bits <= 32, got ${t}`);let e=0;for(let n=0;n<t;n++,r>>>=1)e=e<<1|r&1;return e>>>0}function Ic(r){return Ir(r),31-Math.clz32(r)}function _c(r){if(!r||typeof r!=\"object\"||typeof r.length!=\"number\")throw new TypeError('\"values\" expected array-like, got type='+typeof r);let t=r.length;if(!jc(t))throw new Error(\"expected positive power-of-two length, got \"+t);let e=Ic(t);for(let n=0;n<t;n++){let o=ts(n,e);if(n<o){let s=r[n];r[n]=r[o],r[o]=s}}return r}var es=(r,t)=>{bt(t,{N:\"number\",roots:\"object\",dit:\"boolean\"},{invertButterflies:\"boolean\",skipStages:\"number\",brp:\"boolean\"},\"coreOpts\");let{N:e,roots:n,dit:o,invertButterflies:s=!1,skipStages:i=0,brp:c=!0}=t;Ir(e,\"coreOpts.N\");let a=Ic(e);if(!jc(e))throw new Error(\"FFT: Polynomial size should be power of two\");Ir(i,\"coreOpts.skipStages\");let l=a===0?0:a-1;if(i>l)throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${l}`);if(n.length!==e)throw new Error(`FFT: wrong roots length: expected ${e}, got ${n.length}`);let u=o!==s;return f=>{if(f.length!==e)throw new Error(\"FFT: wrong Polynomial length\");o&&c&&_c(f);for(let h=0,p=1;h<a-i;h++){let g=o?h+1+i:a-h,m=1<<g,k=m>>1,S=e>>g;for(let x=0;x<e;x+=m)for(let d=0,w=p++;d<k;d++){let y=s?o?e-w:w:d*S,v=x+d,O=x+d+k,E=n[y],b=f[O],T=f[v];if(u){let B=r.mul(b,E);f[v]=r.add(T,B),f[O]=r.sub(T,B)}else s?(f[v]=r.add(b,T),f[O]=r.mul(r.sub(b,T),E)):(f[v]=r.add(T,b),f[O]=r.mul(r.sub(T,b),E))}}return!o&&c&&_c(f),f}};var ke=BigInt(0),Et=BigInt(1),Fn=BigInt(2);function $c(r,t){return r+t-(t>>Et<<Et)}function zl(r){let t=BigInt(6)*r;return(e,n,o)=>{let s=n+o,c=((t+o-n)*e+n)%r;return{x_2:c,x_3:s-c}}}function Kl(r){return bt(r,{P:\"bigint\",type:\"string\",adjustScalarBytes:\"function\",powPminus2:\"function\"},{randomBytes:\"function\",scalarMultBase:\"function\"}),Object.freeze({...r})}function Nc(r){let t=Kl(r),{P:e,type:n,adjustScalarBytes:o,powPminus2:s,randomBytes:i}=t,c=t.scalarMultBase,a=n===\"x25519\";if(!a&&n!==\"x448\")throw new Error(\"invalid type\");let l=i===void 0?Tr:i,u=a?255:448,f=zl(e),h=a?32:56,p=BigInt(a?9:5),g=BigInt(a?121665:39081),m=a?Fn**BigInt(254):Fn**BigInt(447),k=a?BigInt(8)*(Fn**BigInt(251)-Et):BigInt(4)*(Fn**BigInt(445)-Et),S=m+k+Et,x=R=>H(R,e),d=w(p);function w(R){return Rn(x(R),h)}function y(R){let F=fe(Y(R,h,\"uCoordinate\"));return a&&(F[31]&=127),x(Kt(F))}function v(R){return Kt(o(fe(Y(R,h,\"scalar\"))))}let O=new Set(a?[ke,Et,e-Et,BigInt(\"325606250916557431795983626356110631294008115727848805560023387167927233504\"),BigInt(\"39382357235489614581723060781553021112529911719440698176882885853963445705823\")]:[ke,Et,e-Et]);function E(R,F){let M=y(F);if(O.has(M))throw new Error(\"invalid private or public key received\");let W=j(M,v(R));if(W===ke)throw new Error(\"invalid private or public key received\");return w(W)}function b(R){if(c===void 0)return E(R,d);let F=v(R);xe(\"scalar\",F,m,S);let M=x(c(F));if(M===ke)throw new Error(\"invalid private or public key received\");return w(M)}let T=b,B=E;function j(R,F){xe(\"u\",R,ke,e),xe(\"scalar\",F,m,S);let M=F,W=R,Z=Et,et=ke,it=R,ct=Et,Ct=M^M>>Et;for(let wr=BigInt(u-1);wr>=ke;wr--){let So=$c(e,Ct>>wr);({x_2:Z,x_3:it}=f(So,Z,it)),{x_2:et,x_3:ct}=f(So,et,ct);let yn=Z+et,To=x(yn*yn),Ro=Z-et,$i=x(Ro*Ro),Ni=To-$i,Za=it+ct,Xa=it-ct,Li=x(Xa*yn),Di=x(Za*Ro),Pi=Li+Di,Fi=Li-Di;it=x(Pi*Pi),ct=x(W*x(Fi*Fi)),Z=x(To*$i),et=x(Ni*(To+x(g*Ni)))}let pr=$c(e,M);({x_2:Z,x_3:it}=f(pr,Z,it)),{x_2:et,x_3:ct}=f(pr,et,ct);let wn=s(et);return x(Z*wn)}let P={secretKey:h,publicKey:h,seed:h},A=R=>(R=R===void 0?l(h):R,Y(R,P.seed,\"seed\"),R),N={randomSecretKey:A};return Object.freeze(P),Object.freeze(N),Object.freeze({keygen:Nn(A,T),getSharedSecret:B,getPublicKey:T,scalarMult:E,scalarMultBase:b,utils:N,GuBytes:d.slice(),lengths:P})}var Lc=BigInt(0),rs=BigInt(1),Dc=BigInt(2),Wl=BigInt(3),Gl=BigInt(5),Zl=BigInt(8),Mn=BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed\"),Xl={p:Mn,n:BigInt(\"0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed\"),h:Zl,a:BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec\"),d:BigInt(\"0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3\"),Gx:BigInt(\"0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a\"),Gy:BigInt(\"0x6666666666666666666666666666666666666666666666666666666666666658\")};function Mc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Mn,c=r*r%s*r%s,a=xt(c,Dc,s)*c%s,l=xt(a,rs,s)*r%s,u=xt(l,Gl,s)*l%s,f=xt(u,t,s)*u%s,h=xt(f,e,s)*f%s,p=xt(h,n,s)*h%s,g=xt(p,o,s)*p%s,m=xt(g,o,s)*p%s,k=xt(m,t,s)*u%s;return{pow_p_5_8:xt(k,Dc,s)*r%s,b2:c}}function ns(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Pc=BigInt(\"19681161376707505956807079304988542015446066515923890162744021073123829784752\");function Yl(r,t){let e=Mn,n=H(t*t*t,e),o=H(n*n*t,e),s=Mc(r*o).pow_p_5_8,i=H(r*n*s,e),c=H(t*i*i,e),a=i,l=H(i*Pc,e),u=c===r,f=c===H(-r,e),h=c===H(-r*Pc,e);return u&&(i=a),(f||h)&&(i=l),bc(i,e)&&(i=H(-i,e)),{isValid:u||f,value:i}}var $r=Tc(Xl,{uvRatio:Yl}),Fc=$r.Fp;function Vl(r){let{y:t}=r;return Fc.toBytes(Fc.div(rs+t,rs-t))}function Jl(r){let t=$r.Fp.BYTES;return z(r,t),ns(Ho(r.subarray(0,t))).subarray(0,t)}function Ql(r){return Rc($r,Ho,Object.assign({adjustScalarBytes:ns,toMontgomery:Vl,toMontgomerySecret:Jl,zip215:!0},r))}var Ve=Ql({});var os=(()=>{let r=Mn,t=e=>{let{pow_p_5_8:n,b2:o}=Mc(e);return H(xt(n,Wl,r)*o,r)};return Nc({P:r,type:\"x25519\",powPminus2:t,adjustScalarBytes:ns,scalarMultBase:e=>{let n=H(e,$r.Fn.ORDER);if(n===Lc)return Lc;let o=$r.BASE.multiply(n);return H((o.Z+o.Y)*t(H(o.Z-o.Y,r)),r)}})})();var Je=async r=>{if(r.length!==32)throw new TypeError(\"a secret is thirty-two bytes\");return os.getPublicKey(r)},Un=async(r,t)=>{if(t.length!==32||r.length!==32)return null;try{let e=os.getSharedSecret(r,t);return yr(e)?null:e}catch{return null}};var Wt=2n**255n-19n,Uc=2n**252n+27742317777372353535851937790883648493n,J=r=>(r%Wt+Wt)%Wt,Nr=(r,t)=>{let e=1n,n=J(r);for(let o=t;o>0n;o>>=1n)o&1n&&(e=e*n%Wt),n=n*n%Wt;return e},Hc=J(-121665n*Nr(121666n,Wt-2n)),tu=Nr(2n,(Wt-1n)/4n),ss=r=>r.reduceRight((t,e)=>t<<8n|BigInt(e),0n),Cc=r=>{if(r.length!==32)return null;let t=(r[31]&128)!==0,e=ss(r)&(1n<<255n)-1n;if(e>=Wt)return null;let n=J(e*e-1n),o=J(Hc*e*e+1n),s=J(n*Nr(o,3n)*Nr(n*Nr(o,7n),(Wt-5n)/8n)),i=J(o*s*s);if(i===J(-n))s=J(s*tu);else if(i!==n)return null;return s===0n&&t?null:((s&1n)!==(t?1n:0n)&&(s=J(-s)),{x:s,y:e,z:1n,t:J(s*e)})},eu=(r,t)=>{let e=J((r.y-r.x)*(t.y-t.x)),n=J((r.y+r.x)*(t.y+t.x)),o=J(2n*Hc*r.t*t.t),s=J(2n*r.z*t.z),[i,c,a,l]=[n-e,s-o,s+o,n+e];return{x:J(i*c),y:J(a*l),z:J(c*a),t:J(i*l)}},ru=r=>{let t=r;for(let e=0;e<3;e+=1)t=eu(t,t);return t.x===0n&&t.y===t.z},qc=r=>{if(r.length!==32)throw new TypeError(\"a secret is thirty-two bytes\");return r},is=async r=>Ve.getPublicKey(qc(r)),cs=async(r,t)=>Ve.sign(t,qc(r)),as=async(r,t,e)=>{if(e.length!==64)return!1;let n=Cc(r);if(n===null||ru(n)||Cc(e.subarray(0,32))===null)return!1;let o=ss(e.subarray(32));if(o>=Uc)return!1;let s=Ve.Point.fromBytes(e.subarray(0,32)),i=Ve.Point.fromBytes(r),c=new Uint8Array(await gt().digest(\"SHA-512\",rt(C(e.subarray(0,32),r,t)))),a=ss(c)%Uc;return Ve.Point.BASE.multiplyUnsafe(o).equals(s.add(i.multiplyUnsafe(a)))};var nu=BigInt(0),Lr=BigInt(1),ou=BigInt(2),su=BigInt(7),iu=BigInt(256),cu=BigInt(113),Wc=[],Gc=[],Zc=[];for(let r=0,t=Lr,e=1,n=0;r<24;r++){[e,n]=[n,(2*e+3*n)%5],Wc.push(2*(5*n+e)),Gc.push((r+1)*(r+2)/2%64);let o=nu;for(let s=0;s<7;s++)t=(t<<Lr^(t>>su)*cu)%iu,t&ou&&(o^=Lr<<(Lr<<BigInt(s))-Lr);Zc.push(o)}var Xc=bn(Zc,!0),au=Xc[0],lu=Xc[1],uu=(r,t,e)=>r<<e|t>>>32-e,fu=(r,t,e)=>t<<e|r>>>32-e,du=(r,t,e)=>t<<e-32|r>>>64-e,hu=(r,t,e)=>r<<e-32|t>>>64-e,zc=(r,t,e)=>e>32?du(r,t,e):uu(r,t,e),Kc=(r,t,e)=>e>32?hu(r,t,e):fu(r,t,e),Qe=new Uint32Array(10);function pu(r,t=24){if(!(r instanceof Uint32Array))throw new TypeError('\"s\" expected Uint32Array(50), got type='+typeof r);if(r.length!==50)throw new RangeError('\"s\" expected Uint32Array(50), got length='+r.length);if(at(t,\"rounds\"),t<1||t>24)throw new Error('\"rounds\" expected integer 1..24');for(let e=24-t;e<24;e++){for(let s=0;s<10;s++)Qe[s]=r[s]^r[s+10]^r[s+20]^r[s+30]^r[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,c=(s+2)%10,a=Qe[c],l=Qe[c+1],u=zc(a,l,1)^Qe[i],f=Kc(a,l,1)^Qe[i+1];for(let h=0;h<50;h+=10)r[s+h]^=u,r[s+h+1]^=f}let n=r[2],o=r[3];for(let s=0;s<24;s++){let i=Gc[s],c=zc(n,o,i),a=Kc(n,o,i),l=Wc[s];n=r[l],o=r[l+1],r[l]=c,r[l+1]=a}for(let s=0;s<50;s+=10){let i=r[s],c=r[s+1],a=r[s+2],l=r[s+3];r[s]^=~r[s+2]&r[s+4],r[s+1]^=~r[s+3]&r[s+5],r[s+2]^=~r[s+4]&r[s+6],r[s+3]^=~r[s+5]&r[s+7],r[s+4]^=~r[s+6]&r[s+8],r[s+5]^=~r[s+7]&r[s+9],r[s+6]^=~r[s+8]&i,r[s+7]^=~r[s+9]&c,r[s+8]^=~i&a,r[s+9]^=~c&l}r[0]^=au[e],r[1]^=lu[e]}Ge(Qe)}var Cn=class r{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;enableXOF=!1;rounds;constructor(t,e,n,o=!1,s=24){if(at(t,\"blockLen\"),at(e,\"suffix\"),at(s,\"rounds\"),ec(o,\"enableXOF\"),this.blockLen=t,this.suffix=e,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,at(n,\"outputLen\"),!(0<t&&t<200))throw new Error('\"blockLen\" must be 1..199');this.state=new Uint8Array(200),this.state32=Or(this.state)}clone(){return this._cloneInto()}keccak(){Ze(this.state32),pu(this.state32,this.rounds),Ze(this.state32),this.posOut=0,this.pos=0}update(t){We(this),z(t);let{blockLen:e,state:n,state32:o}=this,s=t.length,i=e%4===0&&t.byteOffset%4===0,c=e/4,a=i&&s>=e?Or(t):void 0;for(let l=0;l<s;){if(a!==void 0&&this.pos===0&&l%4===0&&s-l>=e){for(let f=0,h=l/4;f<c;f++)o[f]^=a[h+f];l+=e,this.pos=e,this.keccak();continue}let u=Math.min(e-this.pos,s-l);for(let f=0;f<u;f++)n[this.pos++]^=t[l++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:t,suffix:e,pos:n,blockLen:o}=this;t[n]^=e,(e&128)!==0&&n===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){We(this,!1),z(t),this.finish();let e=this.state,{blockLen:n}=this;for(let o=0,s=t.length;o<s;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,s-o);t.set(e.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error(\"XOF is not enabled\");return this.writeInto(t)}xof(t){return at(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(En(t,this),this.finished)throw new Error(\"digest() was already called\");this.writeInto(t.length===this.outputLen?t:t.subarray(0,this.outputLen)),this.destroy()}digest(){let t=new Uint8Array(this.outputLen);return this.digestInto(t),t}destroy(){this.destroyed=!0,Ge(this.state)}_cloneInto(t){let{blockLen:e,suffix:n,outputLen:o,rounds:s,enableXOF:i}=this;return t||=new r(e,n,o,i,s),t.blockLen=e,t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=o,t.enableXOF=i,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}},Yc=(r,t,e,n={})=>Ar(()=>new Cn(t,r,e),n);var Vc=Yc(6,136,32,ge(8));var Jc=Yc(6,72,64,ge(10));var Qc=(r,t,e,n={})=>Ar((o={})=>(o=Mo({},o),new Cn(t,r,o.dkLen===void 0?e:o.dkLen,!0)),n),ta=Qc(31,168,16,ge(11)),Hn=Qc(31,136,32,ge(12));var At=z;var qn=An;function wu(r,t,e=()=>{}){if(!Array.isArray(r))throw new TypeError(`\"${t}\" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)e(r[n],`${t}[${n}]`);return r}function Oe(r,t){if(r=z(r),t=z(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function ls(r){return new Uint8Array(z(r))}function Dr(r,...t){let e=o=>typeof o==\"number\"?o:o.bytesLen,n=t.reduce((o,s)=>o+e(s),0);return{bytesLen:n,encode:o=>{let s=new Uint8Array(n);for(let i=0,c=0;i<t.length;i++){let a=t[i],l=e(a),u=typeof a==\"number\"?o[i]:a.encode(o[i]);z(u,l,r),s.set(u,c),typeof a!=\"number\"&&u.fill(0),c+=l}return s},decode:o=>{z(o,n,r);let s=[];for(let i of t){let c=e(i),a=o.subarray(0,c);s.push(typeof i==\"number\"?a:i.decode(a)),o=o.subarray(c)}return s}}}function zn(r,t){let e=r,n=t*e.bytesLen;return{bytesLen:n,encode:o=>{let s=wu(o,\"u\");if(s.length!==t)throw new RangeError(`vecCoder.encode: wrong length=${s.length}. Expected: ${t}`);let i=new Uint8Array(n);for(let c=0,a=0;c<s.length;c++){let l=e.encode(s[c]);i.set(l,a),l.fill(0),a+=l.length}return i},decode:o=>{z(o,n);let s=[];for(let i=0;i<o.length;i+=e.bytesLen)s.push(e.decode(o.subarray(i,i+e.bytesLen)));return s}}}function Q(...r){for(let t of r)if(Array.isArray(t))for(let e of t)e.fill(0);else t.fill(0)}function Kn(r){if(at(r,\"bits\"),r>32)throw new RangeError('\"bits\" expected <= 32, got '+r);return r===32?4294967295:~(-1<<r)>>>0}var ea=r=>{let{newPoly:t,N:e,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:c}=r,a=(d,w=n)=>{let y=d%w|0;return(y>=0?y|0:w+y|0)|0},l=(d,w=n)=>{let y=a(d,w)|0;return(y>w>>1?y-w|0:y)|0};function u(){let d=t(e);for(let w=0;w<e;w++){let y=ts(w,i),v=BigInt(s)**BigInt(y)%BigInt(n);d[w]=Number(v)|0}return d}let f=u(),h=d=>{throw new Error(\"not implemented\")},p=c?{add:(d,w)=>{let y=d+w|0;return y>=n?y-n|0:y},sub:(d,w)=>{let y=d-w|0;return y<0?y+n|0:y},mul:(d,w)=>a((d|0)*(w|0))|0,inv:h}:{add:(d,w)=>a((d|0)+(w|0))|0,sub:(d,w)=>a((d|0)-(w|0))|0,mul:(d,w)=>a((d|0)*(w|0))|0,inv:h},g={N:e,roots:f,invertButterflies:!0,skipStages:c?1:0,brp:!1},m=es(p,{dit:!1,...g}),k=es(p,{dit:!0,...g}),S={encode:d=>m(d),decode:d=>{k(d);for(let w=0;w<d.length;w++)d[w]=a(o*d[w]);return d}};return{mod:a,smod:l,nttZetas:f,NTT:{encode:d=>S.encode(d),decode:d=>S.decode(d)},bitsCoder:(d,w)=>{for(let O=0,E=0;O<e;O++)E+=d,E>32&&Kn(E),E%=8;let y=Kn(d),v=d*(e/8);return{bytesLen:v,encode:O=>{let E=O,b=new Uint8Array(v);for(let T=0,B=0,j=0,P=0;T<E.length;T++)for(B|=(w.encode(E[T])&y)<<j,j+=d;j>=8;j-=8,B>>=8)b[P++]=B&255;return b},decode:O=>{let E=t(e);for(let b=0,T=0,B=0,j=0;b<O.length;b++)for(T|=O[b]<<B,B+=8;B>=d;B-=d,T>>=d)E[j++]=w.decode(T&y);return E}}}}},yu=r=>(t,e)=>{e||(e=r.blockLen);let n=new Uint8Array(t.length+2);n.set(t);let o=t.length,s=new Uint8Array(e),i=r.create({}),c=0,a=0;return{stats:()=>({calls:c,xofs:a}),get:(l,u)=>(n[o+0]=l,n[o+1]=u,i.destroy(),i=r.create({}).update(n),c++,()=>(a++,i.xofInto(s))),clean:()=>{i.destroy(),Q(s,n)}}},ra=yu(ta);var ot=256,nt=3329,mu=3303,gu=17,lt=ea({N:ot,Q:nt,F:mu,ROOT_OF_UNITY:gu,newPoly:r=>new Uint16Array(r),brvBits:7,isKyber:!0}),bu=Object.freeze({512:Object.freeze({N:ot,Q:nt,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128}),768:Object.freeze({N:ot,Q:nt,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192}),1024:Object.freeze({N:ot,Q:nt,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256})}),xu=r=>{if(r>=12)return{encode:e=>e,decode:e=>e>=nt?e-nt:e};let t=2**(r-1);return{encode:e=>((e<<r)+nt/2)/nt,decode:e=>e*nt+t>>>r}},Eu=r=>lt.bitsCoder(r,r===12?{encode:t=>t,decode:t=>t>=nt?t-nt:t}:{encode:t=>t,decode:t=>t}),Pr=r=>r===12?Eu(12):lt.bitsCoder(r,xu(r));function ve(r,t){let e=r,n=t;for(let o=0;o<ot;o++){let s=e[o]+n[o];e[o]=s>=nt?s-nt:s}}function ku(r,t){let e=r,n=t;for(let o=0;o<ot;o++){let s=e[o]-n[o];e[o]=s<0?s+nt:s}}function Ou(r,t,e,n,o){let s=lt.mod(lt.mod(t*n)*o+r*e),i=lt.mod(r*n+t*e);return{c0:s,c1:i}}function Wn(r,t){let e=r,n=t;for(let o=0;o<ot/2;o++){let s=lt.nttZetas[64+(o>>1)];o&1&&(s=-s);let{c0:i,c1:c}=Ou(e[2*o+0],e[2*o+1],n[2*o+0],n[2*o+1],s);e[2*o+0]=i,e[2*o+1]=c}return e}function us(r){let t=r,e=new Uint16Array(ot);for(let n=0;n<ot;){let o=t();if(o.length%3)throw new Error(\"SampleNTT: unaligned block\");for(let s=0;n<ot&&s+3<=o.length;s+=3){let i=(o[s+0]>>0|o[s+1]<<8)&4095,c=(o[s+1]>>4|o[s+2]<<4)&4095;i<nt&&(e[n++]=i),n<ot&&c<nt&&(e[n++]=c)}}return e}var vu=(r,t)=>{let e=new Uint16Array(ot),n=Or(r);Ze(n);let o=0;for(let s=0,i=0,c=0,a=0;s<n.length;s++){let l=n[s];for(let u=0;u<32;u++)c+=l&1,l>>=1,o+=1,o===t?(a=c,c=0):o===2*t&&(e[i++]=lt.mod(a-c),c=0,o=0)}if(Ze(n),o)throw new Error(`sampleCBD: leftover bits: ${o}`);return e};function Fr(r,t,e,n){return vu(r(n*ot/4,t,e),n)}var Au=r=>{let t=r,{K:e,PRF:n,XOF:o,HASH512:s,ETA1:i,ETA2:c,du:a,dv:l}=t,u=Pr(1),f=Pr(l),h=Pr(a),p=Dr(\"publicKey\",zn(Pr(12),e),32),g=zn(Pr(12),e),m=Dr(\"ciphertext\",zn(h,e),f),k=Dr(\"seed\",32,32),S=(x,d,w,y)=>{let v=[];for(let B=0;B<e;B++)v.push(lt.NTT.encode(Fr(n,y,B,i)));let O=new Uint16Array(ot),E=[];for(let B=0;B<e;B++){let j=Fr(n,y,e+B,c),P=new Uint16Array(ot);for(let A=0;A<e;A++){let N=d(B,A);ve(P,Wn(N,v[A]))}ve(j,lt.NTT.decode(P)),E.push(j),ve(O,Wn(x[B],v[B])),Q(P)}let b=Fr(n,y,2*e,c);ve(b,lt.NTT.decode(O));let T=u.decode(w);return ve(T,b),Q(x,v,O,b),m.encode([E,T])};return{secretCoder:g,lengths:{secretKey:g.bytesLen,publicKey:p.bytesLen,cipherText:m.bytesLen},keygen:x=>{At(x,32,\"seed\");let d=new Uint8Array(33);d.set(x),d[32]=e;let w=s(d),[y,v]=k.decode(w),O=[],E=[];for(let B=0;B<e;B++)O.push(lt.NTT.encode(Fr(n,v,B,i)));let b=o(y);for(let B=0;B<e;B++){let j=lt.NTT.encode(Fr(n,v,e+B,i));for(let P=0;P<e;P++){let A=us(b.get(P,B));ve(j,Wn(A,O[P]))}E.push(j)}b.clean();let T={publicKey:p.encode([E,y]),secretKey:g.encode(O)};return Q(y,v,O,E,d,w),T},encrypt:(x,d,w)=>{let[y,v]=p.decode(x),O=o(v),E=S(y,(b,T)=>us(O.get(b,T)),d,w);return O.clean(),E},prepare:x=>{let[d,w]=p.decode(x),y=o(w),v=[];for(let O=0;O<e;O++)for(let E=0;E<e;E++)v.push(us(y.get(O,E)));return y.clean(),{encrypt:(O,E)=>S(d.map(b=>b.slice()),(b,T)=>v[b*e+T].slice(),O,E),clean:()=>Q(d,v)}},decrypt:(x,d)=>{let[w,y]=m.decode(x),v=g.decode(d),O=new Uint16Array(ot);for(let b=0;b<e;b++)ve(O,Wn(v[b],lt.NTT.encode(w[b])));ku(y,lt.NTT.decode(O));let E=u.encode(y);return Q(O,v,w,y),E}}};function Bu(r){let t=r,e=Au(t),{HASH256:n,HASH512:o,KDF:s}=t,{secretCoder:i,lengths:c}=e,a=Dr(\"secretKey\",c.secretKey,c.publicKey,32,32),l=32,u=64,f=(p,g)=>{let m=p.subarray(0,384*t.K),k=i.encode(i.decode(ls(m))),S=Oe(k,m);if(Q(k),!S)throw new Error(`ML-KEM.${g}: wrong publicKey modulus`)},h=Object.freeze({...c,seed:64,msg:l,msgRand:l,secretKey:a.bytesLen});return Object.freeze({info:Object.freeze({type:\"ml-kem\"}),lengths:h,keygen:p=>{let g=p===void 0,m=g?qn(u):p,k,S;try{At(m,u,\"seed\");let x=e.keygen(m.subarray(0,32)),d=x.publicKey;k=x.secretKey,S=n(d);let w=a.encode([k,d,S,m.subarray(32)]);return{publicKey:d,secretKey:w}}finally{k!==void 0&&Q(k),S!==void 0&&Q(S),g&&Q(m)}},getPublicKey:p=>{let[g,m,k,S]=a.decode(p);return Uint8Array.from(m)},encapsulate:(p,g)=>{let m=g===void 0,k=m?qn(l):g,S;try{return At(p,c.publicKey,\"publicKey\"),At(k,l,\"message\"),f(p,\"encapsulate\"),S=o.create().update(k).update(n(p)).digest(),{cipherText:e.encrypt(p,k,S.subarray(32,64)),sharedSecret:S.subarray(0,32)}}finally{S!==void 0&&Q(S.subarray(32)),m&&Q(k)}},decapsulate:(p,g)=>{At(g,a.bytesLen,\"secretKey\"),At(p,c.cipherText,\"cipherText\");let m=a.bytesLen-96,k=m+32,S=n(g.subarray(m/2,k));if(!Oe(S,g.subarray(k,k+32)))throw new Error(\"invalid secretKey: hash check failed\");let[x,d,w,y]=a.decode(g),v=e.decrypt(p,x),O=o.create().update(v).update(w).digest(),E=O.subarray(0,32),b=e.encrypt(d,v,O.subarray(32,64)),T=Oe(p,b),B=s.create({dkLen:32}).update(y).update(p).digest();return Q(v,b,O.subarray(32),T?B:E),T?E:B},prepare:p=>{At(p,c.publicKey,\"publicKey\"),f(p,\"prepare\");let g=ls(p),m=n(g),k=e.prepare(g);return Object.freeze({publicKey:g,encapsulate:S=>{let x=S===void 0,d=x?qn(l):S,w;try{return At(d,l,\"message\"),w=o.create().update(d).update(m).digest(),{cipherText:k.encrypt(d,w.subarray(32,64)),sharedSecret:w.subarray(0,32)}}finally{w!==void 0&&Q(w.subarray(32)),x&&Q(d)}},decapsulate:(S,x)=>{At(x,a.bytesLen,\"secretKey\"),At(S,c.cipherText,\"cipherText\");let[d,w,y,v]=a.decode(x);if(!Oe(w,g)||!Oe(y,m))throw new Error(\"ML-KEM.decapsulate: secretKey does not match prepared publicKey\");let O=e.decrypt(S,d),E=o.create().update(O).update(m).digest(),b=E.subarray(0,32),T=k.encrypt(O,E.subarray(32,64)),B=Oe(S,T),j=s.create({dkLen:32}).update(v).update(S).digest();return Q(O,T,E.subarray(32),B?j:b),B?b:j},clean:k.clean})}})}function Su(r,t,e){return Hn.create({dkLen:r}).update(t).update(new Uint8Array([e])).digest()}var Tu={HASH256:Vc,HASH512:Jc,KDF:Hn,XOF:ra,PRF:Su},Ru=r=>Bu({...Tu,...r});var Gn=Ru(bu[768]);var Zn=1184,tr=1088,fs=(r,t)=>{let{publicKey:e,secretKey:n}=Gn.keygen(Uint8Array.from([...r,...t]));return{ek:e,dk:n}},Mr=(r,t)=>{if(r.length!==Zn)return null;try{let{cipherText:e,sharedSecret:n}=Gn.encapsulate(r,t);return{ciphertext:e,shared:n}}catch{return null}},ds=(r,t)=>{if(t.length!==tr)return null;try{return Gn.decapsulate(t,r)}catch{return null}};var Xn=\"org.nervur.\",_u=/^[a-z0-9][a-z0-9-]*(?:\\.[a-z0-9][a-z0-9-]*){2,}$/,Yn=r=>typeof r==\"string\"&&_u.test(r),Gt=r=>{if(typeof r!=\"function\"||!Object.hasOwn(r,\"kind\"))return;let t=r.kind;return Yn(t)?t:void 0},na=Symbol.for(\"org.nervur.ships\"),U=r=>{Object.defineProperty(r,na,{value:!0})},er=r=>typeof r==\"function\"&&Object.hasOwn(r,na),Zt=r=>{let t=Gt(r);if(t===void 0)throw new Error(`class ${typeof r==\"function\"?r.name:String(r)} declares no kind of its own`);return t};var ju=new Set([\"answer\",\"describe\",\"stance\",\"cells\",\"notes\",\"constructor\"]),Iu=(r,t)=>{for(let e=Object.getPrototypeOf(r);e!==null&&e!==Object.prototype;e=Object.getPrototypeOf(e))if(Object.hasOwn(e,t))return typeof e[t]==\"function\";return!1},Xt=class{static kind=\"org.nervur.being\";static{U(this)}static cells={};static asks={};stance;constructor(t){this.stance=t;let e=this.constructor;for(let n of Object.keys(e.asks)){if(ju.has(n))throw new Error(`ask '${n}' is a reserved name`);if(!Iu(this,n))throw new Error(`ask '${n}' has no method`)}for(let[n,o]of Object.entries(e.cells))Object.hasOwn(t.cells,n)||(t.cells[n]=structuredClone(o))}get cells(){return this.stance.cells}notes(t){return t.id===void 0?void 0:this.stance.occupants.notes(t.id)}describe(t){let e=this.constructor,n=this.notes(t),o=[];for(let[s,i]of Object.entries(e.asks))i.for&&!i.for(t,n)||o.push({name:s,...i.description===void 0?{}:{description:i.description},input:i.input??{type:\"object\"}});return{asks:o,notes:{}}}async answer(t,e,n){if(e===void 0)return this.describe(t);let o=this.constructor,s=Object.hasOwn(o.asks,e)?o.asks[e]:void 0;return!s||s.for&&!s.for(t,this.notes(t))?{error:\"unknown ask\"}:this[e].call(this,n,t)}};var rr=r=>Array.isArray(r)?`[${r.map(rr).join(\",\")}]`:r!==null&&typeof r==\"object\"?`{${Object.keys(r).sort().map(t=>`${JSON.stringify(t)}:${rr(r[t])}`).join(\",\")}}`:JSON.stringify(r),Ur=async r=>_(await se(I(rr(r))));var Bt=\"OWNER\",D=\"ward\";var G=class r extends Xt{static kind=\"org.nervur.faculty\";static{U(this)}static contracts(t){let e=[];for(let n=t;typeof n==\"function\"&&n!==r;n=Object.getPrototypeOf(n))e.push(Zt(n));return e}static fulfils(t){return typeof t==\"function\"&&t.prototype instanceof r}#t(){return this.cells.offers===void 0&&(this.cells.offers={}),this.cells.offers}async#e(){let t=(this.cells.offered??0)+1;this.cells.offered=t;let e=`lent:${t}`,n=await this.stance.occupants.invite(e);return n===null?{error:\"not invited\"}:(this.#t()[n.heir]=e,{invitation:n})}#r(t){let e=this.#t(),n=typeof t.heir==\"string\"&&Object.hasOwn(e,t.heir)?e[t.heir]:void 0;return n===void 0?{retracted:null}:(this.stance.occupants.remove(n),delete e[t.heir],{retracted:n})}describe(t){let e=super.describe(t);return t.id!==D?e:{...e,asks:[...e.asks,{name:\"offer\",input:{type:\"object\"}},{name:\"retract\",input:{type:\"object\",required:[\"heir\"]}}]}}answer(t,e,n){if(t.id===D&&e===\"offer\")return this.#e();if(t.id===D&&e===\"retract\")return Promise.resolve(this.#r(n));let o=this.#t();for(let[s,i]of Object.entries(o))i===t.id&&delete o[s];return super.answer(t,e,n)}};var ht=Symbol.for(\"nervur.silence\"),St=r=>r===ht,hs=Symbol.for(\"nervur.word\"),oa=new Map,pt=r=>{let t=oa.get(r);return t||oa.set(r,t=Object.freeze({[hs]:r})),t},wt=r=>typeof r==\"object\"&&r!==null&&typeof r[hs]==\"string\",de=r=>wt(r)?r[hs]:r;var sa=async(r,t)=>{let e=t.writable.getWriter();return e.write(rt(r)).catch(()=>{}),e.close().catch(()=>{}),new Uint8Array(await new Response(t.readable).arrayBuffer())},ys=r=>sa(r,new CompressionStream(\"deflate\")),ms=async r=>{try{return await sa(r,new DecompressionStream(\"deflate\"))}catch{throw new Error(\"bytes that do not inflate\")}},$u=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],Nu=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Lu=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Du=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Pu=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Vn=15,Cr=r=>{let t=new Uint16Array(Vn+1);for(let o=0;o<r.length;o+=1)t[r[o]]+=1;let e=new Uint16Array(Vn+1);for(let o=1;o<Vn;o+=1)e[o+1]=e[o]+t[o];let n=new Uint16Array(r.length);for(let o=0;o<r.length;o+=1)r[o]!==0&&(n[e[r[o]]++]=o);return t[0]=0,{count:t,symbol:n}},Fu=Cr(Array.from({length:288},(r,t)=>t<144?8:t<256?9:t<280?7:8)),Mu=Cr(Array.from({length:30},()=>5)),ps=class{#t;at;#e=0;#r=0;constructor(t,e){this.#t=t,this.at=e}bits(t){for(;this.#r<t;){if(this.at>=this.#t.length)throw new Error(\"a stream cut short\");this.#e|=this.#t[this.at++]<<this.#r,this.#r+=8}let e=this.#e&(1<<t)-1;return this.#e>>>=t,this.#r-=t,e}align(){this.#e=0,this.#r=0}byte(){if(this.at>=this.#t.length)throw new Error(\"a stream cut short\");return this.#t[this.at++]}decode(t){let e=0,n=0,o=0;for(let s=1;s<=Vn;s+=1){e|=this.bits(1);let i=t.count[s];if(e-i<n)return t.symbol[o+(e-n)];o+=i,n+=i,n<<=1,e<<=1}throw new Error(\"a code no table holds\")}},ws=class{bytes=new Uint8Array(1024);length=0;#t(t){if(this.length+t<=this.bytes.length)return;let e=this.bytes.length*2;for(;e<this.length+t;)e*=2;let n=new Uint8Array(e);n.set(this.bytes.subarray(0,this.length)),this.bytes=n}push(t){this.#t(1),this.bytes[this.length++]=t}copy(t,e){if(t>this.length)throw new Error(\"a distance before the start\");this.#t(e);for(let n=0;n<e;n+=1)this.bytes[this.length]=this.bytes[this.length++-t]}},Uu=r=>{let t=r.bits(5)+257,e=r.bits(5)+1,n=r.bits(4)+4,o=new Uint8Array(19);for(let c=0;c<n;c+=1)o[Pu[c]]=r.bits(3);let s=Cr(o),i=new Uint8Array(t+e);for(let c=0;c<t+e;){let a=r.decode(s);if(a<16){i[c++]=a;continue}let l,u=0;if(a===16){if(c===0)throw new Error(\"a repeat with nothing before it\");u=i[c-1],l=3+r.bits(2)}else a===17?l=3+r.bits(3):l=11+r.bits(7);if(c+l>t+e)throw new Error(\"too many lengths\");for(;l-- >0;)i[c++]=u}return[Cr(i.subarray(0,t)),Cr(i.subarray(t))]},Cu=r=>{let t=1,e=0;for(let n=0;n<r.length;n+=1)t=(t+r[n])%65521,e=(e+t)%65521;return(e<<16|t)>>>0},gs=(r,t)=>{let e=new ps(r,t),n=e.byte(),o=e.byte();if((n&15)!==8||(n<<8|o)%31!==0||(o&32)!==0)throw new Error(\"no zlib stream\");let s=new ws;for(let a=0;a===0;){a=e.bits(1);let l=e.bits(2);if(l===0){e.align();let h=e.byte()|e.byte()<<8,p=e.byte()|e.byte()<<8;if((h^65535)!==p)throw new Error(\"a stored block whose length does not check\");for(let g=0;g<h;g+=1)s.push(e.byte());continue}if(l===3)throw new Error(\"a block of no type\");let[u,f]=l===1?[Fu,Mu]:Uu(e);for(;;){let h=e.decode(u);if(h<256)s.push(h);else{if(h===256)break;{let p=h-257;if(p>=29)throw new Error(\"a length of no code\");let g=$u[p]+e.bits(Nu[p]),m=e.decode(f);if(m>=30)throw new Error(\"a distance of no code\");s.copy(Lu[m]+e.bits(Du[m]),g)}}}}e.align();let i=(e.byte()<<24|e.byte()<<16|e.byte()<<8|e.byte())>>>0,c=s.bytes.slice(0,s.length);if(i!==Cu(c))throw new Error(\"a stream whose sum does not check\");return{out:c,end:e.at}};var Hu=[\"blob\",\"tree\",\"commit\",\"tag\"];var qu=new TextDecoder(\"utf-8\",{fatal:!0}),Yt=r=>qu.decode(r),Jn=async r=>_(new Uint8Array(await gt().digest(\"SHA-1\",rt(r)))),Vt=r=>typeof r==\"string\"&&/^[0-9a-f]{40}$/.test(r),bs=r=>C(I(`${r.type} ${String(r.body.length)}\\0`),r.body),Ft=r=>Jn(bs(r)),la=r=>{let t=r.indexOf(0),e=t<0?\"\":Yt(r.subarray(0,t)),[n,o]=e.split(\" \"),s=r.subarray(t+1);if(!Hu.includes(n)||String(s.length)!==o)throw new Error(\"no loose object\");return{type:n,body:s.slice()}},xs=r=>ys(bs(r)),Es=async r=>la(await ms(r)),Hr=r=>({type:\"blob\",body:I(r)}),ks=\"100644\",nr=\"40000\",ia=r=>r.mode===nr?`${r.name}/`:r.name,zu=(r,t)=>{let[e,n]=[I(ia(r)),I(ia(t))];for(let o=0;o<Math.min(e.length,n.length);o+=1)if(e[o]!==n[o])return e[o]-n[o];return e.length-n.length},qr=r=>({type:\"tree\",body:C(...[...r].sort(zu).flatMap(t=>[I(`${t.mode} ${t.name}\\0`),$(t.id)]))}),Qn=r=>{if(r.type!==\"tree\")throw new Error(\"no tree\");let t=[];for(let e=0;e<r.body.length;){let n=r.body.indexOf(32,e),o=r.body.indexOf(0,n);if(n<0||o<0||o+21>r.body.length)throw new Error(\"a tree cut short\");t.push({mode:Yt(r.body.subarray(e,n)),name:Yt(r.body.subarray(n+1,o)),id:_(r.body.subarray(o+1,o+21))}),e=o+21}return t},ca=r=>`${r.name} <${r.email}> ${String(r.seconds)} ${r.zone}`,aa=r=>{let t=/^(.*) <([^>]*)> (\\d+) ([+-]\\d{4})$/.exec(r);if(!t)throw new Error(\"a signature git does not write\");return{name:t[1],email:t[2],seconds:Number(t[3]),zone:t[4]}},Os=r=>({type:\"commit\",body:I([`tree ${r.tree}`,...r.parents.map(t=>`parent ${t}`),`author ${ca(r.author)}`,`committer ${ca(r.committer)}`,\"\",r.message].join(`\n`))}),he=r=>{if(r.type!==\"commit\")throw new Error(\"no commit\");let t=Yt(r.body),e=t.indexOf(`\n\n`),n=e<0?t:t.slice(0,e),o=e<0?\"\":t.slice(e+2),s,i=[],c,a;for(let l of n.split(`\n`)){let u=l.indexOf(\" \"),[f,h]=[l.slice(0,u),l.slice(u+1)];f===\"tree\"?s=h:f===\"parent\"?i.push(h):f===\"author\"?c=aa(h):f===\"committer\"&&(a=aa(h))}if(!Vt(s)||!c||!a||!i.every(Vt))throw new Error(\"a commit git does not write\");return{tree:s,parents:i,author:c,committer:a,message:o}};var ua={1:\"commit\",2:\"tree\",3:\"blob\",4:\"tag\"},Ku=6,Wu=7,fa=(r,t)=>{let e=0,n=()=>{let i=0,c=0;for(let a=128;a&128;c+=7)a=t[e++],i+=(a&127)*2**c;return i};if(n()!==r.length)throw new Error(\"a delta for another base\");let o=new Uint8Array(n()),s=0;for(;e<t.length;){let i=t[e++];if(i&128){let c=0,a=0;for(let l=0;l<4;l+=1)i&1<<l&&(c|=t[e++]<<8*l);for(let l=0;l<3;l+=1)i&16<<l&&(a|=t[e++]<<8*l);if(a===0&&(a=65536),c>>>=0,c+a>r.length||s+a>o.length)throw new Error(\"a delta copy past its bounds\");o.set(r.subarray(c,c+a),s),s+=a}else if(i!==0){if(e+i>t.length||s+i>o.length)throw new Error(\"a delta insert past its bounds\");o.set(t.subarray(e,e+i),s),s+=i,e+=i}else throw new Error(\"a delta op of nothing\")}if(s!==o.length)throw new Error(\"a delta short of its size\");return o},vs=async(r,t=()=>Promise.resolve(null))=>{if(r.length<32||new TextDecoder().decode(r.subarray(0,4))!==\"PACK\")throw new Error(\"no pack\");let e=f=>(r[f]<<24|r[f+1]<<16|r[f+2]<<8|r[f+3])>>>0;if(e(4)!==2)throw new Error(\"a pack of another version\");let n=e(8),o=r.subarray(0,r.length-20);if(await Jn(o)!==_(r.subarray(r.length-20)))throw new Error(\"a pack whose sum does not check\");let s=new Map,i=12;for(let f=0;f<n;f+=1){let h=i,p=r[i++],g=p>>4&7,m=p&15;for(let d=4;p&128;d+=7)p=r[i++],m+=(p&127)*2**d;let k;if(g===Ku){p=r[i++];let d=p&127;for(;p&128;)p=r[i++],d=(d+1)*128+(p&127);k=h-d}else if(g===Wu)k=_(r.subarray(i,i+20)),i+=20;else if(!ua[g])throw new Error(`a pack entry of type ${String(g)}`);let{out:S,end:x}=gs(o,i);if(S.length!==m)throw new Error(\"a pack entry of another size\");i=x,s.set(h,{type:g,data:S,...k===void 0?{}:{base:k}})}if(i!==o.length)throw new Error(\"a pack with bytes past its objects\");let c=new Map,a=new Map,l=new Map,u=async f=>{if(typeof f==\"number\")return c.get(f);let h=a.get(f);return h||(l.has(f)||l.set(f,await t(f)),l.get(f)??void 0)};for(;c.size<s.size;){let f=c.size;for(let[h,p]of s){if(c.has(h))continue;let g;if(p.base===void 0)g={type:ua[p.type],body:p.data};else{let m=await u(p.base);if(!m)continue;g={type:m.type,body:fa(m.body,p.data)}}c.set(h,g),a.set(await Ft(g),g)}if(c.size===f)throw new Error(\"a delta whose base is nowhere\")}return a},zr=r=>{let t=I(r);return new Uint8Array([...I((t.length+4).toString(16).padStart(4,\"0\")),...t])},As=I(\"0000\"),Kr=(r,t=0,e=n=>!1)=>{let n=[];for(;t+4<=r.length;){let o=parseInt(new TextDecoder().decode(r.subarray(t,t+4)),16);if(Number.isNaN(o))throw new Error(\"no pkt-line\");if(o===0)return{lines:n,end:t+4};if(o<4||t+o>r.length)throw new Error(\"a pkt-line cut short\");let s=new TextDecoder().decode(r.subarray(t+4,t+o));if(n.push(s),t+=o,e(s))return{lines:n,end:t}}return{lines:n,end:t}};var Wr=async(r,t,e)=>{let n=await r.get(t);if(!n)throw new Error(`${t} is no object this harbor holds`);if(n.type!==e)throw new Error(`${t} is a ${n.type}, not a ${e}`);return n},eo=async(r,t)=>{let e=new Map,n=async(o,s)=>{for(let i of Qn(await Wr(r,o,\"tree\")))i.mode===nr?await n(i.id,`${s}${i.name}/`):e.set(`${s}${i.name}`,i.id)};return await n(he(await Wr(r,t,\"commit\")).tree,\"\"),e},Bs=async(r,t)=>{let e=async n=>{let o=[],s=new Map;for(let[c,a]of n){let l=c.indexOf(\"/\");if(l<0)o.push({mode:ks,name:c,id:a});else{let u=c.slice(0,l);s.has(u)||s.set(u,new Map),s.get(u).set(c.slice(l+1),a)}}for(let[c,a]of s)o.push({mode:nr,name:c,id:await e(a)});let[i]=await r.put([qr(o)]);return i};return e(t)},Ss=async(r,t)=>{let[e]=await r.put([Os(t)]);return e},Ts=async(r,t)=>{let e=new Set,n=async s=>{if(!e.has(s)){e.add(s);for(let i of Qn(await Wr(r,s,\"tree\")))i.mode===nr?await n(i.id):e.add(i.id)}},o=[t];for(;o.length>0;){let s=o.pop();if(e.has(s))continue;e.add(s);let i=he(await Wr(r,s,\"commit\"));await n(i.tree),o.push(...i.parents)}return[...e]},to=class{#t=new Map;objects(){return[...this.#t.values()]}get(t){return Promise.resolve(this.#t.get(t)??null)}async put(t){let e=[];for(let n of t){let o=await Ft(n);this.#t.set(o,n),e.push(o)}return e}},or=class{#t;#e=new to;constructor(t){this.#t=t}async get(t){return await this.#e.get(t)??this.#t.get(t)}put(t){return this.#e.put(t)}async flush(){await this.#t.put(this.#e.objects())}};var sr=\"git-upload-pack\",Gu=\"agent=nervur\",da=r=>r.replace(/\\/+$/,\"\"),Rs=async r=>{let t=await fetch(`${da(r)}/info/refs?service=${sr}`,{headers:{accept:`application/x-${sr}-advertisement`}});if(!t.ok)throw new Error(`${r} answered ${String(t.status)}`);let e=new Uint8Array(await t.arrayBuffer()),n=Kr(e);if(n.lines[0]?.trim()!==`# service=${sr}`)throw new Error(`${r} is no git repository over smart HTTP`);let o={};for(let s of Kr(e,n.end).lines){let[i]=s.replace(/\\n$/,\"\").split(\"\\0\"),[c,a]=i.split(\" \");Vt(c)&&a!==void 0&&!a.endsWith(\"^{}\")&&!/^0{40}$/.test(c)&&(o[a]=c)}return o},_s=256,js=async(r,t)=>{let e=[],n=new Set,o=[],s=async i=>{if(n.has(i))return;n.add(i);let c=await t(i);if(c?.type!==\"commit\")return;let a=he(c);o.push({id:i,seconds:a.committer.seconds,parents:a.parents})};for(let i of r)await s(i);for(;o.length>0&&e.length<_s;){o.sort((c,a)=>a.seconds-c.seconds);let i=o.shift();e.push(i.id);for(let c of i.parents)await s(c)}return e},Is=async(r,t,e,n=[])=>{let o=[];for(let u of new Set(t))await e(u)||o.push(u);if(o.length===0)return new Map;let s=C(...o.map((u,f)=>zr(f===0?`want ${u} ofs-delta thin-pack ${Gu}\n`:`want ${u}\n`)),As,...n.slice(0,_s).map(u=>zr(`have ${u}\n`)),zr(`done\n`)),i=await fetch(`${da(r)}/${sr}`,{method:\"POST\",headers:{\"content-type\":`application/x-${sr}-request`,accept:`application/x-${sr}-result`},body:Uint8Array.from(s)});if(!i.ok)throw new Error(`${r} answered ${String(i.status)}`);let c=new Uint8Array(await i.arrayBuffer()),a=0,l=[];for(;a<c.length&&new TextDecoder(\"latin1\").decode(c.subarray(a,a+4))!==\"PACK\";){let u=Kr(c,a,()=>!0);if(l.push(...u.lines),u.end===a||!/^(ACK|NAK)/.test(u.lines.at(-1)??\"\"))throw new Error(`${r} sent no pack: ${l.join(\" \").slice(0,200)||\"nothing\"}`);a=u.end}return vs(c.subarray(a),e)};var $s=3e4,Ns=3e5,Ls=r=>{let t=typeof r?.time==\"number\"?Math.floor(r.time):NaN;return Math.min(Number.isFinite(t)&&t>0?t:3e4,3e5)},no=Symbol(\"late\"),ro=class{#t;#e;#r=!1;constructor(t,e){this.#t=t.wait(e),this.#e=this.#t.done.then(()=>(this.#r=!0,no))}get rang(){return this.#r}race(t){return t.catch(()=>{}),Promise.race([t,this.#e])}cancel(){this.#t.cancel()}};var Zu=/^(?:([^:/?#]+):)?(?:\\/\\/([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$/,Xu=/^(?:[A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=]|%[0-9A-Fa-f]{2})*$/,Yu=/^[A-Za-z][A-Za-z0-9+.-]*$/,Vu=/^(?:[A-Za-z0-9\\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*$/,Ju=/^\\[(?:[0-9A-Fa-f:.]+|v[0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&'()*+,;=:]+)\\]$/,Ds=r=>{if(typeof r!=\"string\"||!Xu.test(r))return null;let t=Zu.exec(r);if(!t||t[1]===void 0||!Yu.test(t[1]))return null;let e={scheme:t[1].toLowerCase(),authority:t[2]??null,userinfo:null,host:null,port:null,path:t[3]??\"\",query:t[4]??null,fragment:t[5]??null};if(e.authority===null)return e;let n=e.authority,o=n.lastIndexOf(\"@\");o>=0&&(e.userinfo=n.slice(0,o),n=n.slice(o+1));let s=/^(\\[[^\\]]*\\]|[^:[\\]]*)(?::([0-9]*))?$/.exec(n);if(!s)return null;let i=s[1];return(i.startsWith(\"[\")?!Ju.test(i):!Vu.test(i))?null:(e.host=i,e.port=s[2]??null,e)},ha=r=>r.startsWith(\"[\")?r.slice(1,-1):r;var Ae=r=>{let t=Ds(r);if(!t||t.scheme!==\"tcp\"||t.authority===null||t.userinfo!==null||t.path!==\"\"||t.query!==null||t.fragment!==null||!t.host||t.port===null||!/^[0-9]+$/.test(t.port))return null;let e=Number(t.port);return e<1||e>65535?null:{host:ha(t.host),port:e}},oo=(r,t)=>`tcp://${r.includes(\":\")?`[${r}]`:r}:${t}`,Qu=new Set([\"http\",\"https\",\"ws\",\"wss\"]),ir=r=>{let t=Ds(r);if(!t||!Qu.has(t.scheme)||t.authority===null||t.userinfo!==null||t.fragment!==null||!t.host||t.port!==null&&t.port!==\"\"&&(!/^[0-9]+$/.test(t.port)||Number(t.port)>65535))return null;let e=t.scheme,n=e===\"https\"||e===\"wss\",o=t.port?Number(t.port):n?443:80,s=`${t.path||\"/\"}${t.query!==null?`?${t.query}`:\"\"}`;return{scheme:e,secure:n,held:e===\"ws\"||e===\"wss\",host:ha(t.host),port:o,path:s,href:r}},Ps=r=>{let t=(Ae(r)??ir(r))?.host;return t===\"0.0.0.0\"||t===\"::\"},Gr=r=>Array.isArray(r)?r.filter(t=>Ds(t)!==null):[];var Tt={seal:I(\"quo-seal\"),edgeSeal:I(\"quo-edge-seal\"),lock:I(\"quo-lock\"),edge:I(\"quo-edge\"),wardSign:I(\"quo-ward-sign\"),wardSeal:I(\"quo-ward-seal\")},Rt=class r{secret;pk;constructor(t,e){this.secret=t,this.pk=e}static async from(t){return new r(t,await is(t))}static draw(t){return r.from(t(32))}get id(){return _(this.pk)}},Jt=class r{secret;pk;constructor(t,e){this.secret=t,this.pk=e}static async from(t){return new r(t,await Je(t))}static draw(t){return r.from(t(32))}agree(t){return Un(this.secret,t)}},Be=class r{signing;sealSecret;padlock;constructor(t,e,n){this.signing=t,this.sealSecret=e,this.padlock=n}static async from(t){let e=typeof t==\"string\"?await se(I(t)):t.length===32?t:await se(t),n=await dt(e,Tt.wardSeal,32);return new r(await Rt.from(await dt(e,Tt.wardSign,32)),n,await Je(n))}get pk(){return _(this.signing.pk)+_(this.padlock)}open(t){return Un(this.sealSecret,t)}},so=r=>({signing:r.slice(0,64),padlock:r.slice(64)}),pa=r=>{let t=r(64);return fs(t.subarray(0,32),t.subarray(32))};var tf=[\"to\",\"by\",\"next\",\"seq\"],ef=\"0\".repeat(64),rf=r=>K(r,32)&&r!==ef,Fs=(r,t)=>{if(t&&r===\"null\")return null;if(!/^\"[0-9a-f]{64}\"$/.test(r))return;let e=r.slice(1,-1);return rf(e)?e:void 0},Ms=r=>{let t=[`\"to\":${JSON.stringify(r.to)}`,`\"by\":\"${r.by}\"`,`\"next\":${JSON.stringify(r.next)}`,`\"seq\":${r.seq}`];return r.method!==void 0&&t.push(`\"method\":${JSON.stringify(r.method)}`),r.args!==void 0&&t.push(`\"args\":${r.args}`),`{${t.join(\",\")}}`},Us=r=>{let t=gr(r);if(t===null)return{fault:\"not an object\"};let e={fault:\"not well formed\"};if(!tf.every(l=>t.has(l)))return e;let n=Fs(t.get(\"to\"),!0),o=Fs(t.get(\"by\"),!1),s=Fs(t.get(\"next\"),!0),i=t.get(\"seq\");if(n===void 0||!o||s===void 0||!Do(i))return e;let c=t.get(\"method\");if(c!==void 0&&!c.startsWith('\"'))return e;let a=t.get(\"args\");return a!==void 0&&!a.startsWith(\"{\")?e:{payload:{to:n,by:o,next:s,seq:Number(i),...c===void 0?{}:{method:JSON.parse(c)},...a===void 0?{}:{args:a}}}};var wa=[\"removed\",\"unannounced\",\"repeated\"],ya='{\"silence\":true}',Hs=r=>\"silence\"in r?ya:\"quo\"in r?`{\"quo\":\"${r.quo}\"}`:`{\"object\":${r.object},\"seen\":${JSON.stringify(r.seen)}}`,Cs=(r,...t)=>r.size===t.length&&t.every(e=>r.has(e)),qs=r=>{let t=gr(r);if(t===null)return null;if(Cs(t,\"silence\"))return t.get(\"silence\")===\"true\"?{silence:!0}:null;if(Cs(t,\"quo\")){let e=t.get(\"quo\"),n=e.startsWith('\"')?JSON.parse(e):null;return wa.find(o=>o===n)?{quo:n}:null}if(Cs(t,\"object\",\"seen\")){let e=t.get(\"seen\");return e===\"null\"?{object:t.get(\"object\"),seen:null}:e.startsWith('\"')?{object:t.get(\"object\"),seen:JSON.parse(e)}:null}return null};var io=1048576,tt=32,zs=64,Ks=tt+Ke,ma=new Uint8Array(32),lp=new Uint8Array(tt),ga=async(r,...t)=>{let e=await dt(C(...t),r,44);return{key:e.subarray(0,32),nonce:e.subarray(32)}},Ws=async(r,t,e,n)=>{let{key:o,nonce:s}=await ga(r,...t);return Dt(o,s,e,n)},Gs=async(r,t,e,n)=>{let{key:o,nonce:s}=await ga(r,...t);return qt(o,s,e,n)},co=r=>dt(r,Tt.lock,32),ao=(r,t)=>dt(C(r,t),Tt.edge,32),lo=async(r,t)=>C(r,await cs(t.secret,r)),uo=r=>r.length<=zs?null:{text:r.subarray(0,-zs),signature:r.subarray(-zs)},Zr=(r,t)=>as(r,t.text,t.signature),Zs=async(r,t,e,n,o,s)=>{let i=await r.agree(t);if(i===null)return null;let c=await Ws(Tt.seal,[i],r.pk,e),a=await Ws(Tt.edgeSeal,[i,n],r.pk,o);return C(r.pk,c,s??new Uint8Array(0),a)},ba=async(r,t)=>{if(r.length<tt+Ks)return null;let e=r.subarray(0,tt),n=await Gs(Tt.seal,[t],e,r.subarray(tt,tt+Ks));return n===null?null:{lid:e,agreement:t,head:n,rest:r.subarray(tt+Ks)}},xa=r=>r.length<tr?null:{ciphertext:r.subarray(0,tr),sealedBody:r.subarray(tr)},Ea=(r,t,e)=>Gs(Tt.edgeSeal,[r.agreement,t],r.lid,e),Xr=async(r,t)=>{let e=await Jt.draw(r),n=await e.agree(t);return n===null?null:{ephemeral:e,agreement:n}},Yr=async(r,t)=>C(r.ephemeral.pk,await Ws(Tt.seal,[r.agreement],r.ephemeral.pk,t)),ka=async(r,t)=>{if(r.length>io||r.length<tt+Ke)return null;let e=r.subarray(0,tt),n=await t.agree(e);if(n===null)return null;let o=await Gs(Tt.seal,[n],e,r.subarray(tt));return o===null?null:{bytes:o,agreement:n}};var Xs=64,Vr=class{key;relations;behind;draw;constructor(t,e,n,o){this.key=t,this.relations=e,this.behind=n,this.draw=o}async invite(t=[]){let e=this.relations.lock();e||this.relations.setLock(e=pa(this.draw));let n=await Rt.draw(this.draw);this.relations.set(n.id,{state:\"fresh\"});let o={ward:this.key.pk,heir:n.id,secret:_(n.secret),lock:_(e.ek),...t.length>0?{at:[...t]}:{}};return{heir:n.id,invitation:o}}remove(t){let e=this.relations.get(t);return e===void 0||e.state===\"kept\"?!1:(e.state===\"fresh\"?this.relations.delete(t):this.relations.set(t,{state:\"kept\",held:e.held,vouched:e.vouched,open:e.open,offered:e.offered}),!0)}async arrive(t){let e=async k=>({bytes:await this.#s(t),case:k,heard:!1});if(t.length>io||t.length<tt)return e(1);let n=await this.key.open(t.subarray(0,tt)),o=n&&await ba(t,n);if(!o)return e(1);let s=yr(o.head),i=_(o.head),c=s?void 0:this.relations.get(i),a=await this.#o(o,c);if(!a)return e(1);let l=Us(a.text);if(\"fault\"in l)return e(l.fault===\"not an object\"?2:3);let u=l.payload;if(s?u.to!==null:u.to!==i)return e(3);if(s){if(!this.behind.zero)return e(4);if(!await Zr($(u.by),a))return e(5);let k=await this.#r(null,u);return{bytes:await this.#n(o,k),case:\"object\"in k?12:13,heard:!1}}if(c===void 0)return e(6);if(!Oa(c,i,u.by))return e(7);if(!await Zr($(u.by),a))return e(8);let f=await Xr(this.draw,o.lid);if(!f)return e(1);let h=await ao(a.edge,f.agreement),p=this.relations.get(i);if(p===void 0||!Oa(p,i,u.by)||!nf(p,a.edge))return e(7);if(p.state===\"kept\")return this.#t(f,{quo:\"removed\"},9);if(p.state===\"fresh\"&&(u.next===null||u.next===i))return this.#t(f,{quo:\"unannounced\"},10);if(p.state===\"spent\"&&!of(p,u.seq))return this.#t(f,{quo:\"repeated\"},11);this.relations.set(i,sf(p,i,u,_(a.edge),_(h)));let g=await this.#r(i,u),m=await this.relations.kept().catch(()=>!1);return this.#t(f,m?g:{silence:!0},m&&\"object\"in g?12:13)}async#t(t,e,n){return{bytes:await Yr(t,await this.#e(e)),case:n,heard:!0}}#e(t){return lo(I(Hs(t)),this.key.signing)}async#r(t,e){try{return await this.behind.answer(t,e)}catch{return{silence:!0}}}async#n(t,e){let n=await Xr(this.draw,t.lid);return n?Yr(n,await this.#e(e)):this.#s(t.lid)}async#o(t,e){let n=[];if(e?.state===\"fresh\"){let o=xa(t.rest),s=this.relations.lock(),i=o&&s?ds(s.dk,o.ciphertext):null;if(!o||!i)return null;n.push({edge:await co(i),sealed:o.sealedBody})}else if(e===void 0)n.push({edge:ma,sealed:t.rest});else for(let o of[e.open,e.offered])n.push({edge:$(o),sealed:t.rest});for(let{edge:o,sealed:s}of n){let i=await Ea(t,o,s);if(i===null)continue;let c=uo(i);return c&&{edge:o,...c}}return null}async#s(t){let e=await this.#e({silence:!0}),n=[t.length>=tt?t.subarray(0,tt):null,this.draw(tt)];for(let o of n){let s=o&&await Xr(this.draw,o);if(s)return Yr(s,e)}return Yr(await Xr(this.draw,await Je(this.draw(tt))),e)}},Oa=(r,t,e)=>r.state===\"fresh\"?e===t:e===r.held||e===r.vouched,nf=(r,t)=>r.state===\"fresh\"||_(t)===r.open||_(t)===r.offered,of=(r,t)=>t>r.highest||t>r.highest-Xs&&t!==r.highest&&!r.honoured.includes(t),sf=(r,t,e,n,o)=>{let s=e.next!==null&&e.next!==t&&e.next!==e.by?e.next:null;if(r.state===\"fresh\")return{state:\"spent\",held:s,vouched:null,open:n,offered:o,highest:e.seq,honoured:[]};if(r.state!==\"spent\")return r;if(e.seq<r.highest)return{...r,honoured:[...r.honoured,e.seq]};let i=e.by===r.held?{held:r.held,vouched:s??r.vouched,open:n,offered:o}:{held:e.by,vouched:s,open:n,offered:o},c=[...r.honoured,r.highest].filter(a=>a>e.seq-Xs);return{state:\"spent\",...i,highest:e.seq,honoured:c}};var kt=r=>{if(typeof r!=\"object\"||r===null||Array.isArray(r))return null;let{ward:t,heir:e,secret:n,lock:o,at:s}=r;if(!K(t,64)||!K(e,32)||!K(n,32)||!K(o,Zn)||Mr($(o),new Uint8Array(32))===null)return null;let i=Gr(s);return{ward:t,heir:e,secret:n,lock:o,...i.length>0?{at:i}:{}}};var Ys=r=>r?{ek:$(r.ek),dk:$(r.dk)}:void 0,Vs=r=>({ek:_(r.ek),dk:_(r.dk)}),Js=256;var Qs=()=>({key:null,edge:null,sent:0,moved:0,knock:null,probed:!1}),cr=class{invitation;state;draw;constructor(t,e,n){this.invitation=t,this.state=e,this.draw=n}async ask(t,e){let n=this.state;return n.key!==null?this.#e($(n.key),$(n.edge),t,e):n.knock===null?this.#t(t,e):n.probed?(this.state={...n,probed:!1},{bytes:$(n.knock.bytes),lid:await Jt.from($(n.knock.lid)),next:n.knock.next,edge:n.knock.edge,seq:n.knock.seq}):(this.state={...n,probed:!0},this.#e($(n.knock.next),$(n.knock.edge),t,e))}async read(t,e){if(e===null)return{nothing:!0};let n=await this.#n(t,e);if(n===null)return{silence:!0};if(\"object\"in n.text&&t.seq>this.state.moved){let o=await ao($(t.edge),n.agreement);this.state={...this.state,key:t.next,edge:_(o),moved:t.seq,knock:null,probed:!1}}return n.text}async#t(t,e){let n=await Rt.from($(this.invitation.secret)),o=await Rt.draw(this.draw),s=await Jt.draw(this.draw),i=Mr($(this.invitation.lock),this.draw(32));if(i===null)return null;let c=await co(i.shared),a=this.state.sent+1,l=await this.#r(n,o,a,t,e),u=await Zs(s,$(so(this.invitation.ward).padlock),$(this.invitation.heir),c,l,i.ciphertext);return u===null?null:(this.state={...this.state,sent:a,knock:{bytes:_(u),lid:_(s.secret),next:_(o.secret),edge:_(c),seq:a}},{bytes:u,lid:s,next:_(o.secret),edge:_(c),seq:a})}async#e(t,e,n,o){let s=await Rt.from(t),i=await Rt.draw(this.draw),c=await Jt.draw(this.draw),a=this.state.sent+1,l=await this.#r(s,i,a,n,o),u=await Zs(c,$(so(this.invitation.ward).padlock),$(this.invitation.heir),e,l);return u===null?null:(this.state={...this.state,sent:a},{bytes:u,lid:c,next:_(i.secret),edge:_(e),seq:a})}#r(t,e,n,o,s){let i=Ms({to:this.invitation.heir,by:t.id,next:e.id,seq:n,...o===void 0?{}:{method:o},...s===void 0?{}:{args:s}});return lo(new TextEncoder().encode(i),t)}async#n(t,e){let n=await ka(e,t.lid),o=n&&uo(n.bytes);if(!n||!o||!await Zr($(so(this.invitation.ward).signing),o))return null;let s=qs(o.text);return s&&{text:s,agreement:n.agreement}}};var Qr=\"\",Jr=class{memory;constructor(t){this.memory=t;let e=t.rows;e.ward??={heirs:{},gone:[],bind:{},public:null},e.beings??={}}get head(){return this.memory.rows.ward}get beings(){return this.memory.rows.beings}being(t){return Object.hasOwn(this.beings,t)?this.beings[t]:void 0}told(t){this.memory.told(t)}toldHead(){this.memory.told(Qr)}kept(){return this.memory.kept().catch(()=>!1)}},fo=class{#t;constructor(t){this.#t=t}get#e(){return this.#t.head}lock(){return Ys(this.#e.lock)}setLock(t){this.#e.lock=Vs(t),this.#t.toldHead()}get(t){return Object.hasOwn(this.#e.heirs,t)?this.#e.heirs[t]:void 0}set(t,e){let n=this.#e;if(n.heirs[t]=e,e.state===\"kept\")for(n.gone.push(t);n.gone.length>Js;)delete n.heirs[n.gone.shift()];this.#t.toldHead()}delete(t){delete this.#e.heirs[t],this.#t.toldHead()}kept(){return this.#t.kept()}};var _t=64,Se=r=>{throw new TypeError(`cells hold values: ${r}`)},cf=(r,t,e)=>{let n=ie(r,t);return n===void 0?Se(`${e} is not a value JSON keeps, within ${t} levels`):JSON.parse(n)},ho=class{#t=new WeakMap;#e;constructor(t){this.#e=t}guard(t){return this.#r(t,\"cells\",1)}#r(t,e,n){let o=this.#t.get(t);if(o)return o;let s=_t-n,i=(a,l,u)=>{if(typeof l!=\"string\")return Se(`${e} takes no symbol key`);let f=`${e}.${l}`;if(Array.isArray(a)){if(l===\"length\")return(typeof u!=\"number\"||u>a.length)&&Se(`${f} past its end would leave a hole`),a.length=u,this.#e(),!0;/^(0|[1-9]\\d*)$/.test(l)||Se(`${f} is not a slot of a list`),Number(l)>a.length&&Se(`${f} would leave a hole`)}let h=Reflect.defineProperty(a,l,{value:cf(u,s,f),enumerable:!0,writable:!0,configurable:!0});return this.#e(),h},c=new Proxy(t,{get:(a,l,u)=>{let f=Reflect.get(a,l,u);return typeof l==\"string\"&&Object.hasOwn(a,l)&&typeof f==\"object\"&&f!==null?this.#r(f,`${e}.${l}`,n+1):f},set:(a,l,u)=>i(a,l,u),defineProperty:(a,l,u)=>\"value\"in u?i(a,l,u.value):Se(`${e}.${String(l)} is an accessor`),deleteProperty:(a,l)=>{let u=Reflect.deleteProperty(a,l);return this.#e(),u},setPrototypeOf:()=>Se(`${e} keeps its prototype`)});return this.#t.set(t,c),c}};var af=new Set([Bt]),lf=2,ti=class{#t=new Map;run(t,e){let n=(this.#t.get(t)??Promise.resolve()).then(e,e),o=n.catch(()=>{});return this.#t.set(t,o),o.then(()=>{this.#t.get(t)===o&&this.#t.delete(t)}),n}},uf=r=>\"nothing\"in r?pt(\"unreached\"):\"silence\"in r?ht:\"quo\"in r?pt(r.quo):br(r.object,_t)??ht,pe=class{key;occupants;standings;#t;#e;#r=new ti;#n=new ho(()=>this.#a());constructor(t,e,n,o={}){Object.assign(this,o),this.key=e,this.#t=t,this.#e=n,this.occupants={invite:(s,i)=>this.#l(s,i),notes:s=>Object.hasOwn(n.occupants,s)?n.occupants[s].notes:void 0,ids:()=>Object.keys(n.occupants),remove:s=>this.#c(s)},this.standings={take:(s,i)=>this.#i(s,i),get:s=>this.#u(s),ids:()=>Object.keys(n.standings),remove:s=>this.#h(s)}}get cells(){return this.#n.guard(this.#e.cells)}get#o(){return this.#t.live(this.key,this.#e)}boot(t,e,n){return this.#o?this.#t.boot(this.key,t,e,n):Promise.resolve(null)}async lend(t,e){let n=Gt(t);if(n===void 0||!this.#s(e,this.#e.standings))return null;let o=await this.#t.offer(n);if(o===null)return null;let s=await this.#i(e,o);return s===null&&await this.#t.retract(n,o.heir),s}#s(t,e){return this.#o&&typeof t==\"string\"&&!af.has(t)&&!Object.hasOwn(e,t)}async#l(t,e={}){let n=ie(e,_t);if(!this.#s(t,this.#e.occupants)||n===void 0)return null;let{heir:o,invitation:s}=await this.#t.door.invite(this.#t.reach());return this.#s(t,this.#e.occupants)?(this.#e.occupants[t]={heir:o,notes:JSON.parse(n)},this.#t.partition.head.bind[o]={being:this.key,id:t},this.#a(),this.#t.partition.toldHead(),s):(this.#t.door.remove(o),null)}#c(t){if(!this.#o||!Object.hasOwn(this.#e.occupants,t))return!1;let{heir:e}=this.#e.occupants[t];return this.#t.door.remove(e),delete this.#e.occupants[t],delete this.#t.partition.head.bind[e],this.#a(),this.#t.partition.toldHead(),!0}async#i(t,e){let n=kt(e);if(!n||!this.#s(t,this.#e.standings))return null;n.at&&await this.#t.learn(n.ward,n.at);let o=new cr(n,Qs(),this.#t.draw),s=await this.#r.run(`take:${t}`,async()=>{let i=await this.#p(o);for(let c=0;c<lf&&(\"nothing\"in i||\"silence\"in i);c+=1)i=await this.#p(o);return i});return!(\"object\"in s)||!this.#s(t,this.#e.standings)?null:(this.#e.standings[t]={invitation:n,state:o.state,seen:s.seen},this.#a(),t)}#h(t){return!this.#o||!Object.hasOwn(this.#e.standings,t)?!1:(delete this.#e.standings[t],this.#a(),!0)}#u(t){if(Object.hasOwn(this.#e.standings,t))return{id:t,ask:(e,n,o)=>this.#f(t,e,n,o)}}async#f(t,e,n={},o){let s=ie(n,_t+1);if(e!==void 0&&typeof e!=\"string\"||s===void 0||Array.isArray(n))return pt(\"unreached\");let i=new ro(this.#t.clock,Ls(o));try{let c=await i.race(this.#r.run(`ask:${t}`,async()=>{let a=Object.hasOwn(this.#e.standings,t)?this.#e.standings[t]:void 0;if(!this.#o||a===void 0)return pt(\"dropped\");if(i.rang)return pt(\"late\");let l=new cr(a.invitation,a.state,this.#t.draw),u=await i.race(this.#p(l,e,s));return a.state=l.state,u===no?pt(\"late\"):(\"object\"in u&&(a.seen=u.seen),this.#a(),await this.#t.partition.kept(),uf(u))}));return c===no?pt(\"late\"):c}finally{i.cancel()}}async#p(t,e,n){let o=await t.ask(e,n);return o?t.read(o,await this.#t.send(t.invitation.ward,o.bytes)):{nothing:!0}}#a(){this.#t.partition.told(this.key)}};var Te=(r,t)=>r.id===Bt||t?.owner===!0,L=(r,t={})=>({description:r,input:{type:\"object\",...t},for:Te}),en=(r,t={})=>({description:r,input:{type:\"object\",...t},for:e=>e.id===Bt}),tn=\"held:\",st=r=>typeof r==\"string\",ei=r=>typeof r==\"object\"&&r!==null&&!Array.isArray(r),yt=class extends Xt{static kind=\"org.nervur.ward\";static{U(this)}static asks={boot:L(\"a new being of this ward\",{required:[\"key\",\"class\"]}),unboot:L(\"a being out, with every relation she holds\",{required:[\"being\"]}),public:L(\"the being a stranger reaches, or none\",{required:[\"key\"]}),invite:L(\"an invitation on a being of this ward\",{required:[\"being\",\"id\"]}),ask:L(\"a being of this ward, asked as the owner; with no being, the public being asked as nobody\"),own:en(\"an invitation for an owner of this ward, under an id\",{required:[\"id\"]}),disown:en(\"an owner no more\",{required:[\"id\"]}),become:L(\"this ward born again of the class of a kind, her cells and relations kept\",{required:[\"class\"]}),hold:L(\"an owner invitation on a far being, held under a name from now on\",{required:[\"name\",\"invitation\"]}),pilot:L(\"the far being held under a name, asked as its owner\",{required:[\"name\"]}),drop:L(\"the far being held under a name, let go\",{required:[\"name\"]})};steward;constructor(t){super(t),this.steward=t.steward}static fulfils(t){return typeof t==\"function\"&&t.prototype instanceof this}become(t){if(!st(t.class))return{error:\"class is text\"};let e=this.steward.become(t.class);return e===null?{became:t.class}:{error:e}}describe(t){let{asks:e}=super.describe(t);return{asks:e,notes:Te(t,this.notes(t))?{pk:this.steward.pk(),class:Zt(this.constructor),beings:this.steward.beings()}:{}}}async own(t){return st(t.id)?await this.stance.occupants.invite(t.id,{owner:!0})??{error:\"id taken\"}:{error:\"id is text\"}}disown(t){return!st(t.id)||this.stance.occupants.notes(t.id)?.owner!==!0?{error:\"no such owner\"}:(this.stance.occupants.remove(t.id),{disowned:t.id})}async boot(t){if(!st(t.key)||!st(t.class))return{error:\"key and class are text\"};if(er(this.steward.classOf(t.class)))return{error:\"no such class\"};let e=await this.steward.boot(t.key,t.class);return e===\"booted\"?{booted:t.key}:{error:e}}unboot(t){return st(t.being)&&this.steward.unboot(t.being)?{unbooted:t.being}:{error:\"no such being\"}}public(t){return t.key!==null&&!st(t.key)?{error:\"key is text or null\"}:this.steward.publish(t.key)?{public:t.key}:{error:\"no such being\"}}async invite(t){return!st(t.being)||!st(t.id)||t.notes!==void 0&&!ei(t.notes)?{error:\"being and id are text, notes an object\"}:await this.steward.invite(t.being,t.id,t.notes??{})??{error:\"not invited\"}}async ask(t){if(t.being!==void 0&&!st(t.being)||t.method!==void 0&&!st(t.method)||t.args!==void 0&&!ei(t.args))return{error:\"being and method are text, args an object\"};let e=await this.steward.ask(t.being??null,t.method,t.args??{});return St(e)?{error:\"silence\"}:wt(e)?{error:de(e)}:{answer:e}}async hold(t){if(!st(t.name))return{error:\"name is text\"};let e=kt(t.invitation);return e===null?{error:\"no invitation\"}:this.stance.standings.get(tn+t.name)?{error:`${t.name} is held`}:await this.stance.standings.take(tn+t.name,e)===null?{error:\"not taken\"}:{held:t.name,ward:e.ward}}async pilot(t){if(!st(t.name)||t.method!==void 0&&!st(t.method)||t.args!==void 0&&!ei(t.args))return{error:\"name and method are text, args an object\"};let e=this.stance.standings.get(tn+t.name);if(!e)return{error:`${t.name} is not held`};let n=await e.ask(t.method,t.args??{});return St(n)?{error:\"silence\"}:wt(n)?{error:de(n)}:{answer:n}}drop(t){return st(t.name)?this.stance.standings.remove(tn+t.name)?{dropped:t.name}:{error:`${t.name} is not held`}:{error:\"name is text\"}}};var Re=\"dock\",va=r=>typeof r.offer==\"function\",ri=class extends pe{steward;constructor(t,e,n,o){super(t,D,e,o),this.steward=n}},rn=class r{key;partition;door;clock;#t;#e=new Map;#r=new Map;#n=new Set;#o=null;constructor(t,e){this.#t=t,this.key=e,this.clock=t.clock,this.partition=new Jr(t.memory),this.door=new Vr(e,new fo(this.partition),this,t.entropy.drawer)}static async unpack(t){let e=new r(t,await Be.from(t.seed));return e.partition.being(D)||(e.partition.beings[D]={class:e.#l.genesis,cells:{},occupants:{},standings:{}},e.partition.told(D),e.partition.toldHead()),e}async standWard(){if(this.#e.has(D))return;let t=this.partition.being(D),e=new ri(this,t,this.#x,this.#t.carries??{}),n=this.#c(t.class,t.registry),o;if(typeof n==\"string\")this.#o=n;else try{o=new n(e)}catch(i){this.#o=`${t.class} threw at birth: ${i instanceof Error?i.message:String(i)}`}if(!o){let{fallback:i}=this.#l;if(!i)throw new Error(this.#o);o=new i(e)}this.#e.set(D,{being:o,row:t,stance:e});let{dock:s}=this.#t;if(s&&!Object.hasOwn(t.standings,Re)&&await e.standings.take(Re,s)!==null&&!await this.partition.kept())throw new Error(\"the standing on the dock was not kept\")}stand(t){if(this.#e.has(t))return\"stands\";let e=t===D||!this.#t.stands?void 0:this.partition.being(t);if(!e)return\"no such being\";let n=this.#s(e);return n?this.#g(t,e,n)?\"booted\":\"threw at birth\":\"no such class\"}make(t,e){return this.#y(t,e)}#s(t){return this.#t.classes.classOf(t.class,t.registry)}get pk(){return this.key.pk}get draw(){return this.#t.entropy.drawer}get ward(){return this.#e.get(D).being}get fault(){return this.#o}get#l(){return this.#t.ward}#c(t,e){let n=this.#t.classes.classOf(t,e);return n?this.#l.fits(n)?n:`${t} is no ${this.#l.contract}`:`no class of kind ${t} runs`}#i(){let t=this.#e.get(D);if(!t)return;let e=this.#c(t.row.class,t.row.registry);if(typeof e==\"string\"){Gt(t.being.constructor)!==t.row.class&&(this.#o=e);return}if(t.being.constructor!==e)try{t.being=new e(t.stance),this.#o=null}catch(n){this.#o=`${t.row.class} threw at birth: ${n instanceof Error?n.message:String(n)}`}}being(t){return this.#e.get(t)?.being}renew(){this.#i();for(let[t,e]of this.#e){if(t===D)continue;let n=this.#s(e.row);if(!(!n||e.being.constructor===n))try{e.being=new n(e.stance)}catch{continue}}}async root(t,e={}){return this.#h(Object.keys(this.partition.beings),()=>this.#f(D,{id:Bt},t,e))}async#h(t,e){let n=t.flatMap(s=>{let i=this.partition.being(s);return i?[[s,i.cells,JSON.stringify(i.cells)]]:[]}),o=await e();if(await this.partition.kept())return o;for(let[s,i,c]of n)if(JSON.stringify(i)!==c){for(let a of Object.keys(i))delete i[a];for(let[a,l]of Object.entries(JSON.parse(c)))Object.defineProperty(i,a,{value:l,enumerable:!0,writable:!0,configurable:!0});this.partition.told(s)}return ht}get zero(){let t=this.partition.head.public;return t!==null&&this.#u(t)}#u(t){if(this.#e.has(t))return!0;let e=t===D||this.#t.stands?void 0:this.partition.being(t);return e!==void 0&&this.#s(e)!==void 0}async answer(t,e){let n=t===null?void 0:this.partition.head.bind[t],o=t===null?this.partition.head.public:n?.being,s=n?{id:n.id}:{},i=e.args===void 0?{}:br(e.args,_t+1);if(o==null||typeof i!=\"object\"||i===null||Array.isArray(i))return{silence:!0};let c=null,a=await this.#h([o],()=>this.#a(o,ht,async u=>{let f=await this.#p(u,s,e.method,i);return e.method!==void 0&&!St(f)&&!wt(f)&&u.describe&&(c=await Ur(u.describe(s))),f})),l=St(a)||wt(a)?void 0:ie(a,_t);return l===void 0?{silence:!0}:{object:l,seen:c}}#f(t,e,n,o){return this.#a(t,ht,s=>this.#p(s,e,n,o))}async#p(t,e,n,o){let s;try{s=await t.answer(e,n,o)}catch{return ht}return s===void 0||wt(s)?ht:s}async#a(t,e,n){let o=this.#e.get(t);if(o)return n(o.being);let s=this.#w(t);if(!s)return e;try{return await n(s.being)}finally{s.asks-=1,s.asks===0&&this.#r.get(t)===s&&this.#r.delete(t)}}#w(t){let e=this.#r.get(t);if(e)return e.asks+=1,e;let n=t===D||this.#t.stands?void 0:this.partition.being(t),o=n&&this.#s(n);if(!n||!o)return;let s=new pe(this,t,n,this.#t.carries??{});try{let i={being:new o(s),row:n,stance:s,asks:1};return this.#r.set(t,i),i}catch{return}}#d(t){let e=this.#e.get(t)??this.#r.get(t);if(e)return e.stance;let n=t===D?void 0:this.partition.being(t);return n?new pe(this,t,n,this.#t.carries??{}):void 0}async send(t,e){return t===this.pk?(await this.door.arrive(e)).bytes:this.#t.carrier.carry(t,e)}async offer(t){let e=this.#e.get(D);if(va(e.being))return e.being.offer(t);let n=await e.stance.standings.get(Re)?.ask(\"lend\",{contract:t});return kt(n?.invitation)}async retract(t,e){let n=this.#e.get(D);if(va(n.being))return n.being.withdraw(t,e);await n.stance.standings.get(Re)?.ask(\"retract\",{contract:t,heir:e})}reach(){return this.#t.routes?.reach()??[]}learn(t,e){return this.#t.routes?.learn(t,e)??Promise.resolve()}live(t,e){return this.partition.being(t)===e}async boot(t,e,n,o){if(await this.#y(n,e)!==\"booted\")return null;if(o===void 0)return n;let s=await this.#d(n).occupants.invite(t);return(s?await this.#d(t)?.standings.take(o,s):null)?n:(this.#b(n),null)}async#y(t,e,n){if(t===\"\"||t===D||this.partition.being(t)||this.#n.has(t))return\"key taken\";let o=this.#t.classes.classOf(e,n);if(!o||yt.fulfils(o)||G.fulfils(o)!==(this.#t.stands===!0))return\"no such class\";this.#n.add(t);try{let s={class:e,...n===void 0?{}:{registry:n},cells:{},occupants:{},standings:{}};return this.partition.beings[t]=s,(this.#t.stands?this.#g(t,s,o):this.#m(t,s,o)!==void 0)?(this.partition.told(t),\"booted\"):(delete this.partition.beings[t],\"threw at birth\")}finally{this.#n.delete(t)}}#m(t,e,n){try{return new n(new pe(this,t,e,this.#t.carries??{}))}catch{return}}#g(t,e,n){let o=new pe(this,t,e,this.#t.carries??{});try{return this.#e.set(t,{being:new n(o),row:e,stance:o}),!0}catch{return this.#e.delete(t),!1}}#b(t){let e=t===D?void 0:this.partition.being(t);if(!e)return!1;for(let{heir:n}of Object.values(e.occupants))this.door.remove(n),delete this.partition.head.bind[n];return this.partition.head.public===t&&(this.partition.head.public=null),delete this.partition.beings[t],this.#e.delete(t),this.partition.toldHead(),this.partition.told(t),!0}#x={pk:()=>this.pk,classOf:(t,e)=>this.#t.classes.classOf(t,e),beings:()=>{let t={};for(let[e,n]of Object.entries(this.partition.beings))e!==D&&(t[e]={class:n.class,...n.registry===void 0?{}:{registry:n.registry},public:this.partition.head.public===e,absent:!this.#u(e)});return t},boot:(t,e,n)=>this.#y(t,e,n),stand:t=>this.stand(t),unboot:t=>this.#b(t),publish:t=>t!==null&&(t===D||!this.partition.being(t))?!1:(this.partition.head.public=t,this.partition.toldHead(),!0),invite:(t,e,n)=>{let o=t===D||!this.#u(t)?void 0:this.#d(t);return o?o.occupants.invite(e,n):Promise.resolve(null)},ask:(t,e,n)=>{let o=t??this.partition.head.public;return o===null||o===D?Promise.resolve(pt(\"unreached\")):this.#f(o,t===null?{}:{id:Bt},e,n)},become:(t,e)=>{let n=this.#c(t,e);if(typeof n==\"string\")return n;let o=this.#e.get(D);try{o.being=new n(o.stance)}catch{return`${t} threw at birth`}return o.row.class=t,e===void 0?delete o.row.registry:o.row.registry=e,this.partition.told(D),this.#o=null,null}}};var ff=r=>`${r.split(\".\").slice(0,2).join(\".\")}.`,po=\"org.nervur.registry\",Mt=class extends G{static kind=po;static{U(this)}},ar=r=>typeof r==\"function\"&&r.prototype instanceof Mt,Ut=class r{#t=new Map;#e=new Map;constructor(t,e){let n=new Map,o=new Map,s=(i,c)=>{if(this.#t.has(c)&&this.#t.get(c)!==i)throw new Error(`two classes are of kind ${c}`);this.#t.set(c,i)};for(let i of t)s(i,Zt(i));for(let i of e){if(!Yn(i.module)||i.module.startsWith(Xn))throw new Error(`module ${String(i.module)} is no name a module may take`);if(this.#e.has(i.module))throw new Error(`two modules are named ${i.module}`);if(typeof i.version!=\"string\"||i.version===\"\")throw new Error(`module ${i.module} declares no version`);let c=[];for(let a of i.classes){if(typeof a!=\"function\")throw new Error(`module ${i.module} holds something that is no class`);let l=Zt(a);if(!l.startsWith(ff(i.module)))throw new Error(`kind ${l} is outside module ${i.module}`);let u=o.get(l);if(u!==void 0&&u!==i.module)throw new Error(`kind ${l} is in modules ${u} and ${i.module}`);o.set(l,i.module),s(a,l),c.push(l);for(let f=Object.getPrototypeOf(a);typeof f==\"function\";f=Object.getPrototypeOf(f))if(Gt(f)?.startsWith(Xn)&&!er(f))throw new Error(`kind ${Gt(f)} is the kit's`);if(G.fulfils(a))for(let f=Object.getPrototypeOf(a);f!==G;f=Object.getPrototypeOf(f)){let h=Zt(f);if(!er(f)){if(n.has(h)&&n.get(h)!==f)throw new Error(`two contracts are of kind ${h}`);n.set(h,f)}}}this.#e.set(i.module,c)}for(let i of n.keys())if(this.#t.has(i))throw new Error(`kind ${i} is a class and a contract`)}static refusal(t,e){try{let n=new r(t,e);return null}catch(n){return n.message}}classOf(t){return this.#t.get(t)}kindsOf(t){return[...this.#e.get(t)??[]]}};var Qt=\"catalogue\",on=\"modules/\",wo=\".js\",ni=r=>`${on}${r}${wo}`,df={name:\"nervur\",email:\"catalogue@nervur.org\"},lr=r=>typeof r==\"string\",hf=r=>`${r.split(\".\").slice(0,2).join(\".\")}.`,nn=r=>r instanceof Error?r.message:String(r),ut=class extends Mt{static kind=\"org.nervur.catalogue\";static{U(this)}static asks={add:L(\"a module committed on live, and live moved to it\",{required:[\"source\"]}),remove:L(\"a module committed away, and live moved\",{required:[\"module\"]}),live:L(\"live moved to a commit, or the commit that stands\"),log:L(\"the commits from live back\"),origin:L(\"where fetch reads\",{required:[\"url\"]}),fetch:L(\"every ref of origin and all it reaches, kept\"),modules:L(\"the modules live runs\"),sources:L(\"the source of each module file live holds, by its blob\"),gc:L(\"every object neither live nor a fetched ref reaches, forgotten\")};#t;#e;#r=new Map;#n=new Map;#o=null;#s=Promise.resolve();constructor(t){super(t);let{ground:e}=t;if(!e)throw new Error(\"the catalogue stands in the box ward alone\");this.#t=e,this.#e=new Ut(e.kit,[])}classOf(t){return this.#e.classOf(t)}#l(t){return Ut.refusal(this.#t.kit,t)}get#c(){return Vt(this.cells.live)?this.cells.live:void 0}get#i(){return this.cells.refs??{}}#h(){return{...df,seconds:Math.floor(this.#t.terrain.clock.now()/1e3),zone:\"+0000\"}}#u(t){let e=this.#s.then(t,t);return this.#s=e.catch(()=>{}),e}async#f(t,e,n){let o=e.size===0?(await t.put([qr([])]))[0]:await Bs(t,e),s=this.#h();return Ss(t,{tree:o,parents:this.#c?[this.#c]:[],author:s,committer:s,message:`${n}\n`})}async#p(t,e=this.#t.dna){let n=[];for(let[o,s]of await eo(e,t)){if(!o.startsWith(on)||!o.endsWith(wo)||o.slice(on.length).includes(\"/\"))continue;let i=o.slice(on.length,-wo.length),c;try{let a=await e.get(s);if(!a)throw new Error(`blob ${s} is not kept`);if(c=await this.#t.terrain.loader.load(Yt(a.body),s),c.module!==i)throw new Error(`${o} declares module ${c.module}`)}catch(a){c=a instanceof Error?a:new Error(String(a))}n.push({name:i,blob:s,loaded:c})}return n}async wake(){this.#c||(this.cells.live=await this.#f(this.#t.dna,new Map,\"genesis\"),await this.#t.keep());let t=new Map;try{for(let{name:e,blob:n,loaded:o}of await this.#p(this.#c)){let s=o instanceof Error?o.message:this.#l([...[...t.values()].map(i=>i.module),o]);s===null?t.set(e,{module:o,blob:n}):this.#n.set(e,{blob:n,reason:s})}}catch(e){this.#o=nn(e)}this.#r=t,this.#e=new Ut(this.#t.kit,[...t.values()].map(e=>e.module))}async#a(t,e){let n;try{n=await this.#p(t,e)}catch(c){return nn(c)}let o=n.find(c=>c.loaded instanceof Error);if(o)return`${o.name}: ${o.loaded.message}`;let s=n.map(c=>c.loaded),i=this.#l(s);return i!==null?i:(await e?.flush(),this.#e=new Ut(this.#t.kit,s),this.#r=new Map(n.map(c=>[c.name,{module:c.loaded,blob:c.blob}])),this.#n=new Map,this.#o=null,this.cells.live=t,await this.#t.ran(),null)}async#w(){return this.#c?eo(this.#t.dna,this.#c):new Map}add(t){return this.#u(()=>this.#d(t))}async#d(t){if(!lr(t.source))return{error:\"source is text\"};if(t.name!==void 0&&!lr(t.name))return{error:\"name is text\"};let e=new or(this.#t.dna),[n]=await e.put([Hr(t.source)]),o;try{o=await this.#t.terrain.loader.load(t.source,n)}catch(a){return{error:nn(a)}}if(t.name!==void 0&&t.name!==o.module)return{error:`the source is module ${o.module}, not ${t.name}`};let s=await this.#w();s.set(ni(o.module),n);let i=await this.#f(e,s,`add ${o.module} ${o.version}`),c=await this.#a(i,e);return c!==null?{error:c}:{added:o.module,version:o.version,live:i}}remove(t){return this.#u(()=>this.#y(t))}async#y(t){let e=t.module,n=await this.#w();if(!lr(e)||!n.has(ni(e)))return{error:\"no such module\"};if(this.#t.stands(this.#m(e)))return{error:\"a being stands on this module\"};n.delete(ni(e));let o=new or(this.#t.dna),s=await this.#f(o,n,`remove ${e}`),i=await this.#a(s,o);return i!==null?{error:i}:{removed:e,live:s}}#m(t){if(this.#r.has(t))return this.#e.kindsOf(t);let e=hf(t);return this.#t.kept().filter(n=>n.startsWith(e)&&this.#e.classOf(n)===void 0)}live(t){return t.commit===void 0?Promise.resolve({live:this.#c??null}):this.#u(()=>this.#g(t))}async#g(t){let e=t.commit,n=lr(e)&&Object.hasOwn(this.#i,e)?this.#i[e]:e;if(!Vt(n))return{error:\"commit is a commit id or a fetched ref\"};let o=await this.#a(n);return o===null?{live:n}:{error:o}}async log(t){let e=t.commit??this.#c;if(!Vt(e))return{error:\"commit is a commit id\"};let n=[];try{for(let o=e;o!==void 0;){let s=await this.#t.dna.get(o);if(!s)break;let i=he(s);n.push({commit:o,parents:[...i.parents],message:i.message.replace(/\\n$/,\"\"),seconds:i.committer.seconds}),o=i.parents[0]}}catch(o){return{error:nn(o)}}return{log:n}}origin(t){let e=t.url;return e===null?(delete this.cells.origin,{origin:null}):!lr(e)||!/^https?:\\/\\/[^/\\s]+/.test(e)?{error:\"url is an http or https URL, or null\"}:(this.cells.origin=e,{origin:e})}fetch(){return this.#u(()=>this.#b())}async#b(){let t=this.cells.origin;if(!lr(t))return{error:\"no origin is set\"};try{let e=await Rs(t),n=s=>this.#t.dna.get(s),o=await Is(t,Object.values(e),n,await js(this.#x(),n));return await this.#t.dna.put([...o.values()]),this.cells.refs=e,{refs:e,objects:o.size}}catch(e){return{error:nn(e)}}}#x(){return[...new Set([...this.#c?[this.#c]:[],...Object.values(this.#i)])]}gc(){return this.#u(async()=>{if(!await this.#t.keep())throw new Error(\"her cells were not kept\");let t=this.#t.dna,e=new Set;for(let n of this.#x()){let o=n;for(let s=await t.get(o);s?.type===\"tag\";s=await t.get(o))e.add(o),o=/^object ([0-9a-f]{40})$/m.exec(Yt(s.body))?.[1]??\"\";for(let s of await Ts(t,o))e.add(s)}return{collected:await t.collect(e),kept:e.size}})}async sources(){let t=[];for(let[e,n]of await this.#w()){if(!e.startsWith(on)||!e.endsWith(wo))continue;let o=await this.#t.dna.get(n);o&&t.push({blob:n,source:Yt(o.body)})}return{live:this.#c??null,sources:t}}modules(){let t={};for(let[e,n]of this.#r)t[e]={running:n.module.version,blob:n.blob};for(let[e,n]of this.#n)t[e]={running:null,blob:n.blob,failed:n.reason};return{live:this.#c??null,modules:t,...this.#o===null?{}:{failed:this.#o}}}};var sn,yo=12,Aa=2,_e=class{static prefix=_(I(\"catalogue\"));#t;#e;#r=new Map;#n;constructor(t,e){this.#t=t,this.#e=e}static occupies(t){return t.length===sn.prefix.length+Aa&&t.startsWith(sn.prefix)}#o(){return this.#n??=this.#e.derive([\"seal\",\"dna\"],32)}async#s(t){let e=_(await this.#e.derive([\"dna\",t],16));return{place:sn.prefix+e.slice(0,Aa),name:e}}async get(t){let e=this.#r.get(t);if(e)return e;let{place:n,name:o}=await this.#s(t),s=(await this.#t.read(n)).get(o);if(!s||s.length<=yo)return null;let i=await qt(await this.#o(),s.subarray(0,yo),I(o),s.subarray(yo));if(i===null)return null;let c=await Es(i);return await Ft(c)!==t?null:(this.#r.set(t,c),c)}async put(t){let e=[],n=new Map,o=new Map;for(let s of t){let i=await Ft(s);if(e.push(i),this.#r.has(i)||o.has(i))continue;let{place:c,name:a}=await this.#s(i),l=this.#e.entropy.draw(yo),u=C(l,await Dt(await this.#o(),l,I(a),await xs(s)));n.has(c)||n.set(c,new Map),n.get(c).set(a,u),o.set(i,s)}for(let[s,i]of n)await this.#t.write(s,i);for(let[s,i]of o)this.#r.set(s,i);return e}async#l(){return(await this.#t.places()).filter(t=>sn.occupies(t))}async count(){let t=0;for(let e of await this.#l())t+=(await this.#t.read(e)).size;return t}async collect(t){let e=new Set(t),n=new Set;for(let s of e)n.add((await this.#s(s)).name);let o=0;for(let s of await this.#l()){let i=new Map;for(let c of(await this.#t.read(s)).keys())n.has(c)||i.set(c,null);i.size!==0&&(await this.#t.write(s,i),o+=i.size)}for(let s of[...this.#r.keys()])e.has(s)||this.#r.delete(s);return o}};sn=_e;var ur=\"org.nervur.memory\",Ot=class extends G{static kind=ur;static{U(this)}occupies(t){return!1}};var It=\"box\",vt=r=>typeof r==\"string\",oi=r=>Array.isArray(r)&&r.length>0&&Gr(r).length===r.length,Ba=(r,t)=>t?.hosted===!0,pf=r=>r===ut||typeof r==\"function\"&&r.prototype instanceof ut,mo=r=>yt.fulfils(r)&&!jt.fulfils(r),jt=class extends yt{static kind=\"org.nervur.dock\";static{U(this)}static cells={hosted:[],routes:{},reach:[]};static asks={...yt.asks,stand:L(\"every faculty and hosted ward that does not stand yet, stood; silence where everything stands\"),open:L(\"a faculty of this harbor\",{required:[\"key\",\"class\"]}),host:L(\"a ward this harbor hosts, kept by the root memory or by the memory faculty named\",{required:[\"ward\"]}),move:L(\"a hosted ward carried to a memory faculty, or to the root memory with null\",{required:[\"ward\",\"memory\"]}),hold:L(\"an owner invitation on a far being, held under a name from now on, at the address named\",{required:[\"name\",\"invitation\"]}),route:L(\"where a ward is reached, addresses in order, or null\",{required:[\"ward\",\"at\"]}),reach:L(\"where this harbor is reached, the addresses every invitation carries\",{required:[\"at\"]}),sweep:en(\"every place of the memory this harbor does not name, gone\"),heard:L(\"a push heard, told to every carrier, so one that collects for this harbor collects\"),lend:{description:\"an offer from a faculty fulfilling a contract\",input:{type:\"object\",required:[\"contract\"]},for:Ba},retract:{description:\"an offer that was not taken\",input:{type:\"object\",required:[\"contract\",\"heir\"]},for:Ba}};#t;constructor(t){super(t),this.#t=t.ground}async stand(){let t=[...await this.#e(ar),...await this.#e(n=>n.prototype instanceof Ot),...await this.#e(()=>!0)];for(let[n,o]of Object.entries(this.routes))this.#t.reached(n,o);let e=[];for(let n of this.hosted)await this.#t.stand(n)&&e.push(n.ward);return t.length+e.length>0?{stood:t,wards:e}:void 0}async#e(t){let e=[];for(let n=!0;n;){n=!1;for(let[o,s]of Object.entries(this.steward.beings())){let i=s.absent?this.steward.classOf(s.class,s.registry):void 0;!i||!t(i)||this.steward.stand(o)!==\"booted\"||(n=!0,e.push(o),await this.#t.rouse(o))}}return e}describe(t){let e=super.describe(t);if(!Te(t,this.notes(t)))return e;let n=e.notes;return n.wards=Object.fromEntries(this.hosted.map(({ward:o,memory:s,registry:i})=>[o,{...s===void 0?{}:{memory:s},...i===void 0?{}:{registry:i}}])),n.routes=this.routes,n.reach=this.addresses,n.failed=this.#t.failures(),n.listening=this.#t.listening(),this.#t.foreground&&(n.foreground=!0),e}async heard(){return await this.#t.heard(),{heard:!0}}get hosted(){return this.cells.hosted.map(({ward:t,seed:e,memory:n,registry:o})=>({ward:t,seed:e,...n===void 0?{}:{memory:n},...o===void 0?{}:{registry:o}}))}#r(t){return vt(t)&&this.#o(ur).includes(t)}#n(t){if(t==null||t===Qt)return{registry:void 0};if(!vt(t))return null;let e=this.steward.beings()[t],n=e&&!e.absent?this.steward.classOf(e.class,e.registry):void 0;return ar(n)?{registry:t}:null}get routes(){return Object.fromEntries(Object.entries(this.cells.routes).map(([t,e])=>[t,[...e]]))}get addresses(){return[...this.cells.reach]}route(t){let{ward:e}=t,n=typeof t.at==\"string\"?[t.at]:t.at;if(!vt(e)||n!==null&&!oi(n)||!this.#t.route(e,n))return{error:\"not routed\"};let o=this.cells.routes;return n===null?delete o[e]:o[e]=[...n],{routed:e}}reach(t){return oi(t.at)?(this.cells.reach=[...t.at],{reach:[...t.at]}):{error:\"at is a list of addresses\"}}async hold(t){if(t.at!==void 0){if(!oi([t.at]))return{error:\"at is an address\"};let e=kt(t.invitation)?.ward;if(e===void 0)return{error:\"no invitation\"};let n=this.route({ward:e,at:[t.at]});if(n.error!==void 0)return n}return super.hold(t)}async learn(t,e){let n=this.cells.routes;Object.hasOwn(n,t)||!this.#t.route(t,e)||(n[t]=[...e],await this.#t.keep())}become(t){if(!vt(t.class))return{error:\"class is text\"};let e=this.#n(t.registry);if(e===null)return{error:\"no such registry faculty\"};let{registry:n}=e;if(n!==void 0&&this.steward.beings()[n].registry!==void 0)return{error:\"the dock stands through the catalogue or a registry it stands\"};let o=this.steward.become(t.class,n);return o===null?{became:t.class}:{error:o}}boot(){return Promise.resolve({error:\"a faculty is opened, and nothing else stands in the box ward\"})}async unboot(t){return this.hosted.some(e=>e.memory!==void 0&&e.memory===t.being)?{error:\"a ward is kept by this memory faculty\"}:(typeof t.being==\"string\"&&await this.#t.lull(t.being),super.unboot(t))}async open(t){if(!vt(t.key)||!vt(t.class))return{error:\"key and class are text\"};let e=this.#n(t.registry);if(e===null)return{error:\"no such registry faculty\"};let{registry:n}=e,o=this.steward.classOf(t.class,n);if(!G.fulfils(o)||pf(o))return{error:\"no such faculty\"};if(await this.steward.boot(t.key,t.class,n)!==\"booted\")return{error:\"not opened\"};let s=await this.steward.invite(t.key,D,{});return s===null||await this.stance.standings.take(t.key,s)===null?(this.steward.unboot(t.key),{error:\"not opened\"}):(await this.#t.awaken(t.key),{opened:t.key})}async sweep(){return{swept:await this.#t.sweep()}}async host(t){let e=t.ward;if(!vt(e))return{error:\"ward is text\"};if(e===It)return{error:\"box is the box ward\"};if(this.hosted.some(l=>l.ward===e))return{error:`${e} is hosted already`};if(t.seed!==void 0&&!vt(t.seed))return{error:\"seed is text\"};let n=t.memory??void 0;if(n!==void 0&&!this.#r(n))return{error:\"no such memory faculty\"};let o=this.#n(t.registry);if(o===null)return{error:\"no such registry faculty\"};let{registry:s}=o,i=t.class??void 0;if(i!==void 0&&(!vt(i)||!mo(this.steward.classOf(i,s))))return{error:\"no such ward class\"};let c=await this.stance.occupants.invite(e,{hosted:!0});if(c===null)return{error:\"not hosted\"};let a=await this.#t.host(e,c,t.seed,n,i,s);return a===null?(this.stance.occupants.remove(e),{error:\"not hosted\"}):(this.cells.hosted.push({ward:e,seed:a,...n===void 0?{}:{memory:n},...s===void 0?{}:{registry:s}}),{hosted:e})}async move(t){let n=this.cells.hosted.find(a=>a.ward===t.ward);if(!n)return{error:\"no such ward\"};let o=t.memory??void 0;if(o!==void 0&&!this.#r(o))return{error:\"no such memory faculty\"};let s=n.memory;if(s===o)return{error:`${n.ward} is kept there already`};let i=await this.#t.move(n.ward,n.seed,s,o);if(i!==null)return{error:i};let c=a=>{a===void 0?delete n.memory:n.memory=a};return c(o),await this.#t.keep()?(await this.#t.release(n.ward,s),{moved:n.ward,memory:o??null}):(c(s),await this.#t.move(n.ward,n.seed,o,s),{error:\"not kept\"})}async lend(t){if(!vt(t.contract))return{error:\"contract is text\"};let e=await this.offer(t.contract);return e?{invitation:e}:{error:\"nothing lent\"}}async retract(t){return!vt(t.contract)||!vt(t.heir)?{error:\"contract and heir are text\"}:(await this.withdraw(t.contract,t.heir),{retracted:t.heir})}async offer(t){for(let e of this.#o(t)){let n=await this.stance.standings.get(e)?.ask(\"offer\"),o=kt(n?.invitation);if(o)return o}return null}async withdraw(t,e){for(let n of this.#o(t))await this.stance.standings.get(n)?.ask(\"retract\",{heir:e})}#o(t){let e=this.steward.beings();return this.stance.standings.ids().filter(n=>{let o=e[n],s=o&&!o.absent?this.steward.classOf(o.class,o.registry):void 0;return G.fulfils(s)&&G.contracts(s).includes(t)})}};var $t=r=>{let{ground:t}=r;if(!t)throw new Error(\"a kit faculty stands in the box ward alone\");return t},mt=Symbol(\"undialed\"),ft=class extends G{static kind=\"org.nervur.carrier\";static{U(this)}static carries=null;listening(){return[]}relays(t){return!1}relay(t,e){return Promise.resolve(null)}heard(){return Promise.resolve()}awake(){return Promise.resolve()}sleep(){return Promise.resolve()}},si=(r,t,e)=>{let n=t.filter(i=>i.prototype instanceof ft&&i.carries===e),o=Object.entries(r).find(([,i])=>n.some(c=>c.kind===i.class));if(o)return{key:o[0]};let s=n[0];return s?{key:e,open:{method:\"open\",args:{key:e,class:s.kind}}}:null};var ai=async(r,t)=>{let e=await r.places();for(let n of e)await t.write(n,await r.read(n));return e},li=r=>{if(typeof r!=\"object\"||r===null)return null;let{seed:t,places:e}=r;if(t!==void 0&&!K(t,32)||typeof e!=\"object\"||e===null||Array.isArray(e))return null;for(let n of Object.values(e)){if(typeof n!=\"object\"||n===null||Array.isArray(n))return null;for(let o of Object.values(n))if(!K(o))return null}return{...t===void 0?{}:{seed:t},places:e}};var ui=async(r,t)=>{for(let[e,n]of Object.entries(t.places))await r.write(e,new Map(Object.entries(n).map(([o,s])=>[o,$(s)])));return Object.keys(t.places)},go=12,wf=I(\"nervur-package\"),ii=class{rows;#t;#e=new Set;#r=Promise.resolve(!0);constructor(t,e){this.#t=t,this.rows=e}told(t){this.#e.add(t)}kept(){let t=[...this.#e];return this.#e.clear(),this.#r=this.#r.then(()=>this.#n(t)).catch(()=>!1),this.#r}async#n(t){if(t.length===0)return!0;let e=this.rows.beings??{},n=new Map;for(let o of t){let s=o===Qr?this.rows.ward??null:Object.hasOwn(e,o)?e[o]:void 0;n.set(await this.#t.entry(o),s===void 0?null:await this.#t.seal(o,s))}return await this.#t.write(n),!0}},ci=class{#t;#e;#r;#n;place;constructor(t,e,n,o,s){this.#t=t,this.#e=e,this.#r=n,this.place=o,this.#n=s}read(){return this.#n.read(this.place)}entry(t){return this.#t.derive([\"entry\",this.#e,t],16).then(_)}async seal(t,e){let n=this.#t.entropy.draw(go),o=I(JSON.stringify({row:t,value:e}));return C(n,await Dt(this.#r,n,I(await this.entry(t)),o))}async open(t,e){let n=e.length>go?await qt(this.#r,e.subarray(0,go),I(t),e.subarray(go)):null;if(n===null)throw new Error(\"an entry the package did not seal\");return JSON.parse(new TextDecoder().decode(n))}write(t){return this.#n.write(this.place,t)}},cn=class r{memory;entropy;#t;constructor(t,e,n){this.memory=t,this.entropy=e,this.#t=n}static async open(t,e,n){return new r(t,e,await dt(n,wf,32))}derive(t,e){return dt(this.#t,I(JSON.stringify(t)),e)}place(t){return this.derive([\"place\",t],16).then(_)}async rows(t,e=this.memory){let n=new ci(this,t,await this.derive([\"seal\",t],32),await this.place(t),e),o={},s={},i=!1;for(let[c,a]of await n.read()){let{row:l,value:u}=await n.open(c,a);i=!0,l===Qr?o.ward=u:s[l]=u}return i&&(o.beings=s),new ii(n,o)}};var bo=[],je=(r,t)=>{bo.some(e=>e.probe.name===r.name)||bo.push({probe:r,defaults:t})},fi=()=>bo.map(r=>r.probe.name).reverse(),an=(r,t=bo)=>{for(let{probe:e,defaults:n}of[...t].reverse())if(e.fits(r))return{ground:e.name,terrain:e.terrain(r,n)};throw new Error(\"no ground fits here\")};var Sa=r=>typeof r==\"object\"&&r!==null&&!Array.isArray(r),ln=r=>{if(!Sa(r))return null;let{ward:t,method:e,args:n}=r;return t!==void 0&&typeof t!=\"string\"||e!==void 0&&typeof e!=\"string\"||n!==void 0&&!Sa(n)?null:{...t===void 0?{}:{ward:t},...e===void 0?{}:{method:e},...n===void 0?{}:{args:n}}};var te=class{tcp=void 0;web=void 0;wakes=!0;get foreground(){return!1}claim(){return Promise.resolve()}stand(t){return Promise.resolve()}release(){return Promise.resolve()}};var yf=({dock:r})=>({genesis:r.kind,contract:\"dock\",fits:t=>jt.fulfils(t),fallback:r}),di=({ward:r},t=r.kind)=>({genesis:t,contract:\"hosted ward\",fits:mo}),ee=class r{#t;#e;#r=new Map;#n={wards:{},routes:{}};#o;#s={carry:(t,e)=>this.#g(t,e)};#l={classOf:(t,e)=>this.#u(t,e)};constructor(t,e){let{dock:n,ward:o,classes:s}=t.defaults;if(!jt.fulfils(n))throw new Error(\"the default dock is no dock\");if(!mo(o))throw new Error(\"the default ward is no hosted ward\");this.#t=t,this.#e=e;let i=new _e(t.memory,e),c=[ut,n,o,...s];this.#o={terrain:t,dna:i,kit:c,foreground:t.foreground,arrive:(a,l)=>this.arrive(a,l),host:(a,l,u,f,h,p)=>this.#b(a,l,u,f,h,p),stand:a=>this.#p(a),move:(a,l,u,f)=>this.#w(a,l,u,f),release:async(a,l)=>this.#d(l).forget(await this.#e.place(a)),route:(a,l)=>this.#x(a,l),reached:(a,l)=>{this.#O(l)||(this.#n.routes[a]=\"no carrier dials it\")},keep:()=>this.#i.partition.kept(),failures:()=>this.#m(),sweep:()=>this.#a(),awaken:async a=>{let l=this.#i.being(a);l instanceof ft&&await l.awake()},rouse:async a=>{t.wakes&&await this.#o.awaken(a)},lull:async a=>{let l=this.#i.being(a);l instanceof ft&&await l.sleep()},listening:()=>this.#E.flatMap(a=>a.listening()),heard:async()=>{await Promise.all(this.#E.map(a=>a.heard()))},ran:()=>{for(let a of this.#r.values())a.renew();return Promise.resolve()},stands:a=>[...this.#r.values()].some(l=>Object.values(l.partition.beings).some(u=>a.includes(u.class))),kept:()=>[...new Set([...this.#r.values()].flatMap(a=>Object.values(a.partition.beings).map(l=>l.class)))]}}static async open(t={}){let e=t instanceof te?t:an(t).terrain;await e.claim();let n;try{n=await r.#c(e)}catch(o){throw await e.release(),o}try{await e.stand(n)}catch(o){throw await n.close(),o}return n}static async#c(t){let e=await t.custody.seed(),n=new r(t,await cn.open(t.memory,t.entropy,e)),o=await n.#v(It,e,{ward:yf(t.defaults),carries:{ground:n.#o},classes:n.#l,stands:!0});if(o.partition.being(Qt))o.stand(Qt);else if(await o.make(Qt,ut.kind)!==\"booted\"||!await o.partition.kept())throw new Error(\"the catalogue did not stand\");let s=o.being(Qt);if(!(s instanceof ut))throw new Error(\"the catalogue did not stand\");await s.wake();for(let[i,c]of Object.entries(o.partition.beings))c.registry===void 0&&ar(s.classOf(c.class))&&o.stand(i);return await o.standWard(),n}async ask(t){let e=ln(t);if(e===null)return{error:\"not a root request\"};let n=e.ward===void 0?this.#i:this.#r.get(e.ward);if(n===void 0){let s=this.#m().wards[e.ward];return s===void 0?{error:\"no such ward\"}:{error:\"the ward did not stand\",reason:s}}let o=await n.root(e.method,e.args);return St(o)?{silence:!0}:wt(o)?{word:de(o)}:{answer:o}}async arrive(t,e){let n=this.#A(t);return n?(await n.door.arrive(e)).bytes:await this.#k(t)?.relay(t,e)??null}holds(t){return this.#A(t)!==void 0}async close(){for(let t of this.#E.reverse())await t.sleep();await this.#t.release()}get#i(){return this.#r.get(It)}get#h(){return this.#i.ward}#u(t,e=Qt){if(t===ut.kind)return ut;let n=this.#r.get(It)?.being(e);return n instanceof Mt?n.classOf(t):void 0}#f(t){return{classOf:e=>this.#u(e,t)}}async#p(t){let e=!this.#r.has(t.ward);try{return e&&await this.#v(t.ward,$(t.seed),{ward:di(this.#t.defaults),classes:this.#f(t.registry)},this.#d(t.memory)),await this.#r.get(t.ward).standWard(),delete this.#n.wards[t.ward],e}catch(n){return this.#r.delete(t.ward),this.#n.wards[t.ward]=n instanceof Error?n.message:String(n),!1}}async#a(){let t=async s=>{let i=this.#h.hosted.filter(c=>c.memory===s).map(c=>c.ward);return new Set(await Promise.all((s===void 0?[It,...i]:i).map(c=>this.#e.place(c))))},e=this.#y(),n=[],o=await t(void 0);for(let s of await this.#t.memory.places())o.has(s)||_e.occupies(s)||e.some(([,i])=>i.occupies(s))||(await this.#t.memory.forget(s),n.push(s));for(let[s,i]of e){let c=await t(s);for(let a of await i.places())c.has(a)||(await i.forget(a),n.push(a))}return n}async#w(t,e,n,o){let s=this.#r.get(t);if(!s)return\"the ward does not stand\";let i=this.#d(n),c=this.#d(o);this.#r.delete(t);try{if(!await s.partition.kept())throw new Error(\"the ward was not kept\");let a=await this.#e.place(t),l=new Map(await i.read(a));for(let h of(await c.read(a)).keys())l.has(h)||l.set(h,null);await c.write(a,l);let u=this.#h.hosted.find(h=>h.ward===t)?.registry;return await(await this.#v(t,$(e),{ward:di(this.#t.defaults),classes:this.#f(u)},c)).standWard(),null}catch(a){return this.#r.set(t,s),a instanceof Error?a.message:String(a)}}#d(t){if(t===void 0)return this.#t.memory;let e=this.#i.being(t);if(e instanceof Ot)return e;throw new Error(`the memory faculty ${t} does not stand`)}#y(){return Object.keys(this.#i.partition.beings).flatMap(t=>{let e=this.#i.being(t);return e instanceof Ot?[[t,e]]:[]})}#m(){let t=this.#i.fault;return{wards:{...this.#n.wards,...t===null?{}:{[It]:t}},routes:{...this.#n.routes}}}async#g(t,e){if(this.holds(t)||this.#k(t))return this.arrive(t,e);let n=this.#h.routes[t];if(n===void 0)return this.#t.carrier.carry(t,e);for(let o of n){let s=this.#E.find(c=>c.accepts(o)),i=s?await s.dial(o,t,e):mt;if(i!==mt)return i}return null}async#b(t,e,n,o,s,i){if(this.#r.has(t))return null;let c=n===void 0?this.#t.entropy.draw(32):K(n,32)?$(n):null;if(c===null||this.holds((await Be.from(c)).pk))return null;let a;try{a=await this.#v(t,c,{dock:e,ward:di(this.#t.defaults,s),classes:this.#f(i)},this.#d(o)),await a.standWard()}catch{return this.#r.delete(t),null}return a.ward.stance.standings.get(Re)?_(c):(this.#r.delete(t),null)}#x(t,e){let n=K(t,64)&&(e===null||this.#O(e));return n&&delete this.#n.routes[t],n}get#E(){return Object.keys(this.#i.partition.beings).map(t=>this.#i.being(t)).filter(t=>t instanceof ft)}#k(t){return this.#E.find(e=>e.relays(t))}#O(t){return t.some(e=>this.#E.some(n=>n.accepts(e)))}async#v(t,e,n,o){let{entropy:s,clock:i}=this.#t,c=await rn.unpack({seed:e,memory:await this.#e.rows(t,o),entropy:s,clock:i,carrier:this.#s,routes:this.#B,...n});return this.#r.set(t,c),c}#B={reach:()=>{if(!this.#r.has(It))return[];let t=this.#h.addresses;return t.length>0?t:this.#E.flatMap(e=>e.listening()).filter(e=>!Ps(e))},learn:(t,e)=>this.holds(t)?Promise.resolve():this.#h.learn(t,e)};#A(t){for(let e of this.#r.values())if(e.pk===t)return e}};var Eo=0,pi=1,xo=2,Ta=1048645,hi=64,wi=(r,t,...e)=>{let n=new Uint8Array(5);return n[0]=r,new DataView(n.buffer).setUint32(1,t>>>0),C(n,...e)},mf=r=>{let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,r.length),C(t,r)},ko=(r,t,e)=>wi(Eo,r,t,e),yi=(r,t)=>wi(pi,r,t),mi=r=>wi(xo,r),gi=(r,t,e)=>mf(ko(r,t,e));var Ra=(r,t)=>r>Ta||r<5||t!==void 0&&(t>xo||t===Eo&&r<5+hi||t===xo&&r!==5),fr=r=>{if(Ra(r.length,r[0]))return null;let t=new DataView(r.buffer,r.byteOffset).getUint32(1);return r[0]===Eo?{kind:\"ask\",id:t,pk:r.slice(5,5+hi),box:r.slice(5+hi)}:r[0]===pi?{kind:\"reply\",id:t,box:r.slice(5)}:{kind:\"nothing\",id:t}},un=class{#t=new Uint8Array(0);#e=!1;get bad(){return this.#e}push(t){if(this.#e)return[];this.#t=this.#t.length===0?t.slice():C(this.#t,t);let e=[];for(;this.#t.length>=4;){let n=new DataView(this.#t.buffer,this.#t.byteOffset).getUint32(0);if(Ra(n,this.#t.length>4?this.#t[4]:void 0))return this.#e=!0,this.#t=new Uint8Array(0),e;if(this.#t.length<4+n)break;let o=fr(this.#t.subarray(4,4+n));this.#t=this.#t.slice(4+n),e.push(o)}return e}};var _a=65,Oo=1048640,gf=4294967295,ja=r=>new Uint8Array(r),bi=class r{#t;#e=new Map;#r=1;constructor(t){this.#t=t,t.binaryType=\"arraybuffer\",t.addEventListener(\"message\",e=>{let n=typeof e.data==\"string\"?null:fr(new Uint8Array(e.data));if(n===null)return this.close();if(n.kind===\"ask\")return;let o=this.#e.get(n.id);this.#e.delete(n.id),o?.(n.kind===\"reply\"?n.box:null)}),t.addEventListener(\"close\",()=>{for(let e of this.#e.values())e(null);this.#e.clear()})}static open(t,e){return new Promise(n=>{let o;try{o=new WebSocket(t,\"quo\")}catch{n(null);return}let s=new r(o);o.addEventListener(\"open\",()=>o.protocol===\"quo\"?n(s):(o.close(),n(null))),o.addEventListener(\"close\",()=>{e(),n(null)}),o.addEventListener(\"error\",()=>n(null))})}ask(t,e){if(this.#t.readyState!==WebSocket.OPEN)return Promise.resolve(null);let n=this.#r;return this.#r=this.#r===gf?1:this.#r+1,new Promise(o=>{this.#e.set(n,o),this.#t.send(ja(ko(n,t,e)))})}close(){this.#t.close()}},Ie=class{#t=new Map;dial(t,e,n){let o=ir(t);return o===null||!K(e,64)?Promise.resolve(mt):o.held?this.#r(o,e,n):this.#e(o,e,n)}async#e(t,e,n){let o;try{o=await fetch(t.href,{method:\"POST\",body:ja(C($(e),n))})}catch{return mt}let s=new Uint8Array(await o.arrayBuffer().catch(()=>new ArrayBuffer(0)));return o.status===200&&s.length>0?s:null}async#r(t,e,n){let o=this.#t.get(t.href);o||(o=bi.open(t.href,()=>this.#t.delete(t.href)),this.#t.set(t.href,o),o.then(i=>i??this.#t.delete(t.href)));let s=await o;return s?s.ask($(e),n):mt}async close(){let t=[...this.#t.values()];this.#t.clear();for(let e of await Promise.all(t))e?.close()}},xi=r=>r.length<_a||r.length>Oo?null:{pk:_(r.subarray(0,64)),box:r.slice(64)};var bf=(r,t)=>t===null?null:r.includes(\"*\")?\"*\":r.includes(t)?t:null,fn=async(r,t,e)=>{let n=new Headers,o=bf(t.origins,e.headers.get(\"origin\"));if(o!==null&&n.set(\"access-control-allow-origin\",o),new URL(e.url).pathname!==t.path)return new Response(null,{status:404,headers:n});if(e.method===\"OPTIONS\")return o!==null&&(n.set(\"access-control-allow-methods\",\"POST\"),n.set(\"access-control-allow-headers\",\"content-type\")),new Response(null,{status:204,headers:n});if(e.method!==\"POST\")return n.set(\"allow\",\"POST, OPTIONS\"),new Response(null,{status:405,headers:n});let s=new Uint8Array(await e.arrayBuffer()),i=s.length>Oo?null:xi(s);if(i===null)return new Response(null,{status:400,headers:n});let c=await r.arrive(i.pk,i.box).catch(()=>null);return c===null||c.length===0?new Response(null,{status:204,headers:n}):(n.set(\"content-type\",\"application/octet-stream\"),new Response(new Uint8Array(c),{status:200,headers:n}))},Ei=(r,t,e)=>{let n=typeof e==\"string\"?null:fr(e);if(n===null)return t.close();n.kind===\"ask\"&&r.arrive(_(n.pk),n.box).catch(()=>null).then(o=>t.send(o===null?mi(n.id):yi(n.id,o)))};var Na=function(r,t){return typeof r==\"string\"&&/^\\.\\.?\\//.test(r)?r.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i,function(e,n,o,s,i){return n?t?\".jsx\":\".js\":o&&(!s||!i)?e:o+s+\".\"+i.toLowerCase()+\"js\"}):r},Nt=class extends qe{draw(t){return globalThis.crypto.getRandomValues(new Uint8Array(t))}},$e=class extends ze{now(){return Date.now()}wait(t){let e;return{done:new Promise(o=>e=setTimeout(o,t)),cancel:()=>clearTimeout(e)}}},Ne=class extends oe{#t;constructor(t){super(),this.#t=t.draw(32)}seed(){return Promise.resolve(this.#t.slice())}},Ia=async r=>{let t=URL.createObjectURL(new Blob([r],{type:\"text/javascript\"}));try{return await import(Na(t))}finally{URL.revokeObjectURL(t)}},$a=r=>import(Na(`data:text/javascript;charset=utf-8,${encodeURIComponent(r)}`)),xf,Ef=()=>xf??=Ia(\"export const probe = 1;\").then(r=>r.probe===1?Ia:$a,()=>$a),re=class extends Ht{async load(t){let e=jo(t),n;try{n=await(await Ef())(e)}catch(o){throw new Error(`the module did not load: ${o instanceof Error?o.message:String(o)}`,{cause:o})}return He(n)}},Le=class extends Ht{#t;#e;constructor(t=[]){super(),this.#t=t}async load(t,e){this.#e??=Promise.all(this.#t.map(async s=>[await Ft(Hr(s.source)),s.module])).then(s=>new Map(s));let n=(await this.#e).get(e);if(n)return He(n);let o=this.#t.map(s=>s.module.module);throw new Error(`redeploy needed: blob ${e} is no module this bundle carries${o.length===0?\", and it carries none\":`: it carries ${o.join(\", \")}`}`)}},De=class extends ne{#t=new Map;read(t){let e=this.#t.get(t)??new Map;return Promise.resolve(new Map([...e].map(([n,o])=>[n,o.slice()])))}write(t,e){let n=this.#t.get(t);n||this.#t.set(t,n=new Map);for(let[o,s]of e)s===null?n.delete(o):n.set(o,s.slice());return n.size===0&&this.#t.delete(t),Promise.resolve()}places(){return Promise.resolve([...this.#t.keys()])}forget(t){return this.#t.delete(t),Promise.resolve()}};var dr=class extends we{carry(){return Promise.resolve(null)}},hr=class extends we{#t;constructor(t){super(),this.#t=t}carry(t,e){return this.#t.carry(t,e)}},Lt=class extends te{entropy;clock;custody;memory;carrier;loader;defaults;tcp;web;wakes;constructor(t){super(),this.entropy=t.entropy??new Nt,this.clock=t.clock??new $e,this.custody=t.custody??new Ne(this.entropy),this.memory=t.memory??new De,this.carrier=t.carrier??new dr,this.loader=t.loader??new re,this.defaults=t.defaults,this.tcp=t.tcp,this.web=t.web,this.wakes=t.wakes??!0}},dn=class r{#t=new Map;#e;cut=new Set;constructor(t){this.#e=t}async harbor(t,e={}){if(this.#t.has(t))throw new Error(`a harbor named ${t} stands`);let n=new Lt({defaults:this.#e,...e,carrier:new hr(this)}),o=await r.#r(n);return this.#t.set(t,{harbor:o,terrain:n}),o}static async#r(t){let e=await ee.open(t);return await e.ask({method:\"stand\"}),e}get(t){let e=this.#t.get(t);if(!e)throw new Error(`no harbor named ${t}`);return e.harbor}async restart(t,e){let n=this.#t.get(t);if(!n)throw new Error(`no harbor named ${t}`);let o=n.terrain,s={entropy:o.entropy,clock:o.clock,custody:o.custody,memory:o.memory,loader:o.loader,defaults:o.defaults,...o.tcp?{tcp:o.tcp}:{},...o.web?{web:o.web}:{}},i=e?new Lt({...s,...e,carrier:o.carrier}):o,c=await r.#r(i);return this.#t.set(t,{harbor:c,terrain:i}),c}carry(t,e){for(let[n,{harbor:o}]of this.#t)if(o.holds(t))return this.cut.has(n)?Promise.resolve(null):o.arrive(t,e);return Promise.resolve(null)}};var vo=\"neutral\",ki={name:vo,fits:()=>!0,terrain:({bundle:r},t)=>new Lt({loader:r?new Le(r):new re,defaults:t})};var kf=function(r,t){return typeof r==\"string\"&&/^\\.\\.?\\//.test(r)?r.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i,function(e,n,o,s,i){return n?t?\".jsx\":\".js\":o&&(!s||!i)?e:o+s+\".\"+i.toLowerCase()+\"js\"}):r},Of=\"edge\",vf=\"m/\",Af=\"c/seed\",Oi=128,Bf=I(\"nervur edge custody\"),Sf=4294967295,Ai=class{#t;#e=new Set;#r=new Set;constructor(t){this.#t=t}run(t,e){return this.#t?this.#t.run(t,e):e()}refused(){let t=this.#t?.getStore();t!==void 0&&this.#e.add(t)}kept(){let t=this.#t?.getStore();t!==void 0&&this.#r.add(t)}again(t){let e=this.#e.delete(t)&&!this.#r.has(t);return this.#r.delete(t),e}},Ao=class extends Ht{#t;#e=new Map;#r=new Map;#n;constructor(t=[],e){super(),this.#t=new Map(t.map(n=>[n.blob,n.module])),this.#n=e}get carried(){return[...this.#t.keys()]}refuse(t){for(let[e,n]of Object.entries(t))this.#e.set(e,n)}get refused(){return this.#e}load(t,e){if(this.#t.has(e))return Promise.resolve().then(()=>He(this.#t.get(e)));let n=this.#e.get(e);return n!==void 0?Promise.reject(new Error(n)):(this.#r.set(e,t),this.#n?.refused(),Promise.reject(new Error(`blob ${e} is carried by the next child`)))}get missing(){return this.#r.size>0}missed(){return new Map(this.#r)}},Ca=r=>typeof r==\"string\"&&/^[a-z0-9][a-z0-9-]{0,62}$/.test(r),hn=12,X0=r=>{if(typeof r!=\"object\"||r===null||Array.isArray(r))return null;let t={};for(let[e,n]of Object.entries(r)){let{sealed:o,places:s}=n??{},i=li({places:s});if(!Ca(e)||!K(o)||o.length<=hn*2||i===null)return null;t[e]={sealed:o,places:i.places}}return t},Ha=r=>dt(I(r),Bf,32),Y0=async(r,t,e=new Nt)=>{let n=e.draw(hn);return _(C(n,await Dt(await Ha(r),n,new Uint8Array(0),t)))},vi=r=>Array.from({length:Math.ceil(r.length/Oi)},(t,e)=>r.slice(e*Oi,(e+1)*Oi)),Bi=r=>new Uint8Array((r instanceof ArrayBuffer,r)),Si=class extends ne{#t;#e;#r;#n;constructor(t,e=\"\",n=()=>!1,o){super(),this.#t=t,this.#e=`${e}${vf}`,this.#r=n,this.#n=o}#o(){return this.#r()?(this.#n?.refused(),Promise.reject(new Error(\"a module was missed, so this call keeps nothing\"))):null}async read(t){let e=`${this.#e}${t}/`,n=await this.#t.list({prefix:e});return new Map([...n].map(([o,s])=>[o.slice(e.length),Bi(s).slice()]))}write(t,e){let n=this.#o();if(n)return n;let o=[],s=[];for(let[i,c]of e)c===null?s.push(`${this.#e}${t}/${i}`):o.push([`${this.#e}${t}/${i}`,c.slice()]);return this.#t.transaction(async i=>{for(let c of vi(o))await i.put(Object.fromEntries(c));for(let c of vi(s))await i.delete(c)}).then(()=>this.#n?.kept())}async places(){let t=this.#e,e=[...(await this.#t.list({prefix:t})).keys()];return[...new Set(e.map(n=>n.slice(t.length,n.indexOf(\"/\",t.length))))]}async forget(t){await this.#o();let e=[...(await this.#t.list({prefix:`${this.#e}${t}/`})).keys()];await this.#t.transaction(async n=>{for(let o of vi(e))await n.delete(o)}),this.#n?.kept()}},Ti=class extends oe{#t;#e;#r;#n;constructor(t,e,n=new Nt,o=\"\"){super(),this.#t=t,this.#e=e,this.#r=n,this.#n=`${o}${Af}`}async kept(){return await this.#t.get(this.#n)!==void 0}async land(t,e=this.#t){let n=$(t);await e.put({[this.#n]:{nonce:n.slice(0,hn),sealed:n.slice(hn)}})}async seed(){if(!this.#e)throw new Error(\"the worker holds no NERVUR_SECRET\");let t=await Ha(this.#e);return this.#t.transaction(async e=>{let n=await e.get(this.#n);if(n){let i=await qt(t,Bi(n.nonce),new Uint8Array(0),Bi(n.sealed));if(i===null)throw new Error(\"the seed does not open under this NERVUR_SECRET\");return i}let o=this.#r.draw(32),s=this.#r.draw(hn);return await e.put({[this.#n]:{nonce:s,sealed:await Dt(t,s,new Uint8Array(0),o)}}),o.slice()})}},Ri=class{#t;#e;#r=new Map;#n=1;#o=!1;constructor(t,e){this.#t=t,this.#e=t.writable.getWriter();let n=new un;(async()=>{try{for await(let o of t.readable){for(let s of n.push(new Uint8Array(o))){if(s.kind===\"ask\")continue;let i=this.#r.get(s.id);this.#r.delete(s.id),i?.(s.kind===\"reply\"?s.box:null)}if(n.bad)break}}catch{}this.#o=!0,e();for(let o of this.#r.values())o(null);this.#r.clear(),await t.close().catch(()=>{})})()}ask(t,e){if(this.#o)return Promise.resolve(null);let n=this.#n;return this.#n=this.#n===Sf?1:this.#n+1,new Promise(o=>{this.#r.set(n,o),this.#e.write(gi(n,t,e)).catch(()=>o(null))})}close(){return this.#o=!0,this.#t.close().catch(()=>{})}},Tf=\"cloudflare:sockets\",Rf=async()=>{try{return(await import(kf(Tf))).connect}catch{return null}},_i=class{#t=new Map;async dial(t,e,n){let o=Ae(t);if(o===null||!K(e,64))return mt;let s=await this.#e(o);return s?s.ask($(e),n):mt}#e({host:t,port:e}){let n=oo(t,e),o=this.#t.get(n);return o||(o=(async()=>{let s=await Rf();if(!s)return null;try{let i=s({hostname:t,port:e});return await i.opened,new Ri(i,()=>this.#t.delete(n))}catch{return null}})(),this.#t.set(n,o),o.then(s=>s??this.#t.delete(n))),o}listen(){return Promise.reject(new Error(\"an edge takes no inbound TCP\"))}async close(){let t=[...this.#t.values()];this.#t.clear();for(let e of await Promise.all(t))await e?.close()}},_f=(r,t)=>{r.at=t;let e=t.port===0?t.host:`${oo(t.host,t.port).slice(6)}`,[n,o]=t.port===0?[\"https\",\"wss\"]:[\"http\",\"ws\"];return Promise.resolve({port:t.port,at:[`${n}://${e}${t.path}`,`${o}://${e}${t.path}`],close:()=>(r.at===t&&(r.at=void 0),Promise.resolve())})},ji=class extends Lt{given;#t;constructor(t){let e=new Nt,{storage:n}=t.given.state,o=t.given.loader??new Ao,s={at:void 0};super({entropy:e,loader:o,custody:new Ti(n,t.given.env.NERVUR_SECRET,e),memory:new Si(n,\"\",()=>o.missing,t.given.calls),tcp:()=>new _i,web:(i,c)=>_f(s,c),defaults:t.defaults}),this.given=t.given,this.#t=s}get listening(){return this.#t.at}async claim(){let t=this.given.package,e=this.custody;!t||await e.kept()||(await ui(this.memory,{places:t.places}),await e.land(t.sealed))}},jf=r=>{let t=r;return typeof t?.state?.storage?.transaction==\"function\"&&typeof t.env==\"object\"},qa={name:Of,fits:({given:r})=>jf(r),terrain:({given:r},t)=>new ji({given:r,defaults:t})},za=r=>{let t=new URL(r.url).pathname.split(\"/\")[1];return Ca(t)?t:null},Ka=(r,t,e)=>{let n=[...new Set(t)].sort();return n.length===new Set(e).size&&e.every(s=>n.includes(s))?r:`${r}+${n.join(\"+\")}`},La=class{#t;#e;#r;#n;#o;#s;#l;#c;constructor(t,e,n,o,s){this.#t=t,this.#e=e,this.#r=n,this.#o=new Ai(s),this.#n=new Ao(o,this.#o)}async open(t,e,n,o,s){this.#n.refuse(s),this.#s??=this.#t.blockConcurrencyWhile(async()=>{let l=an({given:{state:this.#t,env:this.#e,loader:this.#n,calls:this.#o,...o?{package:o}:{}}}).terrain;this.#l=l;let u=await ee.open(l);if(this.#n.missing)return u;await u.ask({method:\"stand\"});let{beings:f}=(await u.ask({})).answer.notes,h=si(f,l.defaults.classes,\"web\");if(h===null)throw new Error(\"no class this edge runs carries web\");return h.open!==void 0&&await u.ask(h.open),l.listening?.path!==`/${t}/quo`&&await u.ask({method:\"ask\",args:{being:h.key,method:\"listen\",args:{host:e,port:n,path:`/${t}/quo`}}}),u});let i=await this.#s,c=this.#l?.listening;return{listen:c?{host:c.host,port:c.port,path:c.path,origins:[...c.origins]}:null,wanted:await this.#i(i)}}async arrive(t,e,n){let o=await this.#s;return o?this.#n.missing?{reply:null,wanted:await this.#i(o),again:!0}:{reply:await this.#o.run(n,()=>o.arrive(t,e)).catch(()=>null),wanted:await this.#i(o),again:this.#o.again(n)}:{reply:null,wanted:null,again:!1}}async#i(t){let e=this.#n.missed(),n=async a=>(await t.ask({method:\"ask\",args:{being:\"catalogue\",method:a}})).answer.answer,o=(await n(\"live\")).live;if(e.size===0&&o===this.#c)return null;let s=(await n(\"sources\")).sources,i=new Map(s.map(a=>[a.blob,a.source]));for(let[a,l]of e)i.set(a,l);for(let a of this.#n.refused.keys())i.delete(a);let c=s.map(a=>a.blob);return e.size===0&&Ka(o,[...i.keys()],c)===this.#r?(this.#c=o,null):{live:o,liveBlobs:c,modules:Object.fromEntries(i),missed:[...e.keys()]}}},Da=\"harbor\",If=\"Harbor\",Pa=\"harbor.js\",Fa=\"probe.js\",$f=\"boot\",Ma=\"2026-09-01\",Ua=8,Bo=r=>`${r}.js`,Nf=(r,t)=>[\"import { DurableObject } from 'cloudflare:workers';\",\"import { AsyncLocalStorage } from 'node:async_hooks';\",\"import { HarborChild } from 'nervur';\",...t.map((e,n)=>`import * as m${String(n)} from '${Bo(e)}';`),`const carried = [${t.map((e,n)=>`{ blob: '${e}', module: m${String(n)} }`).join(\", \")}];`,\"export class Harbor extends DurableObject {\",` #child = new HarborChild(this.ctx, this.env, ${JSON.stringify(r)}, carried, new AsyncLocalStorage());`,\" open(name, host, port, packed, refused) { return this.#child.open(name, host, port, packed, refused); }\",\" arrive(pk, box, call) { return this.#child.arrive(pk, box, call); }\",\"}\",\"\"].join(`\n`),Lf=r=>`import '${Bo(r)}';\nexport default { fetch() { return new Response(null, { status: 204 }); } };\n`,Df=r=>r instanceof Error?r.message:String(r),V0=({kit:r,pack:t})=>class{#t;#e;#r={};#n;#o;#s;#l;#c;#i;#h=null;#u;#f=Promise.resolve();#p=0;#a=0;#w=[];#d;constructor(e,n){this.#t=e,this.#e=n}async fetch(e){let n=za(e);if(n===null||this.#n!==void 0&&this.#n!==n)return new Response(null,{status:404});if(this.#n===void 0){let h=typeof t==\"function\"?t(this.#e):t,p=h&&Object.hasOwn(h,n)?h[n]:void 0;if(!p)return new Response(null,{status:404});let g=new URL(e.url);this.#n=n,this.#o=p,this.#s={host:g.hostname,port:g.port===\"\"?0:Number(g.port)}}this.#u??=this.#y(()=>this.#b($f,{},0)).catch(h=>{throw this.#u=void 0,h}),await this.#u;let o=this.#h;if(!o)return new Response(null,{status:404});let s={arrive:(h,p)=>this.#k(h,p)};if(e.headers.get(\"upgrade\")?.toLowerCase()!==\"websocket\")return fn(s,o,e);let i=(e.headers.get(\"sec-websocket-protocol\")??\"\").split(\",\").map(h=>h.trim());if(new URL(e.url).pathname!==o.path||!i.includes(\"quo\"))return new Response(null,{status:400});let c=globalThis.WebSocketPair,a=new c,[l,u]=[a[0],a[1]];u.accept();let f={send:h=>u.send(new Uint8Array(h)),close:()=>u.close()};return u.addEventListener(\"message\",h=>Ei(s,f,typeof h.data==\"string\"?h.data:new Uint8Array(h.data))),new Response(null,{status:101,webSocket:l,headers:{\"sec-websocket-protocol\":\"quo\"}})}#y(e){let n=this.#f.then(e,e);return this.#f=n.catch(()=>{}),n}#m(){let e=this.#e.LOADER;if(!e)throw new Error(\"the worker binds no LOADER: its wrangler.toml names a worker_loaders binding\");return e}#g(){return this.#l??=se(I(r)).then(e=>_(e).slice(0,16))}async#b(e,n,o,s=!1){let i=`${await this.#g()}:${e}`,c=Object.keys(n).sort(),a=this.#e.NERVUR_SECRET,l={compatibilityDate:Ma,compatibilityFlags:[\"nodejs_als\"],mainModule:Pa,modules:{[Pa]:{js:Nf(e,c)},nervur:{js:r},...Object.fromEntries(c.map(p=>[Bo(p),{js:n[p]}]))},env:a===void 0?{}:{NERVUR_SECRET:a}},u=this.#m().get(i,()=>Promise.resolve(l));this.#i&&this.#t.facets.abort(Da,new Error(\"live moved\"));let f=this.#t.facets.get(Da,()=>Promise.resolve({class:u.getDurableObjectClass(If)}));this.#i=f,this.#c=e,this.#d=void 0;let h=await f.open(this.#n,this.#s.host,this.#s.port,this.#o??null,{...this.#r});this.#h=h.listen,h.wanted&&(!s||h.wanted.missed.length>0)&&await this.#x(h.wanted,o+1)}async#x(e,n){if(n>Ua)throw new Error(\"the harbor settles on no child\");for(let c of e.missed){if(Object.hasOwn(this.#r,c))continue;let a=await this.#E(c,e.modules[c]??\"\");a!==null&&(this.#r[c]=a)}let o=Object.fromEntries(Object.entries(e.modules).filter(([c])=>!Object.hasOwn(this.#r,c))),s=Ka(e.live,Object.keys(o),e.liveBlobs),i=e.missed.length>0;if(!(s===this.#c&&!i))return this.#b(s,o,n,i)}async#E(e,n){let o={compatibilityDate:Ma,mainModule:Fa,modules:{[Fa]:{js:Lf(e)},nervur:{js:r},[Bo(e)]:{js:n}},env:{}};try{let i=await this.#m().get(`${await this.#g()}:probe:${e}`,()=>Promise.resolve(o)).getEntrypoint().fetch(new Request(\"https://probe.invalid/\"));return i.status===204?null:`the module does not load on the edge: ${await i.text()}`}catch(s){return`the module does not load on the edge: ${Df(s)}`}}async#k(e,n){for(let o=0;o<=Ua;o+=1){let s;do s=this.#f,await s;while(s!==this.#f);let i=this.#i,c=this.#p+=1;this.#a+=1;let a;try{a=await i.arrive(e,n,c)}catch{a=null}finally{if(this.#a-=1,this.#a===0)for(let l of this.#w.splice(0))l()}if(a===null)return null;if(a.wanted&&i===this.#i&&(this.#d=a.wanted,this.#y(()=>this.#O(i)).catch(()=>{})),!a.again)return a.reply}return null}async#O(e){this.#a>0&&await new Promise(o=>this.#w.push(o));let n=this.#d;e!==this.#i||!n||(this.#d=void 0,await this.#x(n,0))}},J0=(r=\"HARBOR\")=>({fetch(t,e){let n=za(t),o=e[r];return n===null||!o?Promise.resolve(new Response(null,{status:404})):o.get(o.idFromName(n)).fetch(t)}});var Ii={};Va(Ii,{BOX:()=>It,Being:()=>Xt,BundleLoader:()=>Le,CEILING:()=>Ns,Carrier:()=>we,CarrierFaculty:()=>ft,Catalogue:()=>ut,Clock:()=>ze,CryptoEntropy:()=>Nt,Custody:()=>oe,DEFAULT:()=>$s,DEFAULTS:()=>pn,DEPTH:()=>_t,DefaultDock:()=>Pe,DefaultWard:()=>Ue,Dock:()=>jt,Entropy:()=>qe,Faculty:()=>G,GroundMemory:()=>Fe,Harbor:()=>ee,HeldCustody:()=>Ne,Loader:()=>Ht,MEMORY:()=>ur,Memory:()=>ne,MemoryFaculty:()=>Ot,NEUTRAL:()=>vo,NoCarrier:()=>dr,OWNER:()=>Bt,PointerCarrier:()=>hr,PointerTerrain:()=>Lt,REGISTRY:()=>po,Registry:()=>Ut,RegistryFaculty:()=>Mt,SourceLoader:()=>re,SystemClock:()=>$e,TcpFaculty:()=>Me,Terrain:()=>te,UNDIALED:()=>mt,VolatileMemory:()=>De,WARD:()=>D,Ward:()=>yt,WebDialer:()=>Ie,WebFaculty:()=>Ce,World:()=>dn,addGround:()=>je,answerPost:()=>fn,canonical:()=>rr,copyPackage:()=>ai,digest:()=>Ur,groundOf:()=>$t,grounds:()=>fi,isSilence:()=>St,isWord:()=>wt,ownerAsk:()=>L,pilots:()=>Te,readInvitation:()=>kt,readRootRequest:()=>ln,silence:()=>ht,told:()=>de,word:()=>pt});var Pe=class extends jt{static kind=\"org.nervur.default-dock\";static{U(this)}};var Pf=32,Fe=class extends Ot{static kind=\"org.nervur.ground-memory\";static{U(this)}#t;constructor(t){super(t),this.#t=$t(t).terrain.memory}get#e(){return _(I(this.stance.key))}occupies(t){return t.length===this.#e.length+Pf&&t.startsWith(this.#e)}read(t){return this.#t.read(this.#e+t)}write(t,e){return this.#t.write(this.#e+t,e)}async places(){return(await this.#t.places()).filter(t=>this.occupies(t)).map(t=>t.slice(this.#e.length))}forget(t){return this.#t.forget(this.#e+t)}};var Wa=r=>{if(typeof r!=\"object\"||r===null)return null;let{host:t,port:e}=r;return typeof t==\"string\"&&Number.isInteger(e)&&e>=0&&e<=65535?{host:t,port:e}:null},Me=class extends ft{static kind=\"org.nervur.tcp\";static carries=\"tcp\";static{U(this)}static asks={listen:L(\"listen for Quo over TCP, and on every wake\",{properties:{host:{type:\"string\"},port:{type:\"integer\"}}}),deaf:L(\"listen nowhere\")};#t;#e;constructor(t){super(t);let e=$t(t).terrain.tcp;if(!e)throw new Error(\"this ground speaks no TCP\");this.#t=e()}accepts(t){return Ae(t)!==null}dial(t,e,n){return this.#t.dial(t,e,n)}listening(){return this.#e?[this.#e.at]:[]}async awake(){let t=Wa(this.cells.listen);t&&!this.#e&&(this.#e=await this.#t.listen($t(this.stance),t.host,t.port))}async sleep(){await this.#t.close(),await this.#e?.close(),this.#e=void 0}async listen(t){let e=Wa({host:t.host??\"127.0.0.1\",port:t.port??0});if(e===null)return{error:\"host is text and port a port\"};await this.#e?.close(),this.#e=void 0;try{this.#e=await this.#t.listen($t(this.stance),e.host,e.port)}catch(n){return{error:n.message}}return this.cells.listen={host:e.host,port:Ae(this.#e.at).port},{at:this.#e.at}}async deaf(){return await this.#e?.close(),this.#e=void 0,delete this.cells.listen,{deaf:!0}}};var Ue=class extends yt{static kind=\"org.nervur.default-ward\";static{U(this)}};var Ga=r=>{if(typeof r!=\"object\"||r===null)return null;let{host:t,port:e,path:n,origins:o}=r;return typeof t==\"string\"&&Number.isInteger(e)&&e>=0&&e<=65535&&typeof n==\"string\"&&n.startsWith(\"/\")&&Array.isArray(o)&&o.every(i=>typeof i==\"string\")?{host:t,port:e,path:n,origins:o}:null},Ce=class extends ft{static kind=\"org.nervur.web\";static carries=\"web\";static{U(this)}static asks={listen:L(\"listen for Quo over the web, and on every wake\"),deaf:L(\"listen nowhere\")};#t=new Ie;#e;get#r(){return $t(this.stance)}accepts(t){return ir(t)!==null}dial(t,e,n){return this.#t.dial(t,e,n)}listening(){return this.#e?[...this.#e.at]:[]}async awake(){let t=Ga(this.cells.listen),e=this.#r.terrain.web;t&&e&&!this.#e&&(this.#e=await e(this.#r,t))}async sleep(){await this.#t.close(),await this.#e?.close(),this.#e=void 0}async listen(t){let e=this.#r.terrain.web;if(!e)return{error:\"this ground listens nowhere on the web\"};let n=Ga({host:t.host??\"127.0.0.1\",port:t.port??0,path:t.path??\"/\",origins:t.origins??[\"*\"]});if(n===null)return{error:\"host is text, port a port, path a path and origins a list\"};await this.#e?.close(),this.#e=void 0;try{this.#e=await e(this.#r,n)}catch(o){return{error:o.message}}return this.cells.listen={...n,port:this.#e.port},{at:[...this.#e.at]}}async deaf(){return await this.#e?.close(),this.#e=void 0,delete this.cells.listen,{deaf:!0}}};var pn={dock:Pe,ward:Ue,classes:[Fe,Me,Ce]};_o(Ii);je(ki,pn);je(qa,pn);export{It as BOX,Xt as Being,Le as BundleLoader,Ns as CEILING,we as Carrier,ft as CarrierFaculty,ut as Catalogue,Ai as ChildCalls,ze as Clock,Nt as CryptoEntropy,oe as Custody,$s as DEFAULT,pn as DEFAULTS,_t as DEPTH,Pe as DefaultDock,Ue as DefaultWard,jt as Dock,Of as EDGE,Ti as EdgeCustody,Ao as EdgeLoader,Si as EdgeMemory,_i as EdgeSockets,ji as EdgeTerrain,qe as Entropy,G as Faculty,Fe as GroundMemory,ee as Harbor,La as HarborChild,Ne as HeldCustody,Ht as Loader,ur as MEMORY,ne as Memory,Ot as MemoryFaculty,vo as NEUTRAL,dr as NoCarrier,Bt as OWNER,hr as PointerCarrier,Lt as PointerTerrain,po as REGISTRY,Ut as Registry,Mt as RegistryFaculty,re as SourceLoader,$e as SystemClock,Me as TcpFaculty,te as Terrain,mt as UNDIALED,De as VolatileMemory,D as WARD,yt as Ward,Ie as WebDialer,Ce as WebFaculty,dn as World,je as addGround,fn as answerPost,rr as canonical,Ka as childKey,ai as copyPackage,Ur as digest,qa as edgeGround,$t as groundOf,fi as grounds,za as harborNameOf,V0 as harborShell,J0 as harborWorker,Ca as isHarborName,St as isSilence,wt as isWord,L as ownerAsk,Te as pilots,kt as readInvitation,X0 as readPack,ln as readRootRequest,Y0 as sealSeed,ht as silence,de as told,pt as word};\n/*! Bundled license information:\n\n@noble/curves/utils.js:\n@noble/curves/abstract/modular.js:\n@noble/curves/abstract/curve.js:\n@noble/curves/abstract/edwards.js:\n@noble/curves/abstract/montgomery.js:\n@noble/curves/ed25519.js:\n (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)\n\n@noble/post-quantum/utils.js:\n@noble/post-quantum/_crystals.js:\n@noble/post-quantum/ml-kem.js:\n (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)\n*/\n";
2
+ export default "var Ya=Object.defineProperty;var Va=(r,t)=>{for(var e in t)Ya(r,e,{get:t[e],enumerable:!0})};var Mi=\"org.nervur.kits\",Ja=()=>{let r=globalThis;return r[Symbol.for(Mi)]??=new Map},mn,_o=r=>{let t=Ja();mn??=`kit${String(t.size)}`,t.set(mn,r)},Qa=/\\bimport\\s*(\\{[^}]*\\}|\\*\\s*as\\s+[A-Za-z_$][\\w$]*)\\s*from\\s*(['\"])nervur\\2\\s*;?/g,tu=/(^|[\\n;{}])\\s*(import\\s*[\\w{*'\"]|export\\s*(\\*|\\{[^}]*\\})\\s*from\\b)/,jo=r=>{if(mn===void 0)throw new Error(\"no kit is bound to link a module against\");let t=`globalThis[Symbol.for(${JSON.stringify(Mi)})].get(${JSON.stringify(mn)})`,e=r.replace(Qa,(n,o)=>o.startsWith(\"*\")?`const ${o.replace(/^\\*\\s*as\\s+/,\"\")} = ${t};`:`const { ${o.slice(1,-1).split(\",\").map(i=>i.trim()).filter(i=>i!==\"\").map(i=>i.replace(/\\s+as\\s+/,\": \")).join(\", \")} } = ${t};`);if(tu.test(e))throw new Error(\"a module imports nothing but 'nervur'\");return e},He=r=>{let{module:t,version:e,classes:n}=r??{};if(typeof t!=\"string\"||typeof e!=\"string\"||!Array.isArray(n))throw new Error(\"the code exports no module: module, version and classes\");return{module:t,version:e,classes:n}};var qe=class{get drawer(){return t=>this.draw(t)}},ze=class{},ne=class{},oe=class{},Ht=class{},we=class{};var eu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,\"0\")),ru=/^(?:[0-9a-f]{2})*$/,_=r=>{let t=\"\";for(let e of r)t+=eu[e];return t},K=(r,t)=>typeof r==\"string\"&&ru.test(r)&&(t===void 0||r.length===t*2),$=r=>{if(!K(r))throw new TypeError(\"not hex\");let t=new Uint8Array(r.length/2);for(let e=0;e<t.length;e+=1)t[e]=parseInt(r.slice(e*2,e*2+2),16);return t},C=(...r)=>{let t=new Uint8Array(r.reduce((n,o)=>n+o.length,0)),e=0;for(let n of r)t.set(n,e),e+=n.length;return t},yr=r=>r.every(t=>t===0),nu=new TextEncoder,I=r=>nu.encode(r);var gt=()=>{let r=globalThis.crypto?.subtle;if(!r)throw new Error(\"this terrain has no crypto.subtle: a ward needs a secure context\");return r},rt=r=>Uint8Array.from(r);var ou=new Uint8Array(0),se=async r=>new Uint8Array(await gt().digest(\"SHA-256\",rt(r))),dt=async(r,t,e)=>{let n=await gt().importKey(\"raw\",rt(r),\"HKDF\",!1,[\"deriveBits\"]),o=await gt().deriveBits({name:\"HKDF\",hash:\"SHA-256\",salt:ou,info:rt(t)},n,e*8);return new Uint8Array(o)};var su=new TextDecoder(\"utf-8\",{fatal:!0,ignoreBOM:!0}),Io=/-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/y,$o=/\\\\(?:[\"\\\\/bfnrt]|u[0-9a-fA-F]{4})/y,No=/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/,Ui=[\"true\",\"false\",\"null\"],X=(r,t)=>{for(;t<r.length&&` \t\n\\r`.includes(r[t]);)t+=1;return t},mr=(r,t)=>{if(r[t]!=='\"')return-1;for(t+=1;t<r.length;){let e=r.charCodeAt(t);if(e===34)return t+1;if(e<32)return-1;if(e!==92){t+=1;continue}if($o.lastIndex=t,!$o.test(r))return-1;t=$o.lastIndex}return-1},Ci=(r,t)=>{if(r[t]==='\"')return mr(r,t);let e=Ui.find(n=>r.startsWith(n,t));return e?t+e.length:(Io.lastIndex=t,Io.test(r)?Io.lastIndex:-1)},Lo=(r,t)=>{let e=mr(r,t);if(e<0)return-1;let n=X(r,e);return r[n]===\":\"?X(r,n+1):-1},Hi=(r,t)=>{let e=[];for(;;){let n=r[t];if(n===\"{\"||n===\"[\")if(t=X(r,t+1),r[t]===(n===\"{\"?\"}\":\"]\"))t+=1;else{if(e.push(n),n===\"{\"&&(t=Lo(r,t))<0)return-1;continue}else if((t=Ci(r,t))<0)return-1;for(;;){if(e.length===0)return t;t=X(r,t);let o=e.at(-1);if(r[t]===\",\"){if(t=X(r,t+1),o===\"{\"&&(t=Lo(r,t))<0)return-1;break}if(r[t]!==(o===\"{\"?\"}\":\"]\"))return-1;e.pop(),t+=1}}},qi=r=>{if(typeof r==\"string\")return r;try{return su.decode(r)}catch{return null}},gr=r=>{let t=qi(r);if(t===null)return null;let e=new Map,n=X(t,0);if(t[n]!==\"{\")return null;if(n=X(t,n+1),t[n]===\"}\")return X(t,n+1)===t.length?e:null;for(;;){let o=n,s=Lo(t,n);if(s<0)return null;let i=JSON.parse(t.slice(o,mr(t,o)));if(e.has(i))return null;let c=Hi(t,s);if(c<0)return null;if(e.set(i,t.slice(s,c)),n=X(t,c),t[n]===\"}\")return X(t,n+1)===t.length?e:null;if(t[n]!==\",\")return null;n=X(t,n+1)}},iu=r=>{let[,t,e,n=\"\",o=\"0\"]=/^(-?)(0|[1-9]\\d*)(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/.exec(r),s=Number(r);if(!Number.isFinite(s))return!1;let i=(e+n).replace(/^0+/,\"\");if(s===0)return i===\"\"&&t===\"\";let c=i.replace(/0+$/,\"\"),a=BigInt(o)-BigInt(n.length)+BigInt(i.length-c.length);return a<0n?!0:BigInt(c)*10n**a===(s<0?-BigInt(s):BigInt(s))||r===String(s)},cu=r=>{let t=0,e=0;for(let n=0;n<r.length;n+=1){let o=r[n];o==='\"'?n=mr(r,n)-1:o===\"{\"||o===\"[\"?e=Math.max(e,t+=1):(o===\"}\"||o===\"]\")&&(t-=1)}return e},au=r=>{let t=0,e=()=>{t=X(r,t);let o=r[t];if(o===\"{\"||o===\"[\"){let c=o===\"{\",a=c?{}:[];if(t=X(r,t+1),r[t]===(c?\"}\":\"]\"))return t+=1,a;for(;;){if(c){let u=n();if(Object.hasOwn(a,u))throw new Error(\"two keys of one name\");t=X(r,t)+1,Object.defineProperty(a,u,{value:e(),enumerable:!0,writable:!0,configurable:!0})}else a.push(e());if(t=X(r,t),r[t++]!==\",\")return a}}if(o==='\"')return n();let s=Ci(r,t),i=r.slice(t,s);if(t=s,Ui.includes(i))return JSON.parse(i);if(!iu(i))throw new Error(\"a number no double holds as written\");return Number(i)},n=()=>{t=X(r,t);let o=mr(r,t),s=JSON.parse(r.slice(t,o));if(No.test(s))throw new Error(\"a lone surrogate\");return t=o,s};return e()},br=(r,t)=>{let e=qi(r);if(e===null)return;let n=X(e,0),o=Hi(e,n);if(!(o<0||X(e,o)!==e.length||cu(e)>t))try{return au(e)}catch{return}},ie=(r,t)=>{let e=(n,o,s)=>{if(n===null||typeof n==\"boolean\")return!0;if(typeof n==\"string\")return!No.test(n);if(typeof n==\"number\")return Number.isFinite(n)&&!Object.is(n,-0);if(typeof n!=\"object\"||o===0||s.has(n))return!1;s.add(n);let i=Array.isArray(n)?Object.keys(n).length===n.length&&n.every(c=>e(c,o-1,s)):[Object.prototype,null].includes(Object.getPrototypeOf(n))&&Object.getOwnPropertySymbols(n).length===0&&Object.entries(Object.getOwnPropertyDescriptors(n)).every(([c,a])=>!No.test(c)&&a.enumerable===!0&&\"value\"in a&&e(a.value,o-1,s));return s.delete(n),i};return e(r,t,new Set)?JSON.stringify(r):void 0},Do=r=>/^[1-9]\\d{0,15}$/.test(r)&&Number(r)<=Number.MAX_SAFE_INTEGER;var Ke=16,zi=(r,t,e)=>({params:{name:\"AES-GCM\",iv:rt(t),additionalData:rt(e),tagLength:Ke*8},key:gt().importKey(\"raw\",rt(r),\"AES-GCM\",!1,[\"encrypt\",\"decrypt\"])}),Dt=async(r,t,e,n)=>{let o=zi(r,t,e);return new Uint8Array(await gt().encrypt(o.params,await o.key,rt(n)))},qt=async(r,t,e,n)=>{if(n.length<Ke)return null;let o=zi(r,t,e);try{return new Uint8Array(await gt().decrypt(o.params,await o.key,rt(n)))}catch{return null}};var gn=BigInt(4294967295),Ki=BigInt(32);function uu(r,t=!1){return t?{h:Number(r&gn),l:Number(r>>Ki&gn)}:{h:Number(r>>Ki&gn)|0,l:Number(r&gn)|0}}function bn(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=uu(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var lu=r=>r/2**32|0,fu=r=>r>>>0;function Wi(r,t,e,n){let o=lu(e),s=fu(e);r.setUint32(t,n?s:o,n),r.setUint32(t+4,n?o:s,n)}var Po=(r,t,e)=>r>>>e,Fo=(r,t,e)=>r<<32-e|t>>>e,ye=(r,t,e)=>r>>>e|t<<32-e,me=(r,t,e)=>r<<32-e|t>>>e,xr=(r,t,e)=>r<<64-e|t>>>e-32,Er=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Gi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Zi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Xi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Yi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Vi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ji=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;function kr(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name===\"Uint8Array\"&&\"BYTES_PER_ELEMENT\"in r&&r.BYTES_PER_ELEMENT===1}var xn=r=>r?`\"${r}\" `:\"\";function at(r,t=\"\"){if(typeof r!=\"number\")throw new TypeError(xn(t)+\"expected number, got \"+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(xn(t)+\"expected integer >= 0, got \"+r);return r}function ec(r,t=\"\"){if(typeof r!=\"boolean\")throw new TypeError(xn(t)+\"expected boolean, got type=\"+typeof r);return r}function z(r,t,e=\"\"){if(kr(r)&&(t===void 0||r.length===t))return r;t!==void 0&&at(t,\"length\");let n=kr(r),o=t!==void 0?` of length ${t}`:\"\",s=n?`length=${r.length}`:`type=${typeof r}`,i=xn(e)+\"expected Uint8Array\"+o+\", got \"+s;throw n?new RangeError(i):new TypeError(i)}var hu=(r,t)=>{if(r===null||typeof r!=\"object\"||Array.isArray(r))throw new TypeError((t===\"object\"?\"\":`\"${t}\" `)+\"expected object, got type=\"+typeof r)},Qi=(r,t)=>{hu(r,t);let e=Object.getPrototypeOf(r);if(e!==Object.prototype&&e!==null)throw new TypeError(`\"${t}\" expected plain object`);if(Object.hasOwn(r,\"__proto__\"))throw new TypeError(`\"${t}.__proto__\" is not allowed`)};function We(r,t=!0){if(r.destroyed)throw new Error(\"hash was destroyed\");if(t&&r.finished)throw new Error(\"digest() was already called\")}function En(r,t){z(r,void 0,\"output\");let e=t.outputLen;if(!(r.length>=e))throw new RangeError('\"output\" expected length >= '+e)}function Or(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Ge(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function kn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var rc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function pu(r){return r<<24&4278190080|r<<8&16711680|r>>>8&65280|r>>>24&255}function wu(r){for(let t=0;t<r.length;t++)r[t]=pu(r[t]);return r}var Ze=rc?r=>r:wu,nc=typeof Uint8Array.from([]).toHex==\"function\"&&typeof Uint8Array.fromHex==\"function\",yu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,\"0\"));function vr(r){if(z(r),nc)return r.toHex();let t=\"\";for(let e=0;e<r.length;e++)t+=yu[r[e]];return t}function tc(r){return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void 0}function On(r){if(typeof r!=\"string\")throw new TypeError(\"hex string expected, got \"+typeof r);if(nc)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError(\"hex string expected, got unpadded hex of length \"+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=tc(r.charCodeAt(s)),c=tc(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character \"'+a+'\" at index '+s)}n[o]=i*16+c}return n}function vn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];z(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Mo(r,t,e=\"opts\"){return Qi(r,\"defaults\"),t!==void 0&&Qi(t,e),Object.assign(Object.create(null),r,t)}function Ar(r,t={}){if(typeof r!=\"function\")throw new TypeError('\"hashCons\" expected function, got type='+typeof r);t=Mo({},t,\"info\");let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function An(r=32){at(r,\"bytesLength\");let t=typeof globalThis==\"object\"?globalThis.crypto:null;if(typeof t?.getRandomValues!=\"function\")throw new Error(\"crypto.getRandomValues must be defined\");if(r>65536)throw new RangeError(`\"bytesLength\" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var ge=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});var Bn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kn(this.buffer)}update(t){We(this),z(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let u=kn(t);for(;o<=s-c;c+=o)this.process(u,c);i=!0;continue}n.set(c===0&&a===s?t:t.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(e,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){We(this),En(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,e.fill(0,i),this.padOffset>o-i&&(this.process(n,0),e.fill(0)),Wi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=t===e?n:kn(t),a=this.outputLen,u=a/4,l=this.get();if(a%4||u>l.length)throw new Error(\"invalid outputLen\");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:e,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(e),t}clone(){return this._cloneInto()}};var oc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var sc=bn([\"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(r=>BigInt(r))),mu=sc[0],gu=sc[1],ce=new Uint32Array(80),ae=new Uint32Array(80),Uo=class extends Bn{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,e){super(128,t,16,!1),this.Ah=e[0]|0,this.Al=e[1]|0,this.Bh=e[2]|0,this.Bl=e[3]|0,this.Ch=e[4]|0,this.Cl=e[5]|0,this.Dh=e[6]|0,this.Dl=e[7]|0,this.Eh=e[8]|0,this.El=e[9]|0,this.Fh=e[10]|0,this.Fl=e[11]|0,this.Gh=e[12]|0,this.Gl=e[13]|0,this.Hh=e[14]|0,this.Hl=e[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:h,Gh:p,Gl:g,Hh:m,Hl:k}=this;return[t,e,n,o,s,i,c,a,u,l,f,h,p,g,m,k]}set(t,e,n,o,s,i,c,a,u,l,f,h,p,g,m,k){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=g|0,this.Hh=m|0,this.Hl=k|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,e){for(let d=0;d<16;d++,e+=4)ce[d]=t.getUint32(e),ae[d]=t.getUint32(e+=4);for(let d=16;d<80;d++){let w=ce[d-15]|0,y=ae[d-15]|0,v=ye(w,y,1)^ye(w,y,8)^Po(w,y,7),O=me(w,y,1)^me(w,y,8)^Fo(w,y,7),E=ce[d-2]|0,b=ae[d-2]|0,T=ye(E,b,19)^xr(E,b,61)^Po(E,b,6),B=me(E,b,19)^Er(E,b,61)^Fo(E,b,6),j=Xi(O,B,ae[d-7],ae[d-16]),P=Yi(j,v,T,ce[d-7],ce[d-16]);ce[d]=P|0,ae[d]=j|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:h,Fh:p,Fl:g,Gh:m,Gl:k,Hh:S,Hl:x}=this;for(let d=0;d<80;d++){let w=ye(f,h,14)^ye(f,h,18)^xr(f,h,41),y=me(f,h,14)^me(f,h,18)^Er(f,h,41),v=f&p^~f&m,O=h&g^~h&k,E=Vi(x,y,O,gu[d],ae[d]),b=Ji(E,S,w,v,mu[d],ce[d]),T=E|0,B=ye(n,o,28)^xr(n,o,34)^xr(n,o,39),j=me(n,o,28)^Er(n,o,34)^Er(n,o,39),P=n&s^n&c^s&c,A=o&i^o&a^i&a;S=m|0,x=k|0,m=p|0,k=g|0,p=f|0,g=h|0,{h:f,l:h}=Pt(u|0,l|0,b|0,T|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let N=Gi(T,j,A);n=Zi(N,b,B,P),o=N|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Pt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Pt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=Pt(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:g}=Pt(this.Fh|0,this.Fl|0,p|0,g|0),{h:m,l:k}=Pt(this.Gh|0,this.Gl|0,m|0,k|0),{h:S,l:x}=Pt(this.Hh|0,this.Hl|0,S|0,x|0),this.set(n,o,s,i,c,a,u,l,f,h,p,g,m,k,S,x)}roundClean(){Ge(ce,ae)}destroy(){this.destroyed=!0,Ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Co=class extends Uo{constructor(){super(64,oc)}};var Ho=Ar(()=>new Co,ge(3));function Br(r,t,e=()=>{}){if(!Array.isArray(r))throw new TypeError(`\"${t}\" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)e(r[n],`${t}[${n}]`);return r}var Y=(r,t,e)=>z(r,t,e),qo=at;function ue(r,t=\"object\"){if(r===null||typeof r!=\"object\"||Array.isArray(r))throw new TypeError(t===\"object\"?\"expected valid options object\":`\"${t}\" expected object, got type=${typeof r}`);return r}function be(r,t){if(typeof r!=\"function\")throw new TypeError(`\"${t}\" is invalid: expected function, got ${typeof r}`);return r}var cc=vr,zo=(...r)=>vn(...r),ac=r=>On(r),Sr=kr,Tr=r=>An(r),Sn=BigInt(0),ic=BigInt(1),bu=r=>r?`\"${r}\" `:\"\";function zt(r,t=\"\"){if(typeof r!=\"boolean\")throw new TypeError(bu(t)+\"expected boolean, got type=\"+typeof r);return r}function xu(r){if(typeof r==\"bigint\"){if(!le(r))throw new RangeError(\"positive bigint expected, got \"+r)}else qo(r);return r}function Xe(r,t=\"\"){if(typeof r!=\"number\"){let e=t&&`\"${t}\" `;throw new TypeError(e+\"expected number, got type=\"+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`\"${t}\" `;throw new RangeError(e+\"expected safe integer, got \"+r)}}function uc(r){if(typeof r!=\"string\")throw new TypeError(\"hex string expected, got \"+typeof r);return r===\"\"?Sn:BigInt(\"0x\"+r)}function Tn(r){return uc(vr(r))}function Kt(r){return uc(vr(fe(z(r)).reverse()))}function Ko(r,t){if(at(t),t===0)throw new Error(\"zero output length is invalid\");r=xu(r);let e=t*2,n=r.toString(16);if(n.length>e)throw new RangeError(\"number is too large\");return On(n.padStart(e,\"0\"))}function Rn(r,t){return Ko(r,t).reverse()}function fe(r){return Uint8Array.from(Y(r))}function le(r){return typeof r==\"bigint\"&&Sn<=r}function Wo(r,t,e){return le(r)&&le(t)&&le(e)&&t<=r&&r<e}function xe(r,t,e,n){if(!Wo(t,e,n))throw new RangeError(\"expected valid \"+r+\": \"+e+\" <= n < \"+n+\", got \"+t)}function Go(r){if(r<Sn)throw new Error(\"expected non-negative bigint, got \"+r);return r===Sn?0:r.toString(2).length}var lc=r=>(Xe(r,\"n\"),(ic<<BigInt(r))-ic);function bt(r,t={},e={},n=\"object\"){ue(r,n),ue(t,\"fields\"),ue(e,\"optFields\");function o(i,c,a){let u=n===\"object\"?`param \"${String(i)}\"`:`\"${n}.${String(i)}\"`,l=r[i];if(!Object.hasOwn(r,i)&&(a?l!==void 0:c!==\"function\"))throw new TypeError(`${u} is invalid: expected own property`);if(a&&l===void 0)return;let f=typeof l;if(f!==c||l===null)throw new TypeError(`${u} is invalid: expected ${c}, got ${f}`)}let s=(i,c)=>Object.entries(i).forEach(([a,u])=>o(a,u,c));s(t,!1),s(e,!0)}var V=BigInt(0),q=BigInt(1),Ee=BigInt(2),hc=BigInt(3),Zo=BigInt(4),pc=BigInt(5),Eu=BigInt(7),wc=BigInt(8),ku=BigInt(9),Ou=BigInt(15),yc=BigInt(16),vu=BigInt(\"0x10000000000000000\");function H(r,t){if(t<=V)throw new Error(\"mod: expected positive modulus, got \"+t);let e=r%t;return e>=V?e:t+e}function Au(r,t,e){if(e<=q)throw new Error(\"pow: expected modulus > 1, got \"+e);if(typeof t!=\"bigint\")throw new TypeError(\"invalid exponent: expected bigint, got \"+typeof t);if(t<V)throw new Error(\"invalid exponent, negatives unsupported\");if(t===V)return q;if(t===q)return r;let n=r%e;if(n<V&&(n+=e),t<vu){let c=q;for(;t>V;)t&q&&(c=c*n%e),n=n*n%e,t>>=q;return c}let o=[];for(;t>V;)o.push(Number(t&Ou)),t>>=Zo;let s=new Array(16);s[0]=q,s[1]=n;for(let c=2;c<16;c++)s[c]=s[c-1]*n%e;let i=s[o[o.length-1]];for(let c=o.length-2;c>=0;c--){i=i*i%e,i=i*i%e,i=i*i%e,i=i*i%e;let a=o[c];a!==0&&(i=i*s[a]%e)}return i}function xt(r,t,e){if(e<=q)throw new Error(\"pow2: expected modulus > 1, got \"+e);if(t<V)throw new Error(\"pow2: expected non-negative exponent, got \"+t);let n=r;for(;t-- >V;)n*=n,n%=e;return n}function fc(r,t){if(r===V)throw new Error(\"invert: expected non-zero number\");if(t<=q)throw new Error(\"invert: expected modulus > 1, got \"+t);let e=H(r,t),n=t,o=V,s=q;for(;e!==V;){let c=n/e,a=n-e*c,u=o-s*c;n=e,e=a,o=s,s=u}if(n!==q)throw new Error(\"invert: does not exist\");return H(o,t)}function Xo(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error(\"Cannot find square root\")}function Yo(r,t){if((r&q)===V)throw new Error(t+\": expected odd modulus, got \"+r)}function mc(r,t){let e=r,n=(e.ORDER+q)/Zo,o=e.pow(t,n);return Xo(e,o,t),o}function Bu(r,t){let e=r,n=(e.ORDER-pc)/wc,o=e.mul(t,Ee),s=e.pow(o,n),i=e.mul(t,s),c=e.mul(e.mul(i,Ee),s),a=e.mul(i,e.sub(c,e.ONE));return Xo(e,a,t),a}function Su(r){let t=In(r),e=gc(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Eu)/yc;return((c,a)=>{let u=c,l=u.pow(a,i),f=u.mul(l,n),h=u.mul(l,o),p=u.mul(l,s),g=u.eql(u.sqr(f),a),m=u.eql(u.sqr(h),a);l=u.cmov(l,f,g),f=u.cmov(p,h,m);let k=u.eql(u.sqr(f),a),S=u.cmov(l,f,k);return Xo(u,S,a),S})}function gc(r){if(r<hc)throw new Error(\"sqrt is not defined for small field\");Yo(r,\"tonelliShanks\");let t=r-q,e=0;for(;t%Ee===V;)t/=Ee,e++;let n=Ee,o=In(r);for(;Rr(o,n)===1;)if(n++>1e3)throw new Error(\"Cannot find square root: probably non-prime P\");if(e===1)return mc;let s=o.pow(n,t),i=(t+q)/Ee;return function(a,u){let l=a;if(l.is0(u))return u;if(Rr(l,u)!==1)throw new Error(\"Cannot find square root\");let f=e,h=l.mul(l.ONE,s),p=l.pow(u,t),g=l.pow(u,i);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error(\"Cannot find square root: probably non-prime P\");let m=1,k=l.sqr(p);for(;!l.eql(k,l.ONE);)if(m++,k=l.sqr(k),m===f)throw new Error(\"Cannot find square root\");let S=q<<BigInt(f-m-1),x=l.pow(h,S);f=m,h=l.sqr(x),p=l.mul(p,h),g=l.mul(g,x)}return g}}function Tu(r){return Yo(r,\"Fp.sqrt\"),r%Zo===hc?mc:r%wc===pc?Bu:r%yc===ku?Su(r):gc(r)}var bc=(r,t)=>(H(r,t)&q)===q,Ru=[\"create\",\"isValid\",\"is0\",\"neg\",\"inv\",\"sqrt\",\"sqr\",\"eql\",\"add\",\"sub\",\"mul\",\"pow\",\"div\",\"addN\",\"subN\",\"mulN\",\"sqrN\"];function Ye(r){if(ue(r,\"field\"),typeof r.ORDER!=\"bigint\")throw new TypeError('param \"ORDER\" is invalid: expected bigint, got '+typeof r.ORDER);Xe(r.BYTES,\"BYTES\"),Xe(r.BITS,\"BITS\");for(let t of Ru)be(r[t],\"field.\"+t);if(r.BYTES<1||r.BITS<1)throw new Error(\"invalid field: expected BYTES/BITS > 0\");if(r.ORDER<=q)throw new Error(\"invalid field: expected ORDER > 1, got \"+r.ORDER);return r}function jn(r,t,e=!1){Ye(r),Br(t,\"nums\"),zt(e,\"passZero\");let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((c,a,u)=>n.is0(a)?c:(o[u]=c,n.mul(c,a)),n.ONE),i=n.inv(s);return t.reduceRight((c,a,u)=>n.is0(a)?c:(o[u]=n.mul(c,o[u]),n.mul(c,a)),i),o}function Rr(r,t){Ye(r);let e=r;Yo(e.ORDER,\"FpLegendre\");let n=(e.ORDER-q)/Ee,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),c=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!c)throw new Error(\"invalid Legendre symbol result\");return s?1:i?0:-1}function _u(r,t){if(t!==void 0&&qo(t),r<=V)throw new Error(\"invalid n length: expected positive n, got \"+r);if(t!==void 0&&t<1)throw new Error(\"invalid n length: expected positive bit length, got \"+t);let e=Go(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${e})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var dc=new WeakMap,_n=class{ORDER;BITS;BYTES;isLE;ZERO=V;ONE=q;_lengths;_mod;constructor(t,e={}){if(t<=q)throw new Error(\"invalid field: expected ORDER > 1, got \"+t);let n;this.isLE=!1,e!=null&&typeof e==\"object\"&&(typeof e.BITS==\"number\"&&(n=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:s}=_u(t,n);if(s>2048)throw new Error(\"invalid field: expected ORDER of <= 2048 bytes\");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return H(t,this.ORDER)}isValid(t){if(typeof t!=\"bigint\")throw new TypeError(\"invalid field element: expected bigint, got \"+typeof t);return V<=t&&t<this.ORDER}is0(t){return t===V}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&q)===q}neg(t){return H(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return H(t*t,this.ORDER)}add(t,e){return H(t+e,this.ORDER)}sub(t,e){return H(t-e,this.ORDER)}mul(t,e){return H(t*e,this.ORDER)}pow(t,e){return Au(t,e,this.ORDER)}div(t,e){return H(t*fc(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 fc(t,this.ORDER)}sqrt(t){let e=dc.get(this);return e||dc.set(this,e=Tu(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Rn(t,this.BYTES):Ko(t,this.BYTES)}fromBytes(t,e=!1){Y(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error(\"Field.fromBytes: expected \"+n+\" bytes, got \"+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error(\"Field.fromBytes: expected \"+o+\" bytes, got \"+t.length);let a=s?Kt(t):Tn(t);if(c&&(a=H(a,i)),!e&&!this.isValid(a))throw new Error(\"invalid field element: outside of range 0..ORDER\");return a}invertBatch(t){return jn(this,t,!0)}cmov(t,e,n){return zt(n,\"condition\"),n?e:t}};function In(r,t={}){return Object.freeze(_n.prototype),new _n(r,t)}var Qo=BigInt(0),_r=BigInt(1),ju=BigInt(4),Vo=16,xc=128,Iu=5,Ec=2**31;function jr(r){let t=r;if(typeof t!=\"function\")throw new TypeError('\"Point\" expected constructor, got type='+typeof r);be(t.fromAffine,\"Point.fromAffine\"),be(t.fromBytes,\"Point.fromBytes\"),be(t.fromHex,\"Point.fromHex\"),ue(t.BASE,\"Point.BASE\"),ue(t.ZERO,\"Point.ZERO\"),Ye(t.Fp),Ye(t.Fn)}function Oc(r,t){jr(r),vc(t,r);let e=jn(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function $u(r,t,e=1){if(!Number.isSafeInteger(r)||r<e||r>t)throw new Error(\"invalid window size, expected [\"+e+\"..\"+t+\"], got W=\"+r)}function Nu(r,t){let e=r*(4*t+128);if(e>Ec)throw new Error(\"invalid window size: table would need ~\"+Math.ceil(e/2**20)+\" MiB, max \"+Ec/2**20+\" MiB\")}function Lu(r,t){if(r!==void 0){be(r,\"randomBytes\");try{let e=r(t);if(!Sr(e)||e.length!==t)return}catch{return}return r}}function vc(r,t){Br(r,\"points\"),r.forEach((e,n)=>{if(!(e instanceof t))throw new Error(\"invalid point at index \"+n)})}function Du(r,t,e){if(!Array.isArray(r))throw new Error(\"array of scalars expected\");r.forEach((n,o)=>{if(!(e===void 0?t.isValid(n):le(n)&&n<e))throw new Error(\"invalid scalar at index \"+o)})}var Ac=new WeakMap;function Jo(r){return Ac.get(r)||1}function Pu(r,t){let e=r.double(),n=[r];for(let o=1;o<t;o++)n.push(n[o-1].add(e));return n}function Fu(r,t){let e=2**t,n=e/2,o=BigInt(e-1),s=[];for(;r>Qo;){let i=0;r&_r&&(i=Number(r&o),i>=n&&(i-=e),r-=BigInt(i)),s.push(i),r>>=_r}return s}function Mu(r,t,e){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),c=[];for(let a=0;a<e;a++){let u=Number(r&s);r>>=i,u>o&&(u-=n,r+=_r),c.push(u)}if(r!==Qo)throw new Error(\"invalid wnaf\");return c}function Uu(r,t,e){let n=0;for(let s of e)n=Math.max(n,s.length);let o=r;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<e.length;i++){let c=e[i][s];if(c){let a=t[i][Math.abs(c)-1>>1];o=o.add(c<0?a.negate():a)}}}return o}var $n=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,e){jr(t),this.randomBytes=Lu(e,Vo),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,e,n){let o=Math.ceil(n/e)+1,s=2**(e-1),i=[],c=t;for(let a=0;a<o;a++){let u=c;for(let l=0;l<s;l++)i.push(u),u=u.add(c);c=i[i.length-1].double()}return{W:e,bits:n,windows:o,comp:i}}wnafCachedCT(t,e){let{W:n,windows:o,comp:s}=t,i=2**(n-1),c=Mu(e,n,o),a=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let f=c[l],h=l*i,p=Math.abs(f)-1,g=s[h];for(let k=1;k<i;k++)g=k===p?s[h+k]:g;let m=g.negate();f===0?u=u.add(s[h]):a=a.add(f<0?m:g)}return{p:a,f:u}}getWnafPrecomputes(t,e,n,o){let s=this.wnafPrecomputes.get(e),i=s?.find(c=>c.W===t&&c.bits===n);return i||(i=this.buildWnafTable(e,t,n),typeof o==\"function\"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(e,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('\"point\" expected Point instance, got type='+typeof t)}validateMulInput(t,e){if(this.assertPoint(t),!Wo(e,_r,this.Point.Fn.ORDER))throw new Error(\"invalid scalar\")}runCT(t,e,n,o){let s=Jo(t);return s===1?this.fixedWindowCT(t,e,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),e)}mulCT(t,e,n){return this.validateMulInput(t,e),this.runCT(t,e,this.bits,n)}mulCTBlinded(t,e,n){if(this.validateMulInput(t,e),this.randomBytes===void 0)throw new Error(\"randomBytes is required for scalar blinding\");let o=this.Point.Fn.BITS+xc,s=this.randomBytes(Vo);if(!Sr(s)||s.length!==Vo)throw new Error(\"randomBytes returned invalid byte array\");s[0]=s[0]&63|128;let i=e+Tn(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,e,n){let o=Iu,s=1<<o,i=lc(o),c=new Array(s);c[0]=this.ZERO;for(let l=1;l<s;l++)c[l]=c[l-1].add(t);let a=Math.ceil(n/o),u=this.ZERO;for(let l=a-1;l>=0;l--){if(l!==a-1)for(let p=0;p<o;p++)u=u.double();let f=Number(e>>BigInt(l*o)&i),h=c[0];for(let p=1;p<s;p++)h=p===f?c[p]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(t,e){return this.randomBytes===void 0?!1:e===_r?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,e,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,e,o):this.mulCT(t,e,o)}mulUnsafe(t,e,n){if(this.assertPoint(t),!le(e))throw new Error(\"invalid scalar\");let o=Jo(t);if(o===1||e>=this.Point.Fn.ORDER)return Cu(this.Point,[t],[e],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,e).p}setWindowSize(t,e){this.assertPoint(t),$u(e,this.bits);let n=Math.ceil((this.bits+xc)/e)+1;Nu(n*2**(e-1),this.Point.Fp.BYTES),Ac.set(t,e),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return Jo(t)!==1}};function Cu(r,t,e,n=!1){if(jr(r),vc(t,r),zt(n,\"allowOversized\"),Du(e,r.Fn,n?r.Fn.ORDER**ju:void 0),t.length!==e.length)throw new Error(\"arrays of points and scalars must have equal length\");let o=t.map(i=>Pu(i,4)),s=e.map(i=>Fu(i,4));return Uu(r.ZERO,o,s)}function kc(r,t,e){if(t){if(t.ORDER!==r)throw new Error(\"Field.ORDER must match order: Fp == p, Fn == n\");return Ye(t),t}else return In(r,{isLE:e})}function Bc(r,t,e={},n){if(r!==\"weierstrass\"&&r!==\"edwards\")throw new Error('expected curve type \"weierstrass\" or \"edwards\"');if(n===void 0&&(n=r===\"edwards\"),!t||typeof t!=\"object\")throw new Error(`expected valid ${r} CURVE object`);bt(e);for(let a of[\"p\",\"n\",\"h\"]){let u=t[a];if(!(le(u)&&u!==Qo))throw new Error(`CURVE.${a} must be positive bigint`)}let o=kc(t.p,e.Fp,n),s=kc(t.n,e.Fn,n),c=[\"Gx\",\"Gy\",\"a\",r===\"weierstrass\"?\"b\":\"d\"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Nn(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Ln=BigInt(0),Dn=BigInt(1),Pn=BigInt(2),Hu=BigInt(4),Sc=BigInt(8);function qu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),c=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,c)}function Tc(r,t={}){bt(t,{},{},\"extraOpts\");let e=t,n=Bc(\"edwards\",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;if(Rr(o,i.a)!==1)throw new Error(\"edwards: CURVE.a must be a square in Fp for complete addition formulas\");if(Rr(o,i.d)!==-1)throw new Error(\"edwards: CURVE.d must be a non-square in Fp for complete addition formulas\");bt(e,{},{uvRatio:\"function\",randomBytes:\"function\"});let a=e.randomBytes===void 0?Tr:e.randomBytes,u=Pn<<BigInt(o.BYTES*8)-Dn;function l(x){if(!o.isOdd)throw new Error(\"Field does not have .isOdd()\");return o.isOdd(x)}let f=e.uvRatio===void 0?(x,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(x,d))}}catch{return{isValid:!1,value:Ln}}}:e.uvRatio;if(!qu(o,i,i.Gx,i.Gy))throw new Error(\"bad curve params: generator point\");let h=o.eql(i.a,o.neg(o.ONE))?x=>o.neg(x):o.eql(i.a,o.ONE)?x=>x:x=>o.mul(i.a,x);function p(x,d,w=!1){let y=w?Dn:Ln;return xe(\"coordinate \"+x,d,y,u),d}function g(x){if(!(x instanceof m))throw new Error(\"EdwardsPoint expected\")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(d,w,y,v){this.X=p(\"x\",d),this.Y=p(\"y\",w),this.Z=p(\"z\",y,!0),this.T=p(\"t\",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){if(d instanceof m)throw new Error(\"extended point not allowed\");let{x:w,y}=d||{};return p(\"x\",w),p(\"y\",y),new m(w,y,o.ONE,o.mul(w,y))}static fromBytes(d,w=!1){let y=o.BYTES,{a:v,d:O}=i;d=fe(Y(d,y,\"point\")),zt(w,\"zip215\");let E=fe(d),b=d[y-1];E[y-1]=b&-129;let T=Kt(E),B=w?u:o.ORDER;xe(\"point.y\",T,Ln,B);let j=o.sqr(T),P=o.sub(j,o.ONE),A=o.sub(o.mulN(O,j),v),{isValid:N,value:R}=f(P,A);if(!N)throw new Error(\"bad point: invalid y coordinate\");let F=l(R),M=(b&128)!==0;if(!w&&o.is0(R)&&M)throw new Error(\"bad point: x=0 and x_0=1\");return M!==F&&(R=o.neg(R)),m.fromAffine({x:R,y:T})}static fromHex(d,w=!1){return m.fromBytes(ac(d),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,w=!0){return S.setWindowSize(this,d),w||this.multiply(Pn),this}assertValidity(){let d=this,{a:w,d:y}=i;if(d.is0())throw new Error(\"bad point: ZERO\");let{X:v,Y:O,Z:E,T:b}=d,T=o.sqr(v),B=o.sqr(O),j=o.sqr(E),P=o.sqr(j),A=o.mul(T,w),N=o.mul(o.add(A,B),j),R=o.add(P,o.mul(y,o.mul(T,B)));if(!o.eql(N,R))throw new Error(\"bad point: equation left != right (1)\");let F=o.mul(v,O),M=o.mul(E,b);if(!o.eql(F,M))throw new Error(\"bad point: equation left != right (2)\")}equals(d){g(d);let{X:w,Y:y,Z:v}=this,{X:O,Y:E,Z:b}=d,T=o.mul(w,b),B=o.mul(O,v),j=o.mul(y,b),P=o.mul(E,v);return o.eql(T,B)&&o.eql(j,P)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:d,Y:w,Z:y}=this,v=o.sqr(d),O=o.sqr(w),E=o.mul(o.sqr(y),Pn),b=h(v),T=o.addN(d,w),B=o.sub(o.subN(o.sqr(T),v),O),j=o.addN(b,O),P=o.subN(j,E),A=o.subN(b,O),N=o.mul(B,P),R=o.mul(j,A),F=o.mul(B,A),M=o.mul(P,j);return new m(N,R,M,F)}add(d){g(d);let{d:w}=i,{X:y,Y:v,Z:O,T:E}=this,{X:b,Y:T,Z:B,T:j}=d,P=o.mul(y,b),A=o.mul(v,T),N=o.mul(o.mulN(E,w),j),R=o.mul(O,B),F=o.sub(o.subN(o.mulN(o.addN(y,v),o.addN(b,T)),P),A),M=o.subN(R,N),W=o.addN(R,N),Z=o.sub(A,h(P)),et=o.mul(F,M),it=o.mul(W,Z),ct=o.mul(F,Z),Ct=o.mul(M,W);return new m(et,it,Ct,ct)}subtract(d){return g(d),this.add(d.negate())}multiply(d){if(!s.isValidNot0(d))throw new RangeError(\"invalid scalar: expected 1 <= sc < curve.n\");let{p:w,f:y}=S.mulSecret(this,d,c,k);return k([w,y])[0]}multiplyUnsafe(d){if(!s.isValid(d))throw new RangeError(\"invalid scalar: expected 0 <= sc < curve.n\");return d===Ln?m.ZERO:this.is0()||d===Dn?this:S.mulUnsafe(this,d,k)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.mulUnsafe(this,i.n).is0()}toAffine(d){let w=this,y=d;if(y!=null&&typeof y!=\"bigint\")throw new TypeError('\"invertedZ\" expected bigint, got type='+typeof y);let{X:v,Y:O,Z:E}=w,b=w.is0();y==null&&(y=b?o.create(Sc):o.inv(E));let T=o.mul(v,y),B=o.mul(O,y),j=o.mul(E,y);if(b)return{x:o.ZERO,y:o.ONE};if(!o.eql(j,o.ONE))throw new Error(\"invZ was invalid\");return{x:T,y:B}}clearCofactor(){return c===Dn?this:c===Pn?this.double():c===Hu?this.double().double():c===Sc?this.double().double().double():this.multiplyUnsafe(c)}toBytes(){let{x:d,y:w}=this.toAffine(),y=o.toBytes(w);return y[y.length-1]|=l(d)?128:0,y}toHex(){return cc(this.toBytes())}toString(){return`<Point ${this.is0()?\"ZERO\":this.toHex()}>`}}let k=x=>Oc(m,x),S=new $n(m,a);return S.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function Rc(r,t,e={}){if(jr(r),typeof t!=\"function\")throw new Error('\"hash\" function param is required');let n=t,o=e;bt(o,{},{adjustScalarBytes:\"function\",randomBytes:\"function\",domain:\"function\",prehash:\"function\",zip215:\"boolean\",mapToCurve:\"function\",toMontgomery:\"function\",toMontgomerySecret:\"function\"});let{prehash:s}=o,{BASE:i,Fp:c,Fn:a}=r,u=n.outputLen,l=2*c.BYTES;if(u!==void 0&&(Xe(u,\"hash.outputLen\"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let f=o.randomBytes===void 0?Tr:o.randomBytes,h=o.toMontgomery,p=o.toMontgomerySecret,g=o.adjustScalarBytes===void 0?A=>A:o.adjustScalarBytes,m=o.domain===void 0?(A,N,R)=>{if(zt(R,\"phflag\"),N.length||R)throw new Error(\"Contexts/pre-hash are not supported\");return A}:o.domain;function k(A){return a.create(Kt(A))}function S(A){let N=b.secretKey;Y(A,b.secretKey,\"secretKey\");let R=Y(n(A),2*N,\"hashedSecretKey\"),F=g(R.slice(0,N)),M=R.slice(N,2*N),W=k(F);return{head:F,prefix:M,scalar:W}}function x(A){let{head:N,prefix:R,scalar:F}=S(A),M=i.multiply(F),W=M.toBytes();return{head:N,prefix:R,scalar:F,point:M,pointBytes:W}}function d(A){return x(A).pointBytes}function w(A=Uint8Array.of(),...N){let R=zo(...N);return k(n(m(R,Y(A,void 0,\"context\"),!!s)))}function y(A,N,R={}){bt(R,{},{},\"options\"),A=fe(Y(A,void 0,\"message\")),s&&(A=s(A));let{prefix:F,scalar:M,pointBytes:W}=x(N),Z=w(R.context,F,A),et=i.multiply(Z).toBytes(),it=w(R.context,et,W,A),ct=a.create(Z+it*M);if(!a.isValid(ct))throw new Error(\"sign failed: invalid s\");let Ct=zo(et,a.toBytes(ct));return Y(Ct,b.signature,\"result\")}let v={zip215:o.zip215};function O(A,N,R,F=v){bt(F);let{context:M}=F,W=F.zip215===void 0?!!v.zip215:F.zip215,Z=b.signature;A=Y(A,Z,\"signature\"),N=Y(N,void 0,\"message\"),R=Y(R,b.publicKey,\"publicKey\"),W!==void 0&&zt(W,\"zip215\"),s&&(N=s(N));let et=Z/2,it=A.subarray(0,et),ct=Kt(A.subarray(et,Z)),Ct,pr,wn;try{Ct=r.fromBytes(R,W),pr=r.fromBytes(it,W),wn=i.multiplyUnsafe(ct)}catch{return!1}if(!W&&Ct.isSmallOrder())return!1;let wr=w(M,it,R,N);return pr.add(Ct.multiplyUnsafe(wr)).subtract(wn).clearCofactor().is0()}let E=c.BYTES,b={secretKey:E,publicKey:E,signature:2*E,seed:E};function T(A){return A=A===void 0?f(b.seed):A,Y(A,b.seed,\"seed\")}function B(A){return Sr(A)&&A.length===b.secretKey}function j(A,N){try{return!!r.fromBytes(A,N===void 0?v.zip215:N)}catch{return!1}}let P={getExtendedPublicKey:x,randomSecretKey:T,isValidSecretKey:B,isValidPublicKey:j,toMontgomery(A){if(h===void 0)throw new Error(\"Montgomery conversion is not supported for this curve\");return h(r.fromBytes(A))},toMontgomerySecret(A){if(p===void 0)throw new Error(\"Montgomery conversion is not supported for this curve\");return p(A)}};return Object.freeze(b),Object.freeze(P),Object.freeze({keygen:Nn(T,d),getPublicKey:d,sign:y,verify:O,utils:P,Point:r,lengths:b})}function Ir(r,t=\"n\"){if(typeof r!=\"number\")throw new TypeError(`wrong u32 integer \"${t}\": expected number, got type=${typeof r}`);if(!Number.isSafeInteger(r)||r<0||r>4294967295)throw new RangeError(`wrong u32 integer \"${t}\": expected 0..4294967295, got ${r}`);return r}function jc(r){return Ir(r,\"x\"),(r&r-1)===0&&r!==0}function ts(r,t){if(Ir(r),typeof t!=\"number\")throw new TypeError('\"bits\" expected number, got type='+typeof t);if(!Number.isSafeInteger(t)||t<0||t>32)throw new Error(`expected integer 0 <= bits <= 32, got ${t}`);let e=0;for(let n=0;n<t;n++,r>>>=1)e=e<<1|r&1;return e>>>0}function Ic(r){return Ir(r),31-Math.clz32(r)}function _c(r){if(!r||typeof r!=\"object\"||typeof r.length!=\"number\")throw new TypeError('\"values\" expected array-like, got type='+typeof r);let t=r.length;if(!jc(t))throw new Error(\"expected positive power-of-two length, got \"+t);let e=Ic(t);for(let n=0;n<t;n++){let o=ts(n,e);if(n<o){let s=r[n];r[n]=r[o],r[o]=s}}return r}var es=(r,t)=>{bt(t,{N:\"number\",roots:\"object\",dit:\"boolean\"},{invertButterflies:\"boolean\",skipStages:\"number\",brp:\"boolean\"},\"coreOpts\");let{N:e,roots:n,dit:o,invertButterflies:s=!1,skipStages:i=0,brp:c=!0}=t;Ir(e,\"coreOpts.N\");let a=Ic(e);if(!jc(e))throw new Error(\"FFT: Polynomial size should be power of two\");Ir(i,\"coreOpts.skipStages\");let u=a===0?0:a-1;if(i>u)throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${u}`);if(n.length!==e)throw new Error(`FFT: wrong roots length: expected ${e}, got ${n.length}`);let l=o!==s;return f=>{if(f.length!==e)throw new Error(\"FFT: wrong Polynomial length\");o&&c&&_c(f);for(let h=0,p=1;h<a-i;h++){let g=o?h+1+i:a-h,m=1<<g,k=m>>1,S=e>>g;for(let x=0;x<e;x+=m)for(let d=0,w=p++;d<k;d++){let y=s?o?e-w:w:d*S,v=x+d,O=x+d+k,E=n[y],b=f[O],T=f[v];if(l){let B=r.mul(b,E);f[v]=r.add(T,B),f[O]=r.sub(T,B)}else s?(f[v]=r.add(b,T),f[O]=r.mul(r.sub(b,T),E)):(f[v]=r.add(T,b),f[O]=r.mul(r.sub(T,b),E))}}return!o&&c&&_c(f),f}};var ke=BigInt(0),Et=BigInt(1),Fn=BigInt(2);function $c(r,t){return r+t-(t>>Et<<Et)}function zu(r){let t=BigInt(6)*r;return(e,n,o)=>{let s=n+o,c=((t+o-n)*e+n)%r;return{x_2:c,x_3:s-c}}}function Ku(r){return bt(r,{P:\"bigint\",type:\"string\",adjustScalarBytes:\"function\",powPminus2:\"function\"},{randomBytes:\"function\",scalarMultBase:\"function\"}),Object.freeze({...r})}function Nc(r){let t=Ku(r),{P:e,type:n,adjustScalarBytes:o,powPminus2:s,randomBytes:i}=t,c=t.scalarMultBase,a=n===\"x25519\";if(!a&&n!==\"x448\")throw new Error(\"invalid type\");let u=i===void 0?Tr:i,l=a?255:448,f=zu(e),h=a?32:56,p=BigInt(a?9:5),g=BigInt(a?121665:39081),m=a?Fn**BigInt(254):Fn**BigInt(447),k=a?BigInt(8)*(Fn**BigInt(251)-Et):BigInt(4)*(Fn**BigInt(445)-Et),S=m+k+Et,x=R=>H(R,e),d=w(p);function w(R){return Rn(x(R),h)}function y(R){let F=fe(Y(R,h,\"uCoordinate\"));return a&&(F[31]&=127),x(Kt(F))}function v(R){return Kt(o(fe(Y(R,h,\"scalar\"))))}let O=new Set(a?[ke,Et,e-Et,BigInt(\"325606250916557431795983626356110631294008115727848805560023387167927233504\"),BigInt(\"39382357235489614581723060781553021112529911719440698176882885853963445705823\")]:[ke,Et,e-Et]);function E(R,F){let M=y(F);if(O.has(M))throw new Error(\"invalid private or public key received\");let W=j(M,v(R));if(W===ke)throw new Error(\"invalid private or public key received\");return w(W)}function b(R){if(c===void 0)return E(R,d);let F=v(R);xe(\"scalar\",F,m,S);let M=x(c(F));if(M===ke)throw new Error(\"invalid private or public key received\");return w(M)}let T=b,B=E;function j(R,F){xe(\"u\",R,ke,e),xe(\"scalar\",F,m,S);let M=F,W=R,Z=Et,et=ke,it=R,ct=Et,Ct=M^M>>Et;for(let wr=BigInt(l-1);wr>=ke;wr--){let So=$c(e,Ct>>wr);({x_2:Z,x_3:it}=f(So,Z,it)),{x_2:et,x_3:ct}=f(So,et,ct);let yn=Z+et,To=x(yn*yn),Ro=Z-et,$i=x(Ro*Ro),Ni=To-$i,Za=it+ct,Xa=it-ct,Li=x(Xa*yn),Di=x(Za*Ro),Pi=Li+Di,Fi=Li-Di;it=x(Pi*Pi),ct=x(W*x(Fi*Fi)),Z=x(To*$i),et=x(Ni*(To+x(g*Ni)))}let pr=$c(e,M);({x_2:Z,x_3:it}=f(pr,Z,it)),{x_2:et,x_3:ct}=f(pr,et,ct);let wn=s(et);return x(Z*wn)}let P={secretKey:h,publicKey:h,seed:h},A=R=>(R=R===void 0?u(h):R,Y(R,P.seed,\"seed\"),R),N={randomSecretKey:A};return Object.freeze(P),Object.freeze(N),Object.freeze({keygen:Nn(A,T),getSharedSecret:B,getPublicKey:T,scalarMult:E,scalarMultBase:b,utils:N,GuBytes:d.slice(),lengths:P})}var Lc=BigInt(0),rs=BigInt(1),Dc=BigInt(2),Wu=BigInt(3),Gu=BigInt(5),Zu=BigInt(8),Mn=BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed\"),Xu={p:Mn,n:BigInt(\"0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed\"),h:Zu,a:BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec\"),d:BigInt(\"0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3\"),Gx:BigInt(\"0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a\"),Gy:BigInt(\"0x6666666666666666666666666666666666666666666666666666666666666658\")};function Mc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Mn,c=r*r%s*r%s,a=xt(c,Dc,s)*c%s,u=xt(a,rs,s)*r%s,l=xt(u,Gu,s)*u%s,f=xt(l,t,s)*l%s,h=xt(f,e,s)*f%s,p=xt(h,n,s)*h%s,g=xt(p,o,s)*p%s,m=xt(g,o,s)*p%s,k=xt(m,t,s)*l%s;return{pow_p_5_8:xt(k,Dc,s)*r%s,b2:c}}function ns(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Pc=BigInt(\"19681161376707505956807079304988542015446066515923890162744021073123829784752\");function Yu(r,t){let e=Mn,n=H(t*t*t,e),o=H(n*n*t,e),s=Mc(r*o).pow_p_5_8,i=H(r*n*s,e),c=H(t*i*i,e),a=i,u=H(i*Pc,e),l=c===r,f=c===H(-r,e),h=c===H(-r*Pc,e);return l&&(i=a),(f||h)&&(i=u),bc(i,e)&&(i=H(-i,e)),{isValid:l||f,value:i}}var $r=Tc(Xu,{uvRatio:Yu}),Fc=$r.Fp;function Vu(r){let{y:t}=r;return Fc.toBytes(Fc.div(rs+t,rs-t))}function Ju(r){let t=$r.Fp.BYTES;return z(r,t),ns(Ho(r.subarray(0,t))).subarray(0,t)}function Qu(r){return Rc($r,Ho,Object.assign({adjustScalarBytes:ns,toMontgomery:Vu,toMontgomerySecret:Ju,zip215:!0},r))}var Ve=Qu({});var os=(()=>{let r=Mn,t=e=>{let{pow_p_5_8:n,b2:o}=Mc(e);return H(xt(n,Wu,r)*o,r)};return Nc({P:r,type:\"x25519\",powPminus2:t,adjustScalarBytes:ns,scalarMultBase:e=>{let n=H(e,$r.Fn.ORDER);if(n===Lc)return Lc;let o=$r.BASE.multiply(n);return H((o.Z+o.Y)*t(H(o.Z-o.Y,r)),r)}})})();var Je=async r=>{if(r.length!==32)throw new TypeError(\"a secret is thirty-two bytes\");return os.getPublicKey(r)},Un=async(r,t)=>{if(t.length!==32||r.length!==32)return null;try{let e=os.getSharedSecret(r,t);return yr(e)?null:e}catch{return null}};var Wt=2n**255n-19n,Uc=2n**252n+27742317777372353535851937790883648493n,J=r=>(r%Wt+Wt)%Wt,Nr=(r,t)=>{let e=1n,n=J(r);for(let o=t;o>0n;o>>=1n)o&1n&&(e=e*n%Wt),n=n*n%Wt;return e},Hc=J(-121665n*Nr(121666n,Wt-2n)),tl=Nr(2n,(Wt-1n)/4n),ss=r=>r.reduceRight((t,e)=>t<<8n|BigInt(e),0n),Cc=r=>{if(r.length!==32)return null;let t=(r[31]&128)!==0,e=ss(r)&(1n<<255n)-1n;if(e>=Wt)return null;let n=J(e*e-1n),o=J(Hc*e*e+1n),s=J(n*Nr(o,3n)*Nr(n*Nr(o,7n),(Wt-5n)/8n)),i=J(o*s*s);if(i===J(-n))s=J(s*tl);else if(i!==n)return null;return s===0n&&t?null:((s&1n)!==(t?1n:0n)&&(s=J(-s)),{x:s,y:e,z:1n,t:J(s*e)})},el=(r,t)=>{let e=J((r.y-r.x)*(t.y-t.x)),n=J((r.y+r.x)*(t.y+t.x)),o=J(2n*Hc*r.t*t.t),s=J(2n*r.z*t.z),[i,c,a,u]=[n-e,s-o,s+o,n+e];return{x:J(i*c),y:J(a*u),z:J(c*a),t:J(i*u)}},rl=r=>{let t=r;for(let e=0;e<3;e+=1)t=el(t,t);return t.x===0n&&t.y===t.z},qc=r=>{if(r.length!==32)throw new TypeError(\"a secret is thirty-two bytes\");return r},is=async r=>Ve.getPublicKey(qc(r)),cs=async(r,t)=>Ve.sign(t,qc(r)),as=async(r,t,e)=>{if(e.length!==64)return!1;let n=Cc(r);if(n===null||rl(n)||Cc(e.subarray(0,32))===null)return!1;let o=ss(e.subarray(32));if(o>=Uc)return!1;let s=Ve.Point.fromBytes(e.subarray(0,32)),i=Ve.Point.fromBytes(r),c=new Uint8Array(await gt().digest(\"SHA-512\",rt(C(e.subarray(0,32),r,t)))),a=ss(c)%Uc;return Ve.Point.BASE.multiplyUnsafe(o).equals(s.add(i.multiplyUnsafe(a)))};var nl=BigInt(0),Lr=BigInt(1),ol=BigInt(2),sl=BigInt(7),il=BigInt(256),cl=BigInt(113),Wc=[],Gc=[],Zc=[];for(let r=0,t=Lr,e=1,n=0;r<24;r++){[e,n]=[n,(2*e+3*n)%5],Wc.push(2*(5*n+e)),Gc.push((r+1)*(r+2)/2%64);let o=nl;for(let s=0;s<7;s++)t=(t<<Lr^(t>>sl)*cl)%il,t&ol&&(o^=Lr<<(Lr<<BigInt(s))-Lr);Zc.push(o)}var Xc=bn(Zc,!0),al=Xc[0],ul=Xc[1],ll=(r,t,e)=>r<<e|t>>>32-e,fl=(r,t,e)=>t<<e|r>>>32-e,dl=(r,t,e)=>t<<e-32|r>>>64-e,hl=(r,t,e)=>r<<e-32|t>>>64-e,zc=(r,t,e)=>e>32?dl(r,t,e):ll(r,t,e),Kc=(r,t,e)=>e>32?hl(r,t,e):fl(r,t,e),Qe=new Uint32Array(10);function pl(r,t=24){if(!(r instanceof Uint32Array))throw new TypeError('\"s\" expected Uint32Array(50), got type='+typeof r);if(r.length!==50)throw new RangeError('\"s\" expected Uint32Array(50), got length='+r.length);if(at(t,\"rounds\"),t<1||t>24)throw new Error('\"rounds\" expected integer 1..24');for(let e=24-t;e<24;e++){for(let s=0;s<10;s++)Qe[s]=r[s]^r[s+10]^r[s+20]^r[s+30]^r[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,c=(s+2)%10,a=Qe[c],u=Qe[c+1],l=zc(a,u,1)^Qe[i],f=Kc(a,u,1)^Qe[i+1];for(let h=0;h<50;h+=10)r[s+h]^=l,r[s+h+1]^=f}let n=r[2],o=r[3];for(let s=0;s<24;s++){let i=Gc[s],c=zc(n,o,i),a=Kc(n,o,i),u=Wc[s];n=r[u],o=r[u+1],r[u]=c,r[u+1]=a}for(let s=0;s<50;s+=10){let i=r[s],c=r[s+1],a=r[s+2],u=r[s+3];r[s]^=~r[s+2]&r[s+4],r[s+1]^=~r[s+3]&r[s+5],r[s+2]^=~r[s+4]&r[s+6],r[s+3]^=~r[s+5]&r[s+7],r[s+4]^=~r[s+6]&r[s+8],r[s+5]^=~r[s+7]&r[s+9],r[s+6]^=~r[s+8]&i,r[s+7]^=~r[s+9]&c,r[s+8]^=~i&a,r[s+9]^=~c&u}r[0]^=al[e],r[1]^=ul[e]}Ge(Qe)}var Cn=class r{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;enableXOF=!1;rounds;constructor(t,e,n,o=!1,s=24){if(at(t,\"blockLen\"),at(e,\"suffix\"),at(s,\"rounds\"),ec(o,\"enableXOF\"),this.blockLen=t,this.suffix=e,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,at(n,\"outputLen\"),!(0<t&&t<200))throw new Error('\"blockLen\" must be 1..199');this.state=new Uint8Array(200),this.state32=Or(this.state)}clone(){return this._cloneInto()}keccak(){Ze(this.state32),pl(this.state32,this.rounds),Ze(this.state32),this.posOut=0,this.pos=0}update(t){We(this),z(t);let{blockLen:e,state:n,state32:o}=this,s=t.length,i=e%4===0&&t.byteOffset%4===0,c=e/4,a=i&&s>=e?Or(t):void 0;for(let u=0;u<s;){if(a!==void 0&&this.pos===0&&u%4===0&&s-u>=e){for(let f=0,h=u/4;f<c;f++)o[f]^=a[h+f];u+=e,this.pos=e,this.keccak();continue}let l=Math.min(e-this.pos,s-u);for(let f=0;f<l;f++)n[this.pos++]^=t[u++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:t,suffix:e,pos:n,blockLen:o}=this;t[n]^=e,(e&128)!==0&&n===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){We(this,!1),z(t),this.finish();let e=this.state,{blockLen:n}=this;for(let o=0,s=t.length;o<s;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,s-o);t.set(e.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error(\"XOF is not enabled\");return this.writeInto(t)}xof(t){return at(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(En(t,this),this.finished)throw new Error(\"digest() was already called\");this.writeInto(t.length===this.outputLen?t:t.subarray(0,this.outputLen)),this.destroy()}digest(){let t=new Uint8Array(this.outputLen);return this.digestInto(t),t}destroy(){this.destroyed=!0,Ge(this.state)}_cloneInto(t){let{blockLen:e,suffix:n,outputLen:o,rounds:s,enableXOF:i}=this;return t||=new r(e,n,o,i,s),t.blockLen=e,t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=n,t.outputLen=o,t.enableXOF=i,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}},Yc=(r,t,e,n={})=>Ar(()=>new Cn(t,r,e),n);var Vc=Yc(6,136,32,ge(8));var Jc=Yc(6,72,64,ge(10));var Qc=(r,t,e,n={})=>Ar((o={})=>(o=Mo({},o),new Cn(t,r,o.dkLen===void 0?e:o.dkLen,!0)),n),ta=Qc(31,168,16,ge(11)),Hn=Qc(31,136,32,ge(12));var At=z;var qn=An;function wl(r,t,e=()=>{}){if(!Array.isArray(r))throw new TypeError(`\"${t}\" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)e(r[n],`${t}[${n}]`);return r}function Oe(r,t){if(r=z(r),t=z(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function us(r){return new Uint8Array(z(r))}function Dr(r,...t){let e=o=>typeof o==\"number\"?o:o.bytesLen,n=t.reduce((o,s)=>o+e(s),0);return{bytesLen:n,encode:o=>{let s=new Uint8Array(n);for(let i=0,c=0;i<t.length;i++){let a=t[i],u=e(a),l=typeof a==\"number\"?o[i]:a.encode(o[i]);z(l,u,r),s.set(l,c),typeof a!=\"number\"&&l.fill(0),c+=u}return s},decode:o=>{z(o,n,r);let s=[];for(let i of t){let c=e(i),a=o.subarray(0,c);s.push(typeof i==\"number\"?a:i.decode(a)),o=o.subarray(c)}return s}}}function zn(r,t){let e=r,n=t*e.bytesLen;return{bytesLen:n,encode:o=>{let s=wl(o,\"u\");if(s.length!==t)throw new RangeError(`vecCoder.encode: wrong length=${s.length}. Expected: ${t}`);let i=new Uint8Array(n);for(let c=0,a=0;c<s.length;c++){let u=e.encode(s[c]);i.set(u,a),u.fill(0),a+=u.length}return i},decode:o=>{z(o,n);let s=[];for(let i=0;i<o.length;i+=e.bytesLen)s.push(e.decode(o.subarray(i,i+e.bytesLen)));return s}}}function Q(...r){for(let t of r)if(Array.isArray(t))for(let e of t)e.fill(0);else t.fill(0)}function Kn(r){if(at(r,\"bits\"),r>32)throw new RangeError('\"bits\" expected <= 32, got '+r);return r===32?4294967295:~(-1<<r)>>>0}var ea=r=>{let{newPoly:t,N:e,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:c}=r,a=(d,w=n)=>{let y=d%w|0;return(y>=0?y|0:w+y|0)|0},u=(d,w=n)=>{let y=a(d,w)|0;return(y>w>>1?y-w|0:y)|0};function l(){let d=t(e);for(let w=0;w<e;w++){let y=ts(w,i),v=BigInt(s)**BigInt(y)%BigInt(n);d[w]=Number(v)|0}return d}let f=l(),h=d=>{throw new Error(\"not implemented\")},p=c?{add:(d,w)=>{let y=d+w|0;return y>=n?y-n|0:y},sub:(d,w)=>{let y=d-w|0;return y<0?y+n|0:y},mul:(d,w)=>a((d|0)*(w|0))|0,inv:h}:{add:(d,w)=>a((d|0)+(w|0))|0,sub:(d,w)=>a((d|0)-(w|0))|0,mul:(d,w)=>a((d|0)*(w|0))|0,inv:h},g={N:e,roots:f,invertButterflies:!0,skipStages:c?1:0,brp:!1},m=es(p,{dit:!1,...g}),k=es(p,{dit:!0,...g}),S={encode:d=>m(d),decode:d=>{k(d);for(let w=0;w<d.length;w++)d[w]=a(o*d[w]);return d}};return{mod:a,smod:u,nttZetas:f,NTT:{encode:d=>S.encode(d),decode:d=>S.decode(d)},bitsCoder:(d,w)=>{for(let O=0,E=0;O<e;O++)E+=d,E>32&&Kn(E),E%=8;let y=Kn(d),v=d*(e/8);return{bytesLen:v,encode:O=>{let E=O,b=new Uint8Array(v);for(let T=0,B=0,j=0,P=0;T<E.length;T++)for(B|=(w.encode(E[T])&y)<<j,j+=d;j>=8;j-=8,B>>=8)b[P++]=B&255;return b},decode:O=>{let E=t(e);for(let b=0,T=0,B=0,j=0;b<O.length;b++)for(T|=O[b]<<B,B+=8;B>=d;B-=d,T>>=d)E[j++]=w.decode(T&y);return E}}}}},yl=r=>(t,e)=>{e||(e=r.blockLen);let n=new Uint8Array(t.length+2);n.set(t);let o=t.length,s=new Uint8Array(e),i=r.create({}),c=0,a=0;return{stats:()=>({calls:c,xofs:a}),get:(u,l)=>(n[o+0]=u,n[o+1]=l,i.destroy(),i=r.create({}).update(n),c++,()=>(a++,i.xofInto(s))),clean:()=>{i.destroy(),Q(s,n)}}},ra=yl(ta);var ot=256,nt=3329,ml=3303,gl=17,ut=ea({N:ot,Q:nt,F:ml,ROOT_OF_UNITY:gl,newPoly:r=>new Uint16Array(r),brvBits:7,isKyber:!0}),bl=Object.freeze({512:Object.freeze({N:ot,Q:nt,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128}),768:Object.freeze({N:ot,Q:nt,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192}),1024:Object.freeze({N:ot,Q:nt,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256})}),xl=r=>{if(r>=12)return{encode:e=>e,decode:e=>e>=nt?e-nt:e};let t=2**(r-1);return{encode:e=>((e<<r)+nt/2)/nt,decode:e=>e*nt+t>>>r}},El=r=>ut.bitsCoder(r,r===12?{encode:t=>t,decode:t=>t>=nt?t-nt:t}:{encode:t=>t,decode:t=>t}),Pr=r=>r===12?El(12):ut.bitsCoder(r,xl(r));function ve(r,t){let e=r,n=t;for(let o=0;o<ot;o++){let s=e[o]+n[o];e[o]=s>=nt?s-nt:s}}function kl(r,t){let e=r,n=t;for(let o=0;o<ot;o++){let s=e[o]-n[o];e[o]=s<0?s+nt:s}}function Ol(r,t,e,n,o){let s=ut.mod(ut.mod(t*n)*o+r*e),i=ut.mod(r*n+t*e);return{c0:s,c1:i}}function Wn(r,t){let e=r,n=t;for(let o=0;o<ot/2;o++){let s=ut.nttZetas[64+(o>>1)];o&1&&(s=-s);let{c0:i,c1:c}=Ol(e[2*o+0],e[2*o+1],n[2*o+0],n[2*o+1],s);e[2*o+0]=i,e[2*o+1]=c}return e}function ls(r){let t=r,e=new Uint16Array(ot);for(let n=0;n<ot;){let o=t();if(o.length%3)throw new Error(\"SampleNTT: unaligned block\");for(let s=0;n<ot&&s+3<=o.length;s+=3){let i=(o[s+0]>>0|o[s+1]<<8)&4095,c=(o[s+1]>>4|o[s+2]<<4)&4095;i<nt&&(e[n++]=i),n<ot&&c<nt&&(e[n++]=c)}}return e}var vl=(r,t)=>{let e=new Uint16Array(ot),n=Or(r);Ze(n);let o=0;for(let s=0,i=0,c=0,a=0;s<n.length;s++){let u=n[s];for(let l=0;l<32;l++)c+=u&1,u>>=1,o+=1,o===t?(a=c,c=0):o===2*t&&(e[i++]=ut.mod(a-c),c=0,o=0)}if(Ze(n),o)throw new Error(`sampleCBD: leftover bits: ${o}`);return e};function Fr(r,t,e,n){return vl(r(n*ot/4,t,e),n)}var Al=r=>{let t=r,{K:e,PRF:n,XOF:o,HASH512:s,ETA1:i,ETA2:c,du:a,dv:u}=t,l=Pr(1),f=Pr(u),h=Pr(a),p=Dr(\"publicKey\",zn(Pr(12),e),32),g=zn(Pr(12),e),m=Dr(\"ciphertext\",zn(h,e),f),k=Dr(\"seed\",32,32),S=(x,d,w,y)=>{let v=[];for(let B=0;B<e;B++)v.push(ut.NTT.encode(Fr(n,y,B,i)));let O=new Uint16Array(ot),E=[];for(let B=0;B<e;B++){let j=Fr(n,y,e+B,c),P=new Uint16Array(ot);for(let A=0;A<e;A++){let N=d(B,A);ve(P,Wn(N,v[A]))}ve(j,ut.NTT.decode(P)),E.push(j),ve(O,Wn(x[B],v[B])),Q(P)}let b=Fr(n,y,2*e,c);ve(b,ut.NTT.decode(O));let T=l.decode(w);return ve(T,b),Q(x,v,O,b),m.encode([E,T])};return{secretCoder:g,lengths:{secretKey:g.bytesLen,publicKey:p.bytesLen,cipherText:m.bytesLen},keygen:x=>{At(x,32,\"seed\");let d=new Uint8Array(33);d.set(x),d[32]=e;let w=s(d),[y,v]=k.decode(w),O=[],E=[];for(let B=0;B<e;B++)O.push(ut.NTT.encode(Fr(n,v,B,i)));let b=o(y);for(let B=0;B<e;B++){let j=ut.NTT.encode(Fr(n,v,e+B,i));for(let P=0;P<e;P++){let A=ls(b.get(P,B));ve(j,Wn(A,O[P]))}E.push(j)}b.clean();let T={publicKey:p.encode([E,y]),secretKey:g.encode(O)};return Q(y,v,O,E,d,w),T},encrypt:(x,d,w)=>{let[y,v]=p.decode(x),O=o(v),E=S(y,(b,T)=>ls(O.get(b,T)),d,w);return O.clean(),E},prepare:x=>{let[d,w]=p.decode(x),y=o(w),v=[];for(let O=0;O<e;O++)for(let E=0;E<e;E++)v.push(ls(y.get(O,E)));return y.clean(),{encrypt:(O,E)=>S(d.map(b=>b.slice()),(b,T)=>v[b*e+T].slice(),O,E),clean:()=>Q(d,v)}},decrypt:(x,d)=>{let[w,y]=m.decode(x),v=g.decode(d),O=new Uint16Array(ot);for(let b=0;b<e;b++)ve(O,Wn(v[b],ut.NTT.encode(w[b])));kl(y,ut.NTT.decode(O));let E=l.encode(y);return Q(O,v,w,y),E}}};function Bl(r){let t=r,e=Al(t),{HASH256:n,HASH512:o,KDF:s}=t,{secretCoder:i,lengths:c}=e,a=Dr(\"secretKey\",c.secretKey,c.publicKey,32,32),u=32,l=64,f=(p,g)=>{let m=p.subarray(0,384*t.K),k=i.encode(i.decode(us(m))),S=Oe(k,m);if(Q(k),!S)throw new Error(`ML-KEM.${g}: wrong publicKey modulus`)},h=Object.freeze({...c,seed:64,msg:u,msgRand:u,secretKey:a.bytesLen});return Object.freeze({info:Object.freeze({type:\"ml-kem\"}),lengths:h,keygen:p=>{let g=p===void 0,m=g?qn(l):p,k,S;try{At(m,l,\"seed\");let x=e.keygen(m.subarray(0,32)),d=x.publicKey;k=x.secretKey,S=n(d);let w=a.encode([k,d,S,m.subarray(32)]);return{publicKey:d,secretKey:w}}finally{k!==void 0&&Q(k),S!==void 0&&Q(S),g&&Q(m)}},getPublicKey:p=>{let[g,m,k,S]=a.decode(p);return Uint8Array.from(m)},encapsulate:(p,g)=>{let m=g===void 0,k=m?qn(u):g,S;try{return At(p,c.publicKey,\"publicKey\"),At(k,u,\"message\"),f(p,\"encapsulate\"),S=o.create().update(k).update(n(p)).digest(),{cipherText:e.encrypt(p,k,S.subarray(32,64)),sharedSecret:S.subarray(0,32)}}finally{S!==void 0&&Q(S.subarray(32)),m&&Q(k)}},decapsulate:(p,g)=>{At(g,a.bytesLen,\"secretKey\"),At(p,c.cipherText,\"cipherText\");let m=a.bytesLen-96,k=m+32,S=n(g.subarray(m/2,k));if(!Oe(S,g.subarray(k,k+32)))throw new Error(\"invalid secretKey: hash check failed\");let[x,d,w,y]=a.decode(g),v=e.decrypt(p,x),O=o.create().update(v).update(w).digest(),E=O.subarray(0,32),b=e.encrypt(d,v,O.subarray(32,64)),T=Oe(p,b),B=s.create({dkLen:32}).update(y).update(p).digest();return Q(v,b,O.subarray(32),T?B:E),T?E:B},prepare:p=>{At(p,c.publicKey,\"publicKey\"),f(p,\"prepare\");let g=us(p),m=n(g),k=e.prepare(g);return Object.freeze({publicKey:g,encapsulate:S=>{let x=S===void 0,d=x?qn(u):S,w;try{return At(d,u,\"message\"),w=o.create().update(d).update(m).digest(),{cipherText:k.encrypt(d,w.subarray(32,64)),sharedSecret:w.subarray(0,32)}}finally{w!==void 0&&Q(w.subarray(32)),x&&Q(d)}},decapsulate:(S,x)=>{At(x,a.bytesLen,\"secretKey\"),At(S,c.cipherText,\"cipherText\");let[d,w,y,v]=a.decode(x);if(!Oe(w,g)||!Oe(y,m))throw new Error(\"ML-KEM.decapsulate: secretKey does not match prepared publicKey\");let O=e.decrypt(S,d),E=o.create().update(O).update(m).digest(),b=E.subarray(0,32),T=k.encrypt(O,E.subarray(32,64)),B=Oe(S,T),j=s.create({dkLen:32}).update(v).update(S).digest();return Q(O,T,E.subarray(32),B?j:b),B?b:j},clean:k.clean})}})}function Sl(r,t,e){return Hn.create({dkLen:r}).update(t).update(new Uint8Array([e])).digest()}var Tl={HASH256:Vc,HASH512:Jc,KDF:Hn,XOF:ra,PRF:Sl},Rl=r=>Bl({...Tl,...r});var Gn=Rl(bl[768]);var Zn=1184,tr=1088,fs=(r,t)=>{let{publicKey:e,secretKey:n}=Gn.keygen(Uint8Array.from([...r,...t]));return{ek:e,dk:n}},Mr=(r,t)=>{if(r.length!==Zn)return null;try{let{cipherText:e,sharedSecret:n}=Gn.encapsulate(r,t);return{ciphertext:e,shared:n}}catch{return null}},ds=(r,t)=>{if(t.length!==tr)return null;try{return Gn.decapsulate(t,r)}catch{return null}};var Xn=\"org.nervur.\",_l=/^[a-z0-9][a-z0-9-]*(?:\\.[a-z0-9][a-z0-9-]*){2,}$/,Yn=r=>typeof r==\"string\"&&_l.test(r),Gt=r=>{if(typeof r!=\"function\"||!Object.hasOwn(r,\"kind\"))return;let t=r.kind;return Yn(t)?t:void 0},na=Symbol.for(\"org.nervur.ships\"),U=r=>{Object.defineProperty(r,na,{value:!0})},er=r=>typeof r==\"function\"&&Object.hasOwn(r,na),Zt=r=>{let t=Gt(r);if(t===void 0)throw new Error(`class ${typeof r==\"function\"?r.name:String(r)} declares no kind of its own`);return t};var jl=new Set([\"answer\",\"describe\",\"stance\",\"cells\",\"notes\",\"constructor\"]),Il=(r,t)=>{for(let e=Object.getPrototypeOf(r);e!==null&&e!==Object.prototype;e=Object.getPrototypeOf(e))if(Object.hasOwn(e,t))return typeof e[t]==\"function\";return!1},Xt=class{static kind=\"org.nervur.being\";static{U(this)}static cells={};static asks={};stance;constructor(t){this.stance=t;let e=this.constructor;for(let n of Object.keys(e.asks)){if(jl.has(n))throw new Error(`ask '${n}' is a reserved name`);if(!Il(this,n))throw new Error(`ask '${n}' has no method`)}for(let[n,o]of Object.entries(e.cells))Object.hasOwn(t.cells,n)||(t.cells[n]=structuredClone(o))}get cells(){return this.stance.cells}notes(t){return t.id===void 0?void 0:this.stance.occupants.notes(t.id)}describe(t){let e=this.constructor,n=this.notes(t),o=[];for(let[s,i]of Object.entries(e.asks))i.for&&!i.for(t,n)||o.push({name:s,...i.description===void 0?{}:{description:i.description},input:i.input??{type:\"object\"}});return{asks:o,notes:{}}}async answer(t,e,n){if(e===void 0)return this.describe(t);let o=this.constructor,s=Object.hasOwn(o.asks,e)?o.asks[e]:void 0;return!s||s.for&&!s.for(t,this.notes(t))?{error:\"unknown ask\"}:this[e].call(this,n,t)}};var rr=r=>Array.isArray(r)?`[${r.map(rr).join(\",\")}]`:r!==null&&typeof r==\"object\"?`{${Object.keys(r).sort().map(t=>`${JSON.stringify(t)}:${rr(r[t])}`).join(\",\")}}`:JSON.stringify(r),Ur=async r=>_(await se(I(rr(r))));var Bt=\"OWNER\",D=\"ward\";var G=class r extends Xt{static kind=\"org.nervur.faculty\";static{U(this)}static contracts(t){let e=[];for(let n=t;typeof n==\"function\"&&n!==r;n=Object.getPrototypeOf(n))e.push(Zt(n));return e}static fulfils(t){return typeof t==\"function\"&&t.prototype instanceof r}#t(){return this.cells.offers===void 0&&(this.cells.offers={}),this.cells.offers}async#e(){let t=(this.cells.offered??0)+1;this.cells.offered=t;let e=`lent:${t}`,n=await this.stance.occupants.invite(e);return n===null?{error:\"not invited\"}:(this.#t()[n.heir]=e,{invitation:n})}#r(t){let e=this.#t(),n=typeof t.heir==\"string\"&&Object.hasOwn(e,t.heir)?e[t.heir]:void 0;return n===void 0?{retracted:null}:(this.stance.occupants.remove(n),delete e[t.heir],{retracted:n})}describe(t){let e=super.describe(t);return t.id!==D?e:{...e,asks:[...e.asks,{name:\"offer\",input:{type:\"object\"}},{name:\"retract\",input:{type:\"object\",required:[\"heir\"]}}]}}answer(t,e,n){if(t.id===D&&e===\"offer\")return this.#e();if(t.id===D&&e===\"retract\")return Promise.resolve(this.#r(n));let o=this.#t();for(let[s,i]of Object.entries(o))i===t.id&&delete o[s];return super.answer(t,e,n)}};var ht=Symbol.for(\"nervur.silence\"),St=r=>r===ht,hs=Symbol.for(\"nervur.word\"),oa=new Map,pt=r=>{let t=oa.get(r);return t||oa.set(r,t=Object.freeze({[hs]:r})),t},wt=r=>typeof r==\"object\"&&r!==null&&typeof r[hs]==\"string\",de=r=>wt(r)?r[hs]:r;var sa=async(r,t)=>{let e=t.writable.getWriter();return e.write(rt(r)).catch(()=>{}),e.close().catch(()=>{}),new Uint8Array(await new Response(t.readable).arrayBuffer())},ys=r=>sa(r,new CompressionStream(\"deflate\")),ms=async r=>{try{return await sa(r,new DecompressionStream(\"deflate\"))}catch{throw new Error(\"bytes that do not inflate\")}},$l=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],Nl=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Ll=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Dl=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Pl=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Vn=15,Cr=r=>{let t=new Uint16Array(Vn+1);for(let o=0;o<r.length;o+=1)t[r[o]]+=1;let e=new Uint16Array(Vn+1);for(let o=1;o<Vn;o+=1)e[o+1]=e[o]+t[o];let n=new Uint16Array(r.length);for(let o=0;o<r.length;o+=1)r[o]!==0&&(n[e[r[o]]++]=o);return t[0]=0,{count:t,symbol:n}},Fl=Cr(Array.from({length:288},(r,t)=>t<144?8:t<256?9:t<280?7:8)),Ml=Cr(Array.from({length:30},()=>5)),ps=class{#t;at;#e=0;#r=0;constructor(t,e){this.#t=t,this.at=e}bits(t){for(;this.#r<t;){if(this.at>=this.#t.length)throw new Error(\"a stream cut short\");this.#e|=this.#t[this.at++]<<this.#r,this.#r+=8}let e=this.#e&(1<<t)-1;return this.#e>>>=t,this.#r-=t,e}align(){this.#e=0,this.#r=0}byte(){if(this.at>=this.#t.length)throw new Error(\"a stream cut short\");return this.#t[this.at++]}decode(t){let e=0,n=0,o=0;for(let s=1;s<=Vn;s+=1){e|=this.bits(1);let i=t.count[s];if(e-i<n)return t.symbol[o+(e-n)];o+=i,n+=i,n<<=1,e<<=1}throw new Error(\"a code no table holds\")}},ws=class{bytes=new Uint8Array(1024);length=0;#t(t){if(this.length+t<=this.bytes.length)return;let e=this.bytes.length*2;for(;e<this.length+t;)e*=2;let n=new Uint8Array(e);n.set(this.bytes.subarray(0,this.length)),this.bytes=n}push(t){this.#t(1),this.bytes[this.length++]=t}copy(t,e){if(t>this.length)throw new Error(\"a distance before the start\");this.#t(e);for(let n=0;n<e;n+=1)this.bytes[this.length]=this.bytes[this.length++-t]}},Ul=r=>{let t=r.bits(5)+257,e=r.bits(5)+1,n=r.bits(4)+4,o=new Uint8Array(19);for(let c=0;c<n;c+=1)o[Pl[c]]=r.bits(3);let s=Cr(o),i=new Uint8Array(t+e);for(let c=0;c<t+e;){let a=r.decode(s);if(a<16){i[c++]=a;continue}let u,l=0;if(a===16){if(c===0)throw new Error(\"a repeat with nothing before it\");l=i[c-1],u=3+r.bits(2)}else a===17?u=3+r.bits(3):u=11+r.bits(7);if(c+u>t+e)throw new Error(\"too many lengths\");for(;u-- >0;)i[c++]=l}return[Cr(i.subarray(0,t)),Cr(i.subarray(t))]},Cl=r=>{let t=1,e=0;for(let n=0;n<r.length;n+=1)t=(t+r[n])%65521,e=(e+t)%65521;return(e<<16|t)>>>0},gs=(r,t)=>{let e=new ps(r,t),n=e.byte(),o=e.byte();if((n&15)!==8||(n<<8|o)%31!==0||(o&32)!==0)throw new Error(\"no zlib stream\");let s=new ws;for(let a=0;a===0;){a=e.bits(1);let u=e.bits(2);if(u===0){e.align();let h=e.byte()|e.byte()<<8,p=e.byte()|e.byte()<<8;if((h^65535)!==p)throw new Error(\"a stored block whose length does not check\");for(let g=0;g<h;g+=1)s.push(e.byte());continue}if(u===3)throw new Error(\"a block of no type\");let[l,f]=u===1?[Fl,Ml]:Ul(e);for(;;){let h=e.decode(l);if(h<256)s.push(h);else{if(h===256)break;{let p=h-257;if(p>=29)throw new Error(\"a length of no code\");let g=$l[p]+e.bits(Nl[p]),m=e.decode(f);if(m>=30)throw new Error(\"a distance of no code\");s.copy(Ll[m]+e.bits(Dl[m]),g)}}}}e.align();let i=(e.byte()<<24|e.byte()<<16|e.byte()<<8|e.byte())>>>0,c=s.bytes.slice(0,s.length);if(i!==Cl(c))throw new Error(\"a stream whose sum does not check\");return{out:c,end:e.at}};var Hl=[\"blob\",\"tree\",\"commit\",\"tag\"];var ql=new TextDecoder(\"utf-8\",{fatal:!0}),Yt=r=>ql.decode(r),Jn=async r=>_(new Uint8Array(await gt().digest(\"SHA-1\",rt(r)))),Vt=r=>typeof r==\"string\"&&/^[0-9a-f]{40}$/.test(r),bs=r=>C(I(`${r.type} ${String(r.body.length)}\\0`),r.body),Ft=r=>Jn(bs(r)),ua=r=>{let t=r.indexOf(0),e=t<0?\"\":Yt(r.subarray(0,t)),[n,o]=e.split(\" \"),s=r.subarray(t+1);if(!Hl.includes(n)||String(s.length)!==o)throw new Error(\"no loose object\");return{type:n,body:s.slice()}},xs=r=>ys(bs(r)),Es=async r=>ua(await ms(r)),Hr=r=>({type:\"blob\",body:I(r)}),ks=\"100644\",nr=\"40000\",ia=r=>r.mode===nr?`${r.name}/`:r.name,zl=(r,t)=>{let[e,n]=[I(ia(r)),I(ia(t))];for(let o=0;o<Math.min(e.length,n.length);o+=1)if(e[o]!==n[o])return e[o]-n[o];return e.length-n.length},qr=r=>({type:\"tree\",body:C(...[...r].sort(zl).flatMap(t=>[I(`${t.mode} ${t.name}\\0`),$(t.id)]))}),Qn=r=>{if(r.type!==\"tree\")throw new Error(\"no tree\");let t=[];for(let e=0;e<r.body.length;){let n=r.body.indexOf(32,e),o=r.body.indexOf(0,n);if(n<0||o<0||o+21>r.body.length)throw new Error(\"a tree cut short\");t.push({mode:Yt(r.body.subarray(e,n)),name:Yt(r.body.subarray(n+1,o)),id:_(r.body.subarray(o+1,o+21))}),e=o+21}return t},ca=r=>`${r.name} <${r.email}> ${String(r.seconds)} ${r.zone}`,aa=r=>{let t=/^(.*) <([^>]*)> (\\d+) ([+-]\\d{4})$/.exec(r);if(!t)throw new Error(\"a signature git does not write\");return{name:t[1],email:t[2],seconds:Number(t[3]),zone:t[4]}},Os=r=>({type:\"commit\",body:I([`tree ${r.tree}`,...r.parents.map(t=>`parent ${t}`),`author ${ca(r.author)}`,`committer ${ca(r.committer)}`,\"\",r.message].join(`\n`))}),he=r=>{if(r.type!==\"commit\")throw new Error(\"no commit\");let t=Yt(r.body),e=t.indexOf(`\n\n`),n=e<0?t:t.slice(0,e),o=e<0?\"\":t.slice(e+2),s,i=[],c,a;for(let u of n.split(`\n`)){let l=u.indexOf(\" \"),[f,h]=[u.slice(0,l),u.slice(l+1)];f===\"tree\"?s=h:f===\"parent\"?i.push(h):f===\"author\"?c=aa(h):f===\"committer\"&&(a=aa(h))}if(!Vt(s)||!c||!a||!i.every(Vt))throw new Error(\"a commit git does not write\");return{tree:s,parents:i,author:c,committer:a,message:o}};var la={1:\"commit\",2:\"tree\",3:\"blob\",4:\"tag\"},Kl=6,Wl=7,fa=(r,t)=>{let e=0,n=()=>{let i=0,c=0;for(let a=128;a&128;c+=7)a=t[e++],i+=(a&127)*2**c;return i};if(n()!==r.length)throw new Error(\"a delta for another base\");let o=new Uint8Array(n()),s=0;for(;e<t.length;){let i=t[e++];if(i&128){let c=0,a=0;for(let u=0;u<4;u+=1)i&1<<u&&(c|=t[e++]<<8*u);for(let u=0;u<3;u+=1)i&16<<u&&(a|=t[e++]<<8*u);if(a===0&&(a=65536),c>>>=0,c+a>r.length||s+a>o.length)throw new Error(\"a delta copy past its bounds\");o.set(r.subarray(c,c+a),s),s+=a}else if(i!==0){if(e+i>t.length||s+i>o.length)throw new Error(\"a delta insert past its bounds\");o.set(t.subarray(e,e+i),s),s+=i,e+=i}else throw new Error(\"a delta op of nothing\")}if(s!==o.length)throw new Error(\"a delta short of its size\");return o},vs=async(r,t=()=>Promise.resolve(null))=>{if(r.length<32||new TextDecoder().decode(r.subarray(0,4))!==\"PACK\")throw new Error(\"no pack\");let e=f=>(r[f]<<24|r[f+1]<<16|r[f+2]<<8|r[f+3])>>>0;if(e(4)!==2)throw new Error(\"a pack of another version\");let n=e(8),o=r.subarray(0,r.length-20);if(await Jn(o)!==_(r.subarray(r.length-20)))throw new Error(\"a pack whose sum does not check\");let s=new Map,i=12;for(let f=0;f<n;f+=1){let h=i,p=r[i++],g=p>>4&7,m=p&15;for(let d=4;p&128;d+=7)p=r[i++],m+=(p&127)*2**d;let k;if(g===Kl){p=r[i++];let d=p&127;for(;p&128;)p=r[i++],d=(d+1)*128+(p&127);k=h-d}else if(g===Wl)k=_(r.subarray(i,i+20)),i+=20;else if(!la[g])throw new Error(`a pack entry of type ${String(g)}`);let{out:S,end:x}=gs(o,i);if(S.length!==m)throw new Error(\"a pack entry of another size\");i=x,s.set(h,{type:g,data:S,...k===void 0?{}:{base:k}})}if(i!==o.length)throw new Error(\"a pack with bytes past its objects\");let c=new Map,a=new Map,u=new Map,l=async f=>{if(typeof f==\"number\")return c.get(f);let h=a.get(f);return h||(u.has(f)||u.set(f,await t(f)),u.get(f)??void 0)};for(;c.size<s.size;){let f=c.size;for(let[h,p]of s){if(c.has(h))continue;let g;if(p.base===void 0)g={type:la[p.type],body:p.data};else{let m=await l(p.base);if(!m)continue;g={type:m.type,body:fa(m.body,p.data)}}c.set(h,g),a.set(await Ft(g),g)}if(c.size===f)throw new Error(\"a delta whose base is nowhere\")}return a},zr=r=>{let t=I(r);return new Uint8Array([...I((t.length+4).toString(16).padStart(4,\"0\")),...t])},As=I(\"0000\"),Kr=(r,t=0,e=n=>!1)=>{let n=[];for(;t+4<=r.length;){let o=parseInt(new TextDecoder().decode(r.subarray(t,t+4)),16);if(Number.isNaN(o))throw new Error(\"no pkt-line\");if(o===0)return{lines:n,end:t+4};if(o<4||t+o>r.length)throw new Error(\"a pkt-line cut short\");let s=new TextDecoder().decode(r.subarray(t+4,t+o));if(n.push(s),t+=o,e(s))return{lines:n,end:t}}return{lines:n,end:t}};var Wr=async(r,t,e)=>{let n=await r.get(t);if(!n)throw new Error(`${t} is no object this harbor holds`);if(n.type!==e)throw new Error(`${t} is a ${n.type}, not a ${e}`);return n},eo=async(r,t)=>{let e=new Map,n=async(o,s)=>{for(let i of Qn(await Wr(r,o,\"tree\")))i.mode===nr?await n(i.id,`${s}${i.name}/`):e.set(`${s}${i.name}`,i.id)};return await n(he(await Wr(r,t,\"commit\")).tree,\"\"),e},Bs=async(r,t)=>{let e=async n=>{let o=[],s=new Map;for(let[c,a]of n){let u=c.indexOf(\"/\");if(u<0)o.push({mode:ks,name:c,id:a});else{let l=c.slice(0,u);s.has(l)||s.set(l,new Map),s.get(l).set(c.slice(u+1),a)}}for(let[c,a]of s)o.push({mode:nr,name:c,id:await e(a)});let[i]=await r.put([qr(o)]);return i};return e(t)},Ss=async(r,t)=>{let[e]=await r.put([Os(t)]);return e},Ts=async(r,t)=>{let e=new Set,n=async s=>{if(!e.has(s)){e.add(s);for(let i of Qn(await Wr(r,s,\"tree\")))i.mode===nr?await n(i.id):e.add(i.id)}},o=[t];for(;o.length>0;){let s=o.pop();if(e.has(s))continue;e.add(s);let i=he(await Wr(r,s,\"commit\"));await n(i.tree),o.push(...i.parents)}return[...e]},to=class{#t=new Map;objects(){return[...this.#t.values()]}get(t){return Promise.resolve(this.#t.get(t)??null)}async put(t){let e=[];for(let n of t){let o=await Ft(n);this.#t.set(o,n),e.push(o)}return e}},or=class{#t;#e=new to;constructor(t){this.#t=t}async get(t){return await this.#e.get(t)??this.#t.get(t)}put(t){return this.#e.put(t)}async flush(){await this.#t.put(this.#e.objects())}};var sr=\"git-upload-pack\",Gl=\"agent=nervur\",da=r=>r.replace(/\\/+$/,\"\"),Rs=async r=>{let t=await fetch(`${da(r)}/info/refs?service=${sr}`,{headers:{accept:`application/x-${sr}-advertisement`}});if(!t.ok)throw new Error(`${r} answered ${String(t.status)}`);let e=new Uint8Array(await t.arrayBuffer()),n=Kr(e);if(n.lines[0]?.trim()!==`# service=${sr}`)throw new Error(`${r} is no git repository over smart HTTP`);let o={};for(let s of Kr(e,n.end).lines){let[i]=s.replace(/\\n$/,\"\").split(\"\\0\"),[c,a]=i.split(\" \");Vt(c)&&a!==void 0&&!a.endsWith(\"^{}\")&&!/^0{40}$/.test(c)&&(o[a]=c)}return o},_s=256,js=async(r,t)=>{let e=[],n=new Set,o=[],s=async i=>{if(n.has(i))return;n.add(i);let c=await t(i);if(c?.type!==\"commit\")return;let a=he(c);o.push({id:i,seconds:a.committer.seconds,parents:a.parents})};for(let i of r)await s(i);for(;o.length>0&&e.length<_s;){o.sort((c,a)=>a.seconds-c.seconds);let i=o.shift();e.push(i.id);for(let c of i.parents)await s(c)}return e},Is=async(r,t,e,n=[])=>{let o=[];for(let l of new Set(t))await e(l)||o.push(l);if(o.length===0)return new Map;let s=C(...o.map((l,f)=>zr(f===0?`want ${l} ofs-delta thin-pack ${Gl}\n`:`want ${l}\n`)),As,...n.slice(0,_s).map(l=>zr(`have ${l}\n`)),zr(`done\n`)),i=await fetch(`${da(r)}/${sr}`,{method:\"POST\",headers:{\"content-type\":`application/x-${sr}-request`,accept:`application/x-${sr}-result`},body:Uint8Array.from(s)});if(!i.ok)throw new Error(`${r} answered ${String(i.status)}`);let c=new Uint8Array(await i.arrayBuffer()),a=0,u=[];for(;a<c.length&&new TextDecoder(\"latin1\").decode(c.subarray(a,a+4))!==\"PACK\";){let l=Kr(c,a,()=>!0);if(u.push(...l.lines),l.end===a||!/^(ACK|NAK)/.test(l.lines.at(-1)??\"\"))throw new Error(`${r} sent no pack: ${u.join(\" \").slice(0,200)||\"nothing\"}`);a=l.end}return vs(c.subarray(a),e)};var $s=3e4,Ns=3e5,Ls=r=>{let t=typeof r?.time==\"number\"?Math.floor(r.time):NaN;return Math.min(Number.isFinite(t)&&t>0?t:3e4,3e5)},no=Symbol(\"late\"),ro=class{#t;#e;#r=!1;constructor(t,e){this.#t=t.wait(e),this.#e=this.#t.done.then(()=>(this.#r=!0,no))}get rang(){return this.#r}race(t){return t.catch(()=>{}),Promise.race([t,this.#e])}cancel(){this.#t.cancel()}};var Zl=/^(?:([^:/?#]+):)?(?:\\/\\/([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$/,Xl=/^(?:[A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=]|%[0-9A-Fa-f]{2})*$/,Yl=/^[A-Za-z][A-Za-z0-9+.-]*$/,Vl=/^(?:[A-Za-z0-9\\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*$/,Jl=/^\\[(?:[0-9A-Fa-f:.]+|v[0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&'()*+,;=:]+)\\]$/,Ds=r=>{if(typeof r!=\"string\"||!Xl.test(r))return null;let t=Zl.exec(r);if(!t||t[1]===void 0||!Yl.test(t[1]))return null;let e={scheme:t[1].toLowerCase(),authority:t[2]??null,userinfo:null,host:null,port:null,path:t[3]??\"\",query:t[4]??null,fragment:t[5]??null};if(e.authority===null)return e;let n=e.authority,o=n.lastIndexOf(\"@\");o>=0&&(e.userinfo=n.slice(0,o),n=n.slice(o+1));let s=/^(\\[[^\\]]*\\]|[^:[\\]]*)(?::([0-9]*))?$/.exec(n);if(!s)return null;let i=s[1];return(i.startsWith(\"[\")?!Jl.test(i):!Vl.test(i))?null:(e.host=i,e.port=s[2]??null,e)},ha=r=>r.startsWith(\"[\")?r.slice(1,-1):r;var Ae=r=>{let t=Ds(r);if(!t||t.scheme!==\"tcp\"||t.authority===null||t.userinfo!==null||t.path!==\"\"||t.query!==null||t.fragment!==null||!t.host||t.port===null||!/^[0-9]+$/.test(t.port))return null;let e=Number(t.port);return e<1||e>65535?null:{host:ha(t.host),port:e}},oo=(r,t)=>`tcp://${r.includes(\":\")?`[${r}]`:r}:${t}`,Ql=new Set([\"http\",\"https\",\"ws\",\"wss\"]),ir=r=>{let t=Ds(r);if(!t||!Ql.has(t.scheme)||t.authority===null||t.userinfo!==null||t.fragment!==null||!t.host||t.port!==null&&t.port!==\"\"&&(!/^[0-9]+$/.test(t.port)||Number(t.port)>65535))return null;let e=t.scheme,n=e===\"https\"||e===\"wss\",o=t.port?Number(t.port):n?443:80,s=`${t.path||\"/\"}${t.query!==null?`?${t.query}`:\"\"}`;return{scheme:e,secure:n,held:e===\"ws\"||e===\"wss\",host:ha(t.host),port:o,path:s,href:r}},Ps=r=>{let t=(Ae(r)??ir(r))?.host;return t===\"0.0.0.0\"||t===\"::\"},Gr=r=>Array.isArray(r)?r.filter(t=>Ds(t)!==null):[];var Tt={seal:I(\"quo-seal\"),edgeSeal:I(\"quo-edge-seal\"),lock:I(\"quo-lock\"),edge:I(\"quo-edge\"),wardSign:I(\"quo-ward-sign\"),wardSeal:I(\"quo-ward-seal\")},Rt=class r{secret;pk;constructor(t,e){this.secret=t,this.pk=e}static async from(t){return new r(t,await is(t))}static draw(t){return r.from(t(32))}get id(){return _(this.pk)}},Jt=class r{secret;pk;constructor(t,e){this.secret=t,this.pk=e}static async from(t){return new r(t,await Je(t))}static draw(t){return r.from(t(32))}agree(t){return Un(this.secret,t)}},Be=class r{signing;sealSecret;padlock;constructor(t,e,n){this.signing=t,this.sealSecret=e,this.padlock=n}static async from(t){let e=typeof t==\"string\"?await se(I(t)):t.length===32?t:await se(t),n=await dt(e,Tt.wardSeal,32);return new r(await Rt.from(await dt(e,Tt.wardSign,32)),n,await Je(n))}get pk(){return _(this.signing.pk)+_(this.padlock)}open(t){return Un(this.sealSecret,t)}},so=r=>({signing:r.slice(0,64),padlock:r.slice(64)}),pa=r=>{let t=r(64);return fs(t.subarray(0,32),t.subarray(32))};var tf=[\"to\",\"by\",\"next\",\"seq\"],ef=\"0\".repeat(64),rf=r=>K(r,32)&&r!==ef,Fs=(r,t)=>{if(t&&r===\"null\")return null;if(!/^\"[0-9a-f]{64}\"$/.test(r))return;let e=r.slice(1,-1);return rf(e)?e:void 0},Ms=r=>{let t=[`\"to\":${JSON.stringify(r.to)}`,`\"by\":\"${r.by}\"`,`\"next\":${JSON.stringify(r.next)}`,`\"seq\":${r.seq}`];return r.method!==void 0&&t.push(`\"method\":${JSON.stringify(r.method)}`),r.args!==void 0&&t.push(`\"args\":${r.args}`),`{${t.join(\",\")}}`},Us=r=>{let t=gr(r);if(t===null)return{fault:\"not an object\"};let e={fault:\"not well formed\"};if(!tf.every(u=>t.has(u)))return e;let n=Fs(t.get(\"to\"),!0),o=Fs(t.get(\"by\"),!1),s=Fs(t.get(\"next\"),!0),i=t.get(\"seq\");if(n===void 0||!o||s===void 0||!Do(i))return e;let c=t.get(\"method\");if(c!==void 0&&!c.startsWith('\"'))return e;let a=t.get(\"args\");return a!==void 0&&!a.startsWith(\"{\")?e:{payload:{to:n,by:o,next:s,seq:Number(i),...c===void 0?{}:{method:JSON.parse(c)},...a===void 0?{}:{args:a}}}};var wa=[\"removed\",\"unannounced\",\"repeated\"],ya='{\"silence\":true}',Hs=r=>\"silence\"in r?ya:\"quo\"in r?`{\"quo\":\"${r.quo}\"}`:`{\"object\":${r.object},\"seen\":${JSON.stringify(r.seen)}}`,Cs=(r,...t)=>r.size===t.length&&t.every(e=>r.has(e)),qs=r=>{let t=gr(r);if(t===null)return null;if(Cs(t,\"silence\"))return t.get(\"silence\")===\"true\"?{silence:!0}:null;if(Cs(t,\"quo\")){let e=t.get(\"quo\"),n=e.startsWith('\"')?JSON.parse(e):null;return wa.find(o=>o===n)?{quo:n}:null}if(Cs(t,\"object\",\"seen\")){let e=t.get(\"seen\");return e===\"null\"?{object:t.get(\"object\"),seen:null}:e.startsWith('\"')?{object:t.get(\"object\"),seen:JSON.parse(e)}:null}return null};var io=1048576,tt=32,zs=64,Ks=tt+Ke,ma=new Uint8Array(32),up=new Uint8Array(tt),ga=async(r,...t)=>{let e=await dt(C(...t),r,44);return{key:e.subarray(0,32),nonce:e.subarray(32)}},Ws=async(r,t,e,n)=>{let{key:o,nonce:s}=await ga(r,...t);return Dt(o,s,e,n)},Gs=async(r,t,e,n)=>{let{key:o,nonce:s}=await ga(r,...t);return qt(o,s,e,n)},co=r=>dt(r,Tt.lock,32),ao=(r,t)=>dt(C(r,t),Tt.edge,32),uo=async(r,t)=>C(r,await cs(t.secret,r)),lo=r=>r.length<=zs?null:{text:r.subarray(0,-zs),signature:r.subarray(-zs)},Zr=(r,t)=>as(r,t.text,t.signature),Zs=async(r,t,e,n,o,s)=>{let i=await r.agree(t);if(i===null)return null;let c=await Ws(Tt.seal,[i],r.pk,e),a=await Ws(Tt.edgeSeal,[i,n],r.pk,o);return C(r.pk,c,s??new Uint8Array(0),a)},ba=async(r,t)=>{if(r.length<tt+Ks)return null;let e=r.subarray(0,tt),n=await Gs(Tt.seal,[t],e,r.subarray(tt,tt+Ks));return n===null?null:{lid:e,agreement:t,head:n,rest:r.subarray(tt+Ks)}},xa=r=>r.length<tr?null:{ciphertext:r.subarray(0,tr),sealedBody:r.subarray(tr)},Ea=(r,t,e)=>Gs(Tt.edgeSeal,[r.agreement,t],r.lid,e),Xr=async(r,t)=>{let e=await Jt.draw(r),n=await e.agree(t);return n===null?null:{ephemeral:e,agreement:n}},Yr=async(r,t)=>C(r.ephemeral.pk,await Ws(Tt.seal,[r.agreement],r.ephemeral.pk,t)),ka=async(r,t)=>{if(r.length>io||r.length<tt+Ke)return null;let e=r.subarray(0,tt),n=await t.agree(e);if(n===null)return null;let o=await Gs(Tt.seal,[n],e,r.subarray(tt));return o===null?null:{bytes:o,agreement:n}};var Xs=64,Vr=class{key;relations;behind;draw;constructor(t,e,n,o){this.key=t,this.relations=e,this.behind=n,this.draw=o}async invite(t=[]){let e=this.relations.lock();e||this.relations.setLock(e=pa(this.draw));let n=await Rt.draw(this.draw);this.relations.set(n.id,{state:\"fresh\"});let o={ward:this.key.pk,heir:n.id,secret:_(n.secret),lock:_(e.ek),...t.length>0?{at:[...t]}:{}};return{heir:n.id,invitation:o}}remove(t){let e=this.relations.get(t);return e===void 0||e.state===\"kept\"?!1:(e.state===\"fresh\"?this.relations.delete(t):this.relations.set(t,{state:\"kept\",held:e.held,vouched:e.vouched,open:e.open,offered:e.offered}),!0)}async arrive(t){let e=async k=>({bytes:await this.#s(t),case:k,heard:!1});if(t.length>io||t.length<tt)return e(1);let n=await this.key.open(t.subarray(0,tt)),o=n&&await ba(t,n);if(!o)return e(1);let s=yr(o.head),i=_(o.head),c=s?void 0:this.relations.get(i),a=await this.#o(o,c);if(!a)return e(1);let u=Us(a.text);if(\"fault\"in u)return e(u.fault===\"not an object\"?2:3);let l=u.payload;if(s?l.to!==null:l.to!==i)return e(3);if(s){if(!this.behind.zero)return e(4);if(!await Zr($(l.by),a))return e(5);let k=await this.#r(null,l);return{bytes:await this.#n(o,k),case:\"object\"in k?12:13,heard:!1}}if(c===void 0)return e(6);if(!Oa(c,i,l.by))return e(7);if(!await Zr($(l.by),a))return e(8);let f=await Xr(this.draw,o.lid);if(!f)return e(1);let h=await ao(a.edge,f.agreement),p=this.relations.get(i);if(p===void 0||!Oa(p,i,l.by)||!nf(p,a.edge))return e(7);if(p.state===\"kept\")return this.#t(f,{quo:\"removed\"},9);if(p.state===\"fresh\"&&(l.next===null||l.next===i))return this.#t(f,{quo:\"unannounced\"},10);if(p.state===\"spent\"&&!of(p,l.seq))return this.#t(f,{quo:\"repeated\"},11);this.relations.set(i,sf(p,i,l,_(a.edge),_(h)));let g=await this.#r(i,l),m=await this.relations.kept().catch(()=>!1);return this.#t(f,m?g:{silence:!0},m&&\"object\"in g?12:13)}async#t(t,e,n){return{bytes:await Yr(t,await this.#e(e)),case:n,heard:!0}}#e(t){return uo(I(Hs(t)),this.key.signing)}async#r(t,e){try{return await this.behind.answer(t,e)}catch{return{silence:!0}}}async#n(t,e){let n=await Xr(this.draw,t.lid);return n?Yr(n,await this.#e(e)):this.#s(t.lid)}async#o(t,e){let n=[];if(e?.state===\"fresh\"){let o=xa(t.rest),s=this.relations.lock(),i=o&&s?ds(s.dk,o.ciphertext):null;if(!o||!i)return null;n.push({edge:await co(i),sealed:o.sealedBody})}else if(e===void 0)n.push({edge:ma,sealed:t.rest});else for(let o of[e.open,e.offered])n.push({edge:$(o),sealed:t.rest});for(let{edge:o,sealed:s}of n){let i=await Ea(t,o,s);if(i===null)continue;let c=lo(i);return c&&{edge:o,...c}}return null}async#s(t){let e=await this.#e({silence:!0}),n=[t.length>=tt?t.subarray(0,tt):null,this.draw(tt)];for(let o of n){let s=o&&await Xr(this.draw,o);if(s)return Yr(s,e)}return Yr(await Xr(this.draw,await Je(this.draw(tt))),e)}},Oa=(r,t,e)=>r.state===\"fresh\"?e===t:e===r.held||e===r.vouched,nf=(r,t)=>r.state===\"fresh\"||_(t)===r.open||_(t)===r.offered,of=(r,t)=>t>r.highest||t>r.highest-Xs&&t!==r.highest&&!r.honoured.includes(t),sf=(r,t,e,n,o)=>{let s=e.next!==null&&e.next!==t&&e.next!==e.by?e.next:null;if(r.state===\"fresh\")return{state:\"spent\",held:s,vouched:null,open:n,offered:o,highest:e.seq,honoured:[]};if(r.state!==\"spent\")return r;if(e.seq<r.highest)return{...r,honoured:[...r.honoured,e.seq]};let i=e.by===r.held?{held:r.held,vouched:s??r.vouched,open:n,offered:o}:{held:e.by,vouched:s,open:n,offered:o},c=[...r.honoured,r.highest].filter(a=>a>e.seq-Xs);return{state:\"spent\",...i,highest:e.seq,honoured:c}};var kt=r=>{if(typeof r!=\"object\"||r===null||Array.isArray(r))return null;let{ward:t,heir:e,secret:n,lock:o,at:s}=r;if(!K(t,64)||!K(e,32)||!K(n,32)||!K(o,Zn)||Mr($(o),new Uint8Array(32))===null)return null;let i=Gr(s);return{ward:t,heir:e,secret:n,lock:o,...i.length>0?{at:i}:{}}};var Ys=r=>r?{ek:$(r.ek),dk:$(r.dk)}:void 0,Vs=r=>({ek:_(r.ek),dk:_(r.dk)}),Js=256;var Qs=()=>({key:null,edge:null,sent:0,moved:0,knock:null,probed:!1}),cr=class{invitation;state;draw;constructor(t,e,n){this.invitation=t,this.state=e,this.draw=n}async ask(t,e){let n=this.state;return n.key!==null?this.#e($(n.key),$(n.edge),t,e):n.knock===null?this.#t(t,e):n.probed?(this.state={...n,probed:!1},{bytes:$(n.knock.bytes),lid:await Jt.from($(n.knock.lid)),next:n.knock.next,edge:n.knock.edge,seq:n.knock.seq}):(this.state={...n,probed:!0},this.#e($(n.knock.next),$(n.knock.edge),t,e))}async read(t,e){if(e===null)return{nothing:!0};let n=await this.#n(t,e);if(n===null)return{silence:!0};if(\"object\"in n.text&&t.seq>this.state.moved){let o=await ao($(t.edge),n.agreement);this.state={...this.state,key:t.next,edge:_(o),moved:t.seq,knock:null,probed:!1}}return n.text}async#t(t,e){let n=await Rt.from($(this.invitation.secret)),o=await Rt.draw(this.draw),s=await Jt.draw(this.draw),i=Mr($(this.invitation.lock),this.draw(32));if(i===null)return null;let c=await co(i.shared),a=this.state.sent+1,u=await this.#r(n,o,a,t,e),l=await Zs(s,$(so(this.invitation.ward).padlock),$(this.invitation.heir),c,u,i.ciphertext);return l===null?null:(this.state={...this.state,sent:a,knock:{bytes:_(l),lid:_(s.secret),next:_(o.secret),edge:_(c),seq:a}},{bytes:l,lid:s,next:_(o.secret),edge:_(c),seq:a})}async#e(t,e,n,o){let s=await Rt.from(t),i=await Rt.draw(this.draw),c=await Jt.draw(this.draw),a=this.state.sent+1,u=await this.#r(s,i,a,n,o),l=await Zs(c,$(so(this.invitation.ward).padlock),$(this.invitation.heir),e,u);return l===null?null:(this.state={...this.state,sent:a},{bytes:l,lid:c,next:_(i.secret),edge:_(e),seq:a})}#r(t,e,n,o,s){let i=Ms({to:this.invitation.heir,by:t.id,next:e.id,seq:n,...o===void 0?{}:{method:o},...s===void 0?{}:{args:s}});return uo(new TextEncoder().encode(i),t)}async#n(t,e){let n=await ka(e,t.lid),o=n&&lo(n.bytes);if(!n||!o||!await Zr($(so(this.invitation.ward).signing),o))return null;let s=qs(o.text);return s&&{text:s,agreement:n.agreement}}};var Qr=\"\",Jr=class{memory;constructor(t){this.memory=t;let e=t.rows;e.ward??={heirs:{},gone:[],bind:{},public:null},e.beings??={}}get head(){return this.memory.rows.ward}get beings(){return this.memory.rows.beings}being(t){return Object.hasOwn(this.beings,t)?this.beings[t]:void 0}told(t){this.memory.told(t)}toldHead(){this.memory.told(Qr)}kept(){return this.memory.kept().catch(()=>!1)}},fo=class{#t;constructor(t){this.#t=t}get#e(){return this.#t.head}lock(){return Ys(this.#e.lock)}setLock(t){this.#e.lock=Vs(t),this.#t.toldHead()}get(t){return Object.hasOwn(this.#e.heirs,t)?this.#e.heirs[t]:void 0}set(t,e){let n=this.#e;if(n.heirs[t]=e,e.state===\"kept\")for(n.gone.push(t);n.gone.length>Js;)delete n.heirs[n.gone.shift()];this.#t.toldHead()}delete(t){delete this.#e.heirs[t],this.#t.toldHead()}kept(){return this.#t.kept()}};var _t=64,Se=r=>{throw new TypeError(`cells hold values: ${r}`)},cf=(r,t,e)=>{let n=ie(r,t);return n===void 0?Se(`${e} is not a value JSON keeps, within ${t} levels`):JSON.parse(n)},ho=class{#t=new WeakMap;#e;constructor(t){this.#e=t}guard(t){return this.#r(t,\"cells\",1)}#r(t,e,n){let o=this.#t.get(t);if(o)return o;let s=_t-n,i=(a,u,l)=>{if(typeof u!=\"string\")return Se(`${e} takes no symbol key`);let f=`${e}.${u}`;if(Array.isArray(a)){if(u===\"length\")return(typeof l!=\"number\"||l>a.length)&&Se(`${f} past its end would leave a hole`),a.length=l,this.#e(),!0;/^(0|[1-9]\\d*)$/.test(u)||Se(`${f} is not a slot of a list`),Number(u)>a.length&&Se(`${f} would leave a hole`)}let h=Reflect.defineProperty(a,u,{value:cf(l,s,f),enumerable:!0,writable:!0,configurable:!0});return this.#e(),h},c=new Proxy(t,{get:(a,u,l)=>{let f=Reflect.get(a,u,l);return typeof u==\"string\"&&Object.hasOwn(a,u)&&typeof f==\"object\"&&f!==null?this.#r(f,`${e}.${u}`,n+1):f},set:(a,u,l)=>i(a,u,l),defineProperty:(a,u,l)=>\"value\"in l?i(a,u,l.value):Se(`${e}.${String(u)} is an accessor`),deleteProperty:(a,u)=>{let l=Reflect.deleteProperty(a,u);return this.#e(),l},setPrototypeOf:()=>Se(`${e} keeps its prototype`)});return this.#t.set(t,c),c}};var af=new Set([Bt]),uf=2,ti=class{#t=new Map;run(t,e){let n=(this.#t.get(t)??Promise.resolve()).then(e,e),o=n.catch(()=>{});return this.#t.set(t,o),o.then(()=>{this.#t.get(t)===o&&this.#t.delete(t)}),n}},lf=r=>\"nothing\"in r?pt(\"unreached\"):\"silence\"in r?ht:\"quo\"in r?pt(r.quo):br(r.object,_t)??ht,pe=class{key;occupants;standings;#t;#e;#r=new ti;#n=new ho(()=>this.#a());constructor(t,e,n,o={}){Object.assign(this,o),this.key=e,this.#t=t,this.#e=n,this.occupants={invite:(s,i)=>this.#u(s,i),notes:s=>Object.hasOwn(n.occupants,s)?n.occupants[s].notes:void 0,ids:()=>Object.keys(n.occupants),remove:s=>this.#c(s)},this.standings={take:(s,i)=>this.#i(s,i),get:s=>this.#l(s),ids:()=>Object.keys(n.standings),remove:s=>this.#d(s)}}get cells(){return this.#n.guard(this.#e.cells)}get#o(){return this.#t.live(this.key,this.#e)}boot(t,e,n){return this.#o?this.#t.boot(this.key,t,e,n):Promise.resolve(null)}async lend(t,e){let n=Gt(t);if(n===void 0||!this.#s(e,this.#e.standings))return null;let o=await this.#t.offer(n);if(o===null)return null;let s=await this.#i(e,o);return s===null&&await this.#t.retract(n,o.heir),s}#s(t,e){return this.#o&&typeof t==\"string\"&&!af.has(t)&&!Object.hasOwn(e,t)}async#u(t,e={}){let n=ie(e,_t);if(!this.#s(t,this.#e.occupants)||n===void 0)return null;let{heir:o,invitation:s}=await this.#t.door.invite(this.#t.reach());return this.#s(t,this.#e.occupants)?(this.#e.occupants[t]={heir:o,notes:JSON.parse(n)},this.#t.partition.head.bind[o]={being:this.key,id:t},this.#a(),this.#t.partition.toldHead(),s):(this.#t.door.remove(o),null)}#c(t){if(!this.#o||!Object.hasOwn(this.#e.occupants,t))return!1;let{heir:e}=this.#e.occupants[t];return this.#t.door.remove(e),delete this.#e.occupants[t],delete this.#t.partition.head.bind[e],this.#a(),this.#t.partition.toldHead(),!0}async#i(t,e){let n=kt(e);if(!n||!this.#s(t,this.#e.standings))return null;n.at&&await this.#t.learn(n.ward,n.at);let o=new cr(n,Qs(),this.#t.draw),s=await this.#r.run(`take:${t}`,async()=>{if(n.ward===this.#t.pk)return this.#t.within(n.heir,!0);let i=await this.#p(o);for(let c=0;c<uf&&(\"nothing\"in i||\"silence\"in i);c+=1)i=await this.#p(o);return i});return!(\"object\"in s)||!this.#s(t,this.#e.standings)?null:(this.#e.standings[t]={invitation:n,state:o.state,seen:s.seen},this.#a(),t)}#d(t){return!this.#o||!Object.hasOwn(this.#e.standings,t)?!1:(delete this.#e.standings[t],this.#a(),!0)}#l(t){if(Object.hasOwn(this.#e.standings,t))return{id:t,ask:(e,n,o)=>this.#f(t,e,n,o)}}async#f(t,e,n={},o){let s=ie(n,_t+1);if(e!==void 0&&typeof e!=\"string\"||s===void 0||Array.isArray(n))return pt(\"unreached\");let i=new ro(this.#t.clock,Ls(o));try{let c=await i.race(this.#r.run(`ask:${t}`,async()=>{let a=Object.hasOwn(this.#e.standings,t)?this.#e.standings[t]:void 0;if(!this.#o||a===void 0)return pt(\"dropped\");if(i.rang)return pt(\"late\");let l=a.invitation.ward===this.#t.pk?null:new cr(a.invitation,a.state,this.#t.draw),f=await i.race(l?this.#p(l,e,s):this.#t.within(a.invitation.heir,!1,e,s));return l&&(a.state=l.state),f===no?pt(\"late\"):(\"object\"in f&&(a.seen=f.seen),this.#a(),await this.#t.partition.kept(),lf(f))}));return c===no?pt(\"late\"):c}finally{i.cancel()}}async#p(t,e,n){let o=await t.ask(e,n);return o?t.read(o,await this.#t.send(t.invitation.ward,o.bytes)):{nothing:!0}}#a(){this.#t.partition.told(this.key)}};var Te=(r,t)=>r.id===Bt||t?.owner===!0,L=(r,t={})=>({description:r,input:{type:\"object\",...t},for:Te}),en=(r,t={})=>({description:r,input:{type:\"object\",...t},for:e=>e.id===Bt}),tn=\"held:\",st=r=>typeof r==\"string\",ei=r=>typeof r==\"object\"&&r!==null&&!Array.isArray(r),yt=class extends Xt{static kind=\"org.nervur.ward\";static{U(this)}static asks={boot:L(\"a new being of this ward\",{required:[\"key\",\"class\"]}),unboot:L(\"a being out, with every relation she holds\",{required:[\"being\"]}),public:L(\"the being a stranger reaches, or none\",{required:[\"key\"]}),invite:L(\"an invitation on a being of this ward\",{required:[\"being\",\"id\"]}),ask:L(\"a being of this ward, asked as the owner; with no being, the public being asked as nobody\"),own:en(\"an invitation for an owner of this ward, under an id\",{required:[\"id\"]}),disown:en(\"an owner no more\",{required:[\"id\"]}),become:L(\"this ward born again of the class of a kind, her cells and relations kept\",{required:[\"class\"]}),hold:L(\"an owner invitation on a far being, held under a name from now on\",{required:[\"name\",\"invitation\"]}),pilot:L(\"the far being held under a name, asked as its owner\",{required:[\"name\"]}),drop:L(\"the far being held under a name, let go\",{required:[\"name\"]})};steward;constructor(t){super(t),this.steward=t.steward}static fulfils(t){return typeof t==\"function\"&&t.prototype instanceof this}become(t){if(!st(t.class))return{error:\"class is text\"};let e=this.steward.become(t.class);return e===null?{became:t.class}:{error:e}}describe(t){let{asks:e}=super.describe(t);return{asks:e,notes:Te(t,this.notes(t))?{pk:this.steward.pk(),class:Zt(this.constructor),beings:this.steward.beings()}:{}}}async own(t){return st(t.id)?await this.stance.occupants.invite(t.id,{owner:!0})??{error:\"id taken\"}:{error:\"id is text\"}}disown(t){return!st(t.id)||this.stance.occupants.notes(t.id)?.owner!==!0?{error:\"no such owner\"}:(this.stance.occupants.remove(t.id),{disowned:t.id})}async boot(t){if(!st(t.key)||!st(t.class))return{error:\"key and class are text\"};if(er(this.steward.classOf(t.class)))return{error:\"no such class\"};let e=await this.steward.boot(t.key,t.class);return e===\"booted\"?{booted:t.key}:{error:e}}unboot(t){return st(t.being)&&this.steward.unboot(t.being)?{unbooted:t.being}:{error:\"no such being\"}}public(t){return t.key!==null&&!st(t.key)?{error:\"key is text or null\"}:this.steward.publish(t.key)?{public:t.key}:{error:\"no such being\"}}async invite(t){return!st(t.being)||!st(t.id)||t.notes!==void 0&&!ei(t.notes)?{error:\"being and id are text, notes an object\"}:await this.steward.invite(t.being,t.id,t.notes??{})??{error:\"not invited\"}}async ask(t){if(t.being!==void 0&&!st(t.being)||t.method!==void 0&&!st(t.method)||t.args!==void 0&&!ei(t.args))return{error:\"being and method are text, args an object\"};let e=await this.steward.ask(t.being??null,t.method,t.args??{});return St(e)?{error:\"silence\"}:wt(e)?{error:de(e)}:{answer:e}}async hold(t){if(!st(t.name))return{error:\"name is text\"};let e=kt(t.invitation);return e===null?{error:\"no invitation\"}:this.stance.standings.get(tn+t.name)?{error:`${t.name} is held`}:await this.stance.standings.take(tn+t.name,e)===null?{error:\"not taken\"}:{held:t.name,ward:e.ward}}async pilot(t){if(!st(t.name)||t.method!==void 0&&!st(t.method)||t.args!==void 0&&!ei(t.args))return{error:\"name and method are text, args an object\"};let e=this.stance.standings.get(tn+t.name);if(!e)return{error:`${t.name} is not held`};let n=await e.ask(t.method,t.args??{});return St(n)?{error:\"silence\"}:wt(n)?{error:de(n)}:{answer:n}}drop(t){return st(t.name)?this.stance.standings.remove(tn+t.name)?{dropped:t.name}:{error:`${t.name} is not held`}:{error:\"name is text\"}}};var Re=\"dock\",va=r=>typeof r.offer==\"function\",ri=class extends pe{steward;constructor(t,e,n,o){super(t,D,e,o),this.steward=n}},rn=class r{key;partition;door;clock;#t;#e=new Map;#r=new Map;#n=new Set;#o=null;constructor(t,e){this.#t=t,this.key=e,this.clock=t.clock,this.partition=new Jr(t.memory),this.door=new Vr(e,new fo(this.partition),this,t.entropy.drawer)}static async unpack(t){let e=new r(t,await Be.from(t.seed));return e.partition.being(D)||(e.partition.beings[D]={class:e.#u.genesis,cells:{},occupants:{},standings:{}},e.partition.told(D),e.partition.toldHead()),e}async standWard(){if(this.#e.has(D))return;let t=this.partition.being(D),e=new ri(this,t,this.#m,this.#t.carries??{}),n=this.#c(t.class,t.registry),o;if(typeof n==\"string\")this.#o=n;else try{o=new n(e)}catch(i){this.#o=`${t.class} threw at birth: ${i instanceof Error?i.message:String(i)}`}if(!o){let{fallback:i}=this.#u;if(!i)throw new Error(this.#o);o=new i(e)}this.#e.set(D,{being:o,row:t,stance:e});let{dock:s}=this.#t;if(s&&!Object.hasOwn(t.standings,Re)&&await e.standings.take(Re,s)!==null&&!await this.partition.kept())throw new Error(\"the standing on the dock was not kept\")}stand(t){if(this.#e.has(t))return\"stands\";let e=t===D||!this.#t.stands?void 0:this.partition.being(t);if(!e)return\"no such being\";let n=this.#s(e);return n?this.#x(t,e,n)?\"booted\":\"threw at birth\":\"no such class\"}make(t,e){return this.#y(t,e)}#s(t){return this.#t.classes.classOf(t.class,t.registry)}get pk(){return this.key.pk}get draw(){return this.#t.entropy.drawer}get ward(){return this.#e.get(D).being}get fault(){return this.#o}get#u(){return this.#t.ward}#c(t,e){let n=this.#t.classes.classOf(t,e);return n?this.#u.fits(n)?n:`${t} is no ${this.#u.contract}`:`no class of kind ${t} runs`}#i(){let t=this.#e.get(D);if(!t)return;let e=this.#c(t.row.class,t.row.registry);if(typeof e==\"string\"){Gt(t.being.constructor)!==t.row.class&&(this.#o=e);return}if(t.being.constructor!==e)try{t.being=new e(t.stance),this.#o=null}catch(n){this.#o=`${t.row.class} threw at birth: ${n instanceof Error?n.message:String(n)}`}}being(t){return this.#e.get(t)?.being}renew(){this.#i();for(let[t,e]of this.#e){if(t===D)continue;let n=this.#s(e.row);if(!(!n||e.being.constructor===n))try{e.being=new n(e.stance)}catch{continue}}}async root(t,e={}){return this.#d(Object.keys(this.partition.beings),()=>this.#p(D,{id:Bt},t,e))}async#d(t,e){let n=t.flatMap(s=>{let i=this.partition.being(s);return i?[[s,i.cells,JSON.stringify(i.cells)]]:[]}),o=await e();if(await this.partition.kept())return o;for(let[s,i,c]of n)if(JSON.stringify(i)!==c){for(let a of Object.keys(i))delete i[a];for(let[a,u]of Object.entries(JSON.parse(c)))Object.defineProperty(i,a,{value:u,enumerable:!0,writable:!0,configurable:!0});this.partition.told(s)}return ht}get zero(){let t=this.partition.head.public;return t!==null&&this.#l(t)}#l(t){if(this.#e.has(t))return!0;let e=t===D||this.#t.stands?void 0:this.partition.being(t);return e!==void 0&&this.#s(e)!==void 0}answer(t,e){return this.#f(t,e.method,e.args)}async within(t,e,n,o){let{bind:s}=this.partition.head,i=Object.hasOwn(s,t)?s[t]:void 0;if(!e)return i?.inside?this.#f(t,n,o):{quo:\"removed\"};if(!i||i.inside||this.door.relations.get(t)?.state!==\"fresh\")return{silence:!0};let c={...i,inside:!0};this.door.relations.delete(t),s[t]=c,this.partition.toldHead();let a=await this.#f(t,n,o);return\"object\"in a||s[t]!==c||(s[t]=i,this.door.relations.set(t,{state:\"fresh\"})),a}async#f(t,e,n){let o=t===null?void 0:this.partition.head.bind[t],s=t===null?this.partition.head.public:o?.being,i=o?{id:o.id}:{},c=n===void 0?{}:br(n,_t+1);if(s==null||typeof c!=\"object\"||c===null||Array.isArray(c))return{silence:!0};let a=null,u=await this.#d([s],()=>this.#w(s,ht,async f=>{let h=await this.#a(f,i,e,c);return e!==void 0&&!St(h)&&!wt(h)&&f.describe&&(a=await Ur(f.describe(i))),h})),l=St(u)||wt(u)?void 0:ie(u,_t);return l===void 0?{silence:!0}:{object:l,seen:a}}#p(t,e,n,o){return this.#w(t,ht,s=>this.#a(s,e,n,o))}async#a(t,e,n,o){let s;try{s=await t.answer(e,n,o)}catch{return ht}return s===void 0||wt(s)?ht:s}async#w(t,e,n){let o=this.#e.get(t);if(o)return n(o.being);let s=this.#h(t);if(!s)return e;try{return await n(s.being)}finally{s.asks-=1,s.asks===0&&this.#r.get(t)===s&&this.#r.delete(t)}}#h(t){let e=this.#r.get(t);if(e)return e.asks+=1,e;let n=t===D||this.#t.stands?void 0:this.partition.being(t),o=n&&this.#s(n);if(!n||!o)return;let s=new pe(this,t,n,this.#t.carries??{});try{let i={being:new o(s),row:n,stance:s,asks:1};return this.#r.set(t,i),i}catch{return}}#g(t){let e=this.#e.get(t)??this.#r.get(t);if(e)return e.stance;let n=t===D?void 0:this.partition.being(t);return n?new pe(this,t,n,this.#t.carries??{}):void 0}send(t,e){return this.#t.carrier.carry(t,e)}async offer(t){let e=this.#e.get(D);if(va(e.being))return e.being.offer(t);let n=await e.stance.standings.get(Re)?.ask(\"lend\",{contract:t});return kt(n?.invitation)}async retract(t,e){let n=this.#e.get(D);if(va(n.being))return n.being.withdraw(t,e);await n.stance.standings.get(Re)?.ask(\"retract\",{contract:t,heir:e})}reach(){return this.#t.routes?.reach()??[]}learn(t,e){return this.#t.routes?.learn(t,e)??Promise.resolve()}live(t,e){return this.partition.being(t)===e}async boot(t,e,n,o){if(await this.#y(n,e)!==\"booted\")return null;if(o===void 0)return n;let s=await this.#g(n).occupants.invite(t);return(s?await this.#g(t)?.standings.take(o,s):null)?n:(this.#b(n),null)}async#y(t,e,n){if(t===\"\"||t===D||this.partition.being(t)||this.#n.has(t))return\"key taken\";let o=this.#t.classes.classOf(e,n);if(!o||yt.fulfils(o)||G.fulfils(o)!==(this.#t.stands===!0))return\"no such class\";this.#n.add(t);try{let s={class:e,...n===void 0?{}:{registry:n},cells:{},occupants:{},standings:{}};return this.partition.beings[t]=s,(this.#t.stands?this.#x(t,s,o):this.#E(t,s,o)!==void 0)?(this.partition.told(t),\"booted\"):(delete this.partition.beings[t],\"threw at birth\")}finally{this.#n.delete(t)}}#E(t,e,n){try{return new n(new pe(this,t,e,this.#t.carries??{}))}catch{return}}#x(t,e,n){let o=new pe(this,t,e,this.#t.carries??{});try{return this.#e.set(t,{being:new n(o),row:e,stance:o}),!0}catch{return this.#e.delete(t),!1}}#b(t){let e=t===D?void 0:this.partition.being(t);if(!e)return!1;for(let{heir:n}of Object.values(e.occupants))this.door.remove(n),delete this.partition.head.bind[n];return this.partition.head.public===t&&(this.partition.head.public=null),delete this.partition.beings[t],this.#e.delete(t),this.partition.toldHead(),this.partition.told(t),!0}#m={pk:()=>this.pk,classOf:(t,e)=>this.#t.classes.classOf(t,e),beings:()=>{let t={};for(let[e,n]of Object.entries(this.partition.beings))e!==D&&(t[e]={class:n.class,...n.registry===void 0?{}:{registry:n.registry},public:this.partition.head.public===e,absent:!this.#l(e)});return t},boot:(t,e,n)=>this.#y(t,e,n),stand:t=>this.stand(t),unboot:t=>this.#b(t),publish:t=>t!==null&&(t===D||!this.partition.being(t))?!1:(this.partition.head.public=t,this.partition.toldHead(),!0),invite:(t,e,n)=>{let o=t===D||!this.#l(t)?void 0:this.#g(t);return o?o.occupants.invite(e,n):Promise.resolve(null)},ask:(t,e,n)=>{let o=t??this.partition.head.public;return o===null||o===D?Promise.resolve(pt(\"unreached\")):this.#p(o,t===null?{}:{id:Bt},e,n)},become:(t,e)=>{let n=this.#c(t,e);if(typeof n==\"string\")return n;let o=this.#e.get(D);try{o.being=new n(o.stance)}catch{return`${t} threw at birth`}return o.row.class=t,e===void 0?delete o.row.registry:o.row.registry=e,this.partition.told(D),this.#o=null,null}}};var ff=r=>`${r.split(\".\").slice(0,2).join(\".\")}.`,po=\"org.nervur.registry\",Mt=class extends G{static kind=po;static{U(this)}},ar=r=>typeof r==\"function\"&&r.prototype instanceof Mt,Ut=class r{#t=new Map;#e=new Map;constructor(t,e){let n=new Map,o=new Map,s=(i,c)=>{if(this.#t.has(c)&&this.#t.get(c)!==i)throw new Error(`two classes are of kind ${c}`);this.#t.set(c,i)};for(let i of t)s(i,Zt(i));for(let i of e){if(!Yn(i.module)||i.module.startsWith(Xn))throw new Error(`module ${String(i.module)} is no name a module may take`);if(this.#e.has(i.module))throw new Error(`two modules are named ${i.module}`);if(typeof i.version!=\"string\"||i.version===\"\")throw new Error(`module ${i.module} declares no version`);let c=[];for(let a of i.classes){if(typeof a!=\"function\")throw new Error(`module ${i.module} holds something that is no class`);let u=Zt(a);if(!u.startsWith(ff(i.module)))throw new Error(`kind ${u} is outside module ${i.module}`);let l=o.get(u);if(l!==void 0&&l!==i.module)throw new Error(`kind ${u} is in modules ${l} and ${i.module}`);o.set(u,i.module),s(a,u),c.push(u);for(let f=Object.getPrototypeOf(a);typeof f==\"function\";f=Object.getPrototypeOf(f))if(Gt(f)?.startsWith(Xn)&&!er(f))throw new Error(`kind ${Gt(f)} is the kit's`);if(G.fulfils(a))for(let f=Object.getPrototypeOf(a);f!==G;f=Object.getPrototypeOf(f)){let h=Zt(f);if(!er(f)){if(n.has(h)&&n.get(h)!==f)throw new Error(`two contracts are of kind ${h}`);n.set(h,f)}}}this.#e.set(i.module,c)}for(let i of n.keys())if(this.#t.has(i))throw new Error(`kind ${i} is a class and a contract`)}static refusal(t,e){try{let n=new r(t,e);return null}catch(n){return n.message}}classOf(t){return this.#t.get(t)}kindsOf(t){return[...this.#e.get(t)??[]]}};var Qt=\"catalogue\",on=\"modules/\",wo=\".js\",ni=r=>`${on}${r}${wo}`,df={name:\"nervur\",email:\"catalogue@nervur.org\"},ur=r=>typeof r==\"string\",hf=r=>`${r.split(\".\").slice(0,2).join(\".\")}.`,nn=r=>r instanceof Error?r.message:String(r),lt=class extends Mt{static kind=\"org.nervur.catalogue\";static{U(this)}static asks={add:L(\"a module committed on live, and live moved to it\",{required:[\"source\"]}),remove:L(\"a module committed away, and live moved\",{required:[\"module\"]}),live:L(\"live moved to a commit, or the commit that stands\"),log:L(\"the commits from live back\"),origin:L(\"where fetch reads\",{required:[\"url\"]}),fetch:L(\"every ref of origin and all it reaches, kept\"),modules:L(\"the modules live runs\"),sources:L(\"the source of each module file live holds, by its blob\"),gc:L(\"every object neither live nor a fetched ref reaches, forgotten\")};#t;#e;#r=new Map;#n=new Map;#o=null;#s=Promise.resolve();constructor(t){super(t);let{ground:e}=t;if(!e)throw new Error(\"the catalogue stands in the box ward alone\");this.#t=e,this.#e=new Ut(e.kit,[])}classOf(t){return this.#e.classOf(t)}#u(t){return Ut.refusal(this.#t.kit,t)}get#c(){return Vt(this.cells.live)?this.cells.live:void 0}get#i(){return this.cells.refs??{}}#d(){return{...df,seconds:Math.floor(this.#t.terrain.clock.now()/1e3),zone:\"+0000\"}}#l(t){let e=this.#s.then(t,t);return this.#s=e.catch(()=>{}),e}async#f(t,e,n){let o=e.size===0?(await t.put([qr([])]))[0]:await Bs(t,e),s=this.#d();return Ss(t,{tree:o,parents:this.#c?[this.#c]:[],author:s,committer:s,message:`${n}\n`})}async#p(t,e=this.#t.dna){let n=[];for(let[o,s]of await eo(e,t)){if(!o.startsWith(on)||!o.endsWith(wo)||o.slice(on.length).includes(\"/\"))continue;let i=o.slice(on.length,-wo.length),c;try{let a=await e.get(s);if(!a)throw new Error(`blob ${s} is not kept`);if(c=await this.#t.terrain.loader.load(Yt(a.body),s),c.module!==i)throw new Error(`${o} declares module ${c.module}`)}catch(a){c=a instanceof Error?a:new Error(String(a))}n.push({name:i,blob:s,loaded:c})}return n}async wake(){this.#c||(this.cells.live=await this.#f(this.#t.dna,new Map,\"genesis\"),await this.#t.keep());let t=new Map;try{for(let{name:e,blob:n,loaded:o}of await this.#p(this.#c)){let s=o instanceof Error?o.message:this.#u([...[...t.values()].map(i=>i.module),o]);s===null?t.set(e,{module:o,blob:n}):this.#n.set(e,{blob:n,reason:s})}}catch(e){this.#o=nn(e)}this.#r=t,this.#e=new Ut(this.#t.kit,[...t.values()].map(e=>e.module))}async#a(t,e){let n;try{n=await this.#p(t,e)}catch(c){return nn(c)}let o=n.find(c=>c.loaded instanceof Error);if(o)return`${o.name}: ${o.loaded.message}`;let s=n.map(c=>c.loaded),i=this.#u(s);return i!==null?i:(await e?.flush(),this.#e=new Ut(this.#t.kit,s),this.#r=new Map(n.map(c=>[c.name,{module:c.loaded,blob:c.blob}])),this.#n=new Map,this.#o=null,this.cells.live=t,await this.#t.ran(),null)}async#w(){return this.#c?eo(this.#t.dna,this.#c):new Map}add(t){return this.#l(()=>this.#h(t))}async#h(t){if(!ur(t.source))return{error:\"source is text\"};if(t.name!==void 0&&!ur(t.name))return{error:\"name is text\"};let e=new or(this.#t.dna),[n]=await e.put([Hr(t.source)]),o;try{o=await this.#t.terrain.loader.load(t.source,n)}catch(a){return{error:nn(a)}}if(t.name!==void 0&&t.name!==o.module)return{error:`the source is module ${o.module}, not ${t.name}`};let s=await this.#w();s.set(ni(o.module),n);let i=await this.#f(e,s,`add ${o.module} ${o.version}`),c=await this.#a(i,e);return c!==null?{error:c}:{added:o.module,version:o.version,live:i}}remove(t){return this.#l(()=>this.#g(t))}async#g(t){let e=t.module,n=await this.#w();if(!ur(e)||!n.has(ni(e)))return{error:\"no such module\"};if(this.#t.stands(this.#y(e)))return{error:\"a being stands on this module\"};n.delete(ni(e));let o=new or(this.#t.dna),s=await this.#f(o,n,`remove ${e}`),i=await this.#a(s,o);return i!==null?{error:i}:{removed:e,live:s}}#y(t){if(this.#r.has(t))return this.#e.kindsOf(t);let e=hf(t);return this.#t.kept().filter(n=>n.startsWith(e)&&this.#e.classOf(n)===void 0)}live(t){return t.commit===void 0?Promise.resolve({live:this.#c??null}):this.#l(()=>this.#E(t))}async#E(t){let e=t.commit,n=ur(e)&&Object.hasOwn(this.#i,e)?this.#i[e]:e;if(!Vt(n))return{error:\"commit is a commit id or a fetched ref\"};let o=await this.#a(n);return o===null?{live:n}:{error:o}}async log(t){let e=t.commit??this.#c;if(!Vt(e))return{error:\"commit is a commit id\"};let n=[];try{for(let o=e;o!==void 0;){let s=await this.#t.dna.get(o);if(!s)break;let i=he(s);n.push({commit:o,parents:[...i.parents],message:i.message.replace(/\\n$/,\"\"),seconds:i.committer.seconds}),o=i.parents[0]}}catch(o){return{error:nn(o)}}return{log:n}}origin(t){let e=t.url;return e===null?(delete this.cells.origin,{origin:null}):!ur(e)||!/^https?:\\/\\/[^/\\s]+/.test(e)?{error:\"url is an http or https URL, or null\"}:(this.cells.origin=e,{origin:e})}fetch(){return this.#l(()=>this.#x())}async#x(){let t=this.cells.origin;if(!ur(t))return{error:\"no origin is set\"};try{let e=await Rs(t),n=s=>this.#t.dna.get(s),o=await Is(t,Object.values(e),n,await js(this.#b(),n));return await this.#t.dna.put([...o.values()]),this.cells.refs=e,{refs:e,objects:o.size}}catch(e){return{error:nn(e)}}}#b(){return[...new Set([...this.#c?[this.#c]:[],...Object.values(this.#i)])]}gc(){return this.#l(async()=>{if(!await this.#t.keep())throw new Error(\"her cells were not kept\");let t=this.#t.dna,e=new Set;for(let n of this.#b()){let o=n;for(let s=await t.get(o);s?.type===\"tag\";s=await t.get(o))e.add(o),o=/^object ([0-9a-f]{40})$/m.exec(Yt(s.body))?.[1]??\"\";for(let s of await Ts(t,o))e.add(s)}return{collected:await t.collect(e),kept:e.size}})}async sources(){let t=[];for(let[e,n]of await this.#w()){if(!e.startsWith(on)||!e.endsWith(wo))continue;let o=await this.#t.dna.get(n);o&&t.push({blob:n,source:Yt(o.body)})}return{live:this.#c??null,sources:t}}modules(){let t={};for(let[e,n]of this.#r)t[e]={running:n.module.version,blob:n.blob};for(let[e,n]of this.#n)t[e]={running:null,blob:n.blob,failed:n.reason};return{live:this.#c??null,modules:t,...this.#o===null?{}:{failed:this.#o}}}};var sn,yo=12,Aa=2,_e=class{static prefix=_(I(\"catalogue\"));#t;#e;#r=new Map;#n;constructor(t,e){this.#t=t,this.#e=e}static occupies(t){return t.length===sn.prefix.length+Aa&&t.startsWith(sn.prefix)}#o(){return this.#n??=this.#e.derive([\"seal\",\"dna\"],32)}async#s(t){let e=_(await this.#e.derive([\"dna\",t],16));return{place:sn.prefix+e.slice(0,Aa),name:e}}async get(t){let e=this.#r.get(t);if(e)return e;let{place:n,name:o}=await this.#s(t),s=(await this.#t.read(n)).get(o);if(!s||s.length<=yo)return null;let i=await qt(await this.#o(),s.subarray(0,yo),I(o),s.subarray(yo));if(i===null)return null;let c=await Es(i);return await Ft(c)!==t?null:(this.#r.set(t,c),c)}async put(t){let e=[],n=new Map,o=new Map;for(let s of t){let i=await Ft(s);if(e.push(i),this.#r.has(i)||o.has(i))continue;let{place:c,name:a}=await this.#s(i),u=this.#e.entropy.draw(yo),l=C(u,await Dt(await this.#o(),u,I(a),await xs(s)));n.has(c)||n.set(c,new Map),n.get(c).set(a,l),o.set(i,s)}for(let[s,i]of n)await this.#t.write(s,i);for(let[s,i]of o)this.#r.set(s,i);return e}async#u(){return(await this.#t.places()).filter(t=>sn.occupies(t))}async count(){let t=0;for(let e of await this.#u())t+=(await this.#t.read(e)).size;return t}async collect(t){let e=new Set(t),n=new Set;for(let s of e)n.add((await this.#s(s)).name);let o=0;for(let s of await this.#u()){let i=new Map;for(let c of(await this.#t.read(s)).keys())n.has(c)||i.set(c,null);i.size!==0&&(await this.#t.write(s,i),o+=i.size)}for(let s of[...this.#r.keys()])e.has(s)||this.#r.delete(s);return o}};sn=_e;var lr=\"org.nervur.memory\",Ot=class extends G{static kind=lr;static{U(this)}occupies(t){return!1}};var It=\"box\",vt=r=>typeof r==\"string\",oi=r=>Array.isArray(r)&&r.length>0&&Gr(r).length===r.length,Ba=(r,t)=>t?.hosted===!0,pf=r=>r===lt||typeof r==\"function\"&&r.prototype instanceof lt,mo=r=>yt.fulfils(r)&&!jt.fulfils(r),jt=class extends yt{static kind=\"org.nervur.dock\";static{U(this)}static cells={hosted:[],routes:{},reach:[]};static asks={...yt.asks,stand:L(\"every faculty and hosted ward that does not stand yet, stood; silence where everything stands\"),open:L(\"a faculty of this harbor\",{required:[\"key\",\"class\"]}),host:L(\"a ward this harbor hosts, kept by the root memory or by the memory faculty named\",{required:[\"ward\"]}),move:L(\"a hosted ward carried to a memory faculty, or to the root memory with null\",{required:[\"ward\",\"memory\"]}),hold:L(\"an owner invitation on a far being, held under a name from now on, at the address named\",{required:[\"name\",\"invitation\"]}),route:L(\"where a ward is reached, addresses in order, or null\",{required:[\"ward\",\"at\"]}),reach:L(\"where this harbor is reached, the addresses every invitation carries\",{required:[\"at\"]}),sweep:en(\"every place of the memory this harbor does not name, gone\"),heard:L(\"a push heard, told to every carrier, so one that collects for this harbor collects\"),lend:{description:\"an offer from a faculty fulfilling a contract\",input:{type:\"object\",required:[\"contract\"]},for:Ba},retract:{description:\"an offer that was not taken\",input:{type:\"object\",required:[\"contract\",\"heir\"]},for:Ba}};#t;constructor(t){super(t),this.#t=t.ground}async stand(){let t=[...await this.#e(ar),...await this.#e(n=>n.prototype instanceof Ot),...await this.#e(()=>!0)];for(let[n,o]of Object.entries(this.routes))this.#t.reached(n,o);let e=[];for(let n of this.hosted)await this.#t.stand(n)&&e.push(n.ward);return t.length+e.length>0?{stood:t,wards:e}:void 0}async#e(t){let e=[];for(let n=!0;n;){n=!1;for(let[o,s]of Object.entries(this.steward.beings())){let i=s.absent?this.steward.classOf(s.class,s.registry):void 0;!i||!t(i)||this.steward.stand(o)!==\"booted\"||(n=!0,e.push(o),await this.#t.rouse(o))}}return e}describe(t){let e=super.describe(t);if(!Te(t,this.notes(t)))return e;let n=e.notes;return n.wards=Object.fromEntries(this.hosted.map(({ward:o,memory:s,registry:i})=>[o,{...s===void 0?{}:{memory:s},...i===void 0?{}:{registry:i}}])),n.routes=this.routes,n.reach=this.addresses,n.failed=this.#t.failures(),n.listening=this.#t.listening(),this.#t.foreground&&(n.foreground=!0),e}async heard(){return await this.#t.heard(),{heard:!0}}get hosted(){return this.cells.hosted.map(({ward:t,seed:e,memory:n,registry:o})=>({ward:t,seed:e,...n===void 0?{}:{memory:n},...o===void 0?{}:{registry:o}}))}#r(t){return vt(t)&&this.#o(lr).includes(t)}#n(t){if(t==null||t===Qt)return{registry:void 0};if(!vt(t))return null;let e=this.steward.beings()[t],n=e&&!e.absent?this.steward.classOf(e.class,e.registry):void 0;return ar(n)?{registry:t}:null}get routes(){return Object.fromEntries(Object.entries(this.cells.routes).map(([t,e])=>[t,[...e]]))}get addresses(){return[...this.cells.reach]}route(t){let{ward:e}=t,n=typeof t.at==\"string\"?[t.at]:t.at;if(!vt(e)||n!==null&&!oi(n)||!this.#t.route(e,n))return{error:\"not routed\"};let o=this.cells.routes;return n===null?delete o[e]:o[e]=[...n],{routed:e}}reach(t){return oi(t.at)?(this.cells.reach=[...t.at],{reach:[...t.at]}):{error:\"at is a list of addresses\"}}async hold(t){if(t.at!==void 0){if(!oi([t.at]))return{error:\"at is an address\"};let e=kt(t.invitation)?.ward;if(e===void 0)return{error:\"no invitation\"};let n=this.route({ward:e,at:[t.at]});if(n.error!==void 0)return n}return super.hold(t)}async learn(t,e){let n=this.cells.routes;Object.hasOwn(n,t)||!this.#t.route(t,e)||(n[t]=[...e],await this.#t.keep())}become(t){if(!vt(t.class))return{error:\"class is text\"};let e=this.#n(t.registry);if(e===null)return{error:\"no such registry faculty\"};let{registry:n}=e;if(n!==void 0&&this.steward.beings()[n].registry!==void 0)return{error:\"the dock stands through the catalogue or a registry it stands\"};let o=this.steward.become(t.class,n);return o===null?{became:t.class}:{error:o}}boot(){return Promise.resolve({error:\"a faculty is opened, and nothing else stands in the box ward\"})}async unboot(t){return this.hosted.some(e=>e.memory!==void 0&&e.memory===t.being)?{error:\"a ward is kept by this memory faculty\"}:(typeof t.being==\"string\"&&await this.#t.lull(t.being),super.unboot(t))}async open(t){if(!vt(t.key)||!vt(t.class))return{error:\"key and class are text\"};let e=this.#n(t.registry);if(e===null)return{error:\"no such registry faculty\"};let{registry:n}=e,o=this.steward.classOf(t.class,n);if(!G.fulfils(o)||pf(o))return{error:\"no such faculty\"};if(await this.steward.boot(t.key,t.class,n)!==\"booted\")return{error:\"not opened\"};let s=await this.steward.invite(t.key,D,{});return s===null||await this.stance.standings.take(t.key,s)===null?(this.steward.unboot(t.key),{error:\"not opened\"}):(await this.#t.awaken(t.key),{opened:t.key})}async sweep(){return{swept:await this.#t.sweep()}}async host(t){let e=t.ward;if(!vt(e))return{error:\"ward is text\"};if(e===It)return{error:\"box is the box ward\"};if(this.hosted.some(u=>u.ward===e))return{error:`${e} is hosted already`};if(t.seed!==void 0&&!vt(t.seed))return{error:\"seed is text\"};let n=t.memory??void 0;if(n!==void 0&&!this.#r(n))return{error:\"no such memory faculty\"};let o=this.#n(t.registry);if(o===null)return{error:\"no such registry faculty\"};let{registry:s}=o,i=t.class??void 0;if(i!==void 0&&(!vt(i)||!mo(this.steward.classOf(i,s))))return{error:\"no such ward class\"};let c=await this.stance.occupants.invite(e,{hosted:!0});if(c===null)return{error:\"not hosted\"};let a=await this.#t.host(e,c,t.seed,n,i,s);return a===null?(this.stance.occupants.remove(e),{error:\"not hosted\"}):(this.cells.hosted.push({ward:e,seed:a,...n===void 0?{}:{memory:n},...s===void 0?{}:{registry:s}}),{hosted:e})}async move(t){let n=this.cells.hosted.find(a=>a.ward===t.ward);if(!n)return{error:\"no such ward\"};let o=t.memory??void 0;if(o!==void 0&&!this.#r(o))return{error:\"no such memory faculty\"};let s=n.memory;if(s===o)return{error:`${n.ward} is kept there already`};let i=await this.#t.move(n.ward,n.seed,s,o);if(i!==null)return{error:i};let c=a=>{a===void 0?delete n.memory:n.memory=a};return c(o),await this.#t.keep()?(await this.#t.release(n.ward,s),{moved:n.ward,memory:o??null}):(c(s),await this.#t.move(n.ward,n.seed,o,s),{error:\"not kept\"})}async lend(t){if(!vt(t.contract))return{error:\"contract is text\"};let e=await this.offer(t.contract);return e?{invitation:e}:{error:\"nothing lent\"}}async retract(t){return!vt(t.contract)||!vt(t.heir)?{error:\"contract and heir are text\"}:(await this.withdraw(t.contract,t.heir),{retracted:t.heir})}async offer(t){for(let e of this.#o(t)){let n=await this.stance.standings.get(e)?.ask(\"offer\"),o=kt(n?.invitation);if(o)return o}return null}async withdraw(t,e){for(let n of this.#o(t))await this.stance.standings.get(n)?.ask(\"retract\",{heir:e})}#o(t){let e=this.steward.beings();return this.stance.standings.ids().filter(n=>{let o=e[n],s=o&&!o.absent?this.steward.classOf(o.class,o.registry):void 0;return G.fulfils(s)&&G.contracts(s).includes(t)})}};var $t=r=>{let{ground:t}=r;if(!t)throw new Error(\"a kit faculty stands in the box ward alone\");return t},mt=Symbol(\"undialed\"),ft=class extends G{static kind=\"org.nervur.carrier\";static{U(this)}static carries=null;listening(){return[]}relay(t,e){return null}heard(){return Promise.resolve()}awake(){return Promise.resolve()}sleep(){return Promise.resolve()}},si=(r,t,e)=>{let n=t.filter(i=>i.prototype instanceof ft&&i.carries===e),o=Object.entries(r).find(([,i])=>n.some(c=>c.kind===i.class));if(o)return{key:o[0]};let s=n[0];return s?{key:e,open:{method:\"open\",args:{key:e,class:s.kind}}}:null};var ai=async(r,t)=>{let e=await r.places();for(let n of e)await t.write(n,await r.read(n));return e},ui=r=>{if(typeof r!=\"object\"||r===null)return null;let{seed:t,places:e}=r;if(t!==void 0&&!K(t,32)||typeof e!=\"object\"||e===null||Array.isArray(e))return null;for(let n of Object.values(e)){if(typeof n!=\"object\"||n===null||Array.isArray(n))return null;for(let o of Object.values(n))if(!K(o))return null}return{...t===void 0?{}:{seed:t},places:e}};var li=async(r,t)=>{for(let[e,n]of Object.entries(t.places))await r.write(e,new Map(Object.entries(n).map(([o,s])=>[o,$(s)])));return Object.keys(t.places)},go=12,wf=I(\"nervur-package\"),ii=class{rows;#t;#e=new Set;#r=Promise.resolve(!0);constructor(t,e){this.#t=t,this.rows=e}told(t){this.#e.add(t)}kept(){let t=[...this.#e];return this.#e.clear(),this.#r=this.#r.then(()=>this.#n(t)).catch(()=>!1),this.#r}async#n(t){if(t.length===0)return!0;let e=this.rows.beings??{},n=new Map;for(let o of t){let s=o===Qr?this.rows.ward??null:Object.hasOwn(e,o)?e[o]:void 0;n.set(await this.#t.entry(o),s===void 0?null:await this.#t.seal(o,s))}return await this.#t.write(n),!0}},ci=class{#t;#e;#r;#n;place;constructor(t,e,n,o,s){this.#t=t,this.#e=e,this.#r=n,this.place=o,this.#n=s}read(){return this.#n.read(this.place)}entry(t){return this.#t.derive([\"entry\",this.#e,t],16).then(_)}async seal(t,e){let n=this.#t.entropy.draw(go),o=I(JSON.stringify({row:t,value:e}));return C(n,await Dt(this.#r,n,I(await this.entry(t)),o))}async open(t,e){let n=e.length>go?await qt(this.#r,e.subarray(0,go),I(t),e.subarray(go)):null;if(n===null)throw new Error(\"an entry the package did not seal\");return JSON.parse(new TextDecoder().decode(n))}write(t){return this.#n.write(this.place,t)}},cn=class r{memory;entropy;#t;constructor(t,e,n){this.memory=t,this.entropy=e,this.#t=n}static async open(t,e,n){return new r(t,e,await dt(n,wf,32))}derive(t,e){return dt(this.#t,I(JSON.stringify(t)),e)}place(t){return this.derive([\"place\",t],16).then(_)}async rows(t,e=this.memory){let n=new ci(this,t,await this.derive([\"seal\",t],32),await this.place(t),e),o={},s={},i=!1;for(let[c,a]of await n.read()){let{row:u,value:l}=await n.open(c,a);i=!0,u===Qr?o.ward=l:s[u]=l}return i&&(o.beings=s),new ii(n,o)}};var bo=[],je=(r,t)=>{bo.some(e=>e.probe.name===r.name)||bo.push({probe:r,defaults:t})},fi=()=>bo.map(r=>r.probe.name).reverse(),an=(r,t=bo)=>{for(let{probe:e,defaults:n}of[...t].reverse())if(e.fits(r))return{ground:e.name,terrain:e.terrain(r,n)};throw new Error(\"no ground fits here\")};var Sa=r=>typeof r==\"object\"&&r!==null&&!Array.isArray(r),un=r=>{if(!Sa(r))return null;let{ward:t,method:e,args:n}=r;return t!==void 0&&typeof t!=\"string\"||e!==void 0&&typeof e!=\"string\"||n!==void 0&&!Sa(n)?null:{...t===void 0?{}:{ward:t},...e===void 0?{}:{method:e},...n===void 0?{}:{args:n}}};var te=class{tcp=void 0;web=void 0;wakes=!0;get foreground(){return!1}claim(){return Promise.resolve()}stand(t){return Promise.resolve()}release(){return Promise.resolve()}};var yf=({dock:r})=>({genesis:r.kind,contract:\"dock\",fits:t=>jt.fulfils(t),fallback:r}),di=({ward:r},t=r.kind)=>({genesis:t,contract:\"hosted ward\",fits:mo}),ee=class r{#t;#e;#r=new Map;#n={wards:{},routes:{}};#o;#s={carry:(t,e)=>this.#E(t,e)};#u={classOf:(t,e)=>this.#l(t,e)};constructor(t,e){let{dock:n,ward:o,classes:s}=t.defaults;if(!jt.fulfils(n))throw new Error(\"the default dock is no dock\");if(!mo(o))throw new Error(\"the default ward is no hosted ward\");this.#t=t,this.#e=e;let i=new _e(t.memory,e),c=[lt,n,o,...s];this.#o={terrain:t,dna:i,kit:c,foreground:t.foreground,arrive:(a,u)=>this.arrive(a,u),host:(a,u,l,f,h,p)=>this.#x(a,u,l,f,h,p),stand:a=>this.#p(a),move:(a,u,l,f)=>this.#w(a,u,l,f),release:async(a,u)=>this.#h(u).forget(await this.#e.place(a)),route:(a,u)=>this.#b(a,u),reached:(a,u)=>{this.#O(u)||(this.#n.routes[a]=\"no carrier dials it\")},keep:()=>this.#i.partition.kept(),failures:()=>this.#y(),sweep:()=>this.#a(),awaken:async a=>{let u=this.#i.being(a);u instanceof ft&&await u.awake()},rouse:async a=>{t.wakes&&await this.#o.awaken(a)},lull:async a=>{let u=this.#i.being(a);u instanceof ft&&await u.sleep()},listening:()=>this.#m.flatMap(a=>a.listening()),heard:async()=>{await Promise.all(this.#m.map(a=>a.heard()))},ran:()=>{for(let a of this.#r.values())a.renew();return Promise.resolve()},stands:a=>[...this.#r.values()].some(u=>Object.values(u.partition.beings).some(l=>a.includes(l.class))),kept:()=>[...new Set([...this.#r.values()].flatMap(a=>Object.values(a.partition.beings).map(u=>u.class)))]}}static async open(t={}){let e=t instanceof te?t:an(t).terrain;await e.claim();let n;try{n=await r.#c(e)}catch(o){throw await e.release(),o}try{await e.stand(n)}catch(o){throw await n.close(),o}return n}static async#c(t){let e=await t.custody.seed(),n=new r(t,await cn.open(t.memory,t.entropy,e)),o=await n.#v(It,e,{ward:yf(t.defaults),carries:{ground:n.#o},classes:n.#u,stands:!0});if(o.partition.being(Qt))o.stand(Qt);else if(await o.make(Qt,lt.kind)!==\"booted\"||!await o.partition.kept())throw new Error(\"the catalogue did not stand\");let s=o.being(Qt);if(!(s instanceof lt))throw new Error(\"the catalogue did not stand\");await s.wake();for(let[i,c]of Object.entries(o.partition.beings))c.registry===void 0&&ar(s.classOf(c.class))&&o.stand(i);return await o.standWard(),n}async ask(t){let e=un(t);if(e===null)return{error:\"not a root request\"};let n=e.ward===void 0?this.#i:this.#r.get(e.ward);if(n===void 0){let s=this.#y().wards[e.ward];return s===void 0?{error:\"no such ward\"}:{error:\"the ward did not stand\",reason:s}}let o=await n.root(e.method,e.args);return St(o)?{silence:!0}:wt(o)?{word:de(o)}:{answer:o}}async arrive(t,e){let n=this.#A(t);return n?(await n.door.arrive(e)).bytes:await this.#k(t,e)??null}holds(t){return this.#A(t)!==void 0}async close(){for(let t of this.#m.reverse())await t.sleep();await this.#t.release()}get#i(){return this.#r.get(It)}get#d(){return this.#i.ward}#l(t,e=Qt){if(t===lt.kind)return lt;let n=this.#r.get(It)?.being(e);return n instanceof Mt?n.classOf(t):void 0}#f(t){return{classOf:e=>this.#l(e,t)}}async#p(t){let e=!this.#r.has(t.ward);try{return e&&await this.#v(t.ward,$(t.seed),{ward:di(this.#t.defaults),classes:this.#f(t.registry)},this.#h(t.memory)),await this.#r.get(t.ward).standWard(),delete this.#n.wards[t.ward],e}catch(n){return this.#r.delete(t.ward),this.#n.wards[t.ward]=n instanceof Error?n.message:String(n),!1}}async#a(){let t=async s=>{let i=this.#d.hosted.filter(c=>c.memory===s).map(c=>c.ward);return new Set(await Promise.all((s===void 0?[It,...i]:i).map(c=>this.#e.place(c))))},e=this.#g(),n=[],o=await t(void 0);for(let s of await this.#t.memory.places())o.has(s)||_e.occupies(s)||e.some(([,i])=>i.occupies(s))||(await this.#t.memory.forget(s),n.push(s));for(let[s,i]of e){let c=await t(s);for(let a of await i.places())c.has(a)||(await i.forget(a),n.push(a))}return n}async#w(t,e,n,o){let s=this.#r.get(t);if(!s)return\"the ward does not stand\";let i=this.#h(n),c=this.#h(o);this.#r.delete(t);try{if(!await s.partition.kept())throw new Error(\"the ward was not kept\");let a=await this.#e.place(t),u=new Map(await i.read(a));for(let h of(await c.read(a)).keys())u.has(h)||u.set(h,null);await c.write(a,u);let l=this.#d.hosted.find(h=>h.ward===t)?.registry;return await(await this.#v(t,$(e),{ward:di(this.#t.defaults),classes:this.#f(l)},c)).standWard(),null}catch(a){return this.#r.set(t,s),a instanceof Error?a.message:String(a)}}#h(t){if(t===void 0)return this.#t.memory;let e=this.#i.being(t);if(e instanceof Ot)return e;throw new Error(`the memory faculty ${t} does not stand`)}#g(){return Object.keys(this.#i.partition.beings).flatMap(t=>{let e=this.#i.being(t);return e instanceof Ot?[[t,e]]:[]})}#y(){let t=this.#i.fault;return{wards:{...this.#n.wards,...t===null?{}:{[It]:t}},routes:{...this.#n.routes}}}async#E(t,e){if(this.holds(t))return this.arrive(t,e);let n=this.#k(t,e);if(n!==void 0)return n;let o=this.#d.routes[t];if(o===void 0)return this.#t.carrier.carry(t,e);for(let s of o){let i=this.#m.find(a=>a.accepts(s)),c=i?await i.dial(s,t,e):mt;if(c!==mt)return c}return null}async#x(t,e,n,o,s,i){if(this.#r.has(t))return null;let c=n===void 0?this.#t.entropy.draw(32):K(n,32)?$(n):null;if(c===null||this.holds((await Be.from(c)).pk))return null;let a;try{a=await this.#v(t,c,{dock:e,ward:di(this.#t.defaults,s),classes:this.#f(i)},this.#h(o)),await a.standWard()}catch{return this.#r.delete(t),null}return a.ward.stance.standings.get(Re)?_(c):(this.#r.delete(t),null)}#b(t,e){let n=K(t,64)&&(e===null||this.#O(e));return n&&delete this.#n.routes[t],n}get#m(){return Object.keys(this.#i.partition.beings).map(t=>this.#i.being(t)).filter(t=>t instanceof ft)}#k(t,e){for(let n of this.#m){let o=n.relay(t,e);if(o!==null)return o}}#O(t){return t.some(e=>this.#m.some(n=>n.accepts(e)))}async#v(t,e,n,o){let{entropy:s,clock:i}=this.#t,c=await rn.unpack({seed:e,memory:await this.#e.rows(t,o),entropy:s,clock:i,carrier:this.#s,routes:this.#B,...n});return this.#r.set(t,c),c}#B={reach:()=>{if(!this.#r.has(It))return[];let t=this.#d.addresses;return t.length>0?t:this.#m.flatMap(e=>e.listening()).filter(e=>!Ps(e))},learn:(t,e)=>this.holds(t)?Promise.resolve():this.#d.learn(t,e)};#A(t){for(let e of this.#r.values())if(e.pk===t)return e}};var Eo=0,pi=1,xo=2,Ta=1048645,hi=64,wi=(r,t,...e)=>{let n=new Uint8Array(5);return n[0]=r,new DataView(n.buffer).setUint32(1,t>>>0),C(n,...e)},mf=r=>{let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,r.length),C(t,r)},ko=(r,t,e)=>wi(Eo,r,t,e),yi=(r,t)=>wi(pi,r,t),mi=r=>wi(xo,r),gi=(r,t,e)=>mf(ko(r,t,e));var Ra=(r,t)=>r>Ta||r<5||t!==void 0&&(t>xo||t===Eo&&r<5+hi||t===xo&&r!==5),fr=r=>{if(Ra(r.length,r[0]))return null;let t=new DataView(r.buffer,r.byteOffset).getUint32(1);return r[0]===Eo?{kind:\"ask\",id:t,pk:r.slice(5,5+hi),box:r.slice(5+hi)}:r[0]===pi?{kind:\"reply\",id:t,box:r.slice(5)}:{kind:\"nothing\",id:t}},ln=class{#t=new Uint8Array(0);#e=!1;get bad(){return this.#e}push(t){if(this.#e)return[];this.#t=this.#t.length===0?t.slice():C(this.#t,t);let e=[];for(;this.#t.length>=4;){let n=new DataView(this.#t.buffer,this.#t.byteOffset).getUint32(0);if(Ra(n,this.#t.length>4?this.#t[4]:void 0))return this.#e=!0,this.#t=new Uint8Array(0),e;if(this.#t.length<4+n)break;let o=fr(this.#t.subarray(4,4+n));this.#t=this.#t.slice(4+n),e.push(o)}return e}};var _a=65,Oo=1048640,gf=4294967295,ja=r=>new Uint8Array(r),bi=class r{#t;#e=new Map;#r=1;constructor(t){this.#t=t,t.binaryType=\"arraybuffer\",t.addEventListener(\"message\",e=>{let n=typeof e.data==\"string\"?null:fr(new Uint8Array(e.data));if(n===null)return this.close();if(n.kind===\"ask\")return;let o=this.#e.get(n.id);this.#e.delete(n.id),o?.(n.kind===\"reply\"?n.box:null)}),t.addEventListener(\"close\",()=>{for(let e of this.#e.values())e(null);this.#e.clear()})}static open(t,e){return new Promise(n=>{let o;try{o=new WebSocket(t,\"quo\")}catch{n(null);return}let s=new r(o);o.addEventListener(\"open\",()=>o.protocol===\"quo\"?n(s):(o.close(),n(null))),o.addEventListener(\"close\",()=>{e(),n(null)}),o.addEventListener(\"error\",()=>n(null))})}ask(t,e){if(this.#t.readyState!==WebSocket.OPEN)return Promise.resolve(null);let n=this.#r;return this.#r=this.#r===gf?1:this.#r+1,new Promise(o=>{this.#e.set(n,o),this.#t.send(ja(ko(n,t,e)))})}close(){this.#t.close()}},Ie=class{#t=new Map;dial(t,e,n){let o=ir(t);return o===null||!K(e,64)?Promise.resolve(mt):o.held?this.#r(o,e,n):this.#e(o,e,n)}async#e(t,e,n){let o;try{o=await fetch(t.href,{method:\"POST\",body:ja(C($(e),n))})}catch{return mt}let s=new Uint8Array(await o.arrayBuffer().catch(()=>new ArrayBuffer(0)));return o.status===200&&s.length>0?s:null}async#r(t,e,n){let o=this.#t.get(t.href);o||(o=bi.open(t.href,()=>this.#t.delete(t.href)),this.#t.set(t.href,o),o.then(i=>i??this.#t.delete(t.href)));let s=await o;return s?s.ask($(e),n):mt}async close(){let t=[...this.#t.values()];this.#t.clear();for(let e of await Promise.all(t))e?.close()}},xi=r=>r.length<_a||r.length>Oo?null:{pk:_(r.subarray(0,64)),box:r.slice(64)};var bf=(r,t)=>t===null?null:r.includes(\"*\")?\"*\":r.includes(t)?t:null,fn=async(r,t,e)=>{let n=new Headers,o=bf(t.origins,e.headers.get(\"origin\"));if(o!==null&&n.set(\"access-control-allow-origin\",o),new URL(e.url).pathname!==t.path)return new Response(null,{status:404,headers:n});if(e.method===\"OPTIONS\")return o!==null&&(n.set(\"access-control-allow-methods\",\"POST\"),n.set(\"access-control-allow-headers\",\"content-type\")),new Response(null,{status:204,headers:n});if(e.method!==\"POST\")return n.set(\"allow\",\"POST, OPTIONS\"),new Response(null,{status:405,headers:n});let s=new Uint8Array(await e.arrayBuffer()),i=s.length>Oo?null:xi(s);if(i===null)return new Response(null,{status:400,headers:n});let c=await r.arrive(i.pk,i.box).catch(()=>null);return c===null||c.length===0?new Response(null,{status:204,headers:n}):(n.set(\"content-type\",\"application/octet-stream\"),new Response(new Uint8Array(c),{status:200,headers:n}))},Ei=(r,t,e)=>{let n=typeof e==\"string\"?null:fr(e);if(n===null)return t.close();n.kind===\"ask\"&&r.arrive(_(n.pk),n.box).catch(()=>null).then(o=>t.send(o===null?mi(n.id):yi(n.id,o)))};var Na=function(r,t){return typeof r==\"string\"&&/^\\.\\.?\\//.test(r)?r.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i,function(e,n,o,s,i){return n?t?\".jsx\":\".js\":o&&(!s||!i)?e:o+s+\".\"+i.toLowerCase()+\"js\"}):r},Nt=class extends qe{draw(t){return globalThis.crypto.getRandomValues(new Uint8Array(t))}},$e=class extends ze{now(){return Date.now()}wait(t){let e;return{done:new Promise(o=>e=setTimeout(o,t)),cancel:()=>clearTimeout(e)}}},Ne=class extends oe{#t;constructor(t){super(),this.#t=t.draw(32)}seed(){return Promise.resolve(this.#t.slice())}},Ia=async r=>{let t=URL.createObjectURL(new Blob([r],{type:\"text/javascript\"}));try{return await import(Na(t))}finally{URL.revokeObjectURL(t)}},$a=r=>import(Na(`data:text/javascript;charset=utf-8,${encodeURIComponent(r)}`)),xf,Ef=()=>xf??=Ia(\"export const probe = 1;\").then(r=>r.probe===1?Ia:$a,()=>$a),re=class extends Ht{async load(t){let e=jo(t),n;try{n=await(await Ef())(e)}catch(o){throw new Error(`the module did not load: ${o instanceof Error?o.message:String(o)}`,{cause:o})}return He(n)}},Le=class extends Ht{#t;#e;constructor(t=[]){super(),this.#t=t}async load(t,e){this.#e??=Promise.all(this.#t.map(async s=>[await Ft(Hr(s.source)),s.module])).then(s=>new Map(s));let n=(await this.#e).get(e);if(n)return He(n);let o=this.#t.map(s=>s.module.module);throw new Error(`redeploy needed: blob ${e} is no module this bundle carries${o.length===0?\", and it carries none\":`: it carries ${o.join(\", \")}`}`)}},De=class extends ne{#t=new Map;read(t){let e=this.#t.get(t)??new Map;return Promise.resolve(new Map([...e].map(([n,o])=>[n,o.slice()])))}write(t,e){let n=this.#t.get(t);n||this.#t.set(t,n=new Map);for(let[o,s]of e)s===null?n.delete(o):n.set(o,s.slice());return n.size===0&&this.#t.delete(t),Promise.resolve()}places(){return Promise.resolve([...this.#t.keys()])}forget(t){return this.#t.delete(t),Promise.resolve()}};var dr=class extends we{carry(){return Promise.resolve(null)}},hr=class extends we{#t;constructor(t){super(),this.#t=t}carry(t,e){return this.#t.carry(t,e)}},Lt=class extends te{entropy;clock;custody;memory;carrier;loader;defaults;tcp;web;wakes;constructor(t){super(),this.entropy=t.entropy??new Nt,this.clock=t.clock??new $e,this.custody=t.custody??new Ne(this.entropy),this.memory=t.memory??new De,this.carrier=t.carrier??new dr,this.loader=t.loader??new re,this.defaults=t.defaults,this.tcp=t.tcp,this.web=t.web,this.wakes=t.wakes??!0}},dn=class r{#t=new Map;#e;cut=new Set;constructor(t){this.#e=t}async harbor(t,e={}){if(this.#t.has(t))throw new Error(`a harbor named ${t} stands`);let n=new Lt({defaults:this.#e,...e,carrier:new hr(this)}),o=await r.#r(n);return this.#t.set(t,{harbor:o,terrain:n}),o}static async#r(t){let e=await ee.open(t);return await e.ask({method:\"stand\"}),e}get(t){let e=this.#t.get(t);if(!e)throw new Error(`no harbor named ${t}`);return e.harbor}async restart(t,e){let n=this.#t.get(t);if(!n)throw new Error(`no harbor named ${t}`);let o=n.terrain,s={entropy:o.entropy,clock:o.clock,custody:o.custody,memory:o.memory,loader:o.loader,defaults:o.defaults,...o.tcp?{tcp:o.tcp}:{},...o.web?{web:o.web}:{}},i=e?new Lt({...s,...e,carrier:o.carrier}):o,c=await r.#r(i);return this.#t.set(t,{harbor:c,terrain:i}),c}carry(t,e){for(let[n,{harbor:o}]of this.#t)if(o.holds(t))return this.cut.has(n)?Promise.resolve(null):o.arrive(t,e);return Promise.resolve(null)}};var vo=\"neutral\",ki={name:vo,fits:()=>!0,terrain:({bundle:r},t)=>new Lt({loader:r?new Le(r):new re,defaults:t})};var kf=function(r,t){return typeof r==\"string\"&&/^\\.\\.?\\//.test(r)?r.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i,function(e,n,o,s,i){return n?t?\".jsx\":\".js\":o&&(!s||!i)?e:o+s+\".\"+i.toLowerCase()+\"js\"}):r},Of=\"edge\",vf=\"m/\",Af=\"c/seed\",Oi=128,Bf=I(\"nervur edge custody\"),Sf=4294967295,Ai=class{#t;#e=new Set;#r=new Set;constructor(t){this.#t=t}run(t,e){return this.#t?this.#t.run(t,e):e()}refused(){let t=this.#t?.getStore();t!==void 0&&this.#e.add(t)}kept(){let t=this.#t?.getStore();t!==void 0&&this.#r.add(t)}again(t){let e=this.#e.delete(t)&&!this.#r.has(t);return this.#r.delete(t),e}},Ao=class extends Ht{#t;#e=new Map;#r=new Map;#n;constructor(t=[],e){super(),this.#t=new Map(t.map(n=>[n.blob,n.module])),this.#n=e}get carried(){return[...this.#t.keys()]}refuse(t){for(let[e,n]of Object.entries(t))this.#e.set(e,n)}get refused(){return this.#e}load(t,e){if(this.#t.has(e))return Promise.resolve().then(()=>He(this.#t.get(e)));let n=this.#e.get(e);return n!==void 0?Promise.reject(new Error(n)):(this.#r.set(e,t),this.#n?.refused(),Promise.reject(new Error(`blob ${e} is carried by the next child`)))}get missing(){return this.#r.size>0}missed(){return new Map(this.#r)}},Ca=r=>typeof r==\"string\"&&/^[a-z0-9][a-z0-9-]{0,62}$/.test(r),hn=12,X0=r=>{if(typeof r!=\"object\"||r===null||Array.isArray(r))return null;let t={};for(let[e,n]of Object.entries(r)){let{sealed:o,places:s}=n??{},i=ui({places:s});if(!Ca(e)||!K(o)||o.length<=hn*2||i===null)return null;t[e]={sealed:o,places:i.places}}return t},Ha=r=>dt(I(r),Bf,32),Y0=async(r,t,e=new Nt)=>{let n=e.draw(hn);return _(C(n,await Dt(await Ha(r),n,new Uint8Array(0),t)))},vi=r=>Array.from({length:Math.ceil(r.length/Oi)},(t,e)=>r.slice(e*Oi,(e+1)*Oi)),Bi=r=>new Uint8Array((r instanceof ArrayBuffer,r)),Si=class extends ne{#t;#e;#r;#n;constructor(t,e=\"\",n=()=>!1,o){super(),this.#t=t,this.#e=`${e}${vf}`,this.#r=n,this.#n=o}#o(){return this.#r()?(this.#n?.refused(),Promise.reject(new Error(\"a module was missed, so this call keeps nothing\"))):null}async read(t){let e=`${this.#e}${t}/`,n=await this.#t.list({prefix:e});return new Map([...n].map(([o,s])=>[o.slice(e.length),Bi(s).slice()]))}write(t,e){let n=this.#o();if(n)return n;let o=[],s=[];for(let[i,c]of e)c===null?s.push(`${this.#e}${t}/${i}`):o.push([`${this.#e}${t}/${i}`,c.slice()]);return this.#t.transaction(async i=>{for(let c of vi(o))await i.put(Object.fromEntries(c));for(let c of vi(s))await i.delete(c)}).then(()=>this.#n?.kept())}async places(){let t=this.#e,e=[...(await this.#t.list({prefix:t})).keys()];return[...new Set(e.map(n=>n.slice(t.length,n.indexOf(\"/\",t.length))))]}async forget(t){await this.#o();let e=[...(await this.#t.list({prefix:`${this.#e}${t}/`})).keys()];await this.#t.transaction(async n=>{for(let o of vi(e))await n.delete(o)}),this.#n?.kept()}},Ti=class extends oe{#t;#e;#r;#n;constructor(t,e,n=new Nt,o=\"\"){super(),this.#t=t,this.#e=e,this.#r=n,this.#n=`${o}${Af}`}async kept(){return await this.#t.get(this.#n)!==void 0}async land(t,e=this.#t){let n=$(t);await e.put({[this.#n]:{nonce:n.slice(0,hn),sealed:n.slice(hn)}})}async seed(){if(!this.#e)throw new Error(\"the worker holds no NERVUR_SECRET\");let t=await Ha(this.#e);return this.#t.transaction(async e=>{let n=await e.get(this.#n);if(n){let i=await qt(t,Bi(n.nonce),new Uint8Array(0),Bi(n.sealed));if(i===null)throw new Error(\"the seed does not open under this NERVUR_SECRET\");return i}let o=this.#r.draw(32),s=this.#r.draw(hn);return await e.put({[this.#n]:{nonce:s,sealed:await Dt(t,s,new Uint8Array(0),o)}}),o.slice()})}},Ri=class{#t;#e;#r=new Map;#n=1;#o=!1;constructor(t,e){this.#t=t,this.#e=t.writable.getWriter();let n=new ln;(async()=>{try{for await(let o of t.readable){for(let s of n.push(new Uint8Array(o))){if(s.kind===\"ask\")continue;let i=this.#r.get(s.id);this.#r.delete(s.id),i?.(s.kind===\"reply\"?s.box:null)}if(n.bad)break}}catch{}this.#o=!0,e();for(let o of this.#r.values())o(null);this.#r.clear(),await t.close().catch(()=>{})})()}ask(t,e){if(this.#o)return Promise.resolve(null);let n=this.#n;return this.#n=this.#n===Sf?1:this.#n+1,new Promise(o=>{this.#r.set(n,o),this.#e.write(gi(n,t,e)).catch(()=>o(null))})}close(){return this.#o=!0,this.#t.close().catch(()=>{})}},Tf=\"cloudflare:sockets\",Rf=async()=>{try{return(await import(kf(Tf))).connect}catch{return null}},_i=class{#t=new Map;async dial(t,e,n){let o=Ae(t);if(o===null||!K(e,64))return mt;let s=await this.#e(o);return s?s.ask($(e),n):mt}#e({host:t,port:e}){let n=oo(t,e),o=this.#t.get(n);return o||(o=(async()=>{let s=await Rf();if(!s)return null;try{let i=s({hostname:t,port:e});return await i.opened,new Ri(i,()=>this.#t.delete(n))}catch{return null}})(),this.#t.set(n,o),o.then(s=>s??this.#t.delete(n))),o}listen(){return Promise.reject(new Error(\"an edge takes no inbound TCP\"))}async close(){let t=[...this.#t.values()];this.#t.clear();for(let e of await Promise.all(t))await e?.close()}},_f=(r,t)=>{r.at=t;let e=t.port===0?t.host:`${oo(t.host,t.port).slice(6)}`,[n,o]=t.port===0?[\"https\",\"wss\"]:[\"http\",\"ws\"];return Promise.resolve({port:t.port,at:[`${n}://${e}${t.path}`,`${o}://${e}${t.path}`],close:()=>(r.at===t&&(r.at=void 0),Promise.resolve())})},ji=class extends Lt{given;#t;constructor(t){let e=new Nt,{storage:n}=t.given.state,o=t.given.loader??new Ao,s={at:void 0};super({entropy:e,loader:o,custody:new Ti(n,t.given.env.NERVUR_SECRET,e),memory:new Si(n,\"\",()=>o.missing,t.given.calls),tcp:()=>new _i,web:(i,c)=>_f(s,c),defaults:t.defaults}),this.given=t.given,this.#t=s}get listening(){return this.#t.at}async claim(){let t=this.given.package,e=this.custody;!t||await e.kept()||(await li(this.memory,{places:t.places}),await e.land(t.sealed))}},jf=r=>{let t=r;return typeof t?.state?.storage?.transaction==\"function\"&&typeof t.env==\"object\"},qa={name:Of,fits:({given:r})=>jf(r),terrain:({given:r},t)=>new ji({given:r,defaults:t})},za=r=>{let t=new URL(r.url).pathname.split(\"/\")[1];return Ca(t)?t:null},Ka=(r,t,e)=>{let n=[...new Set(t)].sort();return n.length===new Set(e).size&&e.every(s=>n.includes(s))?r:`${r}+${n.join(\"+\")}`},La=class{#t;#e;#r;#n;#o;#s;#u;#c;constructor(t,e,n,o,s){this.#t=t,this.#e=e,this.#r=n,this.#o=new Ai(s),this.#n=new Ao(o,this.#o)}async open(t,e,n,o,s){this.#n.refuse(s),this.#s??=this.#t.blockConcurrencyWhile(async()=>{let u=an({given:{state:this.#t,env:this.#e,loader:this.#n,calls:this.#o,...o?{package:o}:{}}}).terrain;this.#u=u;let l=await ee.open(u);if(this.#n.missing)return l;await l.ask({method:\"stand\"});let{beings:f}=(await l.ask({})).answer.notes,h=si(f,u.defaults.classes,\"web\");if(h===null)throw new Error(\"no class this edge runs carries web\");return h.open!==void 0&&await l.ask(h.open),u.listening?.path!==`/${t}/quo`&&await l.ask({method:\"ask\",args:{being:h.key,method:\"listen\",args:{host:e,port:n,path:`/${t}/quo`}}}),l});let i=await this.#s,c=this.#u?.listening;return{listen:c?{host:c.host,port:c.port,path:c.path,origins:[...c.origins]}:null,wanted:await this.#i(i)}}async arrive(t,e,n){let o=await this.#s;return o?this.#n.missing?{reply:null,wanted:await this.#i(o),again:!0}:{reply:await this.#o.run(n,()=>o.arrive(t,e)).catch(()=>null),wanted:await this.#i(o),again:this.#o.again(n)}:{reply:null,wanted:null,again:!1}}async#i(t){let e=this.#n.missed(),n=async a=>(await t.ask({method:\"ask\",args:{being:\"catalogue\",method:a}})).answer.answer,o=(await n(\"live\")).live;if(e.size===0&&o===this.#c)return null;let s=(await n(\"sources\")).sources,i=new Map(s.map(a=>[a.blob,a.source]));for(let[a,u]of e)i.set(a,u);for(let a of this.#n.refused.keys())i.delete(a);let c=s.map(a=>a.blob);return e.size===0&&Ka(o,[...i.keys()],c)===this.#r?(this.#c=o,null):{live:o,liveBlobs:c,modules:Object.fromEntries(i),missed:[...e.keys()]}}},Da=\"harbor\",If=\"Harbor\",Pa=\"harbor.js\",Fa=\"probe.js\",$f=\"boot\",Ma=\"2026-09-01\",Ua=8,Bo=r=>`${r}.js`,Nf=(r,t)=>[\"import { DurableObject } from 'cloudflare:workers';\",\"import { AsyncLocalStorage } from 'node:async_hooks';\",\"import { HarborChild } from 'nervur';\",...t.map((e,n)=>`import * as m${String(n)} from '${Bo(e)}';`),`const carried = [${t.map((e,n)=>`{ blob: '${e}', module: m${String(n)} }`).join(\", \")}];`,\"export class Harbor extends DurableObject {\",` #child = new HarborChild(this.ctx, this.env, ${JSON.stringify(r)}, carried, new AsyncLocalStorage());`,\" open(name, host, port, packed, refused) { return this.#child.open(name, host, port, packed, refused); }\",\" arrive(pk, box, call) { return this.#child.arrive(pk, box, call); }\",\"}\",\"\"].join(`\n`),Lf=r=>`import '${Bo(r)}';\nexport default { fetch() { return new Response(null, { status: 204 }); } };\n`,Df=r=>r instanceof Error?r.message:String(r),V0=({kit:r,pack:t})=>class{#t;#e;#r={};#n;#o;#s;#u;#c;#i;#d=null;#l;#f=Promise.resolve();#p=0;#a=0;#w=[];#h;constructor(e,n){this.#t=e,this.#e=n}async fetch(e){let n=za(e);if(n===null||this.#n!==void 0&&this.#n!==n)return new Response(null,{status:404});if(this.#n===void 0){let h=typeof t==\"function\"?t(this.#e):t,p=h&&Object.hasOwn(h,n)?h[n]:void 0;if(!p)return new Response(null,{status:404});let g=new URL(e.url);this.#n=n,this.#o=p,this.#s={host:g.hostname,port:g.port===\"\"?0:Number(g.port)}}this.#l??=this.#g(()=>this.#x($f,{},0)).catch(h=>{throw this.#l=void 0,h}),await this.#l;let o=this.#d;if(!o)return new Response(null,{status:404});let s={arrive:(h,p)=>this.#k(h,p)};if(e.headers.get(\"upgrade\")?.toLowerCase()!==\"websocket\")return fn(s,o,e);let i=(e.headers.get(\"sec-websocket-protocol\")??\"\").split(\",\").map(h=>h.trim());if(new URL(e.url).pathname!==o.path||!i.includes(\"quo\"))return new Response(null,{status:400});let c=globalThis.WebSocketPair,a=new c,[u,l]=[a[0],a[1]];l.accept();let f={send:h=>l.send(new Uint8Array(h)),close:()=>l.close()};return l.addEventListener(\"message\",h=>Ei(s,f,typeof h.data==\"string\"?h.data:new Uint8Array(h.data))),new Response(null,{status:101,webSocket:u,headers:{\"sec-websocket-protocol\":\"quo\"}})}#g(e){let n=this.#f.then(e,e);return this.#f=n.catch(()=>{}),n}#y(){let e=this.#e.LOADER;if(!e)throw new Error(\"the worker binds no LOADER: its wrangler.toml names a worker_loaders binding\");return e}#E(){return this.#u??=se(I(r)).then(e=>_(e).slice(0,16))}async#x(e,n,o,s=!1){let i=`${await this.#E()}:${e}`,c=Object.keys(n).sort(),a=this.#e.NERVUR_SECRET,u={compatibilityDate:Ma,compatibilityFlags:[\"nodejs_als\"],mainModule:Pa,modules:{[Pa]:{js:Nf(e,c)},nervur:{js:r},...Object.fromEntries(c.map(p=>[Bo(p),{js:n[p]}]))},env:a===void 0?{}:{NERVUR_SECRET:a}},l=this.#y().get(i,()=>Promise.resolve(u));this.#i&&this.#t.facets.abort(Da,new Error(\"live moved\"));let f=this.#t.facets.get(Da,()=>Promise.resolve({class:l.getDurableObjectClass(If)}));this.#i=f,this.#c=e,this.#h=void 0;let h=await f.open(this.#n,this.#s.host,this.#s.port,this.#o??null,{...this.#r});this.#d=h.listen,h.wanted&&(!s||h.wanted.missed.length>0)&&await this.#b(h.wanted,o+1)}async#b(e,n){if(n>Ua)throw new Error(\"the harbor settles on no child\");for(let c of e.missed){if(Object.hasOwn(this.#r,c))continue;let a=await this.#m(c,e.modules[c]??\"\");a!==null&&(this.#r[c]=a)}let o=Object.fromEntries(Object.entries(e.modules).filter(([c])=>!Object.hasOwn(this.#r,c))),s=Ka(e.live,Object.keys(o),e.liveBlobs),i=e.missed.length>0;if(!(s===this.#c&&!i))return this.#x(s,o,n,i)}async#m(e,n){let o={compatibilityDate:Ma,mainModule:Fa,modules:{[Fa]:{js:Lf(e)},nervur:{js:r},[Bo(e)]:{js:n}},env:{}};try{let i=await this.#y().get(`${await this.#E()}:probe:${e}`,()=>Promise.resolve(o)).getEntrypoint().fetch(new Request(\"https://probe.invalid/\"));return i.status===204?null:`the module does not load on the edge: ${await i.text()}`}catch(s){return`the module does not load on the edge: ${Df(s)}`}}async#k(e,n){for(let o=0;o<=Ua;o+=1){let s;do s=this.#f,await s;while(s!==this.#f);let i=this.#i,c=this.#p+=1;this.#a+=1;let a;try{a=await i.arrive(e,n,c)}catch{a=null}finally{if(this.#a-=1,this.#a===0)for(let u of this.#w.splice(0))u()}if(a===null)return null;if(a.wanted&&i===this.#i&&(this.#h=a.wanted,this.#g(()=>this.#O(i)).catch(()=>{})),!a.again)return a.reply}return null}async#O(e){this.#a>0&&await new Promise(o=>this.#w.push(o));let n=this.#h;e!==this.#i||!n||(this.#h=void 0,await this.#b(n,0))}},J0=(r=\"HARBOR\")=>({fetch(t,e){let n=za(t),o=e[r];return n===null||!o?Promise.resolve(new Response(null,{status:404})):o.get(o.idFromName(n)).fetch(t)}});var Ii={};Va(Ii,{BOX:()=>It,Being:()=>Xt,BundleLoader:()=>Le,CEILING:()=>Ns,Carrier:()=>we,CarrierFaculty:()=>ft,Catalogue:()=>lt,Clock:()=>ze,CryptoEntropy:()=>Nt,Custody:()=>oe,DEFAULT:()=>$s,DEFAULTS:()=>pn,DEPTH:()=>_t,DefaultDock:()=>Pe,DefaultWard:()=>Ue,Dock:()=>jt,Entropy:()=>qe,Faculty:()=>G,GroundMemory:()=>Fe,Harbor:()=>ee,HeldCustody:()=>Ne,Loader:()=>Ht,MEMORY:()=>lr,Memory:()=>ne,MemoryFaculty:()=>Ot,NEUTRAL:()=>vo,NoCarrier:()=>dr,OWNER:()=>Bt,PointerCarrier:()=>hr,PointerTerrain:()=>Lt,REGISTRY:()=>po,Registry:()=>Ut,RegistryFaculty:()=>Mt,SourceLoader:()=>re,SystemClock:()=>$e,TcpFaculty:()=>Me,Terrain:()=>te,UNDIALED:()=>mt,VolatileMemory:()=>De,WARD:()=>D,Ward:()=>yt,WebDialer:()=>Ie,WebFaculty:()=>Ce,World:()=>dn,addGround:()=>je,answerPost:()=>fn,canonical:()=>rr,copyPackage:()=>ai,digest:()=>Ur,groundOf:()=>$t,grounds:()=>fi,isSilence:()=>St,isWord:()=>wt,ownerAsk:()=>L,pilots:()=>Te,readInvitation:()=>kt,readRootRequest:()=>un,silence:()=>ht,told:()=>de,word:()=>pt});var Pe=class extends jt{static kind=\"org.nervur.default-dock\";static{U(this)}};var Pf=32,Fe=class extends Ot{static kind=\"org.nervur.ground-memory\";static{U(this)}#t;constructor(t){super(t),this.#t=$t(t).terrain.memory}get#e(){return _(I(this.stance.key))}occupies(t){return t.length===this.#e.length+Pf&&t.startsWith(this.#e)}read(t){return this.#t.read(this.#e+t)}write(t,e){return this.#t.write(this.#e+t,e)}async places(){return(await this.#t.places()).filter(t=>this.occupies(t)).map(t=>t.slice(this.#e.length))}forget(t){return this.#t.forget(this.#e+t)}};var Wa=r=>{if(typeof r!=\"object\"||r===null)return null;let{host:t,port:e}=r;return typeof t==\"string\"&&Number.isInteger(e)&&e>=0&&e<=65535?{host:t,port:e}:null},Me=class extends ft{static kind=\"org.nervur.tcp\";static carries=\"tcp\";static{U(this)}static asks={listen:L(\"listen for Quo over TCP, and on every wake\",{properties:{host:{type:\"string\"},port:{type:\"integer\"}}}),deaf:L(\"listen nowhere\")};#t;#e;constructor(t){super(t);let e=$t(t).terrain.tcp;if(!e)throw new Error(\"this ground speaks no TCP\");this.#t=e()}accepts(t){return Ae(t)!==null}dial(t,e,n){return this.#t.dial(t,e,n)}listening(){return this.#e?[this.#e.at]:[]}async awake(){let t=Wa(this.cells.listen);t&&!this.#e&&(this.#e=await this.#t.listen($t(this.stance),t.host,t.port))}async sleep(){await this.#t.close(),await this.#e?.close(),this.#e=void 0}async listen(t){let e=Wa({host:t.host??\"127.0.0.1\",port:t.port??0});if(e===null)return{error:\"host is text and port a port\"};await this.#e?.close(),this.#e=void 0;try{this.#e=await this.#t.listen($t(this.stance),e.host,e.port)}catch(n){return{error:n.message}}return this.cells.listen={host:e.host,port:Ae(this.#e.at).port},{at:this.#e.at}}async deaf(){return await this.#e?.close(),this.#e=void 0,delete this.cells.listen,{deaf:!0}}};var Ue=class extends yt{static kind=\"org.nervur.default-ward\";static{U(this)}};var Ga=r=>{if(typeof r!=\"object\"||r===null)return null;let{host:t,port:e,path:n,origins:o}=r;return typeof t==\"string\"&&Number.isInteger(e)&&e>=0&&e<=65535&&typeof n==\"string\"&&n.startsWith(\"/\")&&Array.isArray(o)&&o.every(i=>typeof i==\"string\")?{host:t,port:e,path:n,origins:o}:null},Ce=class extends ft{static kind=\"org.nervur.web\";static carries=\"web\";static{U(this)}static asks={listen:L(\"listen for Quo over the web, and on every wake\"),deaf:L(\"listen nowhere\")};#t=new Ie;#e;get#r(){return $t(this.stance)}accepts(t){return ir(t)!==null}dial(t,e,n){return this.#t.dial(t,e,n)}listening(){return this.#e?[...this.#e.at]:[]}async awake(){let t=Ga(this.cells.listen),e=this.#r.terrain.web;t&&e&&!this.#e&&(this.#e=await e(this.#r,t))}async sleep(){await this.#t.close(),await this.#e?.close(),this.#e=void 0}async listen(t){let e=this.#r.terrain.web;if(!e)return{error:\"this ground listens nowhere on the web\"};let n=Ga({host:t.host??\"127.0.0.1\",port:t.port??0,path:t.path??\"/\",origins:t.origins??[\"*\"]});if(n===null)return{error:\"host is text, port a port, path a path and origins a list\"};await this.#e?.close(),this.#e=void 0;try{this.#e=await e(this.#r,n)}catch(o){return{error:o.message}}return this.cells.listen={...n,port:this.#e.port},{at:[...this.#e.at]}}async deaf(){return await this.#e?.close(),this.#e=void 0,delete this.cells.listen,{deaf:!0}}};var pn={dock:Pe,ward:Ue,classes:[Fe,Me,Ce]};_o(Ii);je(ki,pn);je(qa,pn);export{It as BOX,Xt as Being,Le as BundleLoader,Ns as CEILING,we as Carrier,ft as CarrierFaculty,lt as Catalogue,Ai as ChildCalls,ze as Clock,Nt as CryptoEntropy,oe as Custody,$s as DEFAULT,pn as DEFAULTS,_t as DEPTH,Pe as DefaultDock,Ue as DefaultWard,jt as Dock,Of as EDGE,Ti as EdgeCustody,Ao as EdgeLoader,Si as EdgeMemory,_i as EdgeSockets,ji as EdgeTerrain,qe as Entropy,G as Faculty,Fe as GroundMemory,ee as Harbor,La as HarborChild,Ne as HeldCustody,Ht as Loader,lr as MEMORY,ne as Memory,Ot as MemoryFaculty,vo as NEUTRAL,dr as NoCarrier,Bt as OWNER,hr as PointerCarrier,Lt as PointerTerrain,po as REGISTRY,Ut as Registry,Mt as RegistryFaculty,re as SourceLoader,$e as SystemClock,Me as TcpFaculty,te as Terrain,mt as UNDIALED,De as VolatileMemory,D as WARD,yt as Ward,Ie as WebDialer,Ce as WebFaculty,dn as World,je as addGround,fn as answerPost,rr as canonical,Ka as childKey,ai as copyPackage,Ur as digest,qa as edgeGround,$t as groundOf,fi as grounds,za as harborNameOf,V0 as harborShell,J0 as harborWorker,Ca as isHarborName,St as isSilence,wt as isWord,L as ownerAsk,Te as pilots,kt as readInvitation,X0 as readPack,un as readRootRequest,Y0 as sealSeed,ht as silence,de as told,pt as word};\n/*! Bundled license information:\n\n@noble/curves/utils.js:\n@noble/curves/abstract/modular.js:\n@noble/curves/abstract/curve.js:\n@noble/curves/abstract/edwards.js:\n@noble/curves/abstract/montgomery.js:\n@noble/curves/ed25519.js:\n (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)\n\n@noble/post-quantum/utils.js:\n@noble/post-quantum/_crystals.js:\n@noble/post-quantum/ml-kem.js:\n (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)\n*/\n";