@interncom/diplomatic 0.12.2 → 0.12.4

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 NQ=Object.create;var{getPrototypeOf:zQ,defineProperty:NZ,getOwnPropertyNames:IQ}=Object;var MQ=Object.prototype.hasOwnProperty;function PQ($){return this[$]}var RQ,OQ,KQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var V=Z?RQ??=new WeakMap:OQ??=new WeakMap,X=V.get($);if(X)return X}J=$!=null?NQ(zQ($)):{};let Y=Z||!$||!$.__esModule?NZ(J,"default",{value:$,enumerable:!0}):J;for(let W of IQ($))if(!MQ.call(Y,W))NZ(Y,W,{get:PQ.bind($,W),enumerable:!0});if(Q)V.set($,Y);return Y};var c=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var M$=c((WJ)=>{Object.defineProperty(WJ,"__esModule",{value:!0});WJ.utf8Count=aQ;WJ.utf8EncodeJs=VJ;WJ.utf8EncodeTE=XJ;WJ.utf8Encode=eQ;WJ.utf8DecodeJs=YJ;WJ.utf8DecodeTD=GJ;WJ.utf8Decode=QV;function aQ($){let Z=$.length,J=0,Q=0;while(Q<Z){let V=$.charCodeAt(Q++);if((V&4294967168)===0){J++;continue}else if((V&4294965248)===0)J+=2;else{if(V>=55296&&V<=56319){if(Q<Z){let X=$.charCodeAt(Q);if((X&64512)===56320)++Q,V=((V&1023)<<10)+(X&1023)+65536}}if((V&4294901760)===0)J+=3;else J+=4}}return J}function VJ($,Z,J){let Q=$.length,V=J,X=0;while(X<Q){let Y=$.charCodeAt(X++);if((Y&4294967168)===0){Z[V++]=Y;continue}else if((Y&4294965248)===0)Z[V++]=Y>>6&31|192;else{if(Y>=55296&&Y<=56319){if(X<Q){let W=$.charCodeAt(X);if((W&64512)===56320)++X,Y=((Y&1023)<<10)+(W&1023)+65536}}if((Y&4294901760)===0)Z[V++]=Y>>12&15|224,Z[V++]=Y>>6&63|128;else Z[V++]=Y>>18&7|240,Z[V++]=Y>>12&63|128,Z[V++]=Y>>6&63|128}Z[V++]=Y&63|128}}var sQ=new TextEncoder,tQ=50;function XJ($,Z,J){sQ.encodeInto($,Z.subarray(J))}function eQ($,Z,J){if($.length>tQ)XJ($,Z,J);else VJ($,Z,J)}var $V=4096;function YJ($,Z,J){let Q=Z,V=Q+J,X=[],Y="";while(Q<V){let W=$[Q++];if((W&128)===0)X.push(W);else if((W&224)===192){let q=$[Q++]&63;X.push((W&31)<<6|q)}else if((W&240)===224){let q=$[Q++]&63,N=$[Q++]&63;X.push((W&31)<<12|q<<6|N)}else if((W&248)===240){let q=$[Q++]&63,N=$[Q++]&63,z=$[Q++]&63,I=(W&7)<<18|q<<12|N<<6|z;if(I>65535)I-=65536,X.push(I>>>10&1023|55296),I=56320|I&1023;X.push(I)}else X.push(W);if(X.length>=$V)Y+=String.fromCharCode(...X),X.length=0}if(X.length>0)Y+=String.fromCharCode(...X);return Y}var ZV=new TextDecoder,JV=200;function GJ($,Z,J){let Q=$.subarray(Z,Z+J);return ZV.decode(Q)}function QV($,Z,J){if(J>JV)return GJ($,Z,J);else return YJ($,Z,J)}});var a$=c((NJ)=>{Object.defineProperty(NJ,"__esModule",{value:!0});NJ.ExtData=void 0;class qJ{type;data;constructor($,Z){this.type=$,this.data=Z}}NJ.ExtData=qJ});var R$=c((IJ)=>{Object.defineProperty(IJ,"__esModule",{value:!0});IJ.DecodeError=void 0;class P$ extends Error{constructor($){super($);let Z=Object.create(P$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:P$.name})}}IJ.DecodeError=P$});var O$=c((PJ)=>{Object.defineProperty(PJ,"__esModule",{value:!0});PJ.UINT32_MAX=void 0;PJ.setUint64=zV;PJ.setInt64=IV;PJ.getInt64=MV;PJ.getUint64=PV;PJ.UINT32_MAX=4294967295;function zV($,Z,J){let Q=J/4294967296,V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function IV($,Z,J){let Q=Math.floor(J/4294967296),V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function MV($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function PV($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var s$=c((TJ)=>{Object.defineProperty(TJ,"__esModule",{value:!0});TJ.timestampExtension=TJ.EXT_TIMESTAMP=void 0;TJ.encodeTimeSpecToTimestamp=KJ;TJ.encodeDateToTimeSpec=FJ;TJ.encodeTimestampExtension=HJ;TJ.decodeTimestampToTimeSpec=UJ;TJ.decodeTimestampExtension=wJ;var HV=R$(),OJ=O$();TJ.EXT_TIMESTAMP=-1;var UV=4294967295,wV=17179869183;function KJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=wV)if(Z===0&&$<=UV){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,V=new Uint8Array(8),X=new DataView(V.buffer);return X.setUint32(0,Z<<2|J&3),X.setUint32(4,Q),V}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,OJ.setInt64)(Q,4,$),J}}function FJ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,V=Math.floor(Q/1e9);return{sec:J+V,nsec:Q-V*1e9}}function HJ($){if($ instanceof Date){let Z=FJ($);return KJ(Z)}else return null}function UJ($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let J=Z.getUint32(0),Q=0;return{sec:J,nsec:0}}case 8:{let J=Z.getUint32(0),Q=Z.getUint32(4),V=(J&3)*4294967296+Q,X=J>>>2;return{sec:V,nsec:X}}case 12:{let J=(0,OJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new HV.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function wJ($){let Z=UJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}TJ.timestampExtension={type:TJ.EXT_TIMESTAMP,encode:HJ,decode:wJ}});var F$=c((AJ)=>{Object.defineProperty(AJ,"__esModule",{value:!0});AJ.ExtensionCodec=void 0;var K$=a$(),LV=s$();class t${static defaultCodec=new t$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(LV.timestampExtension)}register({type:$,encode:Z,decode:J}){if($>=0)this.encoders[$]=Z,this.decoders[$]=J;else{let Q=-1-$;this.builtInEncoders[Q]=Z,this.builtInDecoders[Q]=J}}tryToEncode($,Z){for(let J=0;J<this.builtInEncoders.length;J++){let Q=this.builtInEncoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let X=-1-J;return new K$.ExtData(X,V)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let X=J;return new K$.ExtData(X,V)}}}if($ instanceof K$.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 K$.ExtData(Z,$)}}AJ.ExtensionCodec=t$});var e$=c((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.ensureUint8Array=SV;function EV($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function SV($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(EV($))return new Uint8Array($);else return Uint8Array.from($)}});var ZZ=c((kJ)=>{Object.defineProperty(kJ,"__esModule",{value:!0});kJ.Encoder=kJ.DEFAULT_INITIAL_BUFFER_SIZE=kJ.DEFAULT_MAX_DEPTH=void 0;var EJ=M$(),mV=F$(),SJ=O$(),_V=e$();kJ.DEFAULT_MAX_DEPTH=100;kJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class $Z{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??mV.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??kJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??kJ.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 $Z({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,EJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,EJ.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,_V.ensureUint8Array)($);this.writeU8a(J)}encodeArray($,Z){let J=$.length;if(J<16)this.writeU8(144+J);else if(J<65536)this.writeU8(220),this.writeU16(J);else if(J<4294967296)this.writeU8(221),this.writeU32(J);else throw Error(`Too large array: ${J}`);for(let Q of $)this.doEncode(Q,Z+1)}countWithoutUndefined($,Z){let J=0;for(let Q of Z)if($[Q]!==void 0)J++;return J}encodeMap($,Z){let J=Object.keys($);if(this.sortKeys)J.sort();let Q=this.ignoreUndefined?this.countWithoutUndefined($,J):J.length;if(Q<16)this.writeU8(128+Q);else if(Q<65536)this.writeU8(222),this.writeU16(Q);else if(Q<4294967296)this.writeU8(223),this.writeU32(Q);else throw Error(`Too large map object: ${Q}`);for(let V of J){let X=$[V];if(!(this.ignoreUndefined&&X===void 0))this.encodeString(V),this.doEncode(X,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}}kJ.Encoder=$Z});var xJ=c((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.encode=gV;var BV=ZZ();function gV($,Z){return new BV.Encoder(Z).encodeSharedRef($)}});var vJ=c((fJ)=>{Object.defineProperty(fJ,"__esModule",{value:!0});fJ.prettyByte=fV;function fV($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var bJ=c((iJ)=>{Object.defineProperty(iJ,"__esModule",{value:!0});iJ.CachedKeyDecoder=void 0;var yV=M$(),iV=16,lV=16;class yJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=iV,Z=lV){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let J=0;J<this.maxKeyLength;J++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,J){let Q=this.caches[J-1];$:for(let V of Q){let X=V.bytes;for(let Y=0;Y<J;Y++)if(X[Y]!==$[Z+Y])continue $;return V.str}return null}store($,Z){let J=this.caches[$.length-1],Q={bytes:$,str:Z};if(J.length>=this.maxLengthPerKey)J[Math.random()*J.length|0]=Q;else J.push(Q)}decode($,Z,J){let Q=this.find($,Z,J);if(Q!=null)return this.hit++,Q;this.miss++;let V=(0,yV.utf8DecodeJs)($,Z,J),X=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(X,V),V}}iJ.CachedKeyDecoder=yJ});var H$=c((nJ)=>{Object.defineProperty(nJ,"__esModule",{value:!0});nJ.Decoder=void 0;var JZ=vJ(),bV=F$(),C0=O$(),uV=M$(),uJ=e$(),hV=bJ(),I0=R$(),QZ="array",o0="map_key",pJ="map_value",pV=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new I0.DecodeError("The type of key must be string or number but "+typeof $)};class dJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=QZ,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===QZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===o0||$.type===pJ){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,VZ=new DataView(new ArrayBuffer(0)),dV=new Uint8Array(VZ.buffer);try{VZ.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 hJ=RangeError("Insufficient data"),nV=new hV.CachedKeyDecoder;class XZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=VZ;bytes=dV;headByte=r0;stack=new dJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??bV.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??C0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??C0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??C0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??C0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??C0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:nV,this.mapKeyConverter=$?.mapKeyConverter??pV}clone(){return new XZ({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,uJ.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,uJ.ensureUint8Array)($),Q=new Uint8Array(Z.length+J.length);Q.set(Z),Q.set(J,Z.length),this.setBuffer(Q)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,J;for await(let Y of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(Y);try{J=this.doDecodeSync(),Z=!0}catch(W){if(!(W instanceof RangeError))throw W}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:Q,pos:V,totalPos:X}=this;throw RangeError(`Insufficient data in parsing ${(0,JZ.prettyByte)(Q)} at ${X} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let J=Z,Q=-1;for await(let V of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(X){if(!(X instanceof RangeError))throw X}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 I0.DecodeError(`Unrecognized type byte: ${(0,JZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===QZ)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 I0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=pJ;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 I0.DecodeError(`Unrecognized array type byte: ${(0,JZ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new I0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new I0.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 I0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw hJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,uV.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 I0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw hJ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new I0.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,C0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,C0.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,$}}nJ.Decoder=XZ});var aJ=c((oJ)=>{Object.defineProperty(oJ,"__esModule",{value:!0});oJ.decode=cV;oJ.decodeMulti=rV;var rJ=H$();function cV($,Z){return new rJ.Decoder(Z).decode($)}function rV($,Z){return new rJ.Decoder(Z).decodeMulti($)}});var $Q=c((eJ)=>{Object.defineProperty(eJ,"__esModule",{value:!0});eJ.isAsyncIterable=sJ;eJ.asyncIterableFromStream=tJ;eJ.ensureAsyncIterable=sV;function sJ($){return $[Symbol.asyncIterator]!=null}async function*tJ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function sV($){if(sJ($))return $;else return tJ($)}});var JQ=c((ZQ)=>{Object.defineProperty(ZQ,"__esModule",{value:!0});ZQ.decodeAsync=ZX;ZQ.decodeArrayStream=JX;ZQ.decodeMultiStream=QX;var YZ=H$(),GZ=$Q();async function ZX($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new YZ.Decoder(Z).decodeAsync(J)}function JX($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new YZ.Decoder(Z).decodeArrayStream(J)}function QX($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new YZ.Decoder(Z).decodeStream(J)}});var VQ=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 GX=xJ();Object.defineProperty(v,"encode",{enumerable:!0,get:function(){return GX.encode}});var QQ=aJ();Object.defineProperty(v,"decode",{enumerable:!0,get:function(){return QQ.decode}});Object.defineProperty(v,"decodeMulti",{enumerable:!0,get:function(){return QQ.decodeMulti}});var WZ=JQ();Object.defineProperty(v,"decodeAsync",{enumerable:!0,get:function(){return WZ.decodeAsync}});Object.defineProperty(v,"decodeArrayStream",{enumerable:!0,get:function(){return WZ.decodeArrayStream}});Object.defineProperty(v,"decodeMultiStream",{enumerable:!0,get:function(){return WZ.decodeMultiStream}});var WX=H$();Object.defineProperty(v,"Decoder",{enumerable:!0,get:function(){return WX.Decoder}});var qX=R$();Object.defineProperty(v,"DecodeError",{enumerable:!0,get:function(){return qX.DecodeError}});var NX=ZZ();Object.defineProperty(v,"Encoder",{enumerable:!0,get:function(){return NX.Encoder}});var zX=F$();Object.defineProperty(v,"ExtensionCodec",{enumerable:!0,get:function(){return zX.ExtensionCodec}});var IX=a$();Object.defineProperty(v,"ExtData",{enumerable:!0,get:function(){return IX.ExtData}});var i0=s$();Object.defineProperty(v,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return i0.EXT_TIMESTAMP}});Object.defineProperty(v,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return i0.encodeDateToTimeSpec}});Object.defineProperty(v,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return i0.encodeTimeSpecToTimestamp}});Object.defineProperty(v,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return i0.decodeTimestampToTimeSpec}});Object.defineProperty(v,"encodeTimestampExtension",{enumerable:!0,get:function(){return i0.encodeTimestampExtension}});Object.defineProperty(v,"decodeTimestampExtension",{enumerable:!0,get:function(){return i0.decodeTimestampExtension}})});import*as Y0 from"node:crypto";var P0=Y0&&typeof Y0==="object"&&"webcrypto"in Y0?Y0.webcrypto:Y0&&typeof Y0==="object"&&("randomBytes"in Y0)?Y0:void 0;function a0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function U$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function u($,...Z){if(!U$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function w$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function zZ($,Z){u($);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 G0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var FQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!FQ)throw Error("Non little-endian hardware is not supported");function HQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function s0($){if(typeof $==="string")$=HQ($);else if(U$($))$=t0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function IZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function MZ($,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 PZ=($,Z)=>{function J(Q,...V){if(u(Q),$.nonceLength!==void 0){let z=V[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)u(z);else u(z,$.nonceLength)}let X=$.tagLength;if(X&&V[1]!==void 0)u(V[1]);let Y=Z(Q,...V),W=(z,I)=>{if(I!==void 0){if(z!==2)throw Error("cipher output not supported");u(I)}},q=!1;return{encrypt(z,I){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,u(z),W(Y.encrypt.length,I),Y.encrypt(z,I)},decrypt(z,I){if(u(z),X&&z.length<X)throw Error("invalid ciphertext length: smaller than tagLength="+X);return W(Y.decrypt.length,I),Y.decrypt(z,I)}}}return Object.assign(J,$),J};function C$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!UQ(Z))throw Error("invalid output, must be aligned");return Z}function UQ($){return $.byteOffset%4===0}function t0($){return Uint8Array.from($)}function J0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function e0($=32){if(P0&&typeof P0.getRandomValues==="function")return P0.getRandomValues(new Uint8Array($));if(P0&&typeof P0.randomBytes==="function")return P0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var OZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),wQ=OZ("expand 16-byte k"),TQ=OZ("expand 32-byte k"),CQ=G0(wQ),DQ=G0(TQ);function H($,Z){return $<<Z|$>>>32-Z}function D$($){return $.byteOffset%4===0}var $$=64,AQ=16,KZ=4294967295,RZ=new Uint32Array;function jQ($,Z,J,Q,V,X,Y,W){let q=V.length,N=new Uint8Array($$),z=G0(N),I=D$(V)&&D$(X),P=I?G0(V):RZ,O=I?G0(X):RZ;for(let K=0;K<q;Y++){if($(Z,J,Q,z,Y,W),Y>=KZ)throw Error("arx: counter overflow");let F=Math.min($$,q-K);if(I&&F===$$){let U=K/4;if(K%4!==0)throw Error("arx: invalid block position");for(let T=0,D;T<AQ;T++)D=U+T,O[D]=P[D]^z[T];K+=$$;continue}for(let U=0,T;U<F;U++)T=K+U,X[T]=V[T]^N[U];K+=F}}function FZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:V,counterRight:X,rounds:Y}=IZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return a0(V),a0(Y),T$(X),T$(J),(W,q,N,z,I=0)=>{u(W),u(q),u(N);let P=N.length;if(z===void 0)z=new Uint8Array(P);if(u(z),a0(I),I<0||I>=KZ)throw Error("arx: counter overflow");if(z.length<P)throw Error(`arx: output (${z.length}) is shorter than data (${P})`);let O=[],K=W.length,F,U;if(K===32)O.push(F=t0(W)),U=DQ;else if(K===16&&J)F=new Uint8Array(32),F.set(W),F.set(W,16),U=CQ,O.push(F);else throw Error(`arx: invalid 32-byte key, got length=${K}`);if(!D$(q))O.push(q=t0(q));let T=G0(F);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(U,T,G0(q.subarray(0,16)),T),q=q.subarray(16)}let D=16-V;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,X?0:12-q.length),q=w,O.push(q)}let j=G0(q);return jQ($,U,T,j,N,z,I,Y),J0(...O),z}}var p=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class HZ{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($),u($,32);let Z=p($,0),J=p($,2),Q=p($,4),V=p($,6),X=p($,8),Y=p($,10),W=p($,12),q=p($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|Q<<6)&7939,this.r[3]=(Q>>>7|V<<9)&8191,this.r[4]=(V>>>4|X<<12)&255,this.r[5]=X>>>1&8190,this.r[6]=(X>>>14|Y<<2)&8191,this.r[7]=(Y>>>11|W<<5)&8065,this.r[8]=(W>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let N=0;N<8;N++)this.pad[N]=p($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:V,r:X}=this,Y=X[0],W=X[1],q=X[2],N=X[3],z=X[4],I=X[5],P=X[6],O=X[7],K=X[8],F=X[9],U=p($,Z+0),T=p($,Z+2),D=p($,Z+4),j=p($,Z+6),w=p($,Z+8),E=p($,Z+10),B=p($,Z+12),h=p($,Z+14),S=V[0]+(U&8191),m=V[1]+((U>>>13|T<<3)&8191),g=V[2]+((T>>>10|D<<6)&8191),R=V[3]+((D>>>7|j<<9)&8191),x=V[4]+((j>>>4|w<<12)&8191),_=V[5]+(w>>>1&8191),y=V[6]+((w>>>14|E<<2)&8191),i=V[7]+((E>>>11|B<<5)&8191),l=V[8]+((B>>>8|h<<8)&8191),b=V[9]+(h>>>5|Q),C=0,n=C+S*Y+m*(5*F)+g*(5*K)+R*(5*O)+x*(5*P);C=n>>>13,n&=8191,n+=_*(5*I)+y*(5*z)+i*(5*N)+l*(5*q)+b*(5*W),C+=n>>>13,n&=8191;let a=C+S*W+m*Y+g*(5*F)+R*(5*K)+x*(5*O);C=a>>>13,a&=8191,a+=_*(5*P)+y*(5*I)+i*(5*z)+l*(5*N)+b*(5*q),C+=a>>>13,a&=8191;let e=C+S*q+m*W+g*Y+R*(5*F)+x*(5*K);C=e>>>13,e&=8191,e+=_*(5*O)+y*(5*P)+i*(5*I)+l*(5*z)+b*(5*N),C+=e>>>13,e&=8191;let k=C+S*N+m*q+g*W+R*Y+x*(5*F);C=k>>>13,k&=8191,k+=_*(5*K)+y*(5*O)+i*(5*P)+l*(5*I)+b*(5*z),C+=k>>>13,k&=8191;let X0=C+S*z+m*N+g*q+R*W+x*Y;C=X0>>>13,X0&=8191,X0+=_*(5*F)+y*(5*K)+i*(5*O)+l*(5*P)+b*(5*I),C+=X0>>>13,X0&=8191;let D0=C+S*I+m*z+g*N+R*q+x*W;C=D0>>>13,D0&=8191,D0+=_*Y+y*(5*F)+i*(5*K)+l*(5*O)+b*(5*P),C+=D0>>>13,D0&=8191;let A0=C+S*P+m*I+g*z+R*N+x*q;C=A0>>>13,A0&=8191,A0+=_*W+y*Y+i*(5*F)+l*(5*K)+b*(5*O),C+=A0>>>13,A0&=8191;let j0=C+S*O+m*P+g*I+R*z+x*N;C=j0>>>13,j0&=8191,j0+=_*q+y*W+i*Y+l*(5*F)+b*(5*K),C+=j0>>>13,j0&=8191;let L0=C+S*K+m*O+g*P+R*I+x*z;C=L0>>>13,L0&=8191,L0+=_*N+y*q+i*W+l*Y+b*(5*F),C+=L0>>>13,L0&=8191;let E0=C+S*F+m*K+g*O+R*P+x*I;C=E0>>>13,E0&=8191,E0+=_*z+y*N+i*q+l*W+b*Y,C+=E0>>>13,E0&=8191,C=(C<<2)+C|0,C=C+n|0,n=C&8191,C=C>>>13,a+=C,V[0]=n,V[1]=a,V[2]=e,V[3]=k,V[4]=X0,V[5]=D0,V[6]=A0,V[7]=j0,V[8]=L0,V[9]=E0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let Y=2;Y<10;Y++)$[Y]+=Q,Q=$[Y]>>>13,$[Y]&=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 Y=1;Y<10;Y++)J[Y]=$[Y]+Q,Q=J[Y]>>>13,J[Y]&=8191;J[9]-=8192;let V=(Q^1)-1;for(let Y=0;Y<10;Y++)J[Y]&=V;V=~V;for(let Y=0;Y<10;Y++)$[Y]=$[Y]&V|J[Y];$[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 X=$[0]+Z[0];$[0]=X&65535;for(let Y=1;Y<8;Y++)X=($[Y]+Z[Y]|0)+(X>>>16)|0,$[Y]=X&65535;J0(J)}update($){w$(this);let{buffer:Z,blockLen:J}=this;$=s0($);let Q=$.length;for(let V=0;V<Q;){let X=Math.min(J-this.pos,Q-V);if(X===J){for(;J<=Q-V;V+=J)this.process($,V);continue}if(Z.set($.subarray(V,V+X),this.pos),this.pos+=X,V+=X,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){J0(this.h,this.r,this.buffer,this.pad)}digestInto($){w$(this),zZ($,this),this.finished=!0;let{buffer:Z,h:J}=this,{pos:Q}=this;if(Q){Z[Q++]=1;for(;Q<16;Q++)Z[Q]=0;this.process(Z,0,!0)}this.finalize();let V=0;for(let X=0;X<8;X++)$[V++]=J[X]>>>0,$[V++]=J[X]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function LQ($){let Z=(Q,V)=>$(V).update(s0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var A$=LQ(($)=>new HZ($));function EQ($,Z,J,Q,V,X=20){let Y=$[0],W=Z[0],q=Z[1],N=Z[2],z=Z[3],I=$[1],P=J[0],O=J[1],K=V,F=0,U=$[2],T=Z[4],D=Z[5],j=Z[6],w=Z[7],E=$[3],B=Y,h=W,S=q,m=N,g=z,R=I,x=P,_=O,y=K,i=F,l=U,b=T,C=D,n=j,a=w,e=E;for(let X0=0;X0<X;X0+=2)g^=H(B+C|0,7),y^=H(g+B|0,9),C^=H(y+g|0,13),B^=H(C+y|0,18),i^=H(R+h|0,7),n^=H(i+R|0,9),h^=H(n+i|0,13),R^=H(h+n|0,18),a^=H(l+x|0,7),S^=H(a+l|0,9),x^=H(S+a|0,13),l^=H(x+S|0,18),m^=H(e+b|0,7),_^=H(m+e|0,9),b^=H(_+m|0,13),e^=H(b+_|0,18),h^=H(B+m|0,7),S^=H(h+B|0,9),m^=H(S+h|0,13),B^=H(m+S|0,18),x^=H(R+g|0,7),_^=H(x+R|0,9),g^=H(_+x|0,13),R^=H(g+_|0,18),b^=H(l+i|0,7),y^=H(b+l|0,9),i^=H(y+b|0,13),l^=H(i+y|0,18),C^=H(e+a|0,7),n^=H(C+e|0,9),a^=H(n+C|0,13),e^=H(a+n|0,18);let k=0;Q[k++]=Y+B|0,Q[k++]=W+h|0,Q[k++]=q+S|0,Q[k++]=N+m|0,Q[k++]=z+g|0,Q[k++]=I+R|0,Q[k++]=P+x|0,Q[k++]=O+_|0,Q[k++]=K+y|0,Q[k++]=F+i|0,Q[k++]=U+l|0,Q[k++]=T+b|0,Q[k++]=D+C|0,Q[k++]=j+n|0,Q[k++]=w+a|0,Q[k++]=E+e|0}function SQ($,Z,J,Q){let V=$[0],X=Z[0],Y=Z[1],W=Z[2],q=Z[3],N=$[1],z=J[0],I=J[1],P=J[2],O=J[3],K=$[2],F=Z[4],U=Z[5],T=Z[6],D=Z[7],j=$[3];for(let E=0;E<20;E+=2)q^=H(V+U|0,7),P^=H(q+V|0,9),U^=H(P+q|0,13),V^=H(U+P|0,18),O^=H(N+X|0,7),T^=H(O+N|0,9),X^=H(T+O|0,13),N^=H(X+T|0,18),D^=H(K+z|0,7),Y^=H(D+K|0,9),z^=H(Y+D|0,13),K^=H(z+Y|0,18),W^=H(j+F|0,7),I^=H(W+j|0,9),F^=H(I+W|0,13),j^=H(F+I|0,18),X^=H(V+W|0,7),Y^=H(X+V|0,9),W^=H(Y+X|0,13),V^=H(W+Y|0,18),z^=H(N+q|0,7),I^=H(z+N|0,9),q^=H(I+z|0,13),N^=H(q+I|0,18),F^=H(K+O|0,7),P^=H(F+K|0,9),O^=H(P+F|0,13),K^=H(O+P|0,18),U^=H(j+D|0,7),T^=H(U+j|0,9),D^=H(T+U|0,13),j^=H(D+T|0,18);let w=0;Q[w++]=V,Q[w++]=N,Q[w++]=K,Q[w++]=j,Q[w++]=z,Q[w++]=I,Q[w++]=P,Q[w++]=O}var j$=FZ(EQ,{counterRight:!0,extendNonceFn:SQ}),L$=PZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=C$(J.length+32,Q,!1);let V=Q.subarray(0,32),X=Q.subarray(32);Q.set(J,32),J0(V),j$($,Z,Q,Q);let Y=A$(X,V);return Q.set(Y,16),J0(Q.subarray(0,16),Y),Q.subarray(16)},decrypt(J,Q){u(J),Q=C$(J.length+32,Q,!1);let V=Q.subarray(0,32),X=Q.subarray(32,48),Y=Q.subarray(48);Q.set(J,32),J0(V);let W=j$($,Z,V,V),q=A$(Y,W);if(!MZ(X,q))throw Error("invalid tag");return j$($,Z,Q.subarray(16),Q.subarray(16)),J0(V,X,q),Y}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function kQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function b0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function R0($,...Z){if(!kQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function u0($,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){R0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function UZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function S0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function k0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function h0($,Z){return $<<32-Z|$>>>Z}var wZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function TZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var CZ=wZ?($)=>$:($)=>TZ($);function mQ($){for(let Z=0;Z<$.length;Z++)$[Z]=TZ($[Z]);return $}var s=wZ?($)=>$:mQ;function _Q($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function m0($){if(typeof $==="string")$=_Q($);return R0($),$}class E${}function DZ($){let Z=(Q,V)=>$(V).update(m0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var AZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J$=BigInt(4294967295),jZ=BigInt(32);function S$($,Z=!1){if(Z)return{h:Number($&J$),l:Number($>>jZ&J$)};return{h:Number($>>jZ&J$)|0,l:Number($&J$)|0}}function W0($,Z,J,Q,V){return $=$+Z+V|0,Q=h0(Q^$,16),J=J+Q|0,Z=h0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function q0($,Z,J,Q,V){return $=$+Z+V|0,Q=h0(Q^$,8),J=J+Q|0,Z=h0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class k$ extends E${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,b0($),b0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=S0(this.buffer)}update($){u0(this),$=m0($),R0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,V=$.length,X=$.byteOffset,Y=$.buffer;for(let W=0;W<V;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(Q),this.pos=0;let q=Math.min(Z-this.pos,V-W),N=X+W;if(q===Z&&!(N%4)&&W+q<V){let z=new Uint32Array(Y,N,Math.floor((V-W)/4));s(z);for(let I=0;W+Z<V;I+=Q.length,W+=Z)this.length+=Z,this.compress(z,I,!1);s(z);continue}J.set($.subarray(W,W+q),this.pos),this.pos+=q,this.length+=q,W+=q}return this}digestInto($){u0(this),Z$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,k0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=S0($);this.get().forEach((V,X)=>Q[X]=CZ(V))}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}_cloneInto($){let{buffer:Z,length:J,finished:Q,destroyed:V,outputLen:X,pos:Y}=this;return $||($=new this.constructor({dkLen:X})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=V,$.finished=Q,$.length=J,$.pos=Y,$.outputLen=X,$}clone(){return this._cloneInto()}}function m$($,Z,J,Q,V,X,Y,W,q,N,z,I,P,O,K,F,U,T,D,j){let w=0;for(let E=0;E<Q;E++)({a:V,b:q,c:P,d:U}=W0(V,q,P,U,J[Z+$[w++]])),{a:V,b:q,c:P,d:U}=q0(V,q,P,U,J[Z+$[w++]]),{a:X,b:N,c:O,d:T}=W0(X,N,O,T,J[Z+$[w++]]),{a:X,b:N,c:O,d:T}=q0(X,N,O,T,J[Z+$[w++]]),{a:Y,b:z,c:K,d:D}=W0(Y,z,K,D,J[Z+$[w++]]),{a:Y,b:z,c:K,d:D}=q0(Y,z,K,D,J[Z+$[w++]]),{a:W,b:I,c:F,d:j}=W0(W,I,F,j,J[Z+$[w++]]),{a:W,b:I,c:F,d:j}=q0(W,I,F,j,J[Z+$[w++]]),{a:V,b:N,c:K,d:j}=W0(V,N,K,j,J[Z+$[w++]]),{a:V,b:N,c:K,d:j}=q0(V,N,K,j,J[Z+$[w++]]),{a:X,b:z,c:F,d:U}=W0(X,z,F,U,J[Z+$[w++]]),{a:X,b:z,c:F,d:U}=q0(X,z,F,U,J[Z+$[w++]]),{a:Y,b:I,c:P,d:T}=W0(Y,I,P,T,J[Z+$[w++]]),{a:Y,b:I,c:P,d:T}=q0(Y,I,P,T,J[Z+$[w++]]),{a:W,b:q,c:O,d:D}=W0(W,q,O,D,J[Z+$[w++]]),{a:W,b:q,c:O,d:D}=q0(W,q,O,D,J[Z+$[w++]]);return{v0:V,v1:X,v2:Y,v3:W,v4:q,v5:N,v6:z,v7:I,v8:P,v9:O,v10:K,v11:F,v12:U,v13:T,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=AZ.slice(),LZ=(()=>{let $=Array.from({length:16},(Q,V)=>V),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Q[V]),J=[];for(let Q=0,V=$;Q<7;Q++,V=Z(V))J.push(...V);return Uint8Array.from(J)})();class _$ extends k${constructor($={},Z=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:J,context:Q}=$,V=Q!==void 0;if(J!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let X=m0(J).slice();R0(X,32),this.IV=S0(X),s(this.IV),this.flags=Z|Q0.KEYED_HASH}else if(V){let X=m0(Q),Y=new _$({dkLen:32},Q0.DERIVE_KEY_CONTEXT).update(X).digest();this.IV=S0(Y),s(this.IV),this.flags=Z|Q0.DERIVE_KEY_MATERIAL}else this.IV=N0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=UZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:V,pos:X}=this,{h:Y,l:W}=S$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:I,v4:P,v5:O,v6:K,v7:F,v8:U,v9:T,v10:D,v11:j,v12:w,v13:E,v14:B,v15:h}=m$(LZ,Q,J,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],N0[0],N0[1],N0[2],N0[3],Y,W,X,Z);V[0]=q^U,V[1]=N^T,V[2]=z^D,V[3]=I^j,V[4]=P^w,V[5]=O^E,V[6]=K^B,V[7]=F^h}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 V=this.state;this.state=this.IV.slice();for(let X,Y=this.chunksDone+1;J||!(Y&1);Y>>=1){if(!(X=this.stack.pop()))break;this.buffer32.set(X,0),this.buffer32.set(V,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|Q0.PARENT,this.buffer32,0),V=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(V)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:V,posOut:X,chunkOut:Y,stack:W,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=W.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=V,$.chunksDone=q,$.posOut=X,$.chunkOut=Y,$.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:V}=this,{h:X,l:Y}=S$(BigInt(this.chunkOut++));s(Q);let{v0:W,v1:q,v2:N,v3:z,v4:I,v5:P,v6:O,v7:K,v8:F,v9:U,v10:T,v11:D,v12:j,v13:w,v14:E,v15:B}=m$(LZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],N0[0],N0[1],N0[2],N0[3],Y,X,Z,J);V[0]=W^F,V[1]=q^U,V[2]=N^T,V[3]=z^D,V[4]=I^j,V[5]=P^w,V[6]=O^E,V[7]=K^B,V[8]=$[0]^F,V[9]=$[1]^U,V[10]=$[2]^T,V[11]=$[3]^D,V[12]=$[4]^j,V[13]=$[5]^w,V[14]=$[6]^E,V[15]=$[7]^B,s(Q),s(V),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,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Q0.CHUNK_START:0)|Q0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){u0(this,!1),R0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,V=$.length;Q<V;){if(this.posOut>=Z)this.b2CompressOut();let X=Math.min(Z-this.posOut,V-Q);$.set(J.subarray(this.posOut,this.posOut+X),Q),this.posOut+=X,Q+=X}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return b0($),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 EZ=DZ(($)=>new _$($));function r($){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 mZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var SZ;if(typeof Uint8Array.prototype.toBase64==="function")SZ=($)=>$.toBase64();else SZ=($)=>btoa(String.fromCharCode(...$));var kZ;if(typeof Uint8Array.fromBase64==="function")kZ=($)=>Uint8Array.fromBase64($);else kZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function p0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var B$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function _Z($){let Z=new Uint8Array(B$.length+32);return Z.set(B$),Z.set($.subarray(0,32),B$.length),Z}function BZ($){return typeof $==="string"?new TextEncoder().encode($):$}function _0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class g${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return e0($)}async gen256BitSecureRandomSeed(){return e0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=e0(24),V=L$(Z,J).encrypt($);return new Uint8Array([...J,...V])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return L$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=_Z(Z),Q=await globalThis.crypto.subtle.importKey("pkcs8",_0(J),{name:"Ed25519"},!0,["sign"]),V=await globalThis.crypto.subtle.exportKey("jwk",Q);if(typeof V.x!=="string")throw Error("Ed25519 JWK missing x");let X=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:V.x},{name:"Ed25519"},!0,["verify"]),Y=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",X)),W=new Uint8Array(64);return W.set(Z,0),W.set(Y,32),this.signKeys.set(r(Z),Q),this.verifyKeys.set(r(Y),X),{keyType:"ed25519",privateKey:W,publicKey:Y}}async importSignKey($){let Z=$.subarray(0,32),J=r(Z),Q=this.signKeys.get(J);if(Q)return Q;let V=_Z(Z),X=await globalThis.crypto.subtle.importKey("pkcs8",_0(V),{name:"Ed25519"},!1,["sign"]);return this.signKeys.set(J,X),X}async importVerifyKey($){let Z=r($),J=this.verifyKeys.get(Z);if(J)return J;let Q=await globalThis.crypto.subtle.importKey("raw",_0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=BZ($),Q=await this.importSignKey(Z),V=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,_0(J));return new Uint8Array(V)}async checkSigEd25519($,Z,J){let Q=BZ(Z);try{let V=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},V,_0($),_0(Q))}catch{return!1}}async blake3($){return EZ($)}}var BQ=new g$,O0=BQ;var B0=64;var gZ=32,g0=8;var xZ=32;var fZ=30000,vZ=512,A;((R)=>{R[R.Success=0]="Success";R[R.InvalidSignature=3]="InvalidSignature";R[R.ClockOutOfSync=4]="ClockOutOfSync";R[R.UserNotRegistered=5]="UserNotRegistered";R[R.ServerMisconfigured=6]="ServerMisconfigured";R[R.MissingBody=7]="MissingBody";R[R.ExtraBodyContent=8]="ExtraBodyContent";R[R.MissingParam=9]="MissingParam";R[R.InvalidParam=10]="InvalidParam";R[R.InvalidRequest=11]="InvalidRequest";R[R.InternalError=12]="InternalError";R[R.NotFound=13]="NotFound";R[R.InvalidMessage=14]="InvalidMessage";R[R.NoChange=15]="NoChange";R[R.DatabaseClosed=16]="DatabaseClosed";R[R.StorageError=17]="StorageError";R[R.DatabaseError=18]="DatabaseError";R[R.HashMismatch=19]="HashMismatch";R[R.DecryptionError=20]="DecryptionError";R[R.NotImplemented=21]="NotImplemented";R[R.MissingSeed=22]="MissingSeed";R[R.OutOfBounds=23]="OutOfBounds";R[R.HostError=24]="HostError";R[R.CommunicationError=25]="CommunicationError";R[R.VarLimitExceeded=26]="VarLimitExceeded";R[R.InvalidResponse=27]="InvalidResponse";R[R.ConnectionClosed=28]="ConnectionClosed"})(A||={});var yZ="t";function M($){return[$,0]}function G($){return[void 0,$]}function gQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return G(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 G(26);return M(new Uint8Array(Z))}function xQ($,Z=0){let J=0n,Q=0,V=Z;while(!0){if(V>=$.length)return G(14);let X=$[V++];if(X===void 0)return G(14);if(J|=BigInt(X&127)<<BigInt(Q),(X&128)===0){if(V-Z>8)return G(26);return M({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:V-Z})}if(Q+=7,Q>=56)return G(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 G(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 G(Z);return M(new Date($))}readVarInt(){let[$,Z]=xQ(this.data,this.pos);if(Z!==0)return G(Z);this.pos+=$.bytesRead;let J=$.value;return M(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);let[J,Q]=this.readBytes($);if(Q!==0)return G(Q);let V=new TextDecoder().decode(J);return M(V)}readBytes($){if($<0)return G(10);if(this.pos+$>this.data.length)return G(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,M(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return G(Q);Z.push(J)}return M(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return G(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]=gQ($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let Z=this.writeVarInt($.length);if(Z!==0)return Z;return this.writeBytes($),0}writeStruct($,Z){return $.encode(this,Z)}writeStructs($,Z){for(let J of Z){let Q=this.writeStruct($,J);if(Q!==0)return Q}return 0}writeBytesSeq($){for(let Z of $)this.writeBytes(Z)}result(){let $=this.parts.reduce((Q,V)=>Q+V.length,0),Z=new Uint8Array($),J=0;for(let Q of this.parts)Z.set(Q,J),J+=Q.length;return Z}*scan(){for(let $ of this.parts)yield $}}var 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 G(J);let[Q,V]=$.readDate();if(V!==0)return G(V);return M({id:Z,ts:Q})}};function iZ($){let Z=new L,J=Z.writeStruct(d0,$);if(J!==0)return G(J);let Q=Z.result();return M(Q)}var x$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let V=$.writeVarInt(Z.ctr);if(V!==0)return V;let X=$.writeVarInt(Z.len);if(X!==0)return X;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let Q=new f(Z),[,V]=d0.decode(Q);if(V!==0)return G(V);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);let[W,q]=$.readVarInt();if(q!==0)return G(q);let[N,z]=$.readVarInt();if(z!==0)return G(z);let I;if(N>0){let[P,O]=$.readBytes(xZ);if(O!==0)return G(O);I=P}return M({eid:Z,off:X,ctr:W,len:N,hsh:I})}};function lZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function bZ($,Z,J,Q){let V;if($.bod&&$.len>0)V=await J.blake3($.bod);let X=new L,Y=x$.encode(X,{...$,hsh:V});if(Y!==0)return G(Y);let W=X.result(),q=await Z.kdmFor(W),N=Q.deriveCipher(q,"encrypt"),z=await N.encrypt(W),I=$.bod?await N.encrypt($.bod):new Uint8Array(0),P=await Z.sign(z);return M({sig:P,kdm:q,headCph:z,bodyCph:I})}async function uZ($,Z,J,Q,V){let X=new f($),[Y,W]=x$.decode(X);if(W!==0)return G(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return G(20)}let N=Y.hsh&&q===void 0,z=Y.hsh===void 0&&q!==void 0;if(N||z)return G(19);if(Y.hsh&&q){let P=await Q.blake3(q);if(!mZ(P,Y.hsh))return G(19)}let I=V??await Q.blake3($);return M({msgHead:Y,bod:q,headHash:I})}async function f$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return G(Q);let V=J.result(),X=await $.sign(V);return M({pubKey:$.publicKey,sig:X,timestamp:Z})}async function $0($,Z,J){let Q=J.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Q-V)>fZ)return 4;let Y=new L;Y.writeDate($.timestamp);let W=Y.result();if(!await Z.checkSigEd25519($.sig,W,$.pubKey))return 3;return 0}class x0{now(){return new Date}}function hZ($,Z,J,Q){let V=Z.getTime()-$.getTime(),X=J.getTime()-Q.getTime();return(V+X)/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 G(J);let Q;if(Z>0){let[V,X]=$.readVarInt();if(X!==0)return G(X);Q=V}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 V=$.writeVarInt(Z.subscription.term);if(V!==0)return V;let X=$.writeVarInt(Z.subscription.elapsed);if(X!==0)return X;let Y=$.writeStruct(n0,Z.subscription.stat);if(Y!==0)return Y;let W=$.writeStruct(n0,Z.subscription.dyn);if(W!==0)return W;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return G(J);let Q=Z[0],[V,X]=$.readDate();if(X!==0)return G(X);let[Y,W]=$.readDate();if(W!==0)return G(W);let[q,N]=$.readVarInt();if(N!==0)return G(N);let[z,I]=$.readVarInt();if(I!==0)return G(I);let[P,O]=$.readStruct(n0);if(O!==0)return G(O);let[K,F]=$.readStruct(n0);if(F!==0)return G(F);return M({status:Q,timeRcvd:V,timeSent:Y,subscription:{term:q,elapsed:z,stat:P,dyn:K}})}};var v$={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 G(J);let[Q,V]=$.readVarInt();if(V!==0)return G(V);return M({headCph:Z,seq:Q})}};var o={encode($,Z){$.writeBytes(Z.pubKey),$.writeBytes(Z.sig);let J=$.writeDate(Z.timestamp);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(gZ);if(J!==0)return G(J);let[Q,V]=$.readBytes(B0);if(V!==0)return G(V);let[X,Y]=$.readDate();if(Y!==0)return G(Y);return M({pubKey:Z,sig:Q,timestamp:X})}};var pZ={async encodeReq($,Z,J,Q,V){let X=V.writeStruct(o,J);if(X!==0)return X;for(let Y of Q)V.writeVarInt(Y);return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X}=$,[Y,W]=Z.readStruct(o);if(W!==0)return W;let q=await $0(Y,V,Q);if(q!==0)return q;let{pubKey:N}=Y,[z,I]=await X.hasUser(N);if(I!==0)return I;if(!z)return 5;let[P,O]=Z.readVarInt();if(O!==0)return O;if(!Z.done())return 8;let[K,F]=await X.listHeads(N,P);if(F!==0)return F;return J.writeStructs(v$,K)},decodeResp($){return $.readStructs(v$)}};var y$={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 G(J);let[Q,V]=$.readVarBytes();if(V!==0)return G(V);return M({seq:Z,bodyCph:Q})}};var dZ={async encodeReq($,Z,J,Q,V){let X=V.writeStruct(o,J);if(X!==0)return X;for(let Y of Q){let W=V.writeVarInt(Y);if(W!==0)return W}return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X}=$,[Y,W]=Z.readStruct(o);if(W!==0)return W;let q=await $0(Y,V,Q);if(q!==0)return q;let{pubKey:N}=Y,[z,I]=await X.hasUser(N);if(I!==0)return I;if(!z)return 5;let P=[];while(!Z.done()){let[F,U]=Z.readVarInt();if(U!==0)return U;P.push(F)}console.info(`PULL: ${P.length} bags`);let[O,K]=await X.getBodies(N,P);if(K!==0)return K;if(!O)return 17;for(let{seq:F,bodyCph:U}of O){let T={seq:F,bodyCph:U},D=J.writeStruct(y$,T);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(y$)}};var i$={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(B0);if(J!==0)return G(J);let[Q,V]=$.readBytes(g0);if(V!==0)return G(V);let[X,Y]=$.readVarBytes();if(Y!==0)return G(Y);let[W,q]=$.readVarBytes();if(q!==0)return G(q);return M({sig:Z,kdm:Q,headCph:X,bodyCph:W})}};var l$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let V=Z.bodyCph?Z.bodyCph.length:0,X=$.writeVarInt(V);if(X!==0)return X;if(V>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);let[Q,V]=$.readVarBytes();if(V!==0)return G(V);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);let W;if(X>0){let[q,N]=$.readBytes(X);if(N!==0)return G(N);W=q}return M({seq:Z,headCph:Q,bodyCph:W})}};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(B0);if(J!==0)return G(J);let[Q,V]=$.readBytes(g0);if(V!==0)return G(V);let[X,Y]=$.readVarBytes();if(Y!==0)return G(Y);return M({sig:Z,kdm:Q,headCph:X})}};var V$={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 G(J);let[Q,V]=$.readBytes(1);if(V!==0)return G(V);let X=Q[0];if(X!==0)return M({idx:Z,status:X});let[Y,W]=$.readVarInt();if(W!==0)return G(W);return M({idx:Z,status:X,seq:Y})}};var nZ={async encodeReq($,Z,J,Q,V){let X=V.writeStruct(o,J);if(X!==0)return X;let Y=V.writeStructs(i$,Q);if(Y!==0)return Y;return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X,notifier:Y}=$,[W,q]=Z.readStruct(o);if(q!==0)return q;let N=await $0(W,V,Q);if(N!==0)return N;let{pubKey:z}=W,[I,P]=await X.hasUser(z);if(P!==0)return P;if(!I)return 5;let[O,K]=Z.readStructs(i$);if(K!==0)return K;console.info(`PUSH: ${O.length} bags`);let F=[],U=[];for(let w=0;w<O.length;w++){let E=O[w];if(!await lZ(E,z,V)){let h={idx:w,status:3},S=J.writeStruct(V$,h);if(S!==0)return S;continue}F.push(w),U.push(E)}let[T,D]=await X.setBags(z,U);if(D!==0)return D;if(!T||T.length!==U.length)return 17;let j=[];for(let w=0;w<U.length;w++){let E=U[w],B=F[w],h=T[w],S=new L,m=S.writeStruct(v0,E);if(m!==0)return m;let g=S.result(),R={seq:h,headCph:g};if(O.length===1&&E.bodyCph.length<=vZ)R.bodyCph=E.bodyCph;j.push(R);let x={idx:B,status:0,seq:h},_=J.writeStruct(V$,x);if(_!==0)return _}if(j.length>0){let w=new L,E=w.writeStructs(l$,j);if(E!==0)return E;let B=w.result();await Promise.resolve(Y.push(z,B))}return 0},decodeResp($){return $.readStructs(V$)}};var cZ={async encodeReq($,Z,J,Q,V){return V.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X}=$,[Y,W]=Z.readStruct(o);if(W!==0)return W;let q=await $0(Y,V,Q);if(q!==0)return q;let{pubKey:N}=Y;if(!Z.done())return 8;let[z,I]=await X.addUser(N);if(I!==0)return I;return 0},decodeResp($){return M(void 0)}};class b${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let X=new L;X.writeStruct(o,$);let Y=X.result(),W=r(Y);return V.searchParams.set("t",W),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Q()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(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:cZ,name:0},push:{path:"/push",endpoint:nZ,name:2},peek:{path:"/peek",endpoint:pZ,name:1},pull:{path:"/pull",endpoint:dZ,name:3}},fQ={0:d.user,2:d.push,1:d.peek,3:d.pull},rZ={[d.user.path]:d.user,[d.push.path]:d.push,[d.peek.path]:d.peek,[d.pull.path]:d.pull};class oZ{url;listener;constructor($){this.url=$;this.listener=new b$($)}async call($,Z){let{path:J}=fQ[$],Q=new URL(J,this.url);try{return await yQ(Q,Z)}catch{return G(25)}}}var u$=($)=>{return new oZ($.handle)};function y0($){let Z=new L;if(Z.writeStruct(f0,$)!==0)return new Response(null,{status:500});return h$(Z)}function h$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var vQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function p$($){return new Response($.body,{headers:{...$.headers,...vQ},status:$.status,statusText:$.statusText})}async function yQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return G(24);let Q=await f.fromResponse(J);return M(Q)}class X${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,V,X){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=V;this.updateHostMeta=X}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:V,name:X}=$,Y=await this.identity(),W=J.now(),[q,N]=await f$(Y,W);if(N!==0)return G(N);let z=new L,I=await V.encodeReq(this,Y,q,Z,z);if(I!==0)return G(I);let P=J.now(),[O,K]=await Q.call(X,z),F=J.now();if(K!==0)return G(K);let[U,T]=O.readStruct(f0);if(T!==0)return G(T);if(U.status!==0)return G(U.status);let j={clockOffset:hZ(P,U.timeRcvd,U.timeSent,F),subscription:U.subscription},w=await this.updateHostMeta(j);if(w!==0)return G(w);return V.decodeResp(O)}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 bZ($,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:V}=this,{listener:X}=V,Y=await this.identity(),W=Q.now(),[q,N]=await f$(Y,W);if(N!==0)return N;return await X.connect(q,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var wW=Symbol("MasterSeed"),TW=Symbol("SealedMasterKey"),V0=32,aZ=24+V0+16;function t($){if($.byteLength!==V0)return G(10);return M($)}function Y$($){if($.byteLength!==aZ)return G(10);return M($)}var K0={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 G(J);let[Q,V]=$.readVarString();if(V!==0)return G(V);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);return M({handle:Z,label:Q,idx:X})}};var G$=1,d$={encode($,Z){if(Z.v!==G$)return 10;let[,J]=t(Z.masterSeed);if(J!==0)return J;let Q=$.writeVarInt(Z.v);if(Q!==0)return Q;$.writeBytes(Z.masterSeed);let V=$.writeVarInt(Z.hosts.length);if(V!==0)return V;for(let X of Z.hosts){let Y=$.writeStruct(K0,X);if(Y!==0)return Y}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);if(Z!==G$)return G(14);let[Q,V]=$.readBytes(V0);if(V!==0)return G(V);if(Q===void 0)return G(14);let[X,Y]=t(Q);if(Y!==0)return G(Y);if(X===void 0)return G(14);let[W,q]=$.readVarInt();if(q!==0)return G(q);if(W===void 0||W<0)return G(10);let N=[];for(let z=0;z<W;z++){let[I,P]=$.readStruct(K0);if(P!==0)return G(P);if(I===void 0)return G(14);N.push(I)}return M({v:G$,masterSeed:X,hosts:N})}};function sZ($,Z){let[J,Q]=t($);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[V,X]=t(J.slice());if(X!==0)return G(X);if(V===void 0)return G(10);return M({v:G$,masterSeed:V,hosts:Z.map((Y)=>({handle:Y.handle,label:Y.label,idx:Y.idx??0}))})}var n$={encode($,Z){let[,J]=t(Z.masterSeed);if(J!==0)return J;$.writeBytes(Z.masterSeed);let Q=$.writeVarInt(Z.hosts.length);if(Q!==0)return Q;for(let V of Z.hosts){let X=$.writeStruct(K0,V);if(X!==0)return X}return 0},decode($){let[Z,J]=$.readBytes(V0);if(J!==0)return G(J);if(Z===void 0)return G(14);let[Q,V]=t(Z);if(V!==0)return G(V);if(Q===void 0)return G(14);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);if(X===void 0||X<0)return G(10);let W=[];for(let q=0;q<X;q++){let[N,z]=$.readStruct(K0);if(z!==0)return G(z);if(N===void 0)return G(14);W.push(N)}return M({masterSeed:Q,hosts:W})}};function z0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var F0=32,iQ=-7,lQ=-8,bQ=-257,W$=[{type:"public-key",alg:iQ},{type:"public-key",alg:lQ},{type:"public-key",alg:bQ}];function uQ($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function H0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z}function U0($){if($?.rpId!==void 0)return M($.rpId);if(typeof location>"u")return G(9);return M(uQ(location.hostname))}function w0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function T0($){if($===null||$.type!=="public-key"||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return G(27);return M($)}async function tZ($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let V=$?.userName??"diplomatic-seed",X={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)X.authenticatorAttachment=$.authenticatorAttachment;let Y={largeBlob:{support:"required"}},W;try{W=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:V,displayName:V},pubKeyCredParams:W$,authenticatorSelection:X,extensions:Y}})}catch{return G(24)}let[q,N]=T0(W);if(N!==0)return G(N);if(q===void 0)return G(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return G(24);return M(new Uint8Array(q.rawId))}async function c$($,Z,J){let Q=w0();if(Q!==0)return Q;let[V,X]=U0(J);if(X!==0)return X;if(V===void 0)return 9;let Y={largeBlob:{write:H0(Z)}},W;try{W=await navigator.credentials.get({publicKey:{challenge:z0(F0),rpId:V,allowCredentials:[{type:"public-key",id:H0($)}],userVerification:"required",extensions:Y}})}catch{return 24}let[q,N]=T0(W);if(N!==0)return N;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 24;return 0}async function eZ($,Z){let J=w0();if(J!==0)return G(J);let[Q,V]=U0(Z);if(V!==0)return G(V);if(Q===void 0)return G(9);let X={largeBlob:{read:!0}},Y;try{let I={challenge:z0(F0),rpId:Q,userVerification:"required",extensions:X};if($!==void 0)I.allowCredentials=[{type:"public-key",id:H0($)}];Y=await navigator.credentials.get({publicKey:I})}catch{return G(24)}let[W,q]=T0(Y);if(q!==0)return G(q);if(W===void 0)return G(27);let z=W.getClientExtensionResults().largeBlob?.blob;if(z===void 0)return G(7);return M({blob:new Uint8Array(z),credId:new Uint8Array(W.rawId)})}var q$=new TextEncoder().encode("diplomatic.prf.v1"),r$=32;async function $J($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let V=$?.userName??"diplomatic-prf",X={residentKey:"required",requireResidentKey:!0,userVerification:"required",authenticatorAttachment:$?.authenticatorAttachment??"platform"},Y;try{Y=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:V,displayName:V},pubKeyCredParams:W$,authenticatorSelection:X,extensions:{prf:{}}}})}catch{return G(24)}let[W,q]=T0(Y);if(q!==0)return G(q);if(W===void 0)return G(27);let N=W.getClientExtensionResults();return M({credId:new Uint8Array(W.rawId),prfEnabled:N.prf?.enabled===!0})}async function c0($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let V=$?.salt??q$,X=H0(V),Y={challenge:z0(F0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:X}}}};if($?.credId!==void 0)Y.allowCredentials=[{type:"public-key",id:H0($.credId)}];let W;try{W=await navigator.credentials.get({publicKey:Y})}catch{return G(24)}let[q,N]=T0(W);if(N!==0)return G(N);if(q===void 0)return G(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return G(7);let I=z.first,P=I instanceof ArrayBuffer?new Uint8Array(I):new Uint8Array(I.buffer,I.byteOffset,I.byteLength),O=P.byteLength>=r$?P.slice(0,r$):P;if(O.byteLength!==r$)return G(27);return M({prf:O,credId:new Uint8Array(q.rawId)})}var N$="";var z$;function pQ(){if(typeof N$!=="string"||N$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(N$)}function dQ(){if(z$!==void 0)return z$;let $=new Blob([pQ()],{type:"text/javascript"});return z$=URL.createObjectURL($),z$}function ZJ(){if(typeof Worker>"u")throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new Worker(dQ(),{type:"module"})}var nQ=new TextEncoder().encode("diplomatic.wrap.v1"),cQ=32,rQ=16;class Z0{#Z;#$;constructor($,Z){this.#Z=$,this.#$=Z}static async fromRandom($){let Z=await $.gen256BitSecureRandomSeed(),[J,Q]=t(Z);if(Q!==0||J===void 0)throw Error(`enclave: invalid random seed (${Q})`);return new Z0(J,$)}static fromBytes($,Z){let[J,Q]=t(Z);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[V,X]=t(J.slice());if(X!==0)return G(X);if(V===void 0)return G(10);return M(new Z0(V,$))}async sealWithPasskey($){let Z=$?.salt??q$,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[X,Y]=await $J({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf"});if(Y!==0)return G(Y);if(X===void 0)return G(24);if(!X.prfEnabled)return G(24);J=X.credId}let[Q,V]=await c0({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z});if(V!==0)return G(V);if(Q===void 0)return G(7);try{let[X,Y]=await this.#V(Q.prf);if(Y!==0)return G(Y);if(X===void 0)return G(12);return M({sealedMaster:X,salt:Z.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async unsealWithPasskey($,Z,J){let[Q,V]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(V!==0)return G(V);if(Q===void 0)return G(7);try{return await Z0.#X($,Z,Q.prf)}finally{Q.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[X,Y]=await tZ(Z);if(Y!==0)return G(Y);if(X===void 0)return G(24);J=X}let[Q,V]=this.#Y($);if(V!==0)return G(V);if(Q===void 0)return G(12);try{let X=await c$(J,Q,Z);if(X!==0)return G(X);return M(J)}finally{Q.fill(0)}}static async fromLargeBlob($,Z){let[J,Q]=await eZ(Z?.credId,Z);if(Q!==0)return G(Q);if(J===void 0)return G(7);try{return Z0.#G($,J.blob,J.credId)}finally{J.blob.fill(0)}}static async clearLargeBlob($,Z){return c$($,new Uint8Array(V0),Z)}async sealPairPackageBody($,Z){let J=Z?.salt??q$,[Q,V]=await c0({rpId:Z?.rpId,rpName:Z?.rpName,credId:Z?.credId,salt:J});if(V!==0)return G(V);if(Q===void 0)return G(7);try{let[X,Y]=await I$(this.#$,Q.prf);if(Y!==0)return G(Y);if(X===void 0)return G(12);let[W,q]=t(this.#Z.slice());if(q!==0)return G(q);if(W===void 0)return G(10);let N={masterSeed:W,hosts:$.map((K)=>({handle:K.handle,label:K.label,idx:K.idx??0}))},z=new L,I=z.writeStruct(n$,N);if(I!==0)return W.fill(0),G(I);let P=z.result();W.fill(0);let O;try{O=await this.#$.encryptXSalsa20Poly1305Combined(P,X)}catch{return P.fill(0),G(12)}return P.fill(0),M({body:O,salt:J.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async openPairPackageBody($,Z,J){let[Q,V]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(V!==0)return G(V);if(Q===void 0)return G(7);try{let[X,Y]=await I$($,Q.prf);if(Y!==0)return G(Y);if(X===void 0)return G(12);let W;try{W=await $.decryptXSalsa20Poly1305Combined(Z,X)}catch{return G(20)}let q=new f(W),[N,z]=q.readStruct(n$);if(W.fill(0),z!==0)return G(z);if(N===void 0)return G(14);let[I,P]=Z0.fromBytes($,N.masterSeed);if(N.masterSeed.fill(0),P!==0)return G(P);if(I===void 0)return G(12);let[O,K]=await I.#V(Q.prf);if(K!==0)return G(K);if(O===void 0)return G(12);return M({enclave:I,hosts:N.hosts.map((F)=>({...F})),sealedMaster:O,credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}spawnSyncWorker($){let Z=ZJ(),J=this.#Z.slice();return Z.postMessage({id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(Y)=>this.#W(J,Y),V=(Y)=>this.#q(J,Y);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:V}),both:Object.freeze({encrypt:Q,decrypt:V})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,V=await this.#Q(J,Q);return Object.freeze({publicKey:V.publicKey,sign:(X)=>this.#z(J,Q,X),kdmFor:(X)=>this.#I(J,Q,X)})}async#V($){let[Z,J]=await I$(this.#$,$);if(J!==0)return G(J);if(Z===void 0)return G(12);try{let Q=await this.#$.encryptXSalsa20Poly1305Combined(this.#Z,Z);return Y$(Q)}catch{return G(12)}}static async#X($,Z,J){let[,Q]=Y$(Z);if(Q!==0)return G(Q);let[V,X]=await I$($,J);if(X!==0)return G(X);if(V===void 0)return G(12);try{let Y=await $.decryptXSalsa20Poly1305Combined(Z,V);return Z0.fromBytes($,Y)}catch{return G(20)}}#Y($){let[Z,J]=t(this.#Z.slice());if(J!==0)return G(J);if(Z===void 0)return G(10);let[Q,V]=sZ(Z,$);if(V!==0)return Z.fill(0),G(V);if(Q===void 0)return Z.fill(0),G(12);Z.fill(0);let X=new L,Y=X.writeStruct(d$,Q);if(Q.masterSeed.fill(0),Y!==0)return G(Y);return M(X.result())}static#G($,Z,J){if(Z.byteLength===0||Z.every((q)=>q===0))return G(22);if(Z.byteLength===V0){let[q,N]=Z0.fromBytes($,Z);if(N!==0)return G(N);if(q===void 0)return G(12);return M({enclave:q,hosts:[],credId:J})}let Q=new f(Z),[V,X]=Q.readStruct(d$);if(X!==0)return G(X);if(V===void 0)return G(14);let[Y,W]=Z0.fromBytes($,V.masterSeed);if(V.masterSeed.fill(0),W!==0)return G(W);if(Y===void 0)return G(12);return M({enclave:Y,hosts:V.hosts.map((q)=>({...q})),credId:J})}async#W($,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(p0(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(p0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);return this.#$.deriveEd25519KeyPair(J)}async#z($,Z,J){let Q=await this.#Q($,Z);return this.#$.signEd25519(J,Q.privateKey)}async#I($,Z,J){let Q=await this.#Q($,Z),V=p0(Q.privateKey,J);return(await this.#$.blake3(V)).slice(0,g0)}}async function I$($,Z){if(Z.byteLength<rQ)return G(10);let J=await $.blake3(p0(Z,nQ));return M(J.slice(0,cQ))}class o${listeners=new Map;addEventListener($,Z){let J=this.listeners.get($);if(!J)J=new Set,this.listeners.set($,J);return J.add(Z),()=>{this.removeEventListener($,Z)}}removeEventListener($,Z){let J=this.listeners.get($);if(J){if(J.delete(Z),J.size===0)this.listeners.delete($)}}emit($,Z){let J=this.listeners.get($);if(J){let Q=Array.from(J);for(let V of Q)V(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function JJ($,Z,J,Q=0){let V=Z.now(),X=new L,Y=X.writeVarString($);if(Y!==0)return G(Y);let q={id:X.result(),ts:new Date(0)},[N,z]=iZ(q);if(z!==0)return G(z);let I=V.getTime()-q.ts.getTime();return M({eid:N,off:I,ctr:Q,len:J.length,bod:J})}class oQ{singletonType;latest;latestOff=-1;emitter=new o$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new f(Z.eid),[Q,V]=J.readStruct(d0);if(V!==0)continue;let X=new L;X.writeVarString(this.singletonType);let Y=X.result();if(Q.id.length===Y.length&&Q.id.every((W,q)=>W===Y[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 QJ($,Z,J,Q){let V=new f($.headCph),[X,Y]=V.readStruct(v0);if(Y!==0)return G(Y);let{sig:W,kdm:q,headCph:N}=X;if(!await Q.checkSigEd25519(W,N,Z))return G(3);let I=J.deriveCipher(q,"decrypt"),P;try{P=await I.decrypt(N)}catch{return G(20)}return M({kdm:q,headEnc:P})}var l0=KQ(VQ(),1),PX={encode:l0.encode,decode:l0.decode,decodeAsync:l0.decodeAsync},RX=PX;import{Database as OX}from"bun:sqlite";var Yq=Symbol("EntityID");var Gq=Symbol("DerivationSeed"),Wq=Symbol("PublicKey"),qq=Symbol("PrivateKey"),Nq=Symbol("HostSpecificKeyPair"),zq=Symbol("Hash"),M0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function KX($="diplomatic.db"){let Z=new OX($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
1
+ var zQ=Object.create;var{getPrototypeOf:PQ,defineProperty:NZ,getOwnPropertyNames:MQ}=Object;var OQ=Object.prototype.hasOwnProperty;function RQ($){return this[$]}var KQ,HQ,FQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var X=Z?KQ??=new WeakMap:HQ??=new WeakMap,Y=X.get($);if(Y)return Y}J=$!=null?zQ(PQ($)):{};let W=Z||!$||!$.__esModule?NZ(J,"default",{value:$,enumerable:!0}):J;for(let V of MQ($))if(!OQ.call(W,V))NZ(W,V,{get:RQ.bind($,V),enumerable:!0});if(Q)X.set($,W);return W};var c=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var M$=c((qJ)=>{Object.defineProperty(qJ,"__esModule",{value:!0});qJ.utf8Count=sQ;qJ.utf8EncodeJs=YJ;qJ.utf8EncodeTE=WJ;qJ.utf8Encode=$X;qJ.utf8DecodeJs=GJ;qJ.utf8DecodeTD=VJ;qJ.utf8Decode=XX;function sQ($){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 YJ($,Z,J){let Q=$.length,X=J,Y=0;while(Y<Q){let W=$.charCodeAt(Y++);if((W&4294967168)===0){Z[X++]=W;continue}else if((W&4294965248)===0)Z[X++]=W>>6&31|192;else{if(W>=55296&&W<=56319){if(Y<Q){let V=$.charCodeAt(Y);if((V&64512)===56320)++Y,W=((W&1023)<<10)+(V&1023)+65536}}if((W&4294901760)===0)Z[X++]=W>>12&15|224,Z[X++]=W>>6&63|128;else Z[X++]=W>>18&7|240,Z[X++]=W>>12&63|128,Z[X++]=W>>6&63|128}Z[X++]=W&63|128}}var eQ=new TextEncoder,tQ=50;function WJ($,Z,J){eQ.encodeInto($,Z.subarray(J))}function $X($,Z,J){if($.length>tQ)WJ($,Z,J);else YJ($,Z,J)}var ZX=4096;function GJ($,Z,J){let Q=Z,X=Q+J,Y=[],W="";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>=ZX)W+=String.fromCharCode(...Y),Y.length=0}if(Y.length>0)W+=String.fromCharCode(...Y);return W}var JX=new TextDecoder,QX=200;function VJ($,Z,J){let Q=$.subarray(Z,Z+J);return JX.decode(Q)}function XX($,Z,J){if(J>QX)return VJ($,Z,J);else return GJ($,Z,J)}});var a$=c((zJ)=>{Object.defineProperty(zJ,"__esModule",{value:!0});zJ.ExtData=void 0;class NJ{type;data;constructor($,Z){this.type=$,this.data=Z}}zJ.ExtData=NJ});var R$=c((MJ)=>{Object.defineProperty(MJ,"__esModule",{value:!0});MJ.DecodeError=void 0;class O$ extends Error{constructor($){super($);let Z=Object.create(O$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:O$.name})}}MJ.DecodeError=O$});var K$=c((RJ)=>{Object.defineProperty(RJ,"__esModule",{value:!0});RJ.UINT32_MAX=void 0;RJ.setUint64=PX;RJ.setInt64=MX;RJ.getInt64=OX;RJ.getUint64=RX;RJ.UINT32_MAX=4294967295;function PX($,Z,J){let Q=J/4294967296,X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function MX($,Z,J){let Q=Math.floor(J/4294967296),X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function OX($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function RX($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var s$=c((TJ)=>{Object.defineProperty(TJ,"__esModule",{value:!0});TJ.timestampExtension=TJ.EXT_TIMESTAMP=void 0;TJ.encodeTimeSpecToTimestamp=FJ;TJ.encodeDateToTimeSpec=IJ;TJ.encodeTimestampExtension=UJ;TJ.decodeTimestampToTimeSpec=wJ;TJ.decodeTimestampExtension=CJ;var UX=R$(),HJ=K$();TJ.EXT_TIMESTAMP=-1;var wX=4294967295,CX=17179869183;function FJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=CX)if(Z===0&&$<=wX){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,HJ.setInt64)(Q,4,$),J}}function IJ($){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 UJ($){if($ instanceof Date){let Z=IJ($);return FJ(Z)}else return null}function wJ($){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,HJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new UX.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function CJ($){let Z=wJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}TJ.timestampExtension={type:TJ.EXT_TIMESTAMP,encode:UJ,decode:CJ}});var F$=c((jJ)=>{Object.defineProperty(jJ,"__esModule",{value:!0});jJ.ExtensionCodec=void 0;var H$=a$(),EX=s$();class e${static defaultCodec=new e$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(EX.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 H$.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 H$.ExtData(Y,X)}}}if($ instanceof H$.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 H$.ExtData(Z,$)}}jJ.ExtensionCodec=e$});var t$=c((EJ)=>{Object.defineProperty(EJ,"__esModule",{value:!0});EJ.ensureUint8Array=kX;function _X($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function kX($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(_X($))return new Uint8Array($);else return Uint8Array.from($)}});var ZZ=c((mJ)=>{Object.defineProperty(mJ,"__esModule",{value:!0});mJ.Encoder=mJ.DEFAULT_INITIAL_BUFFER_SIZE=mJ.DEFAULT_MAX_DEPTH=void 0;var _J=M$(),BX=F$(),kJ=K$(),xX=t$();mJ.DEFAULT_MAX_DEPTH=100;mJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class $Z{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??BX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??mJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??mJ.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 $Z({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,_J.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,_J.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,xX.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,kJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,kJ.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}}mJ.Encoder=$Z});var fJ=c((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.encode=gX;var SX=ZZ();function gX($,Z){return new SX.Encoder(Z).encodeSharedRef($)}});var yJ=c((vJ)=>{Object.defineProperty(vJ,"__esModule",{value:!0});vJ.prettyByte=vX;function vX($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var hJ=c((bJ)=>{Object.defineProperty(bJ,"__esModule",{value:!0});bJ.CachedKeyDecoder=void 0;var lX=M$(),bX=16,iX=16;class lJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=bX,Z=iX){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 W=0;W<J;W++)if(Y[W]!==$[Z+W])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,lX.utf8DecodeJs)($,Z,J),Y=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(Y,X),X}}bJ.CachedKeyDecoder=lJ});var I$=c((cJ)=>{Object.defineProperty(cJ,"__esModule",{value:!0});cJ.Decoder=void 0;var JZ=yJ(),hX=F$(),T0=K$(),pX=M$(),pJ=t$(),uX=hJ(),P0=R$(),QZ="array",o0="map_key",dJ="map_value",dX=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new P0.DecodeError("The type of key must be string or number but "+typeof $)};class nJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=QZ,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===QZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===o0||$.type===dJ){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,XZ=new DataView(new ArrayBuffer(0)),nX=new Uint8Array(XZ.buffer);try{XZ.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 uJ=RangeError("Insufficient data"),cX=new uX.CachedKeyDecoder;class YZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=XZ;bytes=nX;headByte=r0;stack=new nJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??hX.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:cX,this.mapKeyConverter=$?.mapKeyConverter??dX}clone(){return new YZ({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,pJ.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,pJ.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 W of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(W);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,JZ.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,JZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===QZ)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=dJ;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,JZ.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 uJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,pX.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 uJ;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,$}}cJ.Decoder=YZ});var sJ=c((aJ)=>{Object.defineProperty(aJ,"__esModule",{value:!0});aJ.decode=rX;aJ.decodeMulti=oX;var oJ=I$();function rX($,Z){return new oJ.Decoder(Z).decode($)}function oX($,Z){return new oJ.Decoder(Z).decodeMulti($)}});var ZQ=c(($Q)=>{Object.defineProperty($Q,"__esModule",{value:!0});$Q.isAsyncIterable=eJ;$Q.asyncIterableFromStream=tJ;$Q.ensureAsyncIterable=eX;function eJ($){return $[Symbol.asyncIterator]!=null}async function*tJ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function eX($){if(eJ($))return $;else return tJ($)}});var QQ=c((JQ)=>{Object.defineProperty(JQ,"__esModule",{value:!0});JQ.decodeAsync=JY;JQ.decodeArrayStream=QY;JQ.decodeMultiStream=XY;var WZ=I$(),GZ=ZQ();async function JY($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new WZ.Decoder(Z).decodeAsync(J)}function QY($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new WZ.Decoder(Z).decodeArrayStream(J)}function XY($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new WZ.Decoder(Z).decodeStream(J)}});var YQ=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 VY=fJ();Object.defineProperty(v,"encode",{enumerable:!0,get:function(){return VY.encode}});var XQ=sJ();Object.defineProperty(v,"decode",{enumerable:!0,get:function(){return XQ.decode}});Object.defineProperty(v,"decodeMulti",{enumerable:!0,get:function(){return XQ.decodeMulti}});var VZ=QQ();Object.defineProperty(v,"decodeAsync",{enumerable:!0,get:function(){return VZ.decodeAsync}});Object.defineProperty(v,"decodeArrayStream",{enumerable:!0,get:function(){return VZ.decodeArrayStream}});Object.defineProperty(v,"decodeMultiStream",{enumerable:!0,get:function(){return VZ.decodeMultiStream}});var qY=I$();Object.defineProperty(v,"Decoder",{enumerable:!0,get:function(){return qY.Decoder}});var NY=R$();Object.defineProperty(v,"DecodeError",{enumerable:!0,get:function(){return NY.DecodeError}});var zY=ZZ();Object.defineProperty(v,"Encoder",{enumerable:!0,get:function(){return zY.Encoder}});var PY=F$();Object.defineProperty(v,"ExtensionCodec",{enumerable:!0,get:function(){return PY.ExtensionCodec}});var MY=a$();Object.defineProperty(v,"ExtData",{enumerable:!0,get:function(){return MY.ExtData}});var l0=s$();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 W0 from"node:crypto";var O0=W0&&typeof W0==="object"&&"webcrypto"in W0?W0.webcrypto:W0&&typeof W0==="object"&&("randomBytes"in W0)?W0:void 0;function a0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function U$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function h($,...Z){if(!U$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function w$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function zZ($,Z){h($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function C$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var G0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var IQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!IQ)throw Error("Non little-endian hardware is not supported");function UQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function s0($){if(typeof $==="string")$=UQ($);else if(U$($))$=e0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function PZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function MZ($,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 OZ=($,Z)=>{function J(Q,...X){if(h(Q),$.nonceLength!==void 0){let z=X[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)h(z);else h(z,$.nonceLength)}let Y=$.tagLength;if(Y&&X[1]!==void 0)h(X[1]);let W=Z(Q,...X),V=(z,P)=>{if(P!==void 0){if(z!==2)throw Error("cipher output not supported");h(P)}},q=!1;return{encrypt(z,P){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,h(z),V(W.encrypt.length,P),W.encrypt(z,P)},decrypt(z,P){if(h(z),Y&&z.length<Y)throw Error("invalid ciphertext length: smaller than tagLength="+Y);return V(W.decrypt.length,P),W.decrypt(z,P)}}}return Object.assign(J,$),J};function T$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!wQ(Z))throw Error("invalid output, must be aligned");return Z}function wQ($){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 KZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),CQ=KZ("expand 16-byte k"),TQ=KZ("expand 32-byte k"),DQ=G0(CQ),AQ=G0(TQ);function I($,Z){return $<<Z|$>>>32-Z}function D$($){return $.byteOffset%4===0}var $$=64,jQ=16,HZ=4294967295,RZ=new Uint32Array;function LQ($,Z,J,Q,X,Y,W,V){let q=X.length,N=new Uint8Array($$),z=G0(N),P=D$(X)&&D$(Y),O=P?G0(X):RZ,K=P?G0(Y):RZ;for(let H=0;H<q;W++){if($(Z,J,Q,z,W,V),W>=HZ)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<jQ;C++)D=U+C,K[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 FZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:X,counterRight:Y,rounds:W}=PZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return a0(X),a0(W),C$(Y),C$(J),(V,q,N,z,P=0)=>{h(V),h(q),h(N);let O=N.length;if(z===void 0)z=new Uint8Array(O);if(h(z),a0(P),P<0||P>=HZ)throw Error("arx: counter overflow");if(z.length<O)throw Error(`arx: output (${z.length}) is shorter than data (${O})`);let K=[],H=V.length,F,U;if(H===32)K.push(F=e0(V)),U=AQ;else if(H===16&&J)F=new Uint8Array(32),F.set(V),F.set(V,16),U=DQ,K.push(F);else throw Error(`arx: invalid 32-byte key, got length=${H}`);if(!D$(q))K.push(q=e0(q));let C=G0(F);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(U,C,G0(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,K.push(q)}let j=G0(q);return LQ($,U,C,j,N,z,P,W),J0(...K),z}}var u=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class IZ{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($),h($,32);let Z=u($,0),J=u($,2),Q=u($,4),X=u($,6),Y=u($,8),W=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|W<<2)&8191,this.r[7]=(W>>>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,W=Y[0],V=Y[1],q=Y[2],N=Y[3],z=Y[4],P=Y[5],O=Y[6],K=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),R=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),i=X[9]+(p>>>5|Q),T=0,n=T+_*W+m*(5*F)+S*(5*H)+R*(5*K)+g*(5*O);T=n>>>13,n&=8191,n+=B*(5*P)+y*(5*z)+l*(5*N)+b*(5*q)+i*(5*V),T+=n>>>13,n&=8191;let a=T+_*V+m*W+S*(5*F)+R*(5*H)+g*(5*K);T=a>>>13,a&=8191,a+=B*(5*O)+y*(5*P)+l*(5*z)+b*(5*N)+i*(5*q),T+=a>>>13,a&=8191;let t=T+_*q+m*V+S*W+R*(5*F)+g*(5*H);T=t>>>13,t&=8191,t+=B*(5*K)+y*(5*O)+l*(5*P)+b*(5*z)+i*(5*N),T+=t>>>13,t&=8191;let k=T+_*N+m*q+S*V+R*W+g*(5*F);T=k>>>13,k&=8191,k+=B*(5*H)+y*(5*K)+l*(5*O)+b*(5*P)+i*(5*z),T+=k>>>13,k&=8191;let Y0=T+_*z+m*N+S*q+R*V+g*W;T=Y0>>>13,Y0&=8191,Y0+=B*(5*F)+y*(5*H)+l*(5*K)+b*(5*O)+i*(5*P),T+=Y0>>>13,Y0&=8191;let D0=T+_*P+m*z+S*N+R*q+g*V;T=D0>>>13,D0&=8191,D0+=B*W+y*(5*F)+l*(5*H)+b*(5*K)+i*(5*O),T+=D0>>>13,D0&=8191;let A0=T+_*O+m*P+S*z+R*N+g*q;T=A0>>>13,A0&=8191,A0+=B*V+y*W+l*(5*F)+b*(5*H)+i*(5*K),T+=A0>>>13,A0&=8191;let j0=T+_*K+m*O+S*P+R*z+g*N;T=j0>>>13,j0&=8191,j0+=B*q+y*V+l*W+b*(5*F)+i*(5*H),T+=j0>>>13,j0&=8191;let L0=T+_*H+m*K+S*O+R*P+g*z;T=L0>>>13,L0&=8191,L0+=B*N+y*q+l*V+b*W+i*(5*F),T+=L0>>>13,L0&=8191;let E0=T+_*F+m*H+S*K+R*O+g*P;T=E0>>>13,E0&=8191,E0+=B*z+y*N+l*q+b*V+i*W,T+=E0>>>13,E0&=8191,T=(T<<2)+T|0,T=T+n|0,n=T&8191,T=T>>>13,a+=T,X[0]=n,X[1]=a,X[2]=t,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 W=2;W<10;W++)$[W]+=Q,Q=$[W]>>>13,$[W]&=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 W=1;W<10;W++)J[W]=$[W]+Q,Q=J[W]>>>13,J[W]&=8191;J[9]-=8192;let X=(Q^1)-1;for(let W=0;W<10;W++)J[W]&=X;X=~X;for(let W=0;W<10;W++)$[W]=$[W]&X|J[W];$[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 W=1;W<8;W++)Y=($[W]+Z[W]|0)+(Y>>>16)|0,$[W]=Y&65535;J0(J)}update($){w$(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($){w$(this),zZ($,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 EQ($){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 A$=EQ(($)=>new IZ($));function _Q($,Z,J,Q,X,Y=20){let W=$[0],V=Z[0],q=Z[1],N=Z[2],z=Z[3],P=$[1],O=J[0],K=J[1],H=X,F=0,U=$[2],C=Z[4],D=Z[5],j=Z[6],w=Z[7],E=$[3],x=W,p=V,_=q,m=N,S=z,R=P,g=O,B=K,y=H,l=F,b=U,i=C,T=D,n=j,a=w,t=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(R+p|0,7),n^=I(l+R|0,9),p^=I(n+l|0,13),R^=I(p+n|0,18),a^=I(b+g|0,7),_^=I(a+b|0,9),g^=I(_+a|0,13),b^=I(g+_|0,18),m^=I(t+i|0,7),B^=I(m+t|0,9),i^=I(B+m|0,13),t^=I(i+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(R+S|0,7),B^=I(g+R|0,9),S^=I(B+g|0,13),R^=I(S+B|0,18),i^=I(b+l|0,7),y^=I(i+b|0,9),l^=I(y+i|0,13),b^=I(l+y|0,18),T^=I(t+a|0,7),n^=I(T+t|0,9),a^=I(n+T|0,13),t^=I(a+n|0,18);let k=0;Q[k++]=W+x|0,Q[k++]=V+p|0,Q[k++]=q+_|0,Q[k++]=N+m|0,Q[k++]=z+S|0,Q[k++]=P+R|0,Q[k++]=O+g|0,Q[k++]=K+B|0,Q[k++]=H+y|0,Q[k++]=F+l|0,Q[k++]=U+b|0,Q[k++]=C+i|0,Q[k++]=D+T|0,Q[k++]=j+n|0,Q[k++]=w+a|0,Q[k++]=E+t|0}function kQ($,Z,J,Q){let X=$[0],Y=Z[0],W=Z[1],V=Z[2],q=Z[3],N=$[1],z=J[0],P=J[1],O=J[2],K=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),K^=I(N+Y|0,7),C^=I(K+N|0,9),Y^=I(C+K|0,13),N^=I(Y+C|0,18),D^=I(H+z|0,7),W^=I(D+H|0,9),z^=I(W+D|0,13),H^=I(z+W|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),W^=I(Y+X|0,9),V^=I(W+Y|0,13),X^=I(V+W|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+K|0,7),O^=I(F+H|0,9),K^=I(O+F|0,13),H^=I(K+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++]=K}var j$=FZ(_Q,{counterRight:!0,extendNonceFn:kQ}),L$=OZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=T$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32);Q.set(J,32),J0(X),j$($,Z,Q,Q);let W=A$(Y,X);return Q.set(W,16),J0(Q.subarray(0,16),W),Q.subarray(16)},decrypt(J,Q){h(J),Q=T$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32,48),W=Q.subarray(48);Q.set(J,32),J0(X);let V=j$($,Z,X,X),q=A$(W,V);if(!MZ(Y,q))throw Error("invalid tag");return j$($,Z,Q.subarray(16),Q.subarray(16)),J0(X,Y,q),W}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function mQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function i0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function R0($,...Z){if(!mQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function h0($,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){R0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function UZ($){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 wZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function CZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var TZ=wZ?($)=>$:($)=>CZ($);function BQ($){for(let Z=0;Z<$.length;Z++)$[Z]=CZ($[Z]);return $}var s=wZ?($)=>$:BQ;function xQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function m0($){if(typeof $==="string")$=xQ($);return R0($),$}class E${}function DZ($){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 AZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J$=BigInt(4294967295),jZ=BigInt(32);function _$($,Z=!1){if(Z)return{h:Number($&J$),l:Number($>>jZ&J$)};return{h:Number($>>jZ&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 k$ extends E${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,i0($),i0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=_0(this.buffer)}update($){h0(this),$=m0($),R0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,X=$.length,Y=$.byteOffset,W=$.buffer;for(let V=0;V<X;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(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(W,N,Math.floor((X-V)/4));s(z);for(let P=0;V+Z<X;P+=Q.length,V+=Z)this.length+=Z,this.compress(z,P,!1);s(z);continue}J.set($.subarray(V,V+q),this.pos),this.pos+=q,this.length+=q,V+=q}return this}digestInto($){h0(this),Z$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,k0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=_0($);this.get().forEach((X,Y)=>Q[Y]=TZ(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:W}=this;return $||($=new this.constructor({dkLen:Y})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=X,$.finished=Q,$.length=J,$.pos=W,$.outputLen=Y,$}clone(){return this._cloneInto()}}function m$($,Z,J,Q,X,Y,W,V,q,N,z,P,O,K,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:K,d:C}=V0(Y,N,K,C,J[Z+$[w++]]),{a:Y,b:N,c:K,d:C}=q0(Y,N,K,C,J[Z+$[w++]]),{a:W,b:z,c:H,d:D}=V0(W,z,H,D,J[Z+$[w++]]),{a:W,b:z,c:H,d:D}=q0(W,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:W,b:P,c:O,d:C}=V0(W,P,O,C,J[Z+$[w++]]),{a:W,b:P,c:O,d:C}=q0(W,P,O,C,J[Z+$[w++]]),{a:V,b:q,c:K,d:D}=V0(V,q,K,D,J[Z+$[w++]]),{a:V,b:q,c:K,d:D}=q0(V,q,K,D,J[Z+$[w++]]);return{v0:X,v1:Y,v2:W,v3:V,v4:q,v5:N,v6:z,v7:P,v8:O,v9:K,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=AZ.slice(),LZ=(()=>{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 B$ extends k${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();R0(Y,32),this.IV=_0(Y),s(this.IV),this.flags=Z|Q0.KEYED_HASH}else if(X){let Y=m0(Q),W=new B$({dkLen:32},Q0.DERIVE_KEY_CONTEXT).update(Y).digest();this.IV=_0(W),s(this.IV),this.flags=Z|Q0.DERIVE_KEY_MATERIAL}else this.IV=N0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=UZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:X,pos:Y}=this,{h:W,l:V}=_$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:P,v4:O,v5:K,v6:H,v7:F,v8:U,v9:C,v10:D,v11:j,v12:w,v13:E,v14:x,v15:p}=m$(LZ,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],W,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]=K^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,W=this.chunksDone+1;J||!(W&1);W>>=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:W,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=W,$.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:W}=_$(BigInt(this.chunkOut++));s(Q);let{v0:V,v1:q,v2:N,v3:z,v4:P,v5:O,v6:K,v7:H,v8:F,v9:U,v10:C,v11:D,v12:j,v13:w,v14:E,v15:x}=m$(LZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],N0[0],N0[1],N0[2],N0[3],W,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]=K^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,s(Q),s(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,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Q0.CHUNK_START:0)|Q0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){h0(this,!1),R0($),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 i0($),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 EZ=DZ(($)=>new B$($));function r($){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 mZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var _Z;if(typeof Uint8Array.prototype.toBase64==="function")_Z=($)=>$.toBase64();else _Z=($)=>btoa(String.fromCharCode(...$));var kZ;if(typeof Uint8Array.fromBase64==="function")kZ=($)=>Uint8Array.fromBase64($);else kZ=($)=>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 x$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function BZ($){let Z=new Uint8Array(x$.length+32);return Z.set(x$),Z.set($.subarray(0,32),x$.length),Z}function xZ($){return typeof $==="string"?new TextEncoder().encode($):$}function B0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class S${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return t0($)}async gen256BitSecureRandomSeed(){return t0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=t0(24),X=L$(Z,J).encrypt($);return new Uint8Array([...J,...X])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return L$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=BZ(Z),Q=await globalThis.crypto.subtle.importKey("pkcs8",B0(J),{name:"Ed25519"},!0,["sign"]),X=await globalThis.crypto.subtle.exportKey("jwk",Q);if(typeof X.x!=="string")throw Error("Ed25519 JWK missing x");let Y=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:X.x},{name:"Ed25519"},!0,["verify"]),W=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",Y)),V=new Uint8Array(64);return V.set(Z,0),V.set(W,32),this.signKeys.set(r(Z),Q),this.verifyKeys.set(r(W),Y),{keyType:"ed25519",privateKey:V,publicKey:W}}async importSignKey($){let Z=$.subarray(0,32),J=r(Z),Q=this.signKeys.get(J);if(Q)return Q;let X=BZ(Z),Y=await globalThis.crypto.subtle.importKey("pkcs8",B0(X),{name:"Ed25519"},!1,["sign"]);return this.signKeys.set(J,Y),Y}async importVerifyKey($){let Z=r($),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=xZ($),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=xZ(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 EZ($)}}var SQ=new S$,K0=SQ;var x0=64;var SZ=32,S0=8;var gZ=32;var fZ=30000,vZ=512,A;((R)=>{R[R.Success=0]="Success";R[R.InvalidSignature=3]="InvalidSignature";R[R.ClockOutOfSync=4]="ClockOutOfSync";R[R.UserNotRegistered=5]="UserNotRegistered";R[R.ServerMisconfigured=6]="ServerMisconfigured";R[R.MissingBody=7]="MissingBody";R[R.ExtraBodyContent=8]="ExtraBodyContent";R[R.MissingParam=9]="MissingParam";R[R.InvalidParam=10]="InvalidParam";R[R.InvalidRequest=11]="InvalidRequest";R[R.InternalError=12]="InternalError";R[R.NotFound=13]="NotFound";R[R.InvalidMessage=14]="InvalidMessage";R[R.NoChange=15]="NoChange";R[R.DatabaseClosed=16]="DatabaseClosed";R[R.StorageError=17]="StorageError";R[R.DatabaseError=18]="DatabaseError";R[R.HashMismatch=19]="HashMismatch";R[R.DecryptionError=20]="DecryptionError";R[R.NotImplemented=21]="NotImplemented";R[R.MissingSeed=22]="MissingSeed";R[R.OutOfBounds=23]="OutOfBounds";R[R.HostError=24]="HostError";R[R.CommunicationError=25]="CommunicationError";R[R.VarLimitExceeded=26]="VarLimitExceeded";R[R.InvalidResponse=27]="InvalidResponse";R[R.ConnectionClosed=28]="ConnectionClosed"})(A||={});var yZ="t";function M($){return[$,0]}function G($){return[void 0,$]}function gQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return G(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 G(26);return M(new Uint8Array(Z))}function fQ($,Z=0){let J=0n,Q=0,X=Z;while(!0){if(X>=$.length)return G(14);let Y=$[X++];if(Y===void 0)return G(14);if(J|=BigInt(Y&127)<<BigInt(Q),(Y&128)===0){if(X-Z>8)return G(26);return M({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:X-Z})}if(Q+=7,Q>=56)return G(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 G(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 G(Z);return M(new Date($))}readVarInt(){let[$,Z]=fQ(this.data,this.pos);if(Z!==0)return G(Z);this.pos+=$.bytesRead;let J=$.value;return M(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);let[J,Q]=this.readBytes($);if(Q!==0)return G(Q);let X=new TextDecoder().decode(J);return M(X)}readBytes($){if($<0)return G(10);if(this.pos+$>this.data.length)return G(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,M(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return G(Q);Z.push(J)}return M(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return G(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]=gQ($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($.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 G(J);let[Q,X]=$.readDate();if(X!==0)return G(X);return M({id:Z,ts:Q})}};function lZ($){let Z=new L,J=Z.writeStruct(d0,$);if(J!==0)return G(J);let Q=Z.result();return M(Q)}var g$={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 G(J);let Q=new f(Z),[,X]=d0.decode(Q);if(X!==0)return G(X);let[Y,W]=$.readVarInt();if(W!==0)return G(W);let[V,q]=$.readVarInt();if(q!==0)return G(q);let[N,z]=$.readVarInt();if(z!==0)return G(z);let P;if(N>0){let[O,K]=$.readBytes(gZ);if(K!==0)return G(K);P=O}return M({eid:Z,off:Y,ctr:V,len:N,hsh:P})}};function bZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function iZ($,Z,J,Q){let X;if($.bod&&$.len>0)X=await J.blake3($.bod);let Y=new L,W=g$.encode(Y,{...$,hsh:X});if(W!==0)return G(W);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 hZ($,Z,J,Q,X){let Y=new f($),[W,V]=g$.decode(Y);if(V!==0)return G(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return G(20)}let N=W.hsh&&q===void 0,z=W.hsh===void 0&&q!==void 0;if(N||z)return G(19);if(W.hsh&&q){let O=await Q.blake3(q);if(!mZ(O,W.hsh))return G(19)}let P=X??await Q.blake3($);return M({msgHead:W,bod:q,headHash:P})}async function f$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return G(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)>fZ)return 4;let W=new L;W.writeDate($.timestamp);let V=W.result();if(!await Z.checkSigEd25519($.sig,V,$.pubKey))return 3;return 0}class g0{now(){return new Date}}function pZ($,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 G(J);let Q;if(Z>0){let[X,Y]=$.readVarInt();if(Y!==0)return G(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 W=$.writeStruct(n0,Z.subscription.stat);if(W!==0)return W;let V=$.writeStruct(n0,Z.subscription.dyn);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return G(J);let Q=Z[0],[X,Y]=$.readDate();if(Y!==0)return G(Y);let[W,V]=$.readDate();if(V!==0)return G(V);let[q,N]=$.readVarInt();if(N!==0)return G(N);let[z,P]=$.readVarInt();if(P!==0)return G(P);let[O,K]=$.readStruct(n0);if(K!==0)return G(K);let[H,F]=$.readStruct(n0);if(F!==0)return G(F);return M({status:Q,timeRcvd:X,timeSent:W,subscription:{term:q,elapsed:z,stat:O,dyn:H}})}};var v$={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 G(J);let[Q,X]=$.readVarInt();if(X!==0)return G(X);return M({headCph:Z,seq:Q})}};var o={encode($,Z){$.writeBytes(Z.pubKey),$.writeBytes(Z.sig);let J=$.writeDate(Z.timestamp);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(SZ);if(J!==0)return G(J);let[Q,X]=$.readBytes(x0);if(X!==0)return G(X);let[Y,W]=$.readDate();if(W!==0)return G(W);return M({pubKey:Z,sig:Q,timestamp:Y})}};var uZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(o,J);if(Y!==0)return Y;for(let W of Q)X.writeVarInt(W);return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[W,V]=Z.readStruct(o);if(V!==0)return V;let q=await $0(W,X,Q);if(q!==0)return q;let{pubKey:N}=W,[z,P]=await Y.hasUser(N);if(P!==0)return P;if(!z)return 5;let[O,K]=Z.readVarInt();if(K!==0)return K;if(!Z.done())return 8;let[H,F]=await Y.listHeads(N,O);if(F!==0)return F;return J.writeStructs(v$,H)},decodeResp($){return $.readStructs(v$)}};var y$={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 G(J);let[Q,X]=$.readVarBytes();if(X!==0)return G(X);return M({seq:Z,bodyCph:Q})}};var dZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(o,J);if(Y!==0)return Y;for(let W of Q){let V=X.writeVarInt(W);if(V!==0)return V}return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[W,V]=Z.readStruct(o);if(V!==0)return V;let q=await $0(W,X,Q);if(q!==0)return q;let{pubKey:N}=W,[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[K,H]=await Y.getBodies(N,O);if(H!==0)return H;if(!K)return 17;for(let{seq:F,bodyCph:U}of K){let C={seq:F,bodyCph:U},D=J.writeStruct(y$,C);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(y$)}};var l$={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 G(J);let[Q,X]=$.readBytes(S0);if(X!==0)return G(X);let[Y,W]=$.readVarBytes();if(W!==0)return G(W);let[V,q]=$.readVarBytes();if(q!==0)return G(q);return M({sig:Z,kdm:Q,headCph:Y,bodyCph:V})}};var b$={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 G(J);let[Q,X]=$.readVarBytes();if(X!==0)return G(X);let[Y,W]=$.readVarInt();if(W!==0)return G(W);let V;if(Y>0){let[q,N]=$.readBytes(Y);if(N!==0)return G(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 G(J);let[Q,X]=$.readBytes(S0);if(X!==0)return G(X);let[Y,W]=$.readVarBytes();if(W!==0)return G(W);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 G(J);let[Q,X]=$.readBytes(1);if(X!==0)return G(X);let Y=Q[0];if(Y!==0)return M({idx:Z,status:Y});let[W,V]=$.readVarInt();if(V!==0)return G(V);return M({idx:Z,status:Y,seq:W})}};var nZ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(o,J);if(Y!==0)return Y;let W=X.writeStructs(l$,Q);if(W!==0)return W;return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y,notifier:W}=$,[V,q]=Z.readStruct(o);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[K,H]=Z.readStructs(l$);if(H!==0)return H;console.info(`PUSH: ${K.length} bags`);let F=[],U=[];for(let w=0;w<K.length;w++){let E=K[w];if(!await bZ(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(),R={seq:p,headCph:S};if(K.length===1&&E.bodyCph.length<=vZ)R.bodyCph=E.bodyCph;j.push(R);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(b$,j);if(E!==0)return E;let x=w.result();await Promise.resolve(W.push(z,x))}return 0},decodeResp($){return $.readStructs(X$)}};var cZ={async encodeReq($,Z,J,Q,X){return X.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[W,V]=Z.readStruct(o);if(V!==0)return V;let q=await $0(W,X,Q);if(q!==0)return q;let{pubKey:N}=W;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(o,$);let W=Y.result(),V=r(W);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:cZ,name:0},push:{path:"/push",endpoint:nZ,name:2},peek:{path:"/peek",endpoint:uZ,name:1},pull:{path:"/pull",endpoint:dZ,name:3}},vQ={0:d.user,2:d.push,1:d.peek,3:d.pull},rZ={[d.user.path]:d.user,[d.push.path]:d.push,[d.peek.path]:d.peek,[d.pull.path]:d.pull};class oZ{url;listener;constructor($){this.url=$;this.listener=new i$($)}async call($,Z){let{path:J}=vQ[$],Q=new URL(J,this.url);try{return await lQ(Q,Z)}catch{return G(25)}}}var h$=($)=>{return new oZ($.handle)};function y0($){let Z=new L;if(Z.writeStruct(f0,$)!==0)return new Response(null,{status:500});return p$(Z)}function p$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var yQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function u$($){return new Response($.body,{headers:{...$.headers,...yQ},status:$.status,statusText:$.statusText})}async function lQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return G(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}=$,W=await this.identity(),V=J.now(),[q,N]=await f$(W,V);if(N!==0)return G(N);let z=new L,P=await X.encodeReq(this,W,q,Z,z);if(P!==0)return G(P);let O=J.now(),[K,H]=await Q.call(Y,z),F=J.now();if(H!==0)return G(H);let[U,C]=K.readStruct(f0);if(C!==0)return G(C);if(U.status!==0)return G(U.status);let j={clockOffset:pZ(O,U.timeRcvd,U.timeSent,F),subscription:U.subscription},w=await this.updateHostMeta(j);if(w!==0)return G(w);return X.decodeResp(K)}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 iZ($,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,W=await this.identity(),V=Q.now(),[q,N]=await f$(W,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 CV=Symbol("MasterSeed"),TV=Symbol("SealedMasterKey"),X0=32,aZ=24+X0+16;function e($){if($.byteLength!==X0)return G(10);return M($)}function W$($){if($.byteLength!==aZ)return G(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 G(J);let[Q,X]=$.readVarString();if(X!==0)return G(X);let[Y,W]=$.readVarInt();if(W!==0)return G(W);return M({handle:Z,label:Q,idx:Y})}};var G$=1,d$={encode($,Z){if(Z.v!==G$)return 10;let[,J]=e(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 W=$.writeStruct(H0,Y);if(W!==0)return W}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);if(Z!==G$)return G(14);let[Q,X]=$.readBytes(X0);if(X!==0)return G(X);if(Q===void 0)return G(14);let[Y,W]=e(Q);if(W!==0)return G(W);if(Y===void 0)return G(14);let[V,q]=$.readVarInt();if(q!==0)return G(q);if(V===void 0||V<0)return G(10);let N=[];for(let z=0;z<V;z++){let[P,O]=$.readStruct(H0);if(O!==0)return G(O);if(P===void 0)return G(14);N.push(P)}return M({v:G$,masterSeed:Y,hosts:N})}};function sZ($,Z){let[J,Q]=e($);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[X,Y]=e(J.slice());if(Y!==0)return G(Y);if(X===void 0)return G(10);return M({v:G$,masterSeed:X,hosts:Z.map((W)=>({handle:W.handle,label:W.label,idx:W.idx??0}))})}var n$={encode($,Z){let[,J]=e(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 G(J);if(Z===void 0)return G(14);let[Q,X]=e(Z);if(X!==0)return G(X);if(Q===void 0)return G(14);let[Y,W]=$.readVarInt();if(W!==0)return G(W);if(Y===void 0||Y<0)return G(10);let V=[];for(let q=0;q<Y;q++){let[N,z]=$.readStruct(H0);if(z!==0)return G(z);if(N===void 0)return G(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,bQ=-7,iQ=-8,hQ=-257,V$=[{type:"public-key",alg:bQ},{type:"public-key",alg:iQ},{type:"public-key",alg:hQ}];function pQ($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function I0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z.buffer}function eZ($){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 G(9);return M(pQ(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 G(27);return M($)}async function tZ($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let X=$?.userName??"diplomatic-seed",Y={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)Y.authenticatorAttachment=$.authenticatorAttachment;let W={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:W}})}catch{return G(24)}let[q,N]=C0(V);if(N!==0)return G(N);if(q===void 0)return G(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return G(24);return M(new Uint8Array(q.rawId))}async function c$($,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 W={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:W}})}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 $J($,Z){let J=w0();if(J!==0)return G(J);let[Q,X]=U0(Z);if(X!==0)return G(X);if(Q===void 0)return G(9);let Y={largeBlob:{read:!0}},W;try{let O={challenge:z0(F0),rpId:Q,userVerification:"required",extensions:Y};if($!==void 0)O.allowCredentials=[{type:"public-key",id:I0($)}];W=await navigator.credentials.get({publicKey:O})}catch{return G(24)}let[V,q]=C0(W);if(q!==0)return G(q);if(V===void 0)return G(27);let z=V.getClientExtensionResults().largeBlob;if(z===void 0||z.blob===void 0)return G(7);let P=eZ(z.blob);if(P.byteLength===0)return G(7);return M({blob:P,credId:new Uint8Array(V.rawId)})}var q$=new TextEncoder().encode("diplomatic.prf.v1"),r$=32;async function ZJ($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let X=$?.userName??"diplomatic-prf",Y={residentKey:"required",requireResidentKey:!0,userVerification:"required",authenticatorAttachment:$?.authenticatorAttachment??"platform"},W;try{W=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 G(24)}let[V,q]=C0(W);if(q!==0)return G(q);if(V===void 0)return G(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 G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let X=$?.salt??q$,Y=I0(X),W={challenge:z0(F0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:Y}}}};if($?.credId!==void 0)W.allowCredentials=[{type:"public-key",id:I0($.credId)}];let V;try{V=await navigator.credentials.get({publicKey:W})}catch{return G(24)}let[q,N]=C0(V);if(N!==0)return G(N);if(q===void 0)return G(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return G(7);let P=z.first,O=P instanceof ArrayBuffer?new Uint8Array(P):new Uint8Array(P.buffer,P.byteOffset,P.byteLength),K=O.byteLength>=r$?O.slice(0,r$):O;if(K.byteLength!==r$)return G(27);return M({prf:K,credId:new Uint8Array(q.rawId)})}var N$="";var z$;function dQ(){if(typeof N$!=="string"||N$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(N$)}function nQ(){if(z$!==void 0)return z$;let $=new Blob([dQ()],{type:"text/javascript"});return z$=URL.createObjectURL($),z$}function JJ(){if(typeof Worker>"u")throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new Worker(nQ(),{type:"module"})}var cQ=new TextEncoder().encode("diplomatic.wrap.v1"),rQ=32,oQ=16;class Z0{#Z;#$;constructor($,Z){this.#Z=$,this.#$=Z}static async fromRandom($){let Z=await $.gen256BitSecureRandomSeed(),[J,Q]=e(Z);if(Q!==0||J===void 0)throw Error(`enclave: invalid random seed (${Q})`);return new Z0(J,$)}static fromBytes($,Z){let[J,Q]=e(Z);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[X,Y]=e(J.slice());if(Y!==0)return G(Y);if(X===void 0)return G(10);return M(new Z0(X,$))}async sealWithPasskey($){let Z=$?.salt??q$,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[Y,W]=await ZJ({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf"});if(W!==0)return G(W);if(Y===void 0)return G(24);if(!Y.prfEnabled)return G(24);J=Y.credId}let[Q,X]=await c0({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z});if(X!==0)return G(X);if(Q===void 0)return G(7);try{let[Y,W]=await this.#X(Q.prf);if(W!==0)return G(W);if(Y===void 0)return G(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 G(X);if(Q===void 0)return G(7);try{let[Y,W]=await Z0.#Y($,Z,Q.prf);if(W!==0)return G(W);if(Y===void 0)return G(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,W]=await tZ(Z);if(W!==0)return G(W);if(Y===void 0)return G(24);J=Y}let[Q,X]=this.#W($);if(X!==0)return G(X);if(Q===void 0)return G(12);try{let Y=await c$(J,Q,Z);if(Y!==0)return G(Y);return M(J)}finally{Q.fill(0)}}static async fromLargeBlob($,Z){let[J,Q]=await $J(Z?.credId,Z);if(Q!==0)return G(Q);if(J===void 0)return G(7);try{return Z0.#G($,J.blob,J.credId)}finally{J.blob.fill(0)}}static async clearLargeBlob($,Z){return c$($,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 G(X);if(Q===void 0)return G(7);try{let[Y,W]=await P$(this.#$,Q.prf);if(W!==0)return G(W);if(Y===void 0)return G(12);let[V,q]=e(this.#Z.slice());if(q!==0)return G(q);if(V===void 0)return G(10);let N={masterSeed:V,hosts:$.map((H)=>({handle:H.handle,label:H.label,idx:H.idx??0}))},z=new L,P=z.writeStruct(n$,N);if(P!==0)return V.fill(0),G(P);let O=z.result();V.fill(0);let K;try{K=await this.#$.encryptXSalsa20Poly1305Combined(O,Y)}catch{return O.fill(0),G(12)}return O.fill(0),M({body:K,salt:J.slice(),credId:Q.credId.slice()})}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 G(X);if(Q===void 0)return G(7);try{let[Y,W]=await P$($,Q.prf);if(W!==0)return G(W);if(Y===void 0)return G(12);let V;try{V=await $.decryptXSalsa20Poly1305Combined(Z,Y)}catch{return G(20)}let q=new f(V),[N,z]=q.readStruct(n$);if(V.fill(0),z!==0)return G(z);if(N===void 0)return G(14);let[P,O]=Z0.fromBytes($,N.masterSeed);if(N.masterSeed.fill(0),O!==0)return G(O);if(P===void 0)return G(12);let[K,H]=await P.#X(Q.prf);if(H!==0)return G(H);if(K===void 0)return G(12);return M({enclave:P,hosts:N.hosts.map((F)=>({...F})),sealedMaster:K,credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}spawnSyncWorker($){let Z=JJ(),J=this.#Z.slice();return Z.postMessage({id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(W)=>this.#V(J,W),X=(W)=>this.#q(J,W);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);return Object.freeze({publicKey:X.publicKey,sign:(Y)=>this.#z(J,Q,Y),kdmFor:(Y)=>this.#P(J,Q,Y)})}async#X($){let[Z,J]=await P$(this.#$,$);if(J!==0)return G(J);if(Z===void 0)return G(12);try{let Q=await this.#$.encryptXSalsa20Poly1305Combined(this.#Z,Z);return W$(Q)}catch{return G(12)}}static async#Y($,Z,J){let[,Q]=W$(Z);if(Q!==0)return G(Q);let[X,Y]=await P$($,J);if(Y!==0)return G(Y);if(X===void 0)return G(12);try{let W=await $.decryptXSalsa20Poly1305Combined(Z,X);return Z0.fromBytes($,W)}catch{return G(20)}}#W($){let[Z,J]=e(this.#Z.slice());if(J!==0)return G(J);if(Z===void 0)return G(10);let[Q,X]=sZ(Z,$);if(Z.fill(0),X!==0)return G(X);if(Q===void 0)return G(12);try{let Y=new L,W=Y.writeStruct(d$,Q);if(W!==0)return G(W);return M(Y.result())}finally{Q.masterSeed.fill(0)}}static#G($,Z,J){if(Z.byteLength===0||Z.every((W)=>W===0))return G(22);if(Z.byteLength===X0){if(Z.every((q)=>q===0))return G(22);let[W,V]=Z0.fromBytes($,Z);if(V!==0)return G(V);if(W===void 0)return G(12);return M({enclave:W,hosts:[],credId:J})}let Q=new f(Z),[X,Y]=Q.readStruct(d$);if(Y!==0)return G(Y);if(X===void 0)return G(14);try{if(X.masterSeed.every((q)=>q===0))return G(22);let[W,V]=Z0.fromBytes($,X.masterSeed);if(V!==0)return G(V);if(W===void 0)return G(12);return M({enclave:W,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);return this.#$.deriveEd25519KeyPair(J)}async#z($,Z,J){let Q=await this.#Q($,Z);return this.#$.signEd25519(J,Q.privateKey)}async#P($,Z,J){let Q=await this.#Q($,Z),X=u0(Q.privateKey,J);return(await this.#$.blake3(X)).slice(0,S0)}}async function P$($,Z){if(Z.byteLength<oQ)return G(10);let J=await $.blake3(u0(Z,cQ));return M(J.slice(0,rQ))}class o${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 QJ($,Z,J,Q=0){let X=Z.now(),Y=new L,W=Y.writeVarString($);if(W!==0)return G(W);let q={id:Y.result(),ts:new Date(0)},[N,z]=lZ(q);if(z!==0)return G(z);let P=X.getTime()-q.ts.getTime();return M({eid:N,off:P,ctr:Q,len:J.length,bod:J})}class aQ{singletonType;latest;latestOff=-1;emitter=new o$;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 W=Y.result();if(Q.id.length===W.length&&Q.id.every((V,q)=>V===W[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 XJ($,Z,J,Q){let X=new f($.headCph),[Y,W]=X.readStruct(v0);if(W!==0)return G(W);let{sig:V,kdm:q,headCph:N}=Y;if(!await Q.checkSigEd25519(V,N,Z))return G(3);let P=J.deriveCipher(q,"decrypt"),O;try{O=await P.decrypt(N)}catch{return G(20)}return M({kdm:q,headEnc:O})}var b0=FQ(YQ(),1),RY={encode:b0.encode,decode:b0.decode,decodeAsync:b0.decodeAsync},KY=RY;import{Database as HY}from"bun:sqlite";var G8=Symbol("EntityID");var V8=Symbol("DerivationSeed"),q8=Symbol("PublicKey"),N8=Symbol("PrivateKey"),z8=Symbol("HostSpecificKeyPair"),P8=Symbol("Hash"),M0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function FY($="diplomatic.db"){let Z=new HY($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  pubKey TEXT PRIMARY KEY
4
4
  );
@@ -11,4 +11,4 @@ var NQ=Object.create;var{getPrototypeOf:zQ,defineProperty:NZ,getOwnPropertyNames
11
11
  PRIMARY KEY (userPubKey, seq),
12
12
  UNIQUE (userPubKey, seq)
13
13
  );
14
- `),{async addUser(J){try{let Q=r(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),M(void 0)}catch{return G(17)}},async hasUser(J){try{let Q=r(J),V=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return M(Boolean(V?.ok))}catch{return G(17)}},async subMeta(J){return M(M0)},async setBags(J,Q){if(Q.length<1)return M([]);try{let V=r(J);Z.exec("BEGIN IMMEDIATE");try{let X=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(V),Y=X?X.m||0:0,W=[],q=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){Y+=1;let z=new L;z.writeStruct(v0,N),q.run(V,Y,z.result(),N.bodyCph),W.push(Y)}return Z.exec("COMMIT"),M(W)}catch(X){try{Z.exec("ROLLBACK")}catch{}throw X}}catch{return G(17)}},async getBodies(J,Q){if(Q.length<1)return M([]);try{let V=r(J),X=[],Y=100,W=99;for(let q=0;q<Q.length;q+=99){let N=Q.slice(q,q+99),z=N.map(()=>"?").join(","),I=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${z})`).all(V,...N);for(let P of I)if(P.bodyCph)X.push({seq:P.seq,bodyCph:new Uint8Array(P.bodyCph)})}return M(X)}catch{return G(17)}},async listHeads(J,Q){try{let V=r(J),X=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(V,Q);return M(X.map((Y)=>({seq:Y.seq,headCph:new Uint8Array(Y.headCph)})))}catch{return G(17)}}}}var FX=KX(),XQ=FX;class qZ{storage;crypto;notifier;clock;constructor($,Z,J,Q){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=Q}corsHandler=async($)=>{if($.method==="OPTIONS")return p$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),p$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=new URL($.url);if($.method!=="POST"){let N=Z.now();return y0({status:13,timeRcvd:J,timeSent:N,subscription:M0})}if(!$.body){let N=Z.now();return y0({status:7,timeRcvd:J,timeSent:N,subscription:M0})}let X=new Uint8Array(await $.arrayBuffer()),Y=new f(X),W=Q.pathname,q=rZ[W]?.endpoint;if(!q){let N=Z.now();return y0({status:13,timeRcvd:J,timeSent:N,subscription:M0})}try{let N=new L,z=await q.handleReq(this,Y,N),I=M0,P={status:z,timeRcvd:J,timeSent:this.clock.now(),subscription:I},O=new L;if(O.writeStruct(f0,P)!==0)return new Response(null,{status:500});if(z!==0){let F=Z.now();return y0({status:z,timeRcvd:J,timeSent:F,subscription:M0})}return N.prependBytes(O.result()),h$(N)}catch(N){let z=Z.now();return console.error(N),console.trace(),y0({status:12,timeRcvd:J,timeSent:z,subscription:M0})}}}async function YQ($,Z){let Q=new URL($.url).searchParams.get(yZ);if(!Q)return G(11);let V=Q$(Q),X=new f(V),[Y,W]=X.readStruct(o);if(W!==0)return G(11);let q=await $0(Y,Z.crypto,Z.clock);if(q!==0)return G(q);return M(Y)}class WQ{recvs=new Map;async open($,Z,J,Q){let V=await $0($,J,Q);if(V!==0)return{send:()=>V,shut:()=>V,status:V};let X=r($.pubKey);if(!this.recvs.has(X))this.recvs.set(X,new Set);return this.recvs.get(X)?.add(Z),{send:(Y)=>{return Z(Y),0},shut:()=>{return this.recvs.get(X)?.delete(Z),0},status:0}}async push($,Z){let J=r($),Q=this.recvs.get(J);if(Q)for(let V of Q)V(Z)}}var GQ=new WQ;async function HX($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new qZ(XQ,O0,GQ,new x0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,Q)=>{if(J.headers.get("upgrade")==="websocket"){let[V,X]=await YQ(J,Z);if(X!==0)return new Response("Unauthorized",{status:401});return Q.upgrade(J,{data:{authTS:V}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let Q=J.data.authTS;GQ.open(Q,(V)=>J.send(V),Z.crypto,Z.clock).then((V)=>{if(V.status!==0){J.close();return}J.channel=V})},message:(J,Q)=>{},close:(J)=>{J.channel?.shut()}}})}class qQ{enclave;conn;clock;constructor({enclave:$,clock:Z=new x0}){this.enclave=$,this.clock=Z}async connect($,Z){let J=new x0,Q=()=>Promise.resolve(0);this.conn=new X$(this.enclave,O0,$,J,Z,Q);let[,V]=await this.conn.register();return V}async push($){if(!this.conn)return G(28);let Z=[];for(let V of $){let[X,Y]=await this.conn.seal(V);if(Y!==0)return G(Y);Z.push(X)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return G(Q);return M(J)}async peek($){if(!this.conn)return G(28);return this.conn.peek($)}async pull($){if(!this.conn)return G(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return G(28);let J=await this.conn.identity(),[Q,V]=await QJ($,J.publicKey,this.enclave,O0);if(V!==0)return G(V);let X=this.enclave.deriveCipher(Q.kdm,"decrypt");return uZ(Q.headEnc,Z.bodyCph,X,O0)}async upsertSingletonSync($,Z){let[J,Q]=await JJ($,this.clock,Z);if(Q!==0)return Q;let[,V]=await this.push([J]);return V}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function UX({enclave:$,host:Z,transport:J}){let Q=new qQ({enclave:$}),V=await Q.connect(Z,J);return[Q,V]}async function QN({enclave:$,host:Z,transport:J}){let Q=J??u$(Z),[V,X]=await UX({enclave:$,host:Z,transport:Q});if(X!==0)console.error(`Failed to initialize CLI: ${A[X]}`),process.exit(1);return V}function VN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=Q$(Z),[Q,V]=Z0.fromBytes(O0,J);if(J.fill(0),V!==0||Q===void 0)console.error(`${$} must be 64 hex chars (32-byte master seed)`),process.exit(1);return Q}function XN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{HX as runBunHost,l$ as notifItemCodec,RX as msgpack,XN as loadHostOrPanic,VN as loadEnclaveOrPanic,QN as initCLIOrPanic,UX as initCLI,u$ as hostHTTPTransport,A as Status,f as Decoder,qQ as CLIClient};
14
+ `),{async addUser(J){try{let Q=r(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),M(void 0)}catch{return G(17)}},async hasUser(J){try{let Q=r(J),X=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return M(Boolean(X?.ok))}catch{return G(17)}},async subMeta(J){return M(M0)},async setBags(J,Q){if(Q.length<1)return M([]);try{let X=r(J);Z.exec("BEGIN IMMEDIATE");try{let Y=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(X),W=Y?Y.m||0:0,V=[],q=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){W+=1;let z=new L;z.writeStruct(v0,N),q.run(X,W,z.result(),N.bodyCph),V.push(W)}return Z.exec("COMMIT"),M(V)}catch(Y){try{Z.exec("ROLLBACK")}catch{}throw Y}}catch{return G(17)}},async getBodies(J,Q){if(Q.length<1)return M([]);try{let X=r(J),Y=[],W=100,V=99;for(let q=0;q<Q.length;q+=99){let N=Q.slice(q,q+99),z=N.map(()=>"?").join(","),P=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${z})`).all(X,...N);for(let O of P)if(O.bodyCph)Y.push({seq:O.seq,bodyCph:new Uint8Array(O.bodyCph)})}return M(Y)}catch{return G(17)}},async listHeads(J,Q){try{let X=r(J),Y=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(X,Q);return M(Y.map((W)=>({seq:W.seq,headCph:new Uint8Array(W.headCph)})))}catch{return G(17)}}}}var IY=FY(),WQ=IY;class qZ{storage;crypto;notifier;clock;constructor($,Z,J,Q){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=Q}corsHandler=async($)=>{if($.method==="OPTIONS")return u$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),u$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=new URL($.url);if($.method!=="POST"){let N=Z.now();return y0({status:13,timeRcvd:J,timeSent:N,subscription:M0})}if(!$.body){let N=Z.now();return y0({status:7,timeRcvd:J,timeSent:N,subscription:M0})}let Y=new Uint8Array(await $.arrayBuffer()),W=new f(Y),V=Q.pathname,q=rZ[V]?.endpoint;if(!q){let N=Z.now();return y0({status:13,timeRcvd:J,timeSent:N,subscription:M0})}try{let N=new L,z=await q.handleReq(this,W,N),P=M0,O={status:z,timeRcvd:J,timeSent:this.clock.now(),subscription:P},K=new L;if(K.writeStruct(f0,O)!==0)return new Response(null,{status:500});if(z!==0){let F=Z.now();return y0({status:z,timeRcvd:J,timeSent:F,subscription:M0})}return N.prependBytes(K.result()),p$(N)}catch(N){let z=Z.now();return console.error(N),console.trace(),y0({status:12,timeRcvd:J,timeSent:z,subscription:M0})}}}async function GQ($,Z){let Q=new URL($.url).searchParams.get(yZ);if(!Q)return G(11);let X=Q$(Q),Y=new f(X),[W,V]=Y.readStruct(o);if(V!==0)return G(11);let q=await $0(W,Z.crypto,Z.clock);if(q!==0)return G(q);return M(W)}class qQ{recvs=new Map;async open($,Z,J,Q){let X=await $0($,J,Q);if(X!==0)return{send:()=>X,shut:()=>X,status:X};let Y=r($.pubKey);if(!this.recvs.has(Y))this.recvs.set(Y,new Set);return this.recvs.get(Y)?.add(Z),{send:(W)=>{return Z(W),0},shut:()=>{return this.recvs.get(Y)?.delete(Z),0},status:0}}async push($,Z){let J=r($),Q=this.recvs.get(J);if(Q)for(let X of Q)X(Z)}}var VQ=new qQ;async function UY($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new qZ(WQ,K0,VQ,new g0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,Q)=>{if(J.headers.get("upgrade")==="websocket"){let[X,Y]=await GQ(J,Z);if(Y!==0)return new Response("Unauthorized",{status:401});return Q.upgrade(J,{data:{authTS:X}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let Q=J.data.authTS;VQ.open(Q,(X)=>J.send(X),Z.crypto,Z.clock).then((X)=>{if(X.status!==0){J.close();return}J.channel=X})},message:(J,Q)=>{},close:(J)=>{J.channel?.shut()}}})}class NQ{enclave;conn;clock;constructor({enclave:$,clock:Z=new g0}){this.enclave=$,this.clock=Z}async connect($,Z){let J=new g0,Q=()=>Promise.resolve(0);this.conn=new Y$(this.enclave,K0,$,J,Z,Q);let[,X]=await this.conn.register();return X}async push($){if(!this.conn)return G(28);let Z=[];for(let X of $){let[Y,W]=await this.conn.seal(X);if(W!==0)return G(W);Z.push(Y)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return G(Q);return M(J)}async peek($){if(!this.conn)return G(28);return this.conn.peek($)}async pull($){if(!this.conn)return G(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return G(28);let J=await this.conn.identity(),[Q,X]=await XJ($,J.publicKey,this.enclave,K0);if(X!==0)return G(X);let Y=this.enclave.deriveCipher(Q.kdm,"decrypt");return hZ(Q.headEnc,Z.bodyCph,Y,K0)}async upsertSingletonSync($,Z){let[J,Q]=await QJ($,this.clock,Z);if(Q!==0)return Q;let[,X]=await this.push([J]);return X}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function wY({enclave:$,host:Z,transport:J}){let Q=new NQ({enclave:$}),X=await Q.connect(Z,J);return[Q,X]}async function XN({enclave:$,host:Z,transport:J}){let Q=J??h$(Z),[X,Y]=await wY({enclave:$,host:Z,transport:Q});if(Y!==0)console.error(`Failed to initialize CLI: ${A[Y]}`),process.exit(1);return X}function YN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=Q$(Z),[Q,X]=Z0.fromBytes(K0,J);if(J.fill(0),X!==0||Q===void 0)console.error(`${$} must be 64 hex chars (32-byte master seed)`),process.exit(1);return Q}function WN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{UY as runBunHost,b$ as notifItemCodec,KY as msgpack,WN as loadHostOrPanic,YN as loadEnclaveOrPanic,XN as initCLIOrPanic,wY as initCLI,h$ as hostHTTPTransport,A as Status,f as Decoder,NQ as CLIClient};
@@ -29,6 +29,11 @@ export declare class Encoder {
29
29
  writeVarInt(n: number): Status;
30
30
  writeVarString(s: string): Status;
31
31
  prependBytes(bytes: Uint8Array): void;
32
+ /**
33
+ * Append a copy of `bytes`. Parts must not alias caller buffers — callers
34
+ * often zero sensitive material after encode (seed, PRF, etc.); holding a
35
+ * live reference would corrupt the eventual {@link result}.
36
+ */
32
37
  writeBytes(bytes: Uint8Array): void;
33
38
  writeVarBytes(bytes: Uint8Array): Status;
34
39
  writeStruct<T>(codec: ICodecStruct<T>, str: T): Status;
@@ -71,10 +71,14 @@ export declare class Enclave {
71
71
  /**
72
72
  * UV + PRF ceremony, then unseal durable master into a new Enclave.
73
73
  * Callers never supply PRF bytes — only sealed meta + RP/salt/credId.
74
+ * Returns the credential id used so stores can persist it (skip picker next time).
74
75
  */
75
76
  static unsealWithPasskey(crypto: ICrypto, sealedMaster: SealedMasterKey, opts: PasskeyPrfOpts & {
76
77
  salt: Uint8Array;
77
- }): Promise<ValStat<Enclave>>;
78
+ }): Promise<ValStat<{
79
+ enclave: Enclave;
80
+ credId: Uint8Array;
81
+ }>>;
78
82
  /**
79
83
  * UV + write IdentityBundle (seed + hosts) to largeBlob.
80
84
  * Encode and WebAuthn write complete inside this method; nothing seed-bearing
@@ -24,8 +24,15 @@ export type WebAuthnRp = {
24
24
  * Normalizes case and trailing dots. Empty → `"localhost"`.
25
25
  */
26
26
  export declare function defaultWebAuthnRpId(hostname: string): string;
27
- /** Copy into a fresh ArrayBuffer-backed view (DOM BufferSource typing). */
28
- export declare function copyToArrayBuffer(src: Uint8Array): Uint8Array;
27
+ /**
28
+ * Fresh standalone {@link ArrayBuffer} copy of `src`.
29
+ * Safari (and some Chromium paths) are picky about BufferSource for
30
+ * largeBlob write / allowCredentials id — pass a real ArrayBuffer, not a
31
+ * view into a larger pooled buffer.
32
+ */
33
+ export declare function copyToArrayBuffer(src: Uint8Array): ArrayBuffer;
34
+ /** Copy WebAuthn blob / BufferSource into an owned Uint8Array. */
35
+ export declare function bufferSourceToUint8(src: BufferSource): Uint8Array;
29
36
  /** Resolve RP id from opts or `location.hostname`. */
30
37
  export declare function resolveWebAuthnRpId(opts?: WebAuthnRp): ValStat<string>;
31
38
  /** Success if WebAuthn credentials API is available in this environment. */