@interncom/diplomatic 0.5.0 → 0.6.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 +2 -2
- package/dist/cli/shared/singleton.d.ts +2 -1
- package/dist/cli/shared/types.d.ts +30 -3
- package/dist/web/client.d.ts +40 -6
- package/dist/web/entdb/cached.d.ts +52 -0
- package/dist/web/entdb/entdb.d.ts +15 -7
- package/dist/web/entdb/idb.d.ts +2 -0
- package/dist/web/entdb/manager.d.ts +8 -0
- package/dist/web/entdb/memory.d.ts +1 -0
- package/dist/web/index.d.ts +6 -5
- package/dist/web/index.mjs +1 -1
- package/dist/web/shared/singleton.d.ts +2 -1
- package/dist/web/shared/types.d.ts +30 -3
- package/dist/web/state.d.ts +24 -5
- package/dist/web/types.d.ts +8 -4
- package/dist/web/worker/client.d.ts +25 -5
- package/dist/web/worker/protocol.d.ts +5 -38
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var iJ=Object.create;var{getPrototypeOf:lJ,defineProperty:u$,getOwnPropertyNames:yJ}=Object;var rJ=Object.prototype.hasOwnProperty;function nJ($){return this[$]}var dJ,uJ,pJ=($,Z,J)=>{var V=$!=null&&typeof $==="object";if(V){var Q=Z?dJ??=new WeakMap:uJ??=new WeakMap,W=Q.get($);if(W)return W}J=$!=null?iJ(lJ($)):{};let X=Z||!$||!$.__esModule?u$(J,"default",{value:$,enumerable:!0}):J;for(let I of yJ($))if(!rJ.call(X,I))u$(X,I,{get:nJ.bind($,I),enumerable:!0});if(V)Q.set($,X);return X};var b=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var o0=b((fZ)=>{Object.defineProperty(fZ,"__esModule",{value:!0});fZ.utf8Count=wV;fZ.utf8EncodeJs=_Z;fZ.utf8EncodeTE=BZ;fZ.utf8Encode=UV;fZ.utf8DecodeJs=gZ;fZ.utf8DecodeTD=xZ;fZ.utf8Decode=TV;function wV($){let Z=$.length,J=0,V=0;while(V<Z){let Q=$.charCodeAt(V++);if((Q&4294967168)===0){J++;continue}else if((Q&4294965248)===0)J+=2;else{if(Q>=55296&&Q<=56319){if(V<Z){let W=$.charCodeAt(V);if((W&64512)===56320)++V,Q=((Q&1023)<<10)+(W&1023)+65536}}if((Q&4294901760)===0)J+=3;else J+=4}}return J}function _Z($,Z,J){let V=$.length,Q=J,W=0;while(W<V){let X=$.charCodeAt(W++);if((X&4294967168)===0){Z[Q++]=X;continue}else if((X&4294965248)===0)Z[Q++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(W<V){let I=$.charCodeAt(W);if((I&64512)===56320)++W,X=((X&1023)<<10)+(I&1023)+65536}}if((X&4294901760)===0)Z[Q++]=X>>12&15|224,Z[Q++]=X>>6&63|128;else Z[Q++]=X>>18&7|240,Z[Q++]=X>>12&63|128,Z[Q++]=X>>6&63|128}Z[Q++]=X&63|128}}var OV=new TextEncoder,KV=50;function BZ($,Z,J){OV.encodeInto($,Z.subarray(J))}function UV($,Z,J){if($.length>KV)BZ($,Z,J);else _Z($,Z,J)}var zV=4096;function gZ($,Z,J){let V=Z,Q=V+J,W=[],X="";while(V<Q){let I=$[V++];if((I&128)===0)W.push(I);else if((I&224)===192){let Y=$[V++]&63;W.push((I&31)<<6|Y)}else if((I&240)===224){let Y=$[V++]&63,G=$[V++]&63;W.push((I&31)<<12|Y<<6|G)}else if((I&248)===240){let Y=$[V++]&63,G=$[V++]&63,P=$[V++]&63,M=(I&7)<<18|Y<<12|G<<6|P;if(M>65535)M-=65536,W.push(M>>>10&1023|55296),M=56320|M&1023;W.push(M)}else W.push(I);if(W.length>=zV)X+=String.fromCharCode(...W),W.length=0}if(W.length>0)X+=String.fromCharCode(...W);return X}var FV=new TextDecoder,HV=200;function xZ($,Z,J){let V=$.subarray(Z,Z+J);return FV.decode(V)}function TV($,Z,J){if(J>HV)return xZ($,Z,J);else return gZ($,Z,J)}});var j$=b((iZ)=>{Object.defineProperty(iZ,"__esModule",{value:!0});iZ.ExtData=void 0;class vZ{type;data;constructor($,Z){this.type=$,this.data=Z}}iZ.ExtData=vZ});var s0=b((yZ)=>{Object.defineProperty(yZ,"__esModule",{value:!0});yZ.DecodeError=void 0;class a0 extends Error{constructor($){super($);let Z=Object.create(a0.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:a0.name})}}yZ.DecodeError=a0});var t0=b((nZ)=>{Object.defineProperty(nZ,"__esModule",{value:!0});nZ.UINT32_MAX=void 0;nZ.setUint64=jV;nZ.setInt64=kV;nZ.getInt64=_V;nZ.getUint64=BV;nZ.UINT32_MAX=4294967295;function jV($,Z,J){let V=J/4294967296,Q=J;$.setUint32(Z,V),$.setUint32(Z+4,Q)}function kV($,Z,J){let V=Math.floor(J/4294967296),Q=J;$.setUint32(Z,V),$.setUint32(Z+4,Q)}function _V($,Z){let J=$.getInt32(Z),V=$.getUint32(Z+4);return J*4294967296+V}function BV($,Z){let J=$.getUint32(Z),V=$.getUint32(Z+4);return J*4294967296+V}});var k$=b((aZ)=>{Object.defineProperty(aZ,"__esModule",{value:!0});aZ.timestampExtension=aZ.EXT_TIMESTAMP=void 0;aZ.encodeTimeSpecToTimestamp=pZ;aZ.encodeDateToTimeSpec=bZ;aZ.encodeTimestampExtension=hZ;aZ.decodeTimestampToTimeSpec=cZ;aZ.decodeTimestampExtension=oZ;var iV=s0(),uZ=t0();aZ.EXT_TIMESTAMP=-1;var lV=4294967295,yV=17179869183;function pZ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=yV)if(Z===0&&$<=lV){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,V=$&4294967295,Q=new Uint8Array(8),W=new DataView(Q.buffer);return W.setUint32(0,Z<<2|J&3),W.setUint32(4,V),Q}else{let J=new Uint8Array(12),V=new DataView(J.buffer);return V.setUint32(0,Z),(0,uZ.setInt64)(V,4,$),J}}function bZ($){let Z=$.getTime(),J=Math.floor(Z/1000),V=(Z-J*1000)*1e6,Q=Math.floor(V/1e9);return{sec:J+Q,nsec:V-Q*1e9}}function hZ($){if($ instanceof Date){let Z=bZ($);return pZ(Z)}else return null}function cZ($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let J=Z.getUint32(0),V=0;return{sec:J,nsec:0}}case 8:{let J=Z.getUint32(0),V=Z.getUint32(4),Q=(J&3)*4294967296+V,W=J>>>2;return{sec:Q,nsec:W}}case 12:{let J=(0,uZ.getInt64)(Z,4),V=Z.getUint32(0);return{sec:J,nsec:V}}default:throw new iV.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function oZ($){let Z=cZ($);return new Date(Z.sec*1000+Z.nsec/1e6)}aZ.timestampExtension={type:aZ.EXT_TIMESTAMP,encode:hZ,decode:oZ}});var $$=b((eZ)=>{Object.defineProperty(eZ,"__esModule",{value:!0});eZ.ExtensionCodec=void 0;var e0=j$(),bV=k$();class _${static defaultCodec=new _$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(bV.timestampExtension)}register({type:$,encode:Z,decode:J}){if($>=0)this.encoders[$]=Z,this.decoders[$]=J;else{let V=-1-$;this.builtInEncoders[V]=Z,this.builtInDecoders[V]=J}}tryToEncode($,Z){for(let J=0;J<this.builtInEncoders.length;J++){let V=this.builtInEncoders[J];if(V!=null){let Q=V($,Z);if(Q!=null){let W=-1-J;return new e0.ExtData(W,Q)}}}for(let J=0;J<this.encoders.length;J++){let V=this.encoders[J];if(V!=null){let Q=V($,Z);if(Q!=null){let W=J;return new e0.ExtData(W,Q)}}}if($ instanceof e0.ExtData)return $;return null}decode($,Z,J){let V=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(V)return V($,Z,J);else return new e0.ExtData(Z,$)}}eZ.ExtensionCodec=_$});var B$=b((ZJ)=>{Object.defineProperty(ZJ,"__esModule",{value:!0});ZJ.ensureUint8Array=cV;function hV($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function cV($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(hV($))return new Uint8Array($);else return Uint8Array.from($)}});var x$=b((QJ)=>{Object.defineProperty(QJ,"__esModule",{value:!0});QJ.Encoder=QJ.DEFAULT_INITIAL_BUFFER_SIZE=QJ.DEFAULT_MAX_DEPTH=void 0;var JJ=o0(),aV=$$(),VJ=t0(),sV=B$();QJ.DEFAULT_MAX_DEPTH=100;QJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class g${extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??aV.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??QJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??QJ.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 g$({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($,Z){if(Z>this.maxDepth)throw Error(`Too deep objects in depth ${Z}`);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($,Z)}ensureBufferSizeToWrite($){let Z=this.pos+$;if(this.view.byteLength<Z)this.resizeBuffer(Z*2)}resizeBuffer($){let Z=new ArrayBuffer($),J=new Uint8Array(Z),V=new DataView(Z);J.set(this.bytes),this.view=V,this.bytes=J}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 J=(0,JJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,JJ.utf8Encode)($,this.bytes,this.pos),this.pos+=J}encodeObject($,Z){let J=this.extensionCodec.tryToEncode($,this.context);if(J!=null)this.encodeExtension(J);else if(Array.isArray($))this.encodeArray($,Z);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,Z);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let Z=$.byteLength;if(Z<256)this.writeU8(196),this.writeU8(Z);else if(Z<65536)this.writeU8(197),this.writeU16(Z);else if(Z<4294967296)this.writeU8(198),this.writeU32(Z);else throw Error(`Too large binary: ${Z}`);let J=(0,sV.ensureUint8Array)($);this.writeU8a(J)}encodeArray($,Z){let J=$.length;if(J<16)this.writeU8(144+J);else if(J<65536)this.writeU8(220),this.writeU16(J);else if(J<4294967296)this.writeU8(221),this.writeU32(J);else throw Error(`Too large array: ${J}`);for(let V of $)this.doEncode(V,Z+1)}countWithoutUndefined($,Z){let J=0;for(let V of Z)if($[V]!==void 0)J++;return J}encodeMap($,Z){let J=Object.keys($);if(this.sortKeys)J.sort();let V=this.ignoreUndefined?this.countWithoutUndefined($,J):J.length;if(V<16)this.writeU8(128+V);else if(V<65536)this.writeU8(222),this.writeU16(V);else if(V<4294967296)this.writeU8(223),this.writeU32(V);else throw Error(`Too large map object: ${V}`);for(let Q of J){let W=$[Q];if(!(this.ignoreUndefined&&W===void 0))this.encodeString(Q),this.doEncode(W,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),V=J.length;if(V>=4294967296)throw Error(`Too large extension object: ${V}`);this.writeU8(201),this.writeU32(V),this.writeI8($.type),this.writeU8a(J);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}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,VJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,VJ.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}}QJ.Encoder=g$});var GJ=b((YJ)=>{Object.defineProperty(YJ,"__esModule",{value:!0});YJ.encode=eV;var tV=x$();function eV($,Z){return new tV.Encoder(Z).encodeSharedRef($)}});var PJ=b((NJ)=>{Object.defineProperty(NJ,"__esModule",{value:!0});NJ.prettyByte=ZQ;function ZQ($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var wJ=b((qJ)=>{Object.defineProperty(qJ,"__esModule",{value:!0});qJ.CachedKeyDecoder=void 0;var VQ=o0(),QQ=16,WQ=16;class MJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=QQ,Z=WQ){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let J=0;J<this.maxKeyLength;J++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,J){let V=this.caches[J-1];$:for(let Q of V){let W=Q.bytes;for(let X=0;X<J;X++)if(W[X]!==$[Z+X])continue $;return Q.str}return null}store($,Z){let J=this.caches[$.length-1],V={bytes:$,str:Z};if(J.length>=this.maxLengthPerKey)J[Math.random()*J.length|0]=V;else J.push(V)}decode($,Z,J){let V=this.find($,Z,J);if(V!=null)return this.hit++,V;this.miss++;let Q=(0,VQ.utf8DecodeJs)($,Z,J),W=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(W,Q),Q}}qJ.CachedKeyDecoder=MJ});var Z$=b((FJ)=>{Object.defineProperty(FJ,"__esModule",{value:!0});FJ.Decoder=void 0;var f$=PJ(),XQ=$$(),q0=t0(),IQ=o0(),OJ=B$(),YQ=wJ(),Y0=s0(),v$="array",i0="map_key",UJ="map_value",GQ=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new Y0.DecodeError("The type of key must be string or number but "+typeof $)};class zJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=v$,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=i0,Z.readCount=0,Z.size=$,Z.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===v$){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===i0||$.type===UJ){let J=$;J.size=0,J.map=void 0,J.readCount=0,J.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var v0=-1,i$=new DataView(new ArrayBuffer(0)),NQ=new Uint8Array(i$.buffer);try{i$.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 KJ=RangeError("Insufficient data"),PQ=new YQ.CachedKeyDecoder;class l${extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=i$;bytes=NQ;headByte=v0;stack=new zJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??XQ.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??q0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??q0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??q0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??q0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??q0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:PQ,this.mapKeyConverter=$?.mapKeyConverter??GQ}clone(){return new l$({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=v0,this.stack.reset()}setBuffer($){let Z=(0,OJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===v0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,OJ.ensureUint8Array)($),V=new Uint8Array(Z.length+J.length);V.set(Z),V.set(J,Z.length),this.setBuffer(V)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}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 Z=!1,J;for await(let X of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{J=this.doDecodeSync(),Z=!0}catch(I){if(!(I instanceof RangeError))throw I}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:V,pos:Q,totalPos:W}=this;throw RangeError(`Insufficient data in parsing ${(0,f$.prettyByte)(V)} at ${W} (${Q} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let J=Z,V=-1;for await(let Q of $){if(Z&&V===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(Q),J)V=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--V===0)break}catch(W){if(!(W instanceof RangeError))throw W}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let V=$-128;if(V!==0){this.pushMapState(V),this.complete();continue $}else Z={}}else if($<160){let V=$-144;if(V!==0){this.pushArrayState(V),this.complete();continue $}else Z=[]}else{let V=$-160;Z=this.decodeString(V,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let V=this.lookU8();Z=this.decodeString(V,1)}else if($===218){let V=this.lookU16();Z=this.decodeString(V,2)}else if($===219){let V=this.lookU32();Z=this.decodeString(V,4)}else if($===220){let V=this.readU16();if(V!==0){this.pushArrayState(V),this.complete();continue $}else Z=[]}else if($===221){let V=this.readU32();if(V!==0){this.pushArrayState(V),this.complete();continue $}else Z=[]}else if($===222){let V=this.readU16();if(V!==0){this.pushMapState(V),this.complete();continue $}else Z={}}else if($===223){let V=this.readU32();if(V!==0){this.pushMapState(V),this.complete();continue $}else Z={}}else if($===196){let V=this.lookU8();Z=this.decodeBinary(V,1)}else if($===197){let V=this.lookU16();Z=this.decodeBinary(V,2)}else if($===198){let V=this.lookU32();Z=this.decodeBinary(V,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let V=this.lookU8();Z=this.decodeExtension(V,1)}else if($===200){let V=this.lookU16();Z=this.decodeExtension(V,2)}else if($===201){let V=this.lookU32();Z=this.decodeExtension(V,4)}else throw new Y0.DecodeError(`Unrecognized type byte: ${(0,f$.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let V=J.top();if(V.type===v$)if(V.array[V.position]=Z,V.position++,V.position===V.size)Z=V.array,J.release(V);else continue $;else if(V.type===i0){if(Z==="__proto__")throw new Y0.DecodeError("The key __proto__ is not allowed");V.key=this.mapKeyConverter(Z),V.type=UJ;continue $}else if(V.map[V.key]=Z,V.readCount++,V.readCount===V.size)Z=V.map,J.release(V);else{V.key=null,V.type=i0;continue $}}return Z}}readHeadByte(){if(this.headByte===v0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=v0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new Y0.DecodeError(`Unrecognized array type byte: ${(0,f$.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new Y0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new Y0.DecodeError(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,Z){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,Z);return this.decodeBinary($,Z)}decodeUtf8String($,Z){if($>this.maxStrLength)throw new Y0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw KJ;let J=this.pos+Z,V;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))V=this.keyDecoder.decode(this.bytes,J,$);else V=(0,IQ.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,V}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===i0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new Y0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw KJ;let J=this.pos+Z,V=this.bytes.subarray(J,J+$);return this.pos+=Z+$,V}decodeExtension($,Z){if($>this.maxExtLength)throw new Y0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let J=this.view.getInt8(this.pos+Z),V=this.decodeBinary($,Z+1);return this.extensionCodec.decode(V,J,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,q0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,q0.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,$}}FJ.Decoder=l$});var DJ=b((AJ)=>{Object.defineProperty(AJ,"__esModule",{value:!0});AJ.decode=MQ;AJ.decodeMulti=qQ;var TJ=Z$();function MQ($,Z){return new TJ.Decoder(Z).decode($)}function qQ($,Z){return new TJ.Decoder(Z).decodeMulti($)}});var mJ=b((EJ)=>{Object.defineProperty(EJ,"__esModule",{value:!0});EJ.isAsyncIterable=CJ;EJ.asyncIterableFromStream=SJ;EJ.ensureAsyncIterable=OQ;function CJ($){return $[Symbol.asyncIterator]!=null}async function*SJ($){let Z=$.getReader();try{while(!0){let{done:J,value:V}=await Z.read();if(J)return;yield V}}finally{Z.releaseLock()}}function OQ($){if(CJ($))return $;else return SJ($)}});var jJ=b((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.decodeAsync=FQ;LJ.decodeArrayStream=HQ;LJ.decodeMultiStream=TQ;var y$=Z$(),r$=mJ();async function FQ($,Z){let J=(0,r$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeAsync(J)}function HQ($,Z){let J=(0,r$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeArrayStream(J)}function TQ($,Z){let J=(0,r$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeStream(J)}});var _J=b((f)=>{Object.defineProperty(f,"__esModule",{value:!0});f.decodeTimestampExtension=f.encodeTimestampExtension=f.decodeTimestampToTimeSpec=f.encodeTimeSpecToTimestamp=f.encodeDateToTimeSpec=f.EXT_TIMESTAMP=f.ExtData=f.ExtensionCodec=f.Encoder=f.DecodeError=f.Decoder=f.decodeMultiStream=f.decodeArrayStream=f.decodeAsync=f.decodeMulti=f.decode=f.encode=void 0;var SQ=GJ();Object.defineProperty(f,"encode",{enumerable:!0,get:function(){return SQ.encode}});var kJ=DJ();Object.defineProperty(f,"decode",{enumerable:!0,get:function(){return kJ.decode}});Object.defineProperty(f,"decodeMulti",{enumerable:!0,get:function(){return kJ.decodeMulti}});var n$=jJ();Object.defineProperty(f,"decodeAsync",{enumerable:!0,get:function(){return n$.decodeAsync}});Object.defineProperty(f,"decodeArrayStream",{enumerable:!0,get:function(){return n$.decodeArrayStream}});Object.defineProperty(f,"decodeMultiStream",{enumerable:!0,get:function(){return n$.decodeMultiStream}});var EQ=Z$();Object.defineProperty(f,"Decoder",{enumerable:!0,get:function(){return EQ.Decoder}});var mQ=s0();Object.defineProperty(f,"DecodeError",{enumerable:!0,get:function(){return mQ.DecodeError}});var LQ=x$();Object.defineProperty(f,"Encoder",{enumerable:!0,get:function(){return LQ.Encoder}});var jQ=$$();Object.defineProperty(f,"ExtensionCodec",{enumerable:!0,get:function(){return jQ.ExtensionCodec}});var kQ=j$();Object.defineProperty(f,"ExtData",{enumerable:!0,get:function(){return kQ.ExtData}});var L0=k$();Object.defineProperty(f,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return L0.EXT_TIMESTAMP}});Object.defineProperty(f,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return L0.encodeDateToTimeSpec}});Object.defineProperty(f,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return L0.encodeTimeSpecToTimestamp}});Object.defineProperty(f,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return L0.decodeTimestampToTimeSpec}});Object.defineProperty(f,"encodeTimestampExtension",{enumerable:!0,get:function(){return L0.encodeTimestampExtension}});Object.defineProperty(f,"decodeTimestampExtension",{enumerable:!0,get:function(){return L0.decodeTimestampExtension}})});import*as V0 from"node:crypto";var N0=V0&&typeof V0==="object"&&"webcrypto"in V0?V0.webcrypto:V0&&typeof V0==="object"&&("randomBytes"in V0)?V0:void 0;function l0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function J$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function r($,...Z){if(!J$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function V$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function p$($,Z){r($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function Q$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var Q0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var bJ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!bJ)throw Error("Non little-endian hardware is not supported");function hJ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function y0($){if(typeof $==="string")$=hJ($);else if(J$($))$=r0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function b$($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function h$($,Z){if($.length!==Z.length)return!1;let J=0;for(let V=0;V<$.length;V++)J|=$[V]^Z[V];return J===0}var c$=($,Z)=>{function J(V,...Q){if(r(V),$.nonceLength!==void 0){let P=Q[0];if(!P)throw Error("nonce / iv required");if($.varSizeNonce)r(P);else r(P,$.nonceLength)}let W=$.tagLength;if(W&&Q[1]!==void 0)r(Q[1]);let X=Z(V,...Q),I=(P,M)=>{if(M!==void 0){if(P!==2)throw Error("cipher output not supported");r(M)}},Y=!1;return{encrypt(P,M){if(Y)throw Error("cannot encrypt() twice with same key + nonce");return Y=!0,r(P),I(X.encrypt.length,M),X.encrypt(P,M)},decrypt(P,M){if(r(P),W&&P.length<W)throw Error("invalid ciphertext length: smaller than tagLength="+W);return I(X.decrypt.length,M),X.decrypt(P,M)}}}return Object.assign(J,$),J};function W$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!cJ(Z))throw Error("invalid output, must be aligned");return Z}function cJ($){return $.byteOffset%4===0}function r0($){return Uint8Array.from($)}function $0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function n0($=32){if(N0&&typeof N0.getRandomValues==="function")return N0.getRandomValues(new Uint8Array($));if(N0&&typeof N0.randomBytes==="function")return N0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var a$=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),oJ=a$("expand 16-byte k"),aJ=a$("expand 32-byte k"),sJ=Q0(oJ),tJ=Q0(aJ);function O($,Z){return $<<Z|$>>>32-Z}function X$($){return $.byteOffset%4===0}var d0=64,eJ=16,s$=4294967295,o$=new Uint32Array;function $V($,Z,J,V,Q,W,X,I){let Y=Q.length,G=new Uint8Array(d0),P=Q0(G),M=X$(Q)&&X$(W),R=M?Q0(Q):o$,w=M?Q0(W):o$;for(let U=0;U<Y;X++){if($(Z,J,V,P,X,I),X>=s$)throw Error("arx: counter overflow");let K=Math.min(d0,Y-U);if(M&&K===d0){let H=U/4;if(U%4!==0)throw Error("arx: invalid block position");for(let T=0,D;T<eJ;T++)D=H+T,w[D]=R[D]^P[T];U+=d0;continue}for(let H=0,T;H<K;H++)T=U+H,W[T]=Q[T]^G[H];U+=K}}function t$($,Z){let{allowShortKeys:J,extendNonceFn:V,counterLength:Q,counterRight:W,rounds:X}=b$({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return l0(Q),l0(X),Q$(W),Q$(J),(I,Y,G,P,M=0)=>{r(I),r(Y),r(G);let R=G.length;if(P===void 0)P=new Uint8Array(R);if(r(P),l0(M),M<0||M>=s$)throw Error("arx: counter overflow");if(P.length<R)throw Error(`arx: output (${P.length}) is shorter than data (${R})`);let w=[],U=I.length,K,H;if(U===32)w.push(K=r0(I)),H=tJ;else if(U===16&&J)K=new Uint8Array(32),K.set(I),K.set(I,16),H=sJ,w.push(K);else throw Error(`arx: invalid 32-byte key, got length=${U}`);if(!X$(Y))w.push(Y=r0(Y));let T=Q0(K);if(V){if(Y.length!==24)throw Error("arx: extended nonce must be 24 bytes");V(H,T,Q0(Y.subarray(0,16)),T),Y=Y.subarray(16)}let D=16-Q;if(D!==Y.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let F=new Uint8Array(12);F.set(Y,W?0:12-Y.length),Y=F,w.push(Y)}let C=Q0(Y);return $V($,H,T,C,G,P,M,X),$0(...w),P}}var d=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class e${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,$=y0($),r($,32);let Z=d($,0),J=d($,2),V=d($,4),Q=d($,6),W=d($,8),X=d($,10),I=d($,12),Y=d($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|V<<6)&7939,this.r[3]=(V>>>7|Q<<9)&8191,this.r[4]=(Q>>>4|W<<12)&255,this.r[5]=W>>>1&8190,this.r[6]=(W>>>14|X<<2)&8191,this.r[7]=(X>>>11|I<<5)&8065,this.r[8]=(I>>>8|Y<<8)&8191,this.r[9]=Y>>>5&127;for(let G=0;G<8;G++)this.pad[G]=d($,16+2*G)}process($,Z,J=!1){let V=J?0:2048,{h:Q,r:W}=this,X=W[0],I=W[1],Y=W[2],G=W[3],P=W[4],M=W[5],R=W[6],w=W[7],U=W[8],K=W[9],H=d($,Z+0),T=d($,Z+2),D=d($,Z+4),C=d($,Z+6),F=d($,Z+8),E=d($,Z+10),k=d($,Z+12),n=d($,Z+14),L=Q[0]+(H&8191),_=Q[1]+((H>>>13|T<<3)&8191),g=Q[2]+((T>>>10|D<<6)&8191),q=Q[3]+((D>>>7|C<<9)&8191),x=Q[4]+((C>>>4|F<<12)&8191),B=Q[5]+(F>>>1&8191),v=Q[6]+((F>>>14|E<<2)&8191),i=Q[7]+((E>>>11|k<<5)&8191),l=Q[8]+((k>>>8|n<<8)&8191),y=Q[9]+(n>>>5|V),A=0,p=A+L*X+_*(5*K)+g*(5*U)+q*(5*w)+x*(5*R);A=p>>>13,p&=8191,p+=B*(5*M)+v*(5*P)+i*(5*G)+l*(5*Y)+y*(5*I),A+=p>>>13,p&=8191;let a=A+L*I+_*X+g*(5*K)+q*(5*U)+x*(5*w);A=a>>>13,a&=8191,a+=B*(5*R)+v*(5*M)+i*(5*P)+l*(5*G)+y*(5*Y),A+=a>>>13,a&=8191;let t=A+L*Y+_*I+g*X+q*(5*K)+x*(5*U);A=t>>>13,t&=8191,t+=B*(5*w)+v*(5*R)+i*(5*M)+l*(5*P)+y*(5*G),A+=t>>>13,t&=8191;let j=A+L*G+_*Y+g*I+q*X+x*(5*K);A=j>>>13,j&=8191,j+=B*(5*U)+v*(5*w)+i*(5*R)+l*(5*M)+y*(5*P),A+=j>>>13,j&=8191;let J0=A+L*P+_*G+g*Y+q*I+x*X;A=J0>>>13,J0&=8191,J0+=B*(5*K)+v*(5*U)+i*(5*w)+l*(5*R)+y*(5*M),A+=J0>>>13,J0&=8191;let R0=A+L*M+_*P+g*G+q*Y+x*I;A=R0>>>13,R0&=8191,R0+=B*X+v*(5*K)+i*(5*U)+l*(5*w)+y*(5*R),A+=R0>>>13,R0&=8191;let w0=A+L*R+_*M+g*P+q*G+x*Y;A=w0>>>13,w0&=8191,w0+=B*I+v*X+i*(5*K)+l*(5*U)+y*(5*w),A+=w0>>>13,w0&=8191;let O0=A+L*w+_*R+g*M+q*P+x*G;A=O0>>>13,O0&=8191,O0+=B*Y+v*I+i*X+l*(5*K)+y*(5*U),A+=O0>>>13,O0&=8191;let K0=A+L*U+_*w+g*R+q*M+x*P;A=K0>>>13,K0&=8191,K0+=B*G+v*Y+i*I+l*X+y*(5*K),A+=K0>>>13,K0&=8191;let U0=A+L*K+_*U+g*w+q*R+x*M;A=U0>>>13,U0&=8191,U0+=B*P+v*G+i*Y+l*I+y*X,A+=U0>>>13,U0&=8191,A=(A<<2)+A|0,A=A+p|0,p=A&8191,A=A>>>13,a+=A,Q[0]=p,Q[1]=a,Q[2]=t,Q[3]=j,Q[4]=J0,Q[5]=R0,Q[6]=w0,Q[7]=O0,Q[8]=K0,Q[9]=U0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),V=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=V,V=$[X]>>>13,$[X]&=8191;$[0]+=V*5,V=$[0]>>>13,$[0]&=8191,$[1]+=V,V=$[1]>>>13,$[1]&=8191,$[2]+=V,J[0]=$[0]+5,V=J[0]>>>13,J[0]&=8191;for(let X=1;X<10;X++)J[X]=$[X]+V,V=J[X]>>>13,J[X]&=8191;J[9]-=8192;let Q=(V^1)-1;for(let X=0;X<10;X++)J[X]&=Q;Q=~Q;for(let X=0;X<10;X++)$[X]=$[X]&Q|J[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 W=$[0]+Z[0];$[0]=W&65535;for(let X=1;X<8;X++)W=($[X]+Z[X]|0)+(W>>>16)|0,$[X]=W&65535;$0(J)}update($){V$(this);let{buffer:Z,blockLen:J}=this;$=y0($);let V=$.length;for(let Q=0;Q<V;){let W=Math.min(J-this.pos,V-Q);if(W===J){for(;J<=V-Q;Q+=J)this.process($,Q);continue}if(Z.set($.subarray(Q,Q+W),this.pos),this.pos+=W,Q+=W,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){$0(this.h,this.r,this.buffer,this.pad)}digestInto($){V$(this),p$($,this),this.finished=!0;let{buffer:Z,h:J}=this,{pos:V}=this;if(V){Z[V++]=1;for(;V<16;V++)Z[V]=0;this.process(Z,0,!0)}this.finalize();let Q=0;for(let W=0;W<8;W++)$[Q++]=J[W]>>>0,$[Q++]=J[W]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function ZV($){let Z=(V,Q)=>$(Q).update(y0(V)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(V)=>$(V),Z}var I$=ZV(($)=>new e$($));function JV($,Z,J,V,Q,W=20){let X=$[0],I=Z[0],Y=Z[1],G=Z[2],P=Z[3],M=$[1],R=J[0],w=J[1],U=Q,K=0,H=$[2],T=Z[4],D=Z[5],C=Z[6],F=Z[7],E=$[3],k=X,n=I,L=Y,_=G,g=P,q=M,x=R,B=w,v=U,i=K,l=H,y=T,A=D,p=C,a=F,t=E;for(let J0=0;J0<W;J0+=2)g^=O(k+A|0,7),v^=O(g+k|0,9),A^=O(v+g|0,13),k^=O(A+v|0,18),i^=O(q+n|0,7),p^=O(i+q|0,9),n^=O(p+i|0,13),q^=O(n+p|0,18),a^=O(l+x|0,7),L^=O(a+l|0,9),x^=O(L+a|0,13),l^=O(x+L|0,18),_^=O(t+y|0,7),B^=O(_+t|0,9),y^=O(B+_|0,13),t^=O(y+B|0,18),n^=O(k+_|0,7),L^=O(n+k|0,9),_^=O(L+n|0,13),k^=O(_+L|0,18),x^=O(q+g|0,7),B^=O(x+q|0,9),g^=O(B+x|0,13),q^=O(g+B|0,18),y^=O(l+i|0,7),v^=O(y+l|0,9),i^=O(v+y|0,13),l^=O(i+v|0,18),A^=O(t+a|0,7),p^=O(A+t|0,9),a^=O(p+A|0,13),t^=O(a+p|0,18);let j=0;V[j++]=X+k|0,V[j++]=I+n|0,V[j++]=Y+L|0,V[j++]=G+_|0,V[j++]=P+g|0,V[j++]=M+q|0,V[j++]=R+x|0,V[j++]=w+B|0,V[j++]=U+v|0,V[j++]=K+i|0,V[j++]=H+l|0,V[j++]=T+y|0,V[j++]=D+A|0,V[j++]=C+p|0,V[j++]=F+a|0,V[j++]=E+t|0}function VV($,Z,J,V){let Q=$[0],W=Z[0],X=Z[1],I=Z[2],Y=Z[3],G=$[1],P=J[0],M=J[1],R=J[2],w=J[3],U=$[2],K=Z[4],H=Z[5],T=Z[6],D=Z[7],C=$[3];for(let E=0;E<20;E+=2)Y^=O(Q+H|0,7),R^=O(Y+Q|0,9),H^=O(R+Y|0,13),Q^=O(H+R|0,18),w^=O(G+W|0,7),T^=O(w+G|0,9),W^=O(T+w|0,13),G^=O(W+T|0,18),D^=O(U+P|0,7),X^=O(D+U|0,9),P^=O(X+D|0,13),U^=O(P+X|0,18),I^=O(C+K|0,7),M^=O(I+C|0,9),K^=O(M+I|0,13),C^=O(K+M|0,18),W^=O(Q+I|0,7),X^=O(W+Q|0,9),I^=O(X+W|0,13),Q^=O(I+X|0,18),P^=O(G+Y|0,7),M^=O(P+G|0,9),Y^=O(M+P|0,13),G^=O(Y+M|0,18),K^=O(U+w|0,7),R^=O(K+U|0,9),w^=O(R+K|0,13),U^=O(w+R|0,18),H^=O(C+D|0,7),T^=O(H+C|0,9),D^=O(T+H|0,13),C^=O(D+T|0,18);let F=0;V[F++]=Q,V[F++]=G,V[F++]=U,V[F++]=C,V[F++]=P,V[F++]=M,V[F++]=R,V[F++]=w}var Y$=t$(JV,{counterRight:!0,extendNonceFn:VV}),G$=c$({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,V){V=W$(J.length+32,V,!1);let Q=V.subarray(0,32),W=V.subarray(32);V.set(J,32),$0(Q),Y$($,Z,V,V);let X=I$(W,Q);return V.set(X,16),$0(V.subarray(0,16),X),V.subarray(16)},decrypt(J,V){r(J),V=W$(J.length+32,V,!1);let Q=V.subarray(0,32),W=V.subarray(32,48),X=V.subarray(48);V.set(J,32),$0(Q);let I=Y$($,Z,Q,Q),Y=I$(X,I);if(!h$(W,Y))throw Error("invalid tag");return Y$($,Z,V.subarray(16),V.subarray(16)),$0(Q,W,Y),X}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function QV($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function k0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function P0($,...Z){if(!QV($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function _0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function u0($,Z){P0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function $Z($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function z0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function F0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function B0($,Z){return $<<32-Z|$>>>Z}var ZZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function JZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var VZ=ZZ?($)=>$:($)=>JZ($);function WV($){for(let Z=0;Z<$.length;Z++)$[Z]=JZ($[Z]);return $}var s=ZZ?($)=>$:WV;function XV($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function H0($){if(typeof $==="string")$=XV($);return P0($),$}class N${}function QZ($){let Z=(V,Q)=>$(Q).update(H0(V)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(V)=>$(V),Z}var WZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var p0=BigInt(4294967295),XZ=BigInt(32);function P$($,Z=!1){if(Z)return{h:Number($&p0),l:Number($>>XZ&p0)};return{h:Number($>>XZ&p0)|0,l:Number($&p0)|0}}function W0($,Z,J,V,Q){return $=$+Z+Q|0,V=B0(V^$,16),J=J+V|0,Z=B0(Z^J,12),{a:$,b:Z,c:J,d:V}}function X0($,Z,J,V,Q){return $=$+Z+Q|0,V=B0(V^$,8),J=J+V|0,Z=B0(Z^J,7),{a:$,b:Z,c:J,d:V}}class M$ extends N${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,k0($),k0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=z0(this.buffer)}update($){_0(this),$=H0($),P0($);let{blockLen:Z,buffer:J,buffer32:V}=this,Q=$.length,W=$.byteOffset,X=$.buffer;for(let I=0;I<Q;){if(this.pos===Z)s(V),this.compress(V,0,!1),s(V),this.pos=0;let Y=Math.min(Z-this.pos,Q-I),G=W+I;if(Y===Z&&!(G%4)&&I+Y<Q){let P=new Uint32Array(X,G,Math.floor((Q-I)/4));s(P);for(let M=0;I+Z<Q;M+=V.length,I+=Z)this.length+=Z,this.compress(P,M,!1);s(P);continue}J.set($.subarray(I,I+Y),this.pos),this.pos+=Y,this.length+=Y,I+=Y}return this}digestInto($){_0(this),u0($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,F0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let V=z0($);this.get().forEach((Q,W)=>V[W]=VZ(Q))}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}_cloneInto($){let{buffer:Z,length:J,finished:V,destroyed:Q,outputLen:W,pos:X}=this;return $||($=new this.constructor({dkLen:W})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=Q,$.finished=V,$.length=J,$.pos=X,$.outputLen=W,$}clone(){return this._cloneInto()}}function q$($,Z,J,V,Q,W,X,I,Y,G,P,M,R,w,U,K,H,T,D,C){let F=0;for(let E=0;E<V;E++)({a:Q,b:Y,c:R,d:H}=W0(Q,Y,R,H,J[Z+$[F++]])),{a:Q,b:Y,c:R,d:H}=X0(Q,Y,R,H,J[Z+$[F++]]),{a:W,b:G,c:w,d:T}=W0(W,G,w,T,J[Z+$[F++]]),{a:W,b:G,c:w,d:T}=X0(W,G,w,T,J[Z+$[F++]]),{a:X,b:P,c:U,d:D}=W0(X,P,U,D,J[Z+$[F++]]),{a:X,b:P,c:U,d:D}=X0(X,P,U,D,J[Z+$[F++]]),{a:I,b:M,c:K,d:C}=W0(I,M,K,C,J[Z+$[F++]]),{a:I,b:M,c:K,d:C}=X0(I,M,K,C,J[Z+$[F++]]),{a:Q,b:G,c:U,d:C}=W0(Q,G,U,C,J[Z+$[F++]]),{a:Q,b:G,c:U,d:C}=X0(Q,G,U,C,J[Z+$[F++]]),{a:W,b:P,c:K,d:H}=W0(W,P,K,H,J[Z+$[F++]]),{a:W,b:P,c:K,d:H}=X0(W,P,K,H,J[Z+$[F++]]),{a:X,b:M,c:R,d:T}=W0(X,M,R,T,J[Z+$[F++]]),{a:X,b:M,c:R,d:T}=X0(X,M,R,T,J[Z+$[F++]]),{a:I,b:Y,c:w,d:D}=W0(I,Y,w,D,J[Z+$[F++]]),{a:I,b:Y,c:w,d:D}=X0(I,Y,w,D,J[Z+$[F++]]);return{v0:Q,v1:W,v2:X,v3:I,v4:Y,v5:G,v6:P,v7:M,v8:R,v9:w,v10:U,v11:K,v12:H,v13:T,v14:D,v15:C}}var Z0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},I0=WZ.slice(),IZ=(()=>{let $=Array.from({length:16},(V,Q)=>Q),Z=(V)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((Q)=>V[Q]),J=[];for(let V=0,Q=$;V<7;V++,Q=Z(Q))J.push(...Q);return Uint8Array.from(J)})();class R$ extends M${constructor($={},Z=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:J,context:V}=$,Q=V!==void 0;if(J!==void 0){if(Q)throw Error('Only "key" or "context" can be specified at same time');let W=H0(J).slice();P0(W,32),this.IV=z0(W),s(this.IV),this.flags=Z|Z0.KEYED_HASH}else if(Q){let W=H0(V),X=new R$({dkLen:32},Z0.DERIVE_KEY_CONTEXT).update(W).digest();this.IV=z0(X),s(this.IV),this.flags=Z|Z0.DERIVE_KEY_MATERIAL}else this.IV=I0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=$Z(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,V=0){let{state:Q,pos:W}=this,{h:X,l:I}=P$(BigInt($),!0),{v0:Y,v1:G,v2:P,v3:M,v4:R,v5:w,v6:U,v7:K,v8:H,v9:T,v10:D,v11:C,v12:F,v13:E,v14:k,v15:n}=q$(IZ,V,J,7,Q[0],Q[1],Q[2],Q[3],Q[4],Q[5],Q[6],Q[7],I0[0],I0[1],I0[2],I0[3],X,I,W,Z);Q[0]=Y^H,Q[1]=G^T,Q[2]=P^D,Q[3]=M^C,Q[4]=R^F,Q[5]=w^E,Q[6]=U^k,Q[7]=K^n}compress($,Z=0,J=!1){let V=this.flags;if(!this.chunkPos)V|=Z0.CHUNK_START;if(this.chunkPos===15||J)V|=Z0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,V,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let Q=this.state;this.state=this.IV.slice();for(let W,X=this.chunksDone+1;J||!(X&1);X>>=1){if(!(W=this.stack.pop()))break;this.buffer32.set(W,0),this.buffer32.set(Q,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|Z0.PARENT,this.buffer32,0),Q=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(Q)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:V,chunkPos:Q,posOut:W,chunkOut:X,stack:I,chunksDone:Y}=this;return $.state.set(V.slice()),$.stack=I.map((G)=>Uint32Array.from(G)),$.IV.set(Z),$.flags=J,$.chunkPos=Q,$.chunksDone=Y,$.posOut=W,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,F0(this.state,this.buffer32,this.IV,this.bufferOut32),F0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:V,bufferOut32:Q}=this,{h:W,l:X}=P$(BigInt(this.chunkOut++));s(V);let{v0:I,v1:Y,v2:G,v3:P,v4:M,v5:R,v6:w,v7:U,v8:K,v9:H,v10:T,v11:D,v12:C,v13:F,v14:E,v15:k}=q$(IZ,0,V,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],I0[0],I0[1],I0[2],I0[3],X,W,Z,J);Q[0]=I^K,Q[1]=Y^H,Q[2]=G^T,Q[3]=P^D,Q[4]=M^C,Q[5]=R^F,Q[6]=w^E,Q[7]=U^k,Q[8]=$[0]^K,Q[9]=$[1]^H,Q[10]=$[2]^T,Q[11]=$[3]^D,Q[12]=$[4]^C,Q[13]=$[5]^F,Q[14]=$[6]^E,Q[15]=$[7]^k,s(V),s(Q),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,F0(this.buffer.subarray(this.pos));let $=this.flags|Z0.ROOT;if(this.stack.length)$|=Z0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Z0.CHUNK_START:0)|Z0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){_0(this,!1),P0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let V=0,Q=$.length;V<Q;){if(this.posOut>=Z)this.b2CompressOut();let W=Math.min(Z-this.posOut,Q-V);$.set(J.subarray(this.posOut,this.posOut+W),V),this.posOut+=W,V+=W}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return k0($),this.xofInto(new Uint8Array($))}digestInto($){if(u0($,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 YZ=QZ(($)=>new R$($));function h($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function b0($){if($.length%2!==0)throw Error("Invalid hex string");let Z=new Uint8Array($.length/2);for(let J=0;J<$.length;J+=2)Z[J/2]=Number.parseInt($.substr(J,2),16);return Z}function PZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,V)=>J===Z[V])}var GZ;if(typeof Uint8Array.prototype.toBase64==="function")GZ=($)=>$.toBase64();else GZ=($)=>btoa(String.fromCharCode(...$));var NZ;if(typeof Uint8Array.fromBase64==="function")NZ=($)=>Uint8Array.fromBase64($);else NZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function g0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var w$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function MZ($){let Z=new Uint8Array(w$.length+32);return Z.set(w$),Z.set($.subarray(0,32),w$.length),Z}function qZ($){return typeof $==="string"?new TextEncoder().encode($):$}function T0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class O${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return n0($)}async gen256BitSecureRandomSeed(){return n0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=n0(24),Q=G$(Z,J).encrypt($);return new Uint8Array([...J,...Q])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),V=$.slice(24);return G$(Z,J).decrypt(V)}async deriveEd25519KeyPair($){let Z=$,J=MZ(Z),V=await globalThis.crypto.subtle.importKey("pkcs8",T0(J),{name:"Ed25519"},!0,["sign"]),Q=await globalThis.crypto.subtle.exportKey("jwk",V);if(typeof Q.x!=="string")throw Error("Ed25519 JWK missing x");let W=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:Q.x},{name:"Ed25519"},!0,["verify"]),X=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",W)),I=new Uint8Array(64);return I.set(Z,0),I.set(X,32),this.signKeys.set(h(Z),V),this.verifyKeys.set(h(X),W),{keyType:"ed25519",privateKey:I,publicKey:X}}async importSignKey($){let Z=$.subarray(0,32),J=h(Z),V=this.signKeys.get(J);if(V)return V;let Q=MZ(Z),W=await globalThis.crypto.subtle.importKey("pkcs8",T0(Q),{name:"Ed25519"},!1,["sign"]);return this.signKeys.set(J,W),W}async importVerifyKey($){let Z=h($),J=this.verifyKeys.get(Z);if(J)return J;let V=await globalThis.crypto.subtle.importKey("raw",T0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,V),V}async signEd25519($,Z){let J=qZ($),V=await this.importSignKey(Z),Q=await globalThis.crypto.subtle.sign({name:"Ed25519"},V,T0(J));return new Uint8Array(Q)}async checkSigEd25519($,Z,J){let V=qZ(Z);try{let Q=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},Q,T0($),T0(V))}catch{return!1}}async blake3($){return YZ($)}}var IV=new O$,M0=IV;var A0=64;var RZ=32,D0=8;var wZ=32;var OZ=30000,KZ=512,S;((q)=>{q[q.Success=0]="Success";q[q.InvalidSignature=3]="InvalidSignature";q[q.ClockOutOfSync=4]="ClockOutOfSync";q[q.UserNotRegistered=5]="UserNotRegistered";q[q.ServerMisconfigured=6]="ServerMisconfigured";q[q.MissingBody=7]="MissingBody";q[q.ExtraBodyContent=8]="ExtraBodyContent";q[q.MissingParam=9]="MissingParam";q[q.InvalidParam=10]="InvalidParam";q[q.InvalidRequest=11]="InvalidRequest";q[q.InternalError=12]="InternalError";q[q.NotFound=13]="NotFound";q[q.InvalidMessage=14]="InvalidMessage";q[q.NoChange=15]="NoChange";q[q.DatabaseClosed=16]="DatabaseClosed";q[q.StorageError=17]="StorageError";q[q.DatabaseError=18]="DatabaseError";q[q.HashMismatch=19]="HashMismatch";q[q.DecryptionError=20]="DecryptionError";q[q.NotImplemented=21]="NotImplemented";q[q.MissingSeed=22]="MissingSeed";q[q.OutOfBounds=23]="OutOfBounds";q[q.HostError=24]="HostError";q[q.CommunicationError=25]="CommunicationError";q[q.VarLimitExceeded=26]="VarLimitExceeded";q[q.InvalidResponse=27]="InvalidResponse";q[q.ConnectionClosed=28]="ConnectionClosed"})(S||={});var UZ="t";function z($){return[$,0]}function N($){return[void 0,$]}function YV($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return N(10);let Z=[];while($>0n){let J=Number($&0x7fn);if($>>=7n,$>0n)Z.push(J|128);else Z.push(J)}if(Z.length===0)return z(new Uint8Array([0]));if(Z.length>8)return N(26);return z(new Uint8Array(Z))}function GV($,Z=0){let J=0n,V=0,Q=Z;while(!0){if(Q>=$.length)return N(14);let W=$[Q++];if(W===void 0)return N(14);if(J|=BigInt(W&127)<<BigInt(V),(W&128)===0){if(Q-Z>8)return N(26);return z({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:Q-Z})}if(V+=7,V>=56)return N(26)}}class c{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new c(J)}readBigInt(){if(this.pos+8>this.data.length)return N(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,z($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return N(Z);return z(new Date($))}readVarInt(){let[$,Z]=GV(this.data,this.pos);if(Z!==0)return N(Z);this.pos+=$.bytesRead;let J=$.value;return z(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return N(Z);let[J,V]=this.readBytes($);if(V!==0)return N(V);let Q=new TextDecoder().decode(J);return z(Q)}readBytes($){if($<0)return N(10);if(this.pos+$>this.data.length)return N(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,z(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return N(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,V]=this.readStruct($);if(V!==0)return N(V);Z.push(J)}return z(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,V]=this.readBytes($);if(V!==0)return N(V);Z.push(J)}return z(Z)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class m{parts=[];writeBigInt($){let Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,$,!1),this.parts.push(Z)}writeDate($){let Z=$.getTime();return this.writeVarInt(Z)}writeVarInt($){let[Z,J]=YV($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let Z=this.writeVarInt($.length);if(Z!==0)return Z;return this.writeBytes($),0}writeStruct($,Z){return $.encode(this,Z)}writeStructs($,Z){for(let J of Z){let V=this.writeStruct($,J);if(V!==0)return V}return 0}writeBytesSeq($){for(let Z of $)this.writeBytes(Z)}result(){let $=this.parts.reduce((V,Q)=>V+Q.length,0),Z=new Uint8Array($),J=0;for(let V of this.parts)Z.set(V,J),J+=V.length;return Z}*scan(){for(let $ of this.parts)yield $}}var x0={encode($,Z){let J=$.writeVarBytes(Z.id);if(J!==0)return J;let V=$.writeDate(Z.ts);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return N(J);let[V,Q]=$.readDate();if(Q!==0)return N(Q);return z({id:Z,ts:V})}};function zZ($){let Z=new m,J=Z.writeStruct(x0,$);if(J!==0)return N(J);let V=Z.result();return z(V)}var K$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let V=$.writeVarInt(Z.off);if(V!==0)return V;let Q=$.writeVarInt(Z.ctr);if(Q!==0)return Q;let W=$.writeVarInt(Z.len);if(W!==0)return W;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return N(J);let V=new c(Z),[,Q]=x0.decode(V);if(Q!==0)return N(Q);let[W,X]=$.readVarInt();if(X!==0)return N(X);let[I,Y]=$.readVarInt();if(Y!==0)return N(Y);let[G,P]=$.readVarInt();if(P!==0)return N(P);let M;if(G>0){let[R,w]=$.readBytes(wZ);if(w!==0)return N(w);M=R}return z({eid:Z,off:W,ctr:I,len:G,hsh:M})}};function FZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function NV($,Z,J){let V=g0(Z.privateKey,$);return(await J.blake3(V)).slice(0,D0)}async function HZ($,Z,J,V){let Q;if($.bod&&$.len>0)Q=await J.blake3($.bod);let W=new m,X=K$.encode(W,{...$,hsh:Q});if(X!==0)return N(X);let I=W.result(),Y=await NV(I,Z,J),G=await V.deriveFromKDM(Y),P=await J.encryptXSalsa20Poly1305Combined(I,G),M=$.bod?await J.encryptXSalsa20Poly1305Combined($.bod,G):new Uint8Array(0),R=await J.signEd25519(P,Z.privateKey);return z({sig:R,kdm:Y,headCph:P,bodyCph:M})}async function TZ($,Z,J,V,Q){let W=new c($),[X,I]=K$.decode(W);if(I!==0)return N(14);let Y;try{Y=Z&&Z.length>0?await V.decryptXSalsa20Poly1305Combined(Z,J):void 0}catch{return N(20)}let G=X.hsh&&Y===void 0,P=X.hsh===void 0&&Y!==void 0;if(G||P)return N(19);if(X.hsh&&Y){let R=await V.blake3(Y);if(!PZ(R,X.hsh))return N(19)}let M=Q??await V.blake3($);return z({msgHead:X,bod:Y,headHash:M})}async function U$($,Z,J){let V=new m,Q=V.writeDate(Z);if(Q!==0)return N(Q);let W=V.result(),X=await J.signEd25519(W,$.privateKey);return z({pubKey:$.publicKey,sig:X,timestamp:Z})}async function e($,Z,J){let V=J.now().getTime(),Q=$.timestamp.getTime();if(Math.abs(V-Q)>OZ)return 4;let X=new m;X.writeDate($.timestamp);let I=X.result();if(!await Z.checkSigEd25519($.sig,I,$.pubKey))return 3;return 0}class C0{now(){return new Date}}function AZ($,Z,J,V){let Q=Z.getTime()-$.getTime(),W=J.getTime()-V.getTime();return(Q+W)/2}var f0={encode($,Z){if($.writeVarInt(Z.quota),Z.quota>0){if(Z.usage===void 0)return 9;$.writeVarInt(Z.usage)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return N(J);let V;if(Z>0){let[Q,W]=$.readVarInt();if(W!==0)return N(W);V=Q}return z({quota:Z,usage:V})}};var S0={encode($,Z){$.writeBytes(new Uint8Array([Z.status]));let J=$.writeDate(Z.timeRcvd);if(J!==0)return J;let V=$.writeDate(Z.timeSent);if(V!==0)return V;let Q=$.writeVarInt(Z.subscription.term);if(Q!==0)return Q;let W=$.writeVarInt(Z.subscription.elapsed);if(W!==0)return W;let X=$.writeStruct(f0,Z.subscription.stat);if(X!==0)return X;let I=$.writeStruct(f0,Z.subscription.dyn);if(I!==0)return I;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return N(J);let V=Z[0],[Q,W]=$.readDate();if(W!==0)return N(W);let[X,I]=$.readDate();if(I!==0)return N(I);let[Y,G]=$.readVarInt();if(G!==0)return N(G);let[P,M]=$.readVarInt();if(M!==0)return N(M);let[R,w]=$.readStruct(f0);if(w!==0)return N(w);let[U,K]=$.readStruct(f0);if(K!==0)return N(K);return z({status:V,timeRcvd:Q,timeSent:X,subscription:{term:Y,elapsed:P,stat:R,dyn:U}})}};async function z$($,Z,J){let{crypto:V,enclave:Q}=$,W=await Q.derive(Z,J);return await V.deriveEd25519KeyPair(W)}var F$={encode($,Z){let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let V=$.writeVarInt(Z.seq);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return N(J);let[V,Q]=$.readVarInt();if(Q!==0)return N(Q);return z({headCph:Z,seq:V})}};var o={encode($,Z){$.writeBytes(Z.pubKey),$.writeBytes(Z.sig);let J=$.writeDate(Z.timestamp);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(RZ);if(J!==0)return N(J);let[V,Q]=$.readBytes(A0);if(Q!==0)return N(Q);let[W,X]=$.readDate();if(X!==0)return N(X);return z({pubKey:Z,sig:V,timestamp:W})}};var DZ={async encodeReq($,Z,J,V,Q){let W=Q.writeStruct(o,J);if(W!==0)return W;for(let X of V)Q.writeVarInt(X);return 0},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W}=$,[X,I]=Z.readStruct(o);if(I!==0)return I;let Y=await e(X,Q,V);if(Y!==0)return Y;let{pubKey:G}=X,[P,M]=await W.hasUser(G);if(M!==0)return M;if(!P)return 5;let[R,w]=Z.readVarInt();if(w!==0)return w;if(!Z.done())return 8;let[U,K]=await W.listHeads(G,R);if(K!==0)return K;return J.writeStructs(F$,U)},decodeResp($){return $.readStructs(F$)}};var H$={encode($,Z){$.writeVarInt(Z.seq);let J=$.writeVarBytes(Z.bodyCph);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return N(J);let[V,Q]=$.readVarBytes();if(Q!==0)return N(Q);return z({seq:Z,bodyCph:V})}};var CZ={async encodeReq($,Z,J,V,Q){let W=Q.writeStruct(o,J);if(W!==0)return W;for(let X of V){let I=Q.writeVarInt(X);if(I!==0)return I}return 0},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W}=$,[X,I]=Z.readStruct(o);if(I!==0)return I;let Y=await e(X,Q,V);if(Y!==0)return Y;let{pubKey:G}=X,[P,M]=await W.hasUser(G);if(M!==0)return M;if(!P)return 5;let R=[];while(!Z.done()){let[K,H]=Z.readVarInt();if(H!==0)return H;R.push(K)}console.info(`PULL: ${R.length} bags`);let[w,U]=await W.getBodies(G,R);if(U!==0)return U;if(!w)return 17;for(let{seq:K,bodyCph:H}of w){let T={seq:K,bodyCph:H},D=J.writeStruct(H$,T);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(H$)}};var T$={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let V=$.writeVarBytes(Z.bodyCph);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readBytes(A0);if(J!==0)return N(J);let[V,Q]=$.readBytes(D0);if(Q!==0)return N(Q);let[W,X]=$.readVarBytes();if(X!==0)return N(X);let[I,Y]=$.readVarBytes();if(Y!==0)return N(Y);return z({sig:Z,kdm:V,headCph:W,bodyCph:I})}};var A$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let V=$.writeVarBytes(Z.headCph);if(V!==0)return V;let Q=Z.bodyCph?Z.bodyCph.length:0,W=$.writeVarInt(Q);if(W!==0)return W;if(Q>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return N(J);let[V,Q]=$.readVarBytes();if(Q!==0)return N(Q);let[W,X]=$.readVarInt();if(X!==0)return N(X);let I;if(W>0){let[Y,G]=$.readBytes(W);if(G!==0)return N(G);I=Y}return z({seq:Z,headCph:V,bodyCph:I})}};var E0={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(A0);if(J!==0)return N(J);let[V,Q]=$.readBytes(D0);if(Q!==0)return N(Q);let[W,X]=$.readVarBytes();if(X!==0)return N(X);return z({sig:Z,kdm:V,headCph:W})}};var h0={encode($,Z){if($.writeVarInt(Z.idx),$.writeBytes(new Uint8Array([Z.status])),Z.status===0)$.writeVarInt(Z.seq);return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return N(J);let[V,Q]=$.readBytes(1);if(Q!==0)return N(Q);let W=V[0];if(W!==0)return z({idx:Z,status:W});let[X,I]=$.readVarInt();if(I!==0)return N(I);return z({idx:Z,status:W,seq:X})}};var SZ={async encodeReq($,Z,J,V,Q){let W=Q.writeStruct(o,J);if(W!==0)return W;let X=Q.writeStructs(T$,V);if(X!==0)return X;return 0},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W,notifier:X}=$,[I,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(I,Q,V);if(G!==0)return G;let{pubKey:P}=I,[M,R]=await W.hasUser(P);if(R!==0)return R;if(!M)return 5;let[w,U]=Z.readStructs(T$);if(U!==0)return U;console.info(`PUSH: ${w.length} bags`);let K=[],H=[];for(let F=0;F<w.length;F++){let E=w[F];if(!await FZ(E,P,Q)){let n={idx:F,status:3},L=J.writeStruct(h0,n);if(L!==0)return L;continue}K.push(F),H.push(E)}let[T,D]=await W.setBags(P,H);if(D!==0)return D;if(!T||T.length!==H.length)return 17;let C=[];for(let F=0;F<H.length;F++){let E=H[F],k=K[F],n=T[F],L=new m,_=L.writeStruct(E0,E);if(_!==0)return _;let g=L.result(),q={seq:n,headCph:g};if(w.length===1&&E.bodyCph.length<=KZ)q.bodyCph=E.bodyCph;C.push(q);let x={idx:k,status:0,seq:n},B=J.writeStruct(h0,x);if(B!==0)return B}if(C.length>0){let F=new m,E=F.writeStructs(A$,C);if(E!==0)return E;let k=F.result();await Promise.resolve(X.push(P,k))}return 0},decodeResp($){return $.readStructs(h0)}};var EZ={async encodeReq($,Z,J,V,Q){return Q.writeStruct(o,J)},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W}=$,[X,I]=Z.readStruct(o);if(I!==0)return I;let Y=await e(X,Q,V);if(Y!==0)return Y;let{pubKey:G}=X;if(!Z.done())return 8;let[P,M]=await W.addUser(G);if(M!==0)return M;return 0},decodeResp($){return z(void 0)}};class D${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},V=()=>{}){let{url:Q}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let W=new m;W.writeStruct(o,$);let X=W.result(),I=h(X);return Q.searchParams.set("t",I),this.websocket=new WebSocket(Q),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),V()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(Y)=>{let G=new Uint8Array(Y.data);Z(G)},this.websocket.onerror=(Y)=>{console.log(`ERROR: ${JSON.stringify(Y)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var u={user:{path:"/user",endpoint:EZ,name:0},push:{path:"/push",endpoint:SZ,name:2},peek:{path:"/peek",endpoint:DZ,name:1},pull:{path:"/pull",endpoint:CZ,name:3}},PV={0:u.user,2:u.push,1:u.peek,3:u.pull},mZ={[u.user.path]:u.user,[u.push.path]:u.push,[u.peek.path]:u.peek,[u.pull.path]:u.pull};class LZ{url;listener;constructor($){this.url=$;this.listener=new D$($)}async call($,Z){let{path:J}=PV[$],V=new URL(J,this.url);try{return await qV(V,Z)}catch{return N(25)}}}var C$=($)=>{return new LZ($.handle)};function m0($){let Z=new m;if(Z.writeStruct(S0,$)!==0)return new Response(null,{status:500});return S$(Z)}function S$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var MV={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function E$($){return new Response($.body,{headers:{...$.headers,...MV},status:$.status,statusText:$.statusText})}async function qV($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return N(24);let V=await c.fromResponse(J);return z(V)}class c0{enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,V,Q,W){this.enclave=$;this.crypto=Z;this.host=J;this.clock=V;this.transport=Q;this.updateHostMeta=W}async call($,Z){let{clock:J,crypto:V,transport:Q}=this,{endpoint:W,name:X}=$,I=await this.keys(),Y=J.now(),[G,P]=await U$(I,Y,V);if(P!==0)return N(P);let M=new m,R=await W.encodeReq(this,I,G,Z,M);if(R!==0)return N(R);let w=J.now(),[U,K]=await Q.call(X,M),H=J.now();if(K!==0)return N(K);let[T,D]=U.readStruct(S0);if(D!==0)return N(D);if(T.status!==0)return N(T.status);let F={clockOffset:AZ(w,T.timeRcvd,T.timeSent,H),subscription:T.subscription},E=await this.updateHostMeta(F);if(E!==0)return N(E);return W.decodeResp(U)}keys=()=>{let{host:$}=this;return z$(this,$.label,$.idx)};seal=async($)=>{let{crypto:Z,enclave:J}=this,V=await this.keys();return HZ($,V,Z,J)};register=()=>this.call(u.user,[]);peek=($)=>this.call(u.peek,[$]);push=($)=>this.call(u.push,$);pull=($)=>this.call(u.pull,$);listen=async($,Z,J)=>{let{clock:V,crypto:Q,host:W,transport:X}=this,{listener:I}=X,Y=await z$(this,W.label,W.idx),G=V.now(),[P,M]=await U$(Y,G,Q);if(M!==0)return M;return await I.connect(P,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class m${seed;crypto;constructor($,Z){this.seed=$,this.crypto=Z}async deriveFromKDM($){let Z=g0(this.seed,$);return await this.crypto.blake3(Z)}async derive($,Z=0){let J=new TextEncoder().encode($),V=new Uint8Array(8);new DataView(V.buffer).setBigUint64(0,BigInt(Z),!1);let Q=g0(J,V);return await this.deriveFromKDM(Q)}}class L${listeners=new Map;addEventListener($,Z){let J=this.listeners.get($);if(!J)J=new Set,this.listeners.set($,J);return J.add(Z),()=>{this.removeEventListener($,Z)}}removeEventListener($,Z){let J=this.listeners.get($);if(J){if(J.delete(Z),J.size===0)this.listeners.delete($)}}emit($,Z){let J=this.listeners.get($);if(J){let V=Array.from(J);for(let Q of V)Q(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function jZ($,Z,J,V=0){let Q=Z.now(),W=new m,X=W.writeVarString($);if(X!==0)return N(X);let Y={id:W.result(),ts:new Date(0)},[G,P]=zZ(Y);if(P!==0)return N(P);let M=Q.getTime()-Y.ts.getTime();return z({eid:G,off:M,ctr:V,len:J.length,bod:J})}class RV{singletonType;latest;latestOff=-1;emitter=new L$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new c(Z.eid),[V,Q]=J.readStruct(x0);if(Q!==0)continue;let W=new m;W.writeVarString(this.singletonType);let X=W.result();if(V.id.length===X.length&&V.id.every((I,Y)=>I===X[Y])){if(this.latest===void 0||Z.off>this.latestOff)this.latestOff=Z.off,this.latest=Z.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 Z of $)if(Z===this.singletonType)this.emitter.emit(this.singletonType,null)};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function kZ($,Z,J,V){let Q=new c($.headCph),[W,X]=Q.readStruct(E0);if(X!==0)return N(X);let{sig:I,kdm:Y,headCph:G}=W;if(!await V.checkSigEd25519(I,G,Z.publicKey))return N(3);let M=await J.deriveFromKDM(Y),R;try{R=await V.decryptXSalsa20Poly1305Combined(G,M)}catch{return N(20)}return z({kdm:Y,headEnc:R})}var j0=pJ(_J(),1),BQ={encode:j0.encode,decode:j0.decode,decodeAsync:j0.decodeAsync},gQ=BQ;import{Database as xQ}from"bun:sqlite";var vY=Symbol("EntityID");var iY=Symbol("MasterSeed"),lY=Symbol("DerivationSeed"),yY=Symbol("PublicKey"),rY=Symbol("PrivateKey"),nY=Symbol("HostSpecificKeyPair"),dY=Symbol("Hash"),G0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function fQ($="diplomatic.db"){let Z=new xQ($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
|
|
1
|
+
var yJ=Object.create;var{getPrototypeOf:lJ,defineProperty:b$,getOwnPropertyNames:iJ}=Object;var uJ=Object.prototype.hasOwnProperty;function dJ($){return this[$]}var rJ,bJ,pJ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var V=Z?rJ??=new WeakMap:bJ??=new WeakMap,W=V.get($);if(W)return W}J=$!=null?yJ(lJ($)):{};let X=Z||!$||!$.__esModule?b$(J,"default",{value:$,enumerable:!0}):J;for(let Y of iJ($))if(!uJ.call(X,Y))b$(X,Y,{get:dJ.bind($,Y),enumerable:!0});if(Q)V.set($,X);return X};var n=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var o0=n((fZ)=>{Object.defineProperty(fZ,"__esModule",{value:!0});fZ.utf8Count=KQ;fZ.utf8EncodeJs=_Z;fZ.utf8EncodeTE=BZ;fZ.utf8Encode=OQ;fZ.utf8DecodeJs=gZ;fZ.utf8DecodeTD=xZ;fZ.utf8Decode=TQ;function KQ($){let Z=$.length,J=0,Q=0;while(Q<Z){let V=$.charCodeAt(Q++);if((V&4294967168)===0){J++;continue}else if((V&4294965248)===0)J+=2;else{if(V>=55296&&V<=56319){if(Q<Z){let W=$.charCodeAt(Q);if((W&64512)===56320)++Q,V=((V&1023)<<10)+(W&1023)+65536}}if((V&4294901760)===0)J+=3;else J+=4}}return J}function _Z($,Z,J){let Q=$.length,V=J,W=0;while(W<Q){let X=$.charCodeAt(W++);if((X&4294967168)===0){Z[V++]=X;continue}else if((X&4294965248)===0)Z[V++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(W<Q){let Y=$.charCodeAt(W);if((Y&64512)===56320)++W,X=((X&1023)<<10)+(Y&1023)+65536}}if((X&4294901760)===0)Z[V++]=X>>12&15|224,Z[V++]=X>>6&63|128;else Z[V++]=X>>18&7|240,Z[V++]=X>>12&63|128,Z[V++]=X>>6&63|128}Z[V++]=X&63|128}}var UQ=new TextEncoder,zQ=50;function BZ($,Z,J){UQ.encodeInto($,Z.subarray(J))}function OQ($,Z,J){if($.length>zQ)BZ($,Z,J);else _Z($,Z,J)}var wQ=4096;function gZ($,Z,J){let Q=Z,V=Q+J,W=[],X="";while(Q<V){let Y=$[Q++];if((Y&128)===0)W.push(Y);else if((Y&224)===192){let G=$[Q++]&63;W.push((Y&31)<<6|G)}else if((Y&240)===224){let G=$[Q++]&63,N=$[Q++]&63;W.push((Y&31)<<12|G<<6|N)}else if((Y&248)===240){let G=$[Q++]&63,N=$[Q++]&63,P=$[Q++]&63,q=(Y&7)<<18|G<<12|N<<6|P;if(q>65535)q-=65536,W.push(q>>>10&1023|55296),q=56320|q&1023;W.push(q)}else W.push(Y);if(W.length>=wQ)X+=String.fromCharCode(...W),W.length=0}if(W.length>0)X+=String.fromCharCode(...W);return X}var FQ=new TextDecoder,HQ=200;function xZ($,Z,J){let Q=$.subarray(Z,Z+J);return FQ.decode(Q)}function TQ($,Z,J){if(J>HQ)return xZ($,Z,J);else return gZ($,Z,J)}});var k$=n((yZ)=>{Object.defineProperty(yZ,"__esModule",{value:!0});yZ.ExtData=void 0;class vZ{type;data;constructor($,Z){this.type=$,this.data=Z}}yZ.ExtData=vZ});var s0=n((iZ)=>{Object.defineProperty(iZ,"__esModule",{value:!0});iZ.DecodeError=void 0;class a0 extends Error{constructor($){super($);let Z=Object.create(a0.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:a0.name})}}iZ.DecodeError=a0});var t0=n((dZ)=>{Object.defineProperty(dZ,"__esModule",{value:!0});dZ.UINT32_MAX=void 0;dZ.setUint64=kQ;dZ.setInt64=mQ;dZ.getInt64=_Q;dZ.getUint64=BQ;dZ.UINT32_MAX=4294967295;function kQ($,Z,J){let Q=J/4294967296,V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function mQ($,Z,J){let Q=Math.floor(J/4294967296),V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function _Q($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function BQ($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var m$=n((aZ)=>{Object.defineProperty(aZ,"__esModule",{value:!0});aZ.timestampExtension=aZ.EXT_TIMESTAMP=void 0;aZ.encodeTimeSpecToTimestamp=pZ;aZ.encodeDateToTimeSpec=nZ;aZ.encodeTimestampExtension=hZ;aZ.decodeTimestampToTimeSpec=cZ;aZ.decodeTimestampExtension=oZ;var yQ=s0(),bZ=t0();aZ.EXT_TIMESTAMP=-1;var lQ=4294967295,iQ=17179869183;function pZ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=iQ)if(Z===0&&$<=lQ){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,V=new Uint8Array(8),W=new DataView(V.buffer);return W.setUint32(0,Z<<2|J&3),W.setUint32(4,Q),V}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,bZ.setInt64)(Q,4,$),J}}function nZ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,V=Math.floor(Q/1e9);return{sec:J+V,nsec:Q-V*1e9}}function hZ($){if($ instanceof Date){let Z=nZ($);return pZ(Z)}else return null}function cZ($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let J=Z.getUint32(0),Q=0;return{sec:J,nsec:0}}case 8:{let J=Z.getUint32(0),Q=Z.getUint32(4),V=(J&3)*4294967296+Q,W=J>>>2;return{sec:V,nsec:W}}case 12:{let J=(0,bZ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new yQ.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function oZ($){let Z=cZ($);return new Date(Z.sec*1000+Z.nsec/1e6)}aZ.timestampExtension={type:aZ.EXT_TIMESTAMP,encode:hZ,decode:oZ}});var $$=n((eZ)=>{Object.defineProperty(eZ,"__esModule",{value:!0});eZ.ExtensionCodec=void 0;var e0=k$(),nQ=m$();class _${static defaultCodec=new _$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(nQ.timestampExtension)}register({type:$,encode:Z,decode:J}){if($>=0)this.encoders[$]=Z,this.decoders[$]=J;else{let Q=-1-$;this.builtInEncoders[Q]=Z,this.builtInDecoders[Q]=J}}tryToEncode($,Z){for(let J=0;J<this.builtInEncoders.length;J++){let Q=this.builtInEncoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let W=-1-J;return new e0.ExtData(W,V)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let W=J;return new e0.ExtData(W,V)}}}if($ instanceof e0.ExtData)return $;return null}decode($,Z,J){let Q=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(Q)return Q($,Z,J);else return new e0.ExtData(Z,$)}}eZ.ExtensionCodec=_$});var B$=n((ZJ)=>{Object.defineProperty(ZJ,"__esModule",{value:!0});ZJ.ensureUint8Array=cQ;function hQ($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function cQ($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(hQ($))return new Uint8Array($);else return Uint8Array.from($)}});var x$=n((VJ)=>{Object.defineProperty(VJ,"__esModule",{value:!0});VJ.Encoder=VJ.DEFAULT_INITIAL_BUFFER_SIZE=VJ.DEFAULT_MAX_DEPTH=void 0;var JJ=o0(),aQ=$$(),QJ=t0(),sQ=B$();VJ.DEFAULT_MAX_DEPTH=100;VJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class g${extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??aQ.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??VJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??VJ.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 g$({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($,Z){if(Z>this.maxDepth)throw Error(`Too deep objects in depth ${Z}`);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($,Z)}ensureBufferSizeToWrite($){let Z=this.pos+$;if(this.view.byteLength<Z)this.resizeBuffer(Z*2)}resizeBuffer($){let Z=new ArrayBuffer($),J=new Uint8Array(Z),Q=new DataView(Z);J.set(this.bytes),this.view=Q,this.bytes=J}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 J=(0,JJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,JJ.utf8Encode)($,this.bytes,this.pos),this.pos+=J}encodeObject($,Z){let J=this.extensionCodec.tryToEncode($,this.context);if(J!=null)this.encodeExtension(J);else if(Array.isArray($))this.encodeArray($,Z);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,Z);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let Z=$.byteLength;if(Z<256)this.writeU8(196),this.writeU8(Z);else if(Z<65536)this.writeU8(197),this.writeU16(Z);else if(Z<4294967296)this.writeU8(198),this.writeU32(Z);else throw Error(`Too large binary: ${Z}`);let J=(0,sQ.ensureUint8Array)($);this.writeU8a(J)}encodeArray($,Z){let J=$.length;if(J<16)this.writeU8(144+J);else if(J<65536)this.writeU8(220),this.writeU16(J);else if(J<4294967296)this.writeU8(221),this.writeU32(J);else throw Error(`Too large array: ${J}`);for(let Q of $)this.doEncode(Q,Z+1)}countWithoutUndefined($,Z){let J=0;for(let Q of Z)if($[Q]!==void 0)J++;return J}encodeMap($,Z){let J=Object.keys($);if(this.sortKeys)J.sort();let Q=this.ignoreUndefined?this.countWithoutUndefined($,J):J.length;if(Q<16)this.writeU8(128+Q);else if(Q<65536)this.writeU8(222),this.writeU16(Q);else if(Q<4294967296)this.writeU8(223),this.writeU32(Q);else throw Error(`Too large map object: ${Q}`);for(let V of J){let W=$[V];if(!(this.ignoreUndefined&&W===void 0))this.encodeString(V),this.doEncode(W,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),Q=J.length;if(Q>=4294967296)throw Error(`Too large extension object: ${Q}`);this.writeU8(201),this.writeU32(Q),this.writeI8($.type),this.writeU8a(J);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}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,QJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,QJ.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}}VJ.Encoder=g$});var NJ=n((GJ)=>{Object.defineProperty(GJ,"__esModule",{value:!0});GJ.encode=eQ;var tQ=x$();function eQ($,Z){return new tQ.Encoder(Z).encodeSharedRef($)}});var PJ=n((IJ)=>{Object.defineProperty(IJ,"__esModule",{value:!0});IJ.prettyByte=ZV;function ZV($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var KJ=n((MJ)=>{Object.defineProperty(MJ,"__esModule",{value:!0});MJ.CachedKeyDecoder=void 0;var QV=o0(),VV=16,WV=16;class qJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=VV,Z=WV){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let J=0;J<this.maxKeyLength;J++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,J){let Q=this.caches[J-1];$:for(let V of Q){let W=V.bytes;for(let X=0;X<J;X++)if(W[X]!==$[Z+X])continue $;return V.str}return null}store($,Z){let J=this.caches[$.length-1],Q={bytes:$,str:Z};if(J.length>=this.maxLengthPerKey)J[Math.random()*J.length|0]=Q;else J.push(Q)}decode($,Z,J){let Q=this.find($,Z,J);if(Q!=null)return this.hit++,Q;this.miss++;let V=(0,QV.utf8DecodeJs)($,Z,J),W=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(W,V),V}}MJ.CachedKeyDecoder=qJ});var Z$=n((FJ)=>{Object.defineProperty(FJ,"__esModule",{value:!0});FJ.Decoder=void 0;var f$=PJ(),XV=$$(),M0=t0(),YV=o0(),UJ=B$(),GV=KJ(),G0=s0(),v$="array",y0="map_key",OJ="map_value",NV=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new G0.DecodeError("The type of key must be string or number but "+typeof $)};class wJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=v$,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=y0,Z.readCount=0,Z.size=$,Z.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===v$){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===y0||$.type===OJ){let J=$;J.size=0,J.map=void 0,J.readCount=0,J.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var v0=-1,y$=new DataView(new ArrayBuffer(0)),IV=new Uint8Array(y$.buffer);try{y$.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 zJ=RangeError("Insufficient data"),PV=new GV.CachedKeyDecoder;class l${extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=y$;bytes=IV;headByte=v0;stack=new wJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??XV.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:PV,this.mapKeyConverter=$?.mapKeyConverter??NV}clone(){return new l$({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=v0,this.stack.reset()}setBuffer($){let Z=(0,UJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===v0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,UJ.ensureUint8Array)($),Q=new Uint8Array(Z.length+J.length);Q.set(Z),Q.set(J,Z.length),this.setBuffer(Q)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}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 Z=!1,J;for await(let X of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{J=this.doDecodeSync(),Z=!0}catch(Y){if(!(Y instanceof RangeError))throw Y}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:Q,pos:V,totalPos:W}=this;throw RangeError(`Insufficient data in parsing ${(0,f$.prettyByte)(Q)} at ${W} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let J=Z,Q=-1;for await(let V of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(W){if(!(W instanceof RangeError))throw W}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let Q=$-128;if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($<160){let Q=$-144;if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else{let Q=$-160;Z=this.decodeString(Q,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let Q=this.lookU8();Z=this.decodeString(Q,1)}else if($===218){let Q=this.lookU16();Z=this.decodeString(Q,2)}else if($===219){let Q=this.lookU32();Z=this.decodeString(Q,4)}else if($===220){let Q=this.readU16();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===221){let Q=this.readU32();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===222){let Q=this.readU16();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===223){let Q=this.readU32();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===196){let Q=this.lookU8();Z=this.decodeBinary(Q,1)}else if($===197){let Q=this.lookU16();Z=this.decodeBinary(Q,2)}else if($===198){let Q=this.lookU32();Z=this.decodeBinary(Q,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let Q=this.lookU8();Z=this.decodeExtension(Q,1)}else if($===200){let Q=this.lookU16();Z=this.decodeExtension(Q,2)}else if($===201){let Q=this.lookU32();Z=this.decodeExtension(Q,4)}else throw new G0.DecodeError(`Unrecognized type byte: ${(0,f$.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===v$)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===y0){if(Z==="__proto__")throw new G0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=OJ;continue $}else if(Q.map[Q.key]=Z,Q.readCount++,Q.readCount===Q.size)Z=Q.map,J.release(Q);else{Q.key=null,Q.type=y0;continue $}}return Z}}readHeadByte(){if(this.headByte===v0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=v0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new G0.DecodeError(`Unrecognized array type byte: ${(0,f$.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new G0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new G0.DecodeError(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,Z){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,Z);return this.decodeBinary($,Z)}decodeUtf8String($,Z){if($>this.maxStrLength)throw new G0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw zJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,YV.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===y0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new G0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw zJ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new G0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let J=this.view.getInt8(this.pos+Z),Q=this.decodeBinary($,Z+1);return this.extensionCodec.decode(Q,J,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,$}}FJ.Decoder=l$});var CJ=n((AJ)=>{Object.defineProperty(AJ,"__esModule",{value:!0});AJ.decode=qV;AJ.decodeMulti=MV;var TJ=Z$();function qV($,Z){return new TJ.Decoder(Z).decode($)}function MV($,Z){return new TJ.Decoder(Z).decodeMulti($)}});var LJ=n((EJ)=>{Object.defineProperty(EJ,"__esModule",{value:!0});EJ.isAsyncIterable=DJ;EJ.asyncIterableFromStream=SJ;EJ.ensureAsyncIterable=UV;function DJ($){return $[Symbol.asyncIterator]!=null}async function*SJ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function UV($){if(DJ($))return $;else return SJ($)}});var kJ=n((jJ)=>{Object.defineProperty(jJ,"__esModule",{value:!0});jJ.decodeAsync=FV;jJ.decodeArrayStream=HV;jJ.decodeMultiStream=TV;var i$=Z$(),u$=LJ();async function FV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new i$.Decoder(Z).decodeAsync(J)}function HV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new i$.Decoder(Z).decodeArrayStream(J)}function TV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new i$.Decoder(Z).decodeStream(J)}});var _J=n((f)=>{Object.defineProperty(f,"__esModule",{value:!0});f.decodeTimestampExtension=f.encodeTimestampExtension=f.decodeTimestampToTimeSpec=f.encodeTimeSpecToTimestamp=f.encodeDateToTimeSpec=f.EXT_TIMESTAMP=f.ExtData=f.ExtensionCodec=f.Encoder=f.DecodeError=f.Decoder=f.decodeMultiStream=f.decodeArrayStream=f.decodeAsync=f.decodeMulti=f.decode=f.encode=void 0;var SV=NJ();Object.defineProperty(f,"encode",{enumerable:!0,get:function(){return SV.encode}});var mJ=CJ();Object.defineProperty(f,"decode",{enumerable:!0,get:function(){return mJ.decode}});Object.defineProperty(f,"decodeMulti",{enumerable:!0,get:function(){return mJ.decodeMulti}});var d$=kJ();Object.defineProperty(f,"decodeAsync",{enumerable:!0,get:function(){return d$.decodeAsync}});Object.defineProperty(f,"decodeArrayStream",{enumerable:!0,get:function(){return d$.decodeArrayStream}});Object.defineProperty(f,"decodeMultiStream",{enumerable:!0,get:function(){return d$.decodeMultiStream}});var EV=Z$();Object.defineProperty(f,"Decoder",{enumerable:!0,get:function(){return EV.Decoder}});var LV=s0();Object.defineProperty(f,"DecodeError",{enumerable:!0,get:function(){return LV.DecodeError}});var jV=x$();Object.defineProperty(f,"Encoder",{enumerable:!0,get:function(){return jV.Encoder}});var kV=$$();Object.defineProperty(f,"ExtensionCodec",{enumerable:!0,get:function(){return kV.ExtensionCodec}});var mV=k$();Object.defineProperty(f,"ExtData",{enumerable:!0,get:function(){return mV.ExtData}});var j0=m$();Object.defineProperty(f,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return j0.EXT_TIMESTAMP}});Object.defineProperty(f,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return j0.encodeDateToTimeSpec}});Object.defineProperty(f,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return j0.encodeTimeSpecToTimestamp}});Object.defineProperty(f,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return j0.decodeTimestampToTimeSpec}});Object.defineProperty(f,"encodeTimestampExtension",{enumerable:!0,get:function(){return j0.encodeTimestampExtension}});Object.defineProperty(f,"decodeTimestampExtension",{enumerable:!0,get:function(){return j0.decodeTimestampExtension}})});import*as Q0 from"node:crypto";var I0=Q0&&typeof Q0==="object"&&"webcrypto"in Q0?Q0.webcrypto:Q0&&typeof Q0==="object"&&("randomBytes"in Q0)?Q0:void 0;function l0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function J$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function u($,...Z){if(!J$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function Q$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function p$($,Z){u($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function V$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var V0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var nJ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!nJ)throw Error("Non little-endian hardware is not supported");function hJ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function i0($){if(typeof $==="string")$=hJ($);else if(J$($))$=u0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function n$($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function h$($,Z){if($.length!==Z.length)return!1;let J=0;for(let Q=0;Q<$.length;Q++)J|=$[Q]^Z[Q];return J===0}var c$=($,Z)=>{function J(Q,...V){if(u(Q),$.nonceLength!==void 0){let P=V[0];if(!P)throw Error("nonce / iv required");if($.varSizeNonce)u(P);else u(P,$.nonceLength)}let W=$.tagLength;if(W&&V[1]!==void 0)u(V[1]);let X=Z(Q,...V),Y=(P,q)=>{if(q!==void 0){if(P!==2)throw Error("cipher output not supported");u(q)}},G=!1;return{encrypt(P,q){if(G)throw Error("cannot encrypt() twice with same key + nonce");return G=!0,u(P),Y(X.encrypt.length,q),X.encrypt(P,q)},decrypt(P,q){if(u(P),W&&P.length<W)throw Error("invalid ciphertext length: smaller than tagLength="+W);return Y(X.decrypt.length,q),X.decrypt(P,q)}}}return Object.assign(J,$),J};function W$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!cJ(Z))throw Error("invalid output, must be aligned");return Z}function cJ($){return $.byteOffset%4===0}function u0($){return Uint8Array.from($)}function $0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function d0($=32){if(I0&&typeof I0.getRandomValues==="function")return I0.getRandomValues(new Uint8Array($));if(I0&&typeof I0.randomBytes==="function")return I0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var a$=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),oJ=a$("expand 16-byte k"),aJ=a$("expand 32-byte k"),sJ=V0(oJ),tJ=V0(aJ);function U($,Z){return $<<Z|$>>>32-Z}function X$($){return $.byteOffset%4===0}var r0=64,eJ=16,s$=4294967295,o$=new Uint32Array;function $Q($,Z,J,Q,V,W,X,Y){let G=V.length,N=new Uint8Array(r0),P=V0(N),q=X$(V)&&X$(W),R=q?V0(V):o$,K=q?V0(W):o$;for(let O=0;O<G;X++){if($(Z,J,Q,P,X,Y),X>=s$)throw Error("arx: counter overflow");let z=Math.min(r0,G-O);if(q&&z===r0){let H=O/4;if(O%4!==0)throw Error("arx: invalid block position");for(let T=0,C;T<eJ;T++)C=H+T,K[C]=R[C]^P[T];O+=r0;continue}for(let H=0,T;H<z;H++)T=O+H,W[T]=V[T]^N[H];O+=z}}function t$($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:V,counterRight:W,rounds:X}=n$({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return l0(V),l0(X),V$(W),V$(J),(Y,G,N,P,q=0)=>{u(Y),u(G),u(N);let R=N.length;if(P===void 0)P=new Uint8Array(R);if(u(P),l0(q),q<0||q>=s$)throw Error("arx: counter overflow");if(P.length<R)throw Error(`arx: output (${P.length}) is shorter than data (${R})`);let K=[],O=Y.length,z,H;if(O===32)K.push(z=u0(Y)),H=tJ;else if(O===16&&J)z=new Uint8Array(32),z.set(Y),z.set(Y,16),H=sJ,K.push(z);else throw Error(`arx: invalid 32-byte key, got length=${O}`);if(!X$(G))K.push(G=u0(G));let T=V0(z);if(Q){if(G.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(H,T,V0(G.subarray(0,16)),T),G=G.subarray(16)}let C=16-V;if(C!==G.length)throw Error(`arx: nonce must be ${C} or 16 bytes`);if(C!==12){let F=new Uint8Array(12);F.set(G,W?0:12-G.length),G=F,K.push(G)}let D=V0(G);return $Q($,H,T,D,N,P,q,X),$0(...K),P}}var r=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class e${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,$=i0($),u($,32);let Z=r($,0),J=r($,2),Q=r($,4),V=r($,6),W=r($,8),X=r($,10),Y=r($,12),G=r($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|Q<<6)&7939,this.r[3]=(Q>>>7|V<<9)&8191,this.r[4]=(V>>>4|W<<12)&255,this.r[5]=W>>>1&8190,this.r[6]=(W>>>14|X<<2)&8191,this.r[7]=(X>>>11|Y<<5)&8065,this.r[8]=(Y>>>8|G<<8)&8191,this.r[9]=G>>>5&127;for(let N=0;N<8;N++)this.pad[N]=r($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:V,r:W}=this,X=W[0],Y=W[1],G=W[2],N=W[3],P=W[4],q=W[5],R=W[6],K=W[7],O=W[8],z=W[9],H=r($,Z+0),T=r($,Z+2),C=r($,Z+4),D=r($,Z+6),F=r($,Z+8),E=r($,Z+10),m=r($,Z+12),d=r($,Z+14),j=V[0]+(H&8191),_=V[1]+((H>>>13|T<<3)&8191),g=V[2]+((T>>>10|C<<6)&8191),M=V[3]+((C>>>7|D<<9)&8191),x=V[4]+((D>>>4|F<<12)&8191),B=V[5]+(F>>>1&8191),v=V[6]+((F>>>14|E<<2)&8191),y=V[7]+((E>>>11|m<<5)&8191),l=V[8]+((m>>>8|d<<8)&8191),i=V[9]+(d>>>5|Q),A=0,p=A+j*X+_*(5*z)+g*(5*O)+M*(5*K)+x*(5*R);A=p>>>13,p&=8191,p+=B*(5*q)+v*(5*P)+y*(5*N)+l*(5*G)+i*(5*Y),A+=p>>>13,p&=8191;let a=A+j*Y+_*X+g*(5*z)+M*(5*O)+x*(5*K);A=a>>>13,a&=8191,a+=B*(5*R)+v*(5*q)+y*(5*P)+l*(5*N)+i*(5*G),A+=a>>>13,a&=8191;let t=A+j*G+_*Y+g*X+M*(5*z)+x*(5*O);A=t>>>13,t&=8191,t+=B*(5*K)+v*(5*R)+y*(5*q)+l*(5*P)+i*(5*N),A+=t>>>13,t&=8191;let k=A+j*N+_*G+g*Y+M*X+x*(5*z);A=k>>>13,k&=8191,k+=B*(5*O)+v*(5*K)+y*(5*R)+l*(5*q)+i*(5*P),A+=k>>>13,k&=8191;let J0=A+j*P+_*N+g*G+M*Y+x*X;A=J0>>>13,J0&=8191,J0+=B*(5*z)+v*(5*O)+y*(5*K)+l*(5*R)+i*(5*q),A+=J0>>>13,J0&=8191;let R0=A+j*q+_*P+g*N+M*G+x*Y;A=R0>>>13,R0&=8191,R0+=B*X+v*(5*z)+y*(5*O)+l*(5*K)+i*(5*R),A+=R0>>>13,R0&=8191;let K0=A+j*R+_*q+g*P+M*N+x*G;A=K0>>>13,K0&=8191,K0+=B*Y+v*X+y*(5*z)+l*(5*O)+i*(5*K),A+=K0>>>13,K0&=8191;let U0=A+j*K+_*R+g*q+M*P+x*N;A=U0>>>13,U0&=8191,U0+=B*G+v*Y+y*X+l*(5*z)+i*(5*O),A+=U0>>>13,U0&=8191;let z0=A+j*O+_*K+g*R+M*q+x*P;A=z0>>>13,z0&=8191,z0+=B*N+v*G+y*Y+l*X+i*(5*z),A+=z0>>>13,z0&=8191;let O0=A+j*z+_*O+g*K+M*R+x*q;A=O0>>>13,O0&=8191,O0+=B*P+v*N+y*G+l*Y+i*X,A+=O0>>>13,O0&=8191,A=(A<<2)+A|0,A=A+p|0,p=A&8191,A=A>>>13,a+=A,V[0]=p,V[1]=a,V[2]=t,V[3]=k,V[4]=J0,V[5]=R0,V[6]=K0,V[7]=U0,V[8]=z0,V[9]=O0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=Q,Q=$[X]>>>13,$[X]&=8191;$[0]+=Q*5,Q=$[0]>>>13,$[0]&=8191,$[1]+=Q,Q=$[1]>>>13,$[1]&=8191,$[2]+=Q,J[0]=$[0]+5,Q=J[0]>>>13,J[0]&=8191;for(let X=1;X<10;X++)J[X]=$[X]+Q,Q=J[X]>>>13,J[X]&=8191;J[9]-=8192;let V=(Q^1)-1;for(let X=0;X<10;X++)J[X]&=V;V=~V;for(let X=0;X<10;X++)$[X]=$[X]&V|J[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 W=$[0]+Z[0];$[0]=W&65535;for(let X=1;X<8;X++)W=($[X]+Z[X]|0)+(W>>>16)|0,$[X]=W&65535;$0(J)}update($){Q$(this);let{buffer:Z,blockLen:J}=this;$=i0($);let Q=$.length;for(let V=0;V<Q;){let W=Math.min(J-this.pos,Q-V);if(W===J){for(;J<=Q-V;V+=J)this.process($,V);continue}if(Z.set($.subarray(V,V+W),this.pos),this.pos+=W,V+=W,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){$0(this.h,this.r,this.buffer,this.pad)}digestInto($){Q$(this),p$($,this),this.finished=!0;let{buffer:Z,h:J}=this,{pos:Q}=this;if(Q){Z[Q++]=1;for(;Q<16;Q++)Z[Q]=0;this.process(Z,0,!0)}this.finalize();let V=0;for(let W=0;W<8;W++)$[V++]=J[W]>>>0,$[V++]=J[W]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function ZQ($){let Z=(Q,V)=>$(V).update(i0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var Y$=ZQ(($)=>new e$($));function JQ($,Z,J,Q,V,W=20){let X=$[0],Y=Z[0],G=Z[1],N=Z[2],P=Z[3],q=$[1],R=J[0],K=J[1],O=V,z=0,H=$[2],T=Z[4],C=Z[5],D=Z[6],F=Z[7],E=$[3],m=X,d=Y,j=G,_=N,g=P,M=q,x=R,B=K,v=O,y=z,l=H,i=T,A=C,p=D,a=F,t=E;for(let J0=0;J0<W;J0+=2)g^=U(m+A|0,7),v^=U(g+m|0,9),A^=U(v+g|0,13),m^=U(A+v|0,18),y^=U(M+d|0,7),p^=U(y+M|0,9),d^=U(p+y|0,13),M^=U(d+p|0,18),a^=U(l+x|0,7),j^=U(a+l|0,9),x^=U(j+a|0,13),l^=U(x+j|0,18),_^=U(t+i|0,7),B^=U(_+t|0,9),i^=U(B+_|0,13),t^=U(i+B|0,18),d^=U(m+_|0,7),j^=U(d+m|0,9),_^=U(j+d|0,13),m^=U(_+j|0,18),x^=U(M+g|0,7),B^=U(x+M|0,9),g^=U(B+x|0,13),M^=U(g+B|0,18),i^=U(l+y|0,7),v^=U(i+l|0,9),y^=U(v+i|0,13),l^=U(y+v|0,18),A^=U(t+a|0,7),p^=U(A+t|0,9),a^=U(p+A|0,13),t^=U(a+p|0,18);let k=0;Q[k++]=X+m|0,Q[k++]=Y+d|0,Q[k++]=G+j|0,Q[k++]=N+_|0,Q[k++]=P+g|0,Q[k++]=q+M|0,Q[k++]=R+x|0,Q[k++]=K+B|0,Q[k++]=O+v|0,Q[k++]=z+y|0,Q[k++]=H+l|0,Q[k++]=T+i|0,Q[k++]=C+A|0,Q[k++]=D+p|0,Q[k++]=F+a|0,Q[k++]=E+t|0}function QQ($,Z,J,Q){let V=$[0],W=Z[0],X=Z[1],Y=Z[2],G=Z[3],N=$[1],P=J[0],q=J[1],R=J[2],K=J[3],O=$[2],z=Z[4],H=Z[5],T=Z[6],C=Z[7],D=$[3];for(let E=0;E<20;E+=2)G^=U(V+H|0,7),R^=U(G+V|0,9),H^=U(R+G|0,13),V^=U(H+R|0,18),K^=U(N+W|0,7),T^=U(K+N|0,9),W^=U(T+K|0,13),N^=U(W+T|0,18),C^=U(O+P|0,7),X^=U(C+O|0,9),P^=U(X+C|0,13),O^=U(P+X|0,18),Y^=U(D+z|0,7),q^=U(Y+D|0,9),z^=U(q+Y|0,13),D^=U(z+q|0,18),W^=U(V+Y|0,7),X^=U(W+V|0,9),Y^=U(X+W|0,13),V^=U(Y+X|0,18),P^=U(N+G|0,7),q^=U(P+N|0,9),G^=U(q+P|0,13),N^=U(G+q|0,18),z^=U(O+K|0,7),R^=U(z+O|0,9),K^=U(R+z|0,13),O^=U(K+R|0,18),H^=U(D+C|0,7),T^=U(H+D|0,9),C^=U(T+H|0,13),D^=U(C+T|0,18);let F=0;Q[F++]=V,Q[F++]=N,Q[F++]=O,Q[F++]=D,Q[F++]=P,Q[F++]=q,Q[F++]=R,Q[F++]=K}var G$=t$(JQ,{counterRight:!0,extendNonceFn:QQ}),N$=c$({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=W$(J.length+32,Q,!1);let V=Q.subarray(0,32),W=Q.subarray(32);Q.set(J,32),$0(V),G$($,Z,Q,Q);let X=Y$(W,V);return Q.set(X,16),$0(Q.subarray(0,16),X),Q.subarray(16)},decrypt(J,Q){u(J),Q=W$(J.length+32,Q,!1);let V=Q.subarray(0,32),W=Q.subarray(32,48),X=Q.subarray(48);Q.set(J,32),$0(V);let Y=G$($,Z,V,V),G=Y$(X,Y);if(!h$(W,G))throw Error("invalid tag");return G$($,Z,Q.subarray(16),Q.subarray(16)),$0(V,W,G),X}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function VQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function m0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function P0($,...Z){if(!VQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function _0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function b0($,Z){P0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function $Z($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function w0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function F0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function B0($,Z){return $<<32-Z|$>>>Z}var ZZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function JZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var QZ=ZZ?($)=>$:($)=>JZ($);function WQ($){for(let Z=0;Z<$.length;Z++)$[Z]=JZ($[Z]);return $}var s=ZZ?($)=>$:WQ;function XQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function H0($){if(typeof $==="string")$=XQ($);return P0($),$}class I${}function VZ($){let Z=(Q,V)=>$(V).update(H0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var WZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var p0=BigInt(4294967295),XZ=BigInt(32);function P$($,Z=!1){if(Z)return{h:Number($&p0),l:Number($>>XZ&p0)};return{h:Number($>>XZ&p0)|0,l:Number($&p0)|0}}function W0($,Z,J,Q,V){return $=$+Z+V|0,Q=B0(Q^$,16),J=J+Q|0,Z=B0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function X0($,Z,J,Q,V){return $=$+Z+V|0,Q=B0(Q^$,8),J=J+Q|0,Z=B0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class q$ extends I${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,m0($),m0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=w0(this.buffer)}update($){_0(this),$=H0($),P0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,V=$.length,W=$.byteOffset,X=$.buffer;for(let Y=0;Y<V;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(Q),this.pos=0;let G=Math.min(Z-this.pos,V-Y),N=W+Y;if(G===Z&&!(N%4)&&Y+G<V){let P=new Uint32Array(X,N,Math.floor((V-Y)/4));s(P);for(let q=0;Y+Z<V;q+=Q.length,Y+=Z)this.length+=Z,this.compress(P,q,!1);s(P);continue}J.set($.subarray(Y,Y+G),this.pos),this.pos+=G,this.length+=G,Y+=G}return this}digestInto($){_0(this),b0($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,F0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=w0($);this.get().forEach((V,W)=>Q[W]=QZ(V))}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}_cloneInto($){let{buffer:Z,length:J,finished:Q,destroyed:V,outputLen:W,pos:X}=this;return $||($=new this.constructor({dkLen:W})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=V,$.finished=Q,$.length=J,$.pos=X,$.outputLen=W,$}clone(){return this._cloneInto()}}function M$($,Z,J,Q,V,W,X,Y,G,N,P,q,R,K,O,z,H,T,C,D){let F=0;for(let E=0;E<Q;E++)({a:V,b:G,c:R,d:H}=W0(V,G,R,H,J[Z+$[F++]])),{a:V,b:G,c:R,d:H}=X0(V,G,R,H,J[Z+$[F++]]),{a:W,b:N,c:K,d:T}=W0(W,N,K,T,J[Z+$[F++]]),{a:W,b:N,c:K,d:T}=X0(W,N,K,T,J[Z+$[F++]]),{a:X,b:P,c:O,d:C}=W0(X,P,O,C,J[Z+$[F++]]),{a:X,b:P,c:O,d:C}=X0(X,P,O,C,J[Z+$[F++]]),{a:Y,b:q,c:z,d:D}=W0(Y,q,z,D,J[Z+$[F++]]),{a:Y,b:q,c:z,d:D}=X0(Y,q,z,D,J[Z+$[F++]]),{a:V,b:N,c:O,d:D}=W0(V,N,O,D,J[Z+$[F++]]),{a:V,b:N,c:O,d:D}=X0(V,N,O,D,J[Z+$[F++]]),{a:W,b:P,c:z,d:H}=W0(W,P,z,H,J[Z+$[F++]]),{a:W,b:P,c:z,d:H}=X0(W,P,z,H,J[Z+$[F++]]),{a:X,b:q,c:R,d:T}=W0(X,q,R,T,J[Z+$[F++]]),{a:X,b:q,c:R,d:T}=X0(X,q,R,T,J[Z+$[F++]]),{a:Y,b:G,c:K,d:C}=W0(Y,G,K,C,J[Z+$[F++]]),{a:Y,b:G,c:K,d:C}=X0(Y,G,K,C,J[Z+$[F++]]);return{v0:V,v1:W,v2:X,v3:Y,v4:G,v5:N,v6:P,v7:q,v8:R,v9:K,v10:O,v11:z,v12:H,v13:T,v14:C,v15:D}}var Z0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},Y0=WZ.slice(),YZ=(()=>{let $=Array.from({length:16},(Q,V)=>V),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Q[V]),J=[];for(let Q=0,V=$;Q<7;Q++,V=Z(V))J.push(...V);return Uint8Array.from(J)})();class R$ extends q${constructor($={},Z=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:J,context:Q}=$,V=Q!==void 0;if(J!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let W=H0(J).slice();P0(W,32),this.IV=w0(W),s(this.IV),this.flags=Z|Z0.KEYED_HASH}else if(V){let W=H0(Q),X=new R$({dkLen:32},Z0.DERIVE_KEY_CONTEXT).update(W).digest();this.IV=w0(X),s(this.IV),this.flags=Z|Z0.DERIVE_KEY_MATERIAL}else this.IV=Y0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=$Z(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:V,pos:W}=this,{h:X,l:Y}=P$(BigInt($),!0),{v0:G,v1:N,v2:P,v3:q,v4:R,v5:K,v6:O,v7:z,v8:H,v9:T,v10:C,v11:D,v12:F,v13:E,v14:m,v15:d}=M$(YZ,Q,J,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],Y0[0],Y0[1],Y0[2],Y0[3],X,Y,W,Z);V[0]=G^H,V[1]=N^T,V[2]=P^C,V[3]=q^D,V[4]=R^F,V[5]=K^E,V[6]=O^m,V[7]=z^d}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=Z0.CHUNK_START;if(this.chunkPos===15||J)Q|=Z0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let V=this.state;this.state=this.IV.slice();for(let W,X=this.chunksDone+1;J||!(X&1);X>>=1){if(!(W=this.stack.pop()))break;this.buffer32.set(W,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:Z,flags:J,state:Q,chunkPos:V,posOut:W,chunkOut:X,stack:Y,chunksDone:G}=this;return $.state.set(Q.slice()),$.stack=Y.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=V,$.chunksDone=G,$.posOut=W,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,F0(this.state,this.buffer32,this.IV,this.bufferOut32),F0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:V}=this,{h:W,l:X}=P$(BigInt(this.chunkOut++));s(Q);let{v0:Y,v1:G,v2:N,v3:P,v4:q,v5:R,v6:K,v7:O,v8:z,v9:H,v10:T,v11:C,v12:D,v13:F,v14:E,v15:m}=M$(YZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],Y0[0],Y0[1],Y0[2],Y0[3],X,W,Z,J);V[0]=Y^z,V[1]=G^H,V[2]=N^T,V[3]=P^C,V[4]=q^D,V[5]=R^F,V[6]=K^E,V[7]=O^m,V[8]=$[0]^z,V[9]=$[1]^H,V[10]=$[2]^T,V[11]=$[3]^C,V[12]=$[4]^D,V[13]=$[5]^F,V[14]=$[6]^E,V[15]=$[7]^m,s(Q),s(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,F0(this.buffer.subarray(this.pos));let $=this.flags|Z0.ROOT;if(this.stack.length)$|=Z0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Z0.CHUNK_START:0)|Z0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){_0(this,!1),P0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,V=$.length;Q<V;){if(this.posOut>=Z)this.b2CompressOut();let W=Math.min(Z-this.posOut,V-Q);$.set(J.subarray(this.posOut,this.posOut+W),Q),this.posOut+=W,Q+=W}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return m0($),this.xofInto(new Uint8Array($))}digestInto($){if(b0($,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 GZ=VZ(($)=>new R$($));function h($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function n0($){if($.length%2!==0)throw Error("Invalid hex string");let Z=new Uint8Array($.length/2);for(let J=0;J<$.length;J+=2)Z[J/2]=Number.parseInt($.substr(J,2),16);return Z}function PZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var NZ;if(typeof Uint8Array.prototype.toBase64==="function")NZ=($)=>$.toBase64();else NZ=($)=>btoa(String.fromCharCode(...$));var IZ;if(typeof Uint8Array.fromBase64==="function")IZ=($)=>Uint8Array.fromBase64($);else IZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function g0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var K$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function qZ($){let Z=new Uint8Array(K$.length+32);return Z.set(K$),Z.set($.subarray(0,32),K$.length),Z}function MZ($){return typeof $==="string"?new TextEncoder().encode($):$}function T0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class U${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return d0($)}async gen256BitSecureRandomSeed(){return d0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=d0(24),V=N$(Z,J).encrypt($);return new Uint8Array([...J,...V])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return N$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=qZ(Z),Q=await globalThis.crypto.subtle.importKey("pkcs8",T0(J),{name:"Ed25519"},!0,["sign"]),V=await globalThis.crypto.subtle.exportKey("jwk",Q);if(typeof V.x!=="string")throw Error("Ed25519 JWK missing x");let W=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:V.x},{name:"Ed25519"},!0,["verify"]),X=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",W)),Y=new Uint8Array(64);return Y.set(Z,0),Y.set(X,32),this.signKeys.set(h(Z),Q),this.verifyKeys.set(h(X),W),{keyType:"ed25519",privateKey:Y,publicKey:X}}async importSignKey($){let Z=$.subarray(0,32),J=h(Z),Q=this.signKeys.get(J);if(Q)return Q;let V=qZ(Z),W=await globalThis.crypto.subtle.importKey("pkcs8",T0(V),{name:"Ed25519"},!1,["sign"]);return this.signKeys.set(J,W),W}async importVerifyKey($){let Z=h($),J=this.verifyKeys.get(Z);if(J)return J;let Q=await globalThis.crypto.subtle.importKey("raw",T0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=MZ($),Q=await this.importSignKey(Z),V=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,T0(J));return new Uint8Array(V)}async checkSigEd25519($,Z,J){let Q=MZ(Z);try{let V=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},V,T0($),T0(Q))}catch{return!1}}async blake3($){return GZ($)}}var YQ=new U$,q0=YQ;var A0=64;var RZ=32,C0=8;var KZ=32;var UZ=30000,zZ=512,S;((M)=>{M[M.Success=0]="Success";M[M.InvalidSignature=3]="InvalidSignature";M[M.ClockOutOfSync=4]="ClockOutOfSync";M[M.UserNotRegistered=5]="UserNotRegistered";M[M.ServerMisconfigured=6]="ServerMisconfigured";M[M.MissingBody=7]="MissingBody";M[M.ExtraBodyContent=8]="ExtraBodyContent";M[M.MissingParam=9]="MissingParam";M[M.InvalidParam=10]="InvalidParam";M[M.InvalidRequest=11]="InvalidRequest";M[M.InternalError=12]="InternalError";M[M.NotFound=13]="NotFound";M[M.InvalidMessage=14]="InvalidMessage";M[M.NoChange=15]="NoChange";M[M.DatabaseClosed=16]="DatabaseClosed";M[M.StorageError=17]="StorageError";M[M.DatabaseError=18]="DatabaseError";M[M.HashMismatch=19]="HashMismatch";M[M.DecryptionError=20]="DecryptionError";M[M.NotImplemented=21]="NotImplemented";M[M.MissingSeed=22]="MissingSeed";M[M.OutOfBounds=23]="OutOfBounds";M[M.HostError=24]="HostError";M[M.CommunicationError=25]="CommunicationError";M[M.VarLimitExceeded=26]="VarLimitExceeded";M[M.InvalidResponse=27]="InvalidResponse";M[M.ConnectionClosed=28]="ConnectionClosed"})(S||={});var OZ="t";function w($){return[$,0]}function I($){return[void 0,$]}function GQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return I(10);let Z=[];while($>0n){let J=Number($&0x7fn);if($>>=7n,$>0n)Z.push(J|128);else Z.push(J)}if(Z.length===0)return w(new Uint8Array([0]));if(Z.length>8)return I(26);return w(new Uint8Array(Z))}function NQ($,Z=0){let J=0n,Q=0,V=Z;while(!0){if(V>=$.length)return I(14);let W=$[V++];if(W===void 0)return I(14);if(J|=BigInt(W&127)<<BigInt(Q),(W&128)===0){if(V-Z>8)return I(26);return w({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:V-Z})}if(Q+=7,Q>=56)return I(26)}}class c{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new c(J)}readBigInt(){if(this.pos+8>this.data.length)return I(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,w($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);return w(new Date($))}readVarInt(){let[$,Z]=NQ(this.data,this.pos);if(Z!==0)return I(Z);this.pos+=$.bytesRead;let J=$.value;return w(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);let[J,Q]=this.readBytes($);if(Q!==0)return I(Q);let V=new TextDecoder().decode(J);return w(V)}readBytes($){if($<0)return I(10);if(this.pos+$>this.data.length)return I(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,w(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return I(Q);Z.push(J)}return w(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return I(Q);Z.push(J)}return w(Z)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class L{parts=[];writeBigInt($){let Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,$,!1),this.parts.push(Z)}writeDate($){let Z=$.getTime();return this.writeVarInt(Z)}writeVarInt($){let[Z,J]=GQ($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let Z=this.writeVarInt($.length);if(Z!==0)return Z;return this.writeBytes($),0}writeStruct($,Z){return $.encode(this,Z)}writeStructs($,Z){for(let J of Z){let Q=this.writeStruct($,J);if(Q!==0)return Q}return 0}writeBytesSeq($){for(let Z of $)this.writeBytes(Z)}result(){let $=this.parts.reduce((Q,V)=>Q+V.length,0),Z=new Uint8Array($),J=0;for(let Q of this.parts)Z.set(Q,J),J+=Q.length;return Z}*scan(){for(let $ of this.parts)yield $}}var x0={encode($,Z){let J=$.writeVarBytes(Z.id);if(J!==0)return J;let Q=$.writeDate(Z.ts);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return I(J);let[Q,V]=$.readDate();if(V!==0)return I(V);return w({id:Z,ts:Q})}};function wZ($){let Z=new L,J=Z.writeStruct(x0,$);if(J!==0)return I(J);let Q=Z.result();return w(Q)}var z$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let V=$.writeVarInt(Z.ctr);if(V!==0)return V;let W=$.writeVarInt(Z.len);if(W!==0)return W;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return I(J);let Q=new c(Z),[,V]=x0.decode(Q);if(V!==0)return I(V);let[W,X]=$.readVarInt();if(X!==0)return I(X);let[Y,G]=$.readVarInt();if(G!==0)return I(G);let[N,P]=$.readVarInt();if(P!==0)return I(P);let q;if(N>0){let[R,K]=$.readBytes(KZ);if(K!==0)return I(K);q=R}return w({eid:Z,off:W,ctr:Y,len:N,hsh:q})}};function FZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function IQ($,Z,J){let Q=g0(Z.privateKey,$);return(await J.blake3(Q)).slice(0,C0)}async function HZ($,Z,J,Q){let V;if($.bod&&$.len>0)V=await J.blake3($.bod);let W=new L,X=z$.encode(W,{...$,hsh:V});if(X!==0)return I(X);let Y=W.result(),G=await IQ(Y,Z,J),N=await Q.deriveFromKDM(G),P=await J.encryptXSalsa20Poly1305Combined(Y,N),q=$.bod?await J.encryptXSalsa20Poly1305Combined($.bod,N):new Uint8Array(0),R=await J.signEd25519(P,Z.privateKey);return w({sig:R,kdm:G,headCph:P,bodyCph:q})}async function TZ($,Z,J,Q,V){let W=new c($),[X,Y]=z$.decode(W);if(Y!==0)return I(14);let G;try{G=Z&&Z.length>0?await Q.decryptXSalsa20Poly1305Combined(Z,J):void 0}catch{return I(20)}let N=X.hsh&&G===void 0,P=X.hsh===void 0&&G!==void 0;if(N||P)return I(19);if(X.hsh&&G){let R=await Q.blake3(G);if(!PZ(R,X.hsh))return I(19)}let q=V??await Q.blake3($);return w({msgHead:X,bod:G,headHash:q})}async function O$($,Z,J){let Q=new L,V=Q.writeDate(Z);if(V!==0)return I(V);let W=Q.result(),X=await J.signEd25519(W,$.privateKey);return w({pubKey:$.publicKey,sig:X,timestamp:Z})}async function e($,Z,J){let Q=J.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Q-V)>UZ)return 4;let X=new L;X.writeDate($.timestamp);let Y=X.result();if(!await Z.checkSigEd25519($.sig,Y,$.pubKey))return 3;return 0}class D0{now(){return new Date}}function AZ($,Z,J,Q){let V=Z.getTime()-$.getTime(),W=J.getTime()-Q.getTime();return(V+W)/2}var f0={encode($,Z){if($.writeVarInt(Z.quota),Z.quota>0){if(Z.usage===void 0)return 9;$.writeVarInt(Z.usage)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return I(J);let Q;if(Z>0){let[V,W]=$.readVarInt();if(W!==0)return I(W);Q=V}return w({quota:Z,usage:Q})}};var S0={encode($,Z){$.writeBytes(new Uint8Array([Z.status]));let J=$.writeDate(Z.timeRcvd);if(J!==0)return J;let Q=$.writeDate(Z.timeSent);if(Q!==0)return Q;let V=$.writeVarInt(Z.subscription.term);if(V!==0)return V;let W=$.writeVarInt(Z.subscription.elapsed);if(W!==0)return W;let X=$.writeStruct(f0,Z.subscription.stat);if(X!==0)return X;let Y=$.writeStruct(f0,Z.subscription.dyn);if(Y!==0)return Y;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return I(J);let Q=Z[0],[V,W]=$.readDate();if(W!==0)return I(W);let[X,Y]=$.readDate();if(Y!==0)return I(Y);let[G,N]=$.readVarInt();if(N!==0)return I(N);let[P,q]=$.readVarInt();if(q!==0)return I(q);let[R,K]=$.readStruct(f0);if(K!==0)return I(K);let[O,z]=$.readStruct(f0);if(z!==0)return I(z);return w({status:Q,timeRcvd:V,timeSent:X,subscription:{term:G,elapsed:P,stat:R,dyn:O}})}};async function w$($,Z,J){let{crypto:Q,enclave:V}=$,W=await V.derive(Z,J);return await Q.deriveEd25519KeyPair(W)}var F$={encode($,Z){let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let Q=$.writeVarInt(Z.seq);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return I(J);let[Q,V]=$.readVarInt();if(V!==0)return I(V);return w({headCph:Z,seq:Q})}};var o={encode($,Z){$.writeBytes(Z.pubKey),$.writeBytes(Z.sig);let J=$.writeDate(Z.timestamp);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(RZ);if(J!==0)return I(J);let[Q,V]=$.readBytes(A0);if(V!==0)return I(V);let[W,X]=$.readDate();if(X!==0)return I(X);return w({pubKey:Z,sig:Q,timestamp:W})}};var CZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;for(let X of Q)V.writeVarInt(X);return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W}=$,[X,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(X,V,Q);if(G!==0)return G;let{pubKey:N}=X,[P,q]=await W.hasUser(N);if(q!==0)return q;if(!P)return 5;let[R,K]=Z.readVarInt();if(K!==0)return K;if(!Z.done())return 8;let[O,z]=await W.listHeads(N,R);if(z!==0)return z;return J.writeStructs(F$,O)},decodeResp($){return $.readStructs(F$)}};var H$={encode($,Z){$.writeVarInt(Z.seq);let J=$.writeVarBytes(Z.bodyCph);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return I(J);let[Q,V]=$.readVarBytes();if(V!==0)return I(V);return w({seq:Z,bodyCph:Q})}};var DZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;for(let X of Q){let Y=V.writeVarInt(X);if(Y!==0)return Y}return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W}=$,[X,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(X,V,Q);if(G!==0)return G;let{pubKey:N}=X,[P,q]=await W.hasUser(N);if(q!==0)return q;if(!P)return 5;let R=[];while(!Z.done()){let[z,H]=Z.readVarInt();if(H!==0)return H;R.push(z)}console.info(`PULL: ${R.length} bags`);let[K,O]=await W.getBodies(N,R);if(O!==0)return O;if(!K)return 17;for(let{seq:z,bodyCph:H}of K){let T={seq:z,bodyCph:H},C=J.writeStruct(H$,T);if(C!==0)return C}return 0},decodeResp($){return $.readStructs(H$)}};var T$={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let Q=$.writeVarBytes(Z.bodyCph);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readBytes(A0);if(J!==0)return I(J);let[Q,V]=$.readBytes(C0);if(V!==0)return I(V);let[W,X]=$.readVarBytes();if(X!==0)return I(X);let[Y,G]=$.readVarBytes();if(G!==0)return I(G);return w({sig:Z,kdm:Q,headCph:W,bodyCph:Y})}};var A$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let V=Z.bodyCph?Z.bodyCph.length:0,W=$.writeVarInt(V);if(W!==0)return W;if(V>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return I(J);let[Q,V]=$.readVarBytes();if(V!==0)return I(V);let[W,X]=$.readVarInt();if(X!==0)return I(X);let Y;if(W>0){let[G,N]=$.readBytes(W);if(N!==0)return I(N);Y=G}return w({seq:Z,headCph:Q,bodyCph:Y})}};var E0={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(A0);if(J!==0)return I(J);let[Q,V]=$.readBytes(C0);if(V!==0)return I(V);let[W,X]=$.readVarBytes();if(X!==0)return I(X);return w({sig:Z,kdm:Q,headCph:W})}};var h0={encode($,Z){if($.writeVarInt(Z.idx),$.writeBytes(new Uint8Array([Z.status])),Z.status===0)$.writeVarInt(Z.seq);return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return I(J);let[Q,V]=$.readBytes(1);if(V!==0)return I(V);let W=Q[0];if(W!==0)return w({idx:Z,status:W});let[X,Y]=$.readVarInt();if(Y!==0)return I(Y);return w({idx:Z,status:W,seq:X})}};var SZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;let X=V.writeStructs(T$,Q);if(X!==0)return X;return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W,notifier:X}=$,[Y,G]=Z.readStruct(o);if(G!==0)return G;let N=await e(Y,V,Q);if(N!==0)return N;let{pubKey:P}=Y,[q,R]=await W.hasUser(P);if(R!==0)return R;if(!q)return 5;let[K,O]=Z.readStructs(T$);if(O!==0)return O;console.info(`PUSH: ${K.length} bags`);let z=[],H=[];for(let F=0;F<K.length;F++){let E=K[F];if(!await FZ(E,P,V)){let d={idx:F,status:3},j=J.writeStruct(h0,d);if(j!==0)return j;continue}z.push(F),H.push(E)}let[T,C]=await W.setBags(P,H);if(C!==0)return C;if(!T||T.length!==H.length)return 17;let D=[];for(let F=0;F<H.length;F++){let E=H[F],m=z[F],d=T[F],j=new L,_=j.writeStruct(E0,E);if(_!==0)return _;let g=j.result(),M={seq:d,headCph:g};if(K.length===1&&E.bodyCph.length<=zZ)M.bodyCph=E.bodyCph;D.push(M);let x={idx:m,status:0,seq:d},B=J.writeStruct(h0,x);if(B!==0)return B}if(D.length>0){let F=new L,E=F.writeStructs(A$,D);if(E!==0)return E;let m=F.result();await Promise.resolve(X.push(P,m))}return 0},decodeResp($){return $.readStructs(h0)}};var EZ={async encodeReq($,Z,J,Q,V){return V.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W}=$,[X,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(X,V,Q);if(G!==0)return G;let{pubKey:N}=X;if(!Z.done())return 8;let[P,q]=await W.addUser(N);if(q!==0)return q;return 0},decodeResp($){return w(void 0)}};class C${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let W=new L;W.writeStruct(o,$);let X=W.result(),Y=h(X);return V.searchParams.set("t",Y),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Q()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(G)=>{let N=new Uint8Array(G.data);Z(N)},this.websocket.onerror=(G)=>{console.log(`ERROR: ${JSON.stringify(G)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var b={user:{path:"/user",endpoint:EZ,name:0},push:{path:"/push",endpoint:SZ,name:2},peek:{path:"/peek",endpoint:CZ,name:1},pull:{path:"/pull",endpoint:DZ,name:3}},PQ={0:b.user,2:b.push,1:b.peek,3:b.pull},LZ={[b.user.path]:b.user,[b.push.path]:b.push,[b.peek.path]:b.peek,[b.pull.path]:b.pull};class jZ{url;listener;constructor($){this.url=$;this.listener=new C$($)}async call($,Z){let{path:J}=PQ[$],Q=new URL(J,this.url);try{return await MQ(Q,Z)}catch{return I(25)}}}var D$=($)=>{return new jZ($.handle)};function L0($){let Z=new L;if(Z.writeStruct(S0,$)!==0)return new Response(null,{status:500});return S$(Z)}function S$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var qQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function E$($){return new Response($.body,{headers:{...$.headers,...qQ},status:$.status,statusText:$.statusText})}async function MQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return I(24);let Q=await c.fromResponse(J);return w(Q)}class c0{enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,V,W){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=V;this.updateHostMeta=W}async call($,Z){let{clock:J,crypto:Q,transport:V}=this,{endpoint:W,name:X}=$,Y=await this.keys(),G=J.now(),[N,P]=await O$(Y,G,Q);if(P!==0)return I(P);let q=new L,R=await W.encodeReq(this,Y,N,Z,q);if(R!==0)return I(R);let K=J.now(),[O,z]=await V.call(X,q),H=J.now();if(z!==0)return I(z);let[T,C]=O.readStruct(S0);if(C!==0)return I(C);if(T.status!==0)return I(T.status);let F={clockOffset:AZ(K,T.timeRcvd,T.timeSent,H),subscription:T.subscription},E=await this.updateHostMeta(F);if(E!==0)return I(E);return W.decodeResp(O)}keys=()=>{let{host:$}=this;return w$(this,$.label,$.idx)};seal=async($)=>{let{crypto:Z,enclave:J}=this,Q=await this.keys();return HZ($,Q,Z,J)};register=()=>this.call(b.user,[]);peek=($)=>this.call(b.peek,[$]);push=($)=>this.call(b.push,$);pull=($)=>this.call(b.pull,$);listen=async($,Z,J)=>{let{clock:Q,crypto:V,host:W,transport:X}=this,{listener:Y}=X,G=await w$(this,W.label,W.idx),N=Q.now(),[P,q]=await O$(G,N,V);if(q!==0)return q;return await Y.connect(P,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class L${seed;crypto;constructor($,Z){this.seed=$,this.crypto=Z}async deriveFromKDM($){let Z=g0(this.seed,$);return await this.crypto.blake3(Z)}async derive($,Z=0){let J=new TextEncoder().encode($),Q=new Uint8Array(8);new DataView(Q.buffer).setBigUint64(0,BigInt(Z),!1);let V=g0(J,Q);return await this.deriveFromKDM(V)}}class j${listeners=new Map;addEventListener($,Z){let J=this.listeners.get($);if(!J)J=new Set,this.listeners.set($,J);return J.add(Z),()=>{this.removeEventListener($,Z)}}removeEventListener($,Z){let J=this.listeners.get($);if(J){if(J.delete(Z),J.size===0)this.listeners.delete($)}}emit($,Z){let J=this.listeners.get($);if(J){let Q=Array.from(J);for(let V of Q)V(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function kZ($,Z,J,Q=0){let V=Z.now(),W=new L,X=W.writeVarString($);if(X!==0)return I(X);let G={id:W.result(),ts:new Date(0)},[N,P]=wZ(G);if(P!==0)return I(P);let q=V.getTime()-G.ts.getTime();return w({eid:N,off:q,ctr:Q,len:J.length,bod:J})}class RQ{singletonType;latest;latestOff=-1;emitter=new j$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new c(Z.eid),[Q,V]=J.readStruct(x0);if(V!==0)continue;let W=new L;W.writeVarString(this.singletonType);let X=W.result();if(Q.id.length===X.length&&Q.id.every((Y,G)=>Y===X[G])){if(this.latest===void 0||Z.off>this.latestOff)this.latestOff=Z.off,this.latest=Z.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 Z of $)if(Z===this.singletonType)this.emitter.emit(this.singletonType,null)};refresh=async($)=>{this.notify([this.singletonType])};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function mZ($,Z,J,Q){let V=new c($.headCph),[W,X]=V.readStruct(E0);if(X!==0)return I(X);let{sig:Y,kdm:G,headCph:N}=W;if(!await Q.checkSigEd25519(Y,N,Z.publicKey))return I(3);let q=await J.deriveFromKDM(G),R;try{R=await Q.decryptXSalsa20Poly1305Combined(N,q)}catch{return I(20)}return w({kdm:G,headEnc:R})}var k0=pJ(_J(),1),BV={encode:k0.encode,decode:k0.decode,decodeAsync:k0.decodeAsync},gV=BV;import{Database as xV}from"bun:sqlite";var v8=Symbol("EntityID");var y8=Symbol("MasterSeed"),l8=Symbol("DerivationSeed"),i8=Symbol("PublicKey"),u8=Symbol("PrivateKey"),d8=Symbol("HostSpecificKeyPair"),r8=Symbol("Hash"),N0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function fV($="diplomatic.db"){let Z=new xV($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS users (
|
|
3
3
|
pubKey TEXT PRIMARY KEY
|
|
4
4
|
);
|
|
@@ -11,4 +11,4 @@ var iJ=Object.create;var{getPrototypeOf:lJ,defineProperty:u$,getOwnPropertyNames
|
|
|
11
11
|
PRIMARY KEY (userPubKey, seq),
|
|
12
12
|
UNIQUE (userPubKey, seq)
|
|
13
13
|
);
|
|
14
|
-
`),{async addUser(J){try{let
|
|
14
|
+
`),{async addUser(J){try{let Q=h(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),w(void 0)}catch{return I(17)}},async hasUser(J){try{let Q=h(J),V=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return w(Boolean(V?.ok))}catch{return I(17)}},async subMeta(J){return w(N0)},async setBags(J,Q){if(Q.length<1)return w([]);try{let V=h(J);Z.exec("BEGIN IMMEDIATE");try{let W=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(V),X=W?W.m||0:0,Y=[],G=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){X+=1;let P=new L;P.writeStruct(E0,N),G.run(V,X,P.result(),N.bodyCph),Y.push(X)}return Z.exec("COMMIT"),w(Y)}catch(W){try{Z.exec("ROLLBACK")}catch{}throw W}}catch{return I(17)}},async getBodies(J,Q){if(Q.length<1)return w([]);try{let V=h(J),W=[],X=100,Y=99;for(let G=0;G<Q.length;G+=99){let N=Q.slice(G,G+99),P=N.map(()=>"?").join(","),q=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${P})`).all(V,...N);for(let R of q)if(R.bodyCph)W.push({seq:R.seq,bodyCph:new Uint8Array(R.bodyCph)})}return w(W)}catch{return I(17)}},async listHeads(J,Q){try{let V=h(J),W=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(V,Q);return w(W.map((X)=>({seq:X.seq,headCph:new Uint8Array(X.headCph)})))}catch{return I(17)}}}}var vV=fV(),BJ=vV;class r${storage;crypto;notifier;clock;constructor($,Z,J,Q){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=Q}corsHandler=async($)=>{if($.method==="OPTIONS")return E$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),E$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=new URL($.url);if($.method!=="POST"){let N=Z.now();return L0({status:13,timeRcvd:J,timeSent:N,subscription:N0})}if(!$.body){let N=Z.now();return L0({status:7,timeRcvd:J,timeSent:N,subscription:N0})}let W=new Uint8Array(await $.arrayBuffer()),X=new c(W),Y=Q.pathname,G=LZ[Y]?.endpoint;if(!G){let N=Z.now();return L0({status:13,timeRcvd:J,timeSent:N,subscription:N0})}try{let N=new L,P=await G.handleReq(this,X,N),q=N0,R={status:P,timeRcvd:J,timeSent:this.clock.now(),subscription:q},K=new L;if(K.writeStruct(S0,R)!==0)return new Response(null,{status:500});if(P!==0){let z=Z.now();return L0({status:P,timeRcvd:J,timeSent:z,subscription:N0})}return N.prependBytes(K.result()),S$(N)}catch(N){let P=Z.now();return console.error(N),console.trace(),L0({status:12,timeRcvd:J,timeSent:P,subscription:N0})}}}async function gJ($,Z){let Q=new URL($.url).searchParams.get(OZ);if(!Q)return I(11);let V=n0(Q),W=new c(V),[X,Y]=W.readStruct(o);if(Y!==0)return I(11);let G=await e(X,Z.crypto,Z.clock);if(G!==0)return I(G);return w(X)}class fJ{recvs=new Map;async open($,Z,J,Q){let V=await e($,J,Q);if(V!==0)return{send:()=>V,shut:()=>V,status:V};let W=h($.pubKey);if(!this.recvs.has(W))this.recvs.set(W,new Set);return this.recvs.get(W)?.add(Z),{send:(X)=>{return Z(X),0},shut:()=>{return this.recvs.get(W)?.delete(Z),0},status:0}}async push($,Z){let J=h($),Q=this.recvs.get(J);if(Q)for(let V of Q)V(Z)}}var xJ=new fJ;async function yV($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new r$(BJ,q0,xJ,new D0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,Q)=>{if(J.headers.get("upgrade")==="websocket"){let[V,W]=await gJ(J,Z);if(W!==0)return new Response("Unauthorized",{status:401});return Q.upgrade(J,{data:{authTS:V}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let Q=J.data.authTS;xJ.open(Q,(V)=>J.send(V),Z.crypto,Z.clock).then((V)=>{if(V.status!==0){J.close();return}J.channel=V})},message:(J,Q)=>{},close:(J)=>{J.channel?.shut()}}})}class vJ{enclave;conn;clock;constructor({seed:$,clock:Z=new D0}){this.enclave=new L$($,q0),this.clock=Z}async connect($,Z){let J=new D0,Q=()=>Promise.resolve(0);this.conn=new c0(this.enclave,q0,$,J,Z,Q);let[,V]=await this.conn.register();return V}async push($){if(!this.conn)return I(28);let Z=[];for(let V of $){let[W,X]=await this.conn.seal(V);if(X!==0)return I(X);Z.push(W)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return I(Q);return w(J)}async peek($){if(!this.conn)return I(28);return this.conn.peek($)}async pull($){if(!this.conn)return I(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return I(28);let J=await this.conn.keys(),[Q,V]=await mZ($,J,this.enclave,q0);if(V!==0)return I(V);let W=await this.enclave.deriveFromKDM(Q.kdm);return TZ(Q.headEnc,Z.bodyCph,W,q0)}async upsertSingletonSync($,Z){let[J,Q]=await kZ($,this.clock,Z);if(Q!==0)return Q;let[,V]=await this.push([J]);return V}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function lV({seed:$,host:Z,transport:J}){let Q=new vJ({seed:$}),V=await Q.connect(Z,J);return[Q,V]}async function gG({seed:$,host:Z,transport:J}){let Q=J??D$(Z),[V,W]=await lV({seed:$,host:Z,transport:Q});if(W!==0)console.error(`Failed to initialize CLI: ${S[W]}`),process.exit(1);return V}function xG($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=n0(Z);if(J.length!==32)console.error(`${$} must be 64 hex chars (32 bytes)`),process.exit(1);return J}function fG($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{yV as runBunHost,A$ as notifItemCodec,gV as msgpack,xG as loadSeedOrPanic,fG as loadHostOrPanic,gG as initCLIOrPanic,lV as initCLI,D$ as hostHTTPTransport,S as Status,c as Decoder,vJ as CLIClient};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IClock } from "./clock.ts";
|
|
2
2
|
import { Status } from "./consts.ts";
|
|
3
|
-
import { IMessage, IStateManager, IUpsertMessage, SerializedContent } from "./types.ts";
|
|
3
|
+
import { EntityID, IMessage, IStateManager, IUpsertMessage, SerializedContent } from "./types.ts";
|
|
4
4
|
import { ValStat } from "./valstat.ts";
|
|
5
5
|
export declare function genSingletonUpsert(type: string, clk: IClock, content: Uint8Array, ctr?: number): Promise<ValStat<IUpsertMessage>>;
|
|
6
6
|
export declare class SingletonStateManager implements IStateManager {
|
|
@@ -12,6 +12,7 @@ export declare class SingletonStateManager implements IStateManager {
|
|
|
12
12
|
apply(messages: IMessage[]): Promise<Status[]>;
|
|
13
13
|
clear: () => Promise<Status>;
|
|
14
14
|
notify: (types: Iterable<string>) => void;
|
|
15
|
+
refresh: (_eids: Iterable<EntityID>) => Promise<void>;
|
|
15
16
|
on: (event: string, listener: () => void) => void;
|
|
16
17
|
off: (event: string, listener: () => void) => void;
|
|
17
18
|
}
|
|
@@ -39,11 +39,32 @@ export type IOp = IDeleteOp | IMutateOp;
|
|
|
39
39
|
export declare function isDeleteOp(op: IOp): op is IDeleteOp;
|
|
40
40
|
export declare function isMutateOp(op: IOp): op is IMutateOp;
|
|
41
41
|
export interface IInsertParams<T> extends IMsgEntBody<T> {
|
|
42
|
+
/** Optional 8-byte id material for the new eid; else random. */
|
|
42
43
|
id?: Uint8Array;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Revision of an ent used as the base for update/delete.
|
|
47
|
+
* Apps almost always already hold this (the row being edited).
|
|
48
|
+
*/
|
|
49
|
+
export interface IEntRev {
|
|
50
|
+
eid: EntityID;
|
|
51
|
+
ctr: number;
|
|
52
|
+
/** Last-write time of this rev (eid.ts + off of the latest msg for this eid). */
|
|
53
|
+
updatedAt: Date;
|
|
54
|
+
}
|
|
55
|
+
export interface IUpdateParams<T> extends IMsgEntBody<T> {
|
|
56
|
+
prior: IEntRev;
|
|
57
|
+
/** Clock-skew recovery; default client-wide (usually true). */
|
|
58
|
+
force?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** Prefer `{ prior }`; `{ eid }` loads prior from the message archive. */
|
|
61
|
+
export type IDeleteParams = {
|
|
62
|
+
prior: IEntRev;
|
|
63
|
+
force?: boolean;
|
|
64
|
+
} | {
|
|
65
|
+
eid: EntityID;
|
|
66
|
+
force?: boolean;
|
|
67
|
+
};
|
|
47
68
|
export interface IStorage {
|
|
48
69
|
addUser: (pubKey: PublicKey) => Promise<ValStat<void>>;
|
|
49
70
|
hasUser: (pubKey: PublicKey) => Promise<ValStat<boolean>>;
|
|
@@ -172,6 +193,12 @@ export interface IStateManager {
|
|
|
172
193
|
* updated shared application state in IndexedDB).
|
|
173
194
|
*/
|
|
174
195
|
notify: (types: Iterable<string>) => void;
|
|
196
|
+
/**
|
|
197
|
+
* Peer wrote durable application state for these eids (e.g. sync worker).
|
|
198
|
+
* With CachedEntDB: pull those eids from durable; type-level UI notifies
|
|
199
|
+
* fire only if mem changed.
|
|
200
|
+
*/
|
|
201
|
+
refresh: (eids: Iterable<EntityID>) => Promise<void>;
|
|
175
202
|
on: (type: string, listener: () => void) => void;
|
|
176
203
|
off: (type: string, listener: () => void) => void;
|
|
177
204
|
}
|
package/dist/web/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import DiplomaticClientAPI from "./shared/client";
|
|
|
2
2
|
import { IClock } from "./shared/clock";
|
|
3
3
|
import { Status } from "./shared/consts";
|
|
4
4
|
import { EncodedMessage } from "./shared/message";
|
|
5
|
-
import { EntityID, HostHandle, ICrypto, IHostConnectionInfo, IInsertParams, IMessageHead, IStateManager, ITransport,
|
|
5
|
+
import { EntityID, HostHandle, ICrypto, IDeleteParams, IEntRev, IHostConnectionInfo, IInsertParams, IMessageHead, IStateManager, ITransport, IUpdateParams, MasterSeed } from "./shared/types";
|
|
6
6
|
import { ValStat } from "./shared/valstat";
|
|
7
7
|
import { IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore } from "./types";
|
|
8
8
|
export declare class SyncClient<Handle extends HostHandle> implements IClient<Handle> {
|
|
@@ -19,8 +19,8 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
|
|
|
19
19
|
private onScheduleSync?;
|
|
20
20
|
connections: Map<string, DiplomaticClientAPI<Handle>>;
|
|
21
21
|
/**
|
|
22
|
-
* Serializes exec so concurrent drainApplyQueue / apply do
|
|
23
|
-
* markApplied (each job runs fully, in order).
|
|
22
|
+
* Serializes local mutates + exec so concurrent drainApplyQueue / apply do
|
|
23
|
+
* not interleave markApplied (each job runs fully, in order).
|
|
24
24
|
*/
|
|
25
25
|
private applyChain;
|
|
26
26
|
/**
|
|
@@ -64,8 +64,15 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
|
|
|
64
64
|
* 1) durable archive 2) exec + APLD_APPLIED/APLD_ERROR 3) upload queue
|
|
65
65
|
* Exec is where the app validates the msg; only successes are pushed.
|
|
66
66
|
* Crash between 1–2 → drainApplyQueue / exec stage recovers.
|
|
67
|
+
*
|
|
68
|
+
* Serialized on applyChain (with local mutates).
|
|
67
69
|
*/
|
|
68
70
|
private apply;
|
|
71
|
+
/**
|
|
72
|
+
* Core apply without enqueue. Caller must already hold applyChain when
|
|
73
|
+
* composing makeUpdate + apply in one job.
|
|
74
|
+
*/
|
|
75
|
+
private doApply;
|
|
69
76
|
private enqueueApplyJob;
|
|
70
77
|
/**
|
|
71
78
|
* Apply archived msgs that are still unapplied (crash recovery).
|
|
@@ -75,6 +82,7 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
|
|
|
75
82
|
private doDrainApplyQueue;
|
|
76
83
|
/** Apply specific archive keys via IStateManager and mark applied. */
|
|
77
84
|
private applyHashes;
|
|
85
|
+
private doApplyHashes;
|
|
78
86
|
/**
|
|
79
87
|
* Apply a batch of archived msgs via IStateManager and mark outcomes.
|
|
80
88
|
* Success/NoChange → APLD_APPLIED; terminal failures → APLD_ERROR;
|
|
@@ -87,10 +95,36 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
|
|
|
87
95
|
*/
|
|
88
96
|
private applyStored;
|
|
89
97
|
insertRaw(bod: EncodedMessage): Promise<ValStat<IMessageHead>>;
|
|
90
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Build the next update/delete msg from prior. Pure: no archive I/O.
|
|
100
|
+
* Returns ClockOutOfSync if prior is in the future (caller handles force).
|
|
101
|
+
*/
|
|
102
|
+
private makeUpdate;
|
|
103
|
+
/**
|
|
104
|
+
* Recover when prior's last-write time is in the future relative to this
|
|
105
|
+
* clock. That means either:
|
|
106
|
+
* a) another client's clock is skewed into the future, or
|
|
107
|
+
* b) this client's clock is skewed into the past.
|
|
108
|
+
*
|
|
109
|
+
* We recover by deleting the skewed ent and (for a non-delete write)
|
|
110
|
+
* replacing it. The delete must increment off so it overwrites the skewed
|
|
111
|
+
* state, even if that places the delete into the future as well.
|
|
112
|
+
* Replacement keeps the same id bytes with a new created-at of now.
|
|
113
|
+
*/
|
|
114
|
+
private updateWithSkew;
|
|
115
|
+
updateRaw(prior: IEntRev, bod: EncodedMessage | undefined, force?: boolean): Promise<ValStat<IMessageHead>>;
|
|
91
116
|
insert<T = unknown>(op: IInsertParams<T>): Promise<ValStat<IMessageHead>>;
|
|
92
|
-
|
|
93
|
-
|
|
117
|
+
update<T = unknown>(op: IUpdateParams<T>): Promise<ValStat<IMessageHead>>;
|
|
118
|
+
/**
|
|
119
|
+
* Delete by `{ prior }` (preferred) or `{ eid }` (archive lookup).
|
|
120
|
+
* `force` defaults to true (skew recovery on delete).
|
|
121
|
+
*/
|
|
122
|
+
delete(op: IDeleteParams): Promise<ValStat<IMessageHead>>;
|
|
123
|
+
/**
|
|
124
|
+
* Latest rev for eid from the message archive.
|
|
125
|
+
* If none, returns ctr -1 so the next write uses ctr 0.
|
|
126
|
+
*/
|
|
127
|
+
private revFromArchive;
|
|
94
128
|
genEID(id?: Uint8Array): Promise<ValStat<EntityID>>;
|
|
95
129
|
/**
|
|
96
130
|
* Catch up: exec pending → per host peek → push → pull‖open → exec.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Status } from "../shared/consts";
|
|
2
|
+
import { EntityID, IOp } from "../shared/types";
|
|
3
|
+
import { ValStat } from "../shared/valstat";
|
|
4
|
+
import { EntitiesQuery, IEntDB, IEntity } from "./entdb";
|
|
5
|
+
export type EntChangeListener = (types: Set<string>) => void;
|
|
6
|
+
export type OpenEntDBOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* In-memory cache over IndexedDB (default true).
|
|
9
|
+
* Set false for durable-only (e.g. sync worker).
|
|
10
|
+
*/
|
|
11
|
+
cache?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Open EntDB for the app (or worker). Single entry point.
|
|
15
|
+
* Default: cached. Pass `{ cache: false }` for durable IDB only.
|
|
16
|
+
*/
|
|
17
|
+
export declare function openEntDB(opts?: OpenEntDBOptions): Promise<IEntDB>;
|
|
18
|
+
export declare class CachedEntDB implements IEntDB {
|
|
19
|
+
private mem;
|
|
20
|
+
private durable;
|
|
21
|
+
private warmed;
|
|
22
|
+
private listeners;
|
|
23
|
+
private chain;
|
|
24
|
+
constructor(durable: IEntDB, init?: IEntity[]);
|
|
25
|
+
/** UI / StateManager: fired when mem changes (immediate apply or durable ingest). */
|
|
26
|
+
subscribe(listener: EntChangeListener): () => void;
|
|
27
|
+
private emit;
|
|
28
|
+
private run;
|
|
29
|
+
/**
|
|
30
|
+
* Fan-out write: mem (immediate notify) + durable, then reconcile mem
|
|
31
|
+
* from durable for the ops' eids (second notify only if something moved).
|
|
32
|
+
*/
|
|
33
|
+
apply(ops: IOp[]): Promise<import("./entdb").ApplyResult>;
|
|
34
|
+
clear(): Promise<Status>;
|
|
35
|
+
/**
|
|
36
|
+
* Backing store changed outside this.apply (worker wrote shared IDB).
|
|
37
|
+
* Pull only those eids from durable; notify coalesced types if mem changed.
|
|
38
|
+
*/
|
|
39
|
+
ingestFromDurable(eids: Iterable<EntityID>): Promise<Status>;
|
|
40
|
+
/**
|
|
41
|
+
* Install durable truth for each eid into mem.
|
|
42
|
+
* Always writes mem from durable; notifies types only when the full ent
|
|
43
|
+
* identity differs from what mem had (or the row was deleted).
|
|
44
|
+
*/
|
|
45
|
+
private pullEids;
|
|
46
|
+
private warmType;
|
|
47
|
+
getEnt<T>(eid: EntityID): Promise<ValStat<IEntity<T> | undefined>>;
|
|
48
|
+
getEntities<T>(query: EntitiesQuery): Promise<ValStat<IEntity<T>[]>>;
|
|
49
|
+
countEntities({ type }: {
|
|
50
|
+
type: string;
|
|
51
|
+
}): Promise<ValStat<number>>;
|
|
52
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Status } from "../shared/consts";
|
|
2
2
|
import { ValStat } from "../shared/valstat";
|
|
3
|
-
import { EntityID, GroupID, IMsgEntBody, IOp } from "../shared/types";
|
|
4
|
-
|
|
3
|
+
import { EntityID, GroupID, IEntRev, IMessageHead, IMsgEntBody, IOp } from "../shared/types";
|
|
4
|
+
export { entStateManager } from "./manager.ts";
|
|
5
5
|
export interface IEntity<T = unknown> extends Omit<IMsgEntBody<T>, "body"> {
|
|
6
6
|
eid: EntityID;
|
|
7
7
|
updatedAt: Date;
|
|
@@ -25,11 +25,16 @@ export type EntitiesQuery = {
|
|
|
25
25
|
type: string;
|
|
26
26
|
updatedBetween: IDateRange;
|
|
27
27
|
};
|
|
28
|
+
/** Result of applying ops to EntDB. */
|
|
29
|
+
export type ApplyResult = {
|
|
30
|
+
stats: Status[];
|
|
31
|
+
/** Types whose rendered state may have changed (for app list invalidation). */
|
|
32
|
+
types: Set<string>;
|
|
33
|
+
/** Eids that successfully applied (for granular cache ingest). */
|
|
34
|
+
eids: EntityID[];
|
|
35
|
+
};
|
|
28
36
|
export interface IEntDB {
|
|
29
|
-
apply: (ops: IOp[]) => Promise<
|
|
30
|
-
stats: Status[];
|
|
31
|
-
types: Set<string>;
|
|
32
|
-
}>;
|
|
37
|
+
apply: (ops: IOp[]) => Promise<ApplyResult>;
|
|
33
38
|
clear: () => Promise<Status>;
|
|
34
39
|
getEnt<T>(eid: EntityID): Promise<ValStat<IEntity<T> | undefined>>;
|
|
35
40
|
getEntities<T>(query: EntitiesQuery): Promise<ValStat<IEntity<T>[]>>;
|
|
@@ -37,6 +42,9 @@ export interface IEntDB {
|
|
|
37
42
|
type: string;
|
|
38
43
|
}): Promise<ValStat<number>>;
|
|
39
44
|
}
|
|
40
|
-
|
|
45
|
+
/** Prior rev from a loaded entity (typical update/delete input). */
|
|
46
|
+
export declare function revFromEntity(ent: IEntity): IEntRev;
|
|
47
|
+
/** Prior rev from a msg head returned by insert/update/delete. */
|
|
48
|
+
export declare function revFromHead(head: IMessageHead): ValStat<IEntRev>;
|
|
41
49
|
export declare function applyOp(curr: IEntity | undefined, op: IOp): ValStat<IEntity | undefined>;
|
|
42
50
|
export declare const nullEntDB: IEntDB;
|