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