@interncom/diplomatic 0.14.1 → 0.15.1

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,8 +1,8 @@
1
- var pQ=Object.create;var{getPrototypeOf:uQ,defineProperty:BZ,getOwnPropertyNames:dQ}=Object;var nQ=Object.prototype.hasOwnProperty;function cQ($){return this[$]}var rQ,oQ,aQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var X=Z?rQ??=new WeakMap:oQ??=new WeakMap,Y=X.get($);if(Y)return Y}J=$!=null?pQ(uQ($)):{};let V=Z||!$||!$.__esModule?BZ(J,"default",{value:$,enumerable:!0}):J;for(let W of dQ($))if(!nQ.call(V,W))BZ(V,W,{get:cQ.bind($,W),enumerable:!0});if(Q)X.set($,V);return V};var r=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var D$=r((hJ)=>{Object.defineProperty(hJ,"__esModule",{value:!0});hJ.utf8Count=uX;hJ.utf8EncodeJs=vJ;hJ.utf8EncodeTE=yJ;hJ.utf8Encode=cX;hJ.utf8DecodeJs=lJ;hJ.utf8DecodeTD=bJ;hJ.utf8Decode=sX;function uX($){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 vJ($,Z,J){let Q=$.length,X=J,Y=0;while(Y<Q){let V=$.charCodeAt(Y++);if((V&4294967168)===0){Z[X++]=V;continue}else if((V&4294965248)===0)Z[X++]=V>>6&31|192;else{if(V>=55296&&V<=56319){if(Y<Q){let W=$.charCodeAt(Y);if((W&64512)===56320)++Y,V=((V&1023)<<10)+(W&1023)+65536}}if((V&4294901760)===0)Z[X++]=V>>12&15|224,Z[X++]=V>>6&63|128;else Z[X++]=V>>18&7|240,Z[X++]=V>>12&63|128,Z[X++]=V>>6&63|128}Z[X++]=V&63|128}}var dX=new TextEncoder,nX=50;function yJ($,Z,J){dX.encodeInto($,Z.subarray(J))}function cX($,Z,J){if($.length>nX)yJ($,Z,J);else vJ($,Z,J)}var rX=4096;function lJ($,Z,J){let Q=Z,X=Q+J,Y=[],V="";while(Q<X){let W=$[Q++];if((W&128)===0)Y.push(W);else if((W&224)===192){let q=$[Q++]&63;Y.push((W&31)<<6|q)}else if((W&240)===224){let q=$[Q++]&63,z=$[Q++]&63;Y.push((W&31)<<12|q<<6|z)}else if((W&248)===240){let q=$[Q++]&63,z=$[Q++]&63,M=$[Q++]&63,N=(W&7)<<18|q<<12|z<<6|M;if(N>65535)N-=65536,Y.push(N>>>10&1023|55296),N=56320|N&1023;Y.push(N)}else Y.push(W);if(Y.length>=rX)V+=String.fromCharCode(...Y),Y.length=0}if(Y.length>0)V+=String.fromCharCode(...Y);return V}var oX=new TextDecoder,aX=200;function bJ($,Z,J){let Q=$.subarray(Z,Z+J);return oX.decode(Q)}function sX($,Z,J){if(J>aX)return bJ($,Z,J);else return lJ($,Z,J)}});var RZ=r((pJ)=>{Object.defineProperty(pJ,"__esModule",{value:!0});pJ.ExtData=void 0;class iJ{type;data;constructor($,Z){this.type=$,this.data=Z}}pJ.ExtData=iJ});var j$=r((dJ)=>{Object.defineProperty(dJ,"__esModule",{value:!0});dJ.DecodeError=void 0;class A$ extends Error{constructor($){super($);let Z=Object.create(A$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:A$.name})}}dJ.DecodeError=A$});var L$=r((cJ)=>{Object.defineProperty(cJ,"__esModule",{value:!0});cJ.UINT32_MAX=void 0;cJ.setUint64=YY;cJ.setInt64=VY;cJ.getInt64=GY;cJ.getUint64=WY;cJ.UINT32_MAX=4294967295;function YY($,Z,J){let Q=J/4294967296,X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function VY($,Z,J){let Q=Math.floor(J/4294967296),X=J;$.setUint32(Z,Q),$.setUint32(Z+4,X)}function GY($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function WY($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var IZ=r((ZQ)=>{Object.defineProperty(ZQ,"__esModule",{value:!0});ZQ.timestampExtension=ZQ.EXT_TIMESTAMP=void 0;ZQ.encodeTimeSpecToTimestamp=aJ;ZQ.encodeDateToTimeSpec=sJ;ZQ.encodeTimestampExtension=tJ;ZQ.decodeTimestampToTimeSpec=eJ;ZQ.decodeTimestampExtension=$Q;var OY=j$(),oJ=L$();ZQ.EXT_TIMESTAMP=-1;var KY=4294967295,HY=17179869183;function aJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=HY)if(Z===0&&$<=KY){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,oJ.setInt64)(Q,4,$),J}}function sJ($){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 tJ($){if($ instanceof Date){let Z=sJ($);return aJ(Z)}else return null}function eJ($){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,oJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new OY.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function $Q($){let Z=eJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}ZQ.timestampExtension={type:ZQ.EXT_TIMESTAMP,encode:tJ,decode:$Q}});var m$=r((XQ)=>{Object.defineProperty(XQ,"__esModule",{value:!0});XQ.ExtensionCodec=void 0;var E$=RZ(),CY=IZ();class PZ{static defaultCodec=new PZ;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(CY.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 E$.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 E$.ExtData(Y,X)}}}if($ instanceof E$.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 E$.ExtData(Z,$)}}XQ.ExtensionCodec=PZ});var UZ=r((VQ)=>{Object.defineProperty(VQ,"__esModule",{value:!0});VQ.ensureUint8Array=TY;function wY($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function TY($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(wY($))return new Uint8Array($);else return Uint8Array.from($)}});var wZ=r((qQ)=>{Object.defineProperty(qQ,"__esModule",{value:!0});qQ.Encoder=qQ.DEFAULT_INITIAL_BUFFER_SIZE=qQ.DEFAULT_MAX_DEPTH=void 0;var GQ=D$(),AY=m$(),WQ=L$(),jY=UZ();qQ.DEFAULT_MAX_DEPTH=100;qQ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class CZ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??AY.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??qQ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??qQ.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 CZ({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,GQ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,GQ.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,jY.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,WQ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,WQ.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}}qQ.Encoder=CZ});var KQ=r((OQ)=>{Object.defineProperty(OQ,"__esModule",{value:!0});OQ.encode=EY;var LY=wZ();function EY($,Z){return new LY.Encoder(Z).encodeSharedRef($)}});var FQ=r((HQ)=>{Object.defineProperty(HQ,"__esModule",{value:!0});HQ.prettyByte=_Y;function _Y($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var UQ=r((IQ)=>{Object.defineProperty(IQ,"__esModule",{value:!0});IQ.CachedKeyDecoder=void 0;var kY=D$(),xY=16,SY=16;class RQ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=xY,Z=SY){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 V=0;V<J;V++)if(Y[V]!==$[Z+V])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,kY.utf8DecodeJs)($,Z,J),Y=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(Y,X),X}}IQ.CachedKeyDecoder=RQ});var _$=r((AQ)=>{Object.defineProperty(AQ,"__esModule",{value:!0});AQ.Decoder=void 0;var TZ=FQ(),gY=m$(),m0=L$(),fY=D$(),CQ=UZ(),vY=UQ(),I0=j$(),DZ="array",J$="map_key",TQ="map_value",yY=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new I0.DecodeError("The type of key must be string or number but "+typeof $)};class DQ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=DZ,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=J$,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===DZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===J$||$.type===TQ){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 Z$=-1,AZ=new DataView(new ArrayBuffer(0)),lY=new Uint8Array(AZ.buffer);try{AZ.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 wQ=RangeError("Insufficient data"),bY=new vY.CachedKeyDecoder;class jZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=AZ;bytes=lY;headByte=Z$;stack=new DQ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??gY.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??m0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??m0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??m0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??m0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??m0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:bY,this.mapKeyConverter=$?.mapKeyConverter??yY}clone(){return new jZ({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=Z$,this.stack.reset()}setBuffer($){let Z=(0,CQ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===Z$&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,CQ.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 V of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(V);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:X,totalPos:Y}=this;throw RangeError(`Insufficient data in parsing ${(0,TZ.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 I0.DecodeError(`Unrecognized type byte: ${(0,TZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===DZ)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===J$){if(Z==="__proto__")throw new I0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=TQ;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=J$;continue $}}return Z}}readHeadByte(){if(this.headByte===Z$)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=Z$}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,TZ.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 wQ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,fY.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===J$;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new I0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw wQ;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,m0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,m0.getInt64)(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}AQ.Decoder=jZ});var mQ=r((EQ)=>{Object.defineProperty(EQ,"__esModule",{value:!0});EQ.decode=hY;EQ.decodeMulti=iY;var LQ=_$();function hY($,Z){return new LQ.Decoder(Z).decode($)}function iY($,Z){return new LQ.Decoder(Z).decodeMulti($)}});var xQ=r((kQ)=>{Object.defineProperty(kQ,"__esModule",{value:!0});kQ.isAsyncIterable=_Q;kQ.asyncIterableFromStream=BQ;kQ.ensureAsyncIterable=dY;function _Q($){return $[Symbol.asyncIterator]!=null}async function*BQ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function dY($){if(_Q($))return $;else return BQ($)}});var gQ=r((SQ)=>{Object.defineProperty(SQ,"__esModule",{value:!0});SQ.decodeAsync=oY;SQ.decodeArrayStream=aY;SQ.decodeMultiStream=sY;var LZ=_$(),EZ=xQ();async function oY($,Z){let J=(0,EZ.ensureAsyncIterable)($);return new LZ.Decoder(Z).decodeAsync(J)}function aY($,Z){let J=(0,EZ.ensureAsyncIterable)($);return new LZ.Decoder(Z).decodeArrayStream(J)}function sY($,Z){let J=(0,EZ.ensureAsyncIterable)($);return new LZ.Decoder(Z).decodeStream(J)}});var vQ=r((y)=>{Object.defineProperty(y,"__esModule",{value:!0});y.decodeTimestampExtension=y.encodeTimestampExtension=y.decodeTimestampToTimeSpec=y.encodeTimeSpecToTimestamp=y.encodeDateToTimeSpec=y.EXT_TIMESTAMP=y.ExtData=y.ExtensionCodec=y.Encoder=y.DecodeError=y.Decoder=y.decodeMultiStream=y.decodeArrayStream=y.decodeAsync=y.decodeMulti=y.decode=y.encode=void 0;var ZV=KQ();Object.defineProperty(y,"encode",{enumerable:!0,get:function(){return ZV.encode}});var fQ=mQ();Object.defineProperty(y,"decode",{enumerable:!0,get:function(){return fQ.decode}});Object.defineProperty(y,"decodeMulti",{enumerable:!0,get:function(){return fQ.decodeMulti}});var mZ=gQ();Object.defineProperty(y,"decodeAsync",{enumerable:!0,get:function(){return mZ.decodeAsync}});Object.defineProperty(y,"decodeArrayStream",{enumerable:!0,get:function(){return mZ.decodeArrayStream}});Object.defineProperty(y,"decodeMultiStream",{enumerable:!0,get:function(){return mZ.decodeMultiStream}});var JV=_$();Object.defineProperty(y,"Decoder",{enumerable:!0,get:function(){return JV.Decoder}});var QV=j$();Object.defineProperty(y,"DecodeError",{enumerable:!0,get:function(){return QV.DecodeError}});var XV=wZ();Object.defineProperty(y,"Encoder",{enumerable:!0,get:function(){return XV.Encoder}});var YV=m$();Object.defineProperty(y,"ExtensionCodec",{enumerable:!0,get:function(){return YV.ExtensionCodec}});var VV=RZ();Object.defineProperty(y,"ExtData",{enumerable:!0,get:function(){return VV.ExtData}});var n0=IZ();Object.defineProperty(y,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return n0.EXT_TIMESTAMP}});Object.defineProperty(y,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return n0.encodeDateToTimeSpec}});Object.defineProperty(y,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return n0.encodeTimeSpecToTimestamp}});Object.defineProperty(y,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return n0.decodeTimestampToTimeSpec}});Object.defineProperty(y,"encodeTimestampExtension",{enumerable:!0,get:function(){return n0.encodeTimestampExtension}});Object.defineProperty(y,"decodeTimestampExtension",{enumerable:!0,get:function(){return n0.decodeTimestampExtension}})});import*as q0 from"node:crypto";var C0=q0&&typeof q0==="object"&&"webcrypto"in q0?q0.webcrypto:q0&&typeof q0==="object"&&("randomBytes"in q0)?q0:void 0;function Q$($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function B$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function p($,...Z){if(!B$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function k$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function kZ($,Z){p($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function x$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var z0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var sQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!sQ)throw Error("Non little-endian hardware is not supported");function tQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function X$($){if(typeof $==="string")$=tQ($);else if(B$($))$=Y$($);else throw Error("Uint8Array expected, got "+typeof $);return $}function xZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function SZ($,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 gZ=($,Z)=>{function J(Q,...X){if(p(Q),$.nonceLength!==void 0){let M=X[0];if(!M)throw Error("nonce / iv required");if($.varSizeNonce)p(M);else p(M,$.nonceLength)}let Y=$.tagLength;if(Y&&X[1]!==void 0)p(X[1]);let V=Z(Q,...X),W=(M,N)=>{if(N!==void 0){if(M!==2)throw Error("cipher output not supported");p(N)}},q=!1;return{encrypt(M,N){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,p(M),W(V.encrypt.length,N),V.encrypt(M,N)},decrypt(M,N){if(p(M),Y&&M.length<Y)throw Error("invalid ciphertext length: smaller than tagLength="+Y);return W(V.decrypt.length,N),V.decrypt(M,N)}}}return Object.assign(J,$),J};function S$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!eQ(Z))throw Error("invalid output, must be aligned");return Z}function eQ($){return $.byteOffset%4===0}function Y$($){return Uint8Array.from($)}function X0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function r0($=32){if(C0&&typeof C0.getRandomValues==="function")return C0.getRandomValues(new Uint8Array($));if(C0&&typeof C0.randomBytes==="function")return C0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var vZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),$X=vZ("expand 16-byte k"),ZX=vZ("expand 32-byte k"),JX=z0($X),QX=z0(ZX);function U($,Z){return $<<Z|$>>>32-Z}function g$($){return $.byteOffset%4===0}var V$=64,XX=16,yZ=4294967295,fZ=new Uint32Array;function YX($,Z,J,Q,X,Y,V,W){let q=X.length,z=new Uint8Array(V$),M=z0(z),N=g$(X)&&g$(Y),K=N?z0(X):fZ,H=N?z0(Y):fZ;for(let I=0;I<q;V++){if($(Z,J,Q,M,V,W),V>=yZ)throw Error("arx: counter overflow");let R=Math.min(V$,q-I);if(N&&R===V$){let P=I/4;if(I%4!==0)throw Error("arx: invalid block position");for(let w=0,T;w<XX;w++)T=P+w,H[T]=K[T]^M[w];I+=V$;continue}for(let P=0,w;P<R;P++)w=I+P,Y[w]=X[w]^z[P];I+=R}}function lZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:X,counterRight:Y,rounds:V}=xZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return Q$(X),Q$(V),x$(Y),x$(J),(W,q,z,M,N=0)=>{p(W),p(q),p(z);let K=z.length;if(M===void 0)M=new Uint8Array(K);if(p(M),Q$(N),N<0||N>=yZ)throw Error("arx: counter overflow");if(M.length<K)throw Error(`arx: output (${M.length}) is shorter than data (${K})`);let H=[],I=W.length,R,P;if(I===32)H.push(R=Y$(W)),P=QX;else if(I===16&&J)R=new Uint8Array(32),R.set(W),R.set(W,16),P=JX,H.push(R);else throw Error(`arx: invalid 32-byte key, got length=${I}`);if(!g$(q))H.push(q=Y$(q));let w=z0(R);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(P,w,z0(q.subarray(0,16)),w),q=q.subarray(16)}let T=16-X;if(T!==q.length)throw Error(`arx: nonce must be ${T} or 16 bytes`);if(T!==12){let C=new Uint8Array(12);C.set(q,Y?0:12-q.length),q=C,H.push(q)}let j=z0(q);return YX($,P,w,j,z,M,N,V),X0(...H),M}}var d=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class bZ{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,$=X$($),p($,32);let Z=d($,0),J=d($,2),Q=d($,4),X=d($,6),Y=d($,8),V=d($,10),W=d($,12),q=d($,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|V<<2)&8191,this.r[7]=(V>>>11|W<<5)&8065,this.r[8]=(W>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let z=0;z<8;z++)this.pad[z]=d($,16+2*z)}process($,Z,J=!1){let Q=J?0:2048,{h:X,r:Y}=this,V=Y[0],W=Y[1],q=Y[2],z=Y[3],M=Y[4],N=Y[5],K=Y[6],H=Y[7],I=Y[8],R=Y[9],P=d($,Z+0),w=d($,Z+2),T=d($,Z+4),j=d($,Z+6),C=d($,Z+8),L=d($,Z+10),B=d($,Z+12),u=d($,Z+14),_=X[0]+(P&8191),x=X[1]+((P>>>13|w<<3)&8191),g=X[2]+((w>>>10|T<<6)&8191),S=X[3]+((T>>>7|j<<9)&8191),f=X[4]+((j>>>4|C<<12)&8191),F=X[5]+(C>>>1&8191),l=X[6]+((C>>>14|L<<2)&8191),b=X[7]+((L>>>11|B<<5)&8191),h=X[8]+((B>>>8|u<<8)&8191),i=X[9]+(u>>>5|Q),D=0,c=D+_*V+x*(5*R)+g*(5*I)+S*(5*H)+f*(5*K);D=c>>>13,c&=8191,c+=F*(5*N)+l*(5*M)+b*(5*z)+h*(5*q)+i*(5*W),D+=c>>>13,c&=8191;let a=D+_*W+x*V+g*(5*R)+S*(5*I)+f*(5*H);D=a>>>13,a&=8191,a+=F*(5*K)+l*(5*N)+b*(5*M)+h*(5*z)+i*(5*q),D+=a>>>13,a&=8191;let e=D+_*q+x*W+g*V+S*(5*R)+f*(5*I);D=e>>>13,e&=8191,e+=F*(5*H)+l*(5*K)+b*(5*N)+h*(5*M)+i*(5*z),D+=e>>>13,e&=8191;let k=D+_*z+x*q+g*W+S*V+f*(5*R);D=k>>>13,k&=8191,k+=F*(5*I)+l*(5*H)+b*(5*K)+h*(5*N)+i*(5*M),D+=k>>>13,k&=8191;let W0=D+_*M+x*z+g*q+S*W+f*V;D=W0>>>13,W0&=8191,W0+=F*(5*R)+l*(5*I)+b*(5*H)+h*(5*K)+i*(5*N),D+=W0>>>13,W0&=8191;let _0=D+_*N+x*M+g*z+S*q+f*W;D=_0>>>13,_0&=8191,_0+=F*V+l*(5*R)+b*(5*I)+h*(5*H)+i*(5*K),D+=_0>>>13,_0&=8191;let B0=D+_*K+x*N+g*M+S*z+f*q;D=B0>>>13,B0&=8191,B0+=F*W+l*V+b*(5*R)+h*(5*I)+i*(5*H),D+=B0>>>13,B0&=8191;let k0=D+_*H+x*K+g*N+S*M+f*z;D=k0>>>13,k0&=8191,k0+=F*q+l*W+b*V+h*(5*R)+i*(5*I),D+=k0>>>13,k0&=8191;let x0=D+_*I+x*H+g*K+S*N+f*M;D=x0>>>13,x0&=8191,x0+=F*z+l*q+b*W+h*V+i*(5*R),D+=x0>>>13,x0&=8191;let S0=D+_*R+x*I+g*H+S*K+f*N;D=S0>>>13,S0&=8191,S0+=F*M+l*z+b*q+h*W+i*V,D+=S0>>>13,S0&=8191,D=(D<<2)+D|0,D=D+c|0,c=D&8191,D=D>>>13,a+=D,X[0]=c,X[1]=a,X[2]=e,X[3]=k,X[4]=W0,X[5]=_0,X[6]=B0,X[7]=k0,X[8]=x0,X[9]=S0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let V=2;V<10;V++)$[V]+=Q,Q=$[V]>>>13,$[V]&=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 V=1;V<10;V++)J[V]=$[V]+Q,Q=J[V]>>>13,J[V]&=8191;J[9]-=8192;let X=(Q^1)-1;for(let V=0;V<10;V++)J[V]&=X;X=~X;for(let V=0;V<10;V++)$[V]=$[V]&X|J[V];$[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 V=1;V<8;V++)Y=($[V]+Z[V]|0)+(Y>>>16)|0,$[V]=Y&65535;X0(J)}update($){k$(this);let{buffer:Z,blockLen:J}=this;$=X$($);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(){X0(this.h,this.r,this.buffer,this.pad)}digestInto($){k$(this),kZ($,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 VX($){let Z=(Q,X)=>$(X).update(X$(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var f$=VX(($)=>new bZ($));function GX($,Z,J,Q,X,Y=20){let V=$[0],W=Z[0],q=Z[1],z=Z[2],M=Z[3],N=$[1],K=J[0],H=J[1],I=X,R=0,P=$[2],w=Z[4],T=Z[5],j=Z[6],C=Z[7],L=$[3],B=V,u=W,_=q,x=z,g=M,S=N,f=K,F=H,l=I,b=R,h=P,i=w,D=T,c=j,a=C,e=L;for(let W0=0;W0<Y;W0+=2)g^=U(B+D|0,7),l^=U(g+B|0,9),D^=U(l+g|0,13),B^=U(D+l|0,18),b^=U(S+u|0,7),c^=U(b+S|0,9),u^=U(c+b|0,13),S^=U(u+c|0,18),a^=U(h+f|0,7),_^=U(a+h|0,9),f^=U(_+a|0,13),h^=U(f+_|0,18),x^=U(e+i|0,7),F^=U(x+e|0,9),i^=U(F+x|0,13),e^=U(i+F|0,18),u^=U(B+x|0,7),_^=U(u+B|0,9),x^=U(_+u|0,13),B^=U(x+_|0,18),f^=U(S+g|0,7),F^=U(f+S|0,9),g^=U(F+f|0,13),S^=U(g+F|0,18),i^=U(h+b|0,7),l^=U(i+h|0,9),b^=U(l+i|0,13),h^=U(b+l|0,18),D^=U(e+a|0,7),c^=U(D+e|0,9),a^=U(c+D|0,13),e^=U(a+c|0,18);let k=0;Q[k++]=V+B|0,Q[k++]=W+u|0,Q[k++]=q+_|0,Q[k++]=z+x|0,Q[k++]=M+g|0,Q[k++]=N+S|0,Q[k++]=K+f|0,Q[k++]=H+F|0,Q[k++]=I+l|0,Q[k++]=R+b|0,Q[k++]=P+h|0,Q[k++]=w+i|0,Q[k++]=T+D|0,Q[k++]=j+c|0,Q[k++]=C+a|0,Q[k++]=L+e|0}function WX($,Z,J,Q){let X=$[0],Y=Z[0],V=Z[1],W=Z[2],q=Z[3],z=$[1],M=J[0],N=J[1],K=J[2],H=J[3],I=$[2],R=Z[4],P=Z[5],w=Z[6],T=Z[7],j=$[3];for(let L=0;L<20;L+=2)q^=U(X+P|0,7),K^=U(q+X|0,9),P^=U(K+q|0,13),X^=U(P+K|0,18),H^=U(z+Y|0,7),w^=U(H+z|0,9),Y^=U(w+H|0,13),z^=U(Y+w|0,18),T^=U(I+M|0,7),V^=U(T+I|0,9),M^=U(V+T|0,13),I^=U(M+V|0,18),W^=U(j+R|0,7),N^=U(W+j|0,9),R^=U(N+W|0,13),j^=U(R+N|0,18),Y^=U(X+W|0,7),V^=U(Y+X|0,9),W^=U(V+Y|0,13),X^=U(W+V|0,18),M^=U(z+q|0,7),N^=U(M+z|0,9),q^=U(N+M|0,13),z^=U(q+N|0,18),R^=U(I+H|0,7),K^=U(R+I|0,9),H^=U(K+R|0,13),I^=U(H+K|0,18),P^=U(j+T|0,7),w^=U(P+j|0,9),T^=U(w+P|0,13),j^=U(T+w|0,18);let C=0;Q[C++]=X,Q[C++]=z,Q[C++]=I,Q[C++]=j,Q[C++]=M,Q[C++]=N,Q[C++]=K,Q[C++]=H}var v$=lZ(GX,{counterRight:!0,extendNonceFn:WX}),y$=gZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=S$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32);Q.set(J,32),X0(X),v$($,Z,Q,Q);let V=f$(Y,X);return Q.set(V,16),X0(Q.subarray(0,16),V),Q.subarray(16)},decrypt(J,Q){p(J),Q=S$(J.length+32,Q,!1);let X=Q.subarray(0,32),Y=Q.subarray(32,48),V=Q.subarray(48);Q.set(J,32),X0(X);let W=v$($,Z,X,X),q=f$(V,W);if(!SZ(Y,q))throw Error("invalid tag");return v$($,Z,Q.subarray(16),Q.subarray(16)),X0(X,Y,q),V}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function qX($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function o0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function w0($,...Z){if(!qX($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function a0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function G$($,Z){w0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function hZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function g0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function f0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function s0($,Z){return $<<32-Z|$>>>Z}var iZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function pZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var uZ=iZ?($)=>$:($)=>pZ($);function zX($){for(let Z=0;Z<$.length;Z++)$[Z]=pZ($[Z]);return $}var s=iZ?($)=>$:zX;function MX($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function v0($){if(typeof $==="string")$=MX($);return w0($),$}class l${}function dZ($){let Z=(Q,X)=>$(X).update(v0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var nZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var W$=BigInt(4294967295),cZ=BigInt(32);function b$($,Z=!1){if(Z)return{h:Number($&W$),l:Number($>>cZ&W$)};return{h:Number($>>cZ&W$)|0,l:Number($&W$)|0}}function M0($,Z,J,Q,X){return $=$+Z+X|0,Q=s0(Q^$,16),J=J+Q|0,Z=s0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function N0($,Z,J,Q,X){return $=$+Z+X|0,Q=s0(Q^$,8),J=J+Q|0,Z=s0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class h$ extends l${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,o0($),o0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=g0(this.buffer)}update($){a0(this),$=v0($),w0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,X=$.length,Y=$.byteOffset,V=$.buffer;for(let W=0;W<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-W),z=Y+W;if(q===Z&&!(z%4)&&W+q<X){let M=new Uint32Array(V,z,Math.floor((X-W)/4));s(M);for(let N=0;W+Z<X;N+=Q.length,W+=Z)this.length+=Z,this.compress(M,N,!1);s(M);continue}J.set($.subarray(W,W+q),this.pos),this.pos+=q,this.length+=q,W+=q}return this}digestInto($){a0(this),G$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,f0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=g0($);this.get().forEach((X,Y)=>Q[Y]=uZ(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:V}=this;return $||($=new this.constructor({dkLen:Y})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=X,$.finished=Q,$.length=J,$.pos=V,$.outputLen=Y,$}clone(){return this._cloneInto()}}function i$($,Z,J,Q,X,Y,V,W,q,z,M,N,K,H,I,R,P,w,T,j){let C=0;for(let L=0;L<Q;L++)({a:X,b:q,c:K,d:P}=M0(X,q,K,P,J[Z+$[C++]])),{a:X,b:q,c:K,d:P}=N0(X,q,K,P,J[Z+$[C++]]),{a:Y,b:z,c:H,d:w}=M0(Y,z,H,w,J[Z+$[C++]]),{a:Y,b:z,c:H,d:w}=N0(Y,z,H,w,J[Z+$[C++]]),{a:V,b:M,c:I,d:T}=M0(V,M,I,T,J[Z+$[C++]]),{a:V,b:M,c:I,d:T}=N0(V,M,I,T,J[Z+$[C++]]),{a:W,b:N,c:R,d:j}=M0(W,N,R,j,J[Z+$[C++]]),{a:W,b:N,c:R,d:j}=N0(W,N,R,j,J[Z+$[C++]]),{a:X,b:z,c:I,d:j}=M0(X,z,I,j,J[Z+$[C++]]),{a:X,b:z,c:I,d:j}=N0(X,z,I,j,J[Z+$[C++]]),{a:Y,b:M,c:R,d:P}=M0(Y,M,R,P,J[Z+$[C++]]),{a:Y,b:M,c:R,d:P}=N0(Y,M,R,P,J[Z+$[C++]]),{a:V,b:N,c:K,d:w}=M0(V,N,K,w,J[Z+$[C++]]),{a:V,b:N,c:K,d:w}=N0(V,N,K,w,J[Z+$[C++]]),{a:W,b:q,c:H,d:T}=M0(W,q,H,T,J[Z+$[C++]]),{a:W,b:q,c:H,d:T}=N0(W,q,H,T,J[Z+$[C++]]);return{v0:X,v1:Y,v2:V,v3:W,v4:q,v5:z,v6:M,v7:N,v8:K,v9:H,v10:I,v11:R,v12:P,v13:w,v14:T,v15:j}}var Y0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},O0=nZ.slice(),rZ=(()=>{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 p$ extends h${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=v0(J).slice();w0(Y,32),this.IV=g0(Y),s(this.IV),this.flags=Z|Y0.KEYED_HASH}else if(X){let Y=v0(Q),V=new p$({dkLen:32},Y0.DERIVE_KEY_CONTEXT).update(Y).digest();this.IV=g0(V),s(this.IV),this.flags=Z|Y0.DERIVE_KEY_MATERIAL}else this.IV=O0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=hZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:X,pos:Y}=this,{h:V,l:W}=b$(BigInt($),!0),{v0:q,v1:z,v2:M,v3:N,v4:K,v5:H,v6:I,v7:R,v8:P,v9:w,v10:T,v11:j,v12:C,v13:L,v14:B,v15:u}=i$(rZ,Q,J,7,X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],O0[0],O0[1],O0[2],O0[3],V,W,Y,Z);X[0]=q^P,X[1]=z^w,X[2]=M^T,X[3]=N^j,X[4]=K^C,X[5]=H^L,X[6]=I^B,X[7]=R^u}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=Y0.CHUNK_START;if(this.chunkPos===15||J)Q|=Y0.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,V=this.chunksDone+1;J||!(V&1);V>>=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|Y0.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:V,stack:W,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=W.map((z)=>Uint32Array.from(z)),$.IV.set(Z),$.flags=J,$.chunkPos=X,$.chunksDone=q,$.posOut=Y,$.chunkOut=V,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,f0(this.state,this.buffer32,this.IV,this.bufferOut32),f0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:X}=this,{h:Y,l:V}=b$(BigInt(this.chunkOut++));s(Q);let{v0:W,v1:q,v2:z,v3:M,v4:N,v5:K,v6:H,v7:I,v8:R,v9:P,v10:w,v11:T,v12:j,v13:C,v14:L,v15:B}=i$(rZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],O0[0],O0[1],O0[2],O0[3],V,Y,Z,J);X[0]=W^R,X[1]=q^P,X[2]=z^w,X[3]=M^T,X[4]=N^j,X[5]=K^C,X[6]=H^L,X[7]=I^B,X[8]=$[0]^R,X[9]=$[1]^P,X[10]=$[2]^w,X[11]=$[3]^T,X[12]=$[4]^j,X[13]=$[5]^C,X[14]=$[6]^L,X[15]=$[7]^B,s(Q),s(X),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,f0(this.buffer.subarray(this.pos));let $=this.flags|Y0.ROOT;if(this.stack.length)$|=Y0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Y0.CHUNK_START:0)|Y0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){a0(this,!1),w0($),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 o0($),this.xofInto(new Uint8Array($))}digestInto($){if(G$($,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 oZ=dZ(($)=>new p$($));function $0($){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 y0($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var aZ;if(typeof Uint8Array.prototype.toBase64==="function")aZ=($)=>$.toBase64();else aZ=($)=>btoa(String.fromCharCode(...$));var u$;if(typeof Uint8Array.fromBase64==="function")u$=($)=>Uint8Array.fromBase64($);else u$=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function sZ($){let Z=$.length%4===0?"":"=".repeat(4-$.length%4),J=$.replace(/-/g,"+").replace(/_/g,"/")+Z;return u$(J)}function K0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var l0=64;var tZ=32,b0=8;var eZ=32;var $J=30000,ZJ=512,A;((F)=>{F[F.Success=0]="Success";F[F.InvalidSignature=3]="InvalidSignature";F[F.ClockOutOfSync=4]="ClockOutOfSync";F[F.UserNotRegistered=5]="UserNotRegistered";F[F.ServerMisconfigured=6]="ServerMisconfigured";F[F.MissingBody=7]="MissingBody";F[F.ExtraBodyContent=8]="ExtraBodyContent";F[F.MissingParam=9]="MissingParam";F[F.InvalidParam=10]="InvalidParam";F[F.InvalidRequest=11]="InvalidRequest";F[F.InternalError=12]="InternalError";F[F.NotFound=13]="NotFound";F[F.InvalidMessage=14]="InvalidMessage";F[F.NoChange=15]="NoChange";F[F.DatabaseClosed=16]="DatabaseClosed";F[F.StorageError=17]="StorageError";F[F.DatabaseError=18]="DatabaseError";F[F.HashMismatch=19]="HashMismatch";F[F.DecryptionError=20]="DecryptionError";F[F.NotImplemented=21]="NotImplemented";F[F.MissingSeed=22]="MissingSeed";F[F.OutOfBounds=23]="OutOfBounds";F[F.HostError=24]="HostError";F[F.CommunicationError=25]="CommunicationError";F[F.VarLimitExceeded=26]="VarLimitExceeded";F[F.InvalidResponse=27]="InvalidResponse";F[F.ConnectionClosed=28]="ConnectionClosed";F[F.CryptoError=29]="CryptoError";F[F.WebAuthnError=30]="WebAuthnError"})(A||={});var JJ="t";function O($){return[$,0]}function G($){return[void 0,$]}var NX=32,$G=Symbol("X25519Sk");function QJ($){if($.byteLength!==NX)return G(10);return O($)}var E=(1n<<255n)-19n,OX=121665n,XJ=new Uint8Array(32);XJ[0]=9;function YJ($){let Z=0n;for(let J=$.length-1;J>=0;J--)Z=Z<<8n|BigInt($[J]);return Z}function KX($){let Z=new Uint8Array(32),J=($%E+E)%E;for(let Q=0;Q<32;Q++)Z[Q]=Number(J&0xffn),J>>=8n;return Z}function HX($){let Z=$.slice();return Z[31]&=127,YJ(Z)}function FX($){let Z=$.slice();return Z[0]&=248,Z[31]&=127,Z[31]|=64,Z}function z$($,Z,J){let Q=-$,X=(Z^J)&Q;return[Z^X,J^X]}function RX($){let Z=E-2n,J=($%E+E)%E,Q=1n;while(Z>0n){if(Z&1n)Q=Q*J%E;J=J*J%E,Z>>=1n}return Q}function IX($,Z){let J=FX($),Q=HX(Z),X=1n,Y=0n,V=Q,W=1n,q=0n,z=YJ(J);for(let M=254;M>=0;M--){let N=z>>BigInt(M)&1n;q^=N,[X,V]=z$(q,X,V),[Y,W]=z$(q,Y,W),q=N;let K=(X+Y)%E,H=K*K%E,I=(X-Y+E)%E,R=I*I%E,P=(H-R+E)%E,w=(V+W)%E,j=(V-W+E)%E*K%E,C=w*I%E,L=(j+C)%E,B=(j-C+E)%E;V=L*L%E,W=Q*B*B%E,X=H*R%E,Y=P*(H+OX*P)%E}return[X,V]=z$(q,X,V),[Y,W]=z$(q,Y,W),J.fill(0),KX(X*RX(Y)%E)}function VJ($){return IX($,XJ)}var d$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function GJ($){let Z=new Uint8Array(d$.length+32);return Z.set(d$),Z.set($.subarray(0,32),d$.length),Z}var n$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,110,4,34,4,32]);function WJ($){let Z=new Uint8Array(n$.length+32);return Z.set(n$),Z.set($.subarray(0,32),n$.length),Z}function qJ($){return typeof $==="string"?new TextEncoder().encode($):$}function H0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class T0{verifyKeys=new Map;async genRandomBytes($){return r0($)}async gen256BitSecureRandomSeed(){return r0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=r0(24),X=y$(Z,J).encrypt($);return new Uint8Array([...J,...X])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return y$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=GJ(Z),Q=H0(J),X;try{let z=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!0,["sign"]);X=await globalThis.crypto.subtle.exportKey("jwk",z)}finally{J.fill(0),new Uint8Array(Q).fill(0)}if(typeof X.x!=="string")throw Error("Ed25519 JWK missing x");let Y=X.x;X.d=void 0;let V=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:Y},{name:"Ed25519"},!0,["verify"]),W=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",V));this.verifyKeys.set($0(W),V);let q=new Uint8Array(64);return q.set(Z,0),q.set(W,32),{keyType:"ed25519",privateKey:q,publicKey:W}}async importSignKey($){let Z=$.subarray(0,32),J=GJ(Z),Q=H0(J);try{return await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!1,["sign"])}finally{J.fill(0),new Uint8Array(Q).fill(0)}}async importVerifyKey($){let Z=$0($),J=this.verifyKeys.get(Z);if(J)return J;let Q=await globalThis.crypto.subtle.importKey("raw",H0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=qJ($),Q=await this.importSignKey(Z),X=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,H0(J));return new Uint8Array(X)}async checkSigEd25519($,Z,J){let Q=qJ(Z);try{let X=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},X,H0($),H0(Q))}catch{return!1}}async blake3($){return oZ($)}async genX25519(){let $=await r0(32);$[0]&=248,$[31]&=127,$[31]|=64;let[Z,J]=QJ($);if(J!==0||Z===void 0)throw $.fill(0),Error("X25519 scalar brand failed");let Q=VJ(Z),X=WJ(Z),Y=H0(X);try{let V=await globalThis.crypto.subtle.importKey("pkcs8",Y,{name:"X25519"},!0,["deriveBits"]),W=await globalThis.crypto.subtle.exportKey("jwk",V);if(typeof W.x!=="string")throw Error("X25519 JWK missing x");let q=sZ(W.x);if(W.d=void 0,!y0(q,Q))throw Error("X25519 WebCrypto pub != RFC 7748");return{priv:Z,pub:Q}}catch(V){throw Z.fill(0),V}finally{X.fill(0),new Uint8Array(Y).fill(0)}}async x25519Shared($,Z){let J=WJ($),Q=H0(J);try{let X=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"X25519"},!1,["deriveBits"]),Y=await globalThis.crypto.subtle.importKey("raw",H0(Z),{name:"X25519"},!1,[]),V=await globalThis.crypto.subtle.deriveBits({name:"X25519",public:Y},X,256);return new Uint8Array(V)}finally{J.fill(0),new Uint8Array(Q).fill(0)}}}var PX=new T0,h0=PX;function UX($){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 O(new Uint8Array([0]));if(Z.length>8)return G(26);return O(new Uint8Array(Z))}function CX($,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 O({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:X-Z})}if(Q+=7,Q>=56)return G(26)}}class v{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new v(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,O($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);return O(new Date($))}readVarInt(){let[$,Z]=CX(this.data,this.pos);if(Z!==0)return G(Z);this.pos+=$.bytesRead;let J=$.value;return O(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 O(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+=$,O(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 O(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return G(Q);Z.push(J)}return O(Z)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class m{parts=[];writeBigInt($){let Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,$,!1),this.parts.push(Z)}writeDate($){let Z=$.getTime();return this.writeVarInt(Z)}writeVarInt($){let[Z,J]=UX($);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}wipe(){for(let $ of this.parts)$.fill(0);this.parts.length=0}*scan(){for(let $ of this.parts)yield $}}var t0={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 O({id:Z,ts:Q})}};function zJ($){let Z=new m,J=Z.writeStruct(t0,$);if(J!==0)return G(J);let Q=Z.result();return O(Q)}var c$={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 v(Z),[,X]=t0.decode(Q);if(X!==0)return G(X);let[Y,V]=$.readVarInt();if(V!==0)return G(V);let[W,q]=$.readVarInt();if(q!==0)return G(q);let[z,M]=$.readVarInt();if(M!==0)return G(M);let N;if(z>0){let[K,H]=$.readBytes(eZ);if(H!==0)return G(H);N=K}return O({eid:Z,off:Y,ctr:W,len:z,hsh:N})}};function MJ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function NJ($,Z,J,Q){let X;if($.bod&&$.len>0)X=await J.blake3($.bod);let Y=new m,V=c$.encode(Y,{...$,hsh:X});if(V!==0)return G(V);let W=Y.result(),q=await Z.kdmFor(W),z=Q.deriveCipher(q,"encrypt"),M=await z.encrypt(W),N=$.bod?await z.encrypt($.bod):new Uint8Array(0),K=await Z.sign(M);return O({sig:K,kdm:q,headCph:M,bodyCph:N})}async function OJ($,Z,J,Q,X){let Y=new v($),[V,W]=c$.decode(Y);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 z=V.hsh&&q===void 0,M=V.hsh===void 0&&q!==void 0;if(z||M)return G(19);if(V.hsh&&q){let K=await Q.blake3(q);if(!y0(K,V.hsh))return G(19)}let N=X??await Q.blake3($);return O({msgHead:V,bod:q,headHash:N})}async function r$($,Z){let J=new m,Q=J.writeDate(Z);if(Q!==0)return G(Q);let X=J.result(),Y=await $.sign(X);return O({pubKey:$.publicKey,sig:Y,timestamp:Z})}async function J0($,Z,J){let Q=J.now().getTime(),X=$.timestamp.getTime();if(Math.abs(Q-X)>$J)return 4;let V=new m;V.writeDate($.timestamp);let W=V.result();if(!await Z.checkSigEd25519($.sig,W,$.pubKey))return 3;return 0}class i0{now(){return new Date}}function KJ($,Z,J,Q){let X=Z.getTime()-$.getTime(),Y=J.getTime()-Q.getTime();return(X+Y)/2}var e0={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 O({quota:Z,usage:Q})}};var p0={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 V=$.writeStruct(e0,Z.subscription.stat);if(V!==0)return V;let W=$.writeStruct(e0,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],[X,Y]=$.readDate();if(Y!==0)return G(Y);let[V,W]=$.readDate();if(W!==0)return G(W);let[q,z]=$.readVarInt();if(z!==0)return G(z);let[M,N]=$.readVarInt();if(N!==0)return G(N);let[K,H]=$.readStruct(e0);if(H!==0)return G(H);let[I,R]=$.readStruct(e0);if(R!==0)return G(R);return O({status:Q,timeRcvd:X,timeSent:V,subscription:{term:q,elapsed:M,stat:K,dyn:I}})}};var o$={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 O({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(tZ);if(J!==0)return G(J);let[Q,X]=$.readBytes(l0);if(X!==0)return G(X);let[Y,V]=$.readDate();if(V!==0)return G(V);return O({pubKey:Z,sig:Q,timestamp:Y})}};var HJ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(o,J);if(Y!==0)return Y;for(let V of Q)X.writeVarInt(V);return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[V,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(V,X,Q);if(q!==0)return q;let{pubKey:z}=V,[M,N]=await Y.hasUser(z);if(N!==0)return N;if(!M)return 5;let[K,H]=Z.readVarInt();if(H!==0)return H;if(!Z.done())return 8;let[I,R]=await Y.listHeads(z,K);if(R!==0)return R;return J.writeStructs(o$,I)},decodeResp($){return $.readStructs(o$)}};var a$={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 O({seq:Z,bodyCph:Q})}};var FJ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(o,J);if(Y!==0)return Y;for(let V of Q){let W=X.writeVarInt(V);if(W!==0)return W}return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[V,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(V,X,Q);if(q!==0)return q;let{pubKey:z}=V,[M,N]=await Y.hasUser(z);if(N!==0)return N;if(!M)return 5;let K=[];while(!Z.done()){let[R,P]=Z.readVarInt();if(P!==0)return P;K.push(R)}console.info(`PULL: ${K.length} bags`);let[H,I]=await Y.getBodies(z,K);if(I!==0)return I;if(!H)return 17;for(let{seq:R,bodyCph:P}of H){let w={seq:R,bodyCph:P},T=J.writeStruct(a$,w);if(T!==0)return T}return 0},decodeResp($){return $.readStructs(a$)}};var s$={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(l0);if(J!==0)return G(J);let[Q,X]=$.readBytes(b0);if(X!==0)return G(X);let[Y,V]=$.readVarBytes();if(V!==0)return G(V);let[W,q]=$.readVarBytes();if(q!==0)return G(q);return O({sig:Z,kdm:Q,headCph:Y,bodyCph:W})}};var t$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let 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,V]=$.readVarInt();if(V!==0)return G(V);let W;if(Y>0){let[q,z]=$.readBytes(Y);if(z!==0)return G(z);W=q}return O({seq:Z,headCph:Q,bodyCph:W})}};var u0={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(l0);if(J!==0)return G(J);let[Q,X]=$.readBytes(b0);if(X!==0)return G(X);let[Y,V]=$.readVarBytes();if(V!==0)return G(V);return O({sig:Z,kdm:Q,headCph:Y})}};var M$={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 O({idx:Z,status:Y});let[V,W]=$.readVarInt();if(W!==0)return G(W);return O({idx:Z,status:Y,seq:V})}};var RJ={async encodeReq($,Z,J,Q,X){let Y=X.writeStruct(o,J);if(Y!==0)return Y;let V=X.writeStructs(s$,Q);if(V!==0)return V;return 0},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y,notifier:V}=$,[W,q]=Z.readStruct(o);if(q!==0)return q;let z=await J0(W,X,Q);if(z!==0)return z;let{pubKey:M}=W,[N,K]=await Y.hasUser(M);if(K!==0)return K;if(!N)return 5;let[H,I]=Z.readStructs(s$);if(I!==0)return I;console.info(`PUSH: ${H.length} bags`);let R=[],P=[];for(let C=0;C<H.length;C++){let L=H[C];if(!await MJ(L,M,X)){let u={idx:C,status:3},_=J.writeStruct(M$,u);if(_!==0)return _;continue}R.push(C),P.push(L)}let[w,T]=await Y.setBags(M,P);if(T!==0)return T;if(!w||w.length!==P.length)return 17;let j=[];for(let C=0;C<P.length;C++){let L=P[C],B=R[C],u=w[C],_=new m,x=_.writeStruct(u0,L);if(x!==0)return x;let g=_.result(),S={seq:u,headCph:g};if(H.length===1&&L.bodyCph.length<=ZJ)S.bodyCph=L.bodyCph;j.push(S);let f={idx:B,status:0,seq:u},F=J.writeStruct(M$,f);if(F!==0)return F}if(j.length>0){let C=new m,L=C.writeStructs(t$,j);if(L!==0)return L;let B=C.result();await Promise.resolve(V.push(M,B))}return 0},decodeResp($){return $.readStructs(M$)}};var IJ={async encodeReq($,Z,J,Q,X){return X.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:X,storage:Y}=$,[V,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(V,X,Q);if(q!==0)return q;let{pubKey:z}=V;if(!Z.done())return 8;let[M,N]=await Y.addUser(z);if(N!==0)return N;return 0},decodeResp($){return O(void 0)}};class e${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 m;Y.writeStruct(o,$);let V=Y.result(),W=$0(V);return X.searchParams.set("t",W),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 z=new Uint8Array(q.data);Z(z)},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 n={user:{path:"/user",endpoint:IJ,name:0},push:{path:"/push",endpoint:RJ,name:2},peek:{path:"/peek",endpoint:HJ,name:1},pull:{path:"/pull",endpoint:FJ,name:3}},wX={0:n.user,2:n.push,1:n.peek,3:n.pull},PJ={[n.user.path]:n.user,[n.push.path]:n.push,[n.peek.path]:n.peek,[n.pull.path]:n.pull};class UJ{url;listener;constructor($){this.url=$;this.listener=new e$($)}async call($,Z){let{path:J}=wX[$],Q=new URL(J,this.url);try{return await DX(Q,Z)}catch{return G(25)}}}var $Z=($)=>{return new UJ($.handle)};function d0($){let Z=new m;if(Z.writeStruct(p0,$)!==0)return new Response(null,{status:500});return ZZ(Z)}function ZZ($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var TX={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function JZ($){return new Response($.body,{headers:{...$.headers,...TX},status:$.status,statusText:$.statusText})}async function DX($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return G(24);let Q=await v.fromResponse(J);return O(Q)}class N${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}=$,V=await this.identity(),W=J.now(),[q,z]=await r$(V,W);if(z!==0)return G(z);let M=new m,N=await X.encodeReq(this,V,q,Z,M);if(N!==0)return G(N);let K=J.now(),[H,I]=await Q.call(Y,M),R=J.now();if(I!==0)return G(I);let[P,w]=H.readStruct(p0);if(w!==0)return G(w);if(P.status!==0)return G(P.status);let j={clockOffset:KJ(K,P.timeRcvd,P.timeSent,R),subscription:P.subscription},C=await this.updateHostMeta(j);if(C!==0)return G(C);return X.decodeResp(H)}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 NJ($,Q,Z,J)};register=()=>this.call(n.user,[]);peek=($)=>this.call(n.peek,[$]);push=($)=>this.call(n.push,$);pull=($)=>this.call(n.pull,$);listen=async($,Z,J)=>{let{clock:Q,transport:X}=this,{listener:Y}=X,V=await this.identity(),W=Q.now(),[q,z]=await r$(V,W);if(z!==0)return z;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 C8=Symbol("MasterSeed"),w8=Symbol("SealedMasterKey"),V0=32,CJ=24+V0+16;function t($){if($.byteLength!==V0)return G(10);return O($)}function O$($){if($.byteLength!==CJ)return G(10);return O($)}var D0={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,V]=$.readVarInt();if(V!==0)return G(V);return O({handle:Z,label:Q,idx:Y})}};var K$=1,QZ={encode($,Z){if(Z.v!==K$)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 X=$.writeVarInt(Z.hosts.length);if(X!==0)return X;for(let Y of Z.hosts){let V=$.writeStruct(D0,Y);if(V!==0)return V}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);if(Z!==K$)return G(14);let[Q,X]=$.readBytes(V0);if(X!==0)return G(X);if(Q===void 0)return G(14);let[Y,V]=t(Q);if(V!==0)return G(V);if(Y===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 z=[];for(let M=0;M<W;M++){let[N,K]=$.readStruct(D0);if(K!==0)return G(K);if(N===void 0)return G(14);z.push(N)}return O({v:K$,masterSeed:Y,hosts:z})}};function wJ($,Z){let[J,Q]=t($);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[X,Y]=t(J.slice());if(Y!==0)return G(Y);if(X===void 0)return G(10);return O({v:K$,masterSeed:X,hosts:Z.map((V)=>({handle:V.handle,label:V.label,idx:V.idx??0}))})}var H$={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 X of Z.hosts){let Y=$.writeStruct(D0,X);if(Y!==0)return Y}return 0},decode($){let[Z,J]=$.readBytes(V0);if(J!==0)return G(J);if(Z===void 0)return G(14);let[Q,X]=t(Z);if(X!==0)return G(X);if(Q===void 0)return G(14);let[Y,V]=$.readVarInt();if(V!==0)return G(V);if(Y===void 0||Y<0)return G(10);let W=[];for(let q=0;q<Y;q++){let[z,M]=$.readStruct(D0);if(M!==0)return G(M);if(z===void 0)return G(14);W.push(z)}return O({masterSeed:Q,hosts:W})}};var AX=new TextEncoder().encode("diplomatic.qrpair.v1"),$$=32,jX=$$+24+16,LX=32,d8=Symbol("DHKEReq"),n8=Symbol("DHKEResp");function TJ($){if($.byteLength!==$$)return G(10);return O($)}function DJ($){if($.byteLength<jX)return G(10);return O($)}var F$=new T0;async function XZ($,Z,J,Q){let X;try{X=await F$.x25519Shared($,Z)}catch{return G(29)}try{if(X.byteLength!==$$||X.every((W)=>W===0))return G(10);let Y=K0(X,AX),V=K0(Y,K0(J,Q));try{let W=await F$.blake3(V);return O(W.slice(0,LX))}finally{Y.fill(0),V.fill(0)}}finally{X.fill(0)}}class R${#$;#Z;constructor($,Z){this.#$=$,this.#Z=Z}static async create(){let $;try{let Z=await F$.genX25519();$=Z.priv;let[J,Q]=TJ(Z.pub);if(Q!==0)return G(Q);if(J===void 0)return G(10);let X=new R$($,J);return $=void 0,O(X)}catch{return G(29)}finally{$?.fill(0)}}wipe(){this.#$.fill(0)}get dhkeReq(){let[$,Z]=TJ(this.#Z.slice());if($===void 0)throw Error(`dhkeReq ${Z}`);return $}async finish($){let Z=$.subarray(0,$$),J=$.subarray($$),[Q,X]=await XZ(this.#$,Z,this.#Z,Z);if(X!==0)return G(X);if(Q===void 0)return G(12);let Y;try{try{Y=await F$.decryptXSalsa20Poly1305Combined(J,Q)}catch{return G(20)}let V=new v(Y),[W,q]=V.readStruct(H$);if(q!==0)return G(q);if(W===void 0)return G(14);try{let[z,M]=Q0.fromBytes(W.masterSeed);if(M!==0)return G(M);if(z===void 0)return G(12);return this.wipe(),O({enclave:z,hosts:W.hosts.map((N)=>({...N}))})}finally{W.masterSeed.fill(0)}}finally{Q.fill(0),Y?.fill(0)}}}function F0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var A0=32,I$="DIPLOMATIC",G0="public-key",EX=-7,mX=-8,_X=-257,P$=[{type:G0,alg:EX},{type:G0,alg:mX},{type:G0,alg:_X}];function BX($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function R0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z.buffer}function U$($){if($ instanceof ArrayBuffer)return new Uint8Array($).slice();return new Uint8Array($.buffer,$.byteOffset,$.byteLength).slice()}function j0($){if($?.rpId!==void 0)return O($.rpId);if(typeof location>"u")return G(9);return O(BX(location.hostname))}var AJ="";function U0($){if($ instanceof Error){AJ=$.message===""?$.name:`${$.name}: ${$.message}`;return}AJ=String($)}function L0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function E0($){if($===null||$.type!==G0||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return G(27);return O($)}function VZ($){if($==="platform"||$==="cross-platform")return $;return}function GZ($){let Z=$.response;if(!("getTransports"in Z))return;let J=Z.getTransports;if(typeof J!=="function")return;let Q=J.call(Z);if(!Array.isArray(Q))return;let X=[];for(let Y of Q)if(typeof Y==="string"&&Y.length>0)X.push(Y);return X.length===0?void 0:X}var kX=32,xX=64,YZ=37,jJ=16;function LJ($){let Z=$.response;if(!("getAuthenticatorData"in Z))return;let J=Z.getAuthenticatorData;if(typeof J!=="function")return;let Q=J.call(Z);if(!(Q instanceof ArrayBuffer))return;let X=new Uint8Array(Q);if(X.byteLength<YZ+jJ)return;let Y=X[kX];if(Y===void 0||(Y&xX)===0)return;return X.slice(YZ,YZ+jJ)}async function EJ($){let Z=L0();if(Z!==0)return G(Z);let[J,Q]=j0($);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 V={largeBlob:{support:"required"}},W;try{W=await navigator.credentials.create({publicKey:{challenge:F0(A0),rp:{id:J,name:$?.rpName??I$},user:{id:F0(16),name:X,displayName:X},pubKeyCredParams:P$,authenticatorSelection:Y,extensions:V,...$?.hints!==void 0?{hints:$.hints}:{}}})}catch(N){return U0(N),G(30)}let[q,z]=E0(W);if(z!==0)return G(z);if(q===void 0)return G(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return G(30);return O(new Uint8Array(q.rawId))}async function qZ($,Z,J){let Q=L0();if(Q!==0)return Q;let[X,Y]=j0(J);if(Y!==0)return Y;if(X===void 0)return 9;let V={largeBlob:{write:R0(Z)}},W;try{W=await navigator.credentials.get({publicKey:{challenge:F0(A0),rpId:X,allowCredentials:[{type:G0,id:R0($)}],userVerification:"required",extensions:V,...J?.hints!==void 0?{hints:J.hints}:{}}})}catch(N){return U0(N),30}let[q,z]=E0(W);if(z!==0)return z;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 30;return 0}async function WZ($,Z,J,Q){let X={challenge:F0(A0),rpId:$,userVerification:"preferred"};if(Z?.hints!==void 0)X.hints=Z.hints;if(J!==void 0)X.allowCredentials=[{type:G0,id:R0(J)}];if(Q!==void 0)X.extensions=Q;let Y;try{Y=await navigator.credentials.get({publicKey:X})}catch(q){return U0(q),G(30)}let[V,W]=E0(Y);if(W!==0)return G(W);if(V===void 0)return G(27);return O(V)}async function mJ($,Z){let J=L0();if(J!==0)return G(J);let[Q,X]=j0(Z);if(X!==0)return G(X);if(Q===void 0)return G(9);let Y=$;if(Y===void 0){let[N,K]=await WZ(Q,Z);if(K!==0&&Z?.hints!==void 0)[N,K]=await WZ(Q,{rpId:Z.rpId,rpName:Z.rpName});if(K!==0)return G(K);if(N===void 0)return G(27);Y=new Uint8Array(N.rawId)}let[V,W]=await WZ(Q,Z,Y,{largeBlob:{read:!0}});if(W!==0)return G(W);if(V===void 0)return G(27);let z=V.getClientExtensionResults().largeBlob;if(z===void 0||z.blob===void 0)return G(7);let M=U$(z.blob);if(M.byteLength===0)return G(7);return O({blob:M,credId:new Uint8Array(V.rawId)})}var MZ=new TextEncoder().encode("diplomatic.prf.v1"),NZ="diplomatic-prf",zZ=32;function gX($){if($===void 0)return[];if($ instanceof Uint8Array)return[$];return $.filter((Z)=>Z.byteLength>0)}async function _J($){let Z=L0();if(Z!==0)return G(Z);let[J,Q]=j0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let X=$?.userName??NZ,Y=$?.displayName??X,V=F0(16),W=$?.authenticatorAttachment==="cross-platform",q={residentKey:W?"discouraged":"required",requireResidentKey:!W,userVerification:W?"preferred":"required"};if($?.authenticatorAttachment!==void 0)q.authenticatorAttachment=$.authenticatorAttachment;let z={challenge:F0(A0),rp:{id:J,name:$?.rpName??I$},user:{id:V,name:X,displayName:Y},pubKeyCredParams:P$,authenticatorSelection:q,...$?.hints!==void 0?{hints:$.hints}:{},...$?.excludeCredentials!==void 0&&$.excludeCredentials.length>0?{excludeCredentials:$.excludeCredentials.map((T)=>({type:G0,id:R0(T)}))}:{}},M=$?.salt!==void 0?R0($.salt):void 0,N=(T)=>navigator.credentials.create({publicKey:{...z,extensions:T&&M!==void 0?{prf:{eval:{first:M}}}:{prf:{}}}}),K;try{K=await N(M!==void 0)}catch(T){if(M===void 0||!fX(T))return U0(T),G(30);try{K=await N(!1)}catch(j){return U0(j),G(30)}}let[H,I]=E0(K);if(I!==0)return G(I);if(H===void 0)return G(27);let R=H.getClientExtensionResults(),P=BJ(R.prf?.results?.first),w=R.prf?.enabled===!0||P!==void 0;if(W&&P!==void 0)P.fill(0);return O({credId:new Uint8Array(H.rawId),userId:new Uint8Array(V),prfEnabled:w,prf:W?void 0:P,attachment:VZ(H.authenticatorAttachment),transports:GZ(H),aaguid:LJ(H)})}function fX($){if(!($ instanceof Error))return!1;return $.name==="NotSupportedError"||$.name==="TypeError"}function BJ($){if($===void 0)return;let Z=U$($);if(Z.byteLength<zZ){Z.fill(0);return}if(Z.byteLength===zZ)return Z;let J=Z.slice(0,zZ);return Z.fill(0),J}async function OZ($){let Z=L0();if(Z!==0)return G(Z);let[J,Q]=j0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let X=$?.salt??MZ,Y=R0(X),V={challenge:F0(A0),rpId:J,userVerification:"preferred",extensions:{prf:{eval:{first:Y}}}};if($?.hints!==void 0)V.hints=$.hints;let W=gX($?.credId);if(W.length>0)V.allowCredentials=W.map((H)=>({type:G0,id:R0(H)}));let q;try{q=await navigator.credentials.get({publicKey:V})}catch(H){return U0(H),G(30)}let[z,M]=E0(q);if(M!==0)return G(M);if(z===void 0)return G(27);let N=z.getClientExtensionResults().prf?.results;if(N?.first===void 0)return G(7);let K=BJ(N.first);if(K===void 0)return G(27);return O({prf:K,credId:new Uint8Array(z.rawId),attachment:VZ(z.authenticatorAttachment),transports:GZ(z)})}var C$="";var T$=typeof globalThis.Worker==="function"?globalThis.Worker:void 0,KZ=T$===void 0?void 0:T$.prototype.postMessage,w$;function vX(){if(typeof C$!=="string"||C$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(C$)}function yX(){if(w$!==void 0)return w$;let $=new Blob([vX()],{type:"text/javascript"});return w$=URL.createObjectURL($),w$}function kJ(){if(T$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new T$(yX(),{type:"module"})}function xJ($,Z,J){if(KZ===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot post to sync worker");if(J!==void 0&&J.length>0)KZ.call($,Z,{transfer:J});else KZ.call($,Z)}var lX=new TextEncoder().encode("diplomatic.bind.v1"),HZ=new TextEncoder().encode("diplomatic.bindtag.v1"),bX=32,hX=32,iX=16,Z0=new T0;class Q0{#$;constructor($){this.#$=$}static async fromRandom(){let $=await Z0.gen256BitSecureRandomSeed(),[Z,J]=t($);if(J!==0||Z===void 0)throw Error(`enclave: invalid random seed (${J})`);return new Q0(Z)}static fromBytes($){let[Z,J]=t($);if(J!==0)return G(J);if(Z===void 0)return G(10);let[Q,X]=t(Z.slice());if(X!==0)return G(X);if(Q===void 0)return G(10);return O(new Q0(Q))}async sealWithPasskey($){let Z=$?.salt??MZ,J=$?.credId,Q=J,X=$?.createCredIfNeeded===!0&&(J===void 0||!(J instanceof Uint8Array)&&J.length===0),Y,V;if(X){let[M,N]=await _J({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??NZ,displayName:$?.displayName,authenticatorAttachment:$?.authenticatorAttachment,hints:$?.hints,excludeCredentials:$?.excludeCredentials,salt:Z});if(N!==0)return G(N);if(M===void 0)return G(30);if(!M.prfEnabled)return G(30);Q=M.credId,Y=M,V=M.prf}let W=async(M,N,K,H)=>{try{let[I,R]=await this.#V(M);if(R!==0)return G(R);if(I===void 0)return G(12);return O({sealedMaster:I,salt:Z.slice(),credId:N.slice(),userId:Y?.userId===void 0?void 0:Y.userId.slice(),attachment:K??Y?.attachment,transports:H??Y?.transports,aaguid:Y?.aaguid===void 0?void 0:Y.aaguid.slice()})}finally{M.fill(0)}};if(V!==void 0&&Y!==void 0)return W(V,Y.credId,Y.attachment,Y.transports);let[q,z]=await OZ({rpId:$?.rpId,rpName:$?.rpName,credId:Q,salt:Z,hints:$?.hints});if(z!==0)return G(z);if(q===void 0)return G(7);return W(q.prf,q.credId,q.attachment,q.transports)}async bind($,Z){if(Z!==void 0){for(let Y of Z)if(!await this.#Y(Y.credId,Y.tag))return G(10)}let[J,Q]=await this.sealWithPasskey($);if(Q!==0)return G(Q);if(J===void 0)return G(12);let X=await this.#X(J.credId);return O({...J,tag:X})}static async unsealWithPasskey($,Z){if($.length===0)return G(22);let J=[];for(let W of $)if(W.credId.byteLength>0)J.push(W.credId);let[Q,X]=await OZ({rpId:Z.rpId,rpName:Z.rpName,hints:Z.hints,credId:J.length>0?J:void 0,salt:Z.salt});if(X!==0)return G(X);if(Q===void 0)return G(7);let Y=$.find((W)=>y0(W.credId,Q.credId)),V=Y===void 0?$:[Y,...$.filter((W)=>W!==Y)];try{for(let W of V){let[q]=await Q0.#G(W.sealedMaster,Q.prf);if(q!==void 0)return O({enclave:q,credId:Q.credId.slice()})}return G(20)}finally{Q.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[Y,V]=await EJ(Z);if(V!==0)return G(V);if(Y===void 0)return G(30);J=Y}let[Q,X]=this.#W($);if(X!==0)return G(X);if(Q===void 0)return G(12);try{let Y=await qZ(J,Q,Z);if(Y!==0)return G(Y);return O(J)}finally{Q.fill(0)}}static async fromLargeBlob($){let[Z,J]=await mJ($?.credId,$);if(J!==0)return G(J);if(Z===void 0)return G(7);try{return Q0.#q(Z.blob,Z.credId)}finally{Z.blob.fill(0)}}static async clearLargeBlob($,Z){return qZ($,new Uint8Array(V0),Z)}static pairRequest(){return R$.create()}async pairAccept($,Z){let J;try{J=await Z0.genX25519()}catch{return G(29)}try{let[Q,X]=await XZ(J.priv,$,$,J.pub);if(X!==0)return G(X);if(Q===void 0)return G(12);try{let[Y,V]=this.#Z(Z);if(V!==0)return G(V);if(Y===void 0)return G(12);try{let W=await Z0.encryptXSalsa20Poly1305Combined(Y,Q);return DJ(K0(J.pub,W))}catch{return G(12)}finally{Y.fill(0)}}finally{Q.fill(0)}}finally{J.priv.fill(0)}}#Z($){let Z=this.#$.slice(),[J,Q]=t(Z);if(Q!==0)return Z.fill(0),G(Q);if(J===void 0)return Z.fill(0),G(10);try{let X={masterSeed:J,hosts:$.map((V)=>({handle:V.handle,label:V.label,idx:V.idx??0}))},Y=new m;try{let V=Y.writeStruct(H$,X);if(V!==0)return G(V);return O(Y.result())}finally{Y.wipe()}}finally{J.fill(0)}}spawnSyncWorker($){let Z=kJ(),J=this.#$.slice();return xJ(Z,{id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(V)=>this.#z(J,V),X=(V)=>this.#M(J,V);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:X}),both:Object.freeze({encrypt:Q,decrypt:X})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,X=await this.#Q(J,Q),Y=X.publicKey;return X.privateKey.fill(0),Object.freeze({publicKey:Y,sign:(V)=>this.#O(J,Q,V),kdmFor:(V)=>this.#K(J,Q,V)})}async#X($){let Z=new Uint8Array(this.#$.byteLength+HZ.byteLength+$.byteLength);Z.set(this.#$,0),Z.set(HZ,this.#$.byteLength),Z.set($,this.#$.byteLength+HZ.byteLength);try{return await Z0.blake3(Z)}finally{Z.fill(0)}}async#Y($,Z){if(Z.byteLength!==bX)return!1;let J=await this.#X($);try{if(J.byteLength!==Z.byteLength)return!1;let Q=0;for(let X=0;X<J.byteLength;X++){let Y=J[X],V=Z[X];if(Y===void 0||V===void 0)return!1;Q|=Y^V}return Q===0}finally{J.fill(0)}}async#V($){let[Z,J]=await SJ(Z0,$);if(J!==0)return G(J);if(Z===void 0)return G(12);try{let Q=await Z0.encryptXSalsa20Poly1305Combined(this.#$,Z);return O$(Q)}catch{return G(12)}finally{Z.fill(0)}}static async#G($,Z){let[,J]=O$($);if(J!==0)return G(J);let[Q,X]=await SJ(Z0,Z);if(X!==0)return G(X);if(Q===void 0)return G(12);let Y;try{try{Y=await Z0.decryptXSalsa20Poly1305Combined($,Q)}catch{return G(20)}return Q0.fromBytes(Y)}finally{Q.fill(0),Y?.fill(0)}}#W($){let Z=this.#$.slice(),[J,Q]=t(Z);if(Q!==0)return Z.fill(0),G(Q);if(J===void 0)return Z.fill(0),G(10);try{let[X,Y]=wJ(J,$);if(Y!==0)return G(Y);if(X===void 0)return G(12);try{let V=new m,W=V.writeStruct(QZ,X);if(W!==0)return G(W);return O(V.result())}finally{X.masterSeed.fill(0)}}finally{J.fill(0)}}static#q($,Z){if($.byteLength===0||$.every((Y)=>Y===0))return G(22);if($.byteLength===V0){if($.every((W)=>W===0))return G(22);let[Y,V]=Q0.fromBytes($);if(V!==0)return G(V);if(Y===void 0)return G(12);return O({enclave:Y,hosts:[],credId:Z})}let J=new v($),[Q,X]=J.readStruct(QZ);if(X!==0)return G(X);if(Q===void 0)return G(14);try{if(Q.masterSeed.every((W)=>W===0))return G(22);let[Y,V]=Q0.fromBytes(Q.masterSeed);if(V!==0)return G(V);if(Y===void 0)return G(12);return O({enclave:Y,hosts:Q.hosts.map((W)=>({...W})),credId:Z})}finally{Q.masterSeed.fill(0)}}async#z($,Z){let J=await this.#J($);try{return await Z0.encryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#M($,Z){let J=await this.#J($);try{return await Z0.decryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#J($){let Z=new Uint8Array(this.#$.byteLength+$.byteLength);Z.set(this.#$,0),Z.set($,this.#$.byteLength);try{return await Z0.blake3(Z)}finally{Z.fill(0)}}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(K0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);try{return await Z0.deriveEd25519KeyPair(J)}finally{J.fill(0)}}async#O($,Z,J){let Q=await this.#Q($,Z);try{return await Z0.signEd25519(J,Q.privateKey)}finally{Q.privateKey.fill(0)}}async#K($,Z,J){let Q=await this.#Q($,Z),X=K0(Q.privateKey,J);Q.privateKey.fill(0);try{return(await Z0.blake3(X)).slice(0,b0)}finally{X.fill(0)}}}async function SJ($,Z,J=lX){if(Z.byteLength<iX)return G(10);let Q=await $.blake3(K0(Z,J));return O(Q.slice(0,hX))}class FZ{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 gJ($,Z,J,Q=0){let X=Z.now(),Y=new m,V=Y.writeVarString($);if(V!==0)return G(V);let q={id:Y.result(),ts:new Date(0)},[z,M]=zJ(q);if(M!==0)return G(M);let N=X.getTime()-q.ts.getTime();return O({eid:z,off:N,ctr:Q,len:J.length,bod:J})}class pX{singletonType;latest;latestOff=-1;emitter=new FZ;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new v(Z.eid),[Q,X]=J.readStruct(t0);if(X!==0)continue;let Y=new m;Y.writeVarString(this.singletonType);let V=Y.result();if(Q.id.length===V.length&&Q.id.every((W,q)=>W===V[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 fJ($,Z,J,Q){let X=new v($.headCph),[Y,V]=X.readStruct(u0);if(V!==0)return G(V);let{sig:W,kdm:q,headCph:z}=Y;if(!await Q.checkSigEd25519(W,z,Z))return G(3);let N=J.deriveCipher(q,"decrypt"),K;try{K=await N.decrypt(z)}catch{return G(20)}return O({kdm:q,headEnc:K})}var c0=aQ(vQ(),1),WV={encode:c0.encode,decode:c0.decode,decodeAsync:c0.decodeAsync},qV=WV;import{Database as zV}from"bun:sqlite";var Iz=Symbol("EntityID");var Pz=Symbol("DerivationSeed"),Uz=Symbol("PublicKey"),Cz=Symbol("PrivateKey"),wz=Symbol("HostSpecificKeyPair"),Tz=Symbol("Hash"),P0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function MV($="diplomatic.db"){let Z=new zV($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
1
+ var Gs=Object.create;var{getPrototypeOf:js,defineProperty:_r,getOwnPropertyNames:Ys}=Object;var Js=Object.prototype.hasOwnProperty;function Qs(e){return this[e]}var Zs,ei,ti=(e,t,r)=>{var n=e!=null&&typeof e==="object";if(n){var s=t?Zs??=new WeakMap:ei??=new WeakMap,i=s.get(e);if(i)return i}r=e!=null?Gs(js(e)):{};let o=t||!e||!e.__esModule?_r(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let c of Ys(e))if(!Js.call(o,c))_r(o,c,{get:Qs.bind(e,c),enumerable:!0})}if(n)s.set(e,o);return o};var j=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Pt=j(function(zn){Object.defineProperty(zn,"__esModule",{value:!0});zn.utf8Count=Ji;zn.utf8EncodeJs=qn;zn.utf8EncodeTE=Fn;zn.utf8Encode=eo;zn.utf8DecodeJs=Wn;zn.utf8DecodeTD=Xn;zn.utf8Decode=so;function Ji(e){let t=e.length,r=0,n=0;while(n<t){let s=e.charCodeAt(n++);if((s&4294967168)===0){r++;continue}else if((s&4294965248)===0)r+=2;else{if(s>=55296&&s<=56319){if(n<t){let i=e.charCodeAt(n);if((i&64512)===56320)++n,s=((s&1023)<<10)+(i&1023)+65536}}if((s&4294901760)===0)r+=3;else r+=4}}return r}function qn(e,t,r){let n=e.length,s=r,i=0;while(i<n){let o=e.charCodeAt(i++);if((o&4294967168)===0){t[s++]=o;continue}else if((o&4294965248)===0)t[s++]=o>>6&31|192;else{if(o>=55296&&o<=56319){if(i<n){let c=e.charCodeAt(i);if((c&64512)===56320)++i,o=((o&1023)<<10)+(c&1023)+65536}}if((o&4294901760)===0)t[s++]=o>>12&15|224,t[s++]=o>>6&63|128;else t[s++]=o>>18&7|240,t[s++]=o>>12&63|128,t[s++]=o>>6&63|128}t[s++]=o&63|128}}var Qi=new TextEncoder,Zi=50;function Fn(e,t,r){Qi.encodeInto(e,t.subarray(r))}function eo(e,t,r){if(e.length>Zi)Fn(e,t,r);else qn(e,t,r)}var to=4096;function Wn(e,t,r){let n=t,s=n+r,i=[],o="";while(n<s){let c=e[n++];if((c&128)===0)i.push(c);else if((c&224)===192){let u=e[n++]&63;i.push((c&31)<<6|u)}else if((c&240)===224){let u=e[n++]&63,f=e[n++]&63;i.push((c&31)<<12|u<<6|f)}else if((c&248)===240){let u=e[n++]&63,f=e[n++]&63,d=e[n++]&63,l=(c&7)<<18|u<<12|f<<6|d;if(l>65535)l-=65536,i.push(l>>>10&1023|55296),l=56320|l&1023;i.push(l)}else i.push(c);if(i.length>=to)o+=String.fromCharCode(...i),i.length=0}if(i.length>0)o+=String.fromCharCode(...i);return o}var ro=new TextDecoder,no=200;function Xn(e,t,r){let n=e.subarray(t,t+r);return ro.decode(n)}function so(e,t,r){if(r>no)return Xn(e,t,r);else return Wn(e,t,r)}});var gr=j(function(Gn){Object.defineProperty(Gn,"__esModule",{value:!0});Gn.ExtData=void 0;class $n{type;data;constructor(e,t){this.type=e,this.data=t}}Gn.ExtData=$n});var vt=j(function(Yn){Object.defineProperty(Yn,"__esModule",{value:!0});Yn.DecodeError=void 0;class Tt extends Error{constructor(e){super(e);let t=Object.create(Tt.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:Tt.name})}}Yn.DecodeError=Tt});var kt=j(function(Qn){Object.defineProperty(Qn,"__esModule",{value:!0});Qn.UINT32_MAX=void 0;Qn.setUint64=ho;Qn.setInt64=po;Qn.getInt64=yo;Qn.getUint64=mo;Qn.UINT32_MAX=4294967295;function ho(e,t,r){let n=r/4294967296,s=r;e.setUint32(t,n),e.setUint32(t+4,s)}function po(e,t,r){let n=Math.floor(r/4294967296),s=r;e.setUint32(t,n),e.setUint32(t+4,s)}function yo(e,t){let r=e.getInt32(t),n=e.getUint32(t+4);return r*4294967296+n}function mo(e,t){let r=e.getUint32(t),n=e.getUint32(t+4);return r*4294967296+n}});var br=j(function(os){Object.defineProperty(os,"__esModule",{value:!0});os.timestampExtension=os.EXT_TIMESTAMP=void 0;os.encodeTimeSpecToTimestamp=ts;os.encodeDateToTimeSpec=rs;os.encodeTimestampExtension=ns;os.decodeTimestampToTimeSpec=ss;os.decodeTimestampExtension=is;var So=vt(),es=kt();os.EXT_TIMESTAMP=-1;var Io=4294967295,Ao=17179869183;function ts({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=Ao)if(t===0&&e<=Io){let r=new Uint8Array(4);return new DataView(r.buffer).setUint32(0,e),r}else{let r=e/4294967296,n=e&4294967295,s=new Uint8Array(8),i=new DataView(s.buffer);return i.setUint32(0,t<<2|r&3),i.setUint32(4,n),s}else{let r=new Uint8Array(12),n=new DataView(r.buffer);return n.setUint32(0,t),(0,es.setInt64)(n,4,e),r}}function rs(e){let t=e.getTime(),r=Math.floor(t/1000),n=(t-r*1000)*1e6,s=Math.floor(n/1e9);return{sec:r+s,nsec:n-s*1e9}}function ns(e){if(e instanceof Date){let t=rs(e);return ts(t)}else return null}function ss(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:{let r=t.getUint32(0),n=0;return{sec:r,nsec:0}}case 8:{let r=t.getUint32(0),n=t.getUint32(4),s=(r&3)*4294967296+n,i=r>>>2;return{sec:s,nsec:i}}case 12:{let r=(0,es.getInt64)(t,4),n=t.getUint32(0);return{sec:r,nsec:n}}default:throw new So.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function is(e){let t=ss(e);return new Date(t.sec*1000+t.nsec/1e6)}os.timestampExtension={type:os.EXT_TIMESTAMP,encode:ns,decode:is}});var Dt=j(function(us){Object.defineProperty(us,"__esModule",{value:!0});us.ExtensionCodec=void 0;var _t=gr(),To=br();class wr{static defaultCodec=new wr;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(To.timestampExtension)}register({type:e,encode:t,decode:r}){if(e>=0)this.encoders[e]=t,this.decoders[e]=r;else{let n=-1-e;this.builtInEncoders[n]=t,this.builtInDecoders[n]=r}}tryToEncode(e,t){for(let r=0;r<this.builtInEncoders.length;r++){let n=this.builtInEncoders[r];if(n!=null){let s=n(e,t);if(s!=null){let i=-1-r;return new _t.ExtData(i,s)}}}for(let r=0;r<this.encoders.length;r++){let n=this.encoders[r];if(n!=null){let s=n(e,t);if(s!=null){let i=r;return new _t.ExtData(i,s)}}}if(e instanceof _t.ExtData)return e;return null}decode(e,t,r){let n=t<0?this.builtInDecoders[-1-t]:this.decoders[t];if(n)return n(e,t,r);else return new _t.ExtData(t,e)}}us.ExtensionCodec=wr});var Sr=j(function(ds){Object.defineProperty(ds,"__esModule",{value:!0});ds.ensureUint8Array=ko;function vo(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer}function ko(e){if(e instanceof Uint8Array)return e;else if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else if(vo(e))return new Uint8Array(e);else return Uint8Array.from(e)}});var Ar=j(function(ps){Object.defineProperty(ps,"__esModule",{value:!0});ps.Encoder=ps.DEFAULT_INITIAL_BUFFER_SIZE=ps.DEFAULT_MAX_DEPTH=void 0;var ls=Pt(),Do=Dt(),hs=kt(),Lo=Sr();ps.DEFAULT_MAX_DEPTH=100;ps.DEFAULT_INITIAL_BUFFER_SIZE=2048;class Ir{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??Do.ExtensionCodec.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??ps.DEFAULT_MAX_DEPTH,this.initialBufferSize=e?.initialBufferSize??ps.DEFAULT_INITIAL_BUFFER_SIZE,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new Ir({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(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw Error(`Too deep objects in depth ${t}`);if(e==null)this.encodeNil();else if(typeof e==="boolean")this.encodeBoolean(e);else if(typeof e==="number")if(!this.forceIntegerToFloat)this.encodeNumber(e);else this.encodeNumberAsFloat(e);else if(typeof e==="string")this.encodeString(e);else if(this.useBigInt64&&typeof e==="bigint")this.encodeBigInt64(e);else this.encodeObject(e,t)}ensureBufferSizeToWrite(e){let t=this.pos+e;if(this.view.byteLength<t)this.resizeBuffer(t*2)}resizeBuffer(e){let t=new ArrayBuffer(e),r=new Uint8Array(t),n=new DataView(t);r.set(this.bytes),this.view=n,this.bytes=r}encodeNil(){this.writeU8(192)}encodeBoolean(e){if(e===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(e){if(!this.forceIntegerToFloat&&Number.isSafeInteger(e))if(e>=0)if(e<128)this.writeU8(e);else if(e<256)this.writeU8(204),this.writeU8(e);else if(e<65536)this.writeU8(205),this.writeU16(e);else if(e<4294967296)this.writeU8(206),this.writeU32(e);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(e);else this.encodeNumberAsFloat(e);else if(e>=-32)this.writeU8(224|e+32);else if(e>=-128)this.writeU8(208),this.writeI8(e);else if(e>=-32768)this.writeU8(209),this.writeI16(e);else if(e>=-2147483648)this.writeU8(210),this.writeI32(e);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(e);else this.encodeNumberAsFloat(e);else this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){if(this.forceFloat32)this.writeU8(202),this.writeF32(e);else this.writeU8(203),this.writeF64(e)}encodeBigInt64(e){if(e>=BigInt(0))this.writeU8(207),this.writeBigUint64(e);else this.writeU8(211),this.writeBigInt64(e)}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){let r=(0,ls.utf8Count)(e);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),(0,ls.utf8Encode)(e,this.bytes,this.pos),this.pos+=r}encodeObject(e,t){let r=this.extensionCodec.tryToEncode(e,this.context);if(r!=null)this.encodeExtension(r);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e==="object")this.encodeMap(e,t);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw Error(`Too large binary: ${t}`);let r=(0,Lo.ensureUint8Array)(e);this.writeU8a(r)}encodeArray(e,t){let r=e.length;if(r<16)this.writeU8(144+r);else if(r<65536)this.writeU8(220),this.writeU16(r);else if(r<4294967296)this.writeU8(221),this.writeU32(r);else throw Error(`Too large array: ${r}`);for(let n of e)this.doEncode(n,t+1)}countWithoutUndefined(e,t){let r=0;for(let n of t)if(e[n]!==void 0)r++;return r}encodeMap(e,t){let r=Object.keys(e);if(this.sortKeys)r.sort();let n=this.ignoreUndefined?this.countWithoutUndefined(e,r):r.length;if(n<16)this.writeU8(128+n);else if(n<65536)this.writeU8(222),this.writeU16(n);else if(n<4294967296)this.writeU8(223),this.writeU32(n);else throw Error(`Too large map object: ${n}`);for(let s of r){let i=e[s];if(!(this.ignoreUndefined&&i===void 0))this.encodeString(s),this.doEncode(i,t+1)}}encodeExtension(e){if(typeof e.data==="function"){let r=e.data(this.pos+6),n=r.length;if(n>=4294967296)throw Error(`Too large extension object: ${n}`);this.writeU8(201),this.writeU32(n),this.writeI8(e.type),this.writeU8a(r);return}let t=e.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw Error(`Too large extension object: ${t}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),(0,hs.setUint64)(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),(0,hs.setInt64)(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}ps.Encoder=Ir});var bs=j(function(gs){Object.defineProperty(gs,"__esModule",{value:!0});gs.encode=Ho;var Ro=Ar();function Ho(e,t){return new Ro.Encoder(t).encodeSharedRef(e)}});var Ss=j(function(ws){Object.defineProperty(ws,"__esModule",{value:!0});ws.prettyByte=Ko;function Ko(e){return`${e<0?"-":""}0x${Math.abs(e).toString(16).padStart(2,"0")}`}});var Us=j(function(As){Object.defineProperty(As,"__esModule",{value:!0});As.CachedKeyDecoder=void 0;var Vo=Pt(),No=16,qo=16;class Is{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=No,t=qo){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let r=0;r<this.maxKeyLength;r++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,r){let n=this.caches[r-1];e:for(let s of n){let i=s.bytes;for(let o=0;o<r;o++)if(i[o]!==e[t+o])continue e;return s.str}return null}store(e,t){let r=this.caches[e.length-1],n={bytes:e,str:t};if(r.length>=this.maxLengthPerKey)r[Math.random()*r.length|0]=n;else r.push(n)}decode(e,t,r){let n=this.find(e,t,r);if(n!=null)return this.hit++,n;this.miss++;let s=(0,Vo.utf8DecodeJs)(e,t,r),i=Uint8Array.prototype.slice.call(e,t,t+r);return this.store(i,s),s}}As.CachedKeyDecoder=Is});var Lt=j(function(vs){Object.defineProperty(vs,"__esModule",{value:!0});vs.Decoder=void 0;var Er=Ss(),Fo=Dt(),Pe=kt(),Wo=Pt(),Bs=Sr(),Xo=Us(),xe=vt(),Ur="array",rt="map_key",Ps="map_value",zo=(e)=>{if(typeof e==="string"||typeof e==="number")return e;throw new xe.DecodeError("The type of key must be string or number but "+typeof e)};class Ts{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=Ur,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=rt,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===Ur){let r=e;r.size=0,r.array=void 0,r.position=0,r.type=void 0}if(e.type===rt||e.type===Ps){let r=e;r.size=0,r.map=void 0,r.readCount=0,r.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var tt=-1,Br=new DataView(new ArrayBuffer(0)),$o=new Uint8Array(Br.buffer);try{Br.getInt8(0)}catch(e){if(!(e 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 Cs=RangeError("Insufficient data"),Go=new Xo.CachedKeyDecoder;class Cr{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=Br;bytes=$o;headByte=tt;stack=new Ts;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??Fo.ExtensionCodec.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??Pe.UINT32_MAX,this.maxBinLength=e?.maxBinLength??Pe.UINT32_MAX,this.maxArrayLength=e?.maxArrayLength??Pe.UINT32_MAX,this.maxMapLength=e?.maxMapLength??Pe.UINT32_MAX,this.maxExtLength=e?.maxExtLength??Pe.UINT32_MAX,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:Go,this.mapKeyConverter=e?.mapKeyConverter??zo}clone(){return new Cr({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=tt,this.stack.reset()}setBuffer(e){let t=(0,Bs.ensureUint8Array)(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===tt&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),r=(0,Bs.ensureUint8Array)(e),n=new Uint8Array(t.length+r.length);n.set(t),n.set(r,t.length),this.setBuffer(n)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:r}=this;return RangeError(`Extra ${t.byteLength-r} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,r;for await(let o of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(o);try{r=this.doDecodeSync(),t=!0}catch(c){if(!(c instanceof RangeError))throw c}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return r}let{headByte:n,pos:s,totalPos:i}=this;throw RangeError(`Insufficient data in parsing ${(0,Er.prettyByte)(n)} at ${i} (${s} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let r=t,n=-1;for await(let s of e){if(t&&n===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(s),r)n=this.readArraySize(),r=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--n===0)break}catch(i){if(!(i instanceof RangeError))throw i}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:while(!0){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)if(this.useBigInt64)t=this.readU64AsBigInt();else t=this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)if(this.useBigInt64)t=this.readI64AsBigInt();else t=this.readI64();else if(e===217){let n=this.lookU8();t=this.decodeString(n,1)}else if(e===218){let n=this.lookU16();t=this.decodeString(n,2)}else if(e===219){let n=this.lookU32();t=this.decodeString(n,4)}else if(e===220){let n=this.readU16();if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else if(e===221){let n=this.readU32();if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else if(e===222){let n=this.readU16();if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e===223){let n=this.readU32();if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e===196){let n=this.lookU8();t=this.decodeBinary(n,1)}else if(e===197){let n=this.lookU16();t=this.decodeBinary(n,2)}else if(e===198){let n=this.lookU32();t=this.decodeBinary(n,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let n=this.lookU8();t=this.decodeExtension(n,1)}else if(e===200){let n=this.lookU16();t=this.decodeExtension(n,2)}else if(e===201){let n=this.lookU32();t=this.decodeExtension(n,4)}else throw new xe.DecodeError(`Unrecognized type byte: ${(0,Er.prettyByte)(e)}`);this.complete();let r=this.stack;while(r.length>0){let n=r.top();if(n.type===Ur)if(n.array[n.position]=t,n.position++,n.position===n.size)t=n.array,r.release(n);else continue e;else if(n.type===rt){if(t==="__proto__")throw new xe.DecodeError("The key __proto__ is not allowed");n.key=this.mapKeyConverter(t),n.type=Ps;continue e}else if(n.map[n.key]=t,n.readCount++,n.readCount===n.size)t=n.map,r.release(n);else{n.key=null,n.type=rt;continue e}}return t}}readHeadByte(){if(this.headByte===tt)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=tt}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;else throw new xe.DecodeError(`Unrecognized array type byte: ${(0,Er.prettyByte)(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new xe.DecodeError(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new xe.DecodeError(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(e,t);return this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new xe.DecodeError(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Cs;let r=this.pos+t,n;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e))n=this.keyDecoder.decode(this.bytes,r,e);else n=(0,Wo.utf8Decode)(this.bytes,r,e);return this.pos+=t+e,n}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===rt;return!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new xe.DecodeError(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Cs;let r=this.pos+t,n=this.bytes.subarray(r,r+e);return this.pos+=t+e,n}decodeExtension(e,t){if(e>this.maxExtLength)throw new xe.DecodeError(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let r=this.view.getInt8(this.pos+t),n=this.decodeBinary(e,t+1);return this.extensionCodec.decode(n,r,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 e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=(0,Pe.getUint64)(this.view,this.pos);return this.pos+=8,e}readI64(){let e=(0,Pe.getInt64)(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}}vs.Decoder=Cr});var Ls=j(function(Ds){Object.defineProperty(Ds,"__esModule",{value:!0});Ds.decode=jo;Ds.decodeMulti=Yo;var _s=Lt();function jo(e,t){return new _s.Decoder(t).decode(e)}function Yo(e,t){return new _s.Decoder(t).decodeMulti(e)}});var Ks=j(function(Ms){Object.defineProperty(Ms,"__esModule",{value:!0});Ms.isAsyncIterable=Rs;Ms.asyncIterableFromStream=Hs;Ms.ensureAsyncIterable=Zo;function Rs(e){return e[Symbol.asyncIterator]!=null}async function*Hs(e){let t=e.getReader();try{while(!0){let{done:r,value:n}=await t.read();if(r)return;yield n}}finally{t.releaseLock()}}function Zo(e){if(Rs(e))return e;else return Hs(e)}});var Vs=j(function(Os){Object.defineProperty(Os,"__esModule",{value:!0});Os.decodeAsync=na;Os.decodeArrayStream=sa;Os.decodeMultiStream=ia;var Pr=Lt(),Tr=Ks();async function na(e,t){let r=(0,Tr.ensureAsyncIterable)(e);return new Pr.Decoder(t).decodeAsync(r)}function sa(e,t){let r=(0,Tr.ensureAsyncIterable)(e);return new Pr.Decoder(t).decodeArrayStream(r)}function ia(e,t){let r=(0,Tr.ensureAsyncIterable)(e);return new Pr.Decoder(t).decodeStream(r)}});var qs=j(function(M){Object.defineProperty(M,"__esModule",{value:!0});M.decodeTimestampExtension=M.encodeTimestampExtension=M.decodeTimestampToTimeSpec=M.encodeTimeSpecToTimestamp=M.encodeDateToTimeSpec=M.EXT_TIMESTAMP=M.ExtData=M.ExtensionCodec=M.Encoder=M.DecodeError=M.Decoder=M.decodeMultiStream=M.decodeArrayStream=M.decodeAsync=M.decodeMulti=M.decode=M.encode=void 0;var ua=bs();Object.defineProperty(M,"encode",{enumerable:!0,get:function(){return ua.encode}});var Ns=Ls();Object.defineProperty(M,"decode",{enumerable:!0,get:function(){return Ns.decode}});Object.defineProperty(M,"decodeMulti",{enumerable:!0,get:function(){return Ns.decodeMulti}});var vr=Vs();Object.defineProperty(M,"decodeAsync",{enumerable:!0,get:function(){return vr.decodeAsync}});Object.defineProperty(M,"decodeArrayStream",{enumerable:!0,get:function(){return vr.decodeArrayStream}});Object.defineProperty(M,"decodeMultiStream",{enumerable:!0,get:function(){return vr.decodeMultiStream}});var fa=Lt();Object.defineProperty(M,"Decoder",{enumerable:!0,get:function(){return fa.Decoder}});var da=vt();Object.defineProperty(M,"DecodeError",{enumerable:!0,get:function(){return da.DecodeError}});var la=Ar();Object.defineProperty(M,"Encoder",{enumerable:!0,get:function(){return la.Encoder}});var ha=Dt();Object.defineProperty(M,"ExtensionCodec",{enumerable:!0,get:function(){return ha.ExtensionCodec}});var pa=gr();Object.defineProperty(M,"ExtData",{enumerable:!0,get:function(){return pa.ExtData}});var ze=br();Object.defineProperty(M,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return ze.EXT_TIMESTAMP}});Object.defineProperty(M,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return ze.encodeDateToTimeSpec}});Object.defineProperty(M,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return ze.encodeTimeSpecToTimestamp}});Object.defineProperty(M,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return ze.decodeTimestampToTimeSpec}});Object.defineProperty(M,"encodeTimestampExtension",{enumerable:!0,get:function(){return ze.encodeTimestampExtension}});Object.defineProperty(M,"decodeTimestampExtension",{enumerable:!0,get:function(){return ze.decodeTimestampExtension}})});import*as ue from"node:crypto";var Se=ue&&typeof ue==="object"&&"webcrypto"in ue?ue.webcrypto:ue&&typeof ue==="object"&&("randomBytes"in ue)?ue:void 0;function nt(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)}function Rt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function q(e,...t){if(!Rt(e))throw Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ht(e,t=!0){if(e.destroyed)throw Error("Hash instance has been destroyed");if(t&&e.finished)throw Error("Hash#digest() has already been called")}function Dr(e,t){q(e);let r=t.outputLen;if(e.length<r)throw Error("digestInto() expects output buffer of length at least "+r)}function Mt(e){if(typeof e!=="boolean")throw Error(`boolean expected, not ${e}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var fe=(e)=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));var ri=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ri)throw Error("Non little-endian hardware is not supported");function ni(e){if(typeof e!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function st(e){if(typeof e==="string")e=ni(e);else if(Rt(e))e=it(e);else throw Error("Uint8Array expected, got "+typeof e);return e}function Lr(e,t){if(t==null||typeof t!=="object")throw Error("options must be defined");return Object.assign(e,t)}function Rr(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var Hr=(e,t)=>{function r(n,...s){if(q(n),e.nonceLength!==void 0){let d=s[0];if(!d)throw Error("nonce / iv required");if(e.varSizeNonce)q(d);else q(d,e.nonceLength)}let i=e.tagLength;if(i&&s[1]!==void 0)q(s[1]);let o=t(n,...s),c=(d,l)=>{if(l!==void 0){if(d!==2)throw Error("cipher output not supported");q(l)}},u=!1;return{encrypt(d,l){if(u)throw Error("cannot encrypt() twice with same key + nonce");return u=!0,q(d),c(o.encrypt.length,l),o.encrypt(d,l)},decrypt(d,l){if(q(d),i&&d.length<i)throw Error("invalid ciphertext length: smaller than tagLength="+i);return c(o.decrypt.length,l),o.decrypt(d,l)}}}return Object.assign(r,e),r};function Kt(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw Error("invalid output length, expected "+e+", got: "+t.length);if(r&&!si(t))throw Error("invalid output, must be aligned");return t}function si(e){return e.byteOffset%4===0}function it(e){return Uint8Array.from(e)}function se(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ge(e=32){if(Se&&typeof Se.getRandomValues==="function")return Se.getRandomValues(new Uint8Array(e));if(Se&&typeof Se.randomBytes==="function")return Se.randomBytes(e);throw Error("crypto.getRandomValues must be defined")}var Kr=(e)=>Uint8Array.from(e.split("").map((t)=>t.charCodeAt(0))),ii=Kr("expand 16-byte k"),oi=Kr("expand 32-byte k"),ai=fe(ii),ci=fe(oi);function w(e,t){return e<<t|e>>>32-t}function Ot(e){return e.byteOffset%4===0}var ot=64,ui=16,Or=4294967295,Mr=new Uint32Array;function fi(e,t,r,n,s,i,o,c){let u=s.length,f=new Uint8Array(ot),d=fe(f),l=Ot(s)&&Ot(i),p=l?fe(s):Mr,y=l?fe(i):Mr;for(let g=0;g<u;o++){if(e(t,r,n,d,o,c),o>=Or)throw Error("arx: counter overflow");let x=Math.min(ot,u-g);if(l&&x===ot){let b=g/4;if(g%4!==0)throw Error("arx: invalid block position");for(let I=0,A;I<ui;I++)A=b+I,y[A]=p[A]^d[I];g+=ot;continue}for(let b=0,I;b<x;b++)I=g+b,i[I]=s[I]^f[b];g+=x}}function Vr(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:i,rounds:o}=Lr({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!=="function")throw Error("core must be a function");return nt(s),nt(o),Mt(i),Mt(r),(c,u,f,d,l=0)=>{q(c),q(u),q(f);let p=f.length;if(d===void 0)d=new Uint8Array(p);if(q(d),nt(l),l<0||l>=Or)throw Error("arx: counter overflow");if(d.length<p)throw Error(`arx: output (${d.length}) is shorter than data (${p})`);let y=[],g=c.length,x,b;if(g===32)y.push(x=it(c)),b=ci;else if(g===16&&r)x=new Uint8Array(32),x.set(c),x.set(c,16),b=ai,y.push(x);else throw Error(`arx: invalid 32-byte key, got length=${g}`);if(!Ot(u))y.push(u=it(u));let I=fe(x);if(n){if(u.length!==24)throw Error("arx: extended nonce must be 24 bytes");n(b,I,fe(u.subarray(0,16)),I),u=u.subarray(16)}let A=16-s;if(A!==u.length)throw Error(`arx: nonce must be ${A} or 16 bytes`);if(A!==12){let S=new Uint8Array(12);S.set(u,i?0:12-u.length),u=S,y.push(u)}let U=fe(u);return fi(e,b,I,U,f,d,l,o),se(...y),d}}var W=(e,t)=>e[t++]&255|(e[t++]&255)<<8;class Nr{constructor(e){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,e=st(e),q(e,32);let t=W(e,0),r=W(e,2),n=W(e,4),s=W(e,6),i=W(e,8),o=W(e,10),c=W(e,12),u=W(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|r<<3)&8191,this.r[2]=(r>>>10|n<<6)&7939,this.r[3]=(n>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|o<<2)&8191,this.r[7]=(o>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=W(e,16+2*f)}process(e,t,r=!1){let n=r?0:2048,{h:s,r:i}=this,o=i[0],c=i[1],u=i[2],f=i[3],d=i[4],l=i[5],p=i[6],y=i[7],g=i[8],x=i[9],b=W(e,t+0),I=W(e,t+2),A=W(e,t+4),U=W(e,t+6),S=W(e,t+8),C=W(e,t+10),k=W(e,t+12),F=W(e,t+14),v=s[0]+(b&8191),D=s[1]+((b>>>13|I<<3)&8191),R=s[2]+((I>>>10|A<<6)&8191),L=s[3]+((A>>>7|U<<9)&8191),H=s[4]+((U>>>4|S<<12)&8191),m=s[5]+(S>>>1&8191),K=s[6]+((S>>>14|C<<2)&8191),O=s[7]+((C>>>11|k<<5)&8191),V=s[8]+((k>>>8|F<<8)&8191),N=s[9]+(F>>>5|n),E=0,G=E+v*o+D*(5*x)+R*(5*g)+L*(5*y)+H*(5*p);E=G>>>13,G&=8191,G+=m*(5*l)+K*(5*d)+O*(5*f)+V*(5*u)+N*(5*c),E+=G>>>13,G&=8191;let J=E+v*c+D*o+R*(5*x)+L*(5*g)+H*(5*y);E=J>>>13,J&=8191,J+=m*(5*p)+K*(5*l)+O*(5*d)+V*(5*f)+N*(5*u),E+=J>>>13,J&=8191;let Z=E+v*u+D*c+R*o+L*(5*x)+H*(5*g);E=Z>>>13,Z&=8191,Z+=m*(5*y)+K*(5*p)+O*(5*l)+V*(5*d)+N*(5*f),E+=Z>>>13,Z&=8191;let _=E+v*f+D*u+R*c+L*o+H*(5*x);E=_>>>13,_&=8191,_+=m*(5*g)+K*(5*y)+O*(5*p)+V*(5*l)+N*(5*d),E+=_>>>13,_&=8191;let ce=E+v*d+D*f+R*u+L*c+H*o;E=ce>>>13,ce&=8191,ce+=m*(5*x)+K*(5*g)+O*(5*y)+V*(5*p)+N*(5*l),E+=ce>>>13,ce&=8191;let Te=E+v*l+D*d+R*f+L*u+H*c;E=Te>>>13,Te&=8191,Te+=m*o+K*(5*x)+O*(5*g)+V*(5*y)+N*(5*p),E+=Te>>>13,Te&=8191;let ve=E+v*p+D*l+R*d+L*f+H*u;E=ve>>>13,ve&=8191,ve+=m*c+K*o+O*(5*x)+V*(5*g)+N*(5*y),E+=ve>>>13,ve&=8191;let ke=E+v*y+D*p+R*l+L*d+H*f;E=ke>>>13,ke&=8191,ke+=m*u+K*c+O*o+V*(5*x)+N*(5*g),E+=ke>>>13,ke&=8191;let _e=E+v*g+D*y+R*p+L*l+H*d;E=_e>>>13,_e&=8191,_e+=m*f+K*u+O*c+V*o+N*(5*x),E+=_e>>>13,_e&=8191;let De=E+v*x+D*g+R*y+L*p+H*l;E=De>>>13,De&=8191,De+=m*d+K*f+O*u+V*c+N*o,E+=De>>>13,De&=8191,E=(E<<2)+E|0,E=E+G|0,G=E&8191,E=E>>>13,J+=E,s[0]=G,s[1]=J,s[2]=Z,s[3]=_,s[4]=ce,s[5]=Te,s[6]=ve,s[7]=ke,s[8]=_e,s[9]=De}finalize(){let{h:e,pad:t}=this,r=new Uint16Array(10),n=e[1]>>>13;e[1]&=8191;for(let o=2;o<10;o++)e[o]+=n,n=e[o]>>>13,e[o]&=8191;e[0]+=n*5,n=e[0]>>>13,e[0]&=8191,e[1]+=n,n=e[1]>>>13,e[1]&=8191,e[2]+=n,r[0]=e[0]+5,n=r[0]>>>13,r[0]&=8191;for(let o=1;o<10;o++)r[o]=e[o]+n,n=r[o]>>>13,r[o]&=8191;r[9]-=8192;let s=(n^1)-1;for(let o=0;o<10;o++)r[o]&=s;s=~s;for(let o=0;o<10;o++)e[o]=e[o]&s|r[o];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+t[0];e[0]=i&65535;for(let o=1;o<8;o++)i=(e[o]+t[o]|0)+(i>>>16)|0,e[o]=i&65535;se(r)}update(e){Ht(this);let{buffer:t,blockLen:r}=this;e=st(e);let n=e.length;for(let s=0;s<n;){let i=Math.min(r-this.pos,n-s);if(i===r){for(;r<=n-s;s+=r)this.process(e,s);continue}if(t.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===r)this.process(t,0,!1),this.pos=0}return this}destroy(){se(this.h,this.r,this.buffer,this.pad)}digestInto(e){Ht(this),Dr(e,this),this.finished=!0;let{buffer:t,h:r}=this,{pos:n}=this;if(n){t[n++]=1;for(;n<16;n++)t[n]=0;this.process(t,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)e[s++]=r[i]>>>0,e[s++]=r[i]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let r=e.slice(0,t);return this.destroy(),r}}function di(e){let t=(n,s)=>e(s).update(st(n)).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=(n)=>e(n),t}var Vt=di((e)=>new Nr(e));function li(e,t,r,n,s,i=20){let o=e[0],c=t[0],u=t[1],f=t[2],d=t[3],l=e[1],p=r[0],y=r[1],g=s,x=0,b=e[2],I=t[4],A=t[5],U=t[6],S=t[7],C=e[3],k=o,F=c,v=u,D=f,R=d,L=l,H=p,m=y,K=g,O=x,V=b,N=I,E=A,G=U,J=S,Z=C;for(let ce=0;ce<i;ce+=2)R^=w(k+E|0,7),K^=w(R+k|0,9),E^=w(K+R|0,13),k^=w(E+K|0,18),O^=w(L+F|0,7),G^=w(O+L|0,9),F^=w(G+O|0,13),L^=w(F+G|0,18),J^=w(V+H|0,7),v^=w(J+V|0,9),H^=w(v+J|0,13),V^=w(H+v|0,18),D^=w(Z+N|0,7),m^=w(D+Z|0,9),N^=w(m+D|0,13),Z^=w(N+m|0,18),F^=w(k+D|0,7),v^=w(F+k|0,9),D^=w(v+F|0,13),k^=w(D+v|0,18),H^=w(L+R|0,7),m^=w(H+L|0,9),R^=w(m+H|0,13),L^=w(R+m|0,18),N^=w(V+O|0,7),K^=w(N+V|0,9),O^=w(K+N|0,13),V^=w(O+K|0,18),E^=w(Z+J|0,7),G^=w(E+Z|0,9),J^=w(G+E|0,13),Z^=w(J+G|0,18);let _=0;n[_++]=o+k|0,n[_++]=c+F|0,n[_++]=u+v|0,n[_++]=f+D|0,n[_++]=d+R|0,n[_++]=l+L|0,n[_++]=p+H|0,n[_++]=y+m|0,n[_++]=g+K|0,n[_++]=x+O|0,n[_++]=b+V|0,n[_++]=I+N|0,n[_++]=A+E|0,n[_++]=U+G|0,n[_++]=S+J|0,n[_++]=C+Z|0}function hi(e,t,r,n){let s=e[0],i=t[0],o=t[1],c=t[2],u=t[3],f=e[1],d=r[0],l=r[1],p=r[2],y=r[3],g=e[2],x=t[4],b=t[5],I=t[6],A=t[7],U=e[3];for(let C=0;C<20;C+=2)u^=w(s+b|0,7),p^=w(u+s|0,9),b^=w(p+u|0,13),s^=w(b+p|0,18),y^=w(f+i|0,7),I^=w(y+f|0,9),i^=w(I+y|0,13),f^=w(i+I|0,18),A^=w(g+d|0,7),o^=w(A+g|0,9),d^=w(o+A|0,13),g^=w(d+o|0,18),c^=w(U+x|0,7),l^=w(c+U|0,9),x^=w(l+c|0,13),U^=w(x+l|0,18),i^=w(s+c|0,7),o^=w(i+s|0,9),c^=w(o+i|0,13),s^=w(c+o|0,18),d^=w(f+u|0,7),l^=w(d+f|0,9),u^=w(l+d|0,13),f^=w(u+l|0,18),x^=w(g+y|0,7),p^=w(x+g|0,9),y^=w(p+x|0,13),g^=w(y+p|0,18),b^=w(U+A|0,7),I^=w(b+U|0,9),A^=w(I+b|0,13),U^=w(A+I|0,18);let S=0;n[S++]=s,n[S++]=f,n[S++]=g,n[S++]=U,n[S++]=d,n[S++]=l,n[S++]=p,n[S++]=y}var Nt=Vr(li,{counterRight:!0,extendNonceFn:hi}),qt=Hr({blockSize:64,nonceLength:24,tagLength:16},(e,t)=>({encrypt(r,n){n=Kt(r.length+32,n,!1);let s=n.subarray(0,32),i=n.subarray(32);n.set(r,32),se(s),Nt(e,t,n,n);let o=Vt(i,s);return n.set(o,16),se(n.subarray(0,16),o),n.subarray(16)},decrypt(r,n){q(r),n=Kt(r.length+32,n,!1);let s=n.subarray(0,32),i=n.subarray(32,48),o=n.subarray(48);n.set(r,32),se(s);let c=Nt(e,t,s,s),u=Vt(o,c);if(!Rr(i,u))throw Error("invalid tag");return Nt(e,t,n.subarray(16),n.subarray(16)),se(s,i,u),o}}));/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function pi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function je(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)}function Ie(e,...t){if(!pi(e))throw Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ye(e,t=!0){if(e.destroyed)throw Error("Hash instance has been destroyed");if(t&&e.finished)throw Error("Hash#digest() has already been called")}function at(e,t){Ie(e);let r=t.outputLen;if(e.length<r)throw Error("digestInto() expects output buffer of length at least "+r)}function qr(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function Le(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Re(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Je(e,t){return e<<32-t|e>>>t}var Fr=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function Wr(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}var Xr=Fr?(e)=>e:(e)=>Wr(e);function yi(e){for(let t=0;t<e.length;t++)e[t]=Wr(e[t]);return e}var Q=Fr?(e)=>e:yi;function mi(e){if(typeof e!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function He(e){if(typeof e==="string")e=mi(e);return Ie(e),e}class Ft{}function zr(e){let t=(n,s)=>e(s).update(He(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=(n)=>e(n),t}var $r=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=BigInt(4294967295),Gr=BigInt(32);function Wt(e,t=!1){if(t)return{h:Number(e&ct),l:Number(e>>Gr&ct)};return{h:Number(e>>Gr&ct)|0,l:Number(e&ct)|0}}function de(e,t,r,n,s){return e=e+t+s|0,n=Je(n^e,16),r=r+n|0,t=Je(t^r,12),{a:e,b:t,c:r,d:n}}function le(e,t,r,n,s){return e=e+t+s|0,n=Je(n^e,8),r=r+n|0,t=Je(t^r,7),{a:e,b:t,c:r,d:n}}class Xt extends Ft{constructor(e,t){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,je(e),je(t),this.blockLen=e,this.outputLen=t,this.buffer=new Uint8Array(e),this.buffer32=Le(this.buffer)}update(e){Ye(this),e=He(e),Ie(e);let{blockLen:t,buffer:r,buffer32:n}=this,s=e.length,i=e.byteOffset,o=e.buffer;for(let c=0;c<s;){if(this.pos===t)Q(n),this.compress(n,0,!1),Q(n),this.pos=0;let u=Math.min(t-this.pos,s-c),f=i+c;if(u===t&&!(f%4)&&c+u<s){let d=new Uint32Array(o,f,Math.floor((s-c)/4));Q(d);for(let l=0;c+t<s;l+=n.length,c+=t)this.length+=t,this.compress(d,l,!1);Q(d);continue}r.set(e.subarray(c,c+u),this.pos),this.pos+=u,this.length+=u,c+=u}return this}digestInto(e){Ye(this),at(e,this);let{pos:t,buffer32:r}=this;this.finished=!0,Re(this.buffer.subarray(t)),Q(r),this.compress(r,0,!0),Q(r);let n=Le(e);this.get().forEach((s,i)=>n[i]=Xr(s))}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){let{buffer:t,length:r,finished:n,destroyed:s,outputLen:i,pos:o}=this;return e||(e=new this.constructor({dkLen:i})),e.set(...this.get()),e.buffer.set(t),e.destroyed=s,e.finished=n,e.length=r,e.pos=o,e.outputLen=i,e}clone(){return this._cloneInto()}}function zt(e,t,r,n,s,i,o,c,u,f,d,l,p,y,g,x,b,I,A,U){let S=0;for(let C=0;C<n;C++)({a:s,b:u,c:p,d:b}=de(s,u,p,b,r[t+e[S++]])),{a:s,b:u,c:p,d:b}=le(s,u,p,b,r[t+e[S++]]),{a:i,b:f,c:y,d:I}=de(i,f,y,I,r[t+e[S++]]),{a:i,b:f,c:y,d:I}=le(i,f,y,I,r[t+e[S++]]),{a:o,b:d,c:g,d:A}=de(o,d,g,A,r[t+e[S++]]),{a:o,b:d,c:g,d:A}=le(o,d,g,A,r[t+e[S++]]),{a:c,b:l,c:x,d:U}=de(c,l,x,U,r[t+e[S++]]),{a:c,b:l,c:x,d:U}=le(c,l,x,U,r[t+e[S++]]),{a:s,b:f,c:g,d:U}=de(s,f,g,U,r[t+e[S++]]),{a:s,b:f,c:g,d:U}=le(s,f,g,U,r[t+e[S++]]),{a:i,b:d,c:x,d:b}=de(i,d,x,b,r[t+e[S++]]),{a:i,b:d,c:x,d:b}=le(i,d,x,b,r[t+e[S++]]),{a:o,b:l,c:p,d:I}=de(o,l,p,I,r[t+e[S++]]),{a:o,b:l,c:p,d:I}=le(o,l,p,I,r[t+e[S++]]),{a:c,b:u,c:y,d:A}=de(c,u,y,A,r[t+e[S++]]),{a:c,b:u,c:y,d:A}=le(c,u,y,A,r[t+e[S++]]);return{v0:s,v1:i,v2:o,v3:c,v4:u,v5:f,v6:d,v7:l,v8:p,v9:y,v10:g,v11:x,v12:b,v13:I,v14:A,v15:U}}var ie={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},he=$r.slice(),jr=(()=>{let e=Array.from({length:16},(n,s)=>s),t=(n)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((s)=>n[s]),r=[];for(let n=0,s=e;n<7;n++,s=t(s))r.push(...s);return Uint8Array.from(r)})();class $t extends Xt{constructor(e={},t=0){super(64,e.dkLen===void 0?32:e.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:r,context:n}=e,s=n!==void 0;if(r!==void 0){if(s)throw Error('Only "key" or "context" can be specified at same time');let i=He(r).slice();Ie(i,32),this.IV=Le(i),Q(this.IV),this.flags=t|ie.KEYED_HASH}else if(s){let i=He(n),o=new $t({dkLen:32},ie.DERIVE_KEY_CONTEXT).update(i).digest();this.IV=Le(o),Q(this.IV),this.flags=t|ie.DERIVE_KEY_MATERIAL}else this.IV=he.slice(),this.flags=t;this.state=this.IV.slice(),this.bufferOut=qr(this.bufferOut32)}get(){return[]}set(){}b2Compress(e,t,r,n=0){let{state:s,pos:i}=this,{h:o,l:c}=Wt(BigInt(e),!0),{v0:u,v1:f,v2:d,v3:l,v4:p,v5:y,v6:g,v7:x,v8:b,v9:I,v10:A,v11:U,v12:S,v13:C,v14:k,v15:F}=zt(jr,n,r,7,s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],he[0],he[1],he[2],he[3],o,c,i,t);s[0]=u^b,s[1]=f^I,s[2]=d^A,s[3]=l^U,s[4]=p^S,s[5]=y^C,s[6]=g^k,s[7]=x^F}compress(e,t=0,r=!1){let n=this.flags;if(!this.chunkPos)n|=ie.CHUNK_START;if(this.chunkPos===15||r)n|=ie.CHUNK_END;if(!r)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,n,e,t),this.chunkPos+=1,this.chunkPos===16||r){let s=this.state;this.state=this.IV.slice();for(let i,o=this.chunksDone+1;r||!(o&1);o>>=1){if(!(i=this.stack.pop()))break;this.buffer32.set(i,0),this.buffer32.set(s,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|ie.PARENT,this.buffer32,0),s=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(s)}this.pos=0}_cloneInto(e){e=super._cloneInto(e);let{IV:t,flags:r,state:n,chunkPos:s,posOut:i,chunkOut:o,stack:c,chunksDone:u}=this;return e.state.set(n.slice()),e.stack=c.map((f)=>Uint32Array.from(f)),e.IV.set(t),e.flags=r,e.chunkPos=s,e.chunksDone=u,e.posOut=i,e.chunkOut=o,e.enableXOF=this.enableXOF,e.bufferOut32.set(this.bufferOut32),e}destroy(){this.destroyed=!0,Re(this.state,this.buffer32,this.IV,this.bufferOut32),Re(...this.stack)}b2CompressOut(){let{state:e,pos:t,flags:r,buffer32:n,bufferOut32:s}=this,{h:i,l:o}=Wt(BigInt(this.chunkOut++));Q(n);let{v0:c,v1:u,v2:f,v3:d,v4:l,v5:p,v6:y,v7:g,v8:x,v9:b,v10:I,v11:A,v12:U,v13:S,v14:C,v15:k}=zt(jr,0,n,7,e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],he[0],he[1],he[2],he[3],o,i,t,r);s[0]=c^x,s[1]=u^b,s[2]=f^I,s[3]=d^A,s[4]=l^U,s[5]=p^S,s[6]=y^C,s[7]=g^k,s[8]=e[0]^x,s[9]=e[1]^b,s[10]=e[2]^I,s[11]=e[3]^A,s[12]=e[4]^U,s[13]=e[5]^S,s[14]=e[6]^C,s[15]=e[7]^k,Q(n),Q(s),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,Re(this.buffer.subarray(this.pos));let e=this.flags|ie.ROOT;if(this.stack.length)e|=ie.PARENT,Q(this.buffer32),this.compress(this.buffer32,0,!0),Q(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else e|=(!this.chunkPos?ie.CHUNK_START:0)|ie.CHUNK_END;this.flags=e,this.b2CompressOut()}writeInto(e){Ye(this,!1),Ie(e),this.finish();let{blockLen:t,bufferOut:r}=this;for(let n=0,s=e.length;n<s;){if(this.posOut>=t)this.b2CompressOut();let i=Math.min(t-this.posOut,s-n);e.set(r.subarray(this.posOut,this.posOut+i),n),this.posOut+=i,n+=i}return e}xofInto(e){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto(e)}xof(e){return je(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(at(e,this),this.finished)throw Error("digest() was already called");return this.enableXOF=!1,this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}}var Yr=zr((e)=>new $t(e));function ee(e){return Array.from(e).map((r)=>r.toString(16).padStart(2,"0")).join("")}function ut(e){if(e.length%2!==0)throw Error("Invalid hex string");let t=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)t[r/2]=Number.parseInt(e.substr(r,2),16);return t}function Me(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;return e.every((r,n)=>r===t[n])}var Jr;if(typeof Uint8Array.prototype.toBase64==="function")Jr=(e)=>e.toBase64();else Jr=(e)=>btoa(String.fromCharCode(...e));var Gt;if(typeof Uint8Array.fromBase64==="function")Gt=(e)=>Uint8Array.fromBase64(e);else Gt=(e)=>Uint8Array.from(atob(e),(t)=>t.charCodeAt(0));function Qr(e){let t=e.length%4===0?"":"=".repeat(4-e.length%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t;return Gt(r)}function pe(e,t){let r=new Uint8Array(e.length+t.length);return r.set(e,0),r.set(t,e.length),r}var Ke=64;var Zr=32,Oe=8;var en=32;var tn=30000,rn=512,B;((m)=>{m[m.Success=0]="Success";m[m.InvalidSignature=3]="InvalidSignature";m[m.ClockOutOfSync=4]="ClockOutOfSync";m[m.UserNotRegistered=5]="UserNotRegistered";m[m.ServerMisconfigured=6]="ServerMisconfigured";m[m.MissingBody=7]="MissingBody";m[m.ExtraBodyContent=8]="ExtraBodyContent";m[m.MissingParam=9]="MissingParam";m[m.InvalidParam=10]="InvalidParam";m[m.InvalidRequest=11]="InvalidRequest";m[m.InternalError=12]="InternalError";m[m.NotFound=13]="NotFound";m[m.InvalidMessage=14]="InvalidMessage";m[m.NoChange=15]="NoChange";m[m.DatabaseClosed=16]="DatabaseClosed";m[m.StorageError=17]="StorageError";m[m.DatabaseError=18]="DatabaseError";m[m.HashMismatch=19]="HashMismatch";m[m.DecryptionError=20]="DecryptionError";m[m.NotImplemented=21]="NotImplemented";m[m.MissingSeed=22]="MissingSeed";m[m.OutOfBounds=23]="OutOfBounds";m[m.HostError=24]="HostError";m[m.CommunicationError=25]="CommunicationError";m[m.VarLimitExceeded=26]="VarLimitExceeded";m[m.InvalidResponse=27]="InvalidResponse";m[m.ConnectionClosed=28]="ConnectionClosed";m[m.CryptoError=29]="CryptoError";m[m.WebAuthnError=30]="WebAuthnError"})(B||={});var nn="t";function h(e){return[e,0]}function a(e){return[void 0,e]}var xi=32,cc=Symbol("X25519Sk");function sn(e){if(e.byteLength!==xi)return a(10);return h(e)}var P=(1n<<255n)-19n,gi=121665n,on=new Uint8Array(32);on[0]=9;function an(e){let t=0n;for(let r=e.length-1;r>=0;r--)t=t<<8n|BigInt(e[r]);return t}function bi(e){let t=new Uint8Array(32),r=(e%P+P)%P;for(let n=0;n<32;n++)t[n]=Number(r&0xffn),r>>=8n;return t}function wi(e){let t=e.slice();return t[31]&=127,an(t)}function Si(e){let t=e.slice();return t[0]&=248,t[31]&=127,t[31]|=64,t}function ft(e,t,r){let n=-e,s=(t^r)&n;return[t^s,r^s]}function Ii(e){let t=P-2n,r=(e%P+P)%P,n=1n;while(t>0n){if(t&1n)n=n*r%P;r=r*r%P,t>>=1n}return n}function Ai(e,t){let r=Si(e),n=wi(t),s=1n,i=0n,o=n,c=1n,u=0n,f=an(r);for(let d=254;d>=0;d--){let l=f>>BigInt(d)&1n;u^=l,[s,o]=ft(u,s,o),[i,c]=ft(u,i,c),u=l;let p=(s+i)%P,y=p*p%P,g=(s-i+P)%P,x=g*g%P,b=(y-x+P)%P,I=(o+c)%P,U=(o-c+P)%P*p%P,S=I*g%P,C=(U+S)%P,k=(U-S+P)%P;o=C*C%P,c=n*k*k%P,s=y*x%P,i=b*(y+gi*b)%P}return[s,o]=ft(u,s,o),[i,c]=ft(u,i,c),r.fill(0),bi(s*Ii(i)%P)}function cn(e){return Ai(e,on)}var jt=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function un(e){let t=new Uint8Array(jt.length+32);return t.set(jt),t.set(e.subarray(0,32),jt.length),t}var Yt=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,110,4,34,4,32]);function fn(e){let t=new Uint8Array(Yt.length+32);return t.set(Yt),t.set(e.subarray(0,32),Yt.length),t}function dn(e){return typeof e==="string"?new TextEncoder().encode(e):e}function ye(e){let t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(e),t}class Ae{verifyKeys=new Map;async genRandomBytes(e){return Ge(e)}async gen256BitSecureRandomSeed(){return Ge(32)}async encryptXSalsa20Poly1305Combined(e,t){let r=Ge(24),s=qt(t,r).encrypt(e);return new Uint8Array([...r,...s])}async decryptXSalsa20Poly1305Combined(e,t){let r=e.slice(0,24),n=e.slice(24);return qt(t,r).decrypt(n)}async deriveEd25519KeyPair(e){let t=e,r=un(t),n=ye(r),s;try{let f=await globalThis.crypto.subtle.importKey("pkcs8",n,{name:"Ed25519"},!0,["sign"]);s=await globalThis.crypto.subtle.exportKey("jwk",f)}finally{r.fill(0),new Uint8Array(n).fill(0)}if(typeof s.x!=="string")throw Error("Ed25519 JWK missing x");let i=s.x;s.d=void 0;let o=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:i},{name:"Ed25519"},!0,["verify"]),c=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",o));this.verifyKeys.set(ee(c),o);let u=new Uint8Array(64);return u.set(t,0),u.set(c,32),{keyType:"ed25519",privateKey:u,publicKey:c}}async importSignKey(e){let t=e.subarray(0,32),r=un(t),n=ye(r);try{return await globalThis.crypto.subtle.importKey("pkcs8",n,{name:"Ed25519"},!1,["sign"])}finally{r.fill(0),new Uint8Array(n).fill(0)}}async importVerifyKey(e){let t=ee(e),r=this.verifyKeys.get(t);if(r)return r;let n=await globalThis.crypto.subtle.importKey("raw",ye(e),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(t,n),n}async signEd25519(e,t){let r=dn(e),n=await this.importSignKey(t),s=await globalThis.crypto.subtle.sign({name:"Ed25519"},n,ye(r));return new Uint8Array(s)}async checkSigEd25519(e,t,r){let n=dn(t);try{let s=await this.importVerifyKey(r);return await globalThis.crypto.subtle.verify({name:"Ed25519"},s,ye(e),ye(n))}catch{return!1}}async blake3(e){return Yr(e)}async genX25519(){let e=await Ge(32);e[0]&=248,e[31]&=127,e[31]|=64;let[t,r]=sn(e);if(r!==0||t===void 0)throw e.fill(0),Error("X25519 scalar brand failed");let n=cn(t),s=fn(t),i=ye(s);try{let o=await globalThis.crypto.subtle.importKey("pkcs8",i,{name:"X25519"},!0,["deriveBits"]),c=await globalThis.crypto.subtle.exportKey("jwk",o);if(typeof c.x!=="string")throw Error("X25519 JWK missing x");let u=Qr(c.x);if(c.d=void 0,!Me(u,n))throw Error("X25519 WebCrypto pub != RFC 7748");return{priv:t,pub:n}}catch(o){throw t.fill(0),o}finally{s.fill(0),new Uint8Array(i).fill(0)}}async x25519Shared(e,t){let r=fn(e),n=ye(r);try{let s=await globalThis.crypto.subtle.importKey("pkcs8",n,{name:"X25519"},!1,["deriveBits"]),i=await globalThis.crypto.subtle.importKey("raw",ye(t),{name:"X25519"},!1,[]),o=await globalThis.crypto.subtle.deriveBits({name:"X25519",public:i},s,256);return new Uint8Array(o)}finally{r.fill(0),new Uint8Array(n).fill(0)}}}var Ei=new Ae,Ve=Ei;function Ui(e){if(e<0)console.info("N",e),console.trace();if(typeof e!=="bigint")e=BigInt(e);if(e<0n)return a(10);let t=[];while(e>0n){let r=Number(e&0x7fn);if(e>>=7n,e>0n)t.push(r|128);else t.push(r)}if(t.length===0)return h(new Uint8Array([0]));if(t.length>8)return a(26);return h(new Uint8Array(t))}function Bi(e,t=0){let r=0n,n=0,s=t;while(!0){if(s>=e.length)return a(14);let i=e[s++];if(i===void 0)return a(14);if(r|=BigInt(i&127)<<BigInt(n),(i&128)===0){if(s-t>8)return a(26);return h({value:r>0x1fffffffffffffn?r:Number(r),bytesRead:s-t})}if(n+=7,n>=56)return a(26)}}class X{data;pos=0;constructor(e){this.data=e}static async fromResponse(e){let t=await e.arrayBuffer(),r=new Uint8Array(t);return new X(r)}readBigInt(){if(this.pos+8>this.data.length)return a(7);let e=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,h(e)}readDate(){let[e,t]=this.readVarInt();if(t!==0)return a(t);return h(new Date(e))}readVarInt(){let[e,t]=Bi(this.data,this.pos);if(t!==0)return a(t);this.pos+=e.bytesRead;let r=e.value;return h(typeof r==="bigint"?Number(r):r)}readVarString(){let[e,t]=this.readVarInt();if(t!==0)return a(t);let[r,n]=this.readBytes(e);if(n!==0)return a(n);let s=new TextDecoder().decode(r);return h(s)}readBytes(e){if(e<0)return a(10);if(this.pos+e>this.data.length)return a(23);let t=this.data.slice(this.pos,this.pos+e);return this.pos+=e,h(t)}readVarBytes(){let[e,t]=this.readVarInt();if(t!==0)return a(t);return this.readBytes(e)}readStruct(e){return e.decode(this)}readStructs(e){let t=[];while(!this.done()){let[r,n]=this.readStruct(e);if(n!==0)return a(n);t.push(r)}return h(t)}readBytesSeq(e){let t=[];while(!this.done()){let[r,n]=this.readBytes(e);if(n!==0)return a(n);t.push(r)}return h(t)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class T{parts=[];writeBigInt(e){let t=new Uint8Array(8);new DataView(t.buffer).setBigUint64(0,e,!1),this.parts.push(t)}writeDate(e){let t=e.getTime();return this.writeVarInt(t)}writeVarInt(e){let[t,r]=Ui(e);if(r!==0)return r;return this.parts.push(t),0}writeVarString(e){let t=new TextEncoder().encode(e),r=this.writeVarInt(t.length);if(r!==0)return r;return this.writeBytes(t),0}prependBytes(e){this.parts.unshift(e.slice())}writeBytes(e){this.parts.push(e.slice())}writeVarBytes(e){let t=this.writeVarInt(e.length);if(t!==0)return t;return this.writeBytes(e),0}writeStruct(e,t){return e.encode(this,t)}writeStructs(e,t){for(let r of t){let n=this.writeStruct(e,r);if(n!==0)return n}return 0}writeBytesSeq(e){for(let t of e)this.writeBytes(t)}result(){let e=this.parts.reduce((n,s)=>n+s.length,0),t=new Uint8Array(e),r=0;for(let n of this.parts)t.set(n,r),r+=n.length;return t}wipe(){for(let e of this.parts)e.fill(0);this.parts.length=0}*scan(){for(let e of this.parts)yield e}}var dt={encode(e,t){let r=e.writeVarBytes(t.id);if(r!==0)return r;let n=e.writeDate(t.ts);if(n!==0)return n;return 0},decode(e){let[t,r]=e.readVarBytes();if(r!==0)return a(r);let[n,s]=e.readDate();if(s!==0)return a(s);return h({id:t,ts:n})}};function ln(e){let t=new T,r=t.writeStruct(dt,e);if(r!==0)return a(r);let n=t.result();return h(n)}var Jt={encode(e,t){let r=e.writeVarBytes(t.eid);if(r!==0)return r;let n=e.writeVarInt(t.off);if(n!==0)return n;let s=e.writeVarInt(t.ctr);if(s!==0)return s;let i=e.writeVarInt(t.len);if(i!==0)return i;if(t.hsh)e.writeBytes(t.hsh);return 0},decode(e){let[t,r]=e.readVarBytes();if(r!==0)return a(r);let n=new X(t),[,s]=dt.decode(n);if(s!==0)return a(s);let[i,o]=e.readVarInt();if(o!==0)return a(o);let[c,u]=e.readVarInt();if(u!==0)return a(u);let[f,d]=e.readVarInt();if(d!==0)return a(d);let l;if(f>0){let[p,y]=e.readBytes(en);if(y!==0)return a(y);l=p}return h({eid:t,off:i,ctr:c,len:f,hsh:l})}};function hn(e,t,r){return r.checkSigEd25519(e.sig,e.headCph,t)}async function pn(e,t,r,n){let s;if(e.bod&&e.len>0)s=await r.blake3(e.bod);let i=new T,o=Jt.encode(i,{...e,hsh:s});if(o!==0)return a(o);let c=i.result(),u=await t.kdmFor(c),f=n.deriveCipher(u,"encrypt"),d=await f.encrypt(c),l=e.bod?await f.encrypt(e.bod):new Uint8Array(0),p=await t.sign(d);return h({sig:p,kdm:u,headCph:d,bodyCph:l})}async function yn(e,t,r,n,s){let i=new X(e),[o,c]=Jt.decode(i);if(c!==0)return a(14);let u;try{u=t&&t.length>0?await r.decrypt(t):void 0}catch{return a(20)}let f=o.hsh&&u===void 0,d=o.hsh===void 0&&u!==void 0;if(f||d)return a(19);if(o.hsh&&u){let p=await n.blake3(u);if(!Me(p,o.hsh))return a(19)}let l=s??await n.blake3(e);return h({msgHead:o,bod:u,headHash:l})}async function Qt(e,t){let r=new T,n=r.writeDate(t);if(n!==0)return a(n);let s=r.result(),i=await e.sign(s);return h({pubKey:e.publicKey,sig:i,timestamp:t})}async function re(e,t,r){let n=r.now().getTime(),s=e.timestamp.getTime();if(Math.abs(n-s)>tn)return 4;let o=new T;o.writeDate(e.timestamp);let c=o.result();if(!await t.checkSigEd25519(e.sig,c,e.pubKey))return 3;return 0}class Ne{now(){return new Date}}function mn(e,t,r,n){let s=t.getTime()-e.getTime(),i=r.getTime()-n.getTime();return(s+i)/2}var Qe={encode(e,t){if(e.writeVarInt(t.quota),t.quota>0){if(t.usage===void 0)return 9;e.writeVarInt(t.usage)}return 0},decode(e){let[t,r]=e.readVarInt();if(r!==0)return a(r);let n;if(t>0){let[s,i]=e.readVarInt();if(i!==0)return a(i);n=s}return h({quota:t,usage:n})}};var qe={encode(e,t){e.writeBytes(new Uint8Array([t.status]));let r=e.writeDate(t.timeRcvd);if(r!==0)return r;let n=e.writeDate(t.timeSent);if(n!==0)return n;let s=e.writeVarInt(t.subscription.term);if(s!==0)return s;let i=e.writeVarInt(t.subscription.elapsed);if(i!==0)return i;let o=e.writeStruct(Qe,t.subscription.stat);if(o!==0)return o;let c=e.writeStruct(Qe,t.subscription.dyn);if(c!==0)return c;return 0},decode(e){let[t,r]=e.readBytes(1);if(r!==0)return a(r);let n=t[0],[s,i]=e.readDate();if(i!==0)return a(i);let[o,c]=e.readDate();if(c!==0)return a(c);let[u,f]=e.readVarInt();if(f!==0)return a(f);let[d,l]=e.readVarInt();if(l!==0)return a(l);let[p,y]=e.readStruct(Qe);if(y!==0)return a(y);let[g,x]=e.readStruct(Qe);if(x!==0)return a(x);return h({status:n,timeRcvd:s,timeSent:o,subscription:{term:u,elapsed:d,stat:p,dyn:g}})}};var Zt={encode(e,t){let r=e.writeVarBytes(t.headCph);if(r!==0)return r;let n=e.writeVarInt(t.seq);if(n!==0)return n;return 0},decode(e){let[t,r]=e.readVarBytes();if(r!==0)return a(r);let[n,s]=e.readVarInt();if(s!==0)return a(s);return h({headCph:t,seq:n})}};var Y={encode(e,t){e.writeBytes(t.pubKey),e.writeBytes(t.sig);let r=e.writeDate(t.timestamp);if(r!==0)return r;return 0},decode(e){let[t,r]=e.readBytes(Zr);if(r!==0)return a(r);let[n,s]=e.readBytes(Ke);if(s!==0)return a(s);let[i,o]=e.readDate();if(o!==0)return a(o);return h({pubKey:t,sig:n,timestamp:i})}};var xn={async encodeReq(e,t,r,n,s){let i=s.writeStruct(Y,r);if(i!==0)return i;for(let o of n)s.writeVarInt(o);return 0},async handleReq(e,t,r){let{clock:n,crypto:s,storage:i}=e,[o,c]=t.readStruct(Y);if(c!==0)return c;let u=await re(o,s,n);if(u!==0)return u;let{pubKey:f}=o,[d,l]=await i.hasUser(f);if(l!==0)return l;if(!d)return 5;let[p,y]=t.readVarInt();if(y!==0)return y;if(!t.done())return 8;let[g,x]=await i.listHeads(f,p);if(x!==0)return x;return r.writeStructs(Zt,g)},decodeResp(e){return e.readStructs(Zt)}};var er={encode(e,t){e.writeVarInt(t.seq);let r=e.writeVarBytes(t.bodyCph);if(r!==0)return r;return 0},decode(e){let[t,r]=e.readVarInt();if(r!==0)return a(r);let[n,s]=e.readVarBytes();if(s!==0)return a(s);return h({seq:t,bodyCph:n})}};var gn={async encodeReq(e,t,r,n,s){let i=s.writeStruct(Y,r);if(i!==0)return i;for(let o of n){let c=s.writeVarInt(o);if(c!==0)return c}return 0},async handleReq(e,t,r){let{clock:n,crypto:s,storage:i}=e,[o,c]=t.readStruct(Y);if(c!==0)return c;let u=await re(o,s,n);if(u!==0)return u;let{pubKey:f}=o,[d,l]=await i.hasUser(f);if(l!==0)return l;if(!d)return 5;let p=[];while(!t.done()){let[x,b]=t.readVarInt();if(b!==0)return b;p.push(x)}console.info(`PULL: ${p.length} bags`);let[y,g]=await i.getBodies(f,p);if(g!==0)return g;if(!y)return 17;for(let{seq:x,bodyCph:b}of y){let I={seq:x,bodyCph:b},A=r.writeStruct(er,I);if(A!==0)return A}return 0},decodeResp(e){return e.readStructs(er)}};var tr={encode(e,t){e.writeBytes(t.sig),e.writeBytes(t.kdm);let r=e.writeVarBytes(t.headCph);if(r!==0)return r;let n=e.writeVarBytes(t.bodyCph);if(n!==0)return n;return 0},decode(e){let[t,r]=e.readBytes(Ke);if(r!==0)return a(r);let[n,s]=e.readBytes(Oe);if(s!==0)return a(s);let[i,o]=e.readVarBytes();if(o!==0)return a(o);let[c,u]=e.readVarBytes();if(u!==0)return a(u);return h({sig:t,kdm:n,headCph:i,bodyCph:c})}};var rr={encode(e,t){let r=e.writeVarInt(t.seq);if(r!==0)return r;let n=e.writeVarBytes(t.headCph);if(n!==0)return n;let s=t.bodyCph?t.bodyCph.length:0,i=e.writeVarInt(s);if(i!==0)return i;if(s>0){if(!t.bodyCph)return 10;e.writeBytes(t.bodyCph)}return 0},decode(e){let[t,r]=e.readVarInt();if(r!==0)return a(r);let[n,s]=e.readVarBytes();if(s!==0)return a(s);let[i,o]=e.readVarInt();if(o!==0)return a(o);let c;if(i>0){let[u,f]=e.readBytes(i);if(f!==0)return a(f);c=u}return h({seq:t,headCph:n,bodyCph:c})}};var Fe={encode(e,t){e.writeBytes(t.sig),e.writeBytes(t.kdm);let r=e.writeVarBytes(t.headCph);if(r!==0)return r;return 0},decode(e){let[t,r]=e.readBytes(Ke);if(r!==0)return a(r);let[n,s]=e.readBytes(Oe);if(s!==0)return a(s);let[i,o]=e.readVarBytes();if(o!==0)return a(o);return h({sig:t,kdm:n,headCph:i})}};var lt={encode(e,t){if(e.writeVarInt(t.idx),e.writeBytes(new Uint8Array([t.status])),t.status===0)e.writeVarInt(t.seq);return 0},decode(e){let[t,r]=e.readVarInt();if(r!==0)return a(r);let[n,s]=e.readBytes(1);if(s!==0)return a(s);let i=n[0];if(i!==0)return h({idx:t,status:i});let[o,c]=e.readVarInt();if(c!==0)return a(c);return h({idx:t,status:i,seq:o})}};var bn={async encodeReq(e,t,r,n,s){let i=s.writeStruct(Y,r);if(i!==0)return i;let o=s.writeStructs(tr,n);if(o!==0)return o;return 0},async handleReq(e,t,r){let{clock:n,crypto:s,storage:i,notifier:o}=e,[c,u]=t.readStruct(Y);if(u!==0)return u;let f=await re(c,s,n);if(f!==0)return f;let{pubKey:d}=c,[l,p]=await i.hasUser(d);if(p!==0)return p;if(!l)return 5;let[y,g]=t.readStructs(tr);if(g!==0)return g;console.info(`PUSH: ${y.length} bags`);let x=[],b=[];for(let S=0;S<y.length;S++){let C=y[S];if(!await hn(C,d,s)){let F={idx:S,status:3},v=r.writeStruct(lt,F);if(v!==0)return v;continue}x.push(S),b.push(C)}let[I,A]=await i.setBags(d,b);if(A!==0)return A;if(!I||I.length!==b.length)return 17;let U=[];for(let S=0;S<b.length;S++){let C=b[S],k=x[S],F=I[S],v=new T,D=v.writeStruct(Fe,C);if(D!==0)return D;let R=v.result(),L={seq:F,headCph:R};if(y.length===1&&C.bodyCph.length<=rn)L.bodyCph=C.bodyCph;U.push(L);let H={idx:k,status:0,seq:F},m=r.writeStruct(lt,H);if(m!==0)return m}if(U.length>0){let S=new T,C=S.writeStructs(rr,U);if(C!==0)return C;let k=S.result();await Promise.resolve(o.push(d,k))}return 0},decodeResp(e){return e.readStructs(lt)}};var wn={async encodeReq(e,t,r,n,s){return s.writeStruct(Y,r)},async handleReq(e,t,r){let{clock:n,crypto:s,storage:i}=e,[o,c]=t.readStruct(Y);if(c!==0)return c;let u=await re(o,s,n);if(u!==0)return u;let{pubKey:f}=o;if(!t.done())return 8;let[d,l]=await i.addUser(f);if(l!==0)return l;return 0},decodeResp(e){return h(void 0)}};class nr{url;websocket;constructor(e){this.url=e}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect(e,t,r=()=>{},n=()=>{}){let{url:s}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let i=new T;i.writeStruct(Y,e);let o=i.result(),c=ee(o);return s.searchParams.set("t",c),this.websocket=new WebSocket(s),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),n()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,r()},this.websocket.onmessage=(u)=>{let f=new Uint8Array(u.data);t(f)},this.websocket.onerror=(u)=>{console.log(`ERROR: ${JSON.stringify(u)}`),this.websocket=void 0,r()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var z={user:{path:"/user",endpoint:wn,name:0},push:{path:"/push",endpoint:bn,name:2},peek:{path:"/peek",endpoint:xn,name:1},pull:{path:"/pull",endpoint:gn,name:3}},Ci={0:z.user,2:z.push,1:z.peek,3:z.pull},Sn={[z.user.path]:z.user,[z.push.path]:z.push,[z.peek.path]:z.peek,[z.pull.path]:z.pull};class In{url;listener;constructor(e){this.url=e;this.listener=new nr(e)}async call(e,t){let{path:r}=Ci[e],n=new URL(r,this.url);try{return await Ti(n,t)}catch{return a(25)}}}var sr=(e)=>new In(e.handle);function We(e){let t=new T;if(t.writeStruct(qe,e)!==0)return new Response(null,{status:500});return ir(t)}function ir(e){let t=e.result().slice();return new Response(t,{status:200,headers:{"content-type":"application/octet-stream"}})}var Pi={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function or(e){return new Response(e.body,{headers:{...e.headers,...Pi},status:e.status,statusText:e.statusText})}async function Ti(e,t){let r=await fetch(e,{method:"POST",body:t.result().slice()});if(!r.ok)return a(24);let n=await X.fromResponse(r);return h(n)}class ht{enclave;crypto;host;clock;transport;updateHostMeta;constructor(e,t,r,n,s,i){this.enclave=e;this.crypto=t;this.host=r;this.clock=n;this.transport=s;this.updateHostMeta=i}async call(e,t){let{clock:r,transport:n}=this,{endpoint:s,name:i}=e,o=await this.identity(),c=r.now(),[u,f]=await Qt(o,c);if(f!==0)return a(f);let d=new T,l=await s.encodeReq(this,o,u,t,d);if(l!==0)return a(l);let p=r.now(),[y,g]=await n.call(i,d),x=r.now();if(g!==0)return a(g);let[b,I]=y.readStruct(qe);if(I!==0)return a(I);if(b.status!==0)return a(b.status);let U={clockOffset:mn(p,b.timeRcvd,b.timeSent,x),subscription:b.subscription},S=await this.updateHostMeta(U);if(S!==0)return a(S);return s.decodeResp(y)}identity=()=>{let{host:e,enclave:t}=this;return t.deriveIdentity(e.label,e.idx??0)};seal=async(e)=>{let{crypto:t,enclave:r}=this,n=await this.identity();return pn(e,n,t,r)};register=()=>this.call(z.user,[]);peek=(e)=>this.call(z.peek,[e]);push=(e)=>this.call(z.push,e);pull=(e)=>this.call(z.pull,e);listen=async(e,t,r)=>{let{clock:n,transport:s}=this,{listener:i}=s,o=await this.identity(),c=n.now(),[u,f]=await Qt(o,c);if(f!==0)return f;return await i.connect(u,e,t,r)};isConnected(){let e=this.transport?.listener;if(e&&typeof e.connected==="function")return e.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var pt={encode(e,t){let r=e.writeVarString(t.handle);if(r!==0)return r;let n=e.writeVarString(t.label);if(n!==0)return n;return e.writeVarInt(t.idx??0)},decode(e){let[t,r]=e.readVarString();if(r!==0)return a(r);let[n,s]=e.readVarString();if(s!==0)return a(s);let[i,o]=e.readVarInt();if(o!==0)return a(o);return h({handle:t,label:n,idx:i})}};var ar={encode(e,t){let r=e.writeVarInt(t.hosts.length);if(r!==0)return r;for(let n of t.hosts){let s=e.writeStruct(pt,n);if(s!==0)return s}return 0},decode(e){let[t,r]=e.readVarInt();if(r!==0)return a(r);if(t===void 0||t<0)return a(10);let n=[];for(let s=0;s<t;s++){let[i,o]=e.readStruct(pt);if(o!==0)return a(o);if(i===void 0)return a(14);n.push(i)}return h({hosts:n})}};var Kf=Symbol("MasterSeed"),Of=Symbol("SealedMasterKey"),oe=32,An=24+oe+16;function Ze(e){if(e.byteLength!==oe)return a(10);return h(e)}function yt(e){if(e.byteLength!==An)return a(10);return h(e)}var vi=new TextEncoder().encode("diplomatic.qrpair.v1"),et=32,ki=et+24+16,_i=32,zf=Symbol("DHKEReq"),$f=Symbol("DHKEResp");function En(e){if(e.byteLength!==et)return a(10);return h(e)}function Un(e){if(e.byteLength<ki)return a(10);return h(e)}var mt=new Ae;async function cr(e,t,r,n){let s;try{s=await mt.x25519Shared(e,t)}catch{return a(29)}try{if(s.byteLength!==et||s.every((c)=>c===0))return a(10);let i=pe(s,vi),o=pe(i,pe(r,n));try{let c=await mt.blake3(o);return h(c.slice(0,_i))}finally{i.fill(0),o.fill(0)}}finally{s.fill(0)}}class xt{#e;#t;constructor(e,t){this.#e=e,this.#t=t}static async create(){let e;try{let t=await mt.genX25519();e=t.priv;let[r,n]=En(t.pub);if(n!==0)return a(n);if(r===void 0)return a(10);let s=new xt(e,r);return e=void 0,h(s)}catch{return a(29)}finally{e?.fill(0)}}wipe(){this.#e.fill(0)}get dhkeReq(){let[e,t]=En(this.#t.slice());if(e===void 0)throw Error(`dhkeReq ${t}`);return e}async finish(e){let t=e.subarray(0,et),r=e.subarray(et),[n,s]=await cr(this.#e,t,this.#t,t);if(s!==0)return a(s);if(n===void 0)return a(12);let i;try{try{i=await mt.decryptXSalsa20Poly1305Combined(r,n)}catch{return a(20)}let[o,c]=ne.fromPairPlain(i);if(c!==0)return a(c);if(o===void 0)return a(12);return this.wipe(),h(o)}finally{n.fill(0),i?.fill(0)}}}function me(e){let t=new Uint8Array(e);if(e>0)crypto.getRandomValues(t);return t}var Ee=32,gt="DIPLOMATIC",ae="public-key",Di=-7,Li=-8,Ri=-257,bt=[{type:ae,alg:Di},{type:ae,alg:Li},{type:ae,alg:Ri}];function Hi(e){return e.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function be(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}function wt(e){if(e instanceof ArrayBuffer)return new Uint8Array(e).slice();return new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice()}function Ue(e){if(e?.rpId!==void 0)return h(e.rpId);if(typeof location>"u")return a(9);return h(Hi(location.hostname))}var Bn="";function we(e){if(e instanceof Error){Bn=e.message===""?e.name:`${e.name}: ${e.message}`;return}Bn=String(e)}function St(e){if(!(e instanceof Error))return!1;return e.name==="NotAllowedError"&&e.message.toLowerCase().includes("does not have focus")}function Cn(){if(typeof document>"u")return!0;return document.visibilityState!=="hidden"}function Xe(){if(typeof globalThis.focus!=="function")return;try{globalThis.focus()}catch{}}function It(e=2500){if(Cn())return Xe(),Promise.resolve();return new Promise((t)=>{let r=()=>{clearTimeout(s),document.removeEventListener("visibilitychange",n),Xe(),t()},n=()=>{if(Cn())r()},s=setTimeout(r,e);document.addEventListener("visibilitychange",n),n()})}async function At(e){await It();try{return await navigator.credentials.create(e)}catch(t){if(!St(t))throw t;return Xe(),await navigator.credentials.create(e)}}async function Et(e){await It();try{return await navigator.credentials.get(e)}catch(t){if(!St(t))throw t;return Xe(),await navigator.credentials.get(e)}}function Be(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function Ce(e){if(e===null||e.type!==ae||!("rawId"in e)||typeof e.getClientExtensionResults!=="function")return a(27);return h(e)}function fr(e){if(e==="platform"||e==="cross-platform")return e;return}function dr(e){let t=e.response;if(!("getTransports"in t))return;let r=t.getTransports;if(typeof r!=="function")return;let n=r.call(t);if(!Array.isArray(n))return;let s=[];for(let i of n)if(typeof i==="string"&&i.length>0)s.push(i);return s.length===0?void 0:s}var Mi=32,Ki=64,ur=37,Pn=16;function Tn(e){let t=e.response;if(!("getAuthenticatorData"in t))return;let r=t.getAuthenticatorData;if(typeof r!=="function")return;let n=r.call(t);if(!(n instanceof ArrayBuffer))return;let s=new Uint8Array(n);if(s.byteLength<ur+Pn)return;let i=s[Mi];if(i===void 0||(i&Ki)===0)return;return s.slice(ur,ur+Pn)}async function vn(e){let t=Be();if(t!==0)return a(t);let[r,n]=Ue(e);if(n!==0)return a(n);if(r===void 0)return a(9);let s=e?.userName??"diplomatic-seed",i={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if(e?.authenticatorAttachment!==void 0)i.authenticatorAttachment=e.authenticatorAttachment;let o={largeBlob:{support:"required"}},c;try{c=await At({publicKey:{challenge:me(Ee),rp:{id:r,name:e?.rpName??gt},user:{id:me(16),name:s,displayName:s},pubKeyCredParams:bt,authenticatorSelection:i,extensions:o,...e?.hints!==void 0?{hints:e.hints}:{}}})}catch(l){return we(l),a(30)}let[u,f]=Ce(c);if(f!==0)return a(f);if(u===void 0)return a(27);if(u.getClientExtensionResults().largeBlob?.supported!==!0)return a(30);return h(new Uint8Array(u.rawId))}async function lr(e,t,r,n){let s={challenge:me(Ee),rpId:e,userVerification:"preferred"};if(t?.hints!==void 0)s.hints=t.hints;if(r!==void 0)s.allowCredentials=[{type:ae,id:be(r)}];if(n!==void 0)s.extensions=n;let i;try{i=await Et({publicKey:s})}catch(u){return we(u),a(30)}let[o,c]=Ce(i);if(c!==0)return a(c);if(o===void 0)return a(27);return h(o)}async function kn(e,t){let r=Be();if(r!==0)return a(r);let[n,s]=Ue(t);if(s!==0)return a(s);if(n===void 0)return a(9);let i=e;if(i===void 0){let[l,p]=await lr(n,t);if(p!==0&&t?.hints!==void 0)[l,p]=await lr(n,{rpId:t.rpId,rpName:t.rpName});if(p!==0)return a(p);if(l===void 0)return a(27);i=new Uint8Array(l.rawId)}let[o,c]=await lr(n,t,i,{largeBlob:{read:!0}});if(c!==0)return a(c);if(o===void 0)return a(27);let f=o.getClientExtensionResults().largeBlob;if(f===void 0||f.blob===void 0)return a(7);let d=wt(f.blob);if(d.byteLength===0)return a(7);return h({blob:d,credId:new Uint8Array(o.rawId)})}var hr=new TextEncoder().encode("diplomatic.prf.v1"),pr="diplomatic-prf";var Ut="";var Ct=typeof globalThis.Worker==="function"?globalThis.Worker:void 0,yr=Ct===void 0?void 0:Ct.prototype.postMessage,Bt;function Vi(){if(typeof Ut!=="string"||Ut.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(Ut)}function Ni(){if(Bt!==void 0)return Bt;let e=new Blob([Vi()],{type:"text/javascript"});return Bt=URL.createObjectURL(e),Bt}function _n(){if(Ct===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new Ct(Ni(),{type:"module"})}function Dn(e,t,r){if(yr===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot post to sync worker");if(r!==void 0&&r.length>0)yr.call(e,t,{transfer:r});else yr.call(e,t)}var qi=new TextEncoder().encode("diplomatic.bind.v1"),mr=new TextEncoder().encode("diplomatic.bindtag.v1"),Fi=32,Wi=32,Xi=16,te=new Ae;function zi(e){return e.map((t)=>({handle:t.handle,label:t.label,idx:t.idx??0}))}function Ln(e){if(e.byteLength===0||e.every((c)=>c===0))return a(22);if(e.byteLength<oe+1)return a(14);let t=e.subarray(0,oe);if(t.every((c)=>c===0))return a(22);let r=new X(e.subarray(oe)),[n,s]=r.readStruct(ar);if(s!==0)return a(s);if(n===void 0)return a(14);if(!r.done())return a(14);let[i,o]=ne.fromBytes(t);if(o!==0)return a(o);if(i===void 0)return a(12);return h({enclave:i,hosts:n.hosts.map((c)=>({...c}))})}async function Rn(e,t,r){let n=Be();if(n!==0)return n;let[s,i]=Ue(r);if(i!==0)return i;if(s===void 0)return 9;await It();let o=new Uint8Array(t.byteLength);o.set(t);let c={largeBlob:{write:o.buffer}},u={publicKey:{challenge:me(Ee),rpId:s,allowCredentials:[{type:ae,id:be(e)}],userVerification:"required",extensions:c,...r?.hints!==void 0?{hints:r.hints}:{}}},f;try{try{f=await navigator.credentials.get(u)}catch(y){if(!St(y))throw y;Xe(),f=await navigator.credentials.get(u)}}catch(y){return we(y),30}finally{o.fill(0)}let[d,l]=Ce(f);if(l!==0)return l;if(d===void 0)return 27;if(d.getClientExtensionResults().largeBlob?.written!==!0)return 30;return 0}var xr=32;function $i(e){if(e===void 0)return[];if(e instanceof Uint8Array)return[e];return e.filter((t)=>t.byteLength>0)}function Gi(e){if(!(e instanceof Error))return!1;return e.name==="NotSupportedError"||e.name==="TypeError"}function Kn(e){if(e===void 0)return;let t=wt(e);if(t.byteLength<xr){t.fill(0);return}if(t.byteLength===xr)return t;let r=t.slice(0,xr);return t.fill(0),r}async function ji(e){let t=Be();if(t!==0)return a(t);let[r,n]=Ue(e);if(n!==0)return a(n);if(r===void 0)return a(9);let s=e?.userName??pr,i=e?.displayName??s,o=me(16),c=e?.authenticatorAttachment==="cross-platform",u={residentKey:c?"discouraged":"required",requireResidentKey:!c,userVerification:c?"preferred":"required"};if(e?.authenticatorAttachment!==void 0)u.authenticatorAttachment=e.authenticatorAttachment;let f={challenge:me(Ee),rp:{id:r,name:e?.rpName??gt},user:{id:o,name:s,displayName:i},pubKeyCredParams:bt,authenticatorSelection:u,...e?.hints!==void 0?{hints:e.hints}:{},...e?.excludeCredentials!==void 0&&e.excludeCredentials.length>0?{excludeCredentials:e.excludeCredentials.map((A)=>({type:ae,id:be(A)}))}:{}},d=e?.salt!==void 0?be(e.salt):void 0,l=(A)=>At({publicKey:{...f,extensions:A&&d!==void 0?{prf:{eval:{first:d}}}:{prf:{}}}}),p;try{p=await l(d!==void 0)}catch(A){if(d===void 0||!Gi(A))return we(A),a(30);try{p=await l(!1)}catch(U){return we(U),a(30)}}let[y,g]=Ce(p);if(g!==0)return a(g);if(y===void 0)return a(27);let x=y.getClientExtensionResults(),b=Kn(x.prf?.results?.first),I=x.prf?.enabled===!0||b!==void 0;if(c&&b!==void 0)b.fill(0);return h({credId:new Uint8Array(y.rawId),userId:new Uint8Array(o),prfEnabled:I,prf:c?void 0:b,attachment:fr(y.authenticatorAttachment),transports:dr(y),aaguid:Tn(y)})}async function Hn(e){let t=Be();if(t!==0)return a(t);let[r,n]=Ue(e);if(n!==0)return a(n);if(r===void 0)return a(9);let s=e?.salt??hr,i=be(s),o={challenge:me(Ee),rpId:r,userVerification:"preferred",extensions:{prf:{eval:{first:i}}}};if(e?.hints!==void 0)o.hints=e.hints;let c=$i(e?.credId);if(c.length>0)o.allowCredentials=c.map((y)=>({type:ae,id:be(y)}));let u;try{u=await Et({publicKey:o})}catch(y){return we(y),a(30)}let[f,d]=Ce(u);if(d!==0)return a(d);if(f===void 0)return a(27);let l=f.getClientExtensionResults().prf?.results;if(l?.first===void 0)return a(7);let p=Kn(l.first);if(p===void 0)return a(27);return h({prf:p,credId:new Uint8Array(f.rawId),attachment:fr(f.authenticatorAttachment),transports:dr(f)})}class ne{#e;constructor(e){this.#e=e}static async fromRandom(){let e=await te.gen256BitSecureRandomSeed(),[t,r]=Ze(e);if(r!==0||t===void 0)throw Error(`enclave: invalid random seed (${r})`);return new ne(t)}static fromBytes(e){let[t,r]=Ze(e);if(r!==0)return a(r);if(t===void 0)return a(10);let[n,s]=Ze(t.slice());if(s!==0)return a(s);if(n===void 0)return a(10);return h(new ne(n))}async sealWithPasskey(e){let t=e?.salt??hr,r=e?.credId,n=r,s=e?.createCredIfNeeded===!0&&(r===void 0||!(r instanceof Uint8Array)&&r.length===0),i,o;if(s){let[d,l]=await ji({rpId:e?.rpId,rpName:e?.rpName,userName:e?.userName??pr,displayName:e?.displayName,authenticatorAttachment:e?.authenticatorAttachment,hints:e?.hints,excludeCredentials:e?.excludeCredentials,salt:t});if(l!==0)return a(l);if(d===void 0)return a(30);if(!d.prfEnabled)return a(30);n=d.credId,i=d,o=d.prf}let c=async(d,l,p,y)=>{try{let[g,x]=await this.#o(d);if(x!==0)return a(x);if(g===void 0)return a(12);return h({sealedMaster:g,salt:t.slice(),credId:l.slice(),userId:i?.userId===void 0?void 0:i.userId.slice(),attachment:p??i?.attachment,transports:y??i?.transports,aaguid:i?.aaguid===void 0?void 0:i.aaguid.slice()})}finally{d.fill(0)}};if(o!==void 0&&i!==void 0)return c(o,i.credId,i.attachment,i.transports);let[u,f]=await Hn({rpId:e?.rpId,rpName:e?.rpName,credId:n,salt:t,hints:e?.hints});if(f!==0)return a(f);if(u===void 0)return a(7);return c(u.prf,u.credId,u.attachment,u.transports)}async bind(e,t){if(t!==void 0){for(let i of t)if(!await this.#i(i.credId,i.tag))return a(10)}let[r,n]=await this.sealWithPasskey(e);if(n!==0)return a(n);if(r===void 0)return a(12);let s=await this.#t(r.credId);return h({...r,tag:s})}static async unsealWithPasskey(e,t){if(e.length===0)return a(22);let r=[];for(let c of e)if(c.credId.byteLength>0)r.push(c.credId);let[n,s]=await Hn({rpId:t.rpId,rpName:t.rpName,hints:t.hints,credId:r.length>0?r:void 0,salt:t.salt});if(s!==0)return a(s);if(n===void 0)return a(7);let i=e.find((c)=>Me(c.credId,n.credId)),o=i===void 0?e:[i,...e.filter((c)=>c!==i)];try{for(let c of o){let[u]=await ne.#a(c.sealedMaster,n.prf);if(u!==void 0)return h({enclave:u,credId:n.credId.slice()})}return a(20)}finally{n.prf.fill(0)}}async persistToLargeBlob(e=[],t){let r=t?.credId;if(r===void 0){let[i,o]=await vn(t);if(o!==0)return a(o);if(i===void 0)return a(30);r=i}let[n,s]=this.#s(e);if(s!==0)return a(s);if(n===void 0)return a(12);try{let i=await Rn(r,n,t);if(i!==0)return a(i);return h(r)}finally{n.fill(0)}}static async fromLargeBlob(e){let[t,r]=await kn(e?.credId,e);if(r!==0)return a(r);if(t===void 0)return a(7);try{let[n,s]=Ln(t.blob);if(s!==0)return a(s);if(n===void 0)return a(12);return h({...n,credId:t.credId})}finally{t.blob.fill(0)}}static async clearLargeBlob(e,t){return Rn(e,new Uint8Array(oe),t)}static fromPairPlain(e){return Ln(e)}static pairRequest(){return xt.create()}async pairAccept(e,t){let r;try{r=await te.genX25519()}catch{return a(29)}try{let[n,s]=await cr(r.priv,e,e,r.pub);if(s!==0)return a(s);if(n===void 0)return a(12);try{let[i,o]=this.#s(t);if(o!==0)return a(o);if(i===void 0)return a(12);try{let c=await te.encryptXSalsa20Poly1305Combined(i,n);return Un(pe(r.pub,c))}catch{return a(12)}finally{i.fill(0)}}finally{n.fill(0)}}finally{r.priv.fill(0)}}spawnSyncWorker(e){let t=_n(),r=this.#e.slice();return Dn(t,{id:e.id,op:"setSeed",seed:r,persist:e.persist},[r.buffer]),t}deriveCipher(e,t){let r=e.slice(),n=(o)=>this.#c(r,o),s=(o)=>this.#u(r,o);return{encrypt:Object.freeze({encrypt:n}),decrypt:Object.freeze({decrypt:s}),both:Object.freeze({encrypt:n,decrypt:s})}[t]}async deriveIdentity(e,t=0){let r=e,n=t,s=await this.#n(r,n),i=s.publicKey;return s.privateKey.fill(0),Object.freeze({publicKey:i,sign:(o)=>this.#d(r,n,o),kdmFor:(o)=>this.#l(r,n,o)})}async#t(e){let t=new Uint8Array(this.#e.byteLength+mr.byteLength+e.byteLength);t.set(this.#e,0),t.set(mr,this.#e.byteLength),t.set(e,this.#e.byteLength+mr.byteLength);try{return await te.blake3(t)}finally{t.fill(0)}}async#i(e,t){if(t.byteLength!==Fi)return!1;let r=await this.#t(e);try{if(r.byteLength!==t.byteLength)return!1;let n=0;for(let s=0;s<r.byteLength;s++){let i=r[s],o=t[s];if(i===void 0||o===void 0)return!1;n|=i^o}return n===0}finally{r.fill(0)}}async#o(e){let[t,r]=await Mn(te,e);if(r!==0)return a(r);if(t===void 0)return a(12);try{let n=await te.encryptXSalsa20Poly1305Combined(this.#e,t);return yt(n)}catch{return a(12)}finally{t.fill(0)}}static async#a(e,t){let[,r]=yt(e);if(r!==0)return a(r);let[n,s]=await Mn(te,t);if(s!==0)return a(s);if(n===void 0)return a(12);let i;try{try{i=await te.decryptXSalsa20Poly1305Combined(e,n)}catch{return a(20)}return ne.fromBytes(i)}finally{n.fill(0),i?.fill(0)}}#s(e){let t=new T,r=t.writeStruct(ar,{hosts:zi(e)});if(r!==0)return a(r);let n=t.result(),s=new Uint8Array(oe+n.byteLength);return s.set(this.#e,0),s.set(n,oe),h(s)}async#c(e,t){let r=await this.#r(e);try{return await te.encryptXSalsa20Poly1305Combined(t,r)}finally{r.fill(0)}}async#u(e,t){let r=await this.#r(e);try{return await te.decryptXSalsa20Poly1305Combined(t,r)}finally{r.fill(0)}}async#r(e){let t=new Uint8Array(this.#e.byteLength+e.byteLength);t.set(this.#e,0),t.set(e,this.#e.byteLength);try{return await te.blake3(t)}finally{t.fill(0)}}async#f(e,t){let r=new TextEncoder().encode(e),n=new Uint8Array(8);return new DataView(n.buffer).setBigUint64(0,BigInt(t),!1),await this.#r(pe(r,n))}async#n(e,t){let r=await this.#f(e,t);try{return await te.deriveEd25519KeyPair(r)}finally{r.fill(0)}}async#d(e,t,r){let n=await this.#n(e,t);try{return await te.signEd25519(r,n.privateKey)}finally{n.privateKey.fill(0)}}async#l(e,t,r){let n=await this.#n(e,t),s=pe(n.privateKey,r);n.privateKey.fill(0);try{return(await te.blake3(s)).slice(0,Oe)}finally{s.fill(0)}}}async function Mn(e,t,r=qi){if(t.byteLength<Xi)return a(10);let n=await e.blake3(pe(t,r));return h(n.slice(0,Wi))}var Yi=new Set(["constructor","prototype","length","name"]);function On(e){for(let t of Object.getOwnPropertyNames(e)){if(Yi.has(t))continue;let r=Object.getOwnPropertyDescriptor(e,t);if(r===void 0||typeof r.value!=="function")continue;Object.defineProperty(e,t,{value:r.value,writable:!1,configurable:!1})}}On(ne);On(ne.prototype);async function Vn(e,t,r,n=0){let s=t.now(),i=new T,o=i.writeVarString(e);if(o!==0)return a(o);let u={id:i.result(),ts:new Date(0)},[f,d]=ln(u);if(d!==0)return a(d);let l=s.getTime()-u.ts.getTime();return h({eid:f,off:l,ctr:n,len:r.length,bod:r})}async function Nn(e,t,r,n){let s=new X(e.headCph),[i,o]=s.readStruct(Fe);if(o!==0)return a(o);let{sig:c,kdm:u,headCph:f}=i;if(!await n.checkSigEd25519(c,f,t))return a(3);let l=r.deriveCipher(u,"decrypt"),p;try{p=await l.decrypt(f)}catch{return a(20)}return h({kdm:u,headEnc:p})}var $e=ti(qs(),1),ma={encode:$e.encode,decode:$e.decode,decodeAsync:$e.decodeAsync},xa=ma;import{Database as ga}from"bun:sqlite";var gl=Symbol("EntityID");var bl=Symbol("DerivationSeed"),wl=Symbol("PublicKey"),Sl=Symbol("PrivateKey"),Il=Symbol("HostSpecificKeyPair"),Al=Symbol("Hash"),ge={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function ba(e="diplomatic.db"){let t=new ga(e);return t.exec("PRAGMA journal_mode=WAL;"),t.exec("PRAGMA synchronous=NORMAL;"),t.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  pubKey TEXT PRIMARY KEY
4
4
  );
5
- `),Z.exec(`
5
+ `),t.exec(`
6
6
  CREATE TABLE IF NOT EXISTS bags (
7
7
  userPubKey TEXT,
8
8
  seq INTEGER,
@@ -11,4 +11,4 @@ var pQ=Object.create;var{getPrototypeOf:uQ,defineProperty:BZ,getOwnPropertyNames
11
11
  PRIMARY KEY (userPubKey, seq),
12
12
  UNIQUE (userPubKey, seq)
13
13
  );
14
- `),{async addUser(J){try{let Q=$0(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),O(void 0)}catch{return G(17)}},async hasUser(J){try{let Q=$0(J),X=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return O(Boolean(X?.ok))}catch{return G(17)}},async subMeta(J){return O(P0)},async setBags(J,Q){if(Q.length<1)return O([]);try{let X=$0(J);Z.exec("BEGIN IMMEDIATE");try{let Y=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(X),V=Y?Y.m||0:0,W=[],q=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let z of Q){V+=1;let M=new m;M.writeStruct(u0,z),q.run(X,V,M.result(),z.bodyCph),W.push(V)}return Z.exec("COMMIT"),O(W)}catch(Y){try{Z.exec("ROLLBACK")}catch{}throw Y}}catch{return G(17)}},async getBodies(J,Q){if(Q.length<1)return O([]);try{let X=$0(J),Y=[],V=100,W=99;for(let q=0;q<Q.length;q+=99){let z=Q.slice(q,q+99),M=z.map(()=>"?").join(","),N=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${M})`).all(X,...z);for(let K of N)if(K.bodyCph)Y.push({seq:K.seq,bodyCph:new Uint8Array(K.bodyCph)})}return O(Y)}catch{return G(17)}},async listHeads(J,Q){try{let X=$0(J),Y=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(X,Q);return O(Y.map((V)=>({seq:V.seq,headCph:new Uint8Array(V.headCph)})))}catch{return G(17)}}}}var NV=MV(),yQ=NV;class _Z{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 JZ(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),JZ(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=new URL($.url);if($.method!=="POST"){let z=Z.now();return d0({status:13,timeRcvd:J,timeSent:z,subscription:P0})}if(!$.body){let z=Z.now();return d0({status:7,timeRcvd:J,timeSent:z,subscription:P0})}let Y=new Uint8Array(await $.arrayBuffer()),V=new v(Y),W=Q.pathname,q=PJ[W]?.endpoint;if(!q){let z=Z.now();return d0({status:13,timeRcvd:J,timeSent:z,subscription:P0})}try{let z=new m,M=await q.handleReq(this,V,z),N=P0,K={status:M,timeRcvd:J,timeSent:this.clock.now(),subscription:N},H=new m;if(H.writeStruct(p0,K)!==0)return new Response(null,{status:500});if(M!==0){let R=Z.now();return d0({status:M,timeRcvd:J,timeSent:R,subscription:P0})}return z.prependBytes(H.result()),ZZ(z)}catch(z){let M=Z.now();return console.error(z),console.trace(),d0({status:12,timeRcvd:J,timeSent:M,subscription:P0})}}}async function lQ($,Z){let Q=new URL($.url).searchParams.get(JJ);if(!Q)return G(11);let X=q$(Q),Y=new v(X),[V,W]=Y.readStruct(o);if(W!==0)return G(11);let q=await J0(V,Z.crypto,Z.clock);if(q!==0)return G(q);return O(V)}class hQ{recvs=new Map;async open($,Z,J,Q){let X=await J0($,J,Q);if(X!==0)return{send:()=>X,shut:()=>X,status:X};let Y=$0($.pubKey);if(!this.recvs.has(Y))this.recvs.set(Y,new Set);return this.recvs.get(Y)?.add(Z),{send:(V)=>{return Z(V),0},shut:()=>{return this.recvs.get(Y)?.delete(Z),0},status:0}}async push($,Z){let J=$0($),Q=this.recvs.get(J);if(Q)for(let X of Q)X(Z)}}var bQ=new hQ;async function OV($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new _Z(yQ,h0,bQ,new i0);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 lQ(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;bQ.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 iQ{enclave;conn;clock;constructor({enclave:$,clock:Z=new i0}){this.enclave=$,this.clock=Z}async connect($,Z){let J=new i0,Q=()=>Promise.resolve(0);this.conn=new N$(this.enclave,h0,$,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,V]=await this.conn.seal(X);if(V!==0)return G(V);Z.push(Y)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return G(Q);return O(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 fJ($,J.publicKey,this.enclave,h0);if(X!==0)return G(X);let Y=this.enclave.deriveCipher(Q.kdm,"decrypt");return OJ(Q.headEnc,Z.bodyCph,Y,h0)}async upsertSingletonSync($,Z){let[J,Q]=await gJ($,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 KV({enclave:$,host:Z,transport:J}){let Q=new iQ({enclave:$}),X=await Q.connect(Z,J);return[Q,X]}async function HM({enclave:$,host:Z,transport:J}){let Q=J??$Z(Z),[X,Y]=await KV({enclave:$,host:Z,transport:Q});if(Y!==0)console.error(`Failed to initialize CLI: ${A[Y]}`),process.exit(1);return X}function FM($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=q$(Z),[Q,X]=Q0.fromBytes(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 RM($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{OV as runBunHost,t$ as notifItemCodec,qV as msgpack,RM as loadHostOrPanic,FM as loadEnclaveOrPanic,HM as initCLIOrPanic,KV as initCLI,$Z as hostHTTPTransport,A as Status,v as Decoder,iQ as CLIClient};
14
+ `),{async addUser(r){try{let n=ee(r);return t.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[n]),h(void 0)}catch{return a(17)}},async hasUser(r){try{let n=ee(r),s=t.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(n);return h(Boolean(s?.ok))}catch{return a(17)}},async subMeta(r){return h(ge)},async setBags(r,n){if(n.length<1)return h([]);try{let s=ee(r);t.exec("BEGIN IMMEDIATE");try{let i=t.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(s),o=i?i.m||0:0,c=[],u=t.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let f of n){o+=1;let d=new T;d.writeStruct(Fe,f),u.run(s,o,d.result(),f.bodyCph),c.push(o)}return t.exec("COMMIT"),h(c)}catch(i){try{t.exec("ROLLBACK")}catch{}throw i}}catch{return a(17)}},async getBodies(r,n){if(n.length<1)return h([]);try{let s=ee(r),i=[],o=100,c=99;for(let u=0;u<n.length;u+=99){let f=n.slice(u,u+99),d=f.map(()=>"?").join(","),l=t.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${d})`).all(s,...f);for(let p of l)if(p.bodyCph)i.push({seq:p.seq,bodyCph:new Uint8Array(p.bodyCph)})}return h(i)}catch{return a(17)}},async listHeads(r,n){try{let s=ee(r),i=t.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(s,n);return h(i.map((o)=>({seq:o.seq,headCph:new Uint8Array(o.headCph)})))}catch{return a(17)}}}}var wa=ba(),Fs=wa;class kr{storage;crypto;notifier;clock;constructor(e,t,r,n){this.storage=e;this.crypto=t;this.notifier=r;this.clock=n}corsHandler=async(e)=>{if(e.method==="OPTIONS")return or(new Response(null));let t=`${e.method} ${e.url}`;console.time(t);let r=await this.handler(e);return console.timeEnd(t),or(r)};handler=async(e)=>{let{clock:t}=this,r=t.now(),n=new URL(e.url);if(e.method!=="POST"){let f=t.now();return We({status:13,timeRcvd:r,timeSent:f,subscription:ge})}if(!e.body){let f=t.now();return We({status:7,timeRcvd:r,timeSent:f,subscription:ge})}let i=new Uint8Array(await e.arrayBuffer()),o=new X(i),c=n.pathname,u=Sn[c]?.endpoint;if(!u){let f=t.now();return We({status:13,timeRcvd:r,timeSent:f,subscription:ge})}try{let f=new T,d=await u.handleReq(this,o,f),l=ge,p={status:d,timeRcvd:r,timeSent:this.clock.now(),subscription:l},y=new T;if(y.writeStruct(qe,p)!==0)return new Response(null,{status:500});if(d!==0){let x=t.now();return We({status:d,timeRcvd:r,timeSent:x,subscription:ge})}return f.prependBytes(y.result()),ir(f)}catch(f){let d=t.now();return console.error(f),console.trace(),We({status:12,timeRcvd:r,timeSent:d,subscription:ge})}}}async function Ws(e,t){let n=new URL(e.url).searchParams.get(nn);if(!n)return a(11);let s=ut(n),i=new X(s),[o,c]=i.readStruct(Y);if(c!==0)return a(11);let u=await re(o,t.crypto,t.clock);if(u!==0)return a(u);return h(o)}class zs{recvs=new Map;async open(e,t,r,n){let s=await re(e,r,n);if(s!==0)return{send:()=>s,shut:()=>s,status:s};let i=ee(e.pubKey);if(!this.recvs.has(i))this.recvs.set(i,new Set);return this.recvs.get(i)?.add(t),{send:(o)=>(t(o),0),shut:()=>(this.recvs.get(i)?.delete(t),0),status:0}}async push(e,t){let r=ee(e),n=this.recvs.get(r);if(n)for(let s of n)s(t)}}var Xs=new zs;async function Sa(e=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let t=new kr(Fs,Ve,Xs,new Ne);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${e}`),Bun.serve({port:e,fetch:async(r,n)=>{if(r.headers.get("upgrade")==="websocket"){let[s,i]=await Ws(r,t);if(i!==0)return new Response("Unauthorized",{status:401});return n.upgrade(r,{data:{authTS:s}})?void 0:new Response("Upgrade failed",{status:400})}return t.corsHandler(r)},websocket:{data:{},open:(r)=>{let n=r.data.authTS;Xs.open(n,(s)=>r.send(s),t.crypto,t.clock).then((s)=>{if(s.status!==0){r.close();return}r.channel=s})},message:(r,n)=>{},close:(r)=>{r.channel?.shut()}}})}class $s{enclave;conn;clock;constructor({enclave:e,clock:t=new Ne}){this.enclave=e,this.clock=t}async connect(e,t){let r=new Ne,n=()=>Promise.resolve(0);this.conn=new ht(this.enclave,Ve,e,r,t,n);let[,s]=await this.conn.register();return s}async push(e){if(!this.conn)return a(28);let t=[];for(let s of e){let[i,o]=await this.conn.seal(s);if(o!==0)return a(o);t.push(i)}let[r,n]=await this.conn.push(t);if(n!==0)return a(n);return h(r)}async peek(e){if(!this.conn)return a(28);return this.conn.peek(e)}async pull(e){if(!this.conn)return a(28);return this.conn.pull(e)}async open(e,t){if(!this.conn)return a(28);let r=await this.conn.identity(),[n,s]=await Nn(e,r.publicKey,this.enclave,Ve);if(s!==0)return a(s);let i=this.enclave.deriveCipher(n.kdm,"decrypt");return yn(n.headEnc,t.bodyCph,i,Ve)}async upsertSingletonSync(e,t){let[r,n]=await Vn(e,this.clock,t);if(n!==0)return n;let[,s]=await this.push([r]);return s}async listen(e,t,r){if(!this.conn)return 28;return this.conn.listen(e,t,r)}isConnected(){return this.conn?.isConnected()??!1}}async function Ia({enclave:e,host:t,transport:r}){let n=new $s({enclave:e}),s=await n.connect(t,r);return[n,s]}async function yh({enclave:e,host:t,transport:r}){let n=r??sr(t),[s,i]=await Ia({enclave:e,host:t,transport:n});if(i!==0)console.error(`Failed to initialize CLI: ${B[i]}`),process.exit(1);return s}function mh(e){let t=process.env[e];if(!t)console.error(`${e} env var missing`),process.exit(1);let r=ut(t),[n,s]=ne.fromBytes(r);if(r.fill(0),s!==0||n===void 0)console.error(`${e} must be 64 hex chars (32-byte master seed)`),process.exit(1);return n}function xh(e){let t=process.env[e];if(!t)console.error(`${e} env var missing`),process.exit(1);return{handle:new URL(t),label:"host"}}export{$s as CLIClient,X as Decoder,B as Status,sr as hostHTTPTransport,Ia as initCLI,yh as initCLIOrPanic,mh as loadEnclaveOrPanic,xh as loadHostOrPanic,xa as msgpack,rr as notifItemCodec,Sa as runBunHost};
@@ -1,25 +1,12 @@
1
1
  import { ICodecStruct } from "../codec.ts";
2
- import { type MasterSeed } from "../seed.ts";
3
- import { type ValStat } from "../valstat.ts";
4
2
  import { type BundleHost } from "./bundleHost.ts";
5
3
  export { type BundleHost, bundleHostCodec } from "./bundleHost.ts";
6
- export declare const IDENTITY_BUNDLE_VERSION = 1;
7
- export type IdentityBundle = {
8
- v: number;
9
- masterSeed: MasterSeed;
4
+ export type IdentityHosts = {
10
5
  hosts: BundleHost[];
11
6
  };
12
7
  /**
13
- * IdentityBundle wire layout:
14
- * v: varint
15
- * masterSeed: 32 fixed bytes
8
+ * Host list on the IdentityBundle wire:
16
9
  * hostsLen: varint
17
10
  * hosts: hostsLen × BundleHost
18
11
  */
19
- export declare const identityBundleCodec: ICodecStruct<IdentityBundle>;
20
- /**
21
- * Build a wire-format identity bundle from a branded {@link MasterSeed} + hosts.
22
- * Codec/tests only. Runtime seed I/O must go through Enclave.persistToLargeBlob
23
- * — never encode then hand seed-bearing bytes to outer layers.
24
- */
25
- export declare function createIdentityBundle(masterSeed: MasterSeed, hosts: BundleHost[]): ValStat<IdentityBundle>;
12
+ export declare const identityHostsCodec: ICodecStruct<IdentityHosts>;
@@ -125,6 +125,14 @@ export declare class Enclave {
125
125
  }>>;
126
126
  /** UV + overwrite largeBlob with zeros (destroys stored seed material). */
127
127
  static clearLargeBlob(credId: Uint8Array, opts?: LargeBlobRp): Promise<Status>;
128
+ /**
129
+ * Absorb seed‖hosts plaintext (pair AEAD inner).
130
+ * Encoder/Decoder never see the seed.
131
+ */
132
+ static fromPairPlain(plain: Uint8Array): ValStat<{
133
+ enclave: Enclave;
134
+ hosts: BundleHost[];
135
+ }>;
128
136
  static pairRequest(): Promise<ValStat<PairRequest>>;
129
137
  pairAccept(dhkeReq: DHKEReq, hosts: BundleHost[]): Promise<ValStat<DHKEResp>>;
130
138
  /**
@@ -47,6 +47,16 @@ export declare function resolveWebAuthnRpId(opts?: WebAuthnRp): ValStat<string>;
47
47
  export declare function webAuthnLastError(): string;
48
48
  /** Records a WebAuthn DOMException (or other throw) for {@link webAuthnLastError}. */
49
49
  export declare function noteWebAuthnError(e: unknown): void;
50
+ /** Chromium: create/get rejected because the browsing context is unfocused. */
51
+ export declare function webAuthnNotFocused(e: unknown): boolean;
52
+ /** Best-effort `window.focus()` so Chromium's IsFocused check can pass. */
53
+ export declare function tryFocus(): void;
54
+ /** Wait until the document is visible, or `ms` elapses; then try `focus()`. */
55
+ export declare function whenVisible(ms?: number): Promise<void>;
56
+ /** `credentials.create` after the document is visible; one retry on NOT_FOCUSED. */
57
+ export declare function webAuthnCreate(opts: CredentialCreationOptions): Promise<Credential | null>;
58
+ /** `credentials.get` after the document is visible; one retry on NOT_FOCUSED. */
59
+ export declare function webAuthnGet(opts: CredentialRequestOptions): Promise<Credential | null>;
50
60
  /** Success if WebAuthn credentials API is available in this environment. */
51
61
  export declare function checkWebAuthn(): Status;
52
62
  export declare function asPublicKeyCredential(cred: Credential | null): ValStat<PublicKeyCredential>;
@@ -1,4 +1,3 @@
1
- import { Status } from "../consts.ts";
2
1
  import { type ValStat } from "../valstat.ts";
3
2
  import { type WebAuthnRp } from "./common.ts";
4
3
  export type LargeBlobRp = WebAuthnRp;
@@ -10,8 +9,6 @@ export type LargeBlobCreateOpts = LargeBlobRp & {
10
9
  export declare function largeBlobCapable(): Promise<boolean>;
11
10
  /** Create discoverable largeBlob-capable credential; returns credential id. */
12
11
  export declare function largeBlobCreateCred(opts?: LargeBlobCreateOpts): Promise<ValStat<Uint8Array>>;
13
- /** UV write of opaque bytes to largeBlob. */
14
- export declare function largeBlobWrite(credId: Uint8Array, data: Uint8Array, opts?: LargeBlobRp): Promise<Status>;
15
12
  /** UV read from largeBlob; `credId` undefined = discoverable then targeted read. */
16
13
  export declare function largeBlobRead(credId: Uint8Array | undefined, opts?: LargeBlobRp): Promise<ValStat<{
17
14
  blob: Uint8Array;
@@ -1,4 +1,3 @@
1
- import { type ValStat } from "../valstat.ts";
2
1
  import { type AuthenticatorAttachmentName, type WebAuthnRp } from "./common.ts";
3
2
  export type PrfRp = WebAuthnRp;
4
3
  export type PrfCreateOpts = PrfRp & {
@@ -17,8 +16,6 @@ export type PrfCreateOpts = PrfRp & {
17
16
  export declare const DEFAULT_PRF_SALT: Uint8Array<ArrayBufferLike>;
18
17
  /** Default WebAuthn user.name / displayName when none is supplied. */
19
18
  export declare const DEFAULT_PRF_USER_NAME = "diplomatic-prf";
20
- /** Bytes of PRF output we consume (first N of `results.first`). */
21
- export declare const PRF_OUTPUT_LEN = 32;
22
19
  /** Public ceremony facts (no PRF bytes). */
23
20
  export type PrfCeremony = {
24
21
  credId: Uint8Array;
@@ -27,15 +24,6 @@ export type PrfCeremony = {
27
24
  transports?: string[];
28
25
  aaguid?: Uint8Array;
29
26
  };
30
- export type PrfCreateResult = PrfCeremony & {
31
- prfEnabled: boolean;
32
- /** Present when the UA evaluated PRF during create (no second get). */
33
- prf?: Uint8Array;
34
- };
35
- /** Internal: PRF output + cred id. For Enclave only — do not re-export to apps. */
36
- export type PrfEvalResult = PrfCeremony & {
37
- prf: Uint8Array;
38
- };
39
27
  export type PrfEvalOpts = PrfRp & {
40
28
  /** One id, or every bound id so a spare key can assert in one get(). */
41
29
  credId?: Uint8Array | readonly Uint8Array[];
@@ -43,10 +31,3 @@ export type PrfEvalOpts = PrfRp & {
43
31
  };
44
32
  /** Best-effort: client advertises PRF extension. */
45
33
  export declare function prfCapable(): Promise<boolean>;
46
- /** Create a discoverable credential that enables PRF. */
47
- export declare function createPrfCred(opts?: PrfCreateOpts): Promise<ValStat<PrfCreateResult>>;
48
- /**
49
- * Evaluate PRF (UV). Returns PRF bytes — only Enclave should call this and must
50
- * zero/drop PRF after seal/unseal. Apps must not hold PRF alongside sealed meta.
51
- */
52
- export declare function evalPrf(opts?: PrfEvalOpts): Promise<ValStat<PrfEvalResult>>;