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