hfs 3.1.0 → 3.1.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.
@@ -1 +1 @@
1
- import{a as Y,g as Z}from"./index-BXz3BvVz.js";function Q(e,r){for(var l=0;l<r.length;l++){const d=r[l];if(typeof d!="string"&&!Array.isArray(d)){for(const n in d)if(n!=="default"&&!(n in e)){const t=Object.getOwnPropertyDescriptor(d,n);t&&Object.defineProperty(e,n,t.get?t:{enumerable:!0,get:()=>d[n]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var M={},E={},C={};const x={},$=Object.freeze(Object.defineProperty({__proto__:null,default:x},Symbol.toStringTag,{value:"Module"})),V=Y($);var G;function X(){if(G)return C;G=1,Object.defineProperty(C,"__esModule",{value:!0}),C.crossEnvCrypto=void 0;try{const e=typeof window!="undefined"&&window.crypto||V.webcrypto;if(e){if(!e.subtle)throw new Error("Crypto.Subtle is undefined. Make sure you are using HTTPS in a compatible browser.");const r=l=>d=>e.subtle.digest(l,d);C.crossEnvCrypto={randomBytes:e.getRandomValues.bind(e),hashFunctions:{SHA1:r("SHA-1"),SHA256:r("SHA-256"),SHA384:r("SHA-384"),SHA512:r("SHA-512")}}}else{const r=V,l=d=>n=>r.createHash(d).update(n).digest().buffer;C.crossEnvCrypto={randomBytes:r.randomFillSync,hashFunctions:{SHA1:l("sha1"),SHA256:l("sha256"),SHA384:l("sha384"),SHA512:l("sha512")}}}}catch(e){throw console.error(e),new Error("No suitable crypto library was found. You may need a polyfill.")}return C}var U;function ee(){if(U)return E;U=1,Object.defineProperty(E,"__esModule",{value:!0}),E.SRPParameters=void 0;const e=X();class r{constructor(d=r.PrimeGroup[2048],n=r.H.SHA512){if(this.primeGroup=d,this.H=n,this.NBits=this.primeGroup.N.toString(2).length,!n)throw new Error("Hash function required")}}return E.SRPParameters=r,r.PrimeGroup={256:{N:BigInt("125617018995153554710546479714086468244499594888726646874671447258204721048803"),g:BigInt(2)},512:{N:BigInt("11144252439149533417835749556168991736939157778924947037200268358613863350040339017097790259154750906072491181606044774215413467851989724116331597513345603"),g:BigInt(2)},768:{N:BigInt("1087179135105457859072065649059069760280540086975817629066444682366896187793570736574549981488868217843627094867924800342887096064844227836735667168319981288765377499806385489913341488724152562880918438701129530606139552645689583147"),g:BigInt(2)},1024:{N:BigInt("167609434410335061345139523764350090260135525329813904557420930309800865859473551531551523800013916573891864789934747039010546328480848979516637673776605610374669426214776197828492691384519453218253702788022233205683635831626913357154941914129985489522629902540768368409482248290641036967659389658897350067939"),g:BigInt(2)},1536:{N:BigInt("1486998185923128292816507353619409521152457662596380074614818966810244974827752411420380336514078832314731499938313197533147998565301020797040787428051479639316928015998415709101293902971072960487527411068082311763171549170528008620813391411445907584912865222076100726050255271567749213905330659264908657221124284665444825474741087704974475795505492821585749417639344967192301749033325359286273431675492866492416941152646940908101472416714421046022696100064262587"),g:BigInt(2)},2048:{N:BigInt("21766174458617435773191008891802753781907668374255538511144643224689886235383840957210909013086056401571399717235807266581649606472148410291413364152197364477180887395655483738115072677402235101762521901569820740293149529620419333266262073471054548368736039519702486226506248861060256971802984953561121442680157668000761429988222457090413873973970171927093992114751765168063614761119615476233422096442783117971236371647333871414335895773474667308967050807005509320424799678417036867928316761272274230314067548291133582479583061439577559347101961771406173684378522703483495337037655006751328447510550299250924469288819"),g:BigInt(2)}},r.H={SHA1:e.crossEnvCrypto.hashFunctions.SHA1,SHA256:e.crossEnvCrypto.hashFunctions.SHA256,SHA384:e.crossEnvCrypto.hashFunctions.SHA384,SHA512:e.crossEnvCrypto.hashFunctions.SHA512},E}var R={},T={},q;function N(){return q||(q=1,function(e){var r=T&&T.__awaiter||function(c,a,f,h){function y(p){return p instanceof f?p:new f(function(H){H(p)})}return new(f||(f=Promise))(function(p,H){function L(A){try{O(h.next(A))}catch(j){H(j)}}function W(A){try{O(h.throw(A))}catch(j){H(j)}}function O(A){A.done?p(A.value):y(A.value).then(L,W)}O((h=h.apply(c,a||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0}),e.modPow=e.hashBitCount=e.createVerifierAndSalt=e.createVerifier=e.generateRandomBigInt=e.generateRandomString=e.hashPadded=e.hash=e.padStartArrayBuffer=e.stringToArrayBuffer=e.arrayBufferToBigInt=e.bigIntToArrayBuffer=void 0;const l=X(),d=BigInt(0),n=BigInt(1),t=BigInt(2),i=c=>{const a=c.toString(16),f=new ArrayBuffer(Math.ceil(a.length/2)),h=new Uint8Array(f);let y=0;a.length%2!==0&&(h[0]=parseInt(a[0],16),y=1);for(let p=0;p<f.byteLength;p++)h[p+y]=parseInt(a.slice(2*p+y,2*p+2+y),16);return f};e.bigIntToArrayBuffer=i;const o=c=>{const a=[];return new Uint8Array(c).forEach(f=>{a.push(("0"+f.toString(16)).slice(-2))}),BigInt(`0x${a.join("")}`)};e.arrayBufferToBigInt=o;function s(c){return new TextEncoder().encode(c).buffer}e.stringToArrayBuffer=s;const u=(c,a)=>{const f=new Uint8Array(c);if(f.length<a){const h=new Uint8Array(a);return h.fill(0,0,a-f.length),h.set(f,a-f.length),h}return f};e.padStartArrayBuffer=u;function S(c,...a){const f=a.reduce((y,p)=>y+p.byteLength,0),h=new Uint8Array(f);for(let y=0,p=0;p<a.length;p++)h.set(new Uint8Array(a[p]),y),y+=a[p].byteLength;return c.H(h)}e.hash=S;function m(c,a,...f){const h=f.map(y=>e.padStartArrayBuffer(y,a));return S(c,...h)}e.hashPadded=m;function g(c=10){const a=new Uint8Array(Math.ceil(Math.ceil(c/2)));return l.crossEnvCrypto.randomBytes(a),a.reduce((f,h)=>{const y=h.toString(16).toString();return y.length===1?f+"0"+y:f+y},"").slice(0,c)}e.generateRandomString=g;function v(c=16){return e.arrayBufferToBigInt(z(c))}e.generateRandomBigInt=v;function B(c,a,f,h){return r(this,void 0,void 0,function*(){if(!a||!a.trim())throw new Error("Identity (I) must not be null or empty.");if(!f)throw new Error("Salt (s) must not be null.");if(!h)throw new Error("Password (P) must not be null");const y=yield c.computeX(a,f,h);return c.computeVerifier(y)})}e.createVerifier=B;function w(c,a,f,h){return r(this,void 0,void 0,function*(){const y=yield c.generateRandomSalt(h);return{s:y,v:yield B(c,a,y,f)}})}e.createVerifierAndSalt=w;const P=c=>r(void 0,void 0,void 0,function*(){return(yield S(c,e.bigIntToArrayBuffer(BigInt(1)))).byteLength*8});e.hashBitCount=P;function _(c,a,f){let h=n;for(;a>d;)a%t==n?(h=c*h%f,a-=n):(c=c*c%f,a/=t);return h}e.modPow=_;const z=c=>{const a=new Uint8Array(c);return l.crossEnvCrypto.randomBytes(a),a.buffer}}(T)),T}var F;function te(){if(F)return R;F=1;var e=R&&R.__awaiter||function(d,n,t,i){function o(s){return s instanceof t?s:new t(function(u){u(s)})}return new(t||(t=Promise))(function(s,u){function S(v){try{g(i.next(v))}catch(B){u(B)}}function m(v){try{g(i.throw(v))}catch(B){u(B)}}function g(v){v.done?s(v.value):o(v.value).then(S,m)}g((i=i.apply(d,n||[])).next())})};Object.defineProperty(R,"__esModule",{value:!0}),R.SRPRoutines=void 0;const r=N();class l{constructor(n){this.parameters=n}hash(...n){return r.hash(this.parameters,...n)}hashPadded(...n){const t=Math.trunc((this.parameters.NBits+7)/8);return r.hashPadded(this.parameters,t,...n)}computeK(){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hashPadded(r.bigIntToArrayBuffer(this.parameters.primeGroup.N),r.bigIntToArrayBuffer(this.parameters.primeGroup.g)))})}generateRandomSalt(n){return e(this,void 0,void 0,function*(){const t=yield r.hashBitCount(this.parameters),i=n||2*t/8;return r.generateRandomBigInt(i)})}computeX(n,t,i){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(t),yield this.computeIdentityHash(n,i)))})}computeXStep2(n,t){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(n),t))})}computeIdentityHash(n,t){return e(this,void 0,void 0,function*(){return yield this.hash(r.stringToArrayBuffer(t))})}computeVerifier(n){return r.modPow(this.parameters.primeGroup.g,n,this.parameters.primeGroup.N)}generatePrivateValue(){const n=Math.max(256,this.parameters.NBits);let t;do t=r.generateRandomBigInt(n/8)%this.parameters.primeGroup.N;while(t===BigInt(0));return t}computeClientPublicValue(n){return r.modPow(this.parameters.primeGroup.g,n,this.parameters.primeGroup.N)}isValidPublicValue(n){return n%this.parameters.primeGroup.N!==BigInt(0)}computeU(n,t){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hashPadded(r.bigIntToArrayBuffer(n),r.bigIntToArrayBuffer(t)))})}computeClientEvidence(n,t,i,o,s){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(i),r.bigIntToArrayBuffer(o),r.bigIntToArrayBuffer(s)))})}computeServerEvidence(n,t,i){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(n),r.bigIntToArrayBuffer(t),r.bigIntToArrayBuffer(i)))})}computeClientSessionKey(n,t,i,o,s){const u=this.parameters.primeGroup.N,S=i*t+o,m=r.modPow(this.parameters.primeGroup.g,t,u)*n%u;return r.modPow(s+u-m,S,u)}}return R.SRPRoutines=l,R}var b={},K;function re(){if(K)return b;K=1;var e=b&&b.__awaiter||function(n,t,i,o){function s(u){return u instanceof i?u:new i(function(S){S(u)})}return new(i||(i=Promise))(function(u,S){function m(B){try{v(o.next(B))}catch(w){S(w)}}function g(B){try{v(o.throw(B))}catch(w){S(w)}}function v(B){B.done?u(B.value):s(B.value).then(m,g)}v((o=o.apply(n,t||[])).next())})};Object.defineProperty(b,"__esModule",{value:!0}),b.SRPClientSessionStep2=b.SRPClientSessionStep1=b.SRPClientSession=void 0;class r{constructor(t){this.routines=t}step1(t,i){return e(this,void 0,void 0,function*(){if(!t||!t.trim())throw new Error("User identity must not be null nor empty");if(!i)throw new Error("User password must not be null");const o=yield this.routines.computeIdentityHash(t,i);return new l(this.routines,t,o)})}}b.SRPClientSession=r;class l{constructor(t,i,o){this.routines=t,this.I=i,this.IH=o}step2(t,i){return e(this,void 0,void 0,function*(){if(!t)throw new Error("Salt (s) must not be null");if(!i)throw new Error("Public server value (B) must not be null");const o=yield this.routines.computeXStep2(t,this.IH),s=this.routines.generatePrivateValue(),u=this.routines.computeClientPublicValue(s),S=yield this.routines.computeK(),m=yield this.routines.computeU(u,i),g=this.routines.computeClientSessionKey(S,o,m,s,i),v=yield this.routines.computeClientEvidence(this.I,t,u,i,g);return new d(this.routines,u,v,g)})}toJSON(){return{I:this.I,IH:Array.from(new Uint8Array(this.IH))}}static fromState(t,i){return new l(t,i.I,new Uint8Array(i.IH).buffer)}}b.SRPClientSessionStep1=l;class d{constructor(t,i,o,s){this.routines=t,this.A=i,this.M1=o,this.S=s}step3(t){return e(this,void 0,void 0,function*(){if(!t)throw new Error("Server evidence (M2) must not be null");if((yield this.routines.computeServerEvidence(this.A,this.M1,this.S))!==t)throw new Error("Bad server credentials")})}toJSON(){return{A:this.A.toString(16),M1:this.M1.toString(16),S:this.S.toString(16)}}static fromState(t,i){return new d(t,BigInt("0x"+i.A),BigInt("0x"+i.M1),BigInt("0x"+i.S))}}return b.SRPClientSessionStep2=d,b}var I={},k;function ne(){if(k)return I;k=1;var e=I&&I.__awaiter||function(i,o,s,u){function S(m){return m instanceof s?m:new s(function(g){g(m)})}return new(s||(s=Promise))(function(m,g){function v(P){try{w(u.next(P))}catch(_){g(_)}}function B(P){try{w(u.throw(P))}catch(_){g(_)}}function w(P){P.done?m(P.value):S(P.value).then(v,B)}w((u=u.apply(i,o||[])).next())})};Object.defineProperty(I,"__esModule",{value:!0}),I.SRPServerSessionStep1=I.SRPServerSession=void 0;const r=N();class l{constructor(o){this.routines=o}step1(o,s,u){return e(this,void 0,void 0,function*(){const S=this.routines.generatePrivateValue(),m=yield this.routines.computeK(),g=n(this.routines.parameters,m,u,S);return new d(this.routines,o,s,u,S,g)})}}I.SRPServerSession=l;class d{constructor(o,s,u,S,m,g){this.routines=o,this.identifier=s,this.salt=u,this.verifier=S,this.b=m,this.B=g}sessionKey(o){return e(this,void 0,void 0,function*(){if(o===null)throw new Error("Client public value (A) must not be null");if(!this.routines.isValidPublicValue(o))throw new Error(`Invalid Client public value (A): ${o.toString(16)}`);const s=yield this.routines.computeU(o,this.B);return t(this.routines.parameters.primeGroup.N,this.verifier,s,o,this.b)})}step2(o,s){return e(this,void 0,void 0,function*(){if(!s)throw new Error("Client evidence (M1) must not be null");const u=yield this.sessionKey(o);if((yield this.routines.computeClientEvidence(this.identifier,this.salt,o,this.B,u))!==s)throw new Error("Bad client credentials");return this.routines.computeServerEvidence(o,s,u)})}toJSON(){return{identifier:this.identifier,salt:this.salt.toString(16),verifier:this.verifier.toString(16),b:this.b.toString(16),B:this.B.toString(16)}}static fromState(o,s){return new d(o,s.identifier,BigInt("0x"+s.salt),BigInt("0x"+s.verifier),BigInt("0x"+s.b),BigInt("0x"+s.B))}}I.SRPServerSessionStep1=d;const n=(i,o,s,u)=>(r.modPow(i.primeGroup.g,u,i.primeGroup.N)+s*o)%i.primeGroup.N,t=(i,o,s,u,S)=>r.modPow(r.modPow(o,s,i)*u,S,i);return I}var D;function ie(){return D||(D=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.generateRandomBigInt=e.arrayBufferToBigInt=e.bigIntToArrayBuffer=e.createVerifierAndSalt=e.SRPServerSessionStep1=e.SRPServerSession=e.SRPClientSessionStep2=e.SRPClientSessionStep1=e.SRPClientSession=e.SRPRoutines=e.SRPParameters=void 0;var r=ee();Object.defineProperty(e,"SRPParameters",{enumerable:!0,get:function(){return r.SRPParameters}});var l=te();Object.defineProperty(e,"SRPRoutines",{enumerable:!0,get:function(){return l.SRPRoutines}});var d=re();Object.defineProperty(e,"SRPClientSession",{enumerable:!0,get:function(){return d.SRPClientSession}}),Object.defineProperty(e,"SRPClientSessionStep1",{enumerable:!0,get:function(){return d.SRPClientSessionStep1}}),Object.defineProperty(e,"SRPClientSessionStep2",{enumerable:!0,get:function(){return d.SRPClientSessionStep2}});var n=ne();Object.defineProperty(e,"SRPServerSession",{enumerable:!0,get:function(){return n.SRPServerSession}}),Object.defineProperty(e,"SRPServerSessionStep1",{enumerable:!0,get:function(){return n.SRPServerSessionStep1}});var t=N();Object.defineProperty(e,"createVerifierAndSalt",{enumerable:!0,get:function(){return t.createVerifierAndSalt}}),Object.defineProperty(e,"bigIntToArrayBuffer",{enumerable:!0,get:function(){return t.bigIntToArrayBuffer}}),Object.defineProperty(e,"arrayBufferToBigInt",{enumerable:!0,get:function(){return t.arrayBufferToBigInt}}),Object.defineProperty(e,"generateRandomBigInt",{enumerable:!0,get:function(){return t.generateRandomBigInt}})}(M)),M}var J=ie();const oe=Z(J),ue=Q({__proto__:null,default:oe},[J]);export{ue as i};
1
+ import{a as Y,g as Z}from"./index-BhGDgjyF.js";function Q(e,r){for(var l=0;l<r.length;l++){const d=r[l];if(typeof d!="string"&&!Array.isArray(d)){for(const n in d)if(n!=="default"&&!(n in e)){const t=Object.getOwnPropertyDescriptor(d,n);t&&Object.defineProperty(e,n,t.get?t:{enumerable:!0,get:()=>d[n]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var M={},E={},C={};const x={},$=Object.freeze(Object.defineProperty({__proto__:null,default:x},Symbol.toStringTag,{value:"Module"})),V=Y($);var G;function X(){if(G)return C;G=1,Object.defineProperty(C,"__esModule",{value:!0}),C.crossEnvCrypto=void 0;try{const e=typeof window!="undefined"&&window.crypto||V.webcrypto;if(e){if(!e.subtle)throw new Error("Crypto.Subtle is undefined. Make sure you are using HTTPS in a compatible browser.");const r=l=>d=>e.subtle.digest(l,d);C.crossEnvCrypto={randomBytes:e.getRandomValues.bind(e),hashFunctions:{SHA1:r("SHA-1"),SHA256:r("SHA-256"),SHA384:r("SHA-384"),SHA512:r("SHA-512")}}}else{const r=V,l=d=>n=>r.createHash(d).update(n).digest().buffer;C.crossEnvCrypto={randomBytes:r.randomFillSync,hashFunctions:{SHA1:l("sha1"),SHA256:l("sha256"),SHA384:l("sha384"),SHA512:l("sha512")}}}}catch(e){throw console.error(e),new Error("No suitable crypto library was found. You may need a polyfill.")}return C}var U;function ee(){if(U)return E;U=1,Object.defineProperty(E,"__esModule",{value:!0}),E.SRPParameters=void 0;const e=X();class r{constructor(d=r.PrimeGroup[2048],n=r.H.SHA512){if(this.primeGroup=d,this.H=n,this.NBits=this.primeGroup.N.toString(2).length,!n)throw new Error("Hash function required")}}return E.SRPParameters=r,r.PrimeGroup={256:{N:BigInt("125617018995153554710546479714086468244499594888726646874671447258204721048803"),g:BigInt(2)},512:{N:BigInt("11144252439149533417835749556168991736939157778924947037200268358613863350040339017097790259154750906072491181606044774215413467851989724116331597513345603"),g:BigInt(2)},768:{N:BigInt("1087179135105457859072065649059069760280540086975817629066444682366896187793570736574549981488868217843627094867924800342887096064844227836735667168319981288765377499806385489913341488724152562880918438701129530606139552645689583147"),g:BigInt(2)},1024:{N:BigInt("167609434410335061345139523764350090260135525329813904557420930309800865859473551531551523800013916573891864789934747039010546328480848979516637673776605610374669426214776197828492691384519453218253702788022233205683635831626913357154941914129985489522629902540768368409482248290641036967659389658897350067939"),g:BigInt(2)},1536:{N:BigInt("1486998185923128292816507353619409521152457662596380074614818966810244974827752411420380336514078832314731499938313197533147998565301020797040787428051479639316928015998415709101293902971072960487527411068082311763171549170528008620813391411445907584912865222076100726050255271567749213905330659264908657221124284665444825474741087704974475795505492821585749417639344967192301749033325359286273431675492866492416941152646940908101472416714421046022696100064262587"),g:BigInt(2)},2048:{N:BigInt("21766174458617435773191008891802753781907668374255538511144643224689886235383840957210909013086056401571399717235807266581649606472148410291413364152197364477180887395655483738115072677402235101762521901569820740293149529620419333266262073471054548368736039519702486226506248861060256971802984953561121442680157668000761429988222457090413873973970171927093992114751765168063614761119615476233422096442783117971236371647333871414335895773474667308967050807005509320424799678417036867928316761272274230314067548291133582479583061439577559347101961771406173684378522703483495337037655006751328447510550299250924469288819"),g:BigInt(2)}},r.H={SHA1:e.crossEnvCrypto.hashFunctions.SHA1,SHA256:e.crossEnvCrypto.hashFunctions.SHA256,SHA384:e.crossEnvCrypto.hashFunctions.SHA384,SHA512:e.crossEnvCrypto.hashFunctions.SHA512},E}var R={},T={},q;function N(){return q||(q=1,function(e){var r=T&&T.__awaiter||function(c,a,f,h){function y(p){return p instanceof f?p:new f(function(H){H(p)})}return new(f||(f=Promise))(function(p,H){function L(A){try{O(h.next(A))}catch(j){H(j)}}function W(A){try{O(h.throw(A))}catch(j){H(j)}}function O(A){A.done?p(A.value):y(A.value).then(L,W)}O((h=h.apply(c,a||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0}),e.modPow=e.hashBitCount=e.createVerifierAndSalt=e.createVerifier=e.generateRandomBigInt=e.generateRandomString=e.hashPadded=e.hash=e.padStartArrayBuffer=e.stringToArrayBuffer=e.arrayBufferToBigInt=e.bigIntToArrayBuffer=void 0;const l=X(),d=BigInt(0),n=BigInt(1),t=BigInt(2),i=c=>{const a=c.toString(16),f=new ArrayBuffer(Math.ceil(a.length/2)),h=new Uint8Array(f);let y=0;a.length%2!==0&&(h[0]=parseInt(a[0],16),y=1);for(let p=0;p<f.byteLength;p++)h[p+y]=parseInt(a.slice(2*p+y,2*p+2+y),16);return f};e.bigIntToArrayBuffer=i;const o=c=>{const a=[];return new Uint8Array(c).forEach(f=>{a.push(("0"+f.toString(16)).slice(-2))}),BigInt(`0x${a.join("")}`)};e.arrayBufferToBigInt=o;function s(c){return new TextEncoder().encode(c).buffer}e.stringToArrayBuffer=s;const u=(c,a)=>{const f=new Uint8Array(c);if(f.length<a){const h=new Uint8Array(a);return h.fill(0,0,a-f.length),h.set(f,a-f.length),h}return f};e.padStartArrayBuffer=u;function S(c,...a){const f=a.reduce((y,p)=>y+p.byteLength,0),h=new Uint8Array(f);for(let y=0,p=0;p<a.length;p++)h.set(new Uint8Array(a[p]),y),y+=a[p].byteLength;return c.H(h)}e.hash=S;function m(c,a,...f){const h=f.map(y=>e.padStartArrayBuffer(y,a));return S(c,...h)}e.hashPadded=m;function g(c=10){const a=new Uint8Array(Math.ceil(Math.ceil(c/2)));return l.crossEnvCrypto.randomBytes(a),a.reduce((f,h)=>{const y=h.toString(16).toString();return y.length===1?f+"0"+y:f+y},"").slice(0,c)}e.generateRandomString=g;function v(c=16){return e.arrayBufferToBigInt(z(c))}e.generateRandomBigInt=v;function B(c,a,f,h){return r(this,void 0,void 0,function*(){if(!a||!a.trim())throw new Error("Identity (I) must not be null or empty.");if(!f)throw new Error("Salt (s) must not be null.");if(!h)throw new Error("Password (P) must not be null");const y=yield c.computeX(a,f,h);return c.computeVerifier(y)})}e.createVerifier=B;function w(c,a,f,h){return r(this,void 0,void 0,function*(){const y=yield c.generateRandomSalt(h);return{s:y,v:yield B(c,a,y,f)}})}e.createVerifierAndSalt=w;const P=c=>r(void 0,void 0,void 0,function*(){return(yield S(c,e.bigIntToArrayBuffer(BigInt(1)))).byteLength*8});e.hashBitCount=P;function _(c,a,f){let h=n;for(;a>d;)a%t==n?(h=c*h%f,a-=n):(c=c*c%f,a/=t);return h}e.modPow=_;const z=c=>{const a=new Uint8Array(c);return l.crossEnvCrypto.randomBytes(a),a.buffer}}(T)),T}var F;function te(){if(F)return R;F=1;var e=R&&R.__awaiter||function(d,n,t,i){function o(s){return s instanceof t?s:new t(function(u){u(s)})}return new(t||(t=Promise))(function(s,u){function S(v){try{g(i.next(v))}catch(B){u(B)}}function m(v){try{g(i.throw(v))}catch(B){u(B)}}function g(v){v.done?s(v.value):o(v.value).then(S,m)}g((i=i.apply(d,n||[])).next())})};Object.defineProperty(R,"__esModule",{value:!0}),R.SRPRoutines=void 0;const r=N();class l{constructor(n){this.parameters=n}hash(...n){return r.hash(this.parameters,...n)}hashPadded(...n){const t=Math.trunc((this.parameters.NBits+7)/8);return r.hashPadded(this.parameters,t,...n)}computeK(){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hashPadded(r.bigIntToArrayBuffer(this.parameters.primeGroup.N),r.bigIntToArrayBuffer(this.parameters.primeGroup.g)))})}generateRandomSalt(n){return e(this,void 0,void 0,function*(){const t=yield r.hashBitCount(this.parameters),i=n||2*t/8;return r.generateRandomBigInt(i)})}computeX(n,t,i){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(t),yield this.computeIdentityHash(n,i)))})}computeXStep2(n,t){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(n),t))})}computeIdentityHash(n,t){return e(this,void 0,void 0,function*(){return yield this.hash(r.stringToArrayBuffer(t))})}computeVerifier(n){return r.modPow(this.parameters.primeGroup.g,n,this.parameters.primeGroup.N)}generatePrivateValue(){const n=Math.max(256,this.parameters.NBits);let t;do t=r.generateRandomBigInt(n/8)%this.parameters.primeGroup.N;while(t===BigInt(0));return t}computeClientPublicValue(n){return r.modPow(this.parameters.primeGroup.g,n,this.parameters.primeGroup.N)}isValidPublicValue(n){return n%this.parameters.primeGroup.N!==BigInt(0)}computeU(n,t){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hashPadded(r.bigIntToArrayBuffer(n),r.bigIntToArrayBuffer(t)))})}computeClientEvidence(n,t,i,o,s){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(i),r.bigIntToArrayBuffer(o),r.bigIntToArrayBuffer(s)))})}computeServerEvidence(n,t,i){return e(this,void 0,void 0,function*(){return r.arrayBufferToBigInt(yield this.hash(r.bigIntToArrayBuffer(n),r.bigIntToArrayBuffer(t),r.bigIntToArrayBuffer(i)))})}computeClientSessionKey(n,t,i,o,s){const u=this.parameters.primeGroup.N,S=i*t+o,m=r.modPow(this.parameters.primeGroup.g,t,u)*n%u;return r.modPow(s+u-m,S,u)}}return R.SRPRoutines=l,R}var b={},K;function re(){if(K)return b;K=1;var e=b&&b.__awaiter||function(n,t,i,o){function s(u){return u instanceof i?u:new i(function(S){S(u)})}return new(i||(i=Promise))(function(u,S){function m(B){try{v(o.next(B))}catch(w){S(w)}}function g(B){try{v(o.throw(B))}catch(w){S(w)}}function v(B){B.done?u(B.value):s(B.value).then(m,g)}v((o=o.apply(n,t||[])).next())})};Object.defineProperty(b,"__esModule",{value:!0}),b.SRPClientSessionStep2=b.SRPClientSessionStep1=b.SRPClientSession=void 0;class r{constructor(t){this.routines=t}step1(t,i){return e(this,void 0,void 0,function*(){if(!t||!t.trim())throw new Error("User identity must not be null nor empty");if(!i)throw new Error("User password must not be null");const o=yield this.routines.computeIdentityHash(t,i);return new l(this.routines,t,o)})}}b.SRPClientSession=r;class l{constructor(t,i,o){this.routines=t,this.I=i,this.IH=o}step2(t,i){return e(this,void 0,void 0,function*(){if(!t)throw new Error("Salt (s) must not be null");if(!i)throw new Error("Public server value (B) must not be null");const o=yield this.routines.computeXStep2(t,this.IH),s=this.routines.generatePrivateValue(),u=this.routines.computeClientPublicValue(s),S=yield this.routines.computeK(),m=yield this.routines.computeU(u,i),g=this.routines.computeClientSessionKey(S,o,m,s,i),v=yield this.routines.computeClientEvidence(this.I,t,u,i,g);return new d(this.routines,u,v,g)})}toJSON(){return{I:this.I,IH:Array.from(new Uint8Array(this.IH))}}static fromState(t,i){return new l(t,i.I,new Uint8Array(i.IH).buffer)}}b.SRPClientSessionStep1=l;class d{constructor(t,i,o,s){this.routines=t,this.A=i,this.M1=o,this.S=s}step3(t){return e(this,void 0,void 0,function*(){if(!t)throw new Error("Server evidence (M2) must not be null");if((yield this.routines.computeServerEvidence(this.A,this.M1,this.S))!==t)throw new Error("Bad server credentials")})}toJSON(){return{A:this.A.toString(16),M1:this.M1.toString(16),S:this.S.toString(16)}}static fromState(t,i){return new d(t,BigInt("0x"+i.A),BigInt("0x"+i.M1),BigInt("0x"+i.S))}}return b.SRPClientSessionStep2=d,b}var I={},k;function ne(){if(k)return I;k=1;var e=I&&I.__awaiter||function(i,o,s,u){function S(m){return m instanceof s?m:new s(function(g){g(m)})}return new(s||(s=Promise))(function(m,g){function v(P){try{w(u.next(P))}catch(_){g(_)}}function B(P){try{w(u.throw(P))}catch(_){g(_)}}function w(P){P.done?m(P.value):S(P.value).then(v,B)}w((u=u.apply(i,o||[])).next())})};Object.defineProperty(I,"__esModule",{value:!0}),I.SRPServerSessionStep1=I.SRPServerSession=void 0;const r=N();class l{constructor(o){this.routines=o}step1(o,s,u){return e(this,void 0,void 0,function*(){const S=this.routines.generatePrivateValue(),m=yield this.routines.computeK(),g=n(this.routines.parameters,m,u,S);return new d(this.routines,o,s,u,S,g)})}}I.SRPServerSession=l;class d{constructor(o,s,u,S,m,g){this.routines=o,this.identifier=s,this.salt=u,this.verifier=S,this.b=m,this.B=g}sessionKey(o){return e(this,void 0,void 0,function*(){if(o===null)throw new Error("Client public value (A) must not be null");if(!this.routines.isValidPublicValue(o))throw new Error(`Invalid Client public value (A): ${o.toString(16)}`);const s=yield this.routines.computeU(o,this.B);return t(this.routines.parameters.primeGroup.N,this.verifier,s,o,this.b)})}step2(o,s){return e(this,void 0,void 0,function*(){if(!s)throw new Error("Client evidence (M1) must not be null");const u=yield this.sessionKey(o);if((yield this.routines.computeClientEvidence(this.identifier,this.salt,o,this.B,u))!==s)throw new Error("Bad client credentials");return this.routines.computeServerEvidence(o,s,u)})}toJSON(){return{identifier:this.identifier,salt:this.salt.toString(16),verifier:this.verifier.toString(16),b:this.b.toString(16),B:this.B.toString(16)}}static fromState(o,s){return new d(o,s.identifier,BigInt("0x"+s.salt),BigInt("0x"+s.verifier),BigInt("0x"+s.b),BigInt("0x"+s.B))}}I.SRPServerSessionStep1=d;const n=(i,o,s,u)=>(r.modPow(i.primeGroup.g,u,i.primeGroup.N)+s*o)%i.primeGroup.N,t=(i,o,s,u,S)=>r.modPow(r.modPow(o,s,i)*u,S,i);return I}var D;function ie(){return D||(D=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.generateRandomBigInt=e.arrayBufferToBigInt=e.bigIntToArrayBuffer=e.createVerifierAndSalt=e.SRPServerSessionStep1=e.SRPServerSession=e.SRPClientSessionStep2=e.SRPClientSessionStep1=e.SRPClientSession=e.SRPRoutines=e.SRPParameters=void 0;var r=ee();Object.defineProperty(e,"SRPParameters",{enumerable:!0,get:function(){return r.SRPParameters}});var l=te();Object.defineProperty(e,"SRPRoutines",{enumerable:!0,get:function(){return l.SRPRoutines}});var d=re();Object.defineProperty(e,"SRPClientSession",{enumerable:!0,get:function(){return d.SRPClientSession}}),Object.defineProperty(e,"SRPClientSessionStep1",{enumerable:!0,get:function(){return d.SRPClientSessionStep1}}),Object.defineProperty(e,"SRPClientSessionStep2",{enumerable:!0,get:function(){return d.SRPClientSessionStep2}});var n=ne();Object.defineProperty(e,"SRPServerSession",{enumerable:!0,get:function(){return n.SRPServerSession}}),Object.defineProperty(e,"SRPServerSessionStep1",{enumerable:!0,get:function(){return n.SRPServerSessionStep1}});var t=N();Object.defineProperty(e,"createVerifierAndSalt",{enumerable:!0,get:function(){return t.createVerifierAndSalt}}),Object.defineProperty(e,"bigIntToArrayBuffer",{enumerable:!0,get:function(){return t.bigIntToArrayBuffer}}),Object.defineProperty(e,"arrayBufferToBigInt",{enumerable:!0,get:function(){return t.arrayBufferToBigInt}}),Object.defineProperty(e,"generateRandomBigInt",{enumerable:!0,get:function(){return t.generateRandomBigInt}})}(M)),M}var J=ie();const oe=Z(J),ue=Q({__proto__:null,default:oe},[J]);export{ue as i};
@@ -1,4 +1,4 @@
1
- import{c as UF,g as gF}from"./index-BXz3BvVz.js";function RF(sF,xF){for(var eF=0;eF<xF.length;eF++){const tF=xF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var yF={exports:{}};/*
1
+ import{c as UF,g as gF}from"./index-BhGDgjyF.js";function RF(sF,xF){for(var eF=0;eF<xF.length;eF++){const tF=xF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var yF={exports:{}};/*
2
2
  * [js-sha512]{@link https://github.com/emn178/js-sha512}
3
3
  *
4
4
  * @version 0.8.0
package/admin/index.html CHANGED
@@ -8,7 +8,7 @@
8
8
  <link href="../frontend/fontello.css" rel="stylesheet" />
9
9
  <link href="/flags/freakflags.css" rel="stylesheet" />
10
10
  <link href="../frontend/fontello.woff2" rel="prefetch" />
11
- <script type="module" crossorigin src="/assets/index-BXz3BvVz.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-BhGDgjyF.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-B66w-a0v.css">
13
13
  </head>
14
14
  <body>
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "hfs",
9
- "version": "3.1.0",
9
+ "version": "3.1.1",
10
10
  "license": "GPL-3.0",
11
11
  "dependencies": {
12
12
  "@gregoranders/csv": "^0.0.13",
13
- "@rejetto/kvstorage": "^0.17.2",
13
+ "@rejetto/kvstorage": "^0.17.6",
14
14
  "acme-client": "^5.4.0",
15
15
  "busboy": "^1.6.0",
16
16
  "crc-32": "^1.2.2",
@@ -252,9 +252,9 @@
252
252
  }
253
253
  },
254
254
  "node_modules/@rejetto/kvstorage": {
255
- "version": "0.17.2",
256
- "resolved": "https://registry.npmjs.org/@rejetto/kvstorage/-/kvstorage-0.17.2.tgz",
257
- "integrity": "sha512-E7iGOPKUEofg0bC1AJ5TzYJnT1yThYgT86zp7K0B39VKFQ+dpZGqaKryx/6sLD69eKcOgJsDGvL9KDPkK4Ky7g==",
255
+ "version": "0.17.6",
256
+ "resolved": "https://registry.npmjs.org/@rejetto/kvstorage/-/kvstorage-0.17.6.tgz",
257
+ "integrity": "sha512-lebA0WZH+fMwNpdpAlJiw4LO9Mu1hhPiWfSlCuNYc8bxLs/WwqRe8Z/B3DgWF1OKYWSj+h3rKYFY6J5p/nt95g==",
258
258
  "license": "MIT"
259
259
  },
260
260
  "node_modules/accepts": {
@@ -323,13 +323,13 @@
323
323
  }
324
324
  },
325
325
  "node_modules/asn1js": {
326
- "version": "3.0.7",
327
- "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.7.tgz",
328
- "integrity": "sha512-uLvq6KJu04qoQM6gvBfKFjlh6Gl0vOKQuR5cJMDHQkmwfMOQeN3F3SHCv9SNYSL+CRoHvOGFfllDlVz03GQjvQ==",
326
+ "version": "3.0.10",
327
+ "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.10.tgz",
328
+ "integrity": "sha512-S2s3aOytiKdFRdulw2qPE51MzjzVOisppcVv7jVFR+Kw0kxwvFrDcYA0h7Ndqbmj0HkMIXYWaoj7fli8kgx1eg==",
329
329
  "license": "BSD-3-Clause",
330
330
  "dependencies": {
331
331
  "pvtsutils": "^1.3.6",
332
- "pvutils": "^1.1.3",
332
+ "pvutils": "^1.1.5",
333
333
  "tslib": "^2.8.1"
334
334
  },
335
335
  "engines": {
@@ -343,9 +343,9 @@
343
343
  "license": "MIT"
344
344
  },
345
345
  "node_modules/axios": {
346
- "version": "1.15.0",
347
- "resolved": "https://registry.npmjs.org/axios/-/axios-1.15.0.tgz",
348
- "integrity": "sha512-wWyJDlAatxk30ZJer+GeCWS209sA42X+N5jU2jy6oHTp7ufw8uzUTVFBX9+wTfAlhiJXGS0Bq7X6efruWjuK9Q==",
346
+ "version": "1.15.2",
347
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.15.2.tgz",
348
+ "integrity": "sha512-wLrXxPtcrPTsNlJmKjkPnNPK2Ihe0hn0wGSaTEiHRPxwjvJwT3hKmXF4dpqxmPO9SoNb2FsYXj/xEo0gHN+D5A==",
349
349
  "license": "MIT",
350
350
  "dependencies": {
351
351
  "follow-redirects": "^1.15.11",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "dependencies": {
84
84
  "@gregoranders/csv": "^0.0.13",
85
- "@rejetto/kvstorage": "^0.17.2",
85
+ "@rejetto/kvstorage": "^0.17.6",
86
86
  "acme-client": "^5.4.0",
87
87
  "busboy": "^1.6.0",
88
88
  "crc-32": "^1.2.2",
package/src/first.js CHANGED
@@ -13,7 +13,16 @@ exports.quitting = false;
13
13
  onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT', 'SIGHUP'], signal => {
14
14
  console.log('Quitting with signal:', signal || 'unknown');
15
15
  exports.quitting = true;
16
- return Promise.allSettled(Array.from(cbsOnExit).map(cb => cb(signal))).then(() => {
16
+ return Promise.allSettled(Array.from(cbsOnExit).map(cb => {
17
+ try {
18
+ return cb(signal);
19
+ }
20
+ // keep exit moving even when a synchronous cleanup fails after partially shutting down
21
+ catch (e) {
22
+ console.error("Error while quitting", e);
23
+ return Promise.reject(e);
24
+ }
25
+ })).then(() => {
17
26
  console.debug('Process exit');
18
27
  process.exit(0);
19
28
  });
package/src/update.js CHANGED
@@ -181,7 +181,18 @@ async function update(tagOrUrl = '') {
181
181
  catch { }
182
182
  (0, fs_1.renameSync)(bin, oldBin);
183
183
  if (!preserveTerminal) {
184
- (0, fs_1.renameSync)(newBin, (0, path_1.join)(binPath, binFile));
184
+ try {
185
+ renameSyncWithBusyRetry(newBin, (0, path_1.join)(binPath, binFile));
186
+ }
187
+ catch (e) {
188
+ try {
189
+ (0, fs_1.renameSync)(oldBin, bin);
190
+ } // restore the service target because hfs.exe was already moved aside
191
+ catch (rollbackError) {
192
+ console.error("Couldn't restore original binary after failed update", rollbackError);
193
+ }
194
+ throw e;
195
+ }
185
196
  console.log("Updated binary in place, exiting for process supervisor to restart");
186
197
  return;
187
198
  }
@@ -197,6 +208,19 @@ async function update(tagOrUrl = '') {
197
208
  throw e?.message || String(e);
198
209
  }
199
210
  }
211
+ function renameSyncWithBusyRetry(src, dest) {
212
+ const sleepSyncBuffer = new Int32Array(new SharedArrayBuffer(4));
213
+ for (let retry = 0;; retry++) {
214
+ try {
215
+ return (0, fs_1.renameSync)(src, dest);
216
+ }
217
+ catch (e) {
218
+ if (e?.code !== 'EBUSY' || retry >= 20)
219
+ throw e;
220
+ Atomics.wait(sleepSyncBuffer, 0, 0, 500);
221
+ }
222
+ }
223
+ }
200
224
  if (argv_1.argv.updating) { // we were launched with a temporary name, restore original name to avoid breaking references
201
225
  const bin = process.execPath;
202
226
  const dest = (0, path_1.join)((0, path_1.dirname)(bin), argv_1.argv.updating);
package/src/util-files.js CHANGED
@@ -27,7 +27,7 @@ const fs_1 = require("fs");
27
27
  const path_1 = require("path");
28
28
  const fast_glob_1 = __importDefault(require("fast-glob"));
29
29
  const const_1 = require("./const");
30
- const events_1 = require("events");
30
+ const promises_2 = require("stream/promises");
31
31
  const stat_1 = require("./stat");
32
32
  // @ts-ignore
33
33
  const unzip_stream_1 = __importDefault(require("unzip-stream"));
@@ -115,7 +115,7 @@ async function unzip(stream, cb) {
115
115
  return entry.autodrain();
116
116
  console.debug('Unzip', dest);
117
117
  const thisFile = entry.pipe(await createSafeWriteStream(dest));
118
- await (0, events_1.once)(thisFile, 'finish');
118
+ await (0, promises_2.finished)(thisFile);
119
119
  })));
120
120
  }
121
121
  async function ensureParentFolder(path, dirnameIt = true) {
package/src/vfs.js CHANGED
@@ -162,12 +162,13 @@ async function getNodeByName(name, parent, assumeMissingToBeFolder = false) {
162
162
  return ret;
163
163
  }
164
164
  }
165
- const smartUncFolderDetection = (0, config_1.defineConfig)('smart_unc_folder_detection', true);
165
+ const smartUncFolderDetection = (0, config_1.defineConfig)('smart_unc_folder_detection', false);
166
166
  async function setIsFolder(node) {
167
167
  if (!node.source)
168
168
  return;
169
- const isFolder = smartUncFolderDetection.get() && (0, misc_1.getUncHost)(node.source) ? !(0, path_1.basename)(node.source).includes('.') // no dot = folder – not very reliable but fast for unreachable unc hosts, and you can opt-out
170
- : /[\\/]$/.test(node.source) || await nodeStats(node).then(x => x?.isDirectory(), () => undefined);
169
+ const isFolder = /[\\/]$/.test(node.source)
170
+ || smartUncFolderDetection.get() && (0, misc_1.getUncHost)(node.source) && !(0, path_1.basename)(node.source).includes('.') // no dot = folder; not very reliable but fast for unreachable unc hosts, and it's an opt-in
171
+ || await nodeStats(node).then(x => x?.isDirectory(), () => undefined);
171
172
  (0, misc_1.setHidden)(node, { isFolder });
172
173
  return isFolder;
173
174
  }