@interncom/diplomatic 0.6.4 → 0.7.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/auth.d.ts +3 -2
- package/dist/cli/shared/bag.d.ts +4 -5
- package/dist/cli/shared/client.d.ts +3 -3
- package/dist/cli/shared/crypto/enclave.d.ts +42 -0
- package/dist/cli/shared/endpoint.d.ts +4 -5
- package/dist/cli/shared/sync.d.ts +3 -3
- package/dist/cli/shared/types.d.ts +6 -0
- package/dist/web/entdb/cached.d.ts +1 -1
- package/dist/web/entdb/entdb.d.ts +8 -0
- package/dist/web/entdb/idb.d.ts +3 -0
- package/dist/web/entdb/memory.d.ts +4 -1
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.mjs +1 -1
- package/dist/web/shared/auth.d.ts +3 -2
- package/dist/web/shared/bag.d.ts +4 -5
- package/dist/web/shared/client.d.ts +3 -3
- package/dist/web/shared/crypto/enclave.d.ts +42 -0
- package/dist/web/shared/endpoint.d.ts +4 -5
- package/dist/web/shared/exim.d.ts +1 -1
- package/dist/web/shared/sync.d.ts +3 -3
- package/dist/web/shared/types.d.ts +6 -0
- package/dist/web/stores/idb/seed.d.ts +1 -1
- package/dist/web/stores/memory/seed.d.ts +1 -1
- package/dist/web/sync.d.ts +2 -2
- package/dist/web/types.d.ts +1 -1
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -1
- package/dist/cli/shared/enclave.d.ts +0 -8
- package/dist/web/shared/enclave.d.ts +0 -8
package/dist/cli/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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(`
|
|
1
|
+
var vJ=Object.create;var{getPrototypeOf:lJ,defineProperty:p$,getOwnPropertyNames:yJ}=Object;var uJ=Object.prototype.hasOwnProperty;function iJ($){return this[$]}var bJ,pJ,rJ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var V=Z?bJ??=new WeakMap:pJ??=new WeakMap,W=V.get($);if(W)return W}J=$!=null?vJ(lJ($)):{};let X=Z||!$||!$.__esModule?p$(J,"default",{value:$,enumerable:!0}):J;for(let Y of yJ($))if(!uJ.call(X,Y))p$(X,Y,{get:iJ.bind($,Y),enumerable:!0});if(Q)V.set($,X);return X};var n=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var o0=n((xZ)=>{Object.defineProperty(xZ,"__esModule",{value:!0});xZ.utf8Count=MQ;xZ.utf8EncodeJs=_Z;xZ.utf8EncodeTE=mZ;xZ.utf8Encode=KQ;xZ.utf8DecodeJs=BZ;xZ.utf8DecodeTD=gZ;xZ.utf8Decode=wQ;function MQ($){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 RQ=new TextEncoder,zQ=50;function mZ($,Z,J){RQ.encodeInto($,Z.subarray(J))}function KQ($,Z,J){if($.length>zQ)mZ($,Z,J);else _Z($,Z,J)}var OQ=4096;function BZ($,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,q=$[Q++]&63,P=(Y&7)<<18|G<<12|N<<6|q;if(P>65535)P-=65536,W.push(P>>>10&1023|55296),P=56320|P&1023;W.push(P)}else W.push(Y);if(W.length>=OQ)X+=String.fromCharCode(...W),W.length=0}if(W.length>0)X+=String.fromCharCode(...W);return X}var UQ=new TextDecoder,FQ=200;function gZ($,Z,J){let Q=$.subarray(Z,Z+J);return UQ.decode(Q)}function wQ($,Z,J){if(J>FQ)return gZ($,Z,J);else return BZ($,Z,J)}});var j$=n((vZ)=>{Object.defineProperty(vZ,"__esModule",{value:!0});vZ.ExtData=void 0;class fZ{type;data;constructor($,Z){this.type=$,this.data=Z}}vZ.ExtData=fZ});var s0=n((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=n((iZ)=>{Object.defineProperty(iZ,"__esModule",{value:!0});iZ.UINT32_MAX=void 0;iZ.setUint64=LQ;iZ.setInt64=jQ;iZ.getInt64=kQ;iZ.getUint64=_Q;iZ.UINT32_MAX=4294967295;function LQ($,Z,J){let Q=J/4294967296,V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function jQ($,Z,J){let Q=Math.floor(J/4294967296),V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function kQ($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function _Q($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var k$=n((oZ)=>{Object.defineProperty(oZ,"__esModule",{value:!0});oZ.timestampExtension=oZ.EXT_TIMESTAMP=void 0;oZ.encodeTimeSpecToTimestamp=rZ;oZ.encodeDateToTimeSpec=dZ;oZ.encodeTimestampExtension=nZ;oZ.decodeTimestampToTimeSpec=hZ;oZ.decodeTimestampExtension=cZ;var fQ=s0(),pZ=t0();oZ.EXT_TIMESTAMP=-1;var vQ=4294967295,lQ=17179869183;function rZ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=lQ)if(Z===0&&$<=vQ){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,pZ.setInt64)(Q,4,$),J}}function dZ($){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 nZ($){if($ instanceof Date){let Z=dZ($);return rZ(Z)}else return null}function hZ($){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,pZ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new fQ.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function cZ($){let Z=hZ($);return new Date(Z.sec*1000+Z.nsec/1e6)}oZ.timestampExtension={type:oZ.EXT_TIMESTAMP,encode:nZ,decode:cZ}});var $$=n((tZ)=>{Object.defineProperty(tZ,"__esModule",{value:!0});tZ.ExtensionCodec=void 0;var e0=j$(),rQ=k$();class _${static defaultCodec=new _$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(rQ.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,$)}}tZ.ExtensionCodec=_$});var m$=n(($J)=>{Object.defineProperty($J,"__esModule",{value:!0});$J.ensureUint8Array=nQ;function dQ($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function nQ($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(dQ($))return new Uint8Array($);else return Uint8Array.from($)}});var g$=n((QJ)=>{Object.defineProperty(QJ,"__esModule",{value:!0});QJ.Encoder=QJ.DEFAULT_INITIAL_BUFFER_SIZE=QJ.DEFAULT_MAX_DEPTH=void 0;var ZJ=o0(),cQ=$$(),JJ=t0(),oQ=m$();QJ.DEFAULT_MAX_DEPTH=100;QJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class B${extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??cQ.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 B$({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,ZJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,ZJ.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,oQ.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,JJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,JJ.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=B$});var GJ=n((YJ)=>{Object.defineProperty(YJ,"__esModule",{value:!0});YJ.encode=sQ;var aQ=g$();function sQ($,Z){return new aQ.Encoder(Z).encodeSharedRef($)}});var IJ=n((NJ)=>{Object.defineProperty(NJ,"__esModule",{value:!0});NJ.prettyByte=eQ;function eQ($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var RJ=n((PJ)=>{Object.defineProperty(PJ,"__esModule",{value:!0});PJ.CachedKeyDecoder=void 0;var ZV=o0(),JV=16,QV=16;class qJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=JV,Z=QV){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,ZV.utf8DecodeJs)($,Z,J),W=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(W,V),V}}PJ.CachedKeyDecoder=qJ});var Z$=n((FJ)=>{Object.defineProperty(FJ,"__esModule",{value:!0});FJ.Decoder=void 0;var x$=IJ(),VV=$$(),M0=t0(),WV=o0(),zJ=m$(),XV=RJ(),G0=s0(),f$="array",v0="map_key",OJ="map_value",YV=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new G0.DecodeError("The type of key must be string or number but "+typeof $)};class UJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=f$,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=v0,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===f$){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===v0||$.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 f0=-1,v$=new DataView(new ArrayBuffer(0)),GV=new Uint8Array(v$.buffer);try{v$.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"),NV=new XV.CachedKeyDecoder;class l${extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=v$;bytes=GV;headByte=f0;stack=new UJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??VV.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:NV,this.mapKeyConverter=$?.mapKeyConverter??YV}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=f0,this.stack.reset()}setBuffer($){let Z=(0,zJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===f0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,zJ.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,x$.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,x$.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===f$)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===v0){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=v0;continue $}}return Z}}readHeadByte(){if(this.headByte===f0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=f0}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,x$.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 KJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,WV.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===v0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new G0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw KJ;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 AJ=n((TJ)=>{Object.defineProperty(TJ,"__esModule",{value:!0});TJ.decode=IV;TJ.decodeMulti=qV;var HJ=Z$();function IV($,Z){return new HJ.Decoder(Z).decode($)}function qV($,Z){return new HJ.Decoder(Z).decodeMulti($)}});var EJ=n((SJ)=>{Object.defineProperty(SJ,"__esModule",{value:!0});SJ.isAsyncIterable=CJ;SJ.asyncIterableFromStream=DJ;SJ.ensureAsyncIterable=RV;function CJ($){return $[Symbol.asyncIterator]!=null}async function*DJ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function RV($){if(CJ($))return $;else return DJ($)}});var jJ=n((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.decodeAsync=UV;LJ.decodeArrayStream=FV;LJ.decodeMultiStream=wV;var y$=Z$(),u$=EJ();async function UV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeAsync(J)}function FV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeArrayStream(J)}function wV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new y$.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 CV=GJ();Object.defineProperty(f,"encode",{enumerable:!0,get:function(){return CV.encode}});var kJ=AJ();Object.defineProperty(f,"decode",{enumerable:!0,get:function(){return kJ.decode}});Object.defineProperty(f,"decodeMulti",{enumerable:!0,get:function(){return kJ.decodeMulti}});var i$=jJ();Object.defineProperty(f,"decodeAsync",{enumerable:!0,get:function(){return i$.decodeAsync}});Object.defineProperty(f,"decodeArrayStream",{enumerable:!0,get:function(){return i$.decodeArrayStream}});Object.defineProperty(f,"decodeMultiStream",{enumerable:!0,get:function(){return i$.decodeMultiStream}});var DV=Z$();Object.defineProperty(f,"Decoder",{enumerable:!0,get:function(){return DV.Decoder}});var SV=s0();Object.defineProperty(f,"DecodeError",{enumerable:!0,get:function(){return SV.DecodeError}});var EV=g$();Object.defineProperty(f,"Encoder",{enumerable:!0,get:function(){return EV.Encoder}});var LV=$$();Object.defineProperty(f,"ExtensionCodec",{enumerable:!0,get:function(){return LV.ExtensionCodec}});var jV=j$();Object.defineProperty(f,"ExtData",{enumerable:!0,get:function(){return jV.ExtData}});var j0=k$();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 i($,...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 r$($,Z){i($);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 dJ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!dJ)throw Error("Non little-endian hardware is not supported");function nJ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function y0($){if(typeof $==="string")$=nJ($);else if(J$($))$=u0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function d$($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function n$($,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 h$=($,Z)=>{function J(Q,...V){if(i(Q),$.nonceLength!==void 0){let q=V[0];if(!q)throw Error("nonce / iv required");if($.varSizeNonce)i(q);else i(q,$.nonceLength)}let W=$.tagLength;if(W&&V[1]!==void 0)i(V[1]);let X=Z(Q,...V),Y=(q,P)=>{if(P!==void 0){if(q!==2)throw Error("cipher output not supported");i(P)}},G=!1;return{encrypt(q,P){if(G)throw Error("cannot encrypt() twice with same key + nonce");return G=!0,i(q),Y(X.encrypt.length,P),X.encrypt(q,P)},decrypt(q,P){if(i(q),W&&q.length<W)throw Error("invalid ciphertext length: smaller than tagLength="+W);return Y(X.decrypt.length,P),X.decrypt(q,P)}}}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&&!hJ(Z))throw Error("invalid output, must be aligned");return Z}function hJ($){return $.byteOffset%4===0}function u0($){return Uint8Array.from($)}function $0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function i0($=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 o$=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),cJ=o$("expand 16-byte k"),oJ=o$("expand 32-byte k"),aJ=V0(cJ),sJ=V0(oJ);function K($,Z){return $<<Z|$>>>32-Z}function X$($){return $.byteOffset%4===0}var b0=64,tJ=16,a$=4294967295,c$=new Uint32Array;function eJ($,Z,J,Q,V,W,X,Y){let G=V.length,N=new Uint8Array(b0),q=V0(N),P=X$(V)&&X$(W),R=P?V0(V):c$,z=P?V0(W):c$;for(let U=0;U<G;X++){if($(Z,J,Q,q,X,Y),X>=a$)throw Error("arx: counter overflow");let O=Math.min(b0,G-U);if(P&&O===b0){let w=U/4;if(U%4!==0)throw Error("arx: invalid block position");for(let T=0,C;T<tJ;T++)C=w+T,z[C]=R[C]^q[T];U+=b0;continue}for(let w=0,T;w<O;w++)T=U+w,W[T]=V[T]^N[w];U+=O}}function s$($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:V,counterRight:W,rounds:X}=d$({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,q,P=0)=>{i(Y),i(G),i(N);let R=N.length;if(q===void 0)q=new Uint8Array(R);if(i(q),l0(P),P<0||P>=a$)throw Error("arx: counter overflow");if(q.length<R)throw Error(`arx: output (${q.length}) is shorter than data (${R})`);let z=[],U=Y.length,O,w;if(U===32)z.push(O=u0(Y)),w=sJ;else if(U===16&&J)O=new Uint8Array(32),O.set(Y),O.set(Y,16),w=aJ,z.push(O);else throw Error(`arx: invalid 32-byte key, got length=${U}`);if(!X$(G))z.push(G=u0(G));let T=V0(O);if(Q){if(G.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(w,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 H=new Uint8Array(12);H.set(G,W?0:12-G.length),G=H,z.push(G)}let D=V0(G);return eJ($,w,T,D,N,q,P,X),$0(...z),q}}var p=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class t${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($),i($,32);let Z=p($,0),J=p($,2),Q=p($,4),V=p($,6),W=p($,8),X=p($,10),Y=p($,12),G=p($,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]=p($,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],q=W[4],P=W[5],R=W[6],z=W[7],U=W[8],O=W[9],w=p($,Z+0),T=p($,Z+2),C=p($,Z+4),D=p($,Z+6),H=p($,Z+8),E=p($,Z+10),B=p($,Z+12),b=p($,Z+14),j=V[0]+(w&8191),_=V[1]+((w>>>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|H<<12)&8191),m=V[5]+(H>>>1&8191),v=V[6]+((H>>>14|E<<2)&8191),l=V[7]+((E>>>11|B<<5)&8191),y=V[8]+((B>>>8|b<<8)&8191),u=V[9]+(b>>>5|Q),A=0,d=A+j*X+_*(5*O)+g*(5*U)+M*(5*z)+x*(5*R);A=d>>>13,d&=8191,d+=m*(5*P)+v*(5*q)+l*(5*N)+y*(5*G)+u*(5*Y),A+=d>>>13,d&=8191;let a=A+j*Y+_*X+g*(5*O)+M*(5*U)+x*(5*z);A=a>>>13,a&=8191,a+=m*(5*R)+v*(5*P)+l*(5*q)+y*(5*N)+u*(5*G),A+=a>>>13,a&=8191;let t=A+j*G+_*Y+g*X+M*(5*O)+x*(5*U);A=t>>>13,t&=8191,t+=m*(5*z)+v*(5*R)+l*(5*P)+y*(5*q)+u*(5*N),A+=t>>>13,t&=8191;let k=A+j*N+_*G+g*Y+M*X+x*(5*O);A=k>>>13,k&=8191,k+=m*(5*U)+v*(5*z)+l*(5*R)+y*(5*P)+u*(5*q),A+=k>>>13,k&=8191;let J0=A+j*q+_*N+g*G+M*Y+x*X;A=J0>>>13,J0&=8191,J0+=m*(5*O)+v*(5*U)+l*(5*z)+y*(5*R)+u*(5*P),A+=J0>>>13,J0&=8191;let R0=A+j*P+_*q+g*N+M*G+x*Y;A=R0>>>13,R0&=8191,R0+=m*X+v*(5*O)+l*(5*U)+y*(5*z)+u*(5*R),A+=R0>>>13,R0&=8191;let z0=A+j*R+_*P+g*q+M*N+x*G;A=z0>>>13,z0&=8191,z0+=m*Y+v*X+l*(5*O)+y*(5*U)+u*(5*z),A+=z0>>>13,z0&=8191;let K0=A+j*z+_*R+g*P+M*q+x*N;A=K0>>>13,K0&=8191,K0+=m*G+v*Y+l*X+y*(5*O)+u*(5*U),A+=K0>>>13,K0&=8191;let O0=A+j*U+_*z+g*R+M*P+x*q;A=O0>>>13,O0&=8191,O0+=m*N+v*G+l*Y+y*X+u*(5*O),A+=O0>>>13,O0&=8191;let U0=A+j*O+_*U+g*z+M*R+x*P;A=U0>>>13,U0&=8191,U0+=m*q+v*N+l*G+y*Y+u*X,A+=U0>>>13,U0&=8191,A=(A<<2)+A|0,A=A+d|0,d=A&8191,A=A>>>13,a+=A,V[0]=d,V[1]=a,V[2]=t,V[3]=k,V[4]=J0,V[5]=R0,V[6]=z0,V[7]=K0,V[8]=O0,V[9]=U0}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;$=y0($);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),r$($,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 $Q($){let Z=(Q,V)=>$(V).update(y0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var Y$=$Q(($)=>new t$($));function ZQ($,Z,J,Q,V,W=20){let X=$[0],Y=Z[0],G=Z[1],N=Z[2],q=Z[3],P=$[1],R=J[0],z=J[1],U=V,O=0,w=$[2],T=Z[4],C=Z[5],D=Z[6],H=Z[7],E=$[3],B=X,b=Y,j=G,_=N,g=q,M=P,x=R,m=z,v=U,l=O,y=w,u=T,A=C,d=D,a=H,t=E;for(let J0=0;J0<W;J0+=2)g^=K(B+A|0,7),v^=K(g+B|0,9),A^=K(v+g|0,13),B^=K(A+v|0,18),l^=K(M+b|0,7),d^=K(l+M|0,9),b^=K(d+l|0,13),M^=K(b+d|0,18),a^=K(y+x|0,7),j^=K(a+y|0,9),x^=K(j+a|0,13),y^=K(x+j|0,18),_^=K(t+u|0,7),m^=K(_+t|0,9),u^=K(m+_|0,13),t^=K(u+m|0,18),b^=K(B+_|0,7),j^=K(b+B|0,9),_^=K(j+b|0,13),B^=K(_+j|0,18),x^=K(M+g|0,7),m^=K(x+M|0,9),g^=K(m+x|0,13),M^=K(g+m|0,18),u^=K(y+l|0,7),v^=K(u+y|0,9),l^=K(v+u|0,13),y^=K(l+v|0,18),A^=K(t+a|0,7),d^=K(A+t|0,9),a^=K(d+A|0,13),t^=K(a+d|0,18);let k=0;Q[k++]=X+B|0,Q[k++]=Y+b|0,Q[k++]=G+j|0,Q[k++]=N+_|0,Q[k++]=q+g|0,Q[k++]=P+M|0,Q[k++]=R+x|0,Q[k++]=z+m|0,Q[k++]=U+v|0,Q[k++]=O+l|0,Q[k++]=w+y|0,Q[k++]=T+u|0,Q[k++]=C+A|0,Q[k++]=D+d|0,Q[k++]=H+a|0,Q[k++]=E+t|0}function JQ($,Z,J,Q){let V=$[0],W=Z[0],X=Z[1],Y=Z[2],G=Z[3],N=$[1],q=J[0],P=J[1],R=J[2],z=J[3],U=$[2],O=Z[4],w=Z[5],T=Z[6],C=Z[7],D=$[3];for(let E=0;E<20;E+=2)G^=K(V+w|0,7),R^=K(G+V|0,9),w^=K(R+G|0,13),V^=K(w+R|0,18),z^=K(N+W|0,7),T^=K(z+N|0,9),W^=K(T+z|0,13),N^=K(W+T|0,18),C^=K(U+q|0,7),X^=K(C+U|0,9),q^=K(X+C|0,13),U^=K(q+X|0,18),Y^=K(D+O|0,7),P^=K(Y+D|0,9),O^=K(P+Y|0,13),D^=K(O+P|0,18),W^=K(V+Y|0,7),X^=K(W+V|0,9),Y^=K(X+W|0,13),V^=K(Y+X|0,18),q^=K(N+G|0,7),P^=K(q+N|0,9),G^=K(P+q|0,13),N^=K(G+P|0,18),O^=K(U+z|0,7),R^=K(O+U|0,9),z^=K(R+O|0,13),U^=K(z+R|0,18),w^=K(D+C|0,7),T^=K(w+D|0,9),C^=K(T+w|0,13),D^=K(C+T|0,18);let H=0;Q[H++]=V,Q[H++]=N,Q[H++]=U,Q[H++]=D,Q[H++]=q,Q[H++]=P,Q[H++]=R,Q[H++]=z}var G$=s$(ZQ,{counterRight:!0,extendNonceFn:JQ}),N$=h$({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){i(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(!n$(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 QQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function _0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function q0($,...Z){if(!QQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function m0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function p0($,Z){q0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function e$($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function F0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function w0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function B0($,Z){return $<<32-Z|$>>>Z}var $Z=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function ZZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var JZ=$Z?($)=>$:($)=>ZZ($);function VQ($){for(let Z=0;Z<$.length;Z++)$[Z]=ZZ($[Z]);return $}var s=$Z?($)=>$:VQ;function WQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function H0($){if(typeof $==="string")$=WQ($);return q0($),$}class I${}function QZ($){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 VZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var r0=BigInt(4294967295),WZ=BigInt(32);function q$($,Z=!1){if(Z)return{h:Number($&r0),l:Number($>>WZ&r0)};return{h:Number($>>WZ&r0)|0,l:Number($&r0)|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 P$ extends I${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,_0($),_0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=F0(this.buffer)}update($){m0(this),$=H0($),q0($);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 q=new Uint32Array(X,N,Math.floor((V-Y)/4));s(q);for(let P=0;Y+Z<V;P+=Q.length,Y+=Z)this.length+=Z,this.compress(q,P,!1);s(q);continue}J.set($.subarray(Y,Y+G),this.pos),this.pos+=G,this.length+=G,Y+=G}return this}digestInto($){m0(this),p0($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,w0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=F0($);this.get().forEach((V,W)=>Q[W]=JZ(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,q,P,R,z,U,O,w,T,C,D){let H=0;for(let E=0;E<Q;E++)({a:V,b:G,c:R,d:w}=W0(V,G,R,w,J[Z+$[H++]])),{a:V,b:G,c:R,d:w}=X0(V,G,R,w,J[Z+$[H++]]),{a:W,b:N,c:z,d:T}=W0(W,N,z,T,J[Z+$[H++]]),{a:W,b:N,c:z,d:T}=X0(W,N,z,T,J[Z+$[H++]]),{a:X,b:q,c:U,d:C}=W0(X,q,U,C,J[Z+$[H++]]),{a:X,b:q,c:U,d:C}=X0(X,q,U,C,J[Z+$[H++]]),{a:Y,b:P,c:O,d:D}=W0(Y,P,O,D,J[Z+$[H++]]),{a:Y,b:P,c:O,d:D}=X0(Y,P,O,D,J[Z+$[H++]]),{a:V,b:N,c:U,d:D}=W0(V,N,U,D,J[Z+$[H++]]),{a:V,b:N,c:U,d:D}=X0(V,N,U,D,J[Z+$[H++]]),{a:W,b:q,c:O,d:w}=W0(W,q,O,w,J[Z+$[H++]]),{a:W,b:q,c:O,d:w}=X0(W,q,O,w,J[Z+$[H++]]),{a:X,b:P,c:R,d:T}=W0(X,P,R,T,J[Z+$[H++]]),{a:X,b:P,c:R,d:T}=X0(X,P,R,T,J[Z+$[H++]]),{a:Y,b:G,c:z,d:C}=W0(Y,G,z,C,J[Z+$[H++]]),{a:Y,b:G,c:z,d:C}=X0(Y,G,z,C,J[Z+$[H++]]);return{v0:V,v1:W,v2:X,v3:Y,v4:G,v5:N,v6:q,v7:P,v8:R,v9:z,v10:U,v11:O,v12:w,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=VZ.slice(),XZ=(()=>{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 P${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();q0(W,32),this.IV=F0(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=F0(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=e$(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:V,pos:W}=this,{h:X,l:Y}=q$(BigInt($),!0),{v0:G,v1:N,v2:q,v3:P,v4:R,v5:z,v6:U,v7:O,v8:w,v9:T,v10:C,v11:D,v12:H,v13:E,v14:B,v15:b}=M$(XZ,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^w,V[1]=N^T,V[2]=q^C,V[3]=P^D,V[4]=R^H,V[5]=z^E,V[6]=U^B,V[7]=O^b}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,w0(this.state,this.buffer32,this.IV,this.bufferOut32),w0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:V}=this,{h:W,l:X}=q$(BigInt(this.chunkOut++));s(Q);let{v0:Y,v1:G,v2:N,v3:q,v4:P,v5:R,v6:z,v7:U,v8:O,v9:w,v10:T,v11:C,v12:D,v13:H,v14:E,v15:B}=M$(XZ,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^O,V[1]=G^w,V[2]=N^T,V[3]=q^C,V[4]=P^D,V[5]=R^H,V[6]=z^E,V[7]=U^B,V[8]=$[0]^O,V[9]=$[1]^w,V[10]=$[2]^T,V[11]=$[3]^C,V[12]=$[4]^D,V[13]=$[5]^H,V[14]=$[6]^E,V[15]=$[7]^B,s(Q),s(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,w0(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($){m0(this,!1),q0($),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 _0($),this.xofInto(new Uint8Array($))}digestInto($){if(p0($,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 d0($){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 IZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}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 n0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var z$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function qZ($){let Z=new Uint8Array(z$.length+32);return Z.set(z$),Z.set($.subarray(0,32),z$.length),Z}function PZ($){return typeof $==="string"?new TextEncoder().encode($):$}function T0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class K${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return i0($)}async gen256BitSecureRandomSeed(){return i0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=i0(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=PZ($),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=PZ(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 YZ($)}}var XQ=new K$,P0=XQ;var A0=64;var MZ=32,C0=8;var RZ=32;var zZ=30000,KZ=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 F($){return[$,0]}function I($){return[void 0,$]}function YQ($){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 F(new Uint8Array([0]));if(Z.length>8)return I(26);return F(new Uint8Array(Z))}function GQ($,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 F({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,F($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);return F(new Date($))}readVarInt(){let[$,Z]=GQ(this.data,this.pos);if(Z!==0)return I(Z);this.pos+=$.bytesRead;let J=$.value;return F(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 F(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+=$,F(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 F(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return I(Q);Z.push(J)}return F(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]=YQ($);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 g0={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 F({id:Z,ts:Q})}};function UZ($){let Z=new L,J=Z.writeStruct(g0,$);if(J!==0)return I(J);let Q=Z.result();return F(Q)}var O$={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]=g0.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,q]=$.readVarInt();if(q!==0)return I(q);let P;if(N>0){let[R,z]=$.readBytes(RZ);if(z!==0)return I(z);P=R}return F({eid:Z,off:W,ctr:Y,len:N,hsh:P})}};function FZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function wZ($,Z,J,Q){let V;if($.bod&&$.len>0)V=await J.blake3($.bod);let W=new L,X=O$.encode(W,{...$,hsh:V});if(X!==0)return I(X);let Y=W.result(),G=await Z.kdmFor(Y),N=Q.deriveCipher(G,"encrypt"),q=await N.encrypt(Y),P=$.bod?await N.encrypt($.bod):new Uint8Array(0),R=await Z.sign(q);return F({sig:R,kdm:G,headCph:q,bodyCph:P})}async function HZ($,Z,J,Q,V){let W=new c($),[X,Y]=O$.decode(W);if(Y!==0)return I(14);let G;try{G=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return I(20)}let N=X.hsh&&G===void 0,q=X.hsh===void 0&&G!==void 0;if(N||q)return I(19);if(X.hsh&&G){let R=await Q.blake3(G);if(!IZ(R,X.hsh))return I(19)}let P=V??await Q.blake3($);return F({msgHead:X,bod:G,headHash:P})}async function U$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return I(Q);let V=J.result(),W=await $.sign(V);return F({pubKey:$.publicKey,sig:W,timestamp:Z})}async function e($,Z,J){let Q=J.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Q-V)>zZ)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 TZ($,Z,J,Q){let V=Z.getTime()-$.getTime(),W=J.getTime()-Q.getTime();return(V+W)/2}var x0={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 F({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(x0,Z.subscription.stat);if(X!==0)return X;let Y=$.writeStruct(x0,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[q,P]=$.readVarInt();if(P!==0)return I(P);let[R,z]=$.readStruct(x0);if(z!==0)return I(z);let[U,O]=$.readStruct(x0);if(O!==0)return I(O);return F({status:Q,timeRcvd:V,timeSent:X,subscription:{term:G,elapsed:q,stat:R,dyn:U}})}};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 F({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(MZ);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 F({pubKey:Z,sig:Q,timestamp:W})}};var AZ={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,[q,P]=await W.hasUser(N);if(P!==0)return P;if(!q)return 5;let[R,z]=Z.readVarInt();if(z!==0)return z;if(!Z.done())return 8;let[U,O]=await W.listHeads(N,R);if(O!==0)return O;return J.writeStructs(F$,U)},decodeResp($){return $.readStructs(F$)}};var w$={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 F({seq:Z,bodyCph:Q})}};var CZ={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,[q,P]=await W.hasUser(N);if(P!==0)return P;if(!q)return 5;let R=[];while(!Z.done()){let[O,w]=Z.readVarInt();if(w!==0)return w;R.push(O)}console.info(`PULL: ${R.length} bags`);let[z,U]=await W.getBodies(N,R);if(U!==0)return U;if(!z)return 17;for(let{seq:O,bodyCph:w}of z){let T={seq:O,bodyCph:w},C=J.writeStruct(w$,T);if(C!==0)return C}return 0},decodeResp($){return $.readStructs(w$)}};var H$={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 F({sig:Z,kdm:Q,headCph:W,bodyCph:Y})}};var T$={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 F({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 F({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 F({idx:Z,status:W});let[X,Y]=$.readVarInt();if(Y!==0)return I(Y);return F({idx:Z,status:W,seq:X})}};var DZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;let X=V.writeStructs(H$,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:q}=Y,[P,R]=await W.hasUser(q);if(R!==0)return R;if(!P)return 5;let[z,U]=Z.readStructs(H$);if(U!==0)return U;console.info(`PUSH: ${z.length} bags`);let O=[],w=[];for(let H=0;H<z.length;H++){let E=z[H];if(!await FZ(E,q,V)){let b={idx:H,status:3},j=J.writeStruct(h0,b);if(j!==0)return j;continue}O.push(H),w.push(E)}let[T,C]=await W.setBags(q,w);if(C!==0)return C;if(!T||T.length!==w.length)return 17;let D=[];for(let H=0;H<w.length;H++){let E=w[H],B=O[H],b=T[H],j=new L,_=j.writeStruct(E0,E);if(_!==0)return _;let g=j.result(),M={seq:b,headCph:g};if(z.length===1&&E.bodyCph.length<=KZ)M.bodyCph=E.bodyCph;D.push(M);let x={idx:B,status:0,seq:b},m=J.writeStruct(h0,x);if(m!==0)return m}if(D.length>0){let H=new L,E=H.writeStructs(T$,D);if(E!==0)return E;let B=H.result();await Promise.resolve(X.push(q,B))}return 0},decodeResp($){return $.readStructs(h0)}};var SZ={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[q,P]=await W.addUser(N);if(P!==0)return P;return 0},decodeResp($){return F(void 0)}};class A${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 r={user:{path:"/user",endpoint:SZ,name:0},push:{path:"/push",endpoint:DZ,name:2},peek:{path:"/peek",endpoint:AZ,name:1},pull:{path:"/pull",endpoint:CZ,name:3}},NQ={0:r.user,2:r.push,1:r.peek,3:r.pull},EZ={[r.user.path]:r.user,[r.push.path]:r.push,[r.peek.path]:r.peek,[r.pull.path]:r.pull};class LZ{url;listener;constructor($){this.url=$;this.listener=new A$($)}async call($,Z){let{path:J}=NQ[$],Q=new URL(J,this.url);try{return await qQ(Q,Z)}catch{return I(25)}}}var C$=($)=>{return new LZ($.handle)};function L0($){let Z=new L;if(Z.writeStruct(S0,$)!==0)return new Response(null,{status:500});return D$(Z)}function D$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var IQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function S$($){return new Response($.body,{headers:{...$.headers,...IQ},status:$.status,statusText:$.statusText})}async function qQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return I(24);let Q=await c.fromResponse(J);return F(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,transport:Q}=this,{endpoint:V,name:W}=$,X=await this.identity(),Y=J.now(),[G,N]=await U$(X,Y);if(N!==0)return I(N);let q=new L,P=await V.encodeReq(this,X,G,Z,q);if(P!==0)return I(P);let R=J.now(),[z,U]=await Q.call(W,q),O=J.now();if(U!==0)return I(U);let[w,T]=z.readStruct(S0);if(T!==0)return I(T);if(w.status!==0)return I(w.status);let D={clockOffset:TZ(R,w.timeRcvd,w.timeSent,O),subscription:w.subscription},H=await this.updateHostMeta(D);if(H!==0)return I(H);return V.decodeResp(z)}identity=()=>{let{host:$,enclave:Z}=this;return Z.deriveIdentity($.label,$.idx??0)};seal=async($)=>{let{crypto:Z,enclave:J}=this,Q=await this.identity();return wZ($,Q,Z,J)};register=()=>this.call(r.user,[]);peek=($)=>this.call(r.peek,[$]);push=($)=>this.call(r.push,$);pull=($)=>this.call(r.pull,$);listen=async($,Z,J)=>{let{clock:Q,transport:V}=this,{listener:W}=V,X=await this.identity(),Y=Q.now(),[G,N]=await U$(X,Y);if(N!==0)return N;return await W.connect(G,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class E${#Q;#$;constructor($,Z){this.#Q=$,this.#$=Z}deriveCipher($,Z){let J=$.slice(),Q=(X)=>this.#V(J,X),V=(X)=>this.#W(J,X);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:V}),both:Object.freeze({encrypt:Q,decrypt:V})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,V=await this.#J(J,Q);return Object.freeze({publicKey:V.publicKey,sign:(W)=>this.#Y(J,Q,W),kdmFor:(W)=>this.#G(J,Q,W)})}async#V($,Z){let J=await this.#Z($);return this.#$.encryptXSalsa20Poly1305Combined(Z,J)}async#W($,Z){let J=await this.#Z($);return this.#$.decryptXSalsa20Poly1305Combined(Z,J)}async#Z($){return this.#$.blake3(n0(this.#Q,$))}async#X($,Z){let J=new TextEncoder().encode($),Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,BigInt(Z),!1),await this.#Z(n0(J,Q))}async#J($,Z){let J=await this.#X($,Z);return this.#$.deriveEd25519KeyPair(J)}async#Y($,Z,J){let Q=await this.#J($,Z);return this.#$.signEd25519(J,Q.privateKey)}async#G($,Z,J){let Q=await this.#J($,Z),V=n0(Q.privateKey,J);return(await this.#$.blake3(V)).slice(0,C0)}}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 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 jZ($,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,q]=UZ(G);if(q!==0)return I(q);let P=V.getTime()-G.ts.getTime();return F({eid:N,off:P,ctr:Q,len:J.length,bod:J})}class PQ{singletonType;latest;latestOff=-1;emitter=new L$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new c(Z.eid),[Q,V]=J.readStruct(g0);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 kZ($,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))return I(3);let P=J.deriveCipher(G,"decrypt"),R;try{R=await P.decrypt(N)}catch{return I(20)}return F({kdm:G,headEnc:R})}var k0=rJ(_J(),1),_V={encode:k0.encode,decode:k0.decode,decodeAsync:k0.decodeAsync},mV=_V;import{Database as BV}from"bun:sqlite";var BG=Symbol("EntityID");var gG=Symbol("MasterSeed"),xG=Symbol("DerivationSeed"),fG=Symbol("PublicKey"),vG=Symbol("PrivateKey"),lG=Symbol("HostSpecificKeyPair"),yG=Symbol("Hash"),N0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function gV($="diplomatic.db"){let Z=new BV($);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 yJ=Object.create;var{getPrototypeOf:lJ,defineProperty:b$,getOwnPropertyNames
|
|
|
11
11
|
PRIMARY KEY (userPubKey, seq),
|
|
12
12
|
UNIQUE (userPubKey, seq)
|
|
13
13
|
);
|
|
14
|
-
`),{async addUser(J){try{let Q=h(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),
|
|
14
|
+
`),{async addUser(J){try{let Q=h(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),F(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 F(Boolean(V?.ok))}catch{return I(17)}},async subMeta(J){return F(N0)},async setBags(J,Q){if(Q.length<1)return F([]);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 q=new L;q.writeStruct(E0,N),G.run(V,X,q.result(),N.bodyCph),Y.push(X)}return Z.exec("COMMIT"),F(Y)}catch(W){try{Z.exec("ROLLBACK")}catch{}throw W}}catch{return I(17)}},async getBodies(J,Q){if(Q.length<1)return F([]);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),q=N.map(()=>"?").join(","),P=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${q})`).all(V,...N);for(let R of P)if(R.bodyCph)W.push({seq:R.seq,bodyCph:new Uint8Array(R.bodyCph)})}return F(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 F(W.map((X)=>({seq:X.seq,headCph:new Uint8Array(X.headCph)})))}catch{return I(17)}}}}var xV=gV(),mJ=xV;class b${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 S$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),S$(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=EZ[Y]?.endpoint;if(!G){let N=Z.now();return L0({status:13,timeRcvd:J,timeSent:N,subscription:N0})}try{let N=new L,q=await G.handleReq(this,X,N),P=N0,R={status:q,timeRcvd:J,timeSent:this.clock.now(),subscription:P},z=new L;if(z.writeStruct(S0,R)!==0)return new Response(null,{status:500});if(q!==0){let O=Z.now();return L0({status:q,timeRcvd:J,timeSent:O,subscription:N0})}return N.prependBytes(z.result()),D$(N)}catch(N){let q=Z.now();return console.error(N),console.trace(),L0({status:12,timeRcvd:J,timeSent:q,subscription:N0})}}}async function BJ($,Z){let Q=new URL($.url).searchParams.get(OZ);if(!Q)return I(11);let V=d0(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 F(X)}class xJ{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 gJ=new xJ;async function fV($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new b$(mJ,P0,gJ,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 BJ(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;gJ.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 fJ{enclave;conn;clock;constructor({seed:$,clock:Z=new D0}){this.enclave=new E$($,P0),this.clock=Z}async connect($,Z){let J=new D0,Q=()=>Promise.resolve(0);this.conn=new c0(this.enclave,P0,$,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 F(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.identity(),[Q,V]=await kZ($,J.publicKey,this.enclave,P0);if(V!==0)return I(V);let W=this.enclave.deriveCipher(Q.kdm,"decrypt");return HZ(Q.headEnc,Z.bodyCph,W,P0)}async upsertSingletonSync($,Z){let[J,Q]=await jZ($,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 vV({seed:$,host:Z,transport:J}){let Q=new fJ({seed:$}),V=await Q.connect(Z,J);return[Q,V]}async function kN({seed:$,host:Z,transport:J}){let Q=J??C$(Z),[V,W]=await vV({seed:$,host:Z,transport:Q});if(W!==0)console.error(`Failed to initialize CLI: ${S[W]}`),process.exit(1);return V}function _N($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=d0(Z);if(J.length!==32)console.error(`${$} must be 64 hex chars (32 bytes)`),process.exit(1);return J}function mN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{fV as runBunHost,T$ as notifItemCodec,mV as msgpack,_N as loadSeedOrPanic,mN as loadHostOrPanic,kN as initCLIOrPanic,vV as initCLI,C$ as hostHTTPTransport,S as Status,c as Decoder,fJ as CLIClient};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { IClock } from "./clock.ts";
|
|
2
2
|
import { type IAuthTimestamp } from "./codecs/authTimestamp.ts";
|
|
3
3
|
import { Status } from "./consts.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Identity } from "./crypto/enclave.ts";
|
|
5
|
+
import type { IHostCrypto } from "./types.ts";
|
|
5
6
|
import { ValStat } from "./valstat.ts";
|
|
6
7
|
export type EncodedAuthTimestamp = Uint8Array;
|
|
7
|
-
export declare function makeAuthTimestamp(
|
|
8
|
+
export declare function makeAuthTimestamp(identity: Pick<Identity, "publicKey" | "sign">, ts: Date): Promise<ValStat<IAuthTimestamp>>;
|
|
8
9
|
export declare function validateAuthTimestamp(authTS: IAuthTimestamp, crypto: IHostCrypto, clock: IClock): Promise<Status>;
|
package/dist/cli/shared/bag.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { IMessageHead } from "./codecs/messageHead.ts";
|
|
2
|
-
import { Enclave } from "./enclave.ts";
|
|
2
|
+
import { type DecryptCipher, Enclave, type Identity } from "./crypto/enclave.ts";
|
|
3
3
|
import { EncodedMessage } from "./message.ts";
|
|
4
4
|
import { type ValStat } from "./valstat.ts";
|
|
5
|
-
import type { Hash,
|
|
5
|
+
import type { Hash, IBag, ICrypto, IHostCrypto, IMessage, IMessageWithHash, PublicKey } from "./types.ts";
|
|
6
6
|
export declare function bagSigValid(bag: IBag, pubKey: PublicKey, crypto: IHostCrypto): Promise<boolean>;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function sealBag(msg: IMessage, keys: HostSpecificKeyPair, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IBag>>;
|
|
7
|
+
export declare function sealBag(msg: IMessage, identity: Identity, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IBag>>;
|
|
9
8
|
export interface IOpenBag {
|
|
10
9
|
msgHead: IMessageHead;
|
|
11
10
|
bod?: EncodedMessage;
|
|
12
11
|
headHash: Hash;
|
|
13
12
|
}
|
|
14
|
-
export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined,
|
|
13
|
+
export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined, cipher: DecryptCipher, crypto: ICrypto,
|
|
15
14
|
/** When set (e.g. from peek), skip blake3(headEnc). */
|
|
16
15
|
headHashKnown?: Hash): Promise<ValStat<IOpenBag>>;
|
|
17
16
|
export declare function openBag(bag: IBag, pubKey: PublicKey, crypto: ICrypto, enclave: Enclave): Promise<ValStat<IMessageWithHash>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IClock } from "./clock.ts";
|
|
2
2
|
import { Status } from "./consts.ts";
|
|
3
|
-
import { Enclave } from "./enclave.ts";
|
|
4
|
-
import type { HostHandle,
|
|
3
|
+
import { Enclave, type Identity } from "./crypto/enclave.ts";
|
|
4
|
+
import type { HostHandle, IBag, ICrypto, IHostConnectionInfo, IHostMetadata, IMessage, ITransport, PushReceiver } from "./types.ts";
|
|
5
5
|
import { ValStat } from "./valstat.ts";
|
|
6
6
|
export default class DiplomaticClientAPI<Handle extends HostHandle> {
|
|
7
7
|
enclave: Enclave;
|
|
@@ -12,7 +12,7 @@ export default class DiplomaticClientAPI<Handle extends HostHandle> {
|
|
|
12
12
|
private updateHostMeta;
|
|
13
13
|
constructor(enclave: Enclave, crypto: ICrypto, host: IHostConnectionInfo<Handle>, clock: IClock, transport: ITransport, updateHostMeta: (meta: IHostMetadata) => Promise<Status>);
|
|
14
14
|
private call;
|
|
15
|
-
|
|
15
|
+
identity: () => Promise<Identity>;
|
|
16
16
|
seal: (msg: IMessage) => Promise<ValStat<IBag>>;
|
|
17
17
|
register: () => Promise<ValStat<void>>;
|
|
18
18
|
peek: (lastSeq: number) => Promise<ValStat<import("./codecs/peekItem.ts").IBagPeekItem[]>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ICrypto, MasterSeed, PublicKey } from "../types.ts";
|
|
2
|
+
export type EncryptCipher = {
|
|
3
|
+
encrypt: (data: Uint8Array) => Promise<Uint8Array>;
|
|
4
|
+
};
|
|
5
|
+
export type DecryptCipher = {
|
|
6
|
+
decrypt: (data: Uint8Array) => Promise<Uint8Array>;
|
|
7
|
+
};
|
|
8
|
+
/** Encrypt + decrypt capability for one KDM. */
|
|
9
|
+
export type DerivedCipher = EncryptCipher & DecryptCipher;
|
|
10
|
+
/** Which ops the caller needs; only those methods are present on the handle. */
|
|
11
|
+
export type CipherUsage = "encrypt" | "decrypt" | "both";
|
|
12
|
+
/** Return shape of `deriveCipher` for a given usage (type-level enforcement). */
|
|
13
|
+
export type CipherForUsage<U extends CipherUsage> = {
|
|
14
|
+
encrypt: EncryptCipher;
|
|
15
|
+
decrypt: DecryptCipher;
|
|
16
|
+
both: DerivedCipher;
|
|
17
|
+
}[U];
|
|
18
|
+
/**
|
|
19
|
+
* Path-scoped signing identity: public key is public; sign/kdmFor re-enter
|
|
20
|
+
* the enclave so the private key never leaves. Used for hosts, export files, etc.
|
|
21
|
+
*/
|
|
22
|
+
export type Identity = {
|
|
23
|
+
readonly publicKey: PublicKey;
|
|
24
|
+
sign: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
25
|
+
/** Per-bag KDM mixed with this identity's private key (see bag seal). */
|
|
26
|
+
kdmFor: (msgHeadEnc: Uint8Array) => Promise<Uint8Array>;
|
|
27
|
+
};
|
|
28
|
+
export declare class Enclave {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(seed: MasterSeed, crypto: ICrypto);
|
|
31
|
+
/**
|
|
32
|
+
* Cipher for public KDM. Does not hold key bytes; each op re-enters the
|
|
33
|
+
* enclave (async, hardware-shaped). `usage` selects the return shape:
|
|
34
|
+
* `"encrypt"` → `{ encrypt }`, `"decrypt"` → `{ decrypt }`, `"both"` → both.
|
|
35
|
+
*/
|
|
36
|
+
deriveCipher<U extends CipherUsage>(kdm: Uint8Array, usage: U): CipherForUsage<U>;
|
|
37
|
+
/**
|
|
38
|
+
* Path-scoped identity (label+index). Private key stays in the enclave; only
|
|
39
|
+
* publicKey and capability methods are returned (frozen).
|
|
40
|
+
*/
|
|
41
|
+
deriveIdentity(keyPath: string, idx?: number): Promise<Identity>;
|
|
42
|
+
}
|
|
@@ -2,8 +2,8 @@ import { IClock } from "./clock.ts";
|
|
|
2
2
|
import { Decoder, Encoder } from "./codec.ts";
|
|
3
3
|
import { IAuthTimestamp } from "./codecs/authTimestamp.ts";
|
|
4
4
|
import { Status } from "./consts.ts";
|
|
5
|
-
import { Enclave } from "./enclave.ts";
|
|
6
|
-
import {
|
|
5
|
+
import { Enclave, type Identity } from "./crypto/enclave.ts";
|
|
6
|
+
import { ICrypto, IProtoHost } from "./types.ts";
|
|
7
7
|
import { ValStat } from "./valstat.ts";
|
|
8
8
|
interface IProtoClient {
|
|
9
9
|
crypto: ICrypto;
|
|
@@ -11,13 +11,12 @@ interface IProtoClient {
|
|
|
11
11
|
clock: IClock;
|
|
12
12
|
}
|
|
13
13
|
export interface IAuthenticatedEndpoint<ReqItem, Resp> {
|
|
14
|
-
encodeReq(client: IProtoClient,
|
|
14
|
+
encodeReq(client: IProtoClient, identity: Identity, authTS: IAuthTimestamp, body: Iterable<ReqItem>, reqEnc: Encoder): Promise<Status>;
|
|
15
15
|
handleReq(host: IProtoHost, reqDec: Decoder, respEnc: Encoder): Promise<Status>;
|
|
16
16
|
decodeResp(respDec: Decoder): ValStat<Resp>;
|
|
17
17
|
}
|
|
18
18
|
export interface IAuthData {
|
|
19
|
-
|
|
19
|
+
identity: Identity;
|
|
20
20
|
authTS: IAuthTimestamp;
|
|
21
21
|
}
|
|
22
|
-
export declare function hostKeys(host: IProtoClient, keyPath: string, idx?: number): Promise<HostSpecificKeyPair>;
|
|
23
22
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IBagPeekItem } from "./codecs/peekItem.ts";
|
|
2
|
-
import { Enclave } from "./enclave.ts";
|
|
3
|
-
import {
|
|
2
|
+
import { Enclave } from "./crypto/enclave.ts";
|
|
3
|
+
import { ICrypto, PublicKey } from "./types.ts";
|
|
4
4
|
import { ValStat } from "./valstat.ts";
|
|
5
5
|
export interface IDecryptedBagPeekItem {
|
|
6
6
|
kdm: Uint8Array;
|
|
7
7
|
headEnc: Uint8Array;
|
|
8
8
|
}
|
|
9
|
-
export declare function decryptPeekItem(item: IBagPeekItem,
|
|
9
|
+
export declare function decryptPeekItem(item: IBagPeekItem, pubKey: PublicKey, enclave: Enclave, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;
|
|
@@ -14,6 +14,12 @@ export type SerializedContent = Uint8Array;
|
|
|
14
14
|
export interface IMsgEntBody<T = unknown> {
|
|
15
15
|
gid?: GroupID;
|
|
16
16
|
pid?: EntityID;
|
|
17
|
+
/**
|
|
18
|
+
* Optional multi-value tags for reverse multi-ref / label lookup (multiEntry-indexed).
|
|
19
|
+
* Opaque strings; entDB does not parse semantics. Empty strings and duplicates are
|
|
20
|
+
* dropped on apply. Omit or [] means no tags.
|
|
21
|
+
*/
|
|
22
|
+
tags?: string[];
|
|
17
23
|
type: string;
|
|
18
24
|
body?: T;
|
|
19
25
|
}
|
|
@@ -10,7 +10,7 @@ export type OpenEntDBOptions = {
|
|
|
10
10
|
*/
|
|
11
11
|
cache?: boolean;
|
|
12
12
|
/**
|
|
13
|
-
* Secondary type/pid/gid indexes on the in-memory layer (default true).
|
|
13
|
+
* Secondary type/pid/gid/tag indexes on the in-memory layer (default true).
|
|
14
14
|
* Speeds up getEntities list queries after a type is warm.
|
|
15
15
|
* Ignored when `cache` is false.
|
|
16
16
|
*/
|
|
@@ -21,10 +21,18 @@ export type EntitiesQuery = {
|
|
|
21
21
|
} | {
|
|
22
22
|
type: string;
|
|
23
23
|
pid: EntityID;
|
|
24
|
+
} | {
|
|
25
|
+
type: string;
|
|
26
|
+
tag: string;
|
|
24
27
|
} | {
|
|
25
28
|
type: string;
|
|
26
29
|
updatedBetween: IDateRange;
|
|
27
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Normalize tags for storage/index: drop non-strings and empty strings, dedupe
|
|
33
|
+
* (first occurrence wins). Returns undefined when there are no tags left.
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeTags(tags: unknown): string[] | undefined;
|
|
28
36
|
/** Result of applying ops to EntDB. */
|
|
29
37
|
export type ApplyResult = {
|
|
30
38
|
stats: Status[];
|
package/dist/web/entdb/idb.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare const typeIndexName = "entity_type_created_at";
|
|
|
7
7
|
export declare const typeUpdatedAtIndexName = "entity_type_updated_at";
|
|
8
8
|
export declare const typeGroupIndexName = "entity_type_group_id";
|
|
9
9
|
export declare const typeParentIndexName = "entity_type_parent_id";
|
|
10
|
+
/** multiEntry index on tags[]; query by tag then filter by type. */
|
|
11
|
+
export declare const tagsIndexName = "entity_tags";
|
|
10
12
|
export declare class EntIDB implements IEntDB {
|
|
11
13
|
db: IDBDatabase | undefined;
|
|
12
14
|
init(): Promise<void>;
|
|
@@ -20,6 +22,7 @@ export declare class EntIDB implements IEntDB {
|
|
|
20
22
|
getAllOfTypeUpdatedBetween<T>(opType: string, start: Date, end: Date): Promise<ValStat<IEntity<T>[]>>;
|
|
21
23
|
getGroupMembers<T>(opType: string, gid: GroupID): Promise<ValStat<IEntity<T>[]>>;
|
|
22
24
|
getAllOfType<T>(opType: string): Promise<ValStat<IEntity<T>[]>>;
|
|
25
|
+
getByTag<T>(opType: string, tag: string): Promise<ValStat<IEntity<T>[]>>;
|
|
23
26
|
private getAllEntities;
|
|
24
27
|
getEntities<T>(query: EntitiesQuery): Promise<ValStat<IEntity<T>[]>>;
|
|
25
28
|
countEntities({ type }: {
|
|
@@ -10,12 +10,13 @@ type EntitiesQuery = {
|
|
|
10
10
|
type: string;
|
|
11
11
|
gid?: GroupID;
|
|
12
12
|
pid?: EntityID;
|
|
13
|
+
tag?: string;
|
|
13
14
|
updatedBetween?: IDateRange;
|
|
14
15
|
};
|
|
15
16
|
/** Options for {@link EntDBMemory}. */
|
|
16
17
|
export type EntDBMemoryOptions = {
|
|
17
18
|
/**
|
|
18
|
-
* Secondary type / type+pid / type+gid indexes for list queries.
|
|
19
|
+
* Secondary type / type+pid / type+gid / type+tag indexes for list queries.
|
|
19
20
|
* Default true. Disable only if you need to save the index memory.
|
|
20
21
|
*/
|
|
21
22
|
indexes?: boolean;
|
|
@@ -29,6 +30,8 @@ export declare class EntDBMemory implements IEntDB {
|
|
|
29
30
|
private byTypePid;
|
|
30
31
|
/** type → gid → eidKey → ent */
|
|
31
32
|
private byTypeGid;
|
|
33
|
+
/** type → tag → eidKey → ent */
|
|
34
|
+
private byTypeTag;
|
|
32
35
|
constructor(initEnts?: IEntity[], opts?: EntDBMemoryOptions);
|
|
33
36
|
/** Install or replace an entity; keeps secondary indexes in sync. */
|
|
34
37
|
put(ent: IEntity): void;
|