@interncom/diplomatic 0.11.5 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/cli/index.mjs +2 -2
  2. package/dist/cli/shared/binary.d.ts +4 -0
  3. package/dist/cli/shared/codecs/bundleHost.d.ts +11 -0
  4. package/dist/cli/shared/codecs/identityBundle.d.ts +25 -0
  5. package/dist/cli/shared/codecs/pairPackage.d.ts +15 -0
  6. package/dist/cli/shared/crypto/enclave.d.ts +113 -2
  7. package/dist/cli/shared/crypto/entropy.d.ts +11 -0
  8. package/dist/cli/shared/seed.d.ts +25 -0
  9. package/dist/cli/shared/types.d.ts +4 -6
  10. package/dist/cli/shared/webauthn/common.d.ts +38 -0
  11. package/dist/cli/shared/webauthn/largeBlob.d.ts +19 -0
  12. package/dist/cli/shared/webauthn/prf.d.ts +33 -0
  13. package/dist/cli/shared/worker/embeddedWorkerSource.d.ts +1 -0
  14. package/dist/cli/shared/worker/spawn.d.ts +5 -0
  15. package/dist/cli/src/index.d.ts +10 -8
  16. package/dist/web/client.d.ts +3 -2
  17. package/dist/web/identity/pairPackage.d.ts +31 -0
  18. package/dist/web/index.d.ts +18 -6
  19. package/dist/web/index.mjs +1 -1
  20. package/dist/web/openClient.d.ts +14 -109
  21. package/dist/web/passkey/largeBlob.d.ts +17 -0
  22. package/dist/web/passkey/prf-store.d.ts +62 -0
  23. package/dist/web/passkey/seed.d.ts +13 -77
  24. package/dist/web/passkey/webauthn.d.ts +1 -0
  25. package/dist/web/react/useClient.d.ts +14 -21
  26. package/dist/web/shared/binary.d.ts +4 -0
  27. package/dist/web/shared/codecs/bundleHost.d.ts +11 -0
  28. package/dist/web/shared/codecs/identityBundle.d.ts +25 -0
  29. package/dist/web/shared/codecs/pairPackage.d.ts +15 -0
  30. package/dist/web/shared/codecs/pairPackageEnvelope.d.ts +18 -0
  31. package/dist/web/shared/crypto/enclave.d.ts +113 -2
  32. package/dist/web/shared/crypto/entropy.d.ts +11 -0
  33. package/dist/web/shared/seed.d.ts +25 -0
  34. package/dist/web/shared/types.d.ts +4 -6
  35. package/dist/web/shared/webauthn/common.d.ts +38 -0
  36. package/dist/web/shared/webauthn/largeBlob.d.ts +19 -0
  37. package/dist/web/shared/webauthn/prf.d.ts +33 -0
  38. package/dist/web/shared/worker/embeddedWorkerSource.d.ts +1 -0
  39. package/dist/web/shared/worker/spawn.d.ts +5 -0
  40. package/dist/web/stores/idb/seed.d.ts +24 -6
  41. package/dist/web/stores/memory/seed.d.ts +3 -4
  42. package/dist/web/types.d.ts +13 -7
  43. package/dist/web/worker/client.d.ts +26 -48
  44. package/dist/web/worker.mjs +1 -1
  45. package/package.json +1 -5
@@ -1,4 +1,4 @@
1
- var vJ=Object.create;var{getPrototypeOf:lJ,defineProperty:p$,getOwnPropertyNames:yJ}=Object;var uJ=Object.prototype.hasOwnProperty;function iJ($){return this[$]}var bJ,pJ,rJ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var V=Z?bJ??=new WeakMap:pJ??=new WeakMap,W=V.get($);if(W)return W}J=$!=null?vJ(lJ($)):{};let X=Z||!$||!$.__esModule?p$(J,"default",{value:$,enumerable:!0}):J;for(let Y of yJ($))if(!uJ.call(X,Y))p$(X,Y,{get:iJ.bind($,Y),enumerable:!0});if(Q)V.set($,X);return X};var n=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var o0=n((xZ)=>{Object.defineProperty(xZ,"__esModule",{value:!0});xZ.utf8Count=MQ;xZ.utf8EncodeJs=_Z;xZ.utf8EncodeTE=mZ;xZ.utf8Encode=KQ;xZ.utf8DecodeJs=BZ;xZ.utf8DecodeTD=gZ;xZ.utf8Decode=wQ;function MQ($){let Z=$.length,J=0,Q=0;while(Q<Z){let V=$.charCodeAt(Q++);if((V&4294967168)===0){J++;continue}else if((V&4294965248)===0)J+=2;else{if(V>=55296&&V<=56319){if(Q<Z){let W=$.charCodeAt(Q);if((W&64512)===56320)++Q,V=((V&1023)<<10)+(W&1023)+65536}}if((V&4294901760)===0)J+=3;else J+=4}}return J}function _Z($,Z,J){let Q=$.length,V=J,W=0;while(W<Q){let X=$.charCodeAt(W++);if((X&4294967168)===0){Z[V++]=X;continue}else if((X&4294965248)===0)Z[V++]=X>>6&31|192;else{if(X>=55296&&X<=56319){if(W<Q){let Y=$.charCodeAt(W);if((Y&64512)===56320)++W,X=((X&1023)<<10)+(Y&1023)+65536}}if((X&4294901760)===0)Z[V++]=X>>12&15|224,Z[V++]=X>>6&63|128;else Z[V++]=X>>18&7|240,Z[V++]=X>>12&63|128,Z[V++]=X>>6&63|128}Z[V++]=X&63|128}}var RQ=new TextEncoder,zQ=50;function mZ($,Z,J){RQ.encodeInto($,Z.subarray(J))}function KQ($,Z,J){if($.length>zQ)mZ($,Z,J);else _Z($,Z,J)}var OQ=4096;function BZ($,Z,J){let Q=Z,V=Q+J,W=[],X="";while(Q<V){let Y=$[Q++];if((Y&128)===0)W.push(Y);else if((Y&224)===192){let G=$[Q++]&63;W.push((Y&31)<<6|G)}else if((Y&240)===224){let G=$[Q++]&63,N=$[Q++]&63;W.push((Y&31)<<12|G<<6|N)}else if((Y&248)===240){let G=$[Q++]&63,N=$[Q++]&63,q=$[Q++]&63,P=(Y&7)<<18|G<<12|N<<6|q;if(P>65535)P-=65536,W.push(P>>>10&1023|55296),P=56320|P&1023;W.push(P)}else W.push(Y);if(W.length>=OQ)X+=String.fromCharCode(...W),W.length=0}if(W.length>0)X+=String.fromCharCode(...W);return X}var UQ=new TextDecoder,FQ=200;function gZ($,Z,J){let Q=$.subarray(Z,Z+J);return UQ.decode(Q)}function wQ($,Z,J){if(J>FQ)return gZ($,Z,J);else return BZ($,Z,J)}});var j$=n((vZ)=>{Object.defineProperty(vZ,"__esModule",{value:!0});vZ.ExtData=void 0;class fZ{type;data;constructor($,Z){this.type=$,this.data=Z}}vZ.ExtData=fZ});var s0=n((yZ)=>{Object.defineProperty(yZ,"__esModule",{value:!0});yZ.DecodeError=void 0;class a0 extends Error{constructor($){super($);let Z=Object.create(a0.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:a0.name})}}yZ.DecodeError=a0});var t0=n((iZ)=>{Object.defineProperty(iZ,"__esModule",{value:!0});iZ.UINT32_MAX=void 0;iZ.setUint64=LQ;iZ.setInt64=jQ;iZ.getInt64=kQ;iZ.getUint64=_Q;iZ.UINT32_MAX=4294967295;function LQ($,Z,J){let Q=J/4294967296,V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function jQ($,Z,J){let Q=Math.floor(J/4294967296),V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function kQ($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function _Q($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var k$=n((oZ)=>{Object.defineProperty(oZ,"__esModule",{value:!0});oZ.timestampExtension=oZ.EXT_TIMESTAMP=void 0;oZ.encodeTimeSpecToTimestamp=rZ;oZ.encodeDateToTimeSpec=dZ;oZ.encodeTimestampExtension=nZ;oZ.decodeTimestampToTimeSpec=hZ;oZ.decodeTimestampExtension=cZ;var fQ=s0(),pZ=t0();oZ.EXT_TIMESTAMP=-1;var vQ=4294967295,lQ=17179869183;function rZ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=lQ)if(Z===0&&$<=vQ){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,V=new Uint8Array(8),W=new DataView(V.buffer);return W.setUint32(0,Z<<2|J&3),W.setUint32(4,Q),V}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,pZ.setInt64)(Q,4,$),J}}function dZ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,V=Math.floor(Q/1e9);return{sec:J+V,nsec:Q-V*1e9}}function nZ($){if($ instanceof Date){let Z=dZ($);return rZ(Z)}else return null}function hZ($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let J=Z.getUint32(0),Q=0;return{sec:J,nsec:0}}case 8:{let J=Z.getUint32(0),Q=Z.getUint32(4),V=(J&3)*4294967296+Q,W=J>>>2;return{sec:V,nsec:W}}case 12:{let J=(0,pZ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new fQ.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function cZ($){let Z=hZ($);return new Date(Z.sec*1000+Z.nsec/1e6)}oZ.timestampExtension={type:oZ.EXT_TIMESTAMP,encode:nZ,decode:cZ}});var $$=n((tZ)=>{Object.defineProperty(tZ,"__esModule",{value:!0});tZ.ExtensionCodec=void 0;var e0=j$(),rQ=k$();class _${static defaultCodec=new _$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(rQ.timestampExtension)}register({type:$,encode:Z,decode:J}){if($>=0)this.encoders[$]=Z,this.decoders[$]=J;else{let Q=-1-$;this.builtInEncoders[Q]=Z,this.builtInDecoders[Q]=J}}tryToEncode($,Z){for(let J=0;J<this.builtInEncoders.length;J++){let Q=this.builtInEncoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let W=-1-J;return new e0.ExtData(W,V)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let W=J;return new e0.ExtData(W,V)}}}if($ instanceof e0.ExtData)return $;return null}decode($,Z,J){let Q=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(Q)return Q($,Z,J);else return new e0.ExtData(Z,$)}}tZ.ExtensionCodec=_$});var m$=n(($J)=>{Object.defineProperty($J,"__esModule",{value:!0});$J.ensureUint8Array=nQ;function dQ($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function nQ($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(dQ($))return new Uint8Array($);else return Uint8Array.from($)}});var g$=n((QJ)=>{Object.defineProperty(QJ,"__esModule",{value:!0});QJ.Encoder=QJ.DEFAULT_INITIAL_BUFFER_SIZE=QJ.DEFAULT_MAX_DEPTH=void 0;var ZJ=o0(),cQ=$$(),JJ=t0(),oQ=m$();QJ.DEFAULT_MAX_DEPTH=100;QJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class B${extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??cQ.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??QJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??QJ.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 B$({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef($){if(this.entered)return this.clone().encodeSharedRef($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode($){if(this.entered)return this.clone().encode($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode($,Z){if(Z>this.maxDepth)throw Error(`Too deep objects in depth ${Z}`);if($==null)this.encodeNil();else if(typeof $==="boolean")this.encodeBoolean($);else if(typeof $==="number")if(!this.forceIntegerToFloat)this.encodeNumber($);else this.encodeNumberAsFloat($);else if(typeof $==="string")this.encodeString($);else if(this.useBigInt64&&typeof $==="bigint")this.encodeBigInt64($);else this.encodeObject($,Z)}ensureBufferSizeToWrite($){let Z=this.pos+$;if(this.view.byteLength<Z)this.resizeBuffer(Z*2)}resizeBuffer($){let Z=new ArrayBuffer($),J=new Uint8Array(Z),Q=new DataView(Z);J.set(this.bytes),this.view=Q,this.bytes=J}encodeNil(){this.writeU8(192)}encodeBoolean($){if($===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber($){if(!this.forceIntegerToFloat&&Number.isSafeInteger($))if($>=0)if($<128)this.writeU8($);else if($<256)this.writeU8(204),this.writeU8($);else if($<65536)this.writeU8(205),this.writeU16($);else if($<4294967296)this.writeU8(206),this.writeU32($);else if(!this.useBigInt64)this.writeU8(207),this.writeU64($);else this.encodeNumberAsFloat($);else if($>=-32)this.writeU8(224|$+32);else if($>=-128)this.writeU8(208),this.writeI8($);else if($>=-32768)this.writeU8(209),this.writeI16($);else if($>=-2147483648)this.writeU8(210),this.writeI32($);else if(!this.useBigInt64)this.writeU8(211),this.writeI64($);else this.encodeNumberAsFloat($);else this.encodeNumberAsFloat($)}encodeNumberAsFloat($){if(this.forceFloat32)this.writeU8(202),this.writeF32($);else this.writeU8(203),this.writeF64($)}encodeBigInt64($){if($>=BigInt(0))this.writeU8(207),this.writeBigUint64($);else this.writeU8(211),this.writeBigInt64($)}writeStringHeader($){if($<32)this.writeU8(160+$);else if($<256)this.writeU8(217),this.writeU8($);else if($<65536)this.writeU8(218),this.writeU16($);else if($<4294967296)this.writeU8(219),this.writeU32($);else throw Error(`Too long string: ${$} bytes in UTF-8`)}encodeString($){let J=(0,ZJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,ZJ.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,oQ.ensureUint8Array)($);this.writeU8a(J)}encodeArray($,Z){let J=$.length;if(J<16)this.writeU8(144+J);else if(J<65536)this.writeU8(220),this.writeU16(J);else if(J<4294967296)this.writeU8(221),this.writeU32(J);else throw Error(`Too large array: ${J}`);for(let Q of $)this.doEncode(Q,Z+1)}countWithoutUndefined($,Z){let J=0;for(let Q of Z)if($[Q]!==void 0)J++;return J}encodeMap($,Z){let J=Object.keys($);if(this.sortKeys)J.sort();let Q=this.ignoreUndefined?this.countWithoutUndefined($,J):J.length;if(Q<16)this.writeU8(128+Q);else if(Q<65536)this.writeU8(222),this.writeU16(Q);else if(Q<4294967296)this.writeU8(223),this.writeU32(Q);else throw Error(`Too large map object: ${Q}`);for(let V of J){let W=$[V];if(!(this.ignoreUndefined&&W===void 0))this.encodeString(V),this.doEncode(W,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),Q=J.length;if(Q>=4294967296)throw Error(`Too large extension object: ${Q}`);this.writeU8(201),this.writeU32(Q),this.writeI8($.type),this.writeU8a(J);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),(0,JJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,JJ.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}}QJ.Encoder=B$});var GJ=n((YJ)=>{Object.defineProperty(YJ,"__esModule",{value:!0});YJ.encode=sQ;var aQ=g$();function sQ($,Z){return new aQ.Encoder(Z).encodeSharedRef($)}});var IJ=n((NJ)=>{Object.defineProperty(NJ,"__esModule",{value:!0});NJ.prettyByte=eQ;function eQ($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var RJ=n((PJ)=>{Object.defineProperty(PJ,"__esModule",{value:!0});PJ.CachedKeyDecoder=void 0;var ZV=o0(),JV=16,QV=16;class qJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=JV,Z=QV){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let J=0;J<this.maxKeyLength;J++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,J){let Q=this.caches[J-1];$:for(let V of Q){let W=V.bytes;for(let X=0;X<J;X++)if(W[X]!==$[Z+X])continue $;return V.str}return null}store($,Z){let J=this.caches[$.length-1],Q={bytes:$,str:Z};if(J.length>=this.maxLengthPerKey)J[Math.random()*J.length|0]=Q;else J.push(Q)}decode($,Z,J){let Q=this.find($,Z,J);if(Q!=null)return this.hit++,Q;this.miss++;let V=(0,ZV.utf8DecodeJs)($,Z,J),W=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(W,V),V}}PJ.CachedKeyDecoder=qJ});var Z$=n((FJ)=>{Object.defineProperty(FJ,"__esModule",{value:!0});FJ.Decoder=void 0;var x$=IJ(),VV=$$(),M0=t0(),WV=o0(),zJ=m$(),XV=RJ(),G0=s0(),f$="array",v0="map_key",OJ="map_value",YV=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new G0.DecodeError("The type of key must be string or number but "+typeof $)};class UJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=f$,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=v0,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===f$){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===v0||$.type===OJ){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 f0=-1,v$=new DataView(new ArrayBuffer(0)),GV=new Uint8Array(v$.buffer);try{v$.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 KJ=RangeError("Insufficient data"),NV=new XV.CachedKeyDecoder;class l${extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=v$;bytes=GV;headByte=f0;stack=new UJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??VV.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:NV,this.mapKeyConverter=$?.mapKeyConverter??YV}clone(){return new l$({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=f0,this.stack.reset()}setBuffer($){let Z=(0,zJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===f0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,zJ.ensureUint8Array)($),Q=new Uint8Array(Z.length+J.length);Q.set(Z),Q.set(J,Z.length),this.setBuffer(Q)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,J;for await(let X of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(X);try{J=this.doDecodeSync(),Z=!0}catch(Y){if(!(Y instanceof RangeError))throw Y}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:Q,pos:V,totalPos:W}=this;throw RangeError(`Insufficient data in parsing ${(0,x$.prettyByte)(Q)} at ${W} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let J=Z,Q=-1;for await(let V of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(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 Q=$-128;if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($<160){let Q=$-144;if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else{let Q=$-160;Z=this.decodeString(Q,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let Q=this.lookU8();Z=this.decodeString(Q,1)}else if($===218){let Q=this.lookU16();Z=this.decodeString(Q,2)}else if($===219){let Q=this.lookU32();Z=this.decodeString(Q,4)}else if($===220){let Q=this.readU16();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===221){let Q=this.readU32();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===222){let Q=this.readU16();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===223){let Q=this.readU32();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===196){let Q=this.lookU8();Z=this.decodeBinary(Q,1)}else if($===197){let Q=this.lookU16();Z=this.decodeBinary(Q,2)}else if($===198){let Q=this.lookU32();Z=this.decodeBinary(Q,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let Q=this.lookU8();Z=this.decodeExtension(Q,1)}else if($===200){let Q=this.lookU16();Z=this.decodeExtension(Q,2)}else if($===201){let Q=this.lookU32();Z=this.decodeExtension(Q,4)}else throw new G0.DecodeError(`Unrecognized type byte: ${(0,x$.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===f$)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===v0){if(Z==="__proto__")throw new G0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=OJ;continue $}else if(Q.map[Q.key]=Z,Q.readCount++,Q.readCount===Q.size)Z=Q.map,J.release(Q);else{Q.key=null,Q.type=v0;continue $}}return Z}}readHeadByte(){if(this.headByte===f0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=f0}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,x$.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 KJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,WV.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===v0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new G0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw KJ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}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),Q=this.decodeBinary($,Z+1);return this.extensionCodec.decode(Q,J,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=(0,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,$}}FJ.Decoder=l$});var AJ=n((TJ)=>{Object.defineProperty(TJ,"__esModule",{value:!0});TJ.decode=IV;TJ.decodeMulti=qV;var HJ=Z$();function IV($,Z){return new HJ.Decoder(Z).decode($)}function qV($,Z){return new HJ.Decoder(Z).decodeMulti($)}});var EJ=n((SJ)=>{Object.defineProperty(SJ,"__esModule",{value:!0});SJ.isAsyncIterable=CJ;SJ.asyncIterableFromStream=DJ;SJ.ensureAsyncIterable=RV;function CJ($){return $[Symbol.asyncIterator]!=null}async function*DJ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function RV($){if(CJ($))return $;else return DJ($)}});var jJ=n((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.decodeAsync=UV;LJ.decodeArrayStream=FV;LJ.decodeMultiStream=wV;var y$=Z$(),u$=EJ();async function UV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeAsync(J)}function FV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeArrayStream(J)}function wV($,Z){let J=(0,u$.ensureAsyncIterable)($);return new y$.Decoder(Z).decodeStream(J)}});var _J=n((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 CV=GJ();Object.defineProperty(f,"encode",{enumerable:!0,get:function(){return CV.encode}});var kJ=AJ();Object.defineProperty(f,"decode",{enumerable:!0,get:function(){return kJ.decode}});Object.defineProperty(f,"decodeMulti",{enumerable:!0,get:function(){return kJ.decodeMulti}});var i$=jJ();Object.defineProperty(f,"decodeAsync",{enumerable:!0,get:function(){return i$.decodeAsync}});Object.defineProperty(f,"decodeArrayStream",{enumerable:!0,get:function(){return i$.decodeArrayStream}});Object.defineProperty(f,"decodeMultiStream",{enumerable:!0,get:function(){return i$.decodeMultiStream}});var DV=Z$();Object.defineProperty(f,"Decoder",{enumerable:!0,get:function(){return DV.Decoder}});var SV=s0();Object.defineProperty(f,"DecodeError",{enumerable:!0,get:function(){return SV.DecodeError}});var EV=g$();Object.defineProperty(f,"Encoder",{enumerable:!0,get:function(){return EV.Encoder}});var LV=$$();Object.defineProperty(f,"ExtensionCodec",{enumerable:!0,get:function(){return LV.ExtensionCodec}});var jV=j$();Object.defineProperty(f,"ExtData",{enumerable:!0,get:function(){return jV.ExtData}});var j0=k$();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 I0=Q0&&typeof Q0==="object"&&"webcrypto"in Q0?Q0.webcrypto:Q0&&typeof Q0==="object"&&("randomBytes"in Q0)?Q0:void 0;function l0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function J$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function i($,...Z){if(!J$($))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 r$($,Z){i($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function V$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var V0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var dJ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!dJ)throw Error("Non little-endian hardware is not supported");function nJ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function y0($){if(typeof $==="string")$=nJ($);else if(J$($))$=u0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function d$($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function n$($,Z){if($.length!==Z.length)return!1;let J=0;for(let Q=0;Q<$.length;Q++)J|=$[Q]^Z[Q];return J===0}var h$=($,Z)=>{function J(Q,...V){if(i(Q),$.nonceLength!==void 0){let q=V[0];if(!q)throw Error("nonce / iv required");if($.varSizeNonce)i(q);else i(q,$.nonceLength)}let W=$.tagLength;if(W&&V[1]!==void 0)i(V[1]);let X=Z(Q,...V),Y=(q,P)=>{if(P!==void 0){if(q!==2)throw Error("cipher output not supported");i(P)}},G=!1;return{encrypt(q,P){if(G)throw Error("cannot encrypt() twice with same key + nonce");return G=!0,i(q),Y(X.encrypt.length,P),X.encrypt(q,P)},decrypt(q,P){if(i(q),W&&q.length<W)throw Error("invalid ciphertext length: smaller than tagLength="+W);return Y(X.decrypt.length,P),X.decrypt(q,P)}}}return Object.assign(J,$),J};function W$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!hJ(Z))throw Error("invalid output, must be aligned");return Z}function hJ($){return $.byteOffset%4===0}function u0($){return Uint8Array.from($)}function $0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function i0($=32){if(I0&&typeof I0.getRandomValues==="function")return I0.getRandomValues(new Uint8Array($));if(I0&&typeof I0.randomBytes==="function")return I0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var o$=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),cJ=o$("expand 16-byte k"),oJ=o$("expand 32-byte k"),aJ=V0(cJ),sJ=V0(oJ);function K($,Z){return $<<Z|$>>>32-Z}function X$($){return $.byteOffset%4===0}var b0=64,tJ=16,a$=4294967295,c$=new Uint32Array;function eJ($,Z,J,Q,V,W,X,Y){let G=V.length,N=new Uint8Array(b0),q=V0(N),P=X$(V)&&X$(W),R=P?V0(V):c$,z=P?V0(W):c$;for(let U=0;U<G;X++){if($(Z,J,Q,q,X,Y),X>=a$)throw Error("arx: counter overflow");let O=Math.min(b0,G-U);if(P&&O===b0){let w=U/4;if(U%4!==0)throw Error("arx: invalid block position");for(let T=0,C;T<tJ;T++)C=w+T,z[C]=R[C]^q[T];U+=b0;continue}for(let w=0,T;w<O;w++)T=U+w,W[T]=V[T]^N[w];U+=O}}function s$($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:V,counterRight:W,rounds:X}=d$({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return l0(V),l0(X),V$(W),V$(J),(Y,G,N,q,P=0)=>{i(Y),i(G),i(N);let R=N.length;if(q===void 0)q=new Uint8Array(R);if(i(q),l0(P),P<0||P>=a$)throw Error("arx: counter overflow");if(q.length<R)throw Error(`arx: output (${q.length}) is shorter than data (${R})`);let z=[],U=Y.length,O,w;if(U===32)z.push(O=u0(Y)),w=sJ;else if(U===16&&J)O=new Uint8Array(32),O.set(Y),O.set(Y,16),w=aJ,z.push(O);else throw Error(`arx: invalid 32-byte key, got length=${U}`);if(!X$(G))z.push(G=u0(G));let T=V0(O);if(Q){if(G.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(w,T,V0(G.subarray(0,16)),T),G=G.subarray(16)}let C=16-V;if(C!==G.length)throw Error(`arx: nonce must be ${C} or 16 bytes`);if(C!==12){let H=new Uint8Array(12);H.set(G,W?0:12-G.length),G=H,z.push(G)}let D=V0(G);return eJ($,w,T,D,N,q,P,X),$0(...z),q}}var p=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class t${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,$=y0($),i($,32);let Z=p($,0),J=p($,2),Q=p($,4),V=p($,6),W=p($,8),X=p($,10),Y=p($,12),G=p($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|Q<<6)&7939,this.r[3]=(Q>>>7|V<<9)&8191,this.r[4]=(V>>>4|W<<12)&255,this.r[5]=W>>>1&8190,this.r[6]=(W>>>14|X<<2)&8191,this.r[7]=(X>>>11|Y<<5)&8065,this.r[8]=(Y>>>8|G<<8)&8191,this.r[9]=G>>>5&127;for(let N=0;N<8;N++)this.pad[N]=p($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:V,r:W}=this,X=W[0],Y=W[1],G=W[2],N=W[3],q=W[4],P=W[5],R=W[6],z=W[7],U=W[8],O=W[9],w=p($,Z+0),T=p($,Z+2),C=p($,Z+4),D=p($,Z+6),H=p($,Z+8),E=p($,Z+10),B=p($,Z+12),b=p($,Z+14),j=V[0]+(w&8191),_=V[1]+((w>>>13|T<<3)&8191),g=V[2]+((T>>>10|C<<6)&8191),M=V[3]+((C>>>7|D<<9)&8191),x=V[4]+((D>>>4|H<<12)&8191),m=V[5]+(H>>>1&8191),v=V[6]+((H>>>14|E<<2)&8191),l=V[7]+((E>>>11|B<<5)&8191),y=V[8]+((B>>>8|b<<8)&8191),u=V[9]+(b>>>5|Q),A=0,d=A+j*X+_*(5*O)+g*(5*U)+M*(5*z)+x*(5*R);A=d>>>13,d&=8191,d+=m*(5*P)+v*(5*q)+l*(5*N)+y*(5*G)+u*(5*Y),A+=d>>>13,d&=8191;let a=A+j*Y+_*X+g*(5*O)+M*(5*U)+x*(5*z);A=a>>>13,a&=8191,a+=m*(5*R)+v*(5*P)+l*(5*q)+y*(5*N)+u*(5*G),A+=a>>>13,a&=8191;let t=A+j*G+_*Y+g*X+M*(5*O)+x*(5*U);A=t>>>13,t&=8191,t+=m*(5*z)+v*(5*R)+l*(5*P)+y*(5*q)+u*(5*N),A+=t>>>13,t&=8191;let k=A+j*N+_*G+g*Y+M*X+x*(5*O);A=k>>>13,k&=8191,k+=m*(5*U)+v*(5*z)+l*(5*R)+y*(5*P)+u*(5*q),A+=k>>>13,k&=8191;let J0=A+j*q+_*N+g*G+M*Y+x*X;A=J0>>>13,J0&=8191,J0+=m*(5*O)+v*(5*U)+l*(5*z)+y*(5*R)+u*(5*P),A+=J0>>>13,J0&=8191;let R0=A+j*P+_*q+g*N+M*G+x*Y;A=R0>>>13,R0&=8191,R0+=m*X+v*(5*O)+l*(5*U)+y*(5*z)+u*(5*R),A+=R0>>>13,R0&=8191;let z0=A+j*R+_*P+g*q+M*N+x*G;A=z0>>>13,z0&=8191,z0+=m*Y+v*X+l*(5*O)+y*(5*U)+u*(5*z),A+=z0>>>13,z0&=8191;let K0=A+j*z+_*R+g*P+M*q+x*N;A=K0>>>13,K0&=8191,K0+=m*G+v*Y+l*X+y*(5*O)+u*(5*U),A+=K0>>>13,K0&=8191;let O0=A+j*U+_*z+g*R+M*P+x*q;A=O0>>>13,O0&=8191,O0+=m*N+v*G+l*Y+y*X+u*(5*O),A+=O0>>>13,O0&=8191;let U0=A+j*O+_*U+g*z+M*R+x*P;A=U0>>>13,U0&=8191,U0+=m*q+v*N+l*G+y*Y+u*X,A+=U0>>>13,U0&=8191,A=(A<<2)+A|0,A=A+d|0,d=A&8191,A=A>>>13,a+=A,V[0]=d,V[1]=a,V[2]=t,V[3]=k,V[4]=J0,V[5]=R0,V[6]=z0,V[7]=K0,V[8]=O0,V[9]=U0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let X=2;X<10;X++)$[X]+=Q,Q=$[X]>>>13,$[X]&=8191;$[0]+=Q*5,Q=$[0]>>>13,$[0]&=8191,$[1]+=Q,Q=$[1]>>>13,$[1]&=8191,$[2]+=Q,J[0]=$[0]+5,Q=J[0]>>>13,J[0]&=8191;for(let X=1;X<10;X++)J[X]=$[X]+Q,Q=J[X]>>>13,J[X]&=8191;J[9]-=8192;let V=(Q^1)-1;for(let X=0;X<10;X++)J[X]&=V;V=~V;for(let X=0;X<10;X++)$[X]=$[X]&V|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;$0(J)}update($){Q$(this);let{buffer:Z,blockLen:J}=this;$=y0($);let Q=$.length;for(let V=0;V<Q;){let W=Math.min(J-this.pos,Q-V);if(W===J){for(;J<=Q-V;V+=J)this.process($,V);continue}if(Z.set($.subarray(V,V+W),this.pos),this.pos+=W,V+=W,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){$0(this.h,this.r,this.buffer,this.pad)}digestInto($){Q$(this),r$($,this),this.finished=!0;let{buffer:Z,h:J}=this,{pos:Q}=this;if(Q){Z[Q++]=1;for(;Q<16;Q++)Z[Q]=0;this.process(Z,0,!0)}this.finalize();let V=0;for(let W=0;W<8;W++)$[V++]=J[W]>>>0,$[V++]=J[W]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function $Q($){let Z=(Q,V)=>$(V).update(y0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var Y$=$Q(($)=>new t$($));function ZQ($,Z,J,Q,V,W=20){let X=$[0],Y=Z[0],G=Z[1],N=Z[2],q=Z[3],P=$[1],R=J[0],z=J[1],U=V,O=0,w=$[2],T=Z[4],C=Z[5],D=Z[6],H=Z[7],E=$[3],B=X,b=Y,j=G,_=N,g=q,M=P,x=R,m=z,v=U,l=O,y=w,u=T,A=C,d=D,a=H,t=E;for(let J0=0;J0<W;J0+=2)g^=K(B+A|0,7),v^=K(g+B|0,9),A^=K(v+g|0,13),B^=K(A+v|0,18),l^=K(M+b|0,7),d^=K(l+M|0,9),b^=K(d+l|0,13),M^=K(b+d|0,18),a^=K(y+x|0,7),j^=K(a+y|0,9),x^=K(j+a|0,13),y^=K(x+j|0,18),_^=K(t+u|0,7),m^=K(_+t|0,9),u^=K(m+_|0,13),t^=K(u+m|0,18),b^=K(B+_|0,7),j^=K(b+B|0,9),_^=K(j+b|0,13),B^=K(_+j|0,18),x^=K(M+g|0,7),m^=K(x+M|0,9),g^=K(m+x|0,13),M^=K(g+m|0,18),u^=K(y+l|0,7),v^=K(u+y|0,9),l^=K(v+u|0,13),y^=K(l+v|0,18),A^=K(t+a|0,7),d^=K(A+t|0,9),a^=K(d+A|0,13),t^=K(a+d|0,18);let k=0;Q[k++]=X+B|0,Q[k++]=Y+b|0,Q[k++]=G+j|0,Q[k++]=N+_|0,Q[k++]=q+g|0,Q[k++]=P+M|0,Q[k++]=R+x|0,Q[k++]=z+m|0,Q[k++]=U+v|0,Q[k++]=O+l|0,Q[k++]=w+y|0,Q[k++]=T+u|0,Q[k++]=C+A|0,Q[k++]=D+d|0,Q[k++]=H+a|0,Q[k++]=E+t|0}function JQ($,Z,J,Q){let V=$[0],W=Z[0],X=Z[1],Y=Z[2],G=Z[3],N=$[1],q=J[0],P=J[1],R=J[2],z=J[3],U=$[2],O=Z[4],w=Z[5],T=Z[6],C=Z[7],D=$[3];for(let E=0;E<20;E+=2)G^=K(V+w|0,7),R^=K(G+V|0,9),w^=K(R+G|0,13),V^=K(w+R|0,18),z^=K(N+W|0,7),T^=K(z+N|0,9),W^=K(T+z|0,13),N^=K(W+T|0,18),C^=K(U+q|0,7),X^=K(C+U|0,9),q^=K(X+C|0,13),U^=K(q+X|0,18),Y^=K(D+O|0,7),P^=K(Y+D|0,9),O^=K(P+Y|0,13),D^=K(O+P|0,18),W^=K(V+Y|0,7),X^=K(W+V|0,9),Y^=K(X+W|0,13),V^=K(Y+X|0,18),q^=K(N+G|0,7),P^=K(q+N|0,9),G^=K(P+q|0,13),N^=K(G+P|0,18),O^=K(U+z|0,7),R^=K(O+U|0,9),z^=K(R+O|0,13),U^=K(z+R|0,18),w^=K(D+C|0,7),T^=K(w+D|0,9),C^=K(T+w|0,13),D^=K(C+T|0,18);let H=0;Q[H++]=V,Q[H++]=N,Q[H++]=U,Q[H++]=D,Q[H++]=q,Q[H++]=P,Q[H++]=R,Q[H++]=z}var G$=s$(ZQ,{counterRight:!0,extendNonceFn:JQ}),N$=h$({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=W$(J.length+32,Q,!1);let V=Q.subarray(0,32),W=Q.subarray(32);Q.set(J,32),$0(V),G$($,Z,Q,Q);let X=Y$(W,V);return Q.set(X,16),$0(Q.subarray(0,16),X),Q.subarray(16)},decrypt(J,Q){i(J),Q=W$(J.length+32,Q,!1);let V=Q.subarray(0,32),W=Q.subarray(32,48),X=Q.subarray(48);Q.set(J,32),$0(V);let Y=G$($,Z,V,V),G=Y$(X,Y);if(!n$(W,G))throw Error("invalid tag");return G$($,Z,Q.subarray(16),Q.subarray(16)),$0(V,W,G),X}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function QQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function _0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function q0($,...Z){if(!QQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function m0($,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){q0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function e$($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function F0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function w0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function B0($,Z){return $<<32-Z|$>>>Z}var $Z=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function ZZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var JZ=$Z?($)=>$:($)=>ZZ($);function VQ($){for(let Z=0;Z<$.length;Z++)$[Z]=ZZ($[Z]);return $}var s=$Z?($)=>$:VQ;function WQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function H0($){if(typeof $==="string")$=WQ($);return q0($),$}class I${}function QZ($){let Z=(Q,V)=>$(V).update(H0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var VZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var r0=BigInt(4294967295),WZ=BigInt(32);function q$($,Z=!1){if(Z)return{h:Number($&r0),l:Number($>>WZ&r0)};return{h:Number($>>WZ&r0)|0,l:Number($&r0)|0}}function W0($,Z,J,Q,V){return $=$+Z+V|0,Q=B0(Q^$,16),J=J+Q|0,Z=B0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function X0($,Z,J,Q,V){return $=$+Z+V|0,Q=B0(Q^$,8),J=J+Q|0,Z=B0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class P$ extends I${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($){m0(this),$=H0($),q0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,V=$.length,W=$.byteOffset,X=$.buffer;for(let Y=0;Y<V;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(Q),this.pos=0;let G=Math.min(Z-this.pos,V-Y),N=W+Y;if(G===Z&&!(N%4)&&Y+G<V){let q=new Uint32Array(X,N,Math.floor((V-Y)/4));s(q);for(let P=0;Y+Z<V;P+=Q.length,Y+=Z)this.length+=Z,this.compress(q,P,!1);s(q);continue}J.set($.subarray(Y,Y+G),this.pos),this.pos+=G,this.length+=G,Y+=G}return this}digestInto($){m0(this),p0($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,w0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=F0($);this.get().forEach((V,W)=>Q[W]=JZ(V))}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}_cloneInto($){let{buffer:Z,length:J,finished:Q,destroyed:V,outputLen:W,pos:X}=this;return $||($=new this.constructor({dkLen:W})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=V,$.finished=Q,$.length=J,$.pos=X,$.outputLen=W,$}clone(){return this._cloneInto()}}function M$($,Z,J,Q,V,W,X,Y,G,N,q,P,R,z,U,O,w,T,C,D){let H=0;for(let E=0;E<Q;E++)({a:V,b:G,c:R,d:w}=W0(V,G,R,w,J[Z+$[H++]])),{a:V,b:G,c:R,d:w}=X0(V,G,R,w,J[Z+$[H++]]),{a:W,b:N,c:z,d:T}=W0(W,N,z,T,J[Z+$[H++]]),{a:W,b:N,c:z,d:T}=X0(W,N,z,T,J[Z+$[H++]]),{a:X,b:q,c:U,d:C}=W0(X,q,U,C,J[Z+$[H++]]),{a:X,b:q,c:U,d:C}=X0(X,q,U,C,J[Z+$[H++]]),{a:Y,b:P,c:O,d:D}=W0(Y,P,O,D,J[Z+$[H++]]),{a:Y,b:P,c:O,d:D}=X0(Y,P,O,D,J[Z+$[H++]]),{a:V,b:N,c:U,d:D}=W0(V,N,U,D,J[Z+$[H++]]),{a:V,b:N,c:U,d:D}=X0(V,N,U,D,J[Z+$[H++]]),{a:W,b:q,c:O,d:w}=W0(W,q,O,w,J[Z+$[H++]]),{a:W,b:q,c:O,d:w}=X0(W,q,O,w,J[Z+$[H++]]),{a:X,b:P,c:R,d:T}=W0(X,P,R,T,J[Z+$[H++]]),{a:X,b:P,c:R,d:T}=X0(X,P,R,T,J[Z+$[H++]]),{a:Y,b:G,c:z,d:C}=W0(Y,G,z,C,J[Z+$[H++]]),{a:Y,b:G,c:z,d:C}=X0(Y,G,z,C,J[Z+$[H++]]);return{v0:V,v1:W,v2:X,v3:Y,v4:G,v5:N,v6:q,v7:P,v8:R,v9:z,v10:U,v11:O,v12:w,v13:T,v14:C,v15:D}}var Z0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},Y0=VZ.slice(),XZ=(()=>{let $=Array.from({length:16},(Q,V)=>V),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Q[V]),J=[];for(let Q=0,V=$;Q<7;Q++,V=Z(V))J.push(...V);return Uint8Array.from(J)})();class R$ extends P${constructor($={},Z=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:J,context:Q}=$,V=Q!==void 0;if(J!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let W=H0(J).slice();q0(W,32),this.IV=F0(W),s(this.IV),this.flags=Z|Z0.KEYED_HASH}else if(V){let W=H0(Q),X=new R$({dkLen:32},Z0.DERIVE_KEY_CONTEXT).update(W).digest();this.IV=F0(X),s(this.IV),this.flags=Z|Z0.DERIVE_KEY_MATERIAL}else this.IV=Y0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=e$(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:V,pos:W}=this,{h:X,l:Y}=q$(BigInt($),!0),{v0:G,v1:N,v2:q,v3:P,v4:R,v5:z,v6:U,v7:O,v8:w,v9:T,v10:C,v11:D,v12:H,v13:E,v14:B,v15:b}=M$(XZ,Q,J,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],Y0[0],Y0[1],Y0[2],Y0[3],X,Y,W,Z);V[0]=G^w,V[1]=N^T,V[2]=q^C,V[3]=P^D,V[4]=R^H,V[5]=z^E,V[6]=U^B,V[7]=O^b}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=Z0.CHUNK_START;if(this.chunkPos===15||J)Q|=Z0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let V=this.state;this.state=this.IV.slice();for(let W,X=this.chunksDone+1;J||!(X&1);X>>=1){if(!(W=this.stack.pop()))break;this.buffer32.set(W,0),this.buffer32.set(V,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|Z0.PARENT,this.buffer32,0),V=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(V)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:V,posOut:W,chunkOut:X,stack:Y,chunksDone:G}=this;return $.state.set(Q.slice()),$.stack=Y.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=V,$.chunksDone=G,$.posOut=W,$.chunkOut=X,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,w0(this.state,this.buffer32,this.IV,this.bufferOut32),w0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:V}=this,{h:W,l:X}=q$(BigInt(this.chunkOut++));s(Q);let{v0:Y,v1:G,v2:N,v3:q,v4:P,v5:R,v6:z,v7:U,v8:O,v9:w,v10:T,v11:C,v12:D,v13:H,v14:E,v15:B}=M$(XZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],Y0[0],Y0[1],Y0[2],Y0[3],X,W,Z,J);V[0]=Y^O,V[1]=G^w,V[2]=N^T,V[3]=q^C,V[4]=P^D,V[5]=R^H,V[6]=z^E,V[7]=U^B,V[8]=$[0]^O,V[9]=$[1]^w,V[10]=$[2]^T,V[11]=$[3]^C,V[12]=$[4]^D,V[13]=$[5]^H,V[14]=$[6]^E,V[15]=$[7]^B,s(Q),s(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,w0(this.buffer.subarray(this.pos));let $=this.flags|Z0.ROOT;if(this.stack.length)$|=Z0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Z0.CHUNK_START:0)|Z0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){m0(this,!1),q0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,V=$.length;Q<V;){if(this.posOut>=Z)this.b2CompressOut();let W=Math.min(Z-this.posOut,V-Q);$.set(J.subarray(this.posOut,this.posOut+W),Q),this.posOut+=W,Q+=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 YZ=QZ(($)=>new R$($));function h($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function d0($){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 IZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var GZ;if(typeof Uint8Array.prototype.toBase64==="function")GZ=($)=>$.toBase64();else GZ=($)=>btoa(String.fromCharCode(...$));var NZ;if(typeof Uint8Array.fromBase64==="function")NZ=($)=>Uint8Array.fromBase64($);else NZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function n0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var z$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function qZ($){let Z=new Uint8Array(z$.length+32);return Z.set(z$),Z.set($.subarray(0,32),z$.length),Z}function PZ($){return typeof $==="string"?new TextEncoder().encode($):$}function T0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class K${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return i0($)}async gen256BitSecureRandomSeed(){return i0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=i0(24),V=N$(Z,J).encrypt($);return new Uint8Array([...J,...V])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return N$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=qZ(Z),Q=await globalThis.crypto.subtle.importKey("pkcs8",T0(J),{name:"Ed25519"},!0,["sign"]),V=await globalThis.crypto.subtle.exportKey("jwk",Q);if(typeof V.x!=="string")throw Error("Ed25519 JWK missing x");let W=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:V.x},{name:"Ed25519"},!0,["verify"]),X=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",W)),Y=new Uint8Array(64);return Y.set(Z,0),Y.set(X,32),this.signKeys.set(h(Z),Q),this.verifyKeys.set(h(X),W),{keyType:"ed25519",privateKey:Y,publicKey:X}}async importSignKey($){let Z=$.subarray(0,32),J=h(Z),Q=this.signKeys.get(J);if(Q)return Q;let V=qZ(Z),W=await globalThis.crypto.subtle.importKey("pkcs8",T0(V),{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 Q=await globalThis.crypto.subtle.importKey("raw",T0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=PZ($),Q=await this.importSignKey(Z),V=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,T0(J));return new Uint8Array(V)}async checkSigEd25519($,Z,J){let Q=PZ(Z);try{let V=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},V,T0($),T0(Q))}catch{return!1}}async blake3($){return YZ($)}}var XQ=new K$,P0=XQ;var A0=64;var MZ=32,C0=8;var RZ=32;var zZ=30000,KZ=512,S;((M)=>{M[M.Success=0]="Success";M[M.InvalidSignature=3]="InvalidSignature";M[M.ClockOutOfSync=4]="ClockOutOfSync";M[M.UserNotRegistered=5]="UserNotRegistered";M[M.ServerMisconfigured=6]="ServerMisconfigured";M[M.MissingBody=7]="MissingBody";M[M.ExtraBodyContent=8]="ExtraBodyContent";M[M.MissingParam=9]="MissingParam";M[M.InvalidParam=10]="InvalidParam";M[M.InvalidRequest=11]="InvalidRequest";M[M.InternalError=12]="InternalError";M[M.NotFound=13]="NotFound";M[M.InvalidMessage=14]="InvalidMessage";M[M.NoChange=15]="NoChange";M[M.DatabaseClosed=16]="DatabaseClosed";M[M.StorageError=17]="StorageError";M[M.DatabaseError=18]="DatabaseError";M[M.HashMismatch=19]="HashMismatch";M[M.DecryptionError=20]="DecryptionError";M[M.NotImplemented=21]="NotImplemented";M[M.MissingSeed=22]="MissingSeed";M[M.OutOfBounds=23]="OutOfBounds";M[M.HostError=24]="HostError";M[M.CommunicationError=25]="CommunicationError";M[M.VarLimitExceeded=26]="VarLimitExceeded";M[M.InvalidResponse=27]="InvalidResponse";M[M.ConnectionClosed=28]="ConnectionClosed"})(S||={});var OZ="t";function F($){return[$,0]}function I($){return[void 0,$]}function YQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return I(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 F(new Uint8Array([0]));if(Z.length>8)return I(26);return F(new Uint8Array(Z))}function GQ($,Z=0){let J=0n,Q=0,V=Z;while(!0){if(V>=$.length)return I(14);let W=$[V++];if(W===void 0)return I(14);if(J|=BigInt(W&127)<<BigInt(Q),(W&128)===0){if(V-Z>8)return I(26);return F({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:V-Z})}if(Q+=7,Q>=56)return I(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 I(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,F($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);return F(new Date($))}readVarInt(){let[$,Z]=GQ(this.data,this.pos);if(Z!==0)return I(Z);this.pos+=$.bytesRead;let J=$.value;return F(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);let[J,Q]=this.readBytes($);if(Q!==0)return I(Q);let V=new TextDecoder().decode(J);return F(V)}readBytes($){if($<0)return I(10);if(this.pos+$>this.data.length)return I(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,F(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return I(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return I(Q);Z.push(J)}return F(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return I(Q);Z.push(J)}return F(Z)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class L{parts=[];writeBigInt($){let Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,$,!1),this.parts.push(Z)}writeDate($){let Z=$.getTime();return this.writeVarInt(Z)}writeVarInt($){let[Z,J]=YQ($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let Z=this.writeVarInt($.length);if(Z!==0)return Z;return this.writeBytes($),0}writeStruct($,Z){return $.encode(this,Z)}writeStructs($,Z){for(let J of Z){let Q=this.writeStruct($,J);if(Q!==0)return Q}return 0}writeBytesSeq($){for(let Z of $)this.writeBytes(Z)}result(){let $=this.parts.reduce((Q,V)=>Q+V.length,0),Z=new Uint8Array($),J=0;for(let Q of this.parts)Z.set(Q,J),J+=Q.length;return Z}*scan(){for(let $ of this.parts)yield $}}var g0={encode($,Z){let J=$.writeVarBytes(Z.id);if(J!==0)return J;let Q=$.writeDate(Z.ts);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return I(J);let[Q,V]=$.readDate();if(V!==0)return I(V);return F({id:Z,ts:Q})}};function UZ($){let Z=new L,J=Z.writeStruct(g0,$);if(J!==0)return I(J);let Q=Z.result();return F(Q)}var O$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let V=$.writeVarInt(Z.ctr);if(V!==0)return V;let 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 I(J);let Q=new c(Z),[,V]=g0.decode(Q);if(V!==0)return I(V);let[W,X]=$.readVarInt();if(X!==0)return I(X);let[Y,G]=$.readVarInt();if(G!==0)return I(G);let[N,q]=$.readVarInt();if(q!==0)return I(q);let P;if(N>0){let[R,z]=$.readBytes(RZ);if(z!==0)return I(z);P=R}return F({eid:Z,off:W,ctr:Y,len:N,hsh:P})}};function FZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function wZ($,Z,J,Q){let V;if($.bod&&$.len>0)V=await J.blake3($.bod);let W=new L,X=O$.encode(W,{...$,hsh:V});if(X!==0)return I(X);let Y=W.result(),G=await Z.kdmFor(Y),N=Q.deriveCipher(G,"encrypt"),q=await N.encrypt(Y),P=$.bod?await N.encrypt($.bod):new Uint8Array(0),R=await Z.sign(q);return F({sig:R,kdm:G,headCph:q,bodyCph:P})}async function HZ($,Z,J,Q,V){let W=new c($),[X,Y]=O$.decode(W);if(Y!==0)return I(14);let G;try{G=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return I(20)}let N=X.hsh&&G===void 0,q=X.hsh===void 0&&G!==void 0;if(N||q)return I(19);if(X.hsh&&G){let R=await Q.blake3(G);if(!IZ(R,X.hsh))return I(19)}let P=V??await Q.blake3($);return F({msgHead:X,bod:G,headHash:P})}async function U$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return I(Q);let V=J.result(),W=await $.sign(V);return F({pubKey:$.publicKey,sig:W,timestamp:Z})}async function e($,Z,J){let Q=J.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Q-V)>zZ)return 4;let X=new L;X.writeDate($.timestamp);let Y=X.result();if(!await Z.checkSigEd25519($.sig,Y,$.pubKey))return 3;return 0}class D0{now(){return new Date}}function TZ($,Z,J,Q){let V=Z.getTime()-$.getTime(),W=J.getTime()-Q.getTime();return(V+W)/2}var x0={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 I(J);let Q;if(Z>0){let[V,W]=$.readVarInt();if(W!==0)return I(W);Q=V}return F({quota:Z,usage:Q})}};var S0={encode($,Z){$.writeBytes(new Uint8Array([Z.status]));let J=$.writeDate(Z.timeRcvd);if(J!==0)return J;let Q=$.writeDate(Z.timeSent);if(Q!==0)return Q;let V=$.writeVarInt(Z.subscription.term);if(V!==0)return V;let W=$.writeVarInt(Z.subscription.elapsed);if(W!==0)return W;let X=$.writeStruct(x0,Z.subscription.stat);if(X!==0)return X;let Y=$.writeStruct(x0,Z.subscription.dyn);if(Y!==0)return Y;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return I(J);let Q=Z[0],[V,W]=$.readDate();if(W!==0)return I(W);let[X,Y]=$.readDate();if(Y!==0)return I(Y);let[G,N]=$.readVarInt();if(N!==0)return I(N);let[q,P]=$.readVarInt();if(P!==0)return I(P);let[R,z]=$.readStruct(x0);if(z!==0)return I(z);let[U,O]=$.readStruct(x0);if(O!==0)return I(O);return F({status:Q,timeRcvd:V,timeSent:X,subscription:{term:G,elapsed:q,stat:R,dyn:U}})}};var F$={encode($,Z){let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let Q=$.writeVarInt(Z.seq);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return I(J);let[Q,V]=$.readVarInt();if(V!==0)return I(V);return F({headCph:Z,seq:Q})}};var o={encode($,Z){$.writeBytes(Z.pubKey),$.writeBytes(Z.sig);let J=$.writeDate(Z.timestamp);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(MZ);if(J!==0)return I(J);let[Q,V]=$.readBytes(A0);if(V!==0)return I(V);let[W,X]=$.readDate();if(X!==0)return I(X);return F({pubKey:Z,sig:Q,timestamp:W})}};var AZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;for(let X of Q)V.writeVarInt(X);return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W}=$,[X,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(X,V,Q);if(G!==0)return G;let{pubKey:N}=X,[q,P]=await W.hasUser(N);if(P!==0)return P;if(!q)return 5;let[R,z]=Z.readVarInt();if(z!==0)return z;if(!Z.done())return 8;let[U,O]=await W.listHeads(N,R);if(O!==0)return O;return J.writeStructs(F$,U)},decodeResp($){return $.readStructs(F$)}};var w$={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 I(J);let[Q,V]=$.readVarBytes();if(V!==0)return I(V);return F({seq:Z,bodyCph:Q})}};var CZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;for(let X of Q){let Y=V.writeVarInt(X);if(Y!==0)return Y}return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W}=$,[X,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(X,V,Q);if(G!==0)return G;let{pubKey:N}=X,[q,P]=await W.hasUser(N);if(P!==0)return P;if(!q)return 5;let R=[];while(!Z.done()){let[O,w]=Z.readVarInt();if(w!==0)return w;R.push(O)}console.info(`PULL: ${R.length} bags`);let[z,U]=await W.getBodies(N,R);if(U!==0)return U;if(!z)return 17;for(let{seq:O,bodyCph:w}of z){let T={seq:O,bodyCph:w},C=J.writeStruct(w$,T);if(C!==0)return C}return 0},decodeResp($){return $.readStructs(w$)}};var H$={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let Q=$.writeVarBytes(Z.bodyCph);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readBytes(A0);if(J!==0)return I(J);let[Q,V]=$.readBytes(C0);if(V!==0)return I(V);let[W,X]=$.readVarBytes();if(X!==0)return I(X);let[Y,G]=$.readVarBytes();if(G!==0)return I(G);return F({sig:Z,kdm:Q,headCph:W,bodyCph:Y})}};var T$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let V=Z.bodyCph?Z.bodyCph.length:0,W=$.writeVarInt(V);if(W!==0)return W;if(V>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return I(J);let[Q,V]=$.readVarBytes();if(V!==0)return I(V);let[W,X]=$.readVarInt();if(X!==0)return I(X);let Y;if(W>0){let[G,N]=$.readBytes(W);if(N!==0)return I(N);Y=G}return F({seq:Z,headCph:Q,bodyCph:Y})}};var E0={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(A0);if(J!==0)return I(J);let[Q,V]=$.readBytes(C0);if(V!==0)return I(V);let[W,X]=$.readVarBytes();if(X!==0)return I(X);return F({sig:Z,kdm:Q,headCph:W})}};var h0={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 I(J);let[Q,V]=$.readBytes(1);if(V!==0)return I(V);let W=Q[0];if(W!==0)return F({idx:Z,status:W});let[X,Y]=$.readVarInt();if(Y!==0)return I(Y);return F({idx:Z,status:W,seq:X})}};var DZ={async encodeReq($,Z,J,Q,V){let W=V.writeStruct(o,J);if(W!==0)return W;let X=V.writeStructs(H$,Q);if(X!==0)return X;return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W,notifier:X}=$,[Y,G]=Z.readStruct(o);if(G!==0)return G;let N=await e(Y,V,Q);if(N!==0)return N;let{pubKey:q}=Y,[P,R]=await W.hasUser(q);if(R!==0)return R;if(!P)return 5;let[z,U]=Z.readStructs(H$);if(U!==0)return U;console.info(`PUSH: ${z.length} bags`);let O=[],w=[];for(let H=0;H<z.length;H++){let E=z[H];if(!await FZ(E,q,V)){let b={idx:H,status:3},j=J.writeStruct(h0,b);if(j!==0)return j;continue}O.push(H),w.push(E)}let[T,C]=await W.setBags(q,w);if(C!==0)return C;if(!T||T.length!==w.length)return 17;let D=[];for(let H=0;H<w.length;H++){let E=w[H],B=O[H],b=T[H],j=new L,_=j.writeStruct(E0,E);if(_!==0)return _;let g=j.result(),M={seq:b,headCph:g};if(z.length===1&&E.bodyCph.length<=KZ)M.bodyCph=E.bodyCph;D.push(M);let x={idx:B,status:0,seq:b},m=J.writeStruct(h0,x);if(m!==0)return m}if(D.length>0){let H=new L,E=H.writeStructs(T$,D);if(E!==0)return E;let B=H.result();await Promise.resolve(X.push(q,B))}return 0},decodeResp($){return $.readStructs(h0)}};var SZ={async encodeReq($,Z,J,Q,V){return V.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:W}=$,[X,Y]=Z.readStruct(o);if(Y!==0)return Y;let G=await e(X,V,Q);if(G!==0)return G;let{pubKey:N}=X;if(!Z.done())return 8;let[q,P]=await W.addUser(N);if(P!==0)return P;return 0},decodeResp($){return F(void 0)}};class A${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let W=new L;W.writeStruct(o,$);let X=W.result(),Y=h(X);return V.searchParams.set("t",Y),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Q()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(G)=>{let N=new Uint8Array(G.data);Z(N)},this.websocket.onerror=(G)=>{console.log(`ERROR: ${JSON.stringify(G)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var r={user:{path:"/user",endpoint:SZ,name:0},push:{path:"/push",endpoint:DZ,name:2},peek:{path:"/peek",endpoint:AZ,name:1},pull:{path:"/pull",endpoint:CZ,name:3}},NQ={0:r.user,2:r.push,1:r.peek,3:r.pull},EZ={[r.user.path]:r.user,[r.push.path]:r.push,[r.peek.path]:r.peek,[r.pull.path]:r.pull};class LZ{url;listener;constructor($){this.url=$;this.listener=new A$($)}async call($,Z){let{path:J}=NQ[$],Q=new URL(J,this.url);try{return await qQ(Q,Z)}catch{return I(25)}}}var C$=($)=>{return new LZ($.handle)};function L0($){let Z=new L;if(Z.writeStruct(S0,$)!==0)return new Response(null,{status:500});return D$(Z)}function D$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var IQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function S$($){return new Response($.body,{headers:{...$.headers,...IQ},status:$.status,statusText:$.statusText})}async function qQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return I(24);let Q=await c.fromResponse(J);return F(Q)}class c0{enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,V,W){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=V;this.updateHostMeta=W}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:V,name:W}=$,X=await this.identity(),Y=J.now(),[G,N]=await U$(X,Y);if(N!==0)return I(N);let q=new L,P=await V.encodeReq(this,X,G,Z,q);if(P!==0)return I(P);let R=J.now(),[z,U]=await Q.call(W,q),O=J.now();if(U!==0)return I(U);let[w,T]=z.readStruct(S0);if(T!==0)return I(T);if(w.status!==0)return I(w.status);let D={clockOffset:TZ(R,w.timeRcvd,w.timeSent,O),subscription:w.subscription},H=await this.updateHostMeta(D);if(H!==0)return I(H);return V.decodeResp(z)}identity=()=>{let{host:$,enclave:Z}=this;return Z.deriveIdentity($.label,$.idx??0)};seal=async($)=>{let{crypto:Z,enclave:J}=this,Q=await this.identity();return wZ($,Q,Z,J)};register=()=>this.call(r.user,[]);peek=($)=>this.call(r.peek,[$]);push=($)=>this.call(r.push,$);pull=($)=>this.call(r.pull,$);listen=async($,Z,J)=>{let{clock:Q,transport:V}=this,{listener:W}=V,X=await this.identity(),Y=Q.now(),[G,N]=await U$(X,Y);if(N!==0)return N;return await W.connect(G,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}class E${#Q;#$;constructor($,Z){this.#Q=$,this.#$=Z}deriveCipher($,Z){let J=$.slice(),Q=(X)=>this.#V(J,X),V=(X)=>this.#W(J,X);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:V}),both:Object.freeze({encrypt:Q,decrypt:V})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,V=await this.#J(J,Q);return Object.freeze({publicKey:V.publicKey,sign:(W)=>this.#Y(J,Q,W),kdmFor:(W)=>this.#G(J,Q,W)})}async#V($,Z){let J=await this.#Z($);return this.#$.encryptXSalsa20Poly1305Combined(Z,J)}async#W($,Z){let J=await this.#Z($);return this.#$.decryptXSalsa20Poly1305Combined(Z,J)}async#Z($){return this.#$.blake3(n0(this.#Q,$))}async#X($,Z){let J=new TextEncoder().encode($),Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,BigInt(Z),!1),await this.#Z(n0(J,Q))}async#J($,Z){let J=await this.#X($,Z);return this.#$.deriveEd25519KeyPair(J)}async#Y($,Z,J){let Q=await this.#J($,Z);return this.#$.signEd25519(J,Q.privateKey)}async#G($,Z,J){let Q=await this.#J($,Z),V=n0(Q.privateKey,J);return(await this.#$.blake3(V)).slice(0,C0)}}class L${listeners=new Map;addEventListener($,Z){let J=this.listeners.get($);if(!J)J=new Set,this.listeners.set($,J);return J.add(Z),()=>{this.removeEventListener($,Z)}}removeEventListener($,Z){let J=this.listeners.get($);if(J){if(J.delete(Z),J.size===0)this.listeners.delete($)}}emit($,Z){let J=this.listeners.get($);if(J){let Q=Array.from(J);for(let V of Q)V(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function jZ($,Z,J,Q=0){let V=Z.now(),W=new L,X=W.writeVarString($);if(X!==0)return I(X);let G={id:W.result(),ts:new Date(0)},[N,q]=UZ(G);if(q!==0)return I(q);let P=V.getTime()-G.ts.getTime();return F({eid:N,off:P,ctr:Q,len:J.length,bod:J})}class PQ{singletonType;latest;latestOff=-1;emitter=new L$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new c(Z.eid),[Q,V]=J.readStruct(g0);if(V!==0)continue;let W=new L;W.writeVarString(this.singletonType);let X=W.result();if(Q.id.length===X.length&&Q.id.every((Y,G)=>Y===X[G])){if(this.latest===void 0||Z.off>this.latestOff)this.latestOff=Z.off,this.latest=Z.bod,this.emitter.emit(this.singletonType,null)}}return $.map(()=>0)}clear=async()=>{return this.latest=void 0,this.latestOff=-1,this.emitter.emit(this.singletonType,null),0};notify=($)=>{for(let Z of $)if(Z===this.singletonType)this.emitter.emit(this.singletonType,null)};refresh=async($)=>{this.notify([this.singletonType])};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function kZ($,Z,J,Q){let V=new c($.headCph),[W,X]=V.readStruct(E0);if(X!==0)return I(X);let{sig:Y,kdm:G,headCph:N}=W;if(!await Q.checkSigEd25519(Y,N,Z))return I(3);let P=J.deriveCipher(G,"decrypt"),R;try{R=await P.decrypt(N)}catch{return I(20)}return F({kdm:G,headEnc:R})}var k0=rJ(_J(),1),_V={encode:k0.encode,decode:k0.decode,decodeAsync:k0.decodeAsync},mV=_V;import{Database as BV}from"bun:sqlite";var BG=Symbol("EntityID");var gG=Symbol("MasterSeed"),xG=Symbol("DerivationSeed"),fG=Symbol("PublicKey"),vG=Symbol("PrivateKey"),lG=Symbol("HostSpecificKeyPair"),yG=Symbol("Hash"),N0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function gV($="diplomatic.db"){let Z=new BV($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
1
+ var NQ=Object.create;var{getPrototypeOf:zQ,defineProperty:NZ,getOwnPropertyNames:IQ}=Object;var MQ=Object.prototype.hasOwnProperty;function PQ($){return this[$]}var RQ,OQ,KQ=($,Z,J)=>{var Q=$!=null&&typeof $==="object";if(Q){var V=Z?RQ??=new WeakMap:OQ??=new WeakMap,X=V.get($);if(X)return X}J=$!=null?NQ(zQ($)):{};let Y=Z||!$||!$.__esModule?NZ(J,"default",{value:$,enumerable:!0}):J;for(let W of IQ($))if(!MQ.call(Y,W))NZ(Y,W,{get:PQ.bind($,W),enumerable:!0});if(Q)V.set($,Y);return Y};var c=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var M$=c((WJ)=>{Object.defineProperty(WJ,"__esModule",{value:!0});WJ.utf8Count=aQ;WJ.utf8EncodeJs=VJ;WJ.utf8EncodeTE=XJ;WJ.utf8Encode=eQ;WJ.utf8DecodeJs=YJ;WJ.utf8DecodeTD=GJ;WJ.utf8Decode=QV;function aQ($){let Z=$.length,J=0,Q=0;while(Q<Z){let V=$.charCodeAt(Q++);if((V&4294967168)===0){J++;continue}else if((V&4294965248)===0)J+=2;else{if(V>=55296&&V<=56319){if(Q<Z){let X=$.charCodeAt(Q);if((X&64512)===56320)++Q,V=((V&1023)<<10)+(X&1023)+65536}}if((V&4294901760)===0)J+=3;else J+=4}}return J}function VJ($,Z,J){let Q=$.length,V=J,X=0;while(X<Q){let Y=$.charCodeAt(X++);if((Y&4294967168)===0){Z[V++]=Y;continue}else if((Y&4294965248)===0)Z[V++]=Y>>6&31|192;else{if(Y>=55296&&Y<=56319){if(X<Q){let W=$.charCodeAt(X);if((W&64512)===56320)++X,Y=((Y&1023)<<10)+(W&1023)+65536}}if((Y&4294901760)===0)Z[V++]=Y>>12&15|224,Z[V++]=Y>>6&63|128;else Z[V++]=Y>>18&7|240,Z[V++]=Y>>12&63|128,Z[V++]=Y>>6&63|128}Z[V++]=Y&63|128}}var sQ=new TextEncoder,tQ=50;function XJ($,Z,J){sQ.encodeInto($,Z.subarray(J))}function eQ($,Z,J){if($.length>tQ)XJ($,Z,J);else VJ($,Z,J)}var $V=4096;function YJ($,Z,J){let Q=Z,V=Q+J,X=[],Y="";while(Q<V){let W=$[Q++];if((W&128)===0)X.push(W);else if((W&224)===192){let q=$[Q++]&63;X.push((W&31)<<6|q)}else if((W&240)===224){let q=$[Q++]&63,N=$[Q++]&63;X.push((W&31)<<12|q<<6|N)}else if((W&248)===240){let q=$[Q++]&63,N=$[Q++]&63,z=$[Q++]&63,I=(W&7)<<18|q<<12|N<<6|z;if(I>65535)I-=65536,X.push(I>>>10&1023|55296),I=56320|I&1023;X.push(I)}else X.push(W);if(X.length>=$V)Y+=String.fromCharCode(...X),X.length=0}if(X.length>0)Y+=String.fromCharCode(...X);return Y}var ZV=new TextDecoder,JV=200;function GJ($,Z,J){let Q=$.subarray(Z,Z+J);return ZV.decode(Q)}function QV($,Z,J){if(J>JV)return GJ($,Z,J);else return YJ($,Z,J)}});var a$=c((NJ)=>{Object.defineProperty(NJ,"__esModule",{value:!0});NJ.ExtData=void 0;class qJ{type;data;constructor($,Z){this.type=$,this.data=Z}}NJ.ExtData=qJ});var R$=c((IJ)=>{Object.defineProperty(IJ,"__esModule",{value:!0});IJ.DecodeError=void 0;class P$ extends Error{constructor($){super($);let Z=Object.create(P$.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:P$.name})}}IJ.DecodeError=P$});var O$=c((PJ)=>{Object.defineProperty(PJ,"__esModule",{value:!0});PJ.UINT32_MAX=void 0;PJ.setUint64=zV;PJ.setInt64=IV;PJ.getInt64=MV;PJ.getUint64=PV;PJ.UINT32_MAX=4294967295;function zV($,Z,J){let Q=J/4294967296,V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function IV($,Z,J){let Q=Math.floor(J/4294967296),V=J;$.setUint32(Z,Q),$.setUint32(Z+4,V)}function MV($,Z){let J=$.getInt32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}function PV($,Z){let J=$.getUint32(Z),Q=$.getUint32(Z+4);return J*4294967296+Q}});var s$=c((TJ)=>{Object.defineProperty(TJ,"__esModule",{value:!0});TJ.timestampExtension=TJ.EXT_TIMESTAMP=void 0;TJ.encodeTimeSpecToTimestamp=KJ;TJ.encodeDateToTimeSpec=FJ;TJ.encodeTimestampExtension=HJ;TJ.decodeTimestampToTimeSpec=UJ;TJ.decodeTimestampExtension=wJ;var HV=R$(),OJ=O$();TJ.EXT_TIMESTAMP=-1;var UV=4294967295,wV=17179869183;function KJ({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=wV)if(Z===0&&$<=UV){let J=new Uint8Array(4);return new DataView(J.buffer).setUint32(0,$),J}else{let J=$/4294967296,Q=$&4294967295,V=new Uint8Array(8),X=new DataView(V.buffer);return X.setUint32(0,Z<<2|J&3),X.setUint32(4,Q),V}else{let J=new Uint8Array(12),Q=new DataView(J.buffer);return Q.setUint32(0,Z),(0,OJ.setInt64)(Q,4,$),J}}function FJ($){let Z=$.getTime(),J=Math.floor(Z/1000),Q=(Z-J*1000)*1e6,V=Math.floor(Q/1e9);return{sec:J+V,nsec:Q-V*1e9}}function HJ($){if($ instanceof Date){let Z=FJ($);return KJ(Z)}else return null}function UJ($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let J=Z.getUint32(0),Q=0;return{sec:J,nsec:0}}case 8:{let J=Z.getUint32(0),Q=Z.getUint32(4),V=(J&3)*4294967296+Q,X=J>>>2;return{sec:V,nsec:X}}case 12:{let J=(0,OJ.getInt64)(Z,4),Q=Z.getUint32(0);return{sec:J,nsec:Q}}default:throw new HV.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function wJ($){let Z=UJ($);return new Date(Z.sec*1000+Z.nsec/1e6)}TJ.timestampExtension={type:TJ.EXT_TIMESTAMP,encode:HJ,decode:wJ}});var F$=c((AJ)=>{Object.defineProperty(AJ,"__esModule",{value:!0});AJ.ExtensionCodec=void 0;var K$=a$(),LV=s$();class t${static defaultCodec=new t$;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(LV.timestampExtension)}register({type:$,encode:Z,decode:J}){if($>=0)this.encoders[$]=Z,this.decoders[$]=J;else{let Q=-1-$;this.builtInEncoders[Q]=Z,this.builtInDecoders[Q]=J}}tryToEncode($,Z){for(let J=0;J<this.builtInEncoders.length;J++){let Q=this.builtInEncoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let X=-1-J;return new K$.ExtData(X,V)}}}for(let J=0;J<this.encoders.length;J++){let Q=this.encoders[J];if(Q!=null){let V=Q($,Z);if(V!=null){let X=J;return new K$.ExtData(X,V)}}}if($ instanceof K$.ExtData)return $;return null}decode($,Z,J){let Q=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(Q)return Q($,Z,J);else return new K$.ExtData(Z,$)}}AJ.ExtensionCodec=t$});var e$=c((LJ)=>{Object.defineProperty(LJ,"__esModule",{value:!0});LJ.ensureUint8Array=SV;function EV($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function SV($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(EV($))return new Uint8Array($);else return Uint8Array.from($)}});var ZZ=c((kJ)=>{Object.defineProperty(kJ,"__esModule",{value:!0});kJ.Encoder=kJ.DEFAULT_INITIAL_BUFFER_SIZE=kJ.DEFAULT_MAX_DEPTH=void 0;var EJ=M$(),mV=F$(),SJ=O$(),_V=e$();kJ.DEFAULT_MAX_DEPTH=100;kJ.DEFAULT_INITIAL_BUFFER_SIZE=2048;class $Z{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??mV.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??kJ.DEFAULT_MAX_DEPTH,this.initialBufferSize=$?.initialBufferSize??kJ.DEFAULT_INITIAL_BUFFER_SIZE,this.sortKeys=$?.sortKeys??!1,this.forceFloat32=$?.forceFloat32??!1,this.ignoreUndefined=$?.ignoreUndefined??!1,this.forceIntegerToFloat=$?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new $Z({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef($){if(this.entered)return this.clone().encodeSharedRef($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode($){if(this.entered)return this.clone().encode($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode($,Z){if(Z>this.maxDepth)throw Error(`Too deep objects in depth ${Z}`);if($==null)this.encodeNil();else if(typeof $==="boolean")this.encodeBoolean($);else if(typeof $==="number")if(!this.forceIntegerToFloat)this.encodeNumber($);else this.encodeNumberAsFloat($);else if(typeof $==="string")this.encodeString($);else if(this.useBigInt64&&typeof $==="bigint")this.encodeBigInt64($);else this.encodeObject($,Z)}ensureBufferSizeToWrite($){let Z=this.pos+$;if(this.view.byteLength<Z)this.resizeBuffer(Z*2)}resizeBuffer($){let Z=new ArrayBuffer($),J=new Uint8Array(Z),Q=new DataView(Z);J.set(this.bytes),this.view=Q,this.bytes=J}encodeNil(){this.writeU8(192)}encodeBoolean($){if($===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber($){if(!this.forceIntegerToFloat&&Number.isSafeInteger($))if($>=0)if($<128)this.writeU8($);else if($<256)this.writeU8(204),this.writeU8($);else if($<65536)this.writeU8(205),this.writeU16($);else if($<4294967296)this.writeU8(206),this.writeU32($);else if(!this.useBigInt64)this.writeU8(207),this.writeU64($);else this.encodeNumberAsFloat($);else if($>=-32)this.writeU8(224|$+32);else if($>=-128)this.writeU8(208),this.writeI8($);else if($>=-32768)this.writeU8(209),this.writeI16($);else if($>=-2147483648)this.writeU8(210),this.writeI32($);else if(!this.useBigInt64)this.writeU8(211),this.writeI64($);else this.encodeNumberAsFloat($);else this.encodeNumberAsFloat($)}encodeNumberAsFloat($){if(this.forceFloat32)this.writeU8(202),this.writeF32($);else this.writeU8(203),this.writeF64($)}encodeBigInt64($){if($>=BigInt(0))this.writeU8(207),this.writeBigUint64($);else this.writeU8(211),this.writeBigInt64($)}writeStringHeader($){if($<32)this.writeU8(160+$);else if($<256)this.writeU8(217),this.writeU8($);else if($<65536)this.writeU8(218),this.writeU16($);else if($<4294967296)this.writeU8(219),this.writeU32($);else throw Error(`Too long string: ${$} bytes in UTF-8`)}encodeString($){let J=(0,EJ.utf8Count)($);this.ensureBufferSizeToWrite(5+J),this.writeStringHeader(J),(0,EJ.utf8Encode)($,this.bytes,this.pos),this.pos+=J}encodeObject($,Z){let J=this.extensionCodec.tryToEncode($,this.context);if(J!=null)this.encodeExtension(J);else if(Array.isArray($))this.encodeArray($,Z);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,Z);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let Z=$.byteLength;if(Z<256)this.writeU8(196),this.writeU8(Z);else if(Z<65536)this.writeU8(197),this.writeU16(Z);else if(Z<4294967296)this.writeU8(198),this.writeU32(Z);else throw Error(`Too large binary: ${Z}`);let J=(0,_V.ensureUint8Array)($);this.writeU8a(J)}encodeArray($,Z){let J=$.length;if(J<16)this.writeU8(144+J);else if(J<65536)this.writeU8(220),this.writeU16(J);else if(J<4294967296)this.writeU8(221),this.writeU32(J);else throw Error(`Too large array: ${J}`);for(let Q of $)this.doEncode(Q,Z+1)}countWithoutUndefined($,Z){let J=0;for(let Q of Z)if($[Q]!==void 0)J++;return J}encodeMap($,Z){let J=Object.keys($);if(this.sortKeys)J.sort();let Q=this.ignoreUndefined?this.countWithoutUndefined($,J):J.length;if(Q<16)this.writeU8(128+Q);else if(Q<65536)this.writeU8(222),this.writeU16(Q);else if(Q<4294967296)this.writeU8(223),this.writeU32(Q);else throw Error(`Too large map object: ${Q}`);for(let V of J){let X=$[V];if(!(this.ignoreUndefined&&X===void 0))this.encodeString(V),this.doEncode(X,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let J=$.data(this.pos+6),Q=J.length;if(Q>=4294967296)throw Error(`Too large extension object: ${Q}`);this.writeU8(201),this.writeU32(Q),this.writeI8($.type),this.writeU8a(J);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),(0,SJ.setUint64)(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),(0,SJ.setInt64)(this.view,this.pos,$),this.pos+=8}writeBigUint64($){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,$),this.pos+=8}writeBigInt64($){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,$),this.pos+=8}}kJ.Encoder=$Z});var xJ=c((gJ)=>{Object.defineProperty(gJ,"__esModule",{value:!0});gJ.encode=gV;var BV=ZZ();function gV($,Z){return new BV.Encoder(Z).encodeSharedRef($)}});var vJ=c((fJ)=>{Object.defineProperty(fJ,"__esModule",{value:!0});fJ.prettyByte=fV;function fV($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}});var bJ=c((iJ)=>{Object.defineProperty(iJ,"__esModule",{value:!0});iJ.CachedKeyDecoder=void 0;var yV=M$(),iV=16,lV=16;class yJ{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=iV,Z=lV){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let J=0;J<this.maxKeyLength;J++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,J){let Q=this.caches[J-1];$:for(let V of Q){let X=V.bytes;for(let Y=0;Y<J;Y++)if(X[Y]!==$[Z+Y])continue $;return V.str}return null}store($,Z){let J=this.caches[$.length-1],Q={bytes:$,str:Z};if(J.length>=this.maxLengthPerKey)J[Math.random()*J.length|0]=Q;else J.push(Q)}decode($,Z,J){let Q=this.find($,Z,J);if(Q!=null)return this.hit++,Q;this.miss++;let V=(0,yV.utf8DecodeJs)($,Z,J),X=Uint8Array.prototype.slice.call($,Z,Z+J);return this.store(X,V),V}}iJ.CachedKeyDecoder=yJ});var H$=c((nJ)=>{Object.defineProperty(nJ,"__esModule",{value:!0});nJ.Decoder=void 0;var JZ=vJ(),bV=F$(),C0=O$(),uV=M$(),uJ=e$(),hV=bJ(),I0=R$(),QZ="array",o0="map_key",pJ="map_value",pV=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new I0.DecodeError("The type of key must be string or number but "+typeof $)};class dJ{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=QZ,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=o0,Z.readCount=0,Z.size=$,Z.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let $={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push($)}return this.stack[this.stackHeadPosition]}release($){if(this.stack[this.stackHeadPosition]!==$)throw Error("Invalid stack state. Released state is not on top of the stack.");if($.type===QZ){let J=$;J.size=0,J.array=void 0,J.position=0,J.type=void 0}if($.type===o0||$.type===pJ){let J=$;J.size=0,J.map=void 0,J.readCount=0,J.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var r0=-1,VZ=new DataView(new ArrayBuffer(0)),dV=new Uint8Array(VZ.buffer);try{VZ.getInt8(0)}catch($){if(!($ instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var hJ=RangeError("Insufficient data"),nV=new hV.CachedKeyDecoder;class XZ{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=VZ;bytes=dV;headByte=r0;stack=new dJ;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??bV.ExtensionCodec.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??C0.UINT32_MAX,this.maxBinLength=$?.maxBinLength??C0.UINT32_MAX,this.maxArrayLength=$?.maxArrayLength??C0.UINT32_MAX,this.maxMapLength=$?.maxMapLength??C0.UINT32_MAX,this.maxExtLength=$?.maxExtLength??C0.UINT32_MAX,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:nV,this.mapKeyConverter=$?.mapKeyConverter??pV}clone(){return new XZ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=r0,this.stack.reset()}setBuffer($){let Z=(0,uJ.ensureUint8Array)($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===r0&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),J=(0,uJ.ensureUint8Array)($),Q=new Uint8Array(Z.length+J.length);Q.set(Z),Q.set(J,Z.length),this.setBuffer(Q)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:J}=this;return RangeError(`Extra ${Z.byteLength-J} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,J;for await(let Y of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(Y);try{J=this.doDecodeSync(),Z=!0}catch(W){if(!(W instanceof RangeError))throw W}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return J}let{headByte:Q,pos:V,totalPos:X}=this;throw RangeError(`Insufficient data in parsing ${(0,JZ.prettyByte)(Q)} at ${X} (${V} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let J=Z,Q=-1;for await(let V of $){if(Z&&Q===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(V),J)Q=this.readArraySize(),J=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Q===0)break}catch(X){if(!(X instanceof RangeError))throw X}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let Q=$-128;if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($<160){let Q=$-144;if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else{let Q=$-160;Z=this.decodeString(Q,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let Q=this.lookU8();Z=this.decodeString(Q,1)}else if($===218){let Q=this.lookU16();Z=this.decodeString(Q,2)}else if($===219){let Q=this.lookU32();Z=this.decodeString(Q,4)}else if($===220){let Q=this.readU16();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===221){let Q=this.readU32();if(Q!==0){this.pushArrayState(Q),this.complete();continue $}else Z=[]}else if($===222){let Q=this.readU16();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===223){let Q=this.readU32();if(Q!==0){this.pushMapState(Q),this.complete();continue $}else Z={}}else if($===196){let Q=this.lookU8();Z=this.decodeBinary(Q,1)}else if($===197){let Q=this.lookU16();Z=this.decodeBinary(Q,2)}else if($===198){let Q=this.lookU32();Z=this.decodeBinary(Q,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let Q=this.lookU8();Z=this.decodeExtension(Q,1)}else if($===200){let Q=this.lookU16();Z=this.decodeExtension(Q,2)}else if($===201){let Q=this.lookU32();Z=this.decodeExtension(Q,4)}else throw new I0.DecodeError(`Unrecognized type byte: ${(0,JZ.prettyByte)($)}`);this.complete();let J=this.stack;while(J.length>0){let Q=J.top();if(Q.type===QZ)if(Q.array[Q.position]=Z,Q.position++,Q.position===Q.size)Z=Q.array,J.release(Q);else continue $;else if(Q.type===o0){if(Z==="__proto__")throw new I0.DecodeError("The key __proto__ is not allowed");Q.key=this.mapKeyConverter(Z),Q.type=pJ;continue $}else if(Q.map[Q.key]=Z,Q.readCount++,Q.readCount===Q.size)Z=Q.map,J.release(Q);else{Q.key=null,Q.type=o0;continue $}}return Z}}readHeadByte(){if(this.headByte===r0)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=r0}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new I0.DecodeError(`Unrecognized array type byte: ${(0,JZ.prettyByte)($)}`)}}pushMapState($){if($>this.maxMapLength)throw new I0.DecodeError(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new I0.DecodeError(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,Z){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,Z);return this.decodeBinary($,Z)}decodeUtf8String($,Z){if($>this.maxStrLength)throw new I0.DecodeError(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw hJ;let J=this.pos+Z,Q;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))Q=this.keyDecoder.decode(this.bytes,J,$);else Q=(0,uV.utf8Decode)(this.bytes,J,$);return this.pos+=Z+$,Q}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===o0;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new I0.DecodeError(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw hJ;let J=this.pos+Z,Q=this.bytes.subarray(J,J+$);return this.pos+=Z+$,Q}decodeExtension($,Z){if($>this.maxExtLength)throw new I0.DecodeError(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let J=this.view.getInt8(this.pos+Z),Q=this.decodeBinary($,Z+1);return this.extensionCodec.decode(Q,J,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=(0,C0.getUint64)(this.view,this.pos);return this.pos+=8,$}readI64(){let $=(0,C0.getInt64)(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}nJ.Decoder=XZ});var aJ=c((oJ)=>{Object.defineProperty(oJ,"__esModule",{value:!0});oJ.decode=cV;oJ.decodeMulti=rV;var rJ=H$();function cV($,Z){return new rJ.Decoder(Z).decode($)}function rV($,Z){return new rJ.Decoder(Z).decodeMulti($)}});var $Q=c((eJ)=>{Object.defineProperty(eJ,"__esModule",{value:!0});eJ.isAsyncIterable=sJ;eJ.asyncIterableFromStream=tJ;eJ.ensureAsyncIterable=sV;function sJ($){return $[Symbol.asyncIterator]!=null}async function*tJ($){let Z=$.getReader();try{while(!0){let{done:J,value:Q}=await Z.read();if(J)return;yield Q}}finally{Z.releaseLock()}}function sV($){if(sJ($))return $;else return tJ($)}});var JQ=c((ZQ)=>{Object.defineProperty(ZQ,"__esModule",{value:!0});ZQ.decodeAsync=ZX;ZQ.decodeArrayStream=JX;ZQ.decodeMultiStream=QX;var YZ=H$(),GZ=$Q();async function ZX($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new YZ.Decoder(Z).decodeAsync(J)}function JX($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new YZ.Decoder(Z).decodeArrayStream(J)}function QX($,Z){let J=(0,GZ.ensureAsyncIterable)($);return new YZ.Decoder(Z).decodeStream(J)}});var VQ=c((v)=>{Object.defineProperty(v,"__esModule",{value:!0});v.decodeTimestampExtension=v.encodeTimestampExtension=v.decodeTimestampToTimeSpec=v.encodeTimeSpecToTimestamp=v.encodeDateToTimeSpec=v.EXT_TIMESTAMP=v.ExtData=v.ExtensionCodec=v.Encoder=v.DecodeError=v.Decoder=v.decodeMultiStream=v.decodeArrayStream=v.decodeAsync=v.decodeMulti=v.decode=v.encode=void 0;var GX=xJ();Object.defineProperty(v,"encode",{enumerable:!0,get:function(){return GX.encode}});var QQ=aJ();Object.defineProperty(v,"decode",{enumerable:!0,get:function(){return QQ.decode}});Object.defineProperty(v,"decodeMulti",{enumerable:!0,get:function(){return QQ.decodeMulti}});var WZ=JQ();Object.defineProperty(v,"decodeAsync",{enumerable:!0,get:function(){return WZ.decodeAsync}});Object.defineProperty(v,"decodeArrayStream",{enumerable:!0,get:function(){return WZ.decodeArrayStream}});Object.defineProperty(v,"decodeMultiStream",{enumerable:!0,get:function(){return WZ.decodeMultiStream}});var WX=H$();Object.defineProperty(v,"Decoder",{enumerable:!0,get:function(){return WX.Decoder}});var qX=R$();Object.defineProperty(v,"DecodeError",{enumerable:!0,get:function(){return qX.DecodeError}});var NX=ZZ();Object.defineProperty(v,"Encoder",{enumerable:!0,get:function(){return NX.Encoder}});var zX=F$();Object.defineProperty(v,"ExtensionCodec",{enumerable:!0,get:function(){return zX.ExtensionCodec}});var IX=a$();Object.defineProperty(v,"ExtData",{enumerable:!0,get:function(){return IX.ExtData}});var i0=s$();Object.defineProperty(v,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return i0.EXT_TIMESTAMP}});Object.defineProperty(v,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return i0.encodeDateToTimeSpec}});Object.defineProperty(v,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return i0.encodeTimeSpecToTimestamp}});Object.defineProperty(v,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return i0.decodeTimestampToTimeSpec}});Object.defineProperty(v,"encodeTimestampExtension",{enumerable:!0,get:function(){return i0.encodeTimestampExtension}});Object.defineProperty(v,"decodeTimestampExtension",{enumerable:!0,get:function(){return i0.decodeTimestampExtension}})});import*as Y0 from"node:crypto";var P0=Y0&&typeof Y0==="object"&&"webcrypto"in Y0?Y0.webcrypto:Y0&&typeof Y0==="object"&&("randomBytes"in Y0)?Y0:void 0;function a0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function U$($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function u($,...Z){if(!U$($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function w$($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function zZ($,Z){u($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function T$($){if(typeof $!=="boolean")throw Error(`boolean expected, not ${$}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */var G0=($)=>new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4));var FQ=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!FQ)throw Error("Non little-endian hardware is not supported");function HQ($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function s0($){if(typeof $==="string")$=HQ($);else if(U$($))$=t0($);else throw Error("Uint8Array expected, got "+typeof $);return $}function IZ($,Z){if(Z==null||typeof Z!=="object")throw Error("options must be defined");return Object.assign($,Z)}function MZ($,Z){if($.length!==Z.length)return!1;let J=0;for(let Q=0;Q<$.length;Q++)J|=$[Q]^Z[Q];return J===0}var PZ=($,Z)=>{function J(Q,...V){if(u(Q),$.nonceLength!==void 0){let z=V[0];if(!z)throw Error("nonce / iv required");if($.varSizeNonce)u(z);else u(z,$.nonceLength)}let X=$.tagLength;if(X&&V[1]!==void 0)u(V[1]);let Y=Z(Q,...V),W=(z,I)=>{if(I!==void 0){if(z!==2)throw Error("cipher output not supported");u(I)}},q=!1;return{encrypt(z,I){if(q)throw Error("cannot encrypt() twice with same key + nonce");return q=!0,u(z),W(Y.encrypt.length,I),Y.encrypt(z,I)},decrypt(z,I){if(u(z),X&&z.length<X)throw Error("invalid ciphertext length: smaller than tagLength="+X);return W(Y.decrypt.length,I),Y.decrypt(z,I)}}}return Object.assign(J,$),J};function C$($,Z,J=!0){if(Z===void 0)return new Uint8Array($);if(Z.length!==$)throw Error("invalid output length, expected "+$+", got: "+Z.length);if(J&&!UQ(Z))throw Error("invalid output, must be aligned");return Z}function UQ($){return $.byteOffset%4===0}function t0($){return Uint8Array.from($)}function J0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function e0($=32){if(P0&&typeof P0.getRandomValues==="function")return P0.getRandomValues(new Uint8Array($));if(P0&&typeof P0.randomBytes==="function")return P0.randomBytes($);throw Error("crypto.getRandomValues must be defined")}var OZ=($)=>Uint8Array.from($.split("").map((Z)=>Z.charCodeAt(0))),wQ=OZ("expand 16-byte k"),TQ=OZ("expand 32-byte k"),CQ=G0(wQ),DQ=G0(TQ);function H($,Z){return $<<Z|$>>>32-Z}function D$($){return $.byteOffset%4===0}var $$=64,AQ=16,KZ=4294967295,RZ=new Uint32Array;function jQ($,Z,J,Q,V,X,Y,W){let q=V.length,N=new Uint8Array($$),z=G0(N),I=D$(V)&&D$(X),P=I?G0(V):RZ,O=I?G0(X):RZ;for(let K=0;K<q;Y++){if($(Z,J,Q,z,Y,W),Y>=KZ)throw Error("arx: counter overflow");let F=Math.min($$,q-K);if(I&&F===$$){let U=K/4;if(K%4!==0)throw Error("arx: invalid block position");for(let T=0,D;T<AQ;T++)D=U+T,O[D]=P[D]^z[T];K+=$$;continue}for(let U=0,T;U<F;U++)T=K+U,X[T]=V[T]^N[U];K+=F}}function FZ($,Z){let{allowShortKeys:J,extendNonceFn:Q,counterLength:V,counterRight:X,rounds:Y}=IZ({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},Z);if(typeof $!=="function")throw Error("core must be a function");return a0(V),a0(Y),T$(X),T$(J),(W,q,N,z,I=0)=>{u(W),u(q),u(N);let P=N.length;if(z===void 0)z=new Uint8Array(P);if(u(z),a0(I),I<0||I>=KZ)throw Error("arx: counter overflow");if(z.length<P)throw Error(`arx: output (${z.length}) is shorter than data (${P})`);let O=[],K=W.length,F,U;if(K===32)O.push(F=t0(W)),U=DQ;else if(K===16&&J)F=new Uint8Array(32),F.set(W),F.set(W,16),U=CQ,O.push(F);else throw Error(`arx: invalid 32-byte key, got length=${K}`);if(!D$(q))O.push(q=t0(q));let T=G0(F);if(Q){if(q.length!==24)throw Error("arx: extended nonce must be 24 bytes");Q(U,T,G0(q.subarray(0,16)),T),q=q.subarray(16)}let D=16-V;if(D!==q.length)throw Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let w=new Uint8Array(12);w.set(q,X?0:12-q.length),q=w,O.push(q)}let j=G0(q);return jQ($,U,T,j,N,z,I,Y),J0(...O),z}}var p=($,Z)=>$[Z++]&255|($[Z++]&255)<<8;class HZ{constructor($){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,$=s0($),u($,32);let Z=p($,0),J=p($,2),Q=p($,4),V=p($,6),X=p($,8),Y=p($,10),W=p($,12),q=p($,14);this.r[0]=Z&8191,this.r[1]=(Z>>>13|J<<3)&8191,this.r[2]=(J>>>10|Q<<6)&7939,this.r[3]=(Q>>>7|V<<9)&8191,this.r[4]=(V>>>4|X<<12)&255,this.r[5]=X>>>1&8190,this.r[6]=(X>>>14|Y<<2)&8191,this.r[7]=(Y>>>11|W<<5)&8065,this.r[8]=(W>>>8|q<<8)&8191,this.r[9]=q>>>5&127;for(let N=0;N<8;N++)this.pad[N]=p($,16+2*N)}process($,Z,J=!1){let Q=J?0:2048,{h:V,r:X}=this,Y=X[0],W=X[1],q=X[2],N=X[3],z=X[4],I=X[5],P=X[6],O=X[7],K=X[8],F=X[9],U=p($,Z+0),T=p($,Z+2),D=p($,Z+4),j=p($,Z+6),w=p($,Z+8),E=p($,Z+10),B=p($,Z+12),h=p($,Z+14),S=V[0]+(U&8191),m=V[1]+((U>>>13|T<<3)&8191),g=V[2]+((T>>>10|D<<6)&8191),R=V[3]+((D>>>7|j<<9)&8191),x=V[4]+((j>>>4|w<<12)&8191),_=V[5]+(w>>>1&8191),y=V[6]+((w>>>14|E<<2)&8191),i=V[7]+((E>>>11|B<<5)&8191),l=V[8]+((B>>>8|h<<8)&8191),b=V[9]+(h>>>5|Q),C=0,n=C+S*Y+m*(5*F)+g*(5*K)+R*(5*O)+x*(5*P);C=n>>>13,n&=8191,n+=_*(5*I)+y*(5*z)+i*(5*N)+l*(5*q)+b*(5*W),C+=n>>>13,n&=8191;let a=C+S*W+m*Y+g*(5*F)+R*(5*K)+x*(5*O);C=a>>>13,a&=8191,a+=_*(5*P)+y*(5*I)+i*(5*z)+l*(5*N)+b*(5*q),C+=a>>>13,a&=8191;let e=C+S*q+m*W+g*Y+R*(5*F)+x*(5*K);C=e>>>13,e&=8191,e+=_*(5*O)+y*(5*P)+i*(5*I)+l*(5*z)+b*(5*N),C+=e>>>13,e&=8191;let k=C+S*N+m*q+g*W+R*Y+x*(5*F);C=k>>>13,k&=8191,k+=_*(5*K)+y*(5*O)+i*(5*P)+l*(5*I)+b*(5*z),C+=k>>>13,k&=8191;let X0=C+S*z+m*N+g*q+R*W+x*Y;C=X0>>>13,X0&=8191,X0+=_*(5*F)+y*(5*K)+i*(5*O)+l*(5*P)+b*(5*I),C+=X0>>>13,X0&=8191;let D0=C+S*I+m*z+g*N+R*q+x*W;C=D0>>>13,D0&=8191,D0+=_*Y+y*(5*F)+i*(5*K)+l*(5*O)+b*(5*P),C+=D0>>>13,D0&=8191;let A0=C+S*P+m*I+g*z+R*N+x*q;C=A0>>>13,A0&=8191,A0+=_*W+y*Y+i*(5*F)+l*(5*K)+b*(5*O),C+=A0>>>13,A0&=8191;let j0=C+S*O+m*P+g*I+R*z+x*N;C=j0>>>13,j0&=8191,j0+=_*q+y*W+i*Y+l*(5*F)+b*(5*K),C+=j0>>>13,j0&=8191;let L0=C+S*K+m*O+g*P+R*I+x*z;C=L0>>>13,L0&=8191,L0+=_*N+y*q+i*W+l*Y+b*(5*F),C+=L0>>>13,L0&=8191;let E0=C+S*F+m*K+g*O+R*P+x*I;C=E0>>>13,E0&=8191,E0+=_*z+y*N+i*q+l*W+b*Y,C+=E0>>>13,E0&=8191,C=(C<<2)+C|0,C=C+n|0,n=C&8191,C=C>>>13,a+=C,V[0]=n,V[1]=a,V[2]=e,V[3]=k,V[4]=X0,V[5]=D0,V[6]=A0,V[7]=j0,V[8]=L0,V[9]=E0}finalize(){let{h:$,pad:Z}=this,J=new Uint16Array(10),Q=$[1]>>>13;$[1]&=8191;for(let Y=2;Y<10;Y++)$[Y]+=Q,Q=$[Y]>>>13,$[Y]&=8191;$[0]+=Q*5,Q=$[0]>>>13,$[0]&=8191,$[1]+=Q,Q=$[1]>>>13,$[1]&=8191,$[2]+=Q,J[0]=$[0]+5,Q=J[0]>>>13,J[0]&=8191;for(let Y=1;Y<10;Y++)J[Y]=$[Y]+Q,Q=J[Y]>>>13,J[Y]&=8191;J[9]-=8192;let V=(Q^1)-1;for(let Y=0;Y<10;Y++)J[Y]&=V;V=~V;for(let Y=0;Y<10;Y++)$[Y]=$[Y]&V|J[Y];$[0]=($[0]|$[1]<<13)&65535,$[1]=($[1]>>>3|$[2]<<10)&65535,$[2]=($[2]>>>6|$[3]<<7)&65535,$[3]=($[3]>>>9|$[4]<<4)&65535,$[4]=($[4]>>>12|$[5]<<1|$[6]<<14)&65535,$[5]=($[6]>>>2|$[7]<<11)&65535,$[6]=($[7]>>>5|$[8]<<8)&65535,$[7]=($[8]>>>8|$[9]<<5)&65535;let X=$[0]+Z[0];$[0]=X&65535;for(let Y=1;Y<8;Y++)X=($[Y]+Z[Y]|0)+(X>>>16)|0,$[Y]=X&65535;J0(J)}update($){w$(this);let{buffer:Z,blockLen:J}=this;$=s0($);let Q=$.length;for(let V=0;V<Q;){let X=Math.min(J-this.pos,Q-V);if(X===J){for(;J<=Q-V;V+=J)this.process($,V);continue}if(Z.set($.subarray(V,V+X),this.pos),this.pos+=X,V+=X,this.pos===J)this.process(Z,0,!1),this.pos=0}return this}destroy(){J0(this.h,this.r,this.buffer,this.pad)}digestInto($){w$(this),zZ($,this),this.finished=!0;let{buffer:Z,h:J}=this,{pos:Q}=this;if(Q){Z[Q++]=1;for(;Q<16;Q++)Z[Q]=0;this.process(Z,0,!0)}this.finalize();let V=0;for(let X=0;X<8;X++)$[V++]=J[X]>>>0,$[V++]=J[X]>>>8;return $}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}}function LQ($){let Z=(Q,V)=>$(V).update(s0(Q)).digest(),J=$(new Uint8Array(32));return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var A$=LQ(($)=>new HZ($));function EQ($,Z,J,Q,V,X=20){let Y=$[0],W=Z[0],q=Z[1],N=Z[2],z=Z[3],I=$[1],P=J[0],O=J[1],K=V,F=0,U=$[2],T=Z[4],D=Z[5],j=Z[6],w=Z[7],E=$[3],B=Y,h=W,S=q,m=N,g=z,R=I,x=P,_=O,y=K,i=F,l=U,b=T,C=D,n=j,a=w,e=E;for(let X0=0;X0<X;X0+=2)g^=H(B+C|0,7),y^=H(g+B|0,9),C^=H(y+g|0,13),B^=H(C+y|0,18),i^=H(R+h|0,7),n^=H(i+R|0,9),h^=H(n+i|0,13),R^=H(h+n|0,18),a^=H(l+x|0,7),S^=H(a+l|0,9),x^=H(S+a|0,13),l^=H(x+S|0,18),m^=H(e+b|0,7),_^=H(m+e|0,9),b^=H(_+m|0,13),e^=H(b+_|0,18),h^=H(B+m|0,7),S^=H(h+B|0,9),m^=H(S+h|0,13),B^=H(m+S|0,18),x^=H(R+g|0,7),_^=H(x+R|0,9),g^=H(_+x|0,13),R^=H(g+_|0,18),b^=H(l+i|0,7),y^=H(b+l|0,9),i^=H(y+b|0,13),l^=H(i+y|0,18),C^=H(e+a|0,7),n^=H(C+e|0,9),a^=H(n+C|0,13),e^=H(a+n|0,18);let k=0;Q[k++]=Y+B|0,Q[k++]=W+h|0,Q[k++]=q+S|0,Q[k++]=N+m|0,Q[k++]=z+g|0,Q[k++]=I+R|0,Q[k++]=P+x|0,Q[k++]=O+_|0,Q[k++]=K+y|0,Q[k++]=F+i|0,Q[k++]=U+l|0,Q[k++]=T+b|0,Q[k++]=D+C|0,Q[k++]=j+n|0,Q[k++]=w+a|0,Q[k++]=E+e|0}function SQ($,Z,J,Q){let V=$[0],X=Z[0],Y=Z[1],W=Z[2],q=Z[3],N=$[1],z=J[0],I=J[1],P=J[2],O=J[3],K=$[2],F=Z[4],U=Z[5],T=Z[6],D=Z[7],j=$[3];for(let E=0;E<20;E+=2)q^=H(V+U|0,7),P^=H(q+V|0,9),U^=H(P+q|0,13),V^=H(U+P|0,18),O^=H(N+X|0,7),T^=H(O+N|0,9),X^=H(T+O|0,13),N^=H(X+T|0,18),D^=H(K+z|0,7),Y^=H(D+K|0,9),z^=H(Y+D|0,13),K^=H(z+Y|0,18),W^=H(j+F|0,7),I^=H(W+j|0,9),F^=H(I+W|0,13),j^=H(F+I|0,18),X^=H(V+W|0,7),Y^=H(X+V|0,9),W^=H(Y+X|0,13),V^=H(W+Y|0,18),z^=H(N+q|0,7),I^=H(z+N|0,9),q^=H(I+z|0,13),N^=H(q+I|0,18),F^=H(K+O|0,7),P^=H(F+K|0,9),O^=H(P+F|0,13),K^=H(O+P|0,18),U^=H(j+D|0,7),T^=H(U+j|0,9),D^=H(T+U|0,13),j^=H(D+T|0,18);let w=0;Q[w++]=V,Q[w++]=N,Q[w++]=K,Q[w++]=j,Q[w++]=z,Q[w++]=I,Q[w++]=P,Q[w++]=O}var j$=FZ(EQ,{counterRight:!0,extendNonceFn:SQ}),L$=PZ({blockSize:64,nonceLength:24,tagLength:16},($,Z)=>{return{encrypt(J,Q){Q=C$(J.length+32,Q,!1);let V=Q.subarray(0,32),X=Q.subarray(32);Q.set(J,32),J0(V),j$($,Z,Q,Q);let Y=A$(X,V);return Q.set(Y,16),J0(Q.subarray(0,16),Y),Q.subarray(16)},decrypt(J,Q){u(J),Q=C$(J.length+32,Q,!1);let V=Q.subarray(0,32),X=Q.subarray(32,48),Y=Q.subarray(48);Q.set(J,32),J0(V);let W=j$($,Z,V,V),q=A$(Y,W);if(!MZ(X,q))throw Error("invalid tag");return j$($,Z,Q.subarray(16),Q.subarray(16)),J0(V,X,q),Y}}});/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function kQ($){return $ instanceof Uint8Array||ArrayBuffer.isView($)&&$.constructor.name==="Uint8Array"}function b0($){if(!Number.isSafeInteger($)||$<0)throw Error("positive integer expected, got "+$)}function R0($,...Z){if(!kQ($))throw Error("Uint8Array expected");if(Z.length>0&&!Z.includes($.length))throw Error("Uint8Array expected of length "+Z+", got length="+$.length)}function u0($,Z=!0){if($.destroyed)throw Error("Hash instance has been destroyed");if(Z&&$.finished)throw Error("Hash#digest() has already been called")}function Z$($,Z){R0($);let J=Z.outputLen;if($.length<J)throw Error("digestInto() expects output buffer of length at least "+J)}function UZ($){return new Uint8Array($.buffer,$.byteOffset,$.byteLength)}function S0($){return new Uint32Array($.buffer,$.byteOffset,Math.floor($.byteLength/4))}function k0(...$){for(let Z=0;Z<$.length;Z++)$[Z].fill(0)}function h0($,Z){return $<<32-Z|$>>>Z}var wZ=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function TZ($){return $<<24&4278190080|$<<8&16711680|$>>>8&65280|$>>>24&255}var CZ=wZ?($)=>$:($)=>TZ($);function mQ($){for(let Z=0;Z<$.length;Z++)$[Z]=TZ($[Z]);return $}var s=wZ?($)=>$:mQ;function _Q($){if(typeof $!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode($))}function m0($){if(typeof $==="string")$=_Q($);return R0($),$}class E${}function DZ($){let Z=(Q,V)=>$(V).update(m0(Q)).digest(),J=$({});return Z.outputLen=J.outputLen,Z.blockLen=J.blockLen,Z.create=(Q)=>$(Q),Z}var AZ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J$=BigInt(4294967295),jZ=BigInt(32);function S$($,Z=!1){if(Z)return{h:Number($&J$),l:Number($>>jZ&J$)};return{h:Number($>>jZ&J$)|0,l:Number($&J$)|0}}function W0($,Z,J,Q,V){return $=$+Z+V|0,Q=h0(Q^$,16),J=J+Q|0,Z=h0(Z^J,12),{a:$,b:Z,c:J,d:Q}}function q0($,Z,J,Q,V){return $=$+Z+V|0,Q=h0(Q^$,8),J=J+Q|0,Z=h0(Z^J,7),{a:$,b:Z,c:J,d:Q}}class k$ extends E${constructor($,Z){super();this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,b0($),b0(Z),this.blockLen=$,this.outputLen=Z,this.buffer=new Uint8Array($),this.buffer32=S0(this.buffer)}update($){u0(this),$=m0($),R0($);let{blockLen:Z,buffer:J,buffer32:Q}=this,V=$.length,X=$.byteOffset,Y=$.buffer;for(let W=0;W<V;){if(this.pos===Z)s(Q),this.compress(Q,0,!1),s(Q),this.pos=0;let q=Math.min(Z-this.pos,V-W),N=X+W;if(q===Z&&!(N%4)&&W+q<V){let z=new Uint32Array(Y,N,Math.floor((V-W)/4));s(z);for(let I=0;W+Z<V;I+=Q.length,W+=Z)this.length+=Z,this.compress(z,I,!1);s(z);continue}J.set($.subarray(W,W+q),this.pos),this.pos+=q,this.length+=q,W+=q}return this}digestInto($){u0(this),Z$($,this);let{pos:Z,buffer32:J}=this;this.finished=!0,k0(this.buffer.subarray(Z)),s(J),this.compress(J,0,!0),s(J);let Q=S0($);this.get().forEach((V,X)=>Q[X]=CZ(V))}digest(){let{buffer:$,outputLen:Z}=this;this.digestInto($);let J=$.slice(0,Z);return this.destroy(),J}_cloneInto($){let{buffer:Z,length:J,finished:Q,destroyed:V,outputLen:X,pos:Y}=this;return $||($=new this.constructor({dkLen:X})),$.set(...this.get()),$.buffer.set(Z),$.destroyed=V,$.finished=Q,$.length=J,$.pos=Y,$.outputLen=X,$}clone(){return this._cloneInto()}}function m$($,Z,J,Q,V,X,Y,W,q,N,z,I,P,O,K,F,U,T,D,j){let w=0;for(let E=0;E<Q;E++)({a:V,b:q,c:P,d:U}=W0(V,q,P,U,J[Z+$[w++]])),{a:V,b:q,c:P,d:U}=q0(V,q,P,U,J[Z+$[w++]]),{a:X,b:N,c:O,d:T}=W0(X,N,O,T,J[Z+$[w++]]),{a:X,b:N,c:O,d:T}=q0(X,N,O,T,J[Z+$[w++]]),{a:Y,b:z,c:K,d:D}=W0(Y,z,K,D,J[Z+$[w++]]),{a:Y,b:z,c:K,d:D}=q0(Y,z,K,D,J[Z+$[w++]]),{a:W,b:I,c:F,d:j}=W0(W,I,F,j,J[Z+$[w++]]),{a:W,b:I,c:F,d:j}=q0(W,I,F,j,J[Z+$[w++]]),{a:V,b:N,c:K,d:j}=W0(V,N,K,j,J[Z+$[w++]]),{a:V,b:N,c:K,d:j}=q0(V,N,K,j,J[Z+$[w++]]),{a:X,b:z,c:F,d:U}=W0(X,z,F,U,J[Z+$[w++]]),{a:X,b:z,c:F,d:U}=q0(X,z,F,U,J[Z+$[w++]]),{a:Y,b:I,c:P,d:T}=W0(Y,I,P,T,J[Z+$[w++]]),{a:Y,b:I,c:P,d:T}=q0(Y,I,P,T,J[Z+$[w++]]),{a:W,b:q,c:O,d:D}=W0(W,q,O,D,J[Z+$[w++]]),{a:W,b:q,c:O,d:D}=q0(W,q,O,D,J[Z+$[w++]]);return{v0:V,v1:X,v2:Y,v3:W,v4:q,v5:N,v6:z,v7:I,v8:P,v9:O,v10:K,v11:F,v12:U,v13:T,v14:D,v15:j}}var Q0={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},N0=AZ.slice(),LZ=(()=>{let $=Array.from({length:16},(Q,V)=>V),Z=(Q)=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map((V)=>Q[V]),J=[];for(let Q=0,V=$;Q<7;Q++,V=Z(V))J.push(...V);return Uint8Array.from(J)})();class _$ extends k${constructor($={},Z=0){super(64,$.dkLen===void 0?32:$.dkLen);this.chunkPos=0,this.chunksDone=0,this.flags=0,this.stack=[],this.posOut=0,this.bufferOut32=new Uint32Array(16),this.chunkOut=0,this.enableXOF=!0;let{key:J,context:Q}=$,V=Q!==void 0;if(J!==void 0){if(V)throw Error('Only "key" or "context" can be specified at same time');let X=m0(J).slice();R0(X,32),this.IV=S0(X),s(this.IV),this.flags=Z|Q0.KEYED_HASH}else if(V){let X=m0(Q),Y=new _$({dkLen:32},Q0.DERIVE_KEY_CONTEXT).update(X).digest();this.IV=S0(Y),s(this.IV),this.flags=Z|Q0.DERIVE_KEY_MATERIAL}else this.IV=N0.slice(),this.flags=Z;this.state=this.IV.slice(),this.bufferOut=UZ(this.bufferOut32)}get(){return[]}set(){}b2Compress($,Z,J,Q=0){let{state:V,pos:X}=this,{h:Y,l:W}=S$(BigInt($),!0),{v0:q,v1:N,v2:z,v3:I,v4:P,v5:O,v6:K,v7:F,v8:U,v9:T,v10:D,v11:j,v12:w,v13:E,v14:B,v15:h}=m$(LZ,Q,J,7,V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7],N0[0],N0[1],N0[2],N0[3],Y,W,X,Z);V[0]=q^U,V[1]=N^T,V[2]=z^D,V[3]=I^j,V[4]=P^w,V[5]=O^E,V[6]=K^B,V[7]=F^h}compress($,Z=0,J=!1){let Q=this.flags;if(!this.chunkPos)Q|=Q0.CHUNK_START;if(this.chunkPos===15||J)Q|=Q0.CHUNK_END;if(!J)this.pos=this.blockLen;if(this.b2Compress(this.chunksDone,Q,$,Z),this.chunkPos+=1,this.chunkPos===16||J){let V=this.state;this.state=this.IV.slice();for(let X,Y=this.chunksDone+1;J||!(Y&1);Y>>=1){if(!(X=this.stack.pop()))break;this.buffer32.set(X,0),this.buffer32.set(V,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|Q0.PARENT,this.buffer32,0),V=this.state,this.state=this.IV.slice()}this.chunksDone++,this.chunkPos=0,this.stack.push(V)}this.pos=0}_cloneInto($){$=super._cloneInto($);let{IV:Z,flags:J,state:Q,chunkPos:V,posOut:X,chunkOut:Y,stack:W,chunksDone:q}=this;return $.state.set(Q.slice()),$.stack=W.map((N)=>Uint32Array.from(N)),$.IV.set(Z),$.flags=J,$.chunkPos=V,$.chunksDone=q,$.posOut=X,$.chunkOut=Y,$.enableXOF=this.enableXOF,$.bufferOut32.set(this.bufferOut32),$}destroy(){this.destroyed=!0,k0(this.state,this.buffer32,this.IV,this.bufferOut32),k0(...this.stack)}b2CompressOut(){let{state:$,pos:Z,flags:J,buffer32:Q,bufferOut32:V}=this,{h:X,l:Y}=S$(BigInt(this.chunkOut++));s(Q);let{v0:W,v1:q,v2:N,v3:z,v4:I,v5:P,v6:O,v7:K,v8:F,v9:U,v10:T,v11:D,v12:j,v13:w,v14:E,v15:B}=m$(LZ,0,Q,7,$[0],$[1],$[2],$[3],$[4],$[5],$[6],$[7],N0[0],N0[1],N0[2],N0[3],Y,X,Z,J);V[0]=W^F,V[1]=q^U,V[2]=N^T,V[3]=z^D,V[4]=I^j,V[5]=P^w,V[6]=O^E,V[7]=K^B,V[8]=$[0]^F,V[9]=$[1]^U,V[10]=$[2]^T,V[11]=$[3]^D,V[12]=$[4]^j,V[13]=$[5]^w,V[14]=$[6]^E,V[15]=$[7]^B,s(Q),s(V),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,k0(this.buffer.subarray(this.pos));let $=this.flags|Q0.ROOT;if(this.stack.length)$|=Q0.PARENT,s(this.buffer32),this.compress(this.buffer32,0,!0),s(this.buffer32),this.chunksDone=0,this.pos=this.blockLen;else $|=(!this.chunkPos?Q0.CHUNK_START:0)|Q0.CHUNK_END;this.flags=$,this.b2CompressOut()}writeInto($){u0(this,!1),R0($),this.finish();let{blockLen:Z,bufferOut:J}=this;for(let Q=0,V=$.length;Q<V;){if(this.posOut>=Z)this.b2CompressOut();let X=Math.min(Z-this.posOut,V-Q);$.set(J.subarray(this.posOut,this.posOut+X),Q),this.posOut+=X,Q+=X}return $}xofInto($){if(!this.enableXOF)throw Error("XOF is not possible after digest call");return this.writeInto($)}xof($){return b0($),this.xofInto(new Uint8Array($))}digestInto($){if(Z$($,this),this.finished)throw Error("digest() was already called");return this.enableXOF=!1,this.writeInto($),this.destroy(),$}digest(){return this.digestInto(new Uint8Array(this.outputLen))}}var EZ=DZ(($)=>new _$($));function r($){return Array.from($).map((J)=>J.toString(16).padStart(2,"0")).join("")}function Q$($){if($.length%2!==0)throw Error("Invalid hex string");let Z=new Uint8Array($.length/2);for(let J=0;J<$.length;J+=2)Z[J/2]=Number.parseInt($.substr(J,2),16);return Z}function mZ($,Z){if($===Z)return!0;if($.byteLength!==Z.byteLength)return!1;return $.every((J,Q)=>J===Z[Q])}var SZ;if(typeof Uint8Array.prototype.toBase64==="function")SZ=($)=>$.toBase64();else SZ=($)=>btoa(String.fromCharCode(...$));var kZ;if(typeof Uint8Array.fromBase64==="function")kZ=($)=>Uint8Array.fromBase64($);else kZ=($)=>Uint8Array.from(atob($),(Z)=>Z.charCodeAt(0));function p0($,Z){let J=new Uint8Array($.length+Z.length);return J.set($,0),J.set(Z,$.length),J}var B$=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function _Z($){let Z=new Uint8Array(B$.length+32);return Z.set(B$),Z.set($.subarray(0,32),B$.length),Z}function BZ($){return typeof $==="string"?new TextEncoder().encode($):$}function _0($){let Z=new ArrayBuffer($.byteLength);return new Uint8Array(Z).set($),Z}class g${verifyKeys=new Map;signKeys=new Map;async genRandomBytes($){return e0($)}async gen256BitSecureRandomSeed(){return e0(32)}async encryptXSalsa20Poly1305Combined($,Z){let J=e0(24),V=L$(Z,J).encrypt($);return new Uint8Array([...J,...V])}async decryptXSalsa20Poly1305Combined($,Z){let J=$.slice(0,24),Q=$.slice(24);return L$(Z,J).decrypt(Q)}async deriveEd25519KeyPair($){let Z=$,J=_Z(Z),Q=await globalThis.crypto.subtle.importKey("pkcs8",_0(J),{name:"Ed25519"},!0,["sign"]),V=await globalThis.crypto.subtle.exportKey("jwk",Q);if(typeof V.x!=="string")throw Error("Ed25519 JWK missing x");let X=await globalThis.crypto.subtle.importKey("jwk",{kty:"OKP",crv:"Ed25519",x:V.x},{name:"Ed25519"},!0,["verify"]),Y=new Uint8Array(await globalThis.crypto.subtle.exportKey("raw",X)),W=new Uint8Array(64);return W.set(Z,0),W.set(Y,32),this.signKeys.set(r(Z),Q),this.verifyKeys.set(r(Y),X),{keyType:"ed25519",privateKey:W,publicKey:Y}}async importSignKey($){let Z=$.subarray(0,32),J=r(Z),Q=this.signKeys.get(J);if(Q)return Q;let V=_Z(Z),X=await globalThis.crypto.subtle.importKey("pkcs8",_0(V),{name:"Ed25519"},!1,["sign"]);return this.signKeys.set(J,X),X}async importVerifyKey($){let Z=r($),J=this.verifyKeys.get(Z);if(J)return J;let Q=await globalThis.crypto.subtle.importKey("raw",_0($),{name:"Ed25519"},!1,["verify"]);return this.verifyKeys.set(Z,Q),Q}async signEd25519($,Z){let J=BZ($),Q=await this.importSignKey(Z),V=await globalThis.crypto.subtle.sign({name:"Ed25519"},Q,_0(J));return new Uint8Array(V)}async checkSigEd25519($,Z,J){let Q=BZ(Z);try{let V=await this.importVerifyKey(J);return await globalThis.crypto.subtle.verify({name:"Ed25519"},V,_0($),_0(Q))}catch{return!1}}async blake3($){return EZ($)}}var BQ=new g$,O0=BQ;var B0=64;var gZ=32,g0=8;var xZ=32;var fZ=30000,vZ=512,A;((R)=>{R[R.Success=0]="Success";R[R.InvalidSignature=3]="InvalidSignature";R[R.ClockOutOfSync=4]="ClockOutOfSync";R[R.UserNotRegistered=5]="UserNotRegistered";R[R.ServerMisconfigured=6]="ServerMisconfigured";R[R.MissingBody=7]="MissingBody";R[R.ExtraBodyContent=8]="ExtraBodyContent";R[R.MissingParam=9]="MissingParam";R[R.InvalidParam=10]="InvalidParam";R[R.InvalidRequest=11]="InvalidRequest";R[R.InternalError=12]="InternalError";R[R.NotFound=13]="NotFound";R[R.InvalidMessage=14]="InvalidMessage";R[R.NoChange=15]="NoChange";R[R.DatabaseClosed=16]="DatabaseClosed";R[R.StorageError=17]="StorageError";R[R.DatabaseError=18]="DatabaseError";R[R.HashMismatch=19]="HashMismatch";R[R.DecryptionError=20]="DecryptionError";R[R.NotImplemented=21]="NotImplemented";R[R.MissingSeed=22]="MissingSeed";R[R.OutOfBounds=23]="OutOfBounds";R[R.HostError=24]="HostError";R[R.CommunicationError=25]="CommunicationError";R[R.VarLimitExceeded=26]="VarLimitExceeded";R[R.InvalidResponse=27]="InvalidResponse";R[R.ConnectionClosed=28]="ConnectionClosed"})(A||={});var yZ="t";function M($){return[$,0]}function G($){return[void 0,$]}function gQ($){if($<0)console.info("N",$),console.trace();if(typeof $!=="bigint")$=BigInt($);if($<0n)return G(10);let Z=[];while($>0n){let J=Number($&0x7fn);if($>>=7n,$>0n)Z.push(J|128);else Z.push(J)}if(Z.length===0)return M(new Uint8Array([0]));if(Z.length>8)return G(26);return M(new Uint8Array(Z))}function xQ($,Z=0){let J=0n,Q=0,V=Z;while(!0){if(V>=$.length)return G(14);let X=$[V++];if(X===void 0)return G(14);if(J|=BigInt(X&127)<<BigInt(Q),(X&128)===0){if(V-Z>8)return G(26);return M({value:J>0x1fffffffffffffn?J:Number(J),bytesRead:V-Z})}if(Q+=7,Q>=56)return G(26)}}class f{data;pos=0;constructor($){this.data=$}static async fromResponse($){let Z=await $.arrayBuffer(),J=new Uint8Array(Z);return new f(J)}readBigInt(){if(this.pos+8>this.data.length)return G(7);let $=new DataView(this.data.buffer,this.data.byteOffset+this.pos).getBigUint64(0,!1);return this.pos+=8,M($)}readDate(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);return M(new Date($))}readVarInt(){let[$,Z]=xQ(this.data,this.pos);if(Z!==0)return G(Z);this.pos+=$.bytesRead;let J=$.value;return M(typeof J==="bigint"?Number(J):J)}readVarString(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);let[J,Q]=this.readBytes($);if(Q!==0)return G(Q);let V=new TextDecoder().decode(J);return M(V)}readBytes($){if($<0)return G(10);if(this.pos+$>this.data.length)return G(23);let Z=this.data.slice(this.pos,this.pos+$);return this.pos+=$,M(Z)}readVarBytes(){let[$,Z]=this.readVarInt();if(Z!==0)return G(Z);return this.readBytes($)}readStruct($){return $.decode(this)}readStructs($){let Z=[];while(!this.done()){let[J,Q]=this.readStruct($);if(Q!==0)return G(Q);Z.push(J)}return M(Z)}readBytesSeq($){let Z=[];while(!this.done()){let[J,Q]=this.readBytes($);if(Q!==0)return G(Q);Z.push(J)}return M(Z)}done(){return this.pos>=this.data.length}consumed(){return this.pos}}class L{parts=[];writeBigInt($){let Z=new Uint8Array(8);new DataView(Z.buffer).setBigUint64(0,$,!1),this.parts.push(Z)}writeDate($){let Z=$.getTime();return this.writeVarInt(Z)}writeVarInt($){let[Z,J]=gQ($);if(J!==0)return J;return this.parts.push(Z),0}writeVarString($){let Z=new TextEncoder().encode($),J=this.writeVarInt(Z.length);if(J!==0)return J;return this.writeBytes(Z),0}prependBytes($){this.parts.unshift($)}writeBytes($){this.parts.push($)}writeVarBytes($){let Z=this.writeVarInt($.length);if(Z!==0)return Z;return this.writeBytes($),0}writeStruct($,Z){return $.encode(this,Z)}writeStructs($,Z){for(let J of Z){let Q=this.writeStruct($,J);if(Q!==0)return Q}return 0}writeBytesSeq($){for(let Z of $)this.writeBytes(Z)}result(){let $=this.parts.reduce((Q,V)=>Q+V.length,0),Z=new Uint8Array($),J=0;for(let Q of this.parts)Z.set(Q,J),J+=Q.length;return Z}*scan(){for(let $ of this.parts)yield $}}var d0={encode($,Z){let J=$.writeVarBytes(Z.id);if(J!==0)return J;let Q=$.writeDate(Z.ts);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let[Q,V]=$.readDate();if(V!==0)return G(V);return M({id:Z,ts:Q})}};function iZ($){let Z=new L,J=Z.writeStruct(d0,$);if(J!==0)return G(J);let Q=Z.result();return M(Q)}var x$={encode($,Z){let J=$.writeVarBytes(Z.eid);if(J!==0)return J;let Q=$.writeVarInt(Z.off);if(Q!==0)return Q;let V=$.writeVarInt(Z.ctr);if(V!==0)return V;let X=$.writeVarInt(Z.len);if(X!==0)return X;if(Z.hsh)$.writeBytes(Z.hsh);return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let Q=new f(Z),[,V]=d0.decode(Q);if(V!==0)return G(V);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);let[W,q]=$.readVarInt();if(q!==0)return G(q);let[N,z]=$.readVarInt();if(z!==0)return G(z);let I;if(N>0){let[P,O]=$.readBytes(xZ);if(O!==0)return G(O);I=P}return M({eid:Z,off:X,ctr:W,len:N,hsh:I})}};function lZ($,Z,J){return J.checkSigEd25519($.sig,$.headCph,Z)}async function bZ($,Z,J,Q){let V;if($.bod&&$.len>0)V=await J.blake3($.bod);let X=new L,Y=x$.encode(X,{...$,hsh:V});if(Y!==0)return G(Y);let W=X.result(),q=await Z.kdmFor(W),N=Q.deriveCipher(q,"encrypt"),z=await N.encrypt(W),I=$.bod?await N.encrypt($.bod):new Uint8Array(0),P=await Z.sign(z);return M({sig:P,kdm:q,headCph:z,bodyCph:I})}async function uZ($,Z,J,Q,V){let X=new f($),[Y,W]=x$.decode(X);if(W!==0)return G(14);let q;try{q=Z&&Z.length>0?await J.decrypt(Z):void 0}catch{return G(20)}let N=Y.hsh&&q===void 0,z=Y.hsh===void 0&&q!==void 0;if(N||z)return G(19);if(Y.hsh&&q){let P=await Q.blake3(q);if(!mZ(P,Y.hsh))return G(19)}let I=V??await Q.blake3($);return M({msgHead:Y,bod:q,headHash:I})}async function f$($,Z){let J=new L,Q=J.writeDate(Z);if(Q!==0)return G(Q);let V=J.result(),X=await $.sign(V);return M({pubKey:$.publicKey,sig:X,timestamp:Z})}async function $0($,Z,J){let Q=J.now().getTime(),V=$.timestamp.getTime();if(Math.abs(Q-V)>fZ)return 4;let Y=new L;Y.writeDate($.timestamp);let W=Y.result();if(!await Z.checkSigEd25519($.sig,W,$.pubKey))return 3;return 0}class x0{now(){return new Date}}function hZ($,Z,J,Q){let V=Z.getTime()-$.getTime(),X=J.getTime()-Q.getTime();return(V+X)/2}var n0={encode($,Z){if($.writeVarInt(Z.quota),Z.quota>0){if(Z.usage===void 0)return 9;$.writeVarInt(Z.usage)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);let Q;if(Z>0){let[V,X]=$.readVarInt();if(X!==0)return G(X);Q=V}return M({quota:Z,usage:Q})}};var f0={encode($,Z){$.writeBytes(new Uint8Array([Z.status]));let J=$.writeDate(Z.timeRcvd);if(J!==0)return J;let Q=$.writeDate(Z.timeSent);if(Q!==0)return Q;let V=$.writeVarInt(Z.subscription.term);if(V!==0)return V;let X=$.writeVarInt(Z.subscription.elapsed);if(X!==0)return X;let Y=$.writeStruct(n0,Z.subscription.stat);if(Y!==0)return Y;let W=$.writeStruct(n0,Z.subscription.dyn);if(W!==0)return W;return 0},decode($){let[Z,J]=$.readBytes(1);if(J!==0)return G(J);let Q=Z[0],[V,X]=$.readDate();if(X!==0)return G(X);let[Y,W]=$.readDate();if(W!==0)return G(W);let[q,N]=$.readVarInt();if(N!==0)return G(N);let[z,I]=$.readVarInt();if(I!==0)return G(I);let[P,O]=$.readStruct(n0);if(O!==0)return G(O);let[K,F]=$.readStruct(n0);if(F!==0)return G(F);return M({status:Q,timeRcvd:V,timeSent:Y,subscription:{term:q,elapsed:z,stat:P,dyn:K}})}};var v$={encode($,Z){let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let Q=$.writeVarInt(Z.seq);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readVarBytes();if(J!==0)return G(J);let[Q,V]=$.readVarInt();if(V!==0)return G(V);return M({headCph:Z,seq:Q})}};var o={encode($,Z){$.writeBytes(Z.pubKey),$.writeBytes(Z.sig);let J=$.writeDate(Z.timestamp);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(gZ);if(J!==0)return G(J);let[Q,V]=$.readBytes(B0);if(V!==0)return G(V);let[X,Y]=$.readDate();if(Y!==0)return G(Y);return M({pubKey:Z,sig:Q,timestamp:X})}};var pZ={async encodeReq($,Z,J,Q,V){let X=V.writeStruct(o,J);if(X!==0)return X;for(let Y of Q)V.writeVarInt(Y);return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X}=$,[Y,W]=Z.readStruct(o);if(W!==0)return W;let q=await $0(Y,V,Q);if(q!==0)return q;let{pubKey:N}=Y,[z,I]=await X.hasUser(N);if(I!==0)return I;if(!z)return 5;let[P,O]=Z.readVarInt();if(O!==0)return O;if(!Z.done())return 8;let[K,F]=await X.listHeads(N,P);if(F!==0)return F;return J.writeStructs(v$,K)},decodeResp($){return $.readStructs(v$)}};var y$={encode($,Z){$.writeVarInt(Z.seq);let J=$.writeVarBytes(Z.bodyCph);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);let[Q,V]=$.readVarBytes();if(V!==0)return G(V);return M({seq:Z,bodyCph:Q})}};var dZ={async encodeReq($,Z,J,Q,V){let X=V.writeStruct(o,J);if(X!==0)return X;for(let Y of Q){let W=V.writeVarInt(Y);if(W!==0)return W}return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X}=$,[Y,W]=Z.readStruct(o);if(W!==0)return W;let q=await $0(Y,V,Q);if(q!==0)return q;let{pubKey:N}=Y,[z,I]=await X.hasUser(N);if(I!==0)return I;if(!z)return 5;let P=[];while(!Z.done()){let[F,U]=Z.readVarInt();if(U!==0)return U;P.push(F)}console.info(`PULL: ${P.length} bags`);let[O,K]=await X.getBodies(N,P);if(K!==0)return K;if(!O)return 17;for(let{seq:F,bodyCph:U}of O){let T={seq:F,bodyCph:U},D=J.writeStruct(y$,T);if(D!==0)return D}return 0},decodeResp($){return $.readStructs(y$)}};var i$={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;let Q=$.writeVarBytes(Z.bodyCph);if(Q!==0)return Q;return 0},decode($){let[Z,J]=$.readBytes(B0);if(J!==0)return G(J);let[Q,V]=$.readBytes(g0);if(V!==0)return G(V);let[X,Y]=$.readVarBytes();if(Y!==0)return G(Y);let[W,q]=$.readVarBytes();if(q!==0)return G(q);return M({sig:Z,kdm:Q,headCph:X,bodyCph:W})}};var l$={encode($,Z){let J=$.writeVarInt(Z.seq);if(J!==0)return J;let Q=$.writeVarBytes(Z.headCph);if(Q!==0)return Q;let V=Z.bodyCph?Z.bodyCph.length:0,X=$.writeVarInt(V);if(X!==0)return X;if(V>0){if(!Z.bodyCph)return 10;$.writeBytes(Z.bodyCph)}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);let[Q,V]=$.readVarBytes();if(V!==0)return G(V);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);let W;if(X>0){let[q,N]=$.readBytes(X);if(N!==0)return G(N);W=q}return M({seq:Z,headCph:Q,bodyCph:W})}};var v0={encode($,Z){$.writeBytes(Z.sig),$.writeBytes(Z.kdm);let J=$.writeVarBytes(Z.headCph);if(J!==0)return J;return 0},decode($){let[Z,J]=$.readBytes(B0);if(J!==0)return G(J);let[Q,V]=$.readBytes(g0);if(V!==0)return G(V);let[X,Y]=$.readVarBytes();if(Y!==0)return G(Y);return M({sig:Z,kdm:Q,headCph:X})}};var V$={encode($,Z){if($.writeVarInt(Z.idx),$.writeBytes(new Uint8Array([Z.status])),Z.status===0)$.writeVarInt(Z.seq);return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);let[Q,V]=$.readBytes(1);if(V!==0)return G(V);let X=Q[0];if(X!==0)return M({idx:Z,status:X});let[Y,W]=$.readVarInt();if(W!==0)return G(W);return M({idx:Z,status:X,seq:Y})}};var nZ={async encodeReq($,Z,J,Q,V){let X=V.writeStruct(o,J);if(X!==0)return X;let Y=V.writeStructs(i$,Q);if(Y!==0)return Y;return 0},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X,notifier:Y}=$,[W,q]=Z.readStruct(o);if(q!==0)return q;let N=await $0(W,V,Q);if(N!==0)return N;let{pubKey:z}=W,[I,P]=await X.hasUser(z);if(P!==0)return P;if(!I)return 5;let[O,K]=Z.readStructs(i$);if(K!==0)return K;console.info(`PUSH: ${O.length} bags`);let F=[],U=[];for(let w=0;w<O.length;w++){let E=O[w];if(!await lZ(E,z,V)){let h={idx:w,status:3},S=J.writeStruct(V$,h);if(S!==0)return S;continue}F.push(w),U.push(E)}let[T,D]=await X.setBags(z,U);if(D!==0)return D;if(!T||T.length!==U.length)return 17;let j=[];for(let w=0;w<U.length;w++){let E=U[w],B=F[w],h=T[w],S=new L,m=S.writeStruct(v0,E);if(m!==0)return m;let g=S.result(),R={seq:h,headCph:g};if(O.length===1&&E.bodyCph.length<=vZ)R.bodyCph=E.bodyCph;j.push(R);let x={idx:B,status:0,seq:h},_=J.writeStruct(V$,x);if(_!==0)return _}if(j.length>0){let w=new L,E=w.writeStructs(l$,j);if(E!==0)return E;let B=w.result();await Promise.resolve(Y.push(z,B))}return 0},decodeResp($){return $.readStructs(V$)}};var cZ={async encodeReq($,Z,J,Q,V){return V.writeStruct(o,J)},async handleReq($,Z,J){let{clock:Q,crypto:V,storage:X}=$,[Y,W]=Z.readStruct(o);if(W!==0)return W;let q=await $0(Y,V,Q);if(q!==0)return q;let{pubKey:N}=Y;if(!Z.done())return 8;let[z,I]=await X.addUser(N);if(I!==0)return I;return 0},decodeResp($){return M(void 0)}};class b${url;websocket;constructor($){this.url=$}connected(){return this.websocket!==void 0&&this.websocket.readyState===WebSocket.OPEN}async connect($,Z,J=()=>{},Q=()=>{}){let{url:V}=this;if(this.websocket)this.websocket.close(),this.websocket=void 0;let X=new L;X.writeStruct(o,$);let Y=X.result(),W=r(Y);return V.searchParams.set("t",W),this.websocket=new WebSocket(V),this.websocket.binaryType="arraybuffer",this.websocket.onopen=()=>{console.log("CONNECTED"),Q()},this.websocket.onclose=()=>{console.log("DISCONNECTED"),this.websocket=void 0,J()},this.websocket.onmessage=(q)=>{let N=new Uint8Array(q.data);Z(N)},this.websocket.onerror=(q)=>{console.log(`ERROR: ${JSON.stringify(q)}`),this.websocket=void 0,J()},Promise.resolve(0)}disconnect(){this.websocket?.close(),this.websocket=void 0}}var d={user:{path:"/user",endpoint:cZ,name:0},push:{path:"/push",endpoint:nZ,name:2},peek:{path:"/peek",endpoint:pZ,name:1},pull:{path:"/pull",endpoint:dZ,name:3}},fQ={0:d.user,2:d.push,1:d.peek,3:d.pull},rZ={[d.user.path]:d.user,[d.push.path]:d.push,[d.peek.path]:d.peek,[d.pull.path]:d.pull};class oZ{url;listener;constructor($){this.url=$;this.listener=new b$($)}async call($,Z){let{path:J}=fQ[$],Q=new URL(J,this.url);try{return await yQ(Q,Z)}catch{return G(25)}}}var u$=($)=>{return new oZ($.handle)};function y0($){let Z=new L;if(Z.writeStruct(f0,$)!==0)return new Response(null,{status:500});return h$(Z)}function h$($){let Z=$.result().slice();return new Response(Z,{status:200,headers:{"content-type":"application/octet-stream"}})}var vQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,OPTIONS"};function p$($){return new Response($.body,{headers:{...$.headers,...vQ},status:$.status,statusText:$.statusText})}async function yQ($,Z){let J=await fetch($,{method:"POST",body:Z.result().slice()});if(!J.ok)return G(24);let Q=await f.fromResponse(J);return M(Q)}class X${enclave;crypto;host;clock;transport;updateHostMeta;constructor($,Z,J,Q,V,X){this.enclave=$;this.crypto=Z;this.host=J;this.clock=Q;this.transport=V;this.updateHostMeta=X}async call($,Z){let{clock:J,transport:Q}=this,{endpoint:V,name:X}=$,Y=await this.identity(),W=J.now(),[q,N]=await f$(Y,W);if(N!==0)return G(N);let z=new L,I=await V.encodeReq(this,Y,q,Z,z);if(I!==0)return G(I);let P=J.now(),[O,K]=await Q.call(X,z),F=J.now();if(K!==0)return G(K);let[U,T]=O.readStruct(f0);if(T!==0)return G(T);if(U.status!==0)return G(U.status);let j={clockOffset:hZ(P,U.timeRcvd,U.timeSent,F),subscription:U.subscription},w=await this.updateHostMeta(j);if(w!==0)return G(w);return V.decodeResp(O)}identity=()=>{let{host:$,enclave:Z}=this;return Z.deriveIdentity($.label,$.idx??0)};seal=async($)=>{let{crypto:Z,enclave:J}=this,Q=await this.identity();return bZ($,Q,Z,J)};register=()=>this.call(d.user,[]);peek=($)=>this.call(d.peek,[$]);push=($)=>this.call(d.push,$);pull=($)=>this.call(d.pull,$);listen=async($,Z,J)=>{let{clock:Q,transport:V}=this,{listener:X}=V,Y=await this.identity(),W=Q.now(),[q,N]=await f$(Y,W);if(N!==0)return N;return await X.connect(q,$,Z,J)};isConnected(){let $=this.transport?.listener;if($&&typeof $.connected==="function")return $.connected();return!0}closeListener(){this.transport?.listener?.disconnect()}}var wW=Symbol("MasterSeed"),TW=Symbol("SealedMasterKey"),V0=32,aZ=24+V0+16;function t($){if($.byteLength!==V0)return G(10);return M($)}function Y$($){if($.byteLength!==aZ)return G(10);return M($)}var K0={encode($,Z){let J=$.writeVarString(Z.handle);if(J!==0)return J;let Q=$.writeVarString(Z.label);if(Q!==0)return Q;return $.writeVarInt(Z.idx??0)},decode($){let[Z,J]=$.readVarString();if(J!==0)return G(J);let[Q,V]=$.readVarString();if(V!==0)return G(V);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);return M({handle:Z,label:Q,idx:X})}};var G$=1,d$={encode($,Z){if(Z.v!==G$)return 10;let[,J]=t(Z.masterSeed);if(J!==0)return J;let Q=$.writeVarInt(Z.v);if(Q!==0)return Q;$.writeBytes(Z.masterSeed);let V=$.writeVarInt(Z.hosts.length);if(V!==0)return V;for(let X of Z.hosts){let Y=$.writeStruct(K0,X);if(Y!==0)return Y}return 0},decode($){let[Z,J]=$.readVarInt();if(J!==0)return G(J);if(Z!==G$)return G(14);let[Q,V]=$.readBytes(V0);if(V!==0)return G(V);if(Q===void 0)return G(14);let[X,Y]=t(Q);if(Y!==0)return G(Y);if(X===void 0)return G(14);let[W,q]=$.readVarInt();if(q!==0)return G(q);if(W===void 0||W<0)return G(10);let N=[];for(let z=0;z<W;z++){let[I,P]=$.readStruct(K0);if(P!==0)return G(P);if(I===void 0)return G(14);N.push(I)}return M({v:G$,masterSeed:X,hosts:N})}};function sZ($,Z){let[J,Q]=t($);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[V,X]=t(J.slice());if(X!==0)return G(X);if(V===void 0)return G(10);return M({v:G$,masterSeed:V,hosts:Z.map((Y)=>({handle:Y.handle,label:Y.label,idx:Y.idx??0}))})}var n$={encode($,Z){let[,J]=t(Z.masterSeed);if(J!==0)return J;$.writeBytes(Z.masterSeed);let Q=$.writeVarInt(Z.hosts.length);if(Q!==0)return Q;for(let V of Z.hosts){let X=$.writeStruct(K0,V);if(X!==0)return X}return 0},decode($){let[Z,J]=$.readBytes(V0);if(J!==0)return G(J);if(Z===void 0)return G(14);let[Q,V]=t(Z);if(V!==0)return G(V);if(Q===void 0)return G(14);let[X,Y]=$.readVarInt();if(Y!==0)return G(Y);if(X===void 0||X<0)return G(10);let W=[];for(let q=0;q<X;q++){let[N,z]=$.readStruct(K0);if(z!==0)return G(z);if(N===void 0)return G(14);W.push(N)}return M({masterSeed:Q,hosts:W})}};function z0($){let Z=new Uint8Array($);if($>0)crypto.getRandomValues(Z);return Z}var F0=32,iQ=-7,lQ=-8,bQ=-257,W$=[{type:"public-key",alg:iQ},{type:"public-key",alg:lQ},{type:"public-key",alg:bQ}];function uQ($){return $.trim().toLowerCase().replace(/\.$/,"")||"localhost"}function H0($){let Z=new Uint8Array($.byteLength);return Z.set($),Z}function U0($){if($?.rpId!==void 0)return M($.rpId);if(typeof location>"u")return G(9);return M(uQ(location.hostname))}function w0(){if(typeof navigator>"u"||!navigator.credentials||typeof PublicKeyCredential>"u")return 24;return 0}function T0($){if($===null||$.type!=="public-key"||!("rawId"in $)||typeof $.getClientExtensionResults!=="function")return G(27);return M($)}async function tZ($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let V=$?.userName??"diplomatic-seed",X={residentKey:"required",requireResidentKey:!0,userVerification:"required"};if($?.authenticatorAttachment!==void 0)X.authenticatorAttachment=$.authenticatorAttachment;let Y={largeBlob:{support:"required"}},W;try{W=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:V,displayName:V},pubKeyCredParams:W$,authenticatorSelection:X,extensions:Y}})}catch{return G(24)}let[q,N]=T0(W);if(N!==0)return G(N);if(q===void 0)return G(27);if(q.getClientExtensionResults().largeBlob?.supported!==!0)return G(24);return M(new Uint8Array(q.rawId))}async function c$($,Z,J){let Q=w0();if(Q!==0)return Q;let[V,X]=U0(J);if(X!==0)return X;if(V===void 0)return 9;let Y={largeBlob:{write:H0(Z)}},W;try{W=await navigator.credentials.get({publicKey:{challenge:z0(F0),rpId:V,allowCredentials:[{type:"public-key",id:H0($)}],userVerification:"required",extensions:Y}})}catch{return 24}let[q,N]=T0(W);if(N!==0)return N;if(q===void 0)return 27;if(q.getClientExtensionResults().largeBlob?.written!==!0)return 24;return 0}async function eZ($,Z){let J=w0();if(J!==0)return G(J);let[Q,V]=U0(Z);if(V!==0)return G(V);if(Q===void 0)return G(9);let X={largeBlob:{read:!0}},Y;try{let I={challenge:z0(F0),rpId:Q,userVerification:"required",extensions:X};if($!==void 0)I.allowCredentials=[{type:"public-key",id:H0($)}];Y=await navigator.credentials.get({publicKey:I})}catch{return G(24)}let[W,q]=T0(Y);if(q!==0)return G(q);if(W===void 0)return G(27);let z=W.getClientExtensionResults().largeBlob?.blob;if(z===void 0)return G(7);return M({blob:new Uint8Array(z),credId:new Uint8Array(W.rawId)})}var q$=new TextEncoder().encode("diplomatic.prf.v1"),r$=32;async function $J($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let V=$?.userName??"diplomatic-prf",X={residentKey:"required",requireResidentKey:!0,userVerification:"required",authenticatorAttachment:$?.authenticatorAttachment??"platform"},Y;try{Y=await navigator.credentials.create({publicKey:{challenge:z0(F0),rp:{id:J,name:$?.rpName??"DIPLOMATIC"},user:{id:z0(16),name:V,displayName:V},pubKeyCredParams:W$,authenticatorSelection:X,extensions:{prf:{}}}})}catch{return G(24)}let[W,q]=T0(Y);if(q!==0)return G(q);if(W===void 0)return G(27);let N=W.getClientExtensionResults();return M({credId:new Uint8Array(W.rawId),prfEnabled:N.prf?.enabled===!0})}async function c0($){let Z=w0();if(Z!==0)return G(Z);let[J,Q]=U0($);if(Q!==0)return G(Q);if(J===void 0)return G(9);let V=$?.salt??q$,X=H0(V),Y={challenge:z0(F0),rpId:J,userVerification:"required",extensions:{prf:{eval:{first:X}}}};if($?.credId!==void 0)Y.allowCredentials=[{type:"public-key",id:H0($.credId)}];let W;try{W=await navigator.credentials.get({publicKey:Y})}catch{return G(24)}let[q,N]=T0(W);if(N!==0)return G(N);if(q===void 0)return G(27);let z=q.getClientExtensionResults().prf?.results;if(z?.first===void 0)return G(7);let I=z.first,P=I instanceof ArrayBuffer?new Uint8Array(I):new Uint8Array(I.buffer,I.byteOffset,I.byteLength),O=P.byteLength>=r$?P.slice(0,r$):P;if(O.byteLength!==r$)return G(27);return M({prf:O,credId:new Uint8Array(q.rawId)})}var N$="";var z$;function pQ(){if(typeof N$!=="string"||N$.length===0)throw Error("[DIPLOMATIC] worker source not embedded; run pkg build before spawn");return atob(N$)}function dQ(){if(z$!==void 0)return z$;let $=new Blob([pQ()],{type:"text/javascript"});return z$=URL.createObjectURL($),z$}function ZJ(){if(typeof Worker>"u")throw Error("[DIPLOMATIC] Worker API unavailable; cannot spawn sync worker");return new Worker(dQ(),{type:"module"})}var nQ=new TextEncoder().encode("diplomatic.wrap.v1"),cQ=32,rQ=16;class Z0{#Z;#$;constructor($,Z){this.#Z=$,this.#$=Z}static async fromRandom($){let Z=await $.gen256BitSecureRandomSeed(),[J,Q]=t(Z);if(Q!==0||J===void 0)throw Error(`enclave: invalid random seed (${Q})`);return new Z0(J,$)}static fromBytes($,Z){let[J,Q]=t(Z);if(Q!==0)return G(Q);if(J===void 0)return G(10);let[V,X]=t(J.slice());if(X!==0)return G(X);if(V===void 0)return G(10);return M(new Z0(V,$))}async sealWithPasskey($){let Z=$?.salt??q$,J=$?.credId;if(J===void 0&&$?.createCredIfNeeded===!0){let[X,Y]=await $J({rpId:$?.rpId,rpName:$?.rpName,userName:$?.userName??"diplomatic-prf"});if(Y!==0)return G(Y);if(X===void 0)return G(24);if(!X.prfEnabled)return G(24);J=X.credId}let[Q,V]=await c0({rpId:$?.rpId,rpName:$?.rpName,credId:J,salt:Z});if(V!==0)return G(V);if(Q===void 0)return G(7);try{let[X,Y]=await this.#V(Q.prf);if(Y!==0)return G(Y);if(X===void 0)return G(12);return M({sealedMaster:X,salt:Z.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async unsealWithPasskey($,Z,J){let[Q,V]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(V!==0)return G(V);if(Q===void 0)return G(7);try{return await Z0.#X($,Z,Q.prf)}finally{Q.prf.fill(0)}}async persistToLargeBlob($=[],Z){let J=Z?.credId;if(J===void 0){let[X,Y]=await tZ(Z);if(Y!==0)return G(Y);if(X===void 0)return G(24);J=X}let[Q,V]=this.#Y($);if(V!==0)return G(V);if(Q===void 0)return G(12);try{let X=await c$(J,Q,Z);if(X!==0)return G(X);return M(J)}finally{Q.fill(0)}}static async fromLargeBlob($,Z){let[J,Q]=await eZ(Z?.credId,Z);if(Q!==0)return G(Q);if(J===void 0)return G(7);try{return Z0.#G($,J.blob,J.credId)}finally{J.blob.fill(0)}}static async clearLargeBlob($,Z){return c$($,new Uint8Array(V0),Z)}async sealPairPackageBody($,Z){let J=Z?.salt??q$,[Q,V]=await c0({rpId:Z?.rpId,rpName:Z?.rpName,credId:Z?.credId,salt:J});if(V!==0)return G(V);if(Q===void 0)return G(7);try{let[X,Y]=await I$(this.#$,Q.prf);if(Y!==0)return G(Y);if(X===void 0)return G(12);let[W,q]=t(this.#Z.slice());if(q!==0)return G(q);if(W===void 0)return G(10);let N={masterSeed:W,hosts:$.map((K)=>({handle:K.handle,label:K.label,idx:K.idx??0}))},z=new L,I=z.writeStruct(n$,N);if(I!==0)return W.fill(0),G(I);let P=z.result();W.fill(0);let O;try{O=await this.#$.encryptXSalsa20Poly1305Combined(P,X)}catch{return P.fill(0),G(12)}return P.fill(0),M({body:O,salt:J.slice(),credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}static async openPairPackageBody($,Z,J){let[Q,V]=await c0({rpId:J.rpId,rpName:J.rpName,credId:J.credId,salt:J.salt});if(V!==0)return G(V);if(Q===void 0)return G(7);try{let[X,Y]=await I$($,Q.prf);if(Y!==0)return G(Y);if(X===void 0)return G(12);let W;try{W=await $.decryptXSalsa20Poly1305Combined(Z,X)}catch{return G(20)}let q=new f(W),[N,z]=q.readStruct(n$);if(W.fill(0),z!==0)return G(z);if(N===void 0)return G(14);let[I,P]=Z0.fromBytes($,N.masterSeed);if(N.masterSeed.fill(0),P!==0)return G(P);if(I===void 0)return G(12);let[O,K]=await I.#V(Q.prf);if(K!==0)return G(K);if(O===void 0)return G(12);return M({enclave:I,hosts:N.hosts.map((F)=>({...F})),sealedMaster:O,credId:Q.credId.slice()})}finally{Q.prf.fill(0)}}spawnSyncWorker($){let Z=ZJ(),J=this.#Z.slice();return Z.postMessage({id:$.id,op:"setSeed",seed:J,persist:$.persist},[J.buffer]),Z}deriveCipher($,Z){let J=$.slice(),Q=(Y)=>this.#W(J,Y),V=(Y)=>this.#q(J,Y);return{encrypt:Object.freeze({encrypt:Q}),decrypt:Object.freeze({decrypt:V}),both:Object.freeze({encrypt:Q,decrypt:V})}[Z]}async deriveIdentity($,Z=0){let J=$,Q=Z,V=await this.#Q(J,Q);return Object.freeze({publicKey:V.publicKey,sign:(X)=>this.#z(J,Q,X),kdmFor:(X)=>this.#I(J,Q,X)})}async#V($){let[Z,J]=await I$(this.#$,$);if(J!==0)return G(J);if(Z===void 0)return G(12);try{let Q=await this.#$.encryptXSalsa20Poly1305Combined(this.#Z,Z);return Y$(Q)}catch{return G(12)}}static async#X($,Z,J){let[,Q]=Y$(Z);if(Q!==0)return G(Q);let[V,X]=await I$($,J);if(X!==0)return G(X);if(V===void 0)return G(12);try{let Y=await $.decryptXSalsa20Poly1305Combined(Z,V);return Z0.fromBytes($,Y)}catch{return G(20)}}#Y($){let[Z,J]=t(this.#Z.slice());if(J!==0)return G(J);if(Z===void 0)return G(10);let[Q,V]=sZ(Z,$);if(V!==0)return Z.fill(0),G(V);if(Q===void 0)return Z.fill(0),G(12);Z.fill(0);let X=new L,Y=X.writeStruct(d$,Q);if(Q.masterSeed.fill(0),Y!==0)return G(Y);return M(X.result())}static#G($,Z,J){if(Z.byteLength===0||Z.every((q)=>q===0))return G(22);if(Z.byteLength===V0){let[q,N]=Z0.fromBytes($,Z);if(N!==0)return G(N);if(q===void 0)return G(12);return M({enclave:q,hosts:[],credId:J})}let Q=new f(Z),[V,X]=Q.readStruct(d$);if(X!==0)return G(X);if(V===void 0)return G(14);let[Y,W]=Z0.fromBytes($,V.masterSeed);if(V.masterSeed.fill(0),W!==0)return G(W);if(Y===void 0)return G(12);return M({enclave:Y,hosts:V.hosts.map((q)=>({...q})),credId:J})}async#W($,Z){let J=await this.#J($);return this.#$.encryptXSalsa20Poly1305Combined(Z,J)}async#q($,Z){let J=await this.#J($);return this.#$.decryptXSalsa20Poly1305Combined(Z,J)}async#J($){return this.#$.blake3(p0(this.#Z,$))}async#N($,Z){let J=new TextEncoder().encode($),Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,BigInt(Z),!1),await this.#J(p0(J,Q))}async#Q($,Z){let J=await this.#N($,Z);return this.#$.deriveEd25519KeyPair(J)}async#z($,Z,J){let Q=await this.#Q($,Z);return this.#$.signEd25519(J,Q.privateKey)}async#I($,Z,J){let Q=await this.#Q($,Z),V=p0(Q.privateKey,J);return(await this.#$.blake3(V)).slice(0,g0)}}async function I$($,Z){if(Z.byteLength<rQ)return G(10);let J=await $.blake3(p0(Z,nQ));return M(J.slice(0,cQ))}class o${listeners=new Map;addEventListener($,Z){let J=this.listeners.get($);if(!J)J=new Set,this.listeners.set($,J);return J.add(Z),()=>{this.removeEventListener($,Z)}}removeEventListener($,Z){let J=this.listeners.get($);if(J){if(J.delete(Z),J.size===0)this.listeners.delete($)}}emit($,Z){let J=this.listeners.get($);if(J){let Q=Array.from(J);for(let V of Q)V(Z)}}emitAll($){let Z=Array.from(this.listeners.keys());for(let J of Z)this.emit(J,$)}}async function JJ($,Z,J,Q=0){let V=Z.now(),X=new L,Y=X.writeVarString($);if(Y!==0)return G(Y);let q={id:X.result(),ts:new Date(0)},[N,z]=iZ(q);if(z!==0)return G(z);let I=V.getTime()-q.ts.getTime();return M({eid:N,off:I,ctr:Q,len:J.length,bod:J})}class oQ{singletonType;latest;latestOff=-1;emitter=new o$;constructor($){this.singletonType=$}async apply($){for(let Z of $){let J=new f(Z.eid),[Q,V]=J.readStruct(d0);if(V!==0)continue;let X=new L;X.writeVarString(this.singletonType);let Y=X.result();if(Q.id.length===Y.length&&Q.id.every((W,q)=>W===Y[q])){if(this.latest===void 0||Z.off>this.latestOff)this.latestOff=Z.off,this.latest=Z.bod,this.emitter.emit(this.singletonType,null)}}return $.map(()=>0)}clear=async()=>{return this.latest=void 0,this.latestOff=-1,this.emitter.emit(this.singletonType,null),0};notify=($)=>{for(let Z of $)if(Z===this.singletonType)this.emitter.emit(this.singletonType,null)};refresh=async($)=>{this.notify([this.singletonType])};on=($,Z)=>{this.emitter.addEventListener($,Z)};off=($,Z)=>{this.emitter.removeEventListener($,Z)}}async function QJ($,Z,J,Q){let V=new f($.headCph),[X,Y]=V.readStruct(v0);if(Y!==0)return G(Y);let{sig:W,kdm:q,headCph:N}=X;if(!await Q.checkSigEd25519(W,N,Z))return G(3);let I=J.deriveCipher(q,"decrypt"),P;try{P=await I.decrypt(N)}catch{return G(20)}return M({kdm:q,headEnc:P})}var l0=KQ(VQ(),1),PX={encode:l0.encode,decode:l0.decode,decodeAsync:l0.decodeAsync},RX=PX;import{Database as OX}from"bun:sqlite";var Yq=Symbol("EntityID");var Gq=Symbol("DerivationSeed"),Wq=Symbol("PublicKey"),qq=Symbol("PrivateKey"),Nq=Symbol("HostSpecificKeyPair"),zq=Symbol("Hash"),M0={term:0,elapsed:0,stat:{quota:0},dyn:{quota:0}};function KX($="diplomatic.db"){let Z=new OX($);return Z.exec("PRAGMA journal_mode=WAL;"),Z.exec("PRAGMA synchronous=NORMAL;"),Z.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  pubKey TEXT PRIMARY KEY
4
4
  );
@@ -11,4 +11,4 @@ var vJ=Object.create;var{getPrototypeOf:lJ,defineProperty:p$,getOwnPropertyNames
11
11
  PRIMARY KEY (userPubKey, seq),
12
12
  UNIQUE (userPubKey, seq)
13
13
  );
14
- `),{async addUser(J){try{let Q=h(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),F(void 0)}catch{return I(17)}},async hasUser(J){try{let Q=h(J),V=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return F(Boolean(V?.ok))}catch{return I(17)}},async subMeta(J){return F(N0)},async setBags(J,Q){if(Q.length<1)return F([]);try{let V=h(J);Z.exec("BEGIN IMMEDIATE");try{let W=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(V),X=W?W.m||0:0,Y=[],G=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){X+=1;let q=new L;q.writeStruct(E0,N),G.run(V,X,q.result(),N.bodyCph),Y.push(X)}return Z.exec("COMMIT"),F(Y)}catch(W){try{Z.exec("ROLLBACK")}catch{}throw W}}catch{return I(17)}},async getBodies(J,Q){if(Q.length<1)return F([]);try{let V=h(J),W=[],X=100,Y=99;for(let G=0;G<Q.length;G+=99){let N=Q.slice(G,G+99),q=N.map(()=>"?").join(","),P=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${q})`).all(V,...N);for(let R of P)if(R.bodyCph)W.push({seq:R.seq,bodyCph:new Uint8Array(R.bodyCph)})}return F(W)}catch{return I(17)}},async listHeads(J,Q){try{let V=h(J),W=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(V,Q);return F(W.map((X)=>({seq:X.seq,headCph:new Uint8Array(X.headCph)})))}catch{return I(17)}}}}var xV=gV(),mJ=xV;class b${storage;crypto;notifier;clock;constructor($,Z,J,Q){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=Q}corsHandler=async($)=>{if($.method==="OPTIONS")return S$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),S$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=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),Y=Q.pathname,G=EZ[Y]?.endpoint;if(!G){let N=Z.now();return L0({status:13,timeRcvd:J,timeSent:N,subscription:N0})}try{let N=new L,q=await G.handleReq(this,X,N),P=N0,R={status:q,timeRcvd:J,timeSent:this.clock.now(),subscription:P},z=new L;if(z.writeStruct(S0,R)!==0)return new Response(null,{status:500});if(q!==0){let O=Z.now();return L0({status:q,timeRcvd:J,timeSent:O,subscription:N0})}return N.prependBytes(z.result()),D$(N)}catch(N){let q=Z.now();return console.error(N),console.trace(),L0({status:12,timeRcvd:J,timeSent:q,subscription:N0})}}}async function BJ($,Z){let Q=new URL($.url).searchParams.get(OZ);if(!Q)return I(11);let V=d0(Q),W=new c(V),[X,Y]=W.readStruct(o);if(Y!==0)return I(11);let G=await e(X,Z.crypto,Z.clock);if(G!==0)return I(G);return F(X)}class xJ{recvs=new Map;async open($,Z,J,Q){let V=await e($,J,Q);if(V!==0)return{send:()=>V,shut:()=>V,status:V};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($),Q=this.recvs.get(J);if(Q)for(let V of Q)V(Z)}}var gJ=new xJ;async function fV($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new b$(mJ,P0,gJ,new D0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,Q)=>{if(J.headers.get("upgrade")==="websocket"){let[V,W]=await BJ(J,Z);if(W!==0)return new Response("Unauthorized",{status:401});return Q.upgrade(J,{data:{authTS:V}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let Q=J.data.authTS;gJ.open(Q,(V)=>J.send(V),Z.crypto,Z.clock).then((V)=>{if(V.status!==0){J.close();return}J.channel=V})},message:(J,Q)=>{},close:(J)=>{J.channel?.shut()}}})}class fJ{enclave;conn;clock;constructor({seed:$,clock:Z=new D0}){this.enclave=new E$($,P0),this.clock=Z}async connect($,Z){let J=new D0,Q=()=>Promise.resolve(0);this.conn=new c0(this.enclave,P0,$,J,Z,Q);let[,V]=await this.conn.register();return V}async push($){if(!this.conn)return I(28);let Z=[];for(let V of $){let[W,X]=await this.conn.seal(V);if(X!==0)return I(X);Z.push(W)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return I(Q);return F(J)}async peek($){if(!this.conn)return I(28);return this.conn.peek($)}async pull($){if(!this.conn)return I(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return I(28);let J=await this.conn.identity(),[Q,V]=await kZ($,J.publicKey,this.enclave,P0);if(V!==0)return I(V);let W=this.enclave.deriveCipher(Q.kdm,"decrypt");return HZ(Q.headEnc,Z.bodyCph,W,P0)}async upsertSingletonSync($,Z){let[J,Q]=await jZ($,this.clock,Z);if(Q!==0)return Q;let[,V]=await this.push([J]);return V}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function vV({seed:$,host:Z,transport:J}){let Q=new fJ({seed:$}),V=await Q.connect(Z,J);return[Q,V]}async function kN({seed:$,host:Z,transport:J}){let Q=J??C$(Z),[V,W]=await vV({seed:$,host:Z,transport:Q});if(W!==0)console.error(`Failed to initialize CLI: ${S[W]}`),process.exit(1);return V}function _N($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=d0(Z);if(J.length!==32)console.error(`${$} must be 64 hex chars (32 bytes)`),process.exit(1);return J}function mN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{fV as runBunHost,T$ as notifItemCodec,mV as msgpack,_N as loadSeedOrPanic,mN as loadHostOrPanic,kN as initCLIOrPanic,vV as initCLI,C$ as hostHTTPTransport,S as Status,c as Decoder,fJ as CLIClient};
14
+ `),{async addUser(J){try{let Q=r(J);return Z.exec("INSERT INTO users (pubKey) VALUES (?) ON CONFLICT DO NOTHING",[Q]),M(void 0)}catch{return G(17)}},async hasUser(J){try{let Q=r(J),V=Z.prepare("SELECT EXISTS (SELECT 1 FROM users WHERE pubKey = ?) AS ok").get(Q);return M(Boolean(V?.ok))}catch{return G(17)}},async subMeta(J){return M(M0)},async setBags(J,Q){if(Q.length<1)return M([]);try{let V=r(J);Z.exec("BEGIN IMMEDIATE");try{let X=Z.prepare("SELECT MAX(seq) AS m FROM bags WHERE userPubKey = ?").get(V),Y=X?X.m||0:0,W=[],q=Z.prepare("INSERT INTO bags (userPubKey, seq, headCph, bodyCph) VALUES (?, ?, ?, ?)");for(let N of Q){Y+=1;let z=new L;z.writeStruct(v0,N),q.run(V,Y,z.result(),N.bodyCph),W.push(Y)}return Z.exec("COMMIT"),M(W)}catch(X){try{Z.exec("ROLLBACK")}catch{}throw X}}catch{return G(17)}},async getBodies(J,Q){if(Q.length<1)return M([]);try{let V=r(J),X=[],Y=100,W=99;for(let q=0;q<Q.length;q+=99){let N=Q.slice(q,q+99),z=N.map(()=>"?").join(","),I=Z.prepare(`SELECT seq, bodyCph FROM bags WHERE userPubKey = ? AND seq IN (${z})`).all(V,...N);for(let P of I)if(P.bodyCph)X.push({seq:P.seq,bodyCph:new Uint8Array(P.bodyCph)})}return M(X)}catch{return G(17)}},async listHeads(J,Q){try{let V=r(J),X=Z.prepare("SELECT seq, headCph FROM bags WHERE userPubKey = ? AND seq > ? ORDER BY seq").all(V,Q);return M(X.map((Y)=>({seq:Y.seq,headCph:new Uint8Array(Y.headCph)})))}catch{return G(17)}}}}var FX=KX(),XQ=FX;class qZ{storage;crypto;notifier;clock;constructor($,Z,J,Q){this.storage=$;this.crypto=Z;this.notifier=J;this.clock=Q}corsHandler=async($)=>{if($.method==="OPTIONS")return p$(new Response(null));let Z=`${$.method} ${$.url}`;console.time(Z);let J=await this.handler($);return console.timeEnd(Z),p$(J)};handler=async($)=>{let{clock:Z}=this,J=Z.now(),Q=new URL($.url);if($.method!=="POST"){let N=Z.now();return y0({status:13,timeRcvd:J,timeSent:N,subscription:M0})}if(!$.body){let N=Z.now();return y0({status:7,timeRcvd:J,timeSent:N,subscription:M0})}let X=new Uint8Array(await $.arrayBuffer()),Y=new f(X),W=Q.pathname,q=rZ[W]?.endpoint;if(!q){let N=Z.now();return y0({status:13,timeRcvd:J,timeSent:N,subscription:M0})}try{let N=new L,z=await q.handleReq(this,Y,N),I=M0,P={status:z,timeRcvd:J,timeSent:this.clock.now(),subscription:I},O=new L;if(O.writeStruct(f0,P)!==0)return new Response(null,{status:500});if(z!==0){let F=Z.now();return y0({status:z,timeRcvd:J,timeSent:F,subscription:M0})}return N.prependBytes(O.result()),h$(N)}catch(N){let z=Z.now();return console.error(N),console.trace(),y0({status:12,timeRcvd:J,timeSent:z,subscription:M0})}}}async function YQ($,Z){let Q=new URL($.url).searchParams.get(yZ);if(!Q)return G(11);let V=Q$(Q),X=new f(V),[Y,W]=X.readStruct(o);if(W!==0)return G(11);let q=await $0(Y,Z.crypto,Z.clock);if(q!==0)return G(q);return M(Y)}class WQ{recvs=new Map;async open($,Z,J,Q){let V=await $0($,J,Q);if(V!==0)return{send:()=>V,shut:()=>V,status:V};let X=r($.pubKey);if(!this.recvs.has(X))this.recvs.set(X,new Set);return this.recvs.get(X)?.add(Z),{send:(Y)=>{return Z(Y),0},shut:()=>{return this.recvs.get(X)?.delete(Z),0},status:0}}async push($,Z){let J=r($),Q=this.recvs.get(J);if(Q)for(let V of Q)V(Z)}}var GQ=new WQ;async function HX($=Number.parseInt(process.env.DIPLOMATIC_HOST_PORT||"31337")){let Z=new qZ(XQ,O0,GQ,new x0);console.log(`DIPLOMATIC PARCEL SERVICE ACTIVE on http://localhost:${$}`),Bun.serve({port:$,fetch:async(J,Q)=>{if(J.headers.get("upgrade")==="websocket"){let[V,X]=await YQ(J,Z);if(X!==0)return new Response("Unauthorized",{status:401});return Q.upgrade(J,{data:{authTS:V}})?void 0:new Response("Upgrade failed",{status:400})}return Z.corsHandler(J)},websocket:{data:{},open:(J)=>{let Q=J.data.authTS;GQ.open(Q,(V)=>J.send(V),Z.crypto,Z.clock).then((V)=>{if(V.status!==0){J.close();return}J.channel=V})},message:(J,Q)=>{},close:(J)=>{J.channel?.shut()}}})}class qQ{enclave;conn;clock;constructor({enclave:$,clock:Z=new x0}){this.enclave=$,this.clock=Z}async connect($,Z){let J=new x0,Q=()=>Promise.resolve(0);this.conn=new X$(this.enclave,O0,$,J,Z,Q);let[,V]=await this.conn.register();return V}async push($){if(!this.conn)return G(28);let Z=[];for(let V of $){let[X,Y]=await this.conn.seal(V);if(Y!==0)return G(Y);Z.push(X)}let[J,Q]=await this.conn.push(Z);if(Q!==0)return G(Q);return M(J)}async peek($){if(!this.conn)return G(28);return this.conn.peek($)}async pull($){if(!this.conn)return G(28);return this.conn.pull($)}async open($,Z){if(!this.conn)return G(28);let J=await this.conn.identity(),[Q,V]=await QJ($,J.publicKey,this.enclave,O0);if(V!==0)return G(V);let X=this.enclave.deriveCipher(Q.kdm,"decrypt");return uZ(Q.headEnc,Z.bodyCph,X,O0)}async upsertSingletonSync($,Z){let[J,Q]=await JJ($,this.clock,Z);if(Q!==0)return Q;let[,V]=await this.push([J]);return V}async listen($,Z,J){if(!this.conn)return 28;return this.conn.listen($,Z,J)}isConnected(){return this.conn?.isConnected()??!1}}async function UX({enclave:$,host:Z,transport:J}){let Q=new qQ({enclave:$}),V=await Q.connect(Z,J);return[Q,V]}async function QN({enclave:$,host:Z,transport:J}){let Q=J??u$(Z),[V,X]=await UX({enclave:$,host:Z,transport:Q});if(X!==0)console.error(`Failed to initialize CLI: ${A[X]}`),process.exit(1);return V}function VN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);let J=Q$(Z),[Q,V]=Z0.fromBytes(O0,J);if(J.fill(0),V!==0||Q===void 0)console.error(`${$} must be 64 hex chars (32-byte master seed)`),process.exit(1);return Q}function XN($){let Z=process.env[$];if(!Z)console.error(`${$} env var missing`),process.exit(1);return{handle:new URL(Z),label:"host"}}export{HX as runBunHost,l$ as notifItemCodec,RX as msgpack,XN as loadHostOrPanic,VN as loadEnclaveOrPanic,QN as initCLIOrPanic,UX as initCLI,u$ as hostHTTPTransport,A as Status,f as Decoder,qQ as CLIClient};
@@ -3,6 +3,10 @@ export declare function htob(hex: string): Uint8Array;
3
3
  export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
4
4
  export declare let btob64: (bytes: Uint8Array) => string;
5
5
  export declare let b64tob: (b64: string) => Uint8Array;
6
+ /** Bytes → base64url (no padding). For string transport (pair packages, QR payloads). */
7
+ export declare function btob64url(bytes: Uint8Array): string;
8
+ /** Base64url (padding optional) → bytes. */
9
+ export declare function b64urltob(b64url: string): Uint8Array;
6
10
  export declare function concat(a: Uint8Array, b: Uint8Array): Uint8Array;
7
11
  export declare function btob128(bytes: Uint8Array): string;
8
12
  export declare function b128tob(str: string): Uint8Array;
@@ -0,0 +1,11 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import type { IHostConnectionInfo } from "../types.ts";
3
+ /**
4
+ * Wire form of {@link IHostConnectionInfo}: same fields, handle as string URL
5
+ * (live clients use `URL | IProtoHost`).
6
+ */
7
+ export type BundleHost = Omit<IHostConnectionInfo<URL>, "handle"> & {
8
+ handle: string;
9
+ };
10
+ /** handle (varstring), label (varstring), idx (varint; default 0). */
11
+ export declare const bundleHostCodec: ICodecStruct<BundleHost>;
@@ -0,0 +1,25 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import { type MasterSeed } from "../seed.ts";
3
+ import { type ValStat } from "../valstat.ts";
4
+ import { type BundleHost } from "./bundleHost.ts";
5
+ export { type BundleHost, bundleHostCodec } from "./bundleHost.ts";
6
+ export declare const IDENTITY_BUNDLE_VERSION = 1;
7
+ export type IdentityBundle = {
8
+ v: number;
9
+ masterSeed: MasterSeed;
10
+ hosts: BundleHost[];
11
+ };
12
+ /**
13
+ * IdentityBundle wire layout:
14
+ * v: varint
15
+ * masterSeed: 32 fixed bytes
16
+ * hostsLen: varint
17
+ * hosts: hostsLen × BundleHost
18
+ */
19
+ export declare const identityBundleCodec: ICodecStruct<IdentityBundle>;
20
+ /**
21
+ * Build a wire-format identity bundle from a branded {@link MasterSeed} + hosts.
22
+ * Codec/tests only. Runtime seed I/O must go through Enclave.persistToLargeBlob
23
+ * — never encode then hand seed-bearing bytes to outer layers.
24
+ */
25
+ export declare function createIdentityBundle(masterSeed: MasterSeed, hosts: BundleHost[]): ValStat<IdentityBundle>;
@@ -0,0 +1,15 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import { type MasterSeed } from "../seed.ts";
3
+ import { type BundleHost } from "./bundleHost.ts";
4
+ export type PairPackagePlain = {
5
+ masterSeed: MasterSeed;
6
+ hosts: BundleHost[];
7
+ };
8
+ /**
9
+ * Inner plaintext body (not sealed here — AEAD is applied by the pairing
10
+ * ceremony, then carried as `body` in {@link pairPackageEnvelopeCodec}):
11
+ * masterSeed: 32 fixed bytes
12
+ * hostsLen: varint
13
+ * hosts: hostsLen × BundleHost
14
+ */
15
+ export declare const pairPackagePlainCodec: ICodecStruct<PairPackagePlain>;
@@ -1,4 +1,26 @@
1
- import type { ICrypto, MasterSeed, PublicKey } from "../types.ts";
1
+ import type { BundleHost } from "../codecs/bundleHost.ts";
2
+ import { Status } from "../consts.ts";
3
+ import { MASTER_SEED_LEN, type SealedMasterKey } from "../seed.ts";
4
+ import type { ICrypto, PublicKey } from "../types.ts";
5
+ import { type ValStat } from "../valstat.ts";
6
+ import { type LargeBlobCreateOpts, type LargeBlobRp } from "../webauthn/largeBlob.ts";
7
+ import { type PrfCreateOpts, type PrfEvalOpts, type PrfRp } from "../webauthn/prf.ts";
8
+ export type { LargeBlobCreateOpts, LargeBlobRp };
9
+ export type { PrfCreateOpts, PrfEvalOpts, PrfRp };
10
+ /** Options for PRF seal/unseal ceremonies (no raw PRF bytes). */
11
+ export type PasskeyPrfOpts = PrfRp & {
12
+ salt?: Uint8Array;
13
+ credId?: Uint8Array;
14
+ /** Seal only: create a PRF credential first when no credId is known. */
15
+ createCredIfNeeded?: boolean;
16
+ userName?: string;
17
+ };
18
+ /** Durable PRF-sealed master + public meta (never includes PRF output). */
19
+ export type PrfSealedMaster = {
20
+ sealedMaster: SealedMasterKey;
21
+ salt: Uint8Array;
22
+ credId: Uint8Array;
23
+ };
2
24
  export type EncryptCipher = {
3
25
  encrypt: (data: Uint8Array) => Promise<Uint8Array>;
4
26
  };
@@ -25,9 +47,95 @@ export type Identity = {
25
47
  /** Per-bag KDM mixed with this identity's private key (see bag seal). */
26
48
  kdmFor: (msgHeadEnc: Uint8Array) => Promise<Uint8Array>;
27
49
  };
50
+ declare const SEAL_KEY_LEN = 32;
51
+ declare const SEAL_PRF_MIN_LEN = 16;
28
52
  export declare class Enclave {
29
53
  #private;
30
- constructor(seed: MasterSeed, crypto: ICrypto);
54
+ private constructor();
55
+ /** New enclave with a fresh 32-byte master seed. */
56
+ static fromRandom(crypto: ICrypto): Promise<Enclave>;
57
+ /**
58
+ * Construct from raw master seed bytes (import / bootstrap only).
59
+ * Copies the seed so callers may zero their buffer after success.
60
+ * Prefer {@link fromRandom} or {@link unsealWithPasskey} for normal flows.
61
+ */
62
+ static fromBytes(crypto: ICrypto, bytes: Uint8Array): ValStat<Enclave>;
63
+ /**
64
+ * UV + PRF ceremony, then AEAD-seal master. Returns sealed ciphertext + public
65
+ * meta only — never PRF output. Sealed blob on disk is useless without a
66
+ * ceremony Enclave itself runs on unlock.
67
+ *
68
+ * Future: sealWithPassphrase when PRF is unavailable (same sealed layout).
69
+ */
70
+ sealWithPasskey(opts?: PasskeyPrfOpts): Promise<ValStat<PrfSealedMaster>>;
71
+ /**
72
+ * UV + PRF ceremony, then unseal durable master into a new Enclave.
73
+ * Callers never supply PRF bytes — only sealed meta + RP/salt/credId.
74
+ */
75
+ static unsealWithPasskey(crypto: ICrypto, sealedMaster: SealedMasterKey, opts: PasskeyPrfOpts & {
76
+ salt: Uint8Array;
77
+ }): Promise<ValStat<Enclave>>;
78
+ /**
79
+ * UV + write IdentityBundle (seed + hosts) to largeBlob.
80
+ * Encode and WebAuthn write complete inside this method; nothing seed-bearing
81
+ * is returned. Prefer empty `hosts` for seed-only backup.
82
+ *
83
+ * Pass `opts.credId` to write an existing credential (one UV). Omit it to
84
+ * create a largeBlob-capable credential then write (two UV). Returns the
85
+ * credential id used.
86
+ */
87
+ persistToLargeBlob(hosts?: BundleHost[], opts?: LargeBlobCreateOpts & {
88
+ credId?: Uint8Array;
89
+ }): Promise<ValStat<Uint8Array>>;
90
+ /**
91
+ * UV + read largeBlob payload into a new Enclave (+ hosts if IdentityBundle).
92
+ * Seed material never leaves this factory.
93
+ *
94
+ * Pass `opts.credId` for a known credential; omit for discoverable assertion.
95
+ * Returns the credential id used (useful after discover).
96
+ */
97
+ static fromLargeBlob(crypto: ICrypto, opts?: LargeBlobRp & {
98
+ credId?: Uint8Array;
99
+ }): Promise<ValStat<{
100
+ enclave: Enclave;
101
+ hosts: BundleHost[];
102
+ credId: Uint8Array;
103
+ }>>;
104
+ /** UV + overwrite largeBlob with zeros (destroys stored seed material). */
105
+ static clearLargeBlob(credId: Uint8Array, opts?: LargeBlobRp): Promise<Status>;
106
+ /**
107
+ * UV + PRF, then AEAD-seal pair-package plaintext (seed + hosts).
108
+ * Returns ciphertext body + public ceremony meta (no PRF).
109
+ */
110
+ sealPairPackageBody(hosts: BundleHost[], opts?: PasskeyPrfOpts): Promise<ValStat<{
111
+ body: Uint8Array;
112
+ salt: Uint8Array;
113
+ credId: Uint8Array;
114
+ }>>;
115
+ /**
116
+ * UV + PRF (using envelope salt/credId), decrypt pair body, build Enclave.
117
+ * Also seals master under the same PRF for durable IDB (single ceremony).
118
+ */
119
+ static openPairPackageBody(crypto: ICrypto, body: Uint8Array, opts: PasskeyPrfOpts & {
120
+ salt: Uint8Array;
121
+ }): Promise<ValStat<{
122
+ enclave: Enclave;
123
+ hosts: BundleHost[];
124
+ sealedMaster: SealedMasterKey;
125
+ credId: Uint8Array;
126
+ }>>;
127
+ /**
128
+ * Spawn a new sync Worker from the embedded bundle and inject this enclave's
129
+ * master seed into it (transfer). Seed never goes to a caller-supplied port —
130
+ * only to a worker this method just created.
131
+ *
132
+ * Returns the Worker. Caller (WorkerClient) should adopt it and await the
133
+ * `setSeed` reply for `opts.id`.
134
+ */
135
+ spawnSyncWorker(opts: {
136
+ id: number;
137
+ persist?: boolean;
138
+ }): Worker;
31
139
  /**
32
140
  * Cipher for public KDM. Does not hold key bytes; each op re-enters the
33
141
  * enclave (async, hardware-shaped). `usage` selects the return shape:
@@ -40,3 +148,6 @@ export declare class Enclave {
40
148
  */
41
149
  deriveIdentity(keyPath: string, idx?: number): Promise<Identity>;
42
150
  }
151
+ /** Derive seal key from PRF output (domain-separated). Used by enclave seal/unseal. */
152
+ export declare function sealKeyFromPrf(crypto: ICrypto, prf: Uint8Array): Promise<ValStat<Uint8Array>>;
153
+ export { MASTER_SEED_LEN, SEAL_KEY_LEN, SEAL_PRF_MIN_LEN };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Fill and return `n` cryptographically secure random bytes.
3
+ */
4
+ export declare function randomBytes(n: number): Uint8Array;
5
+ /**
6
+ * Same as {@link randomBytes}, typed as `Uint8Array<ArrayBuffer>` for DOM
7
+ * `BufferSource` APIs (e.g. WebAuthn challenges and user ids).
8
+ */
9
+ export declare function randomBytesArrayBuffer(n: number): Uint8Array<ArrayBuffer>;
10
+ /** 32 cryptographically secure random bytes (e.g. master seed material). */
11
+ export declare function random256BitSeed(): Uint8Array;