@interncom/diplomatic 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.mjs +3 -3
- package/dist/cli/shared/events.d.ts +2 -0
- package/dist/cli/shared/singleton.d.ts +2 -0
- package/dist/cli/shared/types.d.ts +23 -2
- package/dist/web/client.d.ts +62 -3
- package/dist/web/coalesce.d.ts +30 -0
- package/dist/web/index.d.ts +9 -3
- package/dist/web/index.mjs +1 -1
- package/dist/web/openClient.d.ts +141 -0
- package/dist/web/progress.d.ts +24 -0
- package/dist/web/react/useClient.d.ts +43 -9
- package/dist/web/saveBlob.d.ts +2 -0
- package/dist/web/shared/events.d.ts +2 -0
- package/dist/web/shared/singleton.d.ts +2 -0
- package/dist/web/shared/types.d.ts +23 -2
- package/dist/web/state.d.ts +9 -2
- package/dist/web/stores/idb/msgs.d.ts +4 -5
- package/dist/web/stores/idb/store.d.ts +4 -0
- package/dist/web/stores/memory/msgs.d.ts +4 -5
- package/dist/web/sync.d.ts +11 -6
- package/dist/web/types.d.ts +42 -7
- package/dist/web/worker/client.d.ts +77 -0
- package/dist/web/worker/entry.d.ts +1 -0
- package/dist/web/worker/protocol.d.ts +125 -0
- package/dist/web/worker/runtime.d.ts +21 -0
- package/dist/web/worker.mjs +1 -0
- package/package.json +7 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var P8=Object.create;var{getPrototypeOf:S8,defineProperty:oJ,getOwnPropertyNames:w8}=Object;var F8=Object.prototype.hasOwnProperty;function k8($){return this[$]}var j8,E8,L8=($,J,Q)=>{var Z=$!=null&&typeof $==="object";if(Z){var V=J?j8??=new WeakMap:E8??=new WeakMap,I=V.get($);if(I)return I}Q=$!=null?P8(S8($)):{};let X=J||!$||!$.__esModule?oJ(Q,"default",{value:$,enumerable:!0}):Q;for(let G of w8($))if(!F8.call(X,G))oJ(X,G,{get:k8.bind($,G),enumerable:!0});if(Z)V.set($,X);return X};var V0=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var w$=V0((WZ)=>{Object.defineProperty(WZ,"__esModule",{value:!0});WZ.utf8Count=eV;WZ.utf8EncodeJs=qZ;WZ.utf8EncodeTE=NZ;WZ.utf8Encode=QI;WZ.utf8DecodeJs=KZ;WZ.utf8DecodeTD=MZ;WZ.utf8Decode=XI;function eV($){let J=$.length,Q=0,Z=0;while(Z<J){let V=$.charCodeAt(Z++);if((V&4294967168)===0){Q++;continue}else if((V&4294965248)===0)Q+=2;else{if(V>=55296&&V<=56319){if(Z<J){let I=$.charCodeAt(Z);if((I&64512)===56320)++Z,V=((V&1023)<<10)+(I&1023)+65536}}if((V&4294901760)===0)Q+=3;else Q+=4}}return Q}function qZ($,J,Q){let Z=$.length,V=Q,I=0;while(I<Z){let X=$.charCodeAt(I++);if((X&4294967168)===0){J[V++]=X;continue}else if((X&4294965248)===0)J[V++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(I<Z){let G=$.charCodeAt(I);if((G&64512)===56320)++I,X=((X&1023)<<10)+(G&1023)+65536}}if((X&4294901760)===0)J[V++]=X>>12&15|224,J[V++]=X>>6&63|128;else J[V++]=X>>18&7|240,J[V++]=X>>12&63|128,J[V++]=X>>6&63|128}J[V++]=X&63|128}}var $I=new TextEncoder,JI=50;function NZ($,J,Q){$I.encodeInto($,J.subarray(Q))}function QI($,J,Q){if($.length>JI)NZ($,J,Q);else qZ($,J,Q)}var ZI=4096;function KZ($,J,Q){let Z=J,V=Z+Q,I=[],X="";while(Z<V){let G=$[Z++];if((G&128)===0)I.push(G);else if((G&224)===192){let Y=$[Z++]&63;I.push((G&31)<<6|Y)}else if((G&240)===224){let Y=$[Z++]&63,N=$[Z++]&63;I.push((G&31)<<12|Y<<6|N)}else if((G&248)===240){let Y=$[Z++]&63,N=$[Z++]&63,q=$[Z++]&63,K=(G&7)<<18|Y<<12|N<<6|q;if(K>65535)K-=65536,I.push(K>>>10&1023|55296),K=56320|K&1023;I.push(K)}else I.push(G);if(I.length>=ZI)X+=String.fromCharCode(...I),I.length=0}if(I.length>0)X+=String.fromCharCode(...I);return X}var VI=new TextDecoder,II=200;function MZ($,J,Q){let Z=$.subarray(J,J+Q);return VI.decode(Z)}function XI($,J,Q){if(Q>II)return MZ($,J,Q);else return KZ($,J,Q)}});var FJ=V0((OZ)=>{Object.defineProperty(OZ,"__esModule",{value:!0});OZ.ExtData=void 0;class UZ{type;data;constructor($,J){this.type=$,this.data=J}}OZ.ExtData=UZ});var k$=V0((HZ)=>{Object.defineProperty(HZ,"__esModule",{value:!0});HZ.DecodeError=void 0;class F$ extends Error{constructor($){super($);let J=Object.create(F$.prototype);Object.setPrototypeOf(this,J),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:F$.name})}}HZ.DecodeError=F$});var j$=V0((RZ)=>{Object.defineProperty(RZ,"__esModule",{value:!0});RZ.UINT32_MAX=void 0;RZ.setUint64=UI;RZ.setInt64=OI;RZ.getInt64=zI;RZ.getUint64=HI;RZ.UINT32_MAX=4294967295;function UI($,J,Q){let Z=Q/4294967296,V=Q;$.setUint32(J,Z),$.setUint32(J+4,V)}function OI($,J,Q){let Z=Math.floor(Q/4294967296),V=Q;$.setUint32(J,Z),$.setUint32(J+4,V)}function zI($,J){let Q=$.getInt32(J),Z=$.getUint32(J+4);return Q*4294967296+Z}function HI($,J){let Q=$.getUint32(J),Z=$.getUint32(J+4);return Q*4294967296+Z}});var kJ=V0((kZ)=>{Object.defineProperty(kZ,"__esModule",{value:!0});kZ.timestampExtension=kZ.EXT_TIMESTAMP=void 0;kZ.encodeTimeSpecToTimestamp=CZ;kZ.encodeDateToTimeSpec=PZ;kZ.encodeTimestampExtension=SZ;kZ.decodeTimestampToTimeSpec=wZ;kZ.decodeTimestampExtension=FZ;var CI=k$(),AZ=j$();kZ.EXT_TIMESTAMP=-1;var PI=4294967295,SI=17179869183;function CZ({sec:$,nsec:J}){if($>=0&&J>=0&&$<=SI)if(J===0&&$<=PI){let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,$),Q}else{let Q=$/4294967296,Z=$&4294967295,V=new Uint8Array(8),I=new DataView(V.buffer);return I.setUint32(0,J<<2|Q&3),I.setUint32(4,Z),V}else{let Q=new Uint8Array(12),Z=new DataView(Q.buffer);return Z.setUint32(0,J),(0,AZ.setInt64)(Z,4,$),Q}}function PZ($){let J=$.getTime(),Q=Math.floor(J/1000),Z=(J-Q*1000)*1e6,V=Math.floor(Z/1e9);return{sec:Q+V,nsec:Z-V*1e9}}function SZ($){if($ instanceof Date){let J=PZ($);return CZ(J)}else return null}function wZ($){let J=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let Q=J.getUint32(0),Z=0;return{sec:Q,nsec:0}}case 8:{let Q=J.getUint32(0),Z=J.getUint32(4),V=(Q&3)*4294967296+Z,I=Q>>>2;return{sec:V,nsec:I}}case 12:{let Q=(0,AZ.getInt64)(J,4),Z=J.getUint32(0);return{sec:Q,nsec:Z}}default:throw new CI.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function FZ($){let J=wZ($);return new Date(J.sec*1000+J.nsec/1e6)}kZ.timestampExtension={type:kZ.EXT_TIMESTAMP,encode:SZ,decode:FZ}});var L$=V0((LZ)=>{Object.defineProperty(LZ,"__esModule",{value:!0});LZ.ExtensionCodec=void 0;var E$=FJ(),LI=kJ();class jJ{static defaultCodec=new jJ;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(LI.timestampExtension)}register({type:$,encode:J,decode:Q}){if($>=0)this.encoders[$]=J,this.decoders[$]=Q;else{let Z=-1-$;this.builtInEncoders[Z]=J,this.builtInDecoders[Z]=Q}}tryToEncode($,J){for(let Q=0;Q<this.builtInEncoders.length;Q++){let Z=this.builtInEncoders[Q];if(Z!=null){let V=Z($,J);if(V!=null){let I=-1-Q;return new E$.ExtData(I,V)}}}for(let Q=0;Q<this.encoders.length;Q++){let Z=this.encoders[Q];if(Z!=null){let V=Z($,J);if(V!=null){let I=Q;return new E$.ExtData(I,V)}}}if($ instanceof E$.ExtData)return $;return null}decode($,J,Q){let Z=J<0?this.builtInDecoders[-1-J]:this.decoders[J];if(Z)return Z($,J,Q);else return new E$.ExtData(J,$)}}LZ.ExtensionCodec=jJ});var EJ=V0((gZ)=>{Object.defineProperty(gZ,"__esModule",{value:!0});gZ.ensureUint8Array=gI;function BI($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function gI($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(BI($))return new Uint8Array($);else return Uint8Array.from($)}});var BJ=V0((xZ)=>{Object.defineProperty(xZ,"__esModule",{value:!0});xZ.Encoder=xZ.DEFAULT_INITIAL_BUFFER_SIZE=xZ.DEFAULT_MAX_DEPTH=void 0;var _Z=w$(),fI=L$(),fZ=j$(),xI=EJ();xZ.DEFAULT_MAX_DEPTH=100;xZ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class LJ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??fI.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??xZ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??xZ.DEFAULT_INITIAL_BUFFER_SIZE,this.sortKeys=$?.sortKeys??!1,this.forceFloat32=$?.forceFloat32??!1,this.ignoreUndefined=$?.ignoreUndefined??!1,this.forceIntegerToFloat=$?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new LJ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef($){if(this.entered)return this.clone().encodeSharedRef($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode($){if(this.entered)return this.clone().encode($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode($,J){if(J>this.maxDepth)throw Error(`Too deep objects in depth ${J}`);if($==null)this.encodeNil();else if(typeof $==="boolean")this.encodeBoolean($);else if(typeof $==="number")if(!this.forceIntegerToFloat)this.encodeNumber($);else this.encodeNumberAsFloat($);else if(typeof $==="string")this.encodeString($);else if(this.useBigInt64&&typeof $==="bigint")this.encodeBigInt64($);else this.encodeObject($,J)}ensureBufferSizeToWrite($){let J=this.pos+$;if(this.view.byteLength<J)this.resizeBuffer(J*2)}resizeBuffer($){let J=new ArrayBuffer($),Q=new Uint8Array(J),Z=new DataView(J);Q.set(this.bytes),this.view=Z,this.bytes=Q}encodeNil(){this.writeU8(192)}encodeBoolean($){if($===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber($){if(!this.forceIntegerToFloat&&Number.isSafeInteger($))if($>=0)if($<128)this.writeU8($);else if($<256)this.writeU8(204),this.writeU8($);else if($<65536)this.writeU8(205),this.writeU16($);else if($<4294967296)this.writeU8(206),this.writeU32($);else if(!this.useBigInt64)this.writeU8(207),this.writeU64($);else this.encodeNumberAsFloat($);else if($>=-32)this.writeU8(224|$+32);else if($>=-128)this.writeU8(208),this.writeI8($);else if($>=-32768)this.writeU8(209),this.writeI16($);else if($>=-2147483648)this.writeU8(210),this.writeI32($);else if(!this.useBigInt64)this.writeU8(211),this.writeI64($);else this.encodeNumberAsFloat($);else this.encodeNumberAsFloat($)}encodeNumberAsFloat($){if(this.forceFloat32)this.writeU8(202),this.writeF32($);else this.writeU8(203),this.writeF64($)}encodeBigInt64($){if($>=BigInt(0))this.writeU8(207),this.writeBigUint64($);else this.writeU8(211),this.writeBigInt64($)}writeStringHeader($){if($<32)this.writeU8(160+$);else if($<256)this.writeU8(217),this.writeU8($);else if($<65536)this.writeU8(218),this.writeU16($);else if($<4294967296)this.writeU8(219),this.writeU32($);else throw Error(`Too long string: ${$} bytes in UTF-8`)}encodeString($){let Q=(0,_Z.utf8Count)($);this.ensureBufferSizeToWrite(5+Q),this.writeStringHeader(Q),(0,_Z.utf8Encode)($,this.bytes,this.pos),this.pos+=Q}encodeObject($,J){let Q=this.extensionCodec.tryToEncode($,this.context);if(Q!=null)this.encodeExtension(Q);else if(Array.isArray($))this.encodeArray($,J);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,J);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let J=$.byteLength;if(J<256)this.writeU8(196),this.writeU8(J);else if(J<65536)this.writeU8(197),this.writeU16(J);else if(J<4294967296)this.writeU8(198),this.writeU32(J);else throw Error(`Too large binary: ${J}`);let Q=(0,xI.ensureUint8Array)($);this.writeU8a(Q)}encodeArray($,J){let Q=$.length;if(Q<16)this.writeU8(144+Q);else if(Q<65536)this.writeU8(220),this.writeU16(Q);else if(Q<4294967296)this.writeU8(221),this.writeU32(Q);else throw Error(`Too large array: ${Q}`);for(let Z of $)this.doEncode(Z,J+1)}countWithoutUndefined($,J){let Q=0;for(let Z of J)if($[Z]!==void 0)Q++;return Q}encodeMap($,J){let Q=Object.keys($);if(this.sortKeys)Q.sort();let Z=this.ignoreUndefined?this.countWithoutUndefined($,Q):Q.length;if(Z<16)this.writeU8(128+Z);else if(Z<65536)this.writeU8(222),this.writeU16(Z);else if(Z<4294967296)this.writeU8(223),this.writeU32(Z);else throw Error(`Too large map object: ${Z}`);for(let V of Q){let I=$[V];if(!(this.ignoreUndefined&&I===void 0))this.encodeString(V),this.doEncode(I,J+1)}}encodeExtension($){if(typeof $.data==="function"){let Q=$.data(this.pos+6),Z=Q.length;if(Z>=4294967296)throw Error(`Too large extension object: ${Z}`);this.writeU8(201),this.writeU32(Z),this.writeI8($.type),this.writeU8a(Q);return}let J=$.data.length;if(J===1)this.writeU8(212);else if(J===2)this.writeU8(213);else if(J===4)this.writeU8(214);else if(J===8)this.writeU8(215);else if(J===16)this.writeU8(216);else if(J<256)this.writeU8(199),this.writeU8(J);else if(J<65536)this.writeU8(200),this.writeU16(J);else if(J<4294967296)this.writeU8(201),this.writeU32(J);else throw Error(`Too large extension object: ${J}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let J=$.length;this.ensureBufferSizeToWrite(J),this.bytes.set($,this.pos),this.pos+=J}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),(0,fZ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,fZ.setInt64)(this.view,this.pos,$),this.pos+=8}writeBigUint64($){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,$),this.pos+=8}writeBigInt64($){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,$),this.pos+=8}}xZ.Encoder=LJ});var uZ=V0((bZ)=>{Object.defineProperty(bZ,"__esModule",{value:!0});bZ.encode=vI;var mI=BJ();function vI($,J){return new mI.Encoder(J).encodeSharedRef($)}});var dZ=V0((lZ)=>{Object.defineProperty(lZ,"__esModule",{value:!0});lZ.prettyByte=bI;function bI($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var iZ=V0((rZ)=>{Object.defineProperty(rZ,"__esModule",{value:!0});rZ.CachedKeyDecoder=void 0;var lI=w$(),dI=16,pI=16;class pZ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=dI,J=pI){this.maxKeyLength=$,this.maxLengthPerKey=J,this.caches=[];for(let Q=0;Q<this.maxKeyLength;Q++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,J,Q){let Z=this.caches[Q-1];$:for(let V of Z){let I=V.bytes;for(let X=0;X<Q;X++)if(I[X]!==$[J+X])continue $;return V.str}return null}store($,J){let Q=this.caches[$.length-1],Z={bytes:$,str:J};if(Q.length>=this.maxLengthPerKey)Q[Math.random()*Q.length|0]=Z;else Q.push(Z)}decode($,J,Q){let Z=this.find($,J,Q);if(Z!=null)return this.hit++,Z;this.miss++;let V=(0,lI.utf8DecodeJs)($,J,Q),I=Uint8Array.prototype.slice.call($,J,J+Q);return this.store(I,V),V}}rZ.CachedKeyDecoder=pZ});var B$=V0((sZ)=>{Object.defineProperty(sZ,"__esModule",{value:!0});sZ.Decoder=void 0;var gJ=dZ(),rI=L$(),m0=j$(),cI=w$(),hZ=EJ(),iI=iZ(),F0=k$(),_J="array",I$="map_key",oZ="map_value",hI=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new F0.DecodeError("The type of key must be string or number but "+typeof $)};class aZ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let J=this.getUninitializedStateFromPool();J.type=_J,J.position=0,J.size=$,J.array=Array($)}pushMapState($){let J=this.getUninitializedStateFromPool();J.type=I$,J.readCount=0,J.size=$,J.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let $={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push($)}return this.stack[this.stackHeadPosition]}release($){if(this.stack[this.stackHeadPosition]!==$)throw Error("Invalid stack state. Released state is not on top of the stack.");if($.type===_J){let Q=$;Q.size=0,Q.array=void 0,Q.position=0,Q.type=void 0}if($.type===I$||$.type===oZ){let Q=$;Q.size=0,Q.map=void 0,Q.readCount=0,Q.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var V$=-1,fJ=new DataView(new ArrayBuffer(0)),nI=new Uint8Array(fJ.buffer);try{fJ.getInt8(0)}catch($){if(!($ instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var nZ=RangeError("Insufficient data"),oI=new iI.CachedKeyDecoder;class xJ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=fJ;bytes=nI;headByte=V$;stack=new aZ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??rI.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??m0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??m0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??m0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??m0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??m0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:oI,this.mapKeyConverter=$?.mapKeyConverter??hI}clone(){return new xJ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=V$,this.stack.reset()}setBuffer($){let J=(0,hZ.ensureUint8Array)($);this.bytes=J,this.view=new DataView(J.buffer,J.byteOffset,J.byteLength),this.pos=0}appendBuffer($){if(this.headByte===V$&&!this.hasRemaining(1))this.setBuffer($);else{let J=this.bytes.subarray(this.pos),Q=(0,hZ.ensureUint8Array)($),Z=new Uint8Array(J.length+Q.length);Z.set(J),Z.set(Q,J.length),this.setBuffer(Z)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:J,pos:Q}=this;return RangeError(`Extra ${J.byteLength-Q} of ${J.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let J=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return J}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let J=!1,Q;for await(let X of $){if(J)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{Q=this.doDecodeSync(),J=!0}catch(G){if(!(G instanceof RangeError))throw G}this.totalPos+=this.pos}if(J){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Q}let{headByte:Z,pos:V,totalPos:I}=this;throw RangeError(`Insufficient data in parsing ${(0,gJ.prettyByte)(Z)} at ${I} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,J){if(this.entered){yield*this.clone().decodeMultiAsync($,J);return}try{this.entered=!0;let Q=J,Z=-1;for await(let V of $){if(J&&Z===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),Q)Z=this.readArraySize(),Q=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Z===0)break}catch(I){if(!(I instanceof RangeError))throw I}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),J;if($>=224)J=$-256;else if($<192)if($<128)J=$;else if($<144){let Z=$-128;if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($<160){let Z=$-144;if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else{let Z=$-160;J=this.decodeString(Z,0)}else if($===192)J=null;else if($===194)J=!1;else if($===195)J=!0;else if($===202)J=this.readF32();else if($===203)J=this.readF64();else if($===204)J=this.readU8();else if($===205)J=this.readU16();else if($===206)J=this.readU32();else if($===207)if(this.useBigInt64)J=this.readU64AsBigInt();else J=this.readU64();else if($===208)J=this.readI8();else if($===209)J=this.readI16();else if($===210)J=this.readI32();else if($===211)if(this.useBigInt64)J=this.readI64AsBigInt();else J=this.readI64();else if($===217){let Z=this.lookU8();J=this.decodeString(Z,1)}else if($===218){let Z=this.lookU16();J=this.decodeString(Z,2)}else if($===219){let Z=this.lookU32();J=this.decodeString(Z,4)}else if($===220){let Z=this.readU16();if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else if($===221){let Z=this.readU32();if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else if($===222){let Z=this.readU16();if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($===223){let Z=this.readU32();if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($===196){let Z=this.lookU8();J=this.decodeBinary(Z,1)}else if($===197){let Z=this.lookU16();J=this.decodeBinary(Z,2)}else if($===198){let Z=this.lookU32();J=this.decodeBinary(Z,4)}else if($===212)J=this.decodeExtension(1,0);else if($===213)J=this.decodeExtension(2,0);else if($===214)J=this.decodeExtension(4,0);else if($===215)J=this.decodeExtension(8,0);else if($===216)J=this.decodeExtension(16,0);else if($===199){let Z=this.lookU8();J=this.decodeExtension(Z,1)}else if($===200){let Z=this.lookU16();J=this.decodeExtension(Z,2)}else if($===201){let Z=this.lookU32();J=this.decodeExtension(Z,4)}else throw new F0.DecodeError(`Unrecognized type byte: ${(0,gJ.prettyByte)($)}`);this.complete();let Q=this.stack;while(Q.length>0){let Z=Q.top();if(Z.type===_J)if(Z.array[Z.position]=J,Z.position++,Z.position===Z.size)J=Z.array,Q.release(Z);else continue $;else if(Z.type===I$){if(J==="__proto__")throw new F0.DecodeError("The key __proto__ is not allowed");Z.key=this.mapKeyConverter(J),Z.type=oZ;continue $}else if(Z.map[Z.key]=J,Z.readCount++,Z.readCount===Z.size)J=Z.map,Q.release(Z);else{Z.key=null,Z.type=I$;continue $}}return J}}readHeadByte(){if(this.headByte===V$)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=V$}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new F0.DecodeError(`Unrecognized array type byte: ${(0,gJ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new F0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new F0.DecodeError(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,J){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,J);return this.decodeBinary($,J)}decodeUtf8String($,J){if($>this.maxStrLength)throw new F0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+J+$)throw nZ;let Q=this.pos+J,Z;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Z=this.keyDecoder.decode(this.bytes,Q,$);else Z=(0,cI.utf8Decode)(this.bytes,Q,$);return this.pos+=J+$,Z}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===I$;return!1}decodeBinary($,J){if($>this.maxBinLength)throw new F0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+J))throw nZ;let Q=this.pos+J,Z=this.bytes.subarray(Q,Q+$);return this.pos+=J+$,Z}decodeExtension($,J){if($>this.maxExtLength)throw new F0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let Q=this.view.getInt8(this.pos+J),Z=this.decodeBinary($,J+1);return this.extensionCodec.decode(Z,Q,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=(0,m0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,m0.getInt64)(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}sZ.Decoder=xJ});var J8=V0(($8)=>{Object.defineProperty($8,"__esModule",{value:!0});$8.decode=aI;$8.decodeMulti=sI;var eZ=B$();function aI($,J){return new eZ.Decoder(J).decode($)}function sI($,J){return new eZ.Decoder(J).decodeMulti($)}});var I8=V0((V8)=>{Object.defineProperty(V8,"__esModule",{value:!0});V8.isAsyncIterable=Q8;V8.asyncIterableFromStream=Z8;V8.ensureAsyncIterable=$X;function Q8($){return $[Symbol.asyncIterator]!=null}async function*Z8($){let J=$.getReader();try{while(!0){let{done:Q,value:Z}=await J.read();if(Q)return;yield Z}}finally{J.releaseLock()}}function $X($){if(Q8($))return $;else return Z8($)}});var Y8=V0((X8)=>{Object.defineProperty(X8,"__esModule",{value:!0});X8.decodeAsync=VX;X8.decodeArrayStream=IX;X8.decodeMultiStream=XX;var mJ=B$(),vJ=I8();async function VX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeAsync(Q)}function IX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeArrayStream(Q)}function XX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeStream(Q)}});var q8=V0((t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.decodeTimestampExtension=t.encodeTimestampExtension=t.decodeTimestampToTimeSpec=t.encodeTimeSpecToTimestamp=t.encodeDateToTimeSpec=t.EXT_TIMESTAMP=t.ExtData=t.ExtensionCodec=t.Encoder=t.DecodeError=t.Decoder=t.decodeMultiStream=t.decodeArrayStream=t.decodeAsync=t.decodeMulti=t.decode=t.encode=void 0;var NX=uZ();Object.defineProperty(t,"encode",{enumerable:!0,get:function(){return NX.encode}});var G8=J8();Object.defineProperty(t,"decode",{enumerable:!0,get:function(){return G8.decode}});Object.defineProperty(t,"decodeMulti",{enumerable:!0,get:function(){return G8.decodeMulti}});var yJ=Y8();Object.defineProperty(t,"decodeAsync",{enumerable:!0,get:function(){return yJ.decodeAsync}});Object.defineProperty(t,"decodeArrayStream",{enumerable:!0,get:function(){return yJ.decodeArrayStream}});Object.defineProperty(t,"decodeMultiStream",{enumerable:!0,get:function(){return yJ.decodeMultiStream}});var KX=B$();Object.defineProperty(t,"Decoder",{enumerable:!0,get:function(){return KX.Decoder}});var MX=k$();Object.defineProperty(t,"DecodeError",{enumerable:!0,get:function(){return MX.DecodeError}});var WX=BJ();Object.defineProperty(t,"Encoder",{enumerable:!0,get:function(){return WX.Encoder}});var UX=L$();Object.defineProperty(t,"ExtensionCodec",{enumerable:!0,get:function(){return UX.ExtensionCodec}});var OX=FJ();Object.defineProperty(t,"ExtData",{enumerable:!0,get:function(){return OX.ExtData}});var o0=kJ();Object.defineProperty(t,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return o0.EXT_TIMESTAMP}});Object.defineProperty(t,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return o0.encodeDateToTimeSpec}});Object.defineProperty(t,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return o0.encodeTimeSpecToTimestamp}});Object.defineProperty(t,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return o0.decodeTimestampToTimeSpec}});Object.defineProperty(t,"encodeTimestampExtension",{enumerable:!0,get:function(){return o0.encodeTimestampExtension}});Object.defineProperty(t,"decodeTimestampExtension",{enumerable:!0,get:function(){return o0.decodeTimestampExtension}})});import*as R0 from"node:crypto";var B0=R0&&typeof R0==="object"&&"webcrypto"in R0?R0.webcrypto:R0&&typeof R0==="object"&&("randomBytes"in R0)?R0:void 0;function Y$($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function _$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function $0($,...J){if(!_$($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function f$($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function aJ($,J){$0($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}function x$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var D0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var B8=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!B8)throw Error("Non little-endian hardware is not supported");function g8($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function G$($){if(typeof $==="string")$=g8($);else if(_$($))$=q$($);else throw Error("Uint8Array expected, got "+typeof $);return $}function sJ($,J){if(J==null||typeof J!=="object")throw Error("options must be defined");return Object.assign($,J)}function tJ($,J){if($.length!==J.length)return!1;let Q=0;for(let Z=0;Z<$.length;Z++)Q|=$[Z]^J[Z];return Q===0}var eJ=($,J)=>{function Q(Z,...V){if($0(Z),$.nonceLength!==void 0){let q=V[0];if(!q)throw Error("nonce / iv required");if($.varSizeNonce)$0(q);else $0(q,$.nonceLength)}let I=$.tagLength;if(I&&V[1]!==void 0)$0(V[1]);let X=J(Z,...V),G=(q,K)=>{if(K!==void 0){if(q!==2)throw Error("cipher output not supported");$0(K)}},Y=!1;return{encrypt(q,K){if(Y)throw Error("cannot encrypt() twice with same key + nonce");return Y=!0,$0(q),G(X.encrypt.length,K),X.encrypt(q,K)},decrypt(q,K){if($0(q),I&&q.length<I)throw Error("invalid ciphertext length: smaller than tagLength="+I);return G(X.decrypt.length,K),X.decrypt(q,K)}}}return Object.assign(Q,$),Q};function m$($,J,Q=!0){if(J===void 0)return new Uint8Array($);if(J.length!==$)throw Error("invalid output length, expected "+$+", got: "+J.length);if(Q&&!_8(J))throw Error("invalid output, must be aligned");return J}function _8($){return $.byteOffset%4===0}function q$($){return Uint8Array.from($)}function O0(...$){for(let J=0;J<$.length;J++)$[J].fill(0)}function N$($=32){if(B0&&typeof B0.getRandomValues==="function")return B0.getRandomValues(new Uint8Array($));if(B0&&typeof B0.randomBytes==="function")return B0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var JQ=($)=>Uint8Array.from($.split("").map((J)=>J.charCodeAt(0))),f8=JQ("expand 16-byte k"),x8=JQ("expand 32-byte k"),m8=D0(f8),v8=D0(x8);function P($,J){return $<<J|$>>>32-J}function v$($){return $.byteOffset%4===0}var K$=64,y8=16,QQ=4294967295,$Q=new Uint32Array;function b8($,J,Q,Z,V,I,X,G){let Y=V.length,N=new Uint8Array(K$),q=D0(N),K=v$(V)&&v$(I),O=K?D0(V):$Q,M=K?D0(I):$Q;for(let H=0;H<Y;X++){if($(J,Q,Z,q,X,G),X>=QQ)throw Error("arx: counter overflow");let T=Math.min(K$,Y-H);if(K&&T===K$){let F=H/4;if(H%4!==0)throw Error("arx: invalid block position");for(let S=0,C;S<y8;S++)C=F+S,M[C]=O[C]^q[S];H+=K$;continue}for(let F=0,S;F<T;F++)S=H+F,I[S]=V[S]^N[F];H+=T}}function ZQ($,J){let{allowShortKeys:Q,extendNonceFn:Z,counterLength:V,counterRight:I,rounds:X}=sJ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},J);if(typeof $!=="function")throw Error("core must be a function");return Y$(V),Y$(X),x$(I),x$(Q),(G,Y,N,q,K=0)=>{$0(G),$0(Y),$0(N);let O=N.length;if(q===void 0)q=new Uint8Array(O);if($0(q),Y$(K),K<0||K>=QQ)throw Error("arx: counter overflow");if(q.length<O)throw Error(`arx: output (${q.length}) is shorter than data (${O})`);let M=[],H=G.length,T,F;if(H===32)M.push(T=q$(G)),F=v8;else if(H===16&&Q)T=new Uint8Array(32),T.set(G),T.set(G,16),F=m8,M.push(T);else throw Error(`arx: invalid 32-byte key, got length=${H}`);if(!v$(Y))M.push(Y=q$(Y));let S=D0(T);if(Z){if(Y.length!==24)throw Error("arx: extended nonce must be 24 bytes");Z(F,S,D0(Y.subarray(0,16)),S),Y=Y.subarray(16)}let C=16-V;if(C!==Y.length)throw Error(`arx: nonce must be ${C} or 16 bytes`);if(C!==12){let w=new Uint8Array(12);w.set(Y,I?0:12-Y.length),Y=w,M.push(Y)}let A=D0(Y);return b8($,F,S,A,N,q,K,X),O0(...M),q}}var Q0=($,J)=>$[J++]&255|($[J++]&255)<<8;class VQ{constructor($){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,$=G$($),$0($,32);let J=Q0($,0),Q=Q0($,2),Z=Q0($,4),V=Q0($,6),I=Q0($,8),X=Q0($,10),G=Q0($,12),Y=Q0($,14);this.r[0]=J&8191,this.r[1]=(J>>>13|Q<<3)&8191,this.r[2]=(Q>>>10|Z<<6)&7939,this.r[3]=(Z>>>7|V<<9)&8191,this.r[4]=(V>>>4|I<<12)&255,this.r[5]=I>>>1&8190,this.r[6]=(I>>>14|X<<2)&8191,this.r[7]=(X>>>11|G<<5)&8065,this.r[8]=(G>>>8|Y<<8)&8191,this.r[9]=Y>>>5&127;for(let N=0;N<8;N++)this.pad[N]=Q0($,16+2*N)}process($,J,Q=!1){let Z=Q?0:2048,{h:V,r:I}=this,X=I[0],G=I[1],Y=I[2],N=I[3],q=I[4],K=I[5],O=I[6],M=I[7],H=I[8],T=I[9],F=Q0($,J+0),S=Q0($,J+2),C=Q0($,J+4),A=Q0($,J+6),w=Q0($,J+8),l=Q0($,J+10),b=Q0($,J+12),y=Q0($,J+14),f=V[0]+(F&8191),x=V[1]+((F>>>13|S<<3)&8191),d=V[2]+((S>>>10|C<<6)&8191),R=V[3]+((C>>>7|A<<9)&8191),p=V[4]+((A>>>4|w<<12)&8191),r=V[5]+(w>>>1&8191),c=V[6]+((w>>>14|l<<2)&8191),n=V[7]+((l>>>11|b<<5)&8191),U=V[8]+((b>>>8|y<<8)&8191),D=V[9]+(y>>>5|Z),z=0,E=z+f*X+x*(5*T)+d*(5*H)+R*(5*M)+p*(5*O);z=E>>>13,E&=8191,E+=r*(5*K)+c*(5*q)+n*(5*N)+U*(5*Y)+D*(5*G),z+=E>>>13,E&=8191;let B=z+f*G+x*X+d*(5*T)+R*(5*H)+p*(5*M);z=B>>>13,B&=8191,B+=r*(5*O)+c*(5*K)+n*(5*q)+U*(5*N)+D*(5*Y),z+=B>>>13,B&=8191;let L=z+f*Y+x*G+d*X+R*(5*T)+p*(5*H);z=L>>>13,L&=8191,L+=r*(5*M)+c*(5*O)+n*(5*K)+U*(5*q)+D*(5*N),z+=L>>>13,L&=8191;let j=z+f*N+x*Y+d*G+R*X+p*(5*T);z=j>>>13,j&=8191,j+=r*(5*H)+c*(5*M)+n*(5*O)+U*(5*K)+D*(5*q),z+=j>>>13,j&=8191;let _=z+f*q+x*N+d*Y+R*G+p*X;z=_>>>13,_&=8191,_+=r*(5*T)+c*(5*H)+n*(5*M)+U*(5*O)+D*(5*K),z+=_>>>13,_&=8191;let v=z+f*K+x*q+d*N+R*Y+p*G;z=v>>>13,v&=8191,v+=r*X+c*(5*T)+n*(5*H)+U*(5*M)+D*(5*O),z+=v>>>13,v&=8191;let u=z+f*O+x*K+d*q+R*N+p*Y;z=u>>>13,u&=8191,u+=r*G+c*X+n*(5*T)+U*(5*H)+D*(5*M),z+=u>>>13,u&=8191;let h=z+f*M+x*O+d*K+R*q+p*N;z=h>>>13,h&=8191,h+=r*Y+c*G+n*X+U*(5*T)+D*(5*H),z+=h>>>13,h&=8191;let e=z+f*H+x*M+d*O+R*K+p*q;z=e>>>13,e&=8191,e+=r*N+c*Y+n*G+U*X+D*(5*T),z+=e>>>13,e&=8191;let J0=z+f*T+x*H+d*M+R*O+p*K;z=J0>>>13,J0&=8191,J0+=r*q+c*N+n*Y+U*G+D*X,z+=J0>>>13,J0&=8191,z=(z<<2)+z|0,z=z+E|0,E=z&8191,z=z>>>13,B+=z,V[0]=E,V[1]=B,V[2]=L,V[3]=j,V[4]=_,V[5]=v,V[6]=u,V[7]=h,V[8]=e,V[9]=J0}finalize(){let{h:$,pad:J}=this,Q=new Uint16Array(10),Z=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=Z,Z=$[X]>>>13,$[X]&=8191;$[0]+=Z*5,Z=$[0]>>>13,$[0]&=8191,$[1]+=Z,Z=$[1]>>>13,$[1]&=8191,$[2]+=Z,Q[0]=$[0]+5,Z=Q[0]>>>13,Q[0]&=8191;for(let X=1;X<10;X++)Q[X]=$[X]+Z,Z=Q[X]>>>13,Q[X]&=8191;Q[9]-=8192;let V=(Z^1)-1;for(let X=0;X<10;X++)Q[X]&=V;V=~V;for(let X=0;X<10;X++)$[X]=$[X]&V|Q[X];$[0]=($[0]|$[1]<<13)&65535,$[1]=($[1]>>>3|$[2]<<10)&65535,$[2]=($[2]>>>6|$[3]<<7)&65535,$[3]=($[3]>>>9|$[4]<<4)&65535,$[4]=($[4]>>>12|$[5]<<1|$[6]<<14)&65535,$[5]=($[6]>>>2|$[7]<<11)&65535,$[6]=($[7]>>>5|$[8]<<8)&65535,$[7]=($[8]>>>8|$[9]<<5)&65535;let I=$[0]+J[0];$[0]=I&65535;for(let X=1;X<8;X++)I=($[X]+J[X]|0)+(I>>>16)|0,$[X]=I&65535;O0(Q)}update($){f$(this);let{buffer:J,blockLen:Q}=this;$=G$($);let Z=$.length;for(let V=0;V<Z;){let I=Math.min(Q-this.pos,Z-V);if(I===Q){for(;Q<=Z-V;V+=Q)this.process($,V);continue}if(J.set($.subarray(V,V+I),this.pos),this.pos+=I,V+=I,this.pos===Q)this.process(J,0,!1),this.pos=0}return this}destroy(){O0(this.h,this.r,this.buffer,this.pad)}digestInto($){f$(this),aJ($,this),this.finished=!0;let{buffer:J,h:Q}=this,{pos:Z}=this;if(Z){J[Z++]=1;for(;Z<16;Z++)J[Z]=0;this.process(J,0,!0)}this.finalize();let V=0;for(let I=0;I<8;I++)$[V++]=Q[I]>>>0,$[V++]=Q[I]>>>8;return $}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}}function u8($){let J=(Z,V)=>$(V).update(G$(Z)).digest(),Q=$(new Uint8Array(32));return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=(Z)=>$(Z),J}var y$=u8(($)=>new VQ($));function l8($,J,Q,Z,V,I=20){let X=$[0],G=J[0],Y=J[1],N=J[2],q=J[3],K=$[1],O=Q[0],M=Q[1],H=V,T=0,F=$[2],S=J[4],C=J[5],A=J[6],w=J[7],l=$[3],b=X,y=G,f=Y,x=N,d=q,R=K,p=O,r=M,c=H,n=T,U=F,D=S,z=C,E=A,B=w,L=l;for(let _=0;_<I;_+=2)d^=P(b+z|0,7),c^=P(d+b|0,9),z^=P(c+d|0,13),b^=P(z+c|0,18),n^=P(R+y|0,7),E^=P(n+R|0,9),y^=P(E+n|0,13),R^=P(y+E|0,18),B^=P(U+p|0,7),f^=P(B+U|0,9),p^=P(f+B|0,13),U^=P(p+f|0,18),x^=P(L+D|0,7),r^=P(x+L|0,9),D^=P(r+x|0,13),L^=P(D+r|0,18),y^=P(b+x|0,7),f^=P(y+b|0,9),x^=P(f+y|0,13),b^=P(x+f|0,18),p^=P(R+d|0,7),r^=P(p+R|0,9),d^=P(r+p|0,13),R^=P(d+r|0,18),D^=P(U+n|0,7),c^=P(D+U|0,9),n^=P(c+D|0,13),U^=P(n+c|0,18),z^=P(L+B|0,7),E^=P(z+L|0,9),B^=P(E+z|0,13),L^=P(B+E|0,18);let j=0;Z[j++]=X+b|0,Z[j++]=G+y|0,Z[j++]=Y+f|0,Z[j++]=N+x|0,Z[j++]=q+d|0,Z[j++]=K+R|0,Z[j++]=O+p|0,Z[j++]=M+r|0,Z[j++]=H+c|0,Z[j++]=T+n|0,Z[j++]=F+U|0,Z[j++]=S+D|0,Z[j++]=C+z|0,Z[j++]=A+E|0,Z[j++]=w+B|0,Z[j++]=l+L|0}function d8($,J,Q,Z){let V=$[0],I=J[0],X=J[1],G=J[2],Y=J[3],N=$[1],q=Q[0],K=Q[1],O=Q[2],M=Q[3],H=$[2],T=J[4],F=J[5],S=J[6],C=J[7],A=$[3];for(let l=0;l<20;l+=2)Y^=P(V+F|0,7),O^=P(Y+V|0,9),F^=P(O+Y|0,13),V^=P(F+O|0,18),M^=P(N+I|0,7),S^=P(M+N|0,9),I^=P(S+M|0,13),N^=P(I+S|0,18),C^=P(H+q|0,7),X^=P(C+H|0,9),q^=P(X+C|0,13),H^=P(q+X|0,18),G^=P(A+T|0,7),K^=P(G+A|0,9),T^=P(K+G|0,13),A^=P(T+K|0,18),I^=P(V+G|0,7),X^=P(I+V|0,9),G^=P(X+I|0,13),V^=P(G+X|0,18),q^=P(N+Y|0,7),K^=P(q+N|0,9),Y^=P(K+q|0,13),N^=P(Y+K|0,18),T^=P(H+M|0,7),O^=P(T+H|0,9),M^=P(O+T|0,13),H^=P(M+O|0,18),F^=P(A+C|0,7),S^=P(F+A|0,9),C^=P(S+F|0,13),A^=P(C+S|0,18);let w=0;Z[w++]=V,Z[w++]=N,Z[w++]=H,Z[w++]=A,Z[w++]=q,Z[w++]=K,Z[w++]=O,Z[w++]=M}var b$=ZQ(l8,{counterRight:!0,extendNonceFn:d8}),u$=eJ({blockSize:64,nonceLength:24,tagLength:16},($,J)=>{return{encrypt(Q,Z){Z=m$(Q.length+32,Z,!1);let V=Z.subarray(0,32),I=Z.subarray(32);Z.set(Q,32),O0(V),b$($,J,Z,Z);let X=y$(I,V);return Z.set(X,16),O0(Z.subarray(0,16),X),Z.subarray(16)},decrypt(Q,Z){$0(Q),Z=m$(Q.length+32,Z,!1);let V=Z.subarray(0,32),I=Z.subarray(32,48),X=Z.subarray(48);Z.set(Q,32),O0(V);let G=b$($,J,V,V),Y=y$(X,G);if(!tJ(I,Y))throw Error("invalid tag");return b$($,J,Z.subarray(16),Z.subarray(16)),O0(V,I,Y),X}}});function p8($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function l$($,...J){if(!p8($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function d$($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function IQ($,J){l$($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}import*as A0 from"node:crypto";var g0=A0&&typeof A0==="object"&&"webcrypto"in A0?A0.webcrypto:A0&&typeof A0==="object"&&("randomBytes"in A0)?A0:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var M$=($)=>new DataView($.buffer,$.byteOffset,$.byteLength);function XQ($){if(typeof $!=="string")throw Error("utf8ToBytes expected string, got "+typeof $);return new Uint8Array(new TextEncoder().encode($))}function p$($){if(typeof $==="string")$=XQ($);return l$($),$}class r${clone(){return this._cloneInto()}}function YQ($){let J=(Z)=>$().update(p$(Z)).digest(),Q=$();return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=()=>$(),J}function GQ($=32){if(g0&&typeof g0.getRandomValues==="function")return g0.getRandomValues(new Uint8Array($));if(g0&&typeof g0.randomBytes==="function")return g0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}function r8($,J,Q,Z){if(typeof $.setBigUint64==="function")return $.setBigUint64(J,Q,Z);let V=BigInt(32),I=BigInt(4294967295),X=Number(Q>>V&I),G=Number(Q&I),Y=Z?4:0,N=Z?0:4;$.setUint32(J+Y,X,Z),$.setUint32(J+N,G,Z)}class c$ extends r${constructor($,J,Q,Z){super();this.blockLen=$,this.outputLen=J,this.padOffset=Q,this.isLE=Z,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array($),this.view=M$(this.buffer)}update($){d$(this);let{view:J,buffer:Q,blockLen:Z}=this;$=p$($);let V=$.length;for(let I=0;I<V;){let X=Math.min(Z-this.pos,V-I);if(X===Z){let G=M$($);for(;Z<=V-I;I+=Z)this.process(G,I);continue}if(Q.set($.subarray(I,I+X),this.pos),this.pos+=X,I+=X,this.pos===Z)this.process(J,0),this.pos=0}return this.length+=$.length,this.roundClean(),this}digestInto($){d$(this),IQ($,this),this.finished=!0;let{buffer:J,view:Q,blockLen:Z,isLE:V}=this,{pos:I}=this;if(J[I++]=128,this.buffer.subarray(I).fill(0),this.padOffset>Z-I)this.process(Q,0),I=0;for(let q=I;q<Z;q++)J[q]=0;r8(Q,Z-8,BigInt(this.length*8),V),this.process(Q,0);let X=M$($),G=this.outputLen;if(G%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Y=G/4,N=this.get();if(Y>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Y;q++)X.setUint32(4*q,N[q],V)}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}_cloneInto($){$||($=new this.constructor),$.set(...this.get());let{blockLen:J,buffer:Q,length:Z,finished:V,destroyed:I,pos:X}=this;if($.length=Z,$.pos=X,$.finished=V,$.destroyed=I,Z%J)$.buffer.set(Q);return $}}var W$=BigInt(4294967295),i$=BigInt(32);function qQ($,J=!1){if(J)return{h:Number($&W$),l:Number($>>i$&W$)};return{h:Number($>>i$&W$)|0,l:Number($&W$)|0}}function c8($,J=!1){let Q=new Uint32Array($.length),Z=new Uint32Array($.length);for(let V=0;V<$.length;V++){let{h:I,l:X}=qQ($[V],J);[Q[V],Z[V]]=[I,X]}return[Q,Z]}var i8=($,J)=>BigInt($>>>0)<<i$|BigInt(J>>>0),h8=($,J,Q)=>$>>>Q,n8=($,J,Q)=>$<<32-Q|J>>>Q,o8=($,J,Q)=>$>>>Q|J<<32-Q,a8=($,J,Q)=>$<<32-Q|J>>>Q,s8=($,J,Q)=>$<<64-Q|J>>>Q-32,t8=($,J,Q)=>$>>>Q-32|J<<64-Q,e8=($,J)=>J,$V=($,J)=>$,JV=($,J,Q)=>$<<Q|J>>>32-Q,QV=($,J,Q)=>J<<Q|$>>>32-Q,ZV=($,J,Q)=>J<<Q-32|$>>>64-Q,VV=($,J,Q)=>$<<Q-32|J>>>64-Q;function IV($,J,Q,Z){let V=(J>>>0)+(Z>>>0);return{h:$+Q+(V/4294967296|0)|0,l:V|0}}var XV=($,J,Q)=>($>>>0)+(J>>>0)+(Q>>>0),YV=($,J,Q,Z)=>J+Q+Z+($/4294967296|0)|0,GV=($,J,Q,Z)=>($>>>0)+(J>>>0)+(Q>>>0)+(Z>>>0),qV=($,J,Q,Z,V)=>J+Q+Z+V+($/4294967296|0)|0,NV=($,J,Q,Z,V)=>($>>>0)+(J>>>0)+(Q>>>0)+(Z>>>0)+(V>>>0),KV=($,J,Q,Z,V,I)=>J+Q+Z+V+I+($/4294967296|0)|0;var MV={fromBig:qQ,split:c8,toBig:i8,shrSH:h8,shrSL:n8,rotrSH:o8,rotrSL:a8,rotrBH:s8,rotrBL:t8,rotr32H:e8,rotr32L:$V,rotlSH:JV,rotlSL:QV,rotlBH:ZV,rotlBL:VV,add:IV,add3L:XV,add3H:YV,add4L:GV,add4H:qV,add5H:KV,add5L:NV},g=MV;var[WV,UV]=(()=>g.split(["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(($)=>BigInt($))))(),E0=new Uint32Array(80),L0=new Uint32Array(80);class NQ extends c${constructor(){super(128,64,16,!1);this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:$,Al:J,Bh:Q,Bl:Z,Ch:V,Cl:I,Dh:X,Dl:G,Eh:Y,El:N,Fh:q,Fl:K,Gh:O,Gl:M,Hh:H,Hl:T}=this;return[$,J,Q,Z,V,I,X,G,Y,N,q,K,O,M,H,T]}set($,J,Q,Z,V,I,X,G,Y,N,q,K,O,M,H,T){this.Ah=$|0,this.Al=J|0,this.Bh=Q|0,this.Bl=Z|0,this.Ch=V|0,this.Cl=I|0,this.Dh=X|0,this.Dl=G|0,this.Eh=Y|0,this.El=N|0,this.Fh=q|0,this.Fl=K|0,this.Gh=O|0,this.Gl=M|0,this.Hh=H|0,this.Hl=T|0}process($,J){for(let C=0;C<16;C++,J+=4)E0[C]=$.getUint32(J),L0[C]=$.getUint32(J+=4);for(let C=16;C<80;C++){let A=E0[C-15]|0,w=L0[C-15]|0,l=g.rotrSH(A,w,1)^g.rotrSH(A,w,8)^g.shrSH(A,w,7),b=g.rotrSL(A,w,1)^g.rotrSL(A,w,8)^g.shrSL(A,w,7),y=E0[C-2]|0,f=L0[C-2]|0,x=g.rotrSH(y,f,19)^g.rotrBH(y,f,61)^g.shrSH(y,f,6),d=g.rotrSL(y,f,19)^g.rotrBL(y,f,61)^g.shrSL(y,f,6),R=g.add4L(b,d,L0[C-7],L0[C-16]),p=g.add4H(R,l,x,E0[C-7],E0[C-16]);E0[C]=p|0,L0[C]=R|0}let{Ah:Q,Al:Z,Bh:V,Bl:I,Ch:X,Cl:G,Dh:Y,Dl:N,Eh:q,El:K,Fh:O,Fl:M,Gh:H,Gl:T,Hh:F,Hl:S}=this;for(let C=0;C<80;C++){let A=g.rotrSH(q,K,14)^g.rotrSH(q,K,18)^g.rotrBH(q,K,41),w=g.rotrSL(q,K,14)^g.rotrSL(q,K,18)^g.rotrBL(q,K,41),l=q&O^~q&H,b=K&M^~K&T,y=g.add5L(S,w,b,UV[C],L0[C]),f=g.add5H(y,F,A,l,WV[C],E0[C]),x=y|0,d=g.rotrSH(Q,Z,28)^g.rotrBH(Q,Z,34)^g.rotrBH(Q,Z,39),R=g.rotrSL(Q,Z,28)^g.rotrBL(Q,Z,34)^g.rotrBL(Q,Z,39),p=Q&V^Q&X^V&X,r=Z&I^Z&G^I&G;F=H|0,S=T|0,H=O|0,T=M|0,O=q|0,M=K|0,{h:q,l:K}=g.add(Y|0,N|0,f|0,x|0),Y=X|0,N=G|0,X=V|0,G=I|0,V=Q|0,I=Z|0;let c=g.add3L(x,R,r);Q=g.add3H(c,f,d,p),Z=c|0}({h:Q,l:Z}=g.add(this.Ah|0,this.Al|0,Q|0,Z|0)),{h:V,l:I}=g.add(this.Bh|0,this.Bl|0,V|0,I|0),{h:X,l:G}=g.add(this.Ch|0,this.Cl|0,X|0,G|0),{h:Y,l:N}=g.add(this.Dh|0,this.Dl|0,Y|0,N|0),{h:q,l:K}=g.add(this.Eh|0,this.El|0,q|0,K|0),{h:O,l:M}=g.add(this.Fh|0,this.Fl|0,O|0,M|0),{h:H,l:T}=g.add(this.Gh|0,this.Gl|0,H|0,T|0),{h:F,l:S}=g.add(this.Hh|0,this.Hl|0,F|0,S|0),this.set(Q,Z,V,I,X,G,Y,N,q,K,O,M,H,T,F,S)}roundClean(){E0.fill(0),L0.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}var KQ=YQ(()=>new NQ);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var n$=BigInt(0),WQ=BigInt(1),OV=BigInt(2);function o$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function a$($){if(!o$($))throw Error("Uint8Array expected")}function U$($,J){if(typeof J!=="boolean")throw Error($+" boolean expected, got "+J)}var zV=Array.from({length:256},($,J)=>J.toString(16).padStart(2,"0"));function O$($){a$($);let J="";for(let Q=0;Q<$.length;Q++)J+=zV[$[Q]];return J}function UQ($){if(typeof $!=="string")throw Error("hex string expected, got "+typeof $);return $===""?n$:BigInt("0x"+$)}var C0={_0:48,_9:57,A:65,F:70,a:97,f:102};function MQ($){if($>=C0._0&&$<=C0._9)return $-C0._0;if($>=C0.A&&$<=C0.F)return $-(C0.A-10);if($>=C0.a&&$<=C0.f)return $-(C0.a-10);return}function OQ($){if(typeof $!=="string")throw Error("hex string expected, got "+typeof $);let J=$.length,Q=J/2;if(J%2)throw Error("hex string expected, got unpadded hex of length "+J);let Z=new Uint8Array(Q);for(let V=0,I=0;V<Q;V++,I+=2){let X=MQ($.charCodeAt(I)),G=MQ($.charCodeAt(I+1));if(X===void 0||G===void 0){let Y=$[I]+$[I+1];throw Error('hex string expected, got non-hex character "'+Y+'" at index '+I)}Z[V]=X*16+G}return Z}function zQ($){return UQ(O$($))}function v0($){return a$($),UQ(O$(Uint8Array.from($).reverse()))}function s$($,J){return OQ($.toString(16).padStart(J*2,"0"))}function s0($,J){return s$($,J).reverse()}function K0($,J,Q){let Z;if(typeof J==="string")try{Z=OQ(J)}catch(I){throw Error($+" must be hex string or Uint8Array, cause: "+I)}else if(o$(J))Z=Uint8Array.from(J);else throw Error($+" must be hex string or Uint8Array");let V=Z.length;if(typeof Q==="number"&&V!==Q)throw Error($+" of length "+Q+" expected, got "+V);return Z}function t$(...$){let J=0;for(let Z=0;Z<$.length;Z++){let V=$[Z];a$(V),J+=V.length}let Q=new Uint8Array(J);for(let Z=0,V=0;Z<$.length;Z++){let I=$[Z];Q.set(I,V),V+=I.length}return Q}var h$=($)=>typeof $==="bigint"&&n$<=$;function HV($,J,Q){return h$($)&&h$(J)&&h$(Q)&&J<=$&&$<Q}function y0($,J,Q,Z){if(!HV(J,Q,Z))throw Error("expected valid "+$+": "+Q+" <= n < "+Z+", got "+J)}function HQ($){let J;for(J=0;$>n$;$>>=WQ,J+=1);return J}var TQ=($)=>(OV<<BigInt($-1))-WQ;var TV={bigint:($)=>typeof $==="bigint",function:($)=>typeof $==="function",boolean:($)=>typeof $==="boolean",string:($)=>typeof $==="string",stringOrUint8Array:($)=>typeof $==="string"||o$($),isSafeInteger:($)=>Number.isSafeInteger($),array:($)=>Array.isArray($),field:($,J)=>J.Fp.isValid($),hash:($)=>typeof $==="function"&&Number.isSafeInteger($.outputLen)};function b0($,J,Q={}){let Z=(V,I,X)=>{let G=TV[I];if(typeof G!=="function")throw Error("invalid validator function");let Y=$[V];if(X&&Y===void 0)return;if(!G(Y,$))throw Error("param "+String(V)+" is invalid. Expected "+I+", got "+Y)};for(let[V,I]of Object.entries(J))Z(V,I,!1);for(let[V,I]of Object.entries(Q))Z(V,I,!0);return $}function e$($){let J=new WeakMap;return(Q,...Z)=>{let V=J.get(Q);if(V!==void 0)return V;let I=$(Q,...Z);return J.set(Q,I),I}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var s=BigInt(0),o=BigInt(1),_0=BigInt(2),DV=BigInt(3),$J=BigInt(4),RQ=BigInt(5),DQ=BigInt(8),AV=BigInt(9),CV=BigInt(16);function a($,J){let Q=$%J;return Q>=s?Q:J+Q}function PV($,J,Q){if(J<s)throw Error("invalid exponent, negatives unsupported");if(Q<=s)throw Error("invalid modulus");if(Q===o)return s;let Z=o;while(J>s){if(J&o)Z=Z*$%Q;$=$*$%Q,J>>=o}return Z}function M0($,J,Q){let Z=$;while(J-- >s)Z*=Z,Z%=Q;return Z}function AQ($,J){if($===s)throw Error("invert: expected non-zero number");if(J<=s)throw Error("invert: expected positive modulus, got "+J);let Q=a($,J),Z=J,V=s,I=o,X=o,G=s;while(Q!==s){let N=Z/Q,q=Z%Q,K=V-X*N,O=I-G*N;Z=Q,Q=q,V=X,I=G,X=K,G=O}if(Z!==o)throw Error("invert: does not exist");return a(V,J)}function SV($){let J=($-o)/_0,Q,Z,V;for(Q=$-o,Z=0;Q%_0===s;Q/=_0,Z++);for(V=_0;V<$&&PV(V,J,$)!==$-o;V++)if(V>1000)throw Error("Cannot find square root: likely non-prime P");if(Z===1){let X=($+o)/$J;return function(Y,N){let q=Y.pow(N,X);if(!Y.eql(Y.sqr(q),N))throw Error("Cannot find square root");return q}}let I=(Q+o)/_0;return function(G,Y){if(G.pow(Y,J)===G.neg(G.ONE))throw Error("Cannot find square root");let N=Z,q=G.pow(G.mul(G.ONE,V),Q),K=G.pow(Y,I),O=G.pow(Y,Q);while(!G.eql(O,G.ONE)){if(G.eql(O,G.ZERO))return G.ZERO;let M=1;for(let T=G.sqr(O);M<N;M++){if(G.eql(T,G.ONE))break;T=G.sqr(T)}let H=G.pow(q,o<<BigInt(N-M-1));q=G.sqr(H),K=G.mul(K,H),O=G.mul(O,q),N=M}return K}}function wV($){if($%$J===DV){let J=($+o)/$J;return function(Z,V){let I=Z.pow(V,J);if(!Z.eql(Z.sqr(I),V))throw Error("Cannot find square root");return I}}if($%DQ===RQ){let J=($-RQ)/DQ;return function(Z,V){let I=Z.mul(V,_0),X=Z.pow(I,J),G=Z.mul(V,X),Y=Z.mul(Z.mul(G,_0),X),N=Z.mul(G,Z.sub(Y,Z.ONE));if(!Z.eql(Z.sqr(N),V))throw Error("Cannot find square root");return N}}if($%CV===AV);return SV($)}var CQ=($,J)=>(a($,J)&o)===o,FV=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function PQ($){let J={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},Q=FV.reduce((Z,V)=>{return Z[V]="function",Z},J);return b0($,Q)}function kV($,J,Q){if(Q<s)throw Error("invalid exponent, negatives unsupported");if(Q===s)return $.ONE;if(Q===o)return J;let Z=$.ONE,V=J;while(Q>s){if(Q&o)Z=$.mul(Z,V);V=$.sqr(V),Q>>=o}return Z}function jV($,J){let Q=Array(J.length),Z=J.reduce((I,X,G)=>{if($.is0(X))return I;return Q[G]=I,$.mul(I,X)},$.ONE),V=$.inv(Z);return J.reduceRight((I,X,G)=>{if($.is0(X))return I;return Q[G]=$.mul(I,Q[G]),$.mul(I,X)},V),Q}function JJ($,J){let Q=J!==void 0?J:$.toString(2).length,Z=Math.ceil(Q/8);return{nBitLength:Q,nByteLength:Z}}function z$($,J,Q=!1,Z={}){if($<=s)throw Error("invalid field: expected ORDER > 0, got "+$);let{nBitLength:V,nByteLength:I}=JJ($,J);if(I>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let X,G=Object.freeze({ORDER:$,isLE:Q,BITS:V,BYTES:I,MASK:TQ(V),ZERO:s,ONE:o,create:(Y)=>a(Y,$),isValid:(Y)=>{if(typeof Y!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof Y);return s<=Y&&Y<$},is0:(Y)=>Y===s,isOdd:(Y)=>(Y&o)===o,neg:(Y)=>a(-Y,$),eql:(Y,N)=>Y===N,sqr:(Y)=>a(Y*Y,$),add:(Y,N)=>a(Y+N,$),sub:(Y,N)=>a(Y-N,$),mul:(Y,N)=>a(Y*N,$),pow:(Y,N)=>kV(G,Y,N),div:(Y,N)=>a(Y*AQ(N,$),$),sqrN:(Y)=>Y*Y,addN:(Y,N)=>Y+N,subN:(Y,N)=>Y-N,mulN:(Y,N)=>Y*N,inv:(Y)=>AQ(Y,$),sqrt:Z.sqrt||((Y)=>{if(!X)X=wV($);return X(G,Y)}),invertBatch:(Y)=>jV(G,Y),cmov:(Y,N,q)=>q?N:Y,toBytes:(Y)=>Q?s0(Y,I):s$(Y,I),fromBytes:(Y)=>{if(Y.length!==I)throw Error("Field.fromBytes: expected "+I+" bytes, got "+Y.length);return Q?v0(Y):zQ(Y)}});return Object.freeze(G)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var SQ=BigInt(0),H$=BigInt(1);function QJ($,J){let Q=J.negate();return $?Q:J}function wQ($,J){if(!Number.isSafeInteger($)||$<=0||$>J)throw Error("invalid window size, expected [1.."+J+"], got W="+$)}function ZJ($,J){wQ($,J);let Q=Math.ceil(J/$)+1,Z=2**($-1);return{windows:Q,windowSize:Z}}function EV($,J){if(!Array.isArray($))throw Error("array expected");$.forEach((Q,Z)=>{if(!(Q instanceof J))throw Error("invalid point at index "+Z)})}function LV($,J){if(!Array.isArray($))throw Error("array of scalars expected");$.forEach((Q,Z)=>{if(!J.isValid(Q))throw Error("invalid scalar at index "+Z)})}var VJ=new WeakMap,FQ=new WeakMap;function IJ($){return FQ.get($)||1}function kQ($,J){return{constTimeNegate:QJ,hasPrecomputes(Q){return IJ(Q)!==1},unsafeLadder(Q,Z,V=$.ZERO){let I=Q;while(Z>SQ){if(Z&H$)V=V.add(I);I=I.double(),Z>>=H$}return V},precomputeWindow(Q,Z){let{windows:V,windowSize:I}=ZJ(Z,J),X=[],G=Q,Y=G;for(let N=0;N<V;N++){Y=G,X.push(Y);for(let q=1;q<I;q++)Y=Y.add(G),X.push(Y);G=Y.double()}return X},wNAF(Q,Z,V){let{windows:I,windowSize:X}=ZJ(Q,J),G=$.ZERO,Y=$.BASE,N=BigInt(2**Q-1),q=2**Q,K=BigInt(Q);for(let O=0;O<I;O++){let M=O*X,H=Number(V&N);if(V>>=K,H>X)H-=q,V+=H$;let T=M,F=M+Math.abs(H)-1,S=O%2!==0,C=H<0;if(H===0)Y=Y.add(QJ(S,Z[T]));else G=G.add(QJ(C,Z[F]))}return{p:G,f:Y}},wNAFUnsafe(Q,Z,V,I=$.ZERO){let{windows:X,windowSize:G}=ZJ(Q,J),Y=BigInt(2**Q-1),N=2**Q,q=BigInt(Q);for(let K=0;K<X;K++){let O=K*G;if(V===SQ)break;let M=Number(V&Y);if(V>>=q,M>G)M-=N,V+=H$;if(M===0)continue;let H=Z[O+Math.abs(M)-1];if(M<0)H=H.negate();I=I.add(H)}return I},getPrecomputes(Q,Z,V){let I=VJ.get(Z);if(!I){if(I=this.precomputeWindow(Z,Q),Q!==1)VJ.set(Z,V(I))}return I},wNAFCached(Q,Z,V){let I=IJ(Q);return this.wNAF(I,this.getPrecomputes(I,Q,V),Z)},wNAFCachedUnsafe(Q,Z,V,I){let X=IJ(Q);if(X===1)return this.unsafeLadder(Q,Z,I);return this.wNAFUnsafe(X,this.getPrecomputes(X,Q,V),Z,I)},setWindowSize(Q,Z){wQ(Z,J),FQ.set(Q,Z),VJ.delete(Q)}}}function jQ($,J,Q,Z){if(EV(Q,$),LV(Z,J),Q.length!==Z.length)throw Error("arrays of points and scalars must have equal length");let V=$.ZERO,I=HQ(BigInt(Q.length)),X=I>12?I-3:I>4?I-2:I?2:1,G=(1<<X)-1,Y=Array(G+1).fill(V),N=Math.floor((J.BITS-1)/X)*X,q=V;for(let K=N;K>=0;K-=X){Y.fill(V);for(let M=0;M<Z.length;M++){let H=Z[M],T=Number(H>>BigInt(K)&BigInt(G));Y[T]=Y[T].add(Q[M])}let O=V;for(let M=Y.length-1,H=V;M>0;M--)H=H.add(Y[M]),O=O.add(H);if(q=q.add(O),K!==0)for(let M=0;M<X;M++)q=q.double()}return q}function EQ($){return PQ($.Fp),b0($,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...JJ($.n,$.nBitLength),...$,...{p:$.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var W0=BigInt(0),G0=BigInt(1),T$=BigInt(2),BV=BigInt(8),gV={zip215:!0};function _V($){let J=EQ($);return b0($,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...J})}function LQ($){let J=_V($),{Fp:Q,n:Z,prehash:V,hash:I,randomBytes:X,nByteLength:G,h:Y}=J,N=T$<<BigInt(G*8)-G0,q=Q.create,K=z$(J.n,J.nBitLength),O=J.uvRatio||((U,D)=>{try{return{isValid:!0,value:Q.sqrt(U*Q.inv(D))}}catch(z){return{isValid:!1,value:W0}}}),M=J.adjustScalarBytes||((U)=>U),H=J.domain||((U,D,z)=>{if(U$("phflag",z),D.length||z)throw Error("Contexts/pre-hash are not supported");return U});function T(U,D){y0("coordinate "+U,D,W0,N)}function F(U){if(!(U instanceof A))throw Error("ExtendedPoint expected")}let S=e$((U,D)=>{let{ex:z,ey:E,ez:B}=U,L=U.is0();if(D==null)D=L?BV:Q.inv(B);let j=q(z*D),_=q(E*D),v=q(B*D);if(L)return{x:W0,y:G0};if(v!==G0)throw Error("invZ was invalid");return{x:j,y:_}}),C=e$((U)=>{let{a:D,d:z}=J;if(U.is0())throw Error("bad point: ZERO");let{ex:E,ey:B,ez:L,et:j}=U,_=q(E*E),v=q(B*B),u=q(L*L),h=q(u*u),e=q(_*D),J0=q(u*q(e+v)),q0=q(h+q(z*q(_*v)));if(J0!==q0)throw Error("bad point: equation left != right (1)");let j0=q(E*B),T0=q(L*j);if(j0!==T0)throw Error("bad point: equation left != right (2)");return!0});class A{constructor(U,D,z,E){this.ex=U,this.ey=D,this.ez=z,this.et=E,T("x",U),T("y",D),T("z",z),T("t",E),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(U){if(U instanceof A)throw Error("extended point not allowed");let{x:D,y:z}=U||{};return T("x",D),T("y",z),new A(D,z,G0,q(D*z))}static normalizeZ(U){let D=Q.invertBatch(U.map((z)=>z.ez));return U.map((z,E)=>z.toAffine(D[E])).map(A.fromAffine)}static msm(U,D){return jQ(A,K,U,D)}_setWindowSize(U){b.setWindowSize(this,U)}assertValidity(){C(this)}equals(U){F(U);let{ex:D,ey:z,ez:E}=this,{ex:B,ey:L,ez:j}=U,_=q(D*j),v=q(B*E),u=q(z*j),h=q(L*E);return _===v&&u===h}is0(){return this.equals(A.ZERO)}negate(){return new A(q(-this.ex),this.ey,this.ez,q(-this.et))}double(){let{a:U}=J,{ex:D,ey:z,ez:E}=this,B=q(D*D),L=q(z*z),j=q(T$*q(E*E)),_=q(U*B),v=D+z,u=q(q(v*v)-B-L),h=_+L,e=h-j,J0=_-L,q0=q(u*e),j0=q(h*J0),T0=q(u*J0),X$=q(e*h);return new A(q0,j0,X$,T0)}add(U){F(U);let{a:D,d:z}=J,{ex:E,ey:B,ez:L,et:j}=this,{ex:_,ey:v,ez:u,et:h}=U;if(D===BigInt(-1)){let dJ=q((B-E)*(v+_)),pJ=q((B+E)*(v-_)),g$=q(pJ-dJ);if(g$===W0)return this.double();let rJ=q(L*T$*h),cJ=q(j*T$*u),iJ=cJ+rJ,hJ=pJ+dJ,nJ=cJ-rJ,R8=q(iJ*g$),D8=q(hJ*nJ),A8=q(iJ*nJ),C8=q(g$*hJ);return new A(R8,D8,C8,A8)}let e=q(E*_),J0=q(B*v),q0=q(j*z*h),j0=q(L*u),T0=q((E+B)*(_+v)-e-J0),X$=j0-q0,uJ=j0+q0,lJ=q(J0-D*e),O8=q(T0*X$),z8=q(uJ*lJ),H8=q(T0*lJ),T8=q(X$*uJ);return new A(O8,z8,T8,H8)}subtract(U){return this.add(U.negate())}wNAF(U){return b.wNAFCached(this,U,A.normalizeZ)}multiply(U){let D=U;y0("scalar",D,G0,Z);let{p:z,f:E}=this.wNAF(D);return A.normalizeZ([z,E])[0]}multiplyUnsafe(U,D=A.ZERO){let z=U;if(y0("scalar",z,W0,Z),z===W0)return l;if(this.is0()||z===G0)return this;return b.wNAFCachedUnsafe(this,z,A.normalizeZ,D)}isSmallOrder(){return this.multiplyUnsafe(Y).is0()}isTorsionFree(){return b.unsafeLadder(this,Z).is0()}toAffine(U){return S(this,U)}clearCofactor(){let{h:U}=J;if(U===G0)return this;return this.multiplyUnsafe(U)}static fromHex(U,D=!1){let{d:z,a:E}=J,B=Q.BYTES;U=K0("pointHex",U,B),U$("zip215",D);let L=U.slice(),j=U[B-1];L[B-1]=j&-129;let _=v0(L),v=D?N:Q.ORDER;y0("pointHex.y",_,W0,v);let u=q(_*_),h=q(u-G0),e=q(z*u-E),{isValid:J0,value:q0}=O(h,e);if(!J0)throw Error("Point.fromHex: invalid y coordinate");let j0=(q0&G0)===G0,T0=(j&128)!==0;if(!D&&q0===W0&&T0)throw Error("Point.fromHex: x=0 and x_0=1");if(T0!==j0)q0=q(-q0);return A.fromAffine({x:q0,y:_})}static fromPrivateKey(U){return x(U).point}toRawBytes(){let{x:U,y:D}=this.toAffine(),z=s0(D,Q.BYTES);return z[z.length-1]|=U&G0?128:0,z}toHex(){return O$(this.toRawBytes())}}A.BASE=new A(J.Gx,J.Gy,G0,q(J.Gx*J.Gy)),A.ZERO=new A(W0,G0,G0,W0);let{BASE:w,ZERO:l}=A,b=kQ(A,G*8);function y(U){return a(U,Z)}function f(U){return y(v0(U))}function x(U){let D=Q.BYTES;U=K0("private key",U,D);let z=K0("hashed private key",I(U),2*D),E=M(z.slice(0,D)),B=z.slice(D,2*D),L=f(E),j=w.multiply(L),_=j.toRawBytes();return{head:E,prefix:B,scalar:L,point:j,pointBytes:_}}function d(U){return x(U).pointBytes}function R(U=new Uint8Array,...D){let z=t$(...D);return f(I(H(z,K0("context",U),!!V)))}function p(U,D,z={}){if(U=K0("message",U),V)U=V(U);let{prefix:E,scalar:B,pointBytes:L}=x(D),j=R(z.context,E,U),_=w.multiply(j).toRawBytes(),v=R(z.context,_,L,U),u=y(j+v*B);y0("signature.s",u,W0,Z);let h=t$(_,s0(u,Q.BYTES));return K0("result",h,Q.BYTES*2)}let r=gV;function c(U,D,z,E=r){let{context:B,zip215:L}=E,j=Q.BYTES;if(U=K0("signature",U,2*j),D=K0("message",D),z=K0("publicKey",z,j),L!==void 0)U$("zip215",L);if(V)D=V(D);let _=v0(U.slice(j,2*j)),v,u,h;try{v=A.fromHex(z,L),u=A.fromHex(U.slice(0,j),L),h=w.multiplyUnsafe(_)}catch(q0){return!1}if(!L&&v.isSmallOrder())return!1;let e=R(B,u.toRawBytes(),v.toRawBytes(),D);return u.add(v.multiplyUnsafe(e)).subtract(h).clearCofactor().equals(A.ZERO)}return w._setWindowSize(8),{CURVE:J,getPublicKey:d,sign:p,verify:c,ExtendedPoint:A,utils:{getExtendedPublicKey:x,randomPrivateKey:()=>X(Q.BYTES),precompute(U=8,D=A.BASE){return D._setWindowSize(U),D.multiply(BigInt(3)),D}}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var XJ=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),BQ=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),OY=BigInt(0),fV=BigInt(1),gQ=BigInt(2),zY=BigInt(3),xV=BigInt(5),mV=BigInt(8);function vV($){let J=BigInt(10),Q=BigInt(20),Z=BigInt(40),V=BigInt(80),I=XJ,G=$*$%I*$%I,Y=M0(G,gQ,I)*G%I,N=M0(Y,fV,I)*$%I,q=M0(N,xV,I)*N%I,K=M0(q,J,I)*q%I,O=M0(K,Q,I)*K%I,M=M0(O,Z,I)*O%I,H=M0(M,V,I)*M%I,T=M0(H,V,I)*M%I,F=M0(T,J,I)*q%I;return{pow_p_5_8:M0(F,gQ,I)*$%I,b2:G}}function yV($){return $[0]&=248,$[31]&=127,$[31]|=64,$}function bV($,J){let Q=XJ,Z=a(J*J*J,Q),V=a(Z*Z*J,Q),I=vV($*V).pow_p_5_8,X=a($*Z*I,Q),G=a(J*X*X,Q),Y=X,N=a(X*BQ,Q),q=G===$,K=G===a(-$,Q),O=G===a(-$*BQ,Q);if(q)X=Y;if(K||O)X=N;if(CQ(X,Q))X=a(-X,Q);return{isValid:q||K,value:X}}var uV=(()=>z$(XJ,void 0,!0))(),lV=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:uV,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:mV,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:KQ,randomBytes:GQ,adjustScalarBytes:yV,uvRatio:bV}))(),R$=(()=>LQ(lV))();/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function dV($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function t0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function f0($,...J){if(!dV($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function e0($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function D$($,J){f0($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}function _Q($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function u0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function l0(...$){for(let J=0;J<$.length;J++)$[J].fill(0)}function $$($,J){return $<<32-J|$>>>J}var fQ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function xQ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var mQ=fQ?($)=>$:($)=>xQ($);function pV($){for(let J=0;J<$.length;J++)$[J]=xQ($[J]);return $}var Y0=fQ?($)=>$:pV;function rV($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function d0($){if(typeof $==="string")$=rV($);return f0($),$}class YJ{}function vQ($){let J=(Z,V)=>$(V).update(d0(Z)).digest(),Q=$({});return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=(Z)=>$(Z),J}var yQ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var A$=BigInt(4294967295),bQ=BigInt(32);function GJ($,J=!1){if(J)return{h:Number($&A$),l:Number($>>bQ&A$)};return{h:Number($>>bQ&A$)|0,l:Number($&A$)|0}}function P0($,J,Q,Z,V){return $=$+J+V|0,Z=$$(Z^$,16),Q=Q+Z|0,J=$$(J^Q,12),{a:$,b:J,c:Q,d:Z}}function S0($,J,Q,Z,V){return $=$+J+V|0,Z=$$(Z^$,8),Q=Q+Z|0,J=$$(J^Q,7),{a:$,b:J,c:Q,d:Z}}class qJ extends YJ{constructor($,J){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,t0($),t0(J),this.blockLen=$,this.outputLen=J,this.buffer=new Uint8Array($),this.buffer32=u0(this.buffer)}update($){e0(this),$=d0($),f0($);let{blockLen:J,buffer:Q,buffer32:Z}=this,V=$.length,I=$.byteOffset,X=$.buffer;for(let G=0;G<V;){if(this.pos===J)Y0(Z),this.compress(Z,0,!1),Y0(Z),this.pos=0;let Y=Math.min(J-this.pos,V-G),N=I+G;if(Y===J&&!(N%4)&&G+Y<V){let q=new Uint32Array(X,N,Math.floor((V-G)/4));Y0(q);for(let K=0;G+J<V;K+=Z.length,G+=J)this.length+=J,this.compress(q,K,!1);Y0(q);continue}Q.set($.subarray(G,G+Y),this.pos),this.pos+=Y,this.length+=Y,G+=Y}return this}digestInto($){e0(this),D$($,this);let{pos:J,buffer32:Q}=this;this.finished=!0,l0(this.buffer.subarray(J)),Y0(Q),this.compress(Q,0,!0),Y0(Q);let Z=u0($);this.get().forEach((V,I)=>Z[I]=mQ(V))}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}_cloneInto($){let{buffer:J,length:Q,finished:Z,destroyed:V,outputLen:I,pos:X}=this;return $||($=new this.constructor({dkLen:I})),$.set(...this.get()),$.buffer.set(J),$.destroyed=V,$.finished=Z,$.length=Q,$.pos=X,$.outputLen=I,$}clone(){return this._cloneInto()}}function NJ($,J,Q,Z,V,I,X,G,Y,N,q,K,O,M,H,T,F,S,C,A){let w=0;for(let l=0;l<Z;l++)({a:V,b:Y,c:O,d:F}=P0(V,Y,O,F,Q[J+$[w++]])),{a:V,b:Y,c:O,d:F}=S0(V,Y,O,F,Q[J+$[w++]]),{a:I,b:N,c:M,d:S}=P0(I,N,M,S,Q[J+$[w++]]),{a:I,b:N,c:M,d:S}=S0(I,N,M,S,Q[J+$[w++]]),{a:X,b:q,c:H,d:C}=P0(X,q,H,C,Q[J+$[w++]]),{a:X,b:q,c:H,d:C}=S0(X,q,H,C,Q[J+$[w++]]),{a:G,b:K,c:T,d:A}=P0(G,K,T,A,Q[J+$[w++]]),{a:G,b:K,c:T,d:A}=S0(G,K,T,A,Q[J+$[w++]]),{a:V,b:N,c:H,d:A}=P0(V,N,H,A,Q[J+$[w++]]),{a:V,b:N,c:H,d:A}=S0(V,N,H,A,Q[J+$[w++]]),{a:I,b:q,c:T,d:F}=P0(I,q,T,F,Q[J+$[w++]]),{a:I,b:q,c:T,d:F}=S0(I,q,T,F,Q[J+$[w++]]),{a:X,b:K,c:O,d:S}=P0(X,K,O,S,Q[J+$[w++]]),{a:X,b:K,c:O,d:S}=S0(X,K,O,S,Q[J+$[w++]]),{a:G,b:Y,c:M,d:C}=P0(G,Y,M,C,Q[J+$[w++]]),{a:G,b:Y,c:M,d:C}=S0(G,Y,M,C,Q[J+$[w++]]);return{v0:V,v1:I,v2:X,v3:G,v4:Y,v5:N,v6:q,v7:K,v8:O,v9:M,v10:H,v11:T,v12:F,v13:S,v14:C,v15:A}}var z0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},w0=yQ.slice(),uQ=(()=>{let $=Array.from({length:16},(Z,V)=>V),J=(Z)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Z[V]),Q=[];for(let Z=0,V=$;Z<7;Z++,V=J(V))Q.push(...V);return Uint8Array.from(Q)})();class KJ extends qJ{constructor($={},J=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:Q,context:Z}=$,V=Z!==void 0;if(Q!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let I=d0(Q).slice();f0(I,32),this.IV=u0(I),Y0(this.IV),this.flags=J|z0.KEYED_HASH}else if(V){let I=d0(Z),X=new KJ({dkLen:32},z0.DERIVE_KEY_CONTEXT).update(I).digest();this.IV=u0(X),Y0(this.IV),this.flags=J|z0.DERIVE_KEY_MATERIAL}else this.IV=w0.slice(),this.flags=J;this.state=this.IV.slice(),this.bufferOut=_Q(this.bufferOut32)}get(){return[]}set(){}b2Compress($,J,Q,Z=0){let{state:V,pos:I}=this,{h:X,l:G}=GJ(BigInt($),!0),{v0:Y,v1:N,v2:q,v3:K,v4:O,v5:M,v6:H,v7:T,v8:F,v9:S,v10:C,v11:A,v12:w,v13:l,v14:b,v15:y}=NJ(uQ,Z,Q,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],w0[0],w0[1],w0[2],w0[3],X,G,I,J);V[0]=Y^F,V[1]=N^S,V[2]=q^C,V[3]=K^A,V[4]=O^w,V[5]=M^l,V[6]=H^b,V[7]=T^y}compress($,J=0,Q=!1){let Z=this.flags;if(!this.chunkPos)Z|=z0.CHUNK_START;if(this.chunkPos===15||Q)Z|=z0.CHUNK_END;if(!Q)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Z,$,J),this.chunkPos+=1,this.chunkPos===16||Q){let V=this.state;this.state=this.IV.slice();for(let I,X=this.chunksDone+1;Q||!(X&1);X>>=1){if(!(I=this.stack.pop()))break;this.buffer32.set(I,0),this.buffer32.set(V,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|z0.PARENT,this.buffer32,0),V=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(V)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:J,flags:Q,state:Z,chunkPos:V,posOut:I,chunkOut:X,stack:G,chunksDone:Y}=this;return $.state.set(Z.slice()),$.stack=G.map((N)=>Uint32Array.from(N)),$.IV.set(J),$.flags=Q,$.chunkPos=V,$.chunksDone=Y,$.posOut=I,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,l0(this.state,this.buffer32,this.IV,this.bufferOut32),l0(...this.stack)}b2CompressOut(){let{state:$,pos:J,flags:Q,buffer32:Z,bufferOut32:V}=this,{h:I,l:X}=GJ(BigInt(this.chunkOut++));Y0(Z);let{v0:G,v1:Y,v2:N,v3:q,v4:K,v5:O,v6:M,v7:H,v8:T,v9:F,v10:S,v11:C,v12:A,v13:w,v14:l,v15:b}=NJ(uQ,0,Z,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],w0[0],w0[1],w0[2],w0[3],X,I,J,Q);V[0]=G^T,V[1]=Y^F,V[2]=N^S,V[3]=q^C,V[4]=K^A,V[5]=O^w,V[6]=M^l,V[7]=H^b,V[8]=$[0]^T,V[9]=$[1]^F,V[10]=$[2]^S,V[11]=$[3]^C,V[12]=$[4]^A,V[13]=$[5]^w,V[14]=$[6]^l,V[15]=$[7]^b,Y0(Z),Y0(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,l0(this.buffer.subarray(this.pos));let $=this.flags|z0.ROOT;if(this.stack.length)$|=z0.PARENT,Y0(this.buffer32),this.compress(this.buffer32,0,!0),Y0(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?z0.CHUNK_START:0)|z0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){e0(this,!1),f0($),this.finish();let{blockLen:J,bufferOut:Q}=this;for(let Z=0,V=$.length;Z<V;){if(this.posOut>=J)this.b2CompressOut();let I=Math.min(J-this.posOut,V-Z);$.set(Q.subarray(this.posOut,this.posOut+I),Z),this.posOut+=I,Z+=I}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return t0($),this.xofInto(new Uint8Array($))}digestInto($){if(D$($,this),this.finished)throw Error("digest() was already called");return this.enableXOF=!1,this.writeInto($),this.destroy(),$}digest(){return this.digestInto(new Uint8Array(this.outputLen))}}var lQ=vQ(($)=>new KJ($));class MJ{async genRandomBytes($){return N$($)}async gen256BitSecureRandomSeed(){return N$(32)}async encryptXSalsa20Poly1305Combined($,J){let Q=N$(24),V=u$(J,Q).encrypt($);return new Uint8Array([...Q,...V])}async decryptXSalsa20Poly1305Combined($,J){let Q=$.slice(0,24),Z=$.slice(24);return u$(J,Q).decrypt(Z)}async deriveEd25519KeyPair($){let J=$,Q=R$.getPublicKey(J),Z=new Uint8Array(64);return Z.set(J,0),Z.set(Q,32),{keyType:"ed25519",privateKey:Z,publicKey:Q}}async signEd25519($,J){let Q=typeof $==="string"?new TextEncoder().encode($):$,Z=J.slice(0,32);return R$.sign(Q,Z)}async checkSigEd25519($,J,Q){let Z=typeof J==="string"?new TextEncoder().encode(J):J;return R$.verify($,Z,Q)}async blake3($){return lQ($)}}var cV=new MJ,x0=cV;var p0=64;var dQ=32,r0=8;var pQ=32;var rQ=30000,cQ=512,m;((R)=>{R[R.Success=0]="Success";R[R.InvalidSignature=3]="InvalidSignature";R[R.ClockOutOfSync=4]="ClockOutOfSync";R[R.UserNotRegistered=5]="UserNotRegistered";R[R.ServerMisconfigured=6]="ServerMisconfigured";R[R.MissingBody=7]="MissingBody";R[R.ExtraBodyContent=8]="ExtraBodyContent";R[R.MissingParam=9]="MissingParam";R[R.InvalidParam=10]="InvalidParam";R[R.InvalidRequest=11]="InvalidRequest";R[R.InternalError=12]="InternalError";R[R.NotFound=13]="NotFound";R[R.InvalidMessage=14]="InvalidMessage";R[R.NoChange=15]="NoChange";R[R.DatabaseClosed=16]="DatabaseClosed";R[R.StorageError=17]="StorageError";R[R.DatabaseError=18]="DatabaseError";R[R.HashMismatch=19]="HashMismatch";R[R.DecryptionError=20]="DecryptionError";R[R.NotImplemented=21]="NotImplemented";R[R.MissingSeed=22]="MissingSeed";R[R.OutOfBounds=23]="OutOfBounds";R[R.HostError=24]="HostError";R[R.CommunicationError=25]="CommunicationError";R[R.VarLimitExceeded=26]="VarLimitExceeded";R[R.InvalidResponse=27]="InvalidResponse";R[R.ConnectionClosed=28]="ConnectionClosed"})(m||={});var iQ="t";function k($){return[$,0]}function W($){return[void 0,$]}function iV($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return W(10);let J=[];while($>0n){let Q=Number($&0x7fn);if($>>=7n,$>0n)J.push(Q|128);else J.push(Q)}if(J.length===0)return k(new Uint8Array([0]));if(J.length>8)return W(26);return k(new Uint8Array(J))}function hV($,J=0){let Q=0n,Z=0,V=J;while(!0){if(V>=$.length)return W(14);let I=$[V++];if(I===void 0)return W(14);if(Q|=BigInt(I&127)<<BigInt(Z),(I&128)===0){if(V-J>8)return W(26);return k({value:Q>0x1fffffffffffffn?Q:Number(Q),bytesRead:V-J})}if(Z+=7,Z>=56)return W(26)}}class I0{data;pos=0;constructor($){this.data=$}static async fromResponse($){let J=await $.arrayBuffer(),Q=new Uint8Array(J);return new I0(Q)}readBigInt(){if(this.pos+8>this.data.length)return W(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,k($)}readDate(){let[$,J]=this.readVarInt();if(J!==0)return W(J);return k(new Date($))}readVarInt(){let[$,J]=hV(this.data,this.pos);if(J!==0)return W(J);this.pos+=$.bytesRead;let Q=$.value;return k(typeof Q==="bigint"?Number(Q):Q)}readVarString(){let[$,J]=this.readVarInt();if(J!==0)return W(J);let[Q,Z]=this.readBytes($);if(Z!==0)return W(Z);let V=new TextDecoder().decode(Q);return k(V)}readBytes($){if($<0)return W(10);if(this.pos+$>this.data.length)return W(23);let J=this.data.slice(this.pos,this.pos+$);return this.pos+=$,k(J)}readVarBytes(){let[$,J]=this.readVarInt();if(J!==0)return W(J);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let J=[];while(!this.done()){let[Q,Z]=this.readStruct($);if(Z!==0)return W(Z);J.push(Q)}return k(J)}readBytesSeq($){let J=[];while(!this.done()){let[Q,Z]=this.readBytes($);if(Z!==0)return W(Z);J.push(Q)}return k(J)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class i{parts=[];writeBigInt($){let J=new Uint8Array(8);new DataView(J.buffer).setBigUint64(0,$,!1),this.parts.push(J)}writeDate($){let J=$.getTime();return this.writeVarInt(J)}writeVarInt($){let[J,Q]=iV($);if(Q!==0)return Q;return this.parts.push(J),0}writeVarString($){let J=new TextEncoder().encode($),Q=this.writeVarInt(J.length);if(Q!==0)return Q;return this.writeBytes(J),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let J=this.writeVarInt($.length);if(J!==0)return J;return this.writeBytes($),0}writeStruct($,J){return $.encode(this,J)}writeStructs($,J){for(let Q of J){let Z=this.writeStruct($,Q);if(Z!==0)return Z}return 0}writeBytesSeq($){for(let J of $)this.writeBytes(J)}result(){let $=this.parts.reduce((Z,V)=>Z+V.length,0),J=new Uint8Array($),Q=0;for(let Z of this.parts)J.set(Z,Q),Q+=Z.length;return J}*scan(){for(let $ of this.parts)yield $}}var J$={encode($,J){let Q=$.writeVarBytes(J.id);if(Q!==0)return Q;let Z=$.writeDate(J.ts);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return W(Q);let[Z,V]=$.readDate();if(V!==0)return W(V);return k({id:J,ts:Z})}};function hQ($){let J=new i,Q=J.writeStruct(J$,$);if(Q!==0)return W(Q);let Z=J.result();return k(Z)}var WJ={encode($,J){let Q=$.writeVarBytes(J.eid);if(Q!==0)return Q;let Z=$.writeVarInt(J.off);if(Z!==0)return Z;let V=$.writeVarInt(J.ctr);if(V!==0)return V;let I=$.writeVarInt(J.len);if(I!==0)return I;if(J.hsh)$.writeBytes(J.hsh);return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return W(Q);let Z=new I0(J),[,V]=J$.decode(Z);if(V!==0)return W(V);let[I,X]=$.readVarInt();if(X!==0)return W(X);let[G,Y]=$.readVarInt();if(Y!==0)return W(Y);let[N,q]=$.readVarInt();if(q!==0)return W(q);let K;if(N>0){let[O,M]=$.readBytes(pQ);if(M!==0)return W(M);K=O}return k({eid:J,off:I,ctr:G,len:N,hsh:K})}};function U0($){return Array.from($).map((Q)=>Q.toString(16).padStart(2,"0")).join("")}function C$($){if($.length%2!==0)throw Error("Invalid hex string");let J=new Uint8Array($.length/2);for(let Q=0;Q<$.length;Q+=2)J[Q/2]=Number.parseInt($.substr(Q,2),16);return J}function aQ($,J){if($===J)return!0;if($.byteLength!==J.byteLength)return!1;return $.every((Q,Z)=>Q===J[Z])}var nQ;if(typeof Uint8Array.prototype.toBase64==="function")nQ=($)=>$.toBase64();else nQ=($)=>btoa(String.fromCharCode(...$));var oQ;if(typeof Uint8Array.fromBase64==="function")oQ=($)=>Uint8Array.fromBase64($);else oQ=($)=>Uint8Array.from(atob($),(J)=>J.charCodeAt(0));function Q$($,J){let Q=new Uint8Array($.length+J.length);return Q.set($,0),Q.set(J,$.length),Q}function sQ($,J,Q){return Q.checkSigEd25519($.sig,$.headCph,J)}async function nV($,J,Q){let Z=Q$(J.privateKey,$);return(await Q.blake3(Z)).slice(0,r0)}async function tQ($,J,Q,Z){let V;if($.bod&&$.len>0)V=await Q.blake3($.bod);let I=new i,X=WJ.encode(I,{...$,hsh:V});if(X!==0)return W(X);let G=I.result(),Y=await nV(G,J,Q),N=await Z.deriveFromKDM(Y),q=await Q.encryptXSalsa20Poly1305Combined(G,N),K=$.bod?await Q.encryptXSalsa20Poly1305Combined($.bod,N):new Uint8Array(0),O=await Q.signEd25519(q,J.privateKey);return k({sig:O,kdm:Y,headCph:q,bodyCph:K})}async function eQ($,J,Q,Z){let V=new I0($),[I,X]=WJ.decode(V);if(X!==0)return W(14);let G;try{G=J&&J.length>0?await Z.decryptXSalsa20Poly1305Combined(J,Q):void 0}catch{return W(20)}let Y=I.hsh&&G===void 0,N=I.hsh===void 0&&G!==void 0;if(Y||N)return W(19);if(I.hsh&&G){let K=await Z.blake3(G);if(!aQ(K,I.hsh))return W(19)}let q=await Z.blake3($);return k({msgHead:I,bod:G,headHash:q})}async function UJ($,J,Q){let Z=new i,V=Z.writeDate(J);if(V!==0)return W(V);let I=Z.result(),X=await Q.signEd25519(I,$.privateKey);return k({pubKey:$.publicKey,sig:X,timestamp:J})}async function N0($,J,Q){let Z=Q.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Z-V)>rQ)return 4;let X=new i;X.writeDate($.timestamp);let G=X.result();if(!await J.checkSigEd25519($.sig,G,$.pubKey))return 3;return 0}class c0{now(){return new Date}}function $Z($,J,Q,Z){let V=J.getTime()-$.getTime(),I=Q.getTime()-Z.getTime();return(V+I)/2}var Z$={encode($,J){if($.writeVarInt(J.quota),J.quota>0){if(J.usage===void 0)return 9;$.writeVarInt(J.usage)}return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return W(Q);let Z;if(J>0){let[V,I]=$.readVarInt();if(I!==0)return W(I);Z=V}return k({quota:J,usage:Z})}};var i0={encode($,J){$.writeBytes(new Uint8Array([J.status]));let Q=$.writeDate(J.timeRcvd);if(Q!==0)return Q;let Z=$.writeDate(J.timeSent);if(Z!==0)return Z;let V=$.writeVarInt(J.subscription.term);if(V!==0)return V;let I=$.writeVarInt(J.subscription.elapsed);if(I!==0)return I;let X=$.writeStruct(Z$,J.subscription.stat);if(X!==0)return X;let G=$.writeStruct(Z$,J.subscription.dyn);if(G!==0)return G;return 0},decode($){let[J,Q]=$.readBytes(1);if(Q!==0)return W(Q);let Z=J[0],[V,I]=$.readDate();if(I!==0)return W(I);let[X,G]=$.readDate();if(G!==0)return W(G);let[Y,N]=$.readVarInt();if(N!==0)return W(N);let[q,K]=$.readVarInt();if(K!==0)return W(K);let[O,M]=$.readStruct(Z$);if(M!==0)return W(M);let[H,T]=$.readStruct(Z$);if(T!==0)return W(T);return k({status:Z,timeRcvd:V,timeSent:X,subscription:{term:Y,elapsed:q,stat:O,dyn:H}})}};async function OJ($,J,Q){let{crypto:Z,enclave:V}=$,I=await V.derive(J,Q);return await Z.deriveEd25519KeyPair(I)}var zJ={encode($,J){let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;let Z=$.writeVarInt(J.seq);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return W(Q);let[Z,V]=$.readVarInt();if(V!==0)return W(V);return k({headCph:J,seq:Z})}};var X0={encode($,J){$.writeBytes(J.pubKey),$.writeBytes(J.sig);let Q=$.writeDate(J.timestamp);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readBytes(dQ);if(Q!==0)return W(Q);let[Z,V]=$.readBytes(p0);if(V!==0)return W(V);let[I,X]=$.readDate();if(X!==0)return W(X);return k({pubKey:J,sig:Z,timestamp:I})}};var JZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;for(let X of Z)V.writeVarInt(X);return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await N0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X,[q,K]=await I.hasUser(N);if(K!==0)return K;if(!q)return 5;let[O,M]=J.readVarInt();if(M!==0)return M;if(!J.done())return 8;let[H,T]=await I.listHeads(N,O);if(T!==0)return T;return Q.writeStructs(zJ,H)},decodeResp($){return $.readStructs(zJ)}};var HJ={encode($,J){$.writeVarInt(J.seq);let Q=$.writeVarBytes(J.bodyCph);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return W(Q);let[Z,V]=$.readVarBytes();if(V!==0)return W(V);return k({seq:J,bodyCph:Z})}};var QZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;for(let X of Z){let G=V.writeVarInt(X);if(G!==0)return G}return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await N0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X,[q,K]=await I.hasUser(N);if(K!==0)return K;if(!q)return 5;let O=[];while(!J.done()){let[M,H]=J.readVarInt();if(H!==0)return H;O.push(M)}console.info(`PULL: ${O.length} bags`);for(let M of O){let[H,T]=await I.getBody(N,M);if(T!==0)return T;if(H){let F={seq:M,bodyCph:H},S=Q.writeStruct(HJ,F);if(S!==0)return S}}return 0},decodeResp($){return $.readStructs(HJ)}};var TJ={encode($,J){$.writeBytes(J.sig),$.writeBytes(J.kdm);let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;let Z=$.writeVarBytes(J.bodyCph);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readBytes(p0);if(Q!==0)return W(Q);let[Z,V]=$.readBytes(r0);if(V!==0)return W(V);let[I,X]=$.readVarBytes();if(X!==0)return W(X);let[G,Y]=$.readVarBytes();if(Y!==0)return W(Y);return k({sig:J,kdm:Z,headCph:I,bodyCph:G})}};var RJ={encode($,J){let Q=$.writeVarInt(J.seq);if(Q!==0)return Q;let Z=$.writeVarBytes(J.headCph);if(Z!==0)return Z;let V=J.bodyCph?J.bodyCph.length:0,I=$.writeVarInt(V);if(I!==0)return I;if(V>0){if(!J.bodyCph)return 10;$.writeBytes(J.bodyCph)}return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return W(Q);let[Z,V]=$.readVarBytes();if(V!==0)return W(V);let[I,X]=$.readVarInt();if(X!==0)return W(X);let G;if(I>0){let[Y,N]=$.readBytes(I);if(N!==0)return W(N);G=Y}return k({seq:J,headCph:Z,bodyCph:G})}};var h0={encode($,J){$.writeBytes(J.sig),$.writeBytes(J.kdm);let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readBytes(p0);if(Q!==0)return W(Q);let[Z,V]=$.readBytes(r0);if(V!==0)return W(V);let[I,X]=$.readVarBytes();if(X!==0)return W(X);return k({sig:J,kdm:Z,headCph:I})}};var P$={encode($,J){if($.writeVarInt(J.idx),$.writeBytes(new Uint8Array([J.status])),J.status===0)$.writeVarInt(J.seq);return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return W(Q);let[Z,V]=$.readBytes(1);if(V!==0)return W(V);let I=Z[0];if(I!==0)return k({idx:J,status:I});let[X,G]=$.readVarInt();if(G!==0)return W(G);return k({idx:J,status:I,seq:X})}};var ZZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;let X=V.writeStructs(TJ,Z);if(X!==0)return X;return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I,notifier:X}=$,[G,Y]=J.readStruct(X0);if(Y!==0)return Y;let N=await N0(G,V,Z);if(N!==0)return N;let{pubKey:q}=G,[K,O]=await I.hasUser(q);if(O!==0)return O;if(!K)return 5;let[M,H]=J.readStructs(TJ);if(H!==0)return H;console.info(`PUSH: ${M.length} bags`);let T=[];for(let A=0;A<M.length;A++){let w=M[A];if(!await sQ(w,q,V)){let c={idx:A,status:3},n=Q.writeStruct(P$,c);if(n!==0)return n;continue}let[b,y]=await I.setBag(q,w);if(y!==0)return y;let f=new i,x=f.writeStruct(h0,w);if(x!==0)return x;let d=f.result(),R={seq:b,headCph:d};if(M.length===1&&w.bodyCph.length<=cQ)R.bodyCph=w.bodyCph;T.push(R);let p={idx:A,status:y,seq:b},r=Q.writeStruct(P$,p);if(r!==0)return r}let F=new i,S=F.writeStructs(RJ,T);if(S!==0)return S;let C=F.result();return await Promise.resolve(X.push(q,C)),0},decodeResp($){return $.readStructs(P$)}};var VZ={async encodeReq($,J,Q,Z,V){return V.writeStruct(X0,Q)},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await N0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X;if(!J.done())return 8;let[q,K]=await I.addUser(N);if(K!==0)return K;return 0},decodeResp($){return k(void 0)}};class DJ{url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,J,Q=()=>{},Z=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let I=new i;I.writeStruct(X0,$);let X=I.result(),G=U0(X);return V.searchParams.set("t",G),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Z()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,Q()},this.websocket.onmessage=(Y)=>{let N=new Uint8Array(Y.data);J(N)},this.websocket.onerror=(Y)=>{console.log(`ERROR: ${JSON.stringify(Y)}`),this.websocket=void 0,Q()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var Z0={user:{path:"/user",endpoint:VZ,name:0},push:{path:"/push",endpoint:ZZ,name:2},peek:{path:"/peek",endpoint:JZ,name:1},pull:{path:"/pull",endpoint:QZ,name:3}},oV={0:Z0.user,2:Z0.push,1:Z0.peek,3:Z0.pull},IZ={[Z0.user.path]:Z0.user,[Z0.push.path]:Z0.push,[Z0.peek.path]:Z0.peek,[Z0.pull.path]:Z0.pull};class XZ{url;listener;constructor($){this.url=$;this.listener=new DJ($)}async call($,J){let{path:Q}=oV[$],Z=new URL(Q,this.url);try{return await sV(Z,J)}catch{return W(25)}}}var AJ=($)=>{return new XZ($.handle)};function n0($){let J=new i;if(J.writeStruct(i0,$)!==0)return new Response(null,{status:500});return CJ(J)}function CJ($){let J=$.result().slice();return new Response(J,{status:200,headers:{"content-type":"application/octet-stream"}})}var aV={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function PJ($){return new Response($.body,{headers:{...$.headers,...aV},status:$.status,statusText:$.statusText})}async function sV($,J){let Q=await fetch($,{method:"POST",body:J.result().slice()});if(!Q.ok)return W(24);let Z=await I0.fromResponse(Q);return k(Z)}class S${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,J,Q,Z,V,I){this.enclave=$;this.crypto=J;this.host=Q;this.clock=Z;this.transport=V;this.updateHostMeta=I}async call($,J){let{clock:Q,crypto:Z,transport:V}=this,{endpoint:I,name:X}=$,G=await this.keys(),Y=Q.now(),[N,q]=await UJ(G,Y,Z);if(q!==0)return W(q);let K=new i,O=await I.encodeReq(this,G,N,J,K);if(O!==0)return W(O);let M=Q.now(),[H,T]=await V.call(X,K),F=Q.now();if(T!==0)return W(T);let[S,C]=H.readStruct(i0);if(C!==0)return W(C);if(S.status!==0)return W(S.status);let w={clockOffset:$Z(M,S.timeRcvd,S.timeSent,F),subscription:S.subscription},l=await this.updateHostMeta(w);if(l!==0)return W(l);return I.decodeResp(H)}keys=()=>{let{host:$}=this;return OJ(this,$.label,$.idx)};seal=async($)=>{let{crypto:J,enclave:Q}=this,Z=await this.keys();return tQ($,Z,J,Q)};register=()=>this.call(Z0.user,[]);peek=($)=>this.call(Z0.peek,[$]);push=($)=>this.call(Z0.push,$);pull=($)=>this.call(Z0.pull,$);listen=async($,J,Q)=>{let{clock:Z,crypto:V,host:I,transport:X}=this,{listener:G}=X,Y=await OJ(this,I.label,I.idx),N=Z.now(),[q,K]=await UJ(Y,N,V);if(K!==0)return K;return await G.connect(q,$,J,Q)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class SJ{seed;crypto;constructor($,J){this.seed=$,this.crypto=J}async deriveFromKDM($){let J=Q$(this.seed,$);return await this.crypto.blake3(J)}async derive($,J=0){let Q=new TextEncoder().encode($),Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,BigInt(J),!1);let V=Q$(Q,Z);return await this.deriveFromKDM(V)}}class wJ{listeners=new Map;addEventListener($,J){let Q=this.listeners.get($);if(!Q)Q=new Set,this.listeners.set($,Q);return Q.add(J),()=>{this.removeEventListener($,J)}}removeEventListener($,J){let Q=this.listeners.get($);if(Q){if(Q.delete(J),Q.size===0)this.listeners.delete($)}}emit($,J){let Q=this.listeners.get($);if(Q){let Z=Array.from(Q);for(let V of Z)V(J)}}}async function YZ($,J,Q,Z=0){let V=J.now(),I=new i,X=I.writeVarString($);if(X!==0)return W(X);let Y={id:I.result(),ts:new Date(0)},[N,q]=hQ(Y);if(q!==0)return W(q);let K=V.getTime()-Y.ts.getTime();return k({eid:N,off:K,ctr:Z,len:Q.length,bod:Q})}class tV{singletonType;latest;latestOff=-1;emitter=new wJ;constructor($){this.singletonType=$}async apply($){for(let J of $){let Q=new I0(J.eid),[Z,V]=Q.readStruct(J$);if(V!==0)continue;let I=new i;I.writeVarString(this.singletonType);let X=I.result();if(Z.id.length===X.length&&Z.id.every((G,Y)=>G===X[Y])){if(this.latest===void 0||J.off>this.latestOff)this.latestOff=J.off,this.latest=J.bod,this.emitter.emit(this.singletonType,null)}}return $.map(()=>0)}on=($,J)=>{this.emitter.addEventListener($,J)};off=($,J)=>{this.emitter.removeEventListener($,J)}}async function GZ($,J,Q,Z){let V=new I0($.headCph),[I,X]=V.readStruct(h0);if(X!==0)return W(X);let{sig:G,kdm:Y,headCph:N}=I;if(!await Z.checkSigEd25519(G,N,J.publicKey))return W(3);let K=await Q.deriveFromKDM(Y),O;try{O=await Z.decryptXSalsa20Poly1305Combined(N,K)}catch{return W(20)}return k({kdm:Y,headEnc:O})}var a0=L8(q8(),1),HX={encode:a0.encode,decode:a0.decode,decodeAsync:a0.decodeAsync},TX=HX;import{Database as RX}from"bun:sqlite";var sN=Symbol("EntityID");var tN=Symbol("MasterSeed"),eN=Symbol("DerivationSeed"),$K=Symbol("PublicKey"),JK=Symbol("PrivateKey"),QK=Symbol("HostSpecificKeyPair"),ZK=Symbol("Hash"),k0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};var H0=new RX("diplomatic.db");H0.exec("PRAGMA journal_mode=WAL;");H0.exec("PRAGMA synchronous=NORMAL;");H0.exec(`
|
|
1
|
+
var P8=Object.create;var{getPrototypeOf:S8,defineProperty:oJ,getOwnPropertyNames:w8}=Object;var F8=Object.prototype.hasOwnProperty;function j8($){return this[$]}var k8,E8,L8=($,J,Q)=>{var Z=$!=null&&typeof $==="object";if(Z){var V=J?k8??=new WeakMap:E8??=new WeakMap,I=V.get($);if(I)return I}Q=$!=null?P8(S8($)):{};let X=J||!$||!$.__esModule?oJ(Q,"default",{value:$,enumerable:!0}):Q;for(let G of w8($))if(!F8.call(X,G))oJ(X,G,{get:j8.bind($,G),enumerable:!0});if(Z)V.set($,X);return X};var V0=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var w$=V0((WZ)=>{Object.defineProperty(WZ,"__esModule",{value:!0});WZ.utf8Count=eV;WZ.utf8EncodeJs=qZ;WZ.utf8EncodeTE=NZ;WZ.utf8Encode=QI;WZ.utf8DecodeJs=KZ;WZ.utf8DecodeTD=MZ;WZ.utf8Decode=XI;function eV($){let J=$.length,Q=0,Z=0;while(Z<J){let V=$.charCodeAt(Z++);if((V&4294967168)===0){Q++;continue}else if((V&4294965248)===0)Q+=2;else{if(V>=55296&&V<=56319){if(Z<J){let I=$.charCodeAt(Z);if((I&64512)===56320)++Z,V=((V&1023)<<10)+(I&1023)+65536}}if((V&4294901760)===0)Q+=3;else Q+=4}}return Q}function qZ($,J,Q){let Z=$.length,V=Q,I=0;while(I<Z){let X=$.charCodeAt(I++);if((X&4294967168)===0){J[V++]=X;continue}else if((X&4294965248)===0)J[V++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(I<Z){let G=$.charCodeAt(I);if((G&64512)===56320)++I,X=((X&1023)<<10)+(G&1023)+65536}}if((X&4294901760)===0)J[V++]=X>>12&15|224,J[V++]=X>>6&63|128;else J[V++]=X>>18&7|240,J[V++]=X>>12&63|128,J[V++]=X>>6&63|128}J[V++]=X&63|128}}var $I=new TextEncoder,JI=50;function NZ($,J,Q){$I.encodeInto($,J.subarray(Q))}function QI($,J,Q){if($.length>JI)NZ($,J,Q);else qZ($,J,Q)}var ZI=4096;function KZ($,J,Q){let Z=J,V=Z+Q,I=[],X="";while(Z<V){let G=$[Z++];if((G&128)===0)I.push(G);else if((G&224)===192){let Y=$[Z++]&63;I.push((G&31)<<6|Y)}else if((G&240)===224){let Y=$[Z++]&63,N=$[Z++]&63;I.push((G&31)<<12|Y<<6|N)}else if((G&248)===240){let Y=$[Z++]&63,N=$[Z++]&63,q=$[Z++]&63,K=(G&7)<<18|Y<<12|N<<6|q;if(K>65535)K-=65536,I.push(K>>>10&1023|55296),K=56320|K&1023;I.push(K)}else I.push(G);if(I.length>=ZI)X+=String.fromCharCode(...I),I.length=0}if(I.length>0)X+=String.fromCharCode(...I);return X}var VI=new TextDecoder,II=200;function MZ($,J,Q){let Z=$.subarray(J,J+Q);return VI.decode(Z)}function XI($,J,Q){if(Q>II)return MZ($,J,Q);else return KZ($,J,Q)}});var FJ=V0((OZ)=>{Object.defineProperty(OZ,"__esModule",{value:!0});OZ.ExtData=void 0;class UZ{type;data;constructor($,J){this.type=$,this.data=J}}OZ.ExtData=UZ});var j$=V0((HZ)=>{Object.defineProperty(HZ,"__esModule",{value:!0});HZ.DecodeError=void 0;class F$ extends Error{constructor($){super($);let J=Object.create(F$.prototype);Object.setPrototypeOf(this,J),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:F$.name})}}HZ.DecodeError=F$});var k$=V0((RZ)=>{Object.defineProperty(RZ,"__esModule",{value:!0});RZ.UINT32_MAX=void 0;RZ.setUint64=UI;RZ.setInt64=OI;RZ.getInt64=zI;RZ.getUint64=HI;RZ.UINT32_MAX=4294967295;function UI($,J,Q){let Z=Q/4294967296,V=Q;$.setUint32(J,Z),$.setUint32(J+4,V)}function OI($,J,Q){let Z=Math.floor(Q/4294967296),V=Q;$.setUint32(J,Z),$.setUint32(J+4,V)}function zI($,J){let Q=$.getInt32(J),Z=$.getUint32(J+4);return Q*4294967296+Z}function HI($,J){let Q=$.getUint32(J),Z=$.getUint32(J+4);return Q*4294967296+Z}});var jJ=V0((jZ)=>{Object.defineProperty(jZ,"__esModule",{value:!0});jZ.timestampExtension=jZ.EXT_TIMESTAMP=void 0;jZ.encodeTimeSpecToTimestamp=CZ;jZ.encodeDateToTimeSpec=PZ;jZ.encodeTimestampExtension=SZ;jZ.decodeTimestampToTimeSpec=wZ;jZ.decodeTimestampExtension=FZ;var CI=j$(),AZ=k$();jZ.EXT_TIMESTAMP=-1;var PI=4294967295,SI=17179869183;function CZ({sec:$,nsec:J}){if($>=0&&J>=0&&$<=SI)if(J===0&&$<=PI){let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,$),Q}else{let Q=$/4294967296,Z=$&4294967295,V=new Uint8Array(8),I=new DataView(V.buffer);return I.setUint32(0,J<<2|Q&3),I.setUint32(4,Z),V}else{let Q=new Uint8Array(12),Z=new DataView(Q.buffer);return Z.setUint32(0,J),(0,AZ.setInt64)(Z,4,$),Q}}function PZ($){let J=$.getTime(),Q=Math.floor(J/1000),Z=(J-Q*1000)*1e6,V=Math.floor(Z/1e9);return{sec:Q+V,nsec:Z-V*1e9}}function SZ($){if($ instanceof Date){let J=PZ($);return CZ(J)}else return null}function wZ($){let J=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let Q=J.getUint32(0),Z=0;return{sec:Q,nsec:0}}case 8:{let Q=J.getUint32(0),Z=J.getUint32(4),V=(Q&3)*4294967296+Z,I=Q>>>2;return{sec:V,nsec:I}}case 12:{let Q=(0,AZ.getInt64)(J,4),Z=J.getUint32(0);return{sec:Q,nsec:Z}}default:throw new CI.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function FZ($){let J=wZ($);return new Date(J.sec*1000+J.nsec/1e6)}jZ.timestampExtension={type:jZ.EXT_TIMESTAMP,encode:SZ,decode:FZ}});var L$=V0((LZ)=>{Object.defineProperty(LZ,"__esModule",{value:!0});LZ.ExtensionCodec=void 0;var E$=FJ(),LI=jJ();class kJ{static defaultCodec=new kJ;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(LI.timestampExtension)}register({type:$,encode:J,decode:Q}){if($>=0)this.encoders[$]=J,this.decoders[$]=Q;else{let Z=-1-$;this.builtInEncoders[Z]=J,this.builtInDecoders[Z]=Q}}tryToEncode($,J){for(let Q=0;Q<this.builtInEncoders.length;Q++){let Z=this.builtInEncoders[Q];if(Z!=null){let V=Z($,J);if(V!=null){let I=-1-Q;return new E$.ExtData(I,V)}}}for(let Q=0;Q<this.encoders.length;Q++){let Z=this.encoders[Q];if(Z!=null){let V=Z($,J);if(V!=null){let I=Q;return new E$.ExtData(I,V)}}}if($ instanceof E$.ExtData)return $;return null}decode($,J,Q){let Z=J<0?this.builtInDecoders[-1-J]:this.decoders[J];if(Z)return Z($,J,Q);else return new E$.ExtData(J,$)}}LZ.ExtensionCodec=kJ});var EJ=V0((gZ)=>{Object.defineProperty(gZ,"__esModule",{value:!0});gZ.ensureUint8Array=gI;function BI($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function gI($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(BI($))return new Uint8Array($);else return Uint8Array.from($)}});var BJ=V0((xZ)=>{Object.defineProperty(xZ,"__esModule",{value:!0});xZ.Encoder=xZ.DEFAULT_INITIAL_BUFFER_SIZE=xZ.DEFAULT_MAX_DEPTH=void 0;var _Z=w$(),fI=L$(),fZ=k$(),xI=EJ();xZ.DEFAULT_MAX_DEPTH=100;xZ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class LJ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??fI.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??xZ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??xZ.DEFAULT_INITIAL_BUFFER_SIZE,this.sortKeys=$?.sortKeys??!1,this.forceFloat32=$?.forceFloat32??!1,this.ignoreUndefined=$?.ignoreUndefined??!1,this.forceIntegerToFloat=$?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new LJ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef($){if(this.entered)return this.clone().encodeSharedRef($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode($){if(this.entered)return this.clone().encode($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode($,J){if(J>this.maxDepth)throw Error(`Too deep objects in depth ${J}`);if($==null)this.encodeNil();else if(typeof $==="boolean")this.encodeBoolean($);else if(typeof $==="number")if(!this.forceIntegerToFloat)this.encodeNumber($);else this.encodeNumberAsFloat($);else if(typeof $==="string")this.encodeString($);else if(this.useBigInt64&&typeof $==="bigint")this.encodeBigInt64($);else this.encodeObject($,J)}ensureBufferSizeToWrite($){let J=this.pos+$;if(this.view.byteLength<J)this.resizeBuffer(J*2)}resizeBuffer($){let J=new ArrayBuffer($),Q=new Uint8Array(J),Z=new DataView(J);Q.set(this.bytes),this.view=Z,this.bytes=Q}encodeNil(){this.writeU8(192)}encodeBoolean($){if($===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber($){if(!this.forceIntegerToFloat&&Number.isSafeInteger($))if($>=0)if($<128)this.writeU8($);else if($<256)this.writeU8(204),this.writeU8($);else if($<65536)this.writeU8(205),this.writeU16($);else if($<4294967296)this.writeU8(206),this.writeU32($);else if(!this.useBigInt64)this.writeU8(207),this.writeU64($);else this.encodeNumberAsFloat($);else if($>=-32)this.writeU8(224|$+32);else if($>=-128)this.writeU8(208),this.writeI8($);else if($>=-32768)this.writeU8(209),this.writeI16($);else if($>=-2147483648)this.writeU8(210),this.writeI32($);else if(!this.useBigInt64)this.writeU8(211),this.writeI64($);else this.encodeNumberAsFloat($);else this.encodeNumberAsFloat($)}encodeNumberAsFloat($){if(this.forceFloat32)this.writeU8(202),this.writeF32($);else this.writeU8(203),this.writeF64($)}encodeBigInt64($){if($>=BigInt(0))this.writeU8(207),this.writeBigUint64($);else this.writeU8(211),this.writeBigInt64($)}writeStringHeader($){if($<32)this.writeU8(160+$);else if($<256)this.writeU8(217),this.writeU8($);else if($<65536)this.writeU8(218),this.writeU16($);else if($<4294967296)this.writeU8(219),this.writeU32($);else throw Error(`Too long string: ${$} bytes in UTF-8`)}encodeString($){let Q=(0,_Z.utf8Count)($);this.ensureBufferSizeToWrite(5+Q),this.writeStringHeader(Q),(0,_Z.utf8Encode)($,this.bytes,this.pos),this.pos+=Q}encodeObject($,J){let Q=this.extensionCodec.tryToEncode($,this.context);if(Q!=null)this.encodeExtension(Q);else if(Array.isArray($))this.encodeArray($,J);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,J);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let J=$.byteLength;if(J<256)this.writeU8(196),this.writeU8(J);else if(J<65536)this.writeU8(197),this.writeU16(J);else if(J<4294967296)this.writeU8(198),this.writeU32(J);else throw Error(`Too large binary: ${J}`);let Q=(0,xI.ensureUint8Array)($);this.writeU8a(Q)}encodeArray($,J){let Q=$.length;if(Q<16)this.writeU8(144+Q);else if(Q<65536)this.writeU8(220),this.writeU16(Q);else if(Q<4294967296)this.writeU8(221),this.writeU32(Q);else throw Error(`Too large array: ${Q}`);for(let Z of $)this.doEncode(Z,J+1)}countWithoutUndefined($,J){let Q=0;for(let Z of J)if($[Z]!==void 0)Q++;return Q}encodeMap($,J){let Q=Object.keys($);if(this.sortKeys)Q.sort();let Z=this.ignoreUndefined?this.countWithoutUndefined($,Q):Q.length;if(Z<16)this.writeU8(128+Z);else if(Z<65536)this.writeU8(222),this.writeU16(Z);else if(Z<4294967296)this.writeU8(223),this.writeU32(Z);else throw Error(`Too large map object: ${Z}`);for(let V of Q){let I=$[V];if(!(this.ignoreUndefined&&I===void 0))this.encodeString(V),this.doEncode(I,J+1)}}encodeExtension($){if(typeof $.data==="function"){let Q=$.data(this.pos+6),Z=Q.length;if(Z>=4294967296)throw Error(`Too large extension object: ${Z}`);this.writeU8(201),this.writeU32(Z),this.writeI8($.type),this.writeU8a(Q);return}let J=$.data.length;if(J===1)this.writeU8(212);else if(J===2)this.writeU8(213);else if(J===4)this.writeU8(214);else if(J===8)this.writeU8(215);else if(J===16)this.writeU8(216);else if(J<256)this.writeU8(199),this.writeU8(J);else if(J<65536)this.writeU8(200),this.writeU16(J);else if(J<4294967296)this.writeU8(201),this.writeU32(J);else throw Error(`Too large extension object: ${J}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let J=$.length;this.ensureBufferSizeToWrite(J),this.bytes.set($,this.pos),this.pos+=J}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),(0,fZ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,fZ.setInt64)(this.view,this.pos,$),this.pos+=8}writeBigUint64($){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,$),this.pos+=8}writeBigInt64($){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,$),this.pos+=8}}xZ.Encoder=LJ});var uZ=V0((bZ)=>{Object.defineProperty(bZ,"__esModule",{value:!0});bZ.encode=vI;var mI=BJ();function vI($,J){return new mI.Encoder(J).encodeSharedRef($)}});var dZ=V0((lZ)=>{Object.defineProperty(lZ,"__esModule",{value:!0});lZ.prettyByte=bI;function bI($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var iZ=V0((rZ)=>{Object.defineProperty(rZ,"__esModule",{value:!0});rZ.CachedKeyDecoder=void 0;var lI=w$(),dI=16,pI=16;class pZ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=dI,J=pI){this.maxKeyLength=$,this.maxLengthPerKey=J,this.caches=[];for(let Q=0;Q<this.maxKeyLength;Q++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,J,Q){let Z=this.caches[Q-1];$:for(let V of Z){let I=V.bytes;for(let X=0;X<Q;X++)if(I[X]!==$[J+X])continue $;return V.str}return null}store($,J){let Q=this.caches[$.length-1],Z={bytes:$,str:J};if(Q.length>=this.maxLengthPerKey)Q[Math.random()*Q.length|0]=Z;else Q.push(Z)}decode($,J,Q){let Z=this.find($,J,Q);if(Z!=null)return this.hit++,Z;this.miss++;let V=(0,lI.utf8DecodeJs)($,J,Q),I=Uint8Array.prototype.slice.call($,J,J+Q);return this.store(I,V),V}}rZ.CachedKeyDecoder=pZ});var B$=V0((sZ)=>{Object.defineProperty(sZ,"__esModule",{value:!0});sZ.Decoder=void 0;var gJ=dZ(),rI=L$(),m0=k$(),cI=w$(),hZ=EJ(),iI=iZ(),F0=j$(),_J="array",I$="map_key",oZ="map_value",hI=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new F0.DecodeError("The type of key must be string or number but "+typeof $)};class aZ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let J=this.getUninitializedStateFromPool();J.type=_J,J.position=0,J.size=$,J.array=Array($)}pushMapState($){let J=this.getUninitializedStateFromPool();J.type=I$,J.readCount=0,J.size=$,J.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let $={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push($)}return this.stack[this.stackHeadPosition]}release($){if(this.stack[this.stackHeadPosition]!==$)throw Error("Invalid stack state. Released state is not on top of the stack.");if($.type===_J){let Q=$;Q.size=0,Q.array=void 0,Q.position=0,Q.type=void 0}if($.type===I$||$.type===oZ){let Q=$;Q.size=0,Q.map=void 0,Q.readCount=0,Q.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var V$=-1,fJ=new DataView(new ArrayBuffer(0)),nI=new Uint8Array(fJ.buffer);try{fJ.getInt8(0)}catch($){if(!($ instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var nZ=RangeError("Insufficient data"),oI=new iI.CachedKeyDecoder;class xJ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=fJ;bytes=nI;headByte=V$;stack=new aZ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??rI.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??m0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??m0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??m0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??m0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??m0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:oI,this.mapKeyConverter=$?.mapKeyConverter??hI}clone(){return new xJ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=V$,this.stack.reset()}setBuffer($){let J=(0,hZ.ensureUint8Array)($);this.bytes=J,this.view=new DataView(J.buffer,J.byteOffset,J.byteLength),this.pos=0}appendBuffer($){if(this.headByte===V$&&!this.hasRemaining(1))this.setBuffer($);else{let J=this.bytes.subarray(this.pos),Q=(0,hZ.ensureUint8Array)($),Z=new Uint8Array(J.length+Q.length);Z.set(J),Z.set(Q,J.length),this.setBuffer(Z)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:J,pos:Q}=this;return RangeError(`Extra ${J.byteLength-Q} of ${J.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let J=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return J}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let J=!1,Q;for await(let X of $){if(J)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{Q=this.doDecodeSync(),J=!0}catch(G){if(!(G instanceof RangeError))throw G}this.totalPos+=this.pos}if(J){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Q}let{headByte:Z,pos:V,totalPos:I}=this;throw RangeError(`Insufficient data in parsing ${(0,gJ.prettyByte)(Z)} at ${I} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,J){if(this.entered){yield*this.clone().decodeMultiAsync($,J);return}try{this.entered=!0;let Q=J,Z=-1;for await(let V of $){if(J&&Z===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),Q)Z=this.readArraySize(),Q=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Z===0)break}catch(I){if(!(I instanceof RangeError))throw I}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),J;if($>=224)J=$-256;else if($<192)if($<128)J=$;else if($<144){let Z=$-128;if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($<160){let Z=$-144;if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else{let Z=$-160;J=this.decodeString(Z,0)}else if($===192)J=null;else if($===194)J=!1;else if($===195)J=!0;else if($===202)J=this.readF32();else if($===203)J=this.readF64();else if($===204)J=this.readU8();else if($===205)J=this.readU16();else if($===206)J=this.readU32();else if($===207)if(this.useBigInt64)J=this.readU64AsBigInt();else J=this.readU64();else if($===208)J=this.readI8();else if($===209)J=this.readI16();else if($===210)J=this.readI32();else if($===211)if(this.useBigInt64)J=this.readI64AsBigInt();else J=this.readI64();else if($===217){let Z=this.lookU8();J=this.decodeString(Z,1)}else if($===218){let Z=this.lookU16();J=this.decodeString(Z,2)}else if($===219){let Z=this.lookU32();J=this.decodeString(Z,4)}else if($===220){let Z=this.readU16();if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else if($===221){let Z=this.readU32();if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else if($===222){let Z=this.readU16();if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($===223){let Z=this.readU32();if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($===196){let Z=this.lookU8();J=this.decodeBinary(Z,1)}else if($===197){let Z=this.lookU16();J=this.decodeBinary(Z,2)}else if($===198){let Z=this.lookU32();J=this.decodeBinary(Z,4)}else if($===212)J=this.decodeExtension(1,0);else if($===213)J=this.decodeExtension(2,0);else if($===214)J=this.decodeExtension(4,0);else if($===215)J=this.decodeExtension(8,0);else if($===216)J=this.decodeExtension(16,0);else if($===199){let Z=this.lookU8();J=this.decodeExtension(Z,1)}else if($===200){let Z=this.lookU16();J=this.decodeExtension(Z,2)}else if($===201){let Z=this.lookU32();J=this.decodeExtension(Z,4)}else throw new F0.DecodeError(`Unrecognized type byte: ${(0,gJ.prettyByte)($)}`);this.complete();let Q=this.stack;while(Q.length>0){let Z=Q.top();if(Z.type===_J)if(Z.array[Z.position]=J,Z.position++,Z.position===Z.size)J=Z.array,Q.release(Z);else continue $;else if(Z.type===I$){if(J==="__proto__")throw new F0.DecodeError("The key __proto__ is not allowed");Z.key=this.mapKeyConverter(J),Z.type=oZ;continue $}else if(Z.map[Z.key]=J,Z.readCount++,Z.readCount===Z.size)J=Z.map,Q.release(Z);else{Z.key=null,Z.type=I$;continue $}}return J}}readHeadByte(){if(this.headByte===V$)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=V$}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new F0.DecodeError(`Unrecognized array type byte: ${(0,gJ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new F0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new F0.DecodeError(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,J){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,J);return this.decodeBinary($,J)}decodeUtf8String($,J){if($>this.maxStrLength)throw new F0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+J+$)throw nZ;let Q=this.pos+J,Z;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Z=this.keyDecoder.decode(this.bytes,Q,$);else Z=(0,cI.utf8Decode)(this.bytes,Q,$);return this.pos+=J+$,Z}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===I$;return!1}decodeBinary($,J){if($>this.maxBinLength)throw new F0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+J))throw nZ;let Q=this.pos+J,Z=this.bytes.subarray(Q,Q+$);return this.pos+=J+$,Z}decodeExtension($,J){if($>this.maxExtLength)throw new F0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let Q=this.view.getInt8(this.pos+J),Z=this.decodeBinary($,J+1);return this.extensionCodec.decode(Z,Q,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=(0,m0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,m0.getInt64)(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}sZ.Decoder=xJ});var J8=V0(($8)=>{Object.defineProperty($8,"__esModule",{value:!0});$8.decode=aI;$8.decodeMulti=sI;var eZ=B$();function aI($,J){return new eZ.Decoder(J).decode($)}function sI($,J){return new eZ.Decoder(J).decodeMulti($)}});var I8=V0((V8)=>{Object.defineProperty(V8,"__esModule",{value:!0});V8.isAsyncIterable=Q8;V8.asyncIterableFromStream=Z8;V8.ensureAsyncIterable=$X;function Q8($){return $[Symbol.asyncIterator]!=null}async function*Z8($){let J=$.getReader();try{while(!0){let{done:Q,value:Z}=await J.read();if(Q)return;yield Z}}finally{J.releaseLock()}}function $X($){if(Q8($))return $;else return Z8($)}});var Y8=V0((X8)=>{Object.defineProperty(X8,"__esModule",{value:!0});X8.decodeAsync=VX;X8.decodeArrayStream=IX;X8.decodeMultiStream=XX;var mJ=B$(),vJ=I8();async function VX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeAsync(Q)}function IX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeArrayStream(Q)}function XX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeStream(Q)}});var q8=V0((t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.decodeTimestampExtension=t.encodeTimestampExtension=t.decodeTimestampToTimeSpec=t.encodeTimeSpecToTimestamp=t.encodeDateToTimeSpec=t.EXT_TIMESTAMP=t.ExtData=t.ExtensionCodec=t.Encoder=t.DecodeError=t.Decoder=t.decodeMultiStream=t.decodeArrayStream=t.decodeAsync=t.decodeMulti=t.decode=t.encode=void 0;var NX=uZ();Object.defineProperty(t,"encode",{enumerable:!0,get:function(){return NX.encode}});var G8=J8();Object.defineProperty(t,"decode",{enumerable:!0,get:function(){return G8.decode}});Object.defineProperty(t,"decodeMulti",{enumerable:!0,get:function(){return G8.decodeMulti}});var yJ=Y8();Object.defineProperty(t,"decodeAsync",{enumerable:!0,get:function(){return yJ.decodeAsync}});Object.defineProperty(t,"decodeArrayStream",{enumerable:!0,get:function(){return yJ.decodeArrayStream}});Object.defineProperty(t,"decodeMultiStream",{enumerable:!0,get:function(){return yJ.decodeMultiStream}});var KX=B$();Object.defineProperty(t,"Decoder",{enumerable:!0,get:function(){return KX.Decoder}});var MX=j$();Object.defineProperty(t,"DecodeError",{enumerable:!0,get:function(){return MX.DecodeError}});var WX=BJ();Object.defineProperty(t,"Encoder",{enumerable:!0,get:function(){return WX.Encoder}});var UX=L$();Object.defineProperty(t,"ExtensionCodec",{enumerable:!0,get:function(){return UX.ExtensionCodec}});var OX=FJ();Object.defineProperty(t,"ExtData",{enumerable:!0,get:function(){return OX.ExtData}});var o0=jJ();Object.defineProperty(t,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return o0.EXT_TIMESTAMP}});Object.defineProperty(t,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return o0.encodeDateToTimeSpec}});Object.defineProperty(t,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return o0.encodeTimeSpecToTimestamp}});Object.defineProperty(t,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return o0.decodeTimestampToTimeSpec}});Object.defineProperty(t,"encodeTimestampExtension",{enumerable:!0,get:function(){return o0.encodeTimestampExtension}});Object.defineProperty(t,"decodeTimestampExtension",{enumerable:!0,get:function(){return o0.decodeTimestampExtension}})});import*as R0 from"node:crypto";var B0=R0&&typeof R0==="object"&&"webcrypto"in R0?R0.webcrypto:R0&&typeof R0==="object"&&("randomBytes"in R0)?R0:void 0;function Y$($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function _$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function $0($,...J){if(!_$($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function f$($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function aJ($,J){$0($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}function x$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var D0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var B8=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!B8)throw Error("Non little-endian hardware is not supported");function g8($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function G$($){if(typeof $==="string")$=g8($);else if(_$($))$=q$($);else throw Error("Uint8Array expected, got "+typeof $);return $}function sJ($,J){if(J==null||typeof J!=="object")throw Error("options must be defined");return Object.assign($,J)}function tJ($,J){if($.length!==J.length)return!1;let Q=0;for(let Z=0;Z<$.length;Z++)Q|=$[Z]^J[Z];return Q===0}var eJ=($,J)=>{function Q(Z,...V){if($0(Z),$.nonceLength!==void 0){let q=V[0];if(!q)throw Error("nonce / iv required");if($.varSizeNonce)$0(q);else $0(q,$.nonceLength)}let I=$.tagLength;if(I&&V[1]!==void 0)$0(V[1]);let X=J(Z,...V),G=(q,K)=>{if(K!==void 0){if(q!==2)throw Error("cipher output not supported");$0(K)}},Y=!1;return{encrypt(q,K){if(Y)throw Error("cannot encrypt() twice with same key + nonce");return Y=!0,$0(q),G(X.encrypt.length,K),X.encrypt(q,K)},decrypt(q,K){if($0(q),I&&q.length<I)throw Error("invalid ciphertext length: smaller than tagLength="+I);return G(X.decrypt.length,K),X.decrypt(q,K)}}}return Object.assign(Q,$),Q};function m$($,J,Q=!0){if(J===void 0)return new Uint8Array($);if(J.length!==$)throw Error("invalid output length, expected "+$+", got: "+J.length);if(Q&&!_8(J))throw Error("invalid output, must be aligned");return J}function _8($){return $.byteOffset%4===0}function q$($){return Uint8Array.from($)}function z0(...$){for(let J=0;J<$.length;J++)$[J].fill(0)}function N$($=32){if(B0&&typeof B0.getRandomValues==="function")return B0.getRandomValues(new Uint8Array($));if(B0&&typeof B0.randomBytes==="function")return B0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var JQ=($)=>Uint8Array.from($.split("").map((J)=>J.charCodeAt(0))),f8=JQ("expand 16-byte k"),x8=JQ("expand 32-byte k"),m8=D0(f8),v8=D0(x8);function w($,J){return $<<J|$>>>32-J}function v$($){return $.byteOffset%4===0}var K$=64,y8=16,QQ=4294967295,$Q=new Uint32Array;function b8($,J,Q,Z,V,I,X,G){let Y=V.length,N=new Uint8Array(K$),q=D0(N),K=v$(V)&&v$(I),O=K?D0(V):$Q,W=K?D0(I):$Q;for(let H=0;H<Y;X++){if($(J,Q,Z,q,X,G),X>=QQ)throw Error("arx: counter overflow");let T=Math.min(K$,Y-H);if(K&&T===K$){let S=H/4;if(H%4!==0)throw Error("arx: invalid block position");for(let F=0,A;F<y8;F++)A=S+F,W[A]=O[A]^q[F];H+=K$;continue}for(let S=0,F;S<T;S++)F=H+S,I[F]=V[F]^N[S];H+=T}}function ZQ($,J){let{allowShortKeys:Q,extendNonceFn:Z,counterLength:V,counterRight:I,rounds:X}=sJ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},J);if(typeof $!=="function")throw Error("core must be a function");return Y$(V),Y$(X),x$(I),x$(Q),(G,Y,N,q,K=0)=>{$0(G),$0(Y),$0(N);let O=N.length;if(q===void 0)q=new Uint8Array(O);if($0(q),Y$(K),K<0||K>=QQ)throw Error("arx: counter overflow");if(q.length<O)throw Error(`arx: output (${q.length}) is shorter than data (${O})`);let W=[],H=G.length,T,S;if(H===32)W.push(T=q$(G)),S=v8;else if(H===16&&Q)T=new Uint8Array(32),T.set(G),T.set(G,16),S=m8,W.push(T);else throw Error(`arx: invalid 32-byte key, got length=${H}`);if(!v$(Y))W.push(Y=q$(Y));let F=D0(T);if(Z){if(Y.length!==24)throw Error("arx: extended nonce must be 24 bytes");Z(S,F,D0(Y.subarray(0,16)),F),Y=Y.subarray(16)}let A=16-V;if(A!==Y.length)throw Error(`arx: nonce must be ${A} or 16 bytes`);if(A!==12){let P=new Uint8Array(12);P.set(Y,I?0:12-Y.length),Y=P,W.push(Y)}let C=D0(Y);return b8($,S,F,C,N,q,K,X),z0(...W),q}}var Q0=($,J)=>$[J++]&255|($[J++]&255)<<8;class VQ{constructor($){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,$=G$($),$0($,32);let J=Q0($,0),Q=Q0($,2),Z=Q0($,4),V=Q0($,6),I=Q0($,8),X=Q0($,10),G=Q0($,12),Y=Q0($,14);this.r[0]=J&8191,this.r[1]=(J>>>13|Q<<3)&8191,this.r[2]=(Q>>>10|Z<<6)&7939,this.r[3]=(Z>>>7|V<<9)&8191,this.r[4]=(V>>>4|I<<12)&255,this.r[5]=I>>>1&8190,this.r[6]=(I>>>14|X<<2)&8191,this.r[7]=(X>>>11|G<<5)&8065,this.r[8]=(G>>>8|Y<<8)&8191,this.r[9]=Y>>>5&127;for(let N=0;N<8;N++)this.pad[N]=Q0($,16+2*N)}process($,J,Q=!1){let Z=Q?0:2048,{h:V,r:I}=this,X=I[0],G=I[1],Y=I[2],N=I[3],q=I[4],K=I[5],O=I[6],W=I[7],H=I[8],T=I[9],S=Q0($,J+0),F=Q0($,J+2),A=Q0($,J+4),C=Q0($,J+6),P=Q0($,J+8),x=Q0($,J+10),y=Q0($,J+12),b=Q0($,J+14),_=V[0]+(S&8191),m=V[1]+((S>>>13|F<<3)&8191),d=V[2]+((F>>>10|A<<6)&8191),R=V[3]+((A>>>7|C<<9)&8191),p=V[4]+((C>>>4|P<<12)&8191),r=V[5]+(P>>>1&8191),h=V[6]+((P>>>14|x<<2)&8191),a=V[7]+((x>>>11|y<<5)&8191),U=V[8]+((y>>>8|b<<8)&8191),D=V[9]+(b>>>5|Z),z=0,E=z+_*X+m*(5*T)+d*(5*H)+R*(5*W)+p*(5*O);z=E>>>13,E&=8191,E+=r*(5*K)+h*(5*q)+a*(5*N)+U*(5*Y)+D*(5*G),z+=E>>>13,E&=8191;let B=z+_*G+m*X+d*(5*T)+R*(5*H)+p*(5*W);z=B>>>13,B&=8191,B+=r*(5*O)+h*(5*K)+a*(5*q)+U*(5*N)+D*(5*Y),z+=B>>>13,B&=8191;let L=z+_*Y+m*G+d*X+R*(5*T)+p*(5*H);z=L>>>13,L&=8191,L+=r*(5*W)+h*(5*O)+a*(5*K)+U*(5*q)+D*(5*N),z+=L>>>13,L&=8191;let k=z+_*N+m*Y+d*G+R*X+p*(5*T);z=k>>>13,k&=8191,k+=r*(5*H)+h*(5*W)+a*(5*O)+U*(5*K)+D*(5*q),z+=k>>>13,k&=8191;let f=z+_*q+m*N+d*Y+R*G+p*X;z=f>>>13,f&=8191,f+=r*(5*T)+h*(5*H)+a*(5*W)+U*(5*O)+D*(5*K),z+=f>>>13,f&=8191;let u=z+_*K+m*q+d*N+R*Y+p*G;z=u>>>13,u&=8191,u+=r*X+h*(5*T)+a*(5*H)+U*(5*W)+D*(5*O),z+=u>>>13,u&=8191;let l=z+_*O+m*K+d*q+R*N+p*Y;z=l>>>13,l&=8191,l+=r*G+h*X+a*(5*T)+U*(5*H)+D*(5*W),z+=l>>>13,l&=8191;let i=z+_*W+m*O+d*K+R*q+p*N;z=i>>>13,i&=8191,i+=r*Y+h*G+a*X+U*(5*T)+D*(5*H),z+=i>>>13,i&=8191;let e=z+_*H+m*W+d*O+R*K+p*q;z=e>>>13,e&=8191,e+=r*N+h*Y+a*G+U*X+D*(5*T),z+=e>>>13,e&=8191;let J0=z+_*T+m*H+d*W+R*O+p*K;z=J0>>>13,J0&=8191,J0+=r*q+h*N+a*Y+U*G+D*X,z+=J0>>>13,J0&=8191,z=(z<<2)+z|0,z=z+E|0,E=z&8191,z=z>>>13,B+=z,V[0]=E,V[1]=B,V[2]=L,V[3]=k,V[4]=f,V[5]=u,V[6]=l,V[7]=i,V[8]=e,V[9]=J0}finalize(){let{h:$,pad:J}=this,Q=new Uint16Array(10),Z=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=Z,Z=$[X]>>>13,$[X]&=8191;$[0]+=Z*5,Z=$[0]>>>13,$[0]&=8191,$[1]+=Z,Z=$[1]>>>13,$[1]&=8191,$[2]+=Z,Q[0]=$[0]+5,Z=Q[0]>>>13,Q[0]&=8191;for(let X=1;X<10;X++)Q[X]=$[X]+Z,Z=Q[X]>>>13,Q[X]&=8191;Q[9]-=8192;let V=(Z^1)-1;for(let X=0;X<10;X++)Q[X]&=V;V=~V;for(let X=0;X<10;X++)$[X]=$[X]&V|Q[X];$[0]=($[0]|$[1]<<13)&65535,$[1]=($[1]>>>3|$[2]<<10)&65535,$[2]=($[2]>>>6|$[3]<<7)&65535,$[3]=($[3]>>>9|$[4]<<4)&65535,$[4]=($[4]>>>12|$[5]<<1|$[6]<<14)&65535,$[5]=($[6]>>>2|$[7]<<11)&65535,$[6]=($[7]>>>5|$[8]<<8)&65535,$[7]=($[8]>>>8|$[9]<<5)&65535;let I=$[0]+J[0];$[0]=I&65535;for(let X=1;X<8;X++)I=($[X]+J[X]|0)+(I>>>16)|0,$[X]=I&65535;z0(Q)}update($){f$(this);let{buffer:J,blockLen:Q}=this;$=G$($);let Z=$.length;for(let V=0;V<Z;){let I=Math.min(Q-this.pos,Z-V);if(I===Q){for(;Q<=Z-V;V+=Q)this.process($,V);continue}if(J.set($.subarray(V,V+I),this.pos),this.pos+=I,V+=I,this.pos===Q)this.process(J,0,!1),this.pos=0}return this}destroy(){z0(this.h,this.r,this.buffer,this.pad)}digestInto($){f$(this),aJ($,this),this.finished=!0;let{buffer:J,h:Q}=this,{pos:Z}=this;if(Z){J[Z++]=1;for(;Z<16;Z++)J[Z]=0;this.process(J,0,!0)}this.finalize();let V=0;for(let I=0;I<8;I++)$[V++]=Q[I]>>>0,$[V++]=Q[I]>>>8;return $}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}}function u8($){let J=(Z,V)=>$(V).update(G$(Z)).digest(),Q=$(new Uint8Array(32));return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=(Z)=>$(Z),J}var y$=u8(($)=>new VQ($));function l8($,J,Q,Z,V,I=20){let X=$[0],G=J[0],Y=J[1],N=J[2],q=J[3],K=$[1],O=Q[0],W=Q[1],H=V,T=0,S=$[2],F=J[4],A=J[5],C=J[6],P=J[7],x=$[3],y=X,b=G,_=Y,m=N,d=q,R=K,p=O,r=W,h=H,a=T,U=S,D=F,z=A,E=C,B=P,L=x;for(let f=0;f<I;f+=2)d^=w(y+z|0,7),h^=w(d+y|0,9),z^=w(h+d|0,13),y^=w(z+h|0,18),a^=w(R+b|0,7),E^=w(a+R|0,9),b^=w(E+a|0,13),R^=w(b+E|0,18),B^=w(U+p|0,7),_^=w(B+U|0,9),p^=w(_+B|0,13),U^=w(p+_|0,18),m^=w(L+D|0,7),r^=w(m+L|0,9),D^=w(r+m|0,13),L^=w(D+r|0,18),b^=w(y+m|0,7),_^=w(b+y|0,9),m^=w(_+b|0,13),y^=w(m+_|0,18),p^=w(R+d|0,7),r^=w(p+R|0,9),d^=w(r+p|0,13),R^=w(d+r|0,18),D^=w(U+a|0,7),h^=w(D+U|0,9),a^=w(h+D|0,13),U^=w(a+h|0,18),z^=w(L+B|0,7),E^=w(z+L|0,9),B^=w(E+z|0,13),L^=w(B+E|0,18);let k=0;Z[k++]=X+y|0,Z[k++]=G+b|0,Z[k++]=Y+_|0,Z[k++]=N+m|0,Z[k++]=q+d|0,Z[k++]=K+R|0,Z[k++]=O+p|0,Z[k++]=W+r|0,Z[k++]=H+h|0,Z[k++]=T+a|0,Z[k++]=S+U|0,Z[k++]=F+D|0,Z[k++]=A+z|0,Z[k++]=C+E|0,Z[k++]=P+B|0,Z[k++]=x+L|0}function d8($,J,Q,Z){let V=$[0],I=J[0],X=J[1],G=J[2],Y=J[3],N=$[1],q=Q[0],K=Q[1],O=Q[2],W=Q[3],H=$[2],T=J[4],S=J[5],F=J[6],A=J[7],C=$[3];for(let x=0;x<20;x+=2)Y^=w(V+S|0,7),O^=w(Y+V|0,9),S^=w(O+Y|0,13),V^=w(S+O|0,18),W^=w(N+I|0,7),F^=w(W+N|0,9),I^=w(F+W|0,13),N^=w(I+F|0,18),A^=w(H+q|0,7),X^=w(A+H|0,9),q^=w(X+A|0,13),H^=w(q+X|0,18),G^=w(C+T|0,7),K^=w(G+C|0,9),T^=w(K+G|0,13),C^=w(T+K|0,18),I^=w(V+G|0,7),X^=w(I+V|0,9),G^=w(X+I|0,13),V^=w(G+X|0,18),q^=w(N+Y|0,7),K^=w(q+N|0,9),Y^=w(K+q|0,13),N^=w(Y+K|0,18),T^=w(H+W|0,7),O^=w(T+H|0,9),W^=w(O+T|0,13),H^=w(W+O|0,18),S^=w(C+A|0,7),F^=w(S+C|0,9),A^=w(F+S|0,13),C^=w(A+F|0,18);let P=0;Z[P++]=V,Z[P++]=N,Z[P++]=H,Z[P++]=C,Z[P++]=q,Z[P++]=K,Z[P++]=O,Z[P++]=W}var b$=ZQ(l8,{counterRight:!0,extendNonceFn:d8}),u$=eJ({blockSize:64,nonceLength:24,tagLength:16},($,J)=>{return{encrypt(Q,Z){Z=m$(Q.length+32,Z,!1);let V=Z.subarray(0,32),I=Z.subarray(32);Z.set(Q,32),z0(V),b$($,J,Z,Z);let X=y$(I,V);return Z.set(X,16),z0(Z.subarray(0,16),X),Z.subarray(16)},decrypt(Q,Z){$0(Q),Z=m$(Q.length+32,Z,!1);let V=Z.subarray(0,32),I=Z.subarray(32,48),X=Z.subarray(48);Z.set(Q,32),z0(V);let G=b$($,J,V,V),Y=y$(X,G);if(!tJ(I,Y))throw Error("invalid tag");return b$($,J,Z.subarray(16),Z.subarray(16)),z0(V,I,Y),X}}});function p8($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function l$($,...J){if(!p8($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function d$($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function IQ($,J){l$($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}import*as A0 from"node:crypto";var g0=A0&&typeof A0==="object"&&"webcrypto"in A0?A0.webcrypto:A0&&typeof A0==="object"&&("randomBytes"in A0)?A0:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var M$=($)=>new DataView($.buffer,$.byteOffset,$.byteLength);function XQ($){if(typeof $!=="string")throw Error("utf8ToBytes expected string, got "+typeof $);return new Uint8Array(new TextEncoder().encode($))}function p$($){if(typeof $==="string")$=XQ($);return l$($),$}class r${clone(){return this._cloneInto()}}function YQ($){let J=(Z)=>$().update(p$(Z)).digest(),Q=$();return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=()=>$(),J}function GQ($=32){if(g0&&typeof g0.getRandomValues==="function")return g0.getRandomValues(new Uint8Array($));if(g0&&typeof g0.randomBytes==="function")return g0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}function r8($,J,Q,Z){if(typeof $.setBigUint64==="function")return $.setBigUint64(J,Q,Z);let V=BigInt(32),I=BigInt(4294967295),X=Number(Q>>V&I),G=Number(Q&I),Y=Z?4:0,N=Z?0:4;$.setUint32(J+Y,X,Z),$.setUint32(J+N,G,Z)}class c$ extends r${constructor($,J,Q,Z){super();this.blockLen=$,this.outputLen=J,this.padOffset=Q,this.isLE=Z,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array($),this.view=M$(this.buffer)}update($){d$(this);let{view:J,buffer:Q,blockLen:Z}=this;$=p$($);let V=$.length;for(let I=0;I<V;){let X=Math.min(Z-this.pos,V-I);if(X===Z){let G=M$($);for(;Z<=V-I;I+=Z)this.process(G,I);continue}if(Q.set($.subarray(I,I+X),this.pos),this.pos+=X,I+=X,this.pos===Z)this.process(J,0),this.pos=0}return this.length+=$.length,this.roundClean(),this}digestInto($){d$(this),IQ($,this),this.finished=!0;let{buffer:J,view:Q,blockLen:Z,isLE:V}=this,{pos:I}=this;if(J[I++]=128,this.buffer.subarray(I).fill(0),this.padOffset>Z-I)this.process(Q,0),I=0;for(let q=I;q<Z;q++)J[q]=0;r8(Q,Z-8,BigInt(this.length*8),V),this.process(Q,0);let X=M$($),G=this.outputLen;if(G%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Y=G/4,N=this.get();if(Y>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Y;q++)X.setUint32(4*q,N[q],V)}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}_cloneInto($){$||($=new this.constructor),$.set(...this.get());let{blockLen:J,buffer:Q,length:Z,finished:V,destroyed:I,pos:X}=this;if($.length=Z,$.pos=X,$.finished=V,$.destroyed=I,Z%J)$.buffer.set(Q);return $}}var W$=BigInt(4294967295),i$=BigInt(32);function qQ($,J=!1){if(J)return{h:Number($&W$),l:Number($>>i$&W$)};return{h:Number($>>i$&W$)|0,l:Number($&W$)|0}}function c8($,J=!1){let Q=new Uint32Array($.length),Z=new Uint32Array($.length);for(let V=0;V<$.length;V++){let{h:I,l:X}=qQ($[V],J);[Q[V],Z[V]]=[I,X]}return[Q,Z]}var i8=($,J)=>BigInt($>>>0)<<i$|BigInt(J>>>0),h8=($,J,Q)=>$>>>Q,n8=($,J,Q)=>$<<32-Q|J>>>Q,o8=($,J,Q)=>$>>>Q|J<<32-Q,a8=($,J,Q)=>$<<32-Q|J>>>Q,s8=($,J,Q)=>$<<64-Q|J>>>Q-32,t8=($,J,Q)=>$>>>Q-32|J<<64-Q,e8=($,J)=>J,$V=($,J)=>$,JV=($,J,Q)=>$<<Q|J>>>32-Q,QV=($,J,Q)=>J<<Q|$>>>32-Q,ZV=($,J,Q)=>J<<Q-32|$>>>64-Q,VV=($,J,Q)=>$<<Q-32|J>>>64-Q;function IV($,J,Q,Z){let V=(J>>>0)+(Z>>>0);return{h:$+Q+(V/4294967296|0)|0,l:V|0}}var XV=($,J,Q)=>($>>>0)+(J>>>0)+(Q>>>0),YV=($,J,Q,Z)=>J+Q+Z+($/4294967296|0)|0,GV=($,J,Q,Z)=>($>>>0)+(J>>>0)+(Q>>>0)+(Z>>>0),qV=($,J,Q,Z,V)=>J+Q+Z+V+($/4294967296|0)|0,NV=($,J,Q,Z,V)=>($>>>0)+(J>>>0)+(Q>>>0)+(Z>>>0)+(V>>>0),KV=($,J,Q,Z,V,I)=>J+Q+Z+V+I+($/4294967296|0)|0;var MV={fromBig:qQ,split:c8,toBig:i8,shrSH:h8,shrSL:n8,rotrSH:o8,rotrSL:a8,rotrBH:s8,rotrBL:t8,rotr32H:e8,rotr32L:$V,rotlSH:JV,rotlSL:QV,rotlBH:ZV,rotlBL:VV,add:IV,add3L:XV,add3H:YV,add4L:GV,add4H:qV,add5H:KV,add5L:NV},g=MV;var[WV,UV]=(()=>g.split(["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(($)=>BigInt($))))(),E0=new Uint32Array(80),L0=new Uint32Array(80);class NQ extends c${constructor(){super(128,64,16,!1);this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:$,Al:J,Bh:Q,Bl:Z,Ch:V,Cl:I,Dh:X,Dl:G,Eh:Y,El:N,Fh:q,Fl:K,Gh:O,Gl:W,Hh:H,Hl:T}=this;return[$,J,Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T]}set($,J,Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T){this.Ah=$|0,this.Al=J|0,this.Bh=Q|0,this.Bl=Z|0,this.Ch=V|0,this.Cl=I|0,this.Dh=X|0,this.Dl=G|0,this.Eh=Y|0,this.El=N|0,this.Fh=q|0,this.Fl=K|0,this.Gh=O|0,this.Gl=W|0,this.Hh=H|0,this.Hl=T|0}process($,J){for(let A=0;A<16;A++,J+=4)E0[A]=$.getUint32(J),L0[A]=$.getUint32(J+=4);for(let A=16;A<80;A++){let C=E0[A-15]|0,P=L0[A-15]|0,x=g.rotrSH(C,P,1)^g.rotrSH(C,P,8)^g.shrSH(C,P,7),y=g.rotrSL(C,P,1)^g.rotrSL(C,P,8)^g.shrSL(C,P,7),b=E0[A-2]|0,_=L0[A-2]|0,m=g.rotrSH(b,_,19)^g.rotrBH(b,_,61)^g.shrSH(b,_,6),d=g.rotrSL(b,_,19)^g.rotrBL(b,_,61)^g.shrSL(b,_,6),R=g.add4L(y,d,L0[A-7],L0[A-16]),p=g.add4H(R,x,m,E0[A-7],E0[A-16]);E0[A]=p|0,L0[A]=R|0}let{Ah:Q,Al:Z,Bh:V,Bl:I,Ch:X,Cl:G,Dh:Y,Dl:N,Eh:q,El:K,Fh:O,Fl:W,Gh:H,Gl:T,Hh:S,Hl:F}=this;for(let A=0;A<80;A++){let C=g.rotrSH(q,K,14)^g.rotrSH(q,K,18)^g.rotrBH(q,K,41),P=g.rotrSL(q,K,14)^g.rotrSL(q,K,18)^g.rotrBL(q,K,41),x=q&O^~q&H,y=K&W^~K&T,b=g.add5L(F,P,y,UV[A],L0[A]),_=g.add5H(b,S,C,x,WV[A],E0[A]),m=b|0,d=g.rotrSH(Q,Z,28)^g.rotrBH(Q,Z,34)^g.rotrBH(Q,Z,39),R=g.rotrSL(Q,Z,28)^g.rotrBL(Q,Z,34)^g.rotrBL(Q,Z,39),p=Q&V^Q&X^V&X,r=Z&I^Z&G^I&G;S=H|0,F=T|0,H=O|0,T=W|0,O=q|0,W=K|0,{h:q,l:K}=g.add(Y|0,N|0,_|0,m|0),Y=X|0,N=G|0,X=V|0,G=I|0,V=Q|0,I=Z|0;let h=g.add3L(m,R,r);Q=g.add3H(h,_,d,p),Z=h|0}({h:Q,l:Z}=g.add(this.Ah|0,this.Al|0,Q|0,Z|0)),{h:V,l:I}=g.add(this.Bh|0,this.Bl|0,V|0,I|0),{h:X,l:G}=g.add(this.Ch|0,this.Cl|0,X|0,G|0),{h:Y,l:N}=g.add(this.Dh|0,this.Dl|0,Y|0,N|0),{h:q,l:K}=g.add(this.Eh|0,this.El|0,q|0,K|0),{h:O,l:W}=g.add(this.Fh|0,this.Fl|0,O|0,W|0),{h:H,l:T}=g.add(this.Gh|0,this.Gl|0,H|0,T|0),{h:S,l:F}=g.add(this.Hh|0,this.Hl|0,S|0,F|0),this.set(Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T,S,F)}roundClean(){E0.fill(0),L0.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}var KQ=YQ(()=>new NQ);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var n$=BigInt(0),WQ=BigInt(1),OV=BigInt(2);function o$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function a$($){if(!o$($))throw Error("Uint8Array expected")}function U$($,J){if(typeof J!=="boolean")throw Error($+" boolean expected, got "+J)}var zV=Array.from({length:256},($,J)=>J.toString(16).padStart(2,"0"));function O$($){a$($);let J="";for(let Q=0;Q<$.length;Q++)J+=zV[$[Q]];return J}function UQ($){if(typeof $!=="string")throw Error("hex string expected, got "+typeof $);return $===""?n$:BigInt("0x"+$)}var C0={_0:48,_9:57,A:65,F:70,a:97,f:102};function MQ($){if($>=C0._0&&$<=C0._9)return $-C0._0;if($>=C0.A&&$<=C0.F)return $-(C0.A-10);if($>=C0.a&&$<=C0.f)return $-(C0.a-10);return}function OQ($){if(typeof $!=="string")throw Error("hex string expected, got "+typeof $);let J=$.length,Q=J/2;if(J%2)throw Error("hex string expected, got unpadded hex of length "+J);let Z=new Uint8Array(Q);for(let V=0,I=0;V<Q;V++,I+=2){let X=MQ($.charCodeAt(I)),G=MQ($.charCodeAt(I+1));if(X===void 0||G===void 0){let Y=$[I]+$[I+1];throw Error('hex string expected, got non-hex character "'+Y+'" at index '+I)}Z[V]=X*16+G}return Z}function zQ($){return UQ(O$($))}function v0($){return a$($),UQ(O$(Uint8Array.from($).reverse()))}function s$($,J){return OQ($.toString(16).padStart(J*2,"0"))}function s0($,J){return s$($,J).reverse()}function M0($,J,Q){let Z;if(typeof J==="string")try{Z=OQ(J)}catch(I){throw Error($+" must be hex string or Uint8Array, cause: "+I)}else if(o$(J))Z=Uint8Array.from(J);else throw Error($+" must be hex string or Uint8Array");let V=Z.length;if(typeof Q==="number"&&V!==Q)throw Error($+" of length "+Q+" expected, got "+V);return Z}function t$(...$){let J=0;for(let Z=0;Z<$.length;Z++){let V=$[Z];a$(V),J+=V.length}let Q=new Uint8Array(J);for(let Z=0,V=0;Z<$.length;Z++){let I=$[Z];Q.set(I,V),V+=I.length}return Q}var h$=($)=>typeof $==="bigint"&&n$<=$;function HV($,J,Q){return h$($)&&h$(J)&&h$(Q)&&J<=$&&$<Q}function y0($,J,Q,Z){if(!HV(J,Q,Z))throw Error("expected valid "+$+": "+Q+" <= n < "+Z+", got "+J)}function HQ($){let J;for(J=0;$>n$;$>>=WQ,J+=1);return J}var TQ=($)=>(OV<<BigInt($-1))-WQ;var TV={bigint:($)=>typeof $==="bigint",function:($)=>typeof $==="function",boolean:($)=>typeof $==="boolean",string:($)=>typeof $==="string",stringOrUint8Array:($)=>typeof $==="string"||o$($),isSafeInteger:($)=>Number.isSafeInteger($),array:($)=>Array.isArray($),field:($,J)=>J.Fp.isValid($),hash:($)=>typeof $==="function"&&Number.isSafeInteger($.outputLen)};function b0($,J,Q={}){let Z=(V,I,X)=>{let G=TV[I];if(typeof G!=="function")throw Error("invalid validator function");let Y=$[V];if(X&&Y===void 0)return;if(!G(Y,$))throw Error("param "+String(V)+" is invalid. Expected "+I+", got "+Y)};for(let[V,I]of Object.entries(J))Z(V,I,!1);for(let[V,I]of Object.entries(Q))Z(V,I,!0);return $}function e$($){let J=new WeakMap;return(Q,...Z)=>{let V=J.get(Q);if(V!==void 0)return V;let I=$(Q,...Z);return J.set(Q,I),I}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var s=BigInt(0),n=BigInt(1),_0=BigInt(2),DV=BigInt(3),$J=BigInt(4),RQ=BigInt(5),DQ=BigInt(8),AV=BigInt(9),CV=BigInt(16);function o($,J){let Q=$%J;return Q>=s?Q:J+Q}function PV($,J,Q){if(J<s)throw Error("invalid exponent, negatives unsupported");if(Q<=s)throw Error("invalid modulus");if(Q===n)return s;let Z=n;while(J>s){if(J&n)Z=Z*$%Q;$=$*$%Q,J>>=n}return Z}function W0($,J,Q){let Z=$;while(J-- >s)Z*=Z,Z%=Q;return Z}function AQ($,J){if($===s)throw Error("invert: expected non-zero number");if(J<=s)throw Error("invert: expected positive modulus, got "+J);let Q=o($,J),Z=J,V=s,I=n,X=n,G=s;while(Q!==s){let N=Z/Q,q=Z%Q,K=V-X*N,O=I-G*N;Z=Q,Q=q,V=X,I=G,X=K,G=O}if(Z!==n)throw Error("invert: does not exist");return o(V,J)}function SV($){let J=($-n)/_0,Q,Z,V;for(Q=$-n,Z=0;Q%_0===s;Q/=_0,Z++);for(V=_0;V<$&&PV(V,J,$)!==$-n;V++)if(V>1000)throw Error("Cannot find square root: likely non-prime P");if(Z===1){let X=($+n)/$J;return function(Y,N){let q=Y.pow(N,X);if(!Y.eql(Y.sqr(q),N))throw Error("Cannot find square root");return q}}let I=(Q+n)/_0;return function(G,Y){if(G.pow(Y,J)===G.neg(G.ONE))throw Error("Cannot find square root");let N=Z,q=G.pow(G.mul(G.ONE,V),Q),K=G.pow(Y,I),O=G.pow(Y,Q);while(!G.eql(O,G.ONE)){if(G.eql(O,G.ZERO))return G.ZERO;let W=1;for(let T=G.sqr(O);W<N;W++){if(G.eql(T,G.ONE))break;T=G.sqr(T)}let H=G.pow(q,n<<BigInt(N-W-1));q=G.sqr(H),K=G.mul(K,H),O=G.mul(O,q),N=W}return K}}function wV($){if($%$J===DV){let J=($+n)/$J;return function(Z,V){let I=Z.pow(V,J);if(!Z.eql(Z.sqr(I),V))throw Error("Cannot find square root");return I}}if($%DQ===RQ){let J=($-RQ)/DQ;return function(Z,V){let I=Z.mul(V,_0),X=Z.pow(I,J),G=Z.mul(V,X),Y=Z.mul(Z.mul(G,_0),X),N=Z.mul(G,Z.sub(Y,Z.ONE));if(!Z.eql(Z.sqr(N),V))throw Error("Cannot find square root");return N}}if($%CV===AV);return SV($)}var CQ=($,J)=>(o($,J)&n)===n,FV=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function PQ($){let J={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},Q=FV.reduce((Z,V)=>{return Z[V]="function",Z},J);return b0($,Q)}function jV($,J,Q){if(Q<s)throw Error("invalid exponent, negatives unsupported");if(Q===s)return $.ONE;if(Q===n)return J;let Z=$.ONE,V=J;while(Q>s){if(Q&n)Z=$.mul(Z,V);V=$.sqr(V),Q>>=n}return Z}function kV($,J){let Q=Array(J.length),Z=J.reduce((I,X,G)=>{if($.is0(X))return I;return Q[G]=I,$.mul(I,X)},$.ONE),V=$.inv(Z);return J.reduceRight((I,X,G)=>{if($.is0(X))return I;return Q[G]=$.mul(I,Q[G]),$.mul(I,X)},V),Q}function JJ($,J){let Q=J!==void 0?J:$.toString(2).length,Z=Math.ceil(Q/8);return{nBitLength:Q,nByteLength:Z}}function z$($,J,Q=!1,Z={}){if($<=s)throw Error("invalid field: expected ORDER > 0, got "+$);let{nBitLength:V,nByteLength:I}=JJ($,J);if(I>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let X,G=Object.freeze({ORDER:$,isLE:Q,BITS:V,BYTES:I,MASK:TQ(V),ZERO:s,ONE:n,create:(Y)=>o(Y,$),isValid:(Y)=>{if(typeof Y!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof Y);return s<=Y&&Y<$},is0:(Y)=>Y===s,isOdd:(Y)=>(Y&n)===n,neg:(Y)=>o(-Y,$),eql:(Y,N)=>Y===N,sqr:(Y)=>o(Y*Y,$),add:(Y,N)=>o(Y+N,$),sub:(Y,N)=>o(Y-N,$),mul:(Y,N)=>o(Y*N,$),pow:(Y,N)=>jV(G,Y,N),div:(Y,N)=>o(Y*AQ(N,$),$),sqrN:(Y)=>Y*Y,addN:(Y,N)=>Y+N,subN:(Y,N)=>Y-N,mulN:(Y,N)=>Y*N,inv:(Y)=>AQ(Y,$),sqrt:Z.sqrt||((Y)=>{if(!X)X=wV($);return X(G,Y)}),invertBatch:(Y)=>kV(G,Y),cmov:(Y,N,q)=>q?N:Y,toBytes:(Y)=>Q?s0(Y,I):s$(Y,I),fromBytes:(Y)=>{if(Y.length!==I)throw Error("Field.fromBytes: expected "+I+" bytes, got "+Y.length);return Q?v0(Y):zQ(Y)}});return Object.freeze(G)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var SQ=BigInt(0),H$=BigInt(1);function QJ($,J){let Q=J.negate();return $?Q:J}function wQ($,J){if(!Number.isSafeInteger($)||$<=0||$>J)throw Error("invalid window size, expected [1.."+J+"], got W="+$)}function ZJ($,J){wQ($,J);let Q=Math.ceil(J/$)+1,Z=2**($-1);return{windows:Q,windowSize:Z}}function EV($,J){if(!Array.isArray($))throw Error("array expected");$.forEach((Q,Z)=>{if(!(Q instanceof J))throw Error("invalid point at index "+Z)})}function LV($,J){if(!Array.isArray($))throw Error("array of scalars expected");$.forEach((Q,Z)=>{if(!J.isValid(Q))throw Error("invalid scalar at index "+Z)})}var VJ=new WeakMap,FQ=new WeakMap;function IJ($){return FQ.get($)||1}function jQ($,J){return{constTimeNegate:QJ,hasPrecomputes(Q){return IJ(Q)!==1},unsafeLadder(Q,Z,V=$.ZERO){let I=Q;while(Z>SQ){if(Z&H$)V=V.add(I);I=I.double(),Z>>=H$}return V},precomputeWindow(Q,Z){let{windows:V,windowSize:I}=ZJ(Z,J),X=[],G=Q,Y=G;for(let N=0;N<V;N++){Y=G,X.push(Y);for(let q=1;q<I;q++)Y=Y.add(G),X.push(Y);G=Y.double()}return X},wNAF(Q,Z,V){let{windows:I,windowSize:X}=ZJ(Q,J),G=$.ZERO,Y=$.BASE,N=BigInt(2**Q-1),q=2**Q,K=BigInt(Q);for(let O=0;O<I;O++){let W=O*X,H=Number(V&N);if(V>>=K,H>X)H-=q,V+=H$;let T=W,S=W+Math.abs(H)-1,F=O%2!==0,A=H<0;if(H===0)Y=Y.add(QJ(F,Z[T]));else G=G.add(QJ(A,Z[S]))}return{p:G,f:Y}},wNAFUnsafe(Q,Z,V,I=$.ZERO){let{windows:X,windowSize:G}=ZJ(Q,J),Y=BigInt(2**Q-1),N=2**Q,q=BigInt(Q);for(let K=0;K<X;K++){let O=K*G;if(V===SQ)break;let W=Number(V&Y);if(V>>=q,W>G)W-=N,V+=H$;if(W===0)continue;let H=Z[O+Math.abs(W)-1];if(W<0)H=H.negate();I=I.add(H)}return I},getPrecomputes(Q,Z,V){let I=VJ.get(Z);if(!I){if(I=this.precomputeWindow(Z,Q),Q!==1)VJ.set(Z,V(I))}return I},wNAFCached(Q,Z,V){let I=IJ(Q);return this.wNAF(I,this.getPrecomputes(I,Q,V),Z)},wNAFCachedUnsafe(Q,Z,V,I){let X=IJ(Q);if(X===1)return this.unsafeLadder(Q,Z,I);return this.wNAFUnsafe(X,this.getPrecomputes(X,Q,V),Z,I)},setWindowSize(Q,Z){wQ(Z,J),FQ.set(Q,Z),VJ.delete(Q)}}}function kQ($,J,Q,Z){if(EV(Q,$),LV(Z,J),Q.length!==Z.length)throw Error("arrays of points and scalars must have equal length");let V=$.ZERO,I=HQ(BigInt(Q.length)),X=I>12?I-3:I>4?I-2:I?2:1,G=(1<<X)-1,Y=Array(G+1).fill(V),N=Math.floor((J.BITS-1)/X)*X,q=V;for(let K=N;K>=0;K-=X){Y.fill(V);for(let W=0;W<Z.length;W++){let H=Z[W],T=Number(H>>BigInt(K)&BigInt(G));Y[T]=Y[T].add(Q[W])}let O=V;for(let W=Y.length-1,H=V;W>0;W--)H=H.add(Y[W]),O=O.add(H);if(q=q.add(O),K!==0)for(let W=0;W<X;W++)q=q.double()}return q}function EQ($){return PQ($.Fp),b0($,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...JJ($.n,$.nBitLength),...$,...{p:$.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var U0=BigInt(0),G0=BigInt(1),T$=BigInt(2),BV=BigInt(8),gV={zip215:!0};function _V($){let J=EQ($);return b0($,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...J})}function LQ($){let J=_V($),{Fp:Q,n:Z,prehash:V,hash:I,randomBytes:X,nByteLength:G,h:Y}=J,N=T$<<BigInt(G*8)-G0,q=Q.create,K=z$(J.n,J.nBitLength),O=J.uvRatio||((U,D)=>{try{return{isValid:!0,value:Q.sqrt(U*Q.inv(D))}}catch(z){return{isValid:!1,value:U0}}}),W=J.adjustScalarBytes||((U)=>U),H=J.domain||((U,D,z)=>{if(U$("phflag",z),D.length||z)throw Error("Contexts/pre-hash are not supported");return U});function T(U,D){y0("coordinate "+U,D,U0,N)}function S(U){if(!(U instanceof C))throw Error("ExtendedPoint expected")}let F=e$((U,D)=>{let{ex:z,ey:E,ez:B}=U,L=U.is0();if(D==null)D=L?BV:Q.inv(B);let k=q(z*D),f=q(E*D),u=q(B*D);if(L)return{x:U0,y:G0};if(u!==G0)throw Error("invZ was invalid");return{x:k,y:f}}),A=e$((U)=>{let{a:D,d:z}=J;if(U.is0())throw Error("bad point: ZERO");let{ex:E,ey:B,ez:L,et:k}=U,f=q(E*E),u=q(B*B),l=q(L*L),i=q(l*l),e=q(f*D),J0=q(l*q(e+u)),q0=q(i+q(z*q(f*u)));if(J0!==q0)throw Error("bad point: equation left != right (1)");let k0=q(E*B),T0=q(L*k);if(k0!==T0)throw Error("bad point: equation left != right (2)");return!0});class C{constructor(U,D,z,E){this.ex=U,this.ey=D,this.ez=z,this.et=E,T("x",U),T("y",D),T("z",z),T("t",E),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(U){if(U instanceof C)throw Error("extended point not allowed");let{x:D,y:z}=U||{};return T("x",D),T("y",z),new C(D,z,G0,q(D*z))}static normalizeZ(U){let D=Q.invertBatch(U.map((z)=>z.ez));return U.map((z,E)=>z.toAffine(D[E])).map(C.fromAffine)}static msm(U,D){return kQ(C,K,U,D)}_setWindowSize(U){y.setWindowSize(this,U)}assertValidity(){A(this)}equals(U){S(U);let{ex:D,ey:z,ez:E}=this,{ex:B,ey:L,ez:k}=U,f=q(D*k),u=q(B*E),l=q(z*k),i=q(L*E);return f===u&&l===i}is0(){return this.equals(C.ZERO)}negate(){return new C(q(-this.ex),this.ey,this.ez,q(-this.et))}double(){let{a:U}=J,{ex:D,ey:z,ez:E}=this,B=q(D*D),L=q(z*z),k=q(T$*q(E*E)),f=q(U*B),u=D+z,l=q(q(u*u)-B-L),i=f+L,e=i-k,J0=f-L,q0=q(l*e),k0=q(i*J0),T0=q(l*J0),X$=q(e*i);return new C(q0,k0,X$,T0)}add(U){S(U);let{a:D,d:z}=J,{ex:E,ey:B,ez:L,et:k}=this,{ex:f,ey:u,ez:l,et:i}=U;if(D===BigInt(-1)){let dJ=q((B-E)*(u+f)),pJ=q((B+E)*(u-f)),g$=q(pJ-dJ);if(g$===U0)return this.double();let rJ=q(L*T$*i),cJ=q(k*T$*l),iJ=cJ+rJ,hJ=pJ+dJ,nJ=cJ-rJ,R8=q(iJ*g$),D8=q(hJ*nJ),A8=q(iJ*nJ),C8=q(g$*hJ);return new C(R8,D8,C8,A8)}let e=q(E*f),J0=q(B*u),q0=q(k*z*i),k0=q(L*l),T0=q((E+B)*(f+u)-e-J0),X$=k0-q0,uJ=k0+q0,lJ=q(J0-D*e),O8=q(T0*X$),z8=q(uJ*lJ),H8=q(T0*lJ),T8=q(X$*uJ);return new C(O8,z8,T8,H8)}subtract(U){return this.add(U.negate())}wNAF(U){return y.wNAFCached(this,U,C.normalizeZ)}multiply(U){let D=U;y0("scalar",D,G0,Z);let{p:z,f:E}=this.wNAF(D);return C.normalizeZ([z,E])[0]}multiplyUnsafe(U,D=C.ZERO){let z=U;if(y0("scalar",z,U0,Z),z===U0)return x;if(this.is0()||z===G0)return this;return y.wNAFCachedUnsafe(this,z,C.normalizeZ,D)}isSmallOrder(){return this.multiplyUnsafe(Y).is0()}isTorsionFree(){return y.unsafeLadder(this,Z).is0()}toAffine(U){return F(this,U)}clearCofactor(){let{h:U}=J;if(U===G0)return this;return this.multiplyUnsafe(U)}static fromHex(U,D=!1){let{d:z,a:E}=J,B=Q.BYTES;U=M0("pointHex",U,B),U$("zip215",D);let L=U.slice(),k=U[B-1];L[B-1]=k&-129;let f=v0(L),u=D?N:Q.ORDER;y0("pointHex.y",f,U0,u);let l=q(f*f),i=q(l-G0),e=q(z*l-E),{isValid:J0,value:q0}=O(i,e);if(!J0)throw Error("Point.fromHex: invalid y coordinate");let k0=(q0&G0)===G0,T0=(k&128)!==0;if(!D&&q0===U0&&T0)throw Error("Point.fromHex: x=0 and x_0=1");if(T0!==k0)q0=q(-q0);return C.fromAffine({x:q0,y:f})}static fromPrivateKey(U){return m(U).point}toRawBytes(){let{x:U,y:D}=this.toAffine(),z=s0(D,Q.BYTES);return z[z.length-1]|=U&G0?128:0,z}toHex(){return O$(this.toRawBytes())}}C.BASE=new C(J.Gx,J.Gy,G0,q(J.Gx*J.Gy)),C.ZERO=new C(U0,G0,G0,U0);let{BASE:P,ZERO:x}=C,y=jQ(C,G*8);function b(U){return o(U,Z)}function _(U){return b(v0(U))}function m(U){let D=Q.BYTES;U=M0("private key",U,D);let z=M0("hashed private key",I(U),2*D),E=W(z.slice(0,D)),B=z.slice(D,2*D),L=_(E),k=P.multiply(L),f=k.toRawBytes();return{head:E,prefix:B,scalar:L,point:k,pointBytes:f}}function d(U){return m(U).pointBytes}function R(U=new Uint8Array,...D){let z=t$(...D);return _(I(H(z,M0("context",U),!!V)))}function p(U,D,z={}){if(U=M0("message",U),V)U=V(U);let{prefix:E,scalar:B,pointBytes:L}=m(D),k=R(z.context,E,U),f=P.multiply(k).toRawBytes(),u=R(z.context,f,L,U),l=b(k+u*B);y0("signature.s",l,U0,Z);let i=t$(f,s0(l,Q.BYTES));return M0("result",i,Q.BYTES*2)}let r=gV;function h(U,D,z,E=r){let{context:B,zip215:L}=E,k=Q.BYTES;if(U=M0("signature",U,2*k),D=M0("message",D),z=M0("publicKey",z,k),L!==void 0)U$("zip215",L);if(V)D=V(D);let f=v0(U.slice(k,2*k)),u,l,i;try{u=C.fromHex(z,L),l=C.fromHex(U.slice(0,k),L),i=P.multiplyUnsafe(f)}catch(q0){return!1}if(!L&&u.isSmallOrder())return!1;let e=R(B,l.toRawBytes(),u.toRawBytes(),D);return l.add(u.multiplyUnsafe(e)).subtract(i).clearCofactor().equals(C.ZERO)}return P._setWindowSize(8),{CURVE:J,getPublicKey:d,sign:p,verify:h,ExtendedPoint:C,utils:{getExtendedPublicKey:m,randomPrivateKey:()=>X(Q.BYTES),precompute(U=8,D=C.BASE){return D._setWindowSize(U),D.multiply(BigInt(3)),D}}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var XJ=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),BQ=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),OY=BigInt(0),fV=BigInt(1),gQ=BigInt(2),zY=BigInt(3),xV=BigInt(5),mV=BigInt(8);function vV($){let J=BigInt(10),Q=BigInt(20),Z=BigInt(40),V=BigInt(80),I=XJ,G=$*$%I*$%I,Y=W0(G,gQ,I)*G%I,N=W0(Y,fV,I)*$%I,q=W0(N,xV,I)*N%I,K=W0(q,J,I)*q%I,O=W0(K,Q,I)*K%I,W=W0(O,Z,I)*O%I,H=W0(W,V,I)*W%I,T=W0(H,V,I)*W%I,S=W0(T,J,I)*q%I;return{pow_p_5_8:W0(S,gQ,I)*$%I,b2:G}}function yV($){return $[0]&=248,$[31]&=127,$[31]|=64,$}function bV($,J){let Q=XJ,Z=o(J*J*J,Q),V=o(Z*Z*J,Q),I=vV($*V).pow_p_5_8,X=o($*Z*I,Q),G=o(J*X*X,Q),Y=X,N=o(X*BQ,Q),q=G===$,K=G===o(-$,Q),O=G===o(-$*BQ,Q);if(q)X=Y;if(K||O)X=N;if(CQ(X,Q))X=o(-X,Q);return{isValid:q||K,value:X}}var uV=(()=>z$(XJ,void 0,!0))(),lV=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:uV,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:mV,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:KQ,randomBytes:GQ,adjustScalarBytes:yV,uvRatio:bV}))(),R$=(()=>LQ(lV))();/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function dV($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function t0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function f0($,...J){if(!dV($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function e0($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function D$($,J){f0($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}function _Q($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function u0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function l0(...$){for(let J=0;J<$.length;J++)$[J].fill(0)}function $$($,J){return $<<32-J|$>>>J}var fQ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function xQ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var mQ=fQ?($)=>$:($)=>xQ($);function pV($){for(let J=0;J<$.length;J++)$[J]=xQ($[J]);return $}var Y0=fQ?($)=>$:pV;function rV($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function d0($){if(typeof $==="string")$=rV($);return f0($),$}class YJ{}function vQ($){let J=(Z,V)=>$(V).update(d0(Z)).digest(),Q=$({});return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=(Z)=>$(Z),J}var yQ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var A$=BigInt(4294967295),bQ=BigInt(32);function GJ($,J=!1){if(J)return{h:Number($&A$),l:Number($>>bQ&A$)};return{h:Number($>>bQ&A$)|0,l:Number($&A$)|0}}function P0($,J,Q,Z,V){return $=$+J+V|0,Z=$$(Z^$,16),Q=Q+Z|0,J=$$(J^Q,12),{a:$,b:J,c:Q,d:Z}}function S0($,J,Q,Z,V){return $=$+J+V|0,Z=$$(Z^$,8),Q=Q+Z|0,J=$$(J^Q,7),{a:$,b:J,c:Q,d:Z}}class qJ extends YJ{constructor($,J){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,t0($),t0(J),this.blockLen=$,this.outputLen=J,this.buffer=new Uint8Array($),this.buffer32=u0(this.buffer)}update($){e0(this),$=d0($),f0($);let{blockLen:J,buffer:Q,buffer32:Z}=this,V=$.length,I=$.byteOffset,X=$.buffer;for(let G=0;G<V;){if(this.pos===J)Y0(Z),this.compress(Z,0,!1),Y0(Z),this.pos=0;let Y=Math.min(J-this.pos,V-G),N=I+G;if(Y===J&&!(N%4)&&G+Y<V){let q=new Uint32Array(X,N,Math.floor((V-G)/4));Y0(q);for(let K=0;G+J<V;K+=Z.length,G+=J)this.length+=J,this.compress(q,K,!1);Y0(q);continue}Q.set($.subarray(G,G+Y),this.pos),this.pos+=Y,this.length+=Y,G+=Y}return this}digestInto($){e0(this),D$($,this);let{pos:J,buffer32:Q}=this;this.finished=!0,l0(this.buffer.subarray(J)),Y0(Q),this.compress(Q,0,!0),Y0(Q);let Z=u0($);this.get().forEach((V,I)=>Z[I]=mQ(V))}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}_cloneInto($){let{buffer:J,length:Q,finished:Z,destroyed:V,outputLen:I,pos:X}=this;return $||($=new this.constructor({dkLen:I})),$.set(...this.get()),$.buffer.set(J),$.destroyed=V,$.finished=Z,$.length=Q,$.pos=X,$.outputLen=I,$}clone(){return this._cloneInto()}}function NJ($,J,Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T,S,F,A,C){let P=0;for(let x=0;x<Z;x++)({a:V,b:Y,c:O,d:S}=P0(V,Y,O,S,Q[J+$[P++]])),{a:V,b:Y,c:O,d:S}=S0(V,Y,O,S,Q[J+$[P++]]),{a:I,b:N,c:W,d:F}=P0(I,N,W,F,Q[J+$[P++]]),{a:I,b:N,c:W,d:F}=S0(I,N,W,F,Q[J+$[P++]]),{a:X,b:q,c:H,d:A}=P0(X,q,H,A,Q[J+$[P++]]),{a:X,b:q,c:H,d:A}=S0(X,q,H,A,Q[J+$[P++]]),{a:G,b:K,c:T,d:C}=P0(G,K,T,C,Q[J+$[P++]]),{a:G,b:K,c:T,d:C}=S0(G,K,T,C,Q[J+$[P++]]),{a:V,b:N,c:H,d:C}=P0(V,N,H,C,Q[J+$[P++]]),{a:V,b:N,c:H,d:C}=S0(V,N,H,C,Q[J+$[P++]]),{a:I,b:q,c:T,d:S}=P0(I,q,T,S,Q[J+$[P++]]),{a:I,b:q,c:T,d:S}=S0(I,q,T,S,Q[J+$[P++]]),{a:X,b:K,c:O,d:F}=P0(X,K,O,F,Q[J+$[P++]]),{a:X,b:K,c:O,d:F}=S0(X,K,O,F,Q[J+$[P++]]),{a:G,b:Y,c:W,d:A}=P0(G,Y,W,A,Q[J+$[P++]]),{a:G,b:Y,c:W,d:A}=S0(G,Y,W,A,Q[J+$[P++]]);return{v0:V,v1:I,v2:X,v3:G,v4:Y,v5:N,v6:q,v7:K,v8:O,v9:W,v10:H,v11:T,v12:S,v13:F,v14:A,v15:C}}var H0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},w0=yQ.slice(),uQ=(()=>{let $=Array.from({length:16},(Z,V)=>V),J=(Z)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Z[V]),Q=[];for(let Z=0,V=$;Z<7;Z++,V=J(V))Q.push(...V);return Uint8Array.from(Q)})();class KJ extends qJ{constructor($={},J=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:Q,context:Z}=$,V=Z!==void 0;if(Q!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let I=d0(Q).slice();f0(I,32),this.IV=u0(I),Y0(this.IV),this.flags=J|H0.KEYED_HASH}else if(V){let I=d0(Z),X=new KJ({dkLen:32},H0.DERIVE_KEY_CONTEXT).update(I).digest();this.IV=u0(X),Y0(this.IV),this.flags=J|H0.DERIVE_KEY_MATERIAL}else this.IV=w0.slice(),this.flags=J;this.state=this.IV.slice(),this.bufferOut=_Q(this.bufferOut32)}get(){return[]}set(){}b2Compress($,J,Q,Z=0){let{state:V,pos:I}=this,{h:X,l:G}=GJ(BigInt($),!0),{v0:Y,v1:N,v2:q,v3:K,v4:O,v5:W,v6:H,v7:T,v8:S,v9:F,v10:A,v11:C,v12:P,v13:x,v14:y,v15:b}=NJ(uQ,Z,Q,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],w0[0],w0[1],w0[2],w0[3],X,G,I,J);V[0]=Y^S,V[1]=N^F,V[2]=q^A,V[3]=K^C,V[4]=O^P,V[5]=W^x,V[6]=H^y,V[7]=T^b}compress($,J=0,Q=!1){let Z=this.flags;if(!this.chunkPos)Z|=H0.CHUNK_START;if(this.chunkPos===15||Q)Z|=H0.CHUNK_END;if(!Q)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Z,$,J),this.chunkPos+=1,this.chunkPos===16||Q){let V=this.state;this.state=this.IV.slice();for(let I,X=this.chunksDone+1;Q||!(X&1);X>>=1){if(!(I=this.stack.pop()))break;this.buffer32.set(I,0),this.buffer32.set(V,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|H0.PARENT,this.buffer32,0),V=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(V)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:J,flags:Q,state:Z,chunkPos:V,posOut:I,chunkOut:X,stack:G,chunksDone:Y}=this;return $.state.set(Z.slice()),$.stack=G.map((N)=>Uint32Array.from(N)),$.IV.set(J),$.flags=Q,$.chunkPos=V,$.chunksDone=Y,$.posOut=I,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,l0(this.state,this.buffer32,this.IV,this.bufferOut32),l0(...this.stack)}b2CompressOut(){let{state:$,pos:J,flags:Q,buffer32:Z,bufferOut32:V}=this,{h:I,l:X}=GJ(BigInt(this.chunkOut++));Y0(Z);let{v0:G,v1:Y,v2:N,v3:q,v4:K,v5:O,v6:W,v7:H,v8:T,v9:S,v10:F,v11:A,v12:C,v13:P,v14:x,v15:y}=NJ(uQ,0,Z,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],w0[0],w0[1],w0[2],w0[3],X,I,J,Q);V[0]=G^T,V[1]=Y^S,V[2]=N^F,V[3]=q^A,V[4]=K^C,V[5]=O^P,V[6]=W^x,V[7]=H^y,V[8]=$[0]^T,V[9]=$[1]^S,V[10]=$[2]^F,V[11]=$[3]^A,V[12]=$[4]^C,V[13]=$[5]^P,V[14]=$[6]^x,V[15]=$[7]^y,Y0(Z),Y0(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,l0(this.buffer.subarray(this.pos));let $=this.flags|H0.ROOT;if(this.stack.length)$|=H0.PARENT,Y0(this.buffer32),this.compress(this.buffer32,0,!0),Y0(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?H0.CHUNK_START:0)|H0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){e0(this,!1),f0($),this.finish();let{blockLen:J,bufferOut:Q}=this;for(let Z=0,V=$.length;Z<V;){if(this.posOut>=J)this.b2CompressOut();let I=Math.min(J-this.posOut,V-Z);$.set(Q.subarray(this.posOut,this.posOut+I),Z),this.posOut+=I,Z+=I}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return t0($),this.xofInto(new Uint8Array($))}digestInto($){if(D$($,this),this.finished)throw Error("digest() was already called");return this.enableXOF=!1,this.writeInto($),this.destroy(),$}digest(){return this.digestInto(new Uint8Array(this.outputLen))}}var lQ=vQ(($)=>new KJ($));class MJ{async genRandomBytes($){return N$($)}async gen256BitSecureRandomSeed(){return N$(32)}async encryptXSalsa20Poly1305Combined($,J){let Q=N$(24),V=u$(J,Q).encrypt($);return new Uint8Array([...Q,...V])}async decryptXSalsa20Poly1305Combined($,J){let Q=$.slice(0,24),Z=$.slice(24);return u$(J,Q).decrypt(Z)}async deriveEd25519KeyPair($){let J=$,Q=R$.getPublicKey(J),Z=new Uint8Array(64);return Z.set(J,0),Z.set(Q,32),{keyType:"ed25519",privateKey:Z,publicKey:Q}}async signEd25519($,J){let Q=typeof $==="string"?new TextEncoder().encode($):$,Z=J.slice(0,32);return R$.sign(Q,Z)}async checkSigEd25519($,J,Q){let Z=typeof J==="string"?new TextEncoder().encode(J):J;return R$.verify($,Z,Q)}async blake3($){return lQ($)}}var cV=new MJ,x0=cV;var p0=64;var dQ=32,r0=8;var pQ=32;var rQ=30000,cQ=512,v;((R)=>{R[R.Success=0]="Success";R[R.InvalidSignature=3]="InvalidSignature";R[R.ClockOutOfSync=4]="ClockOutOfSync";R[R.UserNotRegistered=5]="UserNotRegistered";R[R.ServerMisconfigured=6]="ServerMisconfigured";R[R.MissingBody=7]="MissingBody";R[R.ExtraBodyContent=8]="ExtraBodyContent";R[R.MissingParam=9]="MissingParam";R[R.InvalidParam=10]="InvalidParam";R[R.InvalidRequest=11]="InvalidRequest";R[R.InternalError=12]="InternalError";R[R.NotFound=13]="NotFound";R[R.InvalidMessage=14]="InvalidMessage";R[R.NoChange=15]="NoChange";R[R.DatabaseClosed=16]="DatabaseClosed";R[R.StorageError=17]="StorageError";R[R.DatabaseError=18]="DatabaseError";R[R.HashMismatch=19]="HashMismatch";R[R.DecryptionError=20]="DecryptionError";R[R.NotImplemented=21]="NotImplemented";R[R.MissingSeed=22]="MissingSeed";R[R.OutOfBounds=23]="OutOfBounds";R[R.HostError=24]="HostError";R[R.CommunicationError=25]="CommunicationError";R[R.VarLimitExceeded=26]="VarLimitExceeded";R[R.InvalidResponse=27]="InvalidResponse";R[R.ConnectionClosed=28]="ConnectionClosed"})(v||={});var iQ="t";function j($){return[$,0]}function M($){return[void 0,$]}function iV($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return M(10);let J=[];while($>0n){let Q=Number($&0x7fn);if($>>=7n,$>0n)J.push(Q|128);else J.push(Q)}if(J.length===0)return j(new Uint8Array([0]));if(J.length>8)return M(26);return j(new Uint8Array(J))}function hV($,J=0){let Q=0n,Z=0,V=J;while(!0){if(V>=$.length)return M(14);let I=$[V++];if(I===void 0)return M(14);if(Q|=BigInt(I&127)<<BigInt(Z),(I&128)===0){if(V-J>8)return M(26);return j({value:Q>0x1fffffffffffffn?Q:Number(Q),bytesRead:V-J})}if(Z+=7,Z>=56)return M(26)}}class I0{data;pos=0;constructor($){this.data=$}static async fromResponse($){let J=await $.arrayBuffer(),Q=new Uint8Array(J);return new I0(Q)}readBigInt(){if(this.pos+8>this.data.length)return M(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,j($)}readDate(){let[$,J]=this.readVarInt();if(J!==0)return M(J);return j(new Date($))}readVarInt(){let[$,J]=hV(this.data,this.pos);if(J!==0)return M(J);this.pos+=$.bytesRead;let Q=$.value;return j(typeof Q==="bigint"?Number(Q):Q)}readVarString(){let[$,J]=this.readVarInt();if(J!==0)return M(J);let[Q,Z]=this.readBytes($);if(Z!==0)return M(Z);let V=new TextDecoder().decode(Q);return j(V)}readBytes($){if($<0)return M(10);if(this.pos+$>this.data.length)return M(23);let J=this.data.slice(this.pos,this.pos+$);return this.pos+=$,j(J)}readVarBytes(){let[$,J]=this.readVarInt();if(J!==0)return M(J);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let J=[];while(!this.done()){let[Q,Z]=this.readStruct($);if(Z!==0)return M(Z);J.push(Q)}return j(J)}readBytesSeq($){let J=[];while(!this.done()){let[Q,Z]=this.readBytes($);if(Z!==0)return M(Z);J.push(Q)}return j(J)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class c{parts=[];writeBigInt($){let J=new Uint8Array(8);new DataView(J.buffer).setBigUint64(0,$,!1),this.parts.push(J)}writeDate($){let J=$.getTime();return this.writeVarInt(J)}writeVarInt($){let[J,Q]=iV($);if(Q!==0)return Q;return this.parts.push(J),0}writeVarString($){let J=new TextEncoder().encode($),Q=this.writeVarInt(J.length);if(Q!==0)return Q;return this.writeBytes(J),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let J=this.writeVarInt($.length);if(J!==0)return J;return this.writeBytes($),0}writeStruct($,J){return $.encode(this,J)}writeStructs($,J){for(let Q of J){let Z=this.writeStruct($,Q);if(Z!==0)return Z}return 0}writeBytesSeq($){for(let J of $)this.writeBytes(J)}result(){let $=this.parts.reduce((Z,V)=>Z+V.length,0),J=new Uint8Array($),Q=0;for(let Z of this.parts)J.set(Z,Q),Q+=Z.length;return J}*scan(){for(let $ of this.parts)yield $}}var J$={encode($,J){let Q=$.writeVarBytes(J.id);if(Q!==0)return Q;let Z=$.writeDate(J.ts);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return M(Q);let[Z,V]=$.readDate();if(V!==0)return M(V);return j({id:J,ts:Z})}};function hQ($){let J=new c,Q=J.writeStruct(J$,$);if(Q!==0)return M(Q);let Z=J.result();return j(Z)}var WJ={encode($,J){let Q=$.writeVarBytes(J.eid);if(Q!==0)return Q;let Z=$.writeVarInt(J.off);if(Z!==0)return Z;let V=$.writeVarInt(J.ctr);if(V!==0)return V;let I=$.writeVarInt(J.len);if(I!==0)return I;if(J.hsh)$.writeBytes(J.hsh);return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return M(Q);let Z=new I0(J),[,V]=J$.decode(Z);if(V!==0)return M(V);let[I,X]=$.readVarInt();if(X!==0)return M(X);let[G,Y]=$.readVarInt();if(Y!==0)return M(Y);let[N,q]=$.readVarInt();if(q!==0)return M(q);let K;if(N>0){let[O,W]=$.readBytes(pQ);if(W!==0)return M(W);K=O}return j({eid:J,off:I,ctr:G,len:N,hsh:K})}};function O0($){return Array.from($).map((Q)=>Q.toString(16).padStart(2,"0")).join("")}function C$($){if($.length%2!==0)throw Error("Invalid hex string");let J=new Uint8Array($.length/2);for(let Q=0;Q<$.length;Q+=2)J[Q/2]=Number.parseInt($.substr(Q,2),16);return J}function aQ($,J){if($===J)return!0;if($.byteLength!==J.byteLength)return!1;return $.every((Q,Z)=>Q===J[Z])}var nQ;if(typeof Uint8Array.prototype.toBase64==="function")nQ=($)=>$.toBase64();else nQ=($)=>btoa(String.fromCharCode(...$));var oQ;if(typeof Uint8Array.fromBase64==="function")oQ=($)=>Uint8Array.fromBase64($);else oQ=($)=>Uint8Array.from(atob($),(J)=>J.charCodeAt(0));function Q$($,J){let Q=new Uint8Array($.length+J.length);return Q.set($,0),Q.set(J,$.length),Q}function sQ($,J,Q){return Q.checkSigEd25519($.sig,$.headCph,J)}async function nV($,J,Q){let Z=Q$(J.privateKey,$);return(await Q.blake3(Z)).slice(0,r0)}async function tQ($,J,Q,Z){let V;if($.bod&&$.len>0)V=await Q.blake3($.bod);let I=new c,X=WJ.encode(I,{...$,hsh:V});if(X!==0)return M(X);let G=I.result(),Y=await nV(G,J,Q),N=await Z.deriveFromKDM(Y),q=await Q.encryptXSalsa20Poly1305Combined(G,N),K=$.bod?await Q.encryptXSalsa20Poly1305Combined($.bod,N):new Uint8Array(0),O=await Q.signEd25519(q,J.privateKey);return j({sig:O,kdm:Y,headCph:q,bodyCph:K})}async function eQ($,J,Q,Z){let V=new I0($),[I,X]=WJ.decode(V);if(X!==0)return M(14);let G;try{G=J&&J.length>0?await Z.decryptXSalsa20Poly1305Combined(J,Q):void 0}catch{return M(20)}let Y=I.hsh&&G===void 0,N=I.hsh===void 0&&G!==void 0;if(Y||N)return M(19);if(I.hsh&&G){let K=await Z.blake3(G);if(!aQ(K,I.hsh))return M(19)}let q=await Z.blake3($);return j({msgHead:I,bod:G,headHash:q})}async function UJ($,J,Q){let Z=new c,V=Z.writeDate(J);if(V!==0)return M(V);let I=Z.result(),X=await Q.signEd25519(I,$.privateKey);return j({pubKey:$.publicKey,sig:X,timestamp:J})}async function K0($,J,Q){let Z=Q.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Z-V)>rQ)return 4;let X=new c;X.writeDate($.timestamp);let G=X.result();if(!await J.checkSigEd25519($.sig,G,$.pubKey))return 3;return 0}class c0{now(){return new Date}}function $Z($,J,Q,Z){let V=J.getTime()-$.getTime(),I=Q.getTime()-Z.getTime();return(V+I)/2}var Z$={encode($,J){if($.writeVarInt(J.quota),J.quota>0){if(J.usage===void 0)return 9;$.writeVarInt(J.usage)}return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let Z;if(J>0){let[V,I]=$.readVarInt();if(I!==0)return M(I);Z=V}return j({quota:J,usage:Z})}};var i0={encode($,J){$.writeBytes(new Uint8Array([J.status]));let Q=$.writeDate(J.timeRcvd);if(Q!==0)return Q;let Z=$.writeDate(J.timeSent);if(Z!==0)return Z;let V=$.writeVarInt(J.subscription.term);if(V!==0)return V;let I=$.writeVarInt(J.subscription.elapsed);if(I!==0)return I;let X=$.writeStruct(Z$,J.subscription.stat);if(X!==0)return X;let G=$.writeStruct(Z$,J.subscription.dyn);if(G!==0)return G;return 0},decode($){let[J,Q]=$.readBytes(1);if(Q!==0)return M(Q);let Z=J[0],[V,I]=$.readDate();if(I!==0)return M(I);let[X,G]=$.readDate();if(G!==0)return M(G);let[Y,N]=$.readVarInt();if(N!==0)return M(N);let[q,K]=$.readVarInt();if(K!==0)return M(K);let[O,W]=$.readStruct(Z$);if(W!==0)return M(W);let[H,T]=$.readStruct(Z$);if(T!==0)return M(T);return j({status:Z,timeRcvd:V,timeSent:X,subscription:{term:Y,elapsed:q,stat:O,dyn:H}})}};async function OJ($,J,Q){let{crypto:Z,enclave:V}=$,I=await V.derive(J,Q);return await Z.deriveEd25519KeyPair(I)}var zJ={encode($,J){let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;let Z=$.writeVarInt(J.seq);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return M(Q);let[Z,V]=$.readVarInt();if(V!==0)return M(V);return j({headCph:J,seq:Z})}};var X0={encode($,J){$.writeBytes(J.pubKey),$.writeBytes(J.sig);let Q=$.writeDate(J.timestamp);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readBytes(dQ);if(Q!==0)return M(Q);let[Z,V]=$.readBytes(p0);if(V!==0)return M(V);let[I,X]=$.readDate();if(X!==0)return M(X);return j({pubKey:J,sig:Z,timestamp:I})}};var JZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;for(let X of Z)V.writeVarInt(X);return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await K0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X,[q,K]=await I.hasUser(N);if(K!==0)return K;if(!q)return 5;let[O,W]=J.readVarInt();if(W!==0)return W;if(!J.done())return 8;let[H,T]=await I.listHeads(N,O);if(T!==0)return T;return Q.writeStructs(zJ,H)},decodeResp($){return $.readStructs(zJ)}};var HJ={encode($,J){$.writeVarInt(J.seq);let Q=$.writeVarBytes(J.bodyCph);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let[Z,V]=$.readVarBytes();if(V!==0)return M(V);return j({seq:J,bodyCph:Z})}};var QZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;for(let X of Z){let G=V.writeVarInt(X);if(G!==0)return G}return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await K0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X,[q,K]=await I.hasUser(N);if(K!==0)return K;if(!q)return 5;let O=[];while(!J.done()){let[T,S]=J.readVarInt();if(S!==0)return S;O.push(T)}console.info(`PULL: ${O.length} bags`);let[W,H]=await I.getBodies(N,O);if(H!==0)return H;if(!W)return 17;for(let{seq:T,bodyCph:S}of W){let F={seq:T,bodyCph:S},A=Q.writeStruct(HJ,F);if(A!==0)return A}return 0},decodeResp($){return $.readStructs(HJ)}};var TJ={encode($,J){$.writeBytes(J.sig),$.writeBytes(J.kdm);let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;let Z=$.writeVarBytes(J.bodyCph);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readBytes(p0);if(Q!==0)return M(Q);let[Z,V]=$.readBytes(r0);if(V!==0)return M(V);let[I,X]=$.readVarBytes();if(X!==0)return M(X);let[G,Y]=$.readVarBytes();if(Y!==0)return M(Y);return j({sig:J,kdm:Z,headCph:I,bodyCph:G})}};var RJ={encode($,J){let Q=$.writeVarInt(J.seq);if(Q!==0)return Q;let Z=$.writeVarBytes(J.headCph);if(Z!==0)return Z;let V=J.bodyCph?J.bodyCph.length:0,I=$.writeVarInt(V);if(I!==0)return I;if(V>0){if(!J.bodyCph)return 10;$.writeBytes(J.bodyCph)}return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let[Z,V]=$.readVarBytes();if(V!==0)return M(V);let[I,X]=$.readVarInt();if(X!==0)return M(X);let G;if(I>0){let[Y,N]=$.readBytes(I);if(N!==0)return M(N);G=Y}return j({seq:J,headCph:Z,bodyCph:G})}};var h0={encode($,J){$.writeBytes(J.sig),$.writeBytes(J.kdm);let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readBytes(p0);if(Q!==0)return M(Q);let[Z,V]=$.readBytes(r0);if(V!==0)return M(V);let[I,X]=$.readVarBytes();if(X!==0)return M(X);return j({sig:J,kdm:Z,headCph:I})}};var P$={encode($,J){if($.writeVarInt(J.idx),$.writeBytes(new Uint8Array([J.status])),J.status===0)$.writeVarInt(J.seq);return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let[Z,V]=$.readBytes(1);if(V!==0)return M(V);let I=Z[0];if(I!==0)return j({idx:J,status:I});let[X,G]=$.readVarInt();if(G!==0)return M(G);return j({idx:J,status:I,seq:X})}};var ZZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;let X=V.writeStructs(TJ,Z);if(X!==0)return X;return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I,notifier:X}=$,[G,Y]=J.readStruct(X0);if(Y!==0)return Y;let N=await K0(G,V,Z);if(N!==0)return N;let{pubKey:q}=G,[K,O]=await I.hasUser(q);if(O!==0)return O;if(!K)return 5;let[W,H]=J.readStructs(TJ);if(H!==0)return H;console.info(`PUSH: ${W.length} bags`);let T=[],S=[];for(let P=0;P<W.length;P++){let x=W[P];if(!await sQ(x,q,V)){let b={idx:P,status:3},_=Q.writeStruct(P$,b);if(_!==0)return _;continue}T.push(P),S.push(x)}let[F,A]=await I.setBags(q,S);if(A!==0)return A;if(!F||F.length!==S.length)return 17;let C=[];for(let P=0;P<S.length;P++){let x=S[P],y=T[P],b=F[P],_=new c,m=_.writeStruct(h0,x);if(m!==0)return m;let d=_.result(),R={seq:b,headCph:d};if(W.length===1&&x.bodyCph.length<=cQ)R.bodyCph=x.bodyCph;C.push(R);let p={idx:y,status:0,seq:b},r=Q.writeStruct(P$,p);if(r!==0)return r}if(C.length>0){let P=new c,x=P.writeStructs(RJ,C);if(x!==0)return x;let y=P.result();await Promise.resolve(X.push(q,y))}return 0},decodeResp($){return $.readStructs(P$)}};var VZ={async encodeReq($,J,Q,Z,V){return V.writeStruct(X0,Q)},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await K0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X;if(!J.done())return 8;let[q,K]=await I.addUser(N);if(K!==0)return K;return 0},decodeResp($){return j(void 0)}};class DJ{url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,J,Q=()=>{},Z=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let I=new c;I.writeStruct(X0,$);let X=I.result(),G=O0(X);return V.searchParams.set("t",G),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Z()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,Q()},this.websocket.onmessage=(Y)=>{let N=new Uint8Array(Y.data);J(N)},this.websocket.onerror=(Y)=>{console.log(`ERROR: ${JSON.stringify(Y)}`),this.websocket=void 0,Q()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var Z0={user:{path:"/user",endpoint:VZ,name:0},push:{path:"/push",endpoint:ZZ,name:2},peek:{path:"/peek",endpoint:JZ,name:1},pull:{path:"/pull",endpoint:QZ,name:3}},oV={0:Z0.user,2:Z0.push,1:Z0.peek,3:Z0.pull},IZ={[Z0.user.path]:Z0.user,[Z0.push.path]:Z0.push,[Z0.peek.path]:Z0.peek,[Z0.pull.path]:Z0.pull};class XZ{url;listener;constructor($){this.url=$;this.listener=new DJ($)}async call($,J){let{path:Q}=oV[$],Z=new URL(Q,this.url);try{return await sV(Z,J)}catch{return M(25)}}}var AJ=($)=>{return new XZ($.handle)};function n0($){let J=new c;if(J.writeStruct(i0,$)!==0)return new Response(null,{status:500});return CJ(J)}function CJ($){let J=$.result().slice();return new Response(J,{status:200,headers:{"content-type":"application/octet-stream"}})}var aV={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function PJ($){return new Response($.body,{headers:{...$.headers,...aV},status:$.status,statusText:$.statusText})}async function sV($,J){let Q=await fetch($,{method:"POST",body:J.result().slice()});if(!Q.ok)return M(24);let Z=await I0.fromResponse(Q);return j(Z)}class S${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,J,Q,Z,V,I){this.enclave=$;this.crypto=J;this.host=Q;this.clock=Z;this.transport=V;this.updateHostMeta=I}async call($,J){let{clock:Q,crypto:Z,transport:V}=this,{endpoint:I,name:X}=$,G=await this.keys(),Y=Q.now(),[N,q]=await UJ(G,Y,Z);if(q!==0)return M(q);let K=new c,O=await I.encodeReq(this,G,N,J,K);if(O!==0)return M(O);let W=Q.now(),[H,T]=await V.call(X,K),S=Q.now();if(T!==0)return M(T);let[F,A]=H.readStruct(i0);if(A!==0)return M(A);if(F.status!==0)return M(F.status);let P={clockOffset:$Z(W,F.timeRcvd,F.timeSent,S),subscription:F.subscription},x=await this.updateHostMeta(P);if(x!==0)return M(x);return I.decodeResp(H)}keys=()=>{let{host:$}=this;return OJ(this,$.label,$.idx)};seal=async($)=>{let{crypto:J,enclave:Q}=this,Z=await this.keys();return tQ($,Z,J,Q)};register=()=>this.call(Z0.user,[]);peek=($)=>this.call(Z0.peek,[$]);push=($)=>this.call(Z0.push,$);pull=($)=>this.call(Z0.pull,$);listen=async($,J,Q)=>{let{clock:Z,crypto:V,host:I,transport:X}=this,{listener:G}=X,Y=await OJ(this,I.label,I.idx),N=Z.now(),[q,K]=await UJ(Y,N,V);if(K!==0)return K;return await G.connect(q,$,J,Q)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class SJ{seed;crypto;constructor($,J){this.seed=$,this.crypto=J}async deriveFromKDM($){let J=Q$(this.seed,$);return await this.crypto.blake3(J)}async derive($,J=0){let Q=new TextEncoder().encode($),Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,BigInt(J),!1);let V=Q$(Q,Z);return await this.deriveFromKDM(V)}}class wJ{listeners=new Map;addEventListener($,J){let Q=this.listeners.get($);if(!Q)Q=new Set,this.listeners.set($,Q);return Q.add(J),()=>{this.removeEventListener($,J)}}removeEventListener($,J){let Q=this.listeners.get($);if(Q){if(Q.delete(J),Q.size===0)this.listeners.delete($)}}emit($,J){let Q=this.listeners.get($);if(Q){let Z=Array.from(Q);for(let V of Z)V(J)}}emitAll($){let J=Array.from(this.listeners.keys());for(let Q of J)this.emit(Q,$)}}async function YZ($,J,Q,Z=0){let V=J.now(),I=new c,X=I.writeVarString($);if(X!==0)return M(X);let Y={id:I.result(),ts:new Date(0)},[N,q]=hQ(Y);if(q!==0)return M(q);let K=V.getTime()-Y.ts.getTime();return j({eid:N,off:K,ctr:Z,len:Q.length,bod:Q})}class tV{singletonType;latest;latestOff=-1;emitter=new wJ;constructor($){this.singletonType=$}async apply($){for(let J of $){let Q=new I0(J.eid),[Z,V]=Q.readStruct(J$);if(V!==0)continue;let I=new c;I.writeVarString(this.singletonType);let X=I.result();if(Z.id.length===X.length&&Z.id.every((G,Y)=>G===X[Y])){if(this.latest===void 0||J.off>this.latestOff)this.latestOff=J.off,this.latest=J.bod,this.emitter.emit(this.singletonType,null)}}return $.map(()=>0)}clear=async()=>{return this.latest=void 0,this.latestOff=-1,this.emitter.emit(this.singletonType,null),0};notify=($)=>{for(let J of $)if(J===this.singletonType)this.emitter.emit(this.singletonType,null)};on=($,J)=>{this.emitter.addEventListener($,J)};off=($,J)=>{this.emitter.removeEventListener($,J)}}async function GZ($,J,Q,Z){let V=new I0($.headCph),[I,X]=V.readStruct(h0);if(X!==0)return M(X);let{sig:G,kdm:Y,headCph:N}=I;if(!await Z.checkSigEd25519(G,N,J.publicKey))return M(3);let K=await Q.deriveFromKDM(Y),O;try{O=await Z.decryptXSalsa20Poly1305Combined(N,K)}catch{return M(20)}return j({kdm:Y,headEnc:O})}var a0=L8(q8(),1),HX={encode:a0.encode,decode:a0.decode,decodeAsync:a0.decodeAsync},TX=HX;import{Database as RX}from"bun:sqlite";var sN=Symbol("EntityID");var tN=Symbol("MasterSeed"),eN=Symbol("DerivationSeed"),$K=Symbol("PublicKey"),JK=Symbol("PrivateKey"),QK=Symbol("HostSpecificKeyPair"),ZK=Symbol("Hash"),j0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};var N0=new RX("diplomatic.db");N0.exec("PRAGMA journal_mode=WAL;");N0.exec("PRAGMA synchronous=NORMAL;");N0.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS users (
|
|
3
3
|
pubKey TEXT PRIMARY KEY
|
|
4
4
|
);
|
|
5
|
-
`);
|
|
5
|
+
`);N0.exec(`
|
|
6
6
|
CREATE TABLE IF NOT EXISTS bags (
|
|
7
7
|
userPubKey TEXT,
|
|
8
8
|
seq INTEGER,
|
|
@@ -11,4 +11,4 @@ var P8=Object.create;var{getPrototypeOf:S8,defineProperty:oJ,getOwnPropertyNames
|
|
|
11
11
|
PRIMARY KEY (userPubKey, seq),
|
|
12
12
|
UNIQUE (userPubKey, seq)
|
|
13
13
|
);
|
|
14
|
-
`);var DX={async addUser($){try{let J=
|
|
14
|
+
`);var DX={async addUser($){try{let J=O0($);return N0.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[J]),j(void 0)}catch{return M(17)}},async hasUser($){try{let J=O0($),Q=N0.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?)").get(J),Z=Q?Q["EXISTS (SELECT 1 FROM users WHERE pubKey = ?)"]:!1;return j(Boolean(Z))}catch{return M(17)}},async subMeta($){return j(j0)},async setBags($,J){if(J.length<1)return j([]);try{let Q=O0($);N0.exec("BEGIN IMMEDIATE");try{let Z=N0.prepare("SELECT MAX(seq) FROM bags WHERE userPubKey = ?").get(Q),V=Z?Z["MAX(seq)"]||0:0,I=[],X=N0.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let G of J){V+=1;let Y=new c;Y.writeStruct(h0,G),X.run(Q,V,Y.result(),G.bodyCph),I.push(V)}return N0.exec("COMMIT"),j(I)}catch(Z){try{N0.exec("ROLLBACK")}catch{}throw Z}}catch{return M(17)}},async getBodies($,J){if(J.length<1)return j([]);try{let Q=O0($),Z=[],V=100,I=99;for(let X=0;X<J.length;X+=99){let G=J.slice(X,X+99),Y=G.map(()=>"?").join(","),N=N0.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${Y})`).all(Q,...G);for(let q of N)if(q.bodyCph)Z.push({seq:q.seq,bodyCph:new Uint8Array(q.bodyCph)})}return j(Z)}catch{return M(17)}},async listHeads($,J){try{let Q=O0($),Z=N0.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(Q,J);return j(Z.map((V)=>({seq:V.seq,headCph:new Uint8Array(V.headCph)})))}catch{return M(17)}}},N8=DX;class bJ{storage;crypto;notifier;clock;constructor($,J,Q,Z){this.storage=$;this.crypto=J;this.notifier=Q;this.clock=Z}corsHandler=async($)=>{if($.method==="OPTIONS")return PJ(new Response(null));let J=`${$.method} ${$.url}`;console.time(J);let Q=await this.handler($);return console.timeEnd(J),PJ(Q)};handler=async($)=>{let{clock:J}=this,Q=J.now(),Z=new URL($.url);if($.method!=="POST"){let N=J.now();return n0({status:13,timeRcvd:Q,timeSent:N,subscription:j0})}if(!$.body){let N=J.now();return n0({status:7,timeRcvd:Q,timeSent:N,subscription:j0})}let I=new Uint8Array(await $.arrayBuffer()),X=new I0(I),G=Z.pathname,Y=IZ[G]?.endpoint;if(!Y){let N=J.now();return n0({status:13,timeRcvd:Q,timeSent:N,subscription:j0})}try{let N=new c,q=await Y.handleReq(this,X,N),K=j0,O={status:q,timeRcvd:Q,timeSent:this.clock.now(),subscription:K},W=new c;if(W.writeStruct(i0,O)!==0)return new Response(null,{status:500});if(q!==0){let T=J.now();return n0({status:q,timeRcvd:Q,timeSent:T,subscription:j0})}return N.prependBytes(W.result()),CJ(N)}catch(N){let q=J.now();return console.error(N),console.trace(),n0({status:12,timeRcvd:Q,timeSent:q,subscription:j0})}}}async function K8($,J){let Z=new URL($.url).searchParams.get(iQ);if(!Z)return M(11);let V=C$(Z),I=new I0(V),[X,G]=I.readStruct(X0);if(G!==0)return M(11);let Y=await K0(X,J.crypto,J.clock);if(Y!==0)return M(Y);return j(X)}class W8{recvs=new Map;async open($,J,Q,Z){let V=await K0($,Q,Z);if(V!==0)return{send:()=>V,shut:()=>V,status:V};let I=O0($.pubKey);if(!this.recvs.has(I))this.recvs.set(I,new Set);return this.recvs.get(I)?.add(J),{send:(X)=>{return J(X),0},shut:()=>{return this.recvs.get(I)?.delete(J),0},status:0}}async push($,J){let Q=O0($),Z=this.recvs.get(Q);if(Z)for(let V of Z)V(J)}}var M8=new W8;async function AX($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let J=new bJ(N8,x0,M8,new c0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(Q,Z)=>{if(Q.headers.get("upgrade")==="websocket"){let[V,I]=await K8(Q,J);if(I!==0)return new Response("Unauthorized",{status:401});return Z.upgrade(Q,{data:{authTS:V}})?void 0:new Response("Upgrade failed",{status:400})}return J.corsHandler(Q)},websocket:{data:{},open:(Q)=>{let Z=Q.data.authTS;M8.open(Z,(V)=>Q.send(V),J.crypto,J.clock).then((V)=>{if(V.status!==0){Q.close();return}Q.channel=V})},message:(Q,Z)=>{},close:(Q)=>{Q.channel?.shut()}}})}class U8{enclave;conn;clock;constructor({seed:$,clock:J=new c0}){this.enclave=new SJ($,x0),this.clock=J}async connect($,J){let Q=new c0,Z=()=>Promise.resolve(0);this.conn=new S$(this.enclave,x0,$,Q,J,Z);let[,V]=await this.conn.register();return V}async push($){if(!this.conn)return M(28);let J=[];for(let V of $){let[I,X]=await this.conn.seal(V);if(X!==0)return M(X);J.push(I)}let[Q,Z]=await this.conn.push(J);if(Z!==0)return M(Z);return j(Q)}async peek($){if(!this.conn)return M(28);return this.conn.peek($)}async pull($){if(!this.conn)return M(28);return this.conn.pull($)}async open($,J){if(!this.conn)return M(28);let Q=await this.conn.keys(),[Z,V]=await GZ($,Q,this.enclave,x0);if(V!==0)return M(V);let I=await this.enclave.deriveFromKDM(Z.kdm);return eQ(Z.headEnc,J.bodyCph,I,x0)}async upsertSingletonSync($,J){let[Q,Z]=await YZ($,this.clock,J);if(Z!==0)return Z;let[,V]=await this.push([Q]);return V}async listen($,J,Q){if(!this.conn)return 28;return this.conn.listen($,J,Q)}isConnected(){return this.conn?.isConnected()??!1}}async function CX({seed:$,host:J,transport:Q}){let Z=new U8({seed:$}),V=await Z.connect(J,Q);return[Z,V]}async function nK({seed:$,host:J,transport:Q}){let Z=Q??AJ(J),[V,I]=await CX({seed:$,host:J,transport:Z});if(I!==0)console.error(`Failed to initialize CLI: ${v[I]}`),process.exit(1);return V}function oK($){let J=process.env[$];if(!J)console.error(`${$} env var missing`),process.exit(1);let Q=C$(J);if(Q.length!==32)console.error(`${$} must be 64 hex chars (32 bytes)`),process.exit(1);return Q}function aK($){let J=process.env[$];if(!J)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(J),label:"host"}}export{AX as runBunHost,RJ as notifItemCodec,TX as msgpack,oK as loadSeedOrPanic,aK as loadHostOrPanic,nK as initCLIOrPanic,CX as initCLI,AJ as hostHTTPTransport,v as Status,I0 as Decoder,U8 as CLIClient};
|
|
@@ -4,5 +4,7 @@ export declare class TypedEventEmitter<T> {
|
|
|
4
4
|
addEventListener(eventType: string, listener: TypedListener<T>): () => void;
|
|
5
5
|
removeEventListener(eventType: string, listener: TypedListener<T>): void;
|
|
6
6
|
emit(eventType: string, data: T): void;
|
|
7
|
+
/** Emit to every event type that currently has listeners (e.g. wipe/reset). */
|
|
8
|
+
emitAll(data: T): void;
|
|
7
9
|
}
|
|
8
10
|
export {};
|
|
@@ -10,6 +10,8 @@ export declare class SingletonStateManager implements IStateManager {
|
|
|
10
10
|
private emitter;
|
|
11
11
|
constructor(singletonType: string);
|
|
12
12
|
apply(messages: IMessage[]): Promise<Status[]>;
|
|
13
|
+
clear: () => Promise<Status>;
|
|
14
|
+
notify: (types: Iterable<string>) => void;
|
|
13
15
|
on: (event: string, listener: () => void) => void;
|
|
14
16
|
off: (event: string, listener: () => void) => void;
|
|
15
17
|
}
|
|
@@ -48,8 +48,22 @@ export interface IStorage {
|
|
|
48
48
|
addUser: (pubKey: PublicKey) => Promise<ValStat<void>>;
|
|
49
49
|
hasUser: (pubKey: PublicKey) => Promise<ValStat<boolean>>;
|
|
50
50
|
subMeta: (pubKey: PublicKey) => Promise<ValStat<ISubscriptionMetadata>>;
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Store bags for a user. Returns host seq for each bag in order.
|
|
53
|
+
* Empty list succeeds with []. Implementations must assign contiguous
|
|
54
|
+
* seqs atomically (transaction / single batch) so concurrent writers
|
|
55
|
+
* cannot claim the same seq.
|
|
56
|
+
*/
|
|
57
|
+
setBags: (pubKey: PublicKey, bags: IBag[]) => Promise<ValStat<number[]>>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch ciphertext bodies for the given host seqs.
|
|
60
|
+
* Returns only seqs that exist (missing seqs are omitted, not an error).
|
|
61
|
+
* Empty `seqs` succeeds with [].
|
|
62
|
+
*/
|
|
63
|
+
getBodies: (pubKey: PublicKey, seqs: number[]) => Promise<ValStat<{
|
|
64
|
+
seq: number;
|
|
65
|
+
bodyCph: Uint8Array;
|
|
66
|
+
}[]>>;
|
|
53
67
|
listHeads: (pubKey: PublicKey, minSeq: number) => Promise<ValStat<IBagPeekItem[]>>;
|
|
54
68
|
}
|
|
55
69
|
export interface KeyPair {
|
|
@@ -151,6 +165,13 @@ export interface ITransport {
|
|
|
151
165
|
}
|
|
152
166
|
export interface IStateManager {
|
|
153
167
|
apply: (msgs: IMessage[]) => Promise<Status[]>;
|
|
168
|
+
/** Drop local application state and notify subscribers. */
|
|
169
|
+
clear: () => Promise<Status>;
|
|
170
|
+
/**
|
|
171
|
+
* Notify type subscribers without applying msgs (e.g. after a peer thread
|
|
172
|
+
* updated shared application state in IndexedDB).
|
|
173
|
+
*/
|
|
174
|
+
notify: (types: Iterable<string>) => void;
|
|
154
175
|
on: (type: string, listener: () => void) => void;
|
|
155
176
|
off: (type: string, listener: () => void) => void;
|
|
156
177
|
}
|