@interncom/diplomatic 0.12.8 → 0.12.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var KQ=Object.create;var{getPrototypeOf:RQ,defineProperty:PZ,getOwnPropertyNames:HQ}=Object;var FQ=Object.prototype.hasOwnProperty;function IQ($){return this[$]}var UQ,wQ,CQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var X=Z?UQ??=new WeakMap:wQ??=new WeakMap,Y=X.get($);if(Y)return Y}J=$!=null?KQ(RQ($)):{};let G=Z||!$||!$.__esModule?PZ(J,"default",{value:$,enumerable:!0}):J;for(let V of HQ($))if(!FQ.call(G,V))PZ(G,V,{get:IQ.bind($,V),enumerable:!0});if(Q)X.set($,G);return G};var c=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var O$=c((MJ)=>{Object.defineProperty(MJ,"__esModule",{value:!0});MJ.utf8Count=ZX;MJ.utf8EncodeJs=qJ;MJ.utf8EncodeTE=NJ;MJ.utf8Encode=XX;MJ.utf8DecodeJs=zJ;MJ.utf8DecodeTD=PJ;MJ.utf8Decode=VX;function ZX($){let Z=$.length,J=0,Q=0;while(Q<Z){let X=$.charCodeAt(Q++);if((X&4294967168)===0){J++;continue}else if((X&4294965248)===0)J+=2;else{if(X>=55296&&X<=56319){if(Q<Z){let Y=$.charCodeAt(Q);if((Y&64512)===56320)++Q,X=((X&1023)<<10)+(Y&1023)+65536}}if((X&4294901760)===0)J+=3;else J+=4}}return J}function qJ($,Z,J){let Q=$.length,X=J,Y=0;while(Y<Q){let G=$.charCodeAt(Y++);if((G&4294967168)===0){Z[X++]=G;continue}else if((G&4294965248)===0)Z[X++]=G>>6&31|192;else{if(G>=55296&&G<=56319){if(Y<Q){let V=$.charCodeAt(Y);if((V&64512)===56320)++Y,G=((G&1023)<<10)+(V&1023)+65536}}if((G&4294901760)===0)Z[X++]=G>>12&15|224,Z[X++]=G>>6&63|128;else Z[X++]=G>>18&7|240,Z[X++]=G>>12&63|128,Z[X++]=G>>6&63|128}Z[X++]=G&63|128}}var JX=new TextEncoder,QX=50;function NJ($,Z,J){JX.encodeInto($,Z.subarray(J))}function XX($,Z,J){if($.length>QX)NJ($,Z,J);else qJ($,Z,J)}var YX=4096;function zJ($,Z,J){let Q=Z,X=Q+J,Y=[],G="";while(Q<X){let V=$[Q++];if((V&128)===0)Y.push(V);else if((V&224)===192){let q=$[Q++]&63;Y.push((V&31)<<6|q)}else if((V&240)===224){let q=$[Q++]&63,N=$[Q++]&63;Y.push((V&31)<<12|q<<6|N)}else if((V&248)===240){let q=$[Q++]&63,N=$[Q++]&63,z=$[Q++]&63,P=(V&7)<<18|q<<12|N<<6|z;if(P>65535)P-=65536,Y.push(P>>>10&1023|55296),P=56320|P&1023;Y.push(P)}else Y.push(V);if(Y.length>=YX)G+=String.fromCharCode(...Y),Y.length=0}if(Y.length>0)G+=String.fromCharCode(...Y);return G}var GX=new TextDecoder,WX=200;function PJ($,Z,J){let Q=$.subarray(Z,Z+J);return GX.decode(Q)}function VX($,Z,J){if(J>WX)return PJ($,Z,J);else return zJ($,Z,J)}});var e$=c((KJ)=>{Object.defineProperty(KJ,"__esModule",{value:!0});KJ.ExtData=void 0;class OJ{type;data;constructor($,Z){this.type=$,this.data=Z}}KJ.ExtData=OJ});var R$=c((HJ)=>{Object.defineProperty(HJ,"__esModule",{value:!0});HJ.DecodeError=void 0;class K$ extends Error{constructor($){super($);let Z=Object.create(K$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:K$.name})}}HJ.DecodeError=K$});var H$=c((IJ)=>{Object.defineProperty(IJ,"__esModule",{value:!0});IJ.UINT32_MAX=void 0;IJ.setUint64=RX;IJ.setInt64=HX;IJ.getInt64=FX;IJ.getUint64=IX;IJ.UINT32_MAX=4294967295;function RX($,Z,J){let Q=J/4294967296,X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function HX($,Z,J){let Q=Math.floor(J/4294967296),X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function FX($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function IX($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var t$=c((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.timestampExtension=LJ.EXT_TIMESTAMP=void 0;LJ.encodeTimeSpecToTimestamp=CJ;LJ.encodeDateToTimeSpec=TJ;LJ.encodeTimestampExtension=DJ;LJ.decodeTimestampToTimeSpec=AJ;LJ.decodeTimestampExtension=jJ;var DX=R$(),wJ=H$();LJ.EXT_TIMESTAMP=-1;var AX=4294967295,jX=17179869183;function CJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=jX)if(Z===0&&$<=AX){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,X=new Uint8Array(8),Y=new DataView(X.buffer);return Y.setUint32(0,Z<<2|J&3),Y.setUint32(4,Q),X}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,wJ.setInt64)(Q,4,$),J}}function TJ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,X=Math.floor(Q/1e9);return{sec:J+X,nsec:Q-X*1e9}}function DJ($){if($ instanceof Date){let Z=TJ($);return CJ(Z)}else return null}function AJ($){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),X=(J&3)*4294967296+Q,Y=J>>>2;return{sec:X,nsec:Y}}case 12:{let J=(0,wJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new DX.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function jJ($){let Z=AJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}LJ.timestampExtension={type:LJ.EXT_TIMESTAMP,encode:DJ,decode:jJ}});var I$=c((kJ)=>{Object.defineProperty(kJ,"__esModule",{value:!0});kJ.ExtensionCodec=void 0;var F$=e$(),BX=t$();class $Z{static defaultCodec=new $Z;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(BX.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 X=Q($,Z);if(X!=null){let Y=-1-J;return new F$.ExtData(Y,X)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let X=Q($,Z);if(X!=null){let Y=J;return new F$.ExtData(Y,X)}}}if($ instanceof F$.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 F$.ExtData(Z,$)}}kJ.ExtensionCodec=$Z});var ZZ=c((BJ)=>{Object.defineProperty(BJ,"__esModule",{value:!0});BJ.ensureUint8Array=SX;function xX($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function SX($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(xX($))return new Uint8Array($);else return Uint8Array.from($)}});var QZ=c((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.Encoder=gJ.DEFAULT_INITIAL_BUFFER_SIZE=gJ.DEFAULT_MAX_DEPTH=void 0;var xJ=O$(),fX=I$(),SJ=H$(),vX=ZZ();gJ.DEFAULT_MAX_DEPTH=100;gJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class JZ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??fX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??gJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??gJ.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 JZ({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,xJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,xJ.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,vX.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 X of J){let Y=$[X];if(!(this.ignoreUndefined&&Y===void 0))this.encodeString(X),this.doEncode(Y,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,SJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,SJ.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}}gJ.Encoder=JZ});var bJ=c((lJ)=>{Object.defineProperty(lJ,"__esModule",{value:!0});lJ.encode=lX;var yX=QZ();function lX($,Z){return new yX.Encoder(Z).encodeSharedRef($)}});var iJ=c((hJ)=>{Object.defineProperty(hJ,"__esModule",{value:!0});hJ.prettyByte=hX;function hX($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var nJ=c((uJ)=>{Object.defineProperty(uJ,"__esModule",{value:!0});uJ.CachedKeyDecoder=void 0;var pX=O$(),uX=16,dX=16;class pJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=uX,Z=dX){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 X of Q){let Y=X.bytes;for(let G=0;G<J;G++)if(Y[G]!==$[Z+G])continue $;return X.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 X=(0,pX.utf8DecodeJs)($,Z,J),Y=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(Y,X),X}}uJ.CachedKeyDecoder=pJ});var U$=c((sJ)=>{Object.defineProperty(sJ,"__esModule",{value:!0});sJ.Decoder=void 0;var XZ=iJ(),nX=I$(),T0=H$(),cX=O$(),cJ=ZZ(),rX=nJ(),P0=R$(),YZ="array",o0="map_key",oJ="map_value",oX=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new P0.DecodeError("The type of key must be string or number but "+typeof $)};class aJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=YZ,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=o0,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===YZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===o0||$.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 r0=-1,GZ=new DataView(new ArrayBuffer(0)),aX=new Uint8Array(GZ.buffer);try{GZ.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 rJ=RangeError("Insufficient data"),sX=new rX.CachedKeyDecoder;class WZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=GZ;bytes=aX;headByte=r0;stack=new aJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??nX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??T0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??T0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??T0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??T0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??T0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:sX,this.mapKeyConverter=$?.mapKeyConverter??oX}clone(){return new WZ({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=r0,this.stack.reset()}setBuffer($){let Z=(0,cJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===r0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,cJ.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 G of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(G);try{J=this.doDecodeSync(),Z=!0}catch(V){if(!(V instanceof RangeError))throw V}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:Q,pos:X,totalPos:Y}=this;throw RangeError(`Insufficient data in parsing ${(0,XZ.prettyByte)(Q)} at ${Y} (${X} 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 X of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(X),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(Y){if(!(Y instanceof RangeError))throw Y}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 P0.DecodeError(`Unrecognized type byte: ${(0,XZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===YZ)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===o0){if(Z==="__proto__")throw new P0.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=o0;continue $}}return Z}}readHeadByte(){if(this.headByte===r0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=r0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new P0.DecodeError(`Unrecognized array type byte: ${(0,XZ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new P0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new P0.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 P0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw rJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,cX.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===o0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new P0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw rJ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new P0.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,T0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,T0.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,$}}sJ.Decoder=WZ});var ZQ=c(($Q)=>{Object.defineProperty($Q,"__esModule",{value:!0});$Q.decode=eX;$Q.decodeMulti=tX;var tJ=U$();function eX($,Z){return new tJ.Decoder(Z).decode($)}function tX($,Z){return new tJ.Decoder(Z).decodeMulti($)}});var YQ=c((XQ)=>{Object.defineProperty(XQ,"__esModule",{value:!0});XQ.isAsyncIterable=JQ;XQ.asyncIterableFromStream=QQ;XQ.ensureAsyncIterable=JY;function JQ($){return $[Symbol.asyncIterator]!=null}async function*QQ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function JY($){if(JQ($))return $;else return QQ($)}});var WQ=c((GQ)=>{Object.defineProperty(GQ,"__esModule",{value:!0});GQ.decodeAsync=GY;GQ.decodeArrayStream=WY;GQ.decodeMultiStream=VY;var VZ=U$(),qZ=YQ();async function GY($,Z){let J=(0,qZ.ensureAsyncIterable)($);return new VZ.Decoder(Z).decodeAsync(J)}function WY($,Z){let J=(0,qZ.ensureAsyncIterable)($);return new VZ.Decoder(Z).decodeArrayStream(J)}function VY($,Z){let J=(0,qZ.ensureAsyncIterable)($);return new VZ.Decoder(Z).decodeStream(J)}});var qQ=c((v)=>{Object.defineProperty(v,"__esModule",{value:!0});v.decodeTimestampExtension=v.encodeTimestampExtension=v.decodeTimestampToTimeSpec=v.encodeTimeSpecToTimestamp=v.encodeDateToTimeSpec=v.EXT_TIMESTAMP=v.ExtData=v.ExtensionCodec=v.Encoder=v.DecodeError=v.Decoder=v.decodeMultiStream=v.decodeArrayStream=v.decodeAsync=v.decodeMulti=v.decode=v.encode=void 0;var PY=bJ();Object.defineProperty(v,"encode",{enumerable:!0,get:function(){return PY.encode}});var VQ=ZQ();Object.defineProperty(v,"decode",{enumerable:!0,get:function(){return VQ.decode}});Object.defineProperty(v,"decodeMulti",{enumerable:!0,get:function(){return VQ.decodeMulti}});var NZ=WQ();Object.defineProperty(v,"decodeAsync",{enumerable:!0,get:function(){return NZ.decodeAsync}});Object.defineProperty(v,"decodeArrayStream",{enumerable:!0,get:function(){return NZ.decodeArrayStream}});Object.defineProperty(v,"decodeMultiStream",{enumerable:!0,get:function(){return NZ.decodeMultiStream}});var MY=U$();Object.defineProperty(v,"Decoder",{enumerable:!0,get:function(){return MY.Decoder}});var OY=R$();Object.defineProperty(v,"DecodeError",{enumerable:!0,get:function(){return OY.DecodeError}});var KY=QZ();Object.defineProperty(v,"Encoder",{enumerable:!0,get:function(){return KY.Encoder}});var RY=I$();Object.defineProperty(v,"ExtensionCodec",{enumerable:!0,get:function(){return RY.ExtensionCodec}});var HY=e$();Object.defineProperty(v,"ExtData",{enumerable:!0,get:function(){return HY.ExtData}});var l0=t$();Object.defineProperty(v,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return l0.EXT_TIMESTAMP}});Object.defineProperty(v,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return l0.encodeDateToTimeSpec}});Object.defineProperty(v,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return l0.encodeTimeSpecToTimestamp}});Object.defineProperty(v,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return l0.decodeTimestampToTimeSpec}});Object.defineProperty(v,"encodeTimestampExtension",{enumerable:!0,get:function(){return l0.encodeTimestampExtension}});Object.defineProperty(v,"decodeTimestampExtension",{enumerable:!0,get:function(){return l0.decodeTimestampExtension}})});import*as G0 from"node:crypto";var O0=G0&&typeof G0==="object"&&"webcrypto"in G0?G0.webcrypto:G0&&typeof G0==="object"&&("randomBytes"in G0)?G0:void 0;function a0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function w$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function i($,...Z){if(!w$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function C$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function MZ($,Z){i($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function T$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var W0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var TQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!TQ)throw Error("Non little-endian hardware is not supported");function DQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function s0($){if(typeof $==="string")$=DQ($);else if(w$($))$=e0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function OZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function KZ($,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 RZ=($,Z)=>{function J(Q,...X){if(i(Q),$.nonceLength!==void 0){let z=X[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)i(z);else i(z,$.nonceLength)}let Y=$.tagLength;if(Y&&X[1]!==void 0)i(X[1]);let G=Z(Q,...X),V=(z,P)=>{if(P!==void 0){if(z!==2)throw Error("cipher output not supported");i(P)}},q=!1;return{encrypt(z,P){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,i(z),V(G.encrypt.length,P),G.encrypt(z,P)},decrypt(z,P){if(i(z),Y&&z.length<Y)throw Error("invalid ciphertext length: smaller than tagLength="+Y);return V(G.decrypt.length,P),G.decrypt(z,P)}}}return Object.assign(J,$),J};function D$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!AQ(Z))throw Error("invalid output, must be aligned");return Z}function AQ($){return $.byteOffset%4===0}function e0($){return Uint8Array.from($)}function J0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function t0($=32){if(O0&&typeof O0.getRandomValues==="function")return O0.getRandomValues(new Uint8Array($));if(O0&&typeof O0.randomBytes==="function")return O0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var FZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),jQ=FZ("expand 16-byte k"),LQ=FZ("expand 32-byte k"),EQ=W0(jQ),_Q=W0(LQ);function I($,Z){return $<<Z|$>>>32-Z}function A$($){return $.byteOffset%4===0}var $$=64,kQ=16,IZ=4294967295,HZ=new Uint32Array;function mQ($,Z,J,Q,X,Y,G,V){let q=X.length,N=new Uint8Array($$),z=W0(N),P=A$(X)&&A$(Y),O=P?W0(X):HZ,R=P?W0(Y):HZ;for(let H=0;H<q;G++){if($(Z,J,Q,z,G,V),G>=IZ)throw Error("arx: counter overflow");let F=Math.min($$,q-H);if(P&&F===$$){let U=H/4;if(H%4!==0)throw Error("arx: invalid block position");for(let C=0,D;C<kQ;C++)D=U+C,R[D]=O[D]^z[C];H+=$$;continue}for(let U=0,C;U<F;U++)C=H+U,Y[C]=X[C]^N[U];H+=F}}function UZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:X,counterRight:Y,rounds:G}=OZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return a0(X),a0(G),T$(Y),T$(J),(V,q,N,z,P=0)=>{i(V),i(q),i(N);let O=N.length;if(z===void 0)z=new Uint8Array(O);if(i(z),a0(P),P<0||P>=IZ)throw Error("arx: counter overflow");if(z.length<O)throw Error(`arx: output (${z.length}) is shorter than data (${O})`);let R=[],H=V.length,F,U;if(H===32)R.push(F=e0(V)),U=_Q;else if(H===16&&J)F=new Uint8Array(32),F.set(V),F.set(V,16),U=EQ,R.push(F);else throw Error(`arx: invalid 32-byte key, got length=${H}`);if(!A$(q))R.push(q=e0(q));let C=W0(F);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(U,C,W0(q.subarray(0,16)),C),q=q.subarray(16)}let D=16-X;if(D!==q.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let w=new Uint8Array(12);w.set(q,Y?0:12-q.length),q=w,R.push(q)}let j=W0(q);return mQ($,U,C,j,N,z,P,G),J0(...R),z}}var u=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class wZ{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,$=s0($),i($,32);let Z=u($,0),J=u($,2),Q=u($,4),X=u($,6),Y=u($,8),G=u($,10),V=u($,12),q=u($,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|X<<9)&8191,this.r[4]=(X>>>4|Y<<12)&255,this.r[5]=Y>>>1&8190,this.r[6]=(Y>>>14|G<<2)&8191,this.r[7]=(G>>>11|V<<5)&8065,this.r[8]=(V>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let N=0;N<8;N++)this.pad[N]=u($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:X,r:Y}=this,G=Y[0],V=Y[1],q=Y[2],N=Y[3],z=Y[4],P=Y[5],O=Y[6],R=Y[7],H=Y[8],F=Y[9],U=u($,Z+0),C=u($,Z+2),D=u($,Z+4),j=u($,Z+6),w=u($,Z+8),E=u($,Z+10),x=u($,Z+12),p=u($,Z+14),_=X[0]+(U&8191),m=X[1]+((U>>>13|C<<3)&8191),S=X[2]+((C>>>10|D<<6)&8191),K=X[3]+((D>>>7|j<<9)&8191),g=X[4]+((j>>>4|w<<12)&8191),B=X[5]+(w>>>1&8191),y=X[6]+((w>>>14|E<<2)&8191),l=X[7]+((E>>>11|x<<5)&8191),b=X[8]+((x>>>8|p<<8)&8191),h=X[9]+(p>>>5|Q),T=0,n=T+_*G+m*(5*F)+S*(5*H)+K*(5*R)+g*(5*O);T=n>>>13,n&=8191,n+=B*(5*P)+y*(5*z)+l*(5*N)+b*(5*q)+h*(5*V),T+=n>>>13,n&=8191;let o=T+_*V+m*G+S*(5*F)+K*(5*H)+g*(5*R);T=o>>>13,o&=8191,o+=B*(5*O)+y*(5*P)+l*(5*z)+b*(5*N)+h*(5*q),T+=o>>>13,o&=8191;let e=T+_*q+m*V+S*G+K*(5*F)+g*(5*H);T=e>>>13,e&=8191,e+=B*(5*R)+y*(5*O)+l*(5*P)+b*(5*z)+h*(5*N),T+=e>>>13,e&=8191;let k=T+_*N+m*q+S*V+K*G+g*(5*F);T=k>>>13,k&=8191,k+=B*(5*H)+y*(5*R)+l*(5*O)+b*(5*P)+h*(5*z),T+=k>>>13,k&=8191;let Y0=T+_*z+m*N+S*q+K*V+g*G;T=Y0>>>13,Y0&=8191,Y0+=B*(5*F)+y*(5*H)+l*(5*R)+b*(5*O)+h*(5*P),T+=Y0>>>13,Y0&=8191;let D0=T+_*P+m*z+S*N+K*q+g*V;T=D0>>>13,D0&=8191,D0+=B*G+y*(5*F)+l*(5*H)+b*(5*R)+h*(5*O),T+=D0>>>13,D0&=8191;let A0=T+_*O+m*P+S*z+K*N+g*q;T=A0>>>13,A0&=8191,A0+=B*V+y*G+l*(5*F)+b*(5*H)+h*(5*R),T+=A0>>>13,A0&=8191;let j0=T+_*R+m*O+S*P+K*z+g*N;T=j0>>>13,j0&=8191,j0+=B*q+y*V+l*G+b*(5*F)+h*(5*H),T+=j0>>>13,j0&=8191;let L0=T+_*H+m*R+S*O+K*P+g*z;T=L0>>>13,L0&=8191,L0+=B*N+y*q+l*V+b*G+h*(5*F),T+=L0>>>13,L0&=8191;let E0=T+_*F+m*H+S*R+K*O+g*P;T=E0>>>13,E0&=8191,E0+=B*z+y*N+l*q+b*V+h*G,T+=E0>>>13,E0&=8191,T=(T<<2)+T|0,T=T+n|0,n=T&8191,T=T>>>13,o+=T,X[0]=n,X[1]=o,X[2]=e,X[3]=k,X[4]=Y0,X[5]=D0,X[6]=A0,X[7]=j0,X[8]=L0,X[9]=E0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let G=2;G<10;G++)$[G]+=Q,Q=$[G]>>>13,$[G]&=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 G=1;G<10;G++)J[G]=$[G]+Q,Q=J[G]>>>13,J[G]&=8191;J[9]-=8192;let X=(Q^1)-1;for(let G=0;G<10;G++)J[G]&=X;X=~X;for(let G=0;G<10;G++)$[G]=$[G]&X|J[G];$[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 Y=$[0]+Z[0];$[0]=Y&65535;for(let G=1;G<8;G++)Y=($[G]+Z[G]|0)+(Y>>>16)|0,$[G]=Y&65535;J0(J)}update($){C$(this);let{buffer:Z,blockLen:J}=this;$=s0($);let Q=$.length;for(let X=0;X<Q;){let Y=Math.min(J-this.pos,Q-X);if(Y===J){for(;J<=Q-X;X+=J)this.process($,X);continue}if(Z.set($.subarray(X,X+Y),this.pos),this.pos+=Y,X+=Y,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){J0(this.h,this.r,this.buffer,this.pad)}digestInto($){C$(this),MZ($,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 X=0;for(let Y=0;Y<8;Y++)$[X++]=J[Y]>>>0,$[X++]=J[Y]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function BQ($){let Z=(Q,X)=>$(X).update(s0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var j$=BQ(($)=>new wZ($));function xQ($,Z,J,Q,X,Y=20){let G=$[0],V=Z[0],q=Z[1],N=Z[2],z=Z[3],P=$[1],O=J[0],R=J[1],H=X,F=0,U=$[2],C=Z[4],D=Z[5],j=Z[6],w=Z[7],E=$[3],x=G,p=V,_=q,m=N,S=z,K=P,g=O,B=R,y=H,l=F,b=U,h=C,T=D,n=j,o=w,e=E;for(let Y0=0;Y0<Y;Y0+=2)S^=I(x+T|0,7),y^=I(S+x|0,9),T^=I(y+S|0,13),x^=I(T+y|0,18),l^=I(K+p|0,7),n^=I(l+K|0,9),p^=I(n+l|0,13),K^=I(p+n|0,18),o^=I(b+g|0,7),_^=I(o+b|0,9),g^=I(_+o|0,13),b^=I(g+_|0,18),m^=I(e+h|0,7),B^=I(m+e|0,9),h^=I(B+m|0,13),e^=I(h+B|0,18),p^=I(x+m|0,7),_^=I(p+x|0,9),m^=I(_+p|0,13),x^=I(m+_|0,18),g^=I(K+S|0,7),B^=I(g+K|0,9),S^=I(B+g|0,13),K^=I(S+B|0,18),h^=I(b+l|0,7),y^=I(h+b|0,9),l^=I(y+h|0,13),b^=I(l+y|0,18),T^=I(e+o|0,7),n^=I(T+e|0,9),o^=I(n+T|0,13),e^=I(o+n|0,18);let k=0;Q[k++]=G+x|0,Q[k++]=V+p|0,Q[k++]=q+_|0,Q[k++]=N+m|0,Q[k++]=z+S|0,Q[k++]=P+K|0,Q[k++]=O+g|0,Q[k++]=R+B|0,Q[k++]=H+y|0,Q[k++]=F+l|0,Q[k++]=U+b|0,Q[k++]=C+h|0,Q[k++]=D+T|0,Q[k++]=j+n|0,Q[k++]=w+o|0,Q[k++]=E+e|0}function SQ($,Z,J,Q){let X=$[0],Y=Z[0],G=Z[1],V=Z[2],q=Z[3],N=$[1],z=J[0],P=J[1],O=J[2],R=J[3],H=$[2],F=Z[4],U=Z[5],C=Z[6],D=Z[7],j=$[3];for(let E=0;E<20;E+=2)q^=I(X+U|0,7),O^=I(q+X|0,9),U^=I(O+q|0,13),X^=I(U+O|0,18),R^=I(N+Y|0,7),C^=I(R+N|0,9),Y^=I(C+R|0,13),N^=I(Y+C|0,18),D^=I(H+z|0,7),G^=I(D+H|0,9),z^=I(G+D|0,13),H^=I(z+G|0,18),V^=I(j+F|0,7),P^=I(V+j|0,9),F^=I(P+V|0,13),j^=I(F+P|0,18),Y^=I(X+V|0,7),G^=I(Y+X|0,9),V^=I(G+Y|0,13),X^=I(V+G|0,18),z^=I(N+q|0,7),P^=I(z+N|0,9),q^=I(P+z|0,13),N^=I(q+P|0,18),F^=I(H+R|0,7),O^=I(F+H|0,9),R^=I(O+F|0,13),H^=I(R+O|0,18),U^=I(j+D|0,7),C^=I(U+j|0,9),D^=I(C+U|0,13),j^=I(D+C|0,18);let w=0;Q[w++]=X,Q[w++]=N,Q[w++]=H,Q[w++]=j,Q[w++]=z,Q[w++]=P,Q[w++]=O,Q[w++]=R}var L$=UZ(xQ,{counterRight:!0,extendNonceFn:SQ}),E$=RZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=D$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32);Q.set(J,32),J0(X),L$($,Z,Q,Q);let G=j$(Y,X);return Q.set(G,16),J0(Q.subarray(0,16),G),Q.subarray(16)},decrypt(J,Q){i(J),Q=D$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32,48),G=Q.subarray(48);Q.set(J,32),J0(X);let V=L$($,Z,X,X),q=j$(G,V);if(!KZ(Y,q))throw Error("invalid tag");return L$($,Z,Q.subarray(16),Q.subarray(16)),J0(X,Y,q),G}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function gQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function h0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function K0($,...Z){if(!gQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function i0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function Z$($,Z){K0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function CZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function _0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function k0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function p0($,Z){return $<<32-Z|$>>>Z}var TZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function DZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var AZ=TZ?($)=>$:($)=>DZ($);function fQ($){for(let Z=0;Z<$.length;Z++)$[Z]=DZ($[Z]);return $}var a=TZ?($)=>$:fQ;function vQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function m0($){if(typeof $==="string")$=vQ($);return K0($),$}class _${}function jZ($){let Z=(Q,X)=>$(X).update(m0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var LZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J$=BigInt(4294967295),EZ=BigInt(32);function k$($,Z=!1){if(Z)return{h:Number($&J$),l:Number($>>EZ&J$)};return{h:Number($>>EZ&J$)|0,l:Number($&J$)|0}}function V0($,Z,J,Q,X){return $=$+Z+X|0,Q=p0(Q^$,16),J=J+Q|0,Z=p0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function q0($,Z,J,Q,X){return $=$+Z+X|0,Q=p0(Q^$,8),J=J+Q|0,Z=p0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class m$ extends _${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,h0($),h0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=_0(this.buffer)}update($){i0(this),$=m0($),K0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,X=$.length,Y=$.byteOffset,G=$.buffer;for(let V=0;V<X;){if(this.pos===Z)a(Q),this.compress(Q,0,!1),a(Q),this.pos=0;let q=Math.min(Z-this.pos,X-V),N=Y+V;if(q===Z&&!(N%4)&&V+q<X){let z=new Uint32Array(G,N,Math.floor((X-V)/4));a(z);for(let P=0;V+Z<X;P+=Q.length,V+=Z)this.length+=Z,this.compress(z,P,!1);a(z);continue}J.set($.subarray(V,V+q),this.pos),this.pos+=q,this.length+=q,V+=q}return this}digestInto($){i0(this),Z$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,k0(this.buffer.subarray(Z)),a(J),this.compress(J,0,!0),a(J);let Q=_0($);this.get().forEach((X,Y)=>Q[Y]=AZ(X))}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:X,outputLen:Y,pos:G}=this;return $||($=new this.constructor({dkLen:Y})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=X,$.finished=Q,$.length=J,$.pos=G,$.outputLen=Y,$}clone(){return this._cloneInto()}}function B$($,Z,J,Q,X,Y,G,V,q,N,z,P,O,R,H,F,U,C,D,j){let w=0;for(let E=0;E<Q;E++)({a:X,b:q,c:O,d:U}=V0(X,q,O,U,J[Z+$[w++]])),{a:X,b:q,c:O,d:U}=q0(X,q,O,U,J[Z+$[w++]]),{a:Y,b:N,c:R,d:C}=V0(Y,N,R,C,J[Z+$[w++]]),{a:Y,b:N,c:R,d:C}=q0(Y,N,R,C,J[Z+$[w++]]),{a:G,b:z,c:H,d:D}=V0(G,z,H,D,J[Z+$[w++]]),{a:G,b:z,c:H,d:D}=q0(G,z,H,D,J[Z+$[w++]]),{a:V,b:P,c:F,d:j}=V0(V,P,F,j,J[Z+$[w++]]),{a:V,b:P,c:F,d:j}=q0(V,P,F,j,J[Z+$[w++]]),{a:X,b:N,c:H,d:j}=V0(X,N,H,j,J[Z+$[w++]]),{a:X,b:N,c:H,d:j}=q0(X,N,H,j,J[Z+$[w++]]),{a:Y,b:z,c:F,d:U}=V0(Y,z,F,U,J[Z+$[w++]]),{a:Y,b:z,c:F,d:U}=q0(Y,z,F,U,J[Z+$[w++]]),{a:G,b:P,c:O,d:C}=V0(G,P,O,C,J[Z+$[w++]]),{a:G,b:P,c:O,d:C}=q0(G,P,O,C,J[Z+$[w++]]),{a:V,b:q,c:R,d:D}=V0(V,q,R,D,J[Z+$[w++]]),{a:V,b:q,c:R,d:D}=q0(V,q,R,D,J[Z+$[w++]]);return{v0:X,v1:Y,v2:G,v3:V,v4:q,v5:N,v6:z,v7:P,v8:O,v9:R,v10:H,v11:F,v12:U,v13:C,v14:D,v15:j}}var Q0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},N0=LZ.slice(),_Z=(()=>{let $=Array.from({length:16},(Q,X)=>X),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((X)=>Q[X]),J=[];for(let Q=0,X=$;Q<7;Q++,X=Z(X))J.push(...X);return Uint8Array.from(J)})();class x$ extends m${constructor($={},Z=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:J,context:Q}=$,X=Q!==void 0;if(J!==void 0){if(X)throw Error('Only "key" or "context" can be specified at same time');let Y=m0(J).slice();K0(Y,32),this.IV=_0(Y),a(this.IV),this.flags=Z|Q0.KEYED_HASH}else if(X){let Y=m0(Q),G=new x$({dkLen:32},Q0.DERIVE_KEY_CONTEXT).update(Y).digest();this.IV=_0(G),a(this.IV),this.flags=Z|Q0.DERIVE_KEY_MATERIAL}else this.IV=N0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=CZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:X,pos:Y}=this,{h:G,l:V}=k$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:P,v4:O,v5:R,v6:H,v7:F,v8:U,v9:C,v10:D,v11:j,v12:w,v13:E,v14:x,v15:p}=B$(_Z,Q,J,7,X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],N0[0],N0[1],N0[2],N0[3],G,V,Y,Z);X[0]=q^U,X[1]=N^C,X[2]=z^D,X[3]=P^j,X[4]=O^w,X[5]=R^E,X[6]=H^x,X[7]=F^p}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=Q0.CHUNK_START;if(this.chunkPos===15||J)Q|=Q0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let X=this.state;this.state=this.IV.slice();for(let Y,G=this.chunksDone+1;J||!(G&1);G>>=1){if(!(Y=this.stack.pop()))break;this.buffer32.set(Y,0),this.buffer32.set(X,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|Q0.PARENT,this.buffer32,0),X=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(X)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:X,posOut:Y,chunkOut:G,stack:V,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=V.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=X,$.chunksDone=q,$.posOut=Y,$.chunkOut=G,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,k0(this.state,this.buffer32,this.IV,this.bufferOut32),k0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:X}=this,{h:Y,l:G}=k$(BigInt(this.chunkOut++));a(Q);let{v0:V,v1:q,v2:N,v3:z,v4:P,v5:O,v6:R,v7:H,v8:F,v9:U,v10:C,v11:D,v12:j,v13:w,v14:E,v15:x}=B$(_Z,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],N0[0],N0[1],N0[2],N0[3],G,Y,Z,J);X[0]=V^F,X[1]=q^U,X[2]=N^C,X[3]=z^D,X[4]=P^j,X[5]=O^w,X[6]=R^E,X[7]=H^x,X[8]=$[0]^F,X[9]=$[1]^U,X[10]=$[2]^C,X[11]=$[3]^D,X[12]=$[4]^j,X[13]=$[5]^w,X[14]=$[6]^E,X[15]=$[7]^x,a(Q),a(X),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,k0(this.buffer.subarray(this.pos));let $=this.flags|Q0.ROOT;if(this.stack.length)$|=Q0.PARENT,a(this.buffer32),this.compress(this.buffer32,0,!0),a(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Q0.CHUNK_START:0)|Q0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){i0(this,!1),K0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,X=$.length;Q<X;){if(this.posOut>=Z)this.b2CompressOut();let Y=Math.min(Z-this.posOut,X-Q);$.set(J.subarray(this.posOut,this.posOut+Y),Q),this.posOut+=Y,Q+=Y}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return h0($),this.xofInto(new Uint8Array($))}digestInto($){if(Z$($,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 kZ=jZ(($)=>new x$($));function t($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function Q$($){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 xZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var mZ;if(typeof Uint8Array.prototype.toBase64==="function")mZ=($)=>$.toBase64();else mZ=($)=>btoa(String.fromCharCode(...$));var BZ;if(typeof Uint8Array.fromBase64==="function")BZ=($)=>Uint8Array.fromBase64($);else BZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function u0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var S$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function SZ($){let Z=new Uint8Array(S$.length+32);return Z.set(S$),Z.set($.subarray(0,32),S$.length),Z}function gZ($){return typeof $==="string"?new TextEncoder().encode($):$}function B0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class g${verifyKeys=new Map;async genRandomBytes($){return t0($)}async gen256BitSecureRandomSeed(){return t0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=t0(24),X=E$(Z,J).encrypt($);return new Uint8Array([...J,...X])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return E$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=SZ(Z),Q=B0(J),X;try{let N=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!0,["sign"]);X=await globalThis.crypto.subtle.exportKey("jwk",N)}finally{J.fill(0),new Uint8Array(Q).fill(0)}if(typeof X.x!=="string")throw Error("Ed25519 JWK missing x");let Y=X.x;X.d=void 0;let G=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:Y},{name:"Ed25519"},!0,["verify"]),V=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",G));this.verifyKeys.set(t(V),G);let q=new Uint8Array(64);return q.set(Z,0),q.set(V,32),{keyType:"ed25519",privateKey:q,publicKey:V}}async importSignKey($){let Z=$.subarray(0,32),J=SZ(Z),Q=B0(J);try{return await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!1,["sign"])}finally{J.fill(0),new Uint8Array(Q).fill(0)}}async importVerifyKey($){let Z=t($),J=this.verifyKeys.get(Z);if(J)return J;let Q=await globalThis.crypto.subtle.importKey("raw",B0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=gZ($),Q=await this.importSignKey(Z),X=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,B0(J));return new Uint8Array(X)}async checkSigEd25519($,Z,J){let Q=gZ(Z);try{let X=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},X,B0($),B0(Q))}catch{return!1}}async blake3($){return kZ($)}}var yQ=new g$,R0=yQ;var x0=64;var fZ=32,S0=8;var vZ=32;var yZ=30000,lZ=512,A;((K)=>{K[K.Success=0]="Success";K[K.InvalidSignature=3]="InvalidSignature";K[K.ClockOutOfSync=4]="ClockOutOfSync";K[K.UserNotRegistered=5]="UserNotRegistered";K[K.ServerMisconfigured=6]="ServerMisconfigured";K[K.MissingBody=7]="MissingBody";K[K.ExtraBodyContent=8]="ExtraBodyContent";K[K.MissingParam=9]="MissingParam";K[K.InvalidParam=10]="InvalidParam";K[K.InvalidRequest=11]="InvalidRequest";K[K.InternalError=12]="InternalError";K[K.NotFound=13]="NotFound";K[K.InvalidMessage=14]="InvalidMessage";K[K.NoChange=15]="NoChange";K[K.DatabaseClosed=16]="DatabaseClosed";K[K.StorageError=17]="StorageError";K[K.DatabaseError=18]="DatabaseError";K[K.HashMismatch=19]="HashMismatch";K[K.DecryptionError=20]="DecryptionError";K[K.NotImplemented=21]="NotImplemented";K[K.MissingSeed=22]="MissingSeed";K[K.OutOfBounds=23]="OutOfBounds";K[K.HostError=24]="HostError";K[K.CommunicationError=25]="CommunicationError";K[K.VarLimitExceeded=26]="VarLimitExceeded";K[K.InvalidResponse=27]="InvalidResponse";K[K.ConnectionClosed=28]="ConnectionClosed"})(A||={});var bZ="t";function M($){return[$,0]}function W($){return[void 0,$]}function lQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return W(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 M(new Uint8Array([0]));if(Z.length>8)return W(26);return M(new Uint8Array(Z))}function bQ($,Z=0){let J=0n,Q=0,X=Z;while(!0){if(X>=$.length)return W(14);let Y=$[X++];if(Y===void 0)return W(14);if(J|=BigInt(Y&127)<<BigInt(Q),(Y&128)===0){if(X-Z>8)return W(26);return M({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:X-Z})}if(Q+=7,Q>=56)return W(26)}}class f{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new f(J)}readBigInt(){if(this.pos+8>this.data.length)return W(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,M($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return W(Z);return M(new Date($))}readVarInt(){let[$,Z]=bQ(this.data,this.pos);if(Z!==0)return W(Z);this.pos+=$.bytesRead;let J=$.value;return M(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return W(Z);let[J,Q]=this.readBytes($);if(Q!==0)return W(Q);let X=new TextDecoder().decode(J);return M(X)}readBytes($){if($<0)return W(10);if(this.pos+$>this.data.length)return W(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,M(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return W(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return W(Q);Z.push(J)}return M(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return W(Q);Z.push(J)}return M(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]=lQ($);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($.slice())}writeBytes($){this.parts.push($.slice())}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,X)=>Q+X.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 d0={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 W(J);let[Q,X]=$.readDate();if(X!==0)return W(X);return M({id:Z,ts:Q})}};function hZ($){let Z=new L,J=Z.writeStruct(d0,$);if(J!==0)return W(J);let Q=Z.result();return M(Q)}var f$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let X=$.writeVarInt(Z.ctr);if(X!==0)return X;let Y=$.writeVarInt(Z.len);if(Y!==0)return Y;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return W(J);let Q=new f(Z),[,X]=d0.decode(Q);if(X!==0)return W(X);let[Y,G]=$.readVarInt();if(G!==0)return W(G);let[V,q]=$.readVarInt();if(q!==0)return W(q);let[N,z]=$.readVarInt();if(z!==0)return W(z);let P;if(N>0){let[O,R]=$.readBytes(vZ);if(R!==0)return W(R);P=O}return M({eid:Z,off:Y,ctr:V,len:N,hsh:P})}};function iZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function pZ($,Z,J,Q){let X;if($.bod&&$.len>0)X=await J.blake3($.bod);let Y=new L,G=f$.encode(Y,{...$,hsh:X});if(G!==0)return W(G);let V=Y.result(),q=await Z.kdmFor(V),N=Q.deriveCipher(q,"encrypt"),z=await N.encrypt(V),P=$.bod?await N.encrypt($.bod):new Uint8Array(0),O=await Z.sign(z);return M({sig:O,kdm:q,headCph:z,bodyCph:P})}async function uZ($,Z,J,Q,X){let Y=new f($),[G,V]=f$.decode(Y);if(V!==0)return W(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return W(20)}let N=G.hsh&&q===void 0,z=G.hsh===void 0&&q!==void 0;if(N||z)return W(19);if(G.hsh&&q){let O=await Q.blake3(q);if(!xZ(O,G.hsh))return W(19)}let P=X??await Q.blake3($);return M({msgHead:G,bod:q,headHash:P})}async function v$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return W(Q);let X=J.result(),Y=await $.sign(X);return M({pubKey:$.publicKey,sig:Y,timestamp:Z})}async function $0($,Z,J){let Q=J.now().getTime(),X=$.timestamp.getTime();if(Math.abs(Q-X)>yZ)return 4;let G=new L;G.writeDate($.timestamp);let V=G.result();if(!await Z.checkSigEd25519($.sig,V,$.pubKey))return 3;return 0}class g0{now(){return new Date}}function dZ($,Z,J,Q){let X=Z.getTime()-$.getTime(),Y=J.getTime()-Q.getTime();return(X+Y)/2}var n0={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 W(J);let Q;if(Z>0){let[X,Y]=$.readVarInt();if(Y!==0)return W(Y);Q=X}return M({quota:Z,usage:Q})}};var f0={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 X=$.writeVarInt(Z.subscription.term);if(X!==0)return X;let Y=$.writeVarInt(Z.subscription.elapsed);if(Y!==0)return Y;let G=$.writeStruct(n0,Z.subscription.stat);if(G!==0)return G;let V=$.writeStruct(n0,Z.subscription.dyn);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return W(J);let Q=Z[0],[X,Y]=$.readDate();if(Y!==0)return W(Y);let[G,V]=$.readDate();if(V!==0)return W(V);let[q,N]=$.readVarInt();if(N!==0)return W(N);let[z,P]=$.readVarInt();if(P!==0)return W(P);let[O,R]=$.readStruct(n0);if(R!==0)return W(R);let[H,F]=$.readStruct(n0);if(F!==0)return W(F);return M({status:Q,timeRcvd:X,timeSent:G,subscription:{term:q,elapsed:z,stat:O,dyn:H}})}};var y$={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 W(J);let[Q,X]=$.readVarInt();if(X!==0)return W(X);return M({headCph:Z,seq:Q})}};var r={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(fZ);if(J!==0)return W(J);let[Q,X]=$.readBytes(x0);if(X!==0)return W(X);let[Y,G]=$.readDate();if(G!==0)return W(G);return M({pubKey:Z,sig:Q,timestamp:Y})}};var nZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(r,J);if(Y!==0)return Y;for(let G of Q)X.writeVarInt(G);return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[G,V]=Z.readStruct(r);if(V!==0)return V;let q=await $0(G,X,Q);if(q!==0)return q;let{pubKey:N}=G,[z,P]=await Y.hasUser(N);if(P!==0)return P;if(!z)return 5;let[O,R]=Z.readVarInt();if(R!==0)return R;if(!Z.done())return 8;let[H,F]=await Y.listHeads(N,O);if(F!==0)return F;return J.writeStructs(y$,H)},decodeResp($){return $.readStructs(y$)}};var l$={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 W(J);let[Q,X]=$.readVarBytes();if(X!==0)return W(X);return M({seq:Z,bodyCph:Q})}};var cZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(r,J);if(Y!==0)return Y;for(let G of Q){let V=X.writeVarInt(G);if(V!==0)return V}return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[G,V]=Z.readStruct(r);if(V!==0)return V;let q=await $0(G,X,Q);if(q!==0)return q;let{pubKey:N}=G,[z,P]=await Y.hasUser(N);if(P!==0)return P;if(!z)return 5;let O=[];while(!Z.done()){let[F,U]=Z.readVarInt();if(U!==0)return U;O.push(F)}console.info(`PULL: ${O.length} bags`);let[R,H]=await Y.getBodies(N,O);if(H!==0)return H;if(!R)return 17;for(let{seq:F,bodyCph:U}of R){let C={seq:F,bodyCph:U},D=J.writeStruct(l$,C);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(l$)}};var b$={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(x0);if(J!==0)return W(J);let[Q,X]=$.readBytes(S0);if(X!==0)return W(X);let[Y,G]=$.readVarBytes();if(G!==0)return W(G);let[V,q]=$.readVarBytes();if(q!==0)return W(q);return M({sig:Z,kdm:Q,headCph:Y,bodyCph:V})}};var h$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let X=Z.bodyCph?Z.bodyCph.length:0,Y=$.writeVarInt(X);if(Y!==0)return Y;if(X>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return W(J);let[Q,X]=$.readVarBytes();if(X!==0)return W(X);let[Y,G]=$.readVarInt();if(G!==0)return W(G);let V;if(Y>0){let[q,N]=$.readBytes(Y);if(N!==0)return W(N);V=q}return M({seq:Z,headCph:Q,bodyCph:V})}};var v0={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(x0);if(J!==0)return W(J);let[Q,X]=$.readBytes(S0);if(X!==0)return W(X);let[Y,G]=$.readVarBytes();if(G!==0)return W(G);return M({sig:Z,kdm:Q,headCph:Y})}};var X$={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 W(J);let[Q,X]=$.readBytes(1);if(X!==0)return W(X);let Y=Q[0];if(Y!==0)return M({idx:Z,status:Y});let[G,V]=$.readVarInt();if(V!==0)return W(V);return M({idx:Z,status:Y,seq:G})}};var rZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(r,J);if(Y!==0)return Y;let G=X.writeStructs(b$,Q);if(G!==0)return G;return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y,notifier:G}=$,[V,q]=Z.readStruct(r);if(q!==0)return q;let N=await $0(V,X,Q);if(N!==0)return N;let{pubKey:z}=V,[P,O]=await Y.hasUser(z);if(O!==0)return O;if(!P)return 5;let[R,H]=Z.readStructs(b$);if(H!==0)return H;console.info(`PUSH: ${R.length} bags`);let F=[],U=[];for(let w=0;w<R.length;w++){let E=R[w];if(!await iZ(E,z,X)){let p={idx:w,status:3},_=J.writeStruct(X$,p);if(_!==0)return _;continue}F.push(w),U.push(E)}let[C,D]=await Y.setBags(z,U);if(D!==0)return D;if(!C||C.length!==U.length)return 17;let j=[];for(let w=0;w<U.length;w++){let E=U[w],x=F[w],p=C[w],_=new L,m=_.writeStruct(v0,E);if(m!==0)return m;let S=_.result(),K={seq:p,headCph:S};if(R.length===1&&E.bodyCph.length<=lZ)K.bodyCph=E.bodyCph;j.push(K);let g={idx:x,status:0,seq:p},B=J.writeStruct(X$,g);if(B!==0)return B}if(j.length>0){let w=new L,E=w.writeStructs(h$,j);if(E!==0)return E;let x=w.result();await Promise.resolve(G.push(z,x))}return 0},decodeResp($){return $.readStructs(X$)}};var oZ={async encodeReq($,Z,J,Q,X){return X.writeStruct(r,J)},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[G,V]=Z.readStruct(r);if(V!==0)return V;let q=await $0(G,X,Q);if(q!==0)return q;let{pubKey:N}=G;if(!Z.done())return 8;let[z,P]=await Y.addUser(N);if(P!==0)return P;return 0},decodeResp($){return M(void 0)}};class i${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:X}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let Y=new L;Y.writeStruct(r,$);let G=Y.result(),V=t(G);return X.searchParams.set("t",V),this.websocket=new WebSocket(X),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=(q)=>{let N=new Uint8Array(q.data);Z(N)},this.websocket.onerror=(q)=>{console.log(`ERROR: ${JSON.stringify(q)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var d={user:{path:"/user",endpoint:oZ,name:0},push:{path:"/push",endpoint:rZ,name:2},peek:{path:"/peek",endpoint:nZ,name:1},pull:{path:"/pull",endpoint:cZ,name:3}},hQ={0:d.user,2:d.push,1:d.peek,3:d.pull},aZ={[d.user.path]:d.user,[d.push.path]:d.push,[d.peek.path]:d.peek,[d.pull.path]:d.pull};class sZ{url;listener;constructor($){this.url=$;this.listener=new i$($)}async call($,Z){let{path:J}=hQ[$],Q=new URL(J,this.url);try{return await pQ(Q,Z)}catch{return W(25)}}}var p$=($)=>{return new sZ($.handle)};function y0($){let Z=new L;if(Z.writeStruct(f0,$)!==0)return new Response(null,{status:500});return u$(Z)}function u$($){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 d$($){return new Response($.body,{headers:{...$.headers,...iQ},status:$.status,statusText:$.statusText})}async function pQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return W(24);let Q=await f.fromResponse(J);return M(Q)}class Y${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,X,Y){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=X;this.updateHostMeta=Y}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:X,name:Y}=$,G=await this.identity(),V=J.now(),[q,N]=await v$(G,V);if(N!==0)return W(N);let z=new L,P=await X.encodeReq(this,G,q,Z,z);if(P!==0)return W(P);let O=J.now(),[R,H]=await Q.call(Y,z),F=J.now();if(H!==0)return W(H);let[U,C]=R.readStruct(f0);if(C!==0)return W(C);if(U.status!==0)return W(U.status);let j={clockOffset:dZ(O,U.timeRcvd,U.timeSent,F),subscription:U.subscription},w=await this.updateHostMeta(j);if(w!==0)return W(w);return X.decodeResp(R)}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 pZ($,Q,Z,J)};register=()=>this.call(d.user,[]);peek=($)=>this.call(d.peek,[$]);push=($)=>this.call(d.push,$);pull=($)=>this.call(d.pull,$);listen=async($,Z,J)=>{let{clock:Q,transport:X}=this,{listener:Y}=X,G=await this.identity(),V=Q.now(),[q,N]=await v$(G,V);if(N!==0)return N;return await Y.connect(q,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var jV=Symbol("MasterSeed"),LV=Symbol("SealedMasterKey"),X0=32,eZ=24+X0+16;function s($){if($.byteLength!==X0)return W(10);return M($)}function G$($){if($.byteLength!==eZ)return W(10);return M($)}var H0={encode($,Z){let J=$.writeVarString(Z.handle);if(J!==0)return J;let Q=$.writeVarString(Z.label);if(Q!==0)return Q;return $.writeVarInt(Z.idx??0)},decode($){let[Z,J]=$.readVarString();if(J!==0)return W(J);let[Q,X]=$.readVarString();if(X!==0)return W(X);let[Y,G]=$.readVarInt();if(G!==0)return W(G);return M({handle:Z,label:Q,idx:Y})}};var W$=1,n$={encode($,Z){if(Z.v!==W$)return 10;let[,J]=s(Z.masterSeed);if(J!==0)return J;let Q=$.writeVarInt(Z.v);if(Q!==0)return Q;$.writeBytes(Z.masterSeed);let X=$.writeVarInt(Z.hosts.length);if(X!==0)return X;for(let Y of Z.hosts){let G=$.writeStruct(H0,Y);if(G!==0)return G}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return W(J);if(Z!==W$)return W(14);let[Q,X]=$.readBytes(X0);if(X!==0)return W(X);if(Q===void 0)return W(14);let[Y,G]=s(Q);if(G!==0)return W(G);if(Y===void 0)return W(14);let[V,q]=$.readVarInt();if(q!==0)return W(q);if(V===void 0||V<0)return W(10);let N=[];for(let z=0;z<V;z++){let[P,O]=$.readStruct(H0);if(O!==0)return W(O);if(P===void 0)return W(14);N.push(P)}return M({v:W$,masterSeed:Y,hosts:N})}};function tZ($,Z){let[J,Q]=s($);if(Q!==0)return W(Q);if(J===void 0)return W(10);let[X,Y]=s(J.slice());if(Y!==0)return W(Y);if(X===void 0)return W(10);return M({v:W$,masterSeed:X,hosts:Z.map((G)=>({handle:G.handle,label:G.label,idx:G.idx??0}))})}var c$={encode($,Z){let[,J]=s(Z.masterSeed);if(J!==0)return J;$.writeBytes(Z.masterSeed);let Q=$.writeVarInt(Z.hosts.length);if(Q!==0)return Q;for(let X of Z.hosts){let Y=$.writeStruct(H0,X);if(Y!==0)return Y}return 0},decode($){let[Z,J]=$.readBytes(X0);if(J!==0)return W(J);if(Z===void 0)return W(14);let[Q,X]=s(Z);if(X!==0)return W(X);if(Q===void 0)return W(14);let[Y,G]=$.readVarInt();if(G!==0)return W(G);if(Y===void 0||Y<0)return W(10);let V=[];for(let q=0;q<Y;q++){let[N,z]=$.readStruct(H0);if(z!==0)return W(z);if(N===void 0)return W(14);V.push(N)}return M({masterSeed:Q,hosts:V})}};function z0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var F0=32,uQ=-7,dQ=-8,nQ=-257,V$=[{type:"public-key",alg:uQ},{type:"public-key",alg:dQ},{type:"public-key",alg:nQ}];function cQ($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function I0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z.buffer}function $J($){if($ instanceof ArrayBuffer)return new Uint8Array($).slice();return new Uint8Array($.buffer,$.byteOffset,$.byteLength).slice()}function U0($){if($?.rpId!==void 0)return M($.rpId);if(typeof location>"u")return W(9);return M(cQ(location.hostname))}function w0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function C0($){if($===null||$.type!=="public-key"||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return W(27);return M($)}async function ZJ($){let Z=w0();if(Z!==0)return W(Z);let[J,Q]=U0($);if(Q!==0)return W(Q);if(J===void 0)return W(9);let X=$?.userName??"diplomatic-seed",Y={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)Y.authenticatorAttachment=$.authenticatorAttachment;let G={largeBlob:{support:"required"}},V;try{V=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:X,displayName:X},pubKeyCredParams:V$,authenticatorSelection:Y,extensions:G}})}catch{return W(24)}let[q,N]=C0(V);if(N!==0)return W(N);if(q===void 0)return W(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return W(24);return M(new Uint8Array(q.rawId))}async function r$($,Z,J){let Q=w0();if(Q!==0)return Q;let[X,Y]=U0(J);if(Y!==0)return Y;if(X===void 0)return 9;let G={largeBlob:{write:I0(Z)}},V;try{V=await navigator.credentials.get({publicKey:{challenge:z0(F0),rpId:X,allowCredentials:[{type:"public-key",id:I0($)}],userVerification:"required",extensions:G}})}catch{return 24}let[q,N]=C0(V);if(N!==0)return N;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 24;return 0}async function JJ($,Z){let J=w0();if(J!==0)return W(J);let[Q,X]=U0(Z);if(X!==0)return W(X);if(Q===void 0)return W(9);let Y={largeBlob:{read:!0}},G;try{let O={challenge:z0(F0),rpId:Q,userVerification:"required",extensions:Y};if($!==void 0)O.allowCredentials=[{type:"public-key",id:I0($)}];G=await navigator.credentials.get({publicKey:O})}catch{return W(24)}let[V,q]=C0(G);if(q!==0)return W(q);if(V===void 0)return W(27);let z=V.getClientExtensionResults().largeBlob;if(z===void 0||z.blob===void 0)return W(7);let P=$J(z.blob);if(P.byteLength===0)return W(7);return M({blob:P,credId:new Uint8Array(V.rawId)})}var q$=new TextEncoder().encode("diplomatic.prf.v1"),o$=32;async function QJ($){let Z=w0();if(Z!==0)return W(Z);let[J,Q]=U0($);if(Q!==0)return W(Q);if(J===void 0)return W(9);let X=$?.userName??"diplomatic-prf",Y={residentKey:"required",requireResidentKey:!0,userVerification:"required",authenticatorAttachment:$?.authenticatorAttachment??"platform"},G;try{G=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:X,displayName:X},pubKeyCredParams:V$,authenticatorSelection:Y,extensions:{prf:{}}}})}catch{return W(24)}let[V,q]=C0(G);if(q!==0)return W(q);if(V===void 0)return W(27);let N=V.getClientExtensionResults();return M({credId:new Uint8Array(V.rawId),prfEnabled:N.prf?.enabled===!0})}async function c0($){let Z=w0();if(Z!==0)return W(Z);let[J,Q]=U0($);if(Q!==0)return W(Q);if(J===void 0)return W(9);let X=$?.salt??q$,Y=I0(X),G={challenge:z0(F0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:Y}}}};if($?.credId!==void 0)G.allowCredentials=[{type:"public-key",id:I0($.credId)}];let V;try{V=await navigator.credentials.get({publicKey:G})}catch{return W(24)}let[q,N]=C0(V);if(N!==0)return W(N);if(q===void 0)return W(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return W(7);let P=z.first,O=P instanceof ArrayBuffer?new Uint8Array(P):new Uint8Array(P.buffer,P.byteOffset,P.byteLength),R=O.byteLength>=o$?O.slice(0,o$):O;if(R.byteLength!==o$)return W(27);return M({prf:R,credId:new Uint8Array(q.rawId)})}var N$="";var P$=typeof globalThis.Worker==="function"?globalThis.Worker:void 0,a$=P$===void 0?void 0:P$.prototype.postMessage,z$;function oQ(){if(typeof N$!=="string"||N$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(N$)}function aQ(){if(z$!==void 0)return z$;let $=new Blob([oQ()],{type:"text/javascript"});return z$=URL.createObjectURL($),z$}function XJ(){if(P$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new P$(aQ(),{type:"module"})}function YJ($,Z,J){if(a$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot post to sync worker");if(J!==void 0&&J.length>0)a$.call($,Z,{transfer:J});else a$.call($,Z)}var sQ=new TextEncoder().encode("diplomatic.wrap.v1"),GJ=new TextEncoder().encode("diplomatic.pair.v1"),eQ=32,tQ=16;class Z0{#Z;#$;constructor($,Z){this.#Z=$,this.#$=Z}static async fromRandom($){let Z=await $.gen256BitSecureRandomSeed(),[J,Q]=s(Z);if(Q!==0||J===void 0)throw Error(`enclave: invalid random seed (${Q})`);return new Z0(J,$)}static fromBytes($,Z){let[J,Q]=s(Z);if(Q!==0)return W(Q);if(J===void 0)return W(10);let[X,Y]=s(J.slice());if(Y!==0)return W(Y);if(X===void 0)return W(10);return M(new Z0(X,$))}async sealWithPasskey($){let Z=$?.salt??q$,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[Y,G]=await QJ({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf"});if(G!==0)return W(G);if(Y===void 0)return W(24);if(!Y.prfEnabled)return W(24);J=Y.credId}let[Q,X]=await c0({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await this.#X(Q.prf);if(G!==0)return W(G);if(Y===void 0)return W(12);return M({sealedMaster:Y,salt:Z.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async unsealWithPasskey($,Z,J){let[Q,X]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await Z0.#Y($,Z,Q.prf);if(G!==0)return W(G);if(Y===void 0)return W(12);return M({enclave:Y,credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[Y,G]=await ZJ(Z);if(G!==0)return W(G);if(Y===void 0)return W(24);J=Y}let[Q,X]=this.#G($);if(X!==0)return W(X);if(Q===void 0)return W(12);try{let Y=await r$(J,Q,Z);if(Y!==0)return W(Y);return M(J)}finally{Q.fill(0)}}static async fromLargeBlob($,Z){let[J,Q]=await JJ(Z?.credId,Z);if(Q!==0)return W(Q);if(J===void 0)return W(7);try{return Z0.#W($,J.blob,J.credId)}finally{J.blob.fill(0)}}static async clearLargeBlob($,Z){return r$($,new Uint8Array(X0),Z)}async sealPairPackageBody($,Z){let J=Z?.salt??q$,[Q,X]=await c0({rpId:Z?.rpId,rpName:Z?.rpName,credId:Z?.credId,salt:J});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await M$(this.#$,Q.prf,GJ);if(G!==0)return W(G);if(Y===void 0)return W(12);try{let[V,q]=s(this.#Z.slice());if(q!==0)return W(q);if(V===void 0)return W(10);let N={masterSeed:V,hosts:$.map((H)=>({handle:H.handle,label:H.label,idx:H.idx??0}))},z=new L,P=z.writeStruct(c$,N);if(P!==0)return V.fill(0),W(P);let O=z.result();V.fill(0);let R;try{R=await this.#$.encryptXSalsa20Poly1305Combined(O,Y)}catch{return O.fill(0),W(12)}return O.fill(0),M({body:R,salt:J.slice(),credId:Q.credId.slice()})}finally{Y.fill(0)}}finally{Q.prf.fill(0)}}static async openPairPackageBody($,Z,J){let[Q,X]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await M$($,Q.prf,GJ);if(G!==0)return W(G);if(Y===void 0)return W(12);try{let V;try{V=await $.decryptXSalsa20Poly1305Combined(Z,Y)}catch{return W(20)}let q=new f(V),[N,z]=q.readStruct(c$);if(V.fill(0),z!==0)return W(z);if(N===void 0)return W(14);let[P,O]=Z0.fromBytes($,N.masterSeed);if(N.masterSeed.fill(0),O!==0)return W(O);if(P===void 0)return W(12);let[R,H]=await P.#X(Q.prf);if(H!==0)return W(H);if(R===void 0)return W(12);return M({enclave:P,hosts:N.hosts.map((F)=>({...F})),sealedMaster:R,credId:Q.credId.slice()})}finally{Y.fill(0)}}finally{Q.prf.fill(0)}}spawnSyncWorker($){let Z=XJ(),J=this.#Z.slice();return YJ(Z,{id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(G)=>this.#V(J,G),X=(G)=>this.#q(J,G);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:X}),both:Object.freeze({encrypt:Q,decrypt:X})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,X=await this.#Q(J,Q),Y=X.publicKey;return X.privateKey.fill(0),Object.freeze({publicKey:Y,sign:(G)=>this.#z(J,Q,G),kdmFor:(G)=>this.#P(J,Q,G)})}async#X($){let[Z,J]=await M$(this.#$,$);if(J!==0)return W(J);if(Z===void 0)return W(12);try{let Q=await this.#$.encryptXSalsa20Poly1305Combined(this.#Z,Z);return G$(Q)}catch{return W(12)}finally{Z.fill(0)}}static async#Y($,Z,J){let[,Q]=G$(Z);if(Q!==0)return W(Q);let[X,Y]=await M$($,J);if(Y!==0)return W(Y);if(X===void 0)return W(12);let G;try{try{G=await $.decryptXSalsa20Poly1305Combined(Z,X)}catch{return W(20)}return Z0.fromBytes($,G)}finally{X.fill(0),G?.fill(0)}}#G($){let[Z,J]=s(this.#Z.slice());if(J!==0)return W(J);if(Z===void 0)return W(10);let[Q,X]=tZ(Z,$);if(Z.fill(0),X!==0)return W(X);if(Q===void 0)return W(12);try{let Y=new L,G=Y.writeStruct(n$,Q);if(G!==0)return W(G);return M(Y.result())}finally{Q.masterSeed.fill(0)}}static#W($,Z,J){if(Z.byteLength===0||Z.every((G)=>G===0))return W(22);if(Z.byteLength===X0){if(Z.every((q)=>q===0))return W(22);let[G,V]=Z0.fromBytes($,Z);if(V!==0)return W(V);if(G===void 0)return W(12);return M({enclave:G,hosts:[],credId:J})}let Q=new f(Z),[X,Y]=Q.readStruct(n$);if(Y!==0)return W(Y);if(X===void 0)return W(14);try{if(X.masterSeed.every((q)=>q===0))return W(22);let[G,V]=Z0.fromBytes($,X.masterSeed);if(V!==0)return W(V);if(G===void 0)return W(12);return M({enclave:G,hosts:X.hosts.map((q)=>({...q})),credId:J})}finally{X.masterSeed.fill(0)}}async#V($,Z){let J=await this.#J($);return this.#$.encryptXSalsa20Poly1305Combined(Z,J)}async#q($,Z){let J=await this.#J($);return this.#$.decryptXSalsa20Poly1305Combined(Z,J)}async#J($){return this.#$.blake3(u0(this.#Z,$))}async#N($,Z){let J=new TextEncoder().encode($),Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,BigInt(Z),!1),await this.#J(u0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);try{return await this.#$.deriveEd25519KeyPair(J)}finally{J.fill(0)}}async#z($,Z,J){let Q=await this.#Q($,Z);try{return await this.#$.signEd25519(J,Q.privateKey)}finally{Q.privateKey.fill(0)}}async#P($,Z,J){let Q=await this.#Q($,Z),X=u0(Q.privateKey,J);Q.privateKey.fill(0);try{return(await this.#$.blake3(X)).slice(0,S0)}finally{X.fill(0)}}}async function M$($,Z,J=sQ){if(Z.byteLength<tQ)return W(10);let Q=await $.blake3(u0(Z,J));return M(Q.slice(0,eQ))}class s${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 X of Q)X(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function WJ($,Z,J,Q=0){let X=Z.now(),Y=new L,G=Y.writeVarString($);if(G!==0)return W(G);let q={id:Y.result(),ts:new Date(0)},[N,z]=hZ(q);if(z!==0)return W(z);let P=X.getTime()-q.ts.getTime();return M({eid:N,off:P,ctr:Q,len:J.length,bod:J})}class $X{singletonType;latest;latestOff=-1;emitter=new s$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new f(Z.eid),[Q,X]=J.readStruct(d0);if(X!==0)continue;let Y=new L;Y.writeVarString(this.singletonType);let G=Y.result();if(Q.id.length===G.length&&Q.id.every((V,q)=>V===G[q])){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 VJ($,Z,J,Q){let X=new f($.headCph),[Y,G]=X.readStruct(v0);if(G!==0)return W(G);let{sig:V,kdm:q,headCph:N}=Y;if(!await Q.checkSigEd25519(V,N,Z))return W(3);let P=J.deriveCipher(q,"decrypt"),O;try{O=await P.decrypt(N)}catch{return W(20)}return M({kdm:q,headEnc:O})}var b0=CQ(qQ(),1),IY={encode:b0.encode,decode:b0.decode,decodeAsync:b0.decodeAsync},UY=IY;import{Database as wY}from"bun:sqlite";var z8=Symbol("EntityID");var P8=Symbol("DerivationSeed"),M8=Symbol("PublicKey"),O8=Symbol("PrivateKey"),K8=Symbol("HostSpecificKeyPair"),R8=Symbol("Hash"),M0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function CY($="diplomatic.db"){let Z=new wY($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
1
+ var KQ=Object.create;var{getPrototypeOf:RQ,defineProperty:PZ,getOwnPropertyNames:HQ}=Object;var FQ=Object.prototype.hasOwnProperty;function IQ($){return this[$]}var UQ,wQ,CQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var X=Z?UQ??=new WeakMap:wQ??=new WeakMap,Y=X.get($);if(Y)return Y}J=$!=null?KQ(RQ($)):{};let G=Z||!$||!$.__esModule?PZ(J,"default",{value:$,enumerable:!0}):J;for(let V of HQ($))if(!FQ.call(G,V))PZ(G,V,{get:IQ.bind($,V),enumerable:!0});if(Q)X.set($,G);return G};var c=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var O$=c((MJ)=>{Object.defineProperty(MJ,"__esModule",{value:!0});MJ.utf8Count=ZX;MJ.utf8EncodeJs=qJ;MJ.utf8EncodeTE=NJ;MJ.utf8Encode=XX;MJ.utf8DecodeJs=zJ;MJ.utf8DecodeTD=PJ;MJ.utf8Decode=VX;function ZX($){let Z=$.length,J=0,Q=0;while(Q<Z){let X=$.charCodeAt(Q++);if((X&4294967168)===0){J++;continue}else if((X&4294965248)===0)J+=2;else{if(X>=55296&&X<=56319){if(Q<Z){let Y=$.charCodeAt(Q);if((Y&64512)===56320)++Q,X=((X&1023)<<10)+(Y&1023)+65536}}if((X&4294901760)===0)J+=3;else J+=4}}return J}function qJ($,Z,J){let Q=$.length,X=J,Y=0;while(Y<Q){let G=$.charCodeAt(Y++);if((G&4294967168)===0){Z[X++]=G;continue}else if((G&4294965248)===0)Z[X++]=G>>6&31|192;else{if(G>=55296&&G<=56319){if(Y<Q){let V=$.charCodeAt(Y);if((V&64512)===56320)++Y,G=((G&1023)<<10)+(V&1023)+65536}}if((G&4294901760)===0)Z[X++]=G>>12&15|224,Z[X++]=G>>6&63|128;else Z[X++]=G>>18&7|240,Z[X++]=G>>12&63|128,Z[X++]=G>>6&63|128}Z[X++]=G&63|128}}var JX=new TextEncoder,QX=50;function NJ($,Z,J){JX.encodeInto($,Z.subarray(J))}function XX($,Z,J){if($.length>QX)NJ($,Z,J);else qJ($,Z,J)}var YX=4096;function zJ($,Z,J){let Q=Z,X=Q+J,Y=[],G="";while(Q<X){let V=$[Q++];if((V&128)===0)Y.push(V);else if((V&224)===192){let q=$[Q++]&63;Y.push((V&31)<<6|q)}else if((V&240)===224){let q=$[Q++]&63,N=$[Q++]&63;Y.push((V&31)<<12|q<<6|N)}else if((V&248)===240){let q=$[Q++]&63,N=$[Q++]&63,z=$[Q++]&63,P=(V&7)<<18|q<<12|N<<6|z;if(P>65535)P-=65536,Y.push(P>>>10&1023|55296),P=56320|P&1023;Y.push(P)}else Y.push(V);if(Y.length>=YX)G+=String.fromCharCode(...Y),Y.length=0}if(Y.length>0)G+=String.fromCharCode(...Y);return G}var GX=new TextDecoder,WX=200;function PJ($,Z,J){let Q=$.subarray(Z,Z+J);return GX.decode(Q)}function VX($,Z,J){if(J>WX)return PJ($,Z,J);else return zJ($,Z,J)}});var e$=c((KJ)=>{Object.defineProperty(KJ,"__esModule",{value:!0});KJ.ExtData=void 0;class OJ{type;data;constructor($,Z){this.type=$,this.data=Z}}KJ.ExtData=OJ});var R$=c((HJ)=>{Object.defineProperty(HJ,"__esModule",{value:!0});HJ.DecodeError=void 0;class K$ extends Error{constructor($){super($);let Z=Object.create(K$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:K$.name})}}HJ.DecodeError=K$});var H$=c((IJ)=>{Object.defineProperty(IJ,"__esModule",{value:!0});IJ.UINT32_MAX=void 0;IJ.setUint64=RX;IJ.setInt64=HX;IJ.getInt64=FX;IJ.getUint64=IX;IJ.UINT32_MAX=4294967295;function RX($,Z,J){let Q=J/4294967296,X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function HX($,Z,J){let Q=Math.floor(J/4294967296),X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function FX($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function IX($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var t$=c((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.timestampExtension=LJ.EXT_TIMESTAMP=void 0;LJ.encodeTimeSpecToTimestamp=CJ;LJ.encodeDateToTimeSpec=TJ;LJ.encodeTimestampExtension=DJ;LJ.decodeTimestampToTimeSpec=AJ;LJ.decodeTimestampExtension=jJ;var DX=R$(),wJ=H$();LJ.EXT_TIMESTAMP=-1;var AX=4294967295,jX=17179869183;function CJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=jX)if(Z===0&&$<=AX){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,X=new Uint8Array(8),Y=new DataView(X.buffer);return Y.setUint32(0,Z<<2|J&3),Y.setUint32(4,Q),X}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,wJ.setInt64)(Q,4,$),J}}function TJ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,X=Math.floor(Q/1e9);return{sec:J+X,nsec:Q-X*1e9}}function DJ($){if($ instanceof Date){let Z=TJ($);return CJ(Z)}else return null}function AJ($){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),X=(J&3)*4294967296+Q,Y=J>>>2;return{sec:X,nsec:Y}}case 12:{let J=(0,wJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new DX.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function jJ($){let Z=AJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}LJ.timestampExtension={type:LJ.EXT_TIMESTAMP,encode:DJ,decode:jJ}});var I$=c((kJ)=>{Object.defineProperty(kJ,"__esModule",{value:!0});kJ.ExtensionCodec=void 0;var F$=e$(),BX=t$();class $Z{static defaultCodec=new $Z;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(BX.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 X=Q($,Z);if(X!=null){let Y=-1-J;return new F$.ExtData(Y,X)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let X=Q($,Z);if(X!=null){let Y=J;return new F$.ExtData(Y,X)}}}if($ instanceof F$.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 F$.ExtData(Z,$)}}kJ.ExtensionCodec=$Z});var ZZ=c((BJ)=>{Object.defineProperty(BJ,"__esModule",{value:!0});BJ.ensureUint8Array=SX;function xX($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function SX($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(xX($))return new Uint8Array($);else return Uint8Array.from($)}});var QZ=c((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.Encoder=gJ.DEFAULT_INITIAL_BUFFER_SIZE=gJ.DEFAULT_MAX_DEPTH=void 0;var xJ=O$(),fX=I$(),SJ=H$(),vX=ZZ();gJ.DEFAULT_MAX_DEPTH=100;gJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class JZ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??fX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??gJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??gJ.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 JZ({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,xJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,xJ.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,vX.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 X of J){let Y=$[X];if(!(this.ignoreUndefined&&Y===void 0))this.encodeString(X),this.doEncode(Y,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,SJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,SJ.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}}gJ.Encoder=JZ});var bJ=c((lJ)=>{Object.defineProperty(lJ,"__esModule",{value:!0});lJ.encode=lX;var yX=QZ();function lX($,Z){return new yX.Encoder(Z).encodeSharedRef($)}});var iJ=c((hJ)=>{Object.defineProperty(hJ,"__esModule",{value:!0});hJ.prettyByte=hX;function hX($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var nJ=c((uJ)=>{Object.defineProperty(uJ,"__esModule",{value:!0});uJ.CachedKeyDecoder=void 0;var pX=O$(),uX=16,dX=16;class pJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=uX,Z=dX){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 X of Q){let Y=X.bytes;for(let G=0;G<J;G++)if(Y[G]!==$[Z+G])continue $;return X.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 X=(0,pX.utf8DecodeJs)($,Z,J),Y=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(Y,X),X}}uJ.CachedKeyDecoder=pJ});var U$=c((sJ)=>{Object.defineProperty(sJ,"__esModule",{value:!0});sJ.Decoder=void 0;var XZ=iJ(),nX=I$(),T0=H$(),cX=O$(),cJ=ZZ(),rX=nJ(),P0=R$(),YZ="array",o0="map_key",oJ="map_value",oX=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new P0.DecodeError("The type of key must be string or number but "+typeof $)};class aJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=YZ,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=o0,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===YZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===o0||$.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 r0=-1,GZ=new DataView(new ArrayBuffer(0)),aX=new Uint8Array(GZ.buffer);try{GZ.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 rJ=RangeError("Insufficient data"),sX=new rX.CachedKeyDecoder;class WZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=GZ;bytes=aX;headByte=r0;stack=new aJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??nX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??T0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??T0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??T0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??T0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??T0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:sX,this.mapKeyConverter=$?.mapKeyConverter??oX}clone(){return new WZ({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=r0,this.stack.reset()}setBuffer($){let Z=(0,cJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===r0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,cJ.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 G of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(G);try{J=this.doDecodeSync(),Z=!0}catch(V){if(!(V instanceof RangeError))throw V}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:Q,pos:X,totalPos:Y}=this;throw RangeError(`Insufficient data in parsing ${(0,XZ.prettyByte)(Q)} at ${Y} (${X} 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 X of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(X),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(Y){if(!(Y instanceof RangeError))throw Y}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 P0.DecodeError(`Unrecognized type byte: ${(0,XZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===YZ)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===o0){if(Z==="__proto__")throw new P0.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=o0;continue $}}return Z}}readHeadByte(){if(this.headByte===r0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=r0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new P0.DecodeError(`Unrecognized array type byte: ${(0,XZ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new P0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new P0.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 P0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw rJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,cX.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===o0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new P0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw rJ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new P0.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,T0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,T0.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,$}}sJ.Decoder=WZ});var ZQ=c(($Q)=>{Object.defineProperty($Q,"__esModule",{value:!0});$Q.decode=eX;$Q.decodeMulti=tX;var tJ=U$();function eX($,Z){return new tJ.Decoder(Z).decode($)}function tX($,Z){return new tJ.Decoder(Z).decodeMulti($)}});var YQ=c((XQ)=>{Object.defineProperty(XQ,"__esModule",{value:!0});XQ.isAsyncIterable=JQ;XQ.asyncIterableFromStream=QQ;XQ.ensureAsyncIterable=JY;function JQ($){return $[Symbol.asyncIterator]!=null}async function*QQ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function JY($){if(JQ($))return $;else return QQ($)}});var WQ=c((GQ)=>{Object.defineProperty(GQ,"__esModule",{value:!0});GQ.decodeAsync=GY;GQ.decodeArrayStream=WY;GQ.decodeMultiStream=VY;var VZ=U$(),qZ=YQ();async function GY($,Z){let J=(0,qZ.ensureAsyncIterable)($);return new VZ.Decoder(Z).decodeAsync(J)}function WY($,Z){let J=(0,qZ.ensureAsyncIterable)($);return new VZ.Decoder(Z).decodeArrayStream(J)}function VY($,Z){let J=(0,qZ.ensureAsyncIterable)($);return new VZ.Decoder(Z).decodeStream(J)}});var qQ=c((v)=>{Object.defineProperty(v,"__esModule",{value:!0});v.decodeTimestampExtension=v.encodeTimestampExtension=v.decodeTimestampToTimeSpec=v.encodeTimeSpecToTimestamp=v.encodeDateToTimeSpec=v.EXT_TIMESTAMP=v.ExtData=v.ExtensionCodec=v.Encoder=v.DecodeError=v.Decoder=v.decodeMultiStream=v.decodeArrayStream=v.decodeAsync=v.decodeMulti=v.decode=v.encode=void 0;var PY=bJ();Object.defineProperty(v,"encode",{enumerable:!0,get:function(){return PY.encode}});var VQ=ZQ();Object.defineProperty(v,"decode",{enumerable:!0,get:function(){return VQ.decode}});Object.defineProperty(v,"decodeMulti",{enumerable:!0,get:function(){return VQ.decodeMulti}});var NZ=WQ();Object.defineProperty(v,"decodeAsync",{enumerable:!0,get:function(){return NZ.decodeAsync}});Object.defineProperty(v,"decodeArrayStream",{enumerable:!0,get:function(){return NZ.decodeArrayStream}});Object.defineProperty(v,"decodeMultiStream",{enumerable:!0,get:function(){return NZ.decodeMultiStream}});var MY=U$();Object.defineProperty(v,"Decoder",{enumerable:!0,get:function(){return MY.Decoder}});var OY=R$();Object.defineProperty(v,"DecodeError",{enumerable:!0,get:function(){return OY.DecodeError}});var KY=QZ();Object.defineProperty(v,"Encoder",{enumerable:!0,get:function(){return KY.Encoder}});var RY=I$();Object.defineProperty(v,"ExtensionCodec",{enumerable:!0,get:function(){return RY.ExtensionCodec}});var HY=e$();Object.defineProperty(v,"ExtData",{enumerable:!0,get:function(){return HY.ExtData}});var l0=t$();Object.defineProperty(v,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return l0.EXT_TIMESTAMP}});Object.defineProperty(v,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return l0.encodeDateToTimeSpec}});Object.defineProperty(v,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return l0.encodeTimeSpecToTimestamp}});Object.defineProperty(v,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return l0.decodeTimestampToTimeSpec}});Object.defineProperty(v,"encodeTimestampExtension",{enumerable:!0,get:function(){return l0.encodeTimestampExtension}});Object.defineProperty(v,"decodeTimestampExtension",{enumerable:!0,get:function(){return l0.decodeTimestampExtension}})});import*as G0 from"node:crypto";var O0=G0&&typeof G0==="object"&&"webcrypto"in G0?G0.webcrypto:G0&&typeof G0==="object"&&("randomBytes"in G0)?G0:void 0;function a0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function w$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function i($,...Z){if(!w$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function C$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function MZ($,Z){i($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function T$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var W0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var TQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!TQ)throw Error("Non little-endian hardware is not supported");function DQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function s0($){if(typeof $==="string")$=DQ($);else if(w$($))$=e0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function OZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function KZ($,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 RZ=($,Z)=>{function J(Q,...X){if(i(Q),$.nonceLength!==void 0){let z=X[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)i(z);else i(z,$.nonceLength)}let Y=$.tagLength;if(Y&&X[1]!==void 0)i(X[1]);let G=Z(Q,...X),V=(z,P)=>{if(P!==void 0){if(z!==2)throw Error("cipher output not supported");i(P)}},q=!1;return{encrypt(z,P){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,i(z),V(G.encrypt.length,P),G.encrypt(z,P)},decrypt(z,P){if(i(z),Y&&z.length<Y)throw Error("invalid ciphertext length: smaller than tagLength="+Y);return V(G.decrypt.length,P),G.decrypt(z,P)}}}return Object.assign(J,$),J};function D$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!AQ(Z))throw Error("invalid output, must be aligned");return Z}function AQ($){return $.byteOffset%4===0}function e0($){return Uint8Array.from($)}function J0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function t0($=32){if(O0&&typeof O0.getRandomValues==="function")return O0.getRandomValues(new Uint8Array($));if(O0&&typeof O0.randomBytes==="function")return O0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var FZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),jQ=FZ("expand 16-byte k"),LQ=FZ("expand 32-byte k"),EQ=W0(jQ),_Q=W0(LQ);function I($,Z){return $<<Z|$>>>32-Z}function A$($){return $.byteOffset%4===0}var $$=64,kQ=16,IZ=4294967295,HZ=new Uint32Array;function mQ($,Z,J,Q,X,Y,G,V){let q=X.length,N=new Uint8Array($$),z=W0(N),P=A$(X)&&A$(Y),O=P?W0(X):HZ,R=P?W0(Y):HZ;for(let H=0;H<q;G++){if($(Z,J,Q,z,G,V),G>=IZ)throw Error("arx: counter overflow");let F=Math.min($$,q-H);if(P&&F===$$){let U=H/4;if(H%4!==0)throw Error("arx: invalid block position");for(let C=0,D;C<kQ;C++)D=U+C,R[D]=O[D]^z[C];H+=$$;continue}for(let U=0,C;U<F;U++)C=H+U,Y[C]=X[C]^N[U];H+=F}}function UZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:X,counterRight:Y,rounds:G}=OZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return a0(X),a0(G),T$(Y),T$(J),(V,q,N,z,P=0)=>{i(V),i(q),i(N);let O=N.length;if(z===void 0)z=new Uint8Array(O);if(i(z),a0(P),P<0||P>=IZ)throw Error("arx: counter overflow");if(z.length<O)throw Error(`arx: output (${z.length}) is shorter than data (${O})`);let R=[],H=V.length,F,U;if(H===32)R.push(F=e0(V)),U=_Q;else if(H===16&&J)F=new Uint8Array(32),F.set(V),F.set(V,16),U=EQ,R.push(F);else throw Error(`arx: invalid 32-byte key, got length=${H}`);if(!A$(q))R.push(q=e0(q));let C=W0(F);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(U,C,W0(q.subarray(0,16)),C),q=q.subarray(16)}let D=16-X;if(D!==q.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let w=new Uint8Array(12);w.set(q,Y?0:12-q.length),q=w,R.push(q)}let j=W0(q);return mQ($,U,C,j,N,z,P,G),J0(...R),z}}var u=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class wZ{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,$=s0($),i($,32);let Z=u($,0),J=u($,2),Q=u($,4),X=u($,6),Y=u($,8),G=u($,10),V=u($,12),q=u($,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|X<<9)&8191,this.r[4]=(X>>>4|Y<<12)&255,this.r[5]=Y>>>1&8190,this.r[6]=(Y>>>14|G<<2)&8191,this.r[7]=(G>>>11|V<<5)&8065,this.r[8]=(V>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let N=0;N<8;N++)this.pad[N]=u($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:X,r:Y}=this,G=Y[0],V=Y[1],q=Y[2],N=Y[3],z=Y[4],P=Y[5],O=Y[6],R=Y[7],H=Y[8],F=Y[9],U=u($,Z+0),C=u($,Z+2),D=u($,Z+4),j=u($,Z+6),w=u($,Z+8),E=u($,Z+10),x=u($,Z+12),p=u($,Z+14),_=X[0]+(U&8191),m=X[1]+((U>>>13|C<<3)&8191),S=X[2]+((C>>>10|D<<6)&8191),K=X[3]+((D>>>7|j<<9)&8191),g=X[4]+((j>>>4|w<<12)&8191),B=X[5]+(w>>>1&8191),y=X[6]+((w>>>14|E<<2)&8191),l=X[7]+((E>>>11|x<<5)&8191),b=X[8]+((x>>>8|p<<8)&8191),h=X[9]+(p>>>5|Q),T=0,n=T+_*G+m*(5*F)+S*(5*H)+K*(5*R)+g*(5*O);T=n>>>13,n&=8191,n+=B*(5*P)+y*(5*z)+l*(5*N)+b*(5*q)+h*(5*V),T+=n>>>13,n&=8191;let o=T+_*V+m*G+S*(5*F)+K*(5*H)+g*(5*R);T=o>>>13,o&=8191,o+=B*(5*O)+y*(5*P)+l*(5*z)+b*(5*N)+h*(5*q),T+=o>>>13,o&=8191;let e=T+_*q+m*V+S*G+K*(5*F)+g*(5*H);T=e>>>13,e&=8191,e+=B*(5*R)+y*(5*O)+l*(5*P)+b*(5*z)+h*(5*N),T+=e>>>13,e&=8191;let k=T+_*N+m*q+S*V+K*G+g*(5*F);T=k>>>13,k&=8191,k+=B*(5*H)+y*(5*R)+l*(5*O)+b*(5*P)+h*(5*z),T+=k>>>13,k&=8191;let Y0=T+_*z+m*N+S*q+K*V+g*G;T=Y0>>>13,Y0&=8191,Y0+=B*(5*F)+y*(5*H)+l*(5*R)+b*(5*O)+h*(5*P),T+=Y0>>>13,Y0&=8191;let D0=T+_*P+m*z+S*N+K*q+g*V;T=D0>>>13,D0&=8191,D0+=B*G+y*(5*F)+l*(5*H)+b*(5*R)+h*(5*O),T+=D0>>>13,D0&=8191;let A0=T+_*O+m*P+S*z+K*N+g*q;T=A0>>>13,A0&=8191,A0+=B*V+y*G+l*(5*F)+b*(5*H)+h*(5*R),T+=A0>>>13,A0&=8191;let j0=T+_*R+m*O+S*P+K*z+g*N;T=j0>>>13,j0&=8191,j0+=B*q+y*V+l*G+b*(5*F)+h*(5*H),T+=j0>>>13,j0&=8191;let L0=T+_*H+m*R+S*O+K*P+g*z;T=L0>>>13,L0&=8191,L0+=B*N+y*q+l*V+b*G+h*(5*F),T+=L0>>>13,L0&=8191;let E0=T+_*F+m*H+S*R+K*O+g*P;T=E0>>>13,E0&=8191,E0+=B*z+y*N+l*q+b*V+h*G,T+=E0>>>13,E0&=8191,T=(T<<2)+T|0,T=T+n|0,n=T&8191,T=T>>>13,o+=T,X[0]=n,X[1]=o,X[2]=e,X[3]=k,X[4]=Y0,X[5]=D0,X[6]=A0,X[7]=j0,X[8]=L0,X[9]=E0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let G=2;G<10;G++)$[G]+=Q,Q=$[G]>>>13,$[G]&=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 G=1;G<10;G++)J[G]=$[G]+Q,Q=J[G]>>>13,J[G]&=8191;J[9]-=8192;let X=(Q^1)-1;for(let G=0;G<10;G++)J[G]&=X;X=~X;for(let G=0;G<10;G++)$[G]=$[G]&X|J[G];$[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 Y=$[0]+Z[0];$[0]=Y&65535;for(let G=1;G<8;G++)Y=($[G]+Z[G]|0)+(Y>>>16)|0,$[G]=Y&65535;J0(J)}update($){C$(this);let{buffer:Z,blockLen:J}=this;$=s0($);let Q=$.length;for(let X=0;X<Q;){let Y=Math.min(J-this.pos,Q-X);if(Y===J){for(;J<=Q-X;X+=J)this.process($,X);continue}if(Z.set($.subarray(X,X+Y),this.pos),this.pos+=Y,X+=Y,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){J0(this.h,this.r,this.buffer,this.pad)}digestInto($){C$(this),MZ($,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 X=0;for(let Y=0;Y<8;Y++)$[X++]=J[Y]>>>0,$[X++]=J[Y]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function BQ($){let Z=(Q,X)=>$(X).update(s0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var j$=BQ(($)=>new wZ($));function xQ($,Z,J,Q,X,Y=20){let G=$[0],V=Z[0],q=Z[1],N=Z[2],z=Z[3],P=$[1],O=J[0],R=J[1],H=X,F=0,U=$[2],C=Z[4],D=Z[5],j=Z[6],w=Z[7],E=$[3],x=G,p=V,_=q,m=N,S=z,K=P,g=O,B=R,y=H,l=F,b=U,h=C,T=D,n=j,o=w,e=E;for(let Y0=0;Y0<Y;Y0+=2)S^=I(x+T|0,7),y^=I(S+x|0,9),T^=I(y+S|0,13),x^=I(T+y|0,18),l^=I(K+p|0,7),n^=I(l+K|0,9),p^=I(n+l|0,13),K^=I(p+n|0,18),o^=I(b+g|0,7),_^=I(o+b|0,9),g^=I(_+o|0,13),b^=I(g+_|0,18),m^=I(e+h|0,7),B^=I(m+e|0,9),h^=I(B+m|0,13),e^=I(h+B|0,18),p^=I(x+m|0,7),_^=I(p+x|0,9),m^=I(_+p|0,13),x^=I(m+_|0,18),g^=I(K+S|0,7),B^=I(g+K|0,9),S^=I(B+g|0,13),K^=I(S+B|0,18),h^=I(b+l|0,7),y^=I(h+b|0,9),l^=I(y+h|0,13),b^=I(l+y|0,18),T^=I(e+o|0,7),n^=I(T+e|0,9),o^=I(n+T|0,13),e^=I(o+n|0,18);let k=0;Q[k++]=G+x|0,Q[k++]=V+p|0,Q[k++]=q+_|0,Q[k++]=N+m|0,Q[k++]=z+S|0,Q[k++]=P+K|0,Q[k++]=O+g|0,Q[k++]=R+B|0,Q[k++]=H+y|0,Q[k++]=F+l|0,Q[k++]=U+b|0,Q[k++]=C+h|0,Q[k++]=D+T|0,Q[k++]=j+n|0,Q[k++]=w+o|0,Q[k++]=E+e|0}function SQ($,Z,J,Q){let X=$[0],Y=Z[0],G=Z[1],V=Z[2],q=Z[3],N=$[1],z=J[0],P=J[1],O=J[2],R=J[3],H=$[2],F=Z[4],U=Z[5],C=Z[6],D=Z[7],j=$[3];for(let E=0;E<20;E+=2)q^=I(X+U|0,7),O^=I(q+X|0,9),U^=I(O+q|0,13),X^=I(U+O|0,18),R^=I(N+Y|0,7),C^=I(R+N|0,9),Y^=I(C+R|0,13),N^=I(Y+C|0,18),D^=I(H+z|0,7),G^=I(D+H|0,9),z^=I(G+D|0,13),H^=I(z+G|0,18),V^=I(j+F|0,7),P^=I(V+j|0,9),F^=I(P+V|0,13),j^=I(F+P|0,18),Y^=I(X+V|0,7),G^=I(Y+X|0,9),V^=I(G+Y|0,13),X^=I(V+G|0,18),z^=I(N+q|0,7),P^=I(z+N|0,9),q^=I(P+z|0,13),N^=I(q+P|0,18),F^=I(H+R|0,7),O^=I(F+H|0,9),R^=I(O+F|0,13),H^=I(R+O|0,18),U^=I(j+D|0,7),C^=I(U+j|0,9),D^=I(C+U|0,13),j^=I(D+C|0,18);let w=0;Q[w++]=X,Q[w++]=N,Q[w++]=H,Q[w++]=j,Q[w++]=z,Q[w++]=P,Q[w++]=O,Q[w++]=R}var L$=UZ(xQ,{counterRight:!0,extendNonceFn:SQ}),E$=RZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=D$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32);Q.set(J,32),J0(X),L$($,Z,Q,Q);let G=j$(Y,X);return Q.set(G,16),J0(Q.subarray(0,16),G),Q.subarray(16)},decrypt(J,Q){i(J),Q=D$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32,48),G=Q.subarray(48);Q.set(J,32),J0(X);let V=L$($,Z,X,X),q=j$(G,V);if(!KZ(Y,q))throw Error("invalid tag");return L$($,Z,Q.subarray(16),Q.subarray(16)),J0(X,Y,q),G}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function gQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function h0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function K0($,...Z){if(!gQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function i0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function Z$($,Z){K0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function CZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function _0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function k0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function p0($,Z){return $<<32-Z|$>>>Z}var TZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function DZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var AZ=TZ?($)=>$:($)=>DZ($);function fQ($){for(let Z=0;Z<$.length;Z++)$[Z]=DZ($[Z]);return $}var a=TZ?($)=>$:fQ;function vQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function m0($){if(typeof $==="string")$=vQ($);return K0($),$}class _${}function jZ($){let Z=(Q,X)=>$(X).update(m0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var LZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J$=BigInt(4294967295),EZ=BigInt(32);function k$($,Z=!1){if(Z)return{h:Number($&J$),l:Number($>>EZ&J$)};return{h:Number($>>EZ&J$)|0,l:Number($&J$)|0}}function V0($,Z,J,Q,X){return $=$+Z+X|0,Q=p0(Q^$,16),J=J+Q|0,Z=p0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function q0($,Z,J,Q,X){return $=$+Z+X|0,Q=p0(Q^$,8),J=J+Q|0,Z=p0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class m$ extends _${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,h0($),h0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=_0(this.buffer)}update($){i0(this),$=m0($),K0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,X=$.length,Y=$.byteOffset,G=$.buffer;for(let V=0;V<X;){if(this.pos===Z)a(Q),this.compress(Q,0,!1),a(Q),this.pos=0;let q=Math.min(Z-this.pos,X-V),N=Y+V;if(q===Z&&!(N%4)&&V+q<X){let z=new Uint32Array(G,N,Math.floor((X-V)/4));a(z);for(let P=0;V+Z<X;P+=Q.length,V+=Z)this.length+=Z,this.compress(z,P,!1);a(z);continue}J.set($.subarray(V,V+q),this.pos),this.pos+=q,this.length+=q,V+=q}return this}digestInto($){i0(this),Z$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,k0(this.buffer.subarray(Z)),a(J),this.compress(J,0,!0),a(J);let Q=_0($);this.get().forEach((X,Y)=>Q[Y]=AZ(X))}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:X,outputLen:Y,pos:G}=this;return $||($=new this.constructor({dkLen:Y})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=X,$.finished=Q,$.length=J,$.pos=G,$.outputLen=Y,$}clone(){return this._cloneInto()}}function B$($,Z,J,Q,X,Y,G,V,q,N,z,P,O,R,H,F,U,C,D,j){let w=0;for(let E=0;E<Q;E++)({a:X,b:q,c:O,d:U}=V0(X,q,O,U,J[Z+$[w++]])),{a:X,b:q,c:O,d:U}=q0(X,q,O,U,J[Z+$[w++]]),{a:Y,b:N,c:R,d:C}=V0(Y,N,R,C,J[Z+$[w++]]),{a:Y,b:N,c:R,d:C}=q0(Y,N,R,C,J[Z+$[w++]]),{a:G,b:z,c:H,d:D}=V0(G,z,H,D,J[Z+$[w++]]),{a:G,b:z,c:H,d:D}=q0(G,z,H,D,J[Z+$[w++]]),{a:V,b:P,c:F,d:j}=V0(V,P,F,j,J[Z+$[w++]]),{a:V,b:P,c:F,d:j}=q0(V,P,F,j,J[Z+$[w++]]),{a:X,b:N,c:H,d:j}=V0(X,N,H,j,J[Z+$[w++]]),{a:X,b:N,c:H,d:j}=q0(X,N,H,j,J[Z+$[w++]]),{a:Y,b:z,c:F,d:U}=V0(Y,z,F,U,J[Z+$[w++]]),{a:Y,b:z,c:F,d:U}=q0(Y,z,F,U,J[Z+$[w++]]),{a:G,b:P,c:O,d:C}=V0(G,P,O,C,J[Z+$[w++]]),{a:G,b:P,c:O,d:C}=q0(G,P,O,C,J[Z+$[w++]]),{a:V,b:q,c:R,d:D}=V0(V,q,R,D,J[Z+$[w++]]),{a:V,b:q,c:R,d:D}=q0(V,q,R,D,J[Z+$[w++]]);return{v0:X,v1:Y,v2:G,v3:V,v4:q,v5:N,v6:z,v7:P,v8:O,v9:R,v10:H,v11:F,v12:U,v13:C,v14:D,v15:j}}var Q0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},N0=LZ.slice(),_Z=(()=>{let $=Array.from({length:16},(Q,X)=>X),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((X)=>Q[X]),J=[];for(let Q=0,X=$;Q<7;Q++,X=Z(X))J.push(...X);return Uint8Array.from(J)})();class x$ extends m${constructor($={},Z=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:J,context:Q}=$,X=Q!==void 0;if(J!==void 0){if(X)throw Error('Only "key" or "context" can be specified at same time');let Y=m0(J).slice();K0(Y,32),this.IV=_0(Y),a(this.IV),this.flags=Z|Q0.KEYED_HASH}else if(X){let Y=m0(Q),G=new x$({dkLen:32},Q0.DERIVE_KEY_CONTEXT).update(Y).digest();this.IV=_0(G),a(this.IV),this.flags=Z|Q0.DERIVE_KEY_MATERIAL}else this.IV=N0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=CZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:X,pos:Y}=this,{h:G,l:V}=k$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:P,v4:O,v5:R,v6:H,v7:F,v8:U,v9:C,v10:D,v11:j,v12:w,v13:E,v14:x,v15:p}=B$(_Z,Q,J,7,X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],N0[0],N0[1],N0[2],N0[3],G,V,Y,Z);X[0]=q^U,X[1]=N^C,X[2]=z^D,X[3]=P^j,X[4]=O^w,X[5]=R^E,X[6]=H^x,X[7]=F^p}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=Q0.CHUNK_START;if(this.chunkPos===15||J)Q|=Q0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let X=this.state;this.state=this.IV.slice();for(let Y,G=this.chunksDone+1;J||!(G&1);G>>=1){if(!(Y=this.stack.pop()))break;this.buffer32.set(Y,0),this.buffer32.set(X,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|Q0.PARENT,this.buffer32,0),X=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(X)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:X,posOut:Y,chunkOut:G,stack:V,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=V.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=X,$.chunksDone=q,$.posOut=Y,$.chunkOut=G,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,k0(this.state,this.buffer32,this.IV,this.bufferOut32),k0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:X}=this,{h:Y,l:G}=k$(BigInt(this.chunkOut++));a(Q);let{v0:V,v1:q,v2:N,v3:z,v4:P,v5:O,v6:R,v7:H,v8:F,v9:U,v10:C,v11:D,v12:j,v13:w,v14:E,v15:x}=B$(_Z,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],N0[0],N0[1],N0[2],N0[3],G,Y,Z,J);X[0]=V^F,X[1]=q^U,X[2]=N^C,X[3]=z^D,X[4]=P^j,X[5]=O^w,X[6]=R^E,X[7]=H^x,X[8]=$[0]^F,X[9]=$[1]^U,X[10]=$[2]^C,X[11]=$[3]^D,X[12]=$[4]^j,X[13]=$[5]^w,X[14]=$[6]^E,X[15]=$[7]^x,a(Q),a(X),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,k0(this.buffer.subarray(this.pos));let $=this.flags|Q0.ROOT;if(this.stack.length)$|=Q0.PARENT,a(this.buffer32),this.compress(this.buffer32,0,!0),a(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Q0.CHUNK_START:0)|Q0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){i0(this,!1),K0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,X=$.length;Q<X;){if(this.posOut>=Z)this.b2CompressOut();let Y=Math.min(Z-this.posOut,X-Q);$.set(J.subarray(this.posOut,this.posOut+Y),Q),this.posOut+=Y,Q+=Y}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return h0($),this.xofInto(new Uint8Array($))}digestInto($){if(Z$($,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 kZ=jZ(($)=>new x$($));function t($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function Q$($){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 xZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var mZ;if(typeof Uint8Array.prototype.toBase64==="function")mZ=($)=>$.toBase64();else mZ=($)=>btoa(String.fromCharCode(...$));var BZ;if(typeof Uint8Array.fromBase64==="function")BZ=($)=>Uint8Array.fromBase64($);else BZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function u0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var S$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function SZ($){let Z=new Uint8Array(S$.length+32);return Z.set(S$),Z.set($.subarray(0,32),S$.length),Z}function gZ($){return typeof $==="string"?new TextEncoder().encode($):$}function B0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class g${verifyKeys=new Map;async genRandomBytes($){return t0($)}async gen256BitSecureRandomSeed(){return t0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=t0(24),X=E$(Z,J).encrypt($);return new Uint8Array([...J,...X])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return E$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=SZ(Z),Q=B0(J),X;try{let N=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!0,["sign"]);X=await globalThis.crypto.subtle.exportKey("jwk",N)}finally{J.fill(0),new Uint8Array(Q).fill(0)}if(typeof X.x!=="string")throw Error("Ed25519 JWK missing x");let Y=X.x;X.d=void 0;let G=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:Y},{name:"Ed25519"},!0,["verify"]),V=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",G));this.verifyKeys.set(t(V),G);let q=new Uint8Array(64);return q.set(Z,0),q.set(V,32),{keyType:"ed25519",privateKey:q,publicKey:V}}async importSignKey($){let Z=$.subarray(0,32),J=SZ(Z),Q=B0(J);try{return await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!1,["sign"])}finally{J.fill(0),new Uint8Array(Q).fill(0)}}async importVerifyKey($){let Z=t($),J=this.verifyKeys.get(Z);if(J)return J;let Q=await globalThis.crypto.subtle.importKey("raw",B0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=gZ($),Q=await this.importSignKey(Z),X=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,B0(J));return new Uint8Array(X)}async checkSigEd25519($,Z,J){let Q=gZ(Z);try{let X=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},X,B0($),B0(Q))}catch{return!1}}async blake3($){return kZ($)}}var yQ=new g$,R0=yQ;var x0=64;var fZ=32,S0=8;var vZ=32;var yZ=30000,lZ=512,A;((K)=>{K[K.Success=0]="Success";K[K.InvalidSignature=3]="InvalidSignature";K[K.ClockOutOfSync=4]="ClockOutOfSync";K[K.UserNotRegistered=5]="UserNotRegistered";K[K.ServerMisconfigured=6]="ServerMisconfigured";K[K.MissingBody=7]="MissingBody";K[K.ExtraBodyContent=8]="ExtraBodyContent";K[K.MissingParam=9]="MissingParam";K[K.InvalidParam=10]="InvalidParam";K[K.InvalidRequest=11]="InvalidRequest";K[K.InternalError=12]="InternalError";K[K.NotFound=13]="NotFound";K[K.InvalidMessage=14]="InvalidMessage";K[K.NoChange=15]="NoChange";K[K.DatabaseClosed=16]="DatabaseClosed";K[K.StorageError=17]="StorageError";K[K.DatabaseError=18]="DatabaseError";K[K.HashMismatch=19]="HashMismatch";K[K.DecryptionError=20]="DecryptionError";K[K.NotImplemented=21]="NotImplemented";K[K.MissingSeed=22]="MissingSeed";K[K.OutOfBounds=23]="OutOfBounds";K[K.HostError=24]="HostError";K[K.CommunicationError=25]="CommunicationError";K[K.VarLimitExceeded=26]="VarLimitExceeded";K[K.InvalidResponse=27]="InvalidResponse";K[K.ConnectionClosed=28]="ConnectionClosed"})(A||={});var bZ="t";function M($){return[$,0]}function W($){return[void 0,$]}function lQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return W(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 M(new Uint8Array([0]));if(Z.length>8)return W(26);return M(new Uint8Array(Z))}function bQ($,Z=0){let J=0n,Q=0,X=Z;while(!0){if(X>=$.length)return W(14);let Y=$[X++];if(Y===void 0)return W(14);if(J|=BigInt(Y&127)<<BigInt(Q),(Y&128)===0){if(X-Z>8)return W(26);return M({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:X-Z})}if(Q+=7,Q>=56)return W(26)}}class f{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new f(J)}readBigInt(){if(this.pos+8>this.data.length)return W(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,M($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return W(Z);return M(new Date($))}readVarInt(){let[$,Z]=bQ(this.data,this.pos);if(Z!==0)return W(Z);this.pos+=$.bytesRead;let J=$.value;return M(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return W(Z);let[J,Q]=this.readBytes($);if(Q!==0)return W(Q);let X=new TextDecoder().decode(J);return M(X)}readBytes($){if($<0)return W(10);if(this.pos+$>this.data.length)return W(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,M(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return W(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return W(Q);Z.push(J)}return M(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return W(Q);Z.push(J)}return M(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]=lQ($);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($.slice())}writeBytes($){this.parts.push($.slice())}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,X)=>Q+X.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 d0={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 W(J);let[Q,X]=$.readDate();if(X!==0)return W(X);return M({id:Z,ts:Q})}};function hZ($){let Z=new L,J=Z.writeStruct(d0,$);if(J!==0)return W(J);let Q=Z.result();return M(Q)}var f$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let X=$.writeVarInt(Z.ctr);if(X!==0)return X;let Y=$.writeVarInt(Z.len);if(Y!==0)return Y;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return W(J);let Q=new f(Z),[,X]=d0.decode(Q);if(X!==0)return W(X);let[Y,G]=$.readVarInt();if(G!==0)return W(G);let[V,q]=$.readVarInt();if(q!==0)return W(q);let[N,z]=$.readVarInt();if(z!==0)return W(z);let P;if(N>0){let[O,R]=$.readBytes(vZ);if(R!==0)return W(R);P=O}return M({eid:Z,off:Y,ctr:V,len:N,hsh:P})}};function iZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function pZ($,Z,J,Q){let X;if($.bod&&$.len>0)X=await J.blake3($.bod);let Y=new L,G=f$.encode(Y,{...$,hsh:X});if(G!==0)return W(G);let V=Y.result(),q=await Z.kdmFor(V),N=Q.deriveCipher(q,"encrypt"),z=await N.encrypt(V),P=$.bod?await N.encrypt($.bod):new Uint8Array(0),O=await Z.sign(z);return M({sig:O,kdm:q,headCph:z,bodyCph:P})}async function uZ($,Z,J,Q,X){let Y=new f($),[G,V]=f$.decode(Y);if(V!==0)return W(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return W(20)}let N=G.hsh&&q===void 0,z=G.hsh===void 0&&q!==void 0;if(N||z)return W(19);if(G.hsh&&q){let O=await Q.blake3(q);if(!xZ(O,G.hsh))return W(19)}let P=X??await Q.blake3($);return M({msgHead:G,bod:q,headHash:P})}async function v$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return W(Q);let X=J.result(),Y=await $.sign(X);return M({pubKey:$.publicKey,sig:Y,timestamp:Z})}async function $0($,Z,J){let Q=J.now().getTime(),X=$.timestamp.getTime();if(Math.abs(Q-X)>yZ)return 4;let G=new L;G.writeDate($.timestamp);let V=G.result();if(!await Z.checkSigEd25519($.sig,V,$.pubKey))return 3;return 0}class g0{now(){return new Date}}function dZ($,Z,J,Q){let X=Z.getTime()-$.getTime(),Y=J.getTime()-Q.getTime();return(X+Y)/2}var n0={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 W(J);let Q;if(Z>0){let[X,Y]=$.readVarInt();if(Y!==0)return W(Y);Q=X}return M({quota:Z,usage:Q})}};var f0={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 X=$.writeVarInt(Z.subscription.term);if(X!==0)return X;let Y=$.writeVarInt(Z.subscription.elapsed);if(Y!==0)return Y;let G=$.writeStruct(n0,Z.subscription.stat);if(G!==0)return G;let V=$.writeStruct(n0,Z.subscription.dyn);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return W(J);let Q=Z[0],[X,Y]=$.readDate();if(Y!==0)return W(Y);let[G,V]=$.readDate();if(V!==0)return W(V);let[q,N]=$.readVarInt();if(N!==0)return W(N);let[z,P]=$.readVarInt();if(P!==0)return W(P);let[O,R]=$.readStruct(n0);if(R!==0)return W(R);let[H,F]=$.readStruct(n0);if(F!==0)return W(F);return M({status:Q,timeRcvd:X,timeSent:G,subscription:{term:q,elapsed:z,stat:O,dyn:H}})}};var y$={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 W(J);let[Q,X]=$.readVarInt();if(X!==0)return W(X);return M({headCph:Z,seq:Q})}};var r={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(fZ);if(J!==0)return W(J);let[Q,X]=$.readBytes(x0);if(X!==0)return W(X);let[Y,G]=$.readDate();if(G!==0)return W(G);return M({pubKey:Z,sig:Q,timestamp:Y})}};var nZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(r,J);if(Y!==0)return Y;for(let G of Q)X.writeVarInt(G);return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[G,V]=Z.readStruct(r);if(V!==0)return V;let q=await $0(G,X,Q);if(q!==0)return q;let{pubKey:N}=G,[z,P]=await Y.hasUser(N);if(P!==0)return P;if(!z)return 5;let[O,R]=Z.readVarInt();if(R!==0)return R;if(!Z.done())return 8;let[H,F]=await Y.listHeads(N,O);if(F!==0)return F;return J.writeStructs(y$,H)},decodeResp($){return $.readStructs(y$)}};var l$={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 W(J);let[Q,X]=$.readVarBytes();if(X!==0)return W(X);return M({seq:Z,bodyCph:Q})}};var cZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(r,J);if(Y!==0)return Y;for(let G of Q){let V=X.writeVarInt(G);if(V!==0)return V}return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[G,V]=Z.readStruct(r);if(V!==0)return V;let q=await $0(G,X,Q);if(q!==0)return q;let{pubKey:N}=G,[z,P]=await Y.hasUser(N);if(P!==0)return P;if(!z)return 5;let O=[];while(!Z.done()){let[F,U]=Z.readVarInt();if(U!==0)return U;O.push(F)}console.info(`PULL: ${O.length} bags`);let[R,H]=await Y.getBodies(N,O);if(H!==0)return H;if(!R)return 17;for(let{seq:F,bodyCph:U}of R){let C={seq:F,bodyCph:U},D=J.writeStruct(l$,C);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(l$)}};var b$={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(x0);if(J!==0)return W(J);let[Q,X]=$.readBytes(S0);if(X!==0)return W(X);let[Y,G]=$.readVarBytes();if(G!==0)return W(G);let[V,q]=$.readVarBytes();if(q!==0)return W(q);return M({sig:Z,kdm:Q,headCph:Y,bodyCph:V})}};var h$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let X=Z.bodyCph?Z.bodyCph.length:0,Y=$.writeVarInt(X);if(Y!==0)return Y;if(X>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return W(J);let[Q,X]=$.readVarBytes();if(X!==0)return W(X);let[Y,G]=$.readVarInt();if(G!==0)return W(G);let V;if(Y>0){let[q,N]=$.readBytes(Y);if(N!==0)return W(N);V=q}return M({seq:Z,headCph:Q,bodyCph:V})}};var v0={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(x0);if(J!==0)return W(J);let[Q,X]=$.readBytes(S0);if(X!==0)return W(X);let[Y,G]=$.readVarBytes();if(G!==0)return W(G);return M({sig:Z,kdm:Q,headCph:Y})}};var X$={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 W(J);let[Q,X]=$.readBytes(1);if(X!==0)return W(X);let Y=Q[0];if(Y!==0)return M({idx:Z,status:Y});let[G,V]=$.readVarInt();if(V!==0)return W(V);return M({idx:Z,status:Y,seq:G})}};var rZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(r,J);if(Y!==0)return Y;let G=X.writeStructs(b$,Q);if(G!==0)return G;return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y,notifier:G}=$,[V,q]=Z.readStruct(r);if(q!==0)return q;let N=await $0(V,X,Q);if(N!==0)return N;let{pubKey:z}=V,[P,O]=await Y.hasUser(z);if(O!==0)return O;if(!P)return 5;let[R,H]=Z.readStructs(b$);if(H!==0)return H;console.info(`PUSH: ${R.length} bags`);let F=[],U=[];for(let w=0;w<R.length;w++){let E=R[w];if(!await iZ(E,z,X)){let p={idx:w,status:3},_=J.writeStruct(X$,p);if(_!==0)return _;continue}F.push(w),U.push(E)}let[C,D]=await Y.setBags(z,U);if(D!==0)return D;if(!C||C.length!==U.length)return 17;let j=[];for(let w=0;w<U.length;w++){let E=U[w],x=F[w],p=C[w],_=new L,m=_.writeStruct(v0,E);if(m!==0)return m;let S=_.result(),K={seq:p,headCph:S};if(R.length===1&&E.bodyCph.length<=lZ)K.bodyCph=E.bodyCph;j.push(K);let g={idx:x,status:0,seq:p},B=J.writeStruct(X$,g);if(B!==0)return B}if(j.length>0){let w=new L,E=w.writeStructs(h$,j);if(E!==0)return E;let x=w.result();await Promise.resolve(G.push(z,x))}return 0},decodeResp($){return $.readStructs(X$)}};var oZ={async encodeReq($,Z,J,Q,X){return X.writeStruct(r,J)},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[G,V]=Z.readStruct(r);if(V!==0)return V;let q=await $0(G,X,Q);if(q!==0)return q;let{pubKey:N}=G;if(!Z.done())return 8;let[z,P]=await Y.addUser(N);if(P!==0)return P;return 0},decodeResp($){return M(void 0)}};class i${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:X}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let Y=new L;Y.writeStruct(r,$);let G=Y.result(),V=t(G);return X.searchParams.set("t",V),this.websocket=new WebSocket(X),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=(q)=>{let N=new Uint8Array(q.data);Z(N)},this.websocket.onerror=(q)=>{console.log(`ERROR: ${JSON.stringify(q)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var d={user:{path:"/user",endpoint:oZ,name:0},push:{path:"/push",endpoint:rZ,name:2},peek:{path:"/peek",endpoint:nZ,name:1},pull:{path:"/pull",endpoint:cZ,name:3}},hQ={0:d.user,2:d.push,1:d.peek,3:d.pull},aZ={[d.user.path]:d.user,[d.push.path]:d.push,[d.peek.path]:d.peek,[d.pull.path]:d.pull};class sZ{url;listener;constructor($){this.url=$;this.listener=new i$($)}async call($,Z){let{path:J}=hQ[$],Q=new URL(J,this.url);try{return await pQ(Q,Z)}catch{return W(25)}}}var p$=($)=>{return new sZ($.handle)};function y0($){let Z=new L;if(Z.writeStruct(f0,$)!==0)return new Response(null,{status:500});return u$(Z)}function u$($){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 d$($){return new Response($.body,{headers:{...$.headers,...iQ},status:$.status,statusText:$.statusText})}async function pQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return W(24);let Q=await f.fromResponse(J);return M(Q)}class Y${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,X,Y){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=X;this.updateHostMeta=Y}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:X,name:Y}=$,G=await this.identity(),V=J.now(),[q,N]=await v$(G,V);if(N!==0)return W(N);let z=new L,P=await X.encodeReq(this,G,q,Z,z);if(P!==0)return W(P);let O=J.now(),[R,H]=await Q.call(Y,z),F=J.now();if(H!==0)return W(H);let[U,C]=R.readStruct(f0);if(C!==0)return W(C);if(U.status!==0)return W(U.status);let j={clockOffset:dZ(O,U.timeRcvd,U.timeSent,F),subscription:U.subscription},w=await this.updateHostMeta(j);if(w!==0)return W(w);return X.decodeResp(R)}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 pZ($,Q,Z,J)};register=()=>this.call(d.user,[]);peek=($)=>this.call(d.peek,[$]);push=($)=>this.call(d.push,$);pull=($)=>this.call(d.pull,$);listen=async($,Z,J)=>{let{clock:Q,transport:X}=this,{listener:Y}=X,G=await this.identity(),V=Q.now(),[q,N]=await v$(G,V);if(N!==0)return N;return await Y.connect(q,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var jV=Symbol("MasterSeed"),LV=Symbol("SealedMasterKey"),X0=32,eZ=24+X0+16;function s($){if($.byteLength!==X0)return W(10);return M($)}function G$($){if($.byteLength!==eZ)return W(10);return M($)}var H0={encode($,Z){let J=$.writeVarString(Z.handle);if(J!==0)return J;let Q=$.writeVarString(Z.label);if(Q!==0)return Q;return $.writeVarInt(Z.idx??0)},decode($){let[Z,J]=$.readVarString();if(J!==0)return W(J);let[Q,X]=$.readVarString();if(X!==0)return W(X);let[Y,G]=$.readVarInt();if(G!==0)return W(G);return M({handle:Z,label:Q,idx:Y})}};var W$=1,n$={encode($,Z){if(Z.v!==W$)return 10;let[,J]=s(Z.masterSeed);if(J!==0)return J;let Q=$.writeVarInt(Z.v);if(Q!==0)return Q;$.writeBytes(Z.masterSeed);let X=$.writeVarInt(Z.hosts.length);if(X!==0)return X;for(let Y of Z.hosts){let G=$.writeStruct(H0,Y);if(G!==0)return G}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return W(J);if(Z!==W$)return W(14);let[Q,X]=$.readBytes(X0);if(X!==0)return W(X);if(Q===void 0)return W(14);let[Y,G]=s(Q);if(G!==0)return W(G);if(Y===void 0)return W(14);let[V,q]=$.readVarInt();if(q!==0)return W(q);if(V===void 0||V<0)return W(10);let N=[];for(let z=0;z<V;z++){let[P,O]=$.readStruct(H0);if(O!==0)return W(O);if(P===void 0)return W(14);N.push(P)}return M({v:W$,masterSeed:Y,hosts:N})}};function tZ($,Z){let[J,Q]=s($);if(Q!==0)return W(Q);if(J===void 0)return W(10);let[X,Y]=s(J.slice());if(Y!==0)return W(Y);if(X===void 0)return W(10);return M({v:W$,masterSeed:X,hosts:Z.map((G)=>({handle:G.handle,label:G.label,idx:G.idx??0}))})}var c$={encode($,Z){let[,J]=s(Z.masterSeed);if(J!==0)return J;$.writeBytes(Z.masterSeed);let Q=$.writeVarInt(Z.hosts.length);if(Q!==0)return Q;for(let X of Z.hosts){let Y=$.writeStruct(H0,X);if(Y!==0)return Y}return 0},decode($){let[Z,J]=$.readBytes(X0);if(J!==0)return W(J);if(Z===void 0)return W(14);let[Q,X]=s(Z);if(X!==0)return W(X);if(Q===void 0)return W(14);let[Y,G]=$.readVarInt();if(G!==0)return W(G);if(Y===void 0||Y<0)return W(10);let V=[];for(let q=0;q<Y;q++){let[N,z]=$.readStruct(H0);if(z!==0)return W(z);if(N===void 0)return W(14);V.push(N)}return M({masterSeed:Q,hosts:V})}};function z0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var F0=32,uQ=-7,dQ=-8,nQ=-257,V$=[{type:"public-key",alg:uQ},{type:"public-key",alg:dQ},{type:"public-key",alg:nQ}];function cQ($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function I0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z.buffer}function $J($){if($ instanceof ArrayBuffer)return new Uint8Array($).slice();return new Uint8Array($.buffer,$.byteOffset,$.byteLength).slice()}function U0($){if($?.rpId!==void 0)return M($.rpId);if(typeof location>"u")return W(9);return M(cQ(location.hostname))}function w0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function C0($){if($===null||$.type!=="public-key"||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return W(27);return M($)}async function ZJ($){let Z=w0();if(Z!==0)return W(Z);let[J,Q]=U0($);if(Q!==0)return W(Q);if(J===void 0)return W(9);let X=$?.userName??"diplomatic-seed",Y={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)Y.authenticatorAttachment=$.authenticatorAttachment;let G={largeBlob:{support:"required"}},V;try{V=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:X,displayName:X},pubKeyCredParams:V$,authenticatorSelection:Y,extensions:G}})}catch{return W(24)}let[q,N]=C0(V);if(N!==0)return W(N);if(q===void 0)return W(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return W(24);return M(new Uint8Array(q.rawId))}async function r$($,Z,J){let Q=w0();if(Q!==0)return Q;let[X,Y]=U0(J);if(Y!==0)return Y;if(X===void 0)return 9;let G={largeBlob:{write:I0(Z)}},V;try{V=await navigator.credentials.get({publicKey:{challenge:z0(F0),rpId:X,allowCredentials:[{type:"public-key",id:I0($)}],userVerification:"required",extensions:G}})}catch{return 24}let[q,N]=C0(V);if(N!==0)return N;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 24;return 0}async function JJ($,Z){let J=w0();if(J!==0)return W(J);let[Q,X]=U0(Z);if(X!==0)return W(X);if(Q===void 0)return W(9);let Y={largeBlob:{read:!0}},G;try{let O={challenge:z0(F0),rpId:Q,userVerification:"required",extensions:Y};if($!==void 0)O.allowCredentials=[{type:"public-key",id:I0($)}];G=await navigator.credentials.get({publicKey:O})}catch{return W(24)}let[V,q]=C0(G);if(q!==0)return W(q);if(V===void 0)return W(27);let z=V.getClientExtensionResults().largeBlob;if(z===void 0||z.blob===void 0)return W(7);let P=$J(z.blob);if(P.byteLength===0)return W(7);return M({blob:P,credId:new Uint8Array(V.rawId)})}var q$=new TextEncoder().encode("diplomatic.prf.v1"),o$=32;async function QJ($){let Z=w0();if(Z!==0)return W(Z);let[J,Q]=U0($);if(Q!==0)return W(Q);if(J===void 0)return W(9);let X=$?.userName??"diplomatic-prf",Y={residentKey:"required",requireResidentKey:!0,userVerification:"required",authenticatorAttachment:$?.authenticatorAttachment??"platform"},G;try{G=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:X,displayName:X},pubKeyCredParams:V$,authenticatorSelection:Y,extensions:{prf:{}}}})}catch{return W(24)}let[V,q]=C0(G);if(q!==0)return W(q);if(V===void 0)return W(27);let N=V.getClientExtensionResults();return M({credId:new Uint8Array(V.rawId),prfEnabled:N.prf?.enabled===!0})}async function c0($){let Z=w0();if(Z!==0)return W(Z);let[J,Q]=U0($);if(Q!==0)return W(Q);if(J===void 0)return W(9);let X=$?.salt??q$,Y=I0(X),G={challenge:z0(F0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:Y}}}};if($?.credId!==void 0)G.allowCredentials=[{type:"public-key",id:I0($.credId)}];let V;try{V=await navigator.credentials.get({publicKey:G})}catch{return W(24)}let[q,N]=C0(V);if(N!==0)return W(N);if(q===void 0)return W(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return W(7);let P=z.first,O=P instanceof ArrayBuffer?new Uint8Array(P):new Uint8Array(P.buffer,P.byteOffset,P.byteLength),R=O.byteLength>=o$?O.slice(0,o$):O;if(R.byteLength!==o$)return W(27);return M({prf:R,credId:new Uint8Array(q.rawId)})}var N$="";var P$=typeof globalThis.Worker==="function"?globalThis.Worker:void 0,a$=P$===void 0?void 0:P$.prototype.postMessage,z$;function oQ(){if(typeof N$!=="string"||N$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(N$)}function aQ(){if(z$!==void 0)return z$;let $=new Blob([oQ()],{type:"text/javascript"});return z$=URL.createObjectURL($),z$}function XJ(){if(P$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new P$(aQ(),{type:"module"})}function YJ($,Z,J){if(a$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot post to sync worker");if(J!==void 0&&J.length>0)a$.call($,Z,{transfer:J});else a$.call($,Z)}var sQ=new TextEncoder().encode("diplomatic.wrap.v1"),GJ=new TextEncoder().encode("diplomatic.pair.v1"),eQ=32,tQ=16;class Z0{#Z;#$;constructor($,Z){this.#Z=$,this.#$=Z}static async fromRandom($){let Z=await $.gen256BitSecureRandomSeed(),[J,Q]=s(Z);if(Q!==0||J===void 0)throw Error(`enclave: invalid random seed (${Q})`);return new Z0(J,$)}static fromBytes($,Z){let[J,Q]=s(Z);if(Q!==0)return W(Q);if(J===void 0)return W(10);let[X,Y]=s(J.slice());if(Y!==0)return W(Y);if(X===void 0)return W(10);return M(new Z0(X,$))}async sealWithPasskey($){let Z=$?.salt??q$,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[Y,G]=await QJ({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf"});if(G!==0)return W(G);if(Y===void 0)return W(24);if(!Y.prfEnabled)return W(24);J=Y.credId}let[Q,X]=await c0({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await this.#X(Q.prf);if(G!==0)return W(G);if(Y===void 0)return W(12);return M({sealedMaster:Y,salt:Z.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async unsealWithPasskey($,Z,J){let[Q,X]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await Z0.#Y($,Z,Q.prf);if(G!==0)return W(G);if(Y===void 0)return W(12);return M({enclave:Y,credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[Y,G]=await ZJ(Z);if(G!==0)return W(G);if(Y===void 0)return W(24);J=Y}let[Q,X]=this.#G($);if(X!==0)return W(X);if(Q===void 0)return W(12);try{let Y=await r$(J,Q,Z);if(Y!==0)return W(Y);return M(J)}finally{Q.fill(0)}}static async fromLargeBlob($,Z){let[J,Q]=await JJ(Z?.credId,Z);if(Q!==0)return W(Q);if(J===void 0)return W(7);try{return Z0.#W($,J.blob,J.credId)}finally{J.blob.fill(0)}}static async clearLargeBlob($,Z){return r$($,new Uint8Array(X0),Z)}async sealPairPackageBody($,Z){let J=Z?.salt??q$,[Q,X]=await c0({rpId:Z?.rpId,rpName:Z?.rpName,credId:Z?.credId,salt:J});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await M$(this.#$,Q.prf,GJ);if(G!==0)return W(G);if(Y===void 0)return W(12);try{let[V,q]=s(this.#Z.slice());if(q!==0)return W(q);if(V===void 0)return W(10);let N={masterSeed:V,hosts:$.map((H)=>({handle:H.handle,label:H.label,idx:H.idx??0}))},z=new L,P=z.writeStruct(c$,N);if(P!==0)return V.fill(0),W(P);let O=z.result();V.fill(0);let R;try{R=await this.#$.encryptXSalsa20Poly1305Combined(O,Y)}catch{return O.fill(0),W(12)}return O.fill(0),M({body:R,salt:J.slice(),credId:Q.credId.slice()})}finally{Y.fill(0)}}finally{Q.prf.fill(0)}}static async openPairPackageBody($,Z,J){let[Q,X]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(X!==0)return W(X);if(Q===void 0)return W(7);try{let[Y,G]=await M$($,Q.prf,GJ);if(G!==0)return W(G);if(Y===void 0)return W(12);try{let V;try{V=await $.decryptXSalsa20Poly1305Combined(Z,Y)}catch{return W(20)}let q=new f(V),[N,z]=q.readStruct(c$);if(V.fill(0),z!==0)return W(z);if(N===void 0)return W(14);let[P,O]=Z0.fromBytes($,N.masterSeed);if(N.masterSeed.fill(0),O!==0)return W(O);if(P===void 0)return W(12);let[R,H]=await P.#X(Q.prf);if(H!==0)return W(H);if(R===void 0)return W(12);return M({enclave:P,hosts:N.hosts.map((F)=>({...F})),sealedMaster:R,credId:Q.credId.slice()})}finally{Y.fill(0)}}finally{Q.prf.fill(0)}}spawnSyncWorker($){let Z=XJ(),J=this.#Z.slice();return YJ(Z,{id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(G)=>this.#V(J,G),X=(G)=>this.#q(J,G);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:X}),both:Object.freeze({encrypt:Q,decrypt:X})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,X=await this.#Q(J,Q),Y=X.publicKey;return X.privateKey.fill(0),Object.freeze({publicKey:Y,sign:(G)=>this.#z(J,Q,G),kdmFor:(G)=>this.#P(J,Q,G)})}async#X($){let[Z,J]=await M$(this.#$,$);if(J!==0)return W(J);if(Z===void 0)return W(12);try{let Q=await this.#$.encryptXSalsa20Poly1305Combined(this.#Z,Z);return G$(Q)}catch{return W(12)}finally{Z.fill(0)}}static async#Y($,Z,J){let[,Q]=G$(Z);if(Q!==0)return W(Q);let[X,Y]=await M$($,J);if(Y!==0)return W(Y);if(X===void 0)return W(12);let G;try{try{G=await $.decryptXSalsa20Poly1305Combined(Z,X)}catch{return W(20)}return Z0.fromBytes($,G)}finally{X.fill(0),G?.fill(0)}}#G($){let[Z,J]=s(this.#Z.slice());if(J!==0)return W(J);if(Z===void 0)return W(10);let[Q,X]=tZ(Z,$);if(Z.fill(0),X!==0)return W(X);if(Q===void 0)return W(12);try{let Y=new L,G=Y.writeStruct(n$,Q);if(G!==0)return W(G);return M(Y.result())}finally{Q.masterSeed.fill(0)}}static#W($,Z,J){if(Z.byteLength===0||Z.every((G)=>G===0))return W(22);if(Z.byteLength===X0){if(Z.every((q)=>q===0))return W(22);let[G,V]=Z0.fromBytes($,Z);if(V!==0)return W(V);if(G===void 0)return W(12);return M({enclave:G,hosts:[],credId:J})}let Q=new f(Z),[X,Y]=Q.readStruct(n$);if(Y!==0)return W(Y);if(X===void 0)return W(14);try{if(X.masterSeed.every((q)=>q===0))return W(22);let[G,V]=Z0.fromBytes($,X.masterSeed);if(V!==0)return W(V);if(G===void 0)return W(12);return M({enclave:G,hosts:X.hosts.map((q)=>({...q})),credId:J})}finally{X.masterSeed.fill(0)}}async#V($,Z){let J=await this.#J($);try{return await this.#$.encryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#q($,Z){let J=await this.#J($);try{return await this.#$.decryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#J($){return this.#$.blake3(u0(this.#Z,$))}async#N($,Z){let J=new TextEncoder().encode($),Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,BigInt(Z),!1),await this.#J(u0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);try{return await this.#$.deriveEd25519KeyPair(J)}finally{J.fill(0)}}async#z($,Z,J){let Q=await this.#Q($,Z);try{return await this.#$.signEd25519(J,Q.privateKey)}finally{Q.privateKey.fill(0)}}async#P($,Z,J){let Q=await this.#Q($,Z),X=u0(Q.privateKey,J);Q.privateKey.fill(0);try{return(await this.#$.blake3(X)).slice(0,S0)}finally{X.fill(0)}}}async function M$($,Z,J=sQ){if(Z.byteLength<tQ)return W(10);let Q=await $.blake3(u0(Z,J));return M(Q.slice(0,eQ))}class s${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 X of Q)X(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function WJ($,Z,J,Q=0){let X=Z.now(),Y=new L,G=Y.writeVarString($);if(G!==0)return W(G);let q={id:Y.result(),ts:new Date(0)},[N,z]=hZ(q);if(z!==0)return W(z);let P=X.getTime()-q.ts.getTime();return M({eid:N,off:P,ctr:Q,len:J.length,bod:J})}class $X{singletonType;latest;latestOff=-1;emitter=new s$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new f(Z.eid),[Q,X]=J.readStruct(d0);if(X!==0)continue;let Y=new L;Y.writeVarString(this.singletonType);let G=Y.result();if(Q.id.length===G.length&&Q.id.every((V,q)=>V===G[q])){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 VJ($,Z,J,Q){let X=new f($.headCph),[Y,G]=X.readStruct(v0);if(G!==0)return W(G);let{sig:V,kdm:q,headCph:N}=Y;if(!await Q.checkSigEd25519(V,N,Z))return W(3);let P=J.deriveCipher(q,"decrypt"),O;try{O=await P.decrypt(N)}catch{return W(20)}return M({kdm:q,headEnc:O})}var b0=CQ(qQ(),1),IY={encode:b0.encode,decode:b0.decode,decodeAsync:b0.decodeAsync},UY=IY;import{Database as wY}from"bun:sqlite";var z8=Symbol("EntityID");var P8=Symbol("DerivationSeed"),M8=Symbol("PublicKey"),O8=Symbol("PrivateKey"),K8=Symbol("HostSpecificKeyPair"),R8=Symbol("Hash"),M0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function CY($="diplomatic.db"){let Z=new wY($);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
  );