@interncom/diplomatic 0.4.0 → 0.4.2
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 +3 -3
- package/dist/cli/shared/crypto/noble.d.ts +7 -0
- package/dist/web/index.mjs +1 -1
- package/dist/web/mapPool.d.ts +6 -0
- package/dist/web/shared/crypto/noble.d.ts +7 -0
- package/dist/web/shared/storage/memory.d.ts +3 -0
- package/dist/web/sync.d.ts +11 -1
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -2
package/dist/cli/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var P8=Object.create;var{getPrototypeOf:S8,defineProperty:oJ,getOwnPropertyNames:w8}=Object;var F8=Object.prototype.hasOwnProperty;function j8($){return this[$]}var k8,E8,L8=($,J,Q)=>{var Z=$!=null&&typeof $==="object";if(Z){var V=J?k8??=new WeakMap:E8??=new WeakMap,I=V.get($);if(I)return I}Q=$!=null?P8(S8($)):{};let X=J||!$||!$.__esModule?oJ(Q,"default",{value:$,enumerable:!0}):Q;for(let G of w8($))if(!F8.call(X,G))oJ(X,G,{get:j8.bind($,G),enumerable:!0});if(Z)V.set($,X);return X};var V0=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var w$=V0((WZ)=>{Object.defineProperty(WZ,"__esModule",{value:!0});WZ.utf8Count=eV;WZ.utf8EncodeJs=qZ;WZ.utf8EncodeTE=NZ;WZ.utf8Encode=QI;WZ.utf8DecodeJs=KZ;WZ.utf8DecodeTD=MZ;WZ.utf8Decode=XI;function eV($){let J=$.length,Q=0,Z=0;while(Z<J){let V=$.charCodeAt(Z++);if((V&4294967168)===0){Q++;continue}else if((V&4294965248)===0)Q+=2;else{if(V>=55296&&V<=56319){if(Z<J){let I=$.charCodeAt(Z);if((I&64512)===56320)++Z,V=((V&1023)<<10)+(I&1023)+65536}}if((V&4294901760)===0)Q+=3;else Q+=4}}return Q}function qZ($,J,Q){let Z=$.length,V=Q,I=0;while(I<Z){let X=$.charCodeAt(I++);if((X&4294967168)===0){J[V++]=X;continue}else if((X&4294965248)===0)J[V++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(I<Z){let G=$.charCodeAt(I);if((G&64512)===56320)++I,X=((X&1023)<<10)+(G&1023)+65536}}if((X&4294901760)===0)J[V++]=X>>12&15|224,J[V++]=X>>6&63|128;else J[V++]=X>>18&7|240,J[V++]=X>>12&63|128,J[V++]=X>>6&63|128}J[V++]=X&63|128}}var $I=new TextEncoder,JI=50;function NZ($,J,Q){$I.encodeInto($,J.subarray(Q))}function QI($,J,Q){if($.length>JI)NZ($,J,Q);else qZ($,J,Q)}var ZI=4096;function KZ($,J,Q){let Z=J,V=Z+Q,I=[],X="";while(Z<V){let G=$[Z++];if((G&128)===0)I.push(G);else if((G&224)===192){let Y=$[Z++]&63;I.push((G&31)<<6|Y)}else if((G&240)===224){let Y=$[Z++]&63,N=$[Z++]&63;I.push((G&31)<<12|Y<<6|N)}else if((G&248)===240){let Y=$[Z++]&63,N=$[Z++]&63,q=$[Z++]&63,K=(G&7)<<18|Y<<12|N<<6|q;if(K>65535)K-=65536,I.push(K>>>10&1023|55296),K=56320|K&1023;I.push(K)}else I.push(G);if(I.length>=ZI)X+=String.fromCharCode(...I),I.length=0}if(I.length>0)X+=String.fromCharCode(...I);return X}var VI=new TextDecoder,II=200;function MZ($,J,Q){let Z=$.subarray(J,J+Q);return VI.decode(Z)}function XI($,J,Q){if(Q>II)return MZ($,J,Q);else return KZ($,J,Q)}});var FJ=V0((OZ)=>{Object.defineProperty(OZ,"__esModule",{value:!0});OZ.ExtData=void 0;class UZ{type;data;constructor($,J){this.type=$,this.data=J}}OZ.ExtData=UZ});var j$=V0((HZ)=>{Object.defineProperty(HZ,"__esModule",{value:!0});HZ.DecodeError=void 0;class F$ extends Error{constructor($){super($);let J=Object.create(F$.prototype);Object.setPrototypeOf(this,J),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:F$.name})}}HZ.DecodeError=F$});var k$=V0((RZ)=>{Object.defineProperty(RZ,"__esModule",{value:!0});RZ.UINT32_MAX=void 0;RZ.setUint64=UI;RZ.setInt64=OI;RZ.getInt64=zI;RZ.getUint64=HI;RZ.UINT32_MAX=4294967295;function UI($,J,Q){let Z=Q/4294967296,V=Q;$.setUint32(J,Z),$.setUint32(J+4,V)}function OI($,J,Q){let Z=Math.floor(Q/4294967296),V=Q;$.setUint32(J,Z),$.setUint32(J+4,V)}function zI($,J){let Q=$.getInt32(J),Z=$.getUint32(J+4);return Q*4294967296+Z}function HI($,J){let Q=$.getUint32(J),Z=$.getUint32(J+4);return Q*4294967296+Z}});var jJ=V0((jZ)=>{Object.defineProperty(jZ,"__esModule",{value:!0});jZ.timestampExtension=jZ.EXT_TIMESTAMP=void 0;jZ.encodeTimeSpecToTimestamp=CZ;jZ.encodeDateToTimeSpec=PZ;jZ.encodeTimestampExtension=SZ;jZ.decodeTimestampToTimeSpec=wZ;jZ.decodeTimestampExtension=FZ;var CI=j$(),AZ=k$();jZ.EXT_TIMESTAMP=-1;var PI=4294967295,SI=17179869183;function CZ({sec:$,nsec:J}){if($>=0&&J>=0&&$<=SI)if(J===0&&$<=PI){let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,$),Q}else{let Q=$/4294967296,Z=$&4294967295,V=new Uint8Array(8),I=new DataView(V.buffer);return I.setUint32(0,J<<2|Q&3),I.setUint32(4,Z),V}else{let Q=new Uint8Array(12),Z=new DataView(Q.buffer);return Z.setUint32(0,J),(0,AZ.setInt64)(Z,4,$),Q}}function PZ($){let J=$.getTime(),Q=Math.floor(J/1000),Z=(J-Q*1000)*1e6,V=Math.floor(Z/1e9);return{sec:Q+V,nsec:Z-V*1e9}}function SZ($){if($ instanceof Date){let J=PZ($);return CZ(J)}else return null}function wZ($){let J=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let Q=J.getUint32(0),Z=0;return{sec:Q,nsec:0}}case 8:{let Q=J.getUint32(0),Z=J.getUint32(4),V=(Q&3)*4294967296+Z,I=Q>>>2;return{sec:V,nsec:I}}case 12:{let Q=(0,AZ.getInt64)(J,4),Z=J.getUint32(0);return{sec:Q,nsec:Z}}default:throw new CI.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function FZ($){let J=wZ($);return new Date(J.sec*1000+J.nsec/1e6)}jZ.timestampExtension={type:jZ.EXT_TIMESTAMP,encode:SZ,decode:FZ}});var L$=V0((LZ)=>{Object.defineProperty(LZ,"__esModule",{value:!0});LZ.ExtensionCodec=void 0;var E$=FJ(),LI=jJ();class kJ{static defaultCodec=new kJ;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(LI.timestampExtension)}register({type:$,encode:J,decode:Q}){if($>=0)this.encoders[$]=J,this.decoders[$]=Q;else{let Z=-1-$;this.builtInEncoders[Z]=J,this.builtInDecoders[Z]=Q}}tryToEncode($,J){for(let Q=0;Q<this.builtInEncoders.length;Q++){let Z=this.builtInEncoders[Q];if(Z!=null){let V=Z($,J);if(V!=null){let I=-1-Q;return new E$.ExtData(I,V)}}}for(let Q=0;Q<this.encoders.length;Q++){let Z=this.encoders[Q];if(Z!=null){let V=Z($,J);if(V!=null){let I=Q;return new E$.ExtData(I,V)}}}if($ instanceof E$.ExtData)return $;return null}decode($,J,Q){let Z=J<0?this.builtInDecoders[-1-J]:this.decoders[J];if(Z)return Z($,J,Q);else return new E$.ExtData(J,$)}}LZ.ExtensionCodec=kJ});var EJ=V0((gZ)=>{Object.defineProperty(gZ,"__esModule",{value:!0});gZ.ensureUint8Array=gI;function BI($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function gI($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(BI($))return new Uint8Array($);else return Uint8Array.from($)}});var BJ=V0((xZ)=>{Object.defineProperty(xZ,"__esModule",{value:!0});xZ.Encoder=xZ.DEFAULT_INITIAL_BUFFER_SIZE=xZ.DEFAULT_MAX_DEPTH=void 0;var _Z=w$(),fI=L$(),fZ=k$(),xI=EJ();xZ.DEFAULT_MAX_DEPTH=100;xZ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class LJ{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??fI.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??xZ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??xZ.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 LJ({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($,J){if(J>this.maxDepth)throw Error(`Too deep objects in depth ${J}`);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($,J)}ensureBufferSizeToWrite($){let J=this.pos+$;if(this.view.byteLength<J)this.resizeBuffer(J*2)}resizeBuffer($){let J=new ArrayBuffer($),Q=new Uint8Array(J),Z=new DataView(J);Q.set(this.bytes),this.view=Z,this.bytes=Q}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 Q=(0,_Z.utf8Count)($);this.ensureBufferSizeToWrite(5+Q),this.writeStringHeader(Q),(0,_Z.utf8Encode)($,this.bytes,this.pos),this.pos+=Q}encodeObject($,J){let Q=this.extensionCodec.tryToEncode($,this.context);if(Q!=null)this.encodeExtension(Q);else if(Array.isArray($))this.encodeArray($,J);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,J);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let J=$.byteLength;if(J<256)this.writeU8(196),this.writeU8(J);else if(J<65536)this.writeU8(197),this.writeU16(J);else if(J<4294967296)this.writeU8(198),this.writeU32(J);else throw Error(`Too large binary: ${J}`);let Q=(0,xI.ensureUint8Array)($);this.writeU8a(Q)}encodeArray($,J){let Q=$.length;if(Q<16)this.writeU8(144+Q);else if(Q<65536)this.writeU8(220),this.writeU16(Q);else if(Q<4294967296)this.writeU8(221),this.writeU32(Q);else throw Error(`Too large array: ${Q}`);for(let Z of $)this.doEncode(Z,J+1)}countWithoutUndefined($,J){let Q=0;for(let Z of J)if($[Z]!==void 0)Q++;return Q}encodeMap($,J){let Q=Object.keys($);if(this.sortKeys)Q.sort();let Z=this.ignoreUndefined?this.countWithoutUndefined($,Q):Q.length;if(Z<16)this.writeU8(128+Z);else if(Z<65536)this.writeU8(222),this.writeU16(Z);else if(Z<4294967296)this.writeU8(223),this.writeU32(Z);else throw Error(`Too large map object: ${Z}`);for(let V of Q){let I=$[V];if(!(this.ignoreUndefined&&I===void 0))this.encodeString(V),this.doEncode(I,J+1)}}encodeExtension($){if(typeof $.data==="function"){let Q=$.data(this.pos+6),Z=Q.length;if(Z>=4294967296)throw Error(`Too large extension object: ${Z}`);this.writeU8(201),this.writeU32(Z),this.writeI8($.type),this.writeU8a(Q);return}let J=$.data.length;if(J===1)this.writeU8(212);else if(J===2)this.writeU8(213);else if(J===4)this.writeU8(214);else if(J===8)this.writeU8(215);else if(J===16)this.writeU8(216);else if(J<256)this.writeU8(199),this.writeU8(J);else if(J<65536)this.writeU8(200),this.writeU16(J);else if(J<4294967296)this.writeU8(201),this.writeU32(J);else throw Error(`Too large extension object: ${J}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let J=$.length;this.ensureBufferSizeToWrite(J),this.bytes.set($,this.pos),this.pos+=J}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,fZ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,fZ.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}}xZ.Encoder=LJ});var uZ=V0((bZ)=>{Object.defineProperty(bZ,"__esModule",{value:!0});bZ.encode=vI;var mI=BJ();function vI($,J){return new mI.Encoder(J).encodeSharedRef($)}});var dZ=V0((lZ)=>{Object.defineProperty(lZ,"__esModule",{value:!0});lZ.prettyByte=bI;function bI($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var iZ=V0((rZ)=>{Object.defineProperty(rZ,"__esModule",{value:!0});rZ.CachedKeyDecoder=void 0;var lI=w$(),dI=16,pI=16;class pZ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=dI,J=pI){this.maxKeyLength=$,this.maxLengthPerKey=J,this.caches=[];for(let Q=0;Q<this.maxKeyLength;Q++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,J,Q){let Z=this.caches[Q-1];$:for(let V of Z){let I=V.bytes;for(let X=0;X<Q;X++)if(I[X]!==$[J+X])continue $;return V.str}return null}store($,J){let Q=this.caches[$.length-1],Z={bytes:$,str:J};if(Q.length>=this.maxLengthPerKey)Q[Math.random()*Q.length|0]=Z;else Q.push(Z)}decode($,J,Q){let Z=this.find($,J,Q);if(Z!=null)return this.hit++,Z;this.miss++;let V=(0,lI.utf8DecodeJs)($,J,Q),I=Uint8Array.prototype.slice.call($,J,J+Q);return this.store(I,V),V}}rZ.CachedKeyDecoder=pZ});var B$=V0((sZ)=>{Object.defineProperty(sZ,"__esModule",{value:!0});sZ.Decoder=void 0;var gJ=dZ(),rI=L$(),m0=k$(),cI=w$(),hZ=EJ(),iI=iZ(),F0=j$(),_J="array",I$="map_key",oZ="map_value",hI=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new F0.DecodeError("The type of key must be string or number but "+typeof $)};class aZ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let J=this.getUninitializedStateFromPool();J.type=_J,J.position=0,J.size=$,J.array=Array($)}pushMapState($){let J=this.getUninitializedStateFromPool();J.type=I$,J.readCount=0,J.size=$,J.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===_J){let Q=$;Q.size=0,Q.array=void 0,Q.position=0,Q.type=void 0}if($.type===I$||$.type===oZ){let Q=$;Q.size=0,Q.map=void 0,Q.readCount=0,Q.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var V$=-1,fJ=new DataView(new ArrayBuffer(0)),nI=new Uint8Array(fJ.buffer);try{fJ.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 nZ=RangeError("Insufficient data"),oI=new iI.CachedKeyDecoder;class xJ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=fJ;bytes=nI;headByte=V$;stack=new aZ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??rI.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??m0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??m0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??m0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??m0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??m0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:oI,this.mapKeyConverter=$?.mapKeyConverter??hI}clone(){return new xJ({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=V$,this.stack.reset()}setBuffer($){let J=(0,hZ.ensureUint8Array)($);this.bytes=J,this.view=new DataView(J.buffer,J.byteOffset,J.byteLength),this.pos=0}appendBuffer($){if(this.headByte===V$&&!this.hasRemaining(1))this.setBuffer($);else{let J=this.bytes.subarray(this.pos),Q=(0,hZ.ensureUint8Array)($),Z=new Uint8Array(J.length+Q.length);Z.set(J),Z.set(Q,J.length),this.setBuffer(Z)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:J,pos:Q}=this;return RangeError(`Extra ${J.byteLength-Q} of ${J.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let J=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return J}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 J=!1,Q;for await(let X of $){if(J)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{Q=this.doDecodeSync(),J=!0}catch(G){if(!(G instanceof RangeError))throw G}this.totalPos+=this.pos}if(J){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Q}let{headByte:Z,pos:V,totalPos:I}=this;throw RangeError(`Insufficient data in parsing ${(0,gJ.prettyByte)(Z)} at ${I} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,J){if(this.entered){yield*this.clone().decodeMultiAsync($,J);return}try{this.entered=!0;let Q=J,Z=-1;for await(let V of $){if(J&&Z===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),Q)Z=this.readArraySize(),Q=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Z===0)break}catch(I){if(!(I instanceof RangeError))throw I}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),J;if($>=224)J=$-256;else if($<192)if($<128)J=$;else if($<144){let Z=$-128;if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($<160){let Z=$-144;if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else{let Z=$-160;J=this.decodeString(Z,0)}else if($===192)J=null;else if($===194)J=!1;else if($===195)J=!0;else if($===202)J=this.readF32();else if($===203)J=this.readF64();else if($===204)J=this.readU8();else if($===205)J=this.readU16();else if($===206)J=this.readU32();else if($===207)if(this.useBigInt64)J=this.readU64AsBigInt();else J=this.readU64();else if($===208)J=this.readI8();else if($===209)J=this.readI16();else if($===210)J=this.readI32();else if($===211)if(this.useBigInt64)J=this.readI64AsBigInt();else J=this.readI64();else if($===217){let Z=this.lookU8();J=this.decodeString(Z,1)}else if($===218){let Z=this.lookU16();J=this.decodeString(Z,2)}else if($===219){let Z=this.lookU32();J=this.decodeString(Z,4)}else if($===220){let Z=this.readU16();if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else if($===221){let Z=this.readU32();if(Z!==0){this.pushArrayState(Z),this.complete();continue $}else J=[]}else if($===222){let Z=this.readU16();if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($===223){let Z=this.readU32();if(Z!==0){this.pushMapState(Z),this.complete();continue $}else J={}}else if($===196){let Z=this.lookU8();J=this.decodeBinary(Z,1)}else if($===197){let Z=this.lookU16();J=this.decodeBinary(Z,2)}else if($===198){let Z=this.lookU32();J=this.decodeBinary(Z,4)}else if($===212)J=this.decodeExtension(1,0);else if($===213)J=this.decodeExtension(2,0);else if($===214)J=this.decodeExtension(4,0);else if($===215)J=this.decodeExtension(8,0);else if($===216)J=this.decodeExtension(16,0);else if($===199){let Z=this.lookU8();J=this.decodeExtension(Z,1)}else if($===200){let Z=this.lookU16();J=this.decodeExtension(Z,2)}else if($===201){let Z=this.lookU32();J=this.decodeExtension(Z,4)}else throw new F0.DecodeError(`Unrecognized type byte: ${(0,gJ.prettyByte)($)}`);this.complete();let Q=this.stack;while(Q.length>0){let Z=Q.top();if(Z.type===_J)if(Z.array[Z.position]=J,Z.position++,Z.position===Z.size)J=Z.array,Q.release(Z);else continue $;else if(Z.type===I$){if(J==="__proto__")throw new F0.DecodeError("The key __proto__ is not allowed");Z.key=this.mapKeyConverter(J),Z.type=oZ;continue $}else if(Z.map[Z.key]=J,Z.readCount++,Z.readCount===Z.size)J=Z.map,Q.release(Z);else{Z.key=null,Z.type=I$;continue $}}return J}}readHeadByte(){if(this.headByte===V$)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=V$}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new F0.DecodeError(`Unrecognized array type byte: ${(0,gJ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new F0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new F0.DecodeError(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,J){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,J);return this.decodeBinary($,J)}decodeUtf8String($,J){if($>this.maxStrLength)throw new F0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+J+$)throw nZ;let Q=this.pos+J,Z;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Z=this.keyDecoder.decode(this.bytes,Q,$);else Z=(0,cI.utf8Decode)(this.bytes,Q,$);return this.pos+=J+$,Z}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===I$;return!1}decodeBinary($,J){if($>this.maxBinLength)throw new F0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+J))throw nZ;let Q=this.pos+J,Z=this.bytes.subarray(Q,Q+$);return this.pos+=J+$,Z}decodeExtension($,J){if($>this.maxExtLength)throw new F0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let Q=this.view.getInt8(this.pos+J),Z=this.decodeBinary($,J+1);return this.extensionCodec.decode(Z,Q,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=(0,m0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,m0.getInt64)(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}sZ.Decoder=xJ});var J8=V0(($8)=>{Object.defineProperty($8,"__esModule",{value:!0});$8.decode=aI;$8.decodeMulti=sI;var eZ=B$();function aI($,J){return new eZ.Decoder(J).decode($)}function sI($,J){return new eZ.Decoder(J).decodeMulti($)}});var I8=V0((V8)=>{Object.defineProperty(V8,"__esModule",{value:!0});V8.isAsyncIterable=Q8;V8.asyncIterableFromStream=Z8;V8.ensureAsyncIterable=$X;function Q8($){return $[Symbol.asyncIterator]!=null}async function*Z8($){let J=$.getReader();try{while(!0){let{done:Q,value:Z}=await J.read();if(Q)return;yield Z}}finally{J.releaseLock()}}function $X($){if(Q8($))return $;else return Z8($)}});var Y8=V0((X8)=>{Object.defineProperty(X8,"__esModule",{value:!0});X8.decodeAsync=VX;X8.decodeArrayStream=IX;X8.decodeMultiStream=XX;var mJ=B$(),vJ=I8();async function VX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeAsync(Q)}function IX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeArrayStream(Q)}function XX($,J){let Q=(0,vJ.ensureAsyncIterable)($);return new mJ.Decoder(J).decodeStream(Q)}});var q8=V0((t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.decodeTimestampExtension=t.encodeTimestampExtension=t.decodeTimestampToTimeSpec=t.encodeTimeSpecToTimestamp=t.encodeDateToTimeSpec=t.EXT_TIMESTAMP=t.ExtData=t.ExtensionCodec=t.Encoder=t.DecodeError=t.Decoder=t.decodeMultiStream=t.decodeArrayStream=t.decodeAsync=t.decodeMulti=t.decode=t.encode=void 0;var NX=uZ();Object.defineProperty(t,"encode",{enumerable:!0,get:function(){return NX.encode}});var G8=J8();Object.defineProperty(t,"decode",{enumerable:!0,get:function(){return G8.decode}});Object.defineProperty(t,"decodeMulti",{enumerable:!0,get:function(){return G8.decodeMulti}});var yJ=Y8();Object.defineProperty(t,"decodeAsync",{enumerable:!0,get:function(){return yJ.decodeAsync}});Object.defineProperty(t,"decodeArrayStream",{enumerable:!0,get:function(){return yJ.decodeArrayStream}});Object.defineProperty(t,"decodeMultiStream",{enumerable:!0,get:function(){return yJ.decodeMultiStream}});var KX=B$();Object.defineProperty(t,"Decoder",{enumerable:!0,get:function(){return KX.Decoder}});var MX=j$();Object.defineProperty(t,"DecodeError",{enumerable:!0,get:function(){return MX.DecodeError}});var WX=BJ();Object.defineProperty(t,"Encoder",{enumerable:!0,get:function(){return WX.Encoder}});var UX=L$();Object.defineProperty(t,"ExtensionCodec",{enumerable:!0,get:function(){return UX.ExtensionCodec}});var OX=FJ();Object.defineProperty(t,"ExtData",{enumerable:!0,get:function(){return OX.ExtData}});var o0=jJ();Object.defineProperty(t,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return o0.EXT_TIMESTAMP}});Object.defineProperty(t,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return o0.encodeDateToTimeSpec}});Object.defineProperty(t,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return o0.encodeTimeSpecToTimestamp}});Object.defineProperty(t,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return o0.decodeTimestampToTimeSpec}});Object.defineProperty(t,"encodeTimestampExtension",{enumerable:!0,get:function(){return o0.encodeTimestampExtension}});Object.defineProperty(t,"decodeTimestampExtension",{enumerable:!0,get:function(){return o0.decodeTimestampExtension}})});import*as R0 from"node:crypto";var B0=R0&&typeof R0==="object"&&"webcrypto"in R0?R0.webcrypto:R0&&typeof R0==="object"&&("randomBytes"in R0)?R0:void 0;function Y$($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function _$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function $0($,...J){if(!_$($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function f$($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function aJ($,J){$0($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}function x$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var D0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var B8=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!B8)throw Error("Non little-endian hardware is not supported");function g8($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function G$($){if(typeof $==="string")$=g8($);else if(_$($))$=q$($);else throw Error("Uint8Array expected, got "+typeof $);return $}function sJ($,J){if(J==null||typeof J!=="object")throw Error("options must be defined");return Object.assign($,J)}function tJ($,J){if($.length!==J.length)return!1;let Q=0;for(let Z=0;Z<$.length;Z++)Q|=$[Z]^J[Z];return Q===0}var eJ=($,J)=>{function Q(Z,...V){if($0(Z),$.nonceLength!==void 0){let q=V[0];if(!q)throw Error("nonce / iv required");if($.varSizeNonce)$0(q);else $0(q,$.nonceLength)}let I=$.tagLength;if(I&&V[1]!==void 0)$0(V[1]);let X=J(Z,...V),G=(q,K)=>{if(K!==void 0){if(q!==2)throw Error("cipher output not supported");$0(K)}},Y=!1;return{encrypt(q,K){if(Y)throw Error("cannot encrypt() twice with same key + nonce");return Y=!0,$0(q),G(X.encrypt.length,K),X.encrypt(q,K)},decrypt(q,K){if($0(q),I&&q.length<I)throw Error("invalid ciphertext length: smaller than tagLength="+I);return G(X.decrypt.length,K),X.decrypt(q,K)}}}return Object.assign(Q,$),Q};function m$($,J,Q=!0){if(J===void 0)return new Uint8Array($);if(J.length!==$)throw Error("invalid output length, expected "+$+", got: "+J.length);if(Q&&!_8(J))throw Error("invalid output, must be aligned");return J}function _8($){return $.byteOffset%4===0}function q$($){return Uint8Array.from($)}function z0(...$){for(let J=0;J<$.length;J++)$[J].fill(0)}function N$($=32){if(B0&&typeof B0.getRandomValues==="function")return B0.getRandomValues(new Uint8Array($));if(B0&&typeof B0.randomBytes==="function")return B0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var JQ=($)=>Uint8Array.from($.split("").map((J)=>J.charCodeAt(0))),f8=JQ("expand 16-byte k"),x8=JQ("expand 32-byte k"),m8=D0(f8),v8=D0(x8);function w($,J){return $<<J|$>>>32-J}function v$($){return $.byteOffset%4===0}var K$=64,y8=16,QQ=4294967295,$Q=new Uint32Array;function b8($,J,Q,Z,V,I,X,G){let Y=V.length,N=new Uint8Array(K$),q=D0(N),K=v$(V)&&v$(I),O=K?D0(V):$Q,W=K?D0(I):$Q;for(let H=0;H<Y;X++){if($(J,Q,Z,q,X,G),X>=QQ)throw Error("arx: counter overflow");let T=Math.min(K$,Y-H);if(K&&T===K$){let S=H/4;if(H%4!==0)throw Error("arx: invalid block position");for(let F=0,A;F<y8;F++)A=S+F,W[A]=O[A]^q[F];H+=K$;continue}for(let S=0,F;S<T;S++)F=H+S,I[F]=V[F]^N[S];H+=T}}function ZQ($,J){let{allowShortKeys:Q,extendNonceFn:Z,counterLength:V,counterRight:I,rounds:X}=sJ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},J);if(typeof $!=="function")throw Error("core must be a function");return Y$(V),Y$(X),x$(I),x$(Q),(G,Y,N,q,K=0)=>{$0(G),$0(Y),$0(N);let O=N.length;if(q===void 0)q=new Uint8Array(O);if($0(q),Y$(K),K<0||K>=QQ)throw Error("arx: counter overflow");if(q.length<O)throw Error(`arx: output (${q.length}) is shorter than data (${O})`);let W=[],H=G.length,T,S;if(H===32)W.push(T=q$(G)),S=v8;else if(H===16&&Q)T=new Uint8Array(32),T.set(G),T.set(G,16),S=m8,W.push(T);else throw Error(`arx: invalid 32-byte key, got length=${H}`);if(!v$(Y))W.push(Y=q$(Y));let F=D0(T);if(Z){if(Y.length!==24)throw Error("arx: extended nonce must be 24 bytes");Z(S,F,D0(Y.subarray(0,16)),F),Y=Y.subarray(16)}let A=16-V;if(A!==Y.length)throw Error(`arx: nonce must be ${A} or 16 bytes`);if(A!==12){let P=new Uint8Array(12);P.set(Y,I?0:12-Y.length),Y=P,W.push(Y)}let C=D0(Y);return b8($,S,F,C,N,q,K,X),z0(...W),q}}var Q0=($,J)=>$[J++]&255|($[J++]&255)<<8;class VQ{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,$=G$($),$0($,32);let J=Q0($,0),Q=Q0($,2),Z=Q0($,4),V=Q0($,6),I=Q0($,8),X=Q0($,10),G=Q0($,12),Y=Q0($,14);this.r[0]=J&8191,this.r[1]=(J>>>13|Q<<3)&8191,this.r[2]=(Q>>>10|Z<<6)&7939,this.r[3]=(Z>>>7|V<<9)&8191,this.r[4]=(V>>>4|I<<12)&255,this.r[5]=I>>>1&8190,this.r[6]=(I>>>14|X<<2)&8191,this.r[7]=(X>>>11|G<<5)&8065,this.r[8]=(G>>>8|Y<<8)&8191,this.r[9]=Y>>>5&127;for(let N=0;N<8;N++)this.pad[N]=Q0($,16+2*N)}process($,J,Q=!1){let Z=Q?0:2048,{h:V,r:I}=this,X=I[0],G=I[1],Y=I[2],N=I[3],q=I[4],K=I[5],O=I[6],W=I[7],H=I[8],T=I[9],S=Q0($,J+0),F=Q0($,J+2),A=Q0($,J+4),C=Q0($,J+6),P=Q0($,J+8),x=Q0($,J+10),y=Q0($,J+12),b=Q0($,J+14),_=V[0]+(S&8191),m=V[1]+((S>>>13|F<<3)&8191),d=V[2]+((F>>>10|A<<6)&8191),R=V[3]+((A>>>7|C<<9)&8191),p=V[4]+((C>>>4|P<<12)&8191),r=V[5]+(P>>>1&8191),h=V[6]+((P>>>14|x<<2)&8191),a=V[7]+((x>>>11|y<<5)&8191),U=V[8]+((y>>>8|b<<8)&8191),D=V[9]+(b>>>5|Z),z=0,E=z+_*X+m*(5*T)+d*(5*H)+R*(5*W)+p*(5*O);z=E>>>13,E&=8191,E+=r*(5*K)+h*(5*q)+a*(5*N)+U*(5*Y)+D*(5*G),z+=E>>>13,E&=8191;let B=z+_*G+m*X+d*(5*T)+R*(5*H)+p*(5*W);z=B>>>13,B&=8191,B+=r*(5*O)+h*(5*K)+a*(5*q)+U*(5*N)+D*(5*Y),z+=B>>>13,B&=8191;let L=z+_*Y+m*G+d*X+R*(5*T)+p*(5*H);z=L>>>13,L&=8191,L+=r*(5*W)+h*(5*O)+a*(5*K)+U*(5*q)+D*(5*N),z+=L>>>13,L&=8191;let k=z+_*N+m*Y+d*G+R*X+p*(5*T);z=k>>>13,k&=8191,k+=r*(5*H)+h*(5*W)+a*(5*O)+U*(5*K)+D*(5*q),z+=k>>>13,k&=8191;let f=z+_*q+m*N+d*Y+R*G+p*X;z=f>>>13,f&=8191,f+=r*(5*T)+h*(5*H)+a*(5*W)+U*(5*O)+D*(5*K),z+=f>>>13,f&=8191;let u=z+_*K+m*q+d*N+R*Y+p*G;z=u>>>13,u&=8191,u+=r*X+h*(5*T)+a*(5*H)+U*(5*W)+D*(5*O),z+=u>>>13,u&=8191;let l=z+_*O+m*K+d*q+R*N+p*Y;z=l>>>13,l&=8191,l+=r*G+h*X+a*(5*T)+U*(5*H)+D*(5*W),z+=l>>>13,l&=8191;let i=z+_*W+m*O+d*K+R*q+p*N;z=i>>>13,i&=8191,i+=r*Y+h*G+a*X+U*(5*T)+D*(5*H),z+=i>>>13,i&=8191;let e=z+_*H+m*W+d*O+R*K+p*q;z=e>>>13,e&=8191,e+=r*N+h*Y+a*G+U*X+D*(5*T),z+=e>>>13,e&=8191;let J0=z+_*T+m*H+d*W+R*O+p*K;z=J0>>>13,J0&=8191,J0+=r*q+h*N+a*Y+U*G+D*X,z+=J0>>>13,J0&=8191,z=(z<<2)+z|0,z=z+E|0,E=z&8191,z=z>>>13,B+=z,V[0]=E,V[1]=B,V[2]=L,V[3]=k,V[4]=f,V[5]=u,V[6]=l,V[7]=i,V[8]=e,V[9]=J0}finalize(){let{h:$,pad:J}=this,Q=new Uint16Array(10),Z=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=Z,Z=$[X]>>>13,$[X]&=8191;$[0]+=Z*5,Z=$[0]>>>13,$[0]&=8191,$[1]+=Z,Z=$[1]>>>13,$[1]&=8191,$[2]+=Z,Q[0]=$[0]+5,Z=Q[0]>>>13,Q[0]&=8191;for(let X=1;X<10;X++)Q[X]=$[X]+Z,Z=Q[X]>>>13,Q[X]&=8191;Q[9]-=8192;let V=(Z^1)-1;for(let X=0;X<10;X++)Q[X]&=V;V=~V;for(let X=0;X<10;X++)$[X]=$[X]&V|Q[X];$[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 I=$[0]+J[0];$[0]=I&65535;for(let X=1;X<8;X++)I=($[X]+J[X]|0)+(I>>>16)|0,$[X]=I&65535;z0(Q)}update($){f$(this);let{buffer:J,blockLen:Q}=this;$=G$($);let Z=$.length;for(let V=0;V<Z;){let I=Math.min(Q-this.pos,Z-V);if(I===Q){for(;Q<=Z-V;V+=Q)this.process($,V);continue}if(J.set($.subarray(V,V+I),this.pos),this.pos+=I,V+=I,this.pos===Q)this.process(J,0,!1),this.pos=0}return this}destroy(){z0(this.h,this.r,this.buffer,this.pad)}digestInto($){f$(this),aJ($,this),this.finished=!0;let{buffer:J,h:Q}=this,{pos:Z}=this;if(Z){J[Z++]=1;for(;Z<16;Z++)J[Z]=0;this.process(J,0,!0)}this.finalize();let V=0;for(let I=0;I<8;I++)$[V++]=Q[I]>>>0,$[V++]=Q[I]>>>8;return $}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}}function u8($){let J=(Z,V)=>$(V).update(G$(Z)).digest(),Q=$(new Uint8Array(32));return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=(Z)=>$(Z),J}var y$=u8(($)=>new VQ($));function l8($,J,Q,Z,V,I=20){let X=$[0],G=J[0],Y=J[1],N=J[2],q=J[3],K=$[1],O=Q[0],W=Q[1],H=V,T=0,S=$[2],F=J[4],A=J[5],C=J[6],P=J[7],x=$[3],y=X,b=G,_=Y,m=N,d=q,R=K,p=O,r=W,h=H,a=T,U=S,D=F,z=A,E=C,B=P,L=x;for(let f=0;f<I;f+=2)d^=w(y+z|0,7),h^=w(d+y|0,9),z^=w(h+d|0,13),y^=w(z+h|0,18),a^=w(R+b|0,7),E^=w(a+R|0,9),b^=w(E+a|0,13),R^=w(b+E|0,18),B^=w(U+p|0,7),_^=w(B+U|0,9),p^=w(_+B|0,13),U^=w(p+_|0,18),m^=w(L+D|0,7),r^=w(m+L|0,9),D^=w(r+m|0,13),L^=w(D+r|0,18),b^=w(y+m|0,7),_^=w(b+y|0,9),m^=w(_+b|0,13),y^=w(m+_|0,18),p^=w(R+d|0,7),r^=w(p+R|0,9),d^=w(r+p|0,13),R^=w(d+r|0,18),D^=w(U+a|0,7),h^=w(D+U|0,9),a^=w(h+D|0,13),U^=w(a+h|0,18),z^=w(L+B|0,7),E^=w(z+L|0,9),B^=w(E+z|0,13),L^=w(B+E|0,18);let k=0;Z[k++]=X+y|0,Z[k++]=G+b|0,Z[k++]=Y+_|0,Z[k++]=N+m|0,Z[k++]=q+d|0,Z[k++]=K+R|0,Z[k++]=O+p|0,Z[k++]=W+r|0,Z[k++]=H+h|0,Z[k++]=T+a|0,Z[k++]=S+U|0,Z[k++]=F+D|0,Z[k++]=A+z|0,Z[k++]=C+E|0,Z[k++]=P+B|0,Z[k++]=x+L|0}function d8($,J,Q,Z){let V=$[0],I=J[0],X=J[1],G=J[2],Y=J[3],N=$[1],q=Q[0],K=Q[1],O=Q[2],W=Q[3],H=$[2],T=J[4],S=J[5],F=J[6],A=J[7],C=$[3];for(let x=0;x<20;x+=2)Y^=w(V+S|0,7),O^=w(Y+V|0,9),S^=w(O+Y|0,13),V^=w(S+O|0,18),W^=w(N+I|0,7),F^=w(W+N|0,9),I^=w(F+W|0,13),N^=w(I+F|0,18),A^=w(H+q|0,7),X^=w(A+H|0,9),q^=w(X+A|0,13),H^=w(q+X|0,18),G^=w(C+T|0,7),K^=w(G+C|0,9),T^=w(K+G|0,13),C^=w(T+K|0,18),I^=w(V+G|0,7),X^=w(I+V|0,9),G^=w(X+I|0,13),V^=w(G+X|0,18),q^=w(N+Y|0,7),K^=w(q+N|0,9),Y^=w(K+q|0,13),N^=w(Y+K|0,18),T^=w(H+W|0,7),O^=w(T+H|0,9),W^=w(O+T|0,13),H^=w(W+O|0,18),S^=w(C+A|0,7),F^=w(S+C|0,9),A^=w(F+S|0,13),C^=w(A+F|0,18);let P=0;Z[P++]=V,Z[P++]=N,Z[P++]=H,Z[P++]=C,Z[P++]=q,Z[P++]=K,Z[P++]=O,Z[P++]=W}var b$=ZQ(l8,{counterRight:!0,extendNonceFn:d8}),u$=eJ({blockSize:64,nonceLength:24,tagLength:16},($,J)=>{return{encrypt(Q,Z){Z=m$(Q.length+32,Z,!1);let V=Z.subarray(0,32),I=Z.subarray(32);Z.set(Q,32),z0(V),b$($,J,Z,Z);let X=y$(I,V);return Z.set(X,16),z0(Z.subarray(0,16),X),Z.subarray(16)},decrypt(Q,Z){$0(Q),Z=m$(Q.length+32,Z,!1);let V=Z.subarray(0,32),I=Z.subarray(32,48),X=Z.subarray(48);Z.set(Q,32),z0(V);let G=b$($,J,V,V),Y=y$(X,G);if(!tJ(I,Y))throw Error("invalid tag");return b$($,J,Z.subarray(16),Z.subarray(16)),z0(V,I,Y),X}}});function p8($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function l$($,...J){if(!p8($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function d$($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function IQ($,J){l$($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}import*as A0 from"node:crypto";var g0=A0&&typeof A0==="object"&&"webcrypto"in A0?A0.webcrypto:A0&&typeof A0==="object"&&("randomBytes"in A0)?A0:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var M$=($)=>new DataView($.buffer,$.byteOffset,$.byteLength);function XQ($){if(typeof $!=="string")throw Error("utf8ToBytes expected string, got "+typeof $);return new Uint8Array(new TextEncoder().encode($))}function p$($){if(typeof $==="string")$=XQ($);return l$($),$}class r${clone(){return this._cloneInto()}}function YQ($){let J=(Z)=>$().update(p$(Z)).digest(),Q=$();return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=()=>$(),J}function GQ($=32){if(g0&&typeof g0.getRandomValues==="function")return g0.getRandomValues(new Uint8Array($));if(g0&&typeof g0.randomBytes==="function")return g0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}function r8($,J,Q,Z){if(typeof $.setBigUint64==="function")return $.setBigUint64(J,Q,Z);let V=BigInt(32),I=BigInt(4294967295),X=Number(Q>>V&I),G=Number(Q&I),Y=Z?4:0,N=Z?0:4;$.setUint32(J+Y,X,Z),$.setUint32(J+N,G,Z)}class c$ extends r${constructor($,J,Q,Z){super();this.blockLen=$,this.outputLen=J,this.padOffset=Q,this.isLE=Z,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array($),this.view=M$(this.buffer)}update($){d$(this);let{view:J,buffer:Q,blockLen:Z}=this;$=p$($);let V=$.length;for(let I=0;I<V;){let X=Math.min(Z-this.pos,V-I);if(X===Z){let G=M$($);for(;Z<=V-I;I+=Z)this.process(G,I);continue}if(Q.set($.subarray(I,I+X),this.pos),this.pos+=X,I+=X,this.pos===Z)this.process(J,0),this.pos=0}return this.length+=$.length,this.roundClean(),this}digestInto($){d$(this),IQ($,this),this.finished=!0;let{buffer:J,view:Q,blockLen:Z,isLE:V}=this,{pos:I}=this;if(J[I++]=128,this.buffer.subarray(I).fill(0),this.padOffset>Z-I)this.process(Q,0),I=0;for(let q=I;q<Z;q++)J[q]=0;r8(Q,Z-8,BigInt(this.length*8),V),this.process(Q,0);let X=M$($),G=this.outputLen;if(G%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Y=G/4,N=this.get();if(Y>N.length)throw Error("_sha2: outputLen bigger than state");for(let q=0;q<Y;q++)X.setUint32(4*q,N[q],V)}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}_cloneInto($){$||($=new this.constructor),$.set(...this.get());let{blockLen:J,buffer:Q,length:Z,finished:V,destroyed:I,pos:X}=this;if($.length=Z,$.pos=X,$.finished=V,$.destroyed=I,Z%J)$.buffer.set(Q);return $}}var W$=BigInt(4294967295),i$=BigInt(32);function qQ($,J=!1){if(J)return{h:Number($&W$),l:Number($>>i$&W$)};return{h:Number($>>i$&W$)|0,l:Number($&W$)|0}}function c8($,J=!1){let Q=new Uint32Array($.length),Z=new Uint32Array($.length);for(let V=0;V<$.length;V++){let{h:I,l:X}=qQ($[V],J);[Q[V],Z[V]]=[I,X]}return[Q,Z]}var i8=($,J)=>BigInt($>>>0)<<i$|BigInt(J>>>0),h8=($,J,Q)=>$>>>Q,n8=($,J,Q)=>$<<32-Q|J>>>Q,o8=($,J,Q)=>$>>>Q|J<<32-Q,a8=($,J,Q)=>$<<32-Q|J>>>Q,s8=($,J,Q)=>$<<64-Q|J>>>Q-32,t8=($,J,Q)=>$>>>Q-32|J<<64-Q,e8=($,J)=>J,$V=($,J)=>$,JV=($,J,Q)=>$<<Q|J>>>32-Q,QV=($,J,Q)=>J<<Q|$>>>32-Q,ZV=($,J,Q)=>J<<Q-32|$>>>64-Q,VV=($,J,Q)=>$<<Q-32|J>>>64-Q;function IV($,J,Q,Z){let V=(J>>>0)+(Z>>>0);return{h:$+Q+(V/4294967296|0)|0,l:V|0}}var XV=($,J,Q)=>($>>>0)+(J>>>0)+(Q>>>0),YV=($,J,Q,Z)=>J+Q+Z+($/4294967296|0)|0,GV=($,J,Q,Z)=>($>>>0)+(J>>>0)+(Q>>>0)+(Z>>>0),qV=($,J,Q,Z,V)=>J+Q+Z+V+($/4294967296|0)|0,NV=($,J,Q,Z,V)=>($>>>0)+(J>>>0)+(Q>>>0)+(Z>>>0)+(V>>>0),KV=($,J,Q,Z,V,I)=>J+Q+Z+V+I+($/4294967296|0)|0;var MV={fromBig:qQ,split:c8,toBig:i8,shrSH:h8,shrSL:n8,rotrSH:o8,rotrSL:a8,rotrBH:s8,rotrBL:t8,rotr32H:e8,rotr32L:$V,rotlSH:JV,rotlSL:QV,rotlBH:ZV,rotlBL:VV,add:IV,add3L:XV,add3H:YV,add4L:GV,add4H:qV,add5H:KV,add5L:NV},g=MV;var[WV,UV]=(()=>g.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(($)=>BigInt($))))(),E0=new Uint32Array(80),L0=new Uint32Array(80);class NQ extends c${constructor(){super(128,64,16,!1);this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:$,Al:J,Bh:Q,Bl:Z,Ch:V,Cl:I,Dh:X,Dl:G,Eh:Y,El:N,Fh:q,Fl:K,Gh:O,Gl:W,Hh:H,Hl:T}=this;return[$,J,Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T]}set($,J,Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T){this.Ah=$|0,this.Al=J|0,this.Bh=Q|0,this.Bl=Z|0,this.Ch=V|0,this.Cl=I|0,this.Dh=X|0,this.Dl=G|0,this.Eh=Y|0,this.El=N|0,this.Fh=q|0,this.Fl=K|0,this.Gh=O|0,this.Gl=W|0,this.Hh=H|0,this.Hl=T|0}process($,J){for(let A=0;A<16;A++,J+=4)E0[A]=$.getUint32(J),L0[A]=$.getUint32(J+=4);for(let A=16;A<80;A++){let C=E0[A-15]|0,P=L0[A-15]|0,x=g.rotrSH(C,P,1)^g.rotrSH(C,P,8)^g.shrSH(C,P,7),y=g.rotrSL(C,P,1)^g.rotrSL(C,P,8)^g.shrSL(C,P,7),b=E0[A-2]|0,_=L0[A-2]|0,m=g.rotrSH(b,_,19)^g.rotrBH(b,_,61)^g.shrSH(b,_,6),d=g.rotrSL(b,_,19)^g.rotrBL(b,_,61)^g.shrSL(b,_,6),R=g.add4L(y,d,L0[A-7],L0[A-16]),p=g.add4H(R,x,m,E0[A-7],E0[A-16]);E0[A]=p|0,L0[A]=R|0}let{Ah:Q,Al:Z,Bh:V,Bl:I,Ch:X,Cl:G,Dh:Y,Dl:N,Eh:q,El:K,Fh:O,Fl:W,Gh:H,Gl:T,Hh:S,Hl:F}=this;for(let A=0;A<80;A++){let C=g.rotrSH(q,K,14)^g.rotrSH(q,K,18)^g.rotrBH(q,K,41),P=g.rotrSL(q,K,14)^g.rotrSL(q,K,18)^g.rotrBL(q,K,41),x=q&O^~q&H,y=K&W^~K&T,b=g.add5L(F,P,y,UV[A],L0[A]),_=g.add5H(b,S,C,x,WV[A],E0[A]),m=b|0,d=g.rotrSH(Q,Z,28)^g.rotrBH(Q,Z,34)^g.rotrBH(Q,Z,39),R=g.rotrSL(Q,Z,28)^g.rotrBL(Q,Z,34)^g.rotrBL(Q,Z,39),p=Q&V^Q&X^V&X,r=Z&I^Z&G^I&G;S=H|0,F=T|0,H=O|0,T=W|0,O=q|0,W=K|0,{h:q,l:K}=g.add(Y|0,N|0,_|0,m|0),Y=X|0,N=G|0,X=V|0,G=I|0,V=Q|0,I=Z|0;let h=g.add3L(m,R,r);Q=g.add3H(h,_,d,p),Z=h|0}({h:Q,l:Z}=g.add(this.Ah|0,this.Al|0,Q|0,Z|0)),{h:V,l:I}=g.add(this.Bh|0,this.Bl|0,V|0,I|0),{h:X,l:G}=g.add(this.Ch|0,this.Cl|0,X|0,G|0),{h:Y,l:N}=g.add(this.Dh|0,this.Dl|0,Y|0,N|0),{h:q,l:K}=g.add(this.Eh|0,this.El|0,q|0,K|0),{h:O,l:W}=g.add(this.Fh|0,this.Fl|0,O|0,W|0),{h:H,l:T}=g.add(this.Gh|0,this.Gl|0,H|0,T|0),{h:S,l:F}=g.add(this.Hh|0,this.Hl|0,S|0,F|0),this.set(Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T,S,F)}roundClean(){E0.fill(0),L0.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}var KQ=YQ(()=>new NQ);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var n$=BigInt(0),WQ=BigInt(1),OV=BigInt(2);function o$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function a$($){if(!o$($))throw Error("Uint8Array expected")}function U$($,J){if(typeof J!=="boolean")throw Error($+" boolean expected, got "+J)}var zV=Array.from({length:256},($,J)=>J.toString(16).padStart(2,"0"));function O$($){a$($);let J="";for(let Q=0;Q<$.length;Q++)J+=zV[$[Q]];return J}function UQ($){if(typeof $!=="string")throw Error("hex string expected, got "+typeof $);return $===""?n$:BigInt("0x"+$)}var C0={_0:48,_9:57,A:65,F:70,a:97,f:102};function MQ($){if($>=C0._0&&$<=C0._9)return $-C0._0;if($>=C0.A&&$<=C0.F)return $-(C0.A-10);if($>=C0.a&&$<=C0.f)return $-(C0.a-10);return}function OQ($){if(typeof $!=="string")throw Error("hex string expected, got "+typeof $);let J=$.length,Q=J/2;if(J%2)throw Error("hex string expected, got unpadded hex of length "+J);let Z=new Uint8Array(Q);for(let V=0,I=0;V<Q;V++,I+=2){let X=MQ($.charCodeAt(I)),G=MQ($.charCodeAt(I+1));if(X===void 0||G===void 0){let Y=$[I]+$[I+1];throw Error('hex string expected, got non-hex character "'+Y+'" at index '+I)}Z[V]=X*16+G}return Z}function zQ($){return UQ(O$($))}function v0($){return a$($),UQ(O$(Uint8Array.from($).reverse()))}function s$($,J){return OQ($.toString(16).padStart(J*2,"0"))}function s0($,J){return s$($,J).reverse()}function M0($,J,Q){let Z;if(typeof J==="string")try{Z=OQ(J)}catch(I){throw Error($+" must be hex string or Uint8Array, cause: "+I)}else if(o$(J))Z=Uint8Array.from(J);else throw Error($+" must be hex string or Uint8Array");let V=Z.length;if(typeof Q==="number"&&V!==Q)throw Error($+" of length "+Q+" expected, got "+V);return Z}function t$(...$){let J=0;for(let Z=0;Z<$.length;Z++){let V=$[Z];a$(V),J+=V.length}let Q=new Uint8Array(J);for(let Z=0,V=0;Z<$.length;Z++){let I=$[Z];Q.set(I,V),V+=I.length}return Q}var h$=($)=>typeof $==="bigint"&&n$<=$;function HV($,J,Q){return h$($)&&h$(J)&&h$(Q)&&J<=$&&$<Q}function y0($,J,Q,Z){if(!HV(J,Q,Z))throw Error("expected valid "+$+": "+Q+" <= n < "+Z+", got "+J)}function HQ($){let J;for(J=0;$>n$;$>>=WQ,J+=1);return J}var TQ=($)=>(OV<<BigInt($-1))-WQ;var TV={bigint:($)=>typeof $==="bigint",function:($)=>typeof $==="function",boolean:($)=>typeof $==="boolean",string:($)=>typeof $==="string",stringOrUint8Array:($)=>typeof $==="string"||o$($),isSafeInteger:($)=>Number.isSafeInteger($),array:($)=>Array.isArray($),field:($,J)=>J.Fp.isValid($),hash:($)=>typeof $==="function"&&Number.isSafeInteger($.outputLen)};function b0($,J,Q={}){let Z=(V,I,X)=>{let G=TV[I];if(typeof G!=="function")throw Error("invalid validator function");let Y=$[V];if(X&&Y===void 0)return;if(!G(Y,$))throw Error("param "+String(V)+" is invalid. Expected "+I+", got "+Y)};for(let[V,I]of Object.entries(J))Z(V,I,!1);for(let[V,I]of Object.entries(Q))Z(V,I,!0);return $}function e$($){let J=new WeakMap;return(Q,...Z)=>{let V=J.get(Q);if(V!==void 0)return V;let I=$(Q,...Z);return J.set(Q,I),I}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var s=BigInt(0),n=BigInt(1),_0=BigInt(2),DV=BigInt(3),$J=BigInt(4),RQ=BigInt(5),DQ=BigInt(8),AV=BigInt(9),CV=BigInt(16);function o($,J){let Q=$%J;return Q>=s?Q:J+Q}function PV($,J,Q){if(J<s)throw Error("invalid exponent, negatives unsupported");if(Q<=s)throw Error("invalid modulus");if(Q===n)return s;let Z=n;while(J>s){if(J&n)Z=Z*$%Q;$=$*$%Q,J>>=n}return Z}function W0($,J,Q){let Z=$;while(J-- >s)Z*=Z,Z%=Q;return Z}function AQ($,J){if($===s)throw Error("invert: expected non-zero number");if(J<=s)throw Error("invert: expected positive modulus, got "+J);let Q=o($,J),Z=J,V=s,I=n,X=n,G=s;while(Q!==s){let N=Z/Q,q=Z%Q,K=V-X*N,O=I-G*N;Z=Q,Q=q,V=X,I=G,X=K,G=O}if(Z!==n)throw Error("invert: does not exist");return o(V,J)}function SV($){let J=($-n)/_0,Q,Z,V;for(Q=$-n,Z=0;Q%_0===s;Q/=_0,Z++);for(V=_0;V<$&&PV(V,J,$)!==$-n;V++)if(V>1000)throw Error("Cannot find square root: likely non-prime P");if(Z===1){let X=($+n)/$J;return function(Y,N){let q=Y.pow(N,X);if(!Y.eql(Y.sqr(q),N))throw Error("Cannot find square root");return q}}let I=(Q+n)/_0;return function(G,Y){if(G.pow(Y,J)===G.neg(G.ONE))throw Error("Cannot find square root");let N=Z,q=G.pow(G.mul(G.ONE,V),Q),K=G.pow(Y,I),O=G.pow(Y,Q);while(!G.eql(O,G.ONE)){if(G.eql(O,G.ZERO))return G.ZERO;let W=1;for(let T=G.sqr(O);W<N;W++){if(G.eql(T,G.ONE))break;T=G.sqr(T)}let H=G.pow(q,n<<BigInt(N-W-1));q=G.sqr(H),K=G.mul(K,H),O=G.mul(O,q),N=W}return K}}function wV($){if($%$J===DV){let J=($+n)/$J;return function(Z,V){let I=Z.pow(V,J);if(!Z.eql(Z.sqr(I),V))throw Error("Cannot find square root");return I}}if($%DQ===RQ){let J=($-RQ)/DQ;return function(Z,V){let I=Z.mul(V,_0),X=Z.pow(I,J),G=Z.mul(V,X),Y=Z.mul(Z.mul(G,_0),X),N=Z.mul(G,Z.sub(Y,Z.ONE));if(!Z.eql(Z.sqr(N),V))throw Error("Cannot find square root");return N}}if($%CV===AV);return SV($)}var CQ=($,J)=>(o($,J)&n)===n,FV=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function PQ($){let J={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},Q=FV.reduce((Z,V)=>{return Z[V]="function",Z},J);return b0($,Q)}function jV($,J,Q){if(Q<s)throw Error("invalid exponent, negatives unsupported");if(Q===s)return $.ONE;if(Q===n)return J;let Z=$.ONE,V=J;while(Q>s){if(Q&n)Z=$.mul(Z,V);V=$.sqr(V),Q>>=n}return Z}function kV($,J){let Q=Array(J.length),Z=J.reduce((I,X,G)=>{if($.is0(X))return I;return Q[G]=I,$.mul(I,X)},$.ONE),V=$.inv(Z);return J.reduceRight((I,X,G)=>{if($.is0(X))return I;return Q[G]=$.mul(I,Q[G]),$.mul(I,X)},V),Q}function JJ($,J){let Q=J!==void 0?J:$.toString(2).length,Z=Math.ceil(Q/8);return{nBitLength:Q,nByteLength:Z}}function z$($,J,Q=!1,Z={}){if($<=s)throw Error("invalid field: expected ORDER > 0, got "+$);let{nBitLength:V,nByteLength:I}=JJ($,J);if(I>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let X,G=Object.freeze({ORDER:$,isLE:Q,BITS:V,BYTES:I,MASK:TQ(V),ZERO:s,ONE:n,create:(Y)=>o(Y,$),isValid:(Y)=>{if(typeof Y!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof Y);return s<=Y&&Y<$},is0:(Y)=>Y===s,isOdd:(Y)=>(Y&n)===n,neg:(Y)=>o(-Y,$),eql:(Y,N)=>Y===N,sqr:(Y)=>o(Y*Y,$),add:(Y,N)=>o(Y+N,$),sub:(Y,N)=>o(Y-N,$),mul:(Y,N)=>o(Y*N,$),pow:(Y,N)=>jV(G,Y,N),div:(Y,N)=>o(Y*AQ(N,$),$),sqrN:(Y)=>Y*Y,addN:(Y,N)=>Y+N,subN:(Y,N)=>Y-N,mulN:(Y,N)=>Y*N,inv:(Y)=>AQ(Y,$),sqrt:Z.sqrt||((Y)=>{if(!X)X=wV($);return X(G,Y)}),invertBatch:(Y)=>kV(G,Y),cmov:(Y,N,q)=>q?N:Y,toBytes:(Y)=>Q?s0(Y,I):s$(Y,I),fromBytes:(Y)=>{if(Y.length!==I)throw Error("Field.fromBytes: expected "+I+" bytes, got "+Y.length);return Q?v0(Y):zQ(Y)}});return Object.freeze(G)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var SQ=BigInt(0),H$=BigInt(1);function QJ($,J){let Q=J.negate();return $?Q:J}function wQ($,J){if(!Number.isSafeInteger($)||$<=0||$>J)throw Error("invalid window size, expected [1.."+J+"], got W="+$)}function ZJ($,J){wQ($,J);let Q=Math.ceil(J/$)+1,Z=2**($-1);return{windows:Q,windowSize:Z}}function EV($,J){if(!Array.isArray($))throw Error("array expected");$.forEach((Q,Z)=>{if(!(Q instanceof J))throw Error("invalid point at index "+Z)})}function LV($,J){if(!Array.isArray($))throw Error("array of scalars expected");$.forEach((Q,Z)=>{if(!J.isValid(Q))throw Error("invalid scalar at index "+Z)})}var VJ=new WeakMap,FQ=new WeakMap;function IJ($){return FQ.get($)||1}function jQ($,J){return{constTimeNegate:QJ,hasPrecomputes(Q){return IJ(Q)!==1},unsafeLadder(Q,Z,V=$.ZERO){let I=Q;while(Z>SQ){if(Z&H$)V=V.add(I);I=I.double(),Z>>=H$}return V},precomputeWindow(Q,Z){let{windows:V,windowSize:I}=ZJ(Z,J),X=[],G=Q,Y=G;for(let N=0;N<V;N++){Y=G,X.push(Y);for(let q=1;q<I;q++)Y=Y.add(G),X.push(Y);G=Y.double()}return X},wNAF(Q,Z,V){let{windows:I,windowSize:X}=ZJ(Q,J),G=$.ZERO,Y=$.BASE,N=BigInt(2**Q-1),q=2**Q,K=BigInt(Q);for(let O=0;O<I;O++){let W=O*X,H=Number(V&N);if(V>>=K,H>X)H-=q,V+=H$;let T=W,S=W+Math.abs(H)-1,F=O%2!==0,A=H<0;if(H===0)Y=Y.add(QJ(F,Z[T]));else G=G.add(QJ(A,Z[S]))}return{p:G,f:Y}},wNAFUnsafe(Q,Z,V,I=$.ZERO){let{windows:X,windowSize:G}=ZJ(Q,J),Y=BigInt(2**Q-1),N=2**Q,q=BigInt(Q);for(let K=0;K<X;K++){let O=K*G;if(V===SQ)break;let W=Number(V&Y);if(V>>=q,W>G)W-=N,V+=H$;if(W===0)continue;let H=Z[O+Math.abs(W)-1];if(W<0)H=H.negate();I=I.add(H)}return I},getPrecomputes(Q,Z,V){let I=VJ.get(Z);if(!I){if(I=this.precomputeWindow(Z,Q),Q!==1)VJ.set(Z,V(I))}return I},wNAFCached(Q,Z,V){let I=IJ(Q);return this.wNAF(I,this.getPrecomputes(I,Q,V),Z)},wNAFCachedUnsafe(Q,Z,V,I){let X=IJ(Q);if(X===1)return this.unsafeLadder(Q,Z,I);return this.wNAFUnsafe(X,this.getPrecomputes(X,Q,V),Z,I)},setWindowSize(Q,Z){wQ(Z,J),FQ.set(Q,Z),VJ.delete(Q)}}}function kQ($,J,Q,Z){if(EV(Q,$),LV(Z,J),Q.length!==Z.length)throw Error("arrays of points and scalars must have equal length");let V=$.ZERO,I=HQ(BigInt(Q.length)),X=I>12?I-3:I>4?I-2:I?2:1,G=(1<<X)-1,Y=Array(G+1).fill(V),N=Math.floor((J.BITS-1)/X)*X,q=V;for(let K=N;K>=0;K-=X){Y.fill(V);for(let W=0;W<Z.length;W++){let H=Z[W],T=Number(H>>BigInt(K)&BigInt(G));Y[T]=Y[T].add(Q[W])}let O=V;for(let W=Y.length-1,H=V;W>0;W--)H=H.add(Y[W]),O=O.add(H);if(q=q.add(O),K!==0)for(let W=0;W<X;W++)q=q.double()}return q}function EQ($){return PQ($.Fp),b0($,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...JJ($.n,$.nBitLength),...$,...{p:$.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var U0=BigInt(0),G0=BigInt(1),T$=BigInt(2),BV=BigInt(8),gV={zip215:!0};function _V($){let J=EQ($);return b0($,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...J})}function LQ($){let J=_V($),{Fp:Q,n:Z,prehash:V,hash:I,randomBytes:X,nByteLength:G,h:Y}=J,N=T$<<BigInt(G*8)-G0,q=Q.create,K=z$(J.n,J.nBitLength),O=J.uvRatio||((U,D)=>{try{return{isValid:!0,value:Q.sqrt(U*Q.inv(D))}}catch(z){return{isValid:!1,value:U0}}}),W=J.adjustScalarBytes||((U)=>U),H=J.domain||((U,D,z)=>{if(U$("phflag",z),D.length||z)throw Error("Contexts/pre-hash are not supported");return U});function T(U,D){y0("coordinate "+U,D,U0,N)}function S(U){if(!(U instanceof C))throw Error("ExtendedPoint expected")}let F=e$((U,D)=>{let{ex:z,ey:E,ez:B}=U,L=U.is0();if(D==null)D=L?BV:Q.inv(B);let k=q(z*D),f=q(E*D),u=q(B*D);if(L)return{x:U0,y:G0};if(u!==G0)throw Error("invZ was invalid");return{x:k,y:f}}),A=e$((U)=>{let{a:D,d:z}=J;if(U.is0())throw Error("bad point: ZERO");let{ex:E,ey:B,ez:L,et:k}=U,f=q(E*E),u=q(B*B),l=q(L*L),i=q(l*l),e=q(f*D),J0=q(l*q(e+u)),q0=q(i+q(z*q(f*u)));if(J0!==q0)throw Error("bad point: equation left != right (1)");let k0=q(E*B),T0=q(L*k);if(k0!==T0)throw Error("bad point: equation left != right (2)");return!0});class C{constructor(U,D,z,E){this.ex=U,this.ey=D,this.ez=z,this.et=E,T("x",U),T("y",D),T("z",z),T("t",E),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(U){if(U instanceof C)throw Error("extended point not allowed");let{x:D,y:z}=U||{};return T("x",D),T("y",z),new C(D,z,G0,q(D*z))}static normalizeZ(U){let D=Q.invertBatch(U.map((z)=>z.ez));return U.map((z,E)=>z.toAffine(D[E])).map(C.fromAffine)}static msm(U,D){return kQ(C,K,U,D)}_setWindowSize(U){y.setWindowSize(this,U)}assertValidity(){A(this)}equals(U){S(U);let{ex:D,ey:z,ez:E}=this,{ex:B,ey:L,ez:k}=U,f=q(D*k),u=q(B*E),l=q(z*k),i=q(L*E);return f===u&&l===i}is0(){return this.equals(C.ZERO)}negate(){return new C(q(-this.ex),this.ey,this.ez,q(-this.et))}double(){let{a:U}=J,{ex:D,ey:z,ez:E}=this,B=q(D*D),L=q(z*z),k=q(T$*q(E*E)),f=q(U*B),u=D+z,l=q(q(u*u)-B-L),i=f+L,e=i-k,J0=f-L,q0=q(l*e),k0=q(i*J0),T0=q(l*J0),X$=q(e*i);return new C(q0,k0,X$,T0)}add(U){S(U);let{a:D,d:z}=J,{ex:E,ey:B,ez:L,et:k}=this,{ex:f,ey:u,ez:l,et:i}=U;if(D===BigInt(-1)){let dJ=q((B-E)*(u+f)),pJ=q((B+E)*(u-f)),g$=q(pJ-dJ);if(g$===U0)return this.double();let rJ=q(L*T$*i),cJ=q(k*T$*l),iJ=cJ+rJ,hJ=pJ+dJ,nJ=cJ-rJ,R8=q(iJ*g$),D8=q(hJ*nJ),A8=q(iJ*nJ),C8=q(g$*hJ);return new C(R8,D8,C8,A8)}let e=q(E*f),J0=q(B*u),q0=q(k*z*i),k0=q(L*l),T0=q((E+B)*(f+u)-e-J0),X$=k0-q0,uJ=k0+q0,lJ=q(J0-D*e),O8=q(T0*X$),z8=q(uJ*lJ),H8=q(T0*lJ),T8=q(X$*uJ);return new C(O8,z8,T8,H8)}subtract(U){return this.add(U.negate())}wNAF(U){return y.wNAFCached(this,U,C.normalizeZ)}multiply(U){let D=U;y0("scalar",D,G0,Z);let{p:z,f:E}=this.wNAF(D);return C.normalizeZ([z,E])[0]}multiplyUnsafe(U,D=C.ZERO){let z=U;if(y0("scalar",z,U0,Z),z===U0)return x;if(this.is0()||z===G0)return this;return y.wNAFCachedUnsafe(this,z,C.normalizeZ,D)}isSmallOrder(){return this.multiplyUnsafe(Y).is0()}isTorsionFree(){return y.unsafeLadder(this,Z).is0()}toAffine(U){return F(this,U)}clearCofactor(){let{h:U}=J;if(U===G0)return this;return this.multiplyUnsafe(U)}static fromHex(U,D=!1){let{d:z,a:E}=J,B=Q.BYTES;U=M0("pointHex",U,B),U$("zip215",D);let L=U.slice(),k=U[B-1];L[B-1]=k&-129;let f=v0(L),u=D?N:Q.ORDER;y0("pointHex.y",f,U0,u);let l=q(f*f),i=q(l-G0),e=q(z*l-E),{isValid:J0,value:q0}=O(i,e);if(!J0)throw Error("Point.fromHex: invalid y coordinate");let k0=(q0&G0)===G0,T0=(k&128)!==0;if(!D&&q0===U0&&T0)throw Error("Point.fromHex: x=0 and x_0=1");if(T0!==k0)q0=q(-q0);return C.fromAffine({x:q0,y:f})}static fromPrivateKey(U){return m(U).point}toRawBytes(){let{x:U,y:D}=this.toAffine(),z=s0(D,Q.BYTES);return z[z.length-1]|=U&G0?128:0,z}toHex(){return O$(this.toRawBytes())}}C.BASE=new C(J.Gx,J.Gy,G0,q(J.Gx*J.Gy)),C.ZERO=new C(U0,G0,G0,U0);let{BASE:P,ZERO:x}=C,y=jQ(C,G*8);function b(U){return o(U,Z)}function _(U){return b(v0(U))}function m(U){let D=Q.BYTES;U=M0("private key",U,D);let z=M0("hashed private key",I(U),2*D),E=W(z.slice(0,D)),B=z.slice(D,2*D),L=_(E),k=P.multiply(L),f=k.toRawBytes();return{head:E,prefix:B,scalar:L,point:k,pointBytes:f}}function d(U){return m(U).pointBytes}function R(U=new Uint8Array,...D){let z=t$(...D);return _(I(H(z,M0("context",U),!!V)))}function p(U,D,z={}){if(U=M0("message",U),V)U=V(U);let{prefix:E,scalar:B,pointBytes:L}=m(D),k=R(z.context,E,U),f=P.multiply(k).toRawBytes(),u=R(z.context,f,L,U),l=b(k+u*B);y0("signature.s",l,U0,Z);let i=t$(f,s0(l,Q.BYTES));return M0("result",i,Q.BYTES*2)}let r=gV;function h(U,D,z,E=r){let{context:B,zip215:L}=E,k=Q.BYTES;if(U=M0("signature",U,2*k),D=M0("message",D),z=M0("publicKey",z,k),L!==void 0)U$("zip215",L);if(V)D=V(D);let f=v0(U.slice(k,2*k)),u,l,i;try{u=C.fromHex(z,L),l=C.fromHex(U.slice(0,k),L),i=P.multiplyUnsafe(f)}catch(q0){return!1}if(!L&&u.isSmallOrder())return!1;let e=R(B,l.toRawBytes(),u.toRawBytes(),D);return l.add(u.multiplyUnsafe(e)).subtract(i).clearCofactor().equals(C.ZERO)}return P._setWindowSize(8),{CURVE:J,getPublicKey:d,sign:p,verify:h,ExtendedPoint:C,utils:{getExtendedPublicKey:m,randomPrivateKey:()=>X(Q.BYTES),precompute(U=8,D=C.BASE){return D._setWindowSize(U),D.multiply(BigInt(3)),D}}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var XJ=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),BQ=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),OY=BigInt(0),fV=BigInt(1),gQ=BigInt(2),zY=BigInt(3),xV=BigInt(5),mV=BigInt(8);function vV($){let J=BigInt(10),Q=BigInt(20),Z=BigInt(40),V=BigInt(80),I=XJ,G=$*$%I*$%I,Y=W0(G,gQ,I)*G%I,N=W0(Y,fV,I)*$%I,q=W0(N,xV,I)*N%I,K=W0(q,J,I)*q%I,O=W0(K,Q,I)*K%I,W=W0(O,Z,I)*O%I,H=W0(W,V,I)*W%I,T=W0(H,V,I)*W%I,S=W0(T,J,I)*q%I;return{pow_p_5_8:W0(S,gQ,I)*$%I,b2:G}}function yV($){return $[0]&=248,$[31]&=127,$[31]|=64,$}function bV($,J){let Q=XJ,Z=o(J*J*J,Q),V=o(Z*Z*J,Q),I=vV($*V).pow_p_5_8,X=o($*Z*I,Q),G=o(J*X*X,Q),Y=X,N=o(X*BQ,Q),q=G===$,K=G===o(-$,Q),O=G===o(-$*BQ,Q);if(q)X=Y;if(K||O)X=N;if(CQ(X,Q))X=o(-X,Q);return{isValid:q||K,value:X}}var uV=(()=>z$(XJ,void 0,!0))(),lV=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:uV,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:mV,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:KQ,randomBytes:GQ,adjustScalarBytes:yV,uvRatio:bV}))(),R$=(()=>LQ(lV))();/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function dV($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function t0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function f0($,...J){if(!dV($))throw Error("Uint8Array expected");if(J.length>0&&!J.includes($.length))throw Error("Uint8Array expected of length "+J+", got length="+$.length)}function e0($,J=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(J&&$.finished)throw Error("Hash#digest() has already been called")}function D$($,J){f0($);let Q=J.outputLen;if($.length<Q)throw Error("digestInto() expects output buffer of length at least "+Q)}function _Q($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function u0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function l0(...$){for(let J=0;J<$.length;J++)$[J].fill(0)}function $$($,J){return $<<32-J|$>>>J}var fQ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function xQ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var mQ=fQ?($)=>$:($)=>xQ($);function pV($){for(let J=0;J<$.length;J++)$[J]=xQ($[J]);return $}var Y0=fQ?($)=>$:pV;function rV($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function d0($){if(typeof $==="string")$=rV($);return f0($),$}class YJ{}function vQ($){let J=(Z,V)=>$(V).update(d0(Z)).digest(),Q=$({});return J.outputLen=Q.outputLen,J.blockLen=Q.blockLen,J.create=(Z)=>$(Z),J}var yQ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var A$=BigInt(4294967295),bQ=BigInt(32);function GJ($,J=!1){if(J)return{h:Number($&A$),l:Number($>>bQ&A$)};return{h:Number($>>bQ&A$)|0,l:Number($&A$)|0}}function P0($,J,Q,Z,V){return $=$+J+V|0,Z=$$(Z^$,16),Q=Q+Z|0,J=$$(J^Q,12),{a:$,b:J,c:Q,d:Z}}function S0($,J,Q,Z,V){return $=$+J+V|0,Z=$$(Z^$,8),Q=Q+Z|0,J=$$(J^Q,7),{a:$,b:J,c:Q,d:Z}}class qJ extends YJ{constructor($,J){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,t0($),t0(J),this.blockLen=$,this.outputLen=J,this.buffer=new Uint8Array($),this.buffer32=u0(this.buffer)}update($){e0(this),$=d0($),f0($);let{blockLen:J,buffer:Q,buffer32:Z}=this,V=$.length,I=$.byteOffset,X=$.buffer;for(let G=0;G<V;){if(this.pos===J)Y0(Z),this.compress(Z,0,!1),Y0(Z),this.pos=0;let Y=Math.min(J-this.pos,V-G),N=I+G;if(Y===J&&!(N%4)&&G+Y<V){let q=new Uint32Array(X,N,Math.floor((V-G)/4));Y0(q);for(let K=0;G+J<V;K+=Z.length,G+=J)this.length+=J,this.compress(q,K,!1);Y0(q);continue}Q.set($.subarray(G,G+Y),this.pos),this.pos+=Y,this.length+=Y,G+=Y}return this}digestInto($){e0(this),D$($,this);let{pos:J,buffer32:Q}=this;this.finished=!0,l0(this.buffer.subarray(J)),Y0(Q),this.compress(Q,0,!0),Y0(Q);let Z=u0($);this.get().forEach((V,I)=>Z[I]=mQ(V))}digest(){let{buffer:$,outputLen:J}=this;this.digestInto($);let Q=$.slice(0,J);return this.destroy(),Q}_cloneInto($){let{buffer:J,length:Q,finished:Z,destroyed:V,outputLen:I,pos:X}=this;return $||($=new this.constructor({dkLen:I})),$.set(...this.get()),$.buffer.set(J),$.destroyed=V,$.finished=Z,$.length=Q,$.pos=X,$.outputLen=I,$}clone(){return this._cloneInto()}}function NJ($,J,Q,Z,V,I,X,G,Y,N,q,K,O,W,H,T,S,F,A,C){let P=0;for(let x=0;x<Z;x++)({a:V,b:Y,c:O,d:S}=P0(V,Y,O,S,Q[J+$[P++]])),{a:V,b:Y,c:O,d:S}=S0(V,Y,O,S,Q[J+$[P++]]),{a:I,b:N,c:W,d:F}=P0(I,N,W,F,Q[J+$[P++]]),{a:I,b:N,c:W,d:F}=S0(I,N,W,F,Q[J+$[P++]]),{a:X,b:q,c:H,d:A}=P0(X,q,H,A,Q[J+$[P++]]),{a:X,b:q,c:H,d:A}=S0(X,q,H,A,Q[J+$[P++]]),{a:G,b:K,c:T,d:C}=P0(G,K,T,C,Q[J+$[P++]]),{a:G,b:K,c:T,d:C}=S0(G,K,T,C,Q[J+$[P++]]),{a:V,b:N,c:H,d:C}=P0(V,N,H,C,Q[J+$[P++]]),{a:V,b:N,c:H,d:C}=S0(V,N,H,C,Q[J+$[P++]]),{a:I,b:q,c:T,d:S}=P0(I,q,T,S,Q[J+$[P++]]),{a:I,b:q,c:T,d:S}=S0(I,q,T,S,Q[J+$[P++]]),{a:X,b:K,c:O,d:F}=P0(X,K,O,F,Q[J+$[P++]]),{a:X,b:K,c:O,d:F}=S0(X,K,O,F,Q[J+$[P++]]),{a:G,b:Y,c:W,d:A}=P0(G,Y,W,A,Q[J+$[P++]]),{a:G,b:Y,c:W,d:A}=S0(G,Y,W,A,Q[J+$[P++]]);return{v0:V,v1:I,v2:X,v3:G,v4:Y,v5:N,v6:q,v7:K,v8:O,v9:W,v10:H,v11:T,v12:S,v13:F,v14:A,v15:C}}var H0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},w0=yQ.slice(),uQ=(()=>{let $=Array.from({length:16},(Z,V)=>V),J=(Z)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Z[V]),Q=[];for(let Z=0,V=$;Z<7;Z++,V=J(V))Q.push(...V);return Uint8Array.from(Q)})();class KJ extends qJ{constructor($={},J=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:Q,context:Z}=$,V=Z!==void 0;if(Q!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let I=d0(Q).slice();f0(I,32),this.IV=u0(I),Y0(this.IV),this.flags=J|H0.KEYED_HASH}else if(V){let I=d0(Z),X=new KJ({dkLen:32},H0.DERIVE_KEY_CONTEXT).update(I).digest();this.IV=u0(X),Y0(this.IV),this.flags=J|H0.DERIVE_KEY_MATERIAL}else this.IV=w0.slice(),this.flags=J;this.state=this.IV.slice(),this.bufferOut=_Q(this.bufferOut32)}get(){return[]}set(){}b2Compress($,J,Q,Z=0){let{state:V,pos:I}=this,{h:X,l:G}=GJ(BigInt($),!0),{v0:Y,v1:N,v2:q,v3:K,v4:O,v5:W,v6:H,v7:T,v8:S,v9:F,v10:A,v11:C,v12:P,v13:x,v14:y,v15:b}=NJ(uQ,Z,Q,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],w0[0],w0[1],w0[2],w0[3],X,G,I,J);V[0]=Y^S,V[1]=N^F,V[2]=q^A,V[3]=K^C,V[4]=O^P,V[5]=W^x,V[6]=H^y,V[7]=T^b}compress($,J=0,Q=!1){let Z=this.flags;if(!this.chunkPos)Z|=H0.CHUNK_START;if(this.chunkPos===15||Q)Z|=H0.CHUNK_END;if(!Q)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Z,$,J),this.chunkPos+=1,this.chunkPos===16||Q){let V=this.state;this.state=this.IV.slice();for(let I,X=this.chunksDone+1;Q||!(X&1);X>>=1){if(!(I=this.stack.pop()))break;this.buffer32.set(I,0),this.buffer32.set(V,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|H0.PARENT,this.buffer32,0),V=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(V)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:J,flags:Q,state:Z,chunkPos:V,posOut:I,chunkOut:X,stack:G,chunksDone:Y}=this;return $.state.set(Z.slice()),$.stack=G.map((N)=>Uint32Array.from(N)),$.IV.set(J),$.flags=Q,$.chunkPos=V,$.chunksDone=Y,$.posOut=I,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,l0(this.state,this.buffer32,this.IV,this.bufferOut32),l0(...this.stack)}b2CompressOut(){let{state:$,pos:J,flags:Q,buffer32:Z,bufferOut32:V}=this,{h:I,l:X}=GJ(BigInt(this.chunkOut++));Y0(Z);let{v0:G,v1:Y,v2:N,v3:q,v4:K,v5:O,v6:W,v7:H,v8:T,v9:S,v10:F,v11:A,v12:C,v13:P,v14:x,v15:y}=NJ(uQ,0,Z,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],w0[0],w0[1],w0[2],w0[3],X,I,J,Q);V[0]=G^T,V[1]=Y^S,V[2]=N^F,V[3]=q^A,V[4]=K^C,V[5]=O^P,V[6]=W^x,V[7]=H^y,V[8]=$[0]^T,V[9]=$[1]^S,V[10]=$[2]^F,V[11]=$[3]^A,V[12]=$[4]^C,V[13]=$[5]^P,V[14]=$[6]^x,V[15]=$[7]^y,Y0(Z),Y0(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,l0(this.buffer.subarray(this.pos));let $=this.flags|H0.ROOT;if(this.stack.length)$|=H0.PARENT,Y0(this.buffer32),this.compress(this.buffer32,0,!0),Y0(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?H0.CHUNK_START:0)|H0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){e0(this,!1),f0($),this.finish();let{blockLen:J,bufferOut:Q}=this;for(let Z=0,V=$.length;Z<V;){if(this.posOut>=J)this.b2CompressOut();let I=Math.min(J-this.posOut,V-Z);$.set(Q.subarray(this.posOut,this.posOut+I),Z),this.posOut+=I,Z+=I}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return t0($),this.xofInto(new Uint8Array($))}digestInto($){if(D$($,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 lQ=vQ(($)=>new KJ($));class MJ{async genRandomBytes($){return N$($)}async gen256BitSecureRandomSeed(){return N$(32)}async encryptXSalsa20Poly1305Combined($,J){let Q=N$(24),V=u$(J,Q).encrypt($);return new Uint8Array([...Q,...V])}async decryptXSalsa20Poly1305Combined($,J){let Q=$.slice(0,24),Z=$.slice(24);return u$(J,Q).decrypt(Z)}async deriveEd25519KeyPair($){let J=$,Q=R$.getPublicKey(J),Z=new Uint8Array(64);return Z.set(J,0),Z.set(Q,32),{keyType:"ed25519",privateKey:Z,publicKey:Q}}async signEd25519($,J){let Q=typeof $==="string"?new TextEncoder().encode($):$,Z=J.slice(0,32);return R$.sign(Q,Z)}async checkSigEd25519($,J,Q){let Z=typeof J==="string"?new TextEncoder().encode(J):J;return R$.verify($,Z,Q)}async blake3($){return lQ($)}}var cV=new MJ,x0=cV;var p0=64;var dQ=32,r0=8;var pQ=32;var rQ=30000,cQ=512,v;((R)=>{R[R.Success=0]="Success";R[R.InvalidSignature=3]="InvalidSignature";R[R.ClockOutOfSync=4]="ClockOutOfSync";R[R.UserNotRegistered=5]="UserNotRegistered";R[R.ServerMisconfigured=6]="ServerMisconfigured";R[R.MissingBody=7]="MissingBody";R[R.ExtraBodyContent=8]="ExtraBodyContent";R[R.MissingParam=9]="MissingParam";R[R.InvalidParam=10]="InvalidParam";R[R.InvalidRequest=11]="InvalidRequest";R[R.InternalError=12]="InternalError";R[R.NotFound=13]="NotFound";R[R.InvalidMessage=14]="InvalidMessage";R[R.NoChange=15]="NoChange";R[R.DatabaseClosed=16]="DatabaseClosed";R[R.StorageError=17]="StorageError";R[R.DatabaseError=18]="DatabaseError";R[R.HashMismatch=19]="HashMismatch";R[R.DecryptionError=20]="DecryptionError";R[R.NotImplemented=21]="NotImplemented";R[R.MissingSeed=22]="MissingSeed";R[R.OutOfBounds=23]="OutOfBounds";R[R.HostError=24]="HostError";R[R.CommunicationError=25]="CommunicationError";R[R.VarLimitExceeded=26]="VarLimitExceeded";R[R.InvalidResponse=27]="InvalidResponse";R[R.ConnectionClosed=28]="ConnectionClosed"})(v||={});var iQ="t";function j($){return[$,0]}function M($){return[void 0,$]}function iV($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return M(10);let J=[];while($>0n){let Q=Number($&0x7fn);if($>>=7n,$>0n)J.push(Q|128);else J.push(Q)}if(J.length===0)return j(new Uint8Array([0]));if(J.length>8)return M(26);return j(new Uint8Array(J))}function hV($,J=0){let Q=0n,Z=0,V=J;while(!0){if(V>=$.length)return M(14);let I=$[V++];if(I===void 0)return M(14);if(Q|=BigInt(I&127)<<BigInt(Z),(I&128)===0){if(V-J>8)return M(26);return j({value:Q>0x1fffffffffffffn?Q:Number(Q),bytesRead:V-J})}if(Z+=7,Z>=56)return M(26)}}class I0{data;pos=0;constructor($){this.data=$}static async fromResponse($){let J=await $.arrayBuffer(),Q=new Uint8Array(J);return new I0(Q)}readBigInt(){if(this.pos+8>this.data.length)return M(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,j($)}readDate(){let[$,J]=this.readVarInt();if(J!==0)return M(J);return j(new Date($))}readVarInt(){let[$,J]=hV(this.data,this.pos);if(J!==0)return M(J);this.pos+=$.bytesRead;let Q=$.value;return j(typeof Q==="bigint"?Number(Q):Q)}readVarString(){let[$,J]=this.readVarInt();if(J!==0)return M(J);let[Q,Z]=this.readBytes($);if(Z!==0)return M(Z);let V=new TextDecoder().decode(Q);return j(V)}readBytes($){if($<0)return M(10);if(this.pos+$>this.data.length)return M(23);let J=this.data.slice(this.pos,this.pos+$);return this.pos+=$,j(J)}readVarBytes(){let[$,J]=this.readVarInt();if(J!==0)return M(J);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let J=[];while(!this.done()){let[Q,Z]=this.readStruct($);if(Z!==0)return M(Z);J.push(Q)}return j(J)}readBytesSeq($){let J=[];while(!this.done()){let[Q,Z]=this.readBytes($);if(Z!==0)return M(Z);J.push(Q)}return j(J)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class c{parts=[];writeBigInt($){let J=new Uint8Array(8);new DataView(J.buffer).setBigUint64(0,$,!1),this.parts.push(J)}writeDate($){let J=$.getTime();return this.writeVarInt(J)}writeVarInt($){let[J,Q]=iV($);if(Q!==0)return Q;return this.parts.push(J),0}writeVarString($){let J=new TextEncoder().encode($),Q=this.writeVarInt(J.length);if(Q!==0)return Q;return this.writeBytes(J),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let J=this.writeVarInt($.length);if(J!==0)return J;return this.writeBytes($),0}writeStruct($,J){return $.encode(this,J)}writeStructs($,J){for(let Q of J){let Z=this.writeStruct($,Q);if(Z!==0)return Z}return 0}writeBytesSeq($){for(let J of $)this.writeBytes(J)}result(){let $=this.parts.reduce((Z,V)=>Z+V.length,0),J=new Uint8Array($),Q=0;for(let Z of this.parts)J.set(Z,Q),Q+=Z.length;return J}*scan(){for(let $ of this.parts)yield $}}var J$={encode($,J){let Q=$.writeVarBytes(J.id);if(Q!==0)return Q;let Z=$.writeDate(J.ts);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return M(Q);let[Z,V]=$.readDate();if(V!==0)return M(V);return j({id:J,ts:Z})}};function hQ($){let J=new c,Q=J.writeStruct(J$,$);if(Q!==0)return M(Q);let Z=J.result();return j(Z)}var WJ={encode($,J){let Q=$.writeVarBytes(J.eid);if(Q!==0)return Q;let Z=$.writeVarInt(J.off);if(Z!==0)return Z;let V=$.writeVarInt(J.ctr);if(V!==0)return V;let I=$.writeVarInt(J.len);if(I!==0)return I;if(J.hsh)$.writeBytes(J.hsh);return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return M(Q);let Z=new I0(J),[,V]=J$.decode(Z);if(V!==0)return M(V);let[I,X]=$.readVarInt();if(X!==0)return M(X);let[G,Y]=$.readVarInt();if(Y!==0)return M(Y);let[N,q]=$.readVarInt();if(q!==0)return M(q);let K;if(N>0){let[O,W]=$.readBytes(pQ);if(W!==0)return M(W);K=O}return j({eid:J,off:I,ctr:G,len:N,hsh:K})}};function O0($){return Array.from($).map((Q)=>Q.toString(16).padStart(2,"0")).join("")}function C$($){if($.length%2!==0)throw Error("Invalid hex string");let J=new Uint8Array($.length/2);for(let Q=0;Q<$.length;Q+=2)J[Q/2]=Number.parseInt($.substr(Q,2),16);return J}function aQ($,J){if($===J)return!0;if($.byteLength!==J.byteLength)return!1;return $.every((Q,Z)=>Q===J[Z])}var nQ;if(typeof Uint8Array.prototype.toBase64==="function")nQ=($)=>$.toBase64();else nQ=($)=>btoa(String.fromCharCode(...$));var oQ;if(typeof Uint8Array.fromBase64==="function")oQ=($)=>Uint8Array.fromBase64($);else oQ=($)=>Uint8Array.from(atob($),(J)=>J.charCodeAt(0));function Q$($,J){let Q=new Uint8Array($.length+J.length);return Q.set($,0),Q.set(J,$.length),Q}function sQ($,J,Q){return Q.checkSigEd25519($.sig,$.headCph,J)}async function nV($,J,Q){let Z=Q$(J.privateKey,$);return(await Q.blake3(Z)).slice(0,r0)}async function tQ($,J,Q,Z){let V;if($.bod&&$.len>0)V=await Q.blake3($.bod);let I=new c,X=WJ.encode(I,{...$,hsh:V});if(X!==0)return M(X);let G=I.result(),Y=await nV(G,J,Q),N=await Z.deriveFromKDM(Y),q=await Q.encryptXSalsa20Poly1305Combined(G,N),K=$.bod?await Q.encryptXSalsa20Poly1305Combined($.bod,N):new Uint8Array(0),O=await Q.signEd25519(q,J.privateKey);return j({sig:O,kdm:Y,headCph:q,bodyCph:K})}async function eQ($,J,Q,Z){let V=new I0($),[I,X]=WJ.decode(V);if(X!==0)return M(14);let G;try{G=J&&J.length>0?await Z.decryptXSalsa20Poly1305Combined(J,Q):void 0}catch{return M(20)}let Y=I.hsh&&G===void 0,N=I.hsh===void 0&&G!==void 0;if(Y||N)return M(19);if(I.hsh&&G){let K=await Z.blake3(G);if(!aQ(K,I.hsh))return M(19)}let q=await Z.blake3($);return j({msgHead:I,bod:G,headHash:q})}async function UJ($,J,Q){let Z=new c,V=Z.writeDate(J);if(V!==0)return M(V);let I=Z.result(),X=await Q.signEd25519(I,$.privateKey);return j({pubKey:$.publicKey,sig:X,timestamp:J})}async function K0($,J,Q){let Z=Q.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Z-V)>rQ)return 4;let X=new c;X.writeDate($.timestamp);let G=X.result();if(!await J.checkSigEd25519($.sig,G,$.pubKey))return 3;return 0}class c0{now(){return new Date}}function $Z($,J,Q,Z){let V=J.getTime()-$.getTime(),I=Q.getTime()-Z.getTime();return(V+I)/2}var Z$={encode($,J){if($.writeVarInt(J.quota),J.quota>0){if(J.usage===void 0)return 9;$.writeVarInt(J.usage)}return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let Z;if(J>0){let[V,I]=$.readVarInt();if(I!==0)return M(I);Z=V}return j({quota:J,usage:Z})}};var i0={encode($,J){$.writeBytes(new Uint8Array([J.status]));let Q=$.writeDate(J.timeRcvd);if(Q!==0)return Q;let Z=$.writeDate(J.timeSent);if(Z!==0)return Z;let V=$.writeVarInt(J.subscription.term);if(V!==0)return V;let I=$.writeVarInt(J.subscription.elapsed);if(I!==0)return I;let X=$.writeStruct(Z$,J.subscription.stat);if(X!==0)return X;let G=$.writeStruct(Z$,J.subscription.dyn);if(G!==0)return G;return 0},decode($){let[J,Q]=$.readBytes(1);if(Q!==0)return M(Q);let Z=J[0],[V,I]=$.readDate();if(I!==0)return M(I);let[X,G]=$.readDate();if(G!==0)return M(G);let[Y,N]=$.readVarInt();if(N!==0)return M(N);let[q,K]=$.readVarInt();if(K!==0)return M(K);let[O,W]=$.readStruct(Z$);if(W!==0)return M(W);let[H,T]=$.readStruct(Z$);if(T!==0)return M(T);return j({status:Z,timeRcvd:V,timeSent:X,subscription:{term:Y,elapsed:q,stat:O,dyn:H}})}};async function OJ($,J,Q){let{crypto:Z,enclave:V}=$,I=await V.derive(J,Q);return await Z.deriveEd25519KeyPair(I)}var zJ={encode($,J){let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;let Z=$.writeVarInt(J.seq);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readVarBytes();if(Q!==0)return M(Q);let[Z,V]=$.readVarInt();if(V!==0)return M(V);return j({headCph:J,seq:Z})}};var X0={encode($,J){$.writeBytes(J.pubKey),$.writeBytes(J.sig);let Q=$.writeDate(J.timestamp);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readBytes(dQ);if(Q!==0)return M(Q);let[Z,V]=$.readBytes(p0);if(V!==0)return M(V);let[I,X]=$.readDate();if(X!==0)return M(X);return j({pubKey:J,sig:Z,timestamp:I})}};var JZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;for(let X of Z)V.writeVarInt(X);return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await K0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X,[q,K]=await I.hasUser(N);if(K!==0)return K;if(!q)return 5;let[O,W]=J.readVarInt();if(W!==0)return W;if(!J.done())return 8;let[H,T]=await I.listHeads(N,O);if(T!==0)return T;return Q.writeStructs(zJ,H)},decodeResp($){return $.readStructs(zJ)}};var HJ={encode($,J){$.writeVarInt(J.seq);let Q=$.writeVarBytes(J.bodyCph);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let[Z,V]=$.readVarBytes();if(V!==0)return M(V);return j({seq:J,bodyCph:Z})}};var QZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;for(let X of Z){let G=V.writeVarInt(X);if(G!==0)return G}return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await K0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X,[q,K]=await I.hasUser(N);if(K!==0)return K;if(!q)return 5;let O=[];while(!J.done()){let[T,S]=J.readVarInt();if(S!==0)return S;O.push(T)}console.info(`PULL: ${O.length} bags`);let[W,H]=await I.getBodies(N,O);if(H!==0)return H;if(!W)return 17;for(let{seq:T,bodyCph:S}of W){let F={seq:T,bodyCph:S},A=Q.writeStruct(HJ,F);if(A!==0)return A}return 0},decodeResp($){return $.readStructs(HJ)}};var TJ={encode($,J){$.writeBytes(J.sig),$.writeBytes(J.kdm);let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;let Z=$.writeVarBytes(J.bodyCph);if(Z!==0)return Z;return 0},decode($){let[J,Q]=$.readBytes(p0);if(Q!==0)return M(Q);let[Z,V]=$.readBytes(r0);if(V!==0)return M(V);let[I,X]=$.readVarBytes();if(X!==0)return M(X);let[G,Y]=$.readVarBytes();if(Y!==0)return M(Y);return j({sig:J,kdm:Z,headCph:I,bodyCph:G})}};var RJ={encode($,J){let Q=$.writeVarInt(J.seq);if(Q!==0)return Q;let Z=$.writeVarBytes(J.headCph);if(Z!==0)return Z;let V=J.bodyCph?J.bodyCph.length:0,I=$.writeVarInt(V);if(I!==0)return I;if(V>0){if(!J.bodyCph)return 10;$.writeBytes(J.bodyCph)}return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let[Z,V]=$.readVarBytes();if(V!==0)return M(V);let[I,X]=$.readVarInt();if(X!==0)return M(X);let G;if(I>0){let[Y,N]=$.readBytes(I);if(N!==0)return M(N);G=Y}return j({seq:J,headCph:Z,bodyCph:G})}};var h0={encode($,J){$.writeBytes(J.sig),$.writeBytes(J.kdm);let Q=$.writeVarBytes(J.headCph);if(Q!==0)return Q;return 0},decode($){let[J,Q]=$.readBytes(p0);if(Q!==0)return M(Q);let[Z,V]=$.readBytes(r0);if(V!==0)return M(V);let[I,X]=$.readVarBytes();if(X!==0)return M(X);return j({sig:J,kdm:Z,headCph:I})}};var P$={encode($,J){if($.writeVarInt(J.idx),$.writeBytes(new Uint8Array([J.status])),J.status===0)$.writeVarInt(J.seq);return 0},decode($){let[J,Q]=$.readVarInt();if(Q!==0)return M(Q);let[Z,V]=$.readBytes(1);if(V!==0)return M(V);let I=Z[0];if(I!==0)return j({idx:J,status:I});let[X,G]=$.readVarInt();if(G!==0)return M(G);return j({idx:J,status:I,seq:X})}};var ZZ={async encodeReq($,J,Q,Z,V){let I=V.writeStruct(X0,Q);if(I!==0)return I;let X=V.writeStructs(TJ,Z);if(X!==0)return X;return 0},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I,notifier:X}=$,[G,Y]=J.readStruct(X0);if(Y!==0)return Y;let N=await K0(G,V,Z);if(N!==0)return N;let{pubKey:q}=G,[K,O]=await I.hasUser(q);if(O!==0)return O;if(!K)return 5;let[W,H]=J.readStructs(TJ);if(H!==0)return H;console.info(`PUSH: ${W.length} bags`);let T=[],S=[];for(let P=0;P<W.length;P++){let x=W[P];if(!await sQ(x,q,V)){let b={idx:P,status:3},_=Q.writeStruct(P$,b);if(_!==0)return _;continue}T.push(P),S.push(x)}let[F,A]=await I.setBags(q,S);if(A!==0)return A;if(!F||F.length!==S.length)return 17;let C=[];for(let P=0;P<S.length;P++){let x=S[P],y=T[P],b=F[P],_=new c,m=_.writeStruct(h0,x);if(m!==0)return m;let d=_.result(),R={seq:b,headCph:d};if(W.length===1&&x.bodyCph.length<=cQ)R.bodyCph=x.bodyCph;C.push(R);let p={idx:y,status:0,seq:b},r=Q.writeStruct(P$,p);if(r!==0)return r}if(C.length>0){let P=new c,x=P.writeStructs(RJ,C);if(x!==0)return x;let y=P.result();await Promise.resolve(X.push(q,y))}return 0},decodeResp($){return $.readStructs(P$)}};var VZ={async encodeReq($,J,Q,Z,V){return V.writeStruct(X0,Q)},async handleReq($,J,Q){let{clock:Z,crypto:V,storage:I}=$,[X,G]=J.readStruct(X0);if(G!==0)return G;let Y=await K0(X,V,Z);if(Y!==0)return Y;let{pubKey:N}=X;if(!J.done())return 8;let[q,K]=await I.addUser(N);if(K!==0)return K;return 0},decodeResp($){return j(void 0)}};class DJ{url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,J,Q=()=>{},Z=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let I=new c;I.writeStruct(X0,$);let X=I.result(),G=O0(X);return V.searchParams.set("t",G),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Z()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,Q()},this.websocket.onmessage=(Y)=>{let N=new Uint8Array(Y.data);J(N)},this.websocket.onerror=(Y)=>{console.log(`ERROR: ${JSON.stringify(Y)}`),this.websocket=void 0,Q()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var Z0={user:{path:"/user",endpoint:VZ,name:0},push:{path:"/push",endpoint:ZZ,name:2},peek:{path:"/peek",endpoint:JZ,name:1},pull:{path:"/pull",endpoint:QZ,name:3}},oV={0:Z0.user,2:Z0.push,1:Z0.peek,3:Z0.pull},IZ={[Z0.user.path]:Z0.user,[Z0.push.path]:Z0.push,[Z0.peek.path]:Z0.peek,[Z0.pull.path]:Z0.pull};class XZ{url;listener;constructor($){this.url=$;this.listener=new DJ($)}async call($,J){let{path:Q}=oV[$],Z=new URL(Q,this.url);try{return await sV(Z,J)}catch{return M(25)}}}var AJ=($)=>{return new XZ($.handle)};function n0($){let J=new c;if(J.writeStruct(i0,$)!==0)return new Response(null,{status:500});return CJ(J)}function CJ($){let J=$.result().slice();return new Response(J,{status:200,headers:{"content-type":"application/octet-stream"}})}var aV={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function PJ($){return new Response($.body,{headers:{...$.headers,...aV},status:$.status,statusText:$.statusText})}async function sV($,J){let Q=await fetch($,{method:"POST",body:J.result().slice()});if(!Q.ok)return M(24);let Z=await I0.fromResponse(Q);return j(Z)}class S${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,J,Q,Z,V,I){this.enclave=$;this.crypto=J;this.host=Q;this.clock=Z;this.transport=V;this.updateHostMeta=I}async call($,J){let{clock:Q,crypto:Z,transport:V}=this,{endpoint:I,name:X}=$,G=await this.keys(),Y=Q.now(),[N,q]=await UJ(G,Y,Z);if(q!==0)return M(q);let K=new c,O=await I.encodeReq(this,G,N,J,K);if(O!==0)return M(O);let W=Q.now(),[H,T]=await V.call(X,K),S=Q.now();if(T!==0)return M(T);let[F,A]=H.readStruct(i0);if(A!==0)return M(A);if(F.status!==0)return M(F.status);let P={clockOffset:$Z(W,F.timeRcvd,F.timeSent,S),subscription:F.subscription},x=await this.updateHostMeta(P);if(x!==0)return M(x);return I.decodeResp(H)}keys=()=>{let{host:$}=this;return OJ(this,$.label,$.idx)};seal=async($)=>{let{crypto:J,enclave:Q}=this,Z=await this.keys();return tQ($,Z,J,Q)};register=()=>this.call(Z0.user,[]);peek=($)=>this.call(Z0.peek,[$]);push=($)=>this.call(Z0.push,$);pull=($)=>this.call(Z0.pull,$);listen=async($,J,Q)=>{let{clock:Z,crypto:V,host:I,transport:X}=this,{listener:G}=X,Y=await OJ(this,I.label,I.idx),N=Z.now(),[q,K]=await UJ(Y,N,V);if(K!==0)return K;return await G.connect(q,$,J,Q)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class SJ{seed;crypto;constructor($,J){this.seed=$,this.crypto=J}async deriveFromKDM($){let J=Q$(this.seed,$);return await this.crypto.blake3(J)}async derive($,J=0){let Q=new TextEncoder().encode($),Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,BigInt(J),!1);let V=Q$(Q,Z);return await this.deriveFromKDM(V)}}class wJ{listeners=new Map;addEventListener($,J){let Q=this.listeners.get($);if(!Q)Q=new Set,this.listeners.set($,Q);return Q.add(J),()=>{this.removeEventListener($,J)}}removeEventListener($,J){let Q=this.listeners.get($);if(Q){if(Q.delete(J),Q.size===0)this.listeners.delete($)}}emit($,J){let Q=this.listeners.get($);if(Q){let Z=Array.from(Q);for(let V of Z)V(J)}}emitAll($){let J=Array.from(this.listeners.keys());for(let Q of J)this.emit(Q,$)}}async function YZ($,J,Q,Z=0){let V=J.now(),I=new c,X=I.writeVarString($);if(X!==0)return M(X);let Y={id:I.result(),ts:new Date(0)},[N,q]=hQ(Y);if(q!==0)return M(q);let K=V.getTime()-Y.ts.getTime();return j({eid:N,off:K,ctr:Z,len:Q.length,bod:Q})}class tV{singletonType;latest;latestOff=-1;emitter=new wJ;constructor($){this.singletonType=$}async apply($){for(let J of $){let Q=new I0(J.eid),[Z,V]=Q.readStruct(J$);if(V!==0)continue;let I=new c;I.writeVarString(this.singletonType);let X=I.result();if(Z.id.length===X.length&&Z.id.every((G,Y)=>G===X[Y])){if(this.latest===void 0||J.off>this.latestOff)this.latestOff=J.off,this.latest=J.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 J of $)if(J===this.singletonType)this.emitter.emit(this.singletonType,null)};on=($,J)=>{this.emitter.addEventListener($,J)};off=($,J)=>{this.emitter.removeEventListener($,J)}}async function GZ($,J,Q,Z){let V=new I0($.headCph),[I,X]=V.readStruct(h0);if(X!==0)return M(X);let{sig:G,kdm:Y,headCph:N}=I;if(!await Z.checkSigEd25519(G,N,J.publicKey))return M(3);let K=await Q.deriveFromKDM(Y),O;try{O=await Z.decryptXSalsa20Poly1305Combined(N,K)}catch{return M(20)}return j({kdm:Y,headEnc:O})}var a0=L8(q8(),1),HX={encode:a0.encode,decode:a0.decode,decodeAsync:a0.decodeAsync},TX=HX;import{Database as RX}from"bun:sqlite";var sN=Symbol("EntityID");var tN=Symbol("MasterSeed"),eN=Symbol("DerivationSeed"),$K=Symbol("PublicKey"),JK=Symbol("PrivateKey"),QK=Symbol("HostSpecificKeyPair"),ZK=Symbol("Hash"),j0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};var N0=new RX("diplomatic.db");N0.exec("PRAGMA journal_mode=WAL;");N0.exec("PRAGMA synchronous=NORMAL;");N0.exec(`
|
|
1
|
+
var lJ=Object.create;var{getPrototypeOf:yJ,defineProperty:p$,getOwnPropertyNames:rJ}=Object;var nJ=Object.prototype.hasOwnProperty;function dJ($){return this[$]}var uJ,pJ,bJ=($,Z,J)=>{var V=$!=null&&typeof $==="object";if(V){var Q=Z?uJ??=new WeakMap:pJ??=new WeakMap,W=Q.get($);if(W)return W}J=$!=null?lJ(yJ($)):{};let X=Z||!$||!$.__esModule?p$(J,"default",{value:$,enumerable:!0}):J;for(let I of rJ($))if(!nJ.call(X,I))p$(X,I,{get:dJ.bind($,I),enumerable:!0});if(V)Q.set($,X);return X};var b=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var a0=b((vZ)=>{Object.defineProperty(vZ,"__esModule",{value:!0});vZ.utf8Count=KV;vZ.utf8EncodeJs=BZ;vZ.utf8EncodeTE=gZ;vZ.utf8Encode=zV;vZ.utf8DecodeJs=xZ;vZ.utf8DecodeTD=fZ;vZ.utf8Decode=AV;function KV($){let Z=$.length,J=0,V=0;while(V<Z){let Q=$.charCodeAt(V++);if((Q&4294967168)===0){J++;continue}else if((Q&4294965248)===0)J+=2;else{if(Q>=55296&&Q<=56319){if(V<Z){let W=$.charCodeAt(V);if((W&64512)===56320)++V,Q=((Q&1023)<<10)+(W&1023)+65536}}if((Q&4294901760)===0)J+=3;else J+=4}}return J}function BZ($,Z,J){let V=$.length,Q=J,W=0;while(W<V){let X=$.charCodeAt(W++);if((X&4294967168)===0){Z[Q++]=X;continue}else if((X&4294965248)===0)Z[Q++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(W<V){let I=$.charCodeAt(W);if((I&64512)===56320)++W,X=((X&1023)<<10)+(I&1023)+65536}}if((X&4294901760)===0)Z[Q++]=X>>12&15|224,Z[Q++]=X>>6&63|128;else Z[Q++]=X>>18&7|240,Z[Q++]=X>>12&63|128,Z[Q++]=X>>6&63|128}Z[Q++]=X&63|128}}var OV=new TextEncoder,UV=50;function gZ($,Z,J){OV.encodeInto($,Z.subarray(J))}function zV($,Z,J){if($.length>UV)gZ($,Z,J);else BZ($,Z,J)}var FV=4096;function xZ($,Z,J){let V=Z,Q=V+J,W=[],X="";while(V<Q){let I=$[V++];if((I&128)===0)W.push(I);else if((I&224)===192){let Y=$[V++]&63;W.push((I&31)<<6|Y)}else if((I&240)===224){let Y=$[V++]&63,N=$[V++]&63;W.push((I&31)<<12|Y<<6|N)}else if((I&248)===240){let Y=$[V++]&63,N=$[V++]&63,P=$[V++]&63,M=(I&7)<<18|Y<<12|N<<6|P;if(M>65535)M-=65536,W.push(M>>>10&1023|55296),M=56320|M&1023;W.push(M)}else W.push(I);if(W.length>=FV)X+=String.fromCharCode(...W),W.length=0}if(W.length>0)X+=String.fromCharCode(...W);return X}var HV=new TextDecoder,TV=200;function fZ($,Z,J){let V=$.subarray(Z,Z+J);return HV.decode(V)}function AV($,Z,J){if(J>TV)return fZ($,Z,J);else return xZ($,Z,J)}});var k$=b((lZ)=>{Object.defineProperty(lZ,"__esModule",{value:!0});lZ.ExtData=void 0;class iZ{type;data;constructor($,Z){this.type=$,this.data=Z}}lZ.ExtData=iZ});var t0=b((rZ)=>{Object.defineProperty(rZ,"__esModule",{value:!0});rZ.DecodeError=void 0;class s0 extends Error{constructor($){super($);let Z=Object.create(s0.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:s0.name})}}rZ.DecodeError=s0});var e0=b((dZ)=>{Object.defineProperty(dZ,"__esModule",{value:!0});dZ.UINT32_MAX=void 0;dZ.setUint64=kV;dZ.setInt64=_V;dZ.getInt64=BV;dZ.getUint64=gV;dZ.UINT32_MAX=4294967295;function kV($,Z,J){let V=J/4294967296,Q=J;$.setUint32(Z,V),$.setUint32(Z+4,Q)}function _V($,Z,J){let V=Math.floor(J/4294967296),Q=J;$.setUint32(Z,V),$.setUint32(Z+4,Q)}function BV($,Z){let J=$.getInt32(Z),V=$.getUint32(Z+4);return J*4294967296+V}function gV($,Z){let J=$.getUint32(Z),V=$.getUint32(Z+4);return J*4294967296+V}});var _$=b((sZ)=>{Object.defineProperty(sZ,"__esModule",{value:!0});sZ.timestampExtension=sZ.EXT_TIMESTAMP=void 0;sZ.encodeTimeSpecToTimestamp=bZ;sZ.encodeDateToTimeSpec=hZ;sZ.encodeTimestampExtension=cZ;sZ.decodeTimestampToTimeSpec=oZ;sZ.decodeTimestampExtension=aZ;var lV=t0(),pZ=e0();sZ.EXT_TIMESTAMP=-1;var yV=4294967295,rV=17179869183;function bZ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=rV)if(Z===0&&$<=yV){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,V=$&4294967295,Q=new Uint8Array(8),W=new DataView(Q.buffer);return W.setUint32(0,Z<<2|J&3),W.setUint32(4,V),Q}else{let J=new Uint8Array(12),V=new DataView(J.buffer);return V.setUint32(0,Z),(0,pZ.setInt64)(V,4,$),J}}function hZ($){let Z=$.getTime(),J=Math.floor(Z/1000),V=(Z-J*1000)*1e6,Q=Math.floor(V/1e9);return{sec:J+Q,nsec:V-Q*1e9}}function cZ($){if($ instanceof Date){let Z=hZ($);return bZ(Z)}else return null}function oZ($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let J=Z.getUint32(0),V=0;return{sec:J,nsec:0}}case 8:{let J=Z.getUint32(0),V=Z.getUint32(4),Q=(J&3)*4294967296+V,W=J>>>2;return{sec:Q,nsec:W}}case 12:{let J=(0,pZ.getInt64)(Z,4),V=Z.getUint32(0);return{sec:J,nsec:V}}default:throw new lV.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function aZ($){let Z=oZ($);return new Date(Z.sec*1000+Z.nsec/1e6)}sZ.timestampExtension={type:sZ.EXT_TIMESTAMP,encode:cZ,decode:aZ}});var Z$=b(($J)=>{Object.defineProperty($J,"__esModule",{value:!0});$J.ExtensionCodec=void 0;var $$=k$(),hV=_$();class B${static defaultCodec=new B$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(hV.timestampExtension)}register({type:$,encode:Z,decode:J}){if($>=0)this.encoders[$]=Z,this.decoders[$]=J;else{let V=-1-$;this.builtInEncoders[V]=Z,this.builtInDecoders[V]=J}}tryToEncode($,Z){for(let J=0;J<this.builtInEncoders.length;J++){let V=this.builtInEncoders[J];if(V!=null){let Q=V($,Z);if(Q!=null){let W=-1-J;return new $$.ExtData(W,Q)}}}for(let J=0;J<this.encoders.length;J++){let V=this.encoders[J];if(V!=null){let Q=V($,Z);if(Q!=null){let W=J;return new $$.ExtData(W,Q)}}}if($ instanceof $$.ExtData)return $;return null}decode($,Z,J){let V=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(V)return V($,Z,J);else return new $$.ExtData(Z,$)}}$J.ExtensionCodec=B$});var g$=b((JJ)=>{Object.defineProperty(JJ,"__esModule",{value:!0});JJ.ensureUint8Array=oV;function cV($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function oV($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(cV($))return new Uint8Array($);else return Uint8Array.from($)}});var f$=b((WJ)=>{Object.defineProperty(WJ,"__esModule",{value:!0});WJ.Encoder=WJ.DEFAULT_INITIAL_BUFFER_SIZE=WJ.DEFAULT_MAX_DEPTH=void 0;var VJ=a0(),sV=Z$(),QJ=e0(),tV=g$();WJ.DEFAULT_MAX_DEPTH=100;WJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class x${extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??sV.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??WJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??WJ.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 x$({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),V=new DataView(Z);J.set(this.bytes),this.view=V,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,VJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,VJ.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,tV.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 V of $)this.doEncode(V,Z+1)}countWithoutUndefined($,Z){let J=0;for(let V of Z)if($[V]!==void 0)J++;return J}encodeMap($,Z){let J=Object.keys($);if(this.sortKeys)J.sort();let V=this.ignoreUndefined?this.countWithoutUndefined($,J):J.length;if(V<16)this.writeU8(128+V);else if(V<65536)this.writeU8(222),this.writeU16(V);else if(V<4294967296)this.writeU8(223),this.writeU32(V);else throw Error(`Too large map object: ${V}`);for(let Q of J){let W=$[Q];if(!(this.ignoreUndefined&&W===void 0))this.encodeString(Q),this.doEncode(W,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),V=J.length;if(V>=4294967296)throw Error(`Too large extension object: ${V}`);this.writeU8(201),this.writeU32(V),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,QJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,QJ.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}}WJ.Encoder=x$});var NJ=b((GJ)=>{Object.defineProperty(GJ,"__esModule",{value:!0});GJ.encode=$Q;var eV=f$();function $Q($,Z){return new eV.Encoder(Z).encodeSharedRef($)}});var MJ=b((PJ)=>{Object.defineProperty(PJ,"__esModule",{value:!0});PJ.prettyByte=JQ;function JQ($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var KJ=b((RJ)=>{Object.defineProperty(RJ,"__esModule",{value:!0});RJ.CachedKeyDecoder=void 0;var QQ=a0(),WQ=16,XQ=16;class qJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=WQ,Z=XQ){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 V=this.caches[J-1];$:for(let Q of V){let W=Q.bytes;for(let X=0;X<J;X++)if(W[X]!==$[Z+X])continue $;return Q.str}return null}store($,Z){let J=this.caches[$.length-1],V={bytes:$,str:Z};if(J.length>=this.maxLengthPerKey)J[Math.random()*J.length|0]=V;else J.push(V)}decode($,Z,J){let V=this.find($,Z,J);if(V!=null)return this.hit++,V;this.miss++;let Q=(0,QQ.utf8DecodeJs)($,Z,J),W=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(W,Q),Q}}RJ.CachedKeyDecoder=qJ});var J$=b((HJ)=>{Object.defineProperty(HJ,"__esModule",{value:!0});HJ.Decoder=void 0;var v$=MJ(),IQ=Z$(),R0=e0(),YQ=a0(),OJ=g$(),GQ=KJ(),G0=t0(),i$="array",l0="map_key",zJ="map_value",NQ=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new G0.DecodeError("The type of key must be string or number but "+typeof $)};class FJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=i$,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=l0,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===i$){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===l0||$.type===zJ){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 i0=-1,l$=new DataView(new ArrayBuffer(0)),PQ=new Uint8Array(l$.buffer);try{l$.getInt8(0)}catch($){if(!($ instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var UJ=RangeError("Insufficient data"),MQ=new GQ.CachedKeyDecoder;class y${extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=l$;bytes=PQ;headByte=i0;stack=new FJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??IQ.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??R0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??R0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??R0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??R0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??R0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:MQ,this.mapKeyConverter=$?.mapKeyConverter??NQ}clone(){return new y$({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=i0,this.stack.reset()}setBuffer($){let Z=(0,OJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===i0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,OJ.ensureUint8Array)($),V=new Uint8Array(Z.length+J.length);V.set(Z),V.set(J,Z.length),this.setBuffer(V)}}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 X of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{J=this.doDecodeSync(),Z=!0}catch(I){if(!(I instanceof RangeError))throw I}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:V,pos:Q,totalPos:W}=this;throw RangeError(`Insufficient data in parsing ${(0,v$.prettyByte)(V)} at ${W} (${Q} 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,V=-1;for await(let Q of $){if(Z&&V===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(Q),J)V=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--V===0)break}catch(W){if(!(W instanceof RangeError))throw W}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 V=$-128;if(V!==0){this.pushMapState(V),this.complete();continue $}else Z={}}else if($<160){let V=$-144;if(V!==0){this.pushArrayState(V),this.complete();continue $}else Z=[]}else{let V=$-160;Z=this.decodeString(V,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 V=this.lookU8();Z=this.decodeString(V,1)}else if($===218){let V=this.lookU16();Z=this.decodeString(V,2)}else if($===219){let V=this.lookU32();Z=this.decodeString(V,4)}else if($===220){let V=this.readU16();if(V!==0){this.pushArrayState(V),this.complete();continue $}else Z=[]}else if($===221){let V=this.readU32();if(V!==0){this.pushArrayState(V),this.complete();continue $}else Z=[]}else if($===222){let V=this.readU16();if(V!==0){this.pushMapState(V),this.complete();continue $}else Z={}}else if($===223){let V=this.readU32();if(V!==0){this.pushMapState(V),this.complete();continue $}else Z={}}else if($===196){let V=this.lookU8();Z=this.decodeBinary(V,1)}else if($===197){let V=this.lookU16();Z=this.decodeBinary(V,2)}else if($===198){let V=this.lookU32();Z=this.decodeBinary(V,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 V=this.lookU8();Z=this.decodeExtension(V,1)}else if($===200){let V=this.lookU16();Z=this.decodeExtension(V,2)}else if($===201){let V=this.lookU32();Z=this.decodeExtension(V,4)}else throw new G0.DecodeError(`Unrecognized type byte: ${(0,v$.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let V=J.top();if(V.type===i$)if(V.array[V.position]=Z,V.position++,V.position===V.size)Z=V.array,J.release(V);else continue $;else if(V.type===l0){if(Z==="__proto__")throw new G0.DecodeError("The key __proto__ is not allowed");V.key=this.mapKeyConverter(Z),V.type=zJ;continue $}else if(V.map[V.key]=Z,V.readCount++,V.readCount===V.size)Z=V.map,J.release(V);else{V.key=null,V.type=l0;continue $}}return Z}}readHeadByte(){if(this.headByte===i0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=i0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new G0.DecodeError(`Unrecognized array type byte: ${(0,v$.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new G0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new G0.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 G0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw UJ;let J=this.pos+Z,V;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))V=this.keyDecoder.decode(this.bytes,J,$);else V=(0,YQ.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,V}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===l0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new G0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw UJ;let J=this.pos+Z,V=this.bytes.subarray(J,J+$);return this.pos+=Z+$,V}decodeExtension($,Z){if($>this.maxExtLength)throw new G0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let J=this.view.getInt8(this.pos+Z),V=this.decodeBinary($,Z+1);return this.extensionCodec.decode(V,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,R0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,R0.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,$}}HJ.Decoder=y$});var CJ=b((DJ)=>{Object.defineProperty(DJ,"__esModule",{value:!0});DJ.decode=qQ;DJ.decodeMulti=RQ;var AJ=J$();function qQ($,Z){return new AJ.Decoder(Z).decode($)}function RQ($,Z){return new AJ.Decoder(Z).decodeMulti($)}});var LJ=b((mJ)=>{Object.defineProperty(mJ,"__esModule",{value:!0});mJ.isAsyncIterable=SJ;mJ.asyncIterableFromStream=EJ;mJ.ensureAsyncIterable=OQ;function SJ($){return $[Symbol.asyncIterator]!=null}async function*EJ($){let Z=$.getReader();try{while(!0){let{done:J,value:V}=await Z.read();if(J)return;yield V}}finally{Z.releaseLock()}}function OQ($){if(SJ($))return $;else return EJ($)}});var kJ=b((jJ)=>{Object.defineProperty(jJ,"__esModule",{value:!0});jJ.decodeAsync=HQ;jJ.decodeArrayStream=TQ;jJ.decodeMultiStream=AQ;var r$=J$(),n$=LJ();async function HQ($,Z){let J=(0,n$.ensureAsyncIterable)($);return new r$.Decoder(Z).decodeAsync(J)}function TQ($,Z){let J=(0,n$.ensureAsyncIterable)($);return new r$.Decoder(Z).decodeArrayStream(J)}function AQ($,Z){let J=(0,n$.ensureAsyncIterable)($);return new r$.Decoder(Z).decodeStream(J)}});var BJ=b((f)=>{Object.defineProperty(f,"__esModule",{value:!0});f.decodeTimestampExtension=f.encodeTimestampExtension=f.decodeTimestampToTimeSpec=f.encodeTimeSpecToTimestamp=f.encodeDateToTimeSpec=f.EXT_TIMESTAMP=f.ExtData=f.ExtensionCodec=f.Encoder=f.DecodeError=f.Decoder=f.decodeMultiStream=f.decodeArrayStream=f.decodeAsync=f.decodeMulti=f.decode=f.encode=void 0;var EQ=NJ();Object.defineProperty(f,"encode",{enumerable:!0,get:function(){return EQ.encode}});var _J=CJ();Object.defineProperty(f,"decode",{enumerable:!0,get:function(){return _J.decode}});Object.defineProperty(f,"decodeMulti",{enumerable:!0,get:function(){return _J.decodeMulti}});var d$=kJ();Object.defineProperty(f,"decodeAsync",{enumerable:!0,get:function(){return d$.decodeAsync}});Object.defineProperty(f,"decodeArrayStream",{enumerable:!0,get:function(){return d$.decodeArrayStream}});Object.defineProperty(f,"decodeMultiStream",{enumerable:!0,get:function(){return d$.decodeMultiStream}});var mQ=J$();Object.defineProperty(f,"Decoder",{enumerable:!0,get:function(){return mQ.Decoder}});var LQ=t0();Object.defineProperty(f,"DecodeError",{enumerable:!0,get:function(){return LQ.DecodeError}});var jQ=f$();Object.defineProperty(f,"Encoder",{enumerable:!0,get:function(){return jQ.Encoder}});var kQ=Z$();Object.defineProperty(f,"ExtensionCodec",{enumerable:!0,get:function(){return kQ.ExtensionCodec}});var _Q=k$();Object.defineProperty(f,"ExtData",{enumerable:!0,get:function(){return _Q.ExtData}});var j0=_$();Object.defineProperty(f,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return j0.EXT_TIMESTAMP}});Object.defineProperty(f,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return j0.encodeDateToTimeSpec}});Object.defineProperty(f,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return j0.encodeTimeSpecToTimestamp}});Object.defineProperty(f,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return j0.decodeTimestampToTimeSpec}});Object.defineProperty(f,"encodeTimestampExtension",{enumerable:!0,get:function(){return j0.encodeTimestampExtension}});Object.defineProperty(f,"decodeTimestampExtension",{enumerable:!0,get:function(){return j0.decodeTimestampExtension}})});import*as Q0 from"node:crypto";var P0=Q0&&typeof Q0==="object"&&"webcrypto"in Q0?Q0.webcrypto:Q0&&typeof Q0==="object"&&("randomBytes"in Q0)?Q0:void 0;function y0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function V$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function r($,...Z){if(!V$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function Q$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function b$($,Z){r($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function W$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var W0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var hJ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!hJ)throw Error("Non little-endian hardware is not supported");function cJ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function r0($){if(typeof $==="string")$=cJ($);else if(V$($))$=n0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function h$($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function c$($,Z){if($.length!==Z.length)return!1;let J=0;for(let V=0;V<$.length;V++)J|=$[V]^Z[V];return J===0}var o$=($,Z)=>{function J(V,...Q){if(r(V),$.nonceLength!==void 0){let P=Q[0];if(!P)throw Error("nonce / iv required");if($.varSizeNonce)r(P);else r(P,$.nonceLength)}let W=$.tagLength;if(W&&Q[1]!==void 0)r(Q[1]);let X=Z(V,...Q),I=(P,M)=>{if(M!==void 0){if(P!==2)throw Error("cipher output not supported");r(M)}},Y=!1;return{encrypt(P,M){if(Y)throw Error("cannot encrypt() twice with same key + nonce");return Y=!0,r(P),I(X.encrypt.length,M),X.encrypt(P,M)},decrypt(P,M){if(r(P),W&&P.length<W)throw Error("invalid ciphertext length: smaller than tagLength="+W);return I(X.decrypt.length,M),X.decrypt(P,M)}}}return Object.assign(J,$),J};function X$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!oJ(Z))throw Error("invalid output, must be aligned");return Z}function oJ($){return $.byteOffset%4===0}function n0($){return Uint8Array.from($)}function Z0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function d0($=32){if(P0&&typeof P0.getRandomValues==="function")return P0.getRandomValues(new Uint8Array($));if(P0&&typeof P0.randomBytes==="function")return P0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var s$=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),aJ=s$("expand 16-byte k"),sJ=s$("expand 32-byte k"),tJ=W0(aJ),eJ=W0(sJ);function w($,Z){return $<<Z|$>>>32-Z}function I$($){return $.byteOffset%4===0}var u0=64,$V=16,t$=4294967295,a$=new Uint32Array;function ZV($,Z,J,V,Q,W,X,I){let Y=Q.length,N=new Uint8Array(u0),P=W0(N),M=I$(Q)&&I$(W),K=M?W0(Q):a$,R=M?W0(W):a$;for(let U=0;U<Y;X++){if($(Z,J,V,P,X,I),X>=t$)throw Error("arx: counter overflow");let O=Math.min(u0,Y-U);if(M&&O===u0){let H=U/4;if(U%4!==0)throw Error("arx: invalid block position");for(let T=0,D;T<$V;T++)D=H+T,R[D]=K[D]^P[T];U+=u0;continue}for(let H=0,T;H<O;H++)T=U+H,W[T]=Q[T]^N[H];U+=O}}function e$($,Z){let{allowShortKeys:J,extendNonceFn:V,counterLength:Q,counterRight:W,rounds:X}=h$({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return y0(Q),y0(X),W$(W),W$(J),(I,Y,N,P,M=0)=>{r(I),r(Y),r(N);let K=N.length;if(P===void 0)P=new Uint8Array(K);if(r(P),y0(M),M<0||M>=t$)throw Error("arx: counter overflow");if(P.length<K)throw Error(`arx: output (${P.length}) is shorter than data (${K})`);let R=[],U=I.length,O,H;if(U===32)R.push(O=n0(I)),H=eJ;else if(U===16&&J)O=new Uint8Array(32),O.set(I),O.set(I,16),H=tJ,R.push(O);else throw Error(`arx: invalid 32-byte key, got length=${U}`);if(!I$(Y))R.push(Y=n0(Y));let T=W0(O);if(V){if(Y.length!==24)throw Error("arx: extended nonce must be 24 bytes");V(H,T,W0(Y.subarray(0,16)),T),Y=Y.subarray(16)}let D=16-Q;if(D!==Y.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let F=new Uint8Array(12);F.set(Y,W?0:12-Y.length),Y=F,R.push(Y)}let C=W0(Y);return ZV($,H,T,C,N,P,M,X),Z0(...R),P}}var d=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class $Z{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,$=r0($),r($,32);let Z=d($,0),J=d($,2),V=d($,4),Q=d($,6),W=d($,8),X=d($,10),I=d($,12),Y=d($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|V<<6)&7939,this.r[3]=(V>>>7|Q<<9)&8191,this.r[4]=(Q>>>4|W<<12)&255,this.r[5]=W>>>1&8190,this.r[6]=(W>>>14|X<<2)&8191,this.r[7]=(X>>>11|I<<5)&8065,this.r[8]=(I>>>8|Y<<8)&8191,this.r[9]=Y>>>5&127;for(let N=0;N<8;N++)this.pad[N]=d($,16+2*N)}process($,Z,J=!1){let V=J?0:2048,{h:Q,r:W}=this,X=W[0],I=W[1],Y=W[2],N=W[3],P=W[4],M=W[5],K=W[6],R=W[7],U=W[8],O=W[9],H=d($,Z+0),T=d($,Z+2),D=d($,Z+4),C=d($,Z+6),F=d($,Z+8),E=d($,Z+10),k=d($,Z+12),n=d($,Z+14),L=Q[0]+(H&8191),_=Q[1]+((H>>>13|T<<3)&8191),g=Q[2]+((T>>>10|D<<6)&8191),q=Q[3]+((D>>>7|C<<9)&8191),x=Q[4]+((C>>>4|F<<12)&8191),B=Q[5]+(F>>>1&8191),v=Q[6]+((F>>>14|E<<2)&8191),i=Q[7]+((E>>>11|k<<5)&8191),l=Q[8]+((k>>>8|n<<8)&8191),y=Q[9]+(n>>>5|V),A=0,p=A+L*X+_*(5*O)+g*(5*U)+q*(5*R)+x*(5*K);A=p>>>13,p&=8191,p+=B*(5*M)+v*(5*P)+i*(5*N)+l*(5*Y)+y*(5*I),A+=p>>>13,p&=8191;let a=A+L*I+_*X+g*(5*O)+q*(5*U)+x*(5*R);A=a>>>13,a&=8191,a+=B*(5*K)+v*(5*M)+i*(5*P)+l*(5*N)+y*(5*Y),A+=a>>>13,a&=8191;let t=A+L*Y+_*I+g*X+q*(5*O)+x*(5*U);A=t>>>13,t&=8191,t+=B*(5*R)+v*(5*K)+i*(5*M)+l*(5*P)+y*(5*N),A+=t>>>13,t&=8191;let j=A+L*N+_*Y+g*I+q*X+x*(5*O);A=j>>>13,j&=8191,j+=B*(5*U)+v*(5*R)+i*(5*K)+l*(5*M)+y*(5*P),A+=j>>>13,j&=8191;let V0=A+L*P+_*N+g*Y+q*I+x*X;A=V0>>>13,V0&=8191,V0+=B*(5*O)+v*(5*U)+i*(5*R)+l*(5*K)+y*(5*M),A+=V0>>>13,V0&=8191;let w0=A+L*M+_*P+g*N+q*Y+x*I;A=w0>>>13,w0&=8191,w0+=B*X+v*(5*O)+i*(5*U)+l*(5*R)+y*(5*K),A+=w0>>>13,w0&=8191;let K0=A+L*K+_*M+g*P+q*N+x*Y;A=K0>>>13,K0&=8191,K0+=B*I+v*X+i*(5*O)+l*(5*U)+y*(5*R),A+=K0>>>13,K0&=8191;let O0=A+L*R+_*K+g*M+q*P+x*N;A=O0>>>13,O0&=8191,O0+=B*Y+v*I+i*X+l*(5*O)+y*(5*U),A+=O0>>>13,O0&=8191;let U0=A+L*U+_*R+g*K+q*M+x*P;A=U0>>>13,U0&=8191,U0+=B*N+v*Y+i*I+l*X+y*(5*O),A+=U0>>>13,U0&=8191;let z0=A+L*O+_*U+g*R+q*K+x*M;A=z0>>>13,z0&=8191,z0+=B*P+v*N+i*Y+l*I+y*X,A+=z0>>>13,z0&=8191,A=(A<<2)+A|0,A=A+p|0,p=A&8191,A=A>>>13,a+=A,Q[0]=p,Q[1]=a,Q[2]=t,Q[3]=j,Q[4]=V0,Q[5]=w0,Q[6]=K0,Q[7]=O0,Q[8]=U0,Q[9]=z0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),V=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=V,V=$[X]>>>13,$[X]&=8191;$[0]+=V*5,V=$[0]>>>13,$[0]&=8191,$[1]+=V,V=$[1]>>>13,$[1]&=8191,$[2]+=V,J[0]=$[0]+5,V=J[0]>>>13,J[0]&=8191;for(let X=1;X<10;X++)J[X]=$[X]+V,V=J[X]>>>13,J[X]&=8191;J[9]-=8192;let Q=(V^1)-1;for(let X=0;X<10;X++)J[X]&=Q;Q=~Q;for(let X=0;X<10;X++)$[X]=$[X]&Q|J[X];$[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 W=$[0]+Z[0];$[0]=W&65535;for(let X=1;X<8;X++)W=($[X]+Z[X]|0)+(W>>>16)|0,$[X]=W&65535;Z0(J)}update($){Q$(this);let{buffer:Z,blockLen:J}=this;$=r0($);let V=$.length;for(let Q=0;Q<V;){let W=Math.min(J-this.pos,V-Q);if(W===J){for(;J<=V-Q;Q+=J)this.process($,Q);continue}if(Z.set($.subarray(Q,Q+W),this.pos),this.pos+=W,Q+=W,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){Z0(this.h,this.r,this.buffer,this.pad)}digestInto($){Q$(this),b$($,this),this.finished=!0;let{buffer:Z,h:J}=this,{pos:V}=this;if(V){Z[V++]=1;for(;V<16;V++)Z[V]=0;this.process(Z,0,!0)}this.finalize();let Q=0;for(let W=0;W<8;W++)$[Q++]=J[W]>>>0,$[Q++]=J[W]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function JV($){let Z=(V,Q)=>$(Q).update(r0(V)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(V)=>$(V),Z}var Y$=JV(($)=>new $Z($));function VV($,Z,J,V,Q,W=20){let X=$[0],I=Z[0],Y=Z[1],N=Z[2],P=Z[3],M=$[1],K=J[0],R=J[1],U=Q,O=0,H=$[2],T=Z[4],D=Z[5],C=Z[6],F=Z[7],E=$[3],k=X,n=I,L=Y,_=N,g=P,q=M,x=K,B=R,v=U,i=O,l=H,y=T,A=D,p=C,a=F,t=E;for(let V0=0;V0<W;V0+=2)g^=w(k+A|0,7),v^=w(g+k|0,9),A^=w(v+g|0,13),k^=w(A+v|0,18),i^=w(q+n|0,7),p^=w(i+q|0,9),n^=w(p+i|0,13),q^=w(n+p|0,18),a^=w(l+x|0,7),L^=w(a+l|0,9),x^=w(L+a|0,13),l^=w(x+L|0,18),_^=w(t+y|0,7),B^=w(_+t|0,9),y^=w(B+_|0,13),t^=w(y+B|0,18),n^=w(k+_|0,7),L^=w(n+k|0,9),_^=w(L+n|0,13),k^=w(_+L|0,18),x^=w(q+g|0,7),B^=w(x+q|0,9),g^=w(B+x|0,13),q^=w(g+B|0,18),y^=w(l+i|0,7),v^=w(y+l|0,9),i^=w(v+y|0,13),l^=w(i+v|0,18),A^=w(t+a|0,7),p^=w(A+t|0,9),a^=w(p+A|0,13),t^=w(a+p|0,18);let j=0;V[j++]=X+k|0,V[j++]=I+n|0,V[j++]=Y+L|0,V[j++]=N+_|0,V[j++]=P+g|0,V[j++]=M+q|0,V[j++]=K+x|0,V[j++]=R+B|0,V[j++]=U+v|0,V[j++]=O+i|0,V[j++]=H+l|0,V[j++]=T+y|0,V[j++]=D+A|0,V[j++]=C+p|0,V[j++]=F+a|0,V[j++]=E+t|0}function QV($,Z,J,V){let Q=$[0],W=Z[0],X=Z[1],I=Z[2],Y=Z[3],N=$[1],P=J[0],M=J[1],K=J[2],R=J[3],U=$[2],O=Z[4],H=Z[5],T=Z[6],D=Z[7],C=$[3];for(let E=0;E<20;E+=2)Y^=w(Q+H|0,7),K^=w(Y+Q|0,9),H^=w(K+Y|0,13),Q^=w(H+K|0,18),R^=w(N+W|0,7),T^=w(R+N|0,9),W^=w(T+R|0,13),N^=w(W+T|0,18),D^=w(U+P|0,7),X^=w(D+U|0,9),P^=w(X+D|0,13),U^=w(P+X|0,18),I^=w(C+O|0,7),M^=w(I+C|0,9),O^=w(M+I|0,13),C^=w(O+M|0,18),W^=w(Q+I|0,7),X^=w(W+Q|0,9),I^=w(X+W|0,13),Q^=w(I+X|0,18),P^=w(N+Y|0,7),M^=w(P+N|0,9),Y^=w(M+P|0,13),N^=w(Y+M|0,18),O^=w(U+R|0,7),K^=w(O+U|0,9),R^=w(K+O|0,13),U^=w(R+K|0,18),H^=w(C+D|0,7),T^=w(H+C|0,9),D^=w(T+H|0,13),C^=w(D+T|0,18);let F=0;V[F++]=Q,V[F++]=N,V[F++]=U,V[F++]=C,V[F++]=P,V[F++]=M,V[F++]=K,V[F++]=R}var G$=e$(VV,{counterRight:!0,extendNonceFn:QV}),N$=o$({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,V){V=X$(J.length+32,V,!1);let Q=V.subarray(0,32),W=V.subarray(32);V.set(J,32),Z0(Q),G$($,Z,V,V);let X=Y$(W,Q);return V.set(X,16),Z0(V.subarray(0,16),X),V.subarray(16)},decrypt(J,V){r(J),V=X$(J.length+32,V,!1);let Q=V.subarray(0,32),W=V.subarray(32,48),X=V.subarray(48);V.set(J,32),Z0(Q);let I=G$($,Z,Q,Q),Y=Y$(X,I);if(!c$(W,Y))throw Error("invalid tag");return G$($,Z,V.subarray(16),V.subarray(16)),Z0(Q,W,Y),X}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function WV($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function _0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function M0($,...Z){if(!WV($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function B0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function p0($,Z){M0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function ZZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function F0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function H0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function g0($,Z){return $<<32-Z|$>>>Z}var JZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function VZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var QZ=JZ?($)=>$:($)=>VZ($);function XV($){for(let Z=0;Z<$.length;Z++)$[Z]=VZ($[Z]);return $}var s=JZ?($)=>$:XV;function IV($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function T0($){if(typeof $==="string")$=IV($);return M0($),$}class P${}function WZ($){let Z=(V,Q)=>$(Q).update(T0(V)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(V)=>$(V),Z}var XZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var b0=BigInt(4294967295),IZ=BigInt(32);function M$($,Z=!1){if(Z)return{h:Number($&b0),l:Number($>>IZ&b0)};return{h:Number($>>IZ&b0)|0,l:Number($&b0)|0}}function X0($,Z,J,V,Q){return $=$+Z+Q|0,V=g0(V^$,16),J=J+V|0,Z=g0(Z^J,12),{a:$,b:Z,c:J,d:V}}function I0($,Z,J,V,Q){return $=$+Z+Q|0,V=g0(V^$,8),J=J+V|0,Z=g0(Z^J,7),{a:$,b:Z,c:J,d:V}}class q$ extends P${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,_0($),_0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=F0(this.buffer)}update($){B0(this),$=T0($),M0($);let{blockLen:Z,buffer:J,buffer32:V}=this,Q=$.length,W=$.byteOffset,X=$.buffer;for(let I=0;I<Q;){if(this.pos===Z)s(V),this.compress(V,0,!1),s(V),this.pos=0;let Y=Math.min(Z-this.pos,Q-I),N=W+I;if(Y===Z&&!(N%4)&&I+Y<Q){let P=new Uint32Array(X,N,Math.floor((Q-I)/4));s(P);for(let M=0;I+Z<Q;M+=V.length,I+=Z)this.length+=Z,this.compress(P,M,!1);s(P);continue}J.set($.subarray(I,I+Y),this.pos),this.pos+=Y,this.length+=Y,I+=Y}return this}digestInto($){B0(this),p0($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,H0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let V=F0($);this.get().forEach((Q,W)=>V[W]=QZ(Q))}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}_cloneInto($){let{buffer:Z,length:J,finished:V,destroyed:Q,outputLen:W,pos:X}=this;return $||($=new this.constructor({dkLen:W})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=Q,$.finished=V,$.length=J,$.pos=X,$.outputLen=W,$}clone(){return this._cloneInto()}}function R$($,Z,J,V,Q,W,X,I,Y,N,P,M,K,R,U,O,H,T,D,C){let F=0;for(let E=0;E<V;E++)({a:Q,b:Y,c:K,d:H}=X0(Q,Y,K,H,J[Z+$[F++]])),{a:Q,b:Y,c:K,d:H}=I0(Q,Y,K,H,J[Z+$[F++]]),{a:W,b:N,c:R,d:T}=X0(W,N,R,T,J[Z+$[F++]]),{a:W,b:N,c:R,d:T}=I0(W,N,R,T,J[Z+$[F++]]),{a:X,b:P,c:U,d:D}=X0(X,P,U,D,J[Z+$[F++]]),{a:X,b:P,c:U,d:D}=I0(X,P,U,D,J[Z+$[F++]]),{a:I,b:M,c:O,d:C}=X0(I,M,O,C,J[Z+$[F++]]),{a:I,b:M,c:O,d:C}=I0(I,M,O,C,J[Z+$[F++]]),{a:Q,b:N,c:U,d:C}=X0(Q,N,U,C,J[Z+$[F++]]),{a:Q,b:N,c:U,d:C}=I0(Q,N,U,C,J[Z+$[F++]]),{a:W,b:P,c:O,d:H}=X0(W,P,O,H,J[Z+$[F++]]),{a:W,b:P,c:O,d:H}=I0(W,P,O,H,J[Z+$[F++]]),{a:X,b:M,c:K,d:T}=X0(X,M,K,T,J[Z+$[F++]]),{a:X,b:M,c:K,d:T}=I0(X,M,K,T,J[Z+$[F++]]),{a:I,b:Y,c:R,d:D}=X0(I,Y,R,D,J[Z+$[F++]]),{a:I,b:Y,c:R,d:D}=I0(I,Y,R,D,J[Z+$[F++]]);return{v0:Q,v1:W,v2:X,v3:I,v4:Y,v5:N,v6:P,v7:M,v8:K,v9:R,v10:U,v11:O,v12:H,v13:T,v14:D,v15:C}}var J0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},Y0=XZ.slice(),YZ=(()=>{let $=Array.from({length:16},(V,Q)=>Q),Z=(V)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((Q)=>V[Q]),J=[];for(let V=0,Q=$;V<7;V++,Q=Z(Q))J.push(...Q);return Uint8Array.from(J)})();class w$ extends q${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:V}=$,Q=V!==void 0;if(J!==void 0){if(Q)throw Error('Only "key" or "context" can be specified at same time');let W=T0(J).slice();M0(W,32),this.IV=F0(W),s(this.IV),this.flags=Z|J0.KEYED_HASH}else if(Q){let W=T0(V),X=new w$({dkLen:32},J0.DERIVE_KEY_CONTEXT).update(W).digest();this.IV=F0(X),s(this.IV),this.flags=Z|J0.DERIVE_KEY_MATERIAL}else this.IV=Y0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=ZZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,V=0){let{state:Q,pos:W}=this,{h:X,l:I}=M$(BigInt($),!0),{v0:Y,v1:N,v2:P,v3:M,v4:K,v5:R,v6:U,v7:O,v8:H,v9:T,v10:D,v11:C,v12:F,v13:E,v14:k,v15:n}=R$(YZ,V,J,7,Q[0],Q[1],Q[2],Q[3],Q[4],Q[5],Q[6],Q[7],Y0[0],Y0[1],Y0[2],Y0[3],X,I,W,Z);Q[0]=Y^H,Q[1]=N^T,Q[2]=P^D,Q[3]=M^C,Q[4]=K^F,Q[5]=R^E,Q[6]=U^k,Q[7]=O^n}compress($,Z=0,J=!1){let V=this.flags;if(!this.chunkPos)V|=J0.CHUNK_START;if(this.chunkPos===15||J)V|=J0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,V,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let Q=this.state;this.state=this.IV.slice();for(let W,X=this.chunksDone+1;J||!(X&1);X>>=1){if(!(W=this.stack.pop()))break;this.buffer32.set(W,0),this.buffer32.set(Q,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|J0.PARENT,this.buffer32,0),Q=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(Q)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:V,chunkPos:Q,posOut:W,chunkOut:X,stack:I,chunksDone:Y}=this;return $.state.set(V.slice()),$.stack=I.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=Q,$.chunksDone=Y,$.posOut=W,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,H0(this.state,this.buffer32,this.IV,this.bufferOut32),H0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:V,bufferOut32:Q}=this,{h:W,l:X}=M$(BigInt(this.chunkOut++));s(V);let{v0:I,v1:Y,v2:N,v3:P,v4:M,v5:K,v6:R,v7:U,v8:O,v9:H,v10:T,v11:D,v12:C,v13:F,v14:E,v15:k}=R$(YZ,0,V,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],Y0[0],Y0[1],Y0[2],Y0[3],X,W,Z,J);Q[0]=I^O,Q[1]=Y^H,Q[2]=N^T,Q[3]=P^D,Q[4]=M^C,Q[5]=K^F,Q[6]=R^E,Q[7]=U^k,Q[8]=$[0]^O,Q[9]=$[1]^H,Q[10]=$[2]^T,Q[11]=$[3]^D,Q[12]=$[4]^C,Q[13]=$[5]^F,Q[14]=$[6]^E,Q[15]=$[7]^k,s(V),s(Q),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,H0(this.buffer.subarray(this.pos));let $=this.flags|J0.ROOT;if(this.stack.length)$|=J0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?J0.CHUNK_START:0)|J0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){B0(this,!1),M0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let V=0,Q=$.length;V<Q;){if(this.posOut>=Z)this.b2CompressOut();let W=Math.min(Z-this.posOut,Q-V);$.set(J.subarray(this.posOut,this.posOut+W),V),this.posOut+=W,V+=W}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return _0($),this.xofInto(new Uint8Array($))}digestInto($){if(p0($,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 GZ=WZ(($)=>new w$($));function h($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function h0($){if($.length%2!==0)throw Error("Invalid hex string");let Z=new Uint8Array($.length/2);for(let J=0;J<$.length;J+=2)Z[J/2]=Number.parseInt($.substr(J,2),16);return Z}function MZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,V)=>J===Z[V])}var NZ;if(typeof Uint8Array.prototype.toBase64==="function")NZ=($)=>$.toBase64();else NZ=($)=>btoa(String.fromCharCode(...$));var PZ;if(typeof Uint8Array.fromBase64==="function")PZ=($)=>Uint8Array.fromBase64($);else PZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function x0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var K$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function qZ($){let Z=new Uint8Array(K$.length+32);return Z.set(K$),Z.set($.subarray(0,32),K$.length),Z}function RZ($){return typeof $==="string"?new TextEncoder().encode($):$}function A0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class O${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return d0($)}async gen256BitSecureRandomSeed(){return d0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=d0(24),Q=N$(Z,J).encrypt($);return new Uint8Array([...J,...Q])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),V=$.slice(24);return N$(Z,J).decrypt(V)}async deriveEd25519KeyPair($){let Z=$,J=qZ(Z),V=await globalThis.crypto.subtle.importKey("pkcs8",A0(J),{name:"Ed25519"},!0,["sign"]),Q=await globalThis.crypto.subtle.exportKey("jwk",V);if(typeof Q.x!=="string")throw Error("Ed25519 JWK missing x");let W=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:Q.x},{name:"Ed25519"},!0,["verify"]),X=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",W)),I=new Uint8Array(64);return I.set(Z,0),I.set(X,32),this.signKeys.set(h(Z),V),this.verifyKeys.set(h(X),W),{keyType:"ed25519",privateKey:I,publicKey:X}}async importSignKey($){let Z=$.subarray(0,32),J=h(Z),V=this.signKeys.get(J);if(V)return V;let Q=qZ(Z),W=await globalThis.crypto.subtle.importKey("pkcs8",A0(Q),{name:"Ed25519"},!1,["sign"]);return this.signKeys.set(J,W),W}async importVerifyKey($){let Z=h($),J=this.verifyKeys.get(Z);if(J)return J;let V=await globalThis.crypto.subtle.importKey("raw",A0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,V),V}async signEd25519($,Z){let J=RZ($),V=await this.importSignKey(Z),Q=await globalThis.crypto.subtle.sign({name:"Ed25519"},V,A0(J));return new Uint8Array(Q)}async checkSigEd25519($,Z,J){let V=RZ(Z);try{let Q=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},Q,A0($),A0(V))}catch{return!1}}async blake3($){return GZ($)}}var YV=new O$,q0=YV;var D0=64;var wZ=32,C0=8;var KZ=32;var OZ=30000,UZ=512,S;((q)=>{q[q.Success=0]="Success";q[q.InvalidSignature=3]="InvalidSignature";q[q.ClockOutOfSync=4]="ClockOutOfSync";q[q.UserNotRegistered=5]="UserNotRegistered";q[q.ServerMisconfigured=6]="ServerMisconfigured";q[q.MissingBody=7]="MissingBody";q[q.ExtraBodyContent=8]="ExtraBodyContent";q[q.MissingParam=9]="MissingParam";q[q.InvalidParam=10]="InvalidParam";q[q.InvalidRequest=11]="InvalidRequest";q[q.InternalError=12]="InternalError";q[q.NotFound=13]="NotFound";q[q.InvalidMessage=14]="InvalidMessage";q[q.NoChange=15]="NoChange";q[q.DatabaseClosed=16]="DatabaseClosed";q[q.StorageError=17]="StorageError";q[q.DatabaseError=18]="DatabaseError";q[q.HashMismatch=19]="HashMismatch";q[q.DecryptionError=20]="DecryptionError";q[q.NotImplemented=21]="NotImplemented";q[q.MissingSeed=22]="MissingSeed";q[q.OutOfBounds=23]="OutOfBounds";q[q.HostError=24]="HostError";q[q.CommunicationError=25]="CommunicationError";q[q.VarLimitExceeded=26]="VarLimitExceeded";q[q.InvalidResponse=27]="InvalidResponse";q[q.ConnectionClosed=28]="ConnectionClosed"})(S||={});var zZ="t";function z($){return[$,0]}function G($){return[void 0,$]}function GV($){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 z(new Uint8Array([0]));if(Z.length>8)return G(26);return z(new Uint8Array(Z))}function NV($,Z=0){let J=0n,V=0,Q=Z;while(!0){if(Q>=$.length)return G(14);let W=$[Q++];if(W===void 0)return G(14);if(J|=BigInt(W&127)<<BigInt(V),(W&128)===0){if(Q-Z>8)return G(26);return z({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:Q-Z})}if(V+=7,V>=56)return G(26)}}class c{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new c(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,z($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);return z(new Date($))}readVarInt(){let[$,Z]=NV(this.data,this.pos);if(Z!==0)return G(Z);this.pos+=$.bytesRead;let J=$.value;return z(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);let[J,V]=this.readBytes($);if(V!==0)return G(V);let Q=new TextDecoder().decode(J);return z(Q)}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+=$,z(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,V]=this.readStruct($);if(V!==0)return G(V);Z.push(J)}return z(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,V]=this.readBytes($);if(V!==0)return G(V);Z.push(J)}return z(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]=GV($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let Z=this.writeVarInt($.length);if(Z!==0)return Z;return this.writeBytes($),0}writeStruct($,Z){return $.encode(this,Z)}writeStructs($,Z){for(let J of Z){let V=this.writeStruct($,J);if(V!==0)return V}return 0}writeBytesSeq($){for(let Z of $)this.writeBytes(Z)}result(){let $=this.parts.reduce((V,Q)=>V+Q.length,0),Z=new Uint8Array($),J=0;for(let V of this.parts)Z.set(V,J),J+=V.length;return Z}*scan(){for(let $ of this.parts)yield $}}var f0={encode($,Z){let J=$.writeVarBytes(Z.id);if(J!==0)return J;let V=$.writeDate(Z.ts);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let[V,Q]=$.readDate();if(Q!==0)return G(Q);return z({id:Z,ts:V})}};function FZ($){let Z=new m,J=Z.writeStruct(f0,$);if(J!==0)return G(J);let V=Z.result();return z(V)}var U$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let V=$.writeVarInt(Z.off);if(V!==0)return V;let Q=$.writeVarInt(Z.ctr);if(Q!==0)return Q;let W=$.writeVarInt(Z.len);if(W!==0)return W;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let V=new c(Z),[,Q]=f0.decode(V);if(Q!==0)return G(Q);let[W,X]=$.readVarInt();if(X!==0)return G(X);let[I,Y]=$.readVarInt();if(Y!==0)return G(Y);let[N,P]=$.readVarInt();if(P!==0)return G(P);let M;if(N>0){let[K,R]=$.readBytes(KZ);if(R!==0)return G(R);M=K}return z({eid:Z,off:W,ctr:I,len:N,hsh:M})}};function HZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function PV($,Z,J){let V=x0(Z.privateKey,$);return(await J.blake3(V)).slice(0,C0)}async function TZ($,Z,J,V){let Q;if($.bod&&$.len>0)Q=await J.blake3($.bod);let W=new m,X=U$.encode(W,{...$,hsh:Q});if(X!==0)return G(X);let I=W.result(),Y=await PV(I,Z,J),N=await V.deriveFromKDM(Y),P=await J.encryptXSalsa20Poly1305Combined(I,N),M=$.bod?await J.encryptXSalsa20Poly1305Combined($.bod,N):new Uint8Array(0),K=await J.signEd25519(P,Z.privateKey);return z({sig:K,kdm:Y,headCph:P,bodyCph:M})}async function AZ($,Z,J,V){let Q=new c($),[W,X]=U$.decode(Q);if(X!==0)return G(14);let I;try{I=Z&&Z.length>0?await V.decryptXSalsa20Poly1305Combined(Z,J):void 0}catch{return G(20)}let Y=W.hsh&&I===void 0,N=W.hsh===void 0&&I!==void 0;if(Y||N)return G(19);if(W.hsh&&I){let M=await V.blake3(I);if(!MZ(M,W.hsh))return G(19)}let P=await V.blake3($);return z({msgHead:W,bod:I,headHash:P})}async function z$($,Z,J){let V=new m,Q=V.writeDate(Z);if(Q!==0)return G(Q);let W=V.result(),X=await J.signEd25519(W,$.privateKey);return z({pubKey:$.publicKey,sig:X,timestamp:Z})}async function $0($,Z,J){let V=J.now().getTime(),Q=$.timestamp.getTime();if(Math.abs(V-Q)>OZ)return 4;let X=new m;X.writeDate($.timestamp);let I=X.result();if(!await Z.checkSigEd25519($.sig,I,$.pubKey))return 3;return 0}class S0{now(){return new Date}}function DZ($,Z,J,V){let Q=Z.getTime()-$.getTime(),W=J.getTime()-V.getTime();return(Q+W)/2}var v0={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 V;if(Z>0){let[Q,W]=$.readVarInt();if(W!==0)return G(W);V=Q}return z({quota:Z,usage:V})}};var E0={encode($,Z){$.writeBytes(new Uint8Array([Z.status]));let J=$.writeDate(Z.timeRcvd);if(J!==0)return J;let V=$.writeDate(Z.timeSent);if(V!==0)return V;let Q=$.writeVarInt(Z.subscription.term);if(Q!==0)return Q;let W=$.writeVarInt(Z.subscription.elapsed);if(W!==0)return W;let X=$.writeStruct(v0,Z.subscription.stat);if(X!==0)return X;let I=$.writeStruct(v0,Z.subscription.dyn);if(I!==0)return I;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return G(J);let V=Z[0],[Q,W]=$.readDate();if(W!==0)return G(W);let[X,I]=$.readDate();if(I!==0)return G(I);let[Y,N]=$.readVarInt();if(N!==0)return G(N);let[P,M]=$.readVarInt();if(M!==0)return G(M);let[K,R]=$.readStruct(v0);if(R!==0)return G(R);let[U,O]=$.readStruct(v0);if(O!==0)return G(O);return z({status:V,timeRcvd:Q,timeSent:X,subscription:{term:Y,elapsed:P,stat:K,dyn:U}})}};async function F$($,Z,J){let{crypto:V,enclave:Q}=$,W=await Q.derive(Z,J);return await V.deriveEd25519KeyPair(W)}var H$={encode($,Z){let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let V=$.writeVarInt(Z.seq);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let[V,Q]=$.readVarInt();if(Q!==0)return G(Q);return z({headCph:Z,seq:V})}};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(wZ);if(J!==0)return G(J);let[V,Q]=$.readBytes(D0);if(Q!==0)return G(Q);let[W,X]=$.readDate();if(X!==0)return G(X);return z({pubKey:Z,sig:V,timestamp:W})}};var CZ={async encodeReq($,Z,J,V,Q){let W=Q.writeStruct(o,J);if(W!==0)return W;for(let X of V)Q.writeVarInt(X);return 0},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W}=$,[X,I]=Z.readStruct(o);if(I!==0)return I;let Y=await $0(X,Q,V);if(Y!==0)return Y;let{pubKey:N}=X,[P,M]=await W.hasUser(N);if(M!==0)return M;if(!P)return 5;let[K,R]=Z.readVarInt();if(R!==0)return R;if(!Z.done())return 8;let[U,O]=await W.listHeads(N,K);if(O!==0)return O;return J.writeStructs(H$,U)},decodeResp($){return $.readStructs(H$)}};var T$={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[V,Q]=$.readVarBytes();if(Q!==0)return G(Q);return z({seq:Z,bodyCph:V})}};var SZ={async encodeReq($,Z,J,V,Q){let W=Q.writeStruct(o,J);if(W!==0)return W;for(let X of V){let I=Q.writeVarInt(X);if(I!==0)return I}return 0},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W}=$,[X,I]=Z.readStruct(o);if(I!==0)return I;let Y=await $0(X,Q,V);if(Y!==0)return Y;let{pubKey:N}=X,[P,M]=await W.hasUser(N);if(M!==0)return M;if(!P)return 5;let K=[];while(!Z.done()){let[O,H]=Z.readVarInt();if(H!==0)return H;K.push(O)}console.info(`PULL: ${K.length} bags`);let[R,U]=await W.getBodies(N,K);if(U!==0)return U;if(!R)return 17;for(let{seq:O,bodyCph:H}of R){let T={seq:O,bodyCph:H},D=J.writeStruct(T$,T);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(T$)}};var A$={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let V=$.writeVarBytes(Z.bodyCph);if(V!==0)return V;return 0},decode($){let[Z,J]=$.readBytes(D0);if(J!==0)return G(J);let[V,Q]=$.readBytes(C0);if(Q!==0)return G(Q);let[W,X]=$.readVarBytes();if(X!==0)return G(X);let[I,Y]=$.readVarBytes();if(Y!==0)return G(Y);return z({sig:Z,kdm:V,headCph:W,bodyCph:I})}};var D$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let V=$.writeVarBytes(Z.headCph);if(V!==0)return V;let Q=Z.bodyCph?Z.bodyCph.length:0,W=$.writeVarInt(Q);if(W!==0)return W;if(Q>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);let[V,Q]=$.readVarBytes();if(Q!==0)return G(Q);let[W,X]=$.readVarInt();if(X!==0)return G(X);let I;if(W>0){let[Y,N]=$.readBytes(W);if(N!==0)return G(N);I=Y}return z({seq:Z,headCph:V,bodyCph:I})}};var m0={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(D0);if(J!==0)return G(J);let[V,Q]=$.readBytes(C0);if(Q!==0)return G(Q);let[W,X]=$.readVarBytes();if(X!==0)return G(X);return z({sig:Z,kdm:V,headCph:W})}};var c0={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[V,Q]=$.readBytes(1);if(Q!==0)return G(Q);let W=V[0];if(W!==0)return z({idx:Z,status:W});let[X,I]=$.readVarInt();if(I!==0)return G(I);return z({idx:Z,status:W,seq:X})}};var EZ={async encodeReq($,Z,J,V,Q){let W=Q.writeStruct(o,J);if(W!==0)return W;let X=Q.writeStructs(A$,V);if(X!==0)return X;return 0},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W,notifier:X}=$,[I,Y]=Z.readStruct(o);if(Y!==0)return Y;let N=await $0(I,Q,V);if(N!==0)return N;let{pubKey:P}=I,[M,K]=await W.hasUser(P);if(K!==0)return K;if(!M)return 5;let[R,U]=Z.readStructs(A$);if(U!==0)return U;console.info(`PUSH: ${R.length} bags`);let O=[],H=[];for(let F=0;F<R.length;F++){let E=R[F];if(!await HZ(E,P,Q)){let n={idx:F,status:3},L=J.writeStruct(c0,n);if(L!==0)return L;continue}O.push(F),H.push(E)}let[T,D]=await W.setBags(P,H);if(D!==0)return D;if(!T||T.length!==H.length)return 17;let C=[];for(let F=0;F<H.length;F++){let E=H[F],k=O[F],n=T[F],L=new m,_=L.writeStruct(m0,E);if(_!==0)return _;let g=L.result(),q={seq:n,headCph:g};if(R.length===1&&E.bodyCph.length<=UZ)q.bodyCph=E.bodyCph;C.push(q);let x={idx:k,status:0,seq:n},B=J.writeStruct(c0,x);if(B!==0)return B}if(C.length>0){let F=new m,E=F.writeStructs(D$,C);if(E!==0)return E;let k=F.result();await Promise.resolve(X.push(P,k))}return 0},decodeResp($){return $.readStructs(c0)}};var mZ={async encodeReq($,Z,J,V,Q){return Q.writeStruct(o,J)},async handleReq($,Z,J){let{clock:V,crypto:Q,storage:W}=$,[X,I]=Z.readStruct(o);if(I!==0)return I;let Y=await $0(X,Q,V);if(Y!==0)return Y;let{pubKey:N}=X;if(!Z.done())return 8;let[P,M]=await W.addUser(N);if(M!==0)return M;return 0},decodeResp($){return z(void 0)}};class C${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},V=()=>{}){let{url:Q}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let W=new m;W.writeStruct(o,$);let X=W.result(),I=h(X);return Q.searchParams.set("t",I),this.websocket=new WebSocket(Q),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),V()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(Y)=>{let N=new Uint8Array(Y.data);Z(N)},this.websocket.onerror=(Y)=>{console.log(`ERROR: ${JSON.stringify(Y)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var u={user:{path:"/user",endpoint:mZ,name:0},push:{path:"/push",endpoint:EZ,name:2},peek:{path:"/peek",endpoint:CZ,name:1},pull:{path:"/pull",endpoint:SZ,name:3}},MV={0:u.user,2:u.push,1:u.peek,3:u.pull},LZ={[u.user.path]:u.user,[u.push.path]:u.push,[u.peek.path]:u.peek,[u.pull.path]:u.pull};class jZ{url;listener;constructor($){this.url=$;this.listener=new C$($)}async call($,Z){let{path:J}=MV[$],V=new URL(J,this.url);try{return await RV(V,Z)}catch{return G(25)}}}var S$=($)=>{return new jZ($.handle)};function L0($){let Z=new m;if(Z.writeStruct(E0,$)!==0)return new Response(null,{status:500});return E$(Z)}function E$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var qV={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function m$($){return new Response($.body,{headers:{...$.headers,...qV},status:$.status,statusText:$.statusText})}async function RV($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return G(24);let V=await c.fromResponse(J);return z(V)}class o0{enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,V,Q,W){this.enclave=$;this.crypto=Z;this.host=J;this.clock=V;this.transport=Q;this.updateHostMeta=W}async call($,Z){let{clock:J,crypto:V,transport:Q}=this,{endpoint:W,name:X}=$,I=await this.keys(),Y=J.now(),[N,P]=await z$(I,Y,V);if(P!==0)return G(P);let M=new m,K=await W.encodeReq(this,I,N,Z,M);if(K!==0)return G(K);let R=J.now(),[U,O]=await Q.call(X,M),H=J.now();if(O!==0)return G(O);let[T,D]=U.readStruct(E0);if(D!==0)return G(D);if(T.status!==0)return G(T.status);let F={clockOffset:DZ(R,T.timeRcvd,T.timeSent,H),subscription:T.subscription},E=await this.updateHostMeta(F);if(E!==0)return G(E);return W.decodeResp(U)}keys=()=>{let{host:$}=this;return F$(this,$.label,$.idx)};seal=async($)=>{let{crypto:Z,enclave:J}=this,V=await this.keys();return TZ($,V,Z,J)};register=()=>this.call(u.user,[]);peek=($)=>this.call(u.peek,[$]);push=($)=>this.call(u.push,$);pull=($)=>this.call(u.pull,$);listen=async($,Z,J)=>{let{clock:V,crypto:Q,host:W,transport:X}=this,{listener:I}=X,Y=await F$(this,W.label,W.idx),N=V.now(),[P,M]=await z$(Y,N,Q);if(M!==0)return M;return await I.connect(P,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class L${seed;crypto;constructor($,Z){this.seed=$,this.crypto=Z}async deriveFromKDM($){let Z=x0(this.seed,$);return await this.crypto.blake3(Z)}async derive($,Z=0){let J=new TextEncoder().encode($),V=new Uint8Array(8);new DataView(V.buffer).setBigUint64(0,BigInt(Z),!1);let Q=x0(J,V);return await this.deriveFromKDM(Q)}}class j${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 V=Array.from(J);for(let Q of V)Q(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function kZ($,Z,J,V=0){let Q=Z.now(),W=new m,X=W.writeVarString($);if(X!==0)return G(X);let Y={id:W.result(),ts:new Date(0)},[N,P]=FZ(Y);if(P!==0)return G(P);let M=Q.getTime()-Y.ts.getTime();return z({eid:N,off:M,ctr:V,len:J.length,bod:J})}class wV{singletonType;latest;latestOff=-1;emitter=new j$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new c(Z.eid),[V,Q]=J.readStruct(f0);if(Q!==0)continue;let W=new m;W.writeVarString(this.singletonType);let X=W.result();if(V.id.length===X.length&&V.id.every((I,Y)=>I===X[Y])){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)};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function _Z($,Z,J,V){let Q=new c($.headCph),[W,X]=Q.readStruct(m0);if(X!==0)return G(X);let{sig:I,kdm:Y,headCph:N}=W;if(!await V.checkSigEd25519(I,N,Z.publicKey))return G(3);let M=await J.deriveFromKDM(Y),K;try{K=await V.decryptXSalsa20Poly1305Combined(N,M)}catch{return G(20)}return z({kdm:Y,headEnc:K})}var k0=bJ(BJ(),1),gQ={encode:k0.encode,decode:k0.decode,decodeAsync:k0.decodeAsync},xQ=gQ;import{Database as fQ}from"bun:sqlite";var vY=Symbol("EntityID");var iY=Symbol("MasterSeed"),lY=Symbol("DerivationSeed"),yY=Symbol("PublicKey"),rY=Symbol("PrivateKey"),nY=Symbol("HostSpecificKeyPair"),dY=Symbol("Hash"),N0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};var e=new fQ("diplomatic.db");e.exec("PRAGMA journal_mode=WAL;");e.exec("PRAGMA synchronous=NORMAL;");e.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS users (
|
|
3
3
|
pubKey TEXT PRIMARY KEY
|
|
4
4
|
);
|
|
5
|
-
`);
|
|
5
|
+
`);e.exec(`
|
|
6
6
|
CREATE TABLE IF NOT EXISTS bags (
|
|
7
7
|
userPubKey TEXT,
|
|
8
8
|
seq INTEGER,
|
|
@@ -11,4 +11,4 @@ var P8=Object.create;var{getPrototypeOf:S8,defineProperty:oJ,getOwnPropertyNames
|
|
|
11
11
|
PRIMARY KEY (userPubKey, seq),
|
|
12
12
|
UNIQUE (userPubKey, seq)
|
|
13
13
|
);
|
|
14
|
-
`);var
|
|
14
|
+
`);var vQ={async addUser($){try{let Z=h($);return e.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Z]),z(void 0)}catch{return G(17)}},async hasUser($){try{let Z=h($),J=e.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?)").get(Z),V=J?J["EXISTS (SELECT 1 FROM users WHERE pubKey = ?)"]:!1;return z(Boolean(V))}catch{return G(17)}},async subMeta($){return z(N0)},async setBags($,Z){if(Z.length<1)return z([]);try{let J=h($);e.exec("BEGIN IMMEDIATE");try{let V=e.prepare("SELECT MAX(seq) FROM bags WHERE userPubKey = ?").get(J),Q=V?V["MAX(seq)"]||0:0,W=[],X=e.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let I of Z){Q+=1;let Y=new m;Y.writeStruct(m0,I),X.run(J,Q,Y.result(),I.bodyCph),W.push(Q)}return e.exec("COMMIT"),z(W)}catch(V){try{e.exec("ROLLBACK")}catch{}throw V}}catch{return G(17)}},async getBodies($,Z){if(Z.length<1)return z([]);try{let J=h($),V=[],Q=100,W=99;for(let X=0;X<Z.length;X+=99){let I=Z.slice(X,X+99),Y=I.map(()=>"?").join(","),N=e.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${Y})`).all(J,...I);for(let P of N)if(P.bodyCph)V.push({seq:P.seq,bodyCph:new Uint8Array(P.bodyCph)})}return z(V)}catch{return G(17)}},async listHeads($,Z){try{let J=h($),V=e.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(J,Z);return z(V.map((Q)=>({seq:Q.seq,headCph:new Uint8Array(Q.headCph)})))}catch{return G(17)}}},gJ=vQ;class u${storage;crypto;notifier;clock;constructor($,Z,J,V){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=V}corsHandler=async($)=>{if($.method==="OPTIONS")return m$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),m$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),V=new URL($.url);if($.method!=="POST"){let N=Z.now();return L0({status:13,timeRcvd:J,timeSent:N,subscription:N0})}if(!$.body){let N=Z.now();return L0({status:7,timeRcvd:J,timeSent:N,subscription:N0})}let W=new Uint8Array(await $.arrayBuffer()),X=new c(W),I=V.pathname,Y=LZ[I]?.endpoint;if(!Y){let N=Z.now();return L0({status:13,timeRcvd:J,timeSent:N,subscription:N0})}try{let N=new m,P=await Y.handleReq(this,X,N),M=N0,K={status:P,timeRcvd:J,timeSent:this.clock.now(),subscription:M},R=new m;if(R.writeStruct(E0,K)!==0)return new Response(null,{status:500});if(P!==0){let O=Z.now();return L0({status:P,timeRcvd:J,timeSent:O,subscription:N0})}return N.prependBytes(R.result()),E$(N)}catch(N){let P=Z.now();return console.error(N),console.trace(),L0({status:12,timeRcvd:J,timeSent:P,subscription:N0})}}}async function xJ($,Z){let V=new URL($.url).searchParams.get(zZ);if(!V)return G(11);let Q=h0(V),W=new c(Q),[X,I]=W.readStruct(o);if(I!==0)return G(11);let Y=await $0(X,Z.crypto,Z.clock);if(Y!==0)return G(Y);return z(X)}class vJ{recvs=new Map;async open($,Z,J,V){let Q=await $0($,J,V);if(Q!==0)return{send:()=>Q,shut:()=>Q,status:Q};let W=h($.pubKey);if(!this.recvs.has(W))this.recvs.set(W,new Set);return this.recvs.get(W)?.add(Z),{send:(X)=>{return Z(X),0},shut:()=>{return this.recvs.get(W)?.delete(Z),0},status:0}}async push($,Z){let J=h($),V=this.recvs.get(J);if(V)for(let Q of V)Q(Z)}}var fJ=new vJ;async function iQ($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new u$(gJ,q0,fJ,new S0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,V)=>{if(J.headers.get("upgrade")==="websocket"){let[Q,W]=await xJ(J,Z);if(W!==0)return new Response("Unauthorized",{status:401});return V.upgrade(J,{data:{authTS:Q}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let V=J.data.authTS;fJ.open(V,(Q)=>J.send(Q),Z.crypto,Z.clock).then((Q)=>{if(Q.status!==0){J.close();return}J.channel=Q})},message:(J,V)=>{},close:(J)=>{J.channel?.shut()}}})}class iJ{enclave;conn;clock;constructor({seed:$,clock:Z=new S0}){this.enclave=new L$($,q0),this.clock=Z}async connect($,Z){let J=new S0,V=()=>Promise.resolve(0);this.conn=new o0(this.enclave,q0,$,J,Z,V);let[,Q]=await this.conn.register();return Q}async push($){if(!this.conn)return G(28);let Z=[];for(let Q of $){let[W,X]=await this.conn.seal(Q);if(X!==0)return G(X);Z.push(W)}let[J,V]=await this.conn.push(Z);if(V!==0)return G(V);return z(J)}async peek($){if(!this.conn)return G(28);return this.conn.peek($)}async pull($){if(!this.conn)return G(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return G(28);let J=await this.conn.keys(),[V,Q]=await _Z($,J,this.enclave,q0);if(Q!==0)return G(Q);let W=await this.enclave.deriveFromKDM(V.kdm);return AZ(V.headEnc,Z.bodyCph,W,q0)}async upsertSingletonSync($,Z){let[J,V]=await kZ($,this.clock,Z);if(V!==0)return V;let[,Q]=await this.push([J]);return Q}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function lQ({seed:$,host:Z,transport:J}){let V=new iJ({seed:$}),Q=await V.connect(Z,J);return[V,Q]}async function g8({seed:$,host:Z,transport:J}){let V=J??S$(Z),[Q,W]=await lQ({seed:$,host:Z,transport:V});if(W!==0)console.error(`Failed to initialize CLI: ${S[W]}`),process.exit(1);return Q}function x8($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=h0(Z);if(J.length!==32)console.error(`${$} must be 64 hex chars (32 bytes)`),process.exit(1);return J}function f8($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{iQ as runBunHost,D$ as notifItemCodec,xQ as msgpack,x8 as loadSeedOrPanic,f8 as loadHostOrPanic,g8 as initCLIOrPanic,lQ as initCLI,S$ as hostHTTPTransport,S as Status,c as Decoder,iJ as CLIClient};
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { DerivationSeed, Hash, ICrypto, KeyPair } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* ICrypto: noble for XSalsa20 + blake3; native WebCrypto for all Ed25519.
|
|
4
|
+
*/
|
|
2
5
|
export declare class NobleCrypto implements ICrypto {
|
|
6
|
+
private verifyKeys;
|
|
7
|
+
private signKeys;
|
|
3
8
|
genRandomBytes(bytes: number): Promise<Uint8Array>;
|
|
4
9
|
gen256BitSecureRandomSeed(): Promise<Uint8Array>;
|
|
5
10
|
encryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
6
11
|
decryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
7
12
|
deriveEd25519KeyPair(derivationSeed: DerivationSeed): Promise<KeyPair>;
|
|
13
|
+
private importSignKey;
|
|
14
|
+
private importVerifyKey;
|
|
8
15
|
signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
|
|
9
16
|
checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array): Promise<boolean>;
|
|
10
17
|
blake3(data: Uint8Array): Promise<Hash>;
|