@interncom/diplomatic 0.13.4 → 0.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.mjs +2 -2
- package/dist/web/index.mjs +1 -1
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var gQ=Object.create;var{getPrototypeOf:xQ,defineProperty:CZ,getOwnPropertyNames:SQ}=Object;var fQ=Object.prototype.hasOwnProperty;function vQ($){return this[$]}var yQ,lQ,bQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var Y=Z?yQ??=new WeakMap:lQ??=new WeakMap,X=Y.get($);if(X)return X}J=$!=null?gQ(xQ($)):{};let G=Z||!$||!$.__esModule?CZ(J,"default",{value:$,enumerable:!0}):J;for(let W of SQ($))if(!fQ.call(G,W))CZ(G,W,{get:vQ.bind($,W),enumerable:!0});if(Q)Y.set($,G);return G};var r=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var w$=r((BJ)=>{Object.defineProperty(BJ,"__esModule",{value:!0});BJ.utf8Count=mY;BJ.utf8EncodeJs=LJ;BJ.utf8EncodeTE=EJ;BJ.utf8Encode=kY;BJ.utf8DecodeJs=mJ;BJ.utf8DecodeTD=_J;BJ.utf8Decode=fY;function mY($){let Z=$.length,J=0,Q=0;while(Q<Z){let Y=$.charCodeAt(Q++);if((Y&4294967168)===0){J++;continue}else if((Y&4294965248)===0)J+=2;else{if(Y>=55296&&Y<=56319){if(Q<Z){let X=$.charCodeAt(Q);if((X&64512)===56320)++Q,Y=((Y&1023)<<10)+(X&1023)+65536}}if((Y&4294901760)===0)J+=3;else J+=4}}return J}function LJ($,Z,J){let Q=$.length,Y=J,X=0;while(X<Q){let G=$.charCodeAt(X++);if((G&4294967168)===0){Z[Y++]=G;continue}else if((G&4294965248)===0)Z[Y++]=G>>6&31|192;else{if(G>=55296&&G<=56319){if(X<Q){let W=$.charCodeAt(X);if((W&64512)===56320)++X,G=((G&1023)<<10)+(W&1023)+65536}}if((G&4294901760)===0)Z[Y++]=G>>12&15|224,Z[Y++]=G>>6&63|128;else Z[Y++]=G>>18&7|240,Z[Y++]=G>>12&63|128,Z[Y++]=G>>6&63|128}Z[Y++]=G&63|128}}var _Y=new TextEncoder,BY=50;function EJ($,Z,J){_Y.encodeInto($,Z.subarray(J))}function kY($,Z,J){if($.length>BY)EJ($,Z,J);else LJ($,Z,J)}var gY=4096;function mJ($,Z,J){let Q=Z,Y=Q+J,X=[],G="";while(Q<Y){let W=$[Q++];if((W&128)===0)X.push(W);else if((W&224)===192){let q=$[Q++]&63;X.push((W&31)<<6|q)}else if((W&240)===224){let q=$[Q++]&63,N=$[Q++]&63;X.push((W&31)<<12|q<<6|N)}else if((W&248)===240){let q=$[Q++]&63,N=$[Q++]&63,z=$[Q++]&63,M=(W&7)<<18|q<<12|N<<6|z;if(M>65535)M-=65536,X.push(M>>>10&1023|55296),M=56320|M&1023;X.push(M)}else X.push(W);if(X.length>=gY)G+=String.fromCharCode(...X),X.length=0}if(X.length>0)G+=String.fromCharCode(...X);return G}var xY=new TextDecoder,SY=200;function _J($,Z,J){let Q=$.subarray(Z,Z+J);return xY.decode(Q)}function fY($,Z,J){if(J>SY)return _J($,Z,J);else return mJ($,Z,J)}});var WZ=r((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.ExtData=void 0;class kJ{type;data;constructor($,Z){this.type=$,this.data=Z}}gJ.ExtData=kJ});var T$=r((SJ)=>{Object.defineProperty(SJ,"__esModule",{value:!0});SJ.DecodeError=void 0;class C$ extends Error{constructor($){super($);let Z=Object.create(C$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:C$.name})}}SJ.DecodeError=C$});var D$=r((vJ)=>{Object.defineProperty(vJ,"__esModule",{value:!0});vJ.UINT32_MAX=void 0;vJ.setUint64=dY;vJ.setInt64=uY;vJ.getInt64=nY;vJ.getUint64=cY;vJ.UINT32_MAX=4294967295;function dY($,Z,J){let Q=J/4294967296,Y=J;$.setUint32(Z,Q),$.setUint32(Z+4,Y)}function uY($,Z,J){let Q=Math.floor(J/4294967296),Y=J;$.setUint32(Z,Q),$.setUint32(Z+4,Y)}function nY($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function cY($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var qZ=r((uJ)=>{Object.defineProperty(uJ,"__esModule",{value:!0});uJ.timestampExtension=uJ.EXT_TIMESTAMP=void 0;uJ.encodeTimeSpecToTimestamp=bJ;uJ.encodeDateToTimeSpec=hJ;uJ.encodeTimestampExtension=iJ;uJ.decodeTimestampToTimeSpec=pJ;uJ.decodeTimestampExtension=dJ;var tY=T$(),lJ=D$();uJ.EXT_TIMESTAMP=-1;var eY=4294967295,$X=17179869183;function bJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=$X)if(Z===0&&$<=eY){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,Y=new Uint8Array(8),X=new DataView(Y.buffer);return X.setUint32(0,Z<<2|J&3),X.setUint32(4,Q),Y}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,lJ.setInt64)(Q,4,$),J}}function hJ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,Y=Math.floor(Q/1e9);return{sec:J+Y,nsec:Q-Y*1e9}}function iJ($){if($ instanceof Date){let Z=hJ($);return bJ(Z)}else return null}function pJ($){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),Y=(J&3)*4294967296+Q,X=J>>>2;return{sec:Y,nsec:X}}case 12:{let J=(0,lJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new tY.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function dJ($){let Z=pJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}uJ.timestampExtension={type:uJ.EXT_TIMESTAMP,encode:iJ,decode:dJ}});var j$=r((rJ)=>{Object.defineProperty(rJ,"__esModule",{value:!0});rJ.ExtensionCodec=void 0;var A$=WZ(),GX=qZ();class NZ{static defaultCodec=new NZ;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(GX.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 Y=Q($,Z);if(Y!=null){let X=-1-J;return new A$.ExtData(X,Y)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let Y=Q($,Z);if(Y!=null){let X=J;return new A$.ExtData(X,Y)}}}if($ instanceof A$.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 A$.ExtData(Z,$)}}rJ.ExtensionCodec=NZ});var zZ=r((aJ)=>{Object.defineProperty(aJ,"__esModule",{value:!0});aJ.ensureUint8Array=WX;function VX($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function WX($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(VX($))return new Uint8Array($);else return Uint8Array.from($)}});var OZ=r((eJ)=>{Object.defineProperty(eJ,"__esModule",{value:!0});eJ.Encoder=eJ.DEFAULT_INITIAL_BUFFER_SIZE=eJ.DEFAULT_MAX_DEPTH=void 0;var sJ=w$(),NX=j$(),tJ=D$(),zX=zZ();eJ.DEFAULT_MAX_DEPTH=100;eJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class MZ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??NX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??eJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??eJ.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 MZ({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,sJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,sJ.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,zX.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 Y of J){let X=$[Y];if(!(this.ignoreUndefined&&X===void 0))this.encodeString(Y),this.doEncode(X,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),Q=J.length;if(Q>=4294967296)throw Error(`Too large extension object: ${Q}`);this.writeU8(201),this.writeU32(Q),this.writeI8($.type),this.writeU8a(J);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),(0,tJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,tJ.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}}eJ.Encoder=MZ});var YQ=r((QQ)=>{Object.defineProperty(QQ,"__esModule",{value:!0});QQ.encode=OX;var MX=OZ();function OX($,Z){return new MX.Encoder(Z).encodeSharedRef($)}});var GQ=r((XQ)=>{Object.defineProperty(XQ,"__esModule",{value:!0});XQ.prettyByte=HX;function HX($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var NQ=r((WQ)=>{Object.defineProperty(WQ,"__esModule",{value:!0});WQ.CachedKeyDecoder=void 0;var IX=w$(),RX=16,UX=16;class VQ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=RX,Z=UX){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 Y of Q){let X=Y.bytes;for(let G=0;G<J;G++)if(X[G]!==$[Z+G])continue $;return Y.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 Y=(0,IX.utf8DecodeJs)($,Z,J),X=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(X,Y),Y}}WQ.CachedKeyDecoder=VQ});var L$=r((HQ)=>{Object.defineProperty(HQ,"__esModule",{value:!0});HQ.Decoder=void 0;var FZ=GQ(),PX=j$(),E0=D$(),wX=w$(),zQ=zZ(),CX=NQ(),K0=T$(),HZ="array",$$="map_key",OQ="map_value",TX=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new K0.DecodeError("The type of key must be string or number but "+typeof $)};class FQ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=HZ,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=$$,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===HZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===$$||$.type===OQ){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 e0=-1,KZ=new DataView(new ArrayBuffer(0)),DX=new Uint8Array(KZ.buffer);try{KZ.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 MQ=RangeError("Insufficient data"),AX=new CX.CachedKeyDecoder;class IZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=KZ;bytes=DX;headByte=e0;stack=new FQ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??PX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??E0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??E0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??E0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??E0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??E0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:AX,this.mapKeyConverter=$?.mapKeyConverter??TX}clone(){return new IZ({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=e0,this.stack.reset()}setBuffer($){let Z=(0,zQ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===e0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,zQ.ensureUint8Array)($),Q=new Uint8Array(Z.length+J.length);Q.set(Z),Q.set(J,Z.length),this.setBuffer(Q)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,J;for await(let G of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(G);try{J=this.doDecodeSync(),Z=!0}catch(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:Y,totalPos:X}=this;throw RangeError(`Insufficient data in parsing ${(0,FZ.prettyByte)(Q)} at ${X} (${Y} 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 Y of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(Y),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(X){if(!(X instanceof RangeError))throw X}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let Q=$-128;if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($<160){let Q=$-144;if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else{let Q=$-160;Z=this.decodeString(Q,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let Q=this.lookU8();Z=this.decodeString(Q,1)}else if($===218){let Q=this.lookU16();Z=this.decodeString(Q,2)}else if($===219){let Q=this.lookU32();Z=this.decodeString(Q,4)}else if($===220){let Q=this.readU16();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===221){let Q=this.readU32();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===222){let Q=this.readU16();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===223){let Q=this.readU32();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===196){let Q=this.lookU8();Z=this.decodeBinary(Q,1)}else if($===197){let Q=this.lookU16();Z=this.decodeBinary(Q,2)}else if($===198){let Q=this.lookU32();Z=this.decodeBinary(Q,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let Q=this.lookU8();Z=this.decodeExtension(Q,1)}else if($===200){let Q=this.lookU16();Z=this.decodeExtension(Q,2)}else if($===201){let Q=this.lookU32();Z=this.decodeExtension(Q,4)}else throw new K0.DecodeError(`Unrecognized type byte: ${(0,FZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===HZ)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===$$){if(Z==="__proto__")throw new K0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=OQ;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=$$;continue $}}return Z}}readHeadByte(){if(this.headByte===e0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=e0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new K0.DecodeError(`Unrecognized array type byte: ${(0,FZ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new K0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new K0.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 K0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw MQ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,wX.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===$$;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new K0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw MQ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new K0.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,E0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,E0.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,$}}HQ.Decoder=IZ});var UQ=r((RQ)=>{Object.defineProperty(RQ,"__esModule",{value:!0});RQ.decode=jX;RQ.decodeMulti=LX;var IQ=L$();function jX($,Z){return new IQ.Decoder(Z).decode($)}function LX($,Z){return new IQ.Decoder(Z).decodeMulti($)}});var TQ=r((CQ)=>{Object.defineProperty(CQ,"__esModule",{value:!0});CQ.isAsyncIterable=PQ;CQ.asyncIterableFromStream=wQ;CQ.ensureAsyncIterable=_X;function PQ($){return $[Symbol.asyncIterator]!=null}async function*wQ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function _X($){if(PQ($))return $;else return wQ($)}});var AQ=r((DQ)=>{Object.defineProperty(DQ,"__esModule",{value:!0});DQ.decodeAsync=xX;DQ.decodeArrayStream=SX;DQ.decodeMultiStream=fX;var RZ=L$(),UZ=TQ();async function xX($,Z){let J=(0,UZ.ensureAsyncIterable)($);return new RZ.Decoder(Z).decodeAsync(J)}function SX($,Z){let J=(0,UZ.ensureAsyncIterable)($);return new RZ.Decoder(Z).decodeArrayStream(J)}function fX($,Z){let J=(0,UZ.ensureAsyncIterable)($);return new RZ.Decoder(Z).decodeStream(J)}});var LQ=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 bX=YQ();Object.defineProperty(y,"encode",{enumerable:!0,get:function(){return bX.encode}});var jQ=UQ();Object.defineProperty(y,"decode",{enumerable:!0,get:function(){return jQ.decode}});Object.defineProperty(y,"decodeMulti",{enumerable:!0,get:function(){return jQ.decodeMulti}});var PZ=AQ();Object.defineProperty(y,"decodeAsync",{enumerable:!0,get:function(){return PZ.decodeAsync}});Object.defineProperty(y,"decodeArrayStream",{enumerable:!0,get:function(){return PZ.decodeArrayStream}});Object.defineProperty(y,"decodeMultiStream",{enumerable:!0,get:function(){return PZ.decodeMultiStream}});var hX=L$();Object.defineProperty(y,"Decoder",{enumerable:!0,get:function(){return hX.Decoder}});var iX=T$();Object.defineProperty(y,"DecodeError",{enumerable:!0,get:function(){return iX.DecodeError}});var pX=OZ();Object.defineProperty(y,"Encoder",{enumerable:!0,get:function(){return pX.Encoder}});var dX=j$();Object.defineProperty(y,"ExtensionCodec",{enumerable:!0,get:function(){return dX.ExtensionCodec}});var uX=WZ();Object.defineProperty(y,"ExtData",{enumerable:!0,get:function(){return uX.ExtData}});var d0=qZ();Object.defineProperty(y,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return d0.EXT_TIMESTAMP}});Object.defineProperty(y,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return d0.encodeDateToTimeSpec}});Object.defineProperty(y,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return d0.encodeTimeSpecToTimestamp}});Object.defineProperty(y,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return d0.decodeTimestampToTimeSpec}});Object.defineProperty(y,"encodeTimestampExtension",{enumerable:!0,get:function(){return d0.encodeTimestampExtension}});Object.defineProperty(y,"decodeTimestampExtension",{enumerable:!0,get:function(){return d0.decodeTimestampExtension}})});import*as q0 from"node:crypto";var U0=q0&&typeof q0==="object"&&"webcrypto"in q0?q0.webcrypto:q0&&typeof q0==="object"&&("randomBytes"in q0)?q0:void 0;function Z$($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function E$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function p($,...Z){if(!E$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function m$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function TZ($,Z){p($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function _$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var N0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var hQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!hQ)throw Error("Non little-endian hardware is not supported");function iQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function J$($){if(typeof $==="string")$=iQ($);else if(E$($))$=Q$($);else throw Error("Uint8Array expected, got "+typeof $);return $}function DZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function AZ($,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 jZ=($,Z)=>{function J(Q,...Y){if(p(Q),$.nonceLength!==void 0){let z=Y[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)p(z);else p(z,$.nonceLength)}let X=$.tagLength;if(X&&Y[1]!==void 0)p(Y[1]);let G=Z(Q,...Y),W=(z,M)=>{if(M!==void 0){if(z!==2)throw Error("cipher output not supported");p(M)}},q=!1;return{encrypt(z,M){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,p(z),W(G.encrypt.length,M),G.encrypt(z,M)},decrypt(z,M){if(p(z),X&&z.length<X)throw Error("invalid ciphertext length: smaller than tagLength="+X);return W(G.decrypt.length,M),G.decrypt(z,M)}}}return Object.assign(J,$),J};function B$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!pQ(Z))throw Error("invalid output, must be aligned");return Z}function pQ($){return $.byteOffset%4===0}function Q$($){return Uint8Array.from($)}function Y0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function n0($=32){if(U0&&typeof U0.getRandomValues==="function")return U0.getRandomValues(new Uint8Array($));if(U0&&typeof U0.randomBytes==="function")return U0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var EZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),dQ=EZ("expand 16-byte k"),uQ=EZ("expand 32-byte k"),nQ=N0(dQ),cQ=N0(uQ);function U($,Z){return $<<Z|$>>>32-Z}function k$($){return $.byteOffset%4===0}var Y$=64,rQ=16,mZ=4294967295,LZ=new Uint32Array;function oQ($,Z,J,Q,Y,X,G,W){let q=Y.length,N=new Uint8Array(Y$),z=N0(N),M=k$(Y)&&k$(X),F=M?N0(Y):LZ,K=M?N0(X):LZ;for(let I=0;I<q;G++){if($(Z,J,Q,z,G,W),G>=mZ)throw Error("arx: counter overflow");let R=Math.min(Y$,q-I);if(M&&R===Y$){let P=I/4;if(I%4!==0)throw Error("arx: invalid block position");for(let C=0,D;C<rQ;C++)D=P+C,K[D]=F[D]^z[C];I+=Y$;continue}for(let P=0,C;P<R;P++)C=I+P,X[C]=Y[C]^N[P];I+=R}}function _Z($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:Y,counterRight:X,rounds:G}=DZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return Z$(Y),Z$(G),_$(X),_$(J),(W,q,N,z,M=0)=>{p(W),p(q),p(N);let F=N.length;if(z===void 0)z=new Uint8Array(F);if(p(z),Z$(M),M<0||M>=mZ)throw Error("arx: counter overflow");if(z.length<F)throw Error(`arx: output (${z.length}) is shorter than data (${F})`);let K=[],I=W.length,R,P;if(I===32)K.push(R=Q$(W)),P=cQ;else if(I===16&&J)R=new Uint8Array(32),R.set(W),R.set(W,16),P=nQ,K.push(R);else throw Error(`arx: invalid 32-byte key, got length=${I}`);if(!k$(q))K.push(q=Q$(q));let C=N0(R);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(P,C,N0(q.subarray(0,16)),C),q=q.subarray(16)}let D=16-Y;if(D!==q.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let w=new Uint8Array(12);w.set(q,X?0:12-q.length),q=w,K.push(q)}let j=N0(q);return oQ($,P,C,j,N,z,M,G),Y0(...K),z}}var u=($,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,$=J$($),p($,32);let Z=u($,0),J=u($,2),Q=u($,4),Y=u($,6),X=u($,8),G=u($,10),W=u($,12),q=u($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|Q<<6)&7939,this.r[3]=(Q>>>7|Y<<9)&8191,this.r[4]=(Y>>>4|X<<12)&255,this.r[5]=X>>>1&8190,this.r[6]=(X>>>14|G<<2)&8191,this.r[7]=(G>>>11|W<<5)&8065,this.r[8]=(W>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let N=0;N<8;N++)this.pad[N]=u($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:Y,r:X}=this,G=X[0],W=X[1],q=X[2],N=X[3],z=X[4],M=X[5],F=X[6],K=X[7],I=X[8],R=X[9],P=u($,Z+0),C=u($,Z+2),D=u($,Z+4),j=u($,Z+6),w=u($,Z+8),L=u($,Z+10),B=u($,Z+12),d=u($,Z+14),_=Y[0]+(P&8191),g=Y[1]+((P>>>13|C<<3)&8191),S=Y[2]+((C>>>10|D<<6)&8191),x=Y[3]+((D>>>7|j<<9)&8191),f=Y[4]+((j>>>4|w<<12)&8191),H=Y[5]+(w>>>1&8191),l=Y[6]+((w>>>14|L<<2)&8191),b=Y[7]+((L>>>11|B<<5)&8191),h=Y[8]+((B>>>8|d<<8)&8191),i=Y[9]+(d>>>5|Q),T=0,c=T+_*G+g*(5*R)+S*(5*I)+x*(5*K)+f*(5*F);T=c>>>13,c&=8191,c+=H*(5*M)+l*(5*z)+b*(5*N)+h*(5*q)+i*(5*W),T+=c>>>13,c&=8191;let a=T+_*W+g*G+S*(5*R)+x*(5*I)+f*(5*K);T=a>>>13,a&=8191,a+=H*(5*F)+l*(5*M)+b*(5*z)+h*(5*N)+i*(5*q),T+=a>>>13,a&=8191;let e=T+_*q+g*W+S*G+x*(5*R)+f*(5*I);T=e>>>13,e&=8191,e+=H*(5*K)+l*(5*F)+b*(5*M)+h*(5*z)+i*(5*N),T+=e>>>13,e&=8191;let k=T+_*N+g*q+S*W+x*G+f*(5*R);T=k>>>13,k&=8191,k+=H*(5*I)+l*(5*K)+b*(5*F)+h*(5*M)+i*(5*z),T+=k>>>13,k&=8191;let W0=T+_*z+g*N+S*q+x*W+f*G;T=W0>>>13,W0&=8191,W0+=H*(5*R)+l*(5*I)+b*(5*K)+h*(5*F)+i*(5*M),T+=W0>>>13,W0&=8191;let m0=T+_*M+g*z+S*N+x*q+f*W;T=m0>>>13,m0&=8191,m0+=H*G+l*(5*R)+b*(5*I)+h*(5*K)+i*(5*F),T+=m0>>>13,m0&=8191;let _0=T+_*F+g*M+S*z+x*N+f*q;T=_0>>>13,_0&=8191,_0+=H*W+l*G+b*(5*R)+h*(5*I)+i*(5*K),T+=_0>>>13,_0&=8191;let B0=T+_*K+g*F+S*M+x*z+f*N;T=B0>>>13,B0&=8191,B0+=H*q+l*W+b*G+h*(5*R)+i*(5*I),T+=B0>>>13,B0&=8191;let k0=T+_*I+g*K+S*F+x*M+f*z;T=k0>>>13,k0&=8191,k0+=H*N+l*q+b*W+h*G+i*(5*R),T+=k0>>>13,k0&=8191;let g0=T+_*R+g*I+S*K+x*F+f*M;T=g0>>>13,g0&=8191,g0+=H*z+l*N+b*q+h*W+i*G,T+=g0>>>13,g0&=8191,T=(T<<2)+T|0,T=T+c|0,c=T&8191,T=T>>>13,a+=T,Y[0]=c,Y[1]=a,Y[2]=e,Y[3]=k,Y[4]=W0,Y[5]=m0,Y[6]=_0,Y[7]=B0,Y[8]=k0,Y[9]=g0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let G=2;G<10;G++)$[G]+=Q,Q=$[G]>>>13,$[G]&=8191;$[0]+=Q*5,Q=$[0]>>>13,$[0]&=8191,$[1]+=Q,Q=$[1]>>>13,$[1]&=8191,$[2]+=Q,J[0]=$[0]+5,Q=J[0]>>>13,J[0]&=8191;for(let G=1;G<10;G++)J[G]=$[G]+Q,Q=J[G]>>>13,J[G]&=8191;J[9]-=8192;let Y=(Q^1)-1;for(let G=0;G<10;G++)J[G]&=Y;Y=~Y;for(let G=0;G<10;G++)$[G]=$[G]&Y|J[G];$[0]=($[0]|$[1]<<13)&65535,$[1]=($[1]>>>3|$[2]<<10)&65535,$[2]=($[2]>>>6|$[3]<<7)&65535,$[3]=($[3]>>>9|$[4]<<4)&65535,$[4]=($[4]>>>12|$[5]<<1|$[6]<<14)&65535,$[5]=($[6]>>>2|$[7]<<11)&65535,$[6]=($[7]>>>5|$[8]<<8)&65535,$[7]=($[8]>>>8|$[9]<<5)&65535;let X=$[0]+Z[0];$[0]=X&65535;for(let G=1;G<8;G++)X=($[G]+Z[G]|0)+(X>>>16)|0,$[G]=X&65535;Y0(J)}update($){m$(this);let{buffer:Z,blockLen:J}=this;$=J$($);let Q=$.length;for(let Y=0;Y<Q;){let X=Math.min(J-this.pos,Q-Y);if(X===J){for(;J<=Q-Y;Y+=J)this.process($,Y);continue}if(Z.set($.subarray(Y,Y+X),this.pos),this.pos+=X,Y+=X,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){Y0(this.h,this.r,this.buffer,this.pad)}digestInto($){m$(this),TZ($,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 Y=0;for(let X=0;X<8;X++)$[Y++]=J[X]>>>0,$[Y++]=J[X]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function aQ($){let Z=(Q,Y)=>$(Y).update(J$(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var g$=aQ(($)=>new BZ($));function sQ($,Z,J,Q,Y,X=20){let G=$[0],W=Z[0],q=Z[1],N=Z[2],z=Z[3],M=$[1],F=J[0],K=J[1],I=Y,R=0,P=$[2],C=Z[4],D=Z[5],j=Z[6],w=Z[7],L=$[3],B=G,d=W,_=q,g=N,S=z,x=M,f=F,H=K,l=I,b=R,h=P,i=C,T=D,c=j,a=w,e=L;for(let W0=0;W0<X;W0+=2)S^=U(B+T|0,7),l^=U(S+B|0,9),T^=U(l+S|0,13),B^=U(T+l|0,18),b^=U(x+d|0,7),c^=U(b+x|0,9),d^=U(c+b|0,13),x^=U(d+c|0,18),a^=U(h+f|0,7),_^=U(a+h|0,9),f^=U(_+a|0,13),h^=U(f+_|0,18),g^=U(e+i|0,7),H^=U(g+e|0,9),i^=U(H+g|0,13),e^=U(i+H|0,18),d^=U(B+g|0,7),_^=U(d+B|0,9),g^=U(_+d|0,13),B^=U(g+_|0,18),f^=U(x+S|0,7),H^=U(f+x|0,9),S^=U(H+f|0,13),x^=U(S+H|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),T^=U(e+a|0,7),c^=U(T+e|0,9),a^=U(c+T|0,13),e^=U(a+c|0,18);let k=0;Q[k++]=G+B|0,Q[k++]=W+d|0,Q[k++]=q+_|0,Q[k++]=N+g|0,Q[k++]=z+S|0,Q[k++]=M+x|0,Q[k++]=F+f|0,Q[k++]=K+H|0,Q[k++]=I+l|0,Q[k++]=R+b|0,Q[k++]=P+h|0,Q[k++]=C+i|0,Q[k++]=D+T|0,Q[k++]=j+c|0,Q[k++]=w+a|0,Q[k++]=L+e|0}function tQ($,Z,J,Q){let Y=$[0],X=Z[0],G=Z[1],W=Z[2],q=Z[3],N=$[1],z=J[0],M=J[1],F=J[2],K=J[3],I=$[2],R=Z[4],P=Z[5],C=Z[6],D=Z[7],j=$[3];for(let L=0;L<20;L+=2)q^=U(Y+P|0,7),F^=U(q+Y|0,9),P^=U(F+q|0,13),Y^=U(P+F|0,18),K^=U(N+X|0,7),C^=U(K+N|0,9),X^=U(C+K|0,13),N^=U(X+C|0,18),D^=U(I+z|0,7),G^=U(D+I|0,9),z^=U(G+D|0,13),I^=U(z+G|0,18),W^=U(j+R|0,7),M^=U(W+j|0,9),R^=U(M+W|0,13),j^=U(R+M|0,18),X^=U(Y+W|0,7),G^=U(X+Y|0,9),W^=U(G+X|0,13),Y^=U(W+G|0,18),z^=U(N+q|0,7),M^=U(z+N|0,9),q^=U(M+z|0,13),N^=U(q+M|0,18),R^=U(I+K|0,7),F^=U(R+I|0,9),K^=U(F+R|0,13),I^=U(K+F|0,18),P^=U(j+D|0,7),C^=U(P+j|0,9),D^=U(C+P|0,13),j^=U(D+C|0,18);let w=0;Q[w++]=Y,Q[w++]=N,Q[w++]=I,Q[w++]=j,Q[w++]=z,Q[w++]=M,Q[w++]=F,Q[w++]=K}var x$=_Z(sQ,{counterRight:!0,extendNonceFn:tQ}),S$=jZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=B$(J.length+32,Q,!1);let Y=Q.subarray(0,32),X=Q.subarray(32);Q.set(J,32),Y0(Y),x$($,Z,Q,Q);let G=g$(X,Y);return Q.set(G,16),Y0(Q.subarray(0,16),G),Q.subarray(16)},decrypt(J,Q){p(J),Q=B$(J.length+32,Q,!1);let Y=Q.subarray(0,32),X=Q.subarray(32,48),G=Q.subarray(48);Q.set(J,32),Y0(Y);let W=x$($,Z,Y,Y),q=g$(G,W);if(!AZ(X,q))throw Error("invalid tag");return x$($,Z,Q.subarray(16),Q.subarray(16)),Y0(Y,X,q),G}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function eQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function c0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function P0($,...Z){if(!eQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function r0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function X$($,Z){P0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function kZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function x0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function S0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function o0($,Z){return $<<32-Z|$>>>Z}var gZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function xZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var SZ=gZ?($)=>$:($)=>xZ($);function $Y($){for(let Z=0;Z<$.length;Z++)$[Z]=xZ($[Z]);return $}var s=gZ?($)=>$:$Y;function ZY($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function f0($){if(typeof $==="string")$=ZY($);return P0($),$}class f${}function fZ($){let Z=(Q,Y)=>$(Y).update(f0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var vZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var G$=BigInt(4294967295),yZ=BigInt(32);function v$($,Z=!1){if(Z)return{h:Number($&G$),l:Number($>>yZ&G$)};return{h:Number($>>yZ&G$)|0,l:Number($&G$)|0}}function z0($,Z,J,Q,Y){return $=$+Z+Y|0,Q=o0(Q^$,16),J=J+Q|0,Z=o0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function M0($,Z,J,Q,Y){return $=$+Z+Y|0,Q=o0(Q^$,8),J=J+Q|0,Z=o0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class y$ extends f${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,c0($),c0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=x0(this.buffer)}update($){r0(this),$=f0($),P0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,Y=$.length,X=$.byteOffset,G=$.buffer;for(let W=0;W<Y;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(Q),this.pos=0;let q=Math.min(Z-this.pos,Y-W),N=X+W;if(q===Z&&!(N%4)&&W+q<Y){let z=new Uint32Array(G,N,Math.floor((Y-W)/4));s(z);for(let M=0;W+Z<Y;M+=Q.length,W+=Z)this.length+=Z,this.compress(z,M,!1);s(z);continue}J.set($.subarray(W,W+q),this.pos),this.pos+=q,this.length+=q,W+=q}return this}digestInto($){r0(this),X$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,S0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=x0($);this.get().forEach((Y,X)=>Q[X]=SZ(Y))}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:Y,outputLen:X,pos:G}=this;return $||($=new this.constructor({dkLen:X})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=Y,$.finished=Q,$.length=J,$.pos=G,$.outputLen=X,$}clone(){return this._cloneInto()}}function l$($,Z,J,Q,Y,X,G,W,q,N,z,M,F,K,I,R,P,C,D,j){let w=0;for(let L=0;L<Q;L++)({a:Y,b:q,c:F,d:P}=z0(Y,q,F,P,J[Z+$[w++]])),{a:Y,b:q,c:F,d:P}=M0(Y,q,F,P,J[Z+$[w++]]),{a:X,b:N,c:K,d:C}=z0(X,N,K,C,J[Z+$[w++]]),{a:X,b:N,c:K,d:C}=M0(X,N,K,C,J[Z+$[w++]]),{a:G,b:z,c:I,d:D}=z0(G,z,I,D,J[Z+$[w++]]),{a:G,b:z,c:I,d:D}=M0(G,z,I,D,J[Z+$[w++]]),{a:W,b:M,c:R,d:j}=z0(W,M,R,j,J[Z+$[w++]]),{a:W,b:M,c:R,d:j}=M0(W,M,R,j,J[Z+$[w++]]),{a:Y,b:N,c:I,d:j}=z0(Y,N,I,j,J[Z+$[w++]]),{a:Y,b:N,c:I,d:j}=M0(Y,N,I,j,J[Z+$[w++]]),{a:X,b:z,c:R,d:P}=z0(X,z,R,P,J[Z+$[w++]]),{a:X,b:z,c:R,d:P}=M0(X,z,R,P,J[Z+$[w++]]),{a:G,b:M,c:F,d:C}=z0(G,M,F,C,J[Z+$[w++]]),{a:G,b:M,c:F,d:C}=M0(G,M,F,C,J[Z+$[w++]]),{a:W,b:q,c:K,d:D}=z0(W,q,K,D,J[Z+$[w++]]),{a:W,b:q,c:K,d:D}=M0(W,q,K,D,J[Z+$[w++]]);return{v0:Y,v1:X,v2:G,v3:W,v4:q,v5:N,v6:z,v7:M,v8:F,v9:K,v10:I,v11:R,v12:P,v13:C,v14:D,v15:j}}var X0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},O0=vZ.slice(),lZ=(()=>{let $=Array.from({length:16},(Q,Y)=>Y),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((Y)=>Q[Y]),J=[];for(let Q=0,Y=$;Q<7;Q++,Y=Z(Y))J.push(...Y);return Uint8Array.from(J)})();class b$ extends y${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}=$,Y=Q!==void 0;if(J!==void 0){if(Y)throw Error('Only "key" or "context" can be specified at same time');let X=f0(J).slice();P0(X,32),this.IV=x0(X),s(this.IV),this.flags=Z|X0.KEYED_HASH}else if(Y){let X=f0(Q),G=new b$({dkLen:32},X0.DERIVE_KEY_CONTEXT).update(X).digest();this.IV=x0(G),s(this.IV),this.flags=Z|X0.DERIVE_KEY_MATERIAL}else this.IV=O0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=kZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:Y,pos:X}=this,{h:G,l:W}=v$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:M,v4:F,v5:K,v6:I,v7:R,v8:P,v9:C,v10:D,v11:j,v12:w,v13:L,v14:B,v15:d}=l$(lZ,Q,J,7,Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],O0[0],O0[1],O0[2],O0[3],G,W,X,Z);Y[0]=q^P,Y[1]=N^C,Y[2]=z^D,Y[3]=M^j,Y[4]=F^w,Y[5]=K^L,Y[6]=I^B,Y[7]=R^d}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=X0.CHUNK_START;if(this.chunkPos===15||J)Q|=X0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let Y=this.state;this.state=this.IV.slice();for(let X,G=this.chunksDone+1;J||!(G&1);G>>=1){if(!(X=this.stack.pop()))break;this.buffer32.set(X,0),this.buffer32.set(Y,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|X0.PARENT,this.buffer32,0),Y=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(Y)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:Y,posOut:X,chunkOut:G,stack:W,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=W.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=Y,$.chunksDone=q,$.posOut=X,$.chunkOut=G,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,S0(this.state,this.buffer32,this.IV,this.bufferOut32),S0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:Y}=this,{h:X,l:G}=v$(BigInt(this.chunkOut++));s(Q);let{v0:W,v1:q,v2:N,v3:z,v4:M,v5:F,v6:K,v7:I,v8:R,v9:P,v10:C,v11:D,v12:j,v13:w,v14:L,v15:B}=l$(lZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],O0[0],O0[1],O0[2],O0[3],G,X,Z,J);Y[0]=W^R,Y[1]=q^P,Y[2]=N^C,Y[3]=z^D,Y[4]=M^j,Y[5]=F^w,Y[6]=K^L,Y[7]=I^B,Y[8]=$[0]^R,Y[9]=$[1]^P,Y[10]=$[2]^C,Y[11]=$[3]^D,Y[12]=$[4]^j,Y[13]=$[5]^w,Y[14]=$[6]^L,Y[15]=$[7]^B,s(Q),s(Y),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,S0(this.buffer.subarray(this.pos));let $=this.flags|X0.ROOT;if(this.stack.length)$|=X0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?X0.CHUNK_START:0)|X0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){r0(this,!1),P0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,Y=$.length;Q<Y;){if(this.posOut>=Z)this.b2CompressOut();let X=Math.min(Z-this.posOut,Y-Q);$.set(J.subarray(this.posOut,this.posOut+X),Q),this.posOut+=X,Q+=X}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return c0($),this.xofInto(new Uint8Array($))}digestInto($){if(X$($,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 bZ=fZ(($)=>new b$($));function $0($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function V$($){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 W$($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var hZ;if(typeof Uint8Array.prototype.toBase64==="function")hZ=($)=>$.toBase64();else hZ=($)=>btoa(String.fromCharCode(...$));var h$;if(typeof Uint8Array.fromBase64==="function")h$=($)=>Uint8Array.fromBase64($);else h$=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function iZ($){let Z=$.length%4===0?"":"=".repeat(4-$.length%4),J=$.replace(/-/g,"+").replace(/_/g,"/")+Z;return h$(J)}function G0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var v0=64;var pZ=32,y0=8;var dZ=32;var uZ=30000,nZ=512,A;((H)=>{H[H.Success=0]="Success";H[H.InvalidSignature=3]="InvalidSignature";H[H.ClockOutOfSync=4]="ClockOutOfSync";H[H.UserNotRegistered=5]="UserNotRegistered";H[H.ServerMisconfigured=6]="ServerMisconfigured";H[H.MissingBody=7]="MissingBody";H[H.ExtraBodyContent=8]="ExtraBodyContent";H[H.MissingParam=9]="MissingParam";H[H.InvalidParam=10]="InvalidParam";H[H.InvalidRequest=11]="InvalidRequest";H[H.InternalError=12]="InternalError";H[H.NotFound=13]="NotFound";H[H.InvalidMessage=14]="InvalidMessage";H[H.NoChange=15]="NoChange";H[H.DatabaseClosed=16]="DatabaseClosed";H[H.StorageError=17]="StorageError";H[H.DatabaseError=18]="DatabaseError";H[H.HashMismatch=19]="HashMismatch";H[H.DecryptionError=20]="DecryptionError";H[H.NotImplemented=21]="NotImplemented";H[H.MissingSeed=22]="MissingSeed";H[H.OutOfBounds=23]="OutOfBounds";H[H.HostError=24]="HostError";H[H.CommunicationError=25]="CommunicationError";H[H.VarLimitExceeded=26]="VarLimitExceeded";H[H.InvalidResponse=27]="InvalidResponse";H[H.ConnectionClosed=28]="ConnectionClosed";H[H.CryptoError=29]="CryptoError";H[H.WebAuthnError=30]="WebAuthnError"})(A||={});var cZ="t";function O($){return[$,0]}function V($){return[void 0,$]}var JY=32,lG=Symbol("X25519Sk");function rZ($){if($.byteLength!==JY)return V(10);return O($)}var E=(1n<<255n)-19n,QY=121665n,oZ=new Uint8Array(32);oZ[0]=9;function aZ($){let Z=0n;for(let J=$.length-1;J>=0;J--)Z=Z<<8n|BigInt($[J]);return Z}function YY($){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 XY($){let Z=$.slice();return Z[31]&=127,aZ(Z)}function GY($){let Z=$.slice();return Z[0]&=248,Z[31]&=127,Z[31]|=64,Z}function q$($,Z,J){let Q=-$,Y=(Z^J)&Q;return[Z^Y,J^Y]}function VY($){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 WY($,Z){let J=GY($),Q=XY(Z),Y=1n,X=0n,G=Q,W=1n,q=0n,N=aZ(J);for(let z=254;z>=0;z--){let M=N>>BigInt(z)&1n;q^=M,[Y,G]=q$(q,Y,G),[X,W]=q$(q,X,W),q=M;let F=(Y+X)%E,K=F*F%E,I=(Y-X+E)%E,R=I*I%E,P=(K-R+E)%E,C=(G+W)%E,j=(G-W+E)%E*F%E,w=C*I%E,L=(j+w)%E,B=(j-w+E)%E;G=L*L%E,W=Q*B*B%E,Y=K*R%E,X=P*(K+QY*P)%E}return[Y,G]=q$(q,Y,G),[X,W]=q$(q,X,W),J.fill(0),YY(Y*VY(X)%E)}function sZ($){return WY($,oZ)}var i$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function tZ($){let Z=new Uint8Array(i$.length+32);return Z.set(i$),Z.set($.subarray(0,32),i$.length),Z}var p$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,110,4,34,4,32]);function eZ($){let Z=new Uint8Array(p$.length+32);return Z.set(p$),Z.set($.subarray(0,32),p$.length),Z}function $J($){return typeof $==="string"?new TextEncoder().encode($):$}function F0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class w0{verifyKeys=new Map;async genRandomBytes($){return n0($)}async gen256BitSecureRandomSeed(){return n0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=n0(24),Y=S$(Z,J).encrypt($);return new Uint8Array([...J,...Y])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return S$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=tZ(Z),Q=F0(J),Y;try{let N=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!0,["sign"]);Y=await globalThis.crypto.subtle.exportKey("jwk",N)}finally{J.fill(0),new Uint8Array(Q).fill(0)}if(typeof Y.x!=="string")throw Error("Ed25519 JWK missing x");let X=Y.x;Y.d=void 0;let G=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:X},{name:"Ed25519"},!0,["verify"]),W=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",G));this.verifyKeys.set($0(W),G);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=tZ(Z),Q=F0(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",F0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=$J($),Q=await this.importSignKey(Z),Y=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,F0(J));return new Uint8Array(Y)}async checkSigEd25519($,Z,J){let Q=$J(Z);try{let Y=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},Y,F0($),F0(Q))}catch{return!1}}async blake3($){return bZ($)}async genX25519(){let $=await n0(32);$[0]&=248,$[31]&=127,$[31]|=64;let[Z,J]=rZ($);if(J!==0||Z===void 0)throw $.fill(0),Error("X25519 scalar brand failed");let Q=sZ(Z),Y=eZ(Z),X=F0(Y);try{let G=await globalThis.crypto.subtle.importKey("pkcs8",X,{name:"X25519"},!0,["deriveBits"]),W=await globalThis.crypto.subtle.exportKey("jwk",G);if(typeof W.x!=="string")throw Error("X25519 JWK missing x");let q=iZ(W.x);if(W.d=void 0,!W$(q,Q))throw Error("X25519 WebCrypto pub != RFC 7748");return{priv:Z,pub:Q}}catch(G){throw Z.fill(0),G}finally{Y.fill(0),new Uint8Array(X).fill(0)}}async x25519Shared($,Z){let J=eZ($),Q=F0(J);try{let Y=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"X25519"},!1,["deriveBits"]),X=await globalThis.crypto.subtle.importKey("raw",F0(Z),{name:"X25519"},!1,[]),G=await globalThis.crypto.subtle.deriveBits({name:"X25519",public:X},Y,256);return new Uint8Array(G)}finally{J.fill(0),new Uint8Array(Q).fill(0)}}}var qY=new w0,l0=qY;function NY($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return V(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 V(26);return O(new Uint8Array(Z))}function zY($,Z=0){let J=0n,Q=0,Y=Z;while(!0){if(Y>=$.length)return V(14);let X=$[Y++];if(X===void 0)return V(14);if(J|=BigInt(X&127)<<BigInt(Q),(X&128)===0){if(Y-Z>8)return V(26);return O({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:Y-Z})}if(Q+=7,Q>=56)return V(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 V(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 V(Z);return O(new Date($))}readVarInt(){let[$,Z]=zY(this.data,this.pos);if(Z!==0)return V(Z);this.pos+=$.bytesRead;let J=$.value;return O(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return V(Z);let[J,Q]=this.readBytes($);if(Q!==0)return V(Q);let Y=new TextDecoder().decode(J);return O(Y)}readBytes($){if($<0)return V(10);if(this.pos+$>this.data.length)return V(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,O(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return V(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return V(Q);Z.push(J)}return O(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return V(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]=NY($);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,Y)=>Q+Y.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 a0={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 V(J);let[Q,Y]=$.readDate();if(Y!==0)return V(Y);return O({id:Z,ts:Q})}};function ZJ($){let Z=new m,J=Z.writeStruct(a0,$);if(J!==0)return V(J);let Q=Z.result();return O(Q)}var d$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let Y=$.writeVarInt(Z.ctr);if(Y!==0)return Y;let X=$.writeVarInt(Z.len);if(X!==0)return X;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return V(J);let Q=new v(Z),[,Y]=a0.decode(Q);if(Y!==0)return V(Y);let[X,G]=$.readVarInt();if(G!==0)return V(G);let[W,q]=$.readVarInt();if(q!==0)return V(q);let[N,z]=$.readVarInt();if(z!==0)return V(z);let M;if(N>0){let[F,K]=$.readBytes(dZ);if(K!==0)return V(K);M=F}return O({eid:Z,off:X,ctr:W,len:N,hsh:M})}};function JJ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function QJ($,Z,J,Q){let Y;if($.bod&&$.len>0)Y=await J.blake3($.bod);let X=new m,G=d$.encode(X,{...$,hsh:Y});if(G!==0)return V(G);let W=X.result(),q=await Z.kdmFor(W),N=Q.deriveCipher(q,"encrypt"),z=await N.encrypt(W),M=$.bod?await N.encrypt($.bod):new Uint8Array(0),F=await Z.sign(z);return O({sig:F,kdm:q,headCph:z,bodyCph:M})}async function YJ($,Z,J,Q,Y){let X=new v($),[G,W]=d$.decode(X);if(W!==0)return V(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return V(20)}let N=G.hsh&&q===void 0,z=G.hsh===void 0&&q!==void 0;if(N||z)return V(19);if(G.hsh&&q){let F=await Q.blake3(q);if(!W$(F,G.hsh))return V(19)}let M=Y??await Q.blake3($);return O({msgHead:G,bod:q,headHash:M})}async function u$($,Z){let J=new m,Q=J.writeDate(Z);if(Q!==0)return V(Q);let Y=J.result(),X=await $.sign(Y);return O({pubKey:$.publicKey,sig:X,timestamp:Z})}async function J0($,Z,J){let Q=J.now().getTime(),Y=$.timestamp.getTime();if(Math.abs(Q-Y)>uZ)return 4;let G=new m;G.writeDate($.timestamp);let W=G.result();if(!await Z.checkSigEd25519($.sig,W,$.pubKey))return 3;return 0}class b0{now(){return new Date}}function XJ($,Z,J,Q){let Y=Z.getTime()-$.getTime(),X=J.getTime()-Q.getTime();return(Y+X)/2}var s0={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 V(J);let Q;if(Z>0){let[Y,X]=$.readVarInt();if(X!==0)return V(X);Q=Y}return O({quota:Z,usage:Q})}};var h0={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 Y=$.writeVarInt(Z.subscription.term);if(Y!==0)return Y;let X=$.writeVarInt(Z.subscription.elapsed);if(X!==0)return X;let G=$.writeStruct(s0,Z.subscription.stat);if(G!==0)return G;let W=$.writeStruct(s0,Z.subscription.dyn);if(W!==0)return W;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return V(J);let Q=Z[0],[Y,X]=$.readDate();if(X!==0)return V(X);let[G,W]=$.readDate();if(W!==0)return V(W);let[q,N]=$.readVarInt();if(N!==0)return V(N);let[z,M]=$.readVarInt();if(M!==0)return V(M);let[F,K]=$.readStruct(s0);if(K!==0)return V(K);let[I,R]=$.readStruct(s0);if(R!==0)return V(R);return O({status:Q,timeRcvd:Y,timeSent:G,subscription:{term:q,elapsed:z,stat:F,dyn:I}})}};var n$={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 V(J);let[Q,Y]=$.readVarInt();if(Y!==0)return V(Y);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(pZ);if(J!==0)return V(J);let[Q,Y]=$.readBytes(v0);if(Y!==0)return V(Y);let[X,G]=$.readDate();if(G!==0)return V(G);return O({pubKey:Z,sig:Q,timestamp:X})}};var GJ={async encodeReq($,Z,J,Q,Y){let X=Y.writeStruct(o,J);if(X!==0)return X;for(let G of Q)Y.writeVarInt(G);return 0},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X}=$,[G,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(G,Y,Q);if(q!==0)return q;let{pubKey:N}=G,[z,M]=await X.hasUser(N);if(M!==0)return M;if(!z)return 5;let[F,K]=Z.readVarInt();if(K!==0)return K;if(!Z.done())return 8;let[I,R]=await X.listHeads(N,F);if(R!==0)return R;return J.writeStructs(n$,I)},decodeResp($){return $.readStructs(n$)}};var c$={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 V(J);let[Q,Y]=$.readVarBytes();if(Y!==0)return V(Y);return O({seq:Z,bodyCph:Q})}};var VJ={async encodeReq($,Z,J,Q,Y){let X=Y.writeStruct(o,J);if(X!==0)return X;for(let G of Q){let W=Y.writeVarInt(G);if(W!==0)return W}return 0},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X}=$,[G,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(G,Y,Q);if(q!==0)return q;let{pubKey:N}=G,[z,M]=await X.hasUser(N);if(M!==0)return M;if(!z)return 5;let F=[];while(!Z.done()){let[R,P]=Z.readVarInt();if(P!==0)return P;F.push(R)}console.info(`PULL: ${F.length} bags`);let[K,I]=await X.getBodies(N,F);if(I!==0)return I;if(!K)return 17;for(let{seq:R,bodyCph:P}of K){let C={seq:R,bodyCph:P},D=J.writeStruct(c$,C);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(c$)}};var r$={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(v0);if(J!==0)return V(J);let[Q,Y]=$.readBytes(y0);if(Y!==0)return V(Y);let[X,G]=$.readVarBytes();if(G!==0)return V(G);let[W,q]=$.readVarBytes();if(q!==0)return V(q);return O({sig:Z,kdm:Q,headCph:X,bodyCph:W})}};var o$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let Y=Z.bodyCph?Z.bodyCph.length:0,X=$.writeVarInt(Y);if(X!==0)return X;if(Y>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return V(J);let[Q,Y]=$.readVarBytes();if(Y!==0)return V(Y);let[X,G]=$.readVarInt();if(G!==0)return V(G);let W;if(X>0){let[q,N]=$.readBytes(X);if(N!==0)return V(N);W=q}return O({seq:Z,headCph:Q,bodyCph:W})}};var i0={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(v0);if(J!==0)return V(J);let[Q,Y]=$.readBytes(y0);if(Y!==0)return V(Y);let[X,G]=$.readVarBytes();if(G!==0)return V(G);return O({sig:Z,kdm:Q,headCph:X})}};var N$={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 V(J);let[Q,Y]=$.readBytes(1);if(Y!==0)return V(Y);let X=Q[0];if(X!==0)return O({idx:Z,status:X});let[G,W]=$.readVarInt();if(W!==0)return V(W);return O({idx:Z,status:X,seq:G})}};var WJ={async encodeReq($,Z,J,Q,Y){let X=Y.writeStruct(o,J);if(X!==0)return X;let G=Y.writeStructs(r$,Q);if(G!==0)return G;return 0},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X,notifier:G}=$,[W,q]=Z.readStruct(o);if(q!==0)return q;let N=await J0(W,Y,Q);if(N!==0)return N;let{pubKey:z}=W,[M,F]=await X.hasUser(z);if(F!==0)return F;if(!M)return 5;let[K,I]=Z.readStructs(r$);if(I!==0)return I;console.info(`PUSH: ${K.length} bags`);let R=[],P=[];for(let w=0;w<K.length;w++){let L=K[w];if(!await JJ(L,z,Y)){let d={idx:w,status:3},_=J.writeStruct(N$,d);if(_!==0)return _;continue}R.push(w),P.push(L)}let[C,D]=await X.setBags(z,P);if(D!==0)return D;if(!C||C.length!==P.length)return 17;let j=[];for(let w=0;w<P.length;w++){let L=P[w],B=R[w],d=C[w],_=new m,g=_.writeStruct(i0,L);if(g!==0)return g;let S=_.result(),x={seq:d,headCph:S};if(K.length===1&&L.bodyCph.length<=nZ)x.bodyCph=L.bodyCph;j.push(x);let f={idx:B,status:0,seq:d},H=J.writeStruct(N$,f);if(H!==0)return H}if(j.length>0){let w=new m,L=w.writeStructs(o$,j);if(L!==0)return L;let B=w.result();await Promise.resolve(G.push(z,B))}return 0},decodeResp($){return $.readStructs(N$)}};var qJ={async encodeReq($,Z,J,Q,Y){return Y.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X}=$,[G,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(G,Y,Q);if(q!==0)return q;let{pubKey:N}=G;if(!Z.done())return 8;let[z,M]=await X.addUser(N);if(M!==0)return M;return 0},decodeResp($){return O(void 0)}};class a${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:Y}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let X=new m;X.writeStruct(o,$);let G=X.result(),W=$0(G);return Y.searchParams.set("t",W),this.websocket=new WebSocket(Y),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Q()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(q)=>{let N=new Uint8Array(q.data);Z(N)},this.websocket.onerror=(q)=>{console.log(`ERROR: ${JSON.stringify(q)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var n={user:{path:"/user",endpoint:qJ,name:0},push:{path:"/push",endpoint:WJ,name:2},peek:{path:"/peek",endpoint:GJ,name:1},pull:{path:"/pull",endpoint:VJ,name:3}},MY={0:n.user,2:n.push,1:n.peek,3:n.pull},NJ={[n.user.path]:n.user,[n.push.path]:n.push,[n.peek.path]:n.peek,[n.pull.path]:n.pull};class zJ{url;listener;constructor($){this.url=$;this.listener=new a$($)}async call($,Z){let{path:J}=MY[$],Q=new URL(J,this.url);try{return await FY(Q,Z)}catch{return V(25)}}}var s$=($)=>{return new zJ($.handle)};function p0($){let Z=new m;if(Z.writeStruct(h0,$)!==0)return new Response(null,{status:500});return t$(Z)}function t$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var OY={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function e$($){return new Response($.body,{headers:{...$.headers,...OY},status:$.status,statusText:$.statusText})}async function FY($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return V(24);let Q=await v.fromResponse(J);return O(Q)}class z${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,Y,X){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=Y;this.updateHostMeta=X}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:Y,name:X}=$,G=await this.identity(),W=J.now(),[q,N]=await u$(G,W);if(N!==0)return V(N);let z=new m,M=await Y.encodeReq(this,G,q,Z,z);if(M!==0)return V(M);let F=J.now(),[K,I]=await Q.call(X,z),R=J.now();if(I!==0)return V(I);let[P,C]=K.readStruct(h0);if(C!==0)return V(C);if(P.status!==0)return V(P.status);let j={clockOffset:XJ(F,P.timeRcvd,P.timeSent,R),subscription:P.subscription},w=await this.updateHostMeta(j);if(w!==0)return V(w);return Y.decodeResp(K)}identity=()=>{let{host:$,enclave:Z}=this;return Z.deriveIdentity($.label,$.idx??0)};seal=async($)=>{let{crypto:Z,enclave:J}=this,Q=await this.identity();return QJ($,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:Y}=this,{listener:X}=Y,G=await this.identity(),W=Q.now(),[q,N]=await u$(G,W);if(N!==0)return N;return await X.connect(q,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var G8=Symbol("MasterSeed"),V8=Symbol("SealedMasterKey"),V0=32,MJ=24+V0+16;function t($){if($.byteLength!==V0)return V(10);return O($)}function M$($){if($.byteLength!==MJ)return V(10);return O($)}var C0={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 V(J);let[Q,Y]=$.readVarString();if(Y!==0)return V(Y);let[X,G]=$.readVarInt();if(G!==0)return V(G);return O({handle:Z,label:Q,idx:X})}};var O$=1,$Z={encode($,Z){if(Z.v!==O$)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 Y=$.writeVarInt(Z.hosts.length);if(Y!==0)return Y;for(let X of Z.hosts){let G=$.writeStruct(C0,X);if(G!==0)return G}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return V(J);if(Z!==O$)return V(14);let[Q,Y]=$.readBytes(V0);if(Y!==0)return V(Y);if(Q===void 0)return V(14);let[X,G]=t(Q);if(G!==0)return V(G);if(X===void 0)return V(14);let[W,q]=$.readVarInt();if(q!==0)return V(q);if(W===void 0||W<0)return V(10);let N=[];for(let z=0;z<W;z++){let[M,F]=$.readStruct(C0);if(F!==0)return V(F);if(M===void 0)return V(14);N.push(M)}return O({v:O$,masterSeed:X,hosts:N})}};function OJ($,Z){let[J,Q]=t($);if(Q!==0)return V(Q);if(J===void 0)return V(10);let[Y,X]=t(J.slice());if(X!==0)return V(X);if(Y===void 0)return V(10);return O({v:O$,masterSeed:Y,hosts:Z.map((G)=>({handle:G.handle,label:G.label,idx:G.idx??0}))})}var F$={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 Y of Z.hosts){let X=$.writeStruct(C0,Y);if(X!==0)return X}return 0},decode($){let[Z,J]=$.readBytes(V0);if(J!==0)return V(J);if(Z===void 0)return V(14);let[Q,Y]=t(Z);if(Y!==0)return V(Y);if(Q===void 0)return V(14);let[X,G]=$.readVarInt();if(G!==0)return V(G);if(X===void 0||X<0)return V(10);let W=[];for(let q=0;q<X;q++){let[N,z]=$.readStruct(C0);if(z!==0)return V(z);if(N===void 0)return V(14);W.push(N)}return O({masterSeed:Q,hosts:W})}};var HY=new TextEncoder().encode("diplomatic.qrpair.v1"),t0=32,KY=t0+24+16,IY=32,_8=Symbol("DHKEReq"),B8=Symbol("DHKEResp");function FJ($){if($.byteLength!==t0)return V(10);return O($)}function HJ($){if($.byteLength<KY)return V(10);return O($)}var H$=new w0;async function ZZ($,Z,J,Q){let Y;try{Y=await H$.x25519Shared($,Z)}catch{return V(29)}try{if(Y.byteLength!==t0||Y.every((W)=>W===0))return V(10);let X=G0(Y,HY),G=G0(X,G0(J,Q));try{let W=await H$.blake3(G);return O(W.slice(0,IY))}finally{X.fill(0),G.fill(0)}}finally{Y.fill(0)}}class K${#$;#Z;constructor($,Z){this.#$=$,this.#Z=Z}static async create(){let $;try{let Z=await H$.genX25519();$=Z.priv;let[J,Q]=FJ(Z.pub);if(Q!==0)return V(Q);if(J===void 0)return V(10);let Y=new K$($,J);return $=void 0,O(Y)}catch{return V(29)}finally{$?.fill(0)}}wipe(){this.#$.fill(0)}get dhkeReq(){let[$,Z]=FJ(this.#Z.slice());if($===void 0)throw Error(`dhkeReq ${Z}`);return $}async finish($){let Z=$.subarray(0,t0),J=$.subarray(t0),[Q,Y]=await ZZ(this.#$,Z,this.#Z,Z);if(Y!==0)return V(Y);if(Q===void 0)return V(12);let X;try{try{X=await H$.decryptXSalsa20Poly1305Combined(J,Q)}catch{return V(20)}let G=new v(X),[W,q]=G.readStruct(F$);if(q!==0)return V(q);if(W===void 0)return V(14);try{let[N,z]=Q0.fromBytes(W.masterSeed);if(z!==0)return V(z);if(N===void 0)return V(12);return this.wipe(),O({enclave:N,hosts:W.hosts.map((M)=>({...M}))})}finally{W.masterSeed.fill(0)}}finally{Q.fill(0),X?.fill(0)}}}function H0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var T0=32,RY=-7,UY=-8,PY=-257,I$=[{type:"public-key",alg:RY},{type:"public-key",alg:UY},{type:"public-key",alg:PY}];function wY($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function R0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z.buffer}function IJ($){if($ instanceof ArrayBuffer)return new Uint8Array($).slice();return new Uint8Array($.buffer,$.byteOffset,$.byteLength).slice()}function D0($){if($?.rpId!==void 0)return O($.rpId);if(typeof location>"u")return V(9);return O(wY(location.hostname))}var KJ="";function A0($){if($ instanceof Error){KJ=$.message===""?$.name:`${$.name}: ${$.message}`;return}KJ=String($)}function j0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function L0($){if($===null||$.type!=="public-key"||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return V(27);return O($)}async function UJ($){let Z=j0();if(Z!==0)return V(Z);let[J,Q]=D0($);if(Q!==0)return V(Q);if(J===void 0)return V(9);let Y=$?.userName??"diplomatic-seed",X={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)X.authenticatorAttachment=$.authenticatorAttachment;let G={largeBlob:{support:"required"}},W;try{W=await navigator.credentials.create({publicKey:{challenge:H0(T0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:H0(16),name:Y,displayName:Y},pubKeyCredParams:I$,authenticatorSelection:X,extensions:G,...$?.hints!==void 0?{hints:$.hints}:{}}})}catch(M){return A0(M),V(30)}let[q,N]=L0(W);if(N!==0)return V(N);if(q===void 0)return V(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return V(30);return O(new Uint8Array(q.rawId))}async function JZ($,Z,J){let Q=j0();if(Q!==0)return Q;let[Y,X]=D0(J);if(X!==0)return X;if(Y===void 0)return 9;let G={largeBlob:{write:R0(Z)}},W;try{W=await navigator.credentials.get({publicKey:{challenge:H0(T0),rpId:Y,allowCredentials:[{type:"public-key",id:R0($)}],userVerification:"required",extensions:G,...J?.hints!==void 0?{hints:J.hints}:{}}})}catch(M){return A0(M),30}let[q,N]=L0(W);if(N!==0)return N;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 30;return 0}async function RJ($,Z,J,Q){let Y={challenge:H0(T0),rpId:$,userVerification:"required"};if(Z?.hints!==void 0)Y.hints=Z.hints;if(J!==void 0)Y.allowCredentials=[{type:"public-key",id:R0(J)}];if(Q!==void 0)Y.extensions=Q;let X;try{X=await navigator.credentials.get({publicKey:Y})}catch(q){return A0(q),V(30)}let[G,W]=L0(X);if(W!==0)return V(W);if(G===void 0)return V(27);return O(G)}async function PJ($,Z){let J=j0();if(J!==0)return V(J);let[Q,Y]=D0(Z);if(Y!==0)return V(Y);if(Q===void 0)return V(9);let X=$;if(X===void 0){let[M,F]=await RJ(Q,Z);if(F!==0)return V(F);if(M===void 0)return V(27);X=new Uint8Array(M.rawId)}let[G,W]=await RJ(Q,Z,X,{largeBlob:{read:!0}});if(W!==0)return V(W);if(G===void 0)return V(27);let N=G.getClientExtensionResults().largeBlob;if(N===void 0||N.blob===void 0)return V(7);let z=IJ(N.blob);if(z.byteLength===0)return V(7);return O({blob:z,credId:new Uint8Array(G.rawId)})}var YZ=new TextEncoder().encode("diplomatic.prf.v1"),QZ=32;async function wJ($){let Z=j0();if(Z!==0)return V(Z);let[J,Q]=D0($);if(Q!==0)return V(Q);if(J===void 0)return V(9);let Y=$?.userName??"diplomatic-prf",X={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)X.authenticatorAttachment=$.authenticatorAttachment;let G=$?.salt!==void 0?R0($.salt):void 0,W=G===void 0?{}:{eval:{first:G}},q;try{q=await navigator.credentials.create({publicKey:{challenge:H0(T0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:H0(16),name:Y,displayName:Y},pubKeyCredParams:I$,authenticatorSelection:X,extensions:{prf:W},...$?.hints!==void 0?{hints:$.hints}:{}}})}catch(F){return A0(F),V(30)}let[N,z]=L0(q);if(z!==0)return V(z);if(N===void 0)return V(27);let M=N.getClientExtensionResults();return O({credId:new Uint8Array(N.rawId),prfEnabled:M.prf?.enabled===!0})}async function XZ($){let Z=j0();if(Z!==0)return V(Z);let[J,Q]=D0($);if(Q!==0)return V(Q);if(J===void 0)return V(9);let Y=$?.salt??YZ,X=R0(Y),G={challenge:H0(T0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:X}}}};if($?.hints!==void 0)G.hints=$.hints;if($?.credId!==void 0)G.allowCredentials=[{type:"public-key",id:R0($.credId)}];let W;try{W=await navigator.credentials.get({publicKey:G})}catch(I){return A0(I),V(30)}let[q,N]=L0(W);if(N!==0)return V(N);if(q===void 0)return V(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return V(7);let M=z.first,F=M instanceof ArrayBuffer?new Uint8Array(M):new Uint8Array(M.buffer,M.byteOffset,M.byteLength),K=F.byteLength>=QZ?F.slice(0,QZ):F;if(K.byteLength!==QZ)return V(27);return O({prf:K,credId:new Uint8Array(q.rawId)})}var R$="";var P$=typeof globalThis.Worker==="function"?globalThis.Worker:void 0,GZ=P$===void 0?void 0:P$.prototype.postMessage,U$;function TY(){if(typeof R$!=="string"||R$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(R$)}function DY(){if(U$!==void 0)return U$;let $=new Blob([TY()],{type:"text/javascript"});return U$=URL.createObjectURL($),U$}function CJ(){if(P$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new P$(DY(),{type:"module"})}function TJ($,Z,J){if(GZ===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot post to sync worker");if(J!==void 0&&J.length>0)GZ.call($,Z,{transfer:J});else GZ.call($,Z)}var AY=new TextEncoder().encode("diplomatic.wrap.v1"),jY=32,LY=16,Z0=new w0;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 V(J);if(Z===void 0)return V(10);let[Q,Y]=t(Z.slice());if(Y!==0)return V(Y);if(Q===void 0)return V(10);return O(new Q0(Q))}async sealWithPasskey($){let Z=$?.salt??YZ,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[X,G]=await wJ({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf",authenticatorAttachment:$?.authenticatorAttachment,hints:$?.hints,salt:Z});if(G!==0)return V(G);if(X===void 0)return V(30);if(!X.prfEnabled)return V(30);J=X.credId}let[Q,Y]=await XZ({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z,hints:$?.hints});if(Y!==0)return V(Y);if(Q===void 0)return V(7);try{let[X,G]=await this.#Y(Q.prf);if(G!==0)return V(G);if(X===void 0)return V(12);return O({sealedMaster:X,salt:Z.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async unsealWithPasskey($,Z){let[J,Q]=await XZ({rpId:Z.rpId,rpName:Z.rpName,hints:Z.hints,credId:Z.credId,salt:Z.salt});if(Q!==0)return V(Q);if(J===void 0)return V(7);try{let[Y,X]=await Q0.#X($,J.prf);if(X!==0)return V(X);if(Y===void 0)return V(12);return O({enclave:Y,credId:J.credId.slice()})}finally{J.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[X,G]=await UJ(Z);if(G!==0)return V(G);if(X===void 0)return V(30);J=X}let[Q,Y]=this.#G($);if(Y!==0)return V(Y);if(Q===void 0)return V(12);try{let X=await JZ(J,Q,Z);if(X!==0)return V(X);return O(J)}finally{Q.fill(0)}}static async fromLargeBlob($){let[Z,J]=await PJ($?.credId,$);if(J!==0)return V(J);if(Z===void 0)return V(7);try{return Q0.#V(Z.blob,Z.credId)}finally{Z.blob.fill(0)}}static async clearLargeBlob($,Z){return JZ($,new Uint8Array(V0),Z)}static pairRequest(){return K$.create()}async pairAccept($,Z){let J;try{J=await Z0.genX25519()}catch{return V(29)}try{let[Q,Y]=await ZZ(J.priv,$,$,J.pub);if(Y!==0)return V(Y);if(Q===void 0)return V(12);try{let[X,G]=this.#Z(Z);if(G!==0)return V(G);if(X===void 0)return V(12);try{let W=await Z0.encryptXSalsa20Poly1305Combined(X,Q);return HJ(G0(J.pub,W))}catch{return V(12)}finally{X.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),V(Q);if(J===void 0)return Z.fill(0),V(10);try{let Y={masterSeed:J,hosts:$.map((G)=>({handle:G.handle,label:G.label,idx:G.idx??0}))},X=new m;try{let G=X.writeStruct(F$,Y);if(G!==0)return V(G);return O(X.result())}finally{X.wipe()}}finally{J.fill(0)}}spawnSyncWorker($){let Z=CJ(),J=this.#$.slice();return TJ(Z,{id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(G)=>this.#W(J,G),Y=(G)=>this.#q(J,G);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:Y}),both:Object.freeze({encrypt:Q,decrypt:Y})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,Y=await this.#Q(J,Q),X=Y.publicKey;return Y.privateKey.fill(0),Object.freeze({publicKey:X,sign:(G)=>this.#z(J,Q,G),kdmFor:(G)=>this.#M(J,Q,G)})}async#Y($){let[Z,J]=await DJ(Z0,$);if(J!==0)return V(J);if(Z===void 0)return V(12);try{let Q=await Z0.encryptXSalsa20Poly1305Combined(this.#$,Z);return M$(Q)}catch{return V(12)}finally{Z.fill(0)}}static async#X($,Z){let[,J]=M$($);if(J!==0)return V(J);let[Q,Y]=await DJ(Z0,Z);if(Y!==0)return V(Y);if(Q===void 0)return V(12);let X;try{try{X=await Z0.decryptXSalsa20Poly1305Combined($,Q)}catch{return V(20)}return Q0.fromBytes(X)}finally{Q.fill(0),X?.fill(0)}}#G($){let Z=this.#$.slice(),[J,Q]=t(Z);if(Q!==0)return Z.fill(0),V(Q);if(J===void 0)return Z.fill(0),V(10);try{let[Y,X]=OJ(J,$);if(X!==0)return V(X);if(Y===void 0)return V(12);try{let G=new m,W=G.writeStruct($Z,Y);if(W!==0)return V(W);return O(G.result())}finally{Y.masterSeed.fill(0)}}finally{J.fill(0)}}static#V($,Z){if($.byteLength===0||$.every((X)=>X===0))return V(22);if($.byteLength===V0){if($.every((W)=>W===0))return V(22);let[X,G]=Q0.fromBytes($);if(G!==0)return V(G);if(X===void 0)return V(12);return O({enclave:X,hosts:[],credId:Z})}let J=new v($),[Q,Y]=J.readStruct($Z);if(Y!==0)return V(Y);if(Q===void 0)return V(14);try{if(Q.masterSeed.every((W)=>W===0))return V(22);let[X,G]=Q0.fromBytes(Q.masterSeed);if(G!==0)return V(G);if(X===void 0)return V(12);return O({enclave:X,hosts:Q.hosts.map((W)=>({...W})),credId:Z})}finally{Q.masterSeed.fill(0)}}async#W($,Z){let J=await this.#J($);try{return await Z0.encryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#q($,Z){let J=await this.#J($);try{return await Z0.decryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#J($){return Z0.blake3(G0(this.#$,$))}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(G0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);try{return await Z0.deriveEd25519KeyPair(J)}finally{J.fill(0)}}async#z($,Z,J){let Q=await this.#Q($,Z);try{return await Z0.signEd25519(J,Q.privateKey)}finally{Q.privateKey.fill(0)}}async#M($,Z,J){let Q=await this.#Q($,Z),Y=G0(Q.privateKey,J);Q.privateKey.fill(0);try{return(await Z0.blake3(Y)).slice(0,y0)}finally{Y.fill(0)}}}async function DJ($,Z,J=AY){if(Z.byteLength<LY)return V(10);let Q=await $.blake3(G0(Z,J));return O(Q.slice(0,jY))}class VZ{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 Y of Q)Y(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function AJ($,Z,J,Q=0){let Y=Z.now(),X=new m,G=X.writeVarString($);if(G!==0)return V(G);let q={id:X.result(),ts:new Date(0)},[N,z]=ZJ(q);if(z!==0)return V(z);let M=Y.getTime()-q.ts.getTime();return O({eid:N,off:M,ctr:Q,len:J.length,bod:J})}class EY{singletonType;latest;latestOff=-1;emitter=new VZ;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new v(Z.eid),[Q,Y]=J.readStruct(a0);if(Y!==0)continue;let X=new m;X.writeVarString(this.singletonType);let G=X.result();if(Q.id.length===G.length&&Q.id.every((W,q)=>W===G[q])){if(this.latest===void 0||Z.off>this.latestOff)this.latestOff=Z.off,this.latest=Z.bod,this.emitter.emit(this.singletonType,null)}}return $.map(()=>0)}clear=async()=>{return this.latest=void 0,this.latestOff=-1,this.emitter.emit(this.singletonType,null),0};notify=($)=>{for(let Z of $)if(Z===this.singletonType)this.emitter.emit(this.singletonType,null)};refresh=async($)=>{this.notify([this.singletonType])};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function jJ($,Z,J,Q){let Y=new v($.headCph),[X,G]=Y.readStruct(i0);if(G!==0)return V(G);let{sig:W,kdm:q,headCph:N}=X;if(!await Q.checkSigEd25519(W,N,Z))return V(3);let M=J.deriveCipher(q,"decrypt"),F;try{F=await M.decrypt(N)}catch{return V(20)}return O({kdm:q,headEnc:F})}var u0=bQ(LQ(),1),cX={encode:u0.encode,decode:u0.decode,decodeAsync:u0.decodeAsync},rX=cX;import{Database as oX}from"bun:sqlite";var QN=Symbol("EntityID");var YN=Symbol("DerivationSeed"),XN=Symbol("PublicKey"),GN=Symbol("PrivateKey"),VN=Symbol("HostSpecificKeyPair"),WN=Symbol("Hash"),I0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function aX($="diplomatic.db"){let Z=new oX($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
|
|
1
|
+
var gQ=Object.create;var{getPrototypeOf:xQ,defineProperty:TZ,getOwnPropertyNames:SQ}=Object;var fQ=Object.prototype.hasOwnProperty;function vQ($){return this[$]}var yQ,lQ,bQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var Y=Z?yQ??=new WeakMap:lQ??=new WeakMap,X=Y.get($);if(X)return X}J=$!=null?gQ(xQ($)):{};let G=Z||!$||!$.__esModule?TZ(J,"default",{value:$,enumerable:!0}):J;for(let W of SQ($))if(!fQ.call(G,W))TZ(G,W,{get:vQ.bind($,W),enumerable:!0});if(Q)Y.set($,G);return G};var r=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var w$=r((BJ)=>{Object.defineProperty(BJ,"__esModule",{value:!0});BJ.utf8Count=mY;BJ.utf8EncodeJs=LJ;BJ.utf8EncodeTE=EJ;BJ.utf8Encode=kY;BJ.utf8DecodeJs=mJ;BJ.utf8DecodeTD=_J;BJ.utf8Decode=fY;function mY($){let Z=$.length,J=0,Q=0;while(Q<Z){let Y=$.charCodeAt(Q++);if((Y&4294967168)===0){J++;continue}else if((Y&4294965248)===0)J+=2;else{if(Y>=55296&&Y<=56319){if(Q<Z){let X=$.charCodeAt(Q);if((X&64512)===56320)++Q,Y=((Y&1023)<<10)+(X&1023)+65536}}if((Y&4294901760)===0)J+=3;else J+=4}}return J}function LJ($,Z,J){let Q=$.length,Y=J,X=0;while(X<Q){let G=$.charCodeAt(X++);if((G&4294967168)===0){Z[Y++]=G;continue}else if((G&4294965248)===0)Z[Y++]=G>>6&31|192;else{if(G>=55296&&G<=56319){if(X<Q){let W=$.charCodeAt(X);if((W&64512)===56320)++X,G=((G&1023)<<10)+(W&1023)+65536}}if((G&4294901760)===0)Z[Y++]=G>>12&15|224,Z[Y++]=G>>6&63|128;else Z[Y++]=G>>18&7|240,Z[Y++]=G>>12&63|128,Z[Y++]=G>>6&63|128}Z[Y++]=G&63|128}}var _Y=new TextEncoder,BY=50;function EJ($,Z,J){_Y.encodeInto($,Z.subarray(J))}function kY($,Z,J){if($.length>BY)EJ($,Z,J);else LJ($,Z,J)}var gY=4096;function mJ($,Z,J){let Q=Z,Y=Q+J,X=[],G="";while(Q<Y){let W=$[Q++];if((W&128)===0)X.push(W);else if((W&224)===192){let q=$[Q++]&63;X.push((W&31)<<6|q)}else if((W&240)===224){let q=$[Q++]&63,N=$[Q++]&63;X.push((W&31)<<12|q<<6|N)}else if((W&248)===240){let q=$[Q++]&63,N=$[Q++]&63,z=$[Q++]&63,M=(W&7)<<18|q<<12|N<<6|z;if(M>65535)M-=65536,X.push(M>>>10&1023|55296),M=56320|M&1023;X.push(M)}else X.push(W);if(X.length>=gY)G+=String.fromCharCode(...X),X.length=0}if(X.length>0)G+=String.fromCharCode(...X);return G}var xY=new TextDecoder,SY=200;function _J($,Z,J){let Q=$.subarray(Z,Z+J);return xY.decode(Q)}function fY($,Z,J){if(J>SY)return _J($,Z,J);else return mJ($,Z,J)}});var qZ=r((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.ExtData=void 0;class kJ{type;data;constructor($,Z){this.type=$,this.data=Z}}gJ.ExtData=kJ});var T$=r((SJ)=>{Object.defineProperty(SJ,"__esModule",{value:!0});SJ.DecodeError=void 0;class C$ extends Error{constructor($){super($);let Z=Object.create(C$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:C$.name})}}SJ.DecodeError=C$});var D$=r((vJ)=>{Object.defineProperty(vJ,"__esModule",{value:!0});vJ.UINT32_MAX=void 0;vJ.setUint64=uY;vJ.setInt64=dY;vJ.getInt64=nY;vJ.getUint64=cY;vJ.UINT32_MAX=4294967295;function uY($,Z,J){let Q=J/4294967296,Y=J;$.setUint32(Z,Q),$.setUint32(Z+4,Y)}function dY($,Z,J){let Q=Math.floor(J/4294967296),Y=J;$.setUint32(Z,Q),$.setUint32(Z+4,Y)}function nY($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function cY($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var NZ=r((dJ)=>{Object.defineProperty(dJ,"__esModule",{value:!0});dJ.timestampExtension=dJ.EXT_TIMESTAMP=void 0;dJ.encodeTimeSpecToTimestamp=bJ;dJ.encodeDateToTimeSpec=hJ;dJ.encodeTimestampExtension=iJ;dJ.decodeTimestampToTimeSpec=pJ;dJ.decodeTimestampExtension=uJ;var tY=T$(),lJ=D$();dJ.EXT_TIMESTAMP=-1;var eY=4294967295,$X=17179869183;function bJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=$X)if(Z===0&&$<=eY){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,Y=new Uint8Array(8),X=new DataView(Y.buffer);return X.setUint32(0,Z<<2|J&3),X.setUint32(4,Q),Y}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,lJ.setInt64)(Q,4,$),J}}function hJ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,Y=Math.floor(Q/1e9);return{sec:J+Y,nsec:Q-Y*1e9}}function iJ($){if($ instanceof Date){let Z=hJ($);return bJ(Z)}else return null}function pJ($){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),Y=(J&3)*4294967296+Q,X=J>>>2;return{sec:Y,nsec:X}}case 12:{let J=(0,lJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new tY.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function uJ($){let Z=pJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}dJ.timestampExtension={type:dJ.EXT_TIMESTAMP,encode:iJ,decode:uJ}});var j$=r((rJ)=>{Object.defineProperty(rJ,"__esModule",{value:!0});rJ.ExtensionCodec=void 0;var A$=qZ(),GX=NZ();class zZ{static defaultCodec=new zZ;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(GX.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 Y=Q($,Z);if(Y!=null){let X=-1-J;return new A$.ExtData(X,Y)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let Y=Q($,Z);if(Y!=null){let X=J;return new A$.ExtData(X,Y)}}}if($ instanceof A$.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 A$.ExtData(Z,$)}}rJ.ExtensionCodec=zZ});var MZ=r((aJ)=>{Object.defineProperty(aJ,"__esModule",{value:!0});aJ.ensureUint8Array=WX;function VX($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function WX($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(VX($))return new Uint8Array($);else return Uint8Array.from($)}});var FZ=r((eJ)=>{Object.defineProperty(eJ,"__esModule",{value:!0});eJ.Encoder=eJ.DEFAULT_INITIAL_BUFFER_SIZE=eJ.DEFAULT_MAX_DEPTH=void 0;var sJ=w$(),NX=j$(),tJ=D$(),zX=MZ();eJ.DEFAULT_MAX_DEPTH=100;eJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class OZ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??NX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??eJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??eJ.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 OZ({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,sJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,sJ.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,zX.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 Y of J){let X=$[Y];if(!(this.ignoreUndefined&&X===void 0))this.encodeString(Y),this.doEncode(X,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),Q=J.length;if(Q>=4294967296)throw Error(`Too large extension object: ${Q}`);this.writeU8(201),this.writeU32(Q),this.writeI8($.type),this.writeU8a(J);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),(0,tJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,tJ.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}}eJ.Encoder=OZ});var YQ=r((QQ)=>{Object.defineProperty(QQ,"__esModule",{value:!0});QQ.encode=OX;var MX=FZ();function OX($,Z){return new MX.Encoder(Z).encodeSharedRef($)}});var GQ=r((XQ)=>{Object.defineProperty(XQ,"__esModule",{value:!0});XQ.prettyByte=HX;function HX($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var NQ=r((WQ)=>{Object.defineProperty(WQ,"__esModule",{value:!0});WQ.CachedKeyDecoder=void 0;var IX=w$(),RX=16,UX=16;class VQ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=RX,Z=UX){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 Y of Q){let X=Y.bytes;for(let G=0;G<J;G++)if(X[G]!==$[Z+G])continue $;return Y.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 Y=(0,IX.utf8DecodeJs)($,Z,J),X=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(X,Y),Y}}WQ.CachedKeyDecoder=VQ});var L$=r((HQ)=>{Object.defineProperty(HQ,"__esModule",{value:!0});HQ.Decoder=void 0;var HZ=GQ(),PX=j$(),E0=D$(),wX=w$(),zQ=MZ(),CX=NQ(),K0=T$(),KZ="array",$$="map_key",OQ="map_value",TX=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new K0.DecodeError("The type of key must be string or number but "+typeof $)};class FQ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=KZ,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=$$,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===KZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===$$||$.type===OQ){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 e0=-1,IZ=new DataView(new ArrayBuffer(0)),DX=new Uint8Array(IZ.buffer);try{IZ.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 MQ=RangeError("Insufficient data"),AX=new CX.CachedKeyDecoder;class RZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=IZ;bytes=DX;headByte=e0;stack=new FQ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??PX.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??E0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??E0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??E0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??E0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??E0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:AX,this.mapKeyConverter=$?.mapKeyConverter??TX}clone(){return new RZ({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=e0,this.stack.reset()}setBuffer($){let Z=(0,zQ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===e0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,zQ.ensureUint8Array)($),Q=new Uint8Array(Z.length+J.length);Q.set(Z),Q.set(J,Z.length),this.setBuffer(Q)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,J;for await(let G of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(G);try{J=this.doDecodeSync(),Z=!0}catch(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:Y,totalPos:X}=this;throw RangeError(`Insufficient data in parsing ${(0,HZ.prettyByte)(Q)} at ${X} (${Y} 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 Y of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(Y),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(X){if(!(X instanceof RangeError))throw X}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let Q=$-128;if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($<160){let Q=$-144;if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else{let Q=$-160;Z=this.decodeString(Q,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let Q=this.lookU8();Z=this.decodeString(Q,1)}else if($===218){let Q=this.lookU16();Z=this.decodeString(Q,2)}else if($===219){let Q=this.lookU32();Z=this.decodeString(Q,4)}else if($===220){let Q=this.readU16();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===221){let Q=this.readU32();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===222){let Q=this.readU16();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===223){let Q=this.readU32();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===196){let Q=this.lookU8();Z=this.decodeBinary(Q,1)}else if($===197){let Q=this.lookU16();Z=this.decodeBinary(Q,2)}else if($===198){let Q=this.lookU32();Z=this.decodeBinary(Q,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let Q=this.lookU8();Z=this.decodeExtension(Q,1)}else if($===200){let Q=this.lookU16();Z=this.decodeExtension(Q,2)}else if($===201){let Q=this.lookU32();Z=this.decodeExtension(Q,4)}else throw new K0.DecodeError(`Unrecognized type byte: ${(0,HZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===KZ)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===$$){if(Z==="__proto__")throw new K0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=OQ;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=$$;continue $}}return Z}}readHeadByte(){if(this.headByte===e0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=e0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new K0.DecodeError(`Unrecognized array type byte: ${(0,HZ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new K0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new K0.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 K0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw MQ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,wX.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===$$;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new K0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw MQ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new K0.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,E0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,E0.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,$}}HQ.Decoder=RZ});var UQ=r((RQ)=>{Object.defineProperty(RQ,"__esModule",{value:!0});RQ.decode=jX;RQ.decodeMulti=LX;var IQ=L$();function jX($,Z){return new IQ.Decoder(Z).decode($)}function LX($,Z){return new IQ.Decoder(Z).decodeMulti($)}});var TQ=r((CQ)=>{Object.defineProperty(CQ,"__esModule",{value:!0});CQ.isAsyncIterable=PQ;CQ.asyncIterableFromStream=wQ;CQ.ensureAsyncIterable=_X;function PQ($){return $[Symbol.asyncIterator]!=null}async function*wQ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function _X($){if(PQ($))return $;else return wQ($)}});var AQ=r((DQ)=>{Object.defineProperty(DQ,"__esModule",{value:!0});DQ.decodeAsync=xX;DQ.decodeArrayStream=SX;DQ.decodeMultiStream=fX;var UZ=L$(),PZ=TQ();async function xX($,Z){let J=(0,PZ.ensureAsyncIterable)($);return new UZ.Decoder(Z).decodeAsync(J)}function SX($,Z){let J=(0,PZ.ensureAsyncIterable)($);return new UZ.Decoder(Z).decodeArrayStream(J)}function fX($,Z){let J=(0,PZ.ensureAsyncIterable)($);return new UZ.Decoder(Z).decodeStream(J)}});var LQ=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 bX=YQ();Object.defineProperty(y,"encode",{enumerable:!0,get:function(){return bX.encode}});var jQ=UQ();Object.defineProperty(y,"decode",{enumerable:!0,get:function(){return jQ.decode}});Object.defineProperty(y,"decodeMulti",{enumerable:!0,get:function(){return jQ.decodeMulti}});var wZ=AQ();Object.defineProperty(y,"decodeAsync",{enumerable:!0,get:function(){return wZ.decodeAsync}});Object.defineProperty(y,"decodeArrayStream",{enumerable:!0,get:function(){return wZ.decodeArrayStream}});Object.defineProperty(y,"decodeMultiStream",{enumerable:!0,get:function(){return wZ.decodeMultiStream}});var hX=L$();Object.defineProperty(y,"Decoder",{enumerable:!0,get:function(){return hX.Decoder}});var iX=T$();Object.defineProperty(y,"DecodeError",{enumerable:!0,get:function(){return iX.DecodeError}});var pX=FZ();Object.defineProperty(y,"Encoder",{enumerable:!0,get:function(){return pX.Encoder}});var uX=j$();Object.defineProperty(y,"ExtensionCodec",{enumerable:!0,get:function(){return uX.ExtensionCodec}});var dX=qZ();Object.defineProperty(y,"ExtData",{enumerable:!0,get:function(){return dX.ExtData}});var u0=NZ();Object.defineProperty(y,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return u0.EXT_TIMESTAMP}});Object.defineProperty(y,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return u0.encodeDateToTimeSpec}});Object.defineProperty(y,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return u0.encodeTimeSpecToTimestamp}});Object.defineProperty(y,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return u0.decodeTimestampToTimeSpec}});Object.defineProperty(y,"encodeTimestampExtension",{enumerable:!0,get:function(){return u0.encodeTimestampExtension}});Object.defineProperty(y,"decodeTimestampExtension",{enumerable:!0,get:function(){return u0.decodeTimestampExtension}})});import*as q0 from"node:crypto";var U0=q0&&typeof q0==="object"&&"webcrypto"in q0?q0.webcrypto:q0&&typeof q0==="object"&&("randomBytes"in q0)?q0:void 0;function Z$($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function E$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function p($,...Z){if(!E$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function m$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function DZ($,Z){p($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function _$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var N0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var hQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!hQ)throw Error("Non little-endian hardware is not supported");function iQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function J$($){if(typeof $==="string")$=iQ($);else if(E$($))$=Q$($);else throw Error("Uint8Array expected, got "+typeof $);return $}function AZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function jZ($,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 LZ=($,Z)=>{function J(Q,...Y){if(p(Q),$.nonceLength!==void 0){let z=Y[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)p(z);else p(z,$.nonceLength)}let X=$.tagLength;if(X&&Y[1]!==void 0)p(Y[1]);let G=Z(Q,...Y),W=(z,M)=>{if(M!==void 0){if(z!==2)throw Error("cipher output not supported");p(M)}},q=!1;return{encrypt(z,M){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,p(z),W(G.encrypt.length,M),G.encrypt(z,M)},decrypt(z,M){if(p(z),X&&z.length<X)throw Error("invalid ciphertext length: smaller than tagLength="+X);return W(G.decrypt.length,M),G.decrypt(z,M)}}}return Object.assign(J,$),J};function B$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!pQ(Z))throw Error("invalid output, must be aligned");return Z}function pQ($){return $.byteOffset%4===0}function Q$($){return Uint8Array.from($)}function Y0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function n0($=32){if(U0&&typeof U0.getRandomValues==="function")return U0.getRandomValues(new Uint8Array($));if(U0&&typeof U0.randomBytes==="function")return U0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var mZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),uQ=mZ("expand 16-byte k"),dQ=mZ("expand 32-byte k"),nQ=N0(uQ),cQ=N0(dQ);function U($,Z){return $<<Z|$>>>32-Z}function k$($){return $.byteOffset%4===0}var Y$=64,rQ=16,_Z=4294967295,EZ=new Uint32Array;function oQ($,Z,J,Q,Y,X,G,W){let q=Y.length,N=new Uint8Array(Y$),z=N0(N),M=k$(Y)&&k$(X),F=M?N0(Y):EZ,K=M?N0(X):EZ;for(let I=0;I<q;G++){if($(Z,J,Q,z,G,W),G>=_Z)throw Error("arx: counter overflow");let R=Math.min(Y$,q-I);if(M&&R===Y$){let P=I/4;if(I%4!==0)throw Error("arx: invalid block position");for(let C=0,D;C<rQ;C++)D=P+C,K[D]=F[D]^z[C];I+=Y$;continue}for(let P=0,C;P<R;P++)C=I+P,X[C]=Y[C]^N[P];I+=R}}function BZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:Y,counterRight:X,rounds:G}=AZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return Z$(Y),Z$(G),_$(X),_$(J),(W,q,N,z,M=0)=>{p(W),p(q),p(N);let F=N.length;if(z===void 0)z=new Uint8Array(F);if(p(z),Z$(M),M<0||M>=_Z)throw Error("arx: counter overflow");if(z.length<F)throw Error(`arx: output (${z.length}) is shorter than data (${F})`);let K=[],I=W.length,R,P;if(I===32)K.push(R=Q$(W)),P=cQ;else if(I===16&&J)R=new Uint8Array(32),R.set(W),R.set(W,16),P=nQ,K.push(R);else throw Error(`arx: invalid 32-byte key, got length=${I}`);if(!k$(q))K.push(q=Q$(q));let C=N0(R);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(P,C,N0(q.subarray(0,16)),C),q=q.subarray(16)}let D=16-Y;if(D!==q.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let w=new Uint8Array(12);w.set(q,X?0:12-q.length),q=w,K.push(q)}let j=N0(q);return oQ($,P,C,j,N,z,M,G),Y0(...K),z}}var d=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class kZ{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,$=J$($),p($,32);let Z=d($,0),J=d($,2),Q=d($,4),Y=d($,6),X=d($,8),G=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|Y<<9)&8191,this.r[4]=(Y>>>4|X<<12)&255,this.r[5]=X>>>1&8190,this.r[6]=(X>>>14|G<<2)&8191,this.r[7]=(G>>>11|W<<5)&8065,this.r[8]=(W>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let N=0;N<8;N++)this.pad[N]=d($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:Y,r:X}=this,G=X[0],W=X[1],q=X[2],N=X[3],z=X[4],M=X[5],F=X[6],K=X[7],I=X[8],R=X[9],P=d($,Z+0),C=d($,Z+2),D=d($,Z+4),j=d($,Z+6),w=d($,Z+8),L=d($,Z+10),B=d($,Z+12),u=d($,Z+14),_=Y[0]+(P&8191),g=Y[1]+((P>>>13|C<<3)&8191),S=Y[2]+((C>>>10|D<<6)&8191),x=Y[3]+((D>>>7|j<<9)&8191),f=Y[4]+((j>>>4|w<<12)&8191),H=Y[5]+(w>>>1&8191),l=Y[6]+((w>>>14|L<<2)&8191),b=Y[7]+((L>>>11|B<<5)&8191),h=Y[8]+((B>>>8|u<<8)&8191),i=Y[9]+(u>>>5|Q),T=0,c=T+_*G+g*(5*R)+S*(5*I)+x*(5*K)+f*(5*F);T=c>>>13,c&=8191,c+=H*(5*M)+l*(5*z)+b*(5*N)+h*(5*q)+i*(5*W),T+=c>>>13,c&=8191;let a=T+_*W+g*G+S*(5*R)+x*(5*I)+f*(5*K);T=a>>>13,a&=8191,a+=H*(5*F)+l*(5*M)+b*(5*z)+h*(5*N)+i*(5*q),T+=a>>>13,a&=8191;let e=T+_*q+g*W+S*G+x*(5*R)+f*(5*I);T=e>>>13,e&=8191,e+=H*(5*K)+l*(5*F)+b*(5*M)+h*(5*z)+i*(5*N),T+=e>>>13,e&=8191;let k=T+_*N+g*q+S*W+x*G+f*(5*R);T=k>>>13,k&=8191,k+=H*(5*I)+l*(5*K)+b*(5*F)+h*(5*M)+i*(5*z),T+=k>>>13,k&=8191;let W0=T+_*z+g*N+S*q+x*W+f*G;T=W0>>>13,W0&=8191,W0+=H*(5*R)+l*(5*I)+b*(5*K)+h*(5*F)+i*(5*M),T+=W0>>>13,W0&=8191;let m0=T+_*M+g*z+S*N+x*q+f*W;T=m0>>>13,m0&=8191,m0+=H*G+l*(5*R)+b*(5*I)+h*(5*K)+i*(5*F),T+=m0>>>13,m0&=8191;let _0=T+_*F+g*M+S*z+x*N+f*q;T=_0>>>13,_0&=8191,_0+=H*W+l*G+b*(5*R)+h*(5*I)+i*(5*K),T+=_0>>>13,_0&=8191;let B0=T+_*K+g*F+S*M+x*z+f*N;T=B0>>>13,B0&=8191,B0+=H*q+l*W+b*G+h*(5*R)+i*(5*I),T+=B0>>>13,B0&=8191;let k0=T+_*I+g*K+S*F+x*M+f*z;T=k0>>>13,k0&=8191,k0+=H*N+l*q+b*W+h*G+i*(5*R),T+=k0>>>13,k0&=8191;let g0=T+_*R+g*I+S*K+x*F+f*M;T=g0>>>13,g0&=8191,g0+=H*z+l*N+b*q+h*W+i*G,T+=g0>>>13,g0&=8191,T=(T<<2)+T|0,T=T+c|0,c=T&8191,T=T>>>13,a+=T,Y[0]=c,Y[1]=a,Y[2]=e,Y[3]=k,Y[4]=W0,Y[5]=m0,Y[6]=_0,Y[7]=B0,Y[8]=k0,Y[9]=g0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let G=2;G<10;G++)$[G]+=Q,Q=$[G]>>>13,$[G]&=8191;$[0]+=Q*5,Q=$[0]>>>13,$[0]&=8191,$[1]+=Q,Q=$[1]>>>13,$[1]&=8191,$[2]+=Q,J[0]=$[0]+5,Q=J[0]>>>13,J[0]&=8191;for(let G=1;G<10;G++)J[G]=$[G]+Q,Q=J[G]>>>13,J[G]&=8191;J[9]-=8192;let Y=(Q^1)-1;for(let G=0;G<10;G++)J[G]&=Y;Y=~Y;for(let G=0;G<10;G++)$[G]=$[G]&Y|J[G];$[0]=($[0]|$[1]<<13)&65535,$[1]=($[1]>>>3|$[2]<<10)&65535,$[2]=($[2]>>>6|$[3]<<7)&65535,$[3]=($[3]>>>9|$[4]<<4)&65535,$[4]=($[4]>>>12|$[5]<<1|$[6]<<14)&65535,$[5]=($[6]>>>2|$[7]<<11)&65535,$[6]=($[7]>>>5|$[8]<<8)&65535,$[7]=($[8]>>>8|$[9]<<5)&65535;let X=$[0]+Z[0];$[0]=X&65535;for(let G=1;G<8;G++)X=($[G]+Z[G]|0)+(X>>>16)|0,$[G]=X&65535;Y0(J)}update($){m$(this);let{buffer:Z,blockLen:J}=this;$=J$($);let Q=$.length;for(let Y=0;Y<Q;){let X=Math.min(J-this.pos,Q-Y);if(X===J){for(;J<=Q-Y;Y+=J)this.process($,Y);continue}if(Z.set($.subarray(Y,Y+X),this.pos),this.pos+=X,Y+=X,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){Y0(this.h,this.r,this.buffer,this.pad)}digestInto($){m$(this),DZ($,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 Y=0;for(let X=0;X<8;X++)$[Y++]=J[X]>>>0,$[Y++]=J[X]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function aQ($){let Z=(Q,Y)=>$(Y).update(J$(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var g$=aQ(($)=>new kZ($));function sQ($,Z,J,Q,Y,X=20){let G=$[0],W=Z[0],q=Z[1],N=Z[2],z=Z[3],M=$[1],F=J[0],K=J[1],I=Y,R=0,P=$[2],C=Z[4],D=Z[5],j=Z[6],w=Z[7],L=$[3],B=G,u=W,_=q,g=N,S=z,x=M,f=F,H=K,l=I,b=R,h=P,i=C,T=D,c=j,a=w,e=L;for(let W0=0;W0<X;W0+=2)S^=U(B+T|0,7),l^=U(S+B|0,9),T^=U(l+S|0,13),B^=U(T+l|0,18),b^=U(x+u|0,7),c^=U(b+x|0,9),u^=U(c+b|0,13),x^=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),g^=U(e+i|0,7),H^=U(g+e|0,9),i^=U(H+g|0,13),e^=U(i+H|0,18),u^=U(B+g|0,7),_^=U(u+B|0,9),g^=U(_+u|0,13),B^=U(g+_|0,18),f^=U(x+S|0,7),H^=U(f+x|0,9),S^=U(H+f|0,13),x^=U(S+H|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),T^=U(e+a|0,7),c^=U(T+e|0,9),a^=U(c+T|0,13),e^=U(a+c|0,18);let k=0;Q[k++]=G+B|0,Q[k++]=W+u|0,Q[k++]=q+_|0,Q[k++]=N+g|0,Q[k++]=z+S|0,Q[k++]=M+x|0,Q[k++]=F+f|0,Q[k++]=K+H|0,Q[k++]=I+l|0,Q[k++]=R+b|0,Q[k++]=P+h|0,Q[k++]=C+i|0,Q[k++]=D+T|0,Q[k++]=j+c|0,Q[k++]=w+a|0,Q[k++]=L+e|0}function tQ($,Z,J,Q){let Y=$[0],X=Z[0],G=Z[1],W=Z[2],q=Z[3],N=$[1],z=J[0],M=J[1],F=J[2],K=J[3],I=$[2],R=Z[4],P=Z[5],C=Z[6],D=Z[7],j=$[3];for(let L=0;L<20;L+=2)q^=U(Y+P|0,7),F^=U(q+Y|0,9),P^=U(F+q|0,13),Y^=U(P+F|0,18),K^=U(N+X|0,7),C^=U(K+N|0,9),X^=U(C+K|0,13),N^=U(X+C|0,18),D^=U(I+z|0,7),G^=U(D+I|0,9),z^=U(G+D|0,13),I^=U(z+G|0,18),W^=U(j+R|0,7),M^=U(W+j|0,9),R^=U(M+W|0,13),j^=U(R+M|0,18),X^=U(Y+W|0,7),G^=U(X+Y|0,9),W^=U(G+X|0,13),Y^=U(W+G|0,18),z^=U(N+q|0,7),M^=U(z+N|0,9),q^=U(M+z|0,13),N^=U(q+M|0,18),R^=U(I+K|0,7),F^=U(R+I|0,9),K^=U(F+R|0,13),I^=U(K+F|0,18),P^=U(j+D|0,7),C^=U(P+j|0,9),D^=U(C+P|0,13),j^=U(D+C|0,18);let w=0;Q[w++]=Y,Q[w++]=N,Q[w++]=I,Q[w++]=j,Q[w++]=z,Q[w++]=M,Q[w++]=F,Q[w++]=K}var x$=BZ(sQ,{counterRight:!0,extendNonceFn:tQ}),S$=LZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=B$(J.length+32,Q,!1);let Y=Q.subarray(0,32),X=Q.subarray(32);Q.set(J,32),Y0(Y),x$($,Z,Q,Q);let G=g$(X,Y);return Q.set(G,16),Y0(Q.subarray(0,16),G),Q.subarray(16)},decrypt(J,Q){p(J),Q=B$(J.length+32,Q,!1);let Y=Q.subarray(0,32),X=Q.subarray(32,48),G=Q.subarray(48);Q.set(J,32),Y0(Y);let W=x$($,Z,Y,Y),q=g$(G,W);if(!jZ(X,q))throw Error("invalid tag");return x$($,Z,Q.subarray(16),Q.subarray(16)),Y0(Y,X,q),G}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function eQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function c0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function P0($,...Z){if(!eQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function r0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function X$($,Z){P0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function gZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function x0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function S0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function o0($,Z){return $<<32-Z|$>>>Z}var xZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function SZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var fZ=xZ?($)=>$:($)=>SZ($);function $Y($){for(let Z=0;Z<$.length;Z++)$[Z]=SZ($[Z]);return $}var s=xZ?($)=>$:$Y;function ZY($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function f0($){if(typeof $==="string")$=ZY($);return P0($),$}class f${}function vZ($){let Z=(Q,Y)=>$(Y).update(f0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var yZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var G$=BigInt(4294967295),lZ=BigInt(32);function v$($,Z=!1){if(Z)return{h:Number($&G$),l:Number($>>lZ&G$)};return{h:Number($>>lZ&G$)|0,l:Number($&G$)|0}}function z0($,Z,J,Q,Y){return $=$+Z+Y|0,Q=o0(Q^$,16),J=J+Q|0,Z=o0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function M0($,Z,J,Q,Y){return $=$+Z+Y|0,Q=o0(Q^$,8),J=J+Q|0,Z=o0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class y$ extends f${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,c0($),c0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=x0(this.buffer)}update($){r0(this),$=f0($),P0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,Y=$.length,X=$.byteOffset,G=$.buffer;for(let W=0;W<Y;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(Q),this.pos=0;let q=Math.min(Z-this.pos,Y-W),N=X+W;if(q===Z&&!(N%4)&&W+q<Y){let z=new Uint32Array(G,N,Math.floor((Y-W)/4));s(z);for(let M=0;W+Z<Y;M+=Q.length,W+=Z)this.length+=Z,this.compress(z,M,!1);s(z);continue}J.set($.subarray(W,W+q),this.pos),this.pos+=q,this.length+=q,W+=q}return this}digestInto($){r0(this),X$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,S0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=x0($);this.get().forEach((Y,X)=>Q[X]=fZ(Y))}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:Y,outputLen:X,pos:G}=this;return $||($=new this.constructor({dkLen:X})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=Y,$.finished=Q,$.length=J,$.pos=G,$.outputLen=X,$}clone(){return this._cloneInto()}}function l$($,Z,J,Q,Y,X,G,W,q,N,z,M,F,K,I,R,P,C,D,j){let w=0;for(let L=0;L<Q;L++)({a:Y,b:q,c:F,d:P}=z0(Y,q,F,P,J[Z+$[w++]])),{a:Y,b:q,c:F,d:P}=M0(Y,q,F,P,J[Z+$[w++]]),{a:X,b:N,c:K,d:C}=z0(X,N,K,C,J[Z+$[w++]]),{a:X,b:N,c:K,d:C}=M0(X,N,K,C,J[Z+$[w++]]),{a:G,b:z,c:I,d:D}=z0(G,z,I,D,J[Z+$[w++]]),{a:G,b:z,c:I,d:D}=M0(G,z,I,D,J[Z+$[w++]]),{a:W,b:M,c:R,d:j}=z0(W,M,R,j,J[Z+$[w++]]),{a:W,b:M,c:R,d:j}=M0(W,M,R,j,J[Z+$[w++]]),{a:Y,b:N,c:I,d:j}=z0(Y,N,I,j,J[Z+$[w++]]),{a:Y,b:N,c:I,d:j}=M0(Y,N,I,j,J[Z+$[w++]]),{a:X,b:z,c:R,d:P}=z0(X,z,R,P,J[Z+$[w++]]),{a:X,b:z,c:R,d:P}=M0(X,z,R,P,J[Z+$[w++]]),{a:G,b:M,c:F,d:C}=z0(G,M,F,C,J[Z+$[w++]]),{a:G,b:M,c:F,d:C}=M0(G,M,F,C,J[Z+$[w++]]),{a:W,b:q,c:K,d:D}=z0(W,q,K,D,J[Z+$[w++]]),{a:W,b:q,c:K,d:D}=M0(W,q,K,D,J[Z+$[w++]]);return{v0:Y,v1:X,v2:G,v3:W,v4:q,v5:N,v6:z,v7:M,v8:F,v9:K,v10:I,v11:R,v12:P,v13:C,v14:D,v15:j}}var X0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},O0=yZ.slice(),bZ=(()=>{let $=Array.from({length:16},(Q,Y)=>Y),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((Y)=>Q[Y]),J=[];for(let Q=0,Y=$;Q<7;Q++,Y=Z(Y))J.push(...Y);return Uint8Array.from(J)})();class b$ extends y${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}=$,Y=Q!==void 0;if(J!==void 0){if(Y)throw Error('Only "key" or "context" can be specified at same time');let X=f0(J).slice();P0(X,32),this.IV=x0(X),s(this.IV),this.flags=Z|X0.KEYED_HASH}else if(Y){let X=f0(Q),G=new b$({dkLen:32},X0.DERIVE_KEY_CONTEXT).update(X).digest();this.IV=x0(G),s(this.IV),this.flags=Z|X0.DERIVE_KEY_MATERIAL}else this.IV=O0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=gZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:Y,pos:X}=this,{h:G,l:W}=v$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:M,v4:F,v5:K,v6:I,v7:R,v8:P,v9:C,v10:D,v11:j,v12:w,v13:L,v14:B,v15:u}=l$(bZ,Q,J,7,Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],O0[0],O0[1],O0[2],O0[3],G,W,X,Z);Y[0]=q^P,Y[1]=N^C,Y[2]=z^D,Y[3]=M^j,Y[4]=F^w,Y[5]=K^L,Y[6]=I^B,Y[7]=R^u}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=X0.CHUNK_START;if(this.chunkPos===15||J)Q|=X0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let Y=this.state;this.state=this.IV.slice();for(let X,G=this.chunksDone+1;J||!(G&1);G>>=1){if(!(X=this.stack.pop()))break;this.buffer32.set(X,0),this.buffer32.set(Y,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|X0.PARENT,this.buffer32,0),Y=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(Y)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:Y,posOut:X,chunkOut:G,stack:W,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=W.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=Y,$.chunksDone=q,$.posOut=X,$.chunkOut=G,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,S0(this.state,this.buffer32,this.IV,this.bufferOut32),S0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:Y}=this,{h:X,l:G}=v$(BigInt(this.chunkOut++));s(Q);let{v0:W,v1:q,v2:N,v3:z,v4:M,v5:F,v6:K,v7:I,v8:R,v9:P,v10:C,v11:D,v12:j,v13:w,v14:L,v15:B}=l$(bZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],O0[0],O0[1],O0[2],O0[3],G,X,Z,J);Y[0]=W^R,Y[1]=q^P,Y[2]=N^C,Y[3]=z^D,Y[4]=M^j,Y[5]=F^w,Y[6]=K^L,Y[7]=I^B,Y[8]=$[0]^R,Y[9]=$[1]^P,Y[10]=$[2]^C,Y[11]=$[3]^D,Y[12]=$[4]^j,Y[13]=$[5]^w,Y[14]=$[6]^L,Y[15]=$[7]^B,s(Q),s(Y),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,S0(this.buffer.subarray(this.pos));let $=this.flags|X0.ROOT;if(this.stack.length)$|=X0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?X0.CHUNK_START:0)|X0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){r0(this,!1),P0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,Y=$.length;Q<Y;){if(this.posOut>=Z)this.b2CompressOut();let X=Math.min(Z-this.posOut,Y-Q);$.set(J.subarray(this.posOut,this.posOut+X),Q),this.posOut+=X,Q+=X}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return c0($),this.xofInto(new Uint8Array($))}digestInto($){if(X$($,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 hZ=vZ(($)=>new b$($));function $0($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function V$($){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 W$($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var iZ;if(typeof Uint8Array.prototype.toBase64==="function")iZ=($)=>$.toBase64();else iZ=($)=>btoa(String.fromCharCode(...$));var h$;if(typeof Uint8Array.fromBase64==="function")h$=($)=>Uint8Array.fromBase64($);else h$=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function pZ($){let Z=$.length%4===0?"":"=".repeat(4-$.length%4),J=$.replace(/-/g,"+").replace(/_/g,"/")+Z;return h$(J)}function G0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var v0=64;var uZ=32,y0=8;var dZ=32;var nZ=30000,cZ=512,A;((H)=>{H[H.Success=0]="Success";H[H.InvalidSignature=3]="InvalidSignature";H[H.ClockOutOfSync=4]="ClockOutOfSync";H[H.UserNotRegistered=5]="UserNotRegistered";H[H.ServerMisconfigured=6]="ServerMisconfigured";H[H.MissingBody=7]="MissingBody";H[H.ExtraBodyContent=8]="ExtraBodyContent";H[H.MissingParam=9]="MissingParam";H[H.InvalidParam=10]="InvalidParam";H[H.InvalidRequest=11]="InvalidRequest";H[H.InternalError=12]="InternalError";H[H.NotFound=13]="NotFound";H[H.InvalidMessage=14]="InvalidMessage";H[H.NoChange=15]="NoChange";H[H.DatabaseClosed=16]="DatabaseClosed";H[H.StorageError=17]="StorageError";H[H.DatabaseError=18]="DatabaseError";H[H.HashMismatch=19]="HashMismatch";H[H.DecryptionError=20]="DecryptionError";H[H.NotImplemented=21]="NotImplemented";H[H.MissingSeed=22]="MissingSeed";H[H.OutOfBounds=23]="OutOfBounds";H[H.HostError=24]="HostError";H[H.CommunicationError=25]="CommunicationError";H[H.VarLimitExceeded=26]="VarLimitExceeded";H[H.InvalidResponse=27]="InvalidResponse";H[H.ConnectionClosed=28]="ConnectionClosed";H[H.CryptoError=29]="CryptoError";H[H.WebAuthnError=30]="WebAuthnError"})(A||={});var rZ="t";function O($){return[$,0]}function V($){return[void 0,$]}var JY=32,lG=Symbol("X25519Sk");function oZ($){if($.byteLength!==JY)return V(10);return O($)}var E=(1n<<255n)-19n,QY=121665n,aZ=new Uint8Array(32);aZ[0]=9;function sZ($){let Z=0n;for(let J=$.length-1;J>=0;J--)Z=Z<<8n|BigInt($[J]);return Z}function YY($){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 XY($){let Z=$.slice();return Z[31]&=127,sZ(Z)}function GY($){let Z=$.slice();return Z[0]&=248,Z[31]&=127,Z[31]|=64,Z}function q$($,Z,J){let Q=-$,Y=(Z^J)&Q;return[Z^Y,J^Y]}function VY($){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 WY($,Z){let J=GY($),Q=XY(Z),Y=1n,X=0n,G=Q,W=1n,q=0n,N=sZ(J);for(let z=254;z>=0;z--){let M=N>>BigInt(z)&1n;q^=M,[Y,G]=q$(q,Y,G),[X,W]=q$(q,X,W),q=M;let F=(Y+X)%E,K=F*F%E,I=(Y-X+E)%E,R=I*I%E,P=(K-R+E)%E,C=(G+W)%E,j=(G-W+E)%E*F%E,w=C*I%E,L=(j+w)%E,B=(j-w+E)%E;G=L*L%E,W=Q*B*B%E,Y=K*R%E,X=P*(K+QY*P)%E}return[Y,G]=q$(q,Y,G),[X,W]=q$(q,X,W),J.fill(0),YY(Y*VY(X)%E)}function tZ($){return WY($,aZ)}var i$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function eZ($){let Z=new Uint8Array(i$.length+32);return Z.set(i$),Z.set($.subarray(0,32),i$.length),Z}var p$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,110,4,34,4,32]);function $J($){let Z=new Uint8Array(p$.length+32);return Z.set(p$),Z.set($.subarray(0,32),p$.length),Z}function ZJ($){return typeof $==="string"?new TextEncoder().encode($):$}function F0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class w0{verifyKeys=new Map;async genRandomBytes($){return n0($)}async gen256BitSecureRandomSeed(){return n0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=n0(24),Y=S$(Z,J).encrypt($);return new Uint8Array([...J,...Y])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return S$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=eZ(Z),Q=F0(J),Y;try{let N=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"Ed25519"},!0,["sign"]);Y=await globalThis.crypto.subtle.exportKey("jwk",N)}finally{J.fill(0),new Uint8Array(Q).fill(0)}if(typeof Y.x!=="string")throw Error("Ed25519 JWK missing x");let X=Y.x;Y.d=void 0;let G=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:X},{name:"Ed25519"},!0,["verify"]),W=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",G));this.verifyKeys.set($0(W),G);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=eZ(Z),Q=F0(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",F0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=ZJ($),Q=await this.importSignKey(Z),Y=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,F0(J));return new Uint8Array(Y)}async checkSigEd25519($,Z,J){let Q=ZJ(Z);try{let Y=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},Y,F0($),F0(Q))}catch{return!1}}async blake3($){return hZ($)}async genX25519(){let $=await n0(32);$[0]&=248,$[31]&=127,$[31]|=64;let[Z,J]=oZ($);if(J!==0||Z===void 0)throw $.fill(0),Error("X25519 scalar brand failed");let Q=tZ(Z),Y=$J(Z),X=F0(Y);try{let G=await globalThis.crypto.subtle.importKey("pkcs8",X,{name:"X25519"},!0,["deriveBits"]),W=await globalThis.crypto.subtle.exportKey("jwk",G);if(typeof W.x!=="string")throw Error("X25519 JWK missing x");let q=pZ(W.x);if(W.d=void 0,!W$(q,Q))throw Error("X25519 WebCrypto pub != RFC 7748");return{priv:Z,pub:Q}}catch(G){throw Z.fill(0),G}finally{Y.fill(0),new Uint8Array(X).fill(0)}}async x25519Shared($,Z){let J=$J($),Q=F0(J);try{let Y=await globalThis.crypto.subtle.importKey("pkcs8",Q,{name:"X25519"},!1,["deriveBits"]),X=await globalThis.crypto.subtle.importKey("raw",F0(Z),{name:"X25519"},!1,[]),G=await globalThis.crypto.subtle.deriveBits({name:"X25519",public:X},Y,256);return new Uint8Array(G)}finally{J.fill(0),new Uint8Array(Q).fill(0)}}}var qY=new w0,l0=qY;function NY($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return V(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 V(26);return O(new Uint8Array(Z))}function zY($,Z=0){let J=0n,Q=0,Y=Z;while(!0){if(Y>=$.length)return V(14);let X=$[Y++];if(X===void 0)return V(14);if(J|=BigInt(X&127)<<BigInt(Q),(X&128)===0){if(Y-Z>8)return V(26);return O({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:Y-Z})}if(Q+=7,Q>=56)return V(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 V(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 V(Z);return O(new Date($))}readVarInt(){let[$,Z]=zY(this.data,this.pos);if(Z!==0)return V(Z);this.pos+=$.bytesRead;let J=$.value;return O(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return V(Z);let[J,Q]=this.readBytes($);if(Q!==0)return V(Q);let Y=new TextDecoder().decode(J);return O(Y)}readBytes($){if($<0)return V(10);if(this.pos+$>this.data.length)return V(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,O(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return V(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return V(Q);Z.push(J)}return O(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return V(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]=NY($);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,Y)=>Q+Y.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 a0={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 V(J);let[Q,Y]=$.readDate();if(Y!==0)return V(Y);return O({id:Z,ts:Q})}};function JJ($){let Z=new m,J=Z.writeStruct(a0,$);if(J!==0)return V(J);let Q=Z.result();return O(Q)}var u$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let Y=$.writeVarInt(Z.ctr);if(Y!==0)return Y;let X=$.writeVarInt(Z.len);if(X!==0)return X;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return V(J);let Q=new v(Z),[,Y]=a0.decode(Q);if(Y!==0)return V(Y);let[X,G]=$.readVarInt();if(G!==0)return V(G);let[W,q]=$.readVarInt();if(q!==0)return V(q);let[N,z]=$.readVarInt();if(z!==0)return V(z);let M;if(N>0){let[F,K]=$.readBytes(dZ);if(K!==0)return V(K);M=F}return O({eid:Z,off:X,ctr:W,len:N,hsh:M})}};function QJ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function YJ($,Z,J,Q){let Y;if($.bod&&$.len>0)Y=await J.blake3($.bod);let X=new m,G=u$.encode(X,{...$,hsh:Y});if(G!==0)return V(G);let W=X.result(),q=await Z.kdmFor(W),N=Q.deriveCipher(q,"encrypt"),z=await N.encrypt(W),M=$.bod?await N.encrypt($.bod):new Uint8Array(0),F=await Z.sign(z);return O({sig:F,kdm:q,headCph:z,bodyCph:M})}async function XJ($,Z,J,Q,Y){let X=new v($),[G,W]=u$.decode(X);if(W!==0)return V(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return V(20)}let N=G.hsh&&q===void 0,z=G.hsh===void 0&&q!==void 0;if(N||z)return V(19);if(G.hsh&&q){let F=await Q.blake3(q);if(!W$(F,G.hsh))return V(19)}let M=Y??await Q.blake3($);return O({msgHead:G,bod:q,headHash:M})}async function d$($,Z){let J=new m,Q=J.writeDate(Z);if(Q!==0)return V(Q);let Y=J.result(),X=await $.sign(Y);return O({pubKey:$.publicKey,sig:X,timestamp:Z})}async function J0($,Z,J){let Q=J.now().getTime(),Y=$.timestamp.getTime();if(Math.abs(Q-Y)>nZ)return 4;let G=new m;G.writeDate($.timestamp);let W=G.result();if(!await Z.checkSigEd25519($.sig,W,$.pubKey))return 3;return 0}class b0{now(){return new Date}}function GJ($,Z,J,Q){let Y=Z.getTime()-$.getTime(),X=J.getTime()-Q.getTime();return(Y+X)/2}var s0={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 V(J);let Q;if(Z>0){let[Y,X]=$.readVarInt();if(X!==0)return V(X);Q=Y}return O({quota:Z,usage:Q})}};var h0={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 Y=$.writeVarInt(Z.subscription.term);if(Y!==0)return Y;let X=$.writeVarInt(Z.subscription.elapsed);if(X!==0)return X;let G=$.writeStruct(s0,Z.subscription.stat);if(G!==0)return G;let W=$.writeStruct(s0,Z.subscription.dyn);if(W!==0)return W;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return V(J);let Q=Z[0],[Y,X]=$.readDate();if(X!==0)return V(X);let[G,W]=$.readDate();if(W!==0)return V(W);let[q,N]=$.readVarInt();if(N!==0)return V(N);let[z,M]=$.readVarInt();if(M!==0)return V(M);let[F,K]=$.readStruct(s0);if(K!==0)return V(K);let[I,R]=$.readStruct(s0);if(R!==0)return V(R);return O({status:Q,timeRcvd:Y,timeSent:G,subscription:{term:q,elapsed:z,stat:F,dyn:I}})}};var n$={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 V(J);let[Q,Y]=$.readVarInt();if(Y!==0)return V(Y);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(uZ);if(J!==0)return V(J);let[Q,Y]=$.readBytes(v0);if(Y!==0)return V(Y);let[X,G]=$.readDate();if(G!==0)return V(G);return O({pubKey:Z,sig:Q,timestamp:X})}};var VJ={async encodeReq($,Z,J,Q,Y){let X=Y.writeStruct(o,J);if(X!==0)return X;for(let G of Q)Y.writeVarInt(G);return 0},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X}=$,[G,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(G,Y,Q);if(q!==0)return q;let{pubKey:N}=G,[z,M]=await X.hasUser(N);if(M!==0)return M;if(!z)return 5;let[F,K]=Z.readVarInt();if(K!==0)return K;if(!Z.done())return 8;let[I,R]=await X.listHeads(N,F);if(R!==0)return R;return J.writeStructs(n$,I)},decodeResp($){return $.readStructs(n$)}};var c$={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 V(J);let[Q,Y]=$.readVarBytes();if(Y!==0)return V(Y);return O({seq:Z,bodyCph:Q})}};var WJ={async encodeReq($,Z,J,Q,Y){let X=Y.writeStruct(o,J);if(X!==0)return X;for(let G of Q){let W=Y.writeVarInt(G);if(W!==0)return W}return 0},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X}=$,[G,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(G,Y,Q);if(q!==0)return q;let{pubKey:N}=G,[z,M]=await X.hasUser(N);if(M!==0)return M;if(!z)return 5;let F=[];while(!Z.done()){let[R,P]=Z.readVarInt();if(P!==0)return P;F.push(R)}console.info(`PULL: ${F.length} bags`);let[K,I]=await X.getBodies(N,F);if(I!==0)return I;if(!K)return 17;for(let{seq:R,bodyCph:P}of K){let C={seq:R,bodyCph:P},D=J.writeStruct(c$,C);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(c$)}};var r$={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(v0);if(J!==0)return V(J);let[Q,Y]=$.readBytes(y0);if(Y!==0)return V(Y);let[X,G]=$.readVarBytes();if(G!==0)return V(G);let[W,q]=$.readVarBytes();if(q!==0)return V(q);return O({sig:Z,kdm:Q,headCph:X,bodyCph:W})}};var o$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let Y=Z.bodyCph?Z.bodyCph.length:0,X=$.writeVarInt(Y);if(X!==0)return X;if(Y>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return V(J);let[Q,Y]=$.readVarBytes();if(Y!==0)return V(Y);let[X,G]=$.readVarInt();if(G!==0)return V(G);let W;if(X>0){let[q,N]=$.readBytes(X);if(N!==0)return V(N);W=q}return O({seq:Z,headCph:Q,bodyCph:W})}};var i0={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(v0);if(J!==0)return V(J);let[Q,Y]=$.readBytes(y0);if(Y!==0)return V(Y);let[X,G]=$.readVarBytes();if(G!==0)return V(G);return O({sig:Z,kdm:Q,headCph:X})}};var N$={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 V(J);let[Q,Y]=$.readBytes(1);if(Y!==0)return V(Y);let X=Q[0];if(X!==0)return O({idx:Z,status:X});let[G,W]=$.readVarInt();if(W!==0)return V(W);return O({idx:Z,status:X,seq:G})}};var qJ={async encodeReq($,Z,J,Q,Y){let X=Y.writeStruct(o,J);if(X!==0)return X;let G=Y.writeStructs(r$,Q);if(G!==0)return G;return 0},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X,notifier:G}=$,[W,q]=Z.readStruct(o);if(q!==0)return q;let N=await J0(W,Y,Q);if(N!==0)return N;let{pubKey:z}=W,[M,F]=await X.hasUser(z);if(F!==0)return F;if(!M)return 5;let[K,I]=Z.readStructs(r$);if(I!==0)return I;console.info(`PUSH: ${K.length} bags`);let R=[],P=[];for(let w=0;w<K.length;w++){let L=K[w];if(!await QJ(L,z,Y)){let u={idx:w,status:3},_=J.writeStruct(N$,u);if(_!==0)return _;continue}R.push(w),P.push(L)}let[C,D]=await X.setBags(z,P);if(D!==0)return D;if(!C||C.length!==P.length)return 17;let j=[];for(let w=0;w<P.length;w++){let L=P[w],B=R[w],u=C[w],_=new m,g=_.writeStruct(i0,L);if(g!==0)return g;let S=_.result(),x={seq:u,headCph:S};if(K.length===1&&L.bodyCph.length<=cZ)x.bodyCph=L.bodyCph;j.push(x);let f={idx:B,status:0,seq:u},H=J.writeStruct(N$,f);if(H!==0)return H}if(j.length>0){let w=new m,L=w.writeStructs(o$,j);if(L!==0)return L;let B=w.result();await Promise.resolve(G.push(z,B))}return 0},decodeResp($){return $.readStructs(N$)}};var NJ={async encodeReq($,Z,J,Q,Y){return Y.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:Y,storage:X}=$,[G,W]=Z.readStruct(o);if(W!==0)return W;let q=await J0(G,Y,Q);if(q!==0)return q;let{pubKey:N}=G;if(!Z.done())return 8;let[z,M]=await X.addUser(N);if(M!==0)return M;return 0},decodeResp($){return O(void 0)}};class a${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:Y}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let X=new m;X.writeStruct(o,$);let G=X.result(),W=$0(G);return Y.searchParams.set("t",W),this.websocket=new WebSocket(Y),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Q()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(q)=>{let N=new Uint8Array(q.data);Z(N)},this.websocket.onerror=(q)=>{console.log(`ERROR: ${JSON.stringify(q)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var n={user:{path:"/user",endpoint:NJ,name:0},push:{path:"/push",endpoint:qJ,name:2},peek:{path:"/peek",endpoint:VJ,name:1},pull:{path:"/pull",endpoint:WJ,name:3}},MY={0:n.user,2:n.push,1:n.peek,3:n.pull},zJ={[n.user.path]:n.user,[n.push.path]:n.push,[n.peek.path]:n.peek,[n.pull.path]:n.pull};class MJ{url;listener;constructor($){this.url=$;this.listener=new a$($)}async call($,Z){let{path:J}=MY[$],Q=new URL(J,this.url);try{return await FY(Q,Z)}catch{return V(25)}}}var s$=($)=>{return new MJ($.handle)};function p0($){let Z=new m;if(Z.writeStruct(h0,$)!==0)return new Response(null,{status:500});return t$(Z)}function t$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var OY={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function e$($){return new Response($.body,{headers:{...$.headers,...OY},status:$.status,statusText:$.statusText})}async function FY($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return V(24);let Q=await v.fromResponse(J);return O(Q)}class z${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,Y,X){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=Y;this.updateHostMeta=X}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:Y,name:X}=$,G=await this.identity(),W=J.now(),[q,N]=await d$(G,W);if(N!==0)return V(N);let z=new m,M=await Y.encodeReq(this,G,q,Z,z);if(M!==0)return V(M);let F=J.now(),[K,I]=await Q.call(X,z),R=J.now();if(I!==0)return V(I);let[P,C]=K.readStruct(h0);if(C!==0)return V(C);if(P.status!==0)return V(P.status);let j={clockOffset:GJ(F,P.timeRcvd,P.timeSent,R),subscription:P.subscription},w=await this.updateHostMeta(j);if(w!==0)return V(w);return Y.decodeResp(K)}identity=()=>{let{host:$,enclave:Z}=this;return Z.deriveIdentity($.label,$.idx??0)};seal=async($)=>{let{crypto:Z,enclave:J}=this,Q=await this.identity();return YJ($,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:Y}=this,{listener:X}=Y,G=await this.identity(),W=Q.now(),[q,N]=await d$(G,W);if(N!==0)return N;return await X.connect(q,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var G8=Symbol("MasterSeed"),V8=Symbol("SealedMasterKey"),V0=32,OJ=24+V0+16;function t($){if($.byteLength!==V0)return V(10);return O($)}function M$($){if($.byteLength!==OJ)return V(10);return O($)}var C0={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 V(J);let[Q,Y]=$.readVarString();if(Y!==0)return V(Y);let[X,G]=$.readVarInt();if(G!==0)return V(G);return O({handle:Z,label:Q,idx:X})}};var O$=1,$Z={encode($,Z){if(Z.v!==O$)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 Y=$.writeVarInt(Z.hosts.length);if(Y!==0)return Y;for(let X of Z.hosts){let G=$.writeStruct(C0,X);if(G!==0)return G}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return V(J);if(Z!==O$)return V(14);let[Q,Y]=$.readBytes(V0);if(Y!==0)return V(Y);if(Q===void 0)return V(14);let[X,G]=t(Q);if(G!==0)return V(G);if(X===void 0)return V(14);let[W,q]=$.readVarInt();if(q!==0)return V(q);if(W===void 0||W<0)return V(10);let N=[];for(let z=0;z<W;z++){let[M,F]=$.readStruct(C0);if(F!==0)return V(F);if(M===void 0)return V(14);N.push(M)}return O({v:O$,masterSeed:X,hosts:N})}};function FJ($,Z){let[J,Q]=t($);if(Q!==0)return V(Q);if(J===void 0)return V(10);let[Y,X]=t(J.slice());if(X!==0)return V(X);if(Y===void 0)return V(10);return O({v:O$,masterSeed:Y,hosts:Z.map((G)=>({handle:G.handle,label:G.label,idx:G.idx??0}))})}var F$={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 Y of Z.hosts){let X=$.writeStruct(C0,Y);if(X!==0)return X}return 0},decode($){let[Z,J]=$.readBytes(V0);if(J!==0)return V(J);if(Z===void 0)return V(14);let[Q,Y]=t(Z);if(Y!==0)return V(Y);if(Q===void 0)return V(14);let[X,G]=$.readVarInt();if(G!==0)return V(G);if(X===void 0||X<0)return V(10);let W=[];for(let q=0;q<X;q++){let[N,z]=$.readStruct(C0);if(z!==0)return V(z);if(N===void 0)return V(14);W.push(N)}return O({masterSeed:Q,hosts:W})}};var HY=new TextEncoder().encode("diplomatic.qrpair.v1"),t0=32,KY=t0+24+16,IY=32,_8=Symbol("DHKEReq"),B8=Symbol("DHKEResp");function HJ($){if($.byteLength!==t0)return V(10);return O($)}function KJ($){if($.byteLength<KY)return V(10);return O($)}var H$=new w0;async function ZZ($,Z,J,Q){let Y;try{Y=await H$.x25519Shared($,Z)}catch{return V(29)}try{if(Y.byteLength!==t0||Y.every((W)=>W===0))return V(10);let X=G0(Y,HY),G=G0(X,G0(J,Q));try{let W=await H$.blake3(G);return O(W.slice(0,IY))}finally{X.fill(0),G.fill(0)}}finally{Y.fill(0)}}class K${#$;#Z;constructor($,Z){this.#$=$,this.#Z=Z}static async create(){let $;try{let Z=await H$.genX25519();$=Z.priv;let[J,Q]=HJ(Z.pub);if(Q!==0)return V(Q);if(J===void 0)return V(10);let Y=new K$($,J);return $=void 0,O(Y)}catch{return V(29)}finally{$?.fill(0)}}wipe(){this.#$.fill(0)}get dhkeReq(){let[$,Z]=HJ(this.#Z.slice());if($===void 0)throw Error(`dhkeReq ${Z}`);return $}async finish($){let Z=$.subarray(0,t0),J=$.subarray(t0),[Q,Y]=await ZZ(this.#$,Z,this.#Z,Z);if(Y!==0)return V(Y);if(Q===void 0)return V(12);let X;try{try{X=await H$.decryptXSalsa20Poly1305Combined(J,Q)}catch{return V(20)}let G=new v(X),[W,q]=G.readStruct(F$);if(q!==0)return V(q);if(W===void 0)return V(14);try{let[N,z]=Q0.fromBytes(W.masterSeed);if(z!==0)return V(z);if(N===void 0)return V(12);return this.wipe(),O({enclave:N,hosts:W.hosts.map((M)=>({...M}))})}finally{W.masterSeed.fill(0)}}finally{Q.fill(0),X?.fill(0)}}}function H0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var T0=32,RY=-7,UY=-8,PY=-257,I$=[{type:"public-key",alg:RY},{type:"public-key",alg:UY},{type:"public-key",alg:PY}];function wY($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function R0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z.buffer}function RJ($){if($ instanceof ArrayBuffer)return new Uint8Array($).slice();return new Uint8Array($.buffer,$.byteOffset,$.byteLength).slice()}function D0($){if($?.rpId!==void 0)return O($.rpId);if(typeof location>"u")return V(9);return O(wY(location.hostname))}var IJ="";function A0($){if($ instanceof Error){IJ=$.message===""?$.name:`${$.name}: ${$.message}`;return}IJ=String($)}function j0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function L0($){if($===null||$.type!=="public-key"||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return V(27);return O($)}async function UJ($){let Z=j0();if(Z!==0)return V(Z);let[J,Q]=D0($);if(Q!==0)return V(Q);if(J===void 0)return V(9);let Y=$?.userName??"diplomatic-seed",X={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)X.authenticatorAttachment=$.authenticatorAttachment;let G={largeBlob:{support:"required"}},W;try{W=await navigator.credentials.create({publicKey:{challenge:H0(T0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:H0(16),name:Y,displayName:Y},pubKeyCredParams:I$,authenticatorSelection:X,extensions:G,...$?.hints!==void 0?{hints:$.hints}:{}}})}catch(M){return A0(M),V(30)}let[q,N]=L0(W);if(N!==0)return V(N);if(q===void 0)return V(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return V(30);return O(new Uint8Array(q.rawId))}async function QZ($,Z,J){let Q=j0();if(Q!==0)return Q;let[Y,X]=D0(J);if(X!==0)return X;if(Y===void 0)return 9;let G={largeBlob:{write:R0(Z)}},W;try{W=await navigator.credentials.get({publicKey:{challenge:H0(T0),rpId:Y,allowCredentials:[{type:"public-key",id:R0($)}],userVerification:"required",extensions:G,...J?.hints!==void 0?{hints:J.hints}:{}}})}catch(M){return A0(M),30}let[q,N]=L0(W);if(N!==0)return N;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 30;return 0}async function JZ($,Z,J,Q){let Y={challenge:H0(T0),rpId:$,userVerification:"preferred"};if(Z?.hints!==void 0)Y.hints=Z.hints;if(J!==void 0)Y.allowCredentials=[{type:"public-key",id:R0(J)}];if(Q!==void 0)Y.extensions=Q;let X;try{X=await navigator.credentials.get({publicKey:Y})}catch(q){return A0(q),V(30)}let[G,W]=L0(X);if(W!==0)return V(W);if(G===void 0)return V(27);return O(G)}async function PJ($,Z){let J=j0();if(J!==0)return V(J);let[Q,Y]=D0(Z);if(Y!==0)return V(Y);if(Q===void 0)return V(9);let X=$;if(X===void 0){let[M,F]=await JZ(Q,Z);if(F!==0&&Z?.hints!==void 0)[M,F]=await JZ(Q,{rpId:Z.rpId,rpName:Z.rpName});if(F!==0)return V(F);if(M===void 0)return V(27);X=new Uint8Array(M.rawId)}let[G,W]=await JZ(Q,Z,X,{largeBlob:{read:!0}});if(W!==0)return V(W);if(G===void 0)return V(27);let N=G.getClientExtensionResults().largeBlob;if(N===void 0||N.blob===void 0)return V(7);let z=RJ(N.blob);if(z.byteLength===0)return V(7);return O({blob:z,credId:new Uint8Array(G.rawId)})}var XZ=new TextEncoder().encode("diplomatic.prf.v1"),YZ=32;async function wJ($){let Z=j0();if(Z!==0)return V(Z);let[J,Q]=D0($);if(Q!==0)return V(Q);if(J===void 0)return V(9);let Y=$?.userName??"diplomatic-prf",X={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)X.authenticatorAttachment=$.authenticatorAttachment;let G=$?.salt!==void 0?R0($.salt):void 0,W=G===void 0?{}:{eval:{first:G}},q;try{q=await navigator.credentials.create({publicKey:{challenge:H0(T0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:H0(16),name:Y,displayName:Y},pubKeyCredParams:I$,authenticatorSelection:X,extensions:{prf:W},...$?.hints!==void 0?{hints:$.hints}:{}}})}catch(F){return A0(F),V(30)}let[N,z]=L0(q);if(z!==0)return V(z);if(N===void 0)return V(27);let M=N.getClientExtensionResults();return O({credId:new Uint8Array(N.rawId),prfEnabled:M.prf?.enabled===!0})}async function GZ($){let Z=j0();if(Z!==0)return V(Z);let[J,Q]=D0($);if(Q!==0)return V(Q);if(J===void 0)return V(9);let Y=$?.salt??XZ,X=R0(Y),G={challenge:H0(T0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:X}}}};if($?.hints!==void 0)G.hints=$.hints;if($?.credId!==void 0)G.allowCredentials=[{type:"public-key",id:R0($.credId)}];let W;try{W=await navigator.credentials.get({publicKey:G})}catch(I){return A0(I),V(30)}let[q,N]=L0(W);if(N!==0)return V(N);if(q===void 0)return V(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return V(7);let M=z.first,F=M instanceof ArrayBuffer?new Uint8Array(M):new Uint8Array(M.buffer,M.byteOffset,M.byteLength),K=F.byteLength>=YZ?F.slice(0,YZ):F;if(K.byteLength!==YZ)return V(27);return O({prf:K,credId:new Uint8Array(q.rawId)})}var R$="";var P$=typeof globalThis.Worker==="function"?globalThis.Worker:void 0,VZ=P$===void 0?void 0:P$.prototype.postMessage,U$;function TY(){if(typeof R$!=="string"||R$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(R$)}function DY(){if(U$!==void 0)return U$;let $=new Blob([TY()],{type:"text/javascript"});return U$=URL.createObjectURL($),U$}function CJ(){if(P$===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new P$(DY(),{type:"module"})}function TJ($,Z,J){if(VZ===void 0)throw Error("[DIPLOMATIC] Worker API unavailable; cannot post to sync worker");if(J!==void 0&&J.length>0)VZ.call($,Z,{transfer:J});else VZ.call($,Z)}var AY=new TextEncoder().encode("diplomatic.wrap.v1"),jY=32,LY=16,Z0=new w0;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 V(J);if(Z===void 0)return V(10);let[Q,Y]=t(Z.slice());if(Y!==0)return V(Y);if(Q===void 0)return V(10);return O(new Q0(Q))}async sealWithPasskey($){let Z=$?.salt??XZ,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[X,G]=await wJ({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf",authenticatorAttachment:$?.authenticatorAttachment,hints:$?.hints,salt:Z});if(G!==0)return V(G);if(X===void 0)return V(30);if(!X.prfEnabled)return V(30);J=X.credId}let[Q,Y]=await GZ({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z,hints:$?.hints});if(Y!==0)return V(Y);if(Q===void 0)return V(7);try{let[X,G]=await this.#Y(Q.prf);if(G!==0)return V(G);if(X===void 0)return V(12);return O({sealedMaster:X,salt:Z.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async unsealWithPasskey($,Z){let[J,Q]=await GZ({rpId:Z.rpId,rpName:Z.rpName,hints:Z.hints,credId:Z.credId,salt:Z.salt});if(Q!==0)return V(Q);if(J===void 0)return V(7);try{let[Y,X]=await Q0.#X($,J.prf);if(X!==0)return V(X);if(Y===void 0)return V(12);return O({enclave:Y,credId:J.credId.slice()})}finally{J.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[X,G]=await UJ(Z);if(G!==0)return V(G);if(X===void 0)return V(30);J=X}let[Q,Y]=this.#G($);if(Y!==0)return V(Y);if(Q===void 0)return V(12);try{let X=await QZ(J,Q,Z);if(X!==0)return V(X);return O(J)}finally{Q.fill(0)}}static async fromLargeBlob($){let[Z,J]=await PJ($?.credId,$);if(J!==0)return V(J);if(Z===void 0)return V(7);try{return Q0.#V(Z.blob,Z.credId)}finally{Z.blob.fill(0)}}static async clearLargeBlob($,Z){return QZ($,new Uint8Array(V0),Z)}static pairRequest(){return K$.create()}async pairAccept($,Z){let J;try{J=await Z0.genX25519()}catch{return V(29)}try{let[Q,Y]=await ZZ(J.priv,$,$,J.pub);if(Y!==0)return V(Y);if(Q===void 0)return V(12);try{let[X,G]=this.#Z(Z);if(G!==0)return V(G);if(X===void 0)return V(12);try{let W=await Z0.encryptXSalsa20Poly1305Combined(X,Q);return KJ(G0(J.pub,W))}catch{return V(12)}finally{X.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),V(Q);if(J===void 0)return Z.fill(0),V(10);try{let Y={masterSeed:J,hosts:$.map((G)=>({handle:G.handle,label:G.label,idx:G.idx??0}))},X=new m;try{let G=X.writeStruct(F$,Y);if(G!==0)return V(G);return O(X.result())}finally{X.wipe()}}finally{J.fill(0)}}spawnSyncWorker($){let Z=CJ(),J=this.#$.slice();return TJ(Z,{id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(G)=>this.#W(J,G),Y=(G)=>this.#q(J,G);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:Y}),both:Object.freeze({encrypt:Q,decrypt:Y})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,Y=await this.#Q(J,Q),X=Y.publicKey;return Y.privateKey.fill(0),Object.freeze({publicKey:X,sign:(G)=>this.#z(J,Q,G),kdmFor:(G)=>this.#M(J,Q,G)})}async#Y($){let[Z,J]=await DJ(Z0,$);if(J!==0)return V(J);if(Z===void 0)return V(12);try{let Q=await Z0.encryptXSalsa20Poly1305Combined(this.#$,Z);return M$(Q)}catch{return V(12)}finally{Z.fill(0)}}static async#X($,Z){let[,J]=M$($);if(J!==0)return V(J);let[Q,Y]=await DJ(Z0,Z);if(Y!==0)return V(Y);if(Q===void 0)return V(12);let X;try{try{X=await Z0.decryptXSalsa20Poly1305Combined($,Q)}catch{return V(20)}return Q0.fromBytes(X)}finally{Q.fill(0),X?.fill(0)}}#G($){let Z=this.#$.slice(),[J,Q]=t(Z);if(Q!==0)return Z.fill(0),V(Q);if(J===void 0)return Z.fill(0),V(10);try{let[Y,X]=FJ(J,$);if(X!==0)return V(X);if(Y===void 0)return V(12);try{let G=new m,W=G.writeStruct($Z,Y);if(W!==0)return V(W);return O(G.result())}finally{Y.masterSeed.fill(0)}}finally{J.fill(0)}}static#V($,Z){if($.byteLength===0||$.every((X)=>X===0))return V(22);if($.byteLength===V0){if($.every((W)=>W===0))return V(22);let[X,G]=Q0.fromBytes($);if(G!==0)return V(G);if(X===void 0)return V(12);return O({enclave:X,hosts:[],credId:Z})}let J=new v($),[Q,Y]=J.readStruct($Z);if(Y!==0)return V(Y);if(Q===void 0)return V(14);try{if(Q.masterSeed.every((W)=>W===0))return V(22);let[X,G]=Q0.fromBytes(Q.masterSeed);if(G!==0)return V(G);if(X===void 0)return V(12);return O({enclave:X,hosts:Q.hosts.map((W)=>({...W})),credId:Z})}finally{Q.masterSeed.fill(0)}}async#W($,Z){let J=await this.#J($);try{return await Z0.encryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#q($,Z){let J=await this.#J($);try{return await Z0.decryptXSalsa20Poly1305Combined(Z,J)}finally{J.fill(0)}}async#J($){return Z0.blake3(G0(this.#$,$))}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(G0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);try{return await Z0.deriveEd25519KeyPair(J)}finally{J.fill(0)}}async#z($,Z,J){let Q=await this.#Q($,Z);try{return await Z0.signEd25519(J,Q.privateKey)}finally{Q.privateKey.fill(0)}}async#M($,Z,J){let Q=await this.#Q($,Z),Y=G0(Q.privateKey,J);Q.privateKey.fill(0);try{return(await Z0.blake3(Y)).slice(0,y0)}finally{Y.fill(0)}}}async function DJ($,Z,J=AY){if(Z.byteLength<LY)return V(10);let Q=await $.blake3(G0(Z,J));return O(Q.slice(0,jY))}class WZ{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 Y of Q)Y(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function AJ($,Z,J,Q=0){let Y=Z.now(),X=new m,G=X.writeVarString($);if(G!==0)return V(G);let q={id:X.result(),ts:new Date(0)},[N,z]=JJ(q);if(z!==0)return V(z);let M=Y.getTime()-q.ts.getTime();return O({eid:N,off:M,ctr:Q,len:J.length,bod:J})}class EY{singletonType;latest;latestOff=-1;emitter=new WZ;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new v(Z.eid),[Q,Y]=J.readStruct(a0);if(Y!==0)continue;let X=new m;X.writeVarString(this.singletonType);let G=X.result();if(Q.id.length===G.length&&Q.id.every((W,q)=>W===G[q])){if(this.latest===void 0||Z.off>this.latestOff)this.latestOff=Z.off,this.latest=Z.bod,this.emitter.emit(this.singletonType,null)}}return $.map(()=>0)}clear=async()=>{return this.latest=void 0,this.latestOff=-1,this.emitter.emit(this.singletonType,null),0};notify=($)=>{for(let Z of $)if(Z===this.singletonType)this.emitter.emit(this.singletonType,null)};refresh=async($)=>{this.notify([this.singletonType])};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function jJ($,Z,J,Q){let Y=new v($.headCph),[X,G]=Y.readStruct(i0);if(G!==0)return V(G);let{sig:W,kdm:q,headCph:N}=X;if(!await Q.checkSigEd25519(W,N,Z))return V(3);let M=J.deriveCipher(q,"decrypt"),F;try{F=await M.decrypt(N)}catch{return V(20)}return O({kdm:q,headEnc:F})}var d0=bQ(LQ(),1),cX={encode:d0.encode,decode:d0.decode,decodeAsync:d0.decodeAsync},rX=cX;import{Database as oX}from"bun:sqlite";var QN=Symbol("EntityID");var YN=Symbol("DerivationSeed"),XN=Symbol("PublicKey"),GN=Symbol("PrivateKey"),VN=Symbol("HostSpecificKeyPair"),WN=Symbol("Hash"),I0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function aX($="diplomatic.db"){let Z=new oX($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS users (
|
|
3
3
|
pubKey TEXT PRIMARY KEY
|
|
4
4
|
);
|
|
@@ -11,4 +11,4 @@ var gQ=Object.create;var{getPrototypeOf:xQ,defineProperty:CZ,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 V(17)}},async hasUser(J){try{let Q=$0(J),Y=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return O(Boolean(Y?.ok))}catch{return V(17)}},async subMeta(J){return O(I0)},async setBags(J,Q){if(Q.length<1)return O([]);try{let Y=$0(J);Z.exec("BEGIN IMMEDIATE");try{let X=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(Y),G=X?X.m||0:0,W=[],q=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){G+=1;let z=new m;z.writeStruct(i0,N),q.run(Y,G,z.result(),N.bodyCph),W.push(G)}return Z.exec("COMMIT"),O(W)}catch(X){try{Z.exec("ROLLBACK")}catch{}throw X}}catch{return V(17)}},async getBodies(J,Q){if(Q.length<1)return O([]);try{let Y=$0(J),X=[],G=100,W=99;for(let q=0;q<Q.length;q+=99){let N=Q.slice(q,q+99),z=N.map(()=>"?").join(","),M=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${z})`).all(Y,...N);for(let F of M)if(F.bodyCph)X.push({seq:F.seq,bodyCph:new Uint8Array(F.bodyCph)})}return O(X)}catch{return V(17)}},async listHeads(J,Q){try{let Y=$0(J),X=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(Y,Q);return O(X.map((G)=>({seq:G.seq,headCph:new Uint8Array(G.headCph)})))}catch{return V(17)}}}}var sX=aX(),EQ=sX;class
|
|
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 V(17)}},async hasUser(J){try{let Q=$0(J),Y=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return O(Boolean(Y?.ok))}catch{return V(17)}},async subMeta(J){return O(I0)},async setBags(J,Q){if(Q.length<1)return O([]);try{let Y=$0(J);Z.exec("BEGIN IMMEDIATE");try{let X=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(Y),G=X?X.m||0:0,W=[],q=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){G+=1;let z=new m;z.writeStruct(i0,N),q.run(Y,G,z.result(),N.bodyCph),W.push(G)}return Z.exec("COMMIT"),O(W)}catch(X){try{Z.exec("ROLLBACK")}catch{}throw X}}catch{return V(17)}},async getBodies(J,Q){if(Q.length<1)return O([]);try{let Y=$0(J),X=[],G=100,W=99;for(let q=0;q<Q.length;q+=99){let N=Q.slice(q,q+99),z=N.map(()=>"?").join(","),M=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${z})`).all(Y,...N);for(let F of M)if(F.bodyCph)X.push({seq:F.seq,bodyCph:new Uint8Array(F.bodyCph)})}return O(X)}catch{return V(17)}},async listHeads(J,Q){try{let Y=$0(J),X=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(Y,Q);return O(X.map((G)=>({seq:G.seq,headCph:new Uint8Array(G.headCph)})))}catch{return V(17)}}}}var sX=aX(),EQ=sX;class CZ{storage;crypto;notifier;clock;constructor($,Z,J,Q){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=Q}corsHandler=async($)=>{if($.method==="OPTIONS")return e$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),e$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=new URL($.url);if($.method!=="POST"){let N=Z.now();return p0({status:13,timeRcvd:J,timeSent:N,subscription:I0})}if(!$.body){let N=Z.now();return p0({status:7,timeRcvd:J,timeSent:N,subscription:I0})}let X=new Uint8Array(await $.arrayBuffer()),G=new v(X),W=Q.pathname,q=zJ[W]?.endpoint;if(!q){let N=Z.now();return p0({status:13,timeRcvd:J,timeSent:N,subscription:I0})}try{let N=new m,z=await q.handleReq(this,G,N),M=I0,F={status:z,timeRcvd:J,timeSent:this.clock.now(),subscription:M},K=new m;if(K.writeStruct(h0,F)!==0)return new Response(null,{status:500});if(z!==0){let R=Z.now();return p0({status:z,timeRcvd:J,timeSent:R,subscription:I0})}return N.prependBytes(K.result()),t$(N)}catch(N){let z=Z.now();return console.error(N),console.trace(),p0({status:12,timeRcvd:J,timeSent:z,subscription:I0})}}}async function mQ($,Z){let Q=new URL($.url).searchParams.get(rZ);if(!Q)return V(11);let Y=V$(Q),X=new v(Y),[G,W]=X.readStruct(o);if(W!==0)return V(11);let q=await J0(G,Z.crypto,Z.clock);if(q!==0)return V(q);return O(G)}class BQ{recvs=new Map;async open($,Z,J,Q){let Y=await J0($,J,Q);if(Y!==0)return{send:()=>Y,shut:()=>Y,status:Y};let X=$0($.pubKey);if(!this.recvs.has(X))this.recvs.set(X,new Set);return this.recvs.get(X)?.add(Z),{send:(G)=>{return Z(G),0},shut:()=>{return this.recvs.get(X)?.delete(Z),0},status:0}}async push($,Z){let J=$0($),Q=this.recvs.get(J);if(Q)for(let Y of Q)Y(Z)}}var _Q=new BQ;async function tX($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new CZ(EQ,l0,_Q,new b0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,Q)=>{if(J.headers.get("upgrade")==="websocket"){let[Y,X]=await mQ(J,Z);if(X!==0)return new Response("Unauthorized",{status:401});return Q.upgrade(J,{data:{authTS:Y}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let Q=J.data.authTS;_Q.open(Q,(Y)=>J.send(Y),Z.crypto,Z.clock).then((Y)=>{if(Y.status!==0){J.close();return}J.channel=Y})},message:(J,Q)=>{},close:(J)=>{J.channel?.shut()}}})}class kQ{enclave;conn;clock;constructor({enclave:$,clock:Z=new b0}){this.enclave=$,this.clock=Z}async connect($,Z){let J=new b0,Q=()=>Promise.resolve(0);this.conn=new z$(this.enclave,l0,$,J,Z,Q);let[,Y]=await this.conn.register();return Y}async push($){if(!this.conn)return V(28);let Z=[];for(let Y of $){let[X,G]=await this.conn.seal(Y);if(G!==0)return V(G);Z.push(X)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return V(Q);return O(J)}async peek($){if(!this.conn)return V(28);return this.conn.peek($)}async pull($){if(!this.conn)return V(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return V(28);let J=await this.conn.identity(),[Q,Y]=await jJ($,J.publicKey,this.enclave,l0);if(Y!==0)return V(Y);let X=this.enclave.deriveCipher(Q.kdm,"decrypt");return XJ(Q.headEnc,Z.bodyCph,X,l0)}async upsertSingletonSync($,Z){let[J,Q]=await AJ($,this.clock,Z);if(Q!==0)return Q;let[,Y]=await this.push([J]);return Y}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function eX({enclave:$,host:Z,transport:J}){let Q=new kQ({enclave:$}),Y=await Q.connect(Z,J);return[Q,Y]}async function $z({enclave:$,host:Z,transport:J}){let Q=J??s$(Z),[Y,X]=await eX({enclave:$,host:Z,transport:Q});if(X!==0)console.error(`Failed to initialize CLI: ${A[X]}`),process.exit(1);return Y}function Zz($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=V$(Z),[Q,Y]=Q0.fromBytes(J);if(J.fill(0),Y!==0||Q===void 0)console.error(`${$} must be 64 hex chars (32-byte master seed)`),process.exit(1);return Q}function Jz($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{tX as runBunHost,o$ as notifItemCodec,rX as msgpack,Jz as loadHostOrPanic,Zz as loadEnclaveOrPanic,$z as initCLIOrPanic,eX as initCLI,s$ as hostHTTPTransport,A as Status,v as Decoder,kQ as CLIClient};
|