hfs 3.1.0-alpha1 → 3.1.0-alpha2

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.
@@ -0,0 +1 @@
1
+ import{a as Y,g as Z}from"./index-P5i8LyWl.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};