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